aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/mpt2sas
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/mpt2sas')
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.c75
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.h33
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.c246
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.h7
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_scsih.c392
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_transport.c59
6 files changed, 606 insertions, 206 deletions
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c
index a91f5143ceac..f3da592f7bcc 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -636,6 +636,14 @@ _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
636static irqreturn_t 636static irqreturn_t
637_base_interrupt(int irq, void *bus_id) 637_base_interrupt(int irq, void *bus_id)
638{ 638{
639 union reply_descriptor {
640 u64 word;
641 struct {
642 u32 low;
643 u32 high;
644 } u;
645 };
646 union reply_descriptor rd;
639 u32 post_index, post_index_next, completed_cmds; 647 u32 post_index, post_index_next, completed_cmds;
640 u8 request_desript_type; 648 u8 request_desript_type;
641 u16 smid; 649 u16 smid;
@@ -656,7 +664,8 @@ _base_interrupt(int irq, void *bus_id)
656 664
657 completed_cmds = 0; 665 completed_cmds = 0;
658 do { 666 do {
659 if (ioc->reply_post_free[post_index].Words == ~0ULL) 667 rd.word = ioc->reply_post_free[post_index].Words;
668 if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
660 goto out; 669 goto out;
661 reply = 0; 670 reply = 0;
662 cb_idx = 0xFF; 671 cb_idx = 0xFF;
@@ -721,7 +730,7 @@ _base_interrupt(int irq, void *bus_id)
721 for (i = 0 ; i < completed_cmds; i++) { 730 for (i = 0 ; i < completed_cmds; i++) {
722 post_index = post_index_next; 731 post_index = post_index_next;
723 /* poison the reply post descriptor */ 732 /* poison the reply post descriptor */
724 ioc->reply_post_free[post_index_next].Words = ~0ULL; 733 ioc->reply_post_free[post_index_next].Words = ULLONG_MAX;
725 post_index_next = (post_index == 734 post_index_next = (post_index ==
726 (ioc->reply_post_queue_depth - 1)) 735 (ioc->reply_post_queue_depth - 1))
727 ? 0 : post_index + 1; 736 ? 0 : post_index + 1;
@@ -1387,6 +1396,64 @@ mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1387} 1396}
1388 1397
1389/** 1398/**
1399 * _base_display_dell_branding - Disply branding string
1400 * @ioc: per adapter object
1401 *
1402 * Return nothing.
1403 */
1404static void
1405_base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1406{
1407 char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
1408
1409 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
1410 return;
1411
1412 memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
1413 switch (ioc->pdev->subsystem_device) {
1414 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
1415 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
1416 MPT2SAS_DELL_BRANDING_SIZE - 1);
1417 break;
1418 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
1419 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
1420 MPT2SAS_DELL_BRANDING_SIZE - 1);
1421 break;
1422 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
1423 strncpy(dell_branding,
1424 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
1425 MPT2SAS_DELL_BRANDING_SIZE - 1);
1426 break;
1427 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
1428 strncpy(dell_branding,
1429 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
1430 MPT2SAS_DELL_BRANDING_SIZE - 1);
1431 break;
1432 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
1433 strncpy(dell_branding,
1434 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
1435 MPT2SAS_DELL_BRANDING_SIZE - 1);
1436 break;
1437 case MPT2SAS_DELL_PERC_H200_SSDID:
1438 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
1439 MPT2SAS_DELL_BRANDING_SIZE - 1);
1440 break;
1441 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
1442 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
1443 MPT2SAS_DELL_BRANDING_SIZE - 1);
1444 break;
1445 default:
1446 sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
1447 break;
1448 }
1449
1450 printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
1451 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
1452 ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
1453 ioc->pdev->subsystem_device);
1454}
1455
1456/**
1390 * _base_display_ioc_capabilities - Disply IOC's capabilities. 1457 * _base_display_ioc_capabilities - Disply IOC's capabilities.
1391 * @ioc: per adapter object 1458 * @ioc: per adapter object
1392 * 1459 *
@@ -1427,6 +1494,8 @@ _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
1427 i++; 1494 i++;
1428 } 1495 }
1429 1496
1497 _base_display_dell_branding(ioc);
1498
1430 i = 0; 1499 i = 0;
1431 printk("), "); 1500 printk("), ");
1432 printk("Capabilities=("); 1501 printk("Capabilities=(");
@@ -3068,7 +3137,7 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3068 3137
3069 /* initialize Reply Post Free Queue */ 3138 /* initialize Reply Post Free Queue */
3070 for (i = 0; i < ioc->reply_post_queue_depth; i++) 3139 for (i = 0; i < ioc->reply_post_queue_depth; i++)
3071 ioc->reply_post_free[i].Words = ~0ULL; 3140 ioc->reply_post_free[i].Words = ULLONG_MAX;
3072 3141
3073 r = _base_send_ioc_init(ioc, VF_ID, sleep_flag); 3142 r = _base_send_ioc_init(ioc, VF_ID, sleep_flag);
3074 if (r) 3143 if (r)
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h
index 6945ff4d382e..286c185fa9e4 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.h
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.h
@@ -61,6 +61,7 @@
61#include <scsi/scsi_tcq.h> 61#include <scsi/scsi_tcq.h>
62#include <scsi/scsi_transport_sas.h> 62#include <scsi/scsi_transport_sas.h>
63#include <scsi/scsi_dbg.h> 63#include <scsi/scsi_dbg.h>
64#include <scsi/scsi_eh.h>
64 65
65#include "mpt2sas_debug.h" 66#include "mpt2sas_debug.h"
66 67
@@ -68,11 +69,11 @@
68#define MPT2SAS_DRIVER_NAME "mpt2sas" 69#define MPT2SAS_DRIVER_NAME "mpt2sas"
69#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>" 70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>"
70#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" 71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver"
71#define MPT2SAS_DRIVER_VERSION "00.100.11.16" 72#define MPT2SAS_DRIVER_VERSION "01.100.03.00"
72#define MPT2SAS_MAJOR_VERSION 00 73#define MPT2SAS_MAJOR_VERSION 01
73#define MPT2SAS_MINOR_VERSION 100 74#define MPT2SAS_MINOR_VERSION 100
74#define MPT2SAS_BUILD_VERSION 11 75#define MPT2SAS_BUILD_VERSION 03
75#define MPT2SAS_RELEASE_VERSION 16 76#define MPT2SAS_RELEASE_VERSION 00
76 77
77/* 78/*
78 * Set MPT2SAS_SG_DEPTH value based on user input. 79 * Set MPT2SAS_SG_DEPTH value based on user input.
@@ -130,6 +131,30 @@
130#define MPT2SAS_ERR_FMT KERN_ERR MPT2SAS_FMT 131#define MPT2SAS_ERR_FMT KERN_ERR MPT2SAS_FMT
131 132
132/* 133/*
134 * Dell HBA branding
135 */
136#define MPT2SAS_DELL_BRANDING_SIZE 32
137
138#define MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING "Dell 6Gbps SAS HBA"
139#define MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING "Dell PERC H200 Adapter"
140#define MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING "Dell PERC H200 Integrated"
141#define MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING "Dell PERC H200 Modular"
142#define MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING "Dell PERC H200 Embedded"
143#define MPT2SAS_DELL_PERC_H200_BRANDING "Dell PERC H200"
144#define MPT2SAS_DELL_6GBPS_SAS_BRANDING "Dell 6Gbps SAS"
145
146/*
147 * Dell HBA SSDIDs
148 */
149#define MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID 0x1F1C
150#define MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID 0x1F1D
151#define MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID 0x1F1E
152#define MPT2SAS_DELL_PERC_H200_MODULAR_SSDID 0x1F1F
153#define MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID 0x1F20
154#define MPT2SAS_DELL_PERC_H200_SSDID 0x1F21
155#define MPT2SAS_DELL_6GBPS_SAS_SSDID 0x1F22
156
157/*
133 * per target private data 158 * per target private data
134 */ 159 */
135#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01 160#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 2d4f85c9d7a1..14e473d1fa7b 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -64,6 +64,9 @@
64static struct fasync_struct *async_queue; 64static struct fasync_struct *async_queue;
65static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait); 65static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
66 66
67static int _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type,
68 u8 *issue_reset);
69
67/** 70/**
68 * enum block_state - blocking state 71 * enum block_state - blocking state
69 * @NON_BLOCKING: non blocking 72 * @NON_BLOCKING: non blocking
@@ -378,10 +381,22 @@ _ctl_verify_adapter(int ioc_number, struct MPT2SAS_ADAPTER **iocpp)
378void 381void
379mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) 382mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
380{ 383{
384 int i;
385 u8 issue_reset;
386
381 switch (reset_phase) { 387 switch (reset_phase) {
382 case MPT2_IOC_PRE_RESET: 388 case MPT2_IOC_PRE_RESET:
383 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " 389 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
384 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); 390 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
391 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
392 if (!(ioc->diag_buffer_status[i] &
393 MPT2_DIAG_BUFFER_IS_REGISTERED))
394 continue;
395 if ((ioc->diag_buffer_status[i] &
396 MPT2_DIAG_BUFFER_IS_RELEASED))
397 continue;
398 _ctl_send_release(ioc, i, &issue_reset);
399 }
385 break; 400 break;
386 case MPT2_IOC_AFTER_RESET: 401 case MPT2_IOC_AFTER_RESET:
387 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " 402 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
@@ -395,6 +410,17 @@ mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
395 case MPT2_IOC_DONE_RESET: 410 case MPT2_IOC_DONE_RESET:
396 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " 411 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
397 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); 412 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
413
414 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
415 if (!(ioc->diag_buffer_status[i] &
416 MPT2_DIAG_BUFFER_IS_REGISTERED))
417 continue;
418 if ((ioc->diag_buffer_status[i] &
419 MPT2_DIAG_BUFFER_IS_RELEASED))
420 continue;
421 ioc->diag_buffer_status[i] |=
422 MPT2_DIAG_BUFFER_IS_DIAG_RESET;
423 }
398 break; 424 break;
399 } 425 }
400} 426}
@@ -447,7 +473,7 @@ _ctl_poll(struct file *filep, poll_table *wait)
447} 473}
448 474
449/** 475/**
450 * _ctl_do_task_abort - assign an active smid to the abort_task 476 * _ctl_set_task_mid - assign an active smid to tm request
451 * @ioc: per adapter object 477 * @ioc: per adapter object
452 * @karg - (struct mpt2_ioctl_command) 478 * @karg - (struct mpt2_ioctl_command)
453 * @tm_request - pointer to mf from user space 479 * @tm_request - pointer to mf from user space
@@ -456,7 +482,7 @@ _ctl_poll(struct file *filep, poll_table *wait)
456 * during failure, the reply frame is filled. 482 * during failure, the reply frame is filled.
457 */ 483 */
458static int 484static int
459_ctl_do_task_abort(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg, 485_ctl_set_task_mid(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
460 Mpi2SCSITaskManagementRequest_t *tm_request) 486 Mpi2SCSITaskManagementRequest_t *tm_request)
461{ 487{
462 u8 found = 0; 488 u8 found = 0;
@@ -468,6 +494,14 @@ _ctl_do_task_abort(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
468 Mpi2SCSITaskManagementReply_t *tm_reply; 494 Mpi2SCSITaskManagementReply_t *tm_reply;
469 u32 sz; 495 u32 sz;
470 u32 lun; 496 u32 lun;
497 char *desc = NULL;
498
499 if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
500 desc = "abort_task";
501 else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
502 desc = "query_task";
503 else
504 return 0;
471 505
472 lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN); 506 lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
473 507
@@ -491,13 +525,13 @@ _ctl_do_task_abort(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
491 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 525 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
492 526
493 if (!found) { 527 if (!found) {
494 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ABORT_TASK: " 528 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
495 "DevHandle(0x%04x), lun(%d), no active mid!!\n", ioc->name, 529 "handle(0x%04x), lun(%d), no active mid!!\n", ioc->name,
496 tm_request->DevHandle, lun)); 530 desc, tm_request->DevHandle, lun));
497 tm_reply = ioc->ctl_cmds.reply; 531 tm_reply = ioc->ctl_cmds.reply;
498 tm_reply->DevHandle = tm_request->DevHandle; 532 tm_reply->DevHandle = tm_request->DevHandle;
499 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; 533 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
500 tm_reply->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK; 534 tm_reply->TaskType = tm_request->TaskType;
501 tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4; 535 tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
502 tm_reply->VP_ID = tm_request->VP_ID; 536 tm_reply->VP_ID = tm_request->VP_ID;
503 tm_reply->VF_ID = tm_request->VF_ID; 537 tm_reply->VF_ID = tm_request->VF_ID;
@@ -509,9 +543,9 @@ _ctl_do_task_abort(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg,
509 return 1; 543 return 1;
510 } 544 }
511 545
512 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ABORT_TASK: " 546 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
513 "DevHandle(0x%04x), lun(%d), smid(%d)\n", ioc->name, 547 "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
514 tm_request->DevHandle, lun, tm_request->TaskMID)); 548 desc, tm_request->DevHandle, lun, tm_request->TaskMID));
515 return 0; 549 return 0;
516} 550}
517 551
@@ -713,9 +747,13 @@ _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc,
713 (Mpi2SCSITaskManagementRequest_t *)mpi_request; 747 (Mpi2SCSITaskManagementRequest_t *)mpi_request;
714 748
715 if (tm_request->TaskType == 749 if (tm_request->TaskType ==
716 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) { 750 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
717 if (_ctl_do_task_abort(ioc, &karg, tm_request)) 751 tm_request->TaskType ==
752 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
753 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
754 mpt2sas_base_free_smid(ioc, smid);
718 goto out; 755 goto out;
756 }
719 } 757 }
720 758
721 mutex_lock(&ioc->tm_cmds.mutex); 759 mutex_lock(&ioc->tm_cmds.mutex);
@@ -915,9 +953,9 @@ _ctl_getiocinfo(void __user *arg)
915 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn); 953 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
916 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus); 954 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
917 karg.firmware_version = ioc->facts.FWVersion.Word; 955 karg.firmware_version = ioc->facts.FWVersion.Word;
918 strncpy(karg.driver_version, MPT2SAS_DRIVER_VERSION, 956 strcpy(karg.driver_version, MPT2SAS_DRIVER_NAME);
919 MPT2_IOCTL_VERSION_LENGTH); 957 strcat(karg.driver_version, "-");
920 karg.driver_version[MPT2_IOCTL_VERSION_LENGTH - 1] = '\0'; 958 strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION);
921 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); 959 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
922 960
923 if (copy_to_user(arg, &karg, sizeof(karg))) { 961 if (copy_to_user(arg, &karg, sizeof(karg))) {
@@ -1551,81 +1589,38 @@ _ctl_diag_query(void __user *arg)
1551} 1589}
1552 1590
1553/** 1591/**
1554 * _ctl_diag_release - request to send Diag Release Message to firmware 1592 * _ctl_send_release - Diag Release Message
1555 * @arg - user space buffer containing ioctl content 1593 * @ioc: per adapter object
1556 * @state - NON_BLOCKING or BLOCKING 1594 * @buffer_type - specifies either TRACE or SNAPSHOT
1595 * @issue_reset - specifies whether host reset is required.
1557 * 1596 *
1558 * This allows ownership of the specified buffer to returned to the driver,
1559 * allowing an application to read the buffer without fear that firmware is
1560 * overwritting information in the buffer.
1561 */ 1597 */
1562static long 1598static int
1563_ctl_diag_release(void __user *arg, enum block_state state) 1599_ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, u8 *issue_reset)
1564{ 1600{
1565 struct mpt2_diag_release karg;
1566 struct MPT2SAS_ADAPTER *ioc;
1567 void *request_data;
1568 int rc;
1569 Mpi2DiagReleaseRequest_t *mpi_request; 1601 Mpi2DiagReleaseRequest_t *mpi_request;
1570 Mpi2DiagReleaseReply_t *mpi_reply; 1602 Mpi2DiagReleaseReply_t *mpi_reply;
1571 u8 buffer_type;
1572 unsigned long timeleft;
1573 u16 smid; 1603 u16 smid;
1574 u16 ioc_status; 1604 u16 ioc_status;
1575 u8 issue_reset = 0; 1605 u32 ioc_state;
1576 1606 int rc;
1577 if (copy_from_user(&karg, arg, sizeof(karg))) { 1607 unsigned long timeleft;
1578 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1579 __FILE__, __LINE__, __func__);
1580 return -EFAULT;
1581 }
1582 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1583 return -ENODEV;
1584 1608
1585 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, 1609 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1586 __func__)); 1610 __func__));
1587 1611
1588 buffer_type = karg.unique_id & 0x000000ff; 1612 rc = 0;
1589 if (!_ctl_diag_capability(ioc, buffer_type)) { 1613 *issue_reset = 0;
1590 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1591 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1592 return -EPERM;
1593 }
1594
1595 if ((ioc->diag_buffer_status[buffer_type] &
1596 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1597 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1598 "registered\n", ioc->name, __func__, buffer_type);
1599 return -EINVAL;
1600 }
1601
1602 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1603 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1604 "registered\n", ioc->name, __func__, karg.unique_id);
1605 return -EINVAL;
1606 }
1607
1608 if (ioc->diag_buffer_status[buffer_type] &
1609 MPT2_DIAG_BUFFER_IS_RELEASED) {
1610 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
1611 "is already released\n", ioc->name, __func__,
1612 buffer_type);
1613 return 0;
1614 }
1615
1616 request_data = ioc->diag_buffer[buffer_type];
1617 1614
1618 if (!request_data) { 1615 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
1619 printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for " 1616 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1620 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); 1617 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
1621 return -ENOMEM; 1618 "skipping due to FAULT state\n", ioc->name,
1619 __func__));
1620 rc = -EAGAIN;
1621 goto out;
1622 } 1622 }
1623 1623
1624 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
1625 return -EAGAIN;
1626 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
1627 return -ERESTARTSYS;
1628
1629 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { 1624 if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
1630 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", 1625 printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n",
1631 ioc->name, __func__); 1626 ioc->name, __func__);
@@ -1641,7 +1636,6 @@ _ctl_diag_release(void __user *arg, enum block_state state)
1641 goto out; 1636 goto out;
1642 } 1637 }
1643 1638
1644 rc = 0;
1645 ioc->ctl_cmds.status = MPT2_CMD_PENDING; 1639 ioc->ctl_cmds.status = MPT2_CMD_PENDING;
1646 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); 1640 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1647 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); 1641 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
@@ -1660,8 +1654,9 @@ _ctl_diag_release(void __user *arg, enum block_state state)
1660 _debug_dump_mf(mpi_request, 1654 _debug_dump_mf(mpi_request,
1661 sizeof(Mpi2DiagReleaseRequest_t)/4); 1655 sizeof(Mpi2DiagReleaseRequest_t)/4);
1662 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) 1656 if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET))
1663 issue_reset = 1; 1657 *issue_reset = 1;
1664 goto issue_host_reset; 1658 rc = -EFAULT;
1659 goto out;
1665 } 1660 }
1666 1661
1667 /* process the completed Reply Message Frame */ 1662 /* process the completed Reply Message Frame */
@@ -1687,14 +1682,101 @@ _ctl_diag_release(void __user *arg, enum block_state state)
1687 rc = -EFAULT; 1682 rc = -EFAULT;
1688 } 1683 }
1689 1684
1690 issue_host_reset: 1685 out:
1686 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
1687 return rc;
1688}
1689
1690/**
1691 * _ctl_diag_release - request to send Diag Release Message to firmware
1692 * @arg - user space buffer containing ioctl content
1693 * @state - NON_BLOCKING or BLOCKING
1694 *
1695 * This allows ownership of the specified buffer to returned to the driver,
1696 * allowing an application to read the buffer without fear that firmware is
1697 * overwritting information in the buffer.
1698 */
1699static long
1700_ctl_diag_release(void __user *arg, enum block_state state)
1701{
1702 struct mpt2_diag_release karg;
1703 struct MPT2SAS_ADAPTER *ioc;
1704 void *request_data;
1705 int rc;
1706 u8 buffer_type;
1707 u8 issue_reset = 0;
1708
1709 if (copy_from_user(&karg, arg, sizeof(karg))) {
1710 printk(KERN_ERR "failure at %s:%d/%s()!\n",
1711 __FILE__, __LINE__, __func__);
1712 return -EFAULT;
1713 }
1714 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1715 return -ENODEV;
1716
1717 dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
1718 __func__));
1719
1720 buffer_type = karg.unique_id & 0x000000ff;
1721 if (!_ctl_diag_capability(ioc, buffer_type)) {
1722 printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for "
1723 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1724 return -EPERM;
1725 }
1726
1727 if ((ioc->diag_buffer_status[buffer_type] &
1728 MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) {
1729 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not "
1730 "registered\n", ioc->name, __func__, buffer_type);
1731 return -EINVAL;
1732 }
1733
1734 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1735 printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not "
1736 "registered\n", ioc->name, __func__, karg.unique_id);
1737 return -EINVAL;
1738 }
1739
1740 if (ioc->diag_buffer_status[buffer_type] &
1741 MPT2_DIAG_BUFFER_IS_RELEASED) {
1742 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
1743 "is already released\n", ioc->name, __func__,
1744 buffer_type);
1745 return 0;
1746 }
1747
1748 request_data = ioc->diag_buffer[buffer_type];
1749
1750 if (!request_data) {
1751 printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for "
1752 "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type);
1753 return -ENOMEM;
1754 }
1755
1756 /* buffers were released by due to host reset */
1757 if ((ioc->diag_buffer_status[buffer_type] &
1758 MPT2_DIAG_BUFFER_IS_DIAG_RESET)) {
1759 ioc->diag_buffer_status[buffer_type] |=
1760 MPT2_DIAG_BUFFER_IS_RELEASED;
1761 ioc->diag_buffer_status[buffer_type] &=
1762 ~MPT2_DIAG_BUFFER_IS_DIAG_RESET;
1763 printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) "
1764 "was released due to host reset\n", ioc->name, __func__,
1765 buffer_type);
1766 return 0;
1767 }
1768
1769 if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
1770 return -EAGAIN;
1771 else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
1772 return -ERESTARTSYS;
1773
1774 rc = _ctl_send_release(ioc, buffer_type, &issue_reset);
1775
1691 if (issue_reset) 1776 if (issue_reset)
1692 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, 1777 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1693 FORCE_BIG_HAMMER); 1778 FORCE_BIG_HAMMER);
1694 1779
1695 out:
1696
1697 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
1698 mutex_unlock(&ioc->ctl_cmds.mutex); 1780 mutex_unlock(&ioc->ctl_cmds.mutex);
1699 return rc; 1781 return rc;
1700} 1782}
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.h b/drivers/scsi/mpt2sas/mpt2sas_ctl.h
index dbb6c0cf8889..4da11435533f 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.h
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.h
@@ -50,7 +50,7 @@
50#endif 50#endif
51 51
52#define MPT2SAS_DEV_NAME "mpt2ctl" 52#define MPT2SAS_DEV_NAME "mpt2ctl"
53#define MPT2_MAGIC_NUMBER 'm' 53#define MPT2_MAGIC_NUMBER 'L'
54#define MPT2_IOCTL_DEFAULT_TIMEOUT (10) /* in seconds */ 54#define MPT2_IOCTL_DEFAULT_TIMEOUT (10) /* in seconds */
55 55
56/** 56/**
@@ -295,8 +295,9 @@ struct mpt2_ioctl_btdh_mapping {
295 295
296 296
297/* status bits for ioc->diag_buffer_status */ 297/* status bits for ioc->diag_buffer_status */
298#define MPT2_DIAG_BUFFER_IS_REGISTERED (0x01) 298#define MPT2_DIAG_BUFFER_IS_REGISTERED (0x01)
299#define MPT2_DIAG_BUFFER_IS_RELEASED (0x02) 299#define MPT2_DIAG_BUFFER_IS_RELEASED (0x02)
300#define MPT2_DIAG_BUFFER_IS_DIAG_RESET (0x04)
300 301
301/* application flags for mpt2_diag_register, mpt2_diag_query */ 302/* application flags for mpt2_diag_register, mpt2_diag_query */
302#define MPT2_APP_FLAGS_APP_OWNED (0x0001) 303#define MPT2_APP_FLAGS_APP_OWNED (0x0001)
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index 0c463c483c02..2a01a5f2a84d 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -119,7 +119,7 @@ struct sense_info {
119 */ 119 */
120struct fw_event_work { 120struct fw_event_work {
121 struct list_head list; 121 struct list_head list;
122 struct delayed_work work; 122 struct work_struct work;
123 struct MPT2SAS_ADAPTER *ioc; 123 struct MPT2SAS_ADAPTER *ioc;
124 u8 VF_ID; 124 u8 VF_ID;
125 u8 host_reset_handling; 125 u8 host_reset_handling;
@@ -197,12 +197,12 @@ static struct pci_device_id scsih_pci_table[] = {
197MODULE_DEVICE_TABLE(pci, scsih_pci_table); 197MODULE_DEVICE_TABLE(pci, scsih_pci_table);
198 198
199/** 199/**
200 * scsih_set_debug_level - global setting of ioc->logging_level. 200 * _scsih_set_debug_level - global setting of ioc->logging_level.
201 * 201 *
202 * Note: The logging levels are defined in mpt2sas_debug.h. 202 * Note: The logging levels are defined in mpt2sas_debug.h.
203 */ 203 */
204static int 204static int
205scsih_set_debug_level(const char *val, struct kernel_param *kp) 205_scsih_set_debug_level(const char *val, struct kernel_param *kp)
206{ 206{
207 int ret = param_set_int(val, kp); 207 int ret = param_set_int(val, kp);
208 struct MPT2SAS_ADAPTER *ioc; 208 struct MPT2SAS_ADAPTER *ioc;
@@ -215,7 +215,7 @@ scsih_set_debug_level(const char *val, struct kernel_param *kp)
215 ioc->logging_level = logging_level; 215 ioc->logging_level = logging_level;
216 return 0; 216 return 0;
217} 217}
218module_param_call(logging_level, scsih_set_debug_level, param_get_int, 218module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
219 &logging_level, 0644); 219 &logging_level, 0644);
220 220
221/** 221/**
@@ -516,12 +516,8 @@ _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
516 handle = sas_device->handle; 516 handle = sas_device->handle;
517 parent_handle = sas_device->parent_handle; 517 parent_handle = sas_device->parent_handle;
518 sas_address = sas_device->sas_address; 518 sas_address = sas_device->sas_address;
519 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) { 519 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle))
520 _scsih_sas_device_remove(ioc, sas_device); 520 _scsih_sas_device_remove(ioc, sas_device);
521 } else if (!sas_device->starget) {
522 mpt2sas_transport_port_remove(ioc, sas_address, parent_handle);
523 _scsih_sas_device_remove(ioc, sas_device);
524 }
525} 521}
526 522
527/** 523/**
@@ -888,6 +884,41 @@ _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
888} 884}
889 885
890/** 886/**
887 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
888 * @ioc: per adapter object
889 * @id: target id
890 * @lun: lun number
891 * @channel: channel
892 * Context: This function will acquire ioc->scsi_lookup_lock.
893 *
894 * This will search for a matching channel:id:lun in the scsi_lookup array,
895 * returning 1 if found.
896 */
897static u8
898_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
899 unsigned int lun, int channel)
900{
901 u8 found;
902 unsigned long flags;
903 int i;
904
905 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
906 found = 0;
907 for (i = 0 ; i < ioc->request_depth; i++) {
908 if (ioc->scsi_lookup[i].scmd &&
909 (ioc->scsi_lookup[i].scmd->device->id == id &&
910 ioc->scsi_lookup[i].scmd->device->channel == channel &&
911 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
912 found = 1;
913 goto out;
914 }
915 }
916 out:
917 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
918 return found;
919}
920
921/**
891 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address) 922 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
892 * @ioc: per adapter object 923 * @ioc: per adapter object
893 * @smid: system request message index 924 * @smid: system request message index
@@ -1051,14 +1082,14 @@ _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1051} 1082}
1052 1083
1053/** 1084/**
1054 * scsih_change_queue_depth - setting device queue depth 1085 * _scsih_change_queue_depth - setting device queue depth
1055 * @sdev: scsi device struct 1086 * @sdev: scsi device struct
1056 * @qdepth: requested queue depth 1087 * @qdepth: requested queue depth
1057 * 1088 *
1058 * Returns queue depth. 1089 * Returns queue depth.
1059 */ 1090 */
1060static int 1091static int
1061scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) 1092_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1062{ 1093{
1063 struct Scsi_Host *shost = sdev->host; 1094 struct Scsi_Host *shost = sdev->host;
1064 int max_depth; 1095 int max_depth;
@@ -1083,14 +1114,14 @@ scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1083} 1114}
1084 1115
1085/** 1116/**
1086 * scsih_change_queue_depth - changing device queue tag type 1117 * _scsih_change_queue_depth - changing device queue tag type
1087 * @sdev: scsi device struct 1118 * @sdev: scsi device struct
1088 * @tag_type: requested tag type 1119 * @tag_type: requested tag type
1089 * 1120 *
1090 * Returns queue tag type. 1121 * Returns queue tag type.
1091 */ 1122 */
1092static int 1123static int
1093scsih_change_queue_type(struct scsi_device *sdev, int tag_type) 1124_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1094{ 1125{
1095 if (sdev->tagged_supported) { 1126 if (sdev->tagged_supported) {
1096 scsi_set_tag_type(sdev, tag_type); 1127 scsi_set_tag_type(sdev, tag_type);
@@ -1105,14 +1136,14 @@ scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1105} 1136}
1106 1137
1107/** 1138/**
1108 * scsih_target_alloc - target add routine 1139 * _scsih_target_alloc - target add routine
1109 * @starget: scsi target struct 1140 * @starget: scsi target struct
1110 * 1141 *
1111 * Returns 0 if ok. Any other return is assumed to be an error and 1142 * Returns 0 if ok. Any other return is assumed to be an error and
1112 * the device is ignored. 1143 * the device is ignored.
1113 */ 1144 */
1114static int 1145static int
1115scsih_target_alloc(struct scsi_target *starget) 1146_scsih_target_alloc(struct scsi_target *starget)
1116{ 1147{
1117 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 1148 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1118 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 1149 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
@@ -1167,13 +1198,13 @@ scsih_target_alloc(struct scsi_target *starget)
1167} 1198}
1168 1199
1169/** 1200/**
1170 * scsih_target_destroy - target destroy routine 1201 * _scsih_target_destroy - target destroy routine
1171 * @starget: scsi target struct 1202 * @starget: scsi target struct
1172 * 1203 *
1173 * Returns nothing. 1204 * Returns nothing.
1174 */ 1205 */
1175static void 1206static void
1176scsih_target_destroy(struct scsi_target *starget) 1207_scsih_target_destroy(struct scsi_target *starget)
1177{ 1208{
1178 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 1209 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1179 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 1210 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
@@ -1203,7 +1234,9 @@ scsih_target_destroy(struct scsi_target *starget)
1203 rphy = dev_to_rphy(starget->dev.parent); 1234 rphy = dev_to_rphy(starget->dev.parent);
1204 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, 1235 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1205 rphy->identify.sas_address); 1236 rphy->identify.sas_address);
1206 if (sas_device) 1237 if (sas_device && (sas_device->starget == starget) &&
1238 (sas_device->id == starget->id) &&
1239 (sas_device->channel == starget->channel))
1207 sas_device->starget = NULL; 1240 sas_device->starget = NULL;
1208 1241
1209 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1242 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
@@ -1214,14 +1247,14 @@ scsih_target_destroy(struct scsi_target *starget)
1214} 1247}
1215 1248
1216/** 1249/**
1217 * scsih_slave_alloc - device add routine 1250 * _scsih_slave_alloc - device add routine
1218 * @sdev: scsi device struct 1251 * @sdev: scsi device struct
1219 * 1252 *
1220 * Returns 0 if ok. Any other return is assumed to be an error and 1253 * Returns 0 if ok. Any other return is assumed to be an error and
1221 * the device is ignored. 1254 * the device is ignored.
1222 */ 1255 */
1223static int 1256static int
1224scsih_slave_alloc(struct scsi_device *sdev) 1257_scsih_slave_alloc(struct scsi_device *sdev)
1225{ 1258{
1226 struct Scsi_Host *shost; 1259 struct Scsi_Host *shost;
1227 struct MPT2SAS_ADAPTER *ioc; 1260 struct MPT2SAS_ADAPTER *ioc;
@@ -1275,13 +1308,13 @@ scsih_slave_alloc(struct scsi_device *sdev)
1275} 1308}
1276 1309
1277/** 1310/**
1278 * scsih_slave_destroy - device destroy routine 1311 * _scsih_slave_destroy - device destroy routine
1279 * @sdev: scsi device struct 1312 * @sdev: scsi device struct
1280 * 1313 *
1281 * Returns nothing. 1314 * Returns nothing.
1282 */ 1315 */
1283static void 1316static void
1284scsih_slave_destroy(struct scsi_device *sdev) 1317_scsih_slave_destroy(struct scsi_device *sdev)
1285{ 1318{
1286 struct MPT2SAS_TARGET *sas_target_priv_data; 1319 struct MPT2SAS_TARGET *sas_target_priv_data;
1287 struct scsi_target *starget; 1320 struct scsi_target *starget;
@@ -1297,13 +1330,13 @@ scsih_slave_destroy(struct scsi_device *sdev)
1297} 1330}
1298 1331
1299/** 1332/**
1300 * scsih_display_sata_capabilities - sata capabilities 1333 * _scsih_display_sata_capabilities - sata capabilities
1301 * @ioc: per adapter object 1334 * @ioc: per adapter object
1302 * @sas_device: the sas_device object 1335 * @sas_device: the sas_device object
1303 * @sdev: scsi device struct 1336 * @sdev: scsi device struct
1304 */ 1337 */
1305static void 1338static void
1306scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, 1339_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1307 struct _sas_device *sas_device, struct scsi_device *sdev) 1340 struct _sas_device *sas_device, struct scsi_device *sdev)
1308{ 1341{
1309 Mpi2ConfigReply_t mpi_reply; 1342 Mpi2ConfigReply_t mpi_reply;
@@ -1403,14 +1436,14 @@ _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1403} 1436}
1404 1437
1405/** 1438/**
1406 * scsih_slave_configure - device configure routine. 1439 * _scsih_slave_configure - device configure routine.
1407 * @sdev: scsi device struct 1440 * @sdev: scsi device struct
1408 * 1441 *
1409 * Returns 0 if ok. Any other return is assumed to be an error and 1442 * Returns 0 if ok. Any other return is assumed to be an error and
1410 * the device is ignored. 1443 * the device is ignored.
1411 */ 1444 */
1412static int 1445static int
1413scsih_slave_configure(struct scsi_device *sdev) 1446_scsih_slave_configure(struct scsi_device *sdev)
1414{ 1447{
1415 struct Scsi_Host *shost = sdev->host; 1448 struct Scsi_Host *shost = sdev->host;
1416 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 1449 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
@@ -1491,7 +1524,7 @@ scsih_slave_configure(struct scsi_device *sdev)
1491 r_level, raid_device->handle, 1524 r_level, raid_device->handle,
1492 (unsigned long long)raid_device->wwid, 1525 (unsigned long long)raid_device->wwid,
1493 raid_device->num_pds, ds); 1526 raid_device->num_pds, ds);
1494 scsih_change_queue_depth(sdev, qdepth); 1527 _scsih_change_queue_depth(sdev, qdepth);
1495 return 0; 1528 return 0;
1496 } 1529 }
1497 1530
@@ -1534,10 +1567,10 @@ scsih_slave_configure(struct scsi_device *sdev)
1534 sas_device->slot); 1567 sas_device->slot);
1535 1568
1536 if (!ssp_target) 1569 if (!ssp_target)
1537 scsih_display_sata_capabilities(ioc, sas_device, sdev); 1570 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
1538 } 1571 }
1539 1572
1540 scsih_change_queue_depth(sdev, qdepth); 1573 _scsih_change_queue_depth(sdev, qdepth);
1541 1574
1542 if (ssp_target) 1575 if (ssp_target)
1543 sas_read_port_mode_page(sdev); 1576 sas_read_port_mode_page(sdev);
@@ -1545,7 +1578,7 @@ scsih_slave_configure(struct scsi_device *sdev)
1545} 1578}
1546 1579
1547/** 1580/**
1548 * scsih_bios_param - fetch head, sector, cylinder info for a disk 1581 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1549 * @sdev: scsi device struct 1582 * @sdev: scsi device struct
1550 * @bdev: pointer to block device context 1583 * @bdev: pointer to block device context
1551 * @capacity: device size (in 512 byte sectors) 1584 * @capacity: device size (in 512 byte sectors)
@@ -1557,7 +1590,7 @@ scsih_slave_configure(struct scsi_device *sdev)
1557 * Return nothing. 1590 * Return nothing.
1558 */ 1591 */
1559static int 1592static int
1560scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, 1593_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1561 sector_t capacity, int params[]) 1594 sector_t capacity, int params[])
1562{ 1595{
1563 int heads; 1596 int heads;
@@ -1638,7 +1671,7 @@ _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
1638} 1671}
1639 1672
1640/** 1673/**
1641 * scsih_tm_done - tm completion routine 1674 * _scsih_tm_done - tm completion routine
1642 * @ioc: per adapter object 1675 * @ioc: per adapter object
1643 * @smid: system request message index 1676 * @smid: system request message index
1644 * @VF_ID: virtual function id 1677 * @VF_ID: virtual function id
@@ -1650,7 +1683,7 @@ _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
1650 * Return nothing. 1683 * Return nothing.
1651 */ 1684 */
1652static void 1685static void
1653scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply) 1686_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
1654{ 1687{
1655 MPI2DefaultReply_t *mpi_reply; 1688 MPI2DefaultReply_t *mpi_reply;
1656 1689
@@ -1825,13 +1858,13 @@ mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
1825} 1858}
1826 1859
1827/** 1860/**
1828 * scsih_abort - eh threads main abort routine 1861 * _scsih_abort - eh threads main abort routine
1829 * @sdev: scsi device struct 1862 * @sdev: scsi device struct
1830 * 1863 *
1831 * Returns SUCCESS if command aborted else FAILED 1864 * Returns SUCCESS if command aborted else FAILED
1832 */ 1865 */
1833static int 1866static int
1834scsih_abort(struct scsi_cmnd *scmd) 1867_scsih_abort(struct scsi_cmnd *scmd)
1835{ 1868{
1836 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 1869 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1837 struct MPT2SAS_DEVICE *sas_device_priv_data; 1870 struct MPT2SAS_DEVICE *sas_device_priv_data;
@@ -1891,15 +1924,86 @@ scsih_abort(struct scsi_cmnd *scmd)
1891 return r; 1924 return r;
1892} 1925}
1893 1926
1927/**
1928 * _scsih_dev_reset - eh threads main device reset routine
1929 * @sdev: scsi device struct
1930 *
1931 * Returns SUCCESS if command aborted else FAILED
1932 */
1933static int
1934_scsih_dev_reset(struct scsi_cmnd *scmd)
1935{
1936 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1937 struct MPT2SAS_DEVICE *sas_device_priv_data;
1938 struct _sas_device *sas_device;
1939 unsigned long flags;
1940 u16 handle;
1941 int r;
1942
1943 printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n",
1944 ioc->name, scmd);
1945 scsi_print_command(scmd);
1946
1947 sas_device_priv_data = scmd->device->hostdata;
1948 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1949 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1950 ioc->name, scmd);
1951 scmd->result = DID_NO_CONNECT << 16;
1952 scmd->scsi_done(scmd);
1953 r = SUCCESS;
1954 goto out;
1955 }
1956
1957 /* for hidden raid components obtain the volume_handle */
1958 handle = 0;
1959 if (sas_device_priv_data->sas_target->flags &
1960 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1961 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1962 sas_device = _scsih_sas_device_find_by_handle(ioc,
1963 sas_device_priv_data->sas_target->handle);
1964 if (sas_device)
1965 handle = sas_device->volume_handle;
1966 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1967 } else
1968 handle = sas_device_priv_data->sas_target->handle;
1969
1970 if (!handle) {
1971 scmd->result = DID_RESET << 16;
1972 r = FAILED;
1973 goto out;
1974 }
1975
1976 mutex_lock(&ioc->tm_cmds.mutex);
1977 mpt2sas_scsih_issue_tm(ioc, handle, 0,
1978 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun,
1979 30);
1980
1981 /*
1982 * sanity check see whether all commands to this device been
1983 * completed
1984 */
1985 if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id,
1986 scmd->device->lun, scmd->device->channel))
1987 r = FAILED;
1988 else
1989 r = SUCCESS;
1990 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1991 mutex_unlock(&ioc->tm_cmds.mutex);
1992
1993 out:
1994 printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n",
1995 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1996 return r;
1997}
1894 1998
1895/** 1999/**
1896 * scsih_dev_reset - eh threads main device reset routine 2000 * _scsih_target_reset - eh threads main target reset routine
1897 * @sdev: scsi device struct 2001 * @sdev: scsi device struct
1898 * 2002 *
1899 * Returns SUCCESS if command aborted else FAILED 2003 * Returns SUCCESS if command aborted else FAILED
1900 */ 2004 */
1901static int 2005static int
1902scsih_dev_reset(struct scsi_cmnd *scmd) 2006_scsih_target_reset(struct scsi_cmnd *scmd)
1903{ 2007{
1904 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 2008 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1905 struct MPT2SAS_DEVICE *sas_device_priv_data; 2009 struct MPT2SAS_DEVICE *sas_device_priv_data;
@@ -1914,7 +2018,7 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
1914 2018
1915 sas_device_priv_data = scmd->device->hostdata; 2019 sas_device_priv_data = scmd->device->hostdata;
1916 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { 2020 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1917 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n", 2021 printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n",
1918 ioc->name, scmd); 2022 ioc->name, scmd);
1919 scmd->result = DID_NO_CONNECT << 16; 2023 scmd->result = DID_NO_CONNECT << 16;
1920 scmd->scsi_done(scmd); 2024 scmd->scsi_done(scmd);
@@ -1964,13 +2068,13 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
1964} 2068}
1965 2069
1966/** 2070/**
1967 * scsih_abort - eh threads main host reset routine 2071 * _scsih_abort - eh threads main host reset routine
1968 * @sdev: scsi device struct 2072 * @sdev: scsi device struct
1969 * 2073 *
1970 * Returns SUCCESS if command aborted else FAILED 2074 * Returns SUCCESS if command aborted else FAILED
1971 */ 2075 */
1972static int 2076static int
1973scsih_host_reset(struct scsi_cmnd *scmd) 2077_scsih_host_reset(struct scsi_cmnd *scmd)
1974{ 2078{
1975 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 2079 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1976 int r, retval; 2080 int r, retval;
@@ -2009,8 +2113,8 @@ _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2009 2113
2010 spin_lock_irqsave(&ioc->fw_event_lock, flags); 2114 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2011 list_add_tail(&fw_event->list, &ioc->fw_event_list); 2115 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2012 INIT_DELAYED_WORK(&fw_event->work, _firmware_event_work); 2116 INIT_WORK(&fw_event->work, _firmware_event_work);
2013 queue_delayed_work(ioc->firmware_event_thread, &fw_event->work, 1); 2117 queue_work(ioc->firmware_event_thread, &fw_event->work);
2014 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 2118 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2015} 2119}
2016 2120
@@ -2054,7 +2158,7 @@ _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2054 return; 2158 return;
2055 2159
2056 spin_lock_irqsave(&ioc->fw_event_lock, flags); 2160 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2057 queue_delayed_work(ioc->firmware_event_thread, &fw_event->work, delay); 2161 queue_work(ioc->firmware_event_thread, &fw_event->work);
2058 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 2162 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2059} 2163}
2060 2164
@@ -2392,7 +2496,107 @@ mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
2392} 2496}
2393 2497
2394/** 2498/**
2395 * scsih_qcmd - main scsi request entry point 2499 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2500 * @scmd: pointer to scsi command object
2501 * @mpi_request: pointer to the SCSI_IO reqest message frame
2502 *
2503 * Supporting protection 1 and 3.
2504 *
2505 * Returns nothing
2506 */
2507static void
2508_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
2509{
2510 u16 eedp_flags;
2511 unsigned char prot_op = scsi_get_prot_op(scmd);
2512 unsigned char prot_type = scsi_get_prot_type(scmd);
2513
2514 if (prot_type == SCSI_PROT_DIF_TYPE0 ||
2515 prot_type == SCSI_PROT_DIF_TYPE2 ||
2516 prot_op == SCSI_PROT_NORMAL)
2517 return;
2518
2519 if (prot_op == SCSI_PROT_READ_STRIP)
2520 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
2521 else if (prot_op == SCSI_PROT_WRITE_INSERT)
2522 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
2523 else
2524 return;
2525
2526 mpi_request->EEDPBlockSize = scmd->device->sector_size;
2527
2528 switch (prot_type) {
2529 case SCSI_PROT_DIF_TYPE1:
2530
2531 /*
2532 * enable ref/guard checking
2533 * auto increment ref tag
2534 */
2535 mpi_request->EEDPFlags = eedp_flags |
2536 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2537 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
2538 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2539 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
2540 cpu_to_be32(scsi_get_lba(scmd));
2541
2542 break;
2543
2544 case SCSI_PROT_DIF_TYPE3:
2545
2546 /*
2547 * enable guard checking
2548 */
2549 mpi_request->EEDPFlags = eedp_flags |
2550 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2551
2552 break;
2553 }
2554}
2555
2556/**
2557 * _scsih_eedp_error_handling - return sense code for EEDP errors
2558 * @scmd: pointer to scsi command object
2559 * @ioc_status: ioc status
2560 *
2561 * Returns nothing
2562 */
2563static void
2564_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
2565{
2566 u8 ascq;
2567 u8 sk;
2568 u8 host_byte;
2569
2570 switch (ioc_status) {
2571 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2572 ascq = 0x01;
2573 break;
2574 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2575 ascq = 0x02;
2576 break;
2577 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2578 ascq = 0x03;
2579 break;
2580 default:
2581 ascq = 0x00;
2582 break;
2583 }
2584
2585 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
2586 sk = ILLEGAL_REQUEST;
2587 host_byte = DID_ABORT;
2588 } else {
2589 sk = ABORTED_COMMAND;
2590 host_byte = DID_OK;
2591 }
2592
2593 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
2594 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
2595 SAM_STAT_CHECK_CONDITION;
2596}
2597
2598/**
2599 * _scsih_qcmd - main scsi request entry point
2396 * @scmd: pointer to scsi command object 2600 * @scmd: pointer to scsi command object
2397 * @done: function pointer to be invoked on completion 2601 * @done: function pointer to be invoked on completion
2398 * 2602 *
@@ -2403,7 +2607,7 @@ mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
2403 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full 2607 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2404 */ 2608 */
2405static int 2609static int
2406scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) 2610_scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
2407{ 2611{
2408 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 2612 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2409 struct MPT2SAS_DEVICE *sas_device_priv_data; 2613 struct MPT2SAS_DEVICE *sas_device_priv_data;
@@ -2472,6 +2676,7 @@ scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
2472 } 2676 }
2473 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); 2677 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2474 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); 2678 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
2679 _scsih_setup_eedp(scmd, mpi_request);
2475 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; 2680 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2476 if (sas_device_priv_data->sas_target->flags & 2681 if (sas_device_priv_data->sas_target->flags &
2477 MPT_TARGET_FLAGS_RAID_COMPONENT) 2682 MPT_TARGET_FLAGS_RAID_COMPONENT)
@@ -2606,6 +2811,15 @@ _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
2606 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: 2811 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
2607 desc_ioc_state = "scsi ext terminated"; 2812 desc_ioc_state = "scsi ext terminated";
2608 break; 2813 break;
2814 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2815 desc_ioc_state = "eedp guard error";
2816 break;
2817 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2818 desc_ioc_state = "eedp ref tag error";
2819 break;
2820 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2821 desc_ioc_state = "eedp app tag error";
2822 break;
2609 default: 2823 default:
2610 desc_ioc_state = "unknown"; 2824 desc_ioc_state = "unknown";
2611 break; 2825 break;
@@ -2785,7 +2999,7 @@ _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2785} 2999}
2786 3000
2787/** 3001/**
2788 * scsih_io_done - scsi request callback 3002 * _scsih_io_done - scsi request callback
2789 * @ioc: per adapter object 3003 * @ioc: per adapter object
2790 * @smid: system request message index 3004 * @smid: system request message index
2791 * @VF_ID: virtual function id 3005 * @VF_ID: virtual function id
@@ -2796,7 +3010,7 @@ _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2796 * Return nothing. 3010 * Return nothing.
2797 */ 3011 */
2798static void 3012static void
2799scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply) 3013_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
2800{ 3014{
2801 Mpi2SCSIIORequest_t *mpi_request; 3015 Mpi2SCSIIORequest_t *mpi_request;
2802 Mpi2SCSIIOReply_t *mpi_reply; 3016 Mpi2SCSIIOReply_t *mpi_reply;
@@ -2863,8 +3077,9 @@ scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
2863 struct sense_info data; 3077 struct sense_info data;
2864 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, 3078 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
2865 smid); 3079 smid);
2866 memcpy(scmd->sense_buffer, sense_data, 3080 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
2867 le32_to_cpu(mpi_reply->SenseCount)); 3081 le32_to_cpu(mpi_reply->SenseCount));
3082 memcpy(scmd->sense_buffer, sense_data, sz);
2868 _scsih_normalize_sense(scmd->sense_buffer, &data); 3083 _scsih_normalize_sense(scmd->sense_buffer, &data);
2869 /* failure prediction threshold exceeded */ 3084 /* failure prediction threshold exceeded */
2870 if (data.asc == 0x5D) 3085 if (data.asc == 0x5D)
@@ -2940,6 +3155,11 @@ scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply)
2940 scmd->result = DID_RESET << 16; 3155 scmd->result = DID_RESET << 16;
2941 break; 3156 break;
2942 3157
3158 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3159 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3160 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3161 _scsih_eedp_error_handling(scmd, ioc_status);
3162 break;
2943 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: 3163 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
2944 case MPI2_IOCSTATUS_INVALID_FUNCTION: 3164 case MPI2_IOCSTATUS_INVALID_FUNCTION:
2945 case MPI2_IOCSTATUS_INVALID_SGL: 3165 case MPI2_IOCSTATUS_INVALID_SGL:
@@ -3923,7 +4143,7 @@ _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3923 4143
3924 mpt2sas_scsih_issue_tm(ioc, handle, lun, 4144 mpt2sas_scsih_issue_tm(ioc, handle, lun,
3925 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30); 4145 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
3926 termination_count += le32_to_cpu(mpi_reply->TerminationCount); 4146 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3927 4147
3928 if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) && 4148 if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) &&
3929 (mpi_reply->ResponseCode == 4149 (mpi_reply->ResponseCode ==
@@ -3933,10 +4153,10 @@ _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID,
3933 continue; 4153 continue;
3934 4154
3935 mpt2sas_scsih_issue_tm(ioc, handle, lun, 4155 mpt2sas_scsih_issue_tm(ioc, handle, lun,
3936 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, smid, 30); 4156 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30);
4157 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3937 termination_count += le32_to_cpu(mpi_reply->TerminationCount); 4158 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
3938 } 4159 }
3939 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3940 ioc->broadcast_aen_busy = 0; 4160 ioc->broadcast_aen_busy = 0;
3941 mutex_unlock(&ioc->tm_cmds.mutex); 4161 mutex_unlock(&ioc->tm_cmds.mutex);
3942 4162
@@ -4962,7 +5182,7 @@ static void
4962_firmware_event_work(struct work_struct *work) 5182_firmware_event_work(struct work_struct *work)
4963{ 5183{
4964 struct fw_event_work *fw_event = container_of(work, 5184 struct fw_event_work *fw_event = container_of(work,
4965 struct fw_event_work, work.work); 5185 struct fw_event_work, work);
4966 unsigned long flags; 5186 unsigned long flags;
4967 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; 5187 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
4968 5188
@@ -5131,18 +5351,19 @@ static struct scsi_host_template scsih_driver_template = {
5131 .module = THIS_MODULE, 5351 .module = THIS_MODULE,
5132 .name = "Fusion MPT SAS Host", 5352 .name = "Fusion MPT SAS Host",
5133 .proc_name = MPT2SAS_DRIVER_NAME, 5353 .proc_name = MPT2SAS_DRIVER_NAME,
5134 .queuecommand = scsih_qcmd, 5354 .queuecommand = _scsih_qcmd,
5135 .target_alloc = scsih_target_alloc, 5355 .target_alloc = _scsih_target_alloc,
5136 .slave_alloc = scsih_slave_alloc, 5356 .slave_alloc = _scsih_slave_alloc,
5137 .slave_configure = scsih_slave_configure, 5357 .slave_configure = _scsih_slave_configure,
5138 .target_destroy = scsih_target_destroy, 5358 .target_destroy = _scsih_target_destroy,
5139 .slave_destroy = scsih_slave_destroy, 5359 .slave_destroy = _scsih_slave_destroy,
5140 .change_queue_depth = scsih_change_queue_depth, 5360 .change_queue_depth = _scsih_change_queue_depth,
5141 .change_queue_type = scsih_change_queue_type, 5361 .change_queue_type = _scsih_change_queue_type,
5142 .eh_abort_handler = scsih_abort, 5362 .eh_abort_handler = _scsih_abort,
5143 .eh_device_reset_handler = scsih_dev_reset, 5363 .eh_device_reset_handler = _scsih_dev_reset,
5144 .eh_host_reset_handler = scsih_host_reset, 5364 .eh_target_reset_handler = _scsih_target_reset,
5145 .bios_param = scsih_bios_param, 5365 .eh_host_reset_handler = _scsih_host_reset,
5366 .bios_param = _scsih_bios_param,
5146 .can_queue = 1, 5367 .can_queue = 1,
5147 .this_id = -1, 5368 .this_id = -1,
5148 .sg_tablesize = MPT2SAS_SG_DEPTH, 5369 .sg_tablesize = MPT2SAS_SG_DEPTH,
@@ -5229,13 +5450,13 @@ _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
5229} 5450}
5230 5451
5231/** 5452/**
5232 * scsih_remove - detach and remove add host 5453 * _scsih_remove - detach and remove add host
5233 * @pdev: PCI device struct 5454 * @pdev: PCI device struct
5234 * 5455 *
5235 * Return nothing. 5456 * Return nothing.
5236 */ 5457 */
5237static void __devexit 5458static void __devexit
5238scsih_remove(struct pci_dev *pdev) 5459_scsih_remove(struct pci_dev *pdev)
5239{ 5460{
5240 struct Scsi_Host *shost = pci_get_drvdata(pdev); 5461 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5241 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 5462 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
@@ -5443,14 +5664,14 @@ _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
5443} 5664}
5444 5665
5445/** 5666/**
5446 * scsih_probe - attach and add scsi host 5667 * _scsih_probe - attach and add scsi host
5447 * @pdev: PCI device struct 5668 * @pdev: PCI device struct
5448 * @id: pci device id 5669 * @id: pci device id
5449 * 5670 *
5450 * Returns 0 success, anything else error. 5671 * Returns 0 success, anything else error.
5451 */ 5672 */
5452static int 5673static int
5453scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) 5674_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5454{ 5675{
5455 struct MPT2SAS_ADAPTER *ioc; 5676 struct MPT2SAS_ADAPTER *ioc;
5456 struct Scsi_Host *shost; 5677 struct Scsi_Host *shost;
@@ -5504,6 +5725,9 @@ scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5504 goto out_add_shost_fail; 5725 goto out_add_shost_fail;
5505 } 5726 }
5506 5727
5728 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
5729 | SHOST_DIF_TYPE3_PROTECTION);
5730
5507 /* event thread */ 5731 /* event thread */
5508 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), 5732 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
5509 "fw_event%d", ioc->id); 5733 "fw_event%d", ioc->id);
@@ -5537,14 +5761,14 @@ scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5537 5761
5538#ifdef CONFIG_PM 5762#ifdef CONFIG_PM
5539/** 5763/**
5540 * scsih_suspend - power management suspend main entry point 5764 * _scsih_suspend - power management suspend main entry point
5541 * @pdev: PCI device struct 5765 * @pdev: PCI device struct
5542 * @state: PM state change to (usually PCI_D3) 5766 * @state: PM state change to (usually PCI_D3)
5543 * 5767 *
5544 * Returns 0 success, anything else error. 5768 * Returns 0 success, anything else error.
5545 */ 5769 */
5546static int 5770static int
5547scsih_suspend(struct pci_dev *pdev, pm_message_t state) 5771_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
5548{ 5772{
5549 struct Scsi_Host *shost = pci_get_drvdata(pdev); 5773 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5550 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 5774 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
@@ -5565,13 +5789,13 @@ scsih_suspend(struct pci_dev *pdev, pm_message_t state)
5565} 5789}
5566 5790
5567/** 5791/**
5568 * scsih_resume - power management resume main entry point 5792 * _scsih_resume - power management resume main entry point
5569 * @pdev: PCI device struct 5793 * @pdev: PCI device struct
5570 * 5794 *
5571 * Returns 0 success, anything else error. 5795 * Returns 0 success, anything else error.
5572 */ 5796 */
5573static int 5797static int
5574scsih_resume(struct pci_dev *pdev) 5798_scsih_resume(struct pci_dev *pdev)
5575{ 5799{
5576 struct Scsi_Host *shost = pci_get_drvdata(pdev); 5800 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5577 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 5801 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
@@ -5600,22 +5824,22 @@ scsih_resume(struct pci_dev *pdev)
5600static struct pci_driver scsih_driver = { 5824static struct pci_driver scsih_driver = {
5601 .name = MPT2SAS_DRIVER_NAME, 5825 .name = MPT2SAS_DRIVER_NAME,
5602 .id_table = scsih_pci_table, 5826 .id_table = scsih_pci_table,
5603 .probe = scsih_probe, 5827 .probe = _scsih_probe,
5604 .remove = __devexit_p(scsih_remove), 5828 .remove = __devexit_p(_scsih_remove),
5605#ifdef CONFIG_PM 5829#ifdef CONFIG_PM
5606 .suspend = scsih_suspend, 5830 .suspend = _scsih_suspend,
5607 .resume = scsih_resume, 5831 .resume = _scsih_resume,
5608#endif 5832#endif
5609}; 5833};
5610 5834
5611 5835
5612/** 5836/**
5613 * scsih_init - main entry point for this driver. 5837 * _scsih_init - main entry point for this driver.
5614 * 5838 *
5615 * Returns 0 success, anything else error. 5839 * Returns 0 success, anything else error.
5616 */ 5840 */
5617static int __init 5841static int __init
5618scsih_init(void) 5842_scsih_init(void)
5619{ 5843{
5620 int error; 5844 int error;
5621 5845
@@ -5631,10 +5855,10 @@ scsih_init(void)
5631 mpt2sas_base_initialize_callback_handler(); 5855 mpt2sas_base_initialize_callback_handler();
5632 5856
5633 /* queuecommand callback hander */ 5857 /* queuecommand callback hander */
5634 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(scsih_io_done); 5858 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
5635 5859
5636 /* task managment callback handler */ 5860 /* task managment callback handler */
5637 tm_cb_idx = mpt2sas_base_register_callback_handler(scsih_tm_done); 5861 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
5638 5862
5639 /* base internal commands callback handler */ 5863 /* base internal commands callback handler */
5640 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done); 5864 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
@@ -5660,12 +5884,12 @@ scsih_init(void)
5660} 5884}
5661 5885
5662/** 5886/**
5663 * scsih_exit - exit point for this driver (when it is a module). 5887 * _scsih_exit - exit point for this driver (when it is a module).
5664 * 5888 *
5665 * Returns 0 success, anything else error. 5889 * Returns 0 success, anything else error.
5666 */ 5890 */
5667static void __exit 5891static void __exit
5668scsih_exit(void) 5892_scsih_exit(void)
5669{ 5893{
5670 printk(KERN_INFO "mpt2sas version %s unloading\n", 5894 printk(KERN_INFO "mpt2sas version %s unloading\n",
5671 MPT2SAS_DRIVER_VERSION); 5895 MPT2SAS_DRIVER_VERSION);
@@ -5683,5 +5907,5 @@ scsih_exit(void)
5683 mpt2sas_ctl_exit(); 5907 mpt2sas_ctl_exit();
5684} 5908}
5685 5909
5686module_init(scsih_init); 5910module_init(_scsih_init);
5687module_exit(scsih_exit); 5911module_exit(_scsih_exit);
diff --git a/drivers/scsi/mpt2sas/mpt2sas_transport.c b/drivers/scsi/mpt2sas/mpt2sas_transport.c
index e03dc0b1e1a0..686695b155c7 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_transport.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_transport.c
@@ -264,7 +264,7 @@ struct rep_manu_reply{
264}; 264};
265 265
266/** 266/**
267 * transport_expander_report_manufacture - obtain SMP report_manufacture 267 * _transport_expander_report_manufacture - obtain SMP report_manufacture
268 * @ioc: per adapter object 268 * @ioc: per adapter object
269 * @sas_address: expander sas address 269 * @sas_address: expander sas address
270 * @edev: the sas_expander_device object 270 * @edev: the sas_expander_device object
@@ -274,7 +274,7 @@ struct rep_manu_reply{
274 * Returns 0 for success, non-zero for failure. 274 * Returns 0 for success, non-zero for failure.
275 */ 275 */
276static int 276static int
277transport_expander_report_manufacture(struct MPT2SAS_ADAPTER *ioc, 277_transport_expander_report_manufacture(struct MPT2SAS_ADAPTER *ioc,
278 u64 sas_address, struct sas_expander_device *edev) 278 u64 sas_address, struct sas_expander_device *edev)
279{ 279{
280 Mpi2SmpPassthroughRequest_t *mpi_request; 280 Mpi2SmpPassthroughRequest_t *mpi_request;
@@ -578,7 +578,7 @@ mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc, u16 handle,
578 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER || 578 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
579 mpt2sas_port->remote_identify.device_type == 579 mpt2sas_port->remote_identify.device_type ==
580 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) 580 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER)
581 transport_expander_report_manufacture(ioc, 581 _transport_expander_report_manufacture(ioc,
582 mpt2sas_port->remote_identify.sas_address, 582 mpt2sas_port->remote_identify.sas_address,
583 rphy_to_expander_device(rphy)); 583 rphy_to_expander_device(rphy));
584 584
@@ -852,7 +852,7 @@ rphy_to_ioc(struct sas_rphy *rphy)
852} 852}
853 853
854/** 854/**
855 * transport_get_linkerrors - 855 * _transport_get_linkerrors -
856 * @phy: The sas phy object 856 * @phy: The sas phy object
857 * 857 *
858 * Only support sas_host direct attached phys. 858 * Only support sas_host direct attached phys.
@@ -860,7 +860,7 @@ rphy_to_ioc(struct sas_rphy *rphy)
860 * 860 *
861 */ 861 */
862static int 862static int
863transport_get_linkerrors(struct sas_phy *phy) 863_transport_get_linkerrors(struct sas_phy *phy)
864{ 864{
865 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); 865 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
866 struct _sas_phy *mpt2sas_phy; 866 struct _sas_phy *mpt2sas_phy;
@@ -903,14 +903,14 @@ transport_get_linkerrors(struct sas_phy *phy)
903} 903}
904 904
905/** 905/**
906 * transport_get_enclosure_identifier - 906 * _transport_get_enclosure_identifier -
907 * @phy: The sas phy object 907 * @phy: The sas phy object
908 * 908 *
909 * Obtain the enclosure logical id for an expander. 909 * Obtain the enclosure logical id for an expander.
910 * Returns 0 for success, non-zero for failure. 910 * Returns 0 for success, non-zero for failure.
911 */ 911 */
912static int 912static int
913transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) 913_transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
914{ 914{
915 struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); 915 struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
916 struct _sas_node *sas_expander; 916 struct _sas_node *sas_expander;
@@ -929,13 +929,13 @@ transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
929} 929}
930 930
931/** 931/**
932 * transport_get_bay_identifier - 932 * _transport_get_bay_identifier -
933 * @phy: The sas phy object 933 * @phy: The sas phy object
934 * 934 *
935 * Returns the slot id for a device that resides inside an enclosure. 935 * Returns the slot id for a device that resides inside an enclosure.
936 */ 936 */
937static int 937static int
938transport_get_bay_identifier(struct sas_rphy *rphy) 938_transport_get_bay_identifier(struct sas_rphy *rphy)
939{ 939{
940 struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); 940 struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy);
941 struct _sas_device *sas_device; 941 struct _sas_device *sas_device;
@@ -953,7 +953,7 @@ transport_get_bay_identifier(struct sas_rphy *rphy)
953} 953}
954 954
955/** 955/**
956 * transport_phy_reset - 956 * _transport_phy_reset -
957 * @phy: The sas phy object 957 * @phy: The sas phy object
958 * @hard_reset: 958 * @hard_reset:
959 * 959 *
@@ -961,7 +961,7 @@ transport_get_bay_identifier(struct sas_rphy *rphy)
961 * Returns 0 for success, non-zero for failure. 961 * Returns 0 for success, non-zero for failure.
962 */ 962 */
963static int 963static int
964transport_phy_reset(struct sas_phy *phy, int hard_reset) 964_transport_phy_reset(struct sas_phy *phy, int hard_reset)
965{ 965{
966 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); 966 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
967 struct _sas_phy *mpt2sas_phy; 967 struct _sas_phy *mpt2sas_phy;
@@ -1002,7 +1002,7 @@ transport_phy_reset(struct sas_phy *phy, int hard_reset)
1002} 1002}
1003 1003
1004/** 1004/**
1005 * transport_smp_handler - transport portal for smp passthru 1005 * _transport_smp_handler - transport portal for smp passthru
1006 * @shost: shost object 1006 * @shost: shost object
1007 * @rphy: sas transport rphy object 1007 * @rphy: sas transport rphy object
1008 * @req: 1008 * @req:
@@ -1012,7 +1012,7 @@ transport_phy_reset(struct sas_phy *phy, int hard_reset)
1012 * smp_rep_general /sys/class/bsg/expander-5:0 1012 * smp_rep_general /sys/class/bsg/expander-5:0
1013 */ 1013 */
1014static int 1014static int
1015transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, 1015_transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1016 struct request *req) 1016 struct request *req)
1017{ 1017{
1018 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); 1018 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
@@ -1041,7 +1041,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1041 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { 1041 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
1042 printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, " 1042 printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, "
1043 "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt, 1043 "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt,
1044 req->data_len, rsp->bio->bi_vcnt, rsp->data_len); 1044 blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
1045 return -EINVAL; 1045 return -EINVAL;
1046 } 1046 }
1047 1047
@@ -1104,7 +1104,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1104 *((u64 *)&mpi_request->SASAddress) = (rphy) ? 1104 *((u64 *)&mpi_request->SASAddress) = (rphy) ?
1105 cpu_to_le64(rphy->identify.sas_address) : 1105 cpu_to_le64(rphy->identify.sas_address) :
1106 cpu_to_le64(ioc->sas_hba.sas_address); 1106 cpu_to_le64(ioc->sas_hba.sas_address);
1107 mpi_request->RequestDataLength = cpu_to_le16(req->data_len - 4); 1107 mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
1108 psge = &mpi_request->SGL; 1108 psge = &mpi_request->SGL;
1109 1109
1110 /* WRITE sgel first */ 1110 /* WRITE sgel first */
@@ -1112,13 +1112,13 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1112 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); 1112 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
1113 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; 1113 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1114 dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio), 1114 dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio),
1115 req->data_len, PCI_DMA_BIDIRECTIONAL); 1115 blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
1116 if (!dma_addr_out) { 1116 if (!dma_addr_out) {
1117 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid)); 1117 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
1118 goto unmap; 1118 goto unmap;
1119 } 1119 }
1120 1120
1121 ioc->base_add_sg_single(psge, sgl_flags | (req->data_len - 4), 1121 ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4),
1122 dma_addr_out); 1122 dma_addr_out);
1123 1123
1124 /* incr sgel */ 1124 /* incr sgel */
@@ -1129,14 +1129,14 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1129 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | 1129 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
1130 MPI2_SGE_FLAGS_END_OF_LIST); 1130 MPI2_SGE_FLAGS_END_OF_LIST);
1131 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; 1131 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1132 dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio), 1132 dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio),
1133 rsp->data_len, PCI_DMA_BIDIRECTIONAL); 1133 blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
1134 if (!dma_addr_in) { 1134 if (!dma_addr_in) {
1135 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid)); 1135 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
1136 goto unmap; 1136 goto unmap;
1137 } 1137 }
1138 1138
1139 ioc->base_add_sg_single(psge, sgl_flags | (rsp->data_len + 4), 1139 ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4),
1140 dma_addr_in); 1140 dma_addr_in);
1141 1141
1142 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - " 1142 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - "
@@ -1170,9 +1170,8 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1170 1170
1171 memcpy(req->sense, mpi_reply, sizeof(*mpi_reply)); 1171 memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
1172 req->sense_len = sizeof(*mpi_reply); 1172 req->sense_len = sizeof(*mpi_reply);
1173 req->data_len = 0; 1173 req->resid_len = 0;
1174 rsp->data_len -= mpi_reply->ResponseDataLength; 1174 rsp->resid_len -= mpi_reply->ResponseDataLength;
1175
1176 } else { 1175 } else {
1177 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT 1176 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT
1178 "%s - no reply\n", ioc->name, __func__)); 1177 "%s - no reply\n", ioc->name, __func__));
@@ -1188,10 +1187,10 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1188 1187
1189 unmap: 1188 unmap:
1190 if (dma_addr_out) 1189 if (dma_addr_out)
1191 pci_unmap_single(ioc->pdev, dma_addr_out, req->data_len, 1190 pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req),
1192 PCI_DMA_BIDIRECTIONAL); 1191 PCI_DMA_BIDIRECTIONAL);
1193 if (dma_addr_in) 1192 if (dma_addr_in)
1194 pci_unmap_single(ioc->pdev, dma_addr_in, rsp->data_len, 1193 pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp),
1195 PCI_DMA_BIDIRECTIONAL); 1194 PCI_DMA_BIDIRECTIONAL);
1196 1195
1197 out: 1196 out:
@@ -1201,11 +1200,11 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1201} 1200}
1202 1201
1203struct sas_function_template mpt2sas_transport_functions = { 1202struct sas_function_template mpt2sas_transport_functions = {
1204 .get_linkerrors = transport_get_linkerrors, 1203 .get_linkerrors = _transport_get_linkerrors,
1205 .get_enclosure_identifier = transport_get_enclosure_identifier, 1204 .get_enclosure_identifier = _transport_get_enclosure_identifier,
1206 .get_bay_identifier = transport_get_bay_identifier, 1205 .get_bay_identifier = _transport_get_bay_identifier,
1207 .phy_reset = transport_phy_reset, 1206 .phy_reset = _transport_phy_reset,
1208 .smp_handler = transport_smp_handler, 1207 .smp_handler = _transport_smp_handler,
1209}; 1208};
1210 1209
1211struct scsi_transport_template *mpt2sas_transport_template; 1210struct scsi_transport_template *mpt2sas_transport_template;