aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/mpt3sas
diff options
context:
space:
mode:
authorJames Bottomley <JBottomley@Odin.com>2015-11-12 07:06:18 -0500
committerJames Bottomley <JBottomley@Odin.com>2015-11-12 07:06:18 -0500
commitfebdfbd2137a5727f70dfbf920105c07e6c2a21e (patch)
tree9483a5493ad3e08626e1f53ded594f88a6f4e710 /drivers/scsi/mpt3sas
parent0da39687a15403251bdfd1c6fb18025c0607326b (diff)
parent2c5d16d6a9e7218e57b716e4fd9d77c776d21471 (diff)
Merge tag '4.4-scsi-mkp' into misc
SCSI queue for 4.4. Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi/mpt3sas')
-rw-r--r--drivers/scsi/mpt3sas/Kconfig18
-rw-r--r--drivers/scsi/mpt3sas/Makefile3
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_base.c668
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_base.h233
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_config.c42
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_ctl.c259
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_ctl.h6
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_debug.h16
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_scsih.c1555
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_transport.c18
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_warpdrive.c344
11 files changed, 2436 insertions, 726 deletions
diff --git a/drivers/scsi/mpt3sas/Kconfig b/drivers/scsi/mpt3sas/Kconfig
index 4d235dd741bf..29061467cc17 100644
--- a/drivers/scsi/mpt3sas/Kconfig
+++ b/drivers/scsi/mpt3sas/Kconfig
@@ -41,15 +41,15 @@
41# USA. 41# USA.
42 42
43config SCSI_MPT3SAS 43config SCSI_MPT3SAS
44 tristate "LSI MPT Fusion SAS 3.0 Device Driver" 44 tristate "LSI MPT Fusion SAS 3.0 & SAS 2.0 Device Driver"
45 depends on PCI && SCSI 45 depends on PCI && SCSI
46 select SCSI_SAS_ATTRS 46 select SCSI_SAS_ATTRS
47 select RAID_ATTRS 47 select RAID_ATTRS
48 ---help--- 48 ---help---
49 This driver supports PCI-Express SAS 12Gb/s Host Adapters. 49 This driver supports PCI-Express SAS 12Gb/s Host Adapters.
50 50
51config SCSI_MPT3SAS_MAX_SGE 51config SCSI_MPT2SAS_MAX_SGE
52 int "LSI MPT Fusion Max number of SG Entries (16 - 256)" 52 int "LSI MPT Fusion SAS 2.0 Max number of SG Entries (16 - 256)"
53 depends on PCI && SCSI && SCSI_MPT3SAS 53 depends on PCI && SCSI && SCSI_MPT3SAS
54 default "128" 54 default "128"
55 range 16 256 55 range 16 256
@@ -60,8 +60,14 @@ config SCSI_MPT3SAS_MAX_SGE
60 can be 256. However, it may decreased down to 16. Decreasing this 60 can be 256. However, it may decreased down to 16. Decreasing this
61 parameter will reduce memory requirements on a per controller instance. 61 parameter will reduce memory requirements on a per controller instance.
62 62
63config SCSI_MPT3SAS_LOGGING 63config SCSI_MPT3SAS_MAX_SGE
64 bool "LSI MPT Fusion logging facility" 64 int "LSI MPT Fusion SAS 3.0 Max number of SG Entries (16 - 256)"
65 depends on PCI && SCSI && SCSI_MPT3SAS 65 depends on PCI && SCSI && SCSI_MPT3SAS
66 default "128"
67 range 16 256
66 ---help--- 68 ---help---
67 This turns on a logging facility. 69 This option allows you to specify the maximum number of scatter-
70 gather entries per I/O. The driver default is 128, which matches
71 MAX_PHYS_SEGMENTS in most kernels. However in SuSE kernels this
72 can be 256. However, it may decreased down to 16. Decreasing this
73 parameter will reduce memory requirements on a per controller instance.
diff --git a/drivers/scsi/mpt3sas/Makefile b/drivers/scsi/mpt3sas/Makefile
index efb0c4c2e310..b7643f596c1e 100644
--- a/drivers/scsi/mpt3sas/Makefile
+++ b/drivers/scsi/mpt3sas/Makefile
@@ -5,4 +5,5 @@ mpt3sas-y += mpt3sas_base.o \
5 mpt3sas_scsih.o \ 5 mpt3sas_scsih.o \
6 mpt3sas_transport.o \ 6 mpt3sas_transport.o \
7 mpt3sas_ctl.o \ 7 mpt3sas_ctl.o \
8 mpt3sas_trigger_diag.o 8 mpt3sas_trigger_diag.o \
9 mpt3sas_warpdrive.o
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index d4f1dcdb8361..11393ebf1a68 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -108,9 +108,12 @@ _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
108 if (ret) 108 if (ret)
109 return ret; 109 return ret;
110 110
111 /* global ioc spinlock to protect controller list on list operations */
111 pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug); 112 pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug);
113 spin_lock(&gioc_lock);
112 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) 114 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
113 ioc->fwfault_debug = mpt3sas_fwfault_debug; 115 ioc->fwfault_debug = mpt3sas_fwfault_debug;
116 spin_unlock(&gioc_lock);
114 return 0; 117 return 0;
115} 118}
116module_param_call(mpt3sas_fwfault_debug, _scsih_set_fwfault_debug, 119module_param_call(mpt3sas_fwfault_debug, _scsih_set_fwfault_debug,
@@ -157,7 +160,7 @@ _base_fault_reset_work(struct work_struct *work)
157 160
158 161
159 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); 162 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
160 if (ioc->shost_recovery) 163 if (ioc->shost_recovery || ioc->pci_error_recovery)
161 goto rearm_timer; 164 goto rearm_timer;
162 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); 165 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
163 166
@@ -166,6 +169,20 @@ _base_fault_reset_work(struct work_struct *work)
166 pr_err(MPT3SAS_FMT "SAS host is non-operational !!!!\n", 169 pr_err(MPT3SAS_FMT "SAS host is non-operational !!!!\n",
167 ioc->name); 170 ioc->name);
168 171
172 /* It may be possible that EEH recovery can resolve some of
173 * pci bus failure issues rather removing the dead ioc function
174 * by considering controller is in a non-operational state. So
175 * here priority is given to the EEH recovery. If it doesn't
176 * not resolve this issue, mpt3sas driver will consider this
177 * controller to non-operational state and remove the dead ioc
178 * function.
179 */
180 if (ioc->non_operational_loop++ < 5) {
181 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock,
182 flags);
183 goto rearm_timer;
184 }
185
169 /* 186 /*
170 * Call _scsih_flush_pending_cmds callback so that we flush all 187 * Call _scsih_flush_pending_cmds callback so that we flush all
171 * pending commands back to OS. This call is required to aovid 188 * pending commands back to OS. This call is required to aovid
@@ -181,7 +198,7 @@ _base_fault_reset_work(struct work_struct *work)
181 ioc->remove_host = 1; 198 ioc->remove_host = 1;
182 /*Remove the Dead Host */ 199 /*Remove the Dead Host */
183 p = kthread_run(mpt3sas_remove_dead_ioc_func, ioc, 200 p = kthread_run(mpt3sas_remove_dead_ioc_func, ioc,
184 "mpt3sas_dead_ioc_%d", ioc->id); 201 "%s_dead_ioc_%d", ioc->driver_name, ioc->id);
185 if (IS_ERR(p)) 202 if (IS_ERR(p))
186 pr_err(MPT3SAS_FMT 203 pr_err(MPT3SAS_FMT
187 "%s: Running mpt3sas_dead_ioc thread failed !!!!\n", 204 "%s: Running mpt3sas_dead_ioc thread failed !!!!\n",
@@ -193,6 +210,8 @@ _base_fault_reset_work(struct work_struct *work)
193 return; /* don't rearm timer */ 210 return; /* don't rearm timer */
194 } 211 }
195 212
213 ioc->non_operational_loop = 0;
214
196 if ((doorbell & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) { 215 if ((doorbell & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) {
197 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, 216 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
198 FORCE_BIG_HAMMER); 217 FORCE_BIG_HAMMER);
@@ -235,7 +254,8 @@ mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER *ioc)
235 254
236 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work); 255 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
237 snprintf(ioc->fault_reset_work_q_name, 256 snprintf(ioc->fault_reset_work_q_name,
238 sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id); 257 sizeof(ioc->fault_reset_work_q_name), "poll_%s%d_status",
258 ioc->driver_name, ioc->id);
239 ioc->fault_reset_work_q = 259 ioc->fault_reset_work_q =
240 create_singlethread_workqueue(ioc->fault_reset_work_q_name); 260 create_singlethread_workqueue(ioc->fault_reset_work_q_name);
241 if (!ioc->fault_reset_work_q) { 261 if (!ioc->fault_reset_work_q) {
@@ -324,7 +344,6 @@ mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER *ioc)
324 panic("panic in %s\n", __func__); 344 panic("panic in %s\n", __func__);
325} 345}
326 346
327#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
328/** 347/**
329 * _base_sas_ioc_info - verbose translation of the ioc status 348 * _base_sas_ioc_info - verbose translation of the ioc status
330 * @ioc: per adapter object 349 * @ioc: per adapter object
@@ -578,7 +597,8 @@ _base_display_event_data(struct MPT3SAS_ADAPTER *ioc,
578 desc = "Device Status Change"; 597 desc = "Device Status Change";
579 break; 598 break;
580 case MPI2_EVENT_IR_OPERATION_STATUS: 599 case MPI2_EVENT_IR_OPERATION_STATUS:
581 desc = "IR Operation Status"; 600 if (!ioc->hide_ir_msg)
601 desc = "IR Operation Status";
582 break; 602 break;
583 case MPI2_EVENT_SAS_DISCOVERY: 603 case MPI2_EVENT_SAS_DISCOVERY:
584 { 604 {
@@ -609,16 +629,20 @@ _base_display_event_data(struct MPT3SAS_ADAPTER *ioc,
609 desc = "SAS Enclosure Device Status Change"; 629 desc = "SAS Enclosure Device Status Change";
610 break; 630 break;
611 case MPI2_EVENT_IR_VOLUME: 631 case MPI2_EVENT_IR_VOLUME:
612 desc = "IR Volume"; 632 if (!ioc->hide_ir_msg)
633 desc = "IR Volume";
613 break; 634 break;
614 case MPI2_EVENT_IR_PHYSICAL_DISK: 635 case MPI2_EVENT_IR_PHYSICAL_DISK:
615 desc = "IR Physical Disk"; 636 if (!ioc->hide_ir_msg)
637 desc = "IR Physical Disk";
616 break; 638 break;
617 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: 639 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
618 desc = "IR Configuration Change List"; 640 if (!ioc->hide_ir_msg)
641 desc = "IR Configuration Change List";
619 break; 642 break;
620 case MPI2_EVENT_LOG_ENTRY_ADDED: 643 case MPI2_EVENT_LOG_ENTRY_ADDED:
621 desc = "Log Entry Added"; 644 if (!ioc->hide_ir_msg)
645 desc = "Log Entry Added";
622 break; 646 break;
623 case MPI2_EVENT_TEMP_THRESHOLD: 647 case MPI2_EVENT_TEMP_THRESHOLD:
624 desc = "Temperature Threshold"; 648 desc = "Temperature Threshold";
@@ -630,7 +654,6 @@ _base_display_event_data(struct MPT3SAS_ADAPTER *ioc,
630 654
631 pr_info(MPT3SAS_FMT "%s\n", ioc->name, desc); 655 pr_info(MPT3SAS_FMT "%s\n", ioc->name, desc);
632} 656}
633#endif
634 657
635/** 658/**
636 * _base_sas_log_info - verbose translation of firmware log info 659 * _base_sas_log_info - verbose translation of firmware log info
@@ -675,7 +698,10 @@ _base_sas_log_info(struct MPT3SAS_ADAPTER *ioc , u32 log_info)
675 originator_str = "PL"; 698 originator_str = "PL";
676 break; 699 break;
677 case 2: 700 case 2:
678 originator_str = "IR"; 701 if (!ioc->hide_ir_msg)
702 originator_str = "IR";
703 else
704 originator_str = "WarpDrive";
679 break; 705 break;
680 } 706 }
681 707
@@ -710,13 +736,13 @@ _base_display_reply_info(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
710 return; 736 return;
711 } 737 }
712 ioc_status = le16_to_cpu(mpi_reply->IOCStatus); 738 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
713#ifdef CONFIG_SCSI_MPT3SAS_LOGGING 739
714 if ((ioc_status & MPI2_IOCSTATUS_MASK) && 740 if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
715 (ioc->logging_level & MPT_DEBUG_REPLY)) { 741 (ioc->logging_level & MPT_DEBUG_REPLY)) {
716 _base_sas_ioc_info(ioc , mpi_reply, 742 _base_sas_ioc_info(ioc , mpi_reply,
717 mpt3sas_base_get_msg_frame(ioc, smid)); 743 mpt3sas_base_get_msg_frame(ioc, smid));
718 } 744 }
719#endif 745
720 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) { 746 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
721 loginfo = le32_to_cpu(mpi_reply->IOCLogInfo); 747 loginfo = le32_to_cpu(mpi_reply->IOCLogInfo);
722 _base_sas_log_info(ioc, loginfo); 748 _base_sas_log_info(ioc, loginfo);
@@ -783,9 +809,9 @@ _base_async_event(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
783 return 1; 809 return 1;
784 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION) 810 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
785 return 1; 811 return 1;
786#ifdef CONFIG_SCSI_MPT3SAS_LOGGING 812
787 _base_display_event_data(ioc, mpi_reply); 813 _base_display_event_data(ioc, mpi_reply);
788#endif 814
789 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED)) 815 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
790 goto out; 816 goto out;
791 smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); 817 smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx);
@@ -1009,6 +1035,12 @@ _base_interrupt(int irq, void *bus_id)
1009 } 1035 }
1010 1036
1011 wmb(); 1037 wmb();
1038 if (ioc->is_warpdrive) {
1039 writel(reply_q->reply_post_host_index,
1040 ioc->reply_post_host_index[msix_index]);
1041 atomic_dec(&reply_q->busy);
1042 return IRQ_HANDLED;
1043 }
1012 1044
1013 /* Update Reply Post Host Index. 1045 /* Update Reply Post Host Index.
1014 * For those HBA's which support combined reply queue feature 1046 * For those HBA's which support combined reply queue feature
@@ -1320,6 +1352,149 @@ _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER *ioc, void *paddr)
1320} 1352}
1321 1353
1322/** 1354/**
1355 * _base_build_sg_scmd - main sg creation routine
1356 * @ioc: per adapter object
1357 * @scmd: scsi command
1358 * @smid: system request message index
1359 * Context: none.
1360 *
1361 * The main routine that builds scatter gather table from a given
1362 * scsi request sent via the .queuecommand main handler.
1363 *
1364 * Returns 0 success, anything else error
1365 */
1366static int
1367_base_build_sg_scmd(struct MPT3SAS_ADAPTER *ioc,
1368 struct scsi_cmnd *scmd, u16 smid)
1369{
1370 Mpi2SCSIIORequest_t *mpi_request;
1371 dma_addr_t chain_dma;
1372 struct scatterlist *sg_scmd;
1373 void *sg_local, *chain;
1374 u32 chain_offset;
1375 u32 chain_length;
1376 u32 chain_flags;
1377 int sges_left;
1378 u32 sges_in_segment;
1379 u32 sgl_flags;
1380 u32 sgl_flags_last_element;
1381 u32 sgl_flags_end_buffer;
1382 struct chain_tracker *chain_req;
1383
1384 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1385
1386 /* init scatter gather flags */
1387 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1388 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1389 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1390 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1391 << MPI2_SGE_FLAGS_SHIFT;
1392 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1393 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1394 << MPI2_SGE_FLAGS_SHIFT;
1395 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1396
1397 sg_scmd = scsi_sglist(scmd);
1398 sges_left = scsi_dma_map(scmd);
1399 if (sges_left < 0) {
1400 sdev_printk(KERN_ERR, scmd->device,
1401 "pci_map_sg failed: request for %d bytes!\n",
1402 scsi_bufflen(scmd));
1403 return -ENOMEM;
1404 }
1405
1406 sg_local = &mpi_request->SGL;
1407 sges_in_segment = ioc->max_sges_in_main_message;
1408 if (sges_left <= sges_in_segment)
1409 goto fill_in_last_segment;
1410
1411 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1412 (sges_in_segment * ioc->sge_size))/4;
1413
1414 /* fill in main message segment when there is a chain following */
1415 while (sges_in_segment) {
1416 if (sges_in_segment == 1)
1417 ioc->base_add_sg_single(sg_local,
1418 sgl_flags_last_element | sg_dma_len(sg_scmd),
1419 sg_dma_address(sg_scmd));
1420 else
1421 ioc->base_add_sg_single(sg_local, sgl_flags |
1422 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1423 sg_scmd = sg_next(sg_scmd);
1424 sg_local += ioc->sge_size;
1425 sges_left--;
1426 sges_in_segment--;
1427 }
1428
1429 /* initializing the chain flags and pointers */
1430 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1431 chain_req = _base_get_chain_buffer_tracker(ioc, smid);
1432 if (!chain_req)
1433 return -1;
1434 chain = chain_req->chain_buffer;
1435 chain_dma = chain_req->chain_buffer_dma;
1436 do {
1437 sges_in_segment = (sges_left <=
1438 ioc->max_sges_in_chain_message) ? sges_left :
1439 ioc->max_sges_in_chain_message;
1440 chain_offset = (sges_left == sges_in_segment) ?
1441 0 : (sges_in_segment * ioc->sge_size)/4;
1442 chain_length = sges_in_segment * ioc->sge_size;
1443 if (chain_offset) {
1444 chain_offset = chain_offset <<
1445 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1446 chain_length += ioc->sge_size;
1447 }
1448 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1449 chain_length, chain_dma);
1450 sg_local = chain;
1451 if (!chain_offset)
1452 goto fill_in_last_segment;
1453
1454 /* fill in chain segments */
1455 while (sges_in_segment) {
1456 if (sges_in_segment == 1)
1457 ioc->base_add_sg_single(sg_local,
1458 sgl_flags_last_element |
1459 sg_dma_len(sg_scmd),
1460 sg_dma_address(sg_scmd));
1461 else
1462 ioc->base_add_sg_single(sg_local, sgl_flags |
1463 sg_dma_len(sg_scmd),
1464 sg_dma_address(sg_scmd));
1465 sg_scmd = sg_next(sg_scmd);
1466 sg_local += ioc->sge_size;
1467 sges_left--;
1468 sges_in_segment--;
1469 }
1470
1471 chain_req = _base_get_chain_buffer_tracker(ioc, smid);
1472 if (!chain_req)
1473 return -1;
1474 chain = chain_req->chain_buffer;
1475 chain_dma = chain_req->chain_buffer_dma;
1476 } while (1);
1477
1478
1479 fill_in_last_segment:
1480
1481 /* fill the last segment */
1482 while (sges_left) {
1483 if (sges_left == 1)
1484 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1485 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1486 else
1487 ioc->base_add_sg_single(sg_local, sgl_flags |
1488 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1489 sg_scmd = sg_next(sg_scmd);
1490 sg_local += ioc->sge_size;
1491 sges_left--;
1492 }
1493
1494 return 0;
1495}
1496
1497/**
1323 * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format 1498 * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format
1324 * @ioc: per adapter object 1499 * @ioc: per adapter object
1325 * @scmd: scsi command 1500 * @scmd: scsi command
@@ -1571,6 +1746,14 @@ _base_check_enable_msix(struct MPT3SAS_ADAPTER *ioc)
1571 int base; 1746 int base;
1572 u16 message_control; 1747 u16 message_control;
1573 1748
1749 /* Check whether controller SAS2008 B0 controller,
1750 * if it is SAS2008 B0 controller use IO-APIC instead of MSIX
1751 */
1752 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 &&
1753 ioc->pdev->revision == SAS2_PCI_DEVICE_B0_REVISION) {
1754 return -EINVAL;
1755 }
1756
1574 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); 1757 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1575 if (!base) { 1758 if (!base) {
1576 dfailprintk(ioc, pr_info(MPT3SAS_FMT "msix not supported\n", 1759 dfailprintk(ioc, pr_info(MPT3SAS_FMT "msix not supported\n",
@@ -1579,9 +1762,19 @@ _base_check_enable_msix(struct MPT3SAS_ADAPTER *ioc)
1579 } 1762 }
1580 1763
1581 /* get msix vector count */ 1764 /* get msix vector count */
1582 1765 /* NUMA_IO not supported for older controllers */
1583 pci_read_config_word(ioc->pdev, base + 2, &message_control); 1766 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
1584 ioc->msix_vector_count = (message_control & 0x3FF) + 1; 1767 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
1768 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
1769 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
1770 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
1771 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
1772 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
1773 ioc->msix_vector_count = 1;
1774 else {
1775 pci_read_config_word(ioc->pdev, base + 2, &message_control);
1776 ioc->msix_vector_count = (message_control & 0x3FF) + 1;
1777 }
1585 dinitprintk(ioc, pr_info(MPT3SAS_FMT 1778 dinitprintk(ioc, pr_info(MPT3SAS_FMT
1586 "msix is supported, vector_count(%d)\n", 1779 "msix is supported, vector_count(%d)\n",
1587 ioc->name, ioc->msix_vector_count)); 1780 ioc->name, ioc->msix_vector_count));
@@ -1643,10 +1836,10 @@ _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector)
1643 atomic_set(&reply_q->busy, 0); 1836 atomic_set(&reply_q->busy, 0);
1644 if (ioc->msix_enable) 1837 if (ioc->msix_enable)
1645 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d", 1838 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
1646 MPT3SAS_DRIVER_NAME, ioc->id, index); 1839 ioc->driver_name, ioc->id, index);
1647 else 1840 else
1648 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d", 1841 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
1649 MPT3SAS_DRIVER_NAME, ioc->id); 1842 ioc->driver_name, ioc->id);
1650 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name, 1843 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1651 reply_q); 1844 reply_q);
1652 if (r) { 1845 if (r) {
@@ -1872,7 +2065,7 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc)
1872 2065
1873 2066
1874 if (pci_request_selected_regions(pdev, ioc->bars, 2067 if (pci_request_selected_regions(pdev, ioc->bars,
1875 MPT3SAS_DRIVER_NAME)) { 2068 ioc->driver_name)) {
1876 pr_warn(MPT3SAS_FMT "pci_request_selected_regions: failed\n", 2069 pr_warn(MPT3SAS_FMT "pci_request_selected_regions: failed\n",
1877 ioc->name); 2070 ioc->name);
1878 ioc->bars = 0; 2071 ioc->bars = 0;
@@ -2158,6 +2351,7 @@ mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid)
2158 } 2351 }
2159 ioc->scsi_lookup[i].cb_idx = 0xFF; 2352 ioc->scsi_lookup[i].cb_idx = 0xFF;
2160 ioc->scsi_lookup[i].scmd = NULL; 2353 ioc->scsi_lookup[i].scmd = NULL;
2354 ioc->scsi_lookup[i].direct_io = 0;
2161 list_add(&ioc->scsi_lookup[i].tracker_list, &ioc->free_list); 2355 list_add(&ioc->scsi_lookup[i].tracker_list, &ioc->free_list);
2162 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 2356 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2163 2357
@@ -2318,143 +2512,261 @@ mpt3sas_base_put_smid_default(struct MPT3SAS_ADAPTER *ioc, u16 smid)
2318} 2512}
2319 2513
2320/** 2514/**
2321 * _base_display_intel_branding - Display branding string 2515 * _base_display_OEMs_branding - Display branding string
2322 * @ioc: per adapter object 2516 * @ioc: per adapter object
2323 * 2517 *
2324 * Return nothing. 2518 * Return nothing.
2325 */ 2519 */
2326static void 2520static void
2327_base_display_intel_branding(struct MPT3SAS_ADAPTER *ioc) 2521_base_display_OEMs_branding(struct MPT3SAS_ADAPTER *ioc)
2328{ 2522{
2329 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) 2523 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
2330 return; 2524 return;
2331 2525
2332 switch (ioc->pdev->device) { 2526 switch (ioc->pdev->subsystem_vendor) {
2333 case MPI25_MFGPAGE_DEVID_SAS3008: 2527 case PCI_VENDOR_ID_INTEL:
2334 switch (ioc->pdev->subsystem_device) { 2528 switch (ioc->pdev->device) {
2335 case MPT3SAS_INTEL_RMS3JC080_SSDID: 2529 case MPI2_MFGPAGE_DEVID_SAS2008:
2336 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2530 switch (ioc->pdev->subsystem_device) {
2337 MPT3SAS_INTEL_RMS3JC080_BRANDING); 2531 case MPT2SAS_INTEL_RMS2LL080_SSDID:
2338 break; 2532 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2339 2533 MPT2SAS_INTEL_RMS2LL080_BRANDING);
2340 case MPT3SAS_INTEL_RS3GC008_SSDID: 2534 break;
2341 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2535 case MPT2SAS_INTEL_RMS2LL040_SSDID:
2342 MPT3SAS_INTEL_RS3GC008_BRANDING); 2536 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2343 break; 2537 MPT2SAS_INTEL_RMS2LL040_BRANDING);
2344 case MPT3SAS_INTEL_RS3FC044_SSDID: 2538 break;
2345 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2539 case MPT2SAS_INTEL_SSD910_SSDID:
2346 MPT3SAS_INTEL_RS3FC044_BRANDING); 2540 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2347 break; 2541 MPT2SAS_INTEL_SSD910_BRANDING);
2348 case MPT3SAS_INTEL_RS3UC080_SSDID: 2542 break;
2349 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2543 default:
2350 MPT3SAS_INTEL_RS3UC080_BRANDING); 2544 pr_info(MPT3SAS_FMT
2545 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2546 ioc->name, ioc->pdev->subsystem_device);
2547 break;
2548 }
2549 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2550 switch (ioc->pdev->subsystem_device) {
2551 case MPT2SAS_INTEL_RS25GB008_SSDID:
2552 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2553 MPT2SAS_INTEL_RS25GB008_BRANDING);
2554 break;
2555 case MPT2SAS_INTEL_RMS25JB080_SSDID:
2556 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2557 MPT2SAS_INTEL_RMS25JB080_BRANDING);
2558 break;
2559 case MPT2SAS_INTEL_RMS25JB040_SSDID:
2560 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2561 MPT2SAS_INTEL_RMS25JB040_BRANDING);
2562 break;
2563 case MPT2SAS_INTEL_RMS25KB080_SSDID:
2564 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2565 MPT2SAS_INTEL_RMS25KB080_BRANDING);
2566 break;
2567 case MPT2SAS_INTEL_RMS25KB040_SSDID:
2568 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2569 MPT2SAS_INTEL_RMS25KB040_BRANDING);
2570 break;
2571 case MPT2SAS_INTEL_RMS25LB040_SSDID:
2572 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2573 MPT2SAS_INTEL_RMS25LB040_BRANDING);
2574 break;
2575 case MPT2SAS_INTEL_RMS25LB080_SSDID:
2576 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2577 MPT2SAS_INTEL_RMS25LB080_BRANDING);
2578 break;
2579 default:
2580 pr_info(MPT3SAS_FMT
2581 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2582 ioc->name, ioc->pdev->subsystem_device);
2583 break;
2584 }
2585 case MPI25_MFGPAGE_DEVID_SAS3008:
2586 switch (ioc->pdev->subsystem_device) {
2587 case MPT3SAS_INTEL_RMS3JC080_SSDID:
2588 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2589 MPT3SAS_INTEL_RMS3JC080_BRANDING);
2590 break;
2591
2592 case MPT3SAS_INTEL_RS3GC008_SSDID:
2593 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2594 MPT3SAS_INTEL_RS3GC008_BRANDING);
2595 break;
2596 case MPT3SAS_INTEL_RS3FC044_SSDID:
2597 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2598 MPT3SAS_INTEL_RS3FC044_BRANDING);
2599 break;
2600 case MPT3SAS_INTEL_RS3UC080_SSDID:
2601 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2602 MPT3SAS_INTEL_RS3UC080_BRANDING);
2603 break;
2604 default:
2605 pr_info(MPT3SAS_FMT
2606 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2607 ioc->name, ioc->pdev->subsystem_device);
2608 break;
2609 }
2351 break; 2610 break;
2352 default: 2611 default:
2353 pr_info(MPT3SAS_FMT 2612 pr_info(MPT3SAS_FMT
2354 "Intel(R) Controller: Subsystem ID: 0x%X\n", 2613 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2355 ioc->name, ioc->pdev->subsystem_device); 2614 ioc->name, ioc->pdev->subsystem_device);
2356 break; 2615 break;
2357 } 2616 }
2358 break; 2617 break;
2359 default: 2618 case PCI_VENDOR_ID_DELL:
2360 pr_info(MPT3SAS_FMT 2619 switch (ioc->pdev->device) {
2361 "Intel(R) Controller: Subsystem ID: 0x%X\n", 2620 case MPI2_MFGPAGE_DEVID_SAS2008:
2362 ioc->name, ioc->pdev->subsystem_device); 2621 switch (ioc->pdev->subsystem_device) {
2363 break; 2622 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
2364 } 2623 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2365} 2624 MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING);
2366 2625 break;
2367 2626 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
2368 2627 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2369/** 2628 MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING);
2370 * _base_display_dell_branding - Display branding string 2629 break;
2371 * @ioc: per adapter object 2630 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
2372 * 2631 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2373 * Return nothing. 2632 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING);
2374 */ 2633 break;
2375static void 2634 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
2376_base_display_dell_branding(struct MPT3SAS_ADAPTER *ioc) 2635 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2377{ 2636 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING);
2378 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL) 2637 break;
2379 return; 2638 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
2380 2639 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2381 switch (ioc->pdev->device) { 2640 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING);
2382 case MPI25_MFGPAGE_DEVID_SAS3008: 2641 break;
2383 switch (ioc->pdev->subsystem_device) { 2642 case MPT2SAS_DELL_PERC_H200_SSDID:
2384 case MPT3SAS_DELL_12G_HBA_SSDID: 2643 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2385 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2644 MPT2SAS_DELL_PERC_H200_BRANDING);
2386 MPT3SAS_DELL_12G_HBA_BRANDING); 2645 break;
2646 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
2647 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2648 MPT2SAS_DELL_6GBPS_SAS_BRANDING);
2649 break;
2650 default:
2651 pr_info(MPT3SAS_FMT
2652 "Dell 6Gbps HBA: Subsystem ID: 0x%X\n",
2653 ioc->name, ioc->pdev->subsystem_device);
2654 break;
2655 }
2656 break;
2657 case MPI25_MFGPAGE_DEVID_SAS3008:
2658 switch (ioc->pdev->subsystem_device) {
2659 case MPT3SAS_DELL_12G_HBA_SSDID:
2660 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2661 MPT3SAS_DELL_12G_HBA_BRANDING);
2662 break;
2663 default:
2664 pr_info(MPT3SAS_FMT
2665 "Dell 12Gbps HBA: Subsystem ID: 0x%X\n",
2666 ioc->name, ioc->pdev->subsystem_device);
2667 break;
2668 }
2387 break; 2669 break;
2388 default: 2670 default:
2389 pr_info(MPT3SAS_FMT 2671 pr_info(MPT3SAS_FMT
2390 "Dell 12Gbps HBA: Subsystem ID: 0x%X\n", ioc->name, 2672 "Dell HBA: Subsystem ID: 0x%X\n", ioc->name,
2391 ioc->pdev->subsystem_device); 2673 ioc->pdev->subsystem_device);
2392 break; 2674 break;
2393 } 2675 }
2394 break; 2676 break;
2395 default: 2677 case PCI_VENDOR_ID_CISCO:
2396 pr_info(MPT3SAS_FMT 2678 switch (ioc->pdev->device) {
2397 "Dell 12Gbps HBA: Subsystem ID: 0x%X\n", ioc->name, 2679 case MPI25_MFGPAGE_DEVID_SAS3008:
2398 ioc->pdev->subsystem_device); 2680 switch (ioc->pdev->subsystem_device) {
2399 break; 2681 case MPT3SAS_CISCO_12G_8E_HBA_SSDID:
2400 } 2682 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2401} 2683 MPT3SAS_CISCO_12G_8E_HBA_BRANDING);
2402 2684 break;
2403/** 2685 case MPT3SAS_CISCO_12G_8I_HBA_SSDID:
2404 * _base_display_cisco_branding - Display branding string 2686 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2405 * @ioc: per adapter object 2687 MPT3SAS_CISCO_12G_8I_HBA_BRANDING);
2406 * 2688 break;
2407 * Return nothing. 2689 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID:
2408 */ 2690 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2409static void 2691 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING);
2410_base_display_cisco_branding(struct MPT3SAS_ADAPTER *ioc) 2692 break;
2411{ 2693 default:
2412 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_CISCO) 2694 pr_info(MPT3SAS_FMT
2413 return; 2695 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n",
2414 2696 ioc->name, ioc->pdev->subsystem_device);
2415 switch (ioc->pdev->device) { 2697 break;
2416 case MPI25_MFGPAGE_DEVID_SAS3008: 2698 }
2417 switch (ioc->pdev->subsystem_device) {
2418 case MPT3SAS_CISCO_12G_8E_HBA_SSDID:
2419 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2420 MPT3SAS_CISCO_12G_8E_HBA_BRANDING);
2421 break;
2422 case MPT3SAS_CISCO_12G_8I_HBA_SSDID:
2423 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2424 MPT3SAS_CISCO_12G_8I_HBA_BRANDING);
2425 break; 2699 break;
2426 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: 2700 case MPI25_MFGPAGE_DEVID_SAS3108_1:
2427 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2701 switch (ioc->pdev->subsystem_device) {
2702 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID:
2703 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2428 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); 2704 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING);
2705 break;
2706 case MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_SSDID:
2707 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2708 MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING
2709 );
2710 break;
2711 default:
2712 pr_info(MPT3SAS_FMT
2713 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n",
2714 ioc->name, ioc->pdev->subsystem_device);
2715 break;
2716 }
2429 break; 2717 break;
2430 default: 2718 default:
2431 pr_info(MPT3SAS_FMT 2719 pr_info(MPT3SAS_FMT
2432 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", 2720 "Cisco SAS HBA: Subsystem ID: 0x%X\n",
2433 ioc->name, ioc->pdev->subsystem_device); 2721 ioc->name, ioc->pdev->subsystem_device);
2434 break; 2722 break;
2435 } 2723 }
2436 break; 2724 break;
2437 case MPI25_MFGPAGE_DEVID_SAS3108_1: 2725 case MPT2SAS_HP_3PAR_SSVID:
2438 switch (ioc->pdev->subsystem_device) { 2726 switch (ioc->pdev->device) {
2439 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: 2727 case MPI2_MFGPAGE_DEVID_SAS2004:
2440 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2728 switch (ioc->pdev->subsystem_device) {
2441 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); 2729 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
2442 break; 2730 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2443 case MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_SSDID: 2731 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
2444 pr_info(MPT3SAS_FMT "%s\n", ioc->name, 2732 break;
2445 MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING); 2733 default:
2446 break; 2734 pr_info(MPT3SAS_FMT
2735 "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n",
2736 ioc->name, ioc->pdev->subsystem_device);
2737 break;
2738 }
2739 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2740 switch (ioc->pdev->subsystem_device) {
2741 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
2742 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2743 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
2744 break;
2745 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
2746 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2747 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
2748 break;
2749 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
2750 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2751 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
2752 break;
2753 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
2754 pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2755 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
2756 break;
2757 default:
2758 pr_info(MPT3SAS_FMT
2759 "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n",
2760 ioc->name, ioc->pdev->subsystem_device);
2761 break;
2762 }
2447 default: 2763 default:
2448 pr_info(MPT3SAS_FMT 2764 pr_info(MPT3SAS_FMT
2449 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", 2765 "HP SAS HBA: Subsystem ID: 0x%X\n",
2450 ioc->name, ioc->pdev->subsystem_device); 2766 ioc->name, ioc->pdev->subsystem_device);
2451 break; 2767 break;
2452 } 2768 }
2453 break;
2454 default: 2769 default:
2455 pr_info(MPT3SAS_FMT
2456 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n",
2457 ioc->name, ioc->pdev->subsystem_device);
2458 break; 2770 break;
2459 } 2771 }
2460} 2772}
@@ -2488,9 +2800,7 @@ _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER *ioc)
2488 (bios_version & 0x0000FF00) >> 8, 2800 (bios_version & 0x0000FF00) >> 8,
2489 bios_version & 0x000000FF); 2801 bios_version & 0x000000FF);
2490 2802
2491 _base_display_intel_branding(ioc); 2803 _base_display_OEMs_branding(ioc);
2492 _base_display_dell_branding(ioc);
2493 _base_display_cisco_branding(ioc);
2494 2804
2495 pr_info(MPT3SAS_FMT "Protocol=(", ioc->name); 2805 pr_info(MPT3SAS_FMT "Protocol=(", ioc->name);
2496 2806
@@ -2508,10 +2818,12 @@ _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER *ioc)
2508 pr_info("), "); 2818 pr_info("), ");
2509 pr_info("Capabilities=("); 2819 pr_info("Capabilities=(");
2510 2820
2511 if (ioc->facts.IOCCapabilities & 2821 if (!ioc->hide_ir_msg) {
2822 if (ioc->facts.IOCCapabilities &
2512 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) { 2823 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2513 pr_info("Raid"); 2824 pr_info("Raid");
2514 i++; 2825 i++;
2826 }
2515 } 2827 }
2516 2828
2517 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) { 2829 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
@@ -2852,18 +3164,22 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc, int sleep_flag)
2852 /* command line tunables for max sgl entries */ 3164 /* command line tunables for max sgl entries */
2853 if (max_sgl_entries != -1) 3165 if (max_sgl_entries != -1)
2854 sg_tablesize = max_sgl_entries; 3166 sg_tablesize = max_sgl_entries;
2855 else 3167 else {
2856 sg_tablesize = MPT3SAS_SG_DEPTH; 3168 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
3169 sg_tablesize = MPT2SAS_SG_DEPTH;
3170 else
3171 sg_tablesize = MPT3SAS_SG_DEPTH;
3172 }
2857 3173
2858 if (sg_tablesize < MPT3SAS_MIN_PHYS_SEGMENTS) 3174 if (sg_tablesize < MPT_MIN_PHYS_SEGMENTS)
2859 sg_tablesize = MPT3SAS_MIN_PHYS_SEGMENTS; 3175 sg_tablesize = MPT_MIN_PHYS_SEGMENTS;
2860 else if (sg_tablesize > MPT3SAS_MAX_PHYS_SEGMENTS) { 3176 else if (sg_tablesize > MPT_MAX_PHYS_SEGMENTS) {
2861 sg_tablesize = min_t(unsigned short, sg_tablesize, 3177 sg_tablesize = min_t(unsigned short, sg_tablesize,
2862 SCSI_MAX_SG_CHAIN_SEGMENTS); 3178 SCSI_MAX_SG_CHAIN_SEGMENTS);
2863 pr_warn(MPT3SAS_FMT 3179 pr_warn(MPT3SAS_FMT
2864 "sg_tablesize(%u) is bigger than kernel" 3180 "sg_tablesize(%u) is bigger than kernel"
2865 " defined SCSI_MAX_SG_SEGMENTS(%u)\n", ioc->name, 3181 " defined SCSI_MAX_SG_SEGMENTS(%u)\n", ioc->name,
2866 sg_tablesize, MPT3SAS_MAX_PHYS_SEGMENTS); 3182 sg_tablesize, MPT_MAX_PHYS_SEGMENTS);
2867 } 3183 }
2868 ioc->shost->sg_tablesize = sg_tablesize; 3184 ioc->shost->sg_tablesize = sg_tablesize;
2869 3185
@@ -4021,7 +4337,7 @@ _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc, int sleep_flag)
4021 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER; 4337 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
4022 mpi_request.VF_ID = 0; /* TODO */ 4338 mpi_request.VF_ID = 0; /* TODO */
4023 mpi_request.VP_ID = 0; 4339 mpi_request.VP_ID = 0;
4024 mpi_request.MsgVersion = cpu_to_le16(MPI25_VERSION); 4340 mpi_request.MsgVersion = cpu_to_le16(ioc->hba_mpi_version_belonged);
4025 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); 4341 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
4026 4342
4027 if (_base_is_controller_msix_enabled(ioc)) 4343 if (_base_is_controller_msix_enabled(ioc))
@@ -4655,6 +4971,7 @@ _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc, int sleep_flag)
4655 u32 reply_address; 4971 u32 reply_address;
4656 u16 smid; 4972 u16 smid;
4657 struct _tr_list *delayed_tr, *delayed_tr_next; 4973 struct _tr_list *delayed_tr, *delayed_tr_next;
4974 u8 hide_flag;
4658 struct adapter_reply_queue *reply_q; 4975 struct adapter_reply_queue *reply_q;
4659 long reply_post_free; 4976 long reply_post_free;
4660 u32 reply_post_free_sz, index = 0; 4977 u32 reply_post_free_sz, index = 0;
@@ -4685,6 +5002,7 @@ _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc, int sleep_flag)
4685 ioc->scsi_lookup[i].cb_idx = 0xFF; 5002 ioc->scsi_lookup[i].cb_idx = 0xFF;
4686 ioc->scsi_lookup[i].smid = smid; 5003 ioc->scsi_lookup[i].smid = smid;
4687 ioc->scsi_lookup[i].scmd = NULL; 5004 ioc->scsi_lookup[i].scmd = NULL;
5005 ioc->scsi_lookup[i].direct_io = 0;
4688 list_add_tail(&ioc->scsi_lookup[i].tracker_list, 5006 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4689 &ioc->free_list); 5007 &ioc->free_list);
4690 } 5008 }
@@ -4787,6 +5105,16 @@ _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc, int sleep_flag)
4787 5105
4788 5106
4789 if (ioc->is_driver_loading) { 5107 if (ioc->is_driver_loading) {
5108
5109 if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier
5110 == 0x80) {
5111 hide_flag = (u8) (
5112 le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) &
5113 MFG_PAGE10_HIDE_SSDS_MASK);
5114 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
5115 ioc->mfg_pg10_hide_flag = hide_flag;
5116 }
5117
4790 ioc->wait_for_discovery_to_complete = 5118 ioc->wait_for_discovery_to_complete =
4791 _base_determine_wait_on_discovery(ioc); 5119 _base_determine_wait_on_discovery(ioc);
4792 5120
@@ -4812,6 +5140,8 @@ mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER *ioc)
4812 dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, 5140 dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
4813 __func__)); 5141 __func__));
4814 5142
5143 /* synchronizing freeing resource with pci_access_mutex lock */
5144 mutex_lock(&ioc->pci_access_mutex);
4815 if (ioc->chip_phys && ioc->chip) { 5145 if (ioc->chip_phys && ioc->chip) {
4816 _base_mask_interrupts(ioc); 5146 _base_mask_interrupts(ioc);
4817 ioc->shost_recovery = 1; 5147 ioc->shost_recovery = 1;
@@ -4820,6 +5150,7 @@ mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER *ioc)
4820 } 5150 }
4821 5151
4822 mpt3sas_base_unmap_resources(ioc); 5152 mpt3sas_base_unmap_resources(ioc);
5153 mutex_unlock(&ioc->pci_access_mutex);
4823 return; 5154 return;
4824} 5155}
4825 5156
@@ -4834,7 +5165,6 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
4834{ 5165{
4835 int r, i; 5166 int r, i;
4836 int cpu_id, last_cpu_id = 0; 5167 int cpu_id, last_cpu_id = 0;
4837 u8 revision;
4838 5168
4839 dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, 5169 dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
4840 __func__)); 5170 __func__));
@@ -4854,19 +5184,16 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
4854 goto out_free_resources; 5184 goto out_free_resources;
4855 } 5185 }
4856 5186
4857 /* Check whether the controller revision is C0 or above. 5187 if (ioc->is_warpdrive) {
4858 * only C0 and above revision controllers support 96 MSI-X vectors. 5188 ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
4859 */ 5189 sizeof(resource_size_t *), GFP_KERNEL);
4860 revision = ioc->pdev->revision; 5190 if (!ioc->reply_post_host_index) {
4861 5191 dfailprintk(ioc, pr_info(MPT3SAS_FMT "allocation "
4862 if ((ioc->pdev->device == MPI25_MFGPAGE_DEVID_SAS3004 || 5192 "for cpu_msix_table failed!!!\n", ioc->name));
4863 ioc->pdev->device == MPI25_MFGPAGE_DEVID_SAS3008 || 5193 r = -ENOMEM;
4864 ioc->pdev->device == MPI25_MFGPAGE_DEVID_SAS3108_1 || 5194 goto out_free_resources;
4865 ioc->pdev->device == MPI25_MFGPAGE_DEVID_SAS3108_2 || 5195 }
4866 ioc->pdev->device == MPI25_MFGPAGE_DEVID_SAS3108_5 || 5196 }
4867 ioc->pdev->device == MPI25_MFGPAGE_DEVID_SAS3108_6) &&
4868 (revision >= 0x02))
4869 ioc->msix96_vector = 1;
4870 5197
4871 ioc->rdpq_array_enable_assigned = 0; 5198 ioc->rdpq_array_enable_assigned = 0;
4872 ioc->dma_mask = 0; 5199 ioc->dma_mask = 0;
@@ -4874,23 +5201,41 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
4874 if (r) 5201 if (r)
4875 goto out_free_resources; 5202 goto out_free_resources;
4876 5203
5204 if (ioc->is_warpdrive) {
5205 ioc->reply_post_host_index[0] = (resource_size_t __iomem *)
5206 &ioc->chip->ReplyPostHostIndex;
5207
5208 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
5209 ioc->reply_post_host_index[i] =
5210 (resource_size_t __iomem *)
5211 ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
5212 * 4)));
5213 }
4877 5214
4878 pci_set_drvdata(ioc->pdev, ioc->shost); 5215 pci_set_drvdata(ioc->pdev, ioc->shost);
4879 r = _base_get_ioc_facts(ioc, CAN_SLEEP); 5216 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
4880 if (r) 5217 if (r)
4881 goto out_free_resources; 5218 goto out_free_resources;
4882 5219
4883 /* 5220 switch (ioc->hba_mpi_version_belonged) {
4884 * In SAS3.0, 5221 case MPI2_VERSION:
4885 * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and 5222 ioc->build_sg_scmd = &_base_build_sg_scmd;
4886 * Target Status - all require the IEEE formated scatter gather 5223 ioc->build_sg = &_base_build_sg;
4887 * elements. 5224 ioc->build_zero_len_sge = &_base_build_zero_len_sge;
4888 */ 5225 break;
4889 5226 case MPI25_VERSION:
4890 ioc->build_sg_scmd = &_base_build_sg_scmd_ieee; 5227 /*
4891 ioc->build_sg = &_base_build_sg_ieee; 5228 * In SAS3.0,
4892 ioc->build_zero_len_sge = &_base_build_zero_len_sge_ieee; 5229 * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and
4893 ioc->sge_size_ieee = sizeof(Mpi2IeeeSgeSimple64_t); 5230 * Target Status - all require the IEEE formated scatter gather
5231 * elements.
5232 */
5233 ioc->build_sg_scmd = &_base_build_sg_scmd_ieee;
5234 ioc->build_sg = &_base_build_sg_ieee;
5235 ioc->build_zero_len_sge = &_base_build_zero_len_sge_ieee;
5236 ioc->sge_size_ieee = sizeof(Mpi2IeeeSgeSimple64_t);
5237 break;
5238 }
4894 5239
4895 /* 5240 /*
4896 * These function pointers for other requests that don't 5241 * These function pointers for other requests that don't
@@ -5006,6 +5351,7 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
5006 if (r) 5351 if (r)
5007 goto out_free_resources; 5352 goto out_free_resources;
5008 5353
5354 ioc->non_operational_loop = 0;
5009 return 0; 5355 return 0;
5010 5356
5011 out_free_resources: 5357 out_free_resources:
@@ -5016,6 +5362,8 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
5016 _base_release_memory_pools(ioc); 5362 _base_release_memory_pools(ioc);
5017 pci_set_drvdata(ioc->pdev, NULL); 5363 pci_set_drvdata(ioc->pdev, NULL);
5018 kfree(ioc->cpu_msix_table); 5364 kfree(ioc->cpu_msix_table);
5365 if (ioc->is_warpdrive)
5366 kfree(ioc->reply_post_host_index);
5019 kfree(ioc->pd_handles); 5367 kfree(ioc->pd_handles);
5020 kfree(ioc->blocking_handles); 5368 kfree(ioc->blocking_handles);
5021 kfree(ioc->tm_cmds.reply); 5369 kfree(ioc->tm_cmds.reply);
@@ -5055,6 +5403,8 @@ mpt3sas_base_detach(struct MPT3SAS_ADAPTER *ioc)
5055 _base_release_memory_pools(ioc); 5403 _base_release_memory_pools(ioc);
5056 pci_set_drvdata(ioc->pdev, NULL); 5404 pci_set_drvdata(ioc->pdev, NULL);
5057 kfree(ioc->cpu_msix_table); 5405 kfree(ioc->cpu_msix_table);
5406 if (ioc->is_warpdrive)
5407 kfree(ioc->reply_post_host_index);
5058 kfree(ioc->pd_handles); 5408 kfree(ioc->pd_handles);
5059 kfree(ioc->blocking_handles); 5409 kfree(ioc->blocking_handles);
5060 kfree(ioc->pfacts); 5410 kfree(ioc->pfacts);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index f0e462b0880d..a17bea95b0c5 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -63,6 +63,8 @@
63#include <scsi/scsi_transport_sas.h> 63#include <scsi/scsi_transport_sas.h>
64#include <scsi/scsi_dbg.h> 64#include <scsi/scsi_dbg.h>
65#include <scsi/scsi_eh.h> 65#include <scsi/scsi_eh.h>
66#include <linux/pci.h>
67#include <linux/poll.h>
66 68
67#include "mpt3sas_debug.h" 69#include "mpt3sas_debug.h"
68#include "mpt3sas_trigger_diag.h" 70#include "mpt3sas_trigger_diag.h"
@@ -71,23 +73,37 @@
71#define MPT3SAS_DRIVER_NAME "mpt3sas" 73#define MPT3SAS_DRIVER_NAME "mpt3sas"
72#define MPT3SAS_AUTHOR "Avago Technologies <MPT-FusionLinux.pdl@avagotech.com>" 74#define MPT3SAS_AUTHOR "Avago Technologies <MPT-FusionLinux.pdl@avagotech.com>"
73#define MPT3SAS_DESCRIPTION "LSI MPT Fusion SAS 3.0 Device Driver" 75#define MPT3SAS_DESCRIPTION "LSI MPT Fusion SAS 3.0 Device Driver"
74#define MPT3SAS_DRIVER_VERSION "09.100.00.00" 76#define MPT3SAS_DRIVER_VERSION "09.102.00.00"
75#define MPT3SAS_MAJOR_VERSION 9 77#define MPT3SAS_MAJOR_VERSION 9
76#define MPT3SAS_MINOR_VERSION 100 78#define MPT3SAS_MINOR_VERSION 102
77#define MPT3SAS_BUILD_VERSION 0 79#define MPT3SAS_BUILD_VERSION 0
78#define MPT3SAS_RELEASE_VERSION 00 80#define MPT3SAS_RELEASE_VERSION 00
79 81
82#define MPT2SAS_DRIVER_NAME "mpt2sas"
83#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver"
84#define MPT2SAS_DRIVER_VERSION "20.102.00.00"
85#define MPT2SAS_MAJOR_VERSION 20
86#define MPT2SAS_MINOR_VERSION 102
87#define MPT2SAS_BUILD_VERSION 0
88#define MPT2SAS_RELEASE_VERSION 00
89
80/* 90/*
81 * Set MPT3SAS_SG_DEPTH value based on user input. 91 * Set MPT3SAS_SG_DEPTH value based on user input.
82 */ 92 */
83#define MPT3SAS_MAX_PHYS_SEGMENTS SCSI_MAX_SG_SEGMENTS 93#define MPT_MAX_PHYS_SEGMENTS SCSI_MAX_SG_SEGMENTS
84#define MPT3SAS_MIN_PHYS_SEGMENTS 16 94#define MPT_MIN_PHYS_SEGMENTS 16
95
85#ifdef CONFIG_SCSI_MPT3SAS_MAX_SGE 96#ifdef CONFIG_SCSI_MPT3SAS_MAX_SGE
86#define MPT3SAS_SG_DEPTH CONFIG_SCSI_MPT3SAS_MAX_SGE 97#define MPT3SAS_SG_DEPTH CONFIG_SCSI_MPT3SAS_MAX_SGE
87#else 98#else
88#define MPT3SAS_SG_DEPTH MPT3SAS_MAX_PHYS_SEGMENTS 99#define MPT3SAS_SG_DEPTH MPT_MAX_PHYS_SEGMENTS
89#endif 100#endif
90 101
102#ifdef CONFIG_SCSI_MPT2SAS_MAX_SGE
103#define MPT2SAS_SG_DEPTH CONFIG_SCSI_MPT2SAS_MAX_SGE
104#else
105#define MPT2SAS_SG_DEPTH MPT_MAX_PHYS_SEGMENTS
106#endif
91 107
92/* 108/*
93 * Generic Defines 109 * Generic Defines
@@ -124,6 +140,16 @@
124#define MPT3SAS_FMT "%s: " 140#define MPT3SAS_FMT "%s: "
125 141
126/* 142/*
143 * WarpDrive Specific Log codes
144 */
145
146#define MPT2_WARPDRIVE_LOGENTRY (0x8002)
147#define MPT2_WARPDRIVE_LC_SSDT (0x41)
148#define MPT2_WARPDRIVE_LC_SSDLW (0x43)
149#define MPT2_WARPDRIVE_LC_SSDLF (0x44)
150#define MPT2_WARPDRIVE_LC_BRMF (0x4D)
151
152/*
127 * per target private data 153 * per target private data
128 */ 154 */
129#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01 155#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01
@@ -131,9 +157,33 @@
131#define MPT_TARGET_FLAGS_DELETED 0x04 157#define MPT_TARGET_FLAGS_DELETED 0x04
132#define MPT_TARGET_FASTPATH_IO 0x08 158#define MPT_TARGET_FASTPATH_IO 0x08
133 159
160#define SAS2_PCI_DEVICE_B0_REVISION (0x01)
161#define SAS3_PCI_DEVICE_C0_REVISION (0x02)
162
134/* 163/*
135 * Intel HBA branding 164 * Intel HBA branding
136 */ 165 */
166#define MPT2SAS_INTEL_RMS25JB080_BRANDING \
167 "Intel(R) Integrated RAID Module RMS25JB080"
168#define MPT2SAS_INTEL_RMS25JB040_BRANDING \
169 "Intel(R) Integrated RAID Module RMS25JB040"
170#define MPT2SAS_INTEL_RMS25KB080_BRANDING \
171 "Intel(R) Integrated RAID Module RMS25KB080"
172#define MPT2SAS_INTEL_RMS25KB040_BRANDING \
173 "Intel(R) Integrated RAID Module RMS25KB040"
174#define MPT2SAS_INTEL_RMS25LB040_BRANDING \
175 "Intel(R) Integrated RAID Module RMS25LB040"
176#define MPT2SAS_INTEL_RMS25LB080_BRANDING \
177 "Intel(R) Integrated RAID Module RMS25LB080"
178#define MPT2SAS_INTEL_RMS2LL080_BRANDING \
179 "Intel Integrated RAID Module RMS2LL080"
180#define MPT2SAS_INTEL_RMS2LL040_BRANDING \
181 "Intel Integrated RAID Module RMS2LL040"
182#define MPT2SAS_INTEL_RS25GB008_BRANDING \
183 "Intel(R) RAID Controller RS25GB008"
184#define MPT2SAS_INTEL_SSD910_BRANDING \
185 "Intel(R) SSD 910 Series"
186
137#define MPT3SAS_INTEL_RMS3JC080_BRANDING \ 187#define MPT3SAS_INTEL_RMS3JC080_BRANDING \
138 "Intel(R) Integrated RAID Module RMS3JC080" 188 "Intel(R) Integrated RAID Module RMS3JC080"
139#define MPT3SAS_INTEL_RS3GC008_BRANDING \ 189#define MPT3SAS_INTEL_RS3GC008_BRANDING \
@@ -146,33 +196,62 @@
146/* 196/*
147 * Intel HBA SSDIDs 197 * Intel HBA SSDIDs
148 */ 198 */
149#define MPT3SAS_INTEL_RMS3JC080_SSDID 0x3521 199#define MPT2SAS_INTEL_RMS25JB080_SSDID 0x3516
150#define MPT3SAS_INTEL_RS3GC008_SSDID 0x3522 200#define MPT2SAS_INTEL_RMS25JB040_SSDID 0x3517
151#define MPT3SAS_INTEL_RS3FC044_SSDID 0x3523 201#define MPT2SAS_INTEL_RMS25KB080_SSDID 0x3518
152#define MPT3SAS_INTEL_RS3UC080_SSDID 0x3524 202#define MPT2SAS_INTEL_RMS25KB040_SSDID 0x3519
203#define MPT2SAS_INTEL_RMS25LB040_SSDID 0x351A
204#define MPT2SAS_INTEL_RMS25LB080_SSDID 0x351B
205#define MPT2SAS_INTEL_RMS2LL080_SSDID 0x350E
206#define MPT2SAS_INTEL_RMS2LL040_SSDID 0x350F
207#define MPT2SAS_INTEL_RS25GB008_SSDID 0x3000
208#define MPT2SAS_INTEL_SSD910_SSDID 0x3700
209
210#define MPT3SAS_INTEL_RMS3JC080_SSDID 0x3521
211#define MPT3SAS_INTEL_RS3GC008_SSDID 0x3522
212#define MPT3SAS_INTEL_RS3FC044_SSDID 0x3523
213#define MPT3SAS_INTEL_RS3UC080_SSDID 0x3524
153 214
154/* 215/*
155 * Dell HBA branding 216 * Dell HBA branding
156 */ 217 */
218#define MPT2SAS_DELL_BRANDING_SIZE 32
219
220#define MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING "Dell 6Gbps SAS HBA"
221#define MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING "Dell PERC H200 Adapter"
222#define MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING "Dell PERC H200 Integrated"
223#define MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING "Dell PERC H200 Modular"
224#define MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING "Dell PERC H200 Embedded"
225#define MPT2SAS_DELL_PERC_H200_BRANDING "Dell PERC H200"
226#define MPT2SAS_DELL_6GBPS_SAS_BRANDING "Dell 6Gbps SAS"
227
157#define MPT3SAS_DELL_12G_HBA_BRANDING \ 228#define MPT3SAS_DELL_12G_HBA_BRANDING \
158 "Dell 12Gbps HBA" 229 "Dell 12Gbps HBA"
159 230
160/* 231/*
161 * Dell HBA SSDIDs 232 * Dell HBA SSDIDs
162 */ 233 */
163#define MPT3SAS_DELL_12G_HBA_SSDID 0x1F46 234#define MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID 0x1F1C
235#define MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID 0x1F1D
236#define MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID 0x1F1E
237#define MPT2SAS_DELL_PERC_H200_MODULAR_SSDID 0x1F1F
238#define MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID 0x1F20
239#define MPT2SAS_DELL_PERC_H200_SSDID 0x1F21
240#define MPT2SAS_DELL_6GBPS_SAS_SSDID 0x1F22
241
242#define MPT3SAS_DELL_12G_HBA_SSDID 0x1F46
164 243
165/* 244/*
166 * Cisco HBA branding 245 * Cisco HBA branding
167 */ 246 */
168#define MPT3SAS_CISCO_12G_8E_HBA_BRANDING \ 247#define MPT3SAS_CISCO_12G_8E_HBA_BRANDING \
169 "Cisco 9300-8E 12G SAS HBA" 248 "Cisco 9300-8E 12G SAS HBA"
170#define MPT3SAS_CISCO_12G_8I_HBA_BRANDING \ 249#define MPT3SAS_CISCO_12G_8I_HBA_BRANDING \
171 "Cisco 9300-8i 12G SAS HBA" 250 "Cisco 9300-8i 12G SAS HBA"
172#define MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING \ 251#define MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING \
173 "Cisco 12G Modular SAS Pass through Controller" 252 "Cisco 12G Modular SAS Pass through Controller"
174#define MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING \ 253#define MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING \
175 "UCS C3X60 12G SAS Pass through Controller" 254 "UCS C3X60 12G SAS Pass through Controller"
176/* 255/*
177 * Cisco HBA SSSDIDs 256 * Cisco HBA SSSDIDs
178 */ 257 */
@@ -189,6 +268,31 @@
189#define MPT3_DIAG_BUFFER_IS_DIAG_RESET (0x04) 268#define MPT3_DIAG_BUFFER_IS_DIAG_RESET (0x04)
190 269
191/* 270/*
271 * HP HBA branding
272 */
273#define MPT2SAS_HP_3PAR_SSVID 0x1590
274
275#define MPT2SAS_HP_2_4_INTERNAL_BRANDING \
276 "HP H220 Host Bus Adapter"
277#define MPT2SAS_HP_2_4_EXTERNAL_BRANDING \
278 "HP H221 Host Bus Adapter"
279#define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING \
280 "HP H222 Host Bus Adapter"
281#define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING \
282 "HP H220i Host Bus Adapter"
283#define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING \
284 "HP H210i Host Bus Adapter"
285
286/*
287 * HO HBA SSDIDs
288 */
289#define MPT2SAS_HP_2_4_INTERNAL_SSDID 0x0041
290#define MPT2SAS_HP_2_4_EXTERNAL_SSDID 0x0042
291#define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID 0x0043
292#define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID 0x0044
293#define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID 0x0046
294
295/*
192 * Combined Reply Queue constants, 296 * Combined Reply Queue constants,
193 * There are twelve Supplemental Reply Post Host Index Registers 297 * There are twelve Supplemental Reply Post Host Index Registers
194 * and each register is at offset 0x10 bytes from the previous one. 298 * and each register is at offset 0x10 bytes from the previous one.
@@ -243,20 +347,24 @@ struct Mpi2ManufacturingPage11_t {
243 * struct MPT3SAS_TARGET - starget private hostdata 347 * struct MPT3SAS_TARGET - starget private hostdata
244 * @starget: starget object 348 * @starget: starget object
245 * @sas_address: target sas address 349 * @sas_address: target sas address
350 * @raid_device: raid_device pointer to access volume data
246 * @handle: device handle 351 * @handle: device handle
247 * @num_luns: number luns 352 * @num_luns: number luns
248 * @flags: MPT_TARGET_FLAGS_XXX flags 353 * @flags: MPT_TARGET_FLAGS_XXX flags
249 * @deleted: target flaged for deletion 354 * @deleted: target flaged for deletion
250 * @tm_busy: target is busy with TM request. 355 * @tm_busy: target is busy with TM request.
356 * @sdev: The sas_device associated with this target
251 */ 357 */
252struct MPT3SAS_TARGET { 358struct MPT3SAS_TARGET {
253 struct scsi_target *starget; 359 struct scsi_target *starget;
254 u64 sas_address; 360 u64 sas_address;
361 struct _raid_device *raid_device;
255 u16 handle; 362 u16 handle;
256 int num_luns; 363 int num_luns;
257 u32 flags; 364 u32 flags;
258 u8 deleted; 365 u8 deleted;
259 u8 tm_busy; 366 u8 tm_busy;
367 struct _sas_device *sdev;
260}; 368};
261 369
262 370
@@ -266,6 +374,11 @@ struct MPT3SAS_TARGET {
266#define MPT_DEVICE_FLAGS_INIT 0x01 374#define MPT_DEVICE_FLAGS_INIT 0x01
267#define MPT_DEVICE_TLR_ON 0x02 375#define MPT_DEVICE_TLR_ON 0x02
268 376
377#define MFG_PAGE10_HIDE_SSDS_MASK (0x00000003)
378#define MFG_PAGE10_HIDE_ALL_DISKS (0x00)
379#define MFG_PAGE10_EXPOSE_ALL_DISKS (0x01)
380#define MFG_PAGE10_HIDE_IF_VOL_PRESENT (0x02)
381
269/** 382/**
270 * struct MPT3SAS_DEVICE - sdev private hostdata 383 * struct MPT3SAS_DEVICE - sdev private hostdata
271 * @sas_target: starget private hostdata 384 * @sas_target: starget private hostdata
@@ -358,8 +471,24 @@ struct _sas_device {
358 u8 pend_sas_rphy_add; 471 u8 pend_sas_rphy_add;
359 u8 enclosure_level; 472 u8 enclosure_level;
360 u8 connector_name[4]; 473 u8 connector_name[4];
474 struct kref refcount;
361}; 475};
362 476
477static inline void sas_device_get(struct _sas_device *s)
478{
479 kref_get(&s->refcount);
480}
481
482static inline void sas_device_free(struct kref *r)
483{
484 kfree(container_of(r, struct _sas_device, refcount));
485}
486
487static inline void sas_device_put(struct _sas_device *s)
488{
489 kref_put(&s->refcount, sas_device_free);
490}
491
363/** 492/**
364 * struct _raid_device - raid volume link list 493 * struct _raid_device - raid volume link list
365 * @list: sas device list 494 * @list: sas device list
@@ -367,6 +496,7 @@ struct _sas_device {
367 * @sdev: scsi device struct (volumes are single lun) 496 * @sdev: scsi device struct (volumes are single lun)
368 * @wwid: unique identifier for the volume 497 * @wwid: unique identifier for the volume
369 * @handle: device handle 498 * @handle: device handle
499 * @block_size: Block size of the volume
370 * @id: target id 500 * @id: target id
371 * @channel: target channel 501 * @channel: target channel
372 * @volume_type: the raid level 502 * @volume_type: the raid level
@@ -374,6 +504,13 @@ struct _sas_device {
374 * @num_pds: number of hidden raid components 504 * @num_pds: number of hidden raid components
375 * @responding: used in _scsih_raid_device_mark_responding 505 * @responding: used in _scsih_raid_device_mark_responding
376 * @percent_complete: resync percent complete 506 * @percent_complete: resync percent complete
507 * @direct_io_enabled: Whether direct io to PDs are allowed or not
508 * @stripe_exponent: X where 2powX is the stripe sz in blocks
509 * @block_exponent: X where 2powX is the block sz in bytes
510 * @max_lba: Maximum number of LBA in the volume
511 * @stripe_sz: Stripe Size of the volume
512 * @device_info: Device info of the volume member disk
513 * @pd_handle: Array of handles of the physical drives for direct I/O in le16
377 */ 514 */
378#define MPT_MAX_WARPDRIVE_PDS 8 515#define MPT_MAX_WARPDRIVE_PDS 8
379struct _raid_device { 516struct _raid_device {
@@ -382,13 +519,20 @@ struct _raid_device {
382 struct scsi_device *sdev; 519 struct scsi_device *sdev;
383 u64 wwid; 520 u64 wwid;
384 u16 handle; 521 u16 handle;
522 u16 block_sz;
385 int id; 523 int id;
386 int channel; 524 int channel;
387 u8 volume_type; 525 u8 volume_type;
388 u8 num_pds; 526 u8 num_pds;
389 u8 responding; 527 u8 responding;
390 u8 percent_complete; 528 u8 percent_complete;
529 u8 direct_io_enabled;
530 u8 stripe_exponent;
531 u8 block_exponent;
532 u64 max_lba;
533 u32 stripe_sz;
391 u32 device_info; 534 u32 device_info;
535 u16 pd_handle[MPT_MAX_WARPDRIVE_PDS];
392}; 536};
393 537
394/** 538/**
@@ -497,12 +641,14 @@ struct chain_tracker {
497 * @smid: system message id 641 * @smid: system message id
498 * @scmd: scsi request pointer 642 * @scmd: scsi request pointer
499 * @cb_idx: callback index 643 * @cb_idx: callback index
644 * @direct_io: To indicate whether I/O is direct (WARPDRIVE)
500 * @tracker_list: list of free request (ioc->free_list) 645 * @tracker_list: list of free request (ioc->free_list)
501 */ 646 */
502struct scsiio_tracker { 647struct scsiio_tracker {
503 u16 smid; 648 u16 smid;
504 struct scsi_cmnd *scmd; 649 struct scsi_cmnd *scmd;
505 u8 cb_idx; 650 u8 cb_idx;
651 u8 direct_io;
506 struct list_head chain_list; 652 struct list_head chain_list;
507 struct list_head tracker_list; 653 struct list_head tracker_list;
508}; 654};
@@ -775,7 +921,13 @@ typedef void (*MPT3SAS_FLUSH_RUNNING_CMDS)(struct MPT3SAS_ADAPTER *ioc);
775 * @replyPostRegisterIndex: index of next position in Reply Desc Post Queue 921 * @replyPostRegisterIndex: index of next position in Reply Desc Post Queue
776 * @delayed_tr_list: target reset link list 922 * @delayed_tr_list: target reset link list
777 * @delayed_tr_volume_list: volume target reset link list 923 * @delayed_tr_volume_list: volume target reset link list
778 * @@temp_sensors_count: flag to carry the number of temperature sensors 924 * @temp_sensors_count: flag to carry the number of temperature sensors
925 * @pci_access_mutex: Mutex to synchronize ioctl,sysfs show path and
926 * pci resource handling. PCI resource freeing will lead to free
927 * vital hardware/memory resource, which might be in use by cli/sysfs
928 * path functions resulting in Null pointer reference followed by kernel
929 * crash. To avoid the above race condition we use mutex syncrhonization
930 * which ensures the syncrhonization between cli/sysfs_show path.
779 */ 931 */
780struct MPT3SAS_ADAPTER { 932struct MPT3SAS_ADAPTER {
781 struct list_head list; 933 struct list_head list;
@@ -783,6 +935,7 @@ struct MPT3SAS_ADAPTER {
783 u8 id; 935 u8 id;
784 int cpu_count; 936 int cpu_count;
785 char name[MPT_NAME_LENGTH]; 937 char name[MPT_NAME_LENGTH];
938 char driver_name[MPT_NAME_LENGTH];
786 char tmp_string[MPT_STRING_LENGTH]; 939 char tmp_string[MPT_STRING_LENGTH];
787 struct pci_dev *pdev; 940 struct pci_dev *pdev;
788 Mpi2SystemInterfaceRegs_t __iomem *chip; 941 Mpi2SystemInterfaceRegs_t __iomem *chip;
@@ -829,8 +982,10 @@ struct MPT3SAS_ADAPTER {
829 u16 msix_vector_count; 982 u16 msix_vector_count;
830 u8 *cpu_msix_table; 983 u8 *cpu_msix_table;
831 u16 cpu_msix_table_sz; 984 u16 cpu_msix_table_sz;
985 resource_size_t __iomem **reply_post_host_index;
832 u32 ioc_reset_count; 986 u32 ioc_reset_count;
833 MPT3SAS_FLUSH_RUNNING_CMDS schedule_dead_ioc_flush_running_cmds; 987 MPT3SAS_FLUSH_RUNNING_CMDS schedule_dead_ioc_flush_running_cmds;
988 u32 non_operational_loop;
834 989
835 /* internal commands, callback index */ 990 /* internal commands, callback index */
836 u8 scsi_io_cb_idx; 991 u8 scsi_io_cb_idx;
@@ -859,6 +1014,7 @@ struct MPT3SAS_ADAPTER {
859 MPT_BUILD_SG build_sg; 1014 MPT_BUILD_SG build_sg;
860 MPT_BUILD_ZERO_LEN_SGE build_zero_len_sge; 1015 MPT_BUILD_ZERO_LEN_SGE build_zero_len_sge;
861 u16 sge_size_ieee; 1016 u16 sge_size_ieee;
1017 u16 hba_mpi_version_belonged;
862 1018
863 /* function ptr for MPI sg elements only */ 1019 /* function ptr for MPI sg elements only */
864 MPT_BUILD_SG build_sg_mpi; 1020 MPT_BUILD_SG build_sg_mpi;
@@ -987,6 +1143,7 @@ struct MPT3SAS_ADAPTER {
987 struct list_head delayed_tr_list; 1143 struct list_head delayed_tr_list;
988 struct list_head delayed_tr_volume_list; 1144 struct list_head delayed_tr_volume_list;
989 u8 temp_sensors_count; 1145 u8 temp_sensors_count;
1146 struct mutex pci_access_mutex;
990 1147
991 /* diag buffer support */ 1148 /* diag buffer support */
992 u8 *diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT]; 1149 u8 *diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT];
@@ -998,6 +1155,10 @@ struct MPT3SAS_ADAPTER {
998 u32 diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT]; 1155 u32 diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT];
999 u32 ring_buffer_offset; 1156 u32 ring_buffer_offset;
1000 u32 ring_buffer_sz; 1157 u32 ring_buffer_sz;
1158 u8 is_warpdrive;
1159 u8 hide_ir_msg;
1160 u8 mfg_pg10_hide_flag;
1161 u8 hide_drives;
1001 spinlock_t diag_trigger_lock; 1162 spinlock_t diag_trigger_lock;
1002 u8 diag_trigger_active; 1163 u8 diag_trigger_active;
1003 struct SL_WH_MASTER_TRIGGER_T diag_trigger_master; 1164 struct SL_WH_MASTER_TRIGGER_T diag_trigger_master;
@@ -1012,6 +1173,19 @@ typedef u8 (*MPT_CALLBACK)(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1012 1173
1013/* base shared API */ 1174/* base shared API */
1014extern struct list_head mpt3sas_ioc_list; 1175extern struct list_head mpt3sas_ioc_list;
1176extern char driver_name[MPT_NAME_LENGTH];
1177/* spinlock on list operations over IOCs
1178 * Case: when multiple warpdrive cards(IOCs) are in use
1179 * Each IOC will added to the ioc list structure on initialization.
1180 * Watchdog threads run at regular intervals to check IOC for any
1181 * fault conditions which will trigger the dead_ioc thread to
1182 * deallocate pci resource, resulting deleting the IOC netry from list,
1183 * this deletion need to protected by spinlock to enusre that
1184 * ioc removal is syncrhonized, if not synchronized it might lead to
1185 * list_del corruption as the ioc list is traversed in cli path.
1186 */
1187extern spinlock_t gioc_lock;
1188
1015void mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER *ioc); 1189void mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER *ioc);
1016void mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER *ioc); 1190void mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER *ioc);
1017 1191
@@ -1090,10 +1264,14 @@ struct _sas_node *mpt3sas_scsih_expander_find_by_handle(
1090 struct MPT3SAS_ADAPTER *ioc, u16 handle); 1264 struct MPT3SAS_ADAPTER *ioc, u16 handle);
1091struct _sas_node *mpt3sas_scsih_expander_find_by_sas_address( 1265struct _sas_node *mpt3sas_scsih_expander_find_by_sas_address(
1092 struct MPT3SAS_ADAPTER *ioc, u64 sas_address); 1266 struct MPT3SAS_ADAPTER *ioc, u64 sas_address);
1093struct _sas_device *mpt3sas_scsih_sas_device_find_by_sas_address( 1267struct _sas_device *mpt3sas_get_sdev_by_addr(
1094 struct MPT3SAS_ADAPTER *ioc, u64 sas_address); 1268 struct MPT3SAS_ADAPTER *ioc, u64 sas_address);
1269struct _sas_device *__mpt3sas_get_sdev_by_addr(
1270 struct MPT3SAS_ADAPTER *ioc, u64 sas_address);
1095 1271
1096void mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc); 1272void mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc);
1273struct _raid_device *
1274mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle);
1097 1275
1098/* config shared API */ 1276/* config shared API */
1099u8 mpt3sas_config_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, 1277u8 mpt3sas_config_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
@@ -1133,6 +1311,8 @@ int mpt3sas_config_get_sas_iounit_pg0(struct MPT3SAS_ADAPTER *ioc,
1133 u16 sz); 1311 u16 sz);
1134int mpt3sas_config_get_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t 1312int mpt3sas_config_get_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1135 *mpi_reply, Mpi2IOUnitPage1_t *config_page); 1313 *mpi_reply, Mpi2IOUnitPage1_t *config_page);
1314int mpt3sas_config_get_iounit_pg3(struct MPT3SAS_ADAPTER *ioc,
1315 Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz);
1136int mpt3sas_config_set_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t 1316int mpt3sas_config_set_iounit_pg1(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1137 *mpi_reply, Mpi2IOUnitPage1_t *config_page); 1317 *mpi_reply, Mpi2IOUnitPage1_t *config_page);
1138int mpt3sas_config_get_iounit_pg8(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t 1318int mpt3sas_config_get_iounit_pg8(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t
@@ -1177,8 +1357,8 @@ int mpt3sas_config_get_volume_wwid(struct MPT3SAS_ADAPTER *ioc,
1177/* ctl shared API */ 1357/* ctl shared API */
1178extern struct device_attribute *mpt3sas_host_attrs[]; 1358extern struct device_attribute *mpt3sas_host_attrs[];
1179extern struct device_attribute *mpt3sas_dev_attrs[]; 1359extern struct device_attribute *mpt3sas_dev_attrs[];
1180void mpt3sas_ctl_init(void); 1360void mpt3sas_ctl_init(ushort hbas_to_enumerate);
1181void mpt3sas_ctl_exit(void); 1361void mpt3sas_ctl_exit(ushort hbas_to_enumerate);
1182u8 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, 1362u8 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1183 u32 reply); 1363 u32 reply);
1184void mpt3sas_ctl_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase); 1364void mpt3sas_ctl_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase);
@@ -1193,6 +1373,7 @@ int mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type,
1193 u8 *issue_reset); 1373 u8 *issue_reset);
1194 1374
1195/* transport shared API */ 1375/* transport shared API */
1376extern struct scsi_transport_template *mpt3sas_transport_template;
1196u8 mpt3sas_transport_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, 1377u8 mpt3sas_transport_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1197 u32 reply); 1378 u32 reply);
1198struct _sas_port *mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, 1379struct _sas_port *mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc,
@@ -1224,4 +1405,18 @@ void mpt3sas_trigger_scsi(struct MPT3SAS_ADAPTER *ioc, u8 sense_key,
1224 u8 asc, u8 ascq); 1405 u8 asc, u8 ascq);
1225void mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status, 1406void mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status,
1226 u32 loginfo); 1407 u32 loginfo);
1408
1409/* warpdrive APIs */
1410u8 mpt3sas_get_num_volumes(struct MPT3SAS_ADAPTER *ioc);
1411void mpt3sas_init_warpdrive_properties(struct MPT3SAS_ADAPTER *ioc,
1412 struct _raid_device *raid_device);
1413inline u8
1414mpt3sas_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid);
1415inline void
1416mpt3sas_scsi_direct_io_set(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 direct_io);
1417void
1418mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
1419 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
1420 u16 smid);
1421
1227#endif /* MPT3SAS_BASE_H_INCLUDED */ 1422#endif /* MPT3SAS_BASE_H_INCLUDED */
diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
index e45c4613ef0c..a6914ec99cc0 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_config.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
@@ -83,7 +83,6 @@ struct config_request {
83 dma_addr_t page_dma; 83 dma_addr_t page_dma;
84}; 84};
85 85
86#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
87/** 86/**
88 * _config_display_some_debug - debug routine 87 * _config_display_some_debug - debug routine
89 * @ioc: per adapter object 88 * @ioc: per adapter object
@@ -173,7 +172,6 @@ _config_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid,
173 ioc->name, le16_to_cpu(mpi_reply->IOCStatus), 172 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
174 le32_to_cpu(mpi_reply->IOCLogInfo)); 173 le32_to_cpu(mpi_reply->IOCLogInfo));
175} 174}
176#endif
177 175
178/** 176/**
179 * _config_alloc_config_dma_memory - obtain physical memory 177 * _config_alloc_config_dma_memory - obtain physical memory
@@ -255,9 +253,7 @@ mpt3sas_config_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
255 mpi_reply->MsgLength*4); 253 mpi_reply->MsgLength*4);
256 } 254 }
257 ioc->config_cmds.status &= ~MPT3_CMD_PENDING; 255 ioc->config_cmds.status &= ~MPT3_CMD_PENDING;
258#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
259 _config_display_some_debug(ioc, smid, "config_done", mpi_reply); 256 _config_display_some_debug(ioc, smid, "config_done", mpi_reply);
260#endif
261 ioc->config_cmds.smid = USHRT_MAX; 257 ioc->config_cmds.smid = USHRT_MAX;
262 complete(&ioc->config_cmds.done); 258 complete(&ioc->config_cmds.done);
263 return 1; 259 return 1;
@@ -387,9 +383,7 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
387 config_request = mpt3sas_base_get_msg_frame(ioc, smid); 383 config_request = mpt3sas_base_get_msg_frame(ioc, smid);
388 ioc->config_cmds.smid = smid; 384 ioc->config_cmds.smid = smid;
389 memcpy(config_request, mpi_request, sizeof(Mpi2ConfigRequest_t)); 385 memcpy(config_request, mpi_request, sizeof(Mpi2ConfigRequest_t));
390#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
391 _config_display_some_debug(ioc, smid, "config_request", NULL); 386 _config_display_some_debug(ioc, smid, "config_request", NULL);
392#endif
393 init_completion(&ioc->config_cmds.done); 387 init_completion(&ioc->config_cmds.done);
394 mpt3sas_base_put_smid_default(ioc, smid); 388 mpt3sas_base_put_smid_default(ioc, smid);
395 timeleft = wait_for_completion_timeout(&ioc->config_cmds.done, 389 timeleft = wait_for_completion_timeout(&ioc->config_cmds.done,
@@ -872,6 +866,42 @@ mpt3sas_config_set_iounit_pg1(struct MPT3SAS_ADAPTER *ioc,
872} 866}
873 867
874/** 868/**
869 * mpt3sas_config_get_iounit_pg3 - obtain iounit page 3
870 * @ioc: per adapter object
871 * @mpi_reply: reply mf payload returned from firmware
872 * @config_page: contents of the config page
873 * @sz: size of buffer passed in config_page
874 * Context: sleep.
875 *
876 * Returns 0 for success, non-zero for failure.
877 */
878int
879mpt3sas_config_get_iounit_pg3(struct MPT3SAS_ADAPTER *ioc,
880 Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz)
881{
882 Mpi2ConfigRequest_t mpi_request;
883 int r;
884
885 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
886 mpi_request.Function = MPI2_FUNCTION_CONFIG;
887 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
888 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT;
889 mpi_request.Header.PageNumber = 3;
890 mpi_request.Header.PageVersion = MPI2_IOUNITPAGE3_PAGEVERSION;
891 ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
892 r = _config_request(ioc, &mpi_request, mpi_reply,
893 MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
894 if (r)
895 goto out;
896
897 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
898 r = _config_request(ioc, &mpi_request, mpi_reply,
899 MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
900 out:
901 return r;
902}
903
904/**
875 * mpt3sas_config_get_iounit_pg8 - obtain iounit page 8 905 * mpt3sas_config_get_iounit_pg8 - obtain iounit page 8
876 * @ioc: per adapter object 906 * @ioc: per adapter object
877 * @mpi_reply: reply mf payload returned from firmware 907 * @mpi_reply: reply mf payload returned from firmware
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 080c8a76d23d..d8366b056b70 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -78,7 +78,6 @@ enum block_state {
78 BLOCKING, 78 BLOCKING,
79}; 79};
80 80
81#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
82/** 81/**
83 * _ctl_sas_device_find_by_handle - sas device search 82 * _ctl_sas_device_find_by_handle - sas device search
84 * @ioc: per adapter object 83 * @ioc: per adapter object
@@ -254,8 +253,6 @@ _ctl_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid,
254 } 253 }
255} 254}
256 255
257#endif
258
259/** 256/**
260 * mpt3sas_ctl_done - ctl module completion routine 257 * mpt3sas_ctl_done - ctl module completion routine
261 * @ioc: per adapter object 258 * @ioc: per adapter object
@@ -302,9 +299,7 @@ mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
302 } 299 }
303 } 300 }
304 } 301 }
305#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
306 _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply); 302 _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply);
307#endif
308 ioc->ctl_cmds.status &= ~MPT3_CMD_PENDING; 303 ioc->ctl_cmds.status &= ~MPT3_CMD_PENDING;
309 complete(&ioc->ctl_cmds.done); 304 complete(&ioc->ctl_cmds.done);
310 return 1; 305 return 1;
@@ -414,20 +409,31 @@ mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
414 * _ctl_verify_adapter - validates ioc_number passed from application 409 * _ctl_verify_adapter - validates ioc_number passed from application
415 * @ioc: per adapter object 410 * @ioc: per adapter object
416 * @iocpp: The ioc pointer is returned in this. 411 * @iocpp: The ioc pointer is returned in this.
412 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
413 * MPI25_VERSION for mpt3ctl ioctl device.
417 * 414 *
418 * Return (-1) means error, else ioc_number. 415 * Return (-1) means error, else ioc_number.
419 */ 416 */
420static int 417static int
421_ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp) 418_ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp,
419 int mpi_version)
422{ 420{
423 struct MPT3SAS_ADAPTER *ioc; 421 struct MPT3SAS_ADAPTER *ioc;
424 422 /* global ioc lock to protect controller on list operations */
423 spin_lock(&gioc_lock);
425 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { 424 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
426 if (ioc->id != ioc_number) 425 if (ioc->id != ioc_number)
427 continue; 426 continue;
427 /* Check whether this ioctl command is from right
428 * ioctl device or not, if not continue the search.
429 */
430 if (ioc->hba_mpi_version_belonged != mpi_version)
431 continue;
432 spin_unlock(&gioc_lock);
428 *iocpp = ioc; 433 *iocpp = ioc;
429 return ioc_number; 434 return ioc_number;
430 } 435 }
436 spin_unlock(&gioc_lock);
431 *iocpp = NULL; 437 *iocpp = NULL;
432 return -1; 438 return -1;
433} 439}
@@ -497,7 +503,7 @@ mpt3sas_ctl_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
497 * 503 *
498 * Called when application request fasyn callback handler. 504 * Called when application request fasyn callback handler.
499 */ 505 */
500static int 506int
501_ctl_fasync(int fd, struct file *filep, int mode) 507_ctl_fasync(int fd, struct file *filep, int mode)
502{ 508{
503 return fasync_helper(fd, filep, mode, &async_queue); 509 return fasync_helper(fd, filep, mode, &async_queue);
@@ -509,17 +515,22 @@ _ctl_fasync(int fd, struct file *filep, int mode)
509 * @wait - 515 * @wait -
510 * 516 *
511 */ 517 */
512static unsigned int 518unsigned int
513_ctl_poll(struct file *filep, poll_table *wait) 519_ctl_poll(struct file *filep, poll_table *wait)
514{ 520{
515 struct MPT3SAS_ADAPTER *ioc; 521 struct MPT3SAS_ADAPTER *ioc;
516 522
517 poll_wait(filep, &ctl_poll_wait, wait); 523 poll_wait(filep, &ctl_poll_wait, wait);
518 524
525 /* global ioc lock to protect controller on list operations */
526 spin_lock(&gioc_lock);
519 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { 527 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
520 if (ioc->aen_event_read_flag) 528 if (ioc->aen_event_read_flag) {
529 spin_unlock(&gioc_lock);
521 return POLLIN | POLLRDNORM; 530 return POLLIN | POLLRDNORM;
531 }
522 } 532 }
533 spin_unlock(&gioc_lock);
523 return 0; 534 return 0;
524} 535}
525 536
@@ -759,9 +770,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
759 psge = (void *)request + (karg.data_sge_offset*4); 770 psge = (void *)request + (karg.data_sge_offset*4);
760 771
761 /* send command to firmware */ 772 /* send command to firmware */
762#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
763 _ctl_display_some_debug(ioc, smid, "ctl_request", NULL); 773 _ctl_display_some_debug(ioc, smid, "ctl_request", NULL);
764#endif
765 774
766 init_completion(&ioc->ctl_cmds.done); 775 init_completion(&ioc->ctl_cmds.done);
767 switch (mpi_request->Function) { 776 switch (mpi_request->Function) {
@@ -916,7 +925,6 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
916 mpi_reply = ioc->ctl_cmds.reply; 925 mpi_reply = ioc->ctl_cmds.reply;
917 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; 926 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
918 927
919#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
920 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT && 928 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT &&
921 (ioc->logging_level & MPT_DEBUG_TM)) { 929 (ioc->logging_level & MPT_DEBUG_TM)) {
922 Mpi2SCSITaskManagementReply_t *tm_reply = 930 Mpi2SCSITaskManagementReply_t *tm_reply =
@@ -929,7 +937,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
929 le32_to_cpu(tm_reply->IOCLogInfo), 937 le32_to_cpu(tm_reply->IOCLogInfo),
930 le32_to_cpu(tm_reply->TerminationCount)); 938 le32_to_cpu(tm_reply->TerminationCount));
931 } 939 }
932#endif 940
933 /* copy out xdata to user */ 941 /* copy out xdata to user */
934 if (data_in_sz) { 942 if (data_in_sz) {
935 if (copy_to_user(karg.data_in_buf_ptr, data_in, 943 if (copy_to_user(karg.data_in_buf_ptr, data_in,
@@ -1023,7 +1031,6 @@ _ctl_getiocinfo(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1023 __func__)); 1031 __func__));
1024 1032
1025 memset(&karg, 0 , sizeof(karg)); 1033 memset(&karg, 0 , sizeof(karg));
1026 karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS3;
1027 if (ioc->pfacts) 1034 if (ioc->pfacts)
1028 karg.port_number = ioc->pfacts[0].PortNumber; 1035 karg.port_number = ioc->pfacts[0].PortNumber;
1029 karg.hw_rev = ioc->pdev->revision; 1036 karg.hw_rev = ioc->pdev->revision;
@@ -1035,9 +1042,21 @@ _ctl_getiocinfo(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1035 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn); 1042 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
1036 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus); 1043 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
1037 karg.firmware_version = ioc->facts.FWVersion.Word; 1044 karg.firmware_version = ioc->facts.FWVersion.Word;
1038 strcpy(karg.driver_version, MPT3SAS_DRIVER_NAME); 1045 strcpy(karg.driver_version, ioc->driver_name);
1039 strcat(karg.driver_version, "-"); 1046 strcat(karg.driver_version, "-");
1040 strcat(karg.driver_version, MPT3SAS_DRIVER_VERSION); 1047 switch (ioc->hba_mpi_version_belonged) {
1048 case MPI2_VERSION:
1049 if (ioc->is_warpdrive)
1050 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2_SSS6200;
1051 else
1052 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2;
1053 strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION);
1054 break;
1055 case MPI25_VERSION:
1056 karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS3;
1057 strcat(karg.driver_version, MPT3SAS_DRIVER_VERSION);
1058 break;
1059 }
1041 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); 1060 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
1042 1061
1043 if (copy_to_user(arg, &karg, sizeof(karg))) { 1062 if (copy_to_user(arg, &karg, sizeof(karg))) {
@@ -2181,12 +2200,14 @@ _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER *ioc, unsigned cmd,
2181 * _ctl_ioctl_main - main ioctl entry point 2200 * _ctl_ioctl_main - main ioctl entry point
2182 * @file - (struct file) 2201 * @file - (struct file)
2183 * @cmd - ioctl opcode 2202 * @cmd - ioctl opcode
2184 * @arg - 2203 * @arg - user space data buffer
2185 * compat - handles 32 bit applications in 64bit os 2204 * @compat - handles 32 bit applications in 64bit os
2205 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
2206 * MPI25_VERSION for mpt3ctl ioctl device.
2186 */ 2207 */
2187static long 2208static long
2188_ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg, 2209_ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
2189 u8 compat) 2210 u8 compat, u16 mpi_version)
2190{ 2211{
2191 struct MPT3SAS_ADAPTER *ioc; 2212 struct MPT3SAS_ADAPTER *ioc;
2192 struct mpt3_ioctl_header ioctl_header; 2213 struct mpt3_ioctl_header ioctl_header;
@@ -2201,19 +2222,29 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
2201 return -EFAULT; 2222 return -EFAULT;
2202 } 2223 }
2203 2224
2204 if (_ctl_verify_adapter(ioctl_header.ioc_number, &ioc) == -1 || !ioc) 2225 if (_ctl_verify_adapter(ioctl_header.ioc_number,
2226 &ioc, mpi_version) == -1 || !ioc)
2205 return -ENODEV; 2227 return -ENODEV;
2206 2228
2229 /* pci_access_mutex lock acquired by ioctl path */
2230 mutex_lock(&ioc->pci_access_mutex);
2231
2207 if (ioc->shost_recovery || ioc->pci_error_recovery || 2232 if (ioc->shost_recovery || ioc->pci_error_recovery ||
2208 ioc->is_driver_loading) 2233 ioc->is_driver_loading || ioc->remove_host) {
2209 return -EAGAIN; 2234 ret = -EAGAIN;
2235 goto out_unlock_pciaccess;
2236 }
2210 2237
2211 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING; 2238 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
2212 if (state == NON_BLOCKING) { 2239 if (state == NON_BLOCKING) {
2213 if (!mutex_trylock(&ioc->ctl_cmds.mutex)) 2240 if (!mutex_trylock(&ioc->ctl_cmds.mutex)) {
2214 return -EAGAIN; 2241 ret = -EAGAIN;
2215 } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) 2242 goto out_unlock_pciaccess;
2216 return -ERESTARTSYS; 2243 }
2244 } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) {
2245 ret = -ERESTARTSYS;
2246 goto out_unlock_pciaccess;
2247 }
2217 2248
2218 2249
2219 switch (cmd) { 2250 switch (cmd) {
@@ -2294,39 +2325,78 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
2294 } 2325 }
2295 2326
2296 mutex_unlock(&ioc->ctl_cmds.mutex); 2327 mutex_unlock(&ioc->ctl_cmds.mutex);
2328out_unlock_pciaccess:
2329 mutex_unlock(&ioc->pci_access_mutex);
2297 return ret; 2330 return ret;
2298} 2331}
2299 2332
2300/** 2333/**
2301 * _ctl_ioctl - main ioctl entry point (unlocked) 2334 * _ctl_ioctl - mpt3ctl main ioctl entry point (unlocked)
2302 * @file - (struct file) 2335 * @file - (struct file)
2303 * @cmd - ioctl opcode 2336 * @cmd - ioctl opcode
2304 * @arg - 2337 * @arg -
2305 */ 2338 */
2306static long 2339long
2307_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 2340_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2308{ 2341{
2309 long ret; 2342 long ret;
2310 2343
2311 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0); 2344 /* pass MPI25_VERSION value, to indicate that this ioctl cmd
2345 * came from mpt3ctl ioctl device.
2346 */
2347 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0, MPI25_VERSION);
2312 return ret; 2348 return ret;
2313} 2349}
2314 2350
2351/**
2352 * _ctl_mpt2_ioctl - mpt2ctl main ioctl entry point (unlocked)
2353 * @file - (struct file)
2354 * @cmd - ioctl opcode
2355 * @arg -
2356 */
2357long
2358_ctl_mpt2_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2359{
2360 long ret;
2361
2362 /* pass MPI2_VERSION value, to indicate that this ioctl cmd
2363 * came from mpt2ctl ioctl device.
2364 */
2365 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0, MPI2_VERSION);
2366 return ret;
2367}
2315#ifdef CONFIG_COMPAT 2368#ifdef CONFIG_COMPAT
2316/** 2369/**
2317 * _ctl_ioctl_compat - main ioctl entry point (compat) 2370 *_ ctl_ioctl_compat - main ioctl entry point (compat)
2318 * @file - 2371 * @file -
2319 * @cmd - 2372 * @cmd -
2320 * @arg - 2373 * @arg -
2321 * 2374 *
2322 * This routine handles 32 bit applications in 64bit os. 2375 * This routine handles 32 bit applications in 64bit os.
2323 */ 2376 */
2324static long 2377long
2325_ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg) 2378_ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2326{ 2379{
2327 long ret; 2380 long ret;
2328 2381
2329 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1); 2382 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1, MPI25_VERSION);
2383 return ret;
2384}
2385
2386/**
2387 *_ ctl_mpt2_ioctl_compat - main ioctl entry point (compat)
2388 * @file -
2389 * @cmd -
2390 * @arg -
2391 *
2392 * This routine handles 32 bit applications in 64bit os.
2393 */
2394long
2395_ctl_mpt2_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2396{
2397 long ret;
2398
2399 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1, MPI2_VERSION);
2330 return ret; 2400 return ret;
2331} 2401}
2332#endif 2402#endif
@@ -2713,6 +2783,82 @@ _ctl_ioc_reply_queue_count_show(struct device *cdev,
2713static DEVICE_ATTR(reply_queue_count, S_IRUGO, _ctl_ioc_reply_queue_count_show, 2783static DEVICE_ATTR(reply_queue_count, S_IRUGO, _ctl_ioc_reply_queue_count_show,
2714 NULL); 2784 NULL);
2715 2785
2786/**
2787 * _ctl_BRM_status_show - Backup Rail Monitor Status
2788 * @cdev - pointer to embedded class device
2789 * @buf - the buffer returned
2790 *
2791 * This is number of reply queues
2792 *
2793 * A sysfs 'read-only' shost attribute.
2794 */
2795static ssize_t
2796_ctl_BRM_status_show(struct device *cdev, struct device_attribute *attr,
2797 char *buf)
2798{
2799 struct Scsi_Host *shost = class_to_shost(cdev);
2800 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2801 Mpi2IOUnitPage3_t *io_unit_pg3 = NULL;
2802 Mpi2ConfigReply_t mpi_reply;
2803 u16 backup_rail_monitor_status = 0;
2804 u16 ioc_status;
2805 int sz;
2806 ssize_t rc = 0;
2807
2808 if (!ioc->is_warpdrive) {
2809 pr_err(MPT3SAS_FMT "%s: BRM attribute is only for"
2810 " warpdrive\n", ioc->name, __func__);
2811 goto out;
2812 }
2813 /* pci_access_mutex lock acquired by sysfs show path */
2814 mutex_lock(&ioc->pci_access_mutex);
2815 if (ioc->pci_error_recovery || ioc->remove_host) {
2816 mutex_unlock(&ioc->pci_access_mutex);
2817 return 0;
2818 }
2819
2820 /* allocate upto GPIOVal 36 entries */
2821 sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
2822 io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
2823 if (!io_unit_pg3) {
2824 pr_err(MPT3SAS_FMT "%s: failed allocating memory "
2825 "for iounit_pg3: (%d) bytes\n", ioc->name, __func__, sz);
2826 goto out;
2827 }
2828
2829 if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
2830 0) {
2831 pr_err(MPT3SAS_FMT
2832 "%s: failed reading iounit_pg3\n", ioc->name,
2833 __func__);
2834 goto out;
2835 }
2836
2837 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
2838 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2839 pr_err(MPT3SAS_FMT "%s: iounit_pg3 failed with "
2840 "ioc_status(0x%04x)\n", ioc->name, __func__, ioc_status);
2841 goto out;
2842 }
2843
2844 if (io_unit_pg3->GPIOCount < 25) {
2845 pr_err(MPT3SAS_FMT "%s: iounit_pg3->GPIOCount less than "
2846 "25 entries, detected (%d) entries\n", ioc->name, __func__,
2847 io_unit_pg3->GPIOCount);
2848 goto out;
2849 }
2850
2851 /* BRM status is in bit zero of GPIOVal[24] */
2852 backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]);
2853 rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1));
2854
2855 out:
2856 kfree(io_unit_pg3);
2857 mutex_unlock(&ioc->pci_access_mutex);
2858 return rc;
2859}
2860static DEVICE_ATTR(BRM_status, S_IRUGO, _ctl_BRM_status_show, NULL);
2861
2716struct DIAG_BUFFER_START { 2862struct DIAG_BUFFER_START {
2717 __le32 Size; 2863 __le32 Size;
2718 __le32 DiagVersion; 2864 __le32 DiagVersion;
@@ -3165,6 +3311,7 @@ struct device_attribute *mpt3sas_host_attrs[] = {
3165 &dev_attr_diag_trigger_event, 3311 &dev_attr_diag_trigger_event,
3166 &dev_attr_diag_trigger_scsi, 3312 &dev_attr_diag_trigger_scsi,
3167 &dev_attr_diag_trigger_mpi, 3313 &dev_attr_diag_trigger_mpi,
3314 &dev_attr_BRM_status,
3168 NULL, 3315 NULL,
3169}; 3316};
3170 3317
@@ -3218,6 +3365,7 @@ struct device_attribute *mpt3sas_dev_attrs[] = {
3218 NULL, 3365 NULL,
3219}; 3366};
3220 3367
3368/* file operations table for mpt3ctl device */
3221static const struct file_operations ctl_fops = { 3369static const struct file_operations ctl_fops = {
3222 .owner = THIS_MODULE, 3370 .owner = THIS_MODULE,
3223 .unlocked_ioctl = _ctl_ioctl, 3371 .unlocked_ioctl = _ctl_ioctl,
@@ -3228,23 +3376,53 @@ static const struct file_operations ctl_fops = {
3228#endif 3376#endif
3229}; 3377};
3230 3378
3379/* file operations table for mpt2ctl device */
3380static const struct file_operations ctl_gen2_fops = {
3381 .owner = THIS_MODULE,
3382 .unlocked_ioctl = _ctl_mpt2_ioctl,
3383 .poll = _ctl_poll,
3384 .fasync = _ctl_fasync,
3385#ifdef CONFIG_COMPAT
3386 .compat_ioctl = _ctl_mpt2_ioctl_compat,
3387#endif
3388};
3389
3231static struct miscdevice ctl_dev = { 3390static struct miscdevice ctl_dev = {
3232 .minor = MPT3SAS_MINOR, 3391 .minor = MPT3SAS_MINOR,
3233 .name = MPT3SAS_DEV_NAME, 3392 .name = MPT3SAS_DEV_NAME,
3234 .fops = &ctl_fops, 3393 .fops = &ctl_fops,
3235}; 3394};
3236 3395
3396static struct miscdevice gen2_ctl_dev = {
3397 .minor = MPT2SAS_MINOR,
3398 .name = MPT2SAS_DEV_NAME,
3399 .fops = &ctl_gen2_fops,
3400};
3401
3237/** 3402/**
3238 * mpt3sas_ctl_init - main entry point for ctl. 3403 * mpt3sas_ctl_init - main entry point for ctl.
3239 * 3404 *
3240 */ 3405 */
3241void 3406void
3242mpt3sas_ctl_init(void) 3407mpt3sas_ctl_init(ushort hbas_to_enumerate)
3243{ 3408{
3244 async_queue = NULL; 3409 async_queue = NULL;
3245 if (misc_register(&ctl_dev) < 0) 3410
3246 pr_err("%s can't register misc device [minor=%d]\n", 3411 /* Don't register mpt3ctl ioctl device if
3247 MPT3SAS_DRIVER_NAME, MPT3SAS_MINOR); 3412 * hbas_to_enumarate is one.
3413 */
3414 if (hbas_to_enumerate != 1)
3415 if (misc_register(&ctl_dev) < 0)
3416 pr_err("%s can't register misc device [minor=%d]\n",
3417 MPT3SAS_DRIVER_NAME, MPT3SAS_MINOR);
3418
3419 /* Don't register mpt3ctl ioctl device if
3420 * hbas_to_enumarate is two.
3421 */
3422 if (hbas_to_enumerate != 2)
3423 if (misc_register(&gen2_ctl_dev) < 0)
3424 pr_err("%s can't register misc device [minor=%d]\n",
3425 MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR);
3248 3426
3249 init_waitqueue_head(&ctl_poll_wait); 3427 init_waitqueue_head(&ctl_poll_wait);
3250} 3428}
@@ -3254,7 +3432,7 @@ mpt3sas_ctl_init(void)
3254 * 3432 *
3255 */ 3433 */
3256void 3434void
3257mpt3sas_ctl_exit(void) 3435mpt3sas_ctl_exit(ushort hbas_to_enumerate)
3258{ 3436{
3259 struct MPT3SAS_ADAPTER *ioc; 3437 struct MPT3SAS_ADAPTER *ioc;
3260 int i; 3438 int i;
@@ -3279,5 +3457,8 @@ mpt3sas_ctl_exit(void)
3279 3457
3280 kfree(ioc->event_log); 3458 kfree(ioc->event_log);
3281 } 3459 }
3282 misc_deregister(&ctl_dev); 3460 if (hbas_to_enumerate != 1)
3461 misc_deregister(&ctl_dev);
3462 if (hbas_to_enumerate != 2)
3463 misc_deregister(&gen2_ctl_dev);
3283} 3464}
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.h b/drivers/scsi/mpt3sas/mpt3sas_ctl.h
index aee99ce67e54..89408356d252 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.h
@@ -50,10 +50,13 @@
50#include <linux/miscdevice.h> 50#include <linux/miscdevice.h>
51#endif 51#endif
52 52
53 53#ifndef MPT2SAS_MINOR
54#define MPT2SAS_MINOR (MPT_MINOR + 1)
55#endif
54#ifndef MPT3SAS_MINOR 56#ifndef MPT3SAS_MINOR
55#define MPT3SAS_MINOR (MPT_MINOR + 2) 57#define MPT3SAS_MINOR (MPT_MINOR + 2)
56#endif 58#endif
59#define MPT2SAS_DEV_NAME "mpt2ctl"
57#define MPT3SAS_DEV_NAME "mpt3ctl" 60#define MPT3SAS_DEV_NAME "mpt3ctl"
58#define MPT3_MAGIC_NUMBER 'L' 61#define MPT3_MAGIC_NUMBER 'L'
59#define MPT3_IOCTL_DEFAULT_TIMEOUT (10) /* in seconds */ 62#define MPT3_IOCTL_DEFAULT_TIMEOUT (10) /* in seconds */
@@ -138,6 +141,7 @@ struct mpt3_ioctl_pci_info {
138#define MPT2_IOCTL_INTERFACE_FC_IP (0x02) 141#define MPT2_IOCTL_INTERFACE_FC_IP (0x02)
139#define MPT2_IOCTL_INTERFACE_SAS (0x03) 142#define MPT2_IOCTL_INTERFACE_SAS (0x03)
140#define MPT2_IOCTL_INTERFACE_SAS2 (0x04) 143#define MPT2_IOCTL_INTERFACE_SAS2 (0x04)
144#define MPT2_IOCTL_INTERFACE_SAS2_SSS6200 (0x05)
141#define MPT3_IOCTL_INTERFACE_SAS3 (0x06) 145#define MPT3_IOCTL_INTERFACE_SAS3 (0x06)
142#define MPT2_IOCTL_VERSION_LENGTH (32) 146#define MPT2_IOCTL_VERSION_LENGTH (32)
143 147
diff --git a/drivers/scsi/mpt3sas/mpt3sas_debug.h b/drivers/scsi/mpt3sas/mpt3sas_debug.h
index 4e8a63fdb304..cceeb2c16e64 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_debug.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_debug.h
@@ -68,20 +68,11 @@
68#define MPT_DEBUG_TRIGGER_DIAG 0x00200000 68#define MPT_DEBUG_TRIGGER_DIAG 0x00200000
69 69
70 70
71/*
72 * CONFIG_SCSI_MPT3SAS_LOGGING - enabled in Kconfig
73 */
74
75#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
76#define MPT_CHECK_LOGGING(IOC, CMD, BITS) \ 71#define MPT_CHECK_LOGGING(IOC, CMD, BITS) \
77{ \ 72{ \
78 if (IOC->logging_level & BITS) \ 73 if (IOC->logging_level & BITS) \
79 CMD; \ 74 CMD; \
80} 75}
81#else
82#define MPT_CHECK_LOGGING(IOC, CMD, BITS)
83#endif /* CONFIG_SCSI_MPT3SAS_LOGGING */
84
85 76
86/* 77/*
87 * debug macros 78 * debug macros
@@ -153,7 +144,7 @@
153 144
154 145
155/* inline functions for dumping debug data*/ 146/* inline functions for dumping debug data*/
156#ifdef CONFIG_SCSI_MPT3SAS_LOGGING 147
157/** 148/**
158 * _debug_dump_mf - print message frame contents 149 * _debug_dump_mf - print message frame contents
159 * @mpi_request: pointer to message frame 150 * @mpi_request: pointer to message frame
@@ -211,10 +202,5 @@ _debug_dump_config(void *mpi_request, int sz)
211 } 202 }
212 pr_info("\n"); 203 pr_info("\n");
213} 204}
214#else
215#define _debug_dump_mf(mpi_request, sz)
216#define _debug_dump_reply(mpi_request, sz)
217#define _debug_dump_config(mpi_request, sz)
218#endif /* CONFIG_SCSI_MPT3SAS_LOGGING */
219 205
220#endif /* MPT3SAS_DEBUG_H_INCLUDED */ 206#endif /* MPT3SAS_DEBUG_H_INCLUDED */
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 8ccef38523fa..d95206b7e116 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -54,14 +54,10 @@
54#include <linux/interrupt.h> 54#include <linux/interrupt.h>
55#include <linux/aer.h> 55#include <linux/aer.h>
56#include <linux/raid_class.h> 56#include <linux/raid_class.h>
57#include <asm/unaligned.h>
57 58
58#include "mpt3sas_base.h" 59#include "mpt3sas_base.h"
59 60
60MODULE_AUTHOR(MPT3SAS_AUTHOR);
61MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
62MODULE_LICENSE("GPL");
63MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
64
65#define RAID_CHANNEL 1 61#define RAID_CHANNEL 1
66/* forward proto's */ 62/* forward proto's */
67static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, 63static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
@@ -75,11 +71,16 @@ static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
75 71
76static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); 72static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
77 73
78static void _scsih_scan_start(struct Scsi_Host *shost);
79static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
80
81/* global parameters */ 74/* global parameters */
82LIST_HEAD(mpt3sas_ioc_list); 75LIST_HEAD(mpt3sas_ioc_list);
76/* global ioc lock for list operations */
77DEFINE_SPINLOCK(gioc_lock);
78
79MODULE_AUTHOR(MPT3SAS_AUTHOR);
80MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
81MODULE_LICENSE("GPL");
82MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
83MODULE_ALIAS("mpt2sas");
83 84
84/* local parameters */ 85/* local parameters */
85static u8 scsi_io_cb_idx = -1; 86static u8 scsi_io_cb_idx = -1;
@@ -90,7 +91,8 @@ static u8 port_enable_cb_idx = -1;
90static u8 transport_cb_idx = -1; 91static u8 transport_cb_idx = -1;
91static u8 scsih_cb_idx = -1; 92static u8 scsih_cb_idx = -1;
92static u8 config_cb_idx = -1; 93static u8 config_cb_idx = -1;
93static int mpt_ids; 94static int mpt2_ids;
95static int mpt3_ids;
94 96
95static u8 tm_tr_cb_idx = -1 ; 97static u8 tm_tr_cb_idx = -1 ;
96static u8 tm_tr_volume_cb_idx = -1 ; 98static u8 tm_tr_volume_cb_idx = -1 ;
@@ -117,8 +119,12 @@ static u64 max_lun = MPT3SAS_MAX_LUN;
117module_param(max_lun, ullong, 0); 119module_param(max_lun, ullong, 0);
118MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); 120MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
119 121
120 122static ushort hbas_to_enumerate;
121 123module_param(hbas_to_enumerate, ushort, 0);
124MODULE_PARM_DESC(hbas_to_enumerate,
125 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
126 1 - enumerates only SAS 2.0 generation HBAs\n \
127 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
122 128
123/* diag_buffer_enable is bitwise 129/* diag_buffer_enable is bitwise
124 * bit 0 set = TRACE 130 * bit 0 set = TRACE
@@ -143,8 +149,8 @@ MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
143 149
144 150
145/* raid transport support */ 151/* raid transport support */
146 152struct raid_template *mpt3sas_raid_template;
147static struct raid_template *mpt3sas_raid_template; 153struct raid_template *mpt2sas_raid_template;
148 154
149 155
150/** 156/**
@@ -191,11 +197,36 @@ struct fw_event_work {
191 u8 VP_ID; 197 u8 VP_ID;
192 u8 ignore; 198 u8 ignore;
193 u16 event; 199 u16 event;
200 struct kref refcount;
194 char event_data[0] __aligned(4); 201 char event_data[0] __aligned(4);
195}; 202};
196 203
197/* raid transport support */ 204static void fw_event_work_free(struct kref *r)
198static struct raid_template *mpt3sas_raid_template; 205{
206 kfree(container_of(r, struct fw_event_work, refcount));
207}
208
209static void fw_event_work_get(struct fw_event_work *fw_work)
210{
211 kref_get(&fw_work->refcount);
212}
213
214static void fw_event_work_put(struct fw_event_work *fw_work)
215{
216 kref_put(&fw_work->refcount, fw_event_work_free);
217}
218
219static struct fw_event_work *alloc_fw_event_work(int len)
220{
221 struct fw_event_work *fw_event;
222
223 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
224 if (!fw_event)
225 return NULL;
226
227 kref_init(&fw_event->refcount);
228 return fw_event;
229}
199 230
200/** 231/**
201 * struct _scsi_io_transfer - scsi io transfer 232 * struct _scsi_io_transfer - scsi io transfer
@@ -245,28 +276,6 @@ struct _scsi_io_transfer {
245 u32 transfer_length; 276 u32 transfer_length;
246}; 277};
247 278
248/*
249 * The pci device ids are defined in mpi/mpi2_cnfg.h.
250 */
251static const struct pci_device_id scsih_pci_table[] = {
252 /* Fury ~ 3004 and 3008 */
253 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
254 PCI_ANY_ID, PCI_ANY_ID },
255 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
256 PCI_ANY_ID, PCI_ANY_ID },
257 /* Invader ~ 3108 */
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
265 PCI_ANY_ID, PCI_ANY_ID },
266 {0} /* Terminating entry */
267};
268MODULE_DEVICE_TABLE(pci, scsih_pci_table);
269
270/** 279/**
271 * _scsih_set_debug_level - global setting of ioc->logging_level. 280 * _scsih_set_debug_level - global setting of ioc->logging_level.
272 * 281 *
@@ -282,8 +291,10 @@ _scsih_set_debug_level(const char *val, struct kernel_param *kp)
282 return ret; 291 return ret;
283 292
284 pr_info("setting logging_level(0x%08x)\n", logging_level); 293 pr_info("setting logging_level(0x%08x)\n", logging_level);
294 spin_lock(&gioc_lock);
285 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) 295 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
286 ioc->logging_level = logging_level; 296 ioc->logging_level = logging_level;
297 spin_unlock(&gioc_lock);
287 return 0; 298 return 0;
288} 299}
289module_param_call(logging_level, _scsih_set_debug_level, param_get_int, 300module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
@@ -518,8 +529,61 @@ _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
518 } 529 }
519} 530}
520 531
532static struct _sas_device *
533__mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
534 struct MPT3SAS_TARGET *tgt_priv)
535{
536 struct _sas_device *ret;
537
538 assert_spin_locked(&ioc->sas_device_lock);
539
540 ret = tgt_priv->sdev;
541 if (ret)
542 sas_device_get(ret);
543
544 return ret;
545}
546
547static struct _sas_device *
548mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
549 struct MPT3SAS_TARGET *tgt_priv)
550{
551 struct _sas_device *ret;
552 unsigned long flags;
553
554 spin_lock_irqsave(&ioc->sas_device_lock, flags);
555 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
556 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
557
558 return ret;
559}
560
561
562struct _sas_device *
563__mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
564 u64 sas_address)
565{
566 struct _sas_device *sas_device;
567
568 assert_spin_locked(&ioc->sas_device_lock);
569
570 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
571 if (sas_device->sas_address == sas_address)
572 goto found_device;
573
574 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
575 if (sas_device->sas_address == sas_address)
576 goto found_device;
577
578 return NULL;
579
580found_device:
581 sas_device_get(sas_device);
582 return sas_device;
583}
584
521/** 585/**
522 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search 586 * mpt3sas_get_sdev_by_addr - sas device search
523 * @ioc: per adapter object 587 * @ioc: per adapter object
524 * @sas_address: sas address 588 * @sas_address: sas address
525 * Context: Calling function should acquire ioc->sas_device_lock 589 * Context: Calling function should acquire ioc->sas_device_lock
@@ -528,24 +592,44 @@ _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
528 * object. 592 * object.
529 */ 593 */
530struct _sas_device * 594struct _sas_device *
531mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, 595mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
532 u64 sas_address) 596 u64 sas_address)
533{ 597{
534 struct _sas_device *sas_device; 598 struct _sas_device *sas_device;
599 unsigned long flags;
600
601 spin_lock_irqsave(&ioc->sas_device_lock, flags);
602 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
603 sas_address);
604 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
605
606 return sas_device;
607}
608
609static struct _sas_device *
610__mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
611{
612 struct _sas_device *sas_device;
613
614 assert_spin_locked(&ioc->sas_device_lock);
535 615
536 list_for_each_entry(sas_device, &ioc->sas_device_list, list) 616 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
537 if (sas_device->sas_address == sas_address) 617 if (sas_device->handle == handle)
538 return sas_device; 618 goto found_device;
539 619
540 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) 620 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
541 if (sas_device->sas_address == sas_address) 621 if (sas_device->handle == handle)
542 return sas_device; 622 goto found_device;
543 623
544 return NULL; 624 return NULL;
625
626found_device:
627 sas_device_get(sas_device);
628 return sas_device;
545} 629}
546 630
547/** 631/**
548 * _scsih_sas_device_find_by_handle - sas device search 632 * mpt3sas_get_sdev_by_handle - sas device search
549 * @ioc: per adapter object 633 * @ioc: per adapter object
550 * @handle: sas device handle (assigned by firmware) 634 * @handle: sas device handle (assigned by firmware)
551 * Context: Calling function should acquire ioc->sas_device_lock 635 * Context: Calling function should acquire ioc->sas_device_lock
@@ -554,19 +638,16 @@ mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
554 * object. 638 * object.
555 */ 639 */
556static struct _sas_device * 640static struct _sas_device *
557_scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) 641mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
558{ 642{
559 struct _sas_device *sas_device; 643 struct _sas_device *sas_device;
644 unsigned long flags;
560 645
561 list_for_each_entry(sas_device, &ioc->sas_device_list, list) 646 spin_lock_irqsave(&ioc->sas_device_lock, flags);
562 if (sas_device->handle == handle) 647 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
563 return sas_device; 648 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
564
565 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
566 if (sas_device->handle == handle)
567 return sas_device;
568 649
569 return NULL; 650 return sas_device;
570} 651}
571 652
572/** 653/**
@@ -575,7 +656,7 @@ _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
575 * @sas_device: the sas_device object 656 * @sas_device: the sas_device object
576 * Context: This function will acquire ioc->sas_device_lock. 657 * Context: This function will acquire ioc->sas_device_lock.
577 * 658 *
578 * Removing object and freeing associated memory from the ioc->sas_device_list. 659 * If sas_device is on the list, remove it and decrement its reference count.
579 */ 660 */
580static void 661static void
581_scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, 662_scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
@@ -602,9 +683,15 @@ _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
602 ioc->name, sas_device->enclosure_level, 683 ioc->name, sas_device->enclosure_level,
603 sas_device->connector_name); 684 sas_device->connector_name);
604 685
686 /*
687 * The lock serializes access to the list, but we still need to verify
688 * that nobody removed the entry while we were waiting on the lock.
689 */
605 spin_lock_irqsave(&ioc->sas_device_lock, flags); 690 spin_lock_irqsave(&ioc->sas_device_lock, flags);
606 list_del(&sas_device->list); 691 if (!list_empty(&sas_device->list)) {
607 kfree(sas_device); 692 list_del_init(&sas_device->list);
693 sas_device_put(sas_device);
694 }
608 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 695 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
609} 696}
610 697
@@ -625,12 +712,16 @@ _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
625 return; 712 return;
626 713
627 spin_lock_irqsave(&ioc->sas_device_lock, flags); 714 spin_lock_irqsave(&ioc->sas_device_lock, flags);
628 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 715 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
629 if (sas_device) 716 if (sas_device) {
630 list_del(&sas_device->list); 717 list_del_init(&sas_device->list);
718 sas_device_put(sas_device);
719 }
631 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 720 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
632 if (sas_device) 721 if (sas_device) {
633 _scsih_remove_device(ioc, sas_device); 722 _scsih_remove_device(ioc, sas_device);
723 sas_device_put(sas_device);
724 }
634} 725}
635 726
636/** 727/**
@@ -651,13 +742,16 @@ mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
651 return; 742 return;
652 743
653 spin_lock_irqsave(&ioc->sas_device_lock, flags); 744 spin_lock_irqsave(&ioc->sas_device_lock, flags);
654 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 745 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
655 sas_address); 746 if (sas_device) {
656 if (sas_device) 747 list_del_init(&sas_device->list);
657 list_del(&sas_device->list); 748 sas_device_put(sas_device);
749 }
658 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 750 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
659 if (sas_device) 751 if (sas_device) {
660 _scsih_remove_device(ioc, sas_device); 752 _scsih_remove_device(ioc, sas_device);
753 sas_device_put(sas_device);
754 }
661} 755}
662 756
663/** 757/**
@@ -692,6 +786,7 @@ _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
692 sas_device->enclosure_level, sas_device->connector_name)); 786 sas_device->enclosure_level, sas_device->connector_name));
693 787
694 spin_lock_irqsave(&ioc->sas_device_lock, flags); 788 spin_lock_irqsave(&ioc->sas_device_lock, flags);
789 sas_device_get(sas_device);
695 list_add_tail(&sas_device->list, &ioc->sas_device_list); 790 list_add_tail(&sas_device->list, &ioc->sas_device_list);
696 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 791 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
697 792
@@ -745,6 +840,7 @@ _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
745 sas_device->connector_name)); 840 sas_device->connector_name));
746 841
747 spin_lock_irqsave(&ioc->sas_device_lock, flags); 842 spin_lock_irqsave(&ioc->sas_device_lock, flags);
843 sas_device_get(sas_device);
748 list_add_tail(&sas_device->list, &ioc->sas_device_init_list); 844 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
749 _scsih_determine_boot_device(ioc, sas_device, 0); 845 _scsih_determine_boot_device(ioc, sas_device, 0);
750 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 846 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
@@ -778,7 +874,7 @@ _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
778} 874}
779 875
780/** 876/**
781 * _scsih_raid_device_find_by_handle - raid device search 877 * mpt3sas_raid_device_find_by_handle - raid device search
782 * @ioc: per adapter object 878 * @ioc: per adapter object
783 * @handle: sas device handle (assigned by firmware) 879 * @handle: sas device handle (assigned by firmware)
784 * Context: Calling function should acquire ioc->raid_device_lock 880 * Context: Calling function should acquire ioc->raid_device_lock
@@ -786,8 +882,8 @@ _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
786 * This searches for raid_device based on handle, then return raid_device 882 * This searches for raid_device based on handle, then return raid_device
787 * object. 883 * object.
788 */ 884 */
789static struct _raid_device * 885struct _raid_device *
790_scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) 886mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
791{ 887{
792 struct _raid_device *raid_device, *r; 888 struct _raid_device *raid_device, *r;
793 889
@@ -1095,14 +1191,14 @@ _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1095} 1191}
1096 1192
1097/** 1193/**
1098 * _scsih_change_queue_depth - setting device queue depth 1194 * scsih_change_queue_depth - setting device queue depth
1099 * @sdev: scsi device struct 1195 * @sdev: scsi device struct
1100 * @qdepth: requested queue depth 1196 * @qdepth: requested queue depth
1101 * 1197 *
1102 * Returns queue depth. 1198 * Returns queue depth.
1103 */ 1199 */
1104static int 1200int
1105_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) 1201scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1106{ 1202{
1107 struct Scsi_Host *shost = sdev->host; 1203 struct Scsi_Host *shost = sdev->host;
1108 int max_depth; 1204 int max_depth;
@@ -1123,12 +1219,15 @@ _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1123 goto not_sata; 1219 goto not_sata;
1124 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) 1220 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1125 goto not_sata; 1221 goto not_sata;
1222
1126 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1223 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1127 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1224 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1128 sas_device_priv_data->sas_target->sas_address); 1225 if (sas_device) {
1129 if (sas_device && sas_device->device_info & 1226 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1130 MPI2_SAS_DEVICE_INFO_SATA_DEVICE) 1227 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1131 max_depth = MPT3SAS_SATA_QUEUE_DEPTH; 1228
1229 sas_device_put(sas_device);
1230 }
1132 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1231 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1133 1232
1134 not_sata: 1233 not_sata:
@@ -1141,14 +1240,14 @@ _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1141} 1240}
1142 1241
1143/** 1242/**
1144 * _scsih_target_alloc - target add routine 1243 * scsih_target_alloc - target add routine
1145 * @starget: scsi target struct 1244 * @starget: scsi target struct
1146 * 1245 *
1147 * Returns 0 if ok. Any other return is assumed to be an error and 1246 * Returns 0 if ok. Any other return is assumed to be an error and
1148 * the device is ignored. 1247 * the device is ignored.
1149 */ 1248 */
1150static int 1249int
1151_scsih_target_alloc(struct scsi_target *starget) 1250scsih_target_alloc(struct scsi_target *starget)
1152{ 1251{
1153 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 1252 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1154 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 1253 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -1176,7 +1275,9 @@ _scsih_target_alloc(struct scsi_target *starget)
1176 sas_target_priv_data->handle = raid_device->handle; 1275 sas_target_priv_data->handle = raid_device->handle;
1177 sas_target_priv_data->sas_address = raid_device->wwid; 1276 sas_target_priv_data->sas_address = raid_device->wwid;
1178 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; 1277 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1179 raid_device->starget = starget; 1278 sas_target_priv_data->raid_device = raid_device;
1279 if (ioc->is_warpdrive)
1280 raid_device->starget = starget;
1180 } 1281 }
1181 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1282 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1182 return 0; 1283 return 0;
@@ -1185,12 +1286,13 @@ _scsih_target_alloc(struct scsi_target *starget)
1185 /* sas/sata devices */ 1286 /* sas/sata devices */
1186 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1287 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1187 rphy = dev_to_rphy(starget->dev.parent); 1288 rphy = dev_to_rphy(starget->dev.parent);
1188 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1289 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1189 rphy->identify.sas_address); 1290 rphy->identify.sas_address);
1190 1291
1191 if (sas_device) { 1292 if (sas_device) {
1192 sas_target_priv_data->handle = sas_device->handle; 1293 sas_target_priv_data->handle = sas_device->handle;
1193 sas_target_priv_data->sas_address = sas_device->sas_address; 1294 sas_target_priv_data->sas_address = sas_device->sas_address;
1295 sas_target_priv_data->sdev = sas_device;
1194 sas_device->starget = starget; 1296 sas_device->starget = starget;
1195 sas_device->id = starget->id; 1297 sas_device->id = starget->id;
1196 sas_device->channel = starget->channel; 1298 sas_device->channel = starget->channel;
@@ -1206,13 +1308,13 @@ _scsih_target_alloc(struct scsi_target *starget)
1206} 1308}
1207 1309
1208/** 1310/**
1209 * _scsih_target_destroy - target destroy routine 1311 * scsih_target_destroy - target destroy routine
1210 * @starget: scsi target struct 1312 * @starget: scsi target struct
1211 * 1313 *
1212 * Returns nothing. 1314 * Returns nothing.
1213 */ 1315 */
1214static void 1316void
1215_scsih_target_destroy(struct scsi_target *starget) 1317scsih_target_destroy(struct scsi_target *starget)
1216{ 1318{
1217 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 1319 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1218 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 1320 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -1240,13 +1342,21 @@ _scsih_target_destroy(struct scsi_target *starget)
1240 1342
1241 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1343 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1242 rphy = dev_to_rphy(starget->dev.parent); 1344 rphy = dev_to_rphy(starget->dev.parent);
1243 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1345 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1244 rphy->identify.sas_address);
1245 if (sas_device && (sas_device->starget == starget) && 1346 if (sas_device && (sas_device->starget == starget) &&
1246 (sas_device->id == starget->id) && 1347 (sas_device->id == starget->id) &&
1247 (sas_device->channel == starget->channel)) 1348 (sas_device->channel == starget->channel))
1248 sas_device->starget = NULL; 1349 sas_device->starget = NULL;
1249 1350
1351 if (sas_device) {
1352 /*
1353 * Corresponding get() is in _scsih_target_alloc()
1354 */
1355 sas_target_priv_data->sdev = NULL;
1356 sas_device_put(sas_device);
1357
1358 sas_device_put(sas_device);
1359 }
1250 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1360 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1251 1361
1252 out: 1362 out:
@@ -1255,14 +1365,14 @@ _scsih_target_destroy(struct scsi_target *starget)
1255} 1365}
1256 1366
1257/** 1367/**
1258 * _scsih_slave_alloc - device add routine 1368 * scsih_slave_alloc - device add routine
1259 * @sdev: scsi device struct 1369 * @sdev: scsi device struct
1260 * 1370 *
1261 * Returns 0 if ok. Any other return is assumed to be an error and 1371 * Returns 0 if ok. Any other return is assumed to be an error and
1262 * the device is ignored. 1372 * the device is ignored.
1263 */ 1373 */
1264static int 1374int
1265_scsih_slave_alloc(struct scsi_device *sdev) 1375scsih_slave_alloc(struct scsi_device *sdev)
1266{ 1376{
1267 struct Scsi_Host *shost; 1377 struct Scsi_Host *shost;
1268 struct MPT3SAS_ADAPTER *ioc; 1378 struct MPT3SAS_ADAPTER *ioc;
@@ -1302,14 +1412,18 @@ _scsih_slave_alloc(struct scsi_device *sdev)
1302 1412
1303 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { 1413 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1304 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1414 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1305 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1415 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1306 sas_target_priv_data->sas_address); 1416 sas_target_priv_data->sas_address);
1307 if (sas_device && (sas_device->starget == NULL)) { 1417 if (sas_device && (sas_device->starget == NULL)) {
1308 sdev_printk(KERN_INFO, sdev, 1418 sdev_printk(KERN_INFO, sdev,
1309 "%s : sas_device->starget set to starget @ %d\n", 1419 "%s : sas_device->starget set to starget @ %d\n",
1310 __func__, __LINE__); 1420 __func__, __LINE__);
1311 sas_device->starget = starget; 1421 sas_device->starget = starget;
1312 } 1422 }
1423
1424 if (sas_device)
1425 sas_device_put(sas_device);
1426
1313 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1427 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1314 } 1428 }
1315 1429
@@ -1317,13 +1431,13 @@ _scsih_slave_alloc(struct scsi_device *sdev)
1317} 1431}
1318 1432
1319/** 1433/**
1320 * _scsih_slave_destroy - device destroy routine 1434 * scsih_slave_destroy - device destroy routine
1321 * @sdev: scsi device struct 1435 * @sdev: scsi device struct
1322 * 1436 *
1323 * Returns nothing. 1437 * Returns nothing.
1324 */ 1438 */
1325static void 1439void
1326_scsih_slave_destroy(struct scsi_device *sdev) 1440scsih_slave_destroy(struct scsi_device *sdev)
1327{ 1441{
1328 struct MPT3SAS_TARGET *sas_target_priv_data; 1442 struct MPT3SAS_TARGET *sas_target_priv_data;
1329 struct scsi_target *starget; 1443 struct scsi_target *starget;
@@ -1344,10 +1458,13 @@ _scsih_slave_destroy(struct scsi_device *sdev)
1344 1458
1345 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { 1459 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1346 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1460 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1347 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1461 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1348 sas_target_priv_data->sas_address); 1462 sas_target_priv_data);
1349 if (sas_device && !sas_target_priv_data->num_luns) 1463 if (sas_device && !sas_target_priv_data->num_luns)
1350 sas_device->starget = NULL; 1464 sas_device->starget = NULL;
1465
1466 if (sas_device)
1467 sas_device_put(sas_device);
1351 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1468 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1352 } 1469 }
1353 1470
@@ -1409,23 +1526,26 @@ _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1409 */ 1526 */
1410 1527
1411/** 1528/**
1412 * _scsih_is_raid - return boolean indicating device is raid volume 1529 * scsih_is_raid - return boolean indicating device is raid volume
1413 * @dev the device struct object 1530 * @dev the device struct object
1414 */ 1531 */
1415static int 1532int
1416_scsih_is_raid(struct device *dev) 1533scsih_is_raid(struct device *dev)
1417{ 1534{
1418 struct scsi_device *sdev = to_scsi_device(dev); 1535 struct scsi_device *sdev = to_scsi_device(dev);
1536 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1419 1537
1538 if (ioc->is_warpdrive)
1539 return 0;
1420 return (sdev->channel == RAID_CHANNEL) ? 1 : 0; 1540 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1421} 1541}
1422 1542
1423/** 1543/**
1424 * _scsih_get_resync - get raid volume resync percent complete 1544 * scsih_get_resync - get raid volume resync percent complete
1425 * @dev the device struct object 1545 * @dev the device struct object
1426 */ 1546 */
1427static void 1547void
1428_scsih_get_resync(struct device *dev) 1548scsih_get_resync(struct device *dev)
1429{ 1549{
1430 struct scsi_device *sdev = to_scsi_device(dev); 1550 struct scsi_device *sdev = to_scsi_device(dev);
1431 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); 1551 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
@@ -1439,6 +1559,9 @@ _scsih_get_resync(struct device *dev)
1439 1559
1440 percent_complete = 0; 1560 percent_complete = 0;
1441 handle = 0; 1561 handle = 0;
1562 if (ioc->is_warpdrive)
1563 goto out;
1564
1442 spin_lock_irqsave(&ioc->raid_device_lock, flags); 1565 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1443 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, 1566 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1444 sdev->channel); 1567 sdev->channel);
@@ -1466,15 +1589,18 @@ _scsih_get_resync(struct device *dev)
1466 percent_complete = 0; 1589 percent_complete = 0;
1467 1590
1468 out: 1591 out:
1469 raid_set_resync(mpt3sas_raid_template, dev, percent_complete); 1592 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1593 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1594 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1595 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1470} 1596}
1471 1597
1472/** 1598/**
1473 * _scsih_get_state - get raid volume level 1599 * scsih_get_state - get raid volume level
1474 * @dev the device struct object 1600 * @dev the device struct object
1475 */ 1601 */
1476static void 1602void
1477_scsih_get_state(struct device *dev) 1603scsih_get_state(struct device *dev)
1478{ 1604{
1479 struct scsi_device *sdev = to_scsi_device(dev); 1605 struct scsi_device *sdev = to_scsi_device(dev);
1480 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); 1606 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
@@ -1524,7 +1650,10 @@ _scsih_get_state(struct device *dev)
1524 break; 1650 break;
1525 } 1651 }
1526 out: 1652 out:
1527 raid_set_state(mpt3sas_raid_template, dev, state); 1653 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1654 raid_set_state(mpt2sas_raid_template, dev, state);
1655 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1656 raid_set_state(mpt3sas_raid_template, dev, state);
1528} 1657}
1529 1658
1530/** 1659/**
@@ -1533,7 +1662,8 @@ _scsih_get_state(struct device *dev)
1533 * @volume_type: volume type 1662 * @volume_type: volume type
1534 */ 1663 */
1535static void 1664static void
1536_scsih_set_level(struct scsi_device *sdev, u8 volume_type) 1665_scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
1666 struct scsi_device *sdev, u8 volume_type)
1537{ 1667{
1538 enum raid_level level = RAID_LEVEL_UNKNOWN; 1668 enum raid_level level = RAID_LEVEL_UNKNOWN;
1539 1669
@@ -1552,7 +1682,12 @@ _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1552 break; 1682 break;
1553 } 1683 }
1554 1684
1555 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level); 1685 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1686 raid_set_level(mpt2sas_raid_template,
1687 &sdev->sdev_gendev, level);
1688 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1689 raid_set_level(mpt3sas_raid_template,
1690 &sdev->sdev_gendev, level);
1556} 1691}
1557 1692
1558 1693
@@ -1622,8 +1757,6 @@ _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1622 return 0; 1757 return 0;
1623} 1758}
1624 1759
1625
1626
1627/** 1760/**
1628 * _scsih_enable_tlr - setting TLR flags 1761 * _scsih_enable_tlr - setting TLR flags
1629 * @ioc: per adapter object 1762 * @ioc: per adapter object
@@ -1652,14 +1785,14 @@ _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1652} 1785}
1653 1786
1654/** 1787/**
1655 * _scsih_slave_configure - device configure routine. 1788 * scsih_slave_configure - device configure routine.
1656 * @sdev: scsi device struct 1789 * @sdev: scsi device struct
1657 * 1790 *
1658 * Returns 0 if ok. Any other return is assumed to be an error and 1791 * Returns 0 if ok. Any other return is assumed to be an error and
1659 * the device is ignored. 1792 * the device is ignored.
1660 */ 1793 */
1661static int 1794int
1662_scsih_slave_configure(struct scsi_device *sdev) 1795scsih_slave_configure(struct scsi_device *sdev)
1663{ 1796{
1664 struct Scsi_Host *shost = sdev->host; 1797 struct Scsi_Host *shost = sdev->host;
1665 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 1798 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -1686,7 +1819,7 @@ _scsih_slave_configure(struct scsi_device *sdev)
1686 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { 1819 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1687 1820
1688 spin_lock_irqsave(&ioc->raid_device_lock, flags); 1821 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1689 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 1822 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
1690 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1823 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1691 if (!raid_device) { 1824 if (!raid_device) {
1692 dfailprintk(ioc, pr_warn(MPT3SAS_FMT 1825 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
@@ -1702,6 +1835,10 @@ _scsih_slave_configure(struct scsi_device *sdev)
1702 return 1; 1835 return 1;
1703 } 1836 }
1704 1837
1838 /*
1839 * WARPDRIVE: Initialize the required data for Direct IO
1840 */
1841 mpt3sas_init_warpdrive_properties(ioc, raid_device);
1705 1842
1706 /* RAID Queue Depth Support 1843 /* RAID Queue Depth Support
1707 * IS volume = underlying qdepth of drive type, either 1844 * IS volume = underlying qdepth of drive type, either
@@ -1750,17 +1887,19 @@ _scsih_slave_configure(struct scsi_device *sdev)
1750 break; 1887 break;
1751 } 1888 }
1752 1889
1753 sdev_printk(KERN_INFO, sdev, 1890 if (!ioc->hide_ir_msg)
1754 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n", 1891 sdev_printk(KERN_INFO, sdev,
1755 r_level, raid_device->handle, 1892 "%s: handle(0x%04x), wwid(0x%016llx),"
1756 (unsigned long long)raid_device->wwid, 1893 " pd_count(%d), type(%s)\n",
1757 raid_device->num_pds, ds); 1894 r_level, raid_device->handle,
1758 1895 (unsigned long long)raid_device->wwid,
1896 raid_device->num_pds, ds);
1759 1897
1760 _scsih_change_queue_depth(sdev, qdepth); 1898 scsih_change_queue_depth(sdev, qdepth);
1761 1899
1762/* raid transport support */ 1900 /* raid transport support */
1763 _scsih_set_level(sdev, raid_device->volume_type); 1901 if (!ioc->is_warpdrive)
1902 _scsih_set_level(ioc, sdev, raid_device->volume_type);
1764 return 0; 1903 return 0;
1765 } 1904 }
1766 1905
@@ -1783,7 +1922,7 @@ _scsih_slave_configure(struct scsi_device *sdev)
1783 } 1922 }
1784 1923
1785 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1924 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1786 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1925 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1787 sas_device_priv_data->sas_target->sas_address); 1926 sas_device_priv_data->sas_target->sas_address);
1788 if (!sas_device) { 1927 if (!sas_device) {
1789 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1928 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
@@ -1823,13 +1962,14 @@ _scsih_slave_configure(struct scsi_device *sdev)
1823 ds, sas_device->enclosure_level, 1962 ds, sas_device->enclosure_level,
1824 sas_device->connector_name); 1963 sas_device->connector_name);
1825 1964
1965 sas_device_put(sas_device);
1826 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1966 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1827 1967
1828 if (!ssp_target) 1968 if (!ssp_target)
1829 _scsih_display_sata_capabilities(ioc, handle, sdev); 1969 _scsih_display_sata_capabilities(ioc, handle, sdev);
1830 1970
1831 1971
1832 _scsih_change_queue_depth(sdev, qdepth); 1972 scsih_change_queue_depth(sdev, qdepth);
1833 1973
1834 if (ssp_target) { 1974 if (ssp_target) {
1835 sas_read_port_mode_page(sdev); 1975 sas_read_port_mode_page(sdev);
@@ -1840,7 +1980,7 @@ _scsih_slave_configure(struct scsi_device *sdev)
1840} 1980}
1841 1981
1842/** 1982/**
1843 * _scsih_bios_param - fetch head, sector, cylinder info for a disk 1983 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1844 * @sdev: scsi device struct 1984 * @sdev: scsi device struct
1845 * @bdev: pointer to block device context 1985 * @bdev: pointer to block device context
1846 * @capacity: device size (in 512 byte sectors) 1986 * @capacity: device size (in 512 byte sectors)
@@ -1851,8 +1991,8 @@ _scsih_slave_configure(struct scsi_device *sdev)
1851 * 1991 *
1852 * Return nothing. 1992 * Return nothing.
1853 */ 1993 */
1854static int 1994int
1855_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, 1995scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1856 sector_t capacity, int params[]) 1996 sector_t capacity, int params[])
1857{ 1997{
1858 int heads; 1998 int heads;
@@ -2209,7 +2349,10 @@ _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2209 2349
2210 if (!priv_target) 2350 if (!priv_target)
2211 return; 2351 return;
2212 device_str = "volume"; 2352 if (ioc->hide_ir_msg)
2353 device_str = "WarpDrive";
2354 else
2355 device_str = "volume";
2213 2356
2214 scsi_print_command(scmd); 2357 scsi_print_command(scmd);
2215 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { 2358 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
@@ -2219,8 +2362,7 @@ _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2219 device_str, (unsigned long long)priv_target->sas_address); 2362 device_str, (unsigned long long)priv_target->sas_address);
2220 } else { 2363 } else {
2221 spin_lock_irqsave(&ioc->sas_device_lock, flags); 2364 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2222 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 2365 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2223 priv_target->sas_address);
2224 if (sas_device) { 2366 if (sas_device) {
2225 if (priv_target->flags & 2367 if (priv_target->flags &
2226 MPT_TARGET_FLAGS_RAID_COMPONENT) { 2368 MPT_TARGET_FLAGS_RAID_COMPONENT) {
@@ -2246,19 +2388,21 @@ _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2246 "enclosure level(0x%04x),connector name(%s)\n", 2388 "enclosure level(0x%04x),connector name(%s)\n",
2247 sas_device->enclosure_level, 2389 sas_device->enclosure_level,
2248 sas_device->connector_name); 2390 sas_device->connector_name);
2391
2392 sas_device_put(sas_device);
2249 } 2393 }
2250 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 2394 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2251 } 2395 }
2252} 2396}
2253 2397
2254/** 2398/**
2255 * _scsih_abort - eh threads main abort routine 2399 * scsih_abort - eh threads main abort routine
2256 * @scmd: pointer to scsi command object 2400 * @scmd: pointer to scsi command object
2257 * 2401 *
2258 * Returns SUCCESS if command aborted else FAILED 2402 * Returns SUCCESS if command aborted else FAILED
2259 */ 2403 */
2260static int 2404int
2261_scsih_abort(struct scsi_cmnd *scmd) 2405scsih_abort(struct scsi_cmnd *scmd)
2262{ 2406{
2263 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 2407 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2264 struct MPT3SAS_DEVICE *sas_device_priv_data; 2408 struct MPT3SAS_DEVICE *sas_device_priv_data;
@@ -2311,21 +2455,23 @@ _scsih_abort(struct scsi_cmnd *scmd)
2311} 2455}
2312 2456
2313/** 2457/**
2314 * _scsih_dev_reset - eh threads main device reset routine 2458 * scsih_dev_reset - eh threads main device reset routine
2315 * @scmd: pointer to scsi command object 2459 * @scmd: pointer to scsi command object
2316 * 2460 *
2317 * Returns SUCCESS if command aborted else FAILED 2461 * Returns SUCCESS if command aborted else FAILED
2318 */ 2462 */
2319static int 2463int
2320_scsih_dev_reset(struct scsi_cmnd *scmd) 2464scsih_dev_reset(struct scsi_cmnd *scmd)
2321{ 2465{
2322 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 2466 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2323 struct MPT3SAS_DEVICE *sas_device_priv_data; 2467 struct MPT3SAS_DEVICE *sas_device_priv_data;
2324 struct _sas_device *sas_device; 2468 struct _sas_device *sas_device = NULL;
2325 unsigned long flags;
2326 u16 handle; 2469 u16 handle;
2327 int r; 2470 int r;
2328 2471
2472 struct scsi_target *starget = scmd->device->sdev_target;
2473 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2474
2329 sdev_printk(KERN_INFO, scmd->device, 2475 sdev_printk(KERN_INFO, scmd->device,
2330 "attempting device reset! scmd(%p)\n", scmd); 2476 "attempting device reset! scmd(%p)\n", scmd);
2331 _scsih_tm_display_info(ioc, scmd); 2477 _scsih_tm_display_info(ioc, scmd);
@@ -2344,12 +2490,10 @@ _scsih_dev_reset(struct scsi_cmnd *scmd)
2344 handle = 0; 2490 handle = 0;
2345 if (sas_device_priv_data->sas_target->flags & 2491 if (sas_device_priv_data->sas_target->flags &
2346 MPT_TARGET_FLAGS_RAID_COMPONENT) { 2492 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2347 spin_lock_irqsave(&ioc->sas_device_lock, flags); 2493 sas_device = mpt3sas_get_sdev_from_target(ioc,
2348 sas_device = _scsih_sas_device_find_by_handle(ioc, 2494 target_priv_data);
2349 sas_device_priv_data->sas_target->handle);
2350 if (sas_device) 2495 if (sas_device)
2351 handle = sas_device->volume_handle; 2496 handle = sas_device->volume_handle;
2352 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2353 } else 2497 } else
2354 handle = sas_device_priv_data->sas_target->handle; 2498 handle = sas_device_priv_data->sas_target->handle;
2355 2499
@@ -2366,25 +2510,29 @@ _scsih_dev_reset(struct scsi_cmnd *scmd)
2366 out: 2510 out:
2367 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", 2511 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2368 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); 2512 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2513
2514 if (sas_device)
2515 sas_device_put(sas_device);
2516
2369 return r; 2517 return r;
2370} 2518}
2371 2519
2372/** 2520/**
2373 * _scsih_target_reset - eh threads main target reset routine 2521 * scsih_target_reset - eh threads main target reset routine
2374 * @scmd: pointer to scsi command object 2522 * @scmd: pointer to scsi command object
2375 * 2523 *
2376 * Returns SUCCESS if command aborted else FAILED 2524 * Returns SUCCESS if command aborted else FAILED
2377 */ 2525 */
2378static int 2526int
2379_scsih_target_reset(struct scsi_cmnd *scmd) 2527scsih_target_reset(struct scsi_cmnd *scmd)
2380{ 2528{
2381 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 2529 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2382 struct MPT3SAS_DEVICE *sas_device_priv_data; 2530 struct MPT3SAS_DEVICE *sas_device_priv_data;
2383 struct _sas_device *sas_device; 2531 struct _sas_device *sas_device = NULL;
2384 unsigned long flags;
2385 u16 handle; 2532 u16 handle;
2386 int r; 2533 int r;
2387 struct scsi_target *starget = scmd->device->sdev_target; 2534 struct scsi_target *starget = scmd->device->sdev_target;
2535 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2388 2536
2389 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", 2537 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2390 scmd); 2538 scmd);
@@ -2404,12 +2552,10 @@ _scsih_target_reset(struct scsi_cmnd *scmd)
2404 handle = 0; 2552 handle = 0;
2405 if (sas_device_priv_data->sas_target->flags & 2553 if (sas_device_priv_data->sas_target->flags &
2406 MPT_TARGET_FLAGS_RAID_COMPONENT) { 2554 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2407 spin_lock_irqsave(&ioc->sas_device_lock, flags); 2555 sas_device = mpt3sas_get_sdev_from_target(ioc,
2408 sas_device = _scsih_sas_device_find_by_handle(ioc, 2556 target_priv_data);
2409 sas_device_priv_data->sas_target->handle);
2410 if (sas_device) 2557 if (sas_device)
2411 handle = sas_device->volume_handle; 2558 handle = sas_device->volume_handle;
2412 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2413 } else 2559 } else
2414 handle = sas_device_priv_data->sas_target->handle; 2560 handle = sas_device_priv_data->sas_target->handle;
2415 2561
@@ -2426,18 +2572,22 @@ _scsih_target_reset(struct scsi_cmnd *scmd)
2426 out: 2572 out:
2427 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", 2573 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2428 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); 2574 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2575
2576 if (sas_device)
2577 sas_device_put(sas_device);
2578
2429 return r; 2579 return r;
2430} 2580}
2431 2581
2432 2582
2433/** 2583/**
2434 * _scsih_host_reset - eh threads main host reset routine 2584 * scsih_host_reset - eh threads main host reset routine
2435 * @scmd: pointer to scsi command object 2585 * @scmd: pointer to scsi command object
2436 * 2586 *
2437 * Returns SUCCESS if command aborted else FAILED 2587 * Returns SUCCESS if command aborted else FAILED
2438 */ 2588 */
2439static int 2589int
2440_scsih_host_reset(struct scsi_cmnd *scmd) 2590scsih_host_reset(struct scsi_cmnd *scmd)
2441{ 2591{
2442 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 2592 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2443 int r, retval; 2593 int r, retval;
@@ -2483,32 +2633,36 @@ _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2483 return; 2633 return;
2484 2634
2485 spin_lock_irqsave(&ioc->fw_event_lock, flags); 2635 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2636 fw_event_work_get(fw_event);
2486 INIT_LIST_HEAD(&fw_event->list); 2637 INIT_LIST_HEAD(&fw_event->list);
2487 list_add_tail(&fw_event->list, &ioc->fw_event_list); 2638 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2488 INIT_WORK(&fw_event->work, _firmware_event_work); 2639 INIT_WORK(&fw_event->work, _firmware_event_work);
2640 fw_event_work_get(fw_event);
2489 queue_work(ioc->firmware_event_thread, &fw_event->work); 2641 queue_work(ioc->firmware_event_thread, &fw_event->work);
2490 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 2642 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2491} 2643}
2492 2644
2493/** 2645/**
2494 * _scsih_fw_event_free - delete fw_event 2646 * _scsih_fw_event_del_from_list - delete fw_event from the list
2495 * @ioc: per adapter object 2647 * @ioc: per adapter object
2496 * @fw_event: object describing the event 2648 * @fw_event: object describing the event
2497 * Context: This function will acquire ioc->fw_event_lock. 2649 * Context: This function will acquire ioc->fw_event_lock.
2498 * 2650 *
2499 * This removes firmware event object from link list, frees associated memory. 2651 * If the fw_event is on the fw_event_list, remove it and do a put.
2500 * 2652 *
2501 * Return nothing. 2653 * Return nothing.
2502 */ 2654 */
2503static void 2655static void
2504_scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work 2656_scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2505 *fw_event) 2657 *fw_event)
2506{ 2658{
2507 unsigned long flags; 2659 unsigned long flags;
2508 2660
2509 spin_lock_irqsave(&ioc->fw_event_lock, flags); 2661 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2510 list_del(&fw_event->list); 2662 if (!list_empty(&fw_event->list)) {
2511 kfree(fw_event); 2663 list_del_init(&fw_event->list);
2664 fw_event_work_put(fw_event);
2665 }
2512 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 2666 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2513} 2667}
2514 2668
@@ -2525,17 +2679,19 @@ mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2525 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) 2679 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2526{ 2680{
2527 struct fw_event_work *fw_event; 2681 struct fw_event_work *fw_event;
2682 u16 sz;
2528 2683
2529 if (ioc->is_driver_loading) 2684 if (ioc->is_driver_loading)
2530 return; 2685 return;
2531 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data), 2686 sz = sizeof(*event_data);
2532 GFP_ATOMIC); 2687 fw_event = alloc_fw_event_work(sz);
2533 if (!fw_event) 2688 if (!fw_event)
2534 return; 2689 return;
2535 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; 2690 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2536 fw_event->ioc = ioc; 2691 fw_event->ioc = ioc;
2537 memcpy(fw_event->event_data, event_data, sizeof(*event_data)); 2692 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2538 _scsih_fw_event_add(ioc, fw_event); 2693 _scsih_fw_event_add(ioc, fw_event);
2694 fw_event_work_put(fw_event);
2539} 2695}
2540 2696
2541/** 2697/**
@@ -2551,12 +2707,13 @@ _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2551 2707
2552 if (ioc->is_driver_loading) 2708 if (ioc->is_driver_loading)
2553 return; 2709 return;
2554 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); 2710 fw_event = alloc_fw_event_work(0);
2555 if (!fw_event) 2711 if (!fw_event)
2556 return; 2712 return;
2557 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; 2713 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2558 fw_event->ioc = ioc; 2714 fw_event->ioc = ioc;
2559 _scsih_fw_event_add(ioc, fw_event); 2715 _scsih_fw_event_add(ioc, fw_event);
2716 fw_event_work_put(fw_event);
2560} 2717}
2561 2718
2562/** 2719/**
@@ -2570,12 +2727,29 @@ mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2570{ 2727{
2571 struct fw_event_work *fw_event; 2728 struct fw_event_work *fw_event;
2572 2729
2573 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); 2730 fw_event = alloc_fw_event_work(0);
2574 if (!fw_event) 2731 if (!fw_event)
2575 return; 2732 return;
2576 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; 2733 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2577 fw_event->ioc = ioc; 2734 fw_event->ioc = ioc;
2578 _scsih_fw_event_add(ioc, fw_event); 2735 _scsih_fw_event_add(ioc, fw_event);
2736 fw_event_work_put(fw_event);
2737}
2738
2739static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
2740{
2741 unsigned long flags;
2742 struct fw_event_work *fw_event = NULL;
2743
2744 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2745 if (!list_empty(&ioc->fw_event_list)) {
2746 fw_event = list_first_entry(&ioc->fw_event_list,
2747 struct fw_event_work, list);
2748 list_del_init(&fw_event->list);
2749 }
2750 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2751
2752 return fw_event;
2579} 2753}
2580 2754
2581/** 2755/**
@@ -2590,17 +2764,25 @@ mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2590static void 2764static void
2591_scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) 2765_scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2592{ 2766{
2593 struct fw_event_work *fw_event, *next; 2767 struct fw_event_work *fw_event;
2594 2768
2595 if (list_empty(&ioc->fw_event_list) || 2769 if (list_empty(&ioc->fw_event_list) ||
2596 !ioc->firmware_event_thread || in_interrupt()) 2770 !ioc->firmware_event_thread || in_interrupt())
2597 return; 2771 return;
2598 2772
2599 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { 2773 while ((fw_event = dequeue_next_fw_event(ioc))) {
2600 if (cancel_delayed_work_sync(&fw_event->delayed_work)) { 2774 /*
2601 _scsih_fw_event_free(ioc, fw_event); 2775 * Wait on the fw_event to complete. If this returns 1, then
2602 continue; 2776 * the event was never executed, and we need a put for the
2603 } 2777 * reference the delayed_work had on the fw_event.
2778 *
2779 * If it did execute, we wait for it to finish, and the put will
2780 * happen from _firmware_event_work()
2781 */
2782 if (cancel_delayed_work_sync(&fw_event->delayed_work))
2783 fw_event_work_put(fw_event);
2784
2785 fw_event_work_put(fw_event);
2604 } 2786 }
2605} 2787}
2606 2788
@@ -2763,7 +2945,7 @@ _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2763 struct scsi_device *sdev; 2945 struct scsi_device *sdev;
2764 struct _sas_device *sas_device; 2946 struct _sas_device *sas_device;
2765 2947
2766 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 2948 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
2767 if (!sas_device) 2949 if (!sas_device)
2768 return; 2950 return;
2769 2951
@@ -2779,6 +2961,8 @@ _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2779 continue; 2961 continue;
2780 _scsih_internal_device_block(sdev, sas_device_priv_data); 2962 _scsih_internal_device_block(sdev, sas_device_priv_data);
2781 } 2963 }
2964
2965 sas_device_put(sas_device);
2782} 2966}
2783 2967
2784/** 2968/**
@@ -2807,12 +2991,13 @@ _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2807 if (mpt3sas_port->remote_identify.device_type == 2991 if (mpt3sas_port->remote_identify.device_type ==
2808 SAS_END_DEVICE) { 2992 SAS_END_DEVICE) {
2809 spin_lock_irqsave(&ioc->sas_device_lock, flags); 2993 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2810 sas_device = 2994 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
2811 mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 2995 mpt3sas_port->remote_identify.sas_address);
2812 mpt3sas_port->remote_identify.sas_address); 2996 if (sas_device) {
2813 if (sas_device)
2814 set_bit(sas_device->handle, 2997 set_bit(sas_device->handle,
2815 ioc->blocking_handles); 2998 ioc->blocking_handles);
2999 sas_device_put(sas_device);
3000 }
2816 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 3001 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2817 } 3002 }
2818 } 3003 }
@@ -2880,7 +3065,7 @@ _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2880{ 3065{
2881 Mpi2SCSITaskManagementRequest_t *mpi_request; 3066 Mpi2SCSITaskManagementRequest_t *mpi_request;
2882 u16 smid; 3067 u16 smid;
2883 struct _sas_device *sas_device; 3068 struct _sas_device *sas_device = NULL;
2884 struct MPT3SAS_TARGET *sas_target_priv_data = NULL; 3069 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2885 u64 sas_address = 0; 3070 u64 sas_address = 0;
2886 unsigned long flags; 3071 unsigned long flags;
@@ -2913,7 +3098,7 @@ _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2913 return; 3098 return;
2914 3099
2915 spin_lock_irqsave(&ioc->sas_device_lock, flags); 3100 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2916 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 3101 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
2917 if (sas_device && sas_device->starget && 3102 if (sas_device && sas_device->starget &&
2918 sas_device->starget->hostdata) { 3103 sas_device->starget->hostdata) {
2919 sas_target_priv_data = sas_device->starget->hostdata; 3104 sas_target_priv_data = sas_device->starget->hostdata;
@@ -2947,14 +3132,14 @@ _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2947 if (!smid) { 3132 if (!smid) {
2948 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); 3133 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2949 if (!delayed_tr) 3134 if (!delayed_tr)
2950 return; 3135 goto out;
2951 INIT_LIST_HEAD(&delayed_tr->list); 3136 INIT_LIST_HEAD(&delayed_tr->list);
2952 delayed_tr->handle = handle; 3137 delayed_tr->handle = handle;
2953 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); 3138 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2954 dewtprintk(ioc, pr_info(MPT3SAS_FMT 3139 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2955 "DELAYED:tr:handle(0x%04x), (open)\n", 3140 "DELAYED:tr:handle(0x%04x), (open)\n",
2956 ioc->name, handle)); 3141 ioc->name, handle));
2957 return; 3142 goto out;
2958 } 3143 }
2959 3144
2960 dewtprintk(ioc, pr_info(MPT3SAS_FMT 3145 dewtprintk(ioc, pr_info(MPT3SAS_FMT
@@ -2968,6 +3153,10 @@ _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2968 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; 3153 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2969 mpt3sas_base_put_smid_hi_priority(ioc, smid); 3154 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2970 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); 3155 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3156
3157out:
3158 if (sas_device)
3159 sas_device_put(sas_device);
2971} 3160}
2972 3161
2973/** 3162/**
@@ -3337,7 +3526,7 @@ _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3337 unsigned long flags; 3526 unsigned long flags;
3338 3527
3339 spin_lock_irqsave(&ioc->raid_device_lock, flags); 3528 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3340 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 3529 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3341 if (raid_device && raid_device->starget && 3530 if (raid_device && raid_device->starget &&
3342 raid_device->starget->hostdata) { 3531 raid_device->starget->hostdata) {
3343 sas_target_priv_data = 3532 sas_target_priv_data =
@@ -3398,6 +3587,9 @@ _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3398 a = 0; 3587 a = 0;
3399 b = 0; 3588 b = 0;
3400 3589
3590 if (ioc->is_warpdrive)
3591 return;
3592
3401 /* Volume Resets for Deleted or Removed */ 3593 /* Volume Resets for Deleted or Removed */
3402 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; 3594 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3403 for (i = 0; i < event_data->NumElements; i++, element++) { 3595 for (i = 0; i < event_data->NumElements; i++, element++) {
@@ -3634,8 +3826,9 @@ _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3634} 3826}
3635 3827
3636 3828
3829
3637/** 3830/**
3638 * _scsih_qcmd - main scsi request entry point 3831 * scsih_qcmd - main scsi request entry point
3639 * @scmd: pointer to scsi command object 3832 * @scmd: pointer to scsi command object
3640 * @done: function pointer to be invoked on completion 3833 * @done: function pointer to be invoked on completion
3641 * 3834 *
@@ -3645,21 +3838,20 @@ _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3645 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or 3838 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3646 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full 3839 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3647 */ 3840 */
3648static int 3841int
3649_scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) 3842scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3650{ 3843{
3651 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 3844 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3652 struct MPT3SAS_DEVICE *sas_device_priv_data; 3845 struct MPT3SAS_DEVICE *sas_device_priv_data;
3653 struct MPT3SAS_TARGET *sas_target_priv_data; 3846 struct MPT3SAS_TARGET *sas_target_priv_data;
3847 struct _raid_device *raid_device;
3654 Mpi2SCSIIORequest_t *mpi_request; 3848 Mpi2SCSIIORequest_t *mpi_request;
3655 u32 mpi_control; 3849 u32 mpi_control;
3656 u16 smid; 3850 u16 smid;
3657 u16 handle; 3851 u16 handle;
3658 3852
3659#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3660 if (ioc->logging_level & MPT_DEBUG_SCSI) 3853 if (ioc->logging_level & MPT_DEBUG_SCSI)
3661 scsi_print_command(scmd); 3854 scsi_print_command(scmd);
3662#endif
3663 3855
3664 sas_device_priv_data = scmd->device->hostdata; 3856 sas_device_priv_data = scmd->device->hostdata;
3665 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { 3857 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
@@ -3709,7 +3901,11 @@ _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3709 /* set tags */ 3901 /* set tags */
3710 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; 3902 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3711 3903
3712 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && 3904 /* Make sure Device is not raid volume.
3905 * We do not expose raid functionality to upper layer for warpdrive.
3906 */
3907 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
3908 && (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3713 scmd->cmd_len != 32) 3909 scmd->cmd_len != 32)
3714 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; 3910 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3715 3911
@@ -3752,13 +3948,19 @@ _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3752 } else 3948 } else
3753 ioc->build_zero_len_sge(ioc, &mpi_request->SGL); 3949 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3754 3950
3951 raid_device = sas_target_priv_data->raid_device;
3952 if (raid_device && raid_device->direct_io_enabled)
3953 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3954 smid);
3955
3755 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { 3956 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3756 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { 3957 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3757 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | 3958 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3758 MPI25_SCSIIO_IOFLAGS_FAST_PATH); 3959 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3759 mpt3sas_base_put_smid_fast_path(ioc, smid, handle); 3960 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3760 } else 3961 } else
3761 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle); 3962 mpt3sas_base_put_smid_scsi_io(ioc, smid,
3963 le16_to_cpu(mpi_request->DevHandle));
3762 } else 3964 } else
3763 mpt3sas_base_put_smid_default(ioc, smid); 3965 mpt3sas_base_put_smid_default(ioc, smid);
3764 return 0; 3966 return 0;
@@ -3790,7 +3992,6 @@ _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3790 } 3992 }
3791} 3993}
3792 3994
3793#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3794/** 3995/**
3795 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request 3996 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3796 * @ioc: per adapter object 3997 * @ioc: per adapter object
@@ -3818,14 +4019,16 @@ _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3818 char *desc_scsi_state = ioc->tmp_string; 4019 char *desc_scsi_state = ioc->tmp_string;
3819 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); 4020 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3820 struct _sas_device *sas_device = NULL; 4021 struct _sas_device *sas_device = NULL;
3821 unsigned long flags;
3822 struct scsi_target *starget = scmd->device->sdev_target; 4022 struct scsi_target *starget = scmd->device->sdev_target;
3823 struct MPT3SAS_TARGET *priv_target = starget->hostdata; 4023 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3824 char *device_str = NULL; 4024 char *device_str = NULL;
3825 4025
3826 if (!priv_target) 4026 if (!priv_target)
3827 return; 4027 return;
3828 device_str = "volume"; 4028 if (ioc->hide_ir_msg)
4029 device_str = "WarpDrive";
4030 else
4031 device_str = "volume";
3829 4032
3830 if (log_info == 0x31170000) 4033 if (log_info == 0x31170000)
3831 return; 4034 return;
@@ -3946,9 +4149,7 @@ _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3946 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, 4149 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3947 device_str, (unsigned long long)priv_target->sas_address); 4150 device_str, (unsigned long long)priv_target->sas_address);
3948 } else { 4151 } else {
3949 spin_lock_irqsave(&ioc->sas_device_lock, flags); 4152 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
3950 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3951 priv_target->sas_address);
3952 if (sas_device) { 4153 if (sas_device) {
3953 pr_warn(MPT3SAS_FMT 4154 pr_warn(MPT3SAS_FMT
3954 "\tsas_address(0x%016llx), phy(%d)\n", 4155 "\tsas_address(0x%016llx), phy(%d)\n",
@@ -3967,8 +4168,9 @@ _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3967 " connector name( %s)\n", ioc->name, 4168 " connector name( %s)\n", ioc->name,
3968 sas_device->enclosure_level, 4169 sas_device->enclosure_level,
3969 sas_device->connector_name); 4170 sas_device->connector_name);
4171
4172 sas_device_put(sas_device);
3970 } 4173 }
3971 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3972 } 4174 }
3973 4175
3974 pr_warn(MPT3SAS_FMT 4176 pr_warn(MPT3SAS_FMT
@@ -4003,7 +4205,6 @@ _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4003 _scsih_response_code(ioc, response_bytes[0]); 4205 _scsih_response_code(ioc, response_bytes[0]);
4004 } 4206 }
4005} 4207}
4006#endif
4007 4208
4008/** 4209/**
4009 * _scsih_turn_on_pfa_led - illuminate PFA LED 4210 * _scsih_turn_on_pfa_led - illuminate PFA LED
@@ -4020,7 +4221,7 @@ _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4020 Mpi2SepRequest_t mpi_request; 4221 Mpi2SepRequest_t mpi_request;
4021 struct _sas_device *sas_device; 4222 struct _sas_device *sas_device;
4022 4223
4023 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 4224 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4024 if (!sas_device) 4225 if (!sas_device)
4025 return; 4226 return;
4026 4227
@@ -4035,7 +4236,7 @@ _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4035 &mpi_request)) != 0) { 4236 &mpi_request)) != 0) {
4036 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, 4237 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4037 __FILE__, __LINE__, __func__); 4238 __FILE__, __LINE__, __func__);
4038 return; 4239 goto out;
4039 } 4240 }
4040 sas_device->pfa_led_on = 1; 4241 sas_device->pfa_led_on = 1;
4041 4242
@@ -4044,9 +4245,12 @@ _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4044 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", 4245 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4045 ioc->name, le16_to_cpu(mpi_reply.IOCStatus), 4246 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4046 le32_to_cpu(mpi_reply.IOCLogInfo))); 4247 le32_to_cpu(mpi_reply.IOCLogInfo)));
4047 return; 4248 goto out;
4048 } 4249 }
4250out:
4251 sas_device_put(sas_device);
4049} 4252}
4253
4050/** 4254/**
4051 * _scsih_turn_off_pfa_led - turn off Fault LED 4255 * _scsih_turn_off_pfa_led - turn off Fault LED
4052 * @ioc: per adapter object 4256 * @ioc: per adapter object
@@ -4085,6 +4289,7 @@ _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4085 return; 4289 return;
4086 } 4290 }
4087} 4291}
4292
4088/** 4293/**
4089 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event 4294 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4090 * @ioc: per adapter object 4295 * @ioc: per adapter object
@@ -4098,13 +4303,14 @@ _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4098{ 4303{
4099 struct fw_event_work *fw_event; 4304 struct fw_event_work *fw_event;
4100 4305
4101 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); 4306 fw_event = alloc_fw_event_work(0);
4102 if (!fw_event) 4307 if (!fw_event)
4103 return; 4308 return;
4104 fw_event->event = MPT3SAS_TURN_ON_PFA_LED; 4309 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4105 fw_event->device_handle = handle; 4310 fw_event->device_handle = handle;
4106 fw_event->ioc = ioc; 4311 fw_event->ioc = ioc;
4107 _scsih_fw_event_add(ioc, fw_event); 4312 _scsih_fw_event_add(ioc, fw_event);
4313 fw_event_work_put(fw_event);
4108} 4314}
4109 4315
4110/** 4316/**
@@ -4128,19 +4334,17 @@ _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4128 4334
4129 /* only handle non-raid devices */ 4335 /* only handle non-raid devices */
4130 spin_lock_irqsave(&ioc->sas_device_lock, flags); 4336 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4131 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 4337 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4132 if (!sas_device) { 4338 if (!sas_device)
4133 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 4339 goto out_unlock;
4134 return; 4340
4135 }
4136 starget = sas_device->starget; 4341 starget = sas_device->starget;
4137 sas_target_priv_data = starget->hostdata; 4342 sas_target_priv_data = starget->hostdata;
4138 4343
4139 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || 4344 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4140 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { 4345 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4141 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 4346 goto out_unlock;
4142 return; 4347
4143 }
4144 if (sas_device->enclosure_handle != 0) 4348 if (sas_device->enclosure_handle != 0)
4145 starget_printk(KERN_INFO, starget, "predicted fault, " 4349 starget_printk(KERN_INFO, starget, "predicted fault, "
4146 "enclosure logical id(0x%016llx), slot(%d)\n", 4350 "enclosure logical id(0x%016llx), slot(%d)\n",
@@ -4163,7 +4367,7 @@ _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4163 if (!event_reply) { 4367 if (!event_reply) {
4164 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", 4368 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4165 ioc->name, __FILE__, __LINE__, __func__); 4369 ioc->name, __FILE__, __LINE__, __func__);
4166 return; 4370 goto out;
4167 } 4371 }
4168 4372
4169 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; 4373 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
@@ -4180,6 +4384,14 @@ _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4180 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); 4384 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4181 mpt3sas_ctl_add_to_event_log(ioc, event_reply); 4385 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4182 kfree(event_reply); 4386 kfree(event_reply);
4387out:
4388 if (sas_device)
4389 sas_device_put(sas_device);
4390 return;
4391
4392out_unlock:
4393 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4394 goto out;
4183} 4395}
4184 4396
4185/** 4397/**
@@ -4207,6 +4419,7 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4207 u32 log_info; 4419 u32 log_info;
4208 struct MPT3SAS_DEVICE *sas_device_priv_data; 4420 struct MPT3SAS_DEVICE *sas_device_priv_data;
4209 u32 response_code = 0; 4421 u32 response_code = 0;
4422 unsigned long flags;
4210 4423
4211 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); 4424 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4212 scmd = _scsih_scsi_lookup_get_clear(ioc, smid); 4425 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
@@ -4228,6 +4441,24 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4228 } 4441 }
4229 ioc_status = le16_to_cpu(mpi_reply->IOCStatus); 4442 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4230 4443
4444 /*
4445 * WARPDRIVE: If direct_io is set then it is directIO,
4446 * the failed direct I/O should be redirected to volume
4447 */
4448 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4449 ((ioc_status & MPI2_IOCSTATUS_MASK)
4450 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4451 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4452 ioc->scsi_lookup[smid - 1].scmd = scmd;
4453 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4454 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4455 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4456 mpi_request->DevHandle =
4457 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4458 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4459 sas_device_priv_data->sas_target->handle);
4460 return 0;
4461 }
4231 /* turning off TLR */ 4462 /* turning off TLR */
4232 scsi_state = mpi_reply->SCSIState; 4463 scsi_state = mpi_reply->SCSIState;
4233 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) 4464 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
@@ -4235,10 +4466,13 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4235 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; 4466 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4236 if (!sas_device_priv_data->tlr_snoop_check) { 4467 if (!sas_device_priv_data->tlr_snoop_check) {
4237 sas_device_priv_data->tlr_snoop_check++; 4468 sas_device_priv_data->tlr_snoop_check++;
4238 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && 4469 if (!ioc->is_warpdrive &&
4239 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) 4470 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4240 sas_device_priv_data->flags &= 4471 sas_is_tlr_enabled(scmd->device) &&
4241 ~MPT_DEVICE_TLR_ON; 4472 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4473 sas_disable_tlr(scmd->device);
4474 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4475 }
4242 } 4476 }
4243 4477
4244 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); 4478 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
@@ -4271,13 +4505,11 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4271 le16_to_cpu(mpi_reply->DevHandle)); 4505 le16_to_cpu(mpi_reply->DevHandle));
4272 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); 4506 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4273 4507
4274#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4275 if (!(ioc->logging_level & MPT_DEBUG_REPLY) && 4508 if (!(ioc->logging_level & MPT_DEBUG_REPLY) &&
4276 ((scmd->sense_buffer[2] == UNIT_ATTENTION) || 4509 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4277 (scmd->sense_buffer[2] == MEDIUM_ERROR) || 4510 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4278 (scmd->sense_buffer[2] == HARDWARE_ERROR))) 4511 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4279 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); 4512 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4280#endif
4281 } 4513 }
4282 switch (ioc_status) { 4514 switch (ioc_status) {
4283 case MPI2_IOCSTATUS_BUSY: 4515 case MPI2_IOCSTATUS_BUSY:
@@ -4384,10 +4616,8 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4384 4616
4385 } 4617 }
4386 4618
4387#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4388 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) 4619 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4389 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); 4620 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4390#endif
4391 4621
4392 out: 4622 out:
4393 4623
@@ -4933,13 +5163,11 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4933 5163
4934 spin_lock_irqsave(&ioc->sas_device_lock, flags); 5164 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4935 sas_address = le64_to_cpu(sas_device_pg0.SASAddress); 5165 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4936 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 5166 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
4937 sas_address); 5167 sas_address);
4938 5168
4939 if (!sas_device) { 5169 if (!sas_device)
4940 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5170 goto out_unlock;
4941 return;
4942 }
4943 5171
4944 if (unlikely(sas_device->handle != handle)) { 5172 if (unlikely(sas_device->handle != handle)) {
4945 starget = sas_device->starget; 5173 starget = sas_device->starget;
@@ -4967,20 +5195,25 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4967 pr_err(MPT3SAS_FMT 5195 pr_err(MPT3SAS_FMT
4968 "device is not present handle(0x%04x), flags!!!\n", 5196 "device is not present handle(0x%04x), flags!!!\n",
4969 ioc->name, handle); 5197 ioc->name, handle);
4970 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5198 goto out_unlock;
4971 return;
4972 } 5199 }
4973 5200
4974 /* check if there were any issues with discovery */ 5201 /* check if there were any issues with discovery */
4975 if (_scsih_check_access_status(ioc, sas_address, handle, 5202 if (_scsih_check_access_status(ioc, sas_address, handle,
4976 sas_device_pg0.AccessStatus)) { 5203 sas_device_pg0.AccessStatus))
4977 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5204 goto out_unlock;
4978 return;
4979 }
4980 5205
4981 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5206 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4982 _scsih_ublock_io_device(ioc, sas_address); 5207 _scsih_ublock_io_device(ioc, sas_address);
4983 5208
5209 if (sas_device)
5210 sas_device_put(sas_device);
5211 return;
5212
5213out_unlock:
5214 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5215 if (sas_device)
5216 sas_device_put(sas_device);
4984} 5217}
4985 5218
4986/** 5219/**
@@ -5005,7 +5238,6 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5005 u32 ioc_status; 5238 u32 ioc_status;
5006 u64 sas_address; 5239 u64 sas_address;
5007 u32 device_info; 5240 u32 device_info;
5008 unsigned long flags;
5009 5241
5010 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, 5242 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5011 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { 5243 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
@@ -5041,13 +5273,12 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5041 sas_device_pg0.AccessStatus)) 5273 sas_device_pg0.AccessStatus))
5042 return -1; 5274 return -1;
5043 5275
5044 spin_lock_irqsave(&ioc->sas_device_lock, flags); 5276 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5045 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 5277 sas_address);
5046 sas_address); 5278 if (sas_device) {
5047 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5279 sas_device_put(sas_device);
5048
5049 if (sas_device)
5050 return -1; 5280 return -1;
5281 }
5051 5282
5052 sas_device = kzalloc(sizeof(struct _sas_device), 5283 sas_device = kzalloc(sizeof(struct _sas_device),
5053 GFP_KERNEL); 5284 GFP_KERNEL);
@@ -5057,6 +5288,7 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5057 return 0; 5288 return 0;
5058 } 5289 }
5059 5290
5291 kref_init(&sas_device->refcount);
5060 sas_device->handle = handle; 5292 sas_device->handle = handle;
5061 if (_scsih_get_sas_address(ioc, 5293 if (_scsih_get_sas_address(ioc,
5062 le16_to_cpu(sas_device_pg0.ParentDevHandle), 5294 le16_to_cpu(sas_device_pg0.ParentDevHandle),
@@ -5098,6 +5330,7 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5098 else 5330 else
5099 _scsih_sas_device_add(ioc, sas_device); 5331 _scsih_sas_device_add(ioc, sas_device);
5100 5332
5333 sas_device_put(sas_device);
5101 return 0; 5334 return 0;
5102} 5335}
5103 5336
@@ -5144,7 +5377,9 @@ _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5144 sas_target_priv_data->handle = 5377 sas_target_priv_data->handle =
5145 MPT3SAS_INVALID_DEVICE_HANDLE; 5378 MPT3SAS_INVALID_DEVICE_HANDLE;
5146 } 5379 }
5147 mpt3sas_transport_port_remove(ioc, 5380
5381 if (!ioc->hide_drives)
5382 mpt3sas_transport_port_remove(ioc,
5148 sas_device->sas_address, 5383 sas_device->sas_address,
5149 sas_device->sas_address_parent); 5384 sas_device->sas_address_parent);
5150 5385
@@ -5180,11 +5415,8 @@ _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5180 "%s: exit: enclosure level(0x%04x), connector name(%s)\n", 5415 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5181 ioc->name, __func__, sas_device->enclosure_level, 5416 ioc->name, __func__, sas_device->enclosure_level,
5182 sas_device->connector_name)); 5417 sas_device->connector_name));
5183
5184 kfree(sas_device);
5185} 5418}
5186 5419
5187#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5188/** 5420/**
5189 * _scsih_sas_topology_change_event_debug - debug for topology event 5421 * _scsih_sas_topology_change_event_debug - debug for topology event
5190 * @ioc: per adapter object 5422 * @ioc: per adapter object
@@ -5262,7 +5494,6 @@ _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5262 5494
5263 } 5495 }
5264} 5496}
5265#endif
5266 5497
5267/** 5498/**
5268 * _scsih_sas_topology_change_event - handle topology changes 5499 * _scsih_sas_topology_change_event - handle topology changes
@@ -5287,10 +5518,8 @@ _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5287 (Mpi2EventDataSasTopologyChangeList_t *) 5518 (Mpi2EventDataSasTopologyChangeList_t *)
5288 fw_event->event_data; 5519 fw_event->event_data;
5289 5520
5290#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5291 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) 5521 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5292 _scsih_sas_topology_change_event_debug(ioc, event_data); 5522 _scsih_sas_topology_change_event_debug(ioc, event_data);
5293#endif
5294 5523
5295 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) 5524 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5296 return 0; 5525 return 0;
@@ -5396,7 +5625,6 @@ _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5396 return 0; 5625 return 0;
5397} 5626}
5398 5627
5399#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5400/** 5628/**
5401 * _scsih_sas_device_status_change_event_debug - debug for device event 5629 * _scsih_sas_device_status_change_event_debug - debug for device event
5402 * @event_data: event data payload 5630 * @event_data: event data payload
@@ -5464,7 +5692,6 @@ _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5464 event_data->ASC, event_data->ASCQ); 5692 event_data->ASC, event_data->ASCQ);
5465 pr_info("\n"); 5693 pr_info("\n");
5466} 5694}
5467#endif
5468 5695
5469/** 5696/**
5470 * _scsih_sas_device_status_change_event - handle device status change 5697 * _scsih_sas_device_status_change_event - handle device status change
@@ -5486,11 +5713,9 @@ _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5486 (Mpi2EventDataSasDeviceStatusChange_t *) 5713 (Mpi2EventDataSasDeviceStatusChange_t *)
5487 fw_event->event_data; 5714 fw_event->event_data;
5488 5715
5489#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5490 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) 5716 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5491 _scsih_sas_device_status_change_event_debug(ioc, 5717 _scsih_sas_device_status_change_event_debug(ioc,
5492 event_data); 5718 event_data);
5493#endif
5494 5719
5495 /* In MPI Revision K (0xC), the internal device reset complete was 5720 /* In MPI Revision K (0xC), the internal device reset complete was
5496 * implemented, so avoid setting tm_busy flag for older firmware. 5721 * implemented, so avoid setting tm_busy flag for older firmware.
@@ -5506,29 +5731,30 @@ _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5506 5731
5507 spin_lock_irqsave(&ioc->sas_device_lock, flags); 5732 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5508 sas_address = le64_to_cpu(event_data->SASAddress); 5733 sas_address = le64_to_cpu(event_data->SASAddress);
5509 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 5734 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5510 sas_address); 5735 sas_address);
5511 5736
5512 if (!sas_device || !sas_device->starget) { 5737 if (!sas_device || !sas_device->starget)
5513 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5738 goto out;
5514 return;
5515 }
5516 5739
5517 target_priv_data = sas_device->starget->hostdata; 5740 target_priv_data = sas_device->starget->hostdata;
5518 if (!target_priv_data) { 5741 if (!target_priv_data)
5519 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5742 goto out;
5520 return;
5521 }
5522 5743
5523 if (event_data->ReasonCode == 5744 if (event_data->ReasonCode ==
5524 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) 5745 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5525 target_priv_data->tm_busy = 1; 5746 target_priv_data->tm_busy = 1;
5526 else 5747 else
5527 target_priv_data->tm_busy = 0; 5748 target_priv_data->tm_busy = 0;
5749
5750out:
5751 if (sas_device)
5752 sas_device_put(sas_device);
5753
5528 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 5754 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5755
5529} 5756}
5530 5757
5531#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5532/** 5758/**
5533 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure 5759 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5534 * event 5760 * event
@@ -5563,7 +5789,6 @@ _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5563 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), 5789 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5564 le16_to_cpu(event_data->StartSlot)); 5790 le16_to_cpu(event_data->StartSlot));
5565} 5791}
5566#endif
5567 5792
5568/** 5793/**
5569 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events 5794 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
@@ -5577,12 +5802,10 @@ static void
5577_scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, 5802_scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5578 struct fw_event_work *fw_event) 5803 struct fw_event_work *fw_event)
5579{ 5804{
5580#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5581 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) 5805 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5582 _scsih_sas_enclosure_dev_status_change_event_debug(ioc, 5806 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5583 (Mpi2EventDataSasEnclDevStatusChange_t *) 5807 (Mpi2EventDataSasEnclDevStatusChange_t *)
5584 fw_event->event_data); 5808 fw_event->event_data);
5585#endif
5586} 5809}
5587 5810
5588/** 5811/**
@@ -5762,17 +5985,15 @@ _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5762 Mpi2EventDataSasDiscovery_t *event_data = 5985 Mpi2EventDataSasDiscovery_t *event_data =
5763 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; 5986 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5764 5987
5765#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5766 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { 5988 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5767 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, 5989 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5768 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? 5990 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5769 "start" : "stop"); 5991 "start" : "stop");
5770 if (event_data->DiscoveryStatus) 5992 if (event_data->DiscoveryStatus)
5771 pr_info("discovery_status(0x%08x)", 5993 pr_info("discovery_status(0x%08x)",
5772 le32_to_cpu(event_data->DiscoveryStatus)); 5994 le32_to_cpu(event_data->DiscoveryStatus));
5773 pr_info("\n"); 5995 pr_info("\n");
5774 } 5996 }
5775#endif
5776 5997
5777 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && 5998 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5778 !ioc->sas_hba.num_phys) { 5999 !ioc->sas_hba.num_phys) {
@@ -5804,6 +6025,8 @@ _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5804 u16 ioc_status; 6025 u16 ioc_status;
5805 u32 log_info; 6026 u32 log_info;
5806 6027
6028 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6029 return rc;
5807 6030
5808 mutex_lock(&ioc->scsih_cmds.mutex); 6031 mutex_lock(&ioc->scsih_cmds.mutex);
5809 6032
@@ -5971,7 +6194,7 @@ _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5971 struct scsi_target *starget = NULL; 6194 struct scsi_target *starget = NULL;
5972 6195
5973 spin_lock_irqsave(&ioc->raid_device_lock, flags); 6196 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5974 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 6197 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
5975 if (raid_device) { 6198 if (raid_device) {
5976 if (raid_device->starget) { 6199 if (raid_device->starget) {
5977 starget = raid_device->starget; 6200 starget = raid_device->starget;
@@ -6008,7 +6231,7 @@ _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6008 u16 handle = le16_to_cpu(element->PhysDiskDevHandle); 6231 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6009 6232
6010 spin_lock_irqsave(&ioc->sas_device_lock, flags); 6233 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6011 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 6234 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6012 if (sas_device) { 6235 if (sas_device) {
6013 sas_device->volume_handle = 0; 6236 sas_device->volume_handle = 0;
6014 sas_device->volume_wwid = 0; 6237 sas_device->volume_wwid = 0;
@@ -6027,6 +6250,8 @@ _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6027 /* exposing raid component */ 6250 /* exposing raid component */
6028 if (starget) 6251 if (starget)
6029 starget_for_each_device(starget, NULL, _scsih_reprobe_lun); 6252 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6253
6254 sas_device_put(sas_device);
6030} 6255}
6031 6256
6032/** 6257/**
@@ -6055,7 +6280,7 @@ _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6055 &volume_wwid); 6280 &volume_wwid);
6056 6281
6057 spin_lock_irqsave(&ioc->sas_device_lock, flags); 6282 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6058 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 6283 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6059 if (sas_device) { 6284 if (sas_device) {
6060 set_bit(handle, ioc->pd_handles); 6285 set_bit(handle, ioc->pd_handles);
6061 if (sas_device->starget && sas_device->starget->hostdata) { 6286 if (sas_device->starget && sas_device->starget->hostdata) {
@@ -6073,8 +6298,11 @@ _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6073 6298
6074 /* hiding raid component */ 6299 /* hiding raid component */
6075 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); 6300 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6301
6076 if (starget) 6302 if (starget)
6077 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); 6303 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6304
6305 sas_device_put(sas_device);
6078} 6306}
6079 6307
6080/** 6308/**
@@ -6107,7 +6335,6 @@ _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6107 Mpi2EventIrConfigElement_t *element) 6335 Mpi2EventIrConfigElement_t *element)
6108{ 6336{
6109 struct _sas_device *sas_device; 6337 struct _sas_device *sas_device;
6110 unsigned long flags;
6111 u16 handle = le16_to_cpu(element->PhysDiskDevHandle); 6338 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6112 Mpi2ConfigReply_t mpi_reply; 6339 Mpi2ConfigReply_t mpi_reply;
6113 Mpi2SasDevicePage0_t sas_device_pg0; 6340 Mpi2SasDevicePage0_t sas_device_pg0;
@@ -6117,11 +6344,10 @@ _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6117 6344
6118 set_bit(handle, ioc->pd_handles); 6345 set_bit(handle, ioc->pd_handles);
6119 6346
6120 spin_lock_irqsave(&ioc->sas_device_lock, flags); 6347 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6121 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6122 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6123 if (sas_device) { 6348 if (sas_device) {
6124 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); 6349 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6350 sas_device_put(sas_device);
6125 return; 6351 return;
6126 } 6352 }
6127 6353
@@ -6149,7 +6375,6 @@ _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6149 _scsih_add_device(ioc, handle, 0, 1); 6375 _scsih_add_device(ioc, handle, 0, 1);
6150} 6376}
6151 6377
6152#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6153/** 6378/**
6154 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events 6379 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6155 * @ioc: per adapter object 6380 * @ioc: per adapter object
@@ -6229,7 +6454,6 @@ _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6229 element->PhysDiskNum); 6454 element->PhysDiskNum);
6230 } 6455 }
6231} 6456}
6232#endif
6233 6457
6234/** 6458/**
6235 * _scsih_sas_ir_config_change_event - handle ir configuration change events 6459 * _scsih_sas_ir_config_change_event - handle ir configuration change events
@@ -6250,18 +6474,16 @@ _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6250 (Mpi2EventDataIrConfigChangeList_t *) 6474 (Mpi2EventDataIrConfigChangeList_t *)
6251 fw_event->event_data; 6475 fw_event->event_data;
6252 6476
6253#ifdef CONFIG_SCSI_MPT3SAS_LOGGING 6477 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6254 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) 6478 (!ioc->hide_ir_msg))
6255 _scsih_sas_ir_config_change_event_debug(ioc, event_data); 6479 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6256 6480
6257#endif
6258
6259 foreign_config = (le32_to_cpu(event_data->Flags) & 6481 foreign_config = (le32_to_cpu(event_data->Flags) &
6260 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; 6482 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6261 6483
6262 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; 6484 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6263 if (ioc->shost_recovery) { 6485 if (ioc->shost_recovery &&
6264 6486 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6265 for (i = 0; i < event_data->NumElements; i++, element++) { 6487 for (i = 0; i < event_data->NumElements; i++, element++) {
6266 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) 6488 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6267 _scsih_ir_fastpath(ioc, 6489 _scsih_ir_fastpath(ioc,
@@ -6270,6 +6492,7 @@ _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6270 } 6492 }
6271 return; 6493 return;
6272 } 6494 }
6495
6273 for (i = 0; i < event_data->NumElements; i++, element++) { 6496 for (i = 0; i < event_data->NumElements; i++, element++) {
6274 6497
6275 switch (element->ReasonCode) { 6498 switch (element->ReasonCode) {
@@ -6285,16 +6508,20 @@ _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6285 le16_to_cpu(element->VolDevHandle)); 6508 le16_to_cpu(element->VolDevHandle));
6286 break; 6509 break;
6287 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: 6510 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6288 _scsih_sas_pd_hide(ioc, element); 6511 if (!ioc->is_warpdrive)
6512 _scsih_sas_pd_hide(ioc, element);
6289 break; 6513 break;
6290 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: 6514 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6291 _scsih_sas_pd_expose(ioc, element); 6515 if (!ioc->is_warpdrive)
6516 _scsih_sas_pd_expose(ioc, element);
6292 break; 6517 break;
6293 case MPI2_EVENT_IR_CHANGE_RC_HIDE: 6518 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6294 _scsih_sas_pd_add(ioc, element); 6519 if (!ioc->is_warpdrive)
6520 _scsih_sas_pd_add(ioc, element);
6295 break; 6521 break;
6296 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: 6522 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6297 _scsih_sas_pd_delete(ioc, element); 6523 if (!ioc->is_warpdrive)
6524 _scsih_sas_pd_delete(ioc, element);
6298 break; 6525 break;
6299 } 6526 }
6300 } 6527 }
@@ -6329,10 +6556,11 @@ _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6329 6556
6330 handle = le16_to_cpu(event_data->VolDevHandle); 6557 handle = le16_to_cpu(event_data->VolDevHandle);
6331 state = le32_to_cpu(event_data->NewValue); 6558 state = le32_to_cpu(event_data->NewValue);
6332 dewtprintk(ioc, pr_info(MPT3SAS_FMT 6559 if (!ioc->hide_ir_msg)
6333 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", 6560 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6334 ioc->name, __func__, handle, 6561 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6335 le32_to_cpu(event_data->PreviousValue), state)); 6562 ioc->name, __func__, handle,
6563 le32_to_cpu(event_data->PreviousValue), state));
6336 switch (state) { 6564 switch (state) {
6337 case MPI2_RAID_VOL_STATE_MISSING: 6565 case MPI2_RAID_VOL_STATE_MISSING:
6338 case MPI2_RAID_VOL_STATE_FAILED: 6566 case MPI2_RAID_VOL_STATE_FAILED:
@@ -6344,7 +6572,7 @@ _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6344 case MPI2_RAID_VOL_STATE_OPTIMAL: 6572 case MPI2_RAID_VOL_STATE_OPTIMAL:
6345 6573
6346 spin_lock_irqsave(&ioc->raid_device_lock, flags); 6574 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6347 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 6575 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6348 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 6576 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6349 6577
6350 if (raid_device) 6578 if (raid_device)
@@ -6398,7 +6626,6 @@ _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6398 u16 handle, parent_handle; 6626 u16 handle, parent_handle;
6399 u32 state; 6627 u32 state;
6400 struct _sas_device *sas_device; 6628 struct _sas_device *sas_device;
6401 unsigned long flags;
6402 Mpi2ConfigReply_t mpi_reply; 6629 Mpi2ConfigReply_t mpi_reply;
6403 Mpi2SasDevicePage0_t sas_device_pg0; 6630 Mpi2SasDevicePage0_t sas_device_pg0;
6404 u32 ioc_status; 6631 u32 ioc_status;
@@ -6415,10 +6642,12 @@ _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6415 handle = le16_to_cpu(event_data->PhysDiskDevHandle); 6642 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6416 state = le32_to_cpu(event_data->NewValue); 6643 state = le32_to_cpu(event_data->NewValue);
6417 6644
6418 dewtprintk(ioc, pr_info(MPT3SAS_FMT 6645 if (!ioc->hide_ir_msg)
6419 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", 6646 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6420 ioc->name, __func__, handle, 6647 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6648 ioc->name, __func__, handle,
6421 le32_to_cpu(event_data->PreviousValue), state)); 6649 le32_to_cpu(event_data->PreviousValue), state));
6650
6422 switch (state) { 6651 switch (state) {
6423 case MPI2_RAID_PD_STATE_ONLINE: 6652 case MPI2_RAID_PD_STATE_ONLINE:
6424 case MPI2_RAID_PD_STATE_DEGRADED: 6653 case MPI2_RAID_PD_STATE_DEGRADED:
@@ -6426,13 +6655,14 @@ _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6426 case MPI2_RAID_PD_STATE_OPTIMAL: 6655 case MPI2_RAID_PD_STATE_OPTIMAL:
6427 case MPI2_RAID_PD_STATE_HOT_SPARE: 6656 case MPI2_RAID_PD_STATE_HOT_SPARE:
6428 6657
6429 set_bit(handle, ioc->pd_handles); 6658 if (!ioc->is_warpdrive)
6430 spin_lock_irqsave(&ioc->sas_device_lock, flags); 6659 set_bit(handle, ioc->pd_handles);
6431 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6432 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6433 6660
6434 if (sas_device) 6661 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6662 if (sas_device) {
6663 sas_device_put(sas_device);
6435 return; 6664 return;
6665 }
6436 6666
6437 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, 6667 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6438 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, 6668 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
@@ -6467,7 +6697,6 @@ _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6467 } 6697 }
6468} 6698}
6469 6699
6470#ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6471/** 6700/**
6472 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event 6701 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6473 * @ioc: per adapter object 6702 * @ioc: per adapter object
@@ -6509,7 +6738,6 @@ _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6509 le16_to_cpu(event_data->VolDevHandle), 6738 le16_to_cpu(event_data->VolDevHandle),
6510 event_data->PercentComplete); 6739 event_data->PercentComplete);
6511} 6740}
6512#endif
6513 6741
6514/** 6742/**
6515 * _scsih_sas_ir_operation_status_event - handle RAID operation events 6743 * _scsih_sas_ir_operation_status_event - handle RAID operation events
@@ -6530,18 +6758,17 @@ _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6530 unsigned long flags; 6758 unsigned long flags;
6531 u16 handle; 6759 u16 handle;
6532 6760
6533#ifdef CONFIG_SCSI_MPT3SAS_LOGGING 6761 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6534 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) 6762 (!ioc->hide_ir_msg))
6535 _scsih_sas_ir_operation_status_event_debug(ioc, 6763 _scsih_sas_ir_operation_status_event_debug(ioc,
6536 event_data); 6764 event_data);
6537#endif
6538 6765
6539 /* code added for raid transport support */ 6766 /* code added for raid transport support */
6540 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { 6767 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6541 6768
6542 spin_lock_irqsave(&ioc->raid_device_lock, flags); 6769 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6543 handle = le16_to_cpu(event_data->VolDevHandle); 6770 handle = le16_to_cpu(event_data->VolDevHandle);
6544 raid_device = _scsih_raid_device_find_by_handle(ioc, handle); 6771 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6545 if (raid_device) 6772 if (raid_device)
6546 raid_device->percent_complete = 6773 raid_device->percent_complete =
6547 event_data->PercentComplete; 6774 event_data->PercentComplete;
@@ -6703,7 +6930,7 @@ static void
6703_scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, 6930_scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6704 u16 handle) 6931 u16 handle)
6705{ 6932{
6706 struct MPT3SAS_TARGET *sas_target_priv_data; 6933 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6707 struct scsi_target *starget; 6934 struct scsi_target *starget;
6708 struct _raid_device *raid_device; 6935 struct _raid_device *raid_device;
6709 unsigned long flags; 6936 unsigned long flags;
@@ -6722,6 +6949,13 @@ _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6722 starget_printk(KERN_INFO, raid_device->starget, 6949 starget_printk(KERN_INFO, raid_device->starget,
6723 "handle(0x%04x), wwid(0x%016llx)\n", handle, 6950 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6724 (unsigned long long)raid_device->wwid); 6951 (unsigned long long)raid_device->wwid);
6952
6953 /*
6954 * WARPDRIVE: The handles of the PDs might have changed
6955 * across the host reset so re-initialize the
6956 * required data for Direct IO
6957 */
6958 mpt3sas_init_warpdrive_properties(ioc, raid_device);
6725 spin_lock_irqsave(&ioc->raid_device_lock, flags); 6959 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6726 if (raid_device->handle == handle) { 6960 if (raid_device->handle == handle) {
6727 spin_unlock_irqrestore(&ioc->raid_device_lock, 6961 spin_unlock_irqrestore(&ioc->raid_device_lock,
@@ -6791,6 +7025,7 @@ _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6791 } 7025 }
6792 7026
6793 /* refresh the pd_handles */ 7027 /* refresh the pd_handles */
7028 if (!ioc->is_warpdrive) {
6794 phys_disk_num = 0xFF; 7029 phys_disk_num = 0xFF;
6795 memset(ioc->pd_handles, 0, ioc->pd_handles_sz); 7030 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6796 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, 7031 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
@@ -6804,6 +7039,7 @@ _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6804 handle = le16_to_cpu(pd_pg0.DevHandle); 7039 handle = le16_to_cpu(pd_pg0.DevHandle);
6805 set_bit(handle, ioc->pd_handles); 7040 set_bit(handle, ioc->pd_handles);
6806 } 7041 }
7042 }
6807 out: 7043 out:
6808 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", 7044 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6809 ioc->name); 7045 ioc->name);
@@ -6906,6 +7142,7 @@ _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6906 struct _raid_device *raid_device, *raid_device_next; 7142 struct _raid_device *raid_device, *raid_device_next;
6907 struct list_head tmp_list; 7143 struct list_head tmp_list;
6908 unsigned long flags; 7144 unsigned long flags;
7145 LIST_HEAD(head);
6909 7146
6910 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", 7147 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6911 ioc->name); 7148 ioc->name);
@@ -6913,14 +7150,28 @@ _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6913 /* removing unresponding end devices */ 7150 /* removing unresponding end devices */
6914 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", 7151 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6915 ioc->name); 7152 ioc->name);
7153 /*
7154 * Iterate, pulling off devices marked as non-responding. We become the
7155 * owner for the reference the list had on any object we prune.
7156 */
7157 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6916 list_for_each_entry_safe(sas_device, sas_device_next, 7158 list_for_each_entry_safe(sas_device, sas_device_next,
6917 &ioc->sas_device_list, list) { 7159 &ioc->sas_device_list, list) {
6918 if (!sas_device->responding) 7160 if (!sas_device->responding)
6919 mpt3sas_device_remove_by_sas_address(ioc, 7161 list_move_tail(&sas_device->list, &head);
6920 sas_device->sas_address);
6921 else 7162 else
6922 sas_device->responding = 0; 7163 sas_device->responding = 0;
6923 } 7164 }
7165 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7166
7167 /*
7168 * Now, uninitialize and remove the unresponding devices we pruned.
7169 */
7170 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7171 _scsih_remove_device(ioc, sas_device);
7172 list_del_init(&sas_device->list);
7173 sas_device_put(sas_device);
7174 }
6924 7175
6925 /* removing unresponding volumes */ 7176 /* removing unresponding volumes */
6926 if (ioc->ir_firmware) { 7177 if (ioc->ir_firmware) {
@@ -7074,11 +7325,11 @@ _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7074 } 7325 }
7075 phys_disk_num = pd_pg0.PhysDiskNum; 7326 phys_disk_num = pd_pg0.PhysDiskNum;
7076 handle = le16_to_cpu(pd_pg0.DevHandle); 7327 handle = le16_to_cpu(pd_pg0.DevHandle);
7077 spin_lock_irqsave(&ioc->sas_device_lock, flags); 7328 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7078 sas_device = _scsih_sas_device_find_by_handle(ioc, handle); 7329 if (sas_device) {
7079 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 7330 sas_device_put(sas_device);
7080 if (sas_device)
7081 continue; 7331 continue;
7332 }
7082 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, 7333 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7083 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, 7334 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7084 handle) != 0) 7335 handle) != 0)
@@ -7199,12 +7450,12 @@ _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7199 if (!(_scsih_is_end_device( 7450 if (!(_scsih_is_end_device(
7200 le32_to_cpu(sas_device_pg0.DeviceInfo)))) 7451 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7201 continue; 7452 continue;
7202 spin_lock_irqsave(&ioc->sas_device_lock, flags); 7453 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7203 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
7204 le64_to_cpu(sas_device_pg0.SASAddress)); 7454 le64_to_cpu(sas_device_pg0.SASAddress));
7205 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 7455 if (sas_device) {
7206 if (sas_device) 7456 sas_device_put(sas_device);
7207 continue; 7457 continue;
7458 }
7208 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); 7459 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7209 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { 7460 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7210 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ 7461 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
@@ -7296,10 +7547,11 @@ mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7296static void 7547static void
7297_mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) 7548_mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7298{ 7549{
7550 _scsih_fw_event_del_from_list(ioc, fw_event);
7551
7299 /* the queue is being flushed so ignore this event */ 7552 /* the queue is being flushed so ignore this event */
7300 if (ioc->remove_host || 7553 if (ioc->remove_host || ioc->pci_error_recovery) {
7301 ioc->pci_error_recovery) { 7554 fw_event_work_put(fw_event);
7302 _scsih_fw_event_free(ioc, fw_event);
7303 return; 7555 return;
7304 } 7556 }
7305 7557
@@ -7310,8 +7562,16 @@ _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7310 fw_event->event_data); 7562 fw_event->event_data);
7311 break; 7563 break;
7312 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: 7564 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7313 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) 7565 while (scsi_host_in_recovery(ioc->shost) ||
7566 ioc->shost_recovery) {
7567 /*
7568 * If we're unloading, bail. Otherwise, this can become
7569 * an infinite loop.
7570 */
7571 if (ioc->remove_host)
7572 goto out;
7314 ssleep(1); 7573 ssleep(1);
7574 }
7315 _scsih_remove_unresponding_sas_devices(ioc); 7575 _scsih_remove_unresponding_sas_devices(ioc);
7316 _scsih_scan_for_devices_after_reset(ioc); 7576 _scsih_scan_for_devices_after_reset(ioc);
7317 break; 7577 break;
@@ -7356,7 +7616,8 @@ _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7356 _scsih_sas_ir_operation_status_event(ioc, fw_event); 7616 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7357 break; 7617 break;
7358 } 7618 }
7359 _scsih_fw_event_free(ioc, fw_event); 7619out:
7620 fw_event_work_put(fw_event);
7360} 7621}
7361 7622
7362/** 7623/**
@@ -7453,7 +7714,53 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7453 (Mpi2EventDataIrVolume_t *) 7714 (Mpi2EventDataIrVolume_t *)
7454 mpi_reply->EventData); 7715 mpi_reply->EventData);
7455 break; 7716 break;
7717 case MPI2_EVENT_LOG_ENTRY_ADDED:
7718 {
7719 Mpi2EventDataLogEntryAdded_t *log_entry;
7720 u32 *log_code;
7721
7722 if (!ioc->is_warpdrive)
7723 break;
7724
7725 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7726 mpi_reply->EventData;
7727 log_code = (u32 *)log_entry->LogData;
7456 7728
7729 if (le16_to_cpu(log_entry->LogEntryQualifier)
7730 != MPT2_WARPDRIVE_LOGENTRY)
7731 break;
7732
7733 switch (le32_to_cpu(*log_code)) {
7734 case MPT2_WARPDRIVE_LC_SSDT:
7735 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7736 "IO Throttling has occurred in the WarpDrive "
7737 "subsystem. Check WarpDrive documentation for "
7738 "additional details.\n", ioc->name);
7739 break;
7740 case MPT2_WARPDRIVE_LC_SSDLW:
7741 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7742 "Program/Erase Cycles for the WarpDrive subsystem "
7743 "in degraded range. Check WarpDrive documentation "
7744 "for additional details.\n", ioc->name);
7745 break;
7746 case MPT2_WARPDRIVE_LC_SSDLF:
7747 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7748 "There are no Program/Erase Cycles for the "
7749 "WarpDrive subsystem. The storage device will be "
7750 "in read-only mode. Check WarpDrive documentation "
7751 "for additional details.\n", ioc->name);
7752 break;
7753 case MPT2_WARPDRIVE_LC_BRMF:
7754 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7755 "The Backup Rail Monitor has failed on the "
7756 "WarpDrive subsystem. Check WarpDrive "
7757 "documentation for additional details.\n",
7758 ioc->name);
7759 break;
7760 }
7761
7762 break;
7763 }
7457 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: 7764 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7458 case MPI2_EVENT_IR_OPERATION_STATUS: 7765 case MPI2_EVENT_IR_OPERATION_STATUS:
7459 case MPI2_EVENT_SAS_DISCOVERY: 7766 case MPI2_EVENT_SAS_DISCOVERY:
@@ -7472,7 +7779,7 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7472 } 7779 }
7473 7780
7474 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; 7781 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7475 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC); 7782 fw_event = alloc_fw_event_work(sz);
7476 if (!fw_event) { 7783 if (!fw_event) {
7477 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", 7784 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7478 ioc->name, __FILE__, __LINE__, __func__); 7785 ioc->name, __FILE__, __LINE__, __func__);
@@ -7485,39 +7792,10 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7485 fw_event->VP_ID = mpi_reply->VP_ID; 7792 fw_event->VP_ID = mpi_reply->VP_ID;
7486 fw_event->event = event; 7793 fw_event->event = event;
7487 _scsih_fw_event_add(ioc, fw_event); 7794 _scsih_fw_event_add(ioc, fw_event);
7795 fw_event_work_put(fw_event);
7488 return 1; 7796 return 1;
7489} 7797}
7490 7798
7491/* shost template */
7492static struct scsi_host_template scsih_driver_template = {
7493 .module = THIS_MODULE,
7494 .name = "Fusion MPT SAS Host",
7495 .proc_name = MPT3SAS_DRIVER_NAME,
7496 .queuecommand = _scsih_qcmd,
7497 .target_alloc = _scsih_target_alloc,
7498 .slave_alloc = _scsih_slave_alloc,
7499 .slave_configure = _scsih_slave_configure,
7500 .target_destroy = _scsih_target_destroy,
7501 .slave_destroy = _scsih_slave_destroy,
7502 .scan_finished = _scsih_scan_finished,
7503 .scan_start = _scsih_scan_start,
7504 .change_queue_depth = _scsih_change_queue_depth,
7505 .eh_abort_handler = _scsih_abort,
7506 .eh_device_reset_handler = _scsih_dev_reset,
7507 .eh_target_reset_handler = _scsih_target_reset,
7508 .eh_host_reset_handler = _scsih_host_reset,
7509 .bios_param = _scsih_bios_param,
7510 .can_queue = 1,
7511 .this_id = -1,
7512 .sg_tablesize = MPT3SAS_SG_DEPTH,
7513 .max_sectors = 32767,
7514 .cmd_per_lun = 7,
7515 .use_clustering = ENABLE_CLUSTERING,
7516 .shost_attrs = mpt3sas_host_attrs,
7517 .sdev_attrs = mpt3sas_dev_attrs,
7518 .track_queue_depth = 1,
7519};
7520
7521/** 7799/**
7522 * _scsih_expander_node_remove - removing expander device from list. 7800 * _scsih_expander_node_remove - removing expander device from list.
7523 * @ioc: per adapter object 7801 * @ioc: per adapter object
@@ -7613,7 +7891,8 @@ _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7613 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; 7891 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7614 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; 7892 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7615 7893
7616 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); 7894 if (!ioc->hide_ir_msg)
7895 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7617 init_completion(&ioc->scsih_cmds.done); 7896 init_completion(&ioc->scsih_cmds.done);
7618 mpt3sas_base_put_smid_default(ioc, smid); 7897 mpt3sas_base_put_smid_default(ioc, smid);
7619 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); 7898 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
@@ -7626,10 +7905,11 @@ _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7626 7905
7627 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { 7906 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7628 mpi_reply = ioc->scsih_cmds.reply; 7907 mpi_reply = ioc->scsih_cmds.reply;
7629 pr_info(MPT3SAS_FMT 7908 if (!ioc->hide_ir_msg)
7630 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n", 7909 pr_info(MPT3SAS_FMT "IR shutdown "
7631 ioc->name, le16_to_cpu(mpi_reply->IOCStatus), 7910 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7632 le32_to_cpu(mpi_reply->IOCLogInfo)); 7911 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7912 le32_to_cpu(mpi_reply->IOCLogInfo));
7633 } 7913 }
7634 7914
7635 out: 7915 out:
@@ -7638,13 +7918,13 @@ _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7638} 7918}
7639 7919
7640/** 7920/**
7641 * _scsih_remove - detach and remove add host 7921 * scsih_remove - detach and remove add host
7642 * @pdev: PCI device struct 7922 * @pdev: PCI device struct
7643 * 7923 *
7644 * Routine called when unloading the driver. 7924 * Routine called when unloading the driver.
7645 * Return nothing. 7925 * Return nothing.
7646 */ 7926 */
7647static void _scsih_remove(struct pci_dev *pdev) 7927void scsih_remove(struct pci_dev *pdev)
7648{ 7928{
7649 struct Scsi_Host *shost = pci_get_drvdata(pdev); 7929 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7650 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 7930 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -7705,18 +7985,20 @@ static void _scsih_remove(struct pci_dev *pdev)
7705 sas_remove_host(shost); 7985 sas_remove_host(shost);
7706 scsi_remove_host(shost); 7986 scsi_remove_host(shost);
7707 mpt3sas_base_detach(ioc); 7987 mpt3sas_base_detach(ioc);
7988 spin_lock(&gioc_lock);
7708 list_del(&ioc->list); 7989 list_del(&ioc->list);
7990 spin_unlock(&gioc_lock);
7709 scsi_host_put(shost); 7991 scsi_host_put(shost);
7710} 7992}
7711 7993
7712/** 7994/**
7713 * _scsih_shutdown - routine call during system shutdown 7995 * scsih_shutdown - routine call during system shutdown
7714 * @pdev: PCI device struct 7996 * @pdev: PCI device struct
7715 * 7997 *
7716 * Return nothing. 7998 * Return nothing.
7717 */ 7999 */
7718static void 8000void
7719_scsih_shutdown(struct pci_dev *pdev) 8001scsih_shutdown(struct pci_dev *pdev)
7720{ 8002{
7721 struct Scsi_Host *shost = pci_get_drvdata(pdev); 8003 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7722 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8004 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -7794,6 +8076,8 @@ _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7794 list_move_tail(&sas_device->list, &ioc->sas_device_list); 8076 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7795 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 8077 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7796 8078
8079 if (ioc->hide_drives)
8080 return;
7797 if (!mpt3sas_transport_port_add(ioc, handle, 8081 if (!mpt3sas_transport_port_add(ioc, handle,
7798 sas_address_parent)) { 8082 sas_address_parent)) {
7799 _scsih_sas_device_remove(ioc, sas_device); 8083 _scsih_sas_device_remove(ioc, sas_device);
@@ -7831,6 +8115,48 @@ _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7831 } 8115 }
7832} 8116}
7833 8117
8118static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8119{
8120 struct _sas_device *sas_device = NULL;
8121 unsigned long flags;
8122
8123 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8124 if (!list_empty(&ioc->sas_device_init_list)) {
8125 sas_device = list_first_entry(&ioc->sas_device_init_list,
8126 struct _sas_device, list);
8127 sas_device_get(sas_device);
8128 }
8129 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8130
8131 return sas_device;
8132}
8133
8134static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8135 struct _sas_device *sas_device)
8136{
8137 unsigned long flags;
8138
8139 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8140
8141 /*
8142 * Since we dropped the lock during the call to port_add(), we need to
8143 * be careful here that somebody else didn't move or delete this item
8144 * while we were busy with other things.
8145 *
8146 * If it was on the list, we need a put() for the reference the list
8147 * had. Either way, we need a get() for the destination list.
8148 */
8149 if (!list_empty(&sas_device->list)) {
8150 list_del_init(&sas_device->list);
8151 sas_device_put(sas_device);
8152 }
8153
8154 sas_device_get(sas_device);
8155 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8156
8157 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8158}
8159
7834/** 8160/**
7835 * _scsih_probe_sas - reporting sas devices to sas transport 8161 * _scsih_probe_sas - reporting sas devices to sas transport
7836 * @ioc: per adapter object 8162 * @ioc: per adapter object
@@ -7840,17 +8166,16 @@ _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7840static void 8166static void
7841_scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) 8167_scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7842{ 8168{
7843 struct _sas_device *sas_device, *next; 8169 struct _sas_device *sas_device;
7844 unsigned long flags;
7845 8170
7846 /* SAS Device List */ 8171 if (ioc->hide_drives)
7847 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, 8172 return;
7848 list) {
7849 8173
8174 while ((sas_device = get_next_sas_device(ioc))) {
7850 if (!mpt3sas_transport_port_add(ioc, sas_device->handle, 8175 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7851 sas_device->sas_address_parent)) { 8176 sas_device->sas_address_parent)) {
7852 list_del(&sas_device->list); 8177 _scsih_sas_device_remove(ioc, sas_device);
7853 kfree(sas_device); 8178 sas_device_put(sas_device);
7854 continue; 8179 continue;
7855 } else if (!sas_device->starget) { 8180 } else if (!sas_device->starget) {
7856 /* 8181 /*
@@ -7863,15 +8188,13 @@ _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7863 mpt3sas_transport_port_remove(ioc, 8188 mpt3sas_transport_port_remove(ioc,
7864 sas_device->sas_address, 8189 sas_device->sas_address,
7865 sas_device->sas_address_parent); 8190 sas_device->sas_address_parent);
7866 list_del(&sas_device->list); 8191 _scsih_sas_device_remove(ioc, sas_device);
7867 kfree(sas_device); 8192 sas_device_put(sas_device);
7868 continue; 8193 continue;
7869 } 8194 }
7870 } 8195 }
7871 8196 sas_device_make_active(ioc, sas_device);
7872 spin_lock_irqsave(&ioc->sas_device_lock, flags); 8197 sas_device_put(sas_device);
7873 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7874 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7875 } 8198 }
7876} 8199}
7877 8200
@@ -7908,15 +8231,15 @@ _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7908} 8231}
7909 8232
7910/** 8233/**
7911 * _scsih_scan_start - scsi lld callback for .scan_start 8234 * scsih_scan_start - scsi lld callback for .scan_start
7912 * @shost: SCSI host pointer 8235 * @shost: SCSI host pointer
7913 * 8236 *
7914 * The shost has the ability to discover targets on its own instead 8237 * The shost has the ability to discover targets on its own instead
7915 * of scanning the entire bus. In our implemention, we will kick off 8238 * of scanning the entire bus. In our implemention, we will kick off
7916 * firmware discovery. 8239 * firmware discovery.
7917 */ 8240 */
7918static void 8241void
7919_scsih_scan_start(struct Scsi_Host *shost) 8242scsih_scan_start(struct Scsi_Host *shost)
7920{ 8243{
7921 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8244 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7922 int rc; 8245 int rc;
@@ -7934,7 +8257,7 @@ _scsih_scan_start(struct Scsi_Host *shost)
7934} 8257}
7935 8258
7936/** 8259/**
7937 * _scsih_scan_finished - scsi lld callback for .scan_finished 8260 * scsih_scan_finished - scsi lld callback for .scan_finished
7938 * @shost: SCSI host pointer 8261 * @shost: SCSI host pointer
7939 * @time: elapsed time of the scan in jiffies 8262 * @time: elapsed time of the scan in jiffies
7940 * 8263 *
@@ -7942,8 +8265,8 @@ _scsih_scan_start(struct Scsi_Host *shost)
7942 * scsi_host and the elapsed time of the scan in jiffies. In our implemention, 8265 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7943 * we wait for firmware discovery to complete, then return 1. 8266 * we wait for firmware discovery to complete, then return 1.
7944 */ 8267 */
7945static int 8268int
7946_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) 8269scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7947{ 8270{
7948 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8271 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7949 8272
@@ -7987,6 +8310,124 @@ _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7987 return 1; 8310 return 1;
7988} 8311}
7989 8312
8313/* shost template for SAS 2.0 HBA devices */
8314static struct scsi_host_template mpt2sas_driver_template = {
8315 .module = THIS_MODULE,
8316 .name = "Fusion MPT SAS Host",
8317 .proc_name = MPT2SAS_DRIVER_NAME,
8318 .queuecommand = scsih_qcmd,
8319 .target_alloc = scsih_target_alloc,
8320 .slave_alloc = scsih_slave_alloc,
8321 .slave_configure = scsih_slave_configure,
8322 .target_destroy = scsih_target_destroy,
8323 .slave_destroy = scsih_slave_destroy,
8324 .scan_finished = scsih_scan_finished,
8325 .scan_start = scsih_scan_start,
8326 .change_queue_depth = scsih_change_queue_depth,
8327 .eh_abort_handler = scsih_abort,
8328 .eh_device_reset_handler = scsih_dev_reset,
8329 .eh_target_reset_handler = scsih_target_reset,
8330 .eh_host_reset_handler = scsih_host_reset,
8331 .bios_param = scsih_bios_param,
8332 .can_queue = 1,
8333 .this_id = -1,
8334 .sg_tablesize = MPT2SAS_SG_DEPTH,
8335 .max_sectors = 32767,
8336 .cmd_per_lun = 7,
8337 .use_clustering = ENABLE_CLUSTERING,
8338 .shost_attrs = mpt3sas_host_attrs,
8339 .sdev_attrs = mpt3sas_dev_attrs,
8340 .track_queue_depth = 1,
8341};
8342
8343/* raid transport support for SAS 2.0 HBA devices */
8344static struct raid_function_template mpt2sas_raid_functions = {
8345 .cookie = &mpt2sas_driver_template,
8346 .is_raid = scsih_is_raid,
8347 .get_resync = scsih_get_resync,
8348 .get_state = scsih_get_state,
8349};
8350
8351/* shost template for SAS 3.0 HBA devices */
8352static struct scsi_host_template mpt3sas_driver_template = {
8353 .module = THIS_MODULE,
8354 .name = "Fusion MPT SAS Host",
8355 .proc_name = MPT3SAS_DRIVER_NAME,
8356 .queuecommand = scsih_qcmd,
8357 .target_alloc = scsih_target_alloc,
8358 .slave_alloc = scsih_slave_alloc,
8359 .slave_configure = scsih_slave_configure,
8360 .target_destroy = scsih_target_destroy,
8361 .slave_destroy = scsih_slave_destroy,
8362 .scan_finished = scsih_scan_finished,
8363 .scan_start = scsih_scan_start,
8364 .change_queue_depth = scsih_change_queue_depth,
8365 .eh_abort_handler = scsih_abort,
8366 .eh_device_reset_handler = scsih_dev_reset,
8367 .eh_target_reset_handler = scsih_target_reset,
8368 .eh_host_reset_handler = scsih_host_reset,
8369 .bios_param = scsih_bios_param,
8370 .can_queue = 1,
8371 .this_id = -1,
8372 .sg_tablesize = MPT3SAS_SG_DEPTH,
8373 .max_sectors = 32767,
8374 .cmd_per_lun = 7,
8375 .use_clustering = ENABLE_CLUSTERING,
8376 .shost_attrs = mpt3sas_host_attrs,
8377 .sdev_attrs = mpt3sas_dev_attrs,
8378 .track_queue_depth = 1,
8379};
8380
8381/* raid transport support for SAS 3.0 HBA devices */
8382static struct raid_function_template mpt3sas_raid_functions = {
8383 .cookie = &mpt3sas_driver_template,
8384 .is_raid = scsih_is_raid,
8385 .get_resync = scsih_get_resync,
8386 .get_state = scsih_get_state,
8387};
8388
8389/**
8390 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8391 * this device belongs to.
8392 * @pdev: PCI device struct
8393 *
8394 * return MPI2_VERSION for SAS 2.0 HBA devices,
8395 * MPI25_VERSION for SAS 3.0 HBA devices.
8396 */
8397u16
8398_scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8399{
8400
8401 switch (pdev->device) {
8402 case MPI2_MFGPAGE_DEVID_SSS6200:
8403 case MPI2_MFGPAGE_DEVID_SAS2004:
8404 case MPI2_MFGPAGE_DEVID_SAS2008:
8405 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8406 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8407 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8408 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8409 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8410 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8411 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8412 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8413 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8414 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8415 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8416 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8417 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8418 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8419 return MPI2_VERSION;
8420 case MPI25_MFGPAGE_DEVID_SAS3004:
8421 case MPI25_MFGPAGE_DEVID_SAS3008:
8422 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8423 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8424 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8425 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8426 return MPI25_VERSION;
8427 }
8428 return 0;
8429}
8430
7990/** 8431/**
7991 * _scsih_probe - attach and add scsi host 8432 * _scsih_probe - attach and add scsi host
7992 * @pdev: PCI device struct 8433 * @pdev: PCI device struct
@@ -7994,26 +8435,72 @@ _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7994 * 8435 *
7995 * Returns 0 success, anything else error. 8436 * Returns 0 success, anything else error.
7996 */ 8437 */
7997static int 8438int
7998_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) 8439_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7999{ 8440{
8000 struct MPT3SAS_ADAPTER *ioc; 8441 struct MPT3SAS_ADAPTER *ioc;
8001 struct Scsi_Host *shost; 8442 struct Scsi_Host *shost = NULL;
8002 int rv; 8443 int rv;
8444 u16 hba_mpi_version;
8003 8445
8004 shost = scsi_host_alloc(&scsih_driver_template, 8446 /* Determine in which MPI version class this pci device belongs */
8005 sizeof(struct MPT3SAS_ADAPTER)); 8447 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8006 if (!shost) 8448 if (hba_mpi_version == 0)
8007 return -ENODEV; 8449 return -ENODEV;
8008 8450
8009 /* init local params */ 8451 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8010 ioc = shost_priv(shost); 8452 * for other generation HBA's return with -ENODEV
8011 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); 8453 */
8454 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8455 return -ENODEV;
8456
8457 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8458 * for other generation HBA's return with -ENODEV
8459 */
8460 if ((hbas_to_enumerate == 2) && (hba_mpi_version != MPI25_VERSION))
8461 return -ENODEV;
8462
8463 switch (hba_mpi_version) {
8464 case MPI2_VERSION:
8465 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8466 shost = scsi_host_alloc(&mpt2sas_driver_template,
8467 sizeof(struct MPT3SAS_ADAPTER));
8468 if (!shost)
8469 return -ENODEV;
8470 ioc = shost_priv(shost);
8471 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8472 ioc->hba_mpi_version_belonged = hba_mpi_version;
8473 ioc->id = mpt2_ids++;
8474 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8475 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8476 ioc->is_warpdrive = 1;
8477 ioc->hide_ir_msg = 1;
8478 } else
8479 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8480 break;
8481 case MPI25_VERSION:
8482 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8483 shost = scsi_host_alloc(&mpt3sas_driver_template,
8484 sizeof(struct MPT3SAS_ADAPTER));
8485 if (!shost)
8486 return -ENODEV;
8487 ioc = shost_priv(shost);
8488 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8489 ioc->hba_mpi_version_belonged = hba_mpi_version;
8490 ioc->id = mpt3_ids++;
8491 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8492 if (pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION)
8493 ioc->msix96_vector = 1;
8494 break;
8495 default:
8496 return -ENODEV;
8497 }
8498
8012 INIT_LIST_HEAD(&ioc->list); 8499 INIT_LIST_HEAD(&ioc->list);
8500 spin_lock(&gioc_lock);
8013 list_add_tail(&ioc->list, &mpt3sas_ioc_list); 8501 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8502 spin_unlock(&gioc_lock);
8014 ioc->shost = shost; 8503 ioc->shost = shost;
8015 ioc->id = mpt_ids++;
8016 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
8017 ioc->pdev = pdev; 8504 ioc->pdev = pdev;
8018 ioc->scsi_io_cb_idx = scsi_io_cb_idx; 8505 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8019 ioc->tm_cb_idx = tm_cb_idx; 8506 ioc->tm_cb_idx = tm_cb_idx;
@@ -8030,6 +8517,8 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8030 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; 8517 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8031 /* misc semaphores and spin locks */ 8518 /* misc semaphores and spin locks */
8032 mutex_init(&ioc->reset_in_progress_mutex); 8519 mutex_init(&ioc->reset_in_progress_mutex);
8520 /* initializing pci_access_mutex lock */
8521 mutex_init(&ioc->pci_access_mutex);
8033 spin_lock_init(&ioc->ioc_reset_in_progress_lock); 8522 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8034 spin_lock_init(&ioc->scsi_lookup_lock); 8523 spin_lock_init(&ioc->scsi_lookup_lock);
8035 spin_lock_init(&ioc->sas_device_lock); 8524 spin_lock_init(&ioc->sas_device_lock);
@@ -8048,6 +8537,8 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8048 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); 8537 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8049 INIT_LIST_HEAD(&ioc->reply_queue_list); 8538 INIT_LIST_HEAD(&ioc->reply_queue_list);
8050 8539
8540 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8541
8051 /* init shost parameters */ 8542 /* init shost parameters */
8052 shost->max_cmd_len = 32; 8543 shost->max_cmd_len = 32;
8053 shost->max_lun = max_lun; 8544 shost->max_lun = max_lun;
@@ -8086,7 +8577,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8086 8577
8087 /* event thread */ 8578 /* event thread */
8088 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), 8579 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8089 "fw_event%d", ioc->id); 8580 "fw_event_%s%d", ioc->driver_name, ioc->id);
8090 ioc->firmware_event_thread = alloc_ordered_workqueue( 8581 ioc->firmware_event_thread = alloc_ordered_workqueue(
8091 ioc->firmware_event_name, WQ_MEM_RECLAIM); 8582 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8092 if (!ioc->firmware_event_thread) { 8583 if (!ioc->firmware_event_thread) {
@@ -8103,6 +8594,21 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8103 rv = -ENODEV; 8594 rv = -ENODEV;
8104 goto out_attach_fail; 8595 goto out_attach_fail;
8105 } 8596 }
8597
8598 if (ioc->is_warpdrive) {
8599 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8600 ioc->hide_drives = 0;
8601 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8602 ioc->hide_drives = 1;
8603 else {
8604 if (mpt3sas_get_num_volumes(ioc))
8605 ioc->hide_drives = 1;
8606 else
8607 ioc->hide_drives = 0;
8608 }
8609 } else
8610 ioc->hide_drives = 0;
8611
8106 rv = scsi_add_host(shost, &pdev->dev); 8612 rv = scsi_add_host(shost, &pdev->dev);
8107 if (rv) { 8613 if (rv) {
8108 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", 8614 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
@@ -8117,21 +8623,23 @@ out_add_shost_fail:
8117 out_attach_fail: 8623 out_attach_fail:
8118 destroy_workqueue(ioc->firmware_event_thread); 8624 destroy_workqueue(ioc->firmware_event_thread);
8119 out_thread_fail: 8625 out_thread_fail:
8626 spin_lock(&gioc_lock);
8120 list_del(&ioc->list); 8627 list_del(&ioc->list);
8628 spin_unlock(&gioc_lock);
8121 scsi_host_put(shost); 8629 scsi_host_put(shost);
8122 return rv; 8630 return rv;
8123} 8631}
8124 8632
8125#ifdef CONFIG_PM 8633#ifdef CONFIG_PM
8126/** 8634/**
8127 * _scsih_suspend - power management suspend main entry point 8635 * scsih_suspend - power management suspend main entry point
8128 * @pdev: PCI device struct 8636 * @pdev: PCI device struct
8129 * @state: PM state change to (usually PCI_D3) 8637 * @state: PM state change to (usually PCI_D3)
8130 * 8638 *
8131 * Returns 0 success, anything else error. 8639 * Returns 0 success, anything else error.
8132 */ 8640 */
8133static int 8641int
8134_scsih_suspend(struct pci_dev *pdev, pm_message_t state) 8642scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8135{ 8643{
8136 struct Scsi_Host *shost = pci_get_drvdata(pdev); 8644 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8137 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8645 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -8152,13 +8660,13 @@ _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8152} 8660}
8153 8661
8154/** 8662/**
8155 * _scsih_resume - power management resume main entry point 8663 * scsih_resume - power management resume main entry point
8156 * @pdev: PCI device struct 8664 * @pdev: PCI device struct
8157 * 8665 *
8158 * Returns 0 success, anything else error. 8666 * Returns 0 success, anything else error.
8159 */ 8667 */
8160static int 8668int
8161_scsih_resume(struct pci_dev *pdev) 8669scsih_resume(struct pci_dev *pdev)
8162{ 8670{
8163 struct Scsi_Host *shost = pci_get_drvdata(pdev); 8671 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8164 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8672 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -8185,7 +8693,7 @@ _scsih_resume(struct pci_dev *pdev)
8185#endif /* CONFIG_PM */ 8693#endif /* CONFIG_PM */
8186 8694
8187/** 8695/**
8188 * _scsih_pci_error_detected - Called when a PCI error is detected. 8696 * scsih_pci_error_detected - Called when a PCI error is detected.
8189 * @pdev: PCI device struct 8697 * @pdev: PCI device struct
8190 * @state: PCI channel state 8698 * @state: PCI channel state
8191 * 8699 *
@@ -8194,8 +8702,8 @@ _scsih_resume(struct pci_dev *pdev)
8194 * Return value: 8702 * Return value:
8195 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT 8703 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8196 */ 8704 */
8197static pci_ers_result_t 8705pci_ers_result_t
8198_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) 8706scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8199{ 8707{
8200 struct Scsi_Host *shost = pci_get_drvdata(pdev); 8708 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8201 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8709 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -8224,15 +8732,15 @@ _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8224} 8732}
8225 8733
8226/** 8734/**
8227 * _scsih_pci_slot_reset - Called when PCI slot has been reset. 8735 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8228 * @pdev: PCI device struct 8736 * @pdev: PCI device struct
8229 * 8737 *
8230 * Description: This routine is called by the pci error recovery 8738 * Description: This routine is called by the pci error recovery
8231 * code after the PCI slot has been reset, just before we 8739 * code after the PCI slot has been reset, just before we
8232 * should resume normal operations. 8740 * should resume normal operations.
8233 */ 8741 */
8234static pci_ers_result_t 8742pci_ers_result_t
8235_scsih_pci_slot_reset(struct pci_dev *pdev) 8743scsih_pci_slot_reset(struct pci_dev *pdev)
8236{ 8744{
8237 struct Scsi_Host *shost = pci_get_drvdata(pdev); 8745 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8238 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8746 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -8261,15 +8769,15 @@ _scsih_pci_slot_reset(struct pci_dev *pdev)
8261} 8769}
8262 8770
8263/** 8771/**
8264 * _scsih_pci_resume() - resume normal ops after PCI reset 8772 * scsih_pci_resume() - resume normal ops after PCI reset
8265 * @pdev: pointer to PCI device 8773 * @pdev: pointer to PCI device
8266 * 8774 *
8267 * Called when the error recovery driver tells us that its 8775 * Called when the error recovery driver tells us that its
8268 * OK to resume normal operation. Use completion to allow 8776 * OK to resume normal operation. Use completion to allow
8269 * halted scsi ops to resume. 8777 * halted scsi ops to resume.
8270 */ 8778 */
8271static void 8779void
8272_scsih_pci_resume(struct pci_dev *pdev) 8780scsih_pci_resume(struct pci_dev *pdev)
8273{ 8781{
8274 struct Scsi_Host *shost = pci_get_drvdata(pdev); 8782 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8275 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8783 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -8282,11 +8790,11 @@ _scsih_pci_resume(struct pci_dev *pdev)
8282} 8790}
8283 8791
8284/** 8792/**
8285 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers 8793 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8286 * @pdev: pointer to PCI device 8794 * @pdev: pointer to PCI device
8287 */ 8795 */
8288static pci_ers_result_t 8796pci_ers_result_t
8289_scsih_pci_mmio_enabled(struct pci_dev *pdev) 8797scsih_pci_mmio_enabled(struct pci_dev *pdev)
8290{ 8798{
8291 struct Scsi_Host *shost = pci_get_drvdata(pdev); 8799 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8292 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); 8800 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
@@ -8300,61 +8808,99 @@ _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8300 return PCI_ERS_RESULT_NEED_RESET; 8808 return PCI_ERS_RESULT_NEED_RESET;
8301} 8809}
8302 8810
8303/* raid transport support */ 8811/*
8304static struct raid_function_template mpt3sas_raid_functions = { 8812 * The pci device ids are defined in mpi/mpi2_cnfg.h.
8305 .cookie = &scsih_driver_template, 8813 */
8306 .is_raid = _scsih_is_raid, 8814static const struct pci_device_id mpt3sas_pci_table[] = {
8307 .get_resync = _scsih_get_resync, 8815 /* Spitfire ~ 2004 */
8308 .get_state = _scsih_get_state, 8816 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
8817 PCI_ANY_ID, PCI_ANY_ID },
8818 /* Falcon ~ 2008 */
8819 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
8820 PCI_ANY_ID, PCI_ANY_ID },
8821 /* Liberator ~ 2108 */
8822 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
8823 PCI_ANY_ID, PCI_ANY_ID },
8824 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
8825 PCI_ANY_ID, PCI_ANY_ID },
8826 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
8827 PCI_ANY_ID, PCI_ANY_ID },
8828 /* Meteor ~ 2116 */
8829 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
8830 PCI_ANY_ID, PCI_ANY_ID },
8831 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
8832 PCI_ANY_ID, PCI_ANY_ID },
8833 /* Thunderbolt ~ 2208 */
8834 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
8835 PCI_ANY_ID, PCI_ANY_ID },
8836 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
8837 PCI_ANY_ID, PCI_ANY_ID },
8838 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
8839 PCI_ANY_ID, PCI_ANY_ID },
8840 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
8841 PCI_ANY_ID, PCI_ANY_ID },
8842 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
8843 PCI_ANY_ID, PCI_ANY_ID },
8844 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
8845 PCI_ANY_ID, PCI_ANY_ID },
8846 /* Mustang ~ 2308 */
8847 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
8848 PCI_ANY_ID, PCI_ANY_ID },
8849 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
8850 PCI_ANY_ID, PCI_ANY_ID },
8851 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
8852 PCI_ANY_ID, PCI_ANY_ID },
8853 /* SSS6200 */
8854 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
8855 PCI_ANY_ID, PCI_ANY_ID },
8856 /* Fury ~ 3004 and 3008 */
8857 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
8858 PCI_ANY_ID, PCI_ANY_ID },
8859 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
8860 PCI_ANY_ID, PCI_ANY_ID },
8861 /* Invader ~ 3108 */
8862 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
8863 PCI_ANY_ID, PCI_ANY_ID },
8864 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
8865 PCI_ANY_ID, PCI_ANY_ID },
8866 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
8867 PCI_ANY_ID, PCI_ANY_ID },
8868 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
8869 PCI_ANY_ID, PCI_ANY_ID },
8870 {0} /* Terminating entry */
8309}; 8871};
8872MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
8310 8873
8311static struct pci_error_handlers _scsih_err_handler = { 8874static struct pci_error_handlers _mpt3sas_err_handler = {
8312 .error_detected = _scsih_pci_error_detected, 8875 .error_detected = scsih_pci_error_detected,
8313 .mmio_enabled = _scsih_pci_mmio_enabled, 8876 .mmio_enabled = scsih_pci_mmio_enabled,
8314 .slot_reset = _scsih_pci_slot_reset, 8877 .slot_reset = scsih_pci_slot_reset,
8315 .resume = _scsih_pci_resume, 8878 .resume = scsih_pci_resume,
8316}; 8879};
8317 8880
8318static struct pci_driver scsih_driver = { 8881static struct pci_driver mpt3sas_driver = {
8319 .name = MPT3SAS_DRIVER_NAME, 8882 .name = MPT3SAS_DRIVER_NAME,
8320 .id_table = scsih_pci_table, 8883 .id_table = mpt3sas_pci_table,
8321 .probe = _scsih_probe, 8884 .probe = _scsih_probe,
8322 .remove = _scsih_remove, 8885 .remove = scsih_remove,
8323 .shutdown = _scsih_shutdown, 8886 .shutdown = scsih_shutdown,
8324 .err_handler = &_scsih_err_handler, 8887 .err_handler = &_mpt3sas_err_handler,
8325#ifdef CONFIG_PM 8888#ifdef CONFIG_PM
8326 .suspend = _scsih_suspend, 8889 .suspend = scsih_suspend,
8327 .resume = _scsih_resume, 8890 .resume = scsih_resume,
8328#endif 8891#endif
8329}; 8892};
8330 8893
8331
8332/** 8894/**
8333 * _scsih_init - main entry point for this driver. 8895 * scsih_init - main entry point for this driver.
8334 * 8896 *
8335 * Returns 0 success, anything else error. 8897 * Returns 0 success, anything else error.
8336 */ 8898 */
8337static int __init 8899int
8338_scsih_init(void) 8900scsih_init(void)
8339{ 8901{
8340 int error; 8902 mpt2_ids = 0;
8341 8903 mpt3_ids = 0;
8342 mpt_ids = 0;
8343
8344 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8345 MPT3SAS_DRIVER_VERSION);
8346
8347 mpt3sas_transport_template =
8348 sas_attach_transport(&mpt3sas_transport_functions);
8349 if (!mpt3sas_transport_template)
8350 return -ENODEV;
8351
8352/* raid transport support */
8353 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8354 if (!mpt3sas_raid_template) {
8355 sas_release_transport(mpt3sas_transport_template);
8356 return -ENODEV;
8357 }
8358 8904
8359 mpt3sas_base_initialize_callback_handler(); 8905 mpt3sas_base_initialize_callback_handler();
8360 8906
@@ -8392,33 +8938,17 @@ _scsih_init(void)
8392 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( 8938 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8393 _scsih_sas_control_complete); 8939 _scsih_sas_control_complete);
8394 8940
8395 mpt3sas_ctl_init(); 8941 return 0;
8396
8397 error = pci_register_driver(&scsih_driver);
8398 if (error) {
8399 /* raid transport support */
8400 raid_class_release(mpt3sas_raid_template);
8401 sas_release_transport(mpt3sas_transport_template);
8402 }
8403
8404 return error;
8405} 8942}
8406 8943
8407/** 8944/**
8408 * _scsih_exit - exit point for this driver (when it is a module). 8945 * scsih_exit - exit point for this driver (when it is a module).
8409 * 8946 *
8410 * Returns 0 success, anything else error. 8947 * Returns 0 success, anything else error.
8411 */ 8948 */
8412static void __exit 8949void
8413_scsih_exit(void) 8950scsih_exit(void)
8414{ 8951{
8415 pr_info("mpt3sas version %s unloading\n",
8416 MPT3SAS_DRIVER_VERSION);
8417
8418 mpt3sas_ctl_exit();
8419
8420 pci_unregister_driver(&scsih_driver);
8421
8422 8952
8423 mpt3sas_base_release_callback_handler(scsi_io_cb_idx); 8953 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8424 mpt3sas_base_release_callback_handler(tm_cb_idx); 8954 mpt3sas_base_release_callback_handler(tm_cb_idx);
@@ -8434,9 +8964,86 @@ _scsih_exit(void)
8434 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); 8964 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8435 8965
8436/* raid transport support */ 8966/* raid transport support */
8437 raid_class_release(mpt3sas_raid_template); 8967 if (hbas_to_enumerate != 1)
8968 raid_class_release(mpt3sas_raid_template);
8969 if (hbas_to_enumerate != 2)
8970 raid_class_release(mpt2sas_raid_template);
8438 sas_release_transport(mpt3sas_transport_template); 8971 sas_release_transport(mpt3sas_transport_template);
8439} 8972}
8440 8973
8441module_init(_scsih_init); 8974/**
8442module_exit(_scsih_exit); 8975 * _mpt3sas_init - main entry point for this driver.
8976 *
8977 * Returns 0 success, anything else error.
8978 */
8979static int __init
8980_mpt3sas_init(void)
8981{
8982 int error;
8983
8984 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8985 MPT3SAS_DRIVER_VERSION);
8986
8987 mpt3sas_transport_template =
8988 sas_attach_transport(&mpt3sas_transport_functions);
8989 if (!mpt3sas_transport_template)
8990 return -ENODEV;
8991
8992 /* No need attach mpt3sas raid functions template
8993 * if hbas_to_enumarate value is one.
8994 */
8995 if (hbas_to_enumerate != 1) {
8996 mpt3sas_raid_template =
8997 raid_class_attach(&mpt3sas_raid_functions);
8998 if (!mpt3sas_raid_template) {
8999 sas_release_transport(mpt3sas_transport_template);
9000 return -ENODEV;
9001 }
9002 }
9003
9004 /* No need to attach mpt2sas raid functions template
9005 * if hbas_to_enumarate value is two
9006 */
9007 if (hbas_to_enumerate != 2) {
9008 mpt2sas_raid_template =
9009 raid_class_attach(&mpt2sas_raid_functions);
9010 if (!mpt2sas_raid_template) {
9011 sas_release_transport(mpt3sas_transport_template);
9012 return -ENODEV;
9013 }
9014 }
9015
9016 error = scsih_init();
9017 if (error) {
9018 scsih_exit();
9019 return error;
9020 }
9021
9022 mpt3sas_ctl_init(hbas_to_enumerate);
9023
9024 error = pci_register_driver(&mpt3sas_driver);
9025 if (error)
9026 scsih_exit();
9027
9028 return error;
9029}
9030
9031/**
9032 * _mpt3sas_exit - exit point for this driver (when it is a module).
9033 *
9034 */
9035static void __exit
9036_mpt3sas_exit(void)
9037{
9038 pr_info("mpt3sas version %s unloading\n",
9039 MPT3SAS_DRIVER_VERSION);
9040
9041 pci_unregister_driver(&mpt3sas_driver);
9042
9043 mpt3sas_ctl_exit(hbas_to_enumerate);
9044
9045 scsih_exit();
9046}
9047
9048module_init(_mpt3sas_init);
9049module_exit(_mpt3sas_exit);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
index 70fd019e7ee5..ca36d7ea0964 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
@@ -734,7 +734,7 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
734 rphy->identify = mpt3sas_port->remote_identify; 734 rphy->identify = mpt3sas_port->remote_identify;
735 735
736 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) { 736 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
737 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 737 sas_device = mpt3sas_get_sdev_by_addr(ioc,
738 mpt3sas_port->remote_identify.sas_address); 738 mpt3sas_port->remote_identify.sas_address);
739 if (!sas_device) { 739 if (!sas_device) {
740 dfailprintk(ioc, printk(MPT3SAS_FMT 740 dfailprintk(ioc, printk(MPT3SAS_FMT
@@ -750,8 +750,10 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
750 ioc->name, __FILE__, __LINE__, __func__); 750 ioc->name, __FILE__, __LINE__, __func__);
751 } 751 }
752 752
753 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) 753 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
754 sas_device->pend_sas_rphy_add = 0; 754 sas_device->pend_sas_rphy_add = 0;
755 sas_device_put(sas_device);
756 }
755 757
756 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) 758 if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
757 dev_printk(KERN_INFO, &rphy->dev, 759 dev_printk(KERN_INFO, &rphy->dev,
@@ -1324,15 +1326,17 @@ _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1324 int rc; 1326 int rc;
1325 1327
1326 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1328 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1327 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1329 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1328 rphy->identify.sas_address); 1330 rphy->identify.sas_address);
1329 if (sas_device) { 1331 if (sas_device) {
1330 *identifier = sas_device->enclosure_logical_id; 1332 *identifier = sas_device->enclosure_logical_id;
1331 rc = 0; 1333 rc = 0;
1334 sas_device_put(sas_device);
1332 } else { 1335 } else {
1333 *identifier = 0; 1336 *identifier = 0;
1334 rc = -ENXIO; 1337 rc = -ENXIO;
1335 } 1338 }
1339
1336 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1340 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1337 return rc; 1341 return rc;
1338} 1342}
@@ -1352,12 +1356,14 @@ _transport_get_bay_identifier(struct sas_rphy *rphy)
1352 int rc; 1356 int rc;
1353 1357
1354 spin_lock_irqsave(&ioc->sas_device_lock, flags); 1358 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1355 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, 1359 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1356 rphy->identify.sas_address); 1360 rphy->identify.sas_address);
1357 if (sas_device) 1361 if (sas_device) {
1358 rc = sas_device->slot; 1362 rc = sas_device->slot;
1359 else 1363 sas_device_put(sas_device);
1364 } else {
1360 rc = -ENXIO; 1365 rc = -ENXIO;
1366 }
1361 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1367 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1362 return rc; 1368 return rc;
1363} 1369}
diff --git a/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
new file mode 100644
index 000000000000..540bd5005149
--- /dev/null
+++ b/drivers/scsi/mpt3sas/mpt3sas_warpdrive.c
@@ -0,0 +1,344 @@
1/*
2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
3 *
4 * Copyright (C) 2012-2014 LSI Corporation
5 * Copyright (C) 2013-2015 Avago Technologies
6 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
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
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
37
38 * You should have received a copy of the GNU General Public License
39 * along with this program.
40 */
41#include <linux/kernel.h>
42#include <linux/module.h>
43#include <linux/errno.h>
44#include <linux/types.h>
45#include <asm/unaligned.h>
46
47#include "mpt3sas_base.h"
48
49/**
50 * _warpdrive_disable_ddio - Disable direct I/O for all the volumes
51 * @ioc: per adapter object
52 */
53static void
54_warpdrive_disable_ddio(struct MPT3SAS_ADAPTER *ioc)
55{
56 Mpi2RaidVolPage1_t vol_pg1;
57 Mpi2ConfigReply_t mpi_reply;
58 struct _raid_device *raid_device;
59 u16 handle;
60 u16 ioc_status;
61 unsigned long flags;
62
63 handle = 0xFFFF;
64 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
65 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
66 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
67 MPI2_IOCSTATUS_MASK;
68 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
69 break;
70 handle = le16_to_cpu(vol_pg1.DevHandle);
71 spin_lock_irqsave(&ioc->raid_device_lock, flags);
72 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
73 if (raid_device)
74 raid_device->direct_io_enabled = 0;
75 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
76 }
77 return;
78}
79
80
81/**
82 * mpt3sas_get_num_volumes - Get number of volumes in the ioc
83 * @ioc: per adapter object
84 */
85u8
86mpt3sas_get_num_volumes(struct MPT3SAS_ADAPTER *ioc)
87{
88 Mpi2RaidVolPage1_t vol_pg1;
89 Mpi2ConfigReply_t mpi_reply;
90 u16 handle;
91 u8 vol_cnt = 0;
92 u16 ioc_status;
93
94 handle = 0xFFFF;
95 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
96 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
97 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
98 MPI2_IOCSTATUS_MASK;
99 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
100 break;
101 vol_cnt++;
102 handle = le16_to_cpu(vol_pg1.DevHandle);
103 }
104 return vol_cnt;
105}
106
107
108/**
109 * mpt3sas_init_warpdrive_properties - Set properties for warpdrive direct I/O.
110 * @ioc: per adapter object
111 * @raid_device: the raid_device object
112 */
113void
114mpt3sas_init_warpdrive_properties(struct MPT3SAS_ADAPTER *ioc,
115 struct _raid_device *raid_device)
116{
117 Mpi2RaidVolPage0_t *vol_pg0;
118 Mpi2RaidPhysDiskPage0_t pd_pg0;
119 Mpi2ConfigReply_t mpi_reply;
120 u16 sz;
121 u8 num_pds, count;
122 unsigned long stripe_sz, block_sz;
123 u8 stripe_exp, block_exp;
124 u64 dev_max_lba;
125
126 if (!ioc->is_warpdrive)
127 return;
128
129 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
130 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
131 "globally as drives are exposed\n", ioc->name);
132 return;
133 }
134 if (mpt3sas_get_num_volumes(ioc) > 1) {
135 _warpdrive_disable_ddio(ioc);
136 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
137 "globally as number of drives > 1\n", ioc->name);
138 return;
139 }
140 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
141 &num_pds)) || !num_pds) {
142 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
143 "Failure in computing number of drives\n", ioc->name);
144 return;
145 }
146
147 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
148 sizeof(Mpi2RaidVol0PhysDisk_t));
149 vol_pg0 = kzalloc(sz, GFP_KERNEL);
150 if (!vol_pg0) {
151 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
152 "Memory allocation failure for RVPG0\n", ioc->name);
153 return;
154 }
155
156 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
157 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
158 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
159 "Failure in retrieving RVPG0\n", ioc->name);
160 kfree(vol_pg0);
161 return;
162 }
163
164 /*
165 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
166 * assumed for WARPDRIVE, disable direct I/O
167 */
168 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
169 pr_warn(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
170 "for the drive with handle(0x%04x): num_mem=%d, "
171 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
172 num_pds, MPT_MAX_WARPDRIVE_PDS);
173 kfree(vol_pg0);
174 return;
175 }
176 for (count = 0; count < num_pds; count++) {
177 if (mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
178 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
179 vol_pg0->PhysDisk[count].PhysDiskNum) ||
180 pd_pg0.DevHandle == MPT3SAS_INVALID_DEVICE_HANDLE) {
181 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is "
182 "disabled for the drive with handle(0x%04x) member"
183 "handle retrieval failed for member number=%d\n",
184 ioc->name, raid_device->handle,
185 vol_pg0->PhysDisk[count].PhysDiskNum);
186 goto out_error;
187 }
188 /* Disable direct I/O if member drive lba exceeds 4 bytes */
189 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
190 if (dev_max_lba >> 32) {
191 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is "
192 "disabled for the drive with handle(0x%04x) member"
193 " handle (0x%04x) unsupported max lba 0x%016llx\n",
194 ioc->name, raid_device->handle,
195 le16_to_cpu(pd_pg0.DevHandle),
196 (unsigned long long)dev_max_lba);
197 goto out_error;
198 }
199
200 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
201 }
202
203 /*
204 * Assumption for WD: Direct I/O is not supported if the volume is
205 * not RAID0
206 */
207 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
208 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
209 "for the drive with handle(0x%04x): type=%d, "
210 "s_sz=%uK, blk_size=%u\n", ioc->name,
211 raid_device->handle, raid_device->volume_type,
212 (le32_to_cpu(vol_pg0->StripeSize) *
213 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
214 le16_to_cpu(vol_pg0->BlockSize));
215 goto out_error;
216 }
217
218 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
219 stripe_exp = find_first_bit(&stripe_sz, 32);
220 if (stripe_exp == 32) {
221 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
222 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
223 ioc->name, raid_device->handle,
224 (le32_to_cpu(vol_pg0->StripeSize) *
225 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
226 goto out_error;
227 }
228 raid_device->stripe_exponent = stripe_exp;
229 block_sz = le16_to_cpu(vol_pg0->BlockSize);
230 block_exp = find_first_bit(&block_sz, 16);
231 if (block_exp == 16) {
232 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is disabled "
233 "for the drive with handle(0x%04x) invalid block sz %u\n",
234 ioc->name, raid_device->handle,
235 le16_to_cpu(vol_pg0->BlockSize));
236 goto out_error;
237 }
238 raid_device->block_exponent = block_exp;
239 raid_device->direct_io_enabled = 1;
240
241 pr_info(MPT3SAS_FMT "WarpDrive : Direct IO is Enabled for the drive"
242 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
243 /*
244 * WARPDRIVE: Though the following fields are not used for direct IO,
245 * stored for future purpose:
246 */
247 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
248 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
249 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
250
251
252 kfree(vol_pg0);
253 return;
254
255out_error:
256 raid_device->direct_io_enabled = 0;
257 for (count = 0; count < num_pds; count++)
258 raid_device->pd_handle[count] = 0;
259 kfree(vol_pg0);
260 return;
261}
262
263/**
264 * mpt3sas_scsi_direct_io_get - returns direct io flag
265 * @ioc: per adapter object
266 * @smid: system request message index
267 *
268 * Returns the smid stored scmd pointer.
269 */
270inline u8
271mpt3sas_scsi_direct_io_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
272{
273 return ioc->scsi_lookup[smid - 1].direct_io;
274}
275
276/**
277 * mpt3sas_scsi_direct_io_set - sets direct io flag
278 * @ioc: per adapter object
279 * @smid: system request message index
280 * @direct_io: Zero or non-zero value to set in the direct_io flag
281 *
282 * Returns Nothing.
283 */
284inline void
285mpt3sas_scsi_direct_io_set(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
286{
287 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
288}
289
290/**
291 * mpt3sas_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
292 * @ioc: per adapter object
293 * @scmd: pointer to scsi command object
294 * @raid_device: pointer to raid device data structure
295 * @mpi_request: pointer to the SCSI_IO reqest message frame
296 * @smid: system request message index
297 *
298 * Returns nothing
299 */
300void
301mpt3sas_setup_direct_io(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
302 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
303 u16 smid)
304{
305 sector_t v_lba, p_lba, stripe_off, column, io_size;
306 u32 stripe_sz, stripe_exp;
307 u8 num_pds, cmd = scmd->cmnd[0];
308
309 if (cmd != READ_10 && cmd != WRITE_10 &&
310 cmd != READ_16 && cmd != WRITE_16)
311 return;
312
313 if (cmd == READ_10 || cmd == WRITE_10)
314 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
315 else
316 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
317
318 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
319
320 if (v_lba + io_size - 1 > raid_device->max_lba)
321 return;
322
323 stripe_sz = raid_device->stripe_sz;
324 stripe_exp = raid_device->stripe_exponent;
325 stripe_off = v_lba & (stripe_sz - 1);
326
327 /* Return unless IO falls within a stripe */
328 if (stripe_off + io_size > stripe_sz)
329 return;
330
331 num_pds = raid_device->num_pds;
332 p_lba = v_lba >> stripe_exp;
333 column = sector_div(p_lba, num_pds);
334 p_lba = (p_lba << stripe_exp) + stripe_off;
335 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
336
337 if (cmd == READ_10 || cmd == WRITE_10)
338 put_unaligned_be32(lower_32_bits(p_lba),
339 &mpi_request->CDB.CDB32[2]);
340 else
341 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
342
343 mpt3sas_scsi_direct_io_set(ioc, smid, 1);
344}