2 * linux/drivers/message/fusion/mptctl.c
3 * Fusion MPT misc device (ioctl) driver.
4 * For use with PCI chip/adapter(s):
5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
9 * This driver would not exist if not for Alan Cox's development
10 * of the linux i2o driver.
12 * A special thanks to Pamela Delaney (LSI Logic) for tons of work
13 * and countless enhancements while adding support for the 1030
14 * chip family. Pam has been instrumental in the development of
15 * of the 2.xx.xx series fusion drivers, and her contributions are
16 * far too numerous to hope to list in one place.
18 * A huge debt of gratitude is owed to David S. Miller (DaveM)
19 * for fixing much of the stupid and broken stuff in the early
20 * driver while porting to sparc64 platform. THANK YOU!
22 * A big THANKS to Eddie C. Dost for fixing the ioctl path
23 * and most importantly f/w download on sparc64 platform!
24 * (plus Eddie's other helpful hints and insights)
26 * Thanks to Arnaldo Carvalho de Melo for finding and patching
27 * a potential memory leak in mptctl_do_fw_download(),
28 * and for some kmalloc insight:-)
30 * (see also mptbase.c)
32 * Copyright (c) 1999-2004 LSI Logic Corporation
33 * Originally By: Steven J. Ralston, Noah Romer
34 * (mailto:sjralston1@netscape.net)
35 * (mailto:mpt_linux_developer@lsil.com)
37 * $Id: mptctl.c,v 1.63 2002/12/03 21:26:33 pdelaney Exp $
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
41 This program is free software; you can redistribute it and/or modify
42 it under the terms of the GNU General Public License as published by
43 the Free Software Foundation; version 2 of the License.
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
51 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
52 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
53 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
54 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
55 solely responsible for determining the appropriateness of using and
56 distributing the Program and assumes all risks associated with its
57 exercise of rights under this Agreement, including but not limited to
58 the risks and costs of program errors, damage to or loss of data,
59 programs or equipment, and unavailability or interruption of operations.
61 DISCLAIMER OF LIABILITY
62 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
63 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
65 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
66 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
67 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
68 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
70 You should have received a copy of the GNU General Public License
71 along with this program; if not, write to the Free Software
72 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
76 #include <linux/version.h>
77 #include <linux/kernel.h>
78 #include <linux/module.h>
79 #include <linux/errno.h>
80 #include <linux/init.h>
81 #include <linux/slab.h>
82 #include <linux/types.h>
83 #include <linux/pci.h>
84 #include <linux/miscdevice.h>
85 #include <linux/smp_lock.h>
86 #include <linux/compat.h>
89 #include <asm/uaccess.h>
91 #include <scsi/scsi.h>
92 #include <scsi/scsi_cmnd.h>
93 #include <scsi/scsi_device.h>
94 #include <scsi/scsi_host.h>
95 #include <scsi/scsi_tcq.h>
97 #define COPYRIGHT "Copyright (c) 1999-2004 LSI Logic Corporation"
98 #define MODULEAUTHOR "Steven J. Ralston, Noah Romer, Pamela Delaney"
102 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
103 #define my_NAME "Fusion MPT misc device (ioctl) driver"
104 #define my_VERSION MPT_LINUX_VERSION_COMMON
105 #define MYNAM "mptctl"
107 MODULE_AUTHOR(MODULEAUTHOR);
108 MODULE_DESCRIPTION(my_NAME);
109 MODULE_LICENSE("GPL");
111 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
113 static int mptctl_id = -1;
114 static struct semaphore mptctl_syscall_sem_ioc[MPT_MAX_ADAPTERS];
116 static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
118 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
126 * Function prototypes. Called from OS entry point mptctl_ioctl.
127 * arg contents specific to function.
129 static int mptctl_fw_download(unsigned long arg);
130 static int mptctl_getiocinfo (unsigned long arg, unsigned int cmd);
131 static int mptctl_gettargetinfo (unsigned long arg);
132 static int mptctl_readtest (unsigned long arg);
133 static int mptctl_mpt_command (unsigned long arg);
134 static int mptctl_eventquery (unsigned long arg);
135 static int mptctl_eventenable (unsigned long arg);
136 static int mptctl_eventreport (unsigned long arg);
137 static int mptctl_replace_fw (unsigned long arg);
139 static int mptctl_do_reset(unsigned long arg);
140 static int mptctl_hp_hostinfo(unsigned long arg, unsigned int cmd);
141 static int mptctl_hp_targetinfo(unsigned long arg);
144 * Private function calls.
146 static int mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr);
147 static int mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen);
148 static MptSge_t *kbuf_alloc_2_sgl( int bytes, u32 dir, int sge_offset, int *frags,
149 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);
150 static void kfree_sgl( MptSge_t *sgl, dma_addr_t sgl_dma,
151 struct buflist *buflist, MPT_ADAPTER *ioc);
152 static void mptctl_timer_expired (unsigned long data);
153 static int mptctl_bus_reset(MPT_IOCTL *ioctl);
154 static int mptctl_set_tm_flags(MPT_SCSI_HOST *hd);
155 static void mptctl_free_tm_flags(MPT_ADAPTER *ioc);
158 * Reset Handler cleanup function
160 static int mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase);
162 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
164 * Scatter gather list (SGL) sizes and limits...
166 //#define MAX_SCSI_FRAGS 9
167 #define MAX_FRAGS_SPILL1 9
168 #define MAX_FRAGS_SPILL2 15
169 #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1)
171 //#define MAX_CHAIN_FRAGS 64
172 //#define MAX_CHAIN_FRAGS (15+15+15+16)
173 #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1)
175 // Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each)
176 // Works out to: 592d bytes! (9+1)*8 + 4*(15+1)*8
177 // ^----------------- 80 + 512
178 #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)
180 /* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */
181 #define MAX_KMALLOC_SZ (128*1024)
183 #define MPT_IOCTL_DEFAULT_TIMEOUT 10 /* Default timeout value (seconds) */
185 static u32 fwReplyBuffer[16];
186 static pMPIDefaultReply_t ReplyMsg = NULL;
188 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
190 * mptctl_syscall_down - Down the MPT adapter syscall semaphore.
191 * @ioc: Pointer to MPT adapter
192 * @nonblock: boolean, non-zero if O_NONBLOCK is set
194 * All of the ioctl commands can potentially sleep, which is illegal
195 * with a spinlock held, thus we perform mutual exclusion here.
197 * Returns negative errno on error, or zero for success.
200 mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock)
203 dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down(%p,%d) called\n", ioc, nonblock));
205 if (ioc->ioctl->tmPtr != NULL) {
206 dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down BUSY\n"));
211 if (down_trylock(&mptctl_syscall_sem_ioc[ioc->id]))
214 if (down_interruptible(&mptctl_syscall_sem_ioc[ioc->id]))
217 dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down return %d\n", rc));
221 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
223 * This is the callback for any message we have posted. The message itself
224 * will be returned to the message pool when we return from the IRQ
226 * This runs in irq context so be short and sweet.
229 mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
236 dctlprintk((MYIOC_s_INFO_FMT ": mptctl_reply()!\n", ioc->name));
238 cmd = req->u.hdr.Function;
243 /* If timer is not running, then an error occurred.
244 * A timeout will call the reset routine to reload the messaging
246 * Main callback will free message and reply frames.
248 if (reply && (cmd == MPI_FUNCTION_SCSI_TASK_MGMT) &&
249 (ioc->ioctl->status & MPT_IOCTL_STATUS_TMTIMER_ACTIVE)) {
250 /* This is internally generated TM
252 del_timer (&ioc->ioctl->TMtimer);
253 ioc->ioctl->status &= ~MPT_IOCTL_STATUS_TMTIMER_ACTIVE;
255 mptctl_free_tm_flags(ioc);
257 /* If TM failed, reset the timer on the existing command,
258 * will trigger an adapter reset.
260 iocStatus = reply->u.reply.IOCStatus & MPI_IOCSTATUS_MASK;
261 if (iocStatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED) {
262 if (ioc->ioctl->status & MPT_IOCTL_STATUS_TIMER_ACTIVE) {
263 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
264 del_timer (&ioc->ioctl->timer);
265 ioc->ioctl->timer.expires = jiffies + HZ;
266 add_timer(&ioc->ioctl->timer);
269 ioc->ioctl->tmPtr = NULL;
271 } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_TIMER_ACTIVE) {
274 del_timer (&ioc->ioctl->timer);
275 ioc->ioctl->status &= ~MPT_IOCTL_STATUS_TIMER_ACTIVE;
277 /* Set the overall status byte. Good if:
278 * IOC status is good OR if no reply and a SCSI IO request
281 /* Copy the reply frame (which much exist
282 * for non-SCSI I/O) to the IOC structure.
284 dctlprintk((MYIOC_s_INFO_FMT ": Copying Reply Frame @%p to IOC!\n",
286 memcpy(ioc->ioctl->ReplyFrame, reply,
287 min(ioc->reply_sz, 4*reply->u.reply.MsgLength));
288 ioc->ioctl->status |= MPT_IOCTL_STATUS_RF_VALID;
290 /* Set the command status to GOOD if IOC Status is GOOD
291 * OR if SCSI I/O cmd and data underrun or recovered error.
293 iocStatus = reply->u.reply.IOCStatus & MPI_IOCSTATUS_MASK;
294 if (iocStatus == MPI_IOCSTATUS_SUCCESS)
295 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
297 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
298 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
299 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
301 if ((iocStatus == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) ||
302 (iocStatus == MPI_IOCSTATUS_SCSI_RECOVERED_ERROR)) {
303 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
307 /* Copy the sense data - if present
309 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) &&
310 (reply->u.sreply.SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)){
312 sz = req->u.scsireq.SenseBufferLength;
313 req_index = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
314 sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
315 memcpy(ioc->ioctl->sense, sense_data, sz);
316 ioc->ioctl->status |= MPT_IOCTL_STATUS_SENSE_VALID;
319 if (cmd == MPI_FUNCTION_SCSI_TASK_MGMT)
320 mptctl_free_tm_flags(ioc);
323 } else if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
324 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
325 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
326 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
329 /* We are done, issue wake up
331 ioc->ioctl->wait_done = 1;
332 wake_up (&mptctl_wait);
333 } else if (reply && cmd == MPI_FUNCTION_FW_DOWNLOAD) {
334 /* Two paths to FW DOWNLOAD! */
335 // NOTE: Expects/requires non-Turbo reply!
336 dctlprintk((MYIOC_s_INFO_FMT ":Caching MPI_FUNCTION_FW_DOWNLOAD reply!\n",
338 memcpy(fwReplyBuffer, reply, min_t(int, sizeof(fwReplyBuffer), 4*reply->u.reply.MsgLength));
339 ReplyMsg = (pMPIDefaultReply_t) fwReplyBuffer;
345 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
346 /* mptctl_timer_expired
348 * Call back for timer process. Used only for ioctl functionality.
351 static void mptctl_timer_expired (unsigned long data)
353 MPT_IOCTL *ioctl = (MPT_IOCTL *) data;
356 dctlprintk((KERN_NOTICE MYNAM ": Timer Expired! Host %d\n",
361 if (ioctl->reset & MPTCTL_RESET_OK)
362 rc = mptctl_bus_reset(ioctl);
365 /* Issue a reset for this device.
366 * The IOC is not responding.
368 mpt_HardResetHandler(ioctl->ioc, NO_SLEEP);
379 static int mptctl_bus_reset(MPT_IOCTL *ioctl)
382 SCSITaskMgmt_t *pScsiTm;
388 ioctl->reset &= ~MPTCTL_RESET_OK;
390 if (ioctl->ioc->sh == NULL)
393 hd = (MPT_SCSI_HOST *) ioctl->ioc->sh->hostdata;
397 /* Single threading ....
399 if (mptctl_set_tm_flags(hd) != 0)
404 if ((mf = mpt_get_msg_frame(mptctl_id, ioctl->ioc)) == NULL) {
405 dctlprintk((MYIOC_s_WARN_FMT "IssueTaskMgmt, no msg frames!!\n",
408 mptctl_free_tm_flags(ioctl->ioc);
412 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
413 ioctl->ioc->name, mf));
415 pScsiTm = (SCSITaskMgmt_t *) mf;
416 pScsiTm->TargetID = ioctl->target;
417 pScsiTm->Bus = hd->port; /* 0 */
418 pScsiTm->ChainOffset = 0;
419 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
420 pScsiTm->Reserved = 0;
421 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
422 pScsiTm->Reserved1 = 0;
423 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
425 for (ii= 0; ii < 8; ii++)
426 pScsiTm->LUN[ii] = 0;
428 for (ii=0; ii < 7; ii++)
429 pScsiTm->Reserved2[ii] = 0;
431 pScsiTm->TaskMsgContext = 0;
432 dtmprintk((MYIOC_s_INFO_FMT "mptctl_bus_reset: issued.\n", ioctl->ioc->name));
435 ioctl->TMtimer.expires = jiffies + HZ * 20; /* 20 seconds */
436 ioctl->status |= MPT_IOCTL_STATUS_TMTIMER_ACTIVE;
437 add_timer(&ioctl->TMtimer);
439 retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
440 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, NO_SLEEP);
443 dtmprintk((MYIOC_s_WARN_FMT "_send_handshake FAILED!"
444 " (hd %p, ioc %p, mf %p) \n", ioctl->ioc->name, hd, hd->ioc, mf));
446 mptctl_free_tm_flags(ioctl->ioc);
447 del_timer(&ioctl->TMtimer);
448 mpt_free_msg_frame(mptctl_id, ioctl->ioc, mf);
456 mptctl_set_tm_flags(MPT_SCSI_HOST *hd) {
459 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
461 if (hd->tmState == TM_STATE_NONE) {
462 hd->tmState = TM_STATE_IN_PROGRESS;
464 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
466 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
474 mptctl_free_tm_flags(MPT_ADAPTER *ioc)
479 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
483 spin_lock_irqsave(&ioc->FreeQlock, flags);
485 hd->tmState = TM_STATE_ERROR;
487 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
493 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
496 * Clean-up functionality. Used only if there has been a
497 * reload of the FW due.
501 mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
503 MPT_IOCTL *ioctl = ioc->ioctl;
504 dctlprintk((KERN_INFO MYNAM ": IOC %s_reset routed to IOCTL driver!\n",
505 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
506 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
508 if (reset_phase == MPT_IOC_SETUP_RESET){
510 } else if (reset_phase == MPT_IOC_PRE_RESET){
512 /* Someone has called the reset handler to
513 * do a hard reset. No more replies from the FW.
514 * Delete the timer. TM flags cleaned up by SCSI driver.
515 * Do not need to free msg frame, as re-initialized
517 if (ioctl && (ioctl->status & MPT_IOCTL_STATUS_TIMER_ACTIVE)){
518 del_timer(&ioctl->timer);
520 if (ioctl && (ioctl->status & MPT_IOCTL_STATUS_TMTIMER_ACTIVE)){
521 ioctl->status &= ~MPT_IOCTL_STATUS_TMTIMER_ACTIVE;
522 del_timer(&ioctl->TMtimer);
523 mpt_free_msg_frame(mptctl_id, ioc, ioctl->tmPtr);
529 /* Set the status and continue IOCTL
530 * processing. All memory will be free'd
531 * by originating thread after wake_up is
534 if (ioctl && (ioctl->status & MPT_IOCTL_STATUS_TIMER_ACTIVE)){
535 ioctl->status |= MPT_IOCTL_STATUS_DID_IOCRESET;
537 /* Wake up the calling process
539 ioctl->wait_done = 1;
540 wake_up(&mptctl_wait);
547 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
550 * cmd - specify the particular IOCTL command to be issued
551 * arg - data specific to the command. Must not be null.
554 mptctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
556 mpt_ioctl_header __user *uhdr = (void __user *) arg;
557 mpt_ioctl_header khdr;
560 int nonblock = (file->f_flags & O_NONBLOCK);
562 MPT_ADAPTER *iocp = NULL;
564 dctlprintk(("mptctl_ioctl() called\n"));
566 if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
567 printk(KERN_ERR "%s::mptctl_ioctl() @%d - "
568 "Unable to copy mpt_ioctl_header data @ %p\n",
569 __FILE__, __LINE__, uhdr);
572 ret = -ENXIO; /* (-6) No such device or address */
574 /* Verify intended MPT adapter - set iocnum and the adapter
577 iocnumX = khdr.iocnum & 0xFF;
578 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
580 dctlprintk((KERN_ERR "%s::mptctl_ioctl() @%d - ioc%d not found!\n",
581 __FILE__, __LINE__, iocnumX));
586 printk(KERN_ERR "%s::mptctl_ioctl() @%d - Controller disabled.\n",
591 /* Handle those commands that are just returning
592 * information stored in the driver.
593 * These commands should never time out and are unaffected
594 * by TM and FW reloads.
596 if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
597 return mptctl_getiocinfo(arg, _IOC_SIZE(cmd));
598 } else if (cmd == MPTTARGETINFO) {
599 return mptctl_gettargetinfo(arg);
600 } else if (cmd == MPTTEST) {
601 return mptctl_readtest(arg);
602 } else if (cmd == MPTEVENTQUERY) {
603 return mptctl_eventquery(arg);
604 } else if (cmd == MPTEVENTENABLE) {
605 return mptctl_eventenable(arg);
606 } else if (cmd == MPTEVENTREPORT) {
607 return mptctl_eventreport(arg);
608 } else if (cmd == MPTFWREPLACE) {
609 return mptctl_replace_fw(arg);
612 /* All of these commands require an interrupt or
613 * are unknown/illegal.
615 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
618 dctlprintk((MYIOC_s_INFO_FMT ": mptctl_ioctl()\n", iocp->name));
620 if (cmd == MPTFWDOWNLOAD)
621 ret = mptctl_fw_download(arg);
622 else if (cmd == MPTCOMMAND)
623 ret = mptctl_mpt_command(arg);
624 else if (cmd == MPTHARDRESET)
625 ret = mptctl_do_reset(arg);
626 else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
627 ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
628 else if (cmd == HP_GETTARGETINFO)
629 ret = mptctl_hp_targetinfo(arg);
634 up(&mptctl_syscall_sem_ioc[iocp->id]);
639 static int mptctl_do_reset(unsigned long arg)
641 struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
642 struct mpt_ioctl_diag_reset krinfo;
645 dctlprintk((KERN_INFO "mptctl_do_reset called.\n"));
647 if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
648 printk(KERN_ERR "%s@%d::mptctl_do_reset - "
649 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
650 __FILE__, __LINE__, urinfo);
654 if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
655 dctlprintk((KERN_ERR "%s@%d::mptctl_do_reset - ioc%d not found!\n",
656 __FILE__, __LINE__, krinfo.hdr.iocnum));
657 return -ENODEV; /* (-6) No such device or address */
660 if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
661 printk (KERN_ERR "%s@%d::mptctl_do_reset - reset failed.\n",
669 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
671 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
672 * This structure contains: iocnum, firmware length (bytes),
673 * pointer to user space memory where the fw image is stored.
676 * Return: 0 if successful
677 * -EFAULT if data unavailable
678 * -ENXIO if no such device
679 * -EAGAIN if resource problem
680 * -ENOMEM if no memory for SGE
681 * -EMLINK if too many chain buffers required
682 * -EBADRQC if adapter does not support FW download
683 * -EBUSY if adapter is busy
684 * -ENOMSG if FW upload returned bad status
687 mptctl_fw_download(unsigned long arg)
689 struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
690 struct mpt_fw_xfer kfwdl;
692 dctlprintk((KERN_INFO "mptctl_fwdl called. mptctl_id = %xh\n", mptctl_id)); //tc
693 if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
694 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
695 "Unable to copy mpt_fw_xfer struct @ %p\n",
696 __FILE__, __LINE__, ufwdl);
700 return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
703 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
705 * FW Download engine.
707 * Return: 0 if successful
708 * -EFAULT if data unavailable
709 * -ENXIO if no such device
710 * -EAGAIN if resource problem
711 * -ENOMEM if no memory for SGE
712 * -EMLINK if too many chain buffers required
713 * -EBADRQC if adapter does not support FW download
714 * -EBUSY if adapter is busy
715 * -ENOMSG if FW upload returned bad status
718 mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen)
723 FWDownloadTCSGE_t *ptsge;
724 MptSge_t *sgl, *sgIn;
726 struct buflist *buflist;
735 int fw_bytes_copied = 0;
741 dctlprintk((KERN_INFO "mptctl_do_fwdl called. mptctl_id = %xh.\n", mptctl_id));
743 dctlprintk((KERN_INFO "DbG: kfwdl.bufp = %p\n", ufwbuf));
744 dctlprintk((KERN_INFO "DbG: kfwdl.fwlen = %d\n", (int)fwlen));
745 dctlprintk((KERN_INFO "DbG: kfwdl.ioc = %04xh\n", ioc));
747 if ((ioc = mpt_verify_adapter(ioc, &iocp)) < 0) {
748 dctlprintk(("%s@%d::_ioctl_fwdl - ioc%d not found!\n",
749 __FILE__, __LINE__, ioc));
750 return -ENODEV; /* (-6) No such device or address */
753 /* Valid device. Get a message frame and construct the FW download message.
755 if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
757 dlmsg = (FWDownload_t*) mf;
758 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
759 sgOut = (char *) (ptsge + 1);
762 * Construct f/w download request
764 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
766 dlmsg->ChainOffset = 0;
767 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
768 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
771 /* Set up the Transaction SGE.
774 ptsge->ContextSize = 0;
775 ptsge->DetailsLength = 12;
776 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
777 ptsge->Reserved_0100_Checksum = 0;
778 ptsge->ImageOffset = 0;
779 ptsge->ImageSize = cpu_to_le32(fwlen);
785 * Need to kmalloc area(s) for holding firmware image bytes.
786 * But we need to do it piece meal, using a proper
787 * scatter gather list (with 128kB MAX hunks).
789 * A practical limit here might be # of sg hunks that fit into
790 * a single IOC request frame; 12 or 8 (see below), so:
791 * For FC9xx: 12 x 128kB == 1.5 mB (max)
792 * For C1030: 8 x 128kB == 1 mB (max)
793 * We could support chaining, but things get ugly(ier:)
795 * Set the sge_offset to the start of the sgl (bytes).
797 sgdir = 0x04000000; /* IOC will READ from sys mem */
798 sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
799 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
800 &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
804 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
805 * for FC9xx f/w image, but calculate max number of sge hunks
806 * we can fit into a request frame, and limit ourselves to that.
807 * (currently no chain support)
808 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
814 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t))
815 / (sizeof(dma_addr_t) + sizeof(u32));
816 if (numfrags > maxfrags) {
821 dctlprintk((KERN_INFO "DbG: sgl buffer = %p, sgfrags = %d\n", sgl, numfrags));
824 * Parse SG list, copying sgl itself,
825 * plus f/w image hunks from user space as we go...
830 for (i=0; i < numfrags; i++) {
832 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
833 * Skip everything but Simple. If simple, copy from
834 * user space into kernel space.
835 * Note: we should not have anything but Simple as
836 * Chain SGE are illegal.
838 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
839 if (nib == 0 || nib == 3) {
841 } else if (sgIn->Address) {
842 mpt_add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
844 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
845 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
846 "Unable to copy f/w buffer hunk#%d @ %p\n",
847 __FILE__, __LINE__, n, ufwbuf);
850 fw_bytes_copied += bl->len;
854 sgOut += (sizeof(dma_addr_t) + sizeof(u32));
860 printk(KERN_INFO MYNAM ": F/W download request:\n" KERN_INFO " ");
861 for (i=0; i < 7+numfrags*2; i++)
862 printk(" %08x", le32_to_cpu(m[i]));
868 * Finally, perform firmware download.
871 mpt_put_msg_frame(mptctl_id, iocp, mf);
874 * Wait until the reply has been received
876 for (cntdn=HZ*60, i=1; ReplyMsg == NULL; cntdn--, i++) {
883 dctlprintk((KERN_INFO "DbG::_do_fwdl: "
884 "In ReplyMsg loop - iteration %d\n",
888 set_current_state(TASK_INTERRUPTIBLE);
893 kfree_sgl(sgl, sgl_dma, buflist, iocp);
895 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
896 if (iocstat == MPI_IOCSTATUS_SUCCESS) {
897 printk(KERN_INFO MYNAM ": F/W update successfully sent to %s!\n", iocp->name);
899 } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
900 printk(KERN_WARNING MYNAM ": ?Hmmm... %s says it doesn't support F/W download!?!\n",
902 printk(KERN_WARNING MYNAM ": (time to go bang on somebodies door)\n");
904 } else if (iocstat == MPI_IOCSTATUS_BUSY) {
905 printk(KERN_WARNING MYNAM ": Warning! %s says: IOC_BUSY!\n", iocp->name);
906 printk(KERN_WARNING MYNAM ": (try again later?)\n");
909 printk(KERN_WARNING MYNAM "::ioctl_fwdl() ERROR! %s returned [bad] status = %04xh\n",
910 iocp->name, iocstat);
911 printk(KERN_WARNING MYNAM ": (bad VooDoo)\n");
917 kfree_sgl(sgl, sgl_dma, buflist, iocp);
921 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
923 * SGE Allocation routine
925 * Inputs: bytes - number of bytes to be transferred
926 * sgdir - data direction
927 * sge_offset - offset (in bytes) from the start of the request
928 * frame to the first SGE
929 * ioc - pointer to the mptadapter
930 * Outputs: frags - number of scatter gather elements
931 * blp - point to the buflist pointer
932 * sglbuf_dma - pointer to the (dma) sgl
933 * Returns: Null if failes
934 * pointer to the (virtual) sgl if successful.
937 kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
938 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
940 MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
941 /* and chain buffers */
942 struct buflist *buflist = NULL; /* kernel routine */
946 int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
947 int bytes_allocd = 0;
949 dma_addr_t pa; // phys addr
951 int sg_spill = MAX_FRAGS_SPILL1;
957 /* Allocate and initialize an array of kernel
958 * structures for the SG elements.
960 i = MAX_SGL_BYTES / 8;
961 buflist = kmalloc(i, GFP_USER);
964 memset(buflist, 0, i);
967 /* Allocate a single block of memory to store the sg elements and
968 * the chain buffers. The calling routine is responsible for
969 * copying the data in this array into the correct place in the
970 * request and chain buffers.
972 sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
976 if (sgdir & 0x04000000)
977 dir = PCI_DMA_TODEVICE;
979 dir = PCI_DMA_FROMDEVICE;
982 * sgl = sglbuf = point to beginning of sg buffer
983 * buflist_ent = 0 = first kernel structure
984 * sg_spill = number of SGE that can be written before the first
989 sg_spill = ((ioc->req_sz - sge_offset)/(sizeof(dma_addr_t) + sizeof(u32))) - 1;
990 while (bytes_allocd < bytes) {
991 this_alloc = min(alloc_sz, bytes-bytes_allocd);
992 buflist[buflist_ent].len = this_alloc;
993 buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
996 if (buflist[buflist_ent].kptr == NULL) {
997 alloc_sz = alloc_sz / 2;
999 printk(KERN_WARNING MYNAM "-SG: No can do - "
1000 "not enough memory! :-(\n");
1001 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
1007 dma_addr_t dma_addr;
1009 bytes_allocd += this_alloc;
1010 sgl->FlagsLength = (0x10000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|this_alloc);
1011 dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir);
1012 sgl->Address = dma_addr;
1020 if (bytes_allocd >= bytes)
1023 /* Need to chain? */
1024 if (fragcnt == sg_spill) {
1025 printk(KERN_WARNING MYNAM "-SG: No can do - " "Chain required! :-(\n");
1026 printk(KERN_WARNING MYNAM "(freeing %d frags)\n", numfrags);
1030 /* overflow check... */
1031 if (numfrags*8 > MAX_SGL_BYTES){
1033 printk(KERN_WARNING MYNAM "-SG: No can do - "
1034 "too many SG frags! :-(\n");
1035 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
1041 /* Last sge fixup: set LE+eol+eob bits */
1042 sgl[-1].FlagsLength |= 0xC1000000;
1047 dctlprintk((KERN_INFO MYNAM "-SG: kbuf_alloc_2_sgl() - "
1048 "%d SG frags generated!\n",
1051 dctlprintk((KERN_INFO MYNAM "-SG: kbuf_alloc_2_sgl() - "
1052 "last (big) alloc_sz=%d\n",
1058 if (sglbuf != NULL) {
1061 for (i = 0; i < numfrags; i++) {
1062 dma_addr_t dma_addr;
1066 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
1069 dma_addr = sglbuf[i].Address;
1070 kptr = buflist[i].kptr;
1071 len = buflist[i].len;
1073 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1075 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma);
1081 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1083 * Routine to free the SGL elements.
1086 kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
1089 struct buflist *bl = buflist;
1094 if (sg->FlagsLength & 0x04000000)
1095 dir = PCI_DMA_TODEVICE;
1097 dir = PCI_DMA_FROMDEVICE;
1099 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1100 while (! (nib & 0x4)) { /* eob */
1101 /* skip ignore/chain. */
1102 if (nib == 0 || nib == 3) {
1104 } else if (sg->Address) {
1105 dma_addr_t dma_addr;
1109 dma_addr = sg->Address;
1112 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1113 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1118 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1123 dma_addr_t dma_addr;
1127 dma_addr = sg->Address;
1130 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1131 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1135 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma);
1137 dctlprintk((KERN_INFO MYNAM "-SG: Free'd 1 SGL buf + %d kbufs!\n", n));
1140 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1142 * mptctl_getiocinfo - Query the host adapter for IOC information.
1143 * @arg: User space argument
1146 * Return: 0 if successful
1147 * -EFAULT if data unavailable
1148 * -ENODEV if no such device/adapter
1151 mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1153 struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
1154 struct mpt_ioctl_iocinfo *karg;
1156 struct pci_dev *pdev;
1157 struct Scsi_Host *sh;
1161 unsigned int max_id;
1167 dctlprintk((": mptctl_getiocinfo called.\n"));
1168 /* Add of PCI INFO results in unaligned access for
1169 * IA64 and Sparc. Reset long to int. Return no PCI
1170 * data for obsolete format.
1172 if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
1174 else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
1176 else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
1178 else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
1179 cim_rev = 0; /* obsolete */
1183 karg = kmalloc(data_size, GFP_KERNEL);
1185 printk(KERN_ERR "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
1186 __FILE__, __LINE__);
1190 if (copy_from_user(karg, uarg, data_size)) {
1191 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1192 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1193 __FILE__, __LINE__, uarg);
1198 if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
1200 dctlprintk((KERN_ERR "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
1201 __FILE__, __LINE__, iocnum));
1206 /* Verify the data transfer size is correct.
1207 * Ignore the port setting.
1209 if (karg->hdr.maxDataSize != data_size) {
1210 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1211 "Structure size mismatch. Command not completed.\n",
1212 __FILE__, __LINE__);
1217 /* Fill in the data and return the structure to the calling
1220 if ((int)ioc->chip_type <= (int) FC929)
1221 karg->adapterType = MPT_IOCTL_INTERFACE_FC;
1223 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1225 port = karg->hdr.port;
1228 pdev = (struct pci_dev *) ioc->pcidev;
1230 karg->pciId = pdev->device;
1231 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1232 karg->hwRev = revision;
1233 karg->subSystemDevice = pdev->subsystem_device;
1234 karg->subSystemVendor = pdev->subsystem_vendor;
1237 /* Get the PCI bus, device, and function numbers for the IOC
1239 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1240 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1241 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1242 } else if (cim_rev == 2) {
1243 /* Get the PCI bus, device, function and segment ID numbers
1245 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1246 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1247 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1248 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1249 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
1252 /* Get number of devices
1254 if ((sh = ioc->sh) != NULL) {
1255 /* sh->max_id = maximum target ID + 1
1257 max_id = sh->max_id - 1;
1258 hd = (MPT_SCSI_HOST *) sh->hostdata;
1260 /* Check all of the target structures and
1263 if (hd && hd->Targets) {
1264 for (ii = 0; ii <= max_id; ii++) {
1265 if (hd->Targets[ii])
1270 karg->numDevices = numDevices;
1272 /* Set the BIOS and FW Version
1274 karg->FWVersion = ioc->facts.FWVersion.Word;
1275 karg->BIOSVersion = ioc->biosVersion;
1277 /* Set the Version Strings.
1279 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
1280 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
1282 karg->busChangeEvent = 0;
1283 karg->hostId = ioc->pfacts[port].PortSCSIID;
1284 karg->rsvd[0] = karg->rsvd[1] = 0;
1286 /* Copy the data from kernel memory to user memory
1288 if (copy_to_user((char __user *)arg, karg, data_size)) {
1289 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1290 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1291 __FILE__, __LINE__, uarg);
1300 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1302 * mptctl_gettargetinfo - Query the host adapter for target information.
1303 * @arg: User space argument
1306 * Return: 0 if successful
1307 * -EFAULT if data unavailable
1308 * -ENODEV if no such device/adapter
1311 mptctl_gettargetinfo (unsigned long arg)
1313 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1314 struct mpt_ioctl_targetinfo karg;
1316 struct Scsi_Host *sh;
1325 unsigned int max_id;
1326 int id, jj, indexed_lun, lun_index;
1330 u8 port, devType, bus_id;
1332 dctlprintk(("mptctl_gettargetinfo called.\n"));
1333 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
1334 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1335 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1336 __FILE__, __LINE__, uarg);
1340 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1342 dctlprintk((KERN_ERR "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
1343 __FILE__, __LINE__, iocnum));
1347 /* Get the port number and set the maximum number of bytes
1348 * in the returned structure.
1349 * Ignore the port setting.
1351 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1352 maxWordsLeft = numBytes/sizeof(int);
1353 port = karg.hdr.port;
1355 if (maxWordsLeft <= 0) {
1356 printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1357 __FILE__, __LINE__);
1361 /* Fill in the data and return the structure to the calling
1365 /* struct mpt_ioctl_targetinfo does not contain sufficient space
1366 * for the target structures so when the IOCTL is called, there is
1367 * not sufficient stack space for the structure. Allocate memory,
1368 * populate the memory, copy back to the user, then free memory.
1369 * targetInfo format:
1370 * bits 31-24: reserved
1375 pmem = kmalloc(numBytes, GFP_KERNEL);
1377 printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1378 __FILE__, __LINE__);
1381 memset(pmem, 0, numBytes);
1382 pdata = (int *) pmem;
1384 /* Get number of devices
1386 if ((sh = ioc->sh) != NULL) {
1388 max_id = sh->max_id - 1;
1389 hd = (MPT_SCSI_HOST *) sh->hostdata;
1391 /* Check all of the target structures.
1392 * Save the Id and increment the counter,
1394 * sh->max_id = maximum target ID + 1
1396 if (hd && hd->Targets) {
1397 mpt_findImVolumes(ioc);
1398 pIoc2 = ioc->spi_data.pIocPg2;
1399 for ( id = 0; id <= max_id; ) {
1400 if ( pIoc2 && pIoc2->NumActiveVolumes ) {
1401 if ( id == pIoc2->RaidVolume[0].VolumeID ) {
1402 if (maxWordsLeft <= 0) {
1403 printk(KERN_ERR "mptctl_gettargetinfo - "
1404 "buffer is full but volume is available on ioc %d\n, numDevices=%d", iocnum, numDevices);
1405 goto data_space_full;
1407 if ( ( pIoc2->RaidVolume[0].Flags & MPI_IOCPAGE2_FLAG_VOLUME_INACTIVE ) == 0 )
1411 bus_id = pIoc2->RaidVolume[0].VolumeBus;
1413 *pdata = ( (devType << 24) | (bus_id << 8) | id );
1414 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1415 "volume ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1420 pIoc3 = ioc->spi_data.pIocPg3;
1421 for ( jj = 0; jj < pIoc3->NumPhysDisks; jj++ ) {
1422 if ( pIoc3->PhysDisk[jj].PhysDiskID == id )
1427 if ( (vdev = hd->Targets[id]) ) {
1428 for (jj = 0; jj <= MPT_LAST_LUN; jj++) {
1429 lun_index = (jj >> 5);
1430 indexed_lun = (jj % 32);
1431 lun = (1 << indexed_lun);
1432 if (vdev->luns[lun_index] & lun) {
1433 if (maxWordsLeft <= 0) {
1434 printk(KERN_ERR "mptctl_gettargetinfo - "
1435 "buffer is full but more targets are available on ioc %d numDevices=%d\n", iocnum, numDevices);
1436 goto data_space_full;
1438 bus_id = vdev->bus_id;
1440 *pdata = ( (jj << 16) | (bus_id << 8) | id );
1441 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1442 "target ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1454 karg.numDevices = numDevices;
1456 /* Copy part of the data from kernel memory to user memory
1458 if (copy_to_user((char __user *)arg, &karg,
1459 sizeof(struct mpt_ioctl_targetinfo))) {
1460 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1461 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1462 __FILE__, __LINE__, uarg);
1467 /* Copy the remaining data from kernel memory to user memory
1469 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
1470 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1471 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1472 __FILE__, __LINE__, pdata);
1482 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1483 /* MPT IOCTL Test function.
1486 * Return: 0 if successful
1487 * -EFAULT if data unavailable
1488 * -ENODEV if no such device/adapter
1491 mptctl_readtest (unsigned long arg)
1493 struct mpt_ioctl_test __user *uarg = (void __user *) arg;
1494 struct mpt_ioctl_test karg;
1498 dctlprintk(("mptctl_readtest called.\n"));
1499 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
1500 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1501 "Unable to read in mpt_ioctl_test struct @ %p\n",
1502 __FILE__, __LINE__, uarg);
1506 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1508 dctlprintk((KERN_ERR "%s::mptctl_readtest() @%d - ioc%d not found!\n",
1509 __FILE__, __LINE__, iocnum));
1513 /* Fill in the data and return the structure to the calling
1518 karg.chip_type = ioc->mfcnt;
1520 karg.chip_type = ioc->chip_type;
1522 strncpy (karg.name, ioc->name, MPT_MAX_NAME);
1523 karg.name[MPT_MAX_NAME-1]='\0';
1524 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
1525 karg.product[MPT_PRODUCT_LENGTH-1]='\0';
1527 /* Copy the data from kernel memory to user memory
1529 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
1530 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1531 "Unable to write out mpt_ioctl_test struct @ %p\n",
1532 __FILE__, __LINE__, uarg);
1539 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1541 * mptctl_eventquery - Query the host adapter for the event types
1542 * that are being logged.
1543 * @arg: User space argument
1546 * Return: 0 if successful
1547 * -EFAULT if data unavailable
1548 * -ENODEV if no such device/adapter
1551 mptctl_eventquery (unsigned long arg)
1553 struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
1554 struct mpt_ioctl_eventquery karg;
1558 dctlprintk(("mptctl_eventquery called.\n"));
1559 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
1560 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1561 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1562 __FILE__, __LINE__, uarg);
1566 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1568 dctlprintk((KERN_ERR "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
1569 __FILE__, __LINE__, iocnum));
1573 karg.eventEntries = ioc->eventLogSize;
1574 karg.eventTypes = ioc->eventTypes;
1576 /* Copy the data from kernel memory to user memory
1578 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
1579 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1580 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1581 __FILE__, __LINE__, uarg);
1587 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1589 mptctl_eventenable (unsigned long arg)
1591 struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
1592 struct mpt_ioctl_eventenable karg;
1596 dctlprintk(("mptctl_eventenable called.\n"));
1597 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
1598 printk(KERN_ERR "%s@%d::mptctl_eventenable - "
1599 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1600 __FILE__, __LINE__, uarg);
1604 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1606 dctlprintk((KERN_ERR "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
1607 __FILE__, __LINE__, iocnum));
1611 if (ioc->events == NULL) {
1612 /* Have not yet allocated memory - do so now.
1614 int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1615 ioc->events = kmalloc(sz, GFP_KERNEL);
1616 if (ioc->events == NULL) {
1617 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1620 memset(ioc->events, 0, sz);
1621 ioc->alloc_total += sz;
1623 ioc->eventLogSize = MPTCTL_EVENT_LOG_SIZE;
1624 ioc->eventContext = 0;
1627 /* Update the IOC event logging flag.
1629 ioc->eventTypes = karg.eventTypes;
1634 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1636 mptctl_eventreport (unsigned long arg)
1638 struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
1639 struct mpt_ioctl_eventreport karg;
1642 int numBytes, maxEvents, max;
1644 dctlprintk(("mptctl_eventreport called.\n"));
1645 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
1646 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1647 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1648 __FILE__, __LINE__, uarg);
1652 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1654 dctlprintk((KERN_ERR "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
1655 __FILE__, __LINE__, iocnum));
1659 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1660 maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
1663 max = ioc->eventLogSize < maxEvents ? ioc->eventLogSize : maxEvents;
1665 /* If fewer than 1 event is requested, there must have
1666 * been some type of error.
1668 if ((max < 1) || !ioc->events)
1671 /* Copy the data from kernel memory to user memory
1673 numBytes = max * sizeof(MPT_IOCTL_EVENTS);
1674 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
1675 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1676 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1677 __FILE__, __LINE__, ioc->events);
1684 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1686 mptctl_replace_fw (unsigned long arg)
1688 struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
1689 struct mpt_ioctl_replace_fw karg;
1694 dctlprintk(("mptctl_replace_fw called.\n"));
1695 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
1696 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1697 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1698 __FILE__, __LINE__, uarg);
1702 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1704 dctlprintk((KERN_ERR "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
1705 __FILE__, __LINE__, iocnum));
1709 /* If caching FW, Free the old FW image
1711 if (ioc->cached_fw == NULL)
1714 mpt_free_fw_memory(ioc);
1716 /* Allocate memory for the new FW image
1718 newFwSize = karg.newImageSize;
1720 if (newFwSize & 0x01)
1722 if (newFwSize & 0x02)
1725 mpt_alloc_fw_memory(ioc, newFwSize);
1726 if (ioc->cached_fw == NULL)
1729 /* Copy the data from user memory to kernel space
1731 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
1732 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1733 "Unable to read in mpt_ioctl_replace_fw image "
1734 "@ %p\n", __FILE__, __LINE__, uarg);
1735 mpt_free_fw_memory(ioc);
1739 /* Update IOCFactsReply
1741 ioc->facts.FWImageSize = newFwSize;
1745 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1746 /* MPT IOCTL MPTCOMMAND function.
1747 * Cast the arg into the mpt_ioctl_mpt_command structure.
1750 * Return: 0 if successful
1751 * -EBUSY if previous command timout and IOC reset is not complete.
1752 * -EFAULT if data unavailable
1753 * -ENODEV if no such device/adapter
1754 * -ETIME if timer expires
1755 * -ENOMEM if memory allocation error
1758 mptctl_mpt_command (unsigned long arg)
1760 struct mpt_ioctl_command __user *uarg = (void __user *) arg;
1761 struct mpt_ioctl_command karg;
1766 dctlprintk(("mptctl_command called.\n"));
1768 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
1769 printk(KERN_ERR "%s@%d::mptctl_mpt_command - "
1770 "Unable to read in mpt_ioctl_command struct @ %p\n",
1771 __FILE__, __LINE__, uarg);
1775 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1777 dctlprintk((KERN_ERR "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
1778 __FILE__, __LINE__, iocnum));
1782 rc = mptctl_do_mpt_command (karg, &uarg->MF);
1787 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1788 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1791 * Return: 0 if successful
1792 * -EBUSY if previous command timout and IOC reset is not complete.
1793 * -EFAULT if data unavailable
1794 * -ENODEV if no such device/adapter
1795 * -ETIME if timer expires
1796 * -ENOMEM if memory allocation error
1797 * -EPERM if SCSI I/O and target is untagged
1800 mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1803 MPT_FRAME_HDR *mf = NULL;
1806 struct buflist bufIn; /* data In buffer */
1807 struct buflist bufOut; /* data Out buffer */
1808 dma_addr_t dma_addr_in;
1809 dma_addr_t dma_addr_out;
1810 int dir; /* PCI data direction */
1811 int sgSize = 0; /* Num SG elements */
1812 int iocnum, flagsLength;
1815 int tm_flags_set = 0;
1818 dctlprintk(("mptctl_do_mpt_command called.\n"));
1819 bufIn.kptr = bufOut.kptr = NULL;
1821 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1823 dctlprintk((KERN_ERR "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
1824 __FILE__, __LINE__, iocnum));
1828 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1829 "No memory available during driver init.\n",
1830 __FILE__, __LINE__);
1832 } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) {
1833 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1834 "Busy with IOC Reset \n", __FILE__, __LINE__);
1838 /* Verify that the final request frame will not be too large.
1840 sz = karg.dataSgeOffset * 4;
1841 if (karg.dataInSize > 0)
1842 sz += sizeof(dma_addr_t) + sizeof(u32);
1843 if (karg.dataOutSize > 0)
1844 sz += sizeof(dma_addr_t) + sizeof(u32);
1846 if (sz > ioc->req_sz) {
1847 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1848 "Request frame too large (%d) maximum (%d)\n",
1849 __FILE__, __LINE__, sz, ioc->req_sz);
1853 /* Get a free request frame and save the message context.
1855 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
1858 hdr = (MPIHeader_t *) mf;
1859 msgContext = le32_to_cpu(hdr->MsgContext);
1860 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1862 /* Copy the request frame
1863 * Reset the saved message context.
1864 * Request frame in user space
1866 if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
1867 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1868 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1869 __FILE__, __LINE__, mfPtr);
1873 hdr->MsgContext = cpu_to_le32(msgContext);
1876 /* Verify that this request is allowed.
1878 switch (hdr->Function) {
1879 case MPI_FUNCTION_IOC_FACTS:
1880 case MPI_FUNCTION_PORT_FACTS:
1881 karg.dataOutSize = karg.dataInSize = 0;
1884 case MPI_FUNCTION_CONFIG:
1885 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
1886 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
1887 case MPI_FUNCTION_FW_UPLOAD:
1888 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
1889 case MPI_FUNCTION_FW_DOWNLOAD:
1890 case MPI_FUNCTION_FC_PRIMITIVE_SEND:
1893 case MPI_FUNCTION_SCSI_IO_REQUEST:
1895 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1896 VirtDevice *pTarget = NULL;
1897 MPT_SCSI_HOST *hd = NULL;
1898 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1900 int target = (int) pScsiReq->TargetID;
1903 if ((target < 0) || (target >= ioc->sh->max_id)) {
1904 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1905 "Target ID out of bounds. \n",
1906 __FILE__, __LINE__);
1911 pScsiReq->MsgFlags = mpt_msg_flags();
1913 /* verify that app has not requested
1914 * more sense data than driver
1915 * can provide, if so, reset this parameter
1916 * set the sense buffer pointer low address
1917 * update the control field to specify Q type
1919 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1920 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1922 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1924 pScsiReq->SenseBufferLowAddr =
1925 cpu_to_le32(ioc->sense_buf_low_dma
1926 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1928 if ((hd = (MPT_SCSI_HOST *) ioc->sh->hostdata)) {
1930 pTarget = hd->Targets[target];
1933 if (pTarget &&(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1934 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1936 /* Have the IOCTL driver set the direction based
1937 * on the dataOutSize (ordering issue with Sparc).
1939 if (karg.dataOutSize > 0) {
1940 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1941 dataSize = karg.dataOutSize;
1943 scsidir = MPI_SCSIIO_CONTROL_READ;
1944 dataSize = karg.dataInSize;
1947 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1948 pScsiReq->DataLength = cpu_to_le32(dataSize);
1950 ioc->ioctl->reset = MPTCTL_RESET_OK;
1951 ioc->ioctl->target = target;
1954 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1955 "SCSI driver is not loaded. \n",
1956 __FILE__, __LINE__);
1962 case MPI_FUNCTION_RAID_ACTION:
1967 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1969 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1970 int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1971 int scsidir = MPI_SCSIIO_CONTROL_READ;
1974 pScsiReq->MsgFlags = mpt_msg_flags();
1976 /* verify that app has not requested
1977 * more sense data than driver
1978 * can provide, if so, reset this parameter
1979 * set the sense buffer pointer low address
1980 * update the control field to specify Q type
1982 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1983 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1985 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1987 pScsiReq->SenseBufferLowAddr =
1988 cpu_to_le32(ioc->sense_buf_low_dma
1989 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1991 /* All commands to physical devices are tagged
1994 /* Have the IOCTL driver set the direction based
1995 * on the dataOutSize (ordering issue with Sparc).
1997 if (karg.dataOutSize > 0) {
1998 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1999 dataSize = karg.dataOutSize;
2001 scsidir = MPI_SCSIIO_CONTROL_READ;
2002 dataSize = karg.dataInSize;
2005 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
2006 pScsiReq->DataLength = cpu_to_le32(dataSize);
2008 ioc->ioctl->reset = MPTCTL_RESET_OK;
2009 ioc->ioctl->target = pScsiReq->TargetID;
2011 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2012 "SCSI driver is not loaded. \n",
2013 __FILE__, __LINE__);
2019 case MPI_FUNCTION_SCSI_TASK_MGMT:
2021 MPT_SCSI_HOST *hd = NULL;
2022 if ((ioc->sh == NULL) || ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL)) {
2023 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2024 "SCSI driver not loaded or SCSI host not found. \n",
2025 __FILE__, __LINE__);
2028 } else if (mptctl_set_tm_flags(hd) != 0) {
2036 case MPI_FUNCTION_IOC_INIT:
2038 IOCInit_t *pInit = (IOCInit_t *) mf;
2039 u32 high_addr, sense_high;
2041 /* Verify that all entries in the IOC INIT match
2042 * existing setup (and in LE format).
2044 if (sizeof(dma_addr_t) == sizeof(u64)) {
2045 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
2046 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2052 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
2053 (pInit->MaxBuses != ioc->facts.MaxBuses) ||
2054 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
2055 (pInit->HostMfaHighAddr != high_addr) ||
2056 (pInit->SenseBufferHighAddr != sense_high)) {
2057 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2058 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2059 __FILE__, __LINE__);
2067 * MPI_FUNCTION_PORT_ENABLE
2068 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2069 * MPI_FUNCTION_TARGET_ASSIST
2070 * MPI_FUNCTION_TARGET_STATUS_SEND
2071 * MPI_FUNCTION_TARGET_MODE_ABORT
2072 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2073 * MPI_FUNCTION_IO_UNIT_RESET
2074 * MPI_FUNCTION_HANDSHAKE
2075 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2076 * MPI_FUNCTION_EVENT_NOTIFICATION
2077 * (driver handles event notification)
2078 * MPI_FUNCTION_EVENT_ACK
2081 /* What to do with these??? CHECK ME!!!
2082 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2083 MPI_FUNCTION_FC_LINK_SRVC_RSP
2084 MPI_FUNCTION_FC_ABORT
2085 MPI_FUNCTION_LAN_SEND
2086 MPI_FUNCTION_LAN_RECEIVE
2087 MPI_FUNCTION_LAN_RESET
2090 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2091 "Illegal request (function 0x%x) \n",
2092 __FILE__, __LINE__, hdr->Function);
2097 /* Add the SGL ( at most one data in SGE and one data out SGE )
2098 * In the case of two SGE's - the data out (write) will always
2099 * preceede the data in (read) SGE. psgList is used to free the
2102 psge = (char *) (((int *) mf) + karg.dataSgeOffset);
2105 /* bufIn and bufOut are used for user to kernel space transfers
2107 bufIn.kptr = bufOut.kptr = NULL;
2108 bufIn.len = bufOut.len = 0;
2110 if (karg.dataOutSize > 0)
2113 if (karg.dataInSize > 0)
2118 /* Set up the dataOut memory allocation */
2119 if (karg.dataOutSize > 0) {
2120 dir = PCI_DMA_TODEVICE;
2121 if (karg.dataInSize > 0) {
2122 flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2123 MPI_SGE_FLAGS_DIRECTION |
2125 << MPI_SGE_FLAGS_SHIFT;
2127 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
2129 flagsLength |= karg.dataOutSize;
2130 bufOut.len = karg.dataOutSize;
2131 bufOut.kptr = pci_alloc_consistent(
2132 ioc->pcidev, bufOut.len, &dma_addr_out);
2134 if (bufOut.kptr == NULL) {
2139 * Copy to MF and to sglbuf
2141 mpt_add_sge(psge, flagsLength, dma_addr_out);
2142 psge += (sizeof(u32) + sizeof(dma_addr_t));
2144 /* Copy user data to kernel space.
2146 if (copy_from_user(bufOut.kptr,
2150 "%s@%d::mptctl_do_mpt_command - Unable "
2151 "to read user data "
2153 __FILE__, __LINE__,karg.dataOutBufPtr);
2160 if (karg.dataInSize > 0) {
2161 dir = PCI_DMA_FROMDEVICE;
2162 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2163 flagsLength |= karg.dataInSize;
2165 bufIn.len = karg.dataInSize;
2166 bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
2167 bufIn.len, &dma_addr_in);
2169 if (bufIn.kptr == NULL) {
2174 * Copy to MF and to sglbuf
2176 mpt_add_sge(psge, flagsLength, dma_addr_in);
2182 mpt_add_sge(psge, flagsLength, (dma_addr_t) -1);
2185 /* The request is complete. Set the timer parameters
2186 * and issue the request.
2188 if (karg.timeout > 0) {
2189 ioc->ioctl->timer.expires = jiffies + HZ*karg.timeout;
2191 ioc->ioctl->timer.expires = jiffies + HZ*MPT_IOCTL_DEFAULT_TIMEOUT;
2194 ioc->ioctl->wait_done = 0;
2195 ioc->ioctl->status |= MPT_IOCTL_STATUS_TIMER_ACTIVE;
2196 add_timer(&ioc->ioctl->timer);
2198 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
2199 rc = mpt_send_handshake_request(mptctl_id, ioc,
2200 sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
2202 wait_event(mptctl_wait, ioc->ioctl->wait_done);
2204 mptctl_free_tm_flags(ioc);
2206 del_timer(&ioc->ioctl->timer);
2207 ioc->ioctl->status &= ~MPT_IOCTL_STATUS_TIMER_ACTIVE;
2208 ioc->ioctl->status |= MPT_IOCTL_STATUS_TM_FAILED;
2209 mpt_free_msg_frame(mptctl_id, ioc, mf);
2212 mpt_put_msg_frame(mptctl_id, ioc, mf);
2213 wait_event(mptctl_wait, ioc->ioctl->wait_done);
2219 * If command failed and failure triggered a diagnostic reset
2220 * OR a diagnostic reset happens during command processing,
2221 * no data, messaging queues are reset (mf cannot be accessed),
2222 * and status is DID_IOCRESET
2224 * If a user-requested bus reset fails to be handshaked, then
2225 * mf is returned to free queue and status is TM_FAILED.
2227 * Otherise, the command completed and the mf was freed
2228 # by ISR (mf cannot be touched).
2230 if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) {
2231 /* The timer callback deleted the
2232 * timer and reset the adapter queues.
2234 printk(KERN_WARNING "%s@%d::mptctl_do_mpt_command - "
2235 "Timeout Occurred on IOCTL! Reset IOC.\n", __FILE__, __LINE__);
2238 } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_TM_FAILED) {
2239 /* User TM request failed! mf has not been freed.
2243 /* If a valid reply frame, copy to the user.
2244 * Offset 2: reply length in U32's
2246 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) {
2247 if (karg.maxReplyBytes < ioc->reply_sz) {
2248 sz = min(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]);
2250 sz = min(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]);
2254 if (copy_to_user(karg.replyFrameBufPtr,
2255 &ioc->ioctl->ReplyFrame, sz)){
2257 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2258 "Unable to write out reply frame %p\n",
2259 __FILE__, __LINE__, karg.replyFrameBufPtr);
2266 /* If valid sense data, copy to user.
2268 if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) {
2269 sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
2271 if (copy_to_user(karg.senseDataPtr, ioc->ioctl->sense, sz)) {
2272 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2273 "Unable to write sense data to user %p\n",
2282 /* If the overall status is _GOOD and data in, copy data
2285 if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) &&
2286 (karg.dataInSize > 0) && (bufIn.kptr)) {
2288 if (copy_to_user(karg.dataInBufPtr,
2289 bufIn.kptr, karg.dataInSize)) {
2290 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2291 "Unable to write data to user %p\n",
2300 /* Clear all status bits except TMTIMER_ACTIVE, this bit is cleared
2301 * upon completion of the TM command.
2302 * ioc->ioctl->status = 0;
2304 ioc->ioctl->status &= ~(MPT_IOCTL_STATUS_TIMER_ACTIVE | MPT_IOCTL_STATUS_TM_FAILED |
2305 MPT_IOCTL_STATUS_COMMAND_GOOD | MPT_IOCTL_STATUS_SENSE_VALID |
2306 MPT_IOCTL_STATUS_RF_VALID | MPT_IOCTL_STATUS_DID_IOCRESET);
2309 mptctl_free_tm_flags(ioc);
2311 /* Free the allocated memory.
2313 if (bufOut.kptr != NULL) {
2314 pci_free_consistent(ioc->pcidev,
2315 bufOut.len, (void *) bufOut.kptr, dma_addr_out);
2318 if (bufIn.kptr != NULL) {
2319 pci_free_consistent(ioc->pcidev,
2320 bufIn.len, (void *) bufIn.kptr, dma_addr_in);
2323 /* mf is null if command issued successfully
2324 * otherwise, failure occured after mf acquired.
2327 mpt_free_msg_frame(mptctl_id, ioc, mf);
2332 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2333 /* Prototype Routine for the HP HOST INFO command.
2336 * Return: 0 if successful
2337 * -EFAULT if data unavailable
2338 * -EBUSY if previous command timout and IOC reset is not complete.
2339 * -ENODEV if no such device/adapter
2340 * -ETIME if timer expires
2341 * -ENOMEM if memory allocation error
2344 mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2346 hp_host_info_t __user *uarg = (void __user *) arg;
2348 struct pci_dev *pdev;
2351 hp_host_info_t karg;
2353 ConfigPageHeader_t hdr;
2357 dctlprintk((": mptctl_hp_hostinfo called.\n"));
2358 /* Reset long to int. Should affect IA64 and SPARC only
2360 if (data_size == sizeof(hp_host_info_t))
2362 else if (data_size == sizeof(hp_host_info_rev0_t))
2363 cim_rev = 0; /* obsolete */
2367 if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
2368 printk(KERN_ERR "%s@%d::mptctl_hp_host_info - "
2369 "Unable to read in hp_host_info struct @ %p\n",
2370 __FILE__, __LINE__, uarg);
2374 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2376 dctlprintk((KERN_ERR "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
2377 __FILE__, __LINE__, iocnum));
2381 /* Fill in the data and return the structure to the calling
2384 pdev = (struct pci_dev *) ioc->pcidev;
2386 karg.vendor = pdev->vendor;
2387 karg.device = pdev->device;
2388 karg.subsystem_id = pdev->subsystem_device;
2389 karg.subsystem_vendor = pdev->subsystem_vendor;
2390 karg.devfn = pdev->devfn;
2391 karg.bus = pdev->bus->number;
2393 /* Save the SCSI host no. if
2394 * SCSI driver loaded
2396 if (ioc->sh != NULL)
2397 karg.host_no = ioc->sh->host_no;
2401 /* Reformat the fw_version into a string
2403 karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
2404 ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
2405 karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
2406 karg.fw_version[2] = '.';
2407 karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
2408 ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
2409 karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
2410 karg.fw_version[5] = '.';
2411 karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
2412 ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
2413 karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
2414 karg.fw_version[8] = '.';
2415 karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
2416 ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
2417 karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
2418 karg.fw_version[11] = '\0';
2420 /* Issue a config request to get the device serial number
2422 hdr.PageVersion = 0;
2425 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2429 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2430 cfg.dir = 0; /* read */
2433 strncpy(karg.serial_number, " ", 24);
2434 if (mpt_config(ioc, &cfg) == 0) {
2435 if (cfg.hdr->PageLength > 0) {
2436 /* Issue the second config page request */
2437 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2439 pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
2441 cfg.physAddr = buf_dma;
2442 if (mpt_config(ioc, &cfg) == 0) {
2443 ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
2444 if (strlen(pdata->BoardTracerNumber) > 1) {
2445 strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
2446 karg.serial_number[24-1]='\0';
2449 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
2454 rc = mpt_GetIocState(ioc, 1);
2456 case MPI_IOC_STATE_OPERATIONAL:
2457 karg.ioc_status = HP_STATUS_OK;
2460 case MPI_IOC_STATE_FAULT:
2461 karg.ioc_status = HP_STATUS_FAILED;
2464 case MPI_IOC_STATE_RESET:
2465 case MPI_IOC_STATE_READY:
2467 karg.ioc_status = HP_STATUS_OTHER;
2471 karg.base_io_addr = pci_resource_start(pdev, 0);
2473 if ((int)ioc->chip_type <= (int) FC929)
2474 karg.bus_phys_width = HP_BUS_WIDTH_UNK;
2476 karg.bus_phys_width = HP_BUS_WIDTH_16;
2478 karg.hard_resets = 0;
2479 karg.soft_resets = 0;
2481 if (ioc->sh != NULL) {
2482 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
2484 if (hd && (cim_rev == 1)) {
2485 karg.hard_resets = hd->hard_resets;
2486 karg.soft_resets = hd->soft_resets;
2487 karg.timeouts = hd->timeouts;
2492 cfg.action = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
2493 cfg.dir = MPI_TB_ISTWI_FLAGS_READ;
2495 pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
2497 cfg.physAddr = buf_dma;
2498 if ((mpt_toolbox(ioc, &cfg)) == 0) {
2499 karg.rsvd = *(u32 *)pbuf;
2501 pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
2505 /* Copy the data from kernel memory to user memory
2507 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
2508 printk(KERN_ERR "%s@%d::mptctl_hpgethostinfo - "
2509 "Unable to write out hp_host_info @ %p\n",
2510 __FILE__, __LINE__, uarg);
2518 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2519 /* Prototype Routine for the HP TARGET INFO command.
2522 * Return: 0 if successful
2523 * -EFAULT if data unavailable
2524 * -EBUSY if previous command timout and IOC reset is not complete.
2525 * -ENODEV if no such device/adapter
2526 * -ETIME if timer expires
2527 * -ENOMEM if memory allocation error
2530 mptctl_hp_targetinfo(unsigned long arg)
2532 hp_target_info_t __user *uarg = (void __user *) arg;
2533 SCSIDevicePage0_t *pg0_alloc;
2534 SCSIDevicePage3_t *pg3_alloc;
2536 MPT_SCSI_HOST *hd = NULL;
2537 hp_target_info_t karg;
2540 dma_addr_t page_dma;
2542 ConfigPageHeader_t hdr;
2543 int tmp, np, rc = 0;
2545 dctlprintk((": mptctl_hp_targetinfo called.\n"));
2546 if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
2547 printk(KERN_ERR "%s@%d::mptctl_hp_targetinfo - "
2548 "Unable to read in hp_host_targetinfo struct @ %p\n",
2549 __FILE__, __LINE__, uarg);
2553 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2555 dctlprintk((KERN_ERR "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
2556 __FILE__, __LINE__, iocnum));
2560 /* There is nothing to do for FCP parts.
2562 if ((int) ioc->chip_type <= (int) FC929)
2565 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
2568 if (ioc->sh->host_no != karg.hdr.host)
2571 /* Get the data transfer speeds
2573 data_sz = ioc->spi_data.sdp0length * 4;
2574 pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2576 hdr.PageVersion = ioc->spi_data.sdp0version;
2577 hdr.PageLength = data_sz;
2579 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2582 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2585 cfg.physAddr = page_dma;
2587 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2589 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2590 np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
2591 karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
2592 HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
2594 if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
2595 tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
2597 karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
2598 else if (tmp <= 0x09)
2599 karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
2600 else if (tmp <= 0x0A)
2601 karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
2602 else if (tmp <= 0x0C)
2603 karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
2604 else if (tmp <= 0x25)
2605 karg.negotiated_speed = HP_DEV_SPEED_FAST;
2607 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2609 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2612 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
2617 karg.message_rejects = -1;
2618 karg.phase_errors = -1;
2619 karg.parity_errors = -1;
2620 karg.select_timeouts = -1;
2622 /* Get the target error parameters
2624 hdr.PageVersion = 0;
2627 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2630 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2634 if ((mpt_config(ioc, &cfg) == 0) && (cfg.hdr->PageLength > 0)) {
2635 /* Issue the second config page request */
2636 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2637 data_sz = (int) cfg.hdr->PageLength * 4;
2638 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
2639 ioc->pcidev, data_sz, &page_dma);
2641 cfg.physAddr = page_dma;
2642 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2643 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2644 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
2645 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
2646 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
2648 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
2651 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
2653 karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
2655 /* Copy the data from kernel memory to user memory
2657 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
2658 printk(KERN_ERR "%s@%d::mptctl_hp_target_info - "
2659 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2660 __FILE__, __LINE__, uarg);
2667 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2669 static struct file_operations mptctl_fops = {
2670 .owner = THIS_MODULE,
2671 .llseek = no_llseek,
2672 .ioctl = mptctl_ioctl,
2675 static struct miscdevice mptctl_miscdev = {
2681 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2683 #ifdef CONFIG_COMPAT
2685 #include <linux/ioctl32.h>
2687 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2688 /* compat_XXX functions are used to provide a conversion between
2689 * pointers and u32's. If the arg does not contain any pointers, then
2690 * a specialized function (compat_XXX) is not needed. If the arg
2691 * does contain pointer(s), then the specialized function is used
2692 * to ensure the structure contents is properly processed by mptctl.
2695 compat_mptctl_ioctl(unsigned int fd, unsigned int cmd,
2696 unsigned long arg, struct file *filp)
2701 dctlprintk((KERN_INFO MYNAM "::compat_mptctl_ioctl() called\n"));
2702 ret = mptctl_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
2708 compat_mptfwxfer_ioctl(unsigned int fd, unsigned int cmd,
2709 unsigned long arg, struct file *filp)
2711 struct mpt_fw_xfer32 kfw32;
2712 struct mpt_fw_xfer kfw;
2713 MPT_ADAPTER *iocp = NULL;
2714 int iocnum, iocnumX;
2715 int nonblock = (filp->f_flags & O_NONBLOCK);
2718 dctlprintk((KERN_INFO MYNAM "::compat_mptfwxfer_ioctl() called\n"));
2720 if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
2723 /* Verify intended MPT adapter */
2724 iocnumX = kfw32.iocnum & 0xFF;
2725 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2727 dctlprintk((KERN_ERR MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2728 __LINE__, iocnumX));
2732 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2735 kfw.iocnum = iocnum;
2736 kfw.fwlen = kfw32.fwlen;
2737 kfw.bufp = compat_ptr(kfw32.bufp);
2739 ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
2741 up(&mptctl_syscall_sem_ioc[iocp->id]);
2747 compat_mpt_command(unsigned int fd, unsigned int cmd,
2748 unsigned long arg, struct file *filp)
2750 struct mpt_ioctl_command32 karg32;
2751 struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
2752 struct mpt_ioctl_command karg;
2753 MPT_ADAPTER *iocp = NULL;
2754 int iocnum, iocnumX;
2755 int nonblock = (filp->f_flags & O_NONBLOCK);
2758 dctlprintk((KERN_INFO MYNAM "::compat_mpt_command() called\n"));
2760 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
2763 /* Verify intended MPT adapter */
2764 iocnumX = karg32.hdr.iocnum & 0xFF;
2765 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2767 dctlprintk((KERN_ERR MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
2768 __LINE__, iocnumX));
2772 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2775 /* Copy data to karg */
2776 karg.hdr.iocnum = karg32.hdr.iocnum;
2777 karg.hdr.port = karg32.hdr.port;
2778 karg.timeout = karg32.timeout;
2779 karg.maxReplyBytes = karg32.maxReplyBytes;
2781 karg.dataInSize = karg32.dataInSize;
2782 karg.dataOutSize = karg32.dataOutSize;
2783 karg.maxSenseBytes = karg32.maxSenseBytes;
2784 karg.dataSgeOffset = karg32.dataSgeOffset;
2786 karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
2787 karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
2788 karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
2789 karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
2791 /* Pass new structure to do_mpt_command
2793 ret = mptctl_do_mpt_command (karg, &uarg->MF);
2795 up(&mptctl_syscall_sem_ioc[iocp->id]);
2802 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2803 int __init mptctl_init(void)
2810 MPT_ADAPTER *ioc = NULL;
2813 show_mptmod_ver(my_NAME, my_VERSION);
2815 for (i=0; i<MPT_MAX_ADAPTERS; i++) {
2816 sema_init(&mptctl_syscall_sem_ioc[i], 1);
2819 if (((iocnum = mpt_verify_adapter(i, &ioc)) < 0) ||
2824 /* This adapter instance is found.
2825 * Allocate and inite a MPT_IOCTL structure
2827 sz = sizeof (MPT_IOCTL);
2828 mem = kmalloc(sz, GFP_KERNEL);
2835 ioc->ioctl = (MPT_IOCTL *) mem;
2836 ioc->ioctl->ioc = ioc;
2837 init_timer (&ioc->ioctl->timer);
2838 ioc->ioctl->timer.data = (unsigned long) ioc->ioctl;
2839 ioc->ioctl->timer.function = mptctl_timer_expired;
2840 init_timer (&ioc->ioctl->TMtimer);
2841 ioc->ioctl->TMtimer.data = (unsigned long) ioc->ioctl;
2842 ioc->ioctl->TMtimer.function = mptctl_timer_expired;
2846 #ifdef CONFIG_COMPAT
2847 err = register_ioctl32_conversion(MPTIOCINFO, compat_mptctl_ioctl);
2848 if (++where && err) goto out_fail;
2849 err = register_ioctl32_conversion(MPTIOCINFO1, compat_mptctl_ioctl);
2850 if (++where && err) goto out_fail;
2851 err = register_ioctl32_conversion(MPTIOCINFO2, compat_mptctl_ioctl);
2852 if (++where && err) goto out_fail;
2853 err = register_ioctl32_conversion(MPTTARGETINFO, compat_mptctl_ioctl);
2854 if (++where && err) goto out_fail;
2855 err = register_ioctl32_conversion(MPTTEST, compat_mptctl_ioctl);
2856 if (++where && err) goto out_fail;
2857 err = register_ioctl32_conversion(MPTEVENTQUERY, compat_mptctl_ioctl);
2858 if (++where && err) goto out_fail;
2859 err = register_ioctl32_conversion(MPTEVENTENABLE, compat_mptctl_ioctl);
2860 if (++where && err) goto out_fail;
2861 err = register_ioctl32_conversion(MPTEVENTREPORT, compat_mptctl_ioctl);
2862 if (++where && err) goto out_fail;
2863 err = register_ioctl32_conversion(MPTHARDRESET, compat_mptctl_ioctl);
2864 if (++where && err) goto out_fail;
2865 err = register_ioctl32_conversion(MPTCOMMAND32, compat_mpt_command);
2866 if (++where && err) goto out_fail;
2867 err = register_ioctl32_conversion(MPTFWDOWNLOAD32,
2868 compat_mptfwxfer_ioctl);
2869 if (++where && err) goto out_fail;
2870 err = register_ioctl32_conversion(HP_GETHOSTINFO, compat_mptctl_ioctl);
2871 if (++where && err) goto out_fail;
2872 err = register_ioctl32_conversion(HP_GETTARGETINFO, compat_mptctl_ioctl);
2873 if (++where && err) goto out_fail;
2876 /* Register this device */
2877 err = misc_register(&mptctl_miscdev);
2879 printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
2882 printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
2883 printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
2884 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2887 * Install our handler
2890 if ((mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER)) < 0) {
2891 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2892 misc_deregister(&mptctl_miscdev);
2897 if (mpt_reset_register(mptctl_id, mptctl_ioc_reset) == 0) {
2898 dprintk((KERN_INFO MYNAM ": Registered for IOC reset notifications\n"));
2907 #ifdef CONFIG_COMPAT
2908 printk(KERN_ERR MYNAM ": ERROR: Failed to register ioctl32_conversion!"
2909 " (%d:err=%d)\n", where, err);
2910 unregister_ioctl32_conversion(MPTIOCINFO);
2911 unregister_ioctl32_conversion(MPTIOCINFO1);
2912 unregister_ioctl32_conversion(MPTIOCINFO2);
2913 unregister_ioctl32_conversion(MPTTARGETINFO);
2914 unregister_ioctl32_conversion(MPTTEST);
2915 unregister_ioctl32_conversion(MPTEVENTQUERY);
2916 unregister_ioctl32_conversion(MPTEVENTENABLE);
2917 unregister_ioctl32_conversion(MPTEVENTREPORT);
2918 unregister_ioctl32_conversion(MPTHARDRESET);
2919 unregister_ioctl32_conversion(MPTCOMMAND32);
2920 unregister_ioctl32_conversion(MPTFWDOWNLOAD32);
2921 unregister_ioctl32_conversion(HP_GETHOSTINFO);
2922 unregister_ioctl32_conversion(HP_GETTARGETINFO);
2925 for (i=0; i<MPT_MAX_ADAPTERS; i++) {
2927 if (((iocnum = mpt_verify_adapter(i, &ioc)) < 0) ||
2933 kfree ( ioc->ioctl );
2941 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2942 void mptctl_exit(void)
2948 misc_deregister(&mptctl_miscdev);
2949 printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
2950 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2952 /* De-register reset handler from base module */
2953 mpt_reset_deregister(mptctl_id);
2954 dprintk((KERN_INFO MYNAM ": Deregistered for IOC reset notifications\n"));
2956 /* De-register callback handler from base module */
2957 mpt_deregister(mptctl_id);
2958 printk(KERN_INFO MYNAM ": Deregistered from Fusion MPT base driver\n");
2960 #ifdef CONFIG_COMPAT
2961 unregister_ioctl32_conversion(MPTIOCINFO);
2962 unregister_ioctl32_conversion(MPTIOCINFO1);
2963 unregister_ioctl32_conversion(MPTIOCINFO2);
2964 unregister_ioctl32_conversion(MPTTARGETINFO);
2965 unregister_ioctl32_conversion(MPTTEST);
2966 unregister_ioctl32_conversion(MPTEVENTQUERY);
2967 unregister_ioctl32_conversion(MPTEVENTENABLE);
2968 unregister_ioctl32_conversion(MPTEVENTREPORT);
2969 unregister_ioctl32_conversion(MPTHARDRESET);
2970 unregister_ioctl32_conversion(MPTCOMMAND32);
2971 unregister_ioctl32_conversion(MPTFWDOWNLOAD32);
2972 unregister_ioctl32_conversion(HP_GETHOSTINFO);
2973 unregister_ioctl32_conversion(HP_GETTARGETINFO);
2976 /* Free allocated memory */
2977 for (i=0; i<MPT_MAX_ADAPTERS; i++) {
2979 if (((iocnum = mpt_verify_adapter(i, &ioc)) < 0) ||
2985 kfree ( ioc->ioctl );
2992 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2994 module_init(mptctl_init);
2995 module_exit(mptctl_exit);