/drivers/message/fusion/mptsas.c

https://bitbucket.org/wisechild/galaxy-nexus · C · 5416 lines · 4279 code · 669 blank · 468 comment · 596 complexity · 71677b1d80352a180e7c6361b27e0e19 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * linux/drivers/message/fusion/mptsas.c
  3. * For use with LSI PCI chip/adapter(s)
  4. * running LSI Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2008 LSI Corporation
  7. * (mailto:DL-MPTFusionLinux@lsi.com)
  8. */
  9. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  10. /*
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; version 2 of the License.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. NO WARRANTY
  19. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. solely responsible for determining the appropriateness of using and
  24. distributing the Program and assumes all risks associated with its
  25. exercise of rights under this Agreement, including but not limited to
  26. the risks and costs of program errors, damage to or loss of data,
  27. programs or equipment, and unavailability or interruption of operations.
  28. DISCLAIMER OF LIABILITY
  29. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  30. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  32. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  33. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  35. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  36. You should have received a copy of the GNU General Public License
  37. along with this program; if not, write to the Free Software
  38. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  39. */
  40. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/slab.h>
  44. #include <linux/init.h>
  45. #include <linux/errno.h>
  46. #include <linux/jiffies.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/delay.h> /* for mdelay */
  49. #include <scsi/scsi.h>
  50. #include <scsi/scsi_cmnd.h>
  51. #include <scsi/scsi_device.h>
  52. #include <scsi/scsi_host.h>
  53. #include <scsi/scsi_transport_sas.h>
  54. #include <scsi/scsi_transport.h>
  55. #include <scsi/scsi_dbg.h>
  56. #include "mptbase.h"
  57. #include "mptscsih.h"
  58. #include "mptsas.h"
  59. #define my_NAME "Fusion MPT SAS Host driver"
  60. #define my_VERSION MPT_LINUX_VERSION_COMMON
  61. #define MYNAM "mptsas"
  62. /*
  63. * Reserved channel for integrated raid
  64. */
  65. #define MPTSAS_RAID_CHANNEL 1
  66. #define SAS_CONFIG_PAGE_TIMEOUT 30
  67. MODULE_AUTHOR(MODULEAUTHOR);
  68. MODULE_DESCRIPTION(my_NAME);
  69. MODULE_LICENSE("GPL");
  70. MODULE_VERSION(my_VERSION);
  71. static int mpt_pt_clear;
  72. module_param(mpt_pt_clear, int, 0);
  73. MODULE_PARM_DESC(mpt_pt_clear,
  74. " Clear persistency table: enable=1 "
  75. "(default=MPTSCSIH_PT_CLEAR=0)");
  76. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  77. #define MPTSAS_MAX_LUN (16895)
  78. static int max_lun = MPTSAS_MAX_LUN;
  79. module_param(max_lun, int, 0);
  80. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  81. static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
  82. static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
  83. static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
  84. static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
  85. static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
  86. static void mptsas_firmware_event_work(struct work_struct *work);
  87. static void mptsas_send_sas_event(struct fw_event_work *fw_event);
  88. static void mptsas_send_raid_event(struct fw_event_work *fw_event);
  89. static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
  90. static void mptsas_parse_device_info(struct sas_identify *identify,
  91. struct mptsas_devinfo *device_info);
  92. static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
  93. struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
  94. static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
  95. (MPT_ADAPTER *ioc, u64 sas_address);
  96. static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
  97. struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
  98. static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
  99. struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
  100. static int mptsas_add_end_device(MPT_ADAPTER *ioc,
  101. struct mptsas_phyinfo *phy_info);
  102. static void mptsas_del_end_device(MPT_ADAPTER *ioc,
  103. struct mptsas_phyinfo *phy_info);
  104. static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
  105. static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
  106. (MPT_ADAPTER *ioc, u64 sas_address);
  107. static void mptsas_expander_delete(MPT_ADAPTER *ioc,
  108. struct mptsas_portinfo *port_info, u8 force);
  109. static void mptsas_send_expander_event(struct fw_event_work *fw_event);
  110. static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
  111. static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
  112. static void mptsas_broadcast_primative_work(struct fw_event_work *fw_event);
  113. static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event);
  114. static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id);
  115. void mptsas_schedule_target_reset(void *ioc);
  116. static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
  117. MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
  118. {
  119. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  120. "---- IO UNIT PAGE 0 ------------\n", ioc->name));
  121. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
  122. ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
  123. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
  124. ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
  125. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
  126. ioc->name, phy_data->Port));
  127. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
  128. ioc->name, phy_data->PortFlags));
  129. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
  130. ioc->name, phy_data->PhyFlags));
  131. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
  132. ioc->name, phy_data->NegotiatedLinkRate));
  133. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  134. "Controller PHY Device Info=0x%X\n", ioc->name,
  135. le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
  136. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
  137. ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
  138. }
  139. static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
  140. {
  141. __le64 sas_address;
  142. memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
  143. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  144. "---- SAS PHY PAGE 0 ------------\n", ioc->name));
  145. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  146. "Attached Device Handle=0x%X\n", ioc->name,
  147. le16_to_cpu(pg0->AttachedDevHandle)));
  148. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
  149. ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
  150. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  151. "Attached PHY Identifier=0x%X\n", ioc->name,
  152. pg0->AttachedPhyIdentifier));
  153. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
  154. ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
  155. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
  156. ioc->name, pg0->ProgrammedLinkRate));
  157. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
  158. ioc->name, pg0->ChangeCount));
  159. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
  160. ioc->name, le32_to_cpu(pg0->PhyInfo)));
  161. }
  162. static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
  163. {
  164. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  165. "---- SAS PHY PAGE 1 ------------\n", ioc->name));
  166. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
  167. ioc->name, pg1->InvalidDwordCount));
  168. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  169. "Running Disparity Error Count=0x%x\n", ioc->name,
  170. pg1->RunningDisparityErrorCount));
  171. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  172. "Loss Dword Synch Count=0x%x\n", ioc->name,
  173. pg1->LossDwordSynchCount));
  174. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  175. "PHY Reset Problem Count=0x%x\n\n", ioc->name,
  176. pg1->PhyResetProblemCount));
  177. }
  178. static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
  179. {
  180. __le64 sas_address;
  181. memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
  182. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  183. "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
  184. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
  185. ioc->name, le16_to_cpu(pg0->DevHandle)));
  186. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
  187. ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
  188. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
  189. ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
  190. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
  191. ioc->name, le16_to_cpu(pg0->Slot)));
  192. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
  193. ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
  194. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
  195. ioc->name, pg0->TargetID));
  196. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
  197. ioc->name, pg0->Bus));
  198. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
  199. ioc->name, pg0->PhyNum));
  200. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
  201. ioc->name, le16_to_cpu(pg0->AccessStatus)));
  202. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
  203. ioc->name, le32_to_cpu(pg0->DeviceInfo)));
  204. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
  205. ioc->name, le16_to_cpu(pg0->Flags)));
  206. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
  207. ioc->name, pg0->PhysicalPort));
  208. }
  209. static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
  210. {
  211. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  212. "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
  213. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
  214. ioc->name, pg1->PhysicalPort));
  215. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
  216. ioc->name, pg1->PhyIdentifier));
  217. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
  218. ioc->name, pg1->NegotiatedLinkRate));
  219. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
  220. ioc->name, pg1->ProgrammedLinkRate));
  221. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
  222. ioc->name, pg1->HwLinkRate));
  223. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
  224. ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
  225. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  226. "Attached Device Handle=0x%X\n\n", ioc->name,
  227. le16_to_cpu(pg1->AttachedDevHandle)));
  228. }
  229. /* inhibit sas firmware event handling */
  230. static void
  231. mptsas_fw_event_off(MPT_ADAPTER *ioc)
  232. {
  233. unsigned long flags;
  234. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  235. ioc->fw_events_off = 1;
  236. ioc->sas_discovery_quiesce_io = 0;
  237. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  238. }
  239. /* enable sas firmware event handling */
  240. static void
  241. mptsas_fw_event_on(MPT_ADAPTER *ioc)
  242. {
  243. unsigned long flags;
  244. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  245. ioc->fw_events_off = 0;
  246. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  247. }
  248. /* queue a sas firmware event */
  249. static void
  250. mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
  251. unsigned long delay)
  252. {
  253. unsigned long flags;
  254. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  255. list_add_tail(&fw_event->list, &ioc->fw_event_list);
  256. INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
  257. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)\n",
  258. ioc->name, __func__, fw_event));
  259. queue_delayed_work(ioc->fw_event_q, &fw_event->work,
  260. delay);
  261. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  262. }
  263. /* requeue a sas firmware event */
  264. static void
  265. mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
  266. unsigned long delay)
  267. {
  268. unsigned long flags;
  269. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  270. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task "
  271. "(fw_event=0x%p)\n", ioc->name, __func__, fw_event));
  272. fw_event->retries++;
  273. queue_delayed_work(ioc->fw_event_q, &fw_event->work,
  274. msecs_to_jiffies(delay));
  275. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  276. }
  277. /* free memory associated to a sas firmware event */
  278. static void
  279. mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
  280. {
  281. unsigned long flags;
  282. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  283. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
  284. ioc->name, __func__, fw_event));
  285. list_del(&fw_event->list);
  286. kfree(fw_event);
  287. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  288. }
  289. /* walk the firmware event queue, and either stop or wait for
  290. * outstanding events to complete */
  291. static void
  292. mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
  293. {
  294. struct fw_event_work *fw_event, *next;
  295. struct mptsas_target_reset_event *target_reset_list, *n;
  296. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  297. /* flush the target_reset_list */
  298. if (!list_empty(&hd->target_reset_list)) {
  299. list_for_each_entry_safe(target_reset_list, n,
  300. &hd->target_reset_list, list) {
  301. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  302. "%s: removing target reset for id=%d\n",
  303. ioc->name, __func__,
  304. target_reset_list->sas_event_data.TargetID));
  305. list_del(&target_reset_list->list);
  306. kfree(target_reset_list);
  307. }
  308. }
  309. if (list_empty(&ioc->fw_event_list) ||
  310. !ioc->fw_event_q || in_interrupt())
  311. return;
  312. list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
  313. if (cancel_delayed_work(&fw_event->work))
  314. mptsas_free_fw_event(ioc, fw_event);
  315. }
  316. }
  317. static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
  318. {
  319. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  320. return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
  321. }
  322. static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
  323. {
  324. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  325. return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
  326. }
  327. /*
  328. * mptsas_find_portinfo_by_handle
  329. *
  330. * This function should be called with the sas_topology_mutex already held
  331. */
  332. static struct mptsas_portinfo *
  333. mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
  334. {
  335. struct mptsas_portinfo *port_info, *rc=NULL;
  336. int i;
  337. list_for_each_entry(port_info, &ioc->sas_topology, list)
  338. for (i = 0; i < port_info->num_phys; i++)
  339. if (port_info->phy_info[i].identify.handle == handle) {
  340. rc = port_info;
  341. goto out;
  342. }
  343. out:
  344. return rc;
  345. }
  346. /**
  347. * mptsas_find_portinfo_by_sas_address -
  348. * @ioc: Pointer to MPT_ADAPTER structure
  349. * @handle:
  350. *
  351. * This function should be called with the sas_topology_mutex already held
  352. *
  353. **/
  354. static struct mptsas_portinfo *
  355. mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
  356. {
  357. struct mptsas_portinfo *port_info, *rc = NULL;
  358. int i;
  359. if (sas_address >= ioc->hba_port_sas_addr &&
  360. sas_address < (ioc->hba_port_sas_addr +
  361. ioc->hba_port_num_phy))
  362. return ioc->hba_port_info;
  363. mutex_lock(&ioc->sas_topology_mutex);
  364. list_for_each_entry(port_info, &ioc->sas_topology, list)
  365. for (i = 0; i < port_info->num_phys; i++)
  366. if (port_info->phy_info[i].identify.sas_address ==
  367. sas_address) {
  368. rc = port_info;
  369. goto out;
  370. }
  371. out:
  372. mutex_unlock(&ioc->sas_topology_mutex);
  373. return rc;
  374. }
  375. /*
  376. * Returns true if there is a scsi end device
  377. */
  378. static inline int
  379. mptsas_is_end_device(struct mptsas_devinfo * attached)
  380. {
  381. if ((attached->sas_address) &&
  382. (attached->device_info &
  383. MPI_SAS_DEVICE_INFO_END_DEVICE) &&
  384. ((attached->device_info &
  385. MPI_SAS_DEVICE_INFO_SSP_TARGET) |
  386. (attached->device_info &
  387. MPI_SAS_DEVICE_INFO_STP_TARGET) |
  388. (attached->device_info &
  389. MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
  390. return 1;
  391. else
  392. return 0;
  393. }
  394. /* no mutex */
  395. static void
  396. mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
  397. {
  398. struct mptsas_portinfo *port_info;
  399. struct mptsas_phyinfo *phy_info;
  400. u8 i;
  401. if (!port_details)
  402. return;
  403. port_info = port_details->port_info;
  404. phy_info = port_info->phy_info;
  405. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
  406. "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
  407. port_details->num_phys, (unsigned long long)
  408. port_details->phy_bitmask));
  409. for (i = 0; i < port_info->num_phys; i++, phy_info++) {
  410. if(phy_info->port_details != port_details)
  411. continue;
  412. memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
  413. mptsas_set_rphy(ioc, phy_info, NULL);
  414. phy_info->port_details = NULL;
  415. }
  416. kfree(port_details);
  417. }
  418. static inline struct sas_rphy *
  419. mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
  420. {
  421. if (phy_info->port_details)
  422. return phy_info->port_details->rphy;
  423. else
  424. return NULL;
  425. }
  426. static inline void
  427. mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
  428. {
  429. if (phy_info->port_details) {
  430. phy_info->port_details->rphy = rphy;
  431. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
  432. ioc->name, rphy));
  433. }
  434. if (rphy) {
  435. dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  436. &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
  437. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
  438. ioc->name, rphy, rphy->dev.release));
  439. }
  440. }
  441. static inline struct sas_port *
  442. mptsas_get_port(struct mptsas_phyinfo *phy_info)
  443. {
  444. if (phy_info->port_details)
  445. return phy_info->port_details->port;
  446. else
  447. return NULL;
  448. }
  449. static inline void
  450. mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
  451. {
  452. if (phy_info->port_details)
  453. phy_info->port_details->port = port;
  454. if (port) {
  455. dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  456. &port->dev, MYIOC_s_FMT "add:", ioc->name));
  457. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
  458. ioc->name, port, port->dev.release));
  459. }
  460. }
  461. static inline struct scsi_target *
  462. mptsas_get_starget(struct mptsas_phyinfo *phy_info)
  463. {
  464. if (phy_info->port_details)
  465. return phy_info->port_details->starget;
  466. else
  467. return NULL;
  468. }
  469. static inline void
  470. mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
  471. starget)
  472. {
  473. if (phy_info->port_details)
  474. phy_info->port_details->starget = starget;
  475. }
  476. /**
  477. * mptsas_add_device_component -
  478. * @ioc: Pointer to MPT_ADAPTER structure
  479. * @channel: fw mapped id's
  480. * @id:
  481. * @sas_address:
  482. * @device_info:
  483. *
  484. **/
  485. static void
  486. mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
  487. u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
  488. {
  489. struct mptsas_device_info *sas_info, *next;
  490. struct scsi_device *sdev;
  491. struct scsi_target *starget;
  492. struct sas_rphy *rphy;
  493. /*
  494. * Delete all matching devices out of the list
  495. */
  496. mutex_lock(&ioc->sas_device_info_mutex);
  497. list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
  498. list) {
  499. if (!sas_info->is_logical_volume &&
  500. (sas_info->sas_address == sas_address ||
  501. (sas_info->fw.channel == channel &&
  502. sas_info->fw.id == id))) {
  503. list_del(&sas_info->list);
  504. kfree(sas_info);
  505. }
  506. }
  507. sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
  508. if (!sas_info)
  509. goto out;
  510. /*
  511. * Set Firmware mapping
  512. */
  513. sas_info->fw.id = id;
  514. sas_info->fw.channel = channel;
  515. sas_info->sas_address = sas_address;
  516. sas_info->device_info = device_info;
  517. sas_info->slot = slot;
  518. sas_info->enclosure_logical_id = enclosure_logical_id;
  519. INIT_LIST_HEAD(&sas_info->list);
  520. list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
  521. /*
  522. * Set OS mapping
  523. */
  524. shost_for_each_device(sdev, ioc->sh) {
  525. starget = scsi_target(sdev);
  526. rphy = dev_to_rphy(starget->dev.parent);
  527. if (rphy->identify.sas_address == sas_address) {
  528. sas_info->os.id = starget->id;
  529. sas_info->os.channel = starget->channel;
  530. }
  531. }
  532. out:
  533. mutex_unlock(&ioc->sas_device_info_mutex);
  534. return;
  535. }
  536. /**
  537. * mptsas_add_device_component_by_fw -
  538. * @ioc: Pointer to MPT_ADAPTER structure
  539. * @channel: fw mapped id's
  540. * @id:
  541. *
  542. **/
  543. static void
  544. mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
  545. {
  546. struct mptsas_devinfo sas_device;
  547. struct mptsas_enclosure enclosure_info;
  548. int rc;
  549. rc = mptsas_sas_device_pg0(ioc, &sas_device,
  550. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  551. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  552. (channel << 8) + id);
  553. if (rc)
  554. return;
  555. memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
  556. mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
  557. (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
  558. MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
  559. sas_device.handle_enclosure);
  560. mptsas_add_device_component(ioc, sas_device.channel,
  561. sas_device.id, sas_device.sas_address, sas_device.device_info,
  562. sas_device.slot, enclosure_info.enclosure_logical_id);
  563. }
  564. /**
  565. * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list
  566. * @ioc: Pointer to MPT_ADAPTER structure
  567. * @channel: fw mapped id's
  568. * @id:
  569. *
  570. **/
  571. static void
  572. mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
  573. struct scsi_target *starget)
  574. {
  575. CONFIGPARMS cfg;
  576. ConfigPageHeader_t hdr;
  577. dma_addr_t dma_handle;
  578. pRaidVolumePage0_t buffer = NULL;
  579. int i;
  580. RaidPhysDiskPage0_t phys_disk;
  581. struct mptsas_device_info *sas_info, *next;
  582. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  583. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  584. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
  585. /* assumption that all volumes on channel = 0 */
  586. cfg.pageAddr = starget->id;
  587. cfg.cfghdr.hdr = &hdr;
  588. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  589. cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
  590. if (mpt_config(ioc, &cfg) != 0)
  591. goto out;
  592. if (!hdr.PageLength)
  593. goto out;
  594. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  595. &dma_handle);
  596. if (!buffer)
  597. goto out;
  598. cfg.physAddr = dma_handle;
  599. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  600. if (mpt_config(ioc, &cfg) != 0)
  601. goto out;
  602. if (!buffer->NumPhysDisks)
  603. goto out;
  604. /*
  605. * Adding entry for hidden components
  606. */
  607. for (i = 0; i < buffer->NumPhysDisks; i++) {
  608. if (mpt_raid_phys_disk_pg0(ioc,
  609. buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
  610. continue;
  611. mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
  612. phys_disk.PhysDiskID);
  613. mutex_lock(&ioc->sas_device_info_mutex);
  614. list_for_each_entry(sas_info, &ioc->sas_device_info_list,
  615. list) {
  616. if (!sas_info->is_logical_volume &&
  617. (sas_info->fw.channel == phys_disk.PhysDiskBus &&
  618. sas_info->fw.id == phys_disk.PhysDiskID)) {
  619. sas_info->is_hidden_raid_component = 1;
  620. sas_info->volume_id = starget->id;
  621. }
  622. }
  623. mutex_unlock(&ioc->sas_device_info_mutex);
  624. }
  625. /*
  626. * Delete all matching devices out of the list
  627. */
  628. mutex_lock(&ioc->sas_device_info_mutex);
  629. list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
  630. list) {
  631. if (sas_info->is_logical_volume && sas_info->fw.id ==
  632. starget->id) {
  633. list_del(&sas_info->list);
  634. kfree(sas_info);
  635. }
  636. }
  637. sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
  638. if (sas_info) {
  639. sas_info->fw.id = starget->id;
  640. sas_info->os.id = starget->id;
  641. sas_info->os.channel = starget->channel;
  642. sas_info->is_logical_volume = 1;
  643. INIT_LIST_HEAD(&sas_info->list);
  644. list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
  645. }
  646. mutex_unlock(&ioc->sas_device_info_mutex);
  647. out:
  648. if (buffer)
  649. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  650. dma_handle);
  651. }
  652. /**
  653. * mptsas_add_device_component_starget -
  654. * @ioc: Pointer to MPT_ADAPTER structure
  655. * @starget:
  656. *
  657. **/
  658. static void
  659. mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
  660. struct scsi_target *starget)
  661. {
  662. VirtTarget *vtarget;
  663. struct sas_rphy *rphy;
  664. struct mptsas_phyinfo *phy_info = NULL;
  665. struct mptsas_enclosure enclosure_info;
  666. rphy = dev_to_rphy(starget->dev.parent);
  667. vtarget = starget->hostdata;
  668. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  669. rphy->identify.sas_address);
  670. if (!phy_info)
  671. return;
  672. memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
  673. mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
  674. (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
  675. MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
  676. phy_info->attached.handle_enclosure);
  677. mptsas_add_device_component(ioc, phy_info->attached.channel,
  678. phy_info->attached.id, phy_info->attached.sas_address,
  679. phy_info->attached.device_info,
  680. phy_info->attached.slot, enclosure_info.enclosure_logical_id);
  681. }
  682. /**
  683. * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached
  684. * @ioc: Pointer to MPT_ADAPTER structure
  685. * @channel: os mapped id's
  686. * @id:
  687. *
  688. **/
  689. static void
  690. mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
  691. {
  692. struct mptsas_device_info *sas_info, *next;
  693. /*
  694. * Set is_cached flag
  695. */
  696. list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
  697. list) {
  698. if (sas_info->os.channel == channel && sas_info->os.id == id)
  699. sas_info->is_cached = 1;
  700. }
  701. }
  702. /**
  703. * mptsas_del_device_components - Cleaning the list
  704. * @ioc: Pointer to MPT_ADAPTER structure
  705. *
  706. **/
  707. static void
  708. mptsas_del_device_components(MPT_ADAPTER *ioc)
  709. {
  710. struct mptsas_device_info *sas_info, *next;
  711. mutex_lock(&ioc->sas_device_info_mutex);
  712. list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
  713. list) {
  714. list_del(&sas_info->list);
  715. kfree(sas_info);
  716. }
  717. mutex_unlock(&ioc->sas_device_info_mutex);
  718. }
  719. /*
  720. * mptsas_setup_wide_ports
  721. *
  722. * Updates for new and existing narrow/wide port configuration
  723. * in the sas_topology
  724. */
  725. static void
  726. mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
  727. {
  728. struct mptsas_portinfo_details * port_details;
  729. struct mptsas_phyinfo *phy_info, *phy_info_cmp;
  730. u64 sas_address;
  731. int i, j;
  732. mutex_lock(&ioc->sas_topology_mutex);
  733. phy_info = port_info->phy_info;
  734. for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
  735. if (phy_info->attached.handle)
  736. continue;
  737. port_details = phy_info->port_details;
  738. if (!port_details)
  739. continue;
  740. if (port_details->num_phys < 2)
  741. continue;
  742. /*
  743. * Removing a phy from a port, letting the last
  744. * phy be removed by firmware events.
  745. */
  746. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  747. "%s: [%p]: deleting phy = %d\n",
  748. ioc->name, __func__, port_details, i));
  749. port_details->num_phys--;
  750. port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
  751. memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
  752. if (phy_info->phy) {
  753. devtprintk(ioc, dev_printk(KERN_DEBUG,
  754. &phy_info->phy->dev, MYIOC_s_FMT
  755. "delete phy %d, phy-obj (0x%p)\n", ioc->name,
  756. phy_info->phy_id, phy_info->phy));
  757. sas_port_delete_phy(port_details->port, phy_info->phy);
  758. }
  759. phy_info->port_details = NULL;
  760. }
  761. /*
  762. * Populate and refresh the tree
  763. */
  764. phy_info = port_info->phy_info;
  765. for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
  766. sas_address = phy_info->attached.sas_address;
  767. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
  768. ioc->name, i, (unsigned long long)sas_address));
  769. if (!sas_address)
  770. continue;
  771. port_details = phy_info->port_details;
  772. /*
  773. * Forming a port
  774. */
  775. if (!port_details) {
  776. port_details = kzalloc(sizeof(struct
  777. mptsas_portinfo_details), GFP_KERNEL);
  778. if (!port_details)
  779. goto out;
  780. port_details->num_phys = 1;
  781. port_details->port_info = port_info;
  782. if (phy_info->phy_id < 64 )
  783. port_details->phy_bitmask |=
  784. (1 << phy_info->phy_id);
  785. phy_info->sas_port_add_phy=1;
  786. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
  787. "phy_id=%d sas_address=0x%018llX\n",
  788. ioc->name, i, (unsigned long long)sas_address));
  789. phy_info->port_details = port_details;
  790. }
  791. if (i == port_info->num_phys - 1)
  792. continue;
  793. phy_info_cmp = &port_info->phy_info[i + 1];
  794. for (j = i + 1 ; j < port_info->num_phys ; j++,
  795. phy_info_cmp++) {
  796. if (!phy_info_cmp->attached.sas_address)
  797. continue;
  798. if (sas_address != phy_info_cmp->attached.sas_address)
  799. continue;
  800. if (phy_info_cmp->port_details == port_details )
  801. continue;
  802. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  803. "\t\tphy_id=%d sas_address=0x%018llX\n",
  804. ioc->name, j, (unsigned long long)
  805. phy_info_cmp->attached.sas_address));
  806. if (phy_info_cmp->port_details) {
  807. port_details->rphy =
  808. mptsas_get_rphy(phy_info_cmp);
  809. port_details->port =
  810. mptsas_get_port(phy_info_cmp);
  811. port_details->starget =
  812. mptsas_get_starget(phy_info_cmp);
  813. port_details->num_phys =
  814. phy_info_cmp->port_details->num_phys;
  815. if (!phy_info_cmp->port_details->num_phys)
  816. kfree(phy_info_cmp->port_details);
  817. } else
  818. phy_info_cmp->sas_port_add_phy=1;
  819. /*
  820. * Adding a phy to a port
  821. */
  822. phy_info_cmp->port_details = port_details;
  823. if (phy_info_cmp->phy_id < 64 )
  824. port_details->phy_bitmask |=
  825. (1 << phy_info_cmp->phy_id);
  826. port_details->num_phys++;
  827. }
  828. }
  829. out:
  830. for (i = 0; i < port_info->num_phys; i++) {
  831. port_details = port_info->phy_info[i].port_details;
  832. if (!port_details)
  833. continue;
  834. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  835. "%s: [%p]: phy_id=%02d num_phys=%02d "
  836. "bitmask=0x%016llX\n", ioc->name, __func__,
  837. port_details, i, port_details->num_phys,
  838. (unsigned long long)port_details->phy_bitmask));
  839. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
  840. ioc->name, port_details->port, port_details->rphy));
  841. }
  842. dsaswideprintk(ioc, printk("\n"));
  843. mutex_unlock(&ioc->sas_topology_mutex);
  844. }
  845. /**
  846. * csmisas_find_vtarget
  847. *
  848. * @ioc
  849. * @volume_id
  850. * @volume_bus
  851. *
  852. **/
  853. static VirtTarget *
  854. mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
  855. {
  856. struct scsi_device *sdev;
  857. VirtDevice *vdevice;
  858. VirtTarget *vtarget = NULL;
  859. shost_for_each_device(sdev, ioc->sh) {
  860. vdevice = sdev->hostdata;
  861. if ((vdevice == NULL) ||
  862. (vdevice->vtarget == NULL))
  863. continue;
  864. if ((vdevice->vtarget->tflags &
  865. MPT_TARGET_FLAGS_RAID_COMPONENT ||
  866. vdevice->vtarget->raidVolume))
  867. continue;
  868. if (vdevice->vtarget->id == id &&
  869. vdevice->vtarget->channel == channel)
  870. vtarget = vdevice->vtarget;
  871. }
  872. return vtarget;
  873. }
  874. static void
  875. mptsas_queue_device_delete(MPT_ADAPTER *ioc,
  876. MpiEventDataSasDeviceStatusChange_t *sas_event_data)
  877. {
  878. struct fw_event_work *fw_event;
  879. int sz;
  880. sz = offsetof(struct fw_event_work, event_data) +
  881. sizeof(MpiEventDataSasDeviceStatusChange_t);
  882. fw_event = kzalloc(sz, GFP_ATOMIC);
  883. if (!fw_event) {
  884. printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
  885. ioc->name, __func__, __LINE__);
  886. return;
  887. }
  888. memcpy(fw_event->event_data, sas_event_data,
  889. sizeof(MpiEventDataSasDeviceStatusChange_t));
  890. fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
  891. fw_event->ioc = ioc;
  892. mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
  893. }
  894. static void
  895. mptsas_queue_rescan(MPT_ADAPTER *ioc)
  896. {
  897. struct fw_event_work *fw_event;
  898. int sz;
  899. sz = offsetof(struct fw_event_work, event_data);
  900. fw_event = kzalloc(sz, GFP_ATOMIC);
  901. if (!fw_event) {
  902. printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
  903. ioc->name, __func__, __LINE__);
  904. return;
  905. }
  906. fw_event->event = -1;
  907. fw_event->ioc = ioc;
  908. mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
  909. }
  910. /**
  911. * mptsas_target_reset
  912. *
  913. * Issues TARGET_RESET to end device using handshaking method
  914. *
  915. * @ioc
  916. * @channel
  917. * @id
  918. *
  919. * Returns (1) success
  920. * (0) failure
  921. *
  922. **/
  923. static int
  924. mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
  925. {
  926. MPT_FRAME_HDR *mf;
  927. SCSITaskMgmt_t *pScsiTm;
  928. if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
  929. return 0;
  930. mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
  931. if (mf == NULL) {
  932. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
  933. "%s, no msg frames @%d!!\n", ioc->name,
  934. __func__, __LINE__));
  935. goto out_fail;
  936. }
  937. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
  938. ioc->name, mf));
  939. /* Format the Request
  940. */
  941. pScsiTm = (SCSITaskMgmt_t *) mf;
  942. memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
  943. pScsiTm->TargetID = id;
  944. pScsiTm->Bus = channel;
  945. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  946. pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  947. pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
  948. DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
  949. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  950. "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
  951. ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
  952. mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
  953. return 1;
  954. out_fail:
  955. mpt_clear_taskmgmt_in_progress_flag(ioc);
  956. return 0;
  957. }
  958. static void
  959. mptsas_block_io_sdev(struct scsi_device *sdev, void *data)
  960. {
  961. scsi_device_set_state(sdev, SDEV_BLOCK);
  962. }
  963. static void
  964. mptsas_block_io_starget(struct scsi_target *starget)
  965. {
  966. if (starget)
  967. starget_for_each_device(starget, NULL, mptsas_block_io_sdev);
  968. }
  969. /**
  970. * mptsas_target_reset_queue
  971. *
  972. * Receive request for TARGET_RESET after receiving an firmware
  973. * event NOT_RESPONDING_EVENT, then put command in link list
  974. * and queue if task_queue already in use.
  975. *
  976. * @ioc
  977. * @sas_event_data
  978. *
  979. **/
  980. static void
  981. mptsas_target_reset_queue(MPT_ADAPTER *ioc,
  982. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
  983. {
  984. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  985. VirtTarget *vtarget = NULL;
  986. struct mptsas_target_reset_event *target_reset_list;
  987. u8 id, channel;
  988. id = sas_event_data->TargetID;
  989. channel = sas_event_data->Bus;
  990. vtarget = mptsas_find_vtarget(ioc, channel, id);
  991. if (vtarget) {
  992. mptsas_block_io_starget(vtarget->starget);
  993. vtarget->deleted = 1; /* block IO */
  994. }
  995. target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
  996. GFP_ATOMIC);
  997. if (!target_reset_list) {
  998. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
  999. "%s, failed to allocate mem @%d..!!\n",
  1000. ioc->name, __func__, __LINE__));
  1001. return;
  1002. }
  1003. memcpy(&target_reset_list->sas_event_data, sas_event_data,
  1004. sizeof(*sas_event_data));
  1005. list_add_tail(&target_reset_list->list, &hd->target_reset_list);
  1006. target_reset_list->time_count = jiffies;
  1007. if (mptsas_target_reset(ioc, channel, id)) {
  1008. target_reset_list->target_reset_issued = 1;
  1009. }
  1010. }
  1011. /**
  1012. * mptsas_schedule_target_reset- send pending target reset
  1013. * @iocp: per adapter object
  1014. *
  1015. * This function will delete scheduled target reset from the list and
  1016. * try to send next target reset. This will be called from completion
  1017. * context of any Task management command.
  1018. */
  1019. void
  1020. mptsas_schedule_target_reset(void *iocp)
  1021. {
  1022. MPT_ADAPTER *ioc = (MPT_ADAPTER *)(iocp);
  1023. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  1024. struct list_head *head = &hd->target_reset_list;
  1025. struct mptsas_target_reset_event *target_reset_list;
  1026. u8 id, channel;
  1027. /*
  1028. * issue target reset to next device in the queue
  1029. */
  1030. head = &hd->target_reset_list;
  1031. if (list_empty(head))
  1032. return;
  1033. target_reset_list = list_entry(head->next,
  1034. struct mptsas_target_reset_event, list);
  1035. id = target_reset_list->sas_event_data.TargetID;
  1036. channel = target_reset_list->sas_event_data.Bus;
  1037. target_reset_list->time_count = jiffies;
  1038. if (mptsas_target_reset(ioc, channel, id))
  1039. target_reset_list->target_reset_issued = 1;
  1040. return;
  1041. }
  1042. /**
  1043. * mptsas_taskmgmt_complete - complete SAS task management function
  1044. * @ioc: Pointer to MPT_ADAPTER structure
  1045. *
  1046. * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work
  1047. * queue to finish off removing device from upper layers. then send next
  1048. * TARGET_RESET in the queue.
  1049. **/
  1050. static int
  1051. mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  1052. {
  1053. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  1054. struct list_head *head = &hd->target_reset_list;
  1055. u8 id, channel;
  1056. struct mptsas_target_reset_event *target_reset_list;
  1057. SCSITaskMgmtReply_t *pScsiTmReply;
  1058. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
  1059. "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
  1060. pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
  1061. if (pScsiTmReply) {
  1062. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1063. "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
  1064. "\ttask_type = 0x%02X, iocstatus = 0x%04X "
  1065. "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
  1066. "term_cmnds = %d\n", ioc->name,
  1067. pScsiTmReply->Bus, pScsiTmReply->TargetID,
  1068. pScsiTmReply->TaskType,
  1069. le16_to_cpu(pScsiTmReply->IOCStatus),
  1070. le32_to_cpu(pScsiTmReply->IOCLogInfo),
  1071. pScsiTmReply->ResponseCode,
  1072. le32_to_cpu(pScsiTmReply->TerminationCount)));
  1073. if (pScsiTmReply->ResponseCode)
  1074. mptscsih_taskmgmt_response_code(ioc,
  1075. pScsiTmReply->ResponseCode);
  1076. }
  1077. if (pScsiTmReply && (pScsiTmReply->TaskType ==
  1078. MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
  1079. MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
  1080. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  1081. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  1082. memcpy(ioc->taskmgmt_cmds.reply, mr,
  1083. min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
  1084. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
  1085. ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  1086. complete(&ioc->taskmgmt_cmds.done);
  1087. return 1;
  1088. }
  1089. return 0;
  1090. }
  1091. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1092. if (list_empty(head))
  1093. return 1;
  1094. target_reset_list = list_entry(head->next,
  1095. struct mptsas_target_reset_event, list);
  1096. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1097. "TaskMgmt: completed (%d seconds)\n",
  1098. ioc->name, jiffies_to_msecs(jiffies -
  1099. target_reset_list->time_count)/1000));
  1100. id = pScsiTmReply->TargetID;
  1101. channel = pScsiTmReply->Bus;
  1102. target_reset_list->time_count = jiffies;
  1103. /*
  1104. * retry target reset
  1105. */
  1106. if (!target_reset_list->target_reset_issued) {
  1107. if (mptsas_target_reset(ioc, channel, id))
  1108. target_reset_list->target_reset_issued = 1;
  1109. return 1;
  1110. }
  1111. /*
  1112. * enable work queue to remove device from upper layers
  1113. */
  1114. list_del(&target_reset_list->list);
  1115. if (!ioc->fw_events_off)
  1116. mptsas_queue_device_delete(ioc,
  1117. &target_reset_list->sas_event_data);
  1118. ioc->schedule_target_reset(ioc);
  1119. return 1;
  1120. }
  1121. /**
  1122. * mptscsih_ioc_reset
  1123. *
  1124. * @ioc
  1125. * @reset_phase
  1126. *
  1127. **/
  1128. static int
  1129. mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  1130. {
  1131. MPT_SCSI_HOST *hd;
  1132. int rc;
  1133. rc = mptscsih_ioc_reset(ioc, reset_phase);
  1134. if ((ioc->bus_type != SAS) || (!rc))
  1135. return rc;
  1136. hd = shost_priv(ioc->sh);
  1137. if (!hd->ioc)
  1138. goto out;
  1139. switch (reset_phase) {
  1140. case MPT_IOC_SETUP_RESET:
  1141. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1142. "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
  1143. mptsas_fw_event_off(ioc);
  1144. break;
  1145. case MPT_IOC_PRE_RESET:
  1146. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1147. "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
  1148. break;
  1149. case MPT_IOC_POST_RESET:
  1150. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1151. "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
  1152. if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
  1153. ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
  1154. complete(&ioc->sas_mgmt.done);
  1155. }
  1156. mptsas_cleanup_fw_event_q(ioc);
  1157. mptsas_queue_rescan(ioc);
  1158. break;
  1159. default:
  1160. break;
  1161. }
  1162. out:
  1163. return rc;
  1164. }
  1165. /**
  1166. * enum device_state -
  1167. * @DEVICE_RETRY: need to retry the TUR
  1168. * @DEVICE_ERROR: TUR return error, don't add device
  1169. * @DEVICE_READY: device can be added
  1170. *
  1171. */
  1172. enum device_state{
  1173. DEVICE_RETRY,
  1174. DEVICE_ERROR,
  1175. DEVICE_READY,
  1176. };
  1177. static int
  1178. mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
  1179. u32 form, u32 form_specific)
  1180. {
  1181. ConfigExtendedPageHeader_t hdr;
  1182. CONFIGPARMS cfg;
  1183. SasEnclosurePage0_t *buffer;
  1184. dma_addr_t dma_handle;
  1185. int error;
  1186. __le64 le_identifier;
  1187. memset(&hdr, 0, sizeof(hdr));
  1188. hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
  1189. hdr.PageNumber = 0;
  1190. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1191. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
  1192. cfg.cfghdr.ehdr = &hdr;
  1193. cfg.physAddr = -1;
  1194. cfg.pageAddr = form + form_specific;
  1195. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1196. cfg.dir = 0; /* read */
  1197. cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
  1198. error = mpt_config(ioc, &cfg);
  1199. if (error)
  1200. goto out;
  1201. if (!hdr.ExtPageLength) {
  1202. error = -ENXIO;
  1203. goto out;
  1204. }
  1205. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1206. &dma_handle);
  1207. if (!buffer) {
  1208. error = -ENOMEM;
  1209. goto out;
  1210. }
  1211. cfg.physAddr = dma_handle;
  1212. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1213. error = mpt_config(ioc, &cfg);
  1214. if (error)
  1215. goto out_free_consistent;
  1216. /* save config data */
  1217. memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
  1218. enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
  1219. enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
  1220. enclosure->flags = le16_to_cpu(buffer->Flags);
  1221. enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
  1222. enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
  1223. enclosure->start_id = buffer->StartTargetID;
  1224. enclosure->start_channel = buffer->StartBus;
  1225. enclosure->sep_id = buffer->SEPTargetID;
  1226. enclosure->sep_channel = buffer->SEPBus;
  1227. out_free_consistent:
  1228. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1229. buffer, dma_handle);
  1230. out:
  1231. return error;
  1232. }
  1233. /**
  1234. * mptsas_add_end_device - report a new end device to sas transport layer
  1235. * @ioc: Pointer to MPT_ADAPTER structure
  1236. * @phy_info: describes attached device
  1237. *
  1238. * return (0) success (1) failure
  1239. *
  1240. **/
  1241. static int
  1242. mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
  1243. {
  1244. struct sas_rphy *rphy;
  1245. struct sas_port *port;
  1246. struct sas_identify identify;
  1247. char *ds = NULL;
  1248. u8 fw_id;
  1249. if (!phy_info) {
  1250. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1251. "%s: exit at line=%d\n", ioc->name,
  1252. __func__, __LINE__));
  1253. return 1;
  1254. }
  1255. fw_id = phy_info->attached.id;
  1256. if (mptsas_get_rphy(phy_info)) {
  1257. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1258. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1259. __func__, fw_id, __LINE__));
  1260. return 2;
  1261. }
  1262. port = mptsas_get_port(phy_info);
  1263. if (!port) {
  1264. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1265. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1266. __func__, fw_id, __LINE__));
  1267. return 3;
  1268. }
  1269. if (phy_info->attached.device_info &
  1270. MPI_SAS_DEVICE_INFO_SSP_TARGET)
  1271. ds = "ssp";
  1272. if (phy_info->attached.device_info &
  1273. MPI_SAS_DEVICE_INFO_STP_TARGET)
  1274. ds = "stp";
  1275. if (phy_info->attached.device_info &
  1276. MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  1277. ds = "sata";
  1278. printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
  1279. " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
  1280. phy_info->attached.channel, phy_info->attached.id,
  1281. phy_info->attached.phy_id, (unsigned long long)
  1282. phy_info->attached.sas_address);
  1283. mptsas_parse_device_info(&identify, &phy_info->attached);
  1284. rphy = sas_end_device_alloc(port);
  1285. if (!rphy) {
  1286. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1287. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1288. __func__, fw_id, __LINE__));
  1289. return 5; /* non-fatal: an rphy can be added later */
  1290. }
  1291. rphy->identify = identify;
  1292. if (sas_rphy_add(rphy)) {
  1293. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1294. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1295. __func__, fw_id, __LINE__));
  1296. sas_rphy_free(rphy);
  1297. return 6;
  1298. }
  1299. mptsas_set_rphy(ioc, phy_info, rphy);
  1300. return 0;
  1301. }
  1302. /**
  1303. * mptsas_del_end_device - report a deleted end device to sas transport layer
  1304. * @ioc: Pointer to MPT_ADAPTER structure
  1305. * @phy_info: describes attached device
  1306. *
  1307. **/
  1308. static void
  1309. mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
  1310. {
  1311. struct sas_rphy *rphy;
  1312. struct sas_port *port;
  1313. struct mptsas_portinfo *port_info;
  1314. struct mptsas_phyinfo *phy_info_parent;
  1315. int i;
  1316. char *ds = NULL;
  1317. u8 fw_id;
  1318. u64 sas_address;
  1319. if (!phy_info)
  1320. return;
  1321. fw_id = phy_info->attached.id;
  1322. sas_address = phy_info->attached.sas_address;
  1323. if (!phy_info->port_details) {
  1324. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1325. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1326. __func__, fw_id, __LINE__));
  1327. return;
  1328. }
  1329. rphy = mptsas_get_rphy(phy_info);
  1330. if (!rphy) {
  1331. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1332. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1333. __func__, fw_id, __LINE__));
  1334. return;
  1335. }
  1336. if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
  1337. || phy_info->attached.device_info
  1338. & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
  1339. || phy_info->attached.device_info
  1340. & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
  1341. ds = "initiator";
  1342. if (phy_info->attached.device_info &
  1343. MPI_SAS_DEVICE_INFO_SSP_TARGET)
  1344. ds = "ssp";
  1345. if (phy_info->attached.device_info &
  1346. MPI_SAS_DEVICE_INFO_STP_TARGET)
  1347. ds = "stp";
  1348. if (phy_info->attached.device_info &
  1349. MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  1350. ds = "sata";
  1351. dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
  1352. "removing %s device: fw_channel %d, fw_id %d, phy %d,"
  1353. "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
  1354. phy_info->attached.id, phy_info->attached.phy_id,
  1355. (unsigned long long) sas_address);
  1356. port = mptsas_get_port(phy_info);
  1357. if (!port) {
  1358. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1359. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1360. __func__, fw_id, __LINE__));
  1361. return;
  1362. }
  1363. port_info = phy_info->portinfo;
  1364. phy_info_parent = port_info->phy_info;
  1365. for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
  1366. if (!phy_info_parent->phy)
  1367. continue;
  1368. if (phy_info_parent->attached.sas_address !=
  1369. sas_address)
  1370. continue;
  1371. dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
  1372. MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
  1373. ioc->name, phy_info_parent->phy_id,
  1374. phy_info_parent->phy);
  1375. sas_port_delete_phy(port, phy_info_parent->phy);
  1376. }
  1377. dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
  1378. "delete port %d, sas_addr (0x%llx)\n", ioc->name,
  1379. port->port_identifier, (unsigned long long)sas_address);
  1380. sas_port_delete(port);
  1381. mptsas_set_port(ioc, phy_info, NULL);
  1382. mptsas_port_delete(ioc, phy_info->port_details);
  1383. }
  1384. struct mptsas_phyinfo *
  1385. mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
  1386. struct mptsas_devinfo *sas_device)
  1387. {
  1388. struct mptsas_phyinfo *phy_info;
  1389. struct mptsas_portinfo *port_info;
  1390. int i;
  1391. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  1392. sas_device->sas_address);
  1393. if (!phy_info)
  1394. goto out;
  1395. port_info = phy_info->portinfo;
  1396. if (!port_info)
  1397. goto out;
  1398. mutex_lock(&ioc->sas_topology_mutex);
  1399. for (i = 0; i < port_info->num_phys; i++) {
  1400. if (port_info->phy_info[i].attached.sas_address !=
  1401. sas_device->sas_address)
  1402. continue;
  1403. port_info->phy_info[i].attached.channel = sas_device->channel;
  1404. port_info->phy_info[i].attached.id = sas_device->id;
  1405. port_info->phy_info[i].attached.sas_address =
  1406. sas_device->sas_address;
  1407. port_info->phy_info[i].attached.handle = sas_device->handle;
  1408. port_info->phy_info[i].attached.handle_parent =
  1409. sas_device->handle_parent;
  1410. port_info->phy_info[i].attached.handle_enclosure =
  1411. sas_device->handle_enclosure;
  1412. }
  1413. mutex_unlock(&ioc->sas_topology_mutex);
  1414. out:
  1415. return phy_info;
  1416. }
  1417. /**
  1418. * mptsas_firmware_event_work - work thread for processing fw events
  1419. * @work: work queue payload containing info describing the event
  1420. * Context: user
  1421. *
  1422. */
  1423. static void
  1424. mptsas_firmware_event_work(struct work_struct *work)
  1425. {
  1426. struct fw_event_work *fw_event =
  1427. container_of(work, struct fw_event_work, work.work);
  1428. MPT_ADAPTER *ioc = fw_event->ioc;
  1429. /* special rescan topology handling */
  1430. if (fw_event->event == -1) {
  1431. if (ioc->in_rescan) {
  1432. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1433. "%s: rescan ignored as it is in progress\n",
  1434. ioc->name, __func__));
  1435. return;
  1436. }
  1437. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
  1438. "reset\n", ioc->name, __func__));
  1439. ioc->in_rescan = 1;
  1440. mptsas_not_responding_devices(ioc);
  1441. mptsas_scan_sas_topology(ioc);
  1442. ioc->in_rescan = 0;
  1443. mptsas_free_fw_event(ioc, fw_event);
  1444. mptsas_fw_event_on(ioc);
  1445. return;
  1446. }
  1447. /* events handling turned off during host reset */
  1448. if (ioc->fw_events_off) {
  1449. mptsas_free_fw_event(ioc, fw_event);
  1450. return;
  1451. }
  1452. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
  1453. "event = (0x%02x)\n", ioc->name, __func__, fw_event,
  1454. (fw_event->event & 0xFF)));
  1455. switch (fw_event->event) {
  1456. case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
  1457. mptsas_send_sas_event(fw_event);
  1458. break;
  1459. case MPI_EVENT_INTEGRATED_RAID:
  1460. mptsas_send_raid_event(fw_event);
  1461. break;
  1462. case MPI_EVENT_IR2:
  1463. mptsas_send_ir2_event(fw_event);
  1464. break;
  1465. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  1466. mptbase_sas_persist_operation(ioc,
  1467. MPI_SAS_OP_CLEAR_NOT_PRESENT);
  1468. mptsas_free_fw_event(ioc, fw_event);
  1469. break;
  1470. case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
  1471. mptsas_broadcast_primative_work(fw_event);
  1472. break;
  1473. case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
  1474. mptsas_send_expander_event(fw_event);
  1475. break;
  1476. case MPI_EVENT_SAS_PHY_LINK_STATUS:
  1477. mptsas_send_link_status_event(fw_event);
  1478. break;
  1479. case MPI_EVENT_QUEUE_FULL:
  1480. mptsas_handle_queue_full_event(fw_event);
  1481. break;
  1482. }
  1483. }
  1484. static int
  1485. mptsas_slave_configure(struct scsi_device *sdev)
  1486. {
  1487. struct Scsi_Host *host = sdev->host;
  1488. MPT_SCSI_HOST *hd = shost_priv(host);
  1489. MPT_ADAPTER *ioc = hd->ioc;
  1490. VirtDevice *vdevice = sdev->hostdata;
  1491. if (vdevice->vtarget->deleted) {
  1492. sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n");
  1493. vdevice->vtarget->deleted = 0;
  1494. }
  1495. /*
  1496. * RAID volumes placed beyond the last expected port.
  1497. * Ignore sending sas mode pages in that case..
  1498. */
  1499. if (sdev->channel == MPTSAS_RAID_CHANNEL) {
  1500. mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev));
  1501. goto out;
  1502. }
  1503. sas_read_port_mode_page(sdev);
  1504. mptsas_add_device_component_starget(ioc, scsi_target(sdev));
  1505. out:
  1506. return mptscsih_slave_configure(sdev);
  1507. }
  1508. static int
  1509. mptsas_target_alloc(struct scsi_target *starget)
  1510. {
  1511. struct Scsi_Host *host = dev_to_shost(&starget->dev);
  1512. MPT_SCSI_HOST *hd = shost_priv(host);
  1513. VirtTarget *vtarget;
  1514. u8 id, channel;
  1515. struct sas_rphy *rphy;
  1516. struct mptsas_portinfo *p;
  1517. int i;
  1518. MPT_ADAPTER *ioc