Lines Matching +full:update +full:- +full:fc +full:- +full:fixup
7 * Copyright (c) 1999-2008 LSI Corporation
8 * (mailto:DL-MPTFusionLinux@lsi.com)
11 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
25 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
44 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
69 #define COPYRIGHT "Copyright (c) 1999-2008 LSI Corporation"
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
84 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
92 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
144 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
159 // ^----------------- 80 + 512
167 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
169 * mptctl_syscall_down - Down the MPT adapter syscall semaphore.
171 * @nonblock: boolean, non-zero if O_NONBLOCK is set
184 if (!mutex_trylock(&ioc->ioctl_cmds.mutex)) in mptctl_syscall_down()
185 rc = -EAGAIN; in mptctl_syscall_down()
187 if (mutex_lock_interruptible(&ioc->ioctl_cmds.mutex)) in mptctl_syscall_down()
188 rc = -ERESTARTSYS; in mptctl_syscall_down()
193 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
211 "(0x%02X), req=%p, reply=%p\n", ioc->name, req->u.hdr.Function, in mptctl_reply()
218 if (ioc->ioctl_cmds.msg_context != req->u.hdr.MsgContext) in mptctl_reply()
221 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; in mptctl_reply()
226 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_RF_VALID; in mptctl_reply()
227 sz = min(ioc->reply_sz, 4*reply->u.reply.MsgLength); in mptctl_reply()
228 memcpy(ioc->ioctl_cmds.reply, reply, sz); in mptctl_reply()
230 if (reply->u.reply.IOCStatus || reply->u.reply.IOCLogInfo) in mptctl_reply()
232 "iocstatus (0x%04X), loginfo (0x%08X)\n", ioc->name, in mptctl_reply()
233 le16_to_cpu(reply->u.reply.IOCStatus), in mptctl_reply()
234 le32_to_cpu(reply->u.reply.IOCLogInfo))); in mptctl_reply()
236 if ((req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) || in mptctl_reply()
237 (req->u.hdr.Function == in mptctl_reply()
240 if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState) in mptctl_reply()
243 "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name, in mptctl_reply()
244 reply->u.sreply.SCSIStatus, in mptctl_reply()
245 reply->u.sreply.SCSIState, in mptctl_reply()
246 le16_to_cpu(reply->u.sreply.TaskTag), in mptctl_reply()
247 le32_to_cpu(reply->u.sreply.TransferCount))); in mptctl_reply()
249 if (reply->u.sreply.SCSIState & in mptctl_reply()
251 sz = req->u.scsireq.SenseBufferLength; in mptctl_reply()
253 le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx); in mptctl_reply()
254 sense_data = ((u8 *)ioc->sense_buf_pool + in mptctl_reply()
256 memcpy(ioc->ioctl_cmds.sense, sense_data, sz); in mptctl_reply()
257 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_SENSE_VALID; in mptctl_reply()
264 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) { in mptctl_reply()
265 if (req->u.hdr.Function == MPI_FUNCTION_SCSI_TASK_MGMT) { in mptctl_reply()
267 ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING; in mptctl_reply()
268 complete(&ioc->ioctl_cmds.done); in mptctl_reply()
269 if (ioc->bus_type == SAS) in mptctl_reply()
270 ioc->schedule_target_reset(ioc); in mptctl_reply()
272 ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING; in mptctl_reply()
273 complete(&ioc->ioctl_cmds.done); in mptctl_reply()
278 if (reply && (reply->u.reply.MsgFlags & in mptctl_reply()
293 ioc->name, mf, mr)); in mptctl_taskmgmt_reply()
295 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; in mptctl_taskmgmt_reply()
300 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID; in mptctl_taskmgmt_reply()
301 memcpy(ioc->taskmgmt_cmds.reply, mr, in mptctl_taskmgmt_reply()
302 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength)); in mptctl_taskmgmt_reply()
304 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) { in mptctl_taskmgmt_reply()
306 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING; in mptctl_taskmgmt_reply()
307 complete(&ioc->taskmgmt_cmds.done); in mptctl_taskmgmt_reply()
308 if (ioc->bus_type == SAS) in mptctl_taskmgmt_reply()
309 ioc->schedule_target_reset(ioc); in mptctl_taskmgmt_reply()
327 mutex_lock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_taskmgmt()
329 mutex_unlock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_taskmgmt()
330 return -EPERM; in mptctl_do_taskmgmt()
339 ioc->name)); in mptctl_do_taskmgmt()
341 retval = -ENOMEM; in mptctl_do_taskmgmt()
346 ioc->name, mf)); in mptctl_do_taskmgmt()
350 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; in mptctl_do_taskmgmt()
351 pScsiTm->TaskType = tm_type; in mptctl_do_taskmgmt()
353 (ioc->bus_type == FC)) in mptctl_do_taskmgmt()
354 pScsiTm->MsgFlags = in mptctl_do_taskmgmt()
356 pScsiTm->TargetID = target_id; in mptctl_do_taskmgmt()
357 pScsiTm->Bus = bus_id; in mptctl_do_taskmgmt()
358 pScsiTm->ChainOffset = 0; in mptctl_do_taskmgmt()
359 pScsiTm->Reserved = 0; in mptctl_do_taskmgmt()
360 pScsiTm->Reserved1 = 0; in mptctl_do_taskmgmt()
361 pScsiTm->TaskMsgContext = 0; in mptctl_do_taskmgmt()
363 pScsiTm->LUN[ii] = 0; in mptctl_do_taskmgmt()
365 pScsiTm->Reserved2[ii] = 0; in mptctl_do_taskmgmt()
367 switch (ioc->bus_type) { in mptctl_do_taskmgmt()
368 case FC: in mptctl_do_taskmgmt()
382 ioc->name, tm_type, timeout)); in mptctl_do_taskmgmt()
384 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status) in mptctl_do_taskmgmt()
385 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && in mptctl_do_taskmgmt()
386 (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) in mptctl_do_taskmgmt()
395 " (ioc %p, mf %p, rc=%d) \n", ioc->name, in mptctl_do_taskmgmt()
404 ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ); in mptctl_do_taskmgmt()
406 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { in mptctl_do_taskmgmt()
408 "TaskMgmt failed\n", ioc->name)); in mptctl_do_taskmgmt()
411 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) in mptctl_do_taskmgmt()
414 retval = -1; /* return failure */ in mptctl_do_taskmgmt()
418 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { in mptctl_do_taskmgmt()
420 "TaskMgmt failed\n", ioc->name)); in mptctl_do_taskmgmt()
421 retval = -1; /* return failure */ in mptctl_do_taskmgmt()
425 pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply; in mptctl_do_taskmgmt()
429 "term_cmnds=%d\n", ioc->name, pScsiTmReply->Bus, in mptctl_do_taskmgmt()
430 pScsiTmReply->TargetID, tm_type, in mptctl_do_taskmgmt()
431 le16_to_cpu(pScsiTmReply->IOCStatus), in mptctl_do_taskmgmt()
432 le32_to_cpu(pScsiTmReply->IOCLogInfo), in mptctl_do_taskmgmt()
433 pScsiTmReply->ResponseCode, in mptctl_do_taskmgmt()
434 le32_to_cpu(pScsiTmReply->TerminationCount))); in mptctl_do_taskmgmt()
436 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK; in mptctl_do_taskmgmt()
444 "TaskMgmt failed\n", ioc->name)); in mptctl_do_taskmgmt()
445 retval = -1; /* return failure */ in mptctl_do_taskmgmt()
449 mutex_unlock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_taskmgmt()
450 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status) in mptctl_do_taskmgmt()
454 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
464 int ret_val = -1; in mptctl_timeout_expired()
466 u8 function = mf->u.hdr.Function; in mptctl_timeout_expired()
469 ioc->name, __func__)); in mptctl_timeout_expired()
474 spin_lock_irqsave(&ioc->taskmgmt_lock, flags); in mptctl_timeout_expired()
475 if (ioc->ioc_reset_in_progress) { in mptctl_timeout_expired()
476 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); in mptctl_timeout_expired()
477 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status) in mptctl_timeout_expired()
481 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); in mptctl_timeout_expired()
484 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status) in mptctl_timeout_expired()
486 if (ioc->bus_type == SAS) { in mptctl_timeout_expired()
490 scsi_req->Bus, scsi_req->TargetID); in mptctl_timeout_expired()
494 scsi_req->Bus, 0); in mptctl_timeout_expired()
502 scsi_req->Bus, 0); in mptctl_timeout_expired()
508 ioc->name)); in mptctl_timeout_expired()
514 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
517 * Clean-up functionality. Used only if there has been a
527 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__)); in mptctl_ioc_reset()
531 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__)); in mptctl_ioc_reset()
535 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__)); in mptctl_ioc_reset()
536 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) { in mptctl_ioc_reset()
537 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET; in mptctl_ioc_reset()
538 complete(&ioc->ioctl_cmds.done); in mptctl_ioc_reset()
548 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
555 event = le32_to_cpu(pEvReply->Event) & 0xFF; in mptctl_event_process()
558 ioc->name, __func__)); in mptctl_event_process()
563 * TODO - this define is not in MPI spec yet, in mptctl_event_process()
567 ioc->aen_event_read_flag=1; in mptctl_event_process()
569 ioc->name)); in mptctl_event_process()
571 "Raised SIGIO to application\n", ioc->name)); in mptctl_event_process()
580 if(ioc->aen_event_read_flag) in mptctl_event_process()
586 if (ioc->events && (ioc->eventTypes & ( 1 << event))) { in mptctl_event_process()
587 ioc->aen_event_read_flag=1; in mptctl_event_process()
589 "Raised SIGIO to application\n", ioc->name)); in mptctl_event_process()
591 "Raised SIGIO to application\n", ioc->name)); in mptctl_event_process()
605 ioc->aen_event_read_flag=0; in mptctl_fasync()
612 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
615 * cmd - specify the particular IOCTL command to be issued
616 * arg - data specific to the command. Must not be null.
624 int nonblock = (file->f_flags & O_NONBLOCK); in __mptctl_ioctl()
629 printk(KERN_ERR MYNAM "%s::mptctl_ioctl() @%d - " in __mptctl_ioctl()
632 return -EFAULT; in __mptctl_ioctl()
634 ret = -ENXIO; /* (-6) No such device or address */ in __mptctl_ioctl()
636 /* Verify intended MPT adapter - set iocnumX and the adapter in __mptctl_ioctl()
641 return -ENODEV; in __mptctl_ioctl()
643 if (!iocp->active) { in __mptctl_ioctl()
644 printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - Controller disabled.\n", in __mptctl_ioctl()
646 return -EFAULT; in __mptctl_ioctl()
687 ret = -EINVAL; in __mptctl_ioctl()
689 mutex_unlock(&iocp->ioctl_cmds.mutex); in __mptctl_ioctl()
710 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_reset - " in mptctl_do_reset()
713 return -EFAULT; in mptctl_do_reset()
717 iocp->name)); in mptctl_do_reset()
720 printk (MYIOC_s_ERR_FMT "%s@%d::mptctl_do_reset - reset failed.\n", in mptctl_do_reset()
721 iocp->name, __FILE__, __LINE__); in mptctl_do_reset()
722 return -1; in mptctl_do_reset()
728 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
736 * -EFAULT if data unavailable
737 * -ENXIO if no such device
738 * -EAGAIN if resource problem
739 * -ENOMEM if no memory for SGE
740 * -EMLINK if too many chain buffers required
741 * -EBADRQC if adapter does not support FW download
742 * -EBUSY if adapter is busy
743 * -ENOMSG if FW upload returned bad status
752 printk(KERN_ERR MYNAM "%s@%d::_ioctl_fwdl - " in mptctl_fw_download()
755 return -EFAULT; in mptctl_fw_download()
761 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
766 * -EFAULT if data unavailable
767 * -ENXIO if no such device
768 * -EAGAIN if resource problem
769 * -ENOMEM if no memory for SGE
770 * -EMLINK if too many chain buffers required
771 * -EBADRQC if adapter does not support FW download
772 * -EBUSY if adapter is busy
773 * -ENOMSG if FW upload returned bad status
802 return -EAGAIN; in mptctl_do_fw_download()
805 "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id)); in mptctl_do_fw_download()
807 iocp->name, ufwbuf)); in mptctl_do_fw_download()
809 iocp->name, (int)fwlen)); in mptctl_do_fw_download()
812 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL; in mptctl_do_fw_download()
818 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW; in mptctl_do_fw_download()
819 dlmsg->Reserved = 0; in mptctl_do_fw_download()
820 dlmsg->ChainOffset = 0; in mptctl_do_fw_download()
821 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD; in mptctl_do_fw_download()
822 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0; in mptctl_do_fw_download()
823 if (iocp->facts.MsgVersion >= MPI_VERSION_01_05) in mptctl_do_fw_download()
824 dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT; in mptctl_do_fw_download()
826 dlmsg->MsgFlags = 0; in mptctl_do_fw_download()
831 ptsge->Reserved = 0; in mptctl_do_fw_download()
832 ptsge->ContextSize = 0; in mptctl_do_fw_download()
833 ptsge->DetailsLength = 12; in mptctl_do_fw_download()
834 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT; in mptctl_do_fw_download()
835 ptsge->Reserved_0100_Checksum = 0; in mptctl_do_fw_download()
836 ptsge->ImageOffset = 0; in mptctl_do_fw_download()
837 ptsge->ImageSize = cpu_to_le32(fwlen); in mptctl_do_fw_download()
859 return -ENOMEM; in mptctl_do_fw_download()
866 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE in mptctl_do_fw_download()
872 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - in mptctl_do_fw_download()
874 / iocp->SGE_size; in mptctl_do_fw_download()
876 ret = -EMLINK; in mptctl_do_fw_download()
881 iocp->name, sgl, numfrags)); in mptctl_do_fw_download()
887 ret = -EFAULT; in mptctl_do_fw_download()
892 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE in mptctl_do_fw_download()
898 nib = (sgIn->FlagsLength & 0x30000000) >> 28; in mptctl_do_fw_download()
901 } else if (sgIn->Address) { in mptctl_do_fw_download()
902 iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address); in mptctl_do_fw_download()
904 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) { in mptctl_do_fw_download()
905 printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - " in mptctl_do_fw_download()
907 iocp->name, __FILE__, __LINE__, n, ufwbuf); in mptctl_do_fw_download()
910 fw_bytes_copied += bl->len; in mptctl_do_fw_download()
914 sgOut += iocp->SGE_size; in mptctl_do_fw_download()
923 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->MsgContext); in mptctl_do_fw_download()
924 INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status) in mptctl_do_fw_download()
929 timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60); in mptctl_do_fw_download()
930 if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { in mptctl_do_fw_download()
931 ret = -ETIME; in mptctl_do_fw_download()
932 printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__); in mptctl_do_fw_download()
933 if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { in mptctl_do_fw_download()
940 iocp->name, mpt_GetIocState(iocp, 0)); in mptctl_do_fw_download()
947 if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { in mptctl_do_fw_download()
948 printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__); in mptctl_do_fw_download()
950 ret = -ENODATA; in mptctl_do_fw_download()
957 ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply; in mptctl_do_fw_download()
958 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK; in mptctl_do_fw_download()
960 printk(MYIOC_s_INFO_FMT "F/W update successful!\n", iocp->name); in mptctl_do_fw_download()
964 iocp->name); in mptctl_do_fw_download()
966 iocp->name); in mptctl_do_fw_download()
967 return -EBADRQC; in mptctl_do_fw_download()
969 printk(MYIOC_s_WARN_FMT "IOC_BUSY!\n", iocp->name); in mptctl_do_fw_download()
970 printk(MYIOC_s_WARN_FMT "(try again later?)\n", iocp->name); in mptctl_do_fw_download()
971 return -EBUSY; in mptctl_do_fw_download()
974 iocp->name, iocstat); in mptctl_do_fw_download()
975 printk(MYIOC_s_WARN_FMT "(bad VooDoo)\n", iocp->name); in mptctl_do_fw_download()
976 return -ENOMSG; in mptctl_do_fw_download()
982 CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status); in mptctl_do_fw_download()
983 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0); in mptctl_do_fw_download()
988 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
992 * Inputs: bytes - number of bytes to be transferred
993 * sgdir - data direction
994 * sge_offset - offset (in bytes) from the start of the request
996 * ioc - pointer to the mptadapter
997 * Outputs: frags - number of scatter gather elements
998 * blp - point to the buflist pointer
999 * sglbuf_dma - pointer to the (dma) sgl
1042 sglbuf = dma_alloc_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES, in kbuf_alloc_2_sgl()
1060 sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1; in kbuf_alloc_2_sgl()
1062 this_alloc = min(alloc_sz, bytes-bytes_allocd); in kbuf_alloc_2_sgl()
1064 buflist[buflist_ent].kptr = dma_alloc_coherent(&ioc->pcidev->dev, in kbuf_alloc_2_sgl()
1070 printk(MYIOC_s_WARN_FMT "-SG: No can do - " in kbuf_alloc_2_sgl()
1071 "not enough memory! :-(\n", ioc->name); in kbuf_alloc_2_sgl()
1072 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n", in kbuf_alloc_2_sgl()
1073 ioc->name, numfrags); in kbuf_alloc_2_sgl()
1081 sgl->FlagsLength = (0x10000000|sgdir|this_alloc); in kbuf_alloc_2_sgl()
1082 dma_addr = dma_map_single(&ioc->pcidev->dev, in kbuf_alloc_2_sgl()
1085 sgl->Address = dma_addr; in kbuf_alloc_2_sgl()
1099 "-SG: No can do - " "Chain required! :-(\n", ioc->name); in kbuf_alloc_2_sgl()
1100 printk(MYIOC_s_WARN_FMT "(freeing %d frags)\n", ioc->name, numfrags); in kbuf_alloc_2_sgl()
1107 printk(MYIOC_s_WARN_FMT "-SG: No can do - " in kbuf_alloc_2_sgl()
1108 "too many SG frags! :-(\n", ioc->name); in kbuf_alloc_2_sgl()
1109 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n", in kbuf_alloc_2_sgl()
1110 ioc->name, numfrags); in kbuf_alloc_2_sgl()
1115 /* Last sge fixup: set LE+eol+eob bits */ in kbuf_alloc_2_sgl()
1116 sgl[-1].FlagsLength |= 0xC1000000; in kbuf_alloc_2_sgl()
1121 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - " in kbuf_alloc_2_sgl()
1122 "%d SG frags generated!\n", ioc->name, numfrags)); in kbuf_alloc_2_sgl()
1124 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - " in kbuf_alloc_2_sgl()
1125 "last (big) alloc_sz=%d\n", ioc->name, alloc_sz)); in kbuf_alloc_2_sgl()
1143 dma_free_coherent(&ioc->pcidev->dev, len, kptr, in kbuf_alloc_2_sgl()
1146 dma_free_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES, sglbuf, in kbuf_alloc_2_sgl()
1153 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1166 if (sg->FlagsLength & 0x04000000) in kfree_sgl()
1171 nib = (sg->FlagsLength & 0xF0000000) >> 28; in kfree_sgl()
1176 } else if (sg->Address) { in kfree_sgl()
1181 dma_addr = sg->Address; in kfree_sgl()
1182 kptr = bl->kptr; in kfree_sgl()
1183 len = bl->len; in kfree_sgl()
1184 dma_unmap_single(&ioc->pcidev->dev, dma_addr, len, in kfree_sgl()
1186 dma_free_coherent(&ioc->pcidev->dev, len, kptr, in kfree_sgl()
1192 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28; in kfree_sgl()
1196 if (sg->Address) { in kfree_sgl()
1201 dma_addr = sg->Address; in kfree_sgl()
1202 kptr = bl->kptr; in kfree_sgl()
1203 len = bl->len; in kfree_sgl()
1204 dma_unmap_single(&ioc->pcidev->dev, dma_addr, len, dir); in kfree_sgl()
1205 dma_free_coherent(&ioc->pcidev->dev, len, kptr, dma_addr); in kfree_sgl()
1209 dma_free_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES, sgl, sgl_dma); in kfree_sgl()
1211 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: Free'd 1 SGL buf + %d kbufs!\n", in kfree_sgl()
1212 ioc->name, n)); in kfree_sgl()
1215 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1217 * mptctl_getiocinfo - Query the host adapter for IOC information.
1222 * -EFAULT if data unavailable
1223 * -ENODEV if no such device/adapter
1249 return -EFAULT; in mptctl_getiocinfo()
1253 printk(KERN_ERR MYNAM "%s@%d::mpt_ioctl_iocinfo() - memdup_user returned error [%ld]\n", in mptctl_getiocinfo()
1259 if (karg->hdr.maxDataSize != data_size) { in mptctl_getiocinfo()
1260 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - " in mptctl_getiocinfo()
1262 ioc->name, __FILE__, __LINE__); in mptctl_getiocinfo()
1264 return -EFAULT; in mptctl_getiocinfo()
1268 ioc->name)); in mptctl_getiocinfo()
1273 if (ioc->bus_type == SAS) in mptctl_getiocinfo()
1274 karg->adapterType = MPT_IOCTL_INTERFACE_SAS; in mptctl_getiocinfo()
1275 else if (ioc->bus_type == FC) in mptctl_getiocinfo()
1276 karg->adapterType = MPT_IOCTL_INTERFACE_FC; in mptctl_getiocinfo()
1278 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI; in mptctl_getiocinfo()
1280 if (karg->hdr.port > 1) { in mptctl_getiocinfo()
1282 return -EINVAL; in mptctl_getiocinfo()
1284 port = karg->hdr.port; in mptctl_getiocinfo()
1286 karg->port = port; in mptctl_getiocinfo()
1287 pdev = (struct pci_dev *) ioc->pcidev; in mptctl_getiocinfo()
1289 karg->pciId = pdev->device; in mptctl_getiocinfo()
1290 karg->hwRev = pdev->revision; in mptctl_getiocinfo()
1291 karg->subSystemDevice = pdev->subsystem_device; in mptctl_getiocinfo()
1292 karg->subSystemVendor = pdev->subsystem_vendor; in mptctl_getiocinfo()
1297 karg->pciInfo.u.bits.busNumber = pdev->bus->number; in mptctl_getiocinfo()
1298 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn ); in mptctl_getiocinfo()
1299 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn ); in mptctl_getiocinfo()
1303 karg->pciInfo.u.bits.busNumber = pdev->bus->number; in mptctl_getiocinfo()
1304 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn ); in mptctl_getiocinfo()
1305 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn ); in mptctl_getiocinfo()
1306 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus); in mptctl_getiocinfo()
1311 karg->numDevices = 0; in mptctl_getiocinfo()
1312 if (ioc->sh) { in mptctl_getiocinfo()
1313 shost_for_each_device(sdev, ioc->sh) { in mptctl_getiocinfo()
1314 vdevice = sdev->hostdata; in mptctl_getiocinfo()
1315 if (vdevice == NULL || vdevice->vtarget == NULL) in mptctl_getiocinfo()
1317 if (vdevice->vtarget->tflags & in mptctl_getiocinfo()
1320 karg->numDevices++; in mptctl_getiocinfo()
1326 karg->FWVersion = ioc->facts.FWVersion.Word; in mptctl_getiocinfo()
1327 karg->BIOSVersion = ioc->biosVersion; in mptctl_getiocinfo()
1331 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH); in mptctl_getiocinfo()
1332 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0'; in mptctl_getiocinfo()
1334 karg->busChangeEvent = 0; in mptctl_getiocinfo()
1335 karg->hostId = ioc->pfacts[port].PortSCSIID; in mptctl_getiocinfo()
1336 karg->rsvd[0] = karg->rsvd[1] = 0; in mptctl_getiocinfo()
1341 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - " in mptctl_getiocinfo()
1343 ioc->name, __FILE__, __LINE__, uarg); in mptctl_getiocinfo()
1345 return -EFAULT; in mptctl_getiocinfo()
1352 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1354 * mptctl_gettargetinfo - Query the host adapter for target information.
1359 * -EFAULT if data unavailable
1360 * -ENODEV if no such device/adapter
1377 printk(KERN_ERR MYNAM "%s@%d::mptctl_gettargetinfo - " in mptctl_gettargetinfo()
1380 return -EFAULT; in mptctl_gettargetinfo()
1384 ioc->name)); in mptctl_gettargetinfo()
1385 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header); in mptctl_gettargetinfo()
1389 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n", in mptctl_gettargetinfo()
1390 ioc->name, __FILE__, __LINE__); in mptctl_gettargetinfo()
1391 return -ENOMEM; in mptctl_gettargetinfo()
1403 * bits 31-24: reserved in mptctl_gettargetinfo()
1404 * 23-16: LUN in mptctl_gettargetinfo()
1405 * 15- 8: Bus Number in mptctl_gettargetinfo()
1406 * 7- 0: Target ID in mptctl_gettargetinfo()
1410 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n", in mptctl_gettargetinfo()
1411 ioc->name, __FILE__, __LINE__); in mptctl_gettargetinfo()
1412 return -ENOMEM; in mptctl_gettargetinfo()
1418 if (ioc->sh){ in mptctl_gettargetinfo()
1419 shost_for_each_device(sdev, ioc->sh) { in mptctl_gettargetinfo()
1422 vdevice = sdev->hostdata; in mptctl_gettargetinfo()
1423 if (vdevice == NULL || vdevice->vtarget == NULL) in mptctl_gettargetinfo()
1425 if (vdevice->vtarget->tflags & in mptctl_gettargetinfo()
1428 lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun; in mptctl_gettargetinfo()
1429 *pdata = (((u8)lun << 16) + (vdevice->vtarget->channel << 8) + in mptctl_gettargetinfo()
1430 (vdevice->vtarget->id )); in mptctl_gettargetinfo()
1433 --maxWordsLeft; in mptctl_gettargetinfo()
1442 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - " in mptctl_gettargetinfo()
1444 ioc->name, __FILE__, __LINE__, uarg); in mptctl_gettargetinfo()
1446 return -EFAULT; in mptctl_gettargetinfo()
1451 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) { in mptctl_gettargetinfo()
1452 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - " in mptctl_gettargetinfo()
1454 ioc->name, __FILE__, __LINE__, pdata); in mptctl_gettargetinfo()
1456 return -EFAULT; in mptctl_gettargetinfo()
1464 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1469 * -EFAULT if data unavailable
1470 * -ENODEV if no such device/adapter
1479 printk(KERN_ERR MYNAM "%s@%d::mptctl_readtest - " in mptctl_readtest()
1482 return -EFAULT; in mptctl_readtest()
1486 ioc->name)); in mptctl_readtest()
1492 karg.chip_type = ioc->mfcnt; in mptctl_readtest()
1494 karg.chip_type = ioc->pcidev->device; in mptctl_readtest()
1496 strncpy (karg.name, ioc->name, MPT_MAX_NAME); in mptctl_readtest()
1497 karg.name[MPT_MAX_NAME-1]='\0'; in mptctl_readtest()
1498 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH); in mptctl_readtest()
1499 karg.product[MPT_PRODUCT_LENGTH-1]='\0'; in mptctl_readtest()
1504 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_readtest - " in mptctl_readtest()
1506 ioc->name, __FILE__, __LINE__, uarg); in mptctl_readtest()
1507 return -EFAULT; in mptctl_readtest()
1513 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1515 * mptctl_eventquery - Query the host adapter for the event types
1521 * -EFAULT if data unavailable
1522 * -ENODEV if no such device/adapter
1531 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventquery - " in mptctl_eventquery()
1534 return -EFAULT; in mptctl_eventquery()
1538 ioc->name)); in mptctl_eventquery()
1540 karg.eventTypes = ioc->eventTypes; in mptctl_eventquery()
1545 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventquery - " in mptctl_eventquery()
1547 ioc->name, __FILE__, __LINE__, uarg); in mptctl_eventquery()
1548 return -EFAULT; in mptctl_eventquery()
1553 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1561 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventenable - " in mptctl_eventenable()
1564 return -EFAULT; in mptctl_eventenable()
1568 ioc->name)); in mptctl_eventenable()
1569 if (ioc->events == NULL) { in mptctl_eventenable()
1570 /* Have not yet allocated memory - do so now. in mptctl_eventenable()
1573 ioc->events = kzalloc(sz, GFP_KERNEL); in mptctl_eventenable()
1574 if (!ioc->events) { in mptctl_eventenable()
1576 ": ERROR - Insufficient memory to add adapter!\n", in mptctl_eventenable()
1577 ioc->name); in mptctl_eventenable()
1578 return -ENOMEM; in mptctl_eventenable()
1580 ioc->alloc_total += sz; in mptctl_eventenable()
1582 ioc->eventContext = 0; in mptctl_eventenable()
1585 /* Update the IOC event logging flag. in mptctl_eventenable()
1587 ioc->eventTypes = karg.eventTypes; in mptctl_eventenable()
1592 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1601 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventreport - " in mptctl_eventreport()
1604 return -EFAULT; in mptctl_eventreport()
1608 ioc->name)); in mptctl_eventreport()
1610 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header); in mptctl_eventreport()
1619 if ((max < 1) || !ioc->events) in mptctl_eventreport()
1620 return -ENODATA; in mptctl_eventreport()
1623 ioc->aen_event_read_flag=0; in mptctl_eventreport()
1628 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) { in mptctl_eventreport()
1629 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventreport - " in mptctl_eventreport()
1631 ioc->name, __FILE__, __LINE__, ioc->events); in mptctl_eventreport()
1632 return -EFAULT; in mptctl_eventreport()
1638 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1647 printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - " in mptctl_replace_fw()
1650 return -EFAULT; in mptctl_replace_fw()
1654 ioc->name)); in mptctl_replace_fw()
1657 if (ioc->cached_fw == NULL) in mptctl_replace_fw()
1667 if (ioc->cached_fw == NULL) in mptctl_replace_fw()
1668 return -ENOMEM; in mptctl_replace_fw()
1672 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) { in mptctl_replace_fw()
1673 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - " in mptctl_replace_fw()
1675 "@ %p\n", ioc->name, __FILE__, __LINE__, uarg); in mptctl_replace_fw()
1677 return -EFAULT; in mptctl_replace_fw()
1680 /* Update IOCFactsReply in mptctl_replace_fw()
1682 ioc->facts.FWImageSize = newFwSize; in mptctl_replace_fw()
1686 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1692 * -EBUSY if previous command timeout and IOC reset is not complete.
1693 * -EFAULT if data unavailable
1694 * -ENODEV if no such device/adapter
1695 * -ETIME if timer expires
1696 * -ENOMEM if memory allocation error
1707 printk(KERN_ERR MYNAM "%s@%d::mptctl_mpt_command - " in mptctl_mpt_command()
1710 return -EFAULT; in mptctl_mpt_command()
1713 rc = mptctl_do_mpt_command (ioc, karg, &uarg->MF); in mptctl_mpt_command()
1718 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1723 * -EBUSY if previous command timeout and IOC reset is not complete.
1724 * -EFAULT if data unavailable
1725 * -ENODEV if no such device/adapter
1726 * -ETIME if timer expires
1727 * -ENOMEM if memory allocation error
1728 * -EPERM if SCSI I/O and target is untagged
1756 spin_lock_irqsave(&ioc->taskmgmt_lock, flags); in mptctl_do_mpt_command()
1757 if (ioc->ioc_reset_in_progress) { in mptctl_do_mpt_command()
1758 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); in mptctl_do_mpt_command()
1759 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1761 return -EBUSY; in mptctl_do_mpt_command()
1763 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); in mptctl_do_mpt_command()
1771 karg.dataSgeOffset > ioc->req_sz / 4) in mptctl_do_mpt_command()
1772 return -EINVAL; in mptctl_do_mpt_command()
1778 sz += ioc->SGE_size; in mptctl_do_mpt_command()
1780 sz += ioc->SGE_size; in mptctl_do_mpt_command()
1782 if (sz > ioc->req_sz) { in mptctl_do_mpt_command()
1783 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1785 ioc->name, __FILE__, __LINE__, sz, ioc->req_sz); in mptctl_do_mpt_command()
1786 return -EFAULT; in mptctl_do_mpt_command()
1792 return -EAGAIN; in mptctl_do_mpt_command()
1795 msgContext = le32_to_cpu(hdr->MsgContext); in mptctl_do_mpt_command()
1796 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); in mptctl_do_mpt_command()
1803 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1805 ioc->name, __FILE__, __LINE__, mfPtr); in mptctl_do_mpt_command()
1806 function = -1; in mptctl_do_mpt_command()
1807 rc = -EFAULT; in mptctl_do_mpt_command()
1810 hdr->MsgContext = cpu_to_le32(msgContext); in mptctl_do_mpt_command()
1811 function = hdr->Function; in mptctl_do_mpt_command()
1817 ioc->name, hdr->Function, mf)); in mptctl_do_mpt_command()
1830 "number=0x%02x action=0x%02x\n", ioc->name, in mptctl_do_mpt_command()
1831 config_frame->Header.PageType, in mptctl_do_mpt_command()
1832 config_frame->ExtPageType, in mptctl_do_mpt_command()
1833 config_frame->Header.PageNumber, in mptctl_do_mpt_command()
1834 config_frame->Action)); in mptctl_do_mpt_command()
1849 if (ioc->sh) { in mptctl_do_mpt_command()
1856 id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus; in mptctl_do_mpt_command()
1857 if (pScsiReq->TargetID > id) { in mptctl_do_mpt_command()
1858 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1860 ioc->name, __FILE__, __LINE__); in mptctl_do_mpt_command()
1861 rc = -ENODEV; in mptctl_do_mpt_command()
1865 if (pScsiReq->Bus >= ioc->number_of_buses) { in mptctl_do_mpt_command()
1866 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1868 ioc->name, __FILE__, __LINE__); in mptctl_do_mpt_command()
1869 rc = -ENODEV; in mptctl_do_mpt_command()
1873 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; in mptctl_do_mpt_command()
1874 pScsiReq->MsgFlags |= mpt_msg_flags(ioc); in mptctl_do_mpt_command()
1881 * update the control field to specify Q type in mptctl_do_mpt_command()
1884 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; in mptctl_do_mpt_command()
1886 pScsiReq->SenseBufferLength = karg.maxSenseBytes; in mptctl_do_mpt_command()
1888 pScsiReq->SenseBufferLowAddr = in mptctl_do_mpt_command()
1889 cpu_to_le32(ioc->sense_buf_low_dma in mptctl_do_mpt_command()
1892 shost_for_each_device(sdev, ioc->sh) { in mptctl_do_mpt_command()
1894 VirtTarget *vtarget = starget->hostdata; in mptctl_do_mpt_command()
1899 if ((pScsiReq->TargetID == vtarget->id) && in mptctl_do_mpt_command()
1900 (pScsiReq->Bus == vtarget->channel) && in mptctl_do_mpt_command()
1901 (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)) in mptctl_do_mpt_command()
1916 pScsiReq->Control = cpu_to_le32(scsidir | qtag); in mptctl_do_mpt_command()
1917 pScsiReq->DataLength = cpu_to_le32(dataSize); in mptctl_do_mpt_command()
1921 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1923 ioc->name, __FILE__, __LINE__); in mptctl_do_mpt_command()
1924 rc = -EFAULT; in mptctl_do_mpt_command()
1930 /* Check mf->PassthruFlags to determine if in mptctl_do_mpt_command()
1939 if (!ioc->sh) { in mptctl_do_mpt_command()
1940 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1942 ioc->name, __FILE__, __LINE__); in mptctl_do_mpt_command()
1943 rc = -EFAULT; in mptctl_do_mpt_command()
1954 if (ioc->sh) { in mptctl_do_mpt_command()
1960 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; in mptctl_do_mpt_command()
1961 pScsiReq->MsgFlags |= mpt_msg_flags(ioc); in mptctl_do_mpt_command()
1968 * update the control field to specify Q type in mptctl_do_mpt_command()
1971 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; in mptctl_do_mpt_command()
1973 pScsiReq->SenseBufferLength = karg.maxSenseBytes; in mptctl_do_mpt_command()
1975 pScsiReq->SenseBufferLowAddr = in mptctl_do_mpt_command()
1976 cpu_to_le32(ioc->sense_buf_low_dma in mptctl_do_mpt_command()
1993 pScsiReq->Control = cpu_to_le32(scsidir | qtag); in mptctl_do_mpt_command()
1994 pScsiReq->DataLength = cpu_to_le32(dataSize); in mptctl_do_mpt_command()
1997 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
1999 ioc->name, __FILE__, __LINE__); in mptctl_do_mpt_command()
2000 rc = -EFAULT; in mptctl_do_mpt_command()
2012 ioc->name, pScsiTm->TaskType, le32_to_cpu in mptctl_do_mpt_command()
2013 (pScsiTm->TaskMsgContext), pScsiTm->MsgFlags, in mptctl_do_mpt_command()
2014 pScsiTm->TargetID, pScsiTm->Bus)); in mptctl_do_mpt_command()
2027 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32)); in mptctl_do_mpt_command()
2028 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32)); in mptctl_do_mpt_command()
2034 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) || in mptctl_do_mpt_command()
2035 (pInit->MaxBuses != ioc->facts.MaxBuses) || in mptctl_do_mpt_command()
2036 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) || in mptctl_do_mpt_command()
2037 (pInit->HostMfaHighAddr != high_addr) || in mptctl_do_mpt_command()
2038 (pInit->SenseBufferHighAddr != sense_high)) { in mptctl_do_mpt_command()
2039 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
2041 ioc->name, __FILE__, __LINE__); in mptctl_do_mpt_command()
2042 rc = -EFAULT; in mptctl_do_mpt_command()
2072 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
2074 ioc->name, __FILE__, __LINE__, hdr->Function); in mptctl_do_mpt_command()
2075 rc = -EFAULT; in mptctl_do_mpt_command()
2080 * In the case of two SGE's - the data out (write) will always in mptctl_do_mpt_command()
2107 bufOut.kptr = dma_alloc_coherent(&ioc->pcidev->dev, in mptctl_do_mpt_command()
2112 rc = -ENOMEM; in mptctl_do_mpt_command()
2118 ioc->add_sge(psge, flagsLength, dma_addr_out); in mptctl_do_mpt_command()
2119 psge += ioc->SGE_size; in mptctl_do_mpt_command()
2127 "%s@%d::mptctl_do_mpt_command - Unable " in mptctl_do_mpt_command()
2130 ioc->name, __FILE__, __LINE__,karg.dataOutBufPtr); in mptctl_do_mpt_command()
2131 rc = -EFAULT; in mptctl_do_mpt_command()
2142 bufIn.kptr = dma_alloc_coherent(&ioc->pcidev->dev, in mptctl_do_mpt_command()
2147 rc = -ENOMEM; in mptctl_do_mpt_command()
2153 ioc->add_sge(psge, flagsLength, dma_addr_in); in mptctl_do_mpt_command()
2159 ioc->add_sge(psge, flagsLength, (dma_addr_t) -1); in mptctl_do_mpt_command()
2162 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext); in mptctl_do_mpt_command()
2163 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status) in mptctl_do_mpt_command()
2164 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) { in mptctl_do_mpt_command()
2166 mutex_lock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_mpt_command()
2168 mutex_unlock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_mpt_command()
2174 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && in mptctl_do_mpt_command()
2175 (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) in mptctl_do_mpt_command()
2183 ioc->name, ioc, mf)); in mptctl_do_mpt_command()
2185 rc = -ENODATA; in mptctl_do_mpt_command()
2186 mutex_unlock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_mpt_command()
2197 timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, in mptctl_do_mpt_command()
2199 if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { in mptctl_do_mpt_command()
2200 rc = -ETIME; in mptctl_do_mpt_command()
2202 ioc->name, __func__)); in mptctl_do_mpt_command()
2203 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { in mptctl_do_mpt_command()
2205 mutex_unlock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_mpt_command()
2212 ioc->name, mpt_GetIocState(ioc, 0), function); in mptctl_do_mpt_command()
2214 mutex_unlock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_mpt_command()
2223 mutex_unlock(&ioc->taskmgmt_cmds.mutex); in mptctl_do_mpt_command()
2231 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) { in mptctl_do_mpt_command()
2232 if (karg.maxReplyBytes < ioc->reply_sz) { in mptctl_do_mpt_command()
2234 4*ioc->ioctl_cmds.reply[2]); in mptctl_do_mpt_command()
2236 sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]); in mptctl_do_mpt_command()
2240 ioc->ioctl_cmds.reply, sz)){ in mptctl_do_mpt_command()
2242 "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
2244 ioc->name, __FILE__, __LINE__, karg.replyFrameBufPtr); in mptctl_do_mpt_command()
2245 rc = -ENODATA; in mptctl_do_mpt_command()
2253 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) { in mptctl_do_mpt_command()
2257 ioc->ioctl_cmds.sense, sz)) { in mptctl_do_mpt_command()
2258 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
2260 ioc->name, __FILE__, __LINE__, in mptctl_do_mpt_command()
2262 rc = -ENODATA; in mptctl_do_mpt_command()
2271 if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) && in mptctl_do_mpt_command()
2276 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - " in mptctl_do_mpt_command()
2278 ioc->name, __FILE__, __LINE__, in mptctl_do_mpt_command()
2280 rc = -ENODATA; in mptctl_do_mpt_command()
2286 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status) in mptctl_do_mpt_command()
2287 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0); in mptctl_do_mpt_command()
2292 dma_free_coherent(&ioc->pcidev->dev, bufOut.len, in mptctl_do_mpt_command()
2297 dma_free_coherent(&ioc->pcidev->dev, bufIn.len, in mptctl_do_mpt_command()
2310 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2315 * -EFAULT if data unavailable
2316 * -EBUSY if previous command timeout and IOC reset is not complete.
2317 * -ENODEV if no such device/adapter
2318 * -ETIME if timer expires
2319 * -ENOMEM if memory allocation error
2344 return -EFAULT; in mptctl_hp_hostinfo()
2347 printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_host_info - " in mptctl_hp_hostinfo()
2350 return -EFAULT; in mptctl_hp_hostinfo()
2354 ioc->name)); in mptctl_hp_hostinfo()
2359 pdev = (struct pci_dev *) ioc->pcidev; in mptctl_hp_hostinfo()
2361 karg.vendor = pdev->vendor; in mptctl_hp_hostinfo()
2362 karg.device = pdev->device; in mptctl_hp_hostinfo()
2363 karg.subsystem_id = pdev->subsystem_device; in mptctl_hp_hostinfo()
2364 karg.subsystem_vendor = pdev->subsystem_vendor; in mptctl_hp_hostinfo()
2365 karg.devfn = pdev->devfn; in mptctl_hp_hostinfo()
2366 karg.bus = pdev->bus->number; in mptctl_hp_hostinfo()
2371 if (ioc->sh != NULL) in mptctl_hp_hostinfo()
2372 karg.host_no = ioc->sh->host_no; in mptctl_hp_hostinfo()
2374 karg.host_no = -1; in mptctl_hp_hostinfo()
2379 ioc->facts.FWVersion.Struct.Major, in mptctl_hp_hostinfo()
2380 ioc->facts.FWVersion.Struct.Minor, in mptctl_hp_hostinfo()
2381 ioc->facts.FWVersion.Struct.Unit, in mptctl_hp_hostinfo()
2382 ioc->facts.FWVersion.Struct.Dev); in mptctl_hp_hostinfo()
2391 cfg.physAddr = -1; in mptctl_hp_hostinfo()
2399 if (cfg.cfghdr.hdr->PageLength > 0) { in mptctl_hp_hostinfo()
2403 pbuf = dma_alloc_coherent(&ioc->pcidev->dev, in mptctl_hp_hostinfo()
2410 if (strlen(pdata->BoardTracerNumber) > 1) { in mptctl_hp_hostinfo()
2412 pdata->BoardTracerNumber, 24); in mptctl_hp_hostinfo()
2415 dma_free_coherent(&ioc->pcidev->dev, in mptctl_hp_hostinfo()
2441 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC)) in mptctl_hp_hostinfo()
2449 if (ioc->sh != NULL) { in mptctl_hp_hostinfo()
2450 MPT_SCSI_HOST *hd = shost_priv(ioc->sh); in mptctl_hp_hostinfo()
2453 karg.hard_resets = ioc->hard_resets; in mptctl_hp_hostinfo()
2454 karg.soft_resets = ioc->soft_resets; in mptctl_hp_hostinfo()
2455 karg.timeouts = ioc->timeouts; in mptctl_hp_hostinfo()
2464 "%s, no msg frames!!\n", ioc->name, __func__)); in mptctl_hp_hostinfo()
2469 msgcontext = IstwiRWRequest->MsgContext; in mptctl_hp_hostinfo()
2471 IstwiRWRequest->MsgContext = msgcontext; in mptctl_hp_hostinfo()
2472 IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX; in mptctl_hp_hostinfo()
2473 IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL; in mptctl_hp_hostinfo()
2474 IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ; in mptctl_hp_hostinfo()
2475 IstwiRWRequest->NumAddressBytes = 0x01; in mptctl_hp_hostinfo()
2476 IstwiRWRequest->DataLength = cpu_to_le16(0x04); in mptctl_hp_hostinfo()
2477 if (pdev->devfn & 1) in mptctl_hp_hostinfo()
2478 IstwiRWRequest->DeviceAddr = 0xB2; in mptctl_hp_hostinfo()
2480 IstwiRWRequest->DeviceAddr = 0xB0; in mptctl_hp_hostinfo()
2482 pbuf = dma_alloc_coherent(&ioc->pcidev->dev, 4, &buf_dma, GFP_KERNEL); in mptctl_hp_hostinfo()
2485 ioc->add_sge((char *)&IstwiRWRequest->SGL, in mptctl_hp_hostinfo()
2488 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, in mptctl_hp_hostinfo()
2489 IstwiRWRequest->MsgContext); in mptctl_hp_hostinfo()
2490 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status) in mptctl_hp_hostinfo()
2494 timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, in mptctl_hp_hostinfo()
2496 if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { in mptctl_hp_hostinfo()
2497 printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__); in mptctl_hp_hostinfo()
2498 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { in mptctl_hp_hostinfo()
2505 ioc->name, mpt_GetIocState(ioc, 0)); in mptctl_hp_hostinfo()
2521 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) in mptctl_hp_hostinfo()
2525 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status) in mptctl_hp_hostinfo()
2526 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0); in mptctl_hp_hostinfo()
2529 dma_free_coherent(&ioc->pcidev->dev, 4, pbuf, buf_dma); in mptctl_hp_hostinfo()
2534 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hpgethostinfo - " in mptctl_hp_hostinfo()
2536 ioc->name, __FILE__, __LINE__, uarg); in mptctl_hp_hostinfo()
2537 return -EFAULT; in mptctl_hp_hostinfo()
2544 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2549 * -EFAULT if data unavailable
2550 * -EBUSY if previous command timeout and IOC reset is not complete.
2551 * -ENODEV if no such device/adapter
2552 * -ETIME if timer expires
2553 * -ENOMEM if memory allocation error
2570 printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_targetinfo - " in mptctl_hp_targetinfo()
2573 return -EFAULT; in mptctl_hp_targetinfo()
2577 return -EINVAL; in mptctl_hp_targetinfo()
2579 ioc->name)); in mptctl_hp_targetinfo()
2583 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC)) in mptctl_hp_targetinfo()
2586 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL)) in mptctl_hp_targetinfo()
2589 if (ioc->sh->host_no != karg.hdr.host) in mptctl_hp_targetinfo()
2590 return -ENODEV; in mptctl_hp_targetinfo()
2594 data_sz = ioc->spi_data.sdp0length * 4; in mptctl_hp_targetinfo()
2595 pg0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz, &page_dma, in mptctl_hp_targetinfo()
2598 hdr.PageVersion = ioc->spi_data.sdp0version; in mptctl_hp_targetinfo()
2612 np = le32_to_cpu(pg0_alloc->NegotiatedParameters); in mptctl_hp_targetinfo()
2634 dma_free_coherent(&ioc->pcidev->dev, data_sz, (u8 *)pg0_alloc, in mptctl_hp_targetinfo()
2640 karg.message_rejects = -1; in mptctl_hp_targetinfo()
2641 karg.phase_errors = -1; in mptctl_hp_targetinfo()
2642 karg.parity_errors = -1; in mptctl_hp_targetinfo()
2643 karg.select_timeouts = -1; in mptctl_hp_targetinfo()
2656 cfg.physAddr = -1; in mptctl_hp_targetinfo()
2657 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) { in mptctl_hp_targetinfo()
2660 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4; in mptctl_hp_targetinfo()
2661 pg3_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz, in mptctl_hp_targetinfo()
2667 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount); in mptctl_hp_targetinfo()
2668 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount); in mptctl_hp_targetinfo()
2669 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount); in mptctl_hp_targetinfo()
2671 dma_free_coherent(&ioc->pcidev->dev, data_sz, in mptctl_hp_targetinfo()
2675 hd = shost_priv(ioc->sh); in mptctl_hp_targetinfo()
2677 karg.select_timeouts = hd->sel_timeout[karg.hdr.id]; in mptctl_hp_targetinfo()
2682 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hp_target_info - " in mptctl_hp_targetinfo()
2684 ioc->name, __FILE__, __LINE__, uarg); in mptctl_hp_targetinfo()
2685 return -EFAULT; in mptctl_hp_targetinfo()
2691 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2709 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2721 int nonblock = (filp->f_flags & O_NONBLOCK); in compat_mptfwxfer_ioctl()
2726 return -EFAULT; in compat_mptfwxfer_ioctl()
2732 printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n", in compat_mptfwxfer_ioctl()
2734 return -ENODEV; in compat_mptfwxfer_ioctl()
2741 iocp->name)); in compat_mptfwxfer_ioctl()
2748 mutex_unlock(&iocp->ioctl_cmds.mutex); in compat_mptfwxfer_ioctl()
2762 int nonblock = (filp->f_flags & O_NONBLOCK); in compat_mpt_command()
2766 return -EFAULT; in compat_mpt_command()
2772 printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n", in compat_mpt_command()
2774 return -ENODEV; in compat_mpt_command()
2781 iocp->name)); in compat_mpt_command()
2800 ret = mptctl_do_mpt_command (iocp, karg, &uarg->MF); in compat_mpt_command()
2802 mutex_unlock(&iocp->ioctl_cmds.mutex); in compat_mpt_command()
2832 ret = -ENOIOCTLCMD; in compat_mpctl_ioctl()
2842 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2844 * mptctl_probe - Installs ioctl devices per bus.
2847 * Returns 0 for success, non-zero for failure.
2856 mutex_init(&ioc->ioctl_cmds.mutex); in mptctl_probe()
2857 init_completion(&ioc->ioctl_cmds.done); in mptctl_probe()
2861 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2863 * mptctl_remove - Removed ioctl devices
2878 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2905 err = -EBUSY; in mptctl_init()
2915 err = -EBUSY; in mptctl_init()
2931 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2938 /* De-register event handler from base module */ in mptctl_exit()
2941 /* De-register reset handler from base module */ in mptctl_exit()
2944 /* De-register callback handler from base module */ in mptctl_exit()
2952 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/