48 #include <linux/kernel.h>
49 #include <linux/module.h>
50 #include <linux/errno.h>
52 #include <linux/slab.h>
53 #include <linux/types.h>
54 #include <linux/pci.h>
61 #include <asm/uaccess.h>
63 #include <scsi/scsi.h>
69 #define COPYRIGHT "Copyright (c) 1999-2008 LSI Corporation"
70 #define MODULEAUTHOR "LSI Corporation"
75 #define my_NAME "Fusion MPT misc device (ioctl) driver"
76 #define my_VERSION MPT_LINUX_VERSION_COMMON
77 #define MYNAM "mptctl"
103 static int mptctl_fw_download(
unsigned long arg);
104 static int mptctl_getiocinfo(
unsigned long arg,
unsigned int cmd);
105 static int mptctl_gettargetinfo(
unsigned long arg);
106 static int mptctl_readtest(
unsigned long arg);
107 static int mptctl_mpt_command(
unsigned long arg);
108 static int mptctl_eventquery(
unsigned long arg);
109 static int mptctl_eventenable(
unsigned long arg);
110 static int mptctl_eventreport(
unsigned long arg);
111 static int mptctl_replace_fw(
unsigned long arg);
113 static int mptctl_do_reset(
unsigned long arg);
114 static int mptctl_hp_hostinfo(
unsigned long arg,
unsigned int cmd);
115 static int mptctl_hp_targetinfo(
unsigned long arg);
118 static void mptctl_remove(
struct pci_dev *);
121 static long compat_mpctl_ioctl(
struct file *
f,
unsigned cmd,
unsigned long arg);
126 static int mptctl_do_mpt_command(
struct mpt_ioctl_command karg,
void __user *mfPtr);
127 static int mptctl_do_fw_download(
int ioc,
char __user *ufwbuf,
size_t fwlen);
128 static MptSge_t *kbuf_alloc_2_sgl(
int bytes,
u32 dir,
int sge_offset,
int *frags,
136 static int mptctl_ioc_reset(MPT_ADAPTER *
ioc,
int reset_phase);
149 #define MAX_FRAGS_SPILL1 9
150 #define MAX_FRAGS_SPILL2 15
151 #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1)
155 #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1)
160 #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)
163 #define MAX_KMALLOC_SZ (128*1024)
165 #define MPT_IOCTL_DEFAULT_TIMEOUT 10
179 mptctl_syscall_down(MPT_ADAPTER *
ioc,
int nonblock)
201 mptctl_reply(MPT_ADAPTER *
ioc, MPT_FRAME_HDR *
req, MPT_FRAME_HDR *reply)
211 "(0x%02X), req=%p, reply=%p\n", ioc->name, req->u.hdr.Function,
218 if (ioc->ioctl_cmds.msg_context != req->u.hdr.MsgContext)
219 goto out_continuation;
221 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
226 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
227 sz =
min(ioc->reply_sz, 4*reply->u.reply.MsgLength);
228 memcpy(ioc->ioctl_cmds.reply, reply, sz);
230 if (reply->u.reply.IOCStatus || reply->u.reply.IOCLogInfo)
232 "iocstatus (0x%04X), loginfo (0x%08X)\n", ioc->name,
237 (req->u.hdr.Function ==
240 if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
242 "scsi_status (0x%02x), scsi_state (0x%02x), "
243 "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name,
244 reply->u.sreply.SCSIStatus,
245 reply->u.sreply.SCSIState,
249 if (reply->u.sreply.SCSIState &
251 sz = req->u.scsireq.SenseBufferLength;
253 le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
254 sense_data = ((
u8 *)ioc->sense_buf_pool +
256 memcpy(ioc->ioctl_cmds.sense, sense_data, sz);
257 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_SENSE_VALID;
264 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
267 ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
269 if (ioc->bus_type ==
SAS)
270 ioc->schedule_target_reset(ioc);
272 ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
278 if (reply && (reply->u.reply.MsgFlags &
286 mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
292 "TaskMgmt completed (mf=%p, mr=%p)\n",
295 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
300 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
301 memcpy(ioc->taskmgmt_cmds.reply, mr,
304 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
306 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
308 if (ioc->bus_type ==
SAS)
309 ioc->schedule_target_reset(ioc);
316 mptctl_do_taskmgmt(MPT_ADAPTER *ioc,
u8 tm_type,
u8 bus_id,
u8 target_id)
324 unsigned long time_count;
339 printk(MYIOC_s_WARN_FMT
"TaskMgmt, no msg frames!!\n",
354 (ioc->bus_type ==
FC))
358 pScsiTm->
Bus = bus_id;
363 for (ii= 0; ii < 8; ii++)
364 pScsiTm->
LUN[ii] = 0;
365 for (ii=0; ii < 7; ii++)
368 switch (ioc->bus_type) {
382 printk(MYIOC_s_DEBUG_FMT
"TaskMgmt type=%d timeout=%ld\n",
383 ioc->name, tm_type, timeout));
385 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
386 time_count = jiffies;
396 "TaskMgmt send_handshake FAILED!"
397 " (ioc %p, mf %p, rc=%d) \n", ioc->name,
408 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
410 "TaskMgmt failed\n", ioc->name));
413 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
420 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
422 "TaskMgmt failed\n", ioc->name));
429 "TaskMgmt fw_channel = %d, fw_id = %d, task_type=0x%02X, "
430 "iocstatus=0x%04X\n\tloginfo=0x%08X, response_code=0x%02X, "
431 "term_cmnds=%d\n", ioc->name, pScsiTmReply->
Bus,
446 "TaskMgmt failed\n", ioc->name));
452 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
463 mptctl_timeout_expired(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
471 ioc->name, __func__));
477 if (ioc->ioc_reset_in_progress) {
478 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
479 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
483 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
486 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.
status)
490 ret_val = mptctl_do_taskmgmt(ioc,
494 ret_val = mptctl_do_taskmgmt(ioc,
502 ret_val = mptctl_do_taskmgmt(ioc,
524 mptctl_ioc_reset(MPT_ADAPTER *ioc,
int reset_phase)
526 switch(reset_phase) {
527 case MPT_IOC_SETUP_RESET:
529 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
531 case MPT_IOC_PRE_RESET:
533 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
535 case MPT_IOC_POST_RESET:
537 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
538 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
539 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
560 ioc->name, __func__));
561 if(async_queue ==
NULL)
568 if (event == 0x21 ) {
569 ioc->aen_event_read_flag=1;
573 "Raised SIGIO to application\n", ioc->name));
582 if(ioc->aen_event_read_flag)
588 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
589 ioc->aen_event_read_flag=1;
591 "Raised SIGIO to application\n", ioc->name));
593 "Raised SIGIO to application\n", ioc->name));
607 mptctl_fasync(
int fd,
struct file *filep,
int mode)
614 ioc->aen_event_read_flag=0;
636 MPT_ADAPTER *iocp =
NULL;
640 "Unable to copy mpt_ioctl_header data @ %p\n",
641 __FILE__, __LINE__, uhdr);
649 iocnumX = khdr.
iocnum & 0xFF;
666 return mptctl_getiocinfo(arg,
_IOC_SIZE(cmd));
668 return mptctl_gettargetinfo(arg);
670 return mptctl_readtest(arg);
672 return mptctl_eventquery(arg);
674 return mptctl_eventenable(arg);
676 return mptctl_eventreport(arg);
678 return mptctl_replace_fw(arg);
684 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
688 ret = mptctl_fw_download(arg);
690 ret = mptctl_mpt_command(arg);
692 ret = mptctl_do_reset(arg);
694 ret = mptctl_hp_hostinfo(arg,
_IOC_SIZE(cmd));
696 ret = mptctl_hp_targetinfo(arg);
706 mptctl_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
710 ret = __mptctl_ioctl(file, cmd, arg);
715 static int mptctl_do_reset(
unsigned long arg)
723 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
724 __FILE__, __LINE__, urinfo);
730 __FILE__, __LINE__, krinfo.hdr.iocnum);
738 printk (MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_reset - reset failed.\n",
739 iocp->name, __FILE__, __LINE__);
764 mptctl_fw_download(
unsigned long arg)
771 "Unable to copy mpt_fw_xfer struct @ %p\n",
772 __FILE__, __LINE__, ufwdl);
776 return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
794 mptctl_do_fw_download(
int ioc,
char __user *ufwbuf,
size_t fwlen)
800 MptSge_t *
sgl, *sgIn;
811 int fw_bytes_copied = 0;
816 unsigned long timeleft;
831 "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id));
833 iocp->name, ufwbuf));
835 iocp->name, (
int)fwlen));
841 sgOut = (
char *) (ptsge + 1);
885 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
886 &numfrags, &buflist, &sgl_dma, iocp)) ==
NULL)
903 if (numfrags > maxfrags) {
908 dctlprintk(iocp,
printk(MYIOC_s_DEBUG_FMT
"DbG: sgl buffer = %p, sgfrags = %d\n",
909 iocp->name, sgl, numfrags));
918 for (i=0; i < numfrags; i++) {
926 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
927 if (nib == 0 || nib == 3) {
929 }
else if (sgIn->Address) {
930 iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
933 printk(MYIOC_s_ERR_FMT
"%s@%d::_ioctl_fwdl - "
934 "Unable to copy f/w buffer hunk#%d @ %p\n",
935 iocp->name, __FILE__, __LINE__, n, ufwbuf);
938 fw_bytes_copied += bl->
len;
942 sgOut += iocp->SGE_size;
951 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->
MsgContext);
952 INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status)
958 if (!(iocp->ioctl_cmds.
status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
960 printk(MYIOC_s_WARN_FMT
"%s: failed\n", iocp->name, __func__);
961 if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
967 "FW download timeout, doorbell=0x%08x\n",
969 mptctl_timeout_expired(iocp, mf);
975 if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
976 printk(MYIOC_s_WARN_FMT
"%s: failed\n", iocp->name, __func__);
983 kfree_sgl(sgl, sgl_dma, buflist, iocp);
988 printk(MYIOC_s_INFO_FMT
"F/W update successful!\n", iocp->name);
991 printk(MYIOC_s_WARN_FMT
"Hmmm... F/W download not supported!?!\n",
993 printk(MYIOC_s_WARN_FMT
"(time to go bang on somebodies door)\n",
997 printk(MYIOC_s_WARN_FMT
"IOC_BUSY!\n", iocp->name);
998 printk(MYIOC_s_WARN_FMT
"(try again later?)\n", iocp->name);
1001 printk(MYIOC_s_WARN_FMT
"ioctl_fwdl() returned [bad] status = %04xh\n",
1002 iocp->name, iocstat);
1003 printk(MYIOC_s_WARN_FMT
"(bad VooDoo)\n", iocp->name);
1010 CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status);
1011 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0);
1012 kfree_sgl(sgl, sgl_dma, buflist, iocp);
1032 kbuf_alloc_2_sgl(
int bytes,
u32 sgdir,
int sge_offset,
int *frags,
1033 struct buflist **blp,
dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
1035 MptSge_t *sglbuf =
NULL;
1037 struct buflist *buflist =
NULL;
1042 int bytes_allocd = 0;
1070 if (sgdir & 0x04000000)
1083 sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1;
1084 while (bytes_allocd < bytes) {
1085 this_alloc =
min(alloc_sz, bytes-bytes_allocd);
1086 buflist[buflist_ent].
len = this_alloc;
1090 if (buflist[buflist_ent].
kptr ==
NULL) {
1091 alloc_sz = alloc_sz / 2;
1092 if (alloc_sz == 0) {
1093 printk(MYIOC_s_WARN_FMT
"-SG: No can do - "
1094 "not enough memory! :-(\n", ioc->name);
1095 printk(MYIOC_s_WARN_FMT
"-SG: (freeing %d frags)\n",
1096 ioc->name, numfrags);
1103 bytes_allocd += this_alloc;
1104 sgl->FlagsLength = (0x10000000|sgdir|this_alloc);
1105 dma_addr = pci_map_single(ioc->pcidev,
1106 buflist[buflist_ent].
kptr, this_alloc, dir);
1115 if (bytes_allocd >= bytes)
1119 if (fragcnt == sg_spill) {
1121 "-SG: No can do - " "Chain required! :-(\n", ioc->name);
1122 printk(MYIOC_s_WARN_FMT
"(freeing %d frags)\n", ioc->name, numfrags);
1129 printk(MYIOC_s_WARN_FMT
"-SG: No can do - "
1130 "too many SG frags! :-(\n", ioc->name);
1131 printk(MYIOC_s_WARN_FMT
"-SG: (freeing %d frags)\n",
1132 ioc->name, numfrags);
1138 sgl[-1].FlagsLength |= 0xC1000000;
1144 "%d SG frags generated!\n", ioc->name, numfrags));
1147 "last (big) alloc_sz=%d\n", ioc->name, alloc_sz));
1152 if (sglbuf !=
NULL) {
1153 for (i = 0; i < numfrags; i++) {
1158 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
1161 dma_addr = sglbuf[
i].Address;
1162 kptr = buflist[
i].
kptr;
1163 len = buflist[
i].
len;
1178 kfree_sgl(MptSge_t *sgl,
dma_addr_t sgl_dma,
struct buflist *buflist, MPT_ADAPTER *ioc)
1181 struct buflist *bl = buflist;
1186 if (sg->FlagsLength & 0x04000000)
1191 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1192 while (! (nib & 0x4)) {
1194 if (nib == 0 || nib == 3) {
1196 }
else if (sg->Address) {
1201 dma_addr = sg->Address;
1204 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1210 nib = (
le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1219 dma_addr = sg->Address;
1222 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1229 dctlprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"-SG: Free'd 1 SGL buf + %d kbufs!\n",
1244 mptctl_getiocinfo (
unsigned long arg,
unsigned int data_size)
1254 VirtDevice *vdevice;
1274 __FILE__, __LINE__);
1280 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1281 __FILE__, __LINE__, uarg);
1289 __FILE__, __LINE__, iocnum);
1296 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_getiocinfo - "
1297 "Structure size mismatch. Command not completed.\n",
1298 ioc->name, __FILE__, __LINE__);
1309 if (ioc->bus_type == SAS)
1311 else if (ioc->bus_type ==
FC)
1323 pdev = (
struct pci_dev *) ioc->pcidev;
1333 karg->
pciInfo.u.bits.busNumber = pdev->
bus->number;
1336 }
else if (cim_rev == 2) {
1339 karg->
pciInfo.u.bits.busNumber = pdev->
bus->number;
1351 if (vdevice ==
NULL || vdevice->vtarget ==
NULL)
1353 if (vdevice->vtarget->tflags &
1362 karg->
FWVersion = ioc->facts.FWVersion.Word;
1376 if (
copy_to_user((
char __user *)arg, karg, data_size)) {
1377 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_getiocinfo - "
1378 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1379 ioc->name, __FILE__, __LINE__, uarg);
1399 mptctl_gettargetinfo (
unsigned long arg)
1404 VirtDevice *vdevice;
1417 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1418 __FILE__, __LINE__, uarg);
1425 __FILE__, __LINE__, iocnum);
1436 maxWordsLeft = numBytes/
sizeof(
int);
1439 if (maxWordsLeft <= 0) {
1440 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1441 ioc->name, __FILE__, __LINE__);
1461 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1462 ioc->name, __FILE__, __LINE__);
1465 pdata = (
int *) pmem;
1474 if (vdevice ==
NULL || vdevice->vtarget ==
NULL)
1476 if (vdevice->vtarget->tflags &
1479 lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun;
1480 *pdata = (((
u8)lun << 16) + (vdevice->vtarget->channel << 8) +
1481 (vdevice->vtarget->id ));
1493 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_gettargetinfo - "
1494 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1495 ioc->name, __FILE__, __LINE__, uarg);
1503 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_gettargetinfo - "
1504 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1505 ioc->name, __FILE__, __LINE__, pdata);
1524 mptctl_readtest (
unsigned long arg)
1533 "Unable to read in mpt_ioctl_test struct @ %p\n",
1534 __FILE__, __LINE__, uarg);
1541 __FILE__, __LINE__, iocnum);
1552 karg.chip_type = ioc->mfcnt;
1554 karg.chip_type = ioc->pcidev->device;
1564 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_readtest - "
1565 "Unable to write out mpt_ioctl_test struct @ %p\n",
1566 ioc->name, __FILE__, __LINE__, uarg);
1585 mptctl_eventquery (
unsigned long arg)
1594 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1595 __FILE__, __LINE__, uarg);
1602 __FILE__, __LINE__, iocnum);
1608 karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
1609 karg.eventTypes = ioc->eventTypes;
1614 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_eventquery - "
1615 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1616 ioc->name, __FILE__, __LINE__, uarg);
1624 mptctl_eventenable (
unsigned long arg)
1633 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1634 __FILE__, __LINE__, uarg);
1641 __FILE__, __LINE__, iocnum);
1647 if (ioc->events ==
NULL) {
1654 ": ERROR - Insufficient memory to add adapter!\n",
1658 ioc->alloc_total += sz;
1660 ioc->eventContext = 0;
1665 ioc->eventTypes = karg.eventTypes;
1672 mptctl_eventreport (
unsigned long arg)
1678 int numBytes, maxEvents,
max;
1682 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1683 __FILE__, __LINE__, uarg);
1690 __FILE__, __LINE__, iocnum);
1700 max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
1705 if ((max < 1) || !ioc->events)
1709 ioc->aen_event_read_flag=0;
1715 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_eventreport - "
1716 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1717 ioc->name, __FILE__, __LINE__, ioc->events);
1726 mptctl_replace_fw (
unsigned long arg)
1736 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1737 __FILE__, __LINE__, uarg);
1744 __FILE__, __LINE__, iocnum);
1752 if (ioc->cached_fw ==
NULL)
1759 newFwSize = karg.newImageSize;
1761 if (newFwSize & 0x01)
1763 if (newFwSize & 0x02)
1767 if (ioc->cached_fw ==
NULL)
1773 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_replace_fw - "
1774 "Unable to read in mpt_ioctl_replace_fw image "
1775 "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
1782 ioc->facts.FWImageSize = newFwSize;
1799 mptctl_mpt_command (
unsigned long arg)
1810 "Unable to read in mpt_ioctl_command struct @ %p\n",
1811 __FILE__, __LINE__, uarg);
1818 __FILE__, __LINE__, iocnum);
1822 rc = mptctl_do_mpt_command (karg, &uarg->
MF);
1843 MPT_FRAME_HDR *mf =
NULL;
1846 struct buflist bufIn;
1847 struct buflist bufOut;
1851 int iocnum, flagsLength;
1856 unsigned long timeleft;
1858 unsigned long flags;
1863 bufIn.kptr = bufOut.kptr =
NULL;
1864 bufIn.len = bufOut.len = 0;
1869 __FILE__, __LINE__, iocnum);
1874 if (ioc->ioc_reset_in_progress) {
1875 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
1877 "Busy with diagnostic reset\n", __FILE__, __LINE__);
1880 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
1886 sz += ioc->SGE_size;
1888 sz += ioc->SGE_size;
1890 if (sz > ioc->req_sz) {
1891 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
1892 "Request frame too large (%d) maximum (%d)\n",
1893 ioc->name, __FILE__, __LINE__, sz, ioc->req_sz);
1904 req_idx =
le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1911 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
1912 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1913 ioc->name, __FILE__, __LINE__, mfPtr);
1924 dctlprintk(ioc,
printk(MYIOC_s_DEBUG_FMT
"sending mpi function (0x%02X), req=%p\n",
1938 "number=0x%02x action=0x%02x\n", ioc->name,
1964 id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
1966 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
1967 "Target ID out of bounds. \n",
1968 ioc->name, __FILE__, __LINE__);
1973 if (pScsiReq->
Bus >= ioc->number_of_buses) {
1974 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
1975 "Target Bus out of bounds. \n",
1976 ioc->name, __FILE__, __LINE__);
1982 pScsiReq->
MsgFlags |= mpt_msg_flags(ioc);
2002 VirtTarget *vtarget = starget->
hostdata;
2004 if (vtarget ==
NULL)
2007 if ((pScsiReq->
TargetID == vtarget->id) &&
2008 (pScsiReq->
Bus == vtarget->channel) &&
2009 (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
2029 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
2030 "SCSI driver is not loaded. \n",
2031 ioc->name, __FILE__, __LINE__);
2048 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
2049 "SCSI driver is not loaded. \n",
2050 ioc->name, __FILE__, __LINE__);
2069 pScsiReq->
MsgFlags |= mpt_msg_flags(ioc);
2105 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
2106 "SCSI driver is not loaded. \n",
2107 ioc->name, __FILE__, __LINE__);
2118 "\tTaskType=0x%x MsgFlags=0x%x "
2119 "TaskMsgContext=0x%x id=%d channel=%d\n",
2129 u32 high_addr, sense_high;
2142 if ((pInit->
Flags != 0) || (pInit->
MaxDevices != ioc->facts.MaxDevices) ||
2143 (pInit->
MaxBuses != ioc->facts.MaxBuses) ||
2147 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
2148 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2149 ioc->name, __FILE__, __LINE__);
2180 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
2181 "Illegal request (function 0x%x) \n",
2182 ioc->name, __FILE__, __LINE__, hdr->
Function);
2216 ioc->pcidev, bufOut.len, &dma_addr_out);
2218 if (bufOut.kptr ==
NULL) {
2225 ioc->add_sge(psge, flagsLength, dma_addr_out);
2226 psge += ioc->SGE_size;
2234 "%s@%d::mptctl_do_mpt_command - Unable "
2235 "to read user data "
2250 bufIn.len, &dma_addr_in);
2252 if (bufIn.kptr ==
NULL) {
2259 ioc->add_sge(psge, flagsLength, dma_addr_in);
2265 ioc->add_sge(psge, flagsLength, (
dma_addr_t) -1);
2268 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->
MsgContext);
2269 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
2288 "send_handshake FAILED! (ioc %p, mf %p)\n",
2289 ioc->name, ioc, mf));
2305 if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2308 ioc->name, __func__));
2309 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
2310 if (
function == MPI_FUNCTION_SCSI_TASK_MGMT)
2316 "mpt cmd timeout, doorbell=0x%08x"
2319 if (
function == MPI_FUNCTION_SCSI_TASK_MGMT)
2321 mptctl_timeout_expired(ioc, mf);
2328 if (
function == MPI_FUNCTION_SCSI_TASK_MGMT)
2337 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
2340 4*ioc->ioctl_cmds.reply[2]);
2342 sz =
min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]);
2346 ioc->ioctl_cmds.reply, sz)){
2348 "%s@%d::mptctl_do_mpt_command - "
2349 "Unable to write out reply frame %p\n",
2359 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) {
2363 ioc->ioctl_cmds.sense, sz)) {
2364 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
2365 "Unable to write sense data to user %p\n",
2366 ioc->name, __FILE__, __LINE__,
2377 if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) &&
2382 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_do_mpt_command - "
2383 "Unable to write data to user %p\n",
2384 ioc->name, __FILE__, __LINE__,
2392 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
2393 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
2397 if (bufOut.kptr !=
NULL) {
2399 bufOut.len, (
void *) bufOut.kptr, dma_addr_out);
2402 if (bufIn.kptr !=
NULL) {
2404 bufIn.len, (
void *) bufIn.kptr, dma_addr_in);
2428 mptctl_hp_hostinfo(
unsigned long arg,
unsigned int data_size)
2441 MPT_FRAME_HDR *mf =
NULL;
2443 unsigned long timeleft;
2457 "Unable to read in hp_host_info struct @ %p\n",
2458 __FILE__, __LINE__, uarg);
2465 __FILE__, __LINE__, iocnum);
2474 pdev = (
struct pci_dev *) ioc->pcidev;
2481 karg.
bus = pdev->
bus->number;
2487 karg.
host_no = ioc->sh->host_no;
2493 karg.
fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
2494 ((ioc->facts.FWVersion.Struct.Major / 10) +
'0') :
'0';
2495 karg.
fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) +
'0';
2497 karg.
fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
2498 ((ioc->facts.FWVersion.Struct.Minor / 10) +
'0') :
'0';
2499 karg.
fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) +
'0';
2501 karg.
fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
2502 ((ioc->facts.FWVersion.Struct.Unit / 10) +
'0') :
'0';
2503 karg.
fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) +
'0';
2505 karg.
fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
2506 ((ioc->facts.FWVersion.Struct.Dev / 10) +
'0') :
'0';
2507 karg.
fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) +
'0';
2516 cfg.cfghdr.hdr = &
hdr;
2525 if (cfg.cfghdr.hdr->PageLength > 0) {
2531 cfg.physAddr = buf_dma;
2563 if ((ioc->bus_type == SAS) || (ioc->bus_type ==
FC))
2571 if (ioc->sh !=
NULL) {
2572 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
2574 if (hd && (cim_rev == 1)) {
2586 "%s, no msg frames!!\n", ioc->name, __func__));
2599 if (pdev->
devfn & 1)
2607 ioc->add_sge((
char *)&IstwiRWRequest->
SGL,
2611 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
2613 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
2619 if (!(ioc->ioctl_cmds.
status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2621 printk(MYIOC_s_WARN_FMT
"%s: failed\n", ioc->name, __func__);
2622 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
2628 "HOST INFO command timeout, doorbell=0x%08x\n",
2630 mptctl_timeout_expired(ioc, mf);
2645 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)
2649 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
2650 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
2658 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_hpgethostinfo - "
2659 "Unable to write out hp_host_info @ %p\n",
2660 ioc->name, __FILE__, __LINE__, uarg);
2680 mptctl_hp_targetinfo(
unsigned long arg)
2686 MPT_SCSI_HOST *hd =
NULL;
2693 int tmp, np, rc = 0;
2697 "Unable to read in hp_host_targetinfo struct @ %p\n",
2698 __FILE__, __LINE__, uarg);
2705 __FILE__, __LINE__, iocnum);
2713 if ((ioc->bus_type == SAS) || (ioc->bus_type ==
FC))
2716 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh ==
NULL))
2719 if (ioc->sh->host_no != karg.
hdr.
host)
2724 data_sz = ioc->spi_data.sdp0length * 4;
2732 cfg.cfghdr.hdr = &
hdr;
2736 cfg.physAddr = page_dma;
2749 else if (tmp <= 0x09)
2751 else if (tmp <= 0x0A)
2753 else if (tmp <= 0x0C)
2755 else if (tmp <= 0x25)
2780 cfg.cfghdr.hdr = &
hdr;
2785 if ((
mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2788 data_sz = (
int) cfg.cfghdr.hdr->PageLength * 4;
2790 ioc->pcidev, data_sz, &page_dma);
2792 cfg.physAddr = page_dma;
2802 hd = shost_priv(ioc->sh);
2809 printk(MYIOC_s_ERR_FMT
"%s@%d::mptctl_hp_target_info - "
2810 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2811 ioc->name, __FILE__, __LINE__, uarg);
2823 .fasync = mptctl_fasync,
2824 .unlocked_ioctl = mptctl_ioctl,
2825 .release = mptctl_release,
2826 #ifdef CONFIG_COMPAT
2827 .compat_ioctl = compat_mpctl_ioctl,
2839 #ifdef CONFIG_COMPAT
2842 compat_mptfwxfer_ioctl(
struct file *filp,
unsigned int cmd,
2845 struct mpt_fw_xfer32 kfw32;
2847 MPT_ADAPTER *iocp =
NULL;
2857 iocnumX = kfw32.iocnum & 0xFF;
2865 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2868 dctlprintk(iocp,
printk(MYIOC_s_DEBUG_FMT
"compat_mptfwxfer_ioctl() called\n",
2871 kfw.fwlen = kfw32.fwlen;
2872 kfw.bufp = compat_ptr(kfw32.bufp);
2874 ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
2882 compat_mpt_command(
struct file *filp,
unsigned int cmd,
2885 struct mpt_ioctl_command32 karg32;
2886 struct mpt_ioctl_command32
__user *uarg = (
struct mpt_ioctl_command32
__user *) arg;
2888 MPT_ADAPTER *iocp =
NULL;
2889 int iocnum, iocnumX;
2897 iocnumX = karg32.hdr.iocnum & 0xFF;
2905 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2912 karg.
hdr.port = karg32.hdr.port;
2913 karg.timeout = karg32.timeout;
2914 karg.maxReplyBytes = karg32.maxReplyBytes;
2916 karg.dataInSize = karg32.dataInSize;
2917 karg.dataOutSize = karg32.dataOutSize;
2918 karg.maxSenseBytes = karg32.maxSenseBytes;
2919 karg.dataSgeOffset = karg32.dataSgeOffset;
2921 karg.replyFrameBufPtr = (
char __user *)(
unsigned long)karg32.replyFrameBufPtr;
2922 karg.dataInBufPtr = (
char __user *)(
unsigned long)karg32.dataInBufPtr;
2923 karg.dataOutBufPtr = (
char __user *)(
unsigned long)karg32.dataOutBufPtr;
2924 karg.senseDataPtr = (
char __user *)(
unsigned long)karg32.senseDataPtr;
2928 ret = mptctl_do_mpt_command (karg, &uarg->MF);
2935 static long compat_mpctl_ioctl(
struct file *
f,
unsigned int cmd,
unsigned long arg)
2951 ret = __mptctl_ioctl(f, cmd, arg);
2954 ret = compat_mpt_command(f, cmd, arg);
2956 case MPTFWDOWNLOAD32:
2957 ret = compat_mptfwxfer_ioctl(f, cmd, arg);
2982 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2985 init_completion(&ioc->ioctl_cmds.done);
2997 mptctl_remove(
struct pci_dev *pdev)
3001 static struct mpt_pci_driver mptctl_driver = {
3002 .probe = mptctl_probe,
3003 .remove = mptctl_remove,
3007 static int __init mptctl_init(
void)
3039 mptctl_taskmgmt_id =
mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER,
3040 "mptctl_taskmgmt_reply");
3062 static void mptctl_exit(
void)