📄 mptctl.c
字号:
mptctl_free_tm_flags(ioctl->ioc); del_timer(&ioctl->TMtimer); mpt_free_msg_frame(mptctl_id, ioctl->ioc->id, mf); ioctl->tmPtr = NULL; } return retval;}static intmptctl_set_tm_flags(MPT_SCSI_HOST *hd) { unsigned long flags; spin_lock_irqsave(&hd->ioc->FreeQlock, flags);#ifdef MPT_SCSI_USE_NEW_EH if (hd->tmState == TM_STATE_NONE) { hd->tmState = TM_STATE_IN_PROGRESS; hd->tmPending = 1; spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); } else { spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); return -EBUSY; }#else if (hd->tmPending) { spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); return -EBUSY; } else { hd->tmPending = 1; spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); }#endif return 0;}static voidmptctl_free_tm_flags(MPT_ADAPTER *ioc){ MPT_SCSI_HOST * hd; unsigned long flags; hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; if (hd == NULL) return; spin_lock_irqsave(&ioc->FreeQlock, flags);#ifdef MPT_SCSI_USE_NEW_EH hd->tmState = TM_STATE_ERROR; hd->tmPending = 0; spin_unlock_irqrestore(&ioc->FreeQlock, flags);#else hd->tmPending = 0; spin_unlock_irqrestore(&ioc->FreeQlock, flags);#endif return;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* mptctl_ioc_reset * * Clean-up functionality. Used only if there has been a * reload of the FW due. * */static intmptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase){ MPT_IOCTL *ioctl = ioc->ioctl; dctlprintk((KERN_INFO MYNAM ": IOC %s_reset routed to IOCTL driver!\n", reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")); if (reset_phase == MPT_IOC_PRE_RESET){ /* Someone has called the reset handler to * do a hard reset. No more replies from the FW. * Delete the timer. TM flags cleaned up by SCSI driver. * Do not need to free msg frame, as re-initialized */ if (ioctl && (ioctl->status & MPT_IOCTL_STATUS_TIMER_ACTIVE)){ del_timer(&ioctl->timer); } if (ioctl && (ioctl->status & MPT_IOCTL_STATUS_TMTIMER_ACTIVE)){ ioctl->status &= ~MPT_IOCTL_STATUS_TMTIMER_ACTIVE; del_timer(&ioctl->TMtimer); mpt_free_msg_frame(mptctl_id, ioc->id, ioctl->tmPtr); } } else { /* Set the status and continue IOCTL * processing. All memory will be free'd * by originating thread after wake_up is * called. */ if (ioctl && (ioctl->status & MPT_IOCTL_STATUS_TIMER_ACTIVE)){ ioctl->status = MPT_IOCTL_STATUS_DID_IOCRESET; /* Wake up the calling process */ ioctl->wait_done = 1; wake_up(&mptctl_wait); } } return 1;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* * struct file_operations functionality. * Members: * llseek, write, read, ioctl, open, release *//*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9)static loff_tmptctl_llseek(struct file *file, loff_t offset, int origin){ return -ESPIPE;}#define no_llseek mptctl_llseek#endif/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static ssize_tmptctl_write(struct file *file, const char *buf, size_t count, loff_t *ppos){ printk(KERN_ERR MYNAM ": ioctl WRITE not yet supported\n"); return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static ssize_tmptctl_read(struct file *file, char *buf, size_t count, loff_t *ptr){ printk(KERN_ERR MYNAM ": ioctl READ not yet supported\n"); return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* * MPT ioctl handler * cmd - specify the particular IOCTL command to be issued * arg - data specific to the command. Must not be null. */static intmptctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ mpt_ioctl_header *uhdr = (mpt_ioctl_header *) arg; mpt_ioctl_header khdr; int iocnum; unsigned iocnumX; int nonblock = (file->f_flags & O_NONBLOCK); int ret; MPT_ADAPTER *iocp = NULL; dctlprintk(("mptctl_ioctl() called\n")); if (copy_from_user(&khdr, uhdr, sizeof(khdr))) { printk(KERN_ERR "%s::mptctl_ioctl() @%d - " "Unable to copy mpt_ioctl_header data @ %p\n", __FILE__, __LINE__, (void*)uhdr); return -EFAULT; } ret = -ENXIO; /* (-6) No such device or address */ /* Test for Compaq-specific IOCTL's. */ if ((cmd == CPQFCTS_GETPCIINFO) || (cmd == CPQFCTS_CTLR_STATUS) || (cmd == CPQFCTS_GETDRIVVER) || (cmd == CPQFCTS_SCSI_PASSTHRU) || (cmd == CPQFCTS_SCSI_IOCTL_FC_TARGET_ADDRESS)) return mptctl_compaq_ioctl(file, cmd, arg); /* Verify intended MPT adapter - set iocnum and the adapter * pointer (iocp) */ iocnumX = khdr.iocnum & 0xFF; if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) || (iocp == NULL)) { dctlprintk((KERN_ERR "%s::mptctl_ioctl() @%d - ioc%d not found!\n", __FILE__, __LINE__, iocnumX)); return -ENODEV; } /* Handle those commands that are just returning * information stored in the driver. * These commands should never time out and are unaffected * by TM and FW reloads. */ if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) { return mptctl_getiocinfo(arg, _IOC_SIZE(cmd)); } else if (cmd == MPTTARGETINFO) { return mptctl_gettargetinfo(arg); } else if (cmd == MPTTEST) { return mptctl_readtest(arg); } else if (cmd == MPTEVENTQUERY) { return mptctl_eventquery(arg); } else if (cmd == MPTEVENTENABLE) { return mptctl_eventenable(arg); } else if (cmd == MPTEVENTREPORT) { return mptctl_eventreport(arg); } else if (cmd == MPTFWREPLACE) { return mptctl_replace_fw(arg); } /* All of these commands require an interrupt or * are unknown/illegal. */ if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0) return ret; dctlprintk((MYIOC_s_INFO_FMT ": mptctl_ioctl()\n", iocp->name)); switch(cmd) { case MPTFWDOWNLOAD: ret = mptctl_fw_download(arg); break; case MPTCOMMAND: ret = mptctl_mpt_command(arg); break; case MPTHARDRESET: ret = mptctl_do_reset(arg); break; case HP_GETHOSTINFO: ret = mptctl_hp_hostinfo(arg); break; case HP_GETTARGETINFO: ret = mptctl_hp_targetinfo(arg); break; default: ret = -EINVAL; } up(&mptctl_syscall_sem_ioc[iocp->id]); return ret;}static int mptctl_do_reset(unsigned long arg){ struct mpt_ioctl_diag_reset *urinfo = (struct mpt_ioctl_diag_reset *) arg; struct mpt_ioctl_diag_reset krinfo; MPT_ADAPTER *iocp; dctlprintk((KERN_INFO "mptctl_do_reset called.\n")); if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) { printk(KERN_ERR "%s@%d::mptctl_do_reset - " "Unable to copy mpt_ioctl_diag_reset struct @ %p\n", __FILE__, __LINE__, (void*)urinfo); return -EFAULT; } if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) { dctlprintk((KERN_ERR "%s@%d::mptctl_do_reset - ioc%d not found!\n", __FILE__, __LINE__, krinfo.hdr.iocnum)); return -ENODEV; /* (-6) No such device or address */ } if (mpt_HardResetHandler(iocp, NO_SLEEP) != 0) { printk (KERN_ERR "%s@%d::mptctl_do_reset - reset failed.\n", __FILE__, __LINE__); return -1; } return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static int mptctl_open(struct inode *inode, struct file *file){ /* * Should support multiple management users */ return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static int mptctl_release(struct inode *inode, struct file *file){ return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* * MPT FW download function. Cast the arg into the mpt_fw_xfer structure. * This structure contains: iocnum, firmware length (bytes), * pointer to user space memory where the fw image is stored. * * Outputs: None. * Return: 0 if successful * -EFAULT if data unavailable * -ENXIO if no such device * -EAGAIN if resource problem * -ENOMEM if no memory for SGE * -EMLINK if too many chain buffers required * -EBADRQC if adapter does not support FW download * -EBUSY if adapter is busy * -ENOMSG if FW upload returned bad status */static intmptctl_fw_download(unsigned long arg){ struct mpt_fw_xfer *ufwdl = (struct mpt_fw_xfer *) arg; struct mpt_fw_xfer kfwdl; dctlprintk((KERN_INFO "mptctl_fwdl called. mptctl_id = %xh\n", mptctl_id)); //tc if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) { printk(KERN_ERR "%s@%d::_ioctl_fwdl - " "Unable to copy mpt_fw_xfer struct @ %p\n", __FILE__, __LINE__, (void*)ufwdl); return -EFAULT; } return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* * FW Download engine. * Outputs: None. * Return: 0 if successful * -EFAULT if data unavailable * -ENXIO if no such device * -EAGAIN if resource problem * -ENOMEM if no memory for SGE * -EMLINK if too many chain buffers required * -EBADRQC if adapter does not support FW download * -EBUSY if adapter is busy * -ENOMSG if FW upload returned bad status */static intmptctl_do_fw_download(int ioc, char *ufwbuf, size_t fwlen){ FWDownload_t *dlmsg; MPT_FRAME_HDR *mf; MPT_ADAPTER *iocp; FWDownloadTCSGE_t *ptsge; MptSge_t *sgl, *sgIn; char *sgOut; struct buflist *buflist; struct buflist *bl; dma_addr_t sgl_dma; int ret; int numfrags = 0; int maxfrags; int n = 0; u32 sgdir; u32 nib; int fw_bytes_copied = 0; int i; int cntdn; int sge_offset = 0; u16 iocstat; dctlprintk((KERN_INFO "mptctl_do_fwdl called. mptctl_id = %xh.\n", mptctl_id)); dctlprintk((KERN_INFO "DbG: kfwdl.bufp = %p\n", ufwbuf)); dctlprintk((KERN_INFO "DbG: kfwdl.fwlen = %d\n", (int)fwlen)); dctlprintk((KERN_INFO "DbG: kfwdl.ioc = %04xh\n", ioc)); if ((ioc = mpt_verify_adapter(ioc, &iocp)) < 0) { dctlprintk(("%s@%d::_ioctl_fwdl - ioc%d not found!\n", __FILE__, __LINE__, ioc)); return -ENODEV; /* (-6) No such device or address */ } /* Valid device. Get a message frame and construct the FW download message. */ if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) return -EAGAIN; dlmsg = (FWDownload_t*) mf; ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL; sgOut = (char *) (ptsge + 1); /* * Construct f/w download request */ dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW; dlmsg->Reserved = 0; dlmsg->ChainOffset = 0; dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD; dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0; dlmsg->MsgFlags = 0; /* Set up the Transaction SGE. */ ptsge->Reserved = 0; ptsge->ContextSize = 0; ptsge->DetailsLength = 12; ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT; ptsge->Reserved_0100_Checksum = 0; ptsge->ImageOffset = 0; ptsge->ImageSize = cpu_to_le32(fwlen); /* Add the SGL */ /* * Need to kmalloc area(s) for holding firmware image bytes. * But we need to do it piece meal, using a proper * scatter gather list (with 128kB MAX hunks). * * A practical limit here might be # of sg hunks that fit into * a single IOC request frame; 12 or 8 (see below), so: * For FC9xx: 12 x 128kB == 1.5 mB (max) * For C1030: 8 x 128kB == 1 mB (max) * We could support chaining, but things get ugly(ier:) * * Set the sge_offset to the start of the sgl (bytes). */ sgdir = 0x04000000; /* IOC will READ from sys mem */ sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t); if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset, &numfrags, &buflist, &sgl_dma, iocp)) == NULL) return -ENOMEM; /* * We should only need SGL with 2 simple_32bit entries (up to 256 kB) * for FC9xx f/w image, but calculate max number of sge hunks * we can fit into a request frame, and limit ourselves to that. * (currently no chain support) * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE * Request maxfrags * 128 12 * 96 8 * 64 4 */ maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t)) / (sizeof(dma_addr_t) + sizeof(u32)); if (numfrags > maxfrags) { ret = -EMLINK; goto fwdl_out; } dctlprintk((KERN_INFO "DbG: sgl buffer = %p, sgfrags = %d\n", sgl, numfrags)); /* * Parse SG list, copying sgl itself, * plus f/w image hunks from user space as we go... */ ret = -EFAULT; sgIn = sgl; bl = buflist; for (i=0; i < numfrags; i++) { /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE * Skip everything but Simple. If simple, copy from * user space into kernel space. * Note: we should not have anything but Simple as * Chain SGE are illegal. */ nib = (sgIn->FlagsLength & 0x30000000) >> 28; if (nib == 0 || nib == 3) { ; } else if (sgIn->Address) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -