2 * linux/drivers/message/fusion/mptctl.c
4 * For use with LSI Logic PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * Copyright (c) 1999-2007 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsil.com)
11 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; version 2 of the License.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
23 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
24 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
25 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
26 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
27 solely responsible for determining the appropriateness of using and
28 distributing the Program and assumes all risks associated with its
29 exercise of rights under this Agreement, including but not limited to
30 the risks and costs of program errors, damage to or loss of data,
31 programs or equipment, and unavailability or interruption of operations.
33 DISCLAIMER OF LIABILITY
34 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
35 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
37 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
39 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
40 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, write to the Free Software
44 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
48 #include <linux/kernel.h>
49 #include <linux/module.h>
50 #include <linux/errno.h>
51 #include <linux/init.h>
52 #include <linux/slab.h>
53 #include <linux/types.h>
54 #include <linux/pci.h>
55 #include <linux/delay.h> /* for mdelay */
56 #include <linux/miscdevice.h>
57 #include <linux/smp_lock.h>
58 #include <linux/compat.h>
61 #include <asm/uaccess.h>
63 #include <scsi/scsi.h>
64 #include <scsi/scsi_cmnd.h>
65 #include <scsi/scsi_device.h>
66 #include <scsi/scsi_host.h>
67 #include <scsi/scsi_tcq.h>
69 #define COPYRIGHT "Copyright (c) 1999-2007 LSI Logic Corporation"
70 #define MODULEAUTHOR "LSI Logic Corporation"
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
75 #define my_NAME "Fusion MPT misc device (ioctl) driver"
76 #define my_VERSION MPT_LINUX_VERSION_COMMON
77 #define MYNAM "mptctl"
79 MODULE_AUTHOR(MODULEAUTHOR);
80 MODULE_DESCRIPTION(my_NAME);
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(my_VERSION);
84 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
86 static int mptctl_id = -1;
88 static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
90 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
98 * Function prototypes. Called from OS entry point mptctl_ioctl.
99 * arg contents specific to function.
101 static int mptctl_fw_download(unsigned long arg);
102 static int mptctl_getiocinfo(unsigned long arg, unsigned int cmd);
103 static int mptctl_gettargetinfo(unsigned long arg);
104 static int mptctl_readtest(unsigned long arg);
105 static int mptctl_mpt_command(unsigned long arg);
106 static int mptctl_eventquery(unsigned long arg);
107 static int mptctl_eventenable(unsigned long arg);
108 static int mptctl_eventreport(unsigned long arg);
109 static int mptctl_replace_fw(unsigned long arg);
111 static int mptctl_do_reset(unsigned long arg);
112 static int mptctl_hp_hostinfo(unsigned long arg, unsigned int cmd);
113 static int mptctl_hp_targetinfo(unsigned long arg);
115 static int mptctl_probe(struct pci_dev *, const struct pci_device_id *);
116 static void mptctl_remove(struct pci_dev *);
119 static long compat_mpctl_ioctl(struct file *f, unsigned cmd, unsigned long arg);
122 * Private function calls.
124 static int mptctl_do_mpt_command(struct mpt_ioctl_command karg, void __user *mfPtr);
125 static int mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen);
126 static MptSge_t *kbuf_alloc_2_sgl(int bytes, u32 dir, int sge_offset, int *frags,
127 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);
128 static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma,
129 struct buflist *buflist, MPT_ADAPTER *ioc);
130 static void mptctl_timeout_expired (MPT_IOCTL *ioctl);
131 static int mptctl_bus_reset(MPT_IOCTL *ioctl);
132 static int mptctl_set_tm_flags(MPT_SCSI_HOST *hd);
133 static void mptctl_free_tm_flags(MPT_ADAPTER *ioc);
136 * Reset Handler cleanup function
138 static int mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase);
141 * Event Handler function
143 static int mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
144 static struct fasync_struct *async_queue=NULL;
146 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
148 * Scatter gather list (SGL) sizes and limits...
150 //#define MAX_SCSI_FRAGS 9
151 #define MAX_FRAGS_SPILL1 9
152 #define MAX_FRAGS_SPILL2 15
153 #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1)
155 //#define MAX_CHAIN_FRAGS 64
156 //#define MAX_CHAIN_FRAGS (15+15+15+16)
157 #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1)
159 // Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each)
160 // Works out to: 592d bytes! (9+1)*8 + 4*(15+1)*8
161 // ^----------------- 80 + 512
162 #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)
164 /* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */
165 #define MAX_KMALLOC_SZ (128*1024)
167 #define MPT_IOCTL_DEFAULT_TIMEOUT 10 /* Default timeout value (seconds) */
169 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
171 * mptctl_syscall_down - Down the MPT adapter syscall semaphore.
172 * @ioc: Pointer to MPT adapter
173 * @nonblock: boolean, non-zero if O_NONBLOCK is set
175 * All of the ioctl commands can potentially sleep, which is illegal
176 * with a spinlock held, thus we perform mutual exclusion here.
178 * Returns negative errno on error, or zero for success.
181 mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock)
184 dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down(%p,%d) called\n", ioc, nonblock));
187 if (!mutex_trylock(&ioc->ioctl->ioctl_mutex))
190 if (mutex_lock_interruptible(&ioc->ioctl->ioctl_mutex))
193 dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down return %d\n", rc));
197 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
199 * This is the callback for any message we have posted. The message itself
200 * will be returned to the message pool when we return from the IRQ
202 * This runs in irq context so be short and sweet.
205 mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
212 dctlprintk(("mptctl_reply()!\n"));
214 cmd = req->u.hdr.Function;
222 dctlprintk(("mptctl_reply() NULL Reply "
223 "Function=%x!\n", cmd));
225 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
226 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
228 /* We are done, issue wake up
230 ioc->ioctl->wait_done = 1;
231 wake_up (&mptctl_wait);
236 dctlprintk(("mptctl_reply() with req=%p "
237 "reply=%p Function=%x!\n", req, reply, cmd));
239 /* Copy the reply frame (which much exist
240 * for non-SCSI I/O) to the IOC structure.
242 dctlprintk(("Copying Reply Frame @%p to ioc%d!\n",
244 memcpy(ioc->ioctl->ReplyFrame, reply,
245 min(ioc->reply_sz, 4*reply->u.reply.MsgLength));
246 ioc->ioctl->status |= MPT_IOCTL_STATUS_RF_VALID;
248 /* Set the command status to GOOD if IOC Status is GOOD
249 * OR if SCSI I/O cmd and data underrun or recovered error.
251 iocStatus = le16_to_cpu(reply->u.reply.IOCStatus) & MPI_IOCSTATUS_MASK;
252 if (iocStatus == MPI_IOCSTATUS_SUCCESS)
253 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
255 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
256 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
257 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
259 if ((iocStatus == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) ||
260 (iocStatus == MPI_IOCSTATUS_SCSI_RECOVERED_ERROR)) {
261 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
265 /* Copy the sense data - if present
267 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) &&
268 (reply->u.sreply.SCSIState &
269 MPI_SCSI_STATE_AUTOSENSE_VALID)){
270 sz = req->u.scsireq.SenseBufferLength;
272 le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
274 ((u8 *)ioc->sense_buf_pool +
275 (req_index * MPT_SENSE_BUFFER_ALLOC));
276 memcpy(ioc->ioctl->sense, sense_data, sz);
277 ioc->ioctl->status |= MPT_IOCTL_STATUS_SENSE_VALID;
280 if (cmd == MPI_FUNCTION_SCSI_TASK_MGMT)
281 mptctl_free_tm_flags(ioc);
283 /* We are done, issue wake up
285 ioc->ioctl->wait_done = 1;
286 wake_up (&mptctl_wait);
291 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
292 /* mptctl_timeout_expired
294 * Expecting an interrupt, however timed out.
297 static void mptctl_timeout_expired (MPT_IOCTL *ioctl)
301 dctlprintk((KERN_NOTICE MYNAM ": Timeout Expired! Host %d\n",
306 ioctl->wait_done = 0;
307 if (ioctl->reset & MPTCTL_RESET_OK)
308 rc = mptctl_bus_reset(ioctl);
311 /* Issue a reset for this device.
312 * The IOC is not responding.
314 dctlprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
316 mpt_HardResetHandler(ioctl->ioc, NO_SLEEP);
327 static int mptctl_bus_reset(MPT_IOCTL *ioctl)
330 SCSITaskMgmt_t *pScsiTm;
336 ioctl->reset &= ~MPTCTL_RESET_OK;
338 if (ioctl->ioc->sh == NULL)
341 hd = (MPT_SCSI_HOST *) ioctl->ioc->sh->hostdata;
345 /* Single threading ....
347 if (mptctl_set_tm_flags(hd) != 0)
352 if ((mf = mpt_get_msg_frame(mptctl_id, ioctl->ioc)) == NULL) {
353 dctlprintk((MYIOC_s_WARN_FMT "IssueTaskMgmt, no msg frames!!\n",
356 mptctl_free_tm_flags(ioctl->ioc);
360 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
361 ioctl->ioc->name, mf));
363 pScsiTm = (SCSITaskMgmt_t *) mf;
364 pScsiTm->TargetID = ioctl->target;
365 pScsiTm->Bus = hd->port; /* 0 */
366 pScsiTm->ChainOffset = 0;
367 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
368 pScsiTm->Reserved = 0;
369 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
370 pScsiTm->Reserved1 = 0;
371 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
373 for (ii= 0; ii < 8; ii++)
374 pScsiTm->LUN[ii] = 0;
376 for (ii=0; ii < 7; ii++)
377 pScsiTm->Reserved2[ii] = 0;
379 pScsiTm->TaskMsgContext = 0;
380 dtmprintk((MYIOC_s_INFO_FMT
381 "mptctl_bus_reset: issued.\n", ioctl->ioc->name));
383 DBG_DUMP_TM_REQUEST_FRAME((u32 *)mf);
386 if ((retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
387 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP)) != 0) {
388 dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!"
389 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
391 goto mptctl_bus_reset_done;
394 /* Now wait for the command to complete */
395 ii = wait_event_timeout(mptctl_wait,
396 ioctl->wait_done == 1,
397 HZ*5 /* 5 second timeout */);
399 if(ii <=0 && (ioctl->wait_done != 1 )) {
400 mpt_free_msg_frame(hd->ioc, mf);
401 ioctl->wait_done = 0;
402 retval = -1; /* return failure */
405 mptctl_bus_reset_done:
407 mptctl_free_tm_flags(ioctl->ioc);
412 mptctl_set_tm_flags(MPT_SCSI_HOST *hd) {
415 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
417 if (hd->tmState == TM_STATE_NONE) {
418 hd->tmState = TM_STATE_IN_PROGRESS;
420 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
422 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
430 mptctl_free_tm_flags(MPT_ADAPTER *ioc)
435 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
439 spin_lock_irqsave(&ioc->FreeQlock, flags);
441 hd->tmState = TM_STATE_NONE;
443 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
448 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
451 * Clean-up functionality. Used only if there has been a
452 * reload of the FW due.
456 mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
458 MPT_IOCTL *ioctl = ioc->ioctl;
459 dctlprintk((KERN_INFO MYNAM ": IOC %s_reset routed to IOCTL driver!\n",
460 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
461 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
466 switch(reset_phase) {
467 case MPT_IOC_SETUP_RESET:
468 ioctl->status |= MPT_IOCTL_STATUS_DID_IOCRESET;
470 case MPT_IOC_POST_RESET:
471 ioctl->status &= ~MPT_IOCTL_STATUS_DID_IOCRESET;
473 case MPT_IOC_PRE_RESET:
481 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
482 /* ASYNC Event Notification Support */
484 mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
488 event = le32_to_cpu(pEvReply->Event) & 0xFF;
490 dctlprintk(("%s() called\n", __FUNCTION__));
491 if(async_queue == NULL)
494 /* Raise SIGIO for persistent events.
495 * TODO - this define is not in MPI spec yet,
496 * but they plan to set it to 0x21
498 if (event == 0x21 ) {
499 ioc->aen_event_read_flag=1;
500 dctlprintk(("Raised SIGIO to application\n"));
501 devtverboseprintk(("Raised SIGIO to application\n"));
502 kill_fasync(&async_queue, SIGIO, POLL_IN);
506 /* This flag is set after SIGIO was raised, and
507 * remains set until the application has read
508 * the event log via ioctl=MPTEVENTREPORT
510 if(ioc->aen_event_read_flag)
513 /* Signal only for the events that are
514 * requested for by the application
516 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
517 ioc->aen_event_read_flag=1;
518 dctlprintk(("Raised SIGIO to application\n"));
519 devtverboseprintk(("Raised SIGIO to application\n"));
520 kill_fasync(&async_queue, SIGIO, POLL_IN);
526 mptctl_fasync(int fd, struct file *filep, int mode)
530 list_for_each_entry(ioc, &ioc_list, list)
531 ioc->aen_event_read_flag=0;
533 dctlprintk(("%s() called\n", __FUNCTION__));
534 return fasync_helper(fd, filep, mode, &async_queue);
538 mptctl_release(struct inode *inode, struct file *filep)
540 dctlprintk(("%s() called\n", __FUNCTION__));
541 return fasync_helper(-1, filep, 0, &async_queue);
544 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
547 * cmd - specify the particular IOCTL command to be issued
548 * arg - data specific to the command. Must not be null.
551 __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
553 mpt_ioctl_header __user *uhdr = (void __user *) arg;
554 mpt_ioctl_header khdr;
557 int nonblock = (file->f_flags & O_NONBLOCK);
559 MPT_ADAPTER *iocp = NULL;
561 dctlprintk(("mptctl_ioctl() called\n"));
563 if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
564 printk(KERN_ERR "%s::mptctl_ioctl() @%d - "
565 "Unable to copy mpt_ioctl_header data @ %p\n",
566 __FILE__, __LINE__, uhdr);
569 ret = -ENXIO; /* (-6) No such device or address */
571 /* Verify intended MPT adapter - set iocnum and the adapter
574 iocnumX = khdr.iocnum & 0xFF;
575 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
577 dctlprintk((KERN_ERR "%s::mptctl_ioctl() @%d - ioc%d not found!\n",
578 __FILE__, __LINE__, iocnumX));
583 printk(KERN_ERR "%s::mptctl_ioctl() @%d - Controller disabled.\n",
588 /* Handle those commands that are just returning
589 * information stored in the driver.
590 * These commands should never time out and are unaffected
591 * by TM and FW reloads.
593 if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
594 return mptctl_getiocinfo(arg, _IOC_SIZE(cmd));
595 } else if (cmd == MPTTARGETINFO) {
596 return mptctl_gettargetinfo(arg);
597 } else if (cmd == MPTTEST) {
598 return mptctl_readtest(arg);
599 } else if (cmd == MPTEVENTQUERY) {
600 return mptctl_eventquery(arg);
601 } else if (cmd == MPTEVENTENABLE) {
602 return mptctl_eventenable(arg);
603 } else if (cmd == MPTEVENTREPORT) {
604 return mptctl_eventreport(arg);
605 } else if (cmd == MPTFWREPLACE) {
606 return mptctl_replace_fw(arg);
609 /* All of these commands require an interrupt or
610 * are unknown/illegal.
612 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
615 dctlprintk((MYIOC_s_INFO_FMT ": mptctl_ioctl()\n", iocp->name));
617 if (cmd == MPTFWDOWNLOAD)
618 ret = mptctl_fw_download(arg);
619 else if (cmd == MPTCOMMAND)
620 ret = mptctl_mpt_command(arg);
621 else if (cmd == MPTHARDRESET)
622 ret = mptctl_do_reset(arg);
623 else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
624 ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
625 else if (cmd == HP_GETTARGETINFO)
626 ret = mptctl_hp_targetinfo(arg);
630 mutex_unlock(&iocp->ioctl->ioctl_mutex);
636 mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
640 ret = __mptctl_ioctl(file, cmd, arg);
645 static int mptctl_do_reset(unsigned long arg)
647 struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
648 struct mpt_ioctl_diag_reset krinfo;
651 dctlprintk((KERN_INFO "mptctl_do_reset called.\n"));
653 if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
654 printk(KERN_ERR "%s@%d::mptctl_do_reset - "
655 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
656 __FILE__, __LINE__, urinfo);
660 if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
661 dctlprintk((KERN_ERR "%s@%d::mptctl_do_reset - ioc%d not found!\n",
662 __FILE__, __LINE__, krinfo.hdr.iocnum));
663 return -ENODEV; /* (-6) No such device or address */
666 if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
667 printk (KERN_ERR "%s@%d::mptctl_do_reset - reset failed.\n",
675 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
677 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
678 * This structure contains: iocnum, firmware length (bytes),
679 * pointer to user space memory where the fw image is stored.
682 * Return: 0 if successful
683 * -EFAULT if data unavailable
684 * -ENXIO if no such device
685 * -EAGAIN if resource problem
686 * -ENOMEM if no memory for SGE
687 * -EMLINK if too many chain buffers required
688 * -EBADRQC if adapter does not support FW download
689 * -EBUSY if adapter is busy
690 * -ENOMSG if FW upload returned bad status
693 mptctl_fw_download(unsigned long arg)
695 struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
696 struct mpt_fw_xfer kfwdl;
698 dctlprintk((KERN_INFO "mptctl_fwdl called. mptctl_id = %xh\n", mptctl_id)); //tc
699 if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
700 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
701 "Unable to copy mpt_fw_xfer struct @ %p\n",
702 __FILE__, __LINE__, ufwdl);
706 return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
709 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
711 * FW Download engine.
713 * Return: 0 if successful
714 * -EFAULT if data unavailable
715 * -ENXIO if no such device
716 * -EAGAIN if resource problem
717 * -ENOMEM if no memory for SGE
718 * -EMLINK if too many chain buffers required
719 * -EBADRQC if adapter does not support FW download
720 * -EBUSY if adapter is busy
721 * -ENOMSG if FW upload returned bad status
724 mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen)
729 FWDownloadTCSGE_t *ptsge;
730 MptSge_t *sgl, *sgIn;
732 struct buflist *buflist;
741 int fw_bytes_copied = 0;
745 pFWDownloadReply_t ReplyMsg = NULL;
747 dctlprintk(("mptctl_do_fwdl called. mptctl_id = %xh.\n", mptctl_id));
749 dctlprintk(("DbG: kfwdl.bufp = %p\n", ufwbuf));
750 dctlprintk(("DbG: kfwdl.fwlen = %d\n", (int)fwlen));
751 dctlprintk(("DbG: kfwdl.ioc = %04xh\n", ioc));
753 if (mpt_verify_adapter(ioc, &iocp) < 0) {
754 dctlprintk(("ioctl_fwdl - ioc%d not found!\n",
756 return -ENODEV; /* (-6) No such device or address */
759 /* Valid device. Get a message frame and construct the FW download message.
761 if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
764 dlmsg = (FWDownload_t*) mf;
765 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
766 sgOut = (char *) (ptsge + 1);
769 * Construct f/w download request
771 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
773 dlmsg->ChainOffset = 0;
774 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
775 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
776 if (iocp->facts.MsgVersion >= MPI_VERSION_01_05)
777 dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT;
782 /* Set up the Transaction SGE.
785 ptsge->ContextSize = 0;
786 ptsge->DetailsLength = 12;
787 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
788 ptsge->Reserved_0100_Checksum = 0;
789 ptsge->ImageOffset = 0;
790 ptsge->ImageSize = cpu_to_le32(fwlen);
796 * Need to kmalloc area(s) for holding firmware image bytes.
797 * But we need to do it piece meal, using a proper
798 * scatter gather list (with 128kB MAX hunks).
800 * A practical limit here might be # of sg hunks that fit into
801 * a single IOC request frame; 12 or 8 (see below), so:
802 * For FC9xx: 12 x 128kB == 1.5 mB (max)
803 * For C1030: 8 x 128kB == 1 mB (max)
804 * We could support chaining, but things get ugly(ier:)
806 * Set the sge_offset to the start of the sgl (bytes).
808 sgdir = 0x04000000; /* IOC will READ from sys mem */
809 sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
810 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
811 &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
815 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
816 * for FC9xx f/w image, but calculate max number of sge hunks
817 * we can fit into a request frame, and limit ourselves to that.
818 * (currently no chain support)
819 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
825 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t))
826 / (sizeof(dma_addr_t) + sizeof(u32));
827 if (numfrags > maxfrags) {
832 dctlprintk(("DbG: sgl buffer = %p, sgfrags = %d\n", sgl, numfrags));
835 * Parse SG list, copying sgl itself,
836 * plus f/w image hunks from user space as we go...
841 for (i=0; i < numfrags; i++) {
843 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
844 * Skip everything but Simple. If simple, copy from
845 * user space into kernel space.
846 * Note: we should not have anything but Simple as
847 * Chain SGE are illegal.
849 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
850 if (nib == 0 || nib == 3) {
852 } else if (sgIn->Address) {
853 mpt_add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
855 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
856 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
857 "Unable to copy f/w buffer hunk#%d @ %p\n",
858 __FILE__, __LINE__, n, ufwbuf);
861 fw_bytes_copied += bl->len;
865 sgOut += (sizeof(dma_addr_t) + sizeof(u32));
871 printk(KERN_INFO MYNAM ": F/W download request:\n" KERN_INFO " ");
872 for (i=0; i < 7+numfrags*2; i++)
873 printk(" %08x", le32_to_cpu(m[i]));
879 * Finally, perform firmware download.
882 mpt_put_msg_frame(mptctl_id, iocp, mf);
884 /* Now wait for the command to complete */
885 ret = wait_event_timeout(mptctl_wait,
886 iocp->ioctl->wait_done == 1,
889 if(ret <=0 && (iocp->ioctl->wait_done != 1 )) {
890 /* Now we need to reset the board */
891 mptctl_timeout_expired(iocp->ioctl);
897 kfree_sgl(sgl, sgl_dma, buflist, iocp);
899 ReplyMsg = (pFWDownloadReply_t)iocp->ioctl->ReplyFrame;
900 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
901 if (iocstat == MPI_IOCSTATUS_SUCCESS) {
902 printk(KERN_INFO MYNAM ": F/W update successfully sent to %s!\n", iocp->name);
904 } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
905 printk(KERN_WARNING MYNAM ": ?Hmmm... %s says it doesn't support F/W download!?!\n",
907 printk(KERN_WARNING MYNAM ": (time to go bang on somebodies door)\n");
909 } else if (iocstat == MPI_IOCSTATUS_BUSY) {
910 printk(KERN_WARNING MYNAM ": Warning! %s says: IOC_BUSY!\n", iocp->name);
911 printk(KERN_WARNING MYNAM ": (try again later?)\n");
914 printk(KERN_WARNING MYNAM "::ioctl_fwdl() ERROR! %s returned [bad] status = %04xh\n",
915 iocp->name, iocstat);
916 printk(KERN_WARNING MYNAM ": (bad VooDoo)\n");
922 kfree_sgl(sgl, sgl_dma, buflist, iocp);
926 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
928 * SGE Allocation routine
930 * Inputs: bytes - number of bytes to be transferred
931 * sgdir - data direction
932 * sge_offset - offset (in bytes) from the start of the request
933 * frame to the first SGE
934 * ioc - pointer to the mptadapter
935 * Outputs: frags - number of scatter gather elements
936 * blp - point to the buflist pointer
937 * sglbuf_dma - pointer to the (dma) sgl
938 * Returns: Null if failes
939 * pointer to the (virtual) sgl if successful.
942 kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
943 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
945 MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
946 /* and chain buffers */
947 struct buflist *buflist = NULL; /* kernel routine */
951 int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
952 int bytes_allocd = 0;
954 dma_addr_t pa; // phys addr
956 int sg_spill = MAX_FRAGS_SPILL1;
962 /* Allocate and initialize an array of kernel
963 * structures for the SG elements.
965 i = MAX_SGL_BYTES / 8;
966 buflist = kmalloc(i, GFP_USER);
969 memset(buflist, 0, i);
972 /* Allocate a single block of memory to store the sg elements and
973 * the chain buffers. The calling routine is responsible for
974 * copying the data in this array into the correct place in the
975 * request and chain buffers.
977 sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
981 if (sgdir & 0x04000000)
982 dir = PCI_DMA_TODEVICE;
984 dir = PCI_DMA_FROMDEVICE;
987 * sgl = sglbuf = point to beginning of sg buffer
988 * buflist_ent = 0 = first kernel structure
989 * sg_spill = number of SGE that can be written before the first
994 sg_spill = ((ioc->req_sz - sge_offset)/(sizeof(dma_addr_t) + sizeof(u32))) - 1;
995 while (bytes_allocd < bytes) {
996 this_alloc = min(alloc_sz, bytes-bytes_allocd);
997 buflist[buflist_ent].len = this_alloc;
998 buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
1001 if (buflist[buflist_ent].kptr == NULL) {
1002 alloc_sz = alloc_sz / 2;
1003 if (alloc_sz == 0) {
1004 printk(KERN_WARNING MYNAM "-SG: No can do - "
1005 "not enough memory! :-(\n");
1006 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
1012 dma_addr_t dma_addr;
1014 bytes_allocd += this_alloc;
1015 sgl->FlagsLength = (0x10000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|this_alloc);
1016 dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir);
1017 sgl->Address = dma_addr;
1025 if (bytes_allocd >= bytes)
1028 /* Need to chain? */
1029 if (fragcnt == sg_spill) {
1030 printk(KERN_WARNING MYNAM "-SG: No can do - " "Chain required! :-(\n");
1031 printk(KERN_WARNING MYNAM "(freeing %d frags)\n", numfrags);
1035 /* overflow check... */
1036 if (numfrags*8 > MAX_SGL_BYTES){
1038 printk(KERN_WARNING MYNAM "-SG: No can do - "
1039 "too many SG frags! :-(\n");
1040 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
1046 /* Last sge fixup: set LE+eol+eob bits */
1047 sgl[-1].FlagsLength |= 0xC1000000;
1052 dctlprintk((KERN_INFO MYNAM "-SG: kbuf_alloc_2_sgl() - "
1053 "%d SG frags generated!\n",
1056 dctlprintk((KERN_INFO MYNAM "-SG: kbuf_alloc_2_sgl() - "
1057 "last (big) alloc_sz=%d\n",
1063 if (sglbuf != NULL) {
1066 for (i = 0; i < numfrags; i++) {
1067 dma_addr_t dma_addr;
1071 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
1074 dma_addr = sglbuf[i].Address;
1075 kptr = buflist[i].kptr;
1076 len = buflist[i].len;
1078 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1080 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma);
1086 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1088 * Routine to free the SGL elements.
1091 kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
1094 struct buflist *bl = buflist;
1099 if (sg->FlagsLength & 0x04000000)
1100 dir = PCI_DMA_TODEVICE;
1102 dir = PCI_DMA_FROMDEVICE;
1104 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1105 while (! (nib & 0x4)) { /* eob */
1106 /* skip ignore/chain. */
1107 if (nib == 0 || nib == 3) {
1109 } else if (sg->Address) {
1110 dma_addr_t dma_addr;
1114 dma_addr = sg->Address;
1117 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1118 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1123 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1128 dma_addr_t dma_addr;
1132 dma_addr = sg->Address;
1135 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1136 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1140 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma);
1142 dctlprintk((KERN_INFO MYNAM "-SG: Free'd 1 SGL buf + %d kbufs!\n", n));
1145 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1147 * mptctl_getiocinfo - Query the host adapter for IOC information.
1148 * @arg: User space argument
1151 * Return: 0 if successful
1152 * -EFAULT if data unavailable
1153 * -ENODEV if no such device/adapter
1156 mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1158 struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
1159 struct mpt_ioctl_iocinfo *karg;
1161 struct pci_dev *pdev;
1162 struct Scsi_Host *sh;
1166 unsigned int max_id;
1172 dctlprintk((": mptctl_getiocinfo called.\n"));
1173 /* Add of PCI INFO results in unaligned access for
1174 * IA64 and Sparc. Reset long to int. Return no PCI
1175 * data for obsolete format.
1177 if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
1179 else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
1181 else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
1183 else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
1184 cim_rev = 0; /* obsolete */
1188 karg = kmalloc(data_size, GFP_KERNEL);
1190 printk(KERN_ERR "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
1191 __FILE__, __LINE__);
1195 if (copy_from_user(karg, uarg, data_size)) {
1196 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1197 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1198 __FILE__, __LINE__, uarg);
1203 if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
1205 dctlprintk((KERN_ERR "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
1206 __FILE__, __LINE__, iocnum));
1211 /* Verify the data transfer size is correct. */
1212 if (karg->hdr.maxDataSize != data_size) {
1213 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1214 "Structure size mismatch. Command not completed.\n",
1215 __FILE__, __LINE__);
1220 /* Fill in the data and return the structure to the calling
1223 if (ioc->bus_type == SAS)
1224 karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
1225 else if (ioc->bus_type == FC)
1226 karg->adapterType = MPT_IOCTL_INTERFACE_FC;
1228 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1230 if (karg->hdr.port > 1)
1232 port = karg->hdr.port;
1235 pdev = (struct pci_dev *) ioc->pcidev;
1237 karg->pciId = pdev->device;
1238 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1239 karg->hwRev = revision;
1240 karg->subSystemDevice = pdev->subsystem_device;
1241 karg->subSystemVendor = pdev->subsystem_vendor;
1244 /* Get the PCI bus, device, and function numbers for the IOC
1246 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1247 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1248 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1249 } else if (cim_rev == 2) {
1250 /* Get the PCI bus, device, function and segment ID numbers
1252 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1253 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1254 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1255 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
1258 /* Get number of devices
1260 if ((sh = ioc->sh) != NULL) {
1261 /* sh->max_id = maximum target ID + 1
1263 max_id = sh->max_id - 1;
1264 hd = (MPT_SCSI_HOST *) sh->hostdata;
1266 /* Check all of the target structures and
1269 if (hd && hd->Targets) {
1270 for (ii = 0; ii <= max_id; ii++) {
1271 if (hd->Targets[ii])
1276 karg->numDevices = numDevices;
1278 /* Set the BIOS and FW Version
1280 karg->FWVersion = ioc->facts.FWVersion.Word;
1281 karg->BIOSVersion = ioc->biosVersion;
1283 /* Set the Version Strings.
1285 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
1286 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
1288 karg->busChangeEvent = 0;
1289 karg->hostId = ioc->pfacts[port].PortSCSIID;
1290 karg->rsvd[0] = karg->rsvd[1] = 0;
1292 /* Copy the data from kernel memory to user memory
1294 if (copy_to_user((char __user *)arg, karg, data_size)) {
1295 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1296 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1297 __FILE__, __LINE__, uarg);
1306 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1308 * mptctl_gettargetinfo - Query the host adapter for target information.
1309 * @arg: User space argument
1312 * Return: 0 if successful
1313 * -EFAULT if data unavailable
1314 * -ENODEV if no such device/adapter
1317 mptctl_gettargetinfo (unsigned long arg)
1319 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1320 struct mpt_ioctl_targetinfo karg;
1322 struct Scsi_Host *sh;
1331 unsigned int max_id;
1332 int id, jj, indexed_lun, lun_index;
1336 u8 port, devType, bus_id;
1338 dctlprintk(("mptctl_gettargetinfo called.\n"));
1339 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
1340 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1341 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1342 __FILE__, __LINE__, uarg);
1346 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1348 dctlprintk((KERN_ERR "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
1349 __FILE__, __LINE__, iocnum));
1353 /* Get the port number and set the maximum number of bytes
1354 * in the returned structure.
1355 * Ignore the port setting.
1357 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1358 maxWordsLeft = numBytes/sizeof(int);
1359 port = karg.hdr.port;
1361 if (maxWordsLeft <= 0) {
1362 printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1363 __FILE__, __LINE__);
1367 /* Fill in the data and return the structure to the calling
1371 /* struct mpt_ioctl_targetinfo does not contain sufficient space
1372 * for the target structures so when the IOCTL is called, there is
1373 * not sufficient stack space for the structure. Allocate memory,
1374 * populate the memory, copy back to the user, then free memory.
1375 * targetInfo format:
1376 * bits 31-24: reserved
1381 pmem = kmalloc(numBytes, GFP_KERNEL);
1383 printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1384 __FILE__, __LINE__);
1387 memset(pmem, 0, numBytes);
1388 pdata = (int *) pmem;
1390 /* Get number of devices
1392 if ((sh = ioc->sh) != NULL) {
1394 max_id = sh->max_id - 1;
1395 hd = (MPT_SCSI_HOST *) sh->hostdata;
1397 /* Check all of the target structures.
1398 * Save the Id and increment the counter,
1400 * sh->max_id = maximum target ID + 1
1402 if (hd && hd->Targets) {
1403 mpt_findImVolumes(ioc);
1404 pIoc2 = ioc->raid_data.pIocPg2;
1405 for ( id = 0; id <= max_id; ) {
1406 if ( pIoc2 && pIoc2->NumActiveVolumes ) {
1407 if ( id == pIoc2->RaidVolume[0].VolumeID ) {
1408 if (maxWordsLeft <= 0) {
1409 printk(KERN_ERR "mptctl_gettargetinfo - "
1410 "buffer is full but volume is available on ioc %d\n, numDevices=%d", iocnum, numDevices);
1411 goto data_space_full;
1413 if ( ( pIoc2->RaidVolume[0].Flags & MPI_IOCPAGE2_FLAG_VOLUME_INACTIVE ) == 0 )
1417 bus_id = pIoc2->RaidVolume[0].VolumeBus;
1419 *pdata = ( (devType << 24) | (bus_id << 8) | id );
1420 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1421 "volume ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1426 pIoc3 = ioc->raid_data.pIocPg3;
1427 for ( jj = 0; jj < pIoc3->NumPhysDisks; jj++ ) {
1428 if ( pIoc3->PhysDisk[jj].PhysDiskID == id )
1433 if ( (vdev = hd->Targets[id]) ) {
1434 for (jj = 0; jj <= MPT_LAST_LUN; jj++) {
1435 lun_index = (jj >> 5);
1436 indexed_lun = (jj % 32);
1437 lun = (1 << indexed_lun);
1438 if (vdev->luns[lun_index] & lun) {
1439 if (maxWordsLeft <= 0) {
1440 printk(KERN_ERR "mptctl_gettargetinfo - "
1441 "buffer is full but more targets are available on ioc %d numDevices=%d\n", iocnum, numDevices);
1442 goto data_space_full;
1444 bus_id = vdev->bus_id;
1446 *pdata = ( (jj << 16) | (bus_id << 8) | id );
1447 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1448 "target ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1460 karg.numDevices = numDevices;
1462 /* Copy part of the data from kernel memory to user memory
1464 if (copy_to_user((char __user *)arg, &karg,
1465 sizeof(struct mpt_ioctl_targetinfo))) {
1466 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1467 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1468 __FILE__, __LINE__, uarg);
1473 /* Copy the remaining data from kernel memory to user memory
1475 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
1476 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1477 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1478 __FILE__, __LINE__, pdata);
1488 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1489 /* MPT IOCTL Test function.
1492 * Return: 0 if successful
1493 * -EFAULT if data unavailable
1494 * -ENODEV if no such device/adapter
1497 mptctl_readtest (unsigned long arg)
1499 struct mpt_ioctl_test __user *uarg = (void __user *) arg;
1500 struct mpt_ioctl_test karg;
1504 dctlprintk(("mptctl_readtest called.\n"));
1505 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
1506 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1507 "Unable to read in mpt_ioctl_test struct @ %p\n",
1508 __FILE__, __LINE__, uarg);
1512 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1514 dctlprintk((KERN_ERR "%s::mptctl_readtest() @%d - ioc%d not found!\n",
1515 __FILE__, __LINE__, iocnum));
1519 /* Fill in the data and return the structure to the calling
1524 karg.chip_type = ioc->mfcnt;
1526 karg.chip_type = ioc->pcidev->device;
1528 strncpy (karg.name, ioc->name, MPT_MAX_NAME);
1529 karg.name[MPT_MAX_NAME-1]='\0';
1530 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
1531 karg.product[MPT_PRODUCT_LENGTH-1]='\0';
1533 /* Copy the data from kernel memory to user memory
1535 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
1536 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1537 "Unable to write out mpt_ioctl_test struct @ %p\n",
1538 __FILE__, __LINE__, uarg);
1545 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1547 * mptctl_eventquery - Query the host adapter for the event types
1548 * that are being logged.
1549 * @arg: User space argument
1552 * Return: 0 if successful
1553 * -EFAULT if data unavailable
1554 * -ENODEV if no such device/adapter
1557 mptctl_eventquery (unsigned long arg)
1559 struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
1560 struct mpt_ioctl_eventquery karg;
1564 dctlprintk(("mptctl_eventquery called.\n"));
1565 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
1566 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1567 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1568 __FILE__, __LINE__, uarg);
1572 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1574 dctlprintk((KERN_ERR "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
1575 __FILE__, __LINE__, iocnum));
1579 karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
1580 karg.eventTypes = ioc->eventTypes;
1582 /* Copy the data from kernel memory to user memory
1584 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
1585 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1586 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1587 __FILE__, __LINE__, uarg);
1593 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1595 mptctl_eventenable (unsigned long arg)
1597 struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
1598 struct mpt_ioctl_eventenable karg;
1602 dctlprintk(("mptctl_eventenable called.\n"));
1603 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
1604 printk(KERN_ERR "%s@%d::mptctl_eventenable - "
1605 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1606 __FILE__, __LINE__, uarg);
1610 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1612 dctlprintk((KERN_ERR "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
1613 __FILE__, __LINE__, iocnum));
1617 if (ioc->events == NULL) {
1618 /* Have not yet allocated memory - do so now.
1620 int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1621 ioc->events = kmalloc(sz, GFP_KERNEL);
1622 if (ioc->events == NULL) {
1623 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1626 memset(ioc->events, 0, sz);
1627 ioc->alloc_total += sz;
1629 ioc->eventContext = 0;
1632 /* Update the IOC event logging flag.
1634 ioc->eventTypes = karg.eventTypes;
1639 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1641 mptctl_eventreport (unsigned long arg)
1643 struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
1644 struct mpt_ioctl_eventreport karg;
1647 int numBytes, maxEvents, max;
1649 dctlprintk(("mptctl_eventreport called.\n"));
1650 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
1651 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1652 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1653 __FILE__, __LINE__, uarg);
1657 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1659 dctlprintk((KERN_ERR "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
1660 __FILE__, __LINE__, iocnum));
1664 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1665 maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
1668 max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
1670 /* If fewer than 1 event is requested, there must have
1671 * been some type of error.
1673 if ((max < 1) || !ioc->events)
1676 /* reset this flag so SIGIO can restart */
1677 ioc->aen_event_read_flag=0;
1679 /* Copy the data from kernel memory to user memory
1681 numBytes = max * sizeof(MPT_IOCTL_EVENTS);
1682 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
1683 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1684 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1685 __FILE__, __LINE__, ioc->events);
1692 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1694 mptctl_replace_fw (unsigned long arg)
1696 struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
1697 struct mpt_ioctl_replace_fw karg;
1702 dctlprintk(("mptctl_replace_fw called.\n"));
1703 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
1704 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1705 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1706 __FILE__, __LINE__, uarg);
1710 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1712 dctlprintk((KERN_ERR "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
1713 __FILE__, __LINE__, iocnum));
1717 /* If caching FW, Free the old FW image
1719 if (ioc->cached_fw == NULL)
1722 mpt_free_fw_memory(ioc);
1724 /* Allocate memory for the new FW image
1726 newFwSize = karg.newImageSize;
1728 if (newFwSize & 0x01)
1730 if (newFwSize & 0x02)
1733 mpt_alloc_fw_memory(ioc, newFwSize);
1734 if (ioc->cached_fw == NULL)
1737 /* Copy the data from user memory to kernel space
1739 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
1740 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1741 "Unable to read in mpt_ioctl_replace_fw image "
1742 "@ %p\n", __FILE__, __LINE__, uarg);
1743 mpt_free_fw_memory(ioc);
1747 /* Update IOCFactsReply
1749 ioc->facts.FWImageSize = newFwSize;
1753 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1754 /* MPT IOCTL MPTCOMMAND function.
1755 * Cast the arg into the mpt_ioctl_mpt_command structure.
1758 * Return: 0 if successful
1759 * -EBUSY if previous command timout and IOC reset is not complete.
1760 * -EFAULT if data unavailable
1761 * -ENODEV if no such device/adapter
1762 * -ETIME if timer expires
1763 * -ENOMEM if memory allocation error
1766 mptctl_mpt_command (unsigned long arg)
1768 struct mpt_ioctl_command __user *uarg = (void __user *) arg;
1769 struct mpt_ioctl_command karg;
1774 dctlprintk(("mptctl_command called.\n"));
1776 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
1777 printk(KERN_ERR "%s@%d::mptctl_mpt_command - "
1778 "Unable to read in mpt_ioctl_command struct @ %p\n",
1779 __FILE__, __LINE__, uarg);
1783 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1785 dctlprintk((KERN_ERR "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
1786 __FILE__, __LINE__, iocnum));
1790 rc = mptctl_do_mpt_command (karg, &uarg->MF);
1795 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1796 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1799 * Return: 0 if successful
1800 * -EBUSY if previous command timout and IOC reset is not complete.
1801 * -EFAULT if data unavailable
1802 * -ENODEV if no such device/adapter
1803 * -ETIME if timer expires
1804 * -ENOMEM if memory allocation error
1805 * -EPERM if SCSI I/O and target is untagged
1808 mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1811 MPT_FRAME_HDR *mf = NULL;
1814 struct buflist bufIn; /* data In buffer */
1815 struct buflist bufOut; /* data Out buffer */
1816 dma_addr_t dma_addr_in;
1817 dma_addr_t dma_addr_out;
1818 int sgSize = 0; /* Num SG elements */
1819 int iocnum, flagsLength;
1825 dctlprintk(("mptctl_do_mpt_command called.\n"));
1826 bufIn.kptr = bufOut.kptr = NULL;
1828 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1830 dctlprintk((KERN_ERR "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
1831 __FILE__, __LINE__, iocnum));
1835 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1836 "No memory available during driver init.\n",
1837 __FILE__, __LINE__);
1839 } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) {
1840 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1841 "Busy with IOC Reset \n", __FILE__, __LINE__);
1845 /* Verify that the final request frame will not be too large.
1847 sz = karg.dataSgeOffset * 4;
1848 if (karg.dataInSize > 0)
1849 sz += sizeof(dma_addr_t) + sizeof(u32);
1850 if (karg.dataOutSize > 0)
1851 sz += sizeof(dma_addr_t) + sizeof(u32);
1853 if (sz > ioc->req_sz) {
1854 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1855 "Request frame too large (%d) maximum (%d)\n",
1856 __FILE__, __LINE__, sz, ioc->req_sz);
1860 /* Get a free request frame and save the message context.
1862 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
1865 hdr = (MPIHeader_t *) mf;
1866 msgContext = le32_to_cpu(hdr->MsgContext);
1867 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1869 /* Copy the request frame
1870 * Reset the saved message context.
1871 * Request frame in user space
1873 if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
1874 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1875 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1876 __FILE__, __LINE__, mfPtr);
1880 hdr->MsgContext = cpu_to_le32(msgContext);
1883 /* Verify that this request is allowed.
1885 switch (hdr->Function) {
1886 case MPI_FUNCTION_IOC_FACTS:
1887 case MPI_FUNCTION_PORT_FACTS:
1888 karg.dataOutSize = karg.dataInSize = 0;
1891 case MPI_FUNCTION_CONFIG:
1892 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
1893 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
1894 case MPI_FUNCTION_FW_UPLOAD:
1895 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
1896 case MPI_FUNCTION_FW_DOWNLOAD:
1897 case MPI_FUNCTION_FC_PRIMITIVE_SEND:
1898 case MPI_FUNCTION_TOOLBOX:
1899 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
1902 case MPI_FUNCTION_SCSI_IO_REQUEST:
1904 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1905 VirtTarget *pTarget = NULL;
1906 MPT_SCSI_HOST *hd = NULL;
1907 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1909 int target = (int) pScsiReq->TargetID;
1912 if ((target < 0) || (target >= ioc->sh->max_id)) {
1913 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1914 "Target ID out of bounds. \n",
1915 __FILE__, __LINE__);
1920 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1921 pScsiReq->MsgFlags |= mpt_msg_flags();
1924 /* verify that app has not requested
1925 * more sense data than driver
1926 * can provide, if so, reset this parameter
1927 * set the sense buffer pointer low address
1928 * update the control field to specify Q type
1930 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1931 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1933 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1935 pScsiReq->SenseBufferLowAddr =
1936 cpu_to_le32(ioc->sense_buf_low_dma
1937 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1939 if ((hd = (MPT_SCSI_HOST *) ioc->sh->hostdata)) {
1941 pTarget = hd->Targets[target];
1944 if (pTarget &&(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1945 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1947 /* Have the IOCTL driver set the direction based
1948 * on the dataOutSize (ordering issue with Sparc).
1950 if (karg.dataOutSize > 0) {
1951 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1952 dataSize = karg.dataOutSize;
1954 scsidir = MPI_SCSIIO_CONTROL_READ;
1955 dataSize = karg.dataInSize;
1958 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1959 pScsiReq->DataLength = cpu_to_le32(dataSize);
1961 ioc->ioctl->reset = MPTCTL_RESET_OK;
1962 ioc->ioctl->target = target;
1965 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1966 "SCSI driver is not loaded. \n",
1967 __FILE__, __LINE__);
1973 case MPI_FUNCTION_SMP_PASSTHROUGH:
1974 /* Check mf->PassthruFlags to determine if
1975 * transfer is ImmediateMode or not.
1976 * Immediate mode returns data in the ReplyFrame.
1977 * Else, we are sending request and response data
1978 * in two SGLs at the end of the mf.
1982 case MPI_FUNCTION_SATA_PASSTHROUGH:
1984 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1985 "SCSI driver is not loaded. \n",
1986 __FILE__, __LINE__);
1992 case MPI_FUNCTION_RAID_ACTION:
1997 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1999 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
2000 int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
2001 int scsidir = MPI_SCSIIO_CONTROL_READ;
2004 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
2005 pScsiReq->MsgFlags |= mpt_msg_flags();
2008 /* verify that app has not requested
2009 * more sense data than driver
2010 * can provide, if so, reset this parameter
2011 * set the sense buffer pointer low address
2012 * update the control field to specify Q type
2014 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
2015 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
2017 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
2019 pScsiReq->SenseBufferLowAddr =
2020 cpu_to_le32(ioc->sense_buf_low_dma
2021 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
2023 /* All commands to physical devices are tagged
2026 /* Have the IOCTL driver set the direction based
2027 * on the dataOutSize (ordering issue with Sparc).
2029 if (karg.dataOutSize > 0) {
2030 scsidir = MPI_SCSIIO_CONTROL_WRITE;
2031 dataSize = karg.dataOutSize;
2033 scsidir = MPI_SCSIIO_CONTROL_READ;
2034 dataSize = karg.dataInSize;
2037 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
2038 pScsiReq->DataLength = cpu_to_le32(dataSize);
2040 ioc->ioctl->reset = MPTCTL_RESET_OK;
2041 ioc->ioctl->target = pScsiReq->TargetID;
2043 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2044 "SCSI driver is not loaded. \n",
2045 __FILE__, __LINE__);
2051 case MPI_FUNCTION_SCSI_TASK_MGMT:
2053 MPT_SCSI_HOST *hd = NULL;
2054 if ((ioc->sh == NULL) || ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL)) {
2055 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2056 "SCSI driver not loaded or SCSI host not found. \n",
2057 __FILE__, __LINE__);
2060 } else if (mptctl_set_tm_flags(hd) != 0) {
2067 case MPI_FUNCTION_IOC_INIT:
2069 IOCInit_t *pInit = (IOCInit_t *) mf;
2070 u32 high_addr, sense_high;
2072 /* Verify that all entries in the IOC INIT match
2073 * existing setup (and in LE format).
2075 if (sizeof(dma_addr_t) == sizeof(u64)) {
2076 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
2077 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2083 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
2084 (pInit->MaxBuses != ioc->facts.MaxBuses) ||
2085 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
2086 (pInit->HostMfaHighAddr != high_addr) ||
2087 (pInit->SenseBufferHighAddr != sense_high)) {
2088 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2089 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2090 __FILE__, __LINE__);
2098 * MPI_FUNCTION_PORT_ENABLE
2099 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2100 * MPI_FUNCTION_TARGET_ASSIST
2101 * MPI_FUNCTION_TARGET_STATUS_SEND
2102 * MPI_FUNCTION_TARGET_MODE_ABORT
2103 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2104 * MPI_FUNCTION_IO_UNIT_RESET
2105 * MPI_FUNCTION_HANDSHAKE
2106 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2107 * MPI_FUNCTION_EVENT_NOTIFICATION
2108 * (driver handles event notification)
2109 * MPI_FUNCTION_EVENT_ACK
2112 /* What to do with these??? CHECK ME!!!
2113 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2114 MPI_FUNCTION_FC_LINK_SRVC_RSP
2115 MPI_FUNCTION_FC_ABORT
2116 MPI_FUNCTION_LAN_SEND
2117 MPI_FUNCTION_LAN_RECEIVE
2118 MPI_FUNCTION_LAN_RESET
2121 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2122 "Illegal request (function 0x%x) \n",
2123 __FILE__, __LINE__, hdr->Function);
2128 /* Add the SGL ( at most one data in SGE and one data out SGE )
2129 * In the case of two SGE's - the data out (write) will always
2130 * preceede the data in (read) SGE. psgList is used to free the
2133 psge = (char *) (((int *) mf) + karg.dataSgeOffset);
2136 /* bufIn and bufOut are used for user to kernel space transfers
2138 bufIn.kptr = bufOut.kptr = NULL;
2139 bufIn.len = bufOut.len = 0;
2141 if (karg.dataOutSize > 0)
2144 if (karg.dataInSize > 0)
2149 /* Set up the dataOut memory allocation */
2150 if (karg.dataOutSize > 0) {
2151 if (karg.dataInSize > 0) {
2152 flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2153 MPI_SGE_FLAGS_END_OF_BUFFER |
2154 MPI_SGE_FLAGS_DIRECTION |
2156 << MPI_SGE_FLAGS_SHIFT;
2158 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
2160 flagsLength |= karg.dataOutSize;
2161 bufOut.len = karg.dataOutSize;
2162 bufOut.kptr = pci_alloc_consistent(
2163 ioc->pcidev, bufOut.len, &dma_addr_out);
2165 if (bufOut.kptr == NULL) {
2170 * Copy to MF and to sglbuf
2172 mpt_add_sge(psge, flagsLength, dma_addr_out);
2173 psge += (sizeof(u32) + sizeof(dma_addr_t));
2175 /* Copy user data to kernel space.
2177 if (copy_from_user(bufOut.kptr,
2181 "%s@%d::mptctl_do_mpt_command - Unable "
2182 "to read user data "
2184 __FILE__, __LINE__,karg.dataOutBufPtr);
2191 if (karg.dataInSize > 0) {
2192 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2193 flagsLength |= karg.dataInSize;
2195 bufIn.len = karg.dataInSize;
2196 bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
2197 bufIn.len, &dma_addr_in);
2199 if (bufIn.kptr == NULL) {
2204 * Copy to MF and to sglbuf
2206 mpt_add_sge(psge, flagsLength, dma_addr_in);
2212 mpt_add_sge(psge, flagsLength, (dma_addr_t) -1);
2215 ioc->ioctl->wait_done = 0;
2216 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
2218 DBG_DUMP_TM_REQUEST_FRAME((u32 *)mf);
2220 if (mpt_send_handshake_request(mptctl_id, ioc,
2221 sizeof(SCSITaskMgmt_t), (u32*)mf,
2223 dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!"
2224 " (ioc %p, mf %p) \n", ioc->name,
2226 mptctl_free_tm_flags(ioc);
2232 mpt_put_msg_frame(mptctl_id, ioc, mf);
2234 /* Now wait for the command to complete */
2235 timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
2236 timeout = wait_event_timeout(mptctl_wait,
2237 ioc->ioctl->wait_done == 1,
2240 if(timeout <=0 && (ioc->ioctl->wait_done != 1 )) {
2241 /* Now we need to reset the board */
2243 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT)
2244 mptctl_free_tm_flags(ioc);
2246 mptctl_timeout_expired(ioc->ioctl);
2253 /* If a valid reply frame, copy to the user.
2254 * Offset 2: reply length in U32's
2256 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) {
2257 if (karg.maxReplyBytes < ioc->reply_sz) {
2258 sz = min(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]);
2260 sz = min(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]);
2264 if (copy_to_user(karg.replyFrameBufPtr,
2265 &ioc->ioctl->ReplyFrame, sz)){
2267 "%s@%d::mptctl_do_mpt_command - "
2268 "Unable to write out reply frame %p\n",
2269 __FILE__, __LINE__, karg.replyFrameBufPtr);
2276 /* If valid sense data, copy to user.
2278 if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) {
2279 sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
2281 if (copy_to_user(karg.senseDataPtr, ioc->ioctl->sense, sz)) {
2282 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2283 "Unable to write sense data to user %p\n",
2292 /* If the overall status is _GOOD and data in, copy data
2295 if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) &&
2296 (karg.dataInSize > 0) && (bufIn.kptr)) {
2298 if (copy_to_user(karg.dataInBufPtr,
2299 bufIn.kptr, karg.dataInSize)) {
2300 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2301 "Unable to write data to user %p\n",
2310 ioc->ioctl->status &= ~(MPT_IOCTL_STATUS_COMMAND_GOOD |
2311 MPT_IOCTL_STATUS_SENSE_VALID |
2312 MPT_IOCTL_STATUS_RF_VALID );
2314 /* Free the allocated memory.
2316 if (bufOut.kptr != NULL) {
2317 pci_free_consistent(ioc->pcidev,
2318 bufOut.len, (void *) bufOut.kptr, dma_addr_out);
2321 if (bufIn.kptr != NULL) {
2322 pci_free_consistent(ioc->pcidev,
2323 bufIn.len, (void *) bufIn.kptr, dma_addr_in);
2326 /* mf is null if command issued successfully
2327 * otherwise, failure occured after mf acquired.
2330 mpt_free_msg_frame(ioc, mf);
2335 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2336 /* Prototype Routine for the HOST INFO command.
2339 * Return: 0 if successful
2340 * -EFAULT if data unavailable
2341 * -EBUSY if previous command timout and IOC reset is not complete.
2342 * -ENODEV if no such device/adapter
2343 * -ETIME if timer expires
2344 * -ENOMEM if memory allocation error
2347 mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2349 hp_host_info_t __user *uarg = (void __user *) arg;
2351 struct pci_dev *pdev;
2354 hp_host_info_t karg;
2356 ConfigPageHeader_t hdr;
2359 ToolboxIstwiReadWriteRequest_t *IstwiRWRequest;
2360 MPT_FRAME_HDR *mf = NULL;
2361 MPIHeader_t *mpi_hdr;
2363 dctlprintk((": mptctl_hp_hostinfo called.\n"));
2364 /* Reset long to int. Should affect IA64 and SPARC only
2366 if (data_size == sizeof(hp_host_info_t))
2368 else if (data_size == sizeof(hp_host_info_rev0_t))
2369 cim_rev = 0; /* obsolete */
2373 if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
2374 printk(KERN_ERR "%s@%d::mptctl_hp_host_info - "
2375 "Unable to read in hp_host_info struct @ %p\n",
2376 __FILE__, __LINE__, uarg);
2380 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2382 dctlprintk((KERN_ERR "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
2383 __FILE__, __LINE__, iocnum));
2387 /* Fill in the data and return the structure to the calling
2390 pdev = (struct pci_dev *) ioc->pcidev;
2392 karg.vendor = pdev->vendor;
2393 karg.device = pdev->device;
2394 karg.subsystem_id = pdev->subsystem_device;
2395 karg.subsystem_vendor = pdev->subsystem_vendor;
2396 karg.devfn = pdev->devfn;
2397 karg.bus = pdev->bus->number;
2399 /* Save the SCSI host no. if
2400 * SCSI driver loaded
2402 if (ioc->sh != NULL)
2403 karg.host_no = ioc->sh->host_no;
2407 /* Reformat the fw_version into a string
2409 karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
2410 ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
2411 karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
2412 karg.fw_version[2] = '.';
2413 karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
2414 ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
2415 karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
2416 karg.fw_version[5] = '.';
2417 karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
2418 ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
2419 karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
2420 karg.fw_version[8] = '.';
2421 karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
2422 ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
2423 karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
2424 karg.fw_version[11] = '\0';
2426 /* Issue a config request to get the device serial number
2428 hdr.PageVersion = 0;
2431 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2432 cfg.cfghdr.hdr = &hdr;
2435 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2436 cfg.dir = 0; /* read */
2439 strncpy(karg.serial_number, " ", 24);
2440 if (mpt_config(ioc, &cfg) == 0) {
2441 if (cfg.cfghdr.hdr->PageLength > 0) {
2442 /* Issue the second config page request */
2443 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2445 pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
2447 cfg.physAddr = buf_dma;
2448 if (mpt_config(ioc, &cfg) == 0) {
2449 ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
2450 if (strlen(pdata->BoardTracerNumber) > 1) {
2451 strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
2452 karg.serial_number[24-1]='\0';
2455 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
2460 rc = mpt_GetIocState(ioc, 1);
2462 case MPI_IOC_STATE_OPERATIONAL:
2463 karg.ioc_status = HP_STATUS_OK;
2466 case MPI_IOC_STATE_FAULT:
2467 karg.ioc_status = HP_STATUS_FAILED;
2470 case MPI_IOC_STATE_RESET:
2471 case MPI_IOC_STATE_READY:
2473 karg.ioc_status = HP_STATUS_OTHER;
2477 karg.base_io_addr = pci_resource_start(pdev, 0);
2479 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2480 karg.bus_phys_width = HP_BUS_WIDTH_UNK;
2482 karg.bus_phys_width = HP_BUS_WIDTH_16;
2484 karg.hard_resets = 0;
2485 karg.soft_resets = 0;
2487 if (ioc->sh != NULL) {
2488 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
2490 if (hd && (cim_rev == 1)) {
2491 karg.hard_resets = hd->hard_resets;
2492 karg.soft_resets = hd->soft_resets;
2493 karg.timeouts = hd->timeouts;
2498 * Gather ISTWI(Industry Standard Two Wire Interface) Data
2500 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
2501 dfailprintk((MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
2502 ioc->name,__FUNCTION__));
2506 IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
2507 mpi_hdr = (MPIHeader_t *) mf;
2508 memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
2509 IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
2510 IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
2511 IstwiRWRequest->MsgContext = mpi_hdr->MsgContext;
2512 IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
2513 IstwiRWRequest->NumAddressBytes = 0x01;
2514 IstwiRWRequest->DataLength = cpu_to_le16(0x04);
2515 if (pdev->devfn & 1)
2516 IstwiRWRequest->DeviceAddr = 0xB2;
2518 IstwiRWRequest->DeviceAddr = 0xB0;
2520 pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
2523 mpt_add_sge((char *)&IstwiRWRequest->SGL,
2524 (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
2526 ioc->ioctl->wait_done = 0;
2527 mpt_put_msg_frame(mptctl_id, ioc, mf);
2529 rc = wait_event_timeout(mptctl_wait,
2530 ioc->ioctl->wait_done == 1,
2531 HZ*MPT_IOCTL_DEFAULT_TIMEOUT /* 10 sec */);
2533 if(rc <=0 && (ioc->ioctl->wait_done != 1 )) {
2535 * Now we need to reset the board
2537 mpt_free_msg_frame(ioc, mf);
2538 mptctl_timeout_expired(ioc->ioctl);
2543 *ISTWI Data Definition
2544 * pbuf[0] = FW_VERSION = 0x4
2545 * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
2546 * the config, you should be seeing one out of these three values
2547 * pbuf[2] = Drive Installed Map = bit pattern depend on which
2548 * bays have drives in them
2549 * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
2551 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID)
2552 karg.rsvd = *(u32 *)pbuf;
2556 pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
2558 /* Copy the data from kernel memory to user memory
2560 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
2561 printk(KERN_ERR "%s@%d::mptctl_hpgethostinfo - "
2562 "Unable to write out hp_host_info @ %p\n",
2563 __FILE__, __LINE__, uarg);
2571 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2572 /* Prototype Routine for the TARGET INFO command.
2575 * Return: 0 if successful
2576 * -EFAULT if data unavailable
2577 * -EBUSY if previous command timout and IOC reset is not complete.
2578 * -ENODEV if no such device/adapter
2579 * -ETIME if timer expires
2580 * -ENOMEM if memory allocation error
2583 mptctl_hp_targetinfo(unsigned long arg)
2585 hp_target_info_t __user *uarg = (void __user *) arg;
2586 SCSIDevicePage0_t *pg0_alloc;
2587 SCSIDevicePage3_t *pg3_alloc;
2589 MPT_SCSI_HOST *hd = NULL;
2590 hp_target_info_t karg;
2593 dma_addr_t page_dma;
2595 ConfigPageHeader_t hdr;
2596 int tmp, np, rc = 0;
2598 dctlprintk((": mptctl_hp_targetinfo called.\n"));
2599 if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
2600 printk(KERN_ERR "%s@%d::mptctl_hp_targetinfo - "
2601 "Unable to read in hp_host_targetinfo struct @ %p\n",
2602 __FILE__, __LINE__, uarg);
2606 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2608 dctlprintk((KERN_ERR "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
2609 __FILE__, __LINE__, iocnum));
2613 /* There is nothing to do for FCP parts.
2615 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2618 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
2621 if (ioc->sh->host_no != karg.hdr.host)
2624 /* Get the data transfer speeds
2626 data_sz = ioc->spi_data.sdp0length * 4;
2627 pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2629 hdr.PageVersion = ioc->spi_data.sdp0version;
2630 hdr.PageLength = data_sz;
2632 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2634 cfg.cfghdr.hdr = &hdr;
2635 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2638 cfg.physAddr = page_dma;
2640 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2642 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2643 np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
2644 karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
2645 HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
2647 if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
2648 tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
2650 karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
2651 else if (tmp <= 0x09)
2652 karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
2653 else if (tmp <= 0x0A)
2654 karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
2655 else if (tmp <= 0x0C)
2656 karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
2657 else if (tmp <= 0x25)
2658 karg.negotiated_speed = HP_DEV_SPEED_FAST;
2660 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2662 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2665 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
2670 karg.message_rejects = -1;
2671 karg.phase_errors = -1;
2672 karg.parity_errors = -1;
2673 karg.select_timeouts = -1;
2675 /* Get the target error parameters
2677 hdr.PageVersion = 0;
2680 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2682 cfg.cfghdr.hdr = &hdr;
2683 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2687 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2688 /* Issue the second config page request */
2689 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2690 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2691 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
2692 ioc->pcidev, data_sz, &page_dma);
2694 cfg.physAddr = page_dma;
2695 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2696 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2697 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
2698 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
2699 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
2701 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
2704 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
2706 karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
2708 /* Copy the data from kernel memory to user memory
2710 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
2711 printk(KERN_ERR "%s@%d::mptctl_hp_target_info - "
2712 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2713 __FILE__, __LINE__, uarg);
2720 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2722 static struct file_operations mptctl_fops = {
2723 .owner = THIS_MODULE,
2724 .llseek = no_llseek,
2725 .release = mptctl_release,
2726 .fasync = mptctl_fasync,
2727 .unlocked_ioctl = mptctl_ioctl,
2728 #ifdef CONFIG_COMPAT
2729 .compat_ioctl = compat_mpctl_ioctl,
2733 static struct miscdevice mptctl_miscdev = {
2739 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2741 #ifdef CONFIG_COMPAT
2744 compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
2747 struct mpt_fw_xfer32 kfw32;
2748 struct mpt_fw_xfer kfw;
2749 MPT_ADAPTER *iocp = NULL;
2750 int iocnum, iocnumX;
2751 int nonblock = (filp->f_flags & O_NONBLOCK);
2754 dctlprintk((KERN_INFO MYNAM "::compat_mptfwxfer_ioctl() called\n"));
2756 if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
2759 /* Verify intended MPT adapter */
2760 iocnumX = kfw32.iocnum & 0xFF;
2761 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2763 dctlprintk((KERN_ERR MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2764 __LINE__, iocnumX));
2768 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2771 kfw.iocnum = iocnum;
2772 kfw.fwlen = kfw32.fwlen;
2773 kfw.bufp = compat_ptr(kfw32.bufp);
2775 ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
2777 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2783 compat_mpt_command(struct file *filp, unsigned int cmd,
2786 struct mpt_ioctl_command32 karg32;
2787 struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
2788 struct mpt_ioctl_command karg;
2789 MPT_ADAPTER *iocp = NULL;
2790 int iocnum, iocnumX;
2791 int nonblock = (filp->f_flags & O_NONBLOCK);
2794 dctlprintk((KERN_INFO MYNAM "::compat_mpt_command() called\n"));
2796 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
2799 /* Verify intended MPT adapter */
2800 iocnumX = karg32.hdr.iocnum & 0xFF;
2801 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2803 dctlprintk((KERN_ERR MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
2804 __LINE__, iocnumX));
2808 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2811 /* Copy data to karg */
2812 karg.hdr.iocnum = karg32.hdr.iocnum;
2813 karg.hdr.port = karg32.hdr.port;
2814 karg.timeout = karg32.timeout;
2815 karg.maxReplyBytes = karg32.maxReplyBytes;
2817 karg.dataInSize = karg32.dataInSize;
2818 karg.dataOutSize = karg32.dataOutSize;
2819 karg.maxSenseBytes = karg32.maxSenseBytes;
2820 karg.dataSgeOffset = karg32.dataSgeOffset;
2822 karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
2823 karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
2824 karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
2825 karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
2827 /* Pass new structure to do_mpt_command
2829 ret = mptctl_do_mpt_command (karg, &uarg->MF);
2831 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2836 static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2846 case MPTEVENTENABLE:
2847 case MPTEVENTREPORT:
2849 case HP_GETHOSTINFO:
2850 case HP_GETTARGETINFO:
2852 ret = __mptctl_ioctl(f, cmd, arg);
2855 ret = compat_mpt_command(f, cmd, arg);
2857 case MPTFWDOWNLOAD32:
2858 ret = compat_mptfwxfer_ioctl(f, cmd, arg);
2871 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2873 * mptctl_probe - Installs ioctl devices per bus.
2874 * @pdev: Pointer to pci_dev structure
2876 * Returns 0 for success, non-zero for failure.
2881 mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2886 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2889 * Allocate and inite a MPT_IOCTL structure
2891 sz = sizeof (MPT_IOCTL);
2892 mem = kmalloc(sz, GFP_KERNEL);
2899 ioc->ioctl = (MPT_IOCTL *) mem;
2900 ioc->ioctl->ioc = ioc;
2901 mutex_init(&ioc->ioctl->ioctl_mutex);
2906 mptctl_remove(pdev);
2910 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2912 * mptctl_remove - Removed ioctl devices
2913 * @pdev: Pointer to pci_dev structure
2918 mptctl_remove(struct pci_dev *pdev)
2920 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2922 kfree ( ioc->ioctl );
2925 static struct mpt_pci_driver mptctl_driver = {
2926 .probe = mptctl_probe,
2927 .remove = mptctl_remove,
2930 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2931 static int __init mptctl_init(void)
2936 show_mptmod_ver(my_NAME, my_VERSION);
2938 if(mpt_device_driver_register(&mptctl_driver,
2939 MPTCTL_DRIVER) != 0 ) {
2940 dprintk((KERN_INFO MYNAM
2941 ": failed to register dd callbacks\n"));
2944 /* Register this device */
2945 err = misc_register(&mptctl_miscdev);
2947 printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
2950 printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
2951 printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
2952 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2955 * Install our handler
2958 if ((mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER)) < 0) {
2959 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2960 misc_deregister(&mptctl_miscdev);
2965 if (mpt_reset_register(mptctl_id, mptctl_ioc_reset) == 0) {
2966 dprintk((KERN_INFO MYNAM ": Registered for IOC reset notifications\n"));
2971 if (mpt_event_register(mptctl_id, mptctl_event_process) == 0) {
2972 devtverboseprintk((KERN_INFO MYNAM
2973 ": Registered for IOC event notifications\n"));
2980 mpt_device_driver_deregister(MPTCTL_DRIVER);
2985 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2986 static void mptctl_exit(void)
2988 misc_deregister(&mptctl_miscdev);
2989 printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
2990 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2992 /* De-register reset handler from base module */
2993 mpt_reset_deregister(mptctl_id);
2994 dprintk((KERN_INFO MYNAM ": Deregistered for IOC reset notifications\n"));
2996 /* De-register callback handler from base module */
2997 mpt_deregister(mptctl_id);
2998 printk(KERN_INFO MYNAM ": Deregistered from Fusion MPT base driver\n");
3000 mpt_device_driver_deregister(MPTCTL_DRIVER);
3004 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3006 module_init(mptctl_init);
3007 module_exit(mptctl_exit);