mptctl.c
来自「microwindows移植到S3C44B0的源码」· C语言 代码 · 共 2,303 行 · 第 1/5 页
C
2,303 行
break; case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: if (ioc->sh) { SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf; int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ; int scsidir = MPI_SCSIIO_CONTROL_READ; int dataSize; pScsiReq->MsgFlags = MPT_SCSIIO_MSG_FLAGS; /* verify that app has not requested * more sense data than driver * can provide, if so, reset this parameter * set the sense buffer pointer low address * update the control field to specify Q type */ if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE) pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma + (req_idx * MPT_SENSE_BUFFER_ALLOC)); /* All commands to physical devices are tagged */ /* Have the IOCTL driver set the direction based * on the dataOutSize (ordering issue with Sparc). */ if (karg.dataOutSize > 0 ) { scsidir = MPI_SCSIIO_CONTROL_WRITE; dataSize = karg.dataOutSize; } else { scsidir = MPI_SCSIIO_CONTROL_READ; dataSize = karg.dataInSize; } pScsiReq->Control = cpu_to_le32(scsidir | qtag); pScsiReq->DataLength = cpu_to_le32(dataSize); } else { printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " "SCSI driver is not loaded. \n", __FILE__, __LINE__); rc = -EFAULT; goto done_free_mem; } break; default: /* * MPI_FUNCTION_IOC_INIT * MPI_FUNCTION_PORT_ENABLE * MPI_FUNCTION_TARGET_CMD_BUFFER_POST * MPI_FUNCTION_TARGET_ASSIST * MPI_FUNCTION_TARGET_STATUS_SEND * MPI_FUNCTION_TARGET_MODE_ABORT * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET * MPI_FUNCTION_IO_UNIT_RESET * MPI_FUNCTION_HANDSHAKE * MPI_FUNCTION_REPLY_FRAME_REMOVAL * MPI_FUNCTION_EVENT_NOTIFICATION * (driver handles event notification) * MPI_FUNCTION_EVENT_ACK * MPI_FUNCTION_SCSI_TASK_MGMT */ /* What to do with these??? CHECK ME!!! MPI_FUNCTION_FC_LINK_SRVC_BUF_POST MPI_FUNCTION_FC_LINK_SRVC_RSP MPI_FUNCTION_FC_ABORT MPI_FUNCTION_FC_PRIMITIVE_SEND MPI_FUNCTION_LAN_SEND MPI_FUNCTION_LAN_RECEIVE MPI_FUNCTION_LAN_RESET */ printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " "Illegal request (function 0x%x) \n", __FILE__, __LINE__, hdr->Function); rc = -EFAULT; goto done_free_mem; } /* Add the SGL ( at most one data in SGE and one data out SGE ) * In the case of two SGE's - the data out (write) will always * preceede the data in (read) SGE. psgList is used to free the * allocated memory. */ psge = (MptSge_t *) ( ((int *) mf) + karg.dataSgeOffset); flagsLength = 0; /* bufIn and bufOut are used for user to kernel space transfers */ bufIn.kptr = bufOut.kptr = NULL; bufIn.len = bufOut.len = 0; if (karg.dataOutSize > 0 ) sgSize ++; if (karg.dataInSize > 0 ) sgSize ++; if (sgSize > 0) { /* Allocate memory for the SGL. * Used to free kernel memory once * the MF is freed. */ sglbuf = pci_alloc_consistent (ioc->pcidev, sgSize*sizeof(MptSge_t), &sglbuf_dma); if (sglbuf == NULL) { rc = -ENOMEM; goto done_free_mem; } this_sge = sglbuf; /* Set up the dataOut memory allocation */ if (karg.dataOutSize > 0) { dir = PCI_DMA_TODEVICE; if (karg.dataInSize > 0 ) { flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT | MPI_SGE_FLAGS_DIRECTION | MPT_SGE_ADDRESS_SIZE ) << MPI_SGE_FLAGS_SHIFT; } else { flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE; } flagsLength |= karg.dataOutSize; this_alloc = karg.dataOutSize; bufOut.len = this_alloc; bufOut.kptr = pci_alloc_consistent( ioc->pcidev, this_alloc, &dma_addr); if (bufOut.kptr == NULL) { rc = -ENOMEM; goto done_free_mem; } else { /* Copy user data to kernel space. */ if (copy_from_user(bufOut.kptr, karg.dataOutBufPtr, bufOut.len)) { printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - Unable " "to read user data " "struct @ %p\n", __FILE__, __LINE__,(void*)karg.dataOutBufPtr); rc = -EFAULT; goto done_free_mem; } /* Set up this SGE. * Copy to MF and to sglbuf */ psge->FlagsLength = cpu_to_le32 (flagsLength); cpu_to_leXX(dma_addr, psge->Address); psge++; this_sge->FlagsLength=cpu_to_le32(flagsLength); cpu_to_leXX(dma_addr, this_sge->Address); this_sge++; } } if (karg.dataInSize > 0) { dir = PCI_DMA_FROMDEVICE; flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ; flagsLength |= karg.dataInSize; this_alloc = karg.dataInSize; bufIn.len = this_alloc; bufIn.kptr = pci_alloc_consistent(ioc->pcidev, this_alloc, &dma_addr); if (bufIn.kptr == NULL) { rc = -ENOMEM; goto done_free_mem; } else { /* Set up this SGE * Copy to MF and to sglbuf */ psge->FlagsLength = cpu_to_le32 (flagsLength); cpu_to_leXX(dma_addr, psge->Address); this_sge->FlagsLength=cpu_to_le32(flagsLength); cpu_to_leXX(dma_addr, this_sge->Address); this_sge++; } } } else { /* Add a NULL SGE */ flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ; psge->FlagsLength = cpu_to_le32 (flagsLength); cpu_to_leXX( (dma_addr_t) -1, psge->Address); } /* The request is complete. Set the timer parameters * and issue the request. */ if (karg.timeout > 0) { ioc->ioctl->timer.expires = jiffies + HZ*karg.timeout; } else { ioc->ioctl->timer.expires = jiffies + HZ*MPT_IOCTL_DEFAULT_TIMEOUT; } ioc->ioctl->wait_done = 0; ioc->ioctl->status |= MPT_IOCTL_STATUS_TIMER_ACTIVE; add_timer(&ioc->ioctl->timer); mpt_put_msg_frame(mptctl_id, ioc->id, mf); wait_event(mptctl_wait, ioc->ioctl->wait_done); /* The command is complete. * Return data to the user. * * If command completed, mf has been freed so cannot * use this memory. * * If timeout, a recovery mechanism has been called. * Need to free the mf. */ if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_TIMEOUT) { /* A timeout - there is no data to return to the * the user other than an error. * The timer callback deleted the * timer and reset the adapter queues. */ printk(KERN_WARNING "%s@%d::mptctl_do_mpt_command - " "Timeout Occurred on IOCTL! Resetting IOC.\n", __FILE__, __LINE__); rc = -ETIME; /* Free memory and return to the calling function */ goto done_free_mem; } else { /* Callback freed request frame. */ mf = NULL; /* If a valid reply frame, copy to the user. * Offset 2: reply length in U32's */ if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) { if (karg.maxReplyBytes < ioc->reply_sz) { sz = MIN(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]); } else { sz = MIN(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]); } if (sz > 0) { if (copy_to_user((char *)karg.replyFrameBufPtr, &ioc->ioctl->ReplyFrame, sz)){ printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " "Unable to write out reply frame %p\n", __FILE__, __LINE__, (void*)karg.replyFrameBufPtr); rc = -ENODATA; goto done_free_mem; } } } /* If valid sense data, copy to user. */ if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) { sz = MIN(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE); if (sz > 0) { if (copy_to_user((char *)karg.senseDataPtr, ioc->ioctl->sense, sz)) { printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " "Unable to write sense data to user %p\n", __FILE__, __LINE__, (void*)karg.senseDataPtr); rc = -ENODATA; goto done_free_mem; } } } /* If the overall status is _GOOD and data in, copy data * to user. */ if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) && (karg.dataInSize > 0) && (bufIn.kptr)) { if (copy_to_user((char *)karg.dataInBufPtr, bufIn.kptr, karg.dataInSize)) { printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " "Unable to write data to user %p\n", __FILE__, __LINE__, (void*)karg.dataInBufPtr); rc = -ENODATA; } } }done_free_mem: /* Clear status bits. */ ioc->ioctl->status = 0; if (sglbuf) { this_sge = sglbuf; /* Free the allocated memory. */ if (bufOut.kptr != NULL ) { leXX_to_cpu (dma_addr, this_sge->Address); this_sge++; /* go to next structure */ this_alloc = bufOut.len; pci_free_consistent(ioc->pcidev, this_alloc, (void *) &bufOut, dma_addr); } if (bufIn.kptr != NULL ) { leXX_to_cpu (dma_addr, this_sge->Address); this_alloc = bufIn.len; pci_free_consistent(ioc->pcidev, this_alloc, (void *) &bufIn, dma_addr); } this_alloc = sgSize * sizeof(MptSge_t); pci_free_consistent(ioc->pcidev, this_alloc, (void *) sglbuf, sglbuf_dma); } /* mf will be null if allocation failed OR * if command completed OK (callback freed) */ if (mf) mpt_free_msg_frame(mptctl_id, ioc->id, mf); return rc;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* Routine for the Compaq IOCTL commands. * * Outputs: None. * Return: 0 if successful * -EBUSY if previous command timout and IOC reset is not complete. * -EFAULT if data unavailable * -ENODEV if no such device/adapter * -ETIME if timer expires * -ENOMEM if memory allocation error */static intmptctl_compaq_ioctl(struct file *file, unsigned int cmd, unsigned long arg){ int iocnum = 0; unsigned iocnumX = 0; int ret; int nonblock = (file->f_flags & O_NONBLOCK); MPT_ADAPTER *iocp = NULL; if (cmd == CPQFCTS_SCSI_PASSTHRU) { /* Update the iocnum */ if (copy_from_user(&iocnumX, (int *)arg, sizeof(int))) { printk(KERN_ERR "%s::mptctl_compaq_ioctl() @%d - " "Unable to read controller number @ %p\n", __FILE__, __LINE__, (void*)arg); return -EFAULT; } iocnumX &= 0xFF; } if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) || (iocp == NULL)) { printk(KERN_ERR "%s::mptctl_compaq_ioctl() @%d - ioc%d not found!\n", __FILE__, __LINE__, iocnumX); return -ENODEV; } /* 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_compaq_ioctl()\n", iocp->name)); switch(cmd) { case CPQFCTS_GETPCIINFO: ret = mptctl_cpq_getpciinfo(arg); break; case CPQFCTS_GETDRIVER: ret = mptctl_cpq_getdriver(arg); break; case CPQFCTS_CTLR_STATUS: ret = mptctl_cpq_ctlr_status(arg); break; case CPQFCTS_SCSI_IOCTL_FC_TARGET_ADDRESS: ret = mptctl_cpq_target_address(arg); break; case CPQFCTS_SCSI_PASSTHRU: ret = mptctl_cpq_passthru(arg); break; default: ret = -EINVAL; } up(&mptctl_syscall_sem_ioc[iocp->id]); return ret;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* mptctl_cpq_getpciinfo - Get PCI Information in format desired by Compaq * * Outputs: None. * Return: 0 if successful * -EBUSY if previous command timout and IOC reset is not complete. * -EFAULT if data unavailable * -ENODEV if no such device/adapter * -ETIME if timer expires */static intmptctl_cpq_getpciinfo(unsigned long arg){ cpqfc_pci_info_struct *uarg = (cpqfc_pci_info_struct *) arg; cpqfc_pci_info_struct karg; MPT_ADAPTER *ioc; struct pci_dev *pdev; CONFIGPARMS cfg; ConfigPageHeader_t hdr; int iocnum = 0, iocnumX = 0; dma_addr_t buf_dma; u8 *pbuf = NULL; int failed; dctlprintk((": mptctl_cpq_pciinfo called.\n")); if (copy_from_user(&karg, uarg, sizeof(cpqfc_pci_info_struct))) { printk(KERN_ERR "%s@%d::mptctl_cpq_pciinfo - " "Unable to read in cpqfc_pci_info_struct @ %p\n", __FILE__, __LINE__, (void*)uarg); return -EFAULT; } if (((iocnum = mpt_verify_adapter(iocnumX, &ioc)) < 0) || (ioc == NULL)) { printk(KERN_ERR "%s::mptctl_pciinfo() @%d - ioc%d not found!\n", __FILE__, __LINE__, iocnum); return -ENODEV; } pdev = (struct pci_dev *) ioc->pcidev; /* Populate
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?