46 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/slab.h>
50 #include <linux/errno.h>
55 #include <scsi/scsi.h>
68 #define my_NAME "Fusion MPT SAS Host driver"
69 #define my_VERSION MPT_LINUX_VERSION_COMMON
70 #define MYNAM "mptsas"
75 #define MPTSAS_RAID_CHANNEL 1
77 #define SAS_CONFIG_PAGE_TIMEOUT 30
83 static int mpt_pt_clear;
86 " Clear persistency table: enable=1 "
87 "(default=MPTSCSIH_PT_CLEAR=0)");
90 #define MPTSAS_MAX_LUN (16895)
95 static int mpt_loadtime_max_sectors = 8192;
98 " Maximum sector define for Host Bus Adaptor.Range 64 to 8192 default=8192");
107 static void mptsas_send_sas_event(
struct fw_event_work *fw_event);
108 static void mptsas_send_raid_event(
struct fw_event_work *fw_event);
109 static void mptsas_send_ir2_event(
struct fw_event_work *fw_event);
110 static void mptsas_parse_device_info(
struct sas_identify *identify,
112 static inline void mptsas_set_rphy(MPT_ADAPTER *
ioc,
115 (MPT_ADAPTER *
ioc,
u64 sas_address);
116 static int mptsas_sas_device_pg0(MPT_ADAPTER *
ioc,
118 static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *
ioc,
120 static int mptsas_add_end_device(MPT_ADAPTER *
ioc,
122 static void mptsas_del_end_device(MPT_ADAPTER *
ioc,
124 static void mptsas_send_link_status_event(
struct fw_event_work *fw_event);
126 (MPT_ADAPTER *
ioc,
u64 sas_address);
127 static void mptsas_expander_delete(MPT_ADAPTER *
ioc,
129 static void mptsas_send_expander_event(
struct fw_event_work *fw_event);
130 static void mptsas_not_responding_devices(MPT_ADAPTER *
ioc);
131 static void mptsas_scan_sas_topology(MPT_ADAPTER *
ioc);
132 static void mptsas_broadcast_primative_work(
struct fw_event_work *fw_event);
133 static void mptsas_handle_queue_full_event(
struct fw_event_work *fw_event);
134 static void mptsas_volume_delete(MPT_ADAPTER *
ioc,
u8 id);
137 static void mptsas_print_phy_data(MPT_ADAPTER *
ioc,
141 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
147 ioc->name, phy_data->
Port));
155 "Controller PHY Device Info=0x%X\n", ioc->name,
161 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc,
SasPhyPage0_t *pg0)
168 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
170 "Attached Device Handle=0x%X\n", ioc->name,
173 ioc->name, (
unsigned long long)
le64_to_cpu(sas_address)));
175 "Attached PHY Identifier=0x%X\n", ioc->name,
187 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc,
SasPhyPage1_t *pg1)
190 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
194 "Running Disparity Error Count=0x%x\n", ioc->name,
197 "Loss Dword Synch Count=0x%x\n", ioc->name,
200 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
204 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc,
SasDevicePage0_t *pg0)
211 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
221 ioc->name, (
unsigned long long)
le64_to_cpu(sas_address)));
225 ioc->name, pg0->
Bus));
241 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
255 "Attached Device Handle=0x%X\n\n", ioc->name,
261 mptsas_fw_event_off(MPT_ADAPTER *ioc)
266 ioc->fw_events_off = 1;
267 ioc->sas_discovery_quiesce_io = 0;
268 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
274 mptsas_fw_event_on(MPT_ADAPTER *ioc)
279 ioc->fw_events_off = 0;
280 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
285 mptsas_add_fw_event(MPT_ADAPTER *ioc,
struct fw_event_work *fw_event,
294 "on cpuid %d\n", ioc->name, __func__,
297 &fw_event->
work, delay);
298 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
303 mptsas_requeue_fw_event(MPT_ADAPTER *ioc,
struct fw_event_work *fw_event,
309 "(fw_event=0x%p)on cpuid %d\n", ioc->name, __func__,
314 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
319 mptsas_free_fw_event(MPT_ADAPTER *ioc,
struct fw_event_work *fw_event)
325 ioc->name, __func__, fw_event));
328 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
334 mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
338 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
341 if (!list_empty(&hd->target_reset_list)) {
343 &hd->target_reset_list,
list) {
345 "%s: removing target reset for id=%d\n",
349 kfree(target_reset_list);
353 if (list_empty(&ioc->fw_event_list) ||
359 mptsas_free_fw_event(ioc, fw_event);
364 static inline MPT_ADAPTER *phy_to_ioc(
struct sas_phy *
phy)
367 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
370 static inline MPT_ADAPTER *rphy_to_ioc(
struct sas_rphy *rphy)
372 struct Scsi_Host *shost = dev_to_shost(rphy->
dev.parent->parent);
373 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
382 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc,
u16 handle)
389 if (port_info->
phy_info[i].identify.handle == handle) {
406 mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc,
u64 sas_address)
411 if (sas_address >= ioc->hba_port_sas_addr &&
412 sas_address < (ioc->hba_port_sas_addr +
413 ioc->hba_port_num_phy))
414 return ioc->hba_port_info;
419 if (port_info->
phy_info[i].identify.sas_address ==
464 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
465 port_details->
num_phys, (
unsigned long long)
468 for (i = 0; i < port_info->
num_phys; i++, phy_info++) {
472 mptsas_set_rphy(ioc, phy_info,
NULL);
498 &rphy->
dev, MYIOC_s_FMT
"add:", ioc->name));
500 ioc->name, rphy, rphy->
dev.release));
521 &port->
dev, MYIOC_s_FMT
"add:", ioc->name));
523 ioc->name, port, port->
dev.release));
554 mptsas_add_device_component(MPT_ADAPTER *ioc,
u8 channel,
u8 id,
570 (sas_info->
fw.channel == channel &&
571 sas_info->
fw.id ==
id))) {
584 sas_info->
fw.id =
id;
591 INIT_LIST_HEAD(&sas_info->
list);
600 if (rphy->
identify.sas_address == sas_address) {
601 sas_info->
os.id = starget->
id;
619 mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc,
u8 channel,
u8 id)
625 rc = mptsas_sas_device_pg0(ioc, &sas_device,
628 (channel << 8) +
id);
633 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
636 sas_device.handle_enclosure);
638 mptsas_add_device_component(ioc, sas_device.channel,
639 sas_device.id, sas_device.sas_address, sas_device.device_info,
640 sas_device.slot, enclosure_info.enclosure_logical_id);
651 mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
662 memset(&cfg, 0 ,
sizeof(CONFIGPARMS));
666 cfg.pageAddr = starget->
id;
667 cfg.cfghdr.hdr = &
hdr;
701 mptsas_add_device_component_by_fw(ioc, phys_disk.
PhysDiskBus,
733 sas_info->
fw.id = starget->
id;
734 sas_info->
os.id = starget->
id;
737 INIT_LIST_HEAD(&sas_info->
list);
755 mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
765 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
766 rphy->identify.sas_address);
771 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
774 phy_info->
attached.handle_enclosure);
776 mptsas_add_device_component(ioc, phy_info->
attached.channel,
779 phy_info->
attached.slot, enclosure_info.enclosure_logical_id);
790 mptsas_del_device_component_by_os(MPT_ADAPTER *ioc,
u8 channel,
u8 id)
799 if (sas_info->
os.channel == channel && sas_info->
os.id ==
id)
810 mptsas_del_device_components(MPT_ADAPTER *ioc)
831 mptsas_setup_wide_ports(MPT_ADAPTER *ioc,
struct mptsas_portinfo *port_info)
841 for (i = 0 ; i < port_info->
num_phys ; i++, phy_info++) {
854 "%s: [%p]: deleting phy = %d\n",
855 ioc->name, __func__, port_details, i));
861 &phy_info->
phy->dev, MYIOC_s_FMT
862 "delete phy %d, phy-obj (0x%p)\n", ioc->name,
873 for (i = 0 ; i < port_info->
num_phys ; i++, phy_info++) {
874 sas_address = phy_info->
attached.sas_address;
876 ioc->name, i, (
unsigned long long)sas_address));
884 port_details = kzalloc(
sizeof(
struct
890 if (phy_info->
phy_id < 64 )
895 "phy_id=%d sas_address=0x%018llX\n",
896 ioc->name, i, (
unsigned long long)sas_address));
902 phy_info_cmp = &port_info->
phy_info[i + 1];
903 for (j = i + 1 ; j < port_info->
num_phys ; j++,
905 if (!phy_info_cmp->
attached.sas_address)
907 if (sas_address != phy_info_cmp->
attached.sas_address)
912 "\t\tphy_id=%d sas_address=0x%018llX\n",
913 ioc->name, j, (
unsigned long long)
914 phy_info_cmp->
attached.sas_address));
917 mptsas_get_rphy(phy_info_cmp);
919 mptsas_get_port(phy_info_cmp);
921 mptsas_get_starget(phy_info_cmp);
932 if (phy_info_cmp->
phy_id < 64 )
934 (1 << phy_info_cmp->
phy_id);
941 for (i = 0; i < port_info->
num_phys; i++) {
942 port_details = port_info->
phy_info[
i].port_details;
946 "%s: [%p]: phy_id=%02d num_phys=%02d "
947 "bitmask=0x%016llX\n", ioc->name, __func__,
948 port_details, i, port_details->
num_phys,
951 ioc->name, port_details->
port, port_details->
rphy));
966 mptsas_find_vtarget(MPT_ADAPTER *ioc,
u8 channel,
u8 id)
970 VirtTarget *vtarget =
NULL;
974 if ((vdevice ==
NULL) ||
975 (vdevice->vtarget ==
NULL))
977 if ((vdevice->vtarget->tflags &
979 vdevice->vtarget->raidVolume))
981 if (vdevice->vtarget->id ==
id &&
982 vdevice->vtarget->channel == channel)
983 vtarget = vdevice->vtarget;
989 mptsas_queue_device_delete(MPT_ADAPTER *ioc,
999 printk(MYIOC_s_WARN_FMT
"%s: failed at (line=%d)\n",
1000 ioc->name, __func__, __LINE__);
1011 mptsas_queue_rescan(MPT_ADAPTER *ioc)
1019 printk(MYIOC_s_WARN_FMT
"%s: failed at (line=%d)\n",
1020 ioc->name, __func__, __LINE__);
1023 fw_event->
event = -1;
1043 mptsas_target_reset(MPT_ADAPTER *ioc,
u8 channel,
u8 id)
1054 "%s, no msg frames @%d!!\n", ioc->name,
1055 __func__, __LINE__));
1075 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
1095 mptsas_block_io_starget(
struct scsi_target *starget)
1113 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1116 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1117 VirtTarget *vtarget =
NULL;
1122 channel = sas_event_data->
Bus;
1124 vtarget = mptsas_find_vtarget(ioc, channel,
id);
1126 mptsas_block_io_starget(vtarget->starget);
1127 vtarget->deleted = 1;
1132 if (!target_reset_list) {
1134 "%s, failed to allocate mem @%d..!!\n",
1135 ioc->name, __func__, __LINE__));
1140 sizeof(*sas_event_data));
1145 if (mptsas_target_reset(ioc, channel,
id)) {
1162 MPT_ADAPTER *ioc = (MPT_ADAPTER *)(iocp);
1163 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1171 head = &hd->target_reset_list;
1172 if (list_empty(head))
1182 if (mptsas_target_reset(ioc, channel,
id))
1197 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
1199 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1206 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
1211 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1212 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
1213 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1214 "term_cmnds = %d\n", ioc->name,
1227 if (pScsiTmReply && (pScsiTmReply->
TaskType ==
1230 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1231 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
1232 memcpy(ioc->taskmgmt_cmds.reply, mr,
1234 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
1235 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
1236 complete(&ioc->taskmgmt_cmds.done);
1244 if (list_empty(head))
1251 "TaskMgmt: completed (%d seconds)\n",
1256 channel = pScsiTmReply->
Bus;
1263 if (mptsas_target_reset(ioc, channel,
id))
1272 if (!ioc->fw_events_off)
1273 mptsas_queue_device_delete(ioc,
1277 ioc->schedule_target_reset(ioc);
1290 mptsas_ioc_reset(MPT_ADAPTER *ioc,
int reset_phase)
1296 if ((ioc->bus_type !=
SAS) || (!rc))
1299 hd = shost_priv(ioc->sh);
1303 switch (reset_phase) {
1304 case MPT_IOC_SETUP_RESET:
1306 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
1307 mptsas_fw_event_off(ioc);
1309 case MPT_IOC_PRE_RESET:
1311 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
1313 case MPT_IOC_POST_RESET:
1315 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
1316 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1317 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
1320 mptsas_cleanup_fw_event_q(ioc);
1321 mptsas_queue_rescan(ioc);
1346 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
struct mptsas_enclosure *enclosure,
1356 memset(&hdr, 0,
sizeof(hdr));
1362 cfg.cfghdr.ehdr = &
hdr;
1364 cfg.pageAddr = form + form_specific;
1389 goto out_free_consistent;
1403 out_free_consistent:
1405 buffer, dma_handle);
1419 mptsas_add_end_device(MPT_ADAPTER *ioc,
struct mptsas_phyinfo *phy_info)
1429 "%s: exit at line=%d\n", ioc->name,
1430 __func__, __LINE__));
1436 if (mptsas_get_rphy(phy_info)) {
1438 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1439 __func__, fw_id, __LINE__));
1443 port = mptsas_get_port(phy_info);
1446 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1447 __func__, fw_id, __LINE__));
1451 if (phy_info->
attached.device_info &
1454 if (phy_info->
attached.device_info &
1457 if (phy_info->
attached.device_info &
1461 printk(MYIOC_s_INFO_FMT
"attaching %s device: fw_channel %d, fw_id %d,"
1462 " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
1464 phy_info->
attached.phy_id, (
unsigned long long)
1467 mptsas_parse_device_info(&identify, &phy_info->
attached);
1471 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1472 __func__, fw_id, __LINE__));
1479 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1480 __func__, fw_id, __LINE__));
1484 mptsas_set_rphy(ioc, phy_info, rphy);
1495 mptsas_del_end_device(MPT_ADAPTER *ioc,
struct mptsas_phyinfo *phy_info)
1510 sas_address = phy_info->
attached.sas_address;
1514 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1515 __func__, fw_id, __LINE__));
1518 rphy = mptsas_get_rphy(phy_info);
1521 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1522 __func__, fw_id, __LINE__));
1532 if (phy_info->
attached.device_info &
1535 if (phy_info->
attached.device_info &
1538 if (phy_info->
attached.device_info &
1543 "removing %s device: fw_channel %d, fw_id %d, phy %d,"
1544 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->
attached.channel,
1546 (
unsigned long long) sas_address);
1548 port = mptsas_get_port(phy_info);
1551 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1552 __func__, fw_id, __LINE__));
1556 phy_info_parent = port_info->
phy_info;
1557 for (i = 0; i < port_info->
num_phys; i++, phy_info_parent++) {
1558 if (!phy_info_parent->
phy)
1560 if (phy_info_parent->
attached.sas_address !=
1564 MYIOC_s_FMT
"delete phy %d, phy-obj (0x%p)\n",
1565 ioc->name, phy_info_parent->
phy_id,
1566 phy_info_parent->
phy);
1571 "delete port %d, sas_addr (0x%llx)\n", ioc->name,
1574 mptsas_set_port(ioc, phy_info,
NULL);
1586 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1594 for (i = 0; i < port_info->
num_phys; i++) {
1595 if (port_info->
phy_info[i].attached.sas_address !=
1599 port_info->
phy_info[
i].attached.id = sas_device->
id;
1600 port_info->
phy_info[
i].attached.sas_address =
1603 port_info->
phy_info[
i].attached.handle_parent =
1605 port_info->
phy_info[
i].attached.handle_enclosure =
1624 MPT_ADAPTER *ioc = fw_event->
ioc;
1627 if (fw_event->
event == -1) {
1628 if (ioc->in_rescan) {
1630 "%s: rescan ignored as it is in progress\n",
1631 ioc->name, __func__));
1635 "reset\n", ioc->name, __func__));
1637 mptsas_not_responding_devices(ioc);
1638 mptsas_scan_sas_topology(ioc);
1640 mptsas_free_fw_event(ioc, fw_event);
1641 mptsas_fw_event_on(ioc);
1646 if (ioc->fw_events_off) {
1647 mptsas_free_fw_event(ioc, fw_event);
1652 "event = (0x%02x)\n", ioc->name, __func__, fw_event,
1653 (fw_event->
event & 0xFF)));
1655 switch (fw_event->
event) {
1657 mptsas_send_sas_event(fw_event);
1660 mptsas_send_raid_event(fw_event);
1663 mptsas_send_ir2_event(fw_event);
1668 mptsas_free_fw_event(ioc, fw_event);
1671 mptsas_broadcast_primative_work(fw_event);
1674 mptsas_send_expander_event(fw_event);
1677 mptsas_send_link_status_event(fw_event);
1680 mptsas_handle_queue_full_event(fw_event);
1691 MPT_SCSI_HOST *hd = shost_priv(host);
1692 MPT_ADAPTER *ioc = hd->ioc;
1693 VirtDevice *vdevice = sdev->
hostdata;
1695 if (vdevice->vtarget->deleted) {
1697 vdevice->vtarget->deleted = 0;
1705 mptsas_add_device_component_starget_ir(ioc,
scsi_target(sdev));
1711 mptsas_add_device_component_starget(ioc,
scsi_target(sdev));
1721 MPT_SCSI_HOST *hd = shost_priv(host);
1722 VirtTarget *vtarget;
1727 MPT_ADAPTER *ioc = hd->ioc;
1729 vtarget = kzalloc(
sizeof(VirtTarget),
GFP_KERNEL);
1733 vtarget->starget = starget;
1734 vtarget->ioc_id = ioc->
id;
1735 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
1743 if (!ioc->raid_data.pIocPg2) {
1747 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1748 if (
id == ioc->raid_data.pIocPg2->
1749 RaidVolume[i].VolumeID) {
1750 channel = ioc->raid_data.pIocPg2->
1751 RaidVolume[
i].VolumeBus;
1754 vtarget->raidVolume = 1;
1761 for (i = 0; i < p->
num_phys; i++) {
1762 if (p->
phy_info[i].attached.sas_address !=
1766 channel = p->
phy_info[
i].attached.channel;
1767 mptsas_set_starget(&p->
phy_info[i], starget);
1796 mptsas_target_destroy(
struct scsi_target *starget)
1799 MPT_SCSI_HOST *hd = shost_priv(host);
1803 MPT_ADAPTER *ioc = hd->ioc;
1804 VirtTarget *vtarget;
1811 mptsas_del_device_component_by_os(ioc, starget->
channel,
1820 for (i = 0; i < p->
num_phys; i++) {
1821 if (p->
phy_info[i].attached.sas_address !=
1826 "delete device: fw_channel %d, fw_id %d, phy %d, "
1827 "sas_addr 0x%llx\n", ioc->name,
1830 p->
phy_info[i].attached.phy_id, (
unsigned long long)
1831 p->
phy_info[i].attached.sas_address);
1838 vtarget->starget =
NULL;
1848 MPT_SCSI_HOST *hd = shost_priv(host);
1851 VirtDevice *vdevice;
1854 MPT_ADAPTER *ioc = hd->ioc;
1856 vdevice = kzalloc(
sizeof(VirtDevice),
GFP_KERNEL);
1858 printk(MYIOC_s_ERR_FMT
"slave_alloc kzalloc(%zd) FAILED!\n",
1859 ioc->name,
sizeof(VirtDevice));
1863 vdevice->vtarget = starget->
hostdata;
1871 for (i = 0; i < p->
num_phys; i++) {
1872 if (p->
phy_info[i].attached.sas_address !=
1875 vdevice->lun = sdev->
lun;
1893 vdevice->vtarget->num_luns++;
1903 VirtDevice *vdevice = SCpnt->
device->hostdata;
1905 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1911 hd = shost_priv(SCpnt->
device->host);
1914 if (ioc->sas_discovery_quiesce_io)
1936 VirtDevice *vdevice;
1937 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
1939 hd = shost_priv(sc->device->host);
1947 if (ioc->bus_type !=
SAS) {
1956 if (ioc->ioc_reset_in_progress) {
1958 "SML need to reset the timer (sc=%p)\n",
1959 ioc->name, __func__, sc));
1960 rc = BLK_EH_RESET_TIMER;
1962 vdevice = sc->device->hostdata;
1963 if (vdevice && vdevice->vtarget && (vdevice->vtarget->inDMD
1964 || vdevice->vtarget->deleted)) {
1966 "or in device removal delay (sc=%p)\n",
1967 ioc->name, __func__, sc));
1968 rc = BLK_EH_RESET_TIMER;
1979 .proc_name =
"mptsas",
1981 .name =
"MPT SAS Host",
1983 .queuecommand = mptsas_qcmd,
1984 .target_alloc = mptsas_target_alloc,
1985 .slave_alloc = mptsas_slave_alloc,
1986 .slave_configure = mptsas_slave_configure,
1987 .target_destroy = mptsas_target_destroy,
1997 .max_sectors = 8192,
2003 static int mptsas_get_linkerrors(
struct sas_phy *phy)
2005 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2024 cfg.cfghdr.ehdr = &
hdr;
2026 cfg.pageAddr = phy->
identify.phy_identifier;
2047 goto out_free_consistent;
2049 mptsas_print_phy_pg1(ioc, buffer);
2059 out_free_consistent:
2061 buffer, dma_handle);
2065 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *
req,
2066 MPT_FRAME_HDR *reply)
2068 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2069 if (reply !=
NULL) {
2070 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
2071 memcpy(ioc->sas_mgmt.reply, reply,
2072 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
2075 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
2076 ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING;
2083 static int mptsas_phy_reset(
struct sas_phy *phy,
int hard_reset)
2085 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2090 unsigned long timeleft;
2119 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2124 if (!(ioc->sas_mgmt.
status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2127 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2135 if ((ioc->sas_mgmt.status &
2136 MPT_MGMT_STATUS_RF_VALID) == 0) {
2144 printk(MYIOC_s_INFO_FMT
"%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
2153 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2162 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2170 for (i = 0; i < p->
num_phys; i++) {
2171 if (p->
phy_info[i].attached.sas_address ==
2172 rphy->identify.sas_address) {
2185 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
2189 *identifier = enclosure_info.enclosure_logical_id;
2194 mptsas_get_bay_identifier(
struct sas_rphy *rphy)
2196 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2202 for (i = 0; i < p->
num_phys; i++) {
2203 if (p->
phy_info[i].attached.sas_address ==
2219 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
2225 unsigned long timeleft;
2229 u64 sas_address = 0;
2232 printk(MYIOC_s_ERR_FMT
"%s: the smp response space is missing\n",
2233 ioc->name, __func__);
2238 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
2239 printk(MYIOC_s_ERR_FMT
"%s: multiple segments req %u %u, rsp %u %u\n",
2240 ioc->name, __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
2241 rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
2256 memset(smpreq, 0,
sizeof(*smpreq));
2262 sas_address = rphy->
identify.sas_address;
2267 port_info = ioc->hba_port_info;
2268 if (port_info && port_info->
phy_info)
2270 port_info->
phy_info[0].phy->identify.sas_address;
2284 flagsLength |= (blk_rq_bytes(req) - 4);
2286 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
2290 ioc->add_sge(psge, flagsLength, dma_addr_out);
2291 psge += ioc->SGE_size;
2300 flagsLength |= blk_rq_bytes(rsp) + 4;
2301 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
2305 ioc->add_sge(psge, flagsLength, dma_addr_in);
2307 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2311 if (!(ioc->sas_mgmt.
status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2315 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2323 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2327 memcpy(req->sense, smprep,
sizeof(*smprep));
2328 req->sense_len =
sizeof(*smprep);
2333 "%s: smp passthru reply failed to be returned\n",
2334 ioc->name, __func__);
2339 pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
2342 pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
2348 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2356 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
2357 .get_bay_identifier = mptsas_get_bay_identifier,
2358 .phy_reset = mptsas_phy_reset,
2359 .smp_handler = mptsas_smp_handler,
2365 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc,
struct mptsas_portinfo *port_info)
2381 cfg.cfghdr.ehdr = &
hdr;
2408 goto out_free_consistent;
2415 goto out_free_consistent;
2418 ioc->nvdata_version_persistent =
2420 ioc->nvdata_version_default =
2423 for (i = 0; i < port_info->
num_phys; i++) {
2424 mptsas_print_phy_data(ioc, &buffer->
PhyData[i]);
2428 port_info->
phy_info[
i].negotiated_link_rate =
2430 port_info->
phy_info[
i].portinfo = port_info;
2435 out_free_consistent:
2437 buffer, dma_handle);
2443 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
2450 u8 device_missing_delay;
2453 memset(&cfg, 0,
sizeof(CONFIGPARMS));
2455 cfg.cfghdr.ehdr = &
hdr;
2461 cfg.cfghdr.ehdr->PageNumber = 1;
2483 goto out_free_consistent;
2485 ioc->io_missing_delay =
2492 out_free_consistent:
2494 buffer, dma_handle);
2500 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc,
struct mptsas_phyinfo *phy_info,
2501 u32 form,
u32 form_specific)
2517 cfg.cfghdr.ehdr = &
hdr;
2523 cfg.pageAddr = form + form_specific;
2547 goto out_free_consistent;
2549 mptsas_print_phy_pg0(ioc, buffer);
2556 out_free_consistent:
2558 buffer, dma_handle);
2564 mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
struct mptsas_devinfo *device_info,
2565 u32 form,
u32 form_specific)
2582 cfg.cfghdr.ehdr = &
hdr;
2583 cfg.pageAddr = form + form_specific;
2612 goto out_free_consistent;
2616 goto out_free_consistent;
2618 mptsas_print_device_pg0(ioc, buffer);
2637 out_free_consistent:
2639 buffer, dma_handle);
2645 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc,
struct mptsas_portinfo *port_info,
2646 u32 form,
u32 form_specific)
2664 cfg.cfghdr.ehdr = &
hdr;
2666 cfg.pageAddr = form + form_specific;
2694 goto out_free_consistent;
2698 goto out_free_consistent;
2706 goto out_free_consistent;
2710 for (i = 0; i < port_info->
num_phys; i++) {
2711 port_info->
phy_info[
i].portinfo = port_info;
2714 port_info->
phy_info[
i].identify.sas_address =
2716 port_info->
phy_info[
i].identify.handle_parent =
2720 out_free_consistent:
2722 buffer, dma_handle);
2728 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc,
struct mptsas_phyinfo *phy_info,
2729 u32 form,
u32 form_specific)
2745 cfg.cfghdr.ehdr = &
hdr;
2747 cfg.pageAddr = form + form_specific;
2775 goto out_free_consistent;
2779 goto out_free_consistent;
2782 mptsas_print_expander_pg1(ioc, buffer);
2793 out_free_consistent:
2795 buffer, dma_handle);
2838 mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
2848 unsigned long timeleft;
2850 unsigned long flags;
2856 if (ioc->ioc_reset_in_progress) {
2857 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2858 printk(MYIOC_s_INFO_FMT
"%s: host reset in progress!\n",
2859 __func__, ioc->name);
2862 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2875 memset(smpreq, 0,
sizeof(*smpreq));
2882 __FILE__, __LINE__, __func__);
2887 manufacture_request = data_out;
2908 ioc->add_sge(psge, flagsLength, data_out_dma);
2909 psge += ioc->SGE_size;
2917 ioc->add_sge(psge, flagsLength, data_out_dma +
2920 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2924 if (!(ioc->sas_mgmt.
status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2928 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2937 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2952 edev->
level = manufacture_reply->sas_format;
2953 if (manufacture_reply->sas_format) {
2955 manufacture_reply->component_vendor_id,
2957 tmp = (
u8 *)&manufacture_reply->component_id;
2960 manufacture_reply->component_revision_id;
2964 "%s: smp passthru reply failed to be returned\n",
2965 ioc->name, __func__);
2975 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2987 identify->sas_address = device_info->sas_address;
2988 identify->phy_identifier = device_info->phy_id;
2994 protocols = device_info->device_info & 0x78;
2995 identify->initiator_port_protocols = 0;
3009 protocols = device_info->device_info & 0x780;
3010 identify->target_port_protocols = 0;
3023 switch (device_info->device_info &
3040 static int mptsas_probe_one_phy(
struct device *
dev,
3047 VirtTarget *vtarget;
3054 if (!phy_info->
phy) {
3061 phy = phy_info->
phy;
3149 if (!phy_info->
phy) {
3163 port = mptsas_get_port(phy_info);
3164 ioc = phy_to_ioc(phy_info->
phy);
3177 "%s: exit at line=%d\n", ioc->name,
3178 __func__, __LINE__));
3181 mptsas_set_port(ioc, phy_info, port);
3183 MYIOC_s_FMT
"add port %d, sas_addr (0x%llx)\n",
3185 (
unsigned long long)phy_info->
3189 "sas_port_add_phy: phy_id=%d\n",
3190 ioc->name, phy_info->
phy_id));
3194 MYIOC_s_FMT
"add phy %d, phy-obj (0x%p)\n", ioc->name,
3197 if (!mptsas_get_rphy(phy_info) && port && !port->
rphy) {
3203 parent = dev->
parent->parent;
3209 if (mptsas_is_end_device(&phy_info->
attached) &&
3210 phy_info->
attached.handle_parent) {
3214 mptsas_parse_device_info(&identify, &phy_info->
attached);
3219 port_info = ioc->hba_port_info;
3221 for (i = 0; i < port_info->
num_phys; i++)
3222 if (port_info->
phy_info[i].identify.sas_address ==
3223 identify.sas_address) {
3230 if (identify.sas_address ==
3231 parent_rphy->
identify.sas_address) {
3237 switch (identify.device_type) {
3251 "%s: exit at line=%d\n", ioc->name,
3252 __func__, __LINE__));
3260 "%s: exit at line=%d\n", ioc->name,
3261 __func__, __LINE__));
3265 mptsas_set_rphy(ioc, phy_info, rphy);
3268 mptsas_exp_repmanufacture_info(ioc,
3269 identify.sas_address,
3275 vtarget = mptsas_find_vtarget(ioc,
3278 if (vtarget && vtarget->inDMD) {
3288 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
3297 error = mptsas_sas_io_unit_pg0(ioc, hba);
3299 goto out_free_port_info;
3301 mptsas_sas_io_unit_pg1(ioc);
3303 port_info = ioc->hba_port_info;
3305 ioc->hba_port_info = port_info = hba;
3306 ioc->hba_port_num_phy = port_info->
num_phys;
3309 for (i = 0; i < hba->
num_phys; i++) {
3310 port_info->
phy_info[
i].negotiated_link_rate =
3322 #if defined(CPQ_CIM)
3323 ioc->num_ports = port_info->
num_phys;
3325 for (i = 0; i < port_info->
num_phys; i++) {
3326 mptsas_sas_phy_pg0(ioc, &port_info->
phy_info[i],
3329 port_info->
phy_info[
i].identify.handle =
3331 mptsas_sas_device_pg0(ioc, &port_info->
phy_info[i].identify,
3334 port_info->
phy_info[i].identify.handle);
3335 if (!ioc->hba_port_sas_addr)
3336 ioc->hba_port_sas_addr =
3337 port_info->
phy_info[
i].identify.sas_address;
3338 port_info->
phy_info[
i].identify.phy_id =
3340 if (port_info->
phy_info[i].attached.handle)
3341 mptsas_sas_device_pg0(ioc,
3345 port_info->
phy_info[i].attached.handle);
3348 mptsas_setup_wide_ports(ioc, port_info);
3350 for (i = 0; i < port_info->
num_phys; i++, ioc->sas_index++)
3351 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
3352 &port_info->
phy_info[i], ioc->sas_index, 1);
3363 mptsas_expander_refresh(MPT_ADAPTER *ioc,
struct mptsas_portinfo *port_info)
3366 struct device *parent_dev;
3372 handle = port_info->
phy_info[0].handle;
3373 sas_address = port_info->
phy_info[0].identify.sas_address;
3374 for (i = 0; i < port_info->
num_phys; i++) {
3375 mptsas_sas_expander_pg1(ioc, &port_info->
phy_info[i],
3379 mptsas_sas_device_pg0(ioc,
3383 port_info->
phy_info[i].identify.handle);
3384 port_info->
phy_info[
i].identify.phy_id =
3387 if (port_info->
phy_info[i].attached.handle) {
3388 mptsas_sas_device_pg0(ioc,
3392 port_info->
phy_info[i].attached.handle);
3393 port_info->
phy_info[
i].attached.phy_id =
3399 parent = mptsas_find_portinfo_by_handle(ioc,
3400 port_info->
phy_info[0].identify.handle_parent);
3405 for (i = 0, parent_dev =
NULL; i < parent->
num_phys && !parent_dev;
3407 if (parent->
phy_info[i].attached.sas_address == sas_address) {
3408 rphy = mptsas_get_rphy(&parent->
phy_info[i]);
3409 parent_dev = &rphy->
dev;
3414 mptsas_setup_wide_ports(ioc, port_info);
3415 for (i = 0; i < port_info->
num_phys; i++, ioc->sas_index++)
3416 mptsas_probe_one_phy(parent_dev, &port_info->
phy_info[i],
3421 mptsas_expander_event_add(MPT_ADAPTER *ioc,
3438 for (i = 0; i < port_info->
num_phys; i++) {
3439 port_info->
phy_info[
i].portinfo = port_info;
3442 port_info->
phy_info[
i].identify.sas_address =
3444 port_info->
phy_info[
i].identify.handle_parent =
3452 printk(MYIOC_s_INFO_FMT
"add expander: num_phys %d, "
3453 "sas_addr (0x%llx)\n", ioc->name, port_info->
num_phys,
3454 (
unsigned long long)sas_address);
3456 mptsas_expander_refresh(ioc, port_info);
3466 mptsas_delete_expander_siblings(MPT_ADAPTER *ioc,
struct mptsas_portinfo
3475 for (i = 0; i < expander->
num_phys; i++, phy_info++) {
3476 rphy = mptsas_get_rphy(phy_info);
3480 mptsas_del_end_device(ioc, phy_info);
3484 for (i = 0; i < expander->
num_phys; i++, phy_info++) {
3485 rphy = mptsas_get_rphy(phy_info);
3492 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3496 if (port_info == parent)
3502 mptsas_expander_delete(ioc, port_info, 1);
3516 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
3522 u64 expander_sas_address;
3532 mptsas_sas_expander_pg0(ioc, &buffer,
3535 port_info->
phy_info[0].identify.handle);
3537 if (buffer.num_phys) {
3538 kfree(buffer.phy_info);
3547 port_details =
NULL;
3548 expander_sas_address =
3549 port_info->
phy_info[0].identify.sas_address;
3550 parent = mptsas_find_portinfo_by_handle(ioc,
3551 port_info->
phy_info[0].identify.handle_parent);
3552 mptsas_delete_expander_siblings(ioc, parent, port_info);
3562 for (i = 0; i < parent->
num_phys; i++, phy_info++) {
3565 if (phy_info->
attached.sas_address !=
3566 expander_sas_address)
3569 port = mptsas_get_port(phy_info);
3573 MYIOC_s_FMT
"delete phy %d, phy-obj (0x%p)\n", ioc->name,
3579 MYIOC_s_FMT
"delete port %d, sas_addr (0x%llx)\n",
3581 (
unsigned long long)expander_sas_address);
3583 mptsas_port_delete(ioc, port_details);
3587 printk(MYIOC_s_INFO_FMT
"delete expander: num_phys %d, "
3588 "sas_addr (0x%llx)\n", ioc->name, port_info->
num_phys,
3589 (
unsigned long long)expander_sas_address);
3618 ioc = fw_event->
ioc;
3623 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3627 for (i = 0; i < port_info->
num_phys; i++) {
3628 port_info->
phy_info[
i].portinfo = port_info;
3631 port_info->
phy_info[
i].identify.sas_address =
3633 port_info->
phy_info[
i].identify.handle_parent =
3636 mptsas_expander_refresh(ioc, port_info);
3637 }
else if (!port_info && expander_data->
NumPhys)
3638 mptsas_expander_event_add(ioc, expander_data);
3641 mptsas_expander_delete(ioc, port_info, 0);
3643 mptsas_free_fw_event(ioc, fw_event);
3659 if ((mptsas_sas_expander_pg0(ioc, &buffer,
3667 "%s: exit at line=%d\n", ioc->name,
3668 __func__, __LINE__));
3673 for (i = 0; i < port_info->
num_phys; i++)
3674 port_info->
phy_info[i].portinfo = port_info;
3678 printk(MYIOC_s_INFO_FMT
"add expander: num_phys %d, "
3679 "sas_addr (0x%llx)\n", ioc->name, port_info->
num_phys,
3680 (
unsigned long long)buffer.
phy_info[0].identify.sas_address);
3681 mptsas_expander_refresh(ioc, port_info);
3686 mptsas_send_link_status_event(
struct fw_event_work *fw_event)
3696 ioc = fw_event->
ioc;
3702 phy_num = link_data->
PhyNum;
3704 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3706 phy_info = &port_info->
phy_info[phy_num];
3716 if (ioc->old_sas_discovery_protocal) {
3725 if (port_info == ioc->hba_port_info)
3726 mptsas_probe_hba_phys(ioc);
3728 mptsas_expander_refresh(ioc, port_info);
3729 }
else if (phy_info && phy_info->
phy) {
3731 phy_info->
phy->negotiated_linkrate =
3733 else if (link_rate ==
3735 phy_info->
phy->negotiated_linkrate =
3738 phy_info->
phy->negotiated_linkrate =
3740 if (ioc->device_missing_delay &&
3741 mptsas_is_end_device(&phy_info->
attached)) {
3743 VirtDevice *vdevice;
3746 channel = phy_info->
attached.channel;
3748 "Link down for fw_id %d:fw_channel %d\n",
3754 if ((vdevice ==
NULL) ||
3755 (vdevice->vtarget ==
NULL))
3757 if ((vdevice->vtarget->tflags &
3759 vdevice->vtarget->raidVolume))
3761 if (vdevice->vtarget->id ==
id &&
3762 vdevice->vtarget->channel ==
3766 "SDEV OUTSTANDING CMDS"
3775 mptsas_free_fw_event(ioc, fw_event);
3779 mptsas_not_responding_devices(MPT_ADAPTER *ioc)
3785 VirtTarget *vtarget =
NULL;
3789 unsigned long flags;
3794 if (ioc->ioc_reset_in_progress) {
3796 "%s: exiting due to a parallel reset \n", ioc->name,
3798 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3801 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3810 sas_device.handle = 0;
3813 retval = mptsas_sas_device_pg0(ioc, &sas_device,
3816 (sas_info->
fw.channel << 8) +
3819 if (sas_device.handle)
3821 if (retval == -
EBUSY) {
3823 if (ioc->ioc_reset_in_progress) {
3826 "%s: exiting due to reset\n",
3827 ioc->name, __func__));
3828 spin_unlock_irqrestore
3829 (&ioc->taskmgmt_lock, flags);
3831 sas_device_info_mutex);
3834 spin_unlock_irqrestore(&ioc->taskmgmt_lock,
3838 if (retval && (retval != -
ENODEV)) {
3839 if (retry_count < 10) {
3844 "%s: Config page retry exceeded retry "
3845 "count deleting device 0x%llx\n",
3846 ioc->name, __func__,
3852 vtarget = mptsas_find_vtarget(ioc,
3853 sas_info->
fw.channel, sas_info->
fw.id);
3856 vtarget->deleted = 1;
3858 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3862 mptsas_del_end_device(ioc, phy_info);
3863 goto redo_device_scan;
3866 mptsas_volume_delete(ioc, sas_info->
fw.id);
3876 (!(port_info->
phy_info[0].identify.device_info &
3877 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
3881 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3886 handle = buffer.phy_info[0].handle;
3887 if (buffer.phy_info[0].identify.sas_address ==
3888 port_info->
phy_info[0].identify.sas_address) {
3891 kfree(buffer.phy_info);
3894 if (!found_expander) {
3895 mptsas_expander_delete(ioc, port_info, 0);
3896 goto redo_expander_scan;
3908 mptsas_probe_expanders(MPT_ADAPTER *ioc)
3915 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3919 handle = buffer.phy_info[0].handle;
3920 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3921 buffer.phy_info[0].identify.sas_address);
3925 for (i = 0; i < buffer.num_phys; i++) {
3927 port_info->
phy_info[
i].identify.handle_parent =
3928 buffer.phy_info[0].identify.handle_parent;
3930 mptsas_expander_refresh(ioc, port_info);
3931 kfree(buffer.phy_info);
3938 "%s: exit at line=%d\n", ioc->name,
3939 __func__, __LINE__));
3942 port_info->
num_phys = buffer.num_phys;
3943 port_info->
phy_info = buffer.phy_info;
3944 for (i = 0; i < port_info->
num_phys; i++)
3945 port_info->
phy_info[i].portinfo = port_info;
3949 printk(MYIOC_s_INFO_FMT
"add expander: num_phys %d, "
3950 "sas_addr (0x%llx)\n", ioc->name, port_info->
num_phys,
3951 (
unsigned long long)buffer.phy_info[0].identify.sas_address);
3952 mptsas_expander_refresh(ioc, port_info);
3957 mptsas_probe_devices(MPT_ADAPTER *ioc)
3964 while (!(mptsas_sas_device_pg0(ioc, &sas_device,
3967 handle = sas_device.
handle;
3969 if ((sas_device.device_info &
3970 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
3971 MPI_SAS_DEVICE_INFO_STP_TARGET |
3972 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
3978 || !(sas_device.flags &
3986 if (mptsas_get_rphy(phy_info))
3989 mptsas_add_end_device(ioc, phy_info);
4000 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
4005 mptsas_probe_hba_phys(ioc);
4006 mptsas_probe_expanders(ioc);
4007 mptsas_probe_devices(ioc);
4012 if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
4013 !ioc->raid_data.pIocPg2->NumActiveVolumes)
4015 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
4017 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
4022 printk(MYIOC_s_INFO_FMT
"attaching raid volume, channel %d, "
4024 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
4026 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
4032 mptsas_handle_queue_full_event(
struct fw_event_work *fw_event)
4041 int fw_id, fw_channel;
4045 ioc = fw_event->
ioc;
4048 fw_channel = qfull_data->
Bus;
4060 (sas_info->
fw.channel == fw_channel &&
4061 sas_info->
fw.id == fw_id)) {
4074 if (sas_info->
fw.channel == fw_channel &&
4075 sas_info->
fw.id == fw_id) {
4076 id = sas_info->
os.id;
4077 channel = sas_info->
os.channel;
4089 if (sdev->
id ==
id && sdev->
channel == channel) {
4092 "strange observation, the queue "
4093 "depth is (%d) meanwhile fw queue "
4102 "Queue depth reduced to (%d)\n",
4106 "Tagged Command Queueing is being "
4108 else if (depth == 0)
4110 "Queue depth not changed yet\n");
4115 mptsas_free_fw_event(ioc, fw_event);
4120 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc,
u64 sas_address)
4128 for (i = 0; i < port_info->
num_phys; i++) {
4129 if (!mptsas_is_end_device(
4132 if (port_info->
phy_info[i].attached.sas_address
4152 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc,
u8 phys_disk_num,
4159 u64 sas_address = 0;
4163 if (!ioc->raid_data.pIocPg3)
4174 for (i = 0; i < num_paths; i++) {
4175 if ((phys_disk->
Path[i].
Flags & 1) != 0)
4182 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4200 if (!mptsas_is_end_device(
4203 if (port_info->
phy_info[i].attached.phys_disk_num == ~0)
4205 if ((port_info->
phy_info[i].attached.phys_disk_num ==
4207 (port_info->
phy_info[i].attached.id ==
id) &&
4208 (port_info->
phy_info[i].attached.channel ==
4223 rc = scsi_device_reprobe(sdev);
4227 mptsas_reprobe_target(
struct scsi_target *starget,
int uld_attach)
4230 mptsas_reprobe_lun);
4234 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc,
u8 channel,
u8 id)
4245 memset(&cfg, 0 ,
sizeof(CONFIGPARMS));
4248 cfg.pageAddr = (channel << 8) +
id;
4249 cfg.cfghdr.hdr = &
hdr;
4284 if (mptsas_sas_device_pg0(ioc, &sas_device,
4294 || !(sas_device.flags &
4299 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4300 sas_device.sas_address);
4301 mptsas_add_end_device(ioc, phy_info);
4313 mptsas_hotplug_work(MPT_ADAPTER *ioc,
struct fw_event_work *fw_event,
4319 VirtTarget *vtarget;
4327 if (!ioc->raid_data.pIocPg2)
4330 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
4331 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
4332 hot_plug_info->
id) {
4333 printk(MYIOC_s_WARN_FMT
"firmware bug: unable "
4334 "to add hidden disk - target_id matchs "
4335 "volume_id\n", ioc->name);
4336 mptsas_free_fw_event(ioc, fw_event);
4344 mptsas_sas_device_pg0(ioc, &sas_device,
4347 (hot_plug_info->
channel << 8) +
4353 || !(sas_device.flags &
4357 if (!sas_device.handle)
4362 if (!phy_info && (sas_device.device_info &
4363 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) {
4365 "%s %d SATA HOT PLUG: "
4366 "parent handle of device %x\n", ioc->name,
4367 __func__, __LINE__, sas_device.handle_parent));
4368 port_info = mptsas_find_portinfo_by_handle(ioc,
4369 sas_device.handle_parent);
4371 if (port_info == ioc->hba_port_info)
4372 mptsas_probe_hba_phys(ioc);
4374 mptsas_expander_refresh(ioc, port_info);
4377 "%s %d port info is NULL\n",
4378 ioc->name, __func__, __LINE__));
4387 "%s %d phy info is NULL\n",
4388 ioc->name, __func__, __LINE__));
4392 if (mptsas_get_rphy(phy_info))
4395 mptsas_add_end_device(ioc, phy_info);
4399 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4401 mptsas_del_end_device(ioc, phy_info);
4408 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
4412 mptsas_del_end_device(ioc, phy_info);
4417 if (mptsas_sas_device_pg0(ioc, &sas_device,
4420 (hot_plug_info->
channel << 8) + hot_plug_info->
id)) {
4422 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4423 __func__, hot_plug_info->
id, __LINE__));
4430 || !(sas_device.flags &
4434 phy_info = mptsas_find_phyinfo_by_sas_address(
4435 ioc, sas_device.sas_address);
4439 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4440 __func__, hot_plug_info->
id, __LINE__));
4444 starget = mptsas_get_starget(phy_info);
4447 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4448 __func__, hot_plug_info->
id, __LINE__));
4455 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4456 __func__, hot_plug_info->
id, __LINE__));
4463 "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4464 ioc->name, hot_plug_info->
channel, hot_plug_info->
id,
4466 sas_device.sas_address);
4471 mptsas_reprobe_target(starget, 1);
4476 if (mptsas_sas_device_pg0(ioc, &sas_device,
4479 (hot_plug_info->
channel << 8) + hot_plug_info->
id)) {
4481 "%s: fw_id=%d exit at line=%d\n",
4482 ioc->name, __func__,
4483 hot_plug_info->
id, __LINE__));
4490 || !(sas_device.flags &
4494 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4495 sas_device.sas_address);
4498 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4499 __func__, hot_plug_info->
id, __LINE__));
4503 starget = mptsas_get_starget(phy_info);
4506 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4507 __func__, hot_plug_info->
id, __LINE__));
4514 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4515 __func__, hot_plug_info->
id, __LINE__));
4521 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4522 __func__, hot_plug_info->
id, __LINE__));
4529 " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4530 ioc->name, hot_plug_info->
channel, hot_plug_info->
id,
4532 sas_device.sas_address);
4535 vtarget->id = hot_plug_info->
id;
4536 phy_info->
attached.phys_disk_num = ~0;
4537 mptsas_reprobe_target(starget, 0);
4538 mptsas_add_device_component_by_fw(ioc,
4539 hot_plug_info->
channel, hot_plug_info->
id);
4545 printk(MYIOC_s_INFO_FMT
"attaching raid volume, channel %d, "
4549 hot_plug_info->
id, 0);
4555 printk(MYIOC_s_INFO_FMT
"removing raid volume, channel %d, "
4565 mptsas_adding_inactive_raid_components(ioc,
4566 hot_plug_info->
channel, hot_plug_info->
id);
4573 mptsas_free_fw_event(ioc, fw_event);
4585 ioc = fw_event->
ioc;
4588 device_info =
le32_to_cpu(sas_event_data->DeviceInfo);
4591 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
4592 MPI_SAS_DEVICE_INFO_STP_TARGET |
4593 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
4594 mptsas_free_fw_event(ioc, fw_event);
4598 if (sas_event_data->ReasonCode ==
4602 mptsas_free_fw_event(ioc, fw_event);
4606 switch (sas_event_data->ReasonCode) {
4611 hot_plug_info.
channel = sas_event_data->Bus;
4612 hot_plug_info.
id = sas_event_data->TargetID;
4613 hot_plug_info.
phy_id = sas_event_data->PhyNum;
4614 memcpy(&sas_address, &sas_event_data->SASAddress,
4618 if (sas_event_data->ReasonCode &
4623 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4629 mptsas_free_fw_event(ioc, fw_event);
4637 mptsas_free_fw_event(ioc, fw_event);
4651 VirtDevice *vdevice =
NULL;
4654 ioc = fw_event->
ioc;
4657 state = (status >> 8) & 0xff;
4660 hot_plug_info.
id = raid_event_data->
VolumeID;
4669 hot_plug_info.
id, 0);
4670 hot_plug_info.
sdev = sdev;
4676 "ReasonCode=%02x\n", ioc->name, __func__,
4710 vdevice->vtarget->deleted = 1;
4724 vdevice->vtarget->deleted = 1;
4733 vdevice->vtarget->deleted = 1;
4753 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4755 mptsas_free_fw_event(ioc, fw_event);
4778 unsigned long timeleft;
4785 "msg frames!!\n", ioc->name));
4790 "task_type = 0x%02X,\n\t timeout = %ld, fw_channel = %d, "
4791 "fw_id = %d, lun = %lld,\n\t task_context = 0x%x\n", ioc->name, mf,
4792 type, timeout, channel,
id, (
unsigned long long)lun,
4808 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4809 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
4816 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
4819 "TaskMgmt request: TIMED OUT!(mr=%p)\n", ioc->name, mf));
4821 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
4827 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
4830 "TaskMgmt request: failed with no reply\n", ioc->name));
4835 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4848 MPT_ADAPTER *ioc = fw_event->ioc;
4850 VirtDevice *vdevice;
4858 u32 termination_count;
4862 "%s - enter\n", ioc->name, __func__));
4867 mptsas_requeue_fw_event(ioc, fw_event, 1000);
4872 termination_count = 0;
4877 for (ii = 0; ii < ioc->req_depth; ii++) {
4878 if (ioc->fw_events_off)
4883 mf = MPT_INDEX_2_MFPTR(ioc, ii);
4886 task_context = mf->u.frame.hwhdr.msgctxu.MsgContext;
4887 vdevice = sc->
device->hostdata;
4888 if (!vdevice || !vdevice->vtarget)
4892 if (vdevice->vtarget->raidVolume)
4894 channel = vdevice->vtarget->channel;
4895 id = vdevice->vtarget->id;
4898 channel,
id, (
u64)lun, task_context, 30, &issue_reset))
4901 termination_count +=
4909 if (mptsas_issue_tm(ioc,
4911 channel,
id, (
u64)lun, 0, 30, &issue_reset))
4913 termination_count +=
4919 "%s - exit, query_count = %d termination_count = %d\n",
4920 ioc->name, __func__, query_count, termination_count));
4922 ioc->broadcast_aen_busy = 0;
4928 "Issuing Reset from %s!! doorbell=0x%08x\n",
4932 mptsas_free_fw_event(ioc, fw_event);
4952 ioc = fw_event->
ioc;
4954 reasonCode = ir2_data->ReasonCode;
4957 "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
4960 hot_plug_info.
id = ir2_data->TargetID;
4961 hot_plug_info.
channel = ir2_data->Bus;
4962 switch (reasonCode) {
4973 ir2_data->PhysDiskNum, &phys_disk);
4978 mptsas_free_fw_event(ioc, fw_event);
4981 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4988 int sz, event_data_sz;
4990 unsigned long delay;
4992 if (ioc->bus_type !=
SAS)
4996 if (ioc->fw_events_off)
5008 if (ioc->broadcast_aen_busy)
5010 ioc->broadcast_aen_busy = 1;
5022 mptsas_target_reset_queue(ioc, sas_event_data);
5027 ioc->device_missing_delay &&
5029 VirtTarget *vtarget =
NULL;
5033 channel = sas_event_data->
Bus;
5035 vtarget = mptsas_find_vtarget(ioc, channel,
id);
5038 "LogInfo (0x%x) available for "
5039 "INTERNAL_DEVICE_RESET"
5040 "fw_id %d fw_channel %d\n", ioc->name,
5043 if (vtarget->raidVolume) {
5045 "Skipping Raid Volume for inDMD\n",
5049 "Setting device flag inDMD\n",
5065 if (ioc->old_sas_discovery_protocal)
5070 ioc->device_missing_delay)
5071 delay = HZ * ioc->device_missing_delay;
5076 u32 discovery_status;
5081 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
5082 if (ioc->old_sas_discovery_protocal && !discovery_status)
5083 mptsas_queue_rescan(ioc);
5096 event_data_sz = ((reply->
MsgLength * 4) -
5101 printk(MYIOC_s_WARN_FMT
"%s: failed at (line=%d)\n", ioc->name,
5102 __func__, __LINE__);
5108 mptsas_add_fw_event(ioc, fw_event, delay);
5114 static void mptsas_volume_delete(MPT_ADAPTER *ioc,
u8 id)
5122 if (!ioc->raid_data.pIocPg2)
5124 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
5126 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
5127 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
id)
5130 printk(MYIOC_s_INFO_FMT
"removing raid volume, channel %d, "
5143 unsigned long flags;
5155 ioc = pci_get_drvdata(pdev);
5156 mptsas_fw_event_off(ioc);
5157 ioc->DoneCtx = mptsasDoneCtx;
5158 ioc->TaskCtx = mptsasTaskCtx;
5159 ioc->InternalCtx = mptsasInternalCtx;
5161 ioc->schedule_dead_ioc_flush_running_cmds =
5167 "Skipping because it's not operational!\n",
5170 goto out_mptsas_probe;
5174 printk(MYIOC_s_WARN_FMT
"Skipping because it's disabled!\n",
5177 goto out_mptsas_probe;
5183 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
5184 if (ioc->pfacts[ii].ProtocolFlags &
5191 "Skipping ioc=%p because SCSI Initiator mode "
5192 "is NOT enabled!\n", ioc->name, ioc);
5199 "Unable to register controller with SCSI subsystem\n",
5202 goto out_mptsas_probe;
5226 INIT_LIST_HEAD(&ioc->sas_topology);
5230 init_completion(&ioc->sas_mgmt.done);
5241 scale = ioc->req_sz/ioc->SGE_size;
5242 if (ioc->sg_addr_size ==
sizeof(
u64)) {
5243 numSGE = (scale - 1) *
5244 (ioc->facts.MaxChainDepth-1) + scale +
5245 (ioc->req_sz - 60) / ioc->SGE_size;
5247 numSGE = 1 + (scale - 1) *
5248 (ioc->facts.MaxChainDepth-1) + scale +
5249 (ioc->req_sz - 64) / ioc->SGE_size;
5255 "Resetting sg_tablesize to %d from %d\n",
5260 if (mpt_loadtime_max_sectors) {
5261 if (mpt_loadtime_max_sectors < 64 ||
5262 mpt_loadtime_max_sectors > 8192) {
5263 printk(MYIOC_s_INFO_FMT
"Invalid value passed for"
5264 "mpt_loadtime_max_sectors %d."
5265 "Range from 64 to 8192\n", ioc->name,
5266 mpt_loadtime_max_sectors);
5268 mpt_loadtime_max_sectors &= 0xFFFFFFFE;
5270 "Resetting max sector to %d from %d\n",
5271 ioc->name, mpt_loadtime_max_sectors, sh->
max_sectors));
5275 hd = shost_priv(sh);
5281 ioc->ScsiLookup = kcalloc(ioc->req_depth,
sizeof(
void *),
GFP_ATOMIC);
5282 if (!ioc->ScsiLookup) {
5284 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5285 goto out_mptsas_probe;
5290 ioc->name, ioc->ScsiLookup));
5292 ioc->sas_data.ptClear = mpt_pt_clear;
5294 hd->last_queue_full = 0;
5295 INIT_LIST_HEAD(&hd->target_reset_list);
5296 INIT_LIST_HEAD(&ioc->sas_device_info_list);
5299 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5301 if (ioc->sas_data.ptClear==1) {
5306 error = scsi_add_host(sh, &ioc->pcidev->dev);
5309 "scsi_add_host failed\n", ioc->name));
5310 goto out_mptsas_probe;
5314 if ((ioc->facts.HeaderVersion >> 8) < 0xE)
5315 ioc->old_sas_discovery_protocal = 1;
5316 mptsas_scan_sas_topology(ioc);
5317 mptsas_fw_event_on(ioc);
5329 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
5331 mptsas_fw_event_off(ioc);
5332 mptsas_cleanup_fw_event_q(ioc);
5337 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
5342 printk(MYIOC_s_INFO_FMT
"IOC is in Target mode\n", ioc->name);
5349 mptsas_del_device_components(ioc);
5351 ioc->sas_discovery_ignore_events = 1;
5357 for (i = 0 ; i < p->
num_phys ; i++)
5358 mptsas_port_delete(ioc, p->
phy_info[i].port_details);
5364 ioc->hba_port_info =
NULL;
5388 .id_table = mptsas_pci_table,
5389 .probe = mptsas_probe,
5393 .suspend = mptscsih_suspend,
5394 .resume = mptscsih_resume,
5405 mptsas_transport_template =
5407 if (!mptsas_transport_template)
5409 mptsas_transport_template->
eh_timed_out = mptsas_eh_timed_out;
5412 "mptscsih_io_done");
5414 "mptscsih_taskmgmt_complete");
5417 "mptscsih_scandv_complete");
5418 mptsasMgmtCtx =
mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER,
5419 "mptsas_mgmt_done");
5420 mptsasDeviceResetCtx =
5422 "mptsas_taskmgmt_complete");
5427 error = pci_register_driver(&mptsas_driver);