47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/slab.h>
51 #include <linux/errno.h>
52 #include <linux/kdev_t.h>
56 #include <linux/reboot.h>
59 #include <scsi/scsi.h>
71 #define my_NAME "Fusion MPT SCSI Host driver"
72 #define my_VERSION MPT_LINUX_VERSION_COMMON
73 #define MYNAM "mptscsih"
85 static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *
ioc,
int i);
86 static void mptscsih_set_scsi_lookup(MPT_ADAPTER *
ioc,
int i,
struct scsi_cmnd *scmd);
87 static int SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *
ioc,
struct scsi_cmnd *scmd);
92 static int mptscsih_AddSGE(MPT_ADAPTER *
ioc,
struct scsi_cmnd *SCpnt,
94 static void mptscsih_freeChainBuffers(MPT_ADAPTER *
ioc,
int req_idx);
95 static void mptscsih_copy_sense_data(
struct scsi_cmnd *
sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf,
SCSIIOReply_t *pScsiReply);
98 int lun,
int ctx2abort,
ulong timeout);
105 static int mptscsih_get_completion_code(MPT_ADAPTER *
ioc,
106 MPT_FRAME_HDR *
req, MPT_FRAME_HDR *reply);
108 static int mptscsih_do_cmd(MPT_SCSI_HOST *hd,
INTERNAL_CMD *iocmd);
109 static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
112 mptscsih_taskmgmt_reply(MPT_ADAPTER *
ioc,
u8 type,
118 int mptscsih_resume(
struct pci_dev *pdev);
121 #define SNS_LEN(scp) SCSI_SENSE_BUFFERSIZE
134 mptscsih_getFreeChainBuffer(MPT_ADAPTER *
ioc,
int *retIndex)
136 MPT_FRAME_HDR *chainBuf;
144 if (!list_empty(&ioc->FreeChainQ)) {
147 chainBuf =
list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
148 u.frame.linkage.list);
149 list_del(&chainBuf->u.frame.linkage.list);
150 offset = (
u8 *)chainBuf - (
u8 *)ioc->ChainBuffer;
151 chain_idx = offset / ioc->req_sz;
154 "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
155 ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
158 chain_idx = MPT_HOST_NO_CHAIN;
162 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
164 *retIndex = chain_idx;
179 mptscsih_AddSGE(MPT_ADAPTER *
ioc,
struct scsi_cmnd *SCpnt,
186 int sges_left, sg_done;
187 int chain_idx = MPT_HOST_NO_CHAIN;
189 int numSgeSlots, numSgeThisFrame;
190 u32 sgflags, sgdir, thisxfer = 0;
191 int chain_dma_off = 0;
204 psge = (
char *) &pReq->
SGL;
205 frm_sz = ioc->req_sz;
216 sg = scsi_sglist(SCpnt);
228 numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size);
229 numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
237 for (ii=0; ii < (numSgeThisFrame-1); ii++) {
247 ioc->add_sge(psge, sgflags | thisxfer, v2);
251 psge += ioc->SGE_size;
252 sgeOffset += ioc->SGE_size;
256 if (numSgeThisFrame == sges_left) {
269 ioc->add_sge(psge, sgflags | thisxfer, v2);
270 sgeOffset += ioc->SGE_size;
279 ioc->add_chain((
char *)chainSge, 0, sgeOffset,
280 ioc->ChainBufferDMA + chain_dma_off);
286 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
288 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
289 ioc->RequestNB[req_idx] = RequestNB;
303 dsgprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"SG: Chain Required! sg done %d\n",
304 ioc->name, sg_done));
313 u32 *ptmp = (
u32 *) (psge - ioc->SGE_size);
326 u8 nextChain = (
u8) (sgeOffset >> 2);
327 sgeOffset += ioc->SGE_size;
328 ioc->add_chain((
char *)chainSge, nextChain, sgeOffset,
329 ioc->ChainBufferDMA + chain_dma_off);
336 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
337 dsgprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
338 ioc->RequestNB[req_idx] = RequestNB;
341 sges_left -= sg_done;
347 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) ==
FAILED) {
349 "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
350 ioc->name, pReq->
CDB[0], SCpnt));
358 ioc->ChainToChain[chain_idx] = newIndex;
360 ioc->ReqToChain[req_idx] = newIndex;
362 chain_idx = newIndex;
363 chain_dma_off = ioc->req_sz * chain_idx;
369 chainSge = (
char *) psge;
370 dsgprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
" Current buff @ %p (index 0x%x)",
371 ioc->name, psge, req_idx));
375 psge = (
char *) (ioc->ChainBuffer + chain_dma_off);
379 dsgprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
" Chain buff @ %p (index 0x%x)\n",
380 ioc->name, psge, chain_idx));
392 mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
398 if (ioc->bus_type !=
SAS)
408 ioc->name,__func__));
414 SEPMsg->
Bus = vtarget->channel;
419 "Sending SEP cmd=%x channel=%d id=%d\n",
420 ioc->name, SlotStatus, SEPMsg->
Bus, SEPMsg->
TargetID));
424 #ifdef CONFIG_FUSION_LOGGING
445 switch (ioc_status) {
451 desc =
"invalid bus";
454 desc =
"invalid target_id";
457 desc =
"device not there";
460 desc =
"data overrun";
463 desc =
"data underrun";
466 desc =
"I/O data error";
469 desc =
"protocol error";
472 desc =
"task terminated";
475 desc =
"residual mismatch";
478 desc =
"task management failed";
481 desc =
"IOC terminated";
484 desc =
"ext terminated";
498 desc1 =
"check condition";
501 desc1 =
"condition met";
507 desc1 =
"intermediate";
510 desc1 =
"intermediate condmet";
513 desc1 =
"reservation conflict";
516 desc1 =
"command terminated";
519 desc1 =
"task set full";
522 desc1 =
"aca active";
525 desc1 =
"fcpext device logged out";
528 desc1 =
"fcpext no link";
531 desc1 =
"fcpext unassigned";
539 printk(MYIOC_s_DEBUG_FMT
"\tfw_channel = %d, fw_id = %d, lun = %d\n",
541 printk(MYIOC_s_DEBUG_FMT
"\trequest_len = %d, underflow = %d, "
542 "resid = %d\n", ioc->name, scsi_bufflen(sc), sc->
underflow,
544 printk(MYIOC_s_DEBUG_FMT
"\ttag = %d, transfer_count = %d, "
548 printk(MYIOC_s_DEBUG_FMT
"\tiocstatus = %s (0x%04x), "
549 "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n",
550 ioc->name, desc, ioc_status, desc1, pScsiReply->
SCSIStatus,
558 printk(MYIOC_s_DEBUG_FMT
"\t[sense_key,asc,ascq]: "
559 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, skey, asc, ascq);
567 printk(MYIOC_s_DEBUG_FMT
"response_info = %08xh\n",
594 u16 req_idx, req_idx_MR;
598 hd = shost_priv(ioc->sh);
599 req_idx =
le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
600 req_idx_MR = (mr !=
NULL) ?
601 le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;
607 if ((req_idx != req_idx_MR) ||
608 (
le32_to_cpu(mf->u.frame.linkage.arg1) == 0xdeadbeaf))
611 sc = mptscsih_getclear_scsi_lookup(ioc, req_idx);
620 printk(MYIOC_s_ERR_FMT
"NULL ScsiCmd ptr!\n",
623 mptscsih_freeChainBuffers(ioc, req_idx);
628 mptscsih_freeChainBuffers(ioc, req_idx);
632 if (ioc->bus_type ==
SAS) {
633 VirtDevice *vdevice = sc->
device->hostdata;
635 if (!vdevice || !vdevice->vtarget ||
636 vdevice->vtarget->deleted) {
649 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
650 ioc->name, mf, mr, sc, req_idx, pScsiReply->
TaskTag));
653 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
654 ioc->name, mf, mr, sc, req_idx));
657 if (pScsiReply ==
NULL) {
671 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
688 mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
695 printk(MYIOC_s_NOTE_FMT
"[%d:%d:%d:%d] "
696 "FCP_ResponseInfo=%08xh\n", ioc->name,
720 if (ioc->bus_type !=
FC)
726 if (hd->sel_timeout[pScsiReq->
TargetID] < 0xFFFF)
727 hd->sel_timeout[pScsiReq->
TargetID]++;
729 vdevice = sc->
device->hostdata;
732 vtarget = vdevice->vtarget;
733 if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {
734 mptscsih_issue_sep_command(ioc, vtarget,
736 vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON;
741 if ( ioc->bus_type ==
SAS ) {
749 VirtDevice *vdevice =
756 if (vdevice && vdevice->
761 "Skipping Raid Volume"
773 }
else if (ioc->bus_type ==
FC) {
797 if (ioc->bus_type ==
FC)
804 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
805 if((xfer_cnt==0)||(sc->
underflow > xfer_cnt))
810 "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
820 if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
829 if (ioc->bus_type ==
SPI) {
830 if ((pScsiReq->
CDB[0] ==
READ_6 && ((pScsiReq->
CDB[1] & 0x02) == 0)) ||
834 ((pScsiReq->
CDB[1] & 0x02) == 0)) ||
837 if (scsi_bufflen(sc) !=
842 "on LSI53C1030 occurred."
843 "sc->req_bufflen=0x%02x,"
870 " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
873 " ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
878 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
883 scsi_set_resid(sc, 0);
887 if (scsi_state == 0) {
889 }
else if (scsi_state &
890 MPI_SCSI_STATE_AUTOSENSE_VALID) {
900 if ((ioc->bus_type ==
SPI) &&
909 0x80) && (scsi_bufflen(sc)
916 "on LSI53C1030 occurred."
917 "sc->req_bufflen=0x%02x,"
918 "xfer_cnt=0x%02x\n" ,
925 xfer_cnt + difftransfer)) {
931 "Errata on LSI53C1030 occurred"
932 "sc->req_bufflen=0x%02x,"
934 "difftransfer=0x%02x\n",
948 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
951 else if (scsi_state &
972 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
1001 #ifdef CONFIG_FUSION_LOGGING
1003 mptscsih_info_scsiio(ioc, sc, pScsiReply);
1014 mptscsih_freeChainBuffers(ioc, req_idx);
1031 MPT_ADAPTER *ioc = hd->ioc;
1037 for (ii= 0; ii < ioc->req_depth; ii++) {
1038 sc = mptscsih_getclear_scsi_lookup(ioc, ii);
1046 mptscsih_freeChainBuffers(ioc, ii);
1054 "completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, "
1055 "idx=%x\n", ioc->name, channel,
id, sc, mf, ii));
1076 mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
1082 MPT_ADAPTER *ioc = hd->ioc;
1083 unsigned long flags;
1086 for (ii = 0; ii < ioc->req_depth; ii++) {
1087 if ((sc = ioc->ScsiLookup[ii]) !=
NULL) {
1095 if (vdevice->vtarget->tflags &
1101 if ((mf->
Bus != vdevice->vtarget->channel) ||
1102 (mf->
TargetID != vdevice->vtarget->id) ||
1108 ioc->ScsiLookup[ii] =
NULL;
1109 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1110 mptscsih_freeChainBuffers(ioc, ii);
1116 MYIOC_s_FMT
"completing cmds: fw_channel %d, "
1117 "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name,
1118 vdevice->vtarget->channel, vdevice->vtarget->id,
1124 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1153 if ((hd = shost_priv(sc->
device->host)) ==
NULL)
1156 if (time - hd->last_queue_full > 10 *
HZ) {
1157 dprintk(ioc,
printk(MYIOC_s_WARN_FMT
"Device (%d:%d:%d) reported QUEUE_FULL!\n",
1159 hd->last_queue_full =
time;
1173 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1180 if((hd = shost_priv(host)) ==
NULL)
1187 if (ioc->ScsiLookup !=
NULL) {
1188 sz1 = ioc->req_depth *
sizeof(
void *);
1189 kfree(ioc->ScsiLookup);
1190 ioc->ScsiLookup =
NULL;
1194 "Free'd ScsiLookup (%d) memory\n",
1197 kfree(hd->info_kbuf);
1229 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1234 return mpt_suspend(pdev,state);
1244 mptscsih_resume(
struct pci_dev *pdev)
1246 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1249 rc = mpt_resume(pdev);
1271 h = shost_priv(SChost);
1274 if (h->info_kbuf ==
NULL)
1276 return h->info_kbuf;
1277 h->info_kbuf[0] =
'\0';
1280 h->info_kbuf[size-1] =
'\0';
1283 return h->info_kbuf;
1316 mptscsih_copy_info(
struct info_str *info,
char *
fmt, ...)
1326 mptscsih_copy_mem_info(info, buf, len);
1331 mptscsih_host_info(MPT_ADAPTER *ioc,
char *pbuf,
off_t offset,
int len)
1340 mptscsih_copy_info(&info,
"%s: %s, ", ioc->name, ioc->prod_name);
1342 mptscsih_copy_info(&info,
"Ports=%d, ", ioc->facts.NumberOfPorts);
1343 mptscsih_copy_info(&info,
"MaxQ=%d\n", ioc->req_depth);
1365 MPT_SCSI_HOST *hd = shost_priv(host);
1366 MPT_ADAPTER *ioc = hd->ioc;
1377 size = mptscsih_host_info(ioc, buffer, offset, length);
1384 #define ADD_INDEX_LOG(req_ent) do { } while(0)
1404 VirtDevice *vdevice = SCpnt->
device->hostdata;
1413 hd = shost_priv(SCpnt->
device->host);
1417 dmfprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"qcmd: SCpnt=%p, done()=%p\n",
1418 ioc->name, SCpnt,
done));
1420 if (ioc->taskmgmt_quiesce_io)
1427 dprintk(ioc,
printk(MYIOC_s_WARN_FMT
"QueueCmd, no msg frames!!\n",
1434 my_idx =
le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1443 datalen = scsi_bufflen(SCpnt);
1446 datalen = scsi_bufflen(SCpnt);
1457 && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
1458 && (SCpnt->
device->tagged_supported)) {
1461 if (((SCpnt->
request->ioprio & 0x7) == 1) ||
1462 !(SCpnt->
request->ioprio & 0x7))
1471 pScsiReq->
TargetID = (
u8) vdevice->vtarget->id;
1472 pScsiReq->
Bus = vdevice->vtarget->channel;
1481 pScsiReq->
MsgFlags = mpt_msg_flags(ioc);
1489 for (ii=0; ii <
cmd_len; ii++)
1490 pScsiReq->
CDB[ii] = SCpnt->
cmnd[ii];
1492 for (ii=cmd_len; ii < 16; ii++)
1493 pScsiReq->
CDB[ii] = 0;
1507 ioc->add_sge((
char *)&pScsiReq->
SGL,
1512 if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) !=
SUCCESS)
1517 mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);
1520 dmfprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"Issued SCSI cmd (%p) mf=%p idx=%d\n",
1521 ioc->name, SCpnt, mf, my_idx));
1526 mptscsih_freeChainBuffers(ioc, my_idx);
1542 mptscsih_freeChainBuffers(MPT_ADAPTER *ioc,
int req_idx)
1544 MPT_FRAME_HDR *
chain;
1545 unsigned long flags;
1552 chain_idx = ioc->ReqToChain[req_idx];
1553 ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
1555 while (chain_idx != MPT_HOST_NO_CHAIN) {
1558 next = ioc->ChainToChain[chain_idx];
1563 ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
1565 chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
1566 + (chain_idx * ioc->req_sz));
1569 list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
1570 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1572 dmfprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"FreeChainBuffers (index %d)\n",
1573 ioc->name, chain_idx));
1607 int ctx2abort,
ulong timeout)
1613 MPT_ADAPTER *ioc = hd->ioc;
1614 unsigned long timeleft;
1615 u8 issue_hard_reset;
1617 unsigned long time_count;
1619 issue_hard_reset = 0;
1624 "TaskMgmt type=%x: IOC Not operational (0x%x)!\n",
1625 ioc->name, type, ioc_raw_state);
1626 printk(MYIOC_s_WARN_FMT
"Issuing HardReset from %s!!\n",
1627 ioc->name, __func__);
1629 printk(MYIOC_s_WARN_FMT
"TaskMgmt HardReset "
1630 "FAILED!!\n", ioc->name);
1642 "TaskMgmt type=%x: ioc_state: "
1643 "DOORBELL_ACTIVE (0x%x)!\n",
1644 ioc->name, type, ioc_raw_state);
1659 "TaskMgmt no msg frames!!\n", ioc->name));
1683 for (ii=0; ii < 7; ii++)
1688 dtmprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"TaskMgmt: ctx2abort (0x%08x) "
1689 "task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort,
1694 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
1704 "TaskMgmt handshake FAILED!(mf=%p, rc=%d) \n",
1705 ioc->name, mf, retval));
1714 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
1717 "TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf));
1719 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
1721 issue_hard_reset = 1;
1725 retval = mptscsih_taskmgmt_reply(ioc, type,
1729 "TaskMgmt completed (%d seconds)\n",
1734 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
1735 if (issue_hard_reset) {
1737 "Issuing Reset from %s!! doorbell=0x%08x\n",
1739 retval = (ioc->bus_type ==
SAS) ?
1745 retval = (retval == 0) ? 0 :
FAILED;
1752 mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
1754 switch (ioc->bus_type) {
1782 VirtDevice *vdevice;
1787 if ((hd = shost_priv(SCpnt->
device->host)) ==
NULL) {
1791 "can't locate host! (sc=%p)\n", SCpnt);
1796 printk(MYIOC_s_INFO_FMT
"attempting task abort! (sc=%p)\n",
1800 vdevice = SCpnt->
device->hostdata;
1801 if (!vdevice || !vdevice->vtarget) {
1803 "task abort: device has been deleted (sc=%p)\n",
1815 "task abort: hidden raid component (sc=%p)\n",
1824 if (vdevice->vtarget->raidVolume) {
1826 "task abort: raid volume (sc=%p)\n",
1835 if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
1841 "Command not in the active list! (sc=%p)\n", ioc->name,
1847 if (ioc->timeouts < -1)
1860 mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
1861 ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
1864 vdevice->vtarget->channel,
1865 vdevice->vtarget->id, vdevice->lun,
1866 ctx2abort, mptscsih_get_tm_timeout(ioc));
1868 if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx) {
1870 "task abort: command still in active list! (sc=%p)\n",
1875 "task abort: command cleared from active list! (sc=%p)\n",
1881 printk(MYIOC_s_INFO_FMT
"task abort: %s (rv=%04x) (sc=%p)\n",
1882 ioc->name, ((retval ==
SUCCESS) ?
"SUCCESS" :
"FAILED"), retval,
1902 VirtDevice *vdevice;
1907 if ((hd = shost_priv(SCpnt->
device->host)) ==
NULL){
1909 "Can't locate host! (sc=%p)\n", SCpnt);
1914 printk(MYIOC_s_INFO_FMT
"attempting target reset! (sc=%p)\n",
1918 vdevice = SCpnt->
device->hostdata;
1919 if (!vdevice || !vdevice->vtarget) {
1933 vdevice->vtarget->channel,
1934 vdevice->vtarget->id, 0, 0,
1935 mptscsih_get_tm_timeout(ioc));
1938 printk (MYIOC_s_INFO_FMT
"target reset: %s (sc=%p)\n",
1939 ioc->name, ((retval == 0) ?
"SUCCESS" :
"FAILED" ), SCpnt);
1962 VirtDevice *vdevice;
1967 if ((hd = shost_priv(SCpnt->
device->host)) ==
NULL){
1969 "Can't locate host! (sc=%p)\n", SCpnt);
1974 printk(MYIOC_s_INFO_FMT
"attempting bus reset! (sc=%p)\n",
1978 if (ioc->timeouts < -1)
1981 vdevice = SCpnt->
device->hostdata;
1982 if (!vdevice || !vdevice->vtarget)
1986 vdevice->vtarget->channel, 0, 0, 0,
1987 mptscsih_get_tm_timeout(ioc));
1989 printk(MYIOC_s_INFO_FMT
"bus reset: %s (sc=%p)\n",
1990 ioc->name, ((retval == 0) ?
"SUCCESS" :
"FAILED" ), SCpnt);
2016 if ((hd = shost_priv(SCpnt->
device->host)) ==
NULL){
2018 "Can't locate host! (sc=%p)\n", SCpnt);
2026 printk(MYIOC_s_INFO_FMT
"attempting host reset! (sc=%p)\n",
2038 printk(MYIOC_s_INFO_FMT
"host reset: %s (sc=%p)\n",
2039 ioc->name, ((retval == 0) ?
"SUCCESS" :
"FAILED" ), SCpnt);
2045 mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc,
u8 type,
2049 u32 termination_count;
2052 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
2063 "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"
2064 "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"
2065 "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->
Bus,
2068 termination_count));
2082 if (termination_count == 1)
2101 switch (response_code) {
2103 desc =
"The task completed.";
2106 desc =
"The IOC received an invalid frame status.";
2109 desc =
"The task type is not supported.";
2112 desc =
"The requested task failed.";
2115 desc =
"The task completed successfully.";
2118 desc =
"The LUN request is invalid.";
2121 desc =
"The task is in the IOC queue and has not been sent to target.";
2127 printk(MYIOC_s_INFO_FMT
"Response Code(0x%08x): F/W: %s\n",
2128 ioc->name, response_code, desc);
2151 "TaskMgmt completed (mf=%p, mr=%p)\n", ioc->name, mf, mr));
2153 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2158 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
2159 memcpy(ioc->taskmgmt_cmds.reply, mr,
2162 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
2164 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
2165 complete(&ioc->taskmgmt_cmds.done);
2166 if (ioc->bus_type ==
SAS)
2167 ioc->schedule_target_reset(ioc);
2197 if ((
ulong)capacity >= 0x200000) {
2219 struct inactive_raid_component_info *component_info;
2225 if (!ioc->raid_data.pIocPg3)
2227 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2228 if ((
id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2229 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2235 if (ioc->bus_type !=
SAS)
2241 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2243 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
2251 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
2256 for (j = 0; j < num_paths; j++) {
2277 if (list_empty(&ioc->raid_data.inactive_list))
2280 mutex_lock(&ioc->raid_data.inactive_list_mutex);
2283 if ((component_info->d.PhysDiskID ==
id) &&
2284 (component_info->d.PhysDiskBus == channel))
2297 struct inactive_raid_component_info *component_info;
2303 if (!ioc->raid_data.pIocPg3)
2305 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2306 if ((
id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2307 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2308 rc = ioc->raid_data.pIocPg3->PhysDisk[
i].PhysDiskNum;
2313 if (ioc->bus_type !=
SAS)
2319 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2321 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
2329 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
2334 for (j = 0; j < num_paths; j++) {
2354 if (list_empty(&ioc->raid_data.inactive_list))
2357 mutex_lock(&ioc->raid_data.inactive_list_mutex);
2360 if ((component_info->d.PhysDiskID ==
id) &&
2361 (component_info->d.PhysDiskBus == channel))
2362 rc = component_info->d.PhysDiskNum;
2379 MPT_SCSI_HOST *hd = shost_priv(host);
2380 VirtTarget *vtarget;
2381 VirtDevice *vdevice;
2390 mptscsih_search_running_cmds(hd, vdevice);
2391 vtarget->num_luns--;
2392 mptscsih_synchronize_cache(hd, vdevice);
2409 MPT_SCSI_HOST *hd = shost_priv(sdev->
host);
2410 VirtTarget *vtarget;
2414 MPT_ADAPTER *ioc = hd->ioc;
2422 if (ioc->bus_type ==
SPI) {
2423 if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
2431 max_depth = ioc->sh->can_queue;
2436 if (qdepth > max_depth)
2457 VirtTarget *vtarget;
2458 VirtDevice *vdevice;
2460 MPT_SCSI_HOST *hd = shost_priv(sh);
2461 MPT_ADAPTER *ioc = hd->ioc;
2468 "device @ %p, channel=%d, id=%d, lun=%d\n",
2470 if (ioc->bus_type ==
SPI)
2472 "sdtr %d wdtr %d ppr %d inq length=%d\n",
2476 vdevice->configured_lun = 1;
2479 "Queue depth=%d, tflags=%x\n",
2482 if (ioc->bus_type ==
SPI)
2484 "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
2485 ioc->name, vtarget->negoFlags, vtarget->maxOffset,
2486 vtarget->minSyncFactor));
2491 "tagged %d, simple %d, ordered %d\n",
2511 mptscsih_copy_sense_data(
struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf,
SCSIIOReply_t *pScsiReply)
2513 VirtDevice *vdevice;
2516 MPT_ADAPTER *ioc = hd->ioc;
2521 vdevice = sc->
device->hostdata;
2528 req_index =
le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
2535 if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {
2538 idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
2540 ioc->events[
idx].eventContext = ioc->eventContext;
2542 ioc->events[
idx].data[0] = (pReq->
LUN[1] << 24) |
2546 ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
2548 ioc->eventContext++;
2549 if (ioc->pcidev->vendor ==
2551 mptscsih_issue_sep_command(ioc,
2553 vdevice->vtarget->tflags |=
2554 MPT_TARGET_FLAGS_LED_ON;
2559 dprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"Hmmm... SenseData len=0! (?)\n",
2574 unsigned long flags;
2578 scmd = ioc->ScsiLookup[
i];
2579 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2594 mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc,
int i)
2596 unsigned long flags;
2600 scmd = ioc->ScsiLookup[
i];
2601 ioc->ScsiLookup[
i] =
NULL;
2602 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2616 mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc,
int i,
struct scsi_cmnd *scmd)
2618 unsigned long flags;
2621 ioc->ScsiLookup[
i] = scmd;
2622 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2631 SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc,
struct scsi_cmnd *sc)
2633 unsigned long flags;
2637 for (i = 0; i < ioc->req_depth; i++) {
2638 if (ioc->ScsiLookup[i] == sc) {
2645 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2655 if (ioc->sh ==
NULL || shost_priv(ioc->sh) ==
NULL)
2658 hd = shost_priv(ioc->sh);
2659 switch (reset_phase) {
2660 case MPT_IOC_SETUP_RESET:
2662 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
2664 case MPT_IOC_PRE_RESET:
2666 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
2669 case MPT_IOC_POST_RESET:
2671 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
2672 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {
2673 ioc->internal_cmds.status |=
2674 MPT_MGMT_STATUS_DID_IOCRESET;
2675 complete(&ioc->internal_cmds.done);
2691 "MPT event (=%02Xh) routed to SCSI host driver!\n",
2696 (ioc->bus_type ==
SPI) && (ioc->soft_resets < -1))
2729 MPT_FRAME_HDR *reply)
2738 ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2745 ioc->internal_cmds.completion_code =
2746 mptscsih_get_completion_code(ioc, req, reply);
2747 ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
2748 memcpy(ioc->internal_cmds.reply, reply,
2750 cmd = reply->u.hdr.Function;
2754 req_idx =
le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
2755 sense_data = ((
u8 *)ioc->sense_buf_pool +
2756 (req_idx * MPT_SENSE_BUFFER_ALLOC));
2758 MPT_SENSE_BUFFER_ALLOC);
2759 memcpy(ioc->internal_cmds.sense, sense_data, sz);
2762 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING))
2764 ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
2765 complete(&ioc->internal_cmds.done);
2778 mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *
req,
2779 MPT_FRAME_HDR *reply)
2792 "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh,"
2793 "IOCLogInfo=%08xh\n", ioc->name, status, pReply->
SCSIState,
2829 if (req->u.scsireq.CDB[0] ==
INQUIRY)
2856 " completionCode set to %08xh\n", ioc->name, completion_code));
2885 int my_idx, ii,
dir;
2888 char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2890 MPT_ADAPTER *ioc = hd->ioc;
2892 unsigned long timeleft;
2893 unsigned long flags;
2897 if (ioc->ioc_reset_in_progress) {
2898 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2900 "%s: busy with host reset\n", ioc->name, __func__));
2903 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2953 CDB[6] = (io->
size >> 16) & 0xFF;
2954 CDB[7] = (io->
size >> 8) & 0xFF;
2955 CDB[8] = io->
size & 0xFF;
2968 CDB[6] = (io->
size >> 16) & 0xFF;
2969 CDB[7] = (io->
size >> 8) & 0xFF;
2970 CDB[8] = io->
size & 0xFF;
3007 ioc->name, __func__));
3015 my_idx =
le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
3035 pScsiReq->
MsgFlags = mpt_msg_flags(ioc);
3048 "%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd));
3051 for (ii = 0; ii < 16; ii++)
3052 pScsiReq->
CDB[ii] = CDB[ii];
3056 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
3059 "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n",
3060 ioc->name, __func__, cmd, io->
channel, io->
id, io->
lun));
3063 ioc->add_sge((
char *) &pScsiReq->
SGL,
3066 ioc->add_sge((
char *) &pScsiReq->
SGL,
3069 INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
3073 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
3076 "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__,
3078 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
3084 "Issuing Reset from %s!! doorbell=0x%08xh"
3094 ret = ioc->internal_cmds.completion_code;
3096 ioc->name, __func__, ret));
3099 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
3115 mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
3125 if (vdevice->vtarget->type !=
TYPE_DISK || vdevice->vtarget->deleted ||
3126 !vdevice->configured_lun)
3139 iocmd.
channel = vdevice->vtarget->channel;
3140 iocmd.
id = vdevice->vtarget->id;
3141 iocmd.
lun = vdevice->lun;
3143 mptscsih_do_cmd(hd, &iocmd);
3151 MPT_SCSI_HOST *hd = shost_priv(host);
3152 MPT_ADAPTER *ioc = hd->ioc;
3155 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
3156 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
3157 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
3158 ioc->facts.FWVersion.Word & 0x000000FF);
3167 MPT_SCSI_HOST *hd = shost_priv(host);
3168 MPT_ADAPTER *ioc = hd->ioc;
3171 (ioc->biosVersion & 0xFF000000) >> 24,
3172 (ioc->biosVersion & 0x00FF0000) >> 16,
3173 (ioc->biosVersion & 0x0000FF00) >> 8,
3174 ioc->biosVersion & 0x000000FF);
3183 MPT_SCSI_HOST *hd = shost_priv(host);
3184 MPT_ADAPTER *ioc = hd->ioc;
3191 mptscsih_version_product_show(
struct device *dev,
3196 MPT_SCSI_HOST *hd = shost_priv(host);
3197 MPT_ADAPTER *ioc = hd->ioc;
3202 mptscsih_version_product_show,
NULL);
3205 mptscsih_version_nvdata_persistent_show(
struct device *dev,
3210 MPT_SCSI_HOST *hd = shost_priv(host);
3211 MPT_ADAPTER *ioc = hd->ioc;
3214 ioc->nvdata_version_persistent);
3217 mptscsih_version_nvdata_persistent_show,
NULL);
3220 mptscsih_version_nvdata_default_show(
struct device *dev,
3224 MPT_SCSI_HOST *hd = shost_priv(host);
3225 MPT_ADAPTER *ioc = hd->ioc;
3230 mptscsih_version_nvdata_default_show,
NULL);
3237 MPT_SCSI_HOST *hd = shost_priv(host);
3238 MPT_ADAPTER *ioc = hd->ioc;
3245 mptscsih_board_assembly_show(
struct device *dev,
3249 MPT_SCSI_HOST *hd = shost_priv(host);
3250 MPT_ADAPTER *ioc = hd->ioc;
3255 mptscsih_board_assembly_show,
NULL);
3262 MPT_SCSI_HOST *hd = shost_priv(host);
3263 MPT_ADAPTER *ioc = hd->ioc;
3268 mptscsih_board_tracer_show,
NULL);
3275 MPT_SCSI_HOST *hd = shost_priv(host);
3276 MPT_ADAPTER *ioc = hd->ioc;
3281 mptscsih_io_delay_show,
NULL);
3288 MPT_SCSI_HOST *hd = shost_priv(host);
3289 MPT_ADAPTER *ioc = hd->ioc;
3294 mptscsih_device_delay_show,
NULL);
3301 MPT_SCSI_HOST *hd = shost_priv(host);
3302 MPT_ADAPTER *ioc = hd->ioc;
3308 const char *buf,
size_t count)
3311 MPT_SCSI_HOST *hd = shost_priv(host);
3312 MPT_ADAPTER *ioc = hd->ioc;
3315 if (
sscanf(buf,
"%x", &val) != 1)
3318 ioc->debug_level =
val;
3319 printk(MYIOC_s_INFO_FMT
"debug_level=%08xh\n",
3320 ioc->name, ioc->debug_level);
3324 mptscsih_debug_level_show, mptscsih_debug_level_store);
3327 &dev_attr_version_fw,
3328 &dev_attr_version_bios,
3329 &dev_attr_version_mpi,
3330 &dev_attr_version_product,
3331 &dev_attr_version_nvdata_persistent,
3332 &dev_attr_version_nvdata_default,
3333 &dev_attr_board_name,
3334 &dev_attr_board_assembly,
3335 &dev_attr_board_tracer,
3337 &dev_attr_device_delay,
3338 &dev_attr_debug_level,