2 * linux/drivers/message/fusion/mptctl.c
4 * For use with LSI PCI chip/adapters
5 * running LSI Fusion MPT (Message Passing Technology) firmware.
7 * Copyright (c) 1999-2007 LSI Corporation
8 * (mailto:DL-MPTFusionLinux@lsi.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 Corporation"
70 #define MODULEAUTHOR "LSI 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 u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
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(ioc, printk(KERN_DEBUG 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(ioc, printk(KERN_DEBUG 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)
213 cmd = req->u.hdr.Function;
216 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tcompleting mpi function (0x%02X), req=%p, "
217 "reply=%p\n", ioc->name, req->u.hdr.Function, req, reply));
223 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_reply() NULL Reply "
224 "Function=%x!\n", ioc->name, cmd));
226 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
227 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
229 /* We are done, issue wake up
231 ioc->ioctl->wait_done = 1;
232 wake_up (&mptctl_wait);
237 /* Copy the reply frame (which much exist
238 * for non-SCSI I/O) to the IOC structure.
240 memcpy(ioc->ioctl->ReplyFrame, reply,
241 min(ioc->reply_sz, 4*reply->u.reply.MsgLength));
242 ioc->ioctl->status |= MPT_IOCTL_STATUS_RF_VALID;
244 /* Set the command status to GOOD if IOC Status is GOOD
245 * OR if SCSI I/O cmd and data underrun or recovered error.
247 iocStatus = le16_to_cpu(reply->u.reply.IOCStatus) & MPI_IOCSTATUS_MASK;
248 if (iocStatus == MPI_IOCSTATUS_SUCCESS)
249 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
251 if (iocStatus || reply->u.reply.IOCLogInfo)
252 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tiocstatus (0x%04X), "
253 "loginfo (0x%08X)\n", ioc->name,
255 le32_to_cpu(reply->u.reply.IOCLogInfo)));
257 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
258 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
260 if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
261 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
262 "\tscsi_status (0x%02x), scsi_state (0x%02x), "
263 "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name,
264 reply->u.sreply.SCSIStatus,
265 reply->u.sreply.SCSIState,
266 le16_to_cpu(reply->u.sreply.TaskTag),
267 le32_to_cpu(reply->u.sreply.TransferCount)));
269 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
271 if ((iocStatus == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) ||
272 (iocStatus == MPI_IOCSTATUS_SCSI_RECOVERED_ERROR)) {
273 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
277 /* Copy the sense data - if present
279 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) &&
280 (reply->u.sreply.SCSIState &
281 MPI_SCSI_STATE_AUTOSENSE_VALID)){
282 sz = req->u.scsireq.SenseBufferLength;
284 le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
286 ((u8 *)ioc->sense_buf_pool +
287 (req_index * MPT_SENSE_BUFFER_ALLOC));
288 memcpy(ioc->ioctl->sense, sense_data, sz);
289 ioc->ioctl->status |= MPT_IOCTL_STATUS_SENSE_VALID;
292 if (cmd == MPI_FUNCTION_SCSI_TASK_MGMT)
293 mptctl_free_tm_flags(ioc);
295 /* We are done, issue wake up
297 ioc->ioctl->wait_done = 1;
298 wake_up (&mptctl_wait);
303 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
304 /* mptctl_timeout_expired
306 * Expecting an interrupt, however timed out.
309 static void mptctl_timeout_expired (MPT_IOCTL *ioctl)
313 dctlprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT ": Timeout Expired! Host %d\n",
314 ioctl->ioc->name, ioctl->ioc->id));
318 ioctl->wait_done = 0;
319 if (ioctl->reset & MPTCTL_RESET_OK)
320 rc = mptctl_bus_reset(ioctl);
323 /* Issue a reset for this device.
324 * The IOC is not responding.
326 dctlprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
328 mpt_HardResetHandler(ioctl->ioc, CAN_SLEEP);
339 static int mptctl_bus_reset(MPT_IOCTL *ioctl)
342 SCSITaskMgmt_t *pScsiTm;
348 ioctl->reset &= ~MPTCTL_RESET_OK;
350 if (ioctl->ioc->sh == NULL)
353 hd = (MPT_SCSI_HOST *) ioctl->ioc->sh->hostdata;
357 /* Single threading ....
359 if (mptctl_set_tm_flags(hd) != 0)
364 if ((mf = mpt_get_msg_frame(mptctl_id, ioctl->ioc)) == NULL) {
365 dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt, no msg frames!!\n",
368 mptctl_free_tm_flags(ioctl->ioc);
372 dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt request @ %p\n",
373 ioctl->ioc->name, mf));
375 pScsiTm = (SCSITaskMgmt_t *) mf;
376 pScsiTm->TargetID = ioctl->id;
377 pScsiTm->Bus = hd->port; /* 0 */
378 pScsiTm->ChainOffset = 0;
379 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
380 pScsiTm->Reserved = 0;
381 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
382 pScsiTm->Reserved1 = 0;
383 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
385 for (ii= 0; ii < 8; ii++)
386 pScsiTm->LUN[ii] = 0;
388 for (ii=0; ii < 7; ii++)
389 pScsiTm->Reserved2[ii] = 0;
391 pScsiTm->TaskMsgContext = 0;
392 dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT
393 "mptctl_bus_reset: issued.\n", ioctl->ioc->name));
395 DBG_DUMP_TM_REQUEST_FRAME(ioctl->ioc, (u32 *)mf);
399 if ((ioctl->ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
400 (ioctl->ioc->facts.MsgVersion >= MPI_VERSION_01_05))
401 mpt_put_msg_frame_hi_pri(mptctl_id, ioctl->ioc, mf);
403 retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
404 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
406 dfailprintk(ioctl->ioc, printk(MYIOC_s_ERR_FMT "_send_handshake FAILED!"
407 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
409 goto mptctl_bus_reset_done;
413 /* Now wait for the command to complete */
414 ii = wait_event_timeout(mptctl_wait,
415 ioctl->wait_done == 1,
416 HZ*5 /* 5 second timeout */);
418 if(ii <=0 && (ioctl->wait_done != 1 )) {
419 mpt_free_msg_frame(hd->ioc, mf);
420 ioctl->wait_done = 0;
421 retval = -1; /* return failure */
424 mptctl_bus_reset_done:
426 mptctl_free_tm_flags(ioctl->ioc);
431 mptctl_set_tm_flags(MPT_SCSI_HOST *hd) {
434 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
436 if (hd->tmState == TM_STATE_NONE) {
437 hd->tmState = TM_STATE_IN_PROGRESS;
439 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
441 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
449 mptctl_free_tm_flags(MPT_ADAPTER *ioc)
454 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
458 spin_lock_irqsave(&ioc->FreeQlock, flags);
460 hd->tmState = TM_STATE_NONE;
462 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
467 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
470 * Clean-up functionality. Used only if there has been a
471 * reload of the FW due.
475 mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
477 MPT_IOCTL *ioctl = ioc->ioctl;
478 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": IOC %s_reset routed to IOCTL driver!\n",ioc->name,
479 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
480 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
485 switch(reset_phase) {
486 case MPT_IOC_SETUP_RESET:
487 ioctl->status |= MPT_IOCTL_STATUS_DID_IOCRESET;
489 case MPT_IOC_POST_RESET:
490 ioctl->status &= ~MPT_IOCTL_STATUS_DID_IOCRESET;
492 case MPT_IOC_PRE_RESET:
500 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
501 /* ASYNC Event Notification Support */
503 mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
507 event = le32_to_cpu(pEvReply->Event) & 0xFF;
509 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n",
510 ioc->name, __FUNCTION__));
511 if(async_queue == NULL)
514 /* Raise SIGIO for persistent events.
515 * TODO - this define is not in MPI spec yet,
516 * but they plan to set it to 0x21
518 if (event == 0x21 ) {
519 ioc->aen_event_read_flag=1;
520 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Raised SIGIO to application\n",
522 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
523 "Raised SIGIO to application\n", ioc->name));
524 kill_fasync(&async_queue, SIGIO, POLL_IN);
528 /* This flag is set after SIGIO was raised, and
529 * remains set until the application has read
530 * the event log via ioctl=MPTEVENTREPORT
532 if(ioc->aen_event_read_flag)
535 /* Signal only for the events that are
536 * requested for by the application
538 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
539 ioc->aen_event_read_flag=1;
540 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
541 "Raised SIGIO to application\n", ioc->name));
542 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
543 "Raised SIGIO to application\n", ioc->name));
544 kill_fasync(&async_queue, SIGIO, POLL_IN);
550 mptctl_fasync(int fd, struct file *filep, int mode)
554 list_for_each_entry(ioc, &ioc_list, list)
555 ioc->aen_event_read_flag=0;
557 return fasync_helper(fd, filep, mode, &async_queue);
561 mptctl_release(struct inode *inode, struct file *filep)
563 return fasync_helper(-1, filep, 0, &async_queue);
566 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
569 * cmd - specify the particular IOCTL command to be issued
570 * arg - data specific to the command. Must not be null.
573 __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
575 mpt_ioctl_header __user *uhdr = (void __user *) arg;
576 mpt_ioctl_header khdr;
579 int nonblock = (file->f_flags & O_NONBLOCK);
581 MPT_ADAPTER *iocp = NULL;
583 if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
584 printk(KERN_ERR "%s::mptctl_ioctl() @%d - "
585 "Unable to copy mpt_ioctl_header data @ %p\n",
586 __FILE__, __LINE__, uhdr);
589 ret = -ENXIO; /* (-6) No such device or address */
591 /* Verify intended MPT adapter - set iocnum and the adapter
594 iocnumX = khdr.iocnum & 0xFF;
595 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
597 printk(KERN_DEBUG "%s::mptctl_ioctl() @%d - ioc%d not found!\n",
598 __FILE__, __LINE__, iocnumX);
603 printk(KERN_DEBUG "%s::mptctl_ioctl() @%d - Controller disabled.\n",
608 /* Handle those commands that are just returning
609 * information stored in the driver.
610 * These commands should never time out and are unaffected
611 * by TM and FW reloads.
613 if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
614 return mptctl_getiocinfo(arg, _IOC_SIZE(cmd));
615 } else if (cmd == MPTTARGETINFO) {
616 return mptctl_gettargetinfo(arg);
617 } else if (cmd == MPTTEST) {
618 return mptctl_readtest(arg);
619 } else if (cmd == MPTEVENTQUERY) {
620 return mptctl_eventquery(arg);
621 } else if (cmd == MPTEVENTENABLE) {
622 return mptctl_eventenable(arg);
623 } else if (cmd == MPTEVENTREPORT) {
624 return mptctl_eventreport(arg);
625 } else if (cmd == MPTFWREPLACE) {
626 return mptctl_replace_fw(arg);
629 /* All of these commands require an interrupt or
630 * are unknown/illegal.
632 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
635 if (cmd == MPTFWDOWNLOAD)
636 ret = mptctl_fw_download(arg);
637 else if (cmd == MPTCOMMAND)
638 ret = mptctl_mpt_command(arg);
639 else if (cmd == MPTHARDRESET)
640 ret = mptctl_do_reset(arg);
641 else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
642 ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
643 else if (cmd == HP_GETTARGETINFO)
644 ret = mptctl_hp_targetinfo(arg);
648 mutex_unlock(&iocp->ioctl->ioctl_mutex);
654 mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
658 ret = __mptctl_ioctl(file, cmd, arg);
663 static int mptctl_do_reset(unsigned long arg)
665 struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
666 struct mpt_ioctl_diag_reset krinfo;
669 if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
670 printk(KERN_ERR "%s@%d::mptctl_do_reset - "
671 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
672 __FILE__, __LINE__, urinfo);
676 if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
677 printk(KERN_DEBUG "%s@%d::mptctl_do_reset - ioc%d not found!\n",
678 __FILE__, __LINE__, krinfo.hdr.iocnum);
679 return -ENODEV; /* (-6) No such device or address */
682 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "mptctl_do_reset called.\n",
685 if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
686 printk (KERN_ERR "%s@%d::mptctl_do_reset - reset failed.\n",
694 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
696 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
697 * This structure contains: iocnum, firmware length (bytes),
698 * pointer to user space memory where the fw image is stored.
701 * Return: 0 if successful
702 * -EFAULT if data unavailable
703 * -ENXIO if no such device
704 * -EAGAIN if resource problem
705 * -ENOMEM if no memory for SGE
706 * -EMLINK if too many chain buffers required
707 * -EBADRQC if adapter does not support FW download
708 * -EBUSY if adapter is busy
709 * -ENOMSG if FW upload returned bad status
712 mptctl_fw_download(unsigned long arg)
714 struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
715 struct mpt_fw_xfer kfwdl;
717 if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
718 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
719 "Unable to copy mpt_fw_xfer struct @ %p\n",
720 __FILE__, __LINE__, ufwdl);
724 return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
727 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
729 * FW Download engine.
731 * Return: 0 if successful
732 * -EFAULT if data unavailable
733 * -ENXIO if no such device
734 * -EAGAIN if resource problem
735 * -ENOMEM if no memory for SGE
736 * -EMLINK if too many chain buffers required
737 * -EBADRQC if adapter does not support FW download
738 * -EBUSY if adapter is busy
739 * -ENOMSG if FW upload returned bad status
742 mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen)
747 FWDownloadTCSGE_t *ptsge;
748 MptSge_t *sgl, *sgIn;
750 struct buflist *buflist;
759 int fw_bytes_copied = 0;
763 pFWDownloadReply_t ReplyMsg = NULL;
765 if (mpt_verify_adapter(ioc, &iocp) < 0) {
766 printk(KERN_DEBUG "ioctl_fwdl - ioc%d not found!\n", ioc);
767 return -ENODEV; /* (-6) No such device or address */
770 /* Valid device. Get a message frame and construct the FW download message.
772 if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
776 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT
777 "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id));
778 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.bufp = %p\n",
779 iocp->name, ufwbuf));
780 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.fwlen = %d\n",
781 iocp->name, (int)fwlen));
782 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.ioc = %04xh\n",
785 dlmsg = (FWDownload_t*) mf;
786 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
787 sgOut = (char *) (ptsge + 1);
790 * Construct f/w download request
792 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
794 dlmsg->ChainOffset = 0;
795 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
796 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
797 if (iocp->facts.MsgVersion >= MPI_VERSION_01_05)
798 dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT;
803 /* Set up the Transaction SGE.
806 ptsge->ContextSize = 0;
807 ptsge->DetailsLength = 12;
808 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
809 ptsge->Reserved_0100_Checksum = 0;
810 ptsge->ImageOffset = 0;
811 ptsge->ImageSize = cpu_to_le32(fwlen);
817 * Need to kmalloc area(s) for holding firmware image bytes.
818 * But we need to do it piece meal, using a proper
819 * scatter gather list (with 128kB MAX hunks).
821 * A practical limit here might be # of sg hunks that fit into
822 * a single IOC request frame; 12 or 8 (see below), so:
823 * For FC9xx: 12 x 128kB == 1.5 mB (max)
824 * For C1030: 8 x 128kB == 1 mB (max)
825 * We could support chaining, but things get ugly(ier:)
827 * Set the sge_offset to the start of the sgl (bytes).
829 sgdir = 0x04000000; /* IOC will READ from sys mem */
830 sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
831 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
832 &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
836 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
837 * for FC9xx f/w image, but calculate max number of sge hunks
838 * we can fit into a request frame, and limit ourselves to that.
839 * (currently no chain support)
840 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
846 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t))
847 / (sizeof(dma_addr_t) + sizeof(u32));
848 if (numfrags > maxfrags) {
853 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n",
854 iocp->name, sgl, numfrags));
857 * Parse SG list, copying sgl itself,
858 * plus f/w image hunks from user space as we go...
863 for (i=0; i < numfrags; i++) {
865 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
866 * Skip everything but Simple. If simple, copy from
867 * user space into kernel space.
868 * Note: we should not have anything but Simple as
869 * Chain SGE are illegal.
871 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
872 if (nib == 0 || nib == 3) {
874 } else if (sgIn->Address) {
875 mpt_add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
877 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
878 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
879 "Unable to copy f/w buffer hunk#%d @ %p\n",
880 __FILE__, __LINE__, n, ufwbuf);
883 fw_bytes_copied += bl->len;
887 sgOut += (sizeof(dma_addr_t) + sizeof(u32));
890 DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags);
893 * Finally, perform firmware download.
896 mpt_put_msg_frame(mptctl_id, iocp, mf);
898 /* Now wait for the command to complete */
899 ret = wait_event_timeout(mptctl_wait,
900 iocp->ioctl->wait_done == 1,
903 if(ret <=0 && (iocp->ioctl->wait_done != 1 )) {
904 /* Now we need to reset the board */
905 mptctl_timeout_expired(iocp->ioctl);
911 kfree_sgl(sgl, sgl_dma, buflist, iocp);
913 ReplyMsg = (pFWDownloadReply_t)iocp->ioctl->ReplyFrame;
914 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
915 if (iocstat == MPI_IOCSTATUS_SUCCESS) {
916 printk(KERN_INFO MYNAM ": F/W update successfully sent to %s!\n", iocp->name);
918 } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
919 printk(KERN_WARNING MYNAM ": ?Hmmm... %s says it doesn't support F/W download!?!\n",
921 printk(KERN_WARNING MYNAM ": (time to go bang on somebodies door)\n");
923 } else if (iocstat == MPI_IOCSTATUS_BUSY) {
924 printk(KERN_WARNING MYNAM ": Warning! %s says: IOC_BUSY!\n", iocp->name);
925 printk(KERN_WARNING MYNAM ": (try again later?)\n");
928 printk(KERN_WARNING MYNAM "::ioctl_fwdl() ERROR! %s returned [bad] status = %04xh\n",
929 iocp->name, iocstat);
930 printk(KERN_WARNING MYNAM ": (bad VooDoo)\n");
936 kfree_sgl(sgl, sgl_dma, buflist, iocp);
940 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
942 * SGE Allocation routine
944 * Inputs: bytes - number of bytes to be transferred
945 * sgdir - data direction
946 * sge_offset - offset (in bytes) from the start of the request
947 * frame to the first SGE
948 * ioc - pointer to the mptadapter
949 * Outputs: frags - number of scatter gather elements
950 * blp - point to the buflist pointer
951 * sglbuf_dma - pointer to the (dma) sgl
952 * Returns: Null if failes
953 * pointer to the (virtual) sgl if successful.
956 kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
957 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
959 MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
960 /* and chain buffers */
961 struct buflist *buflist = NULL; /* kernel routine */
965 int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
966 int bytes_allocd = 0;
968 dma_addr_t pa; // phys addr
970 int sg_spill = MAX_FRAGS_SPILL1;
976 /* Allocate and initialize an array of kernel
977 * structures for the SG elements.
979 i = MAX_SGL_BYTES / 8;
980 buflist = kzalloc(i, GFP_USER);
985 /* Allocate a single block of memory to store the sg elements and
986 * the chain buffers. The calling routine is responsible for
987 * copying the data in this array into the correct place in the
988 * request and chain buffers.
990 sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
994 if (sgdir & 0x04000000)
995 dir = PCI_DMA_TODEVICE;
997 dir = PCI_DMA_FROMDEVICE;
1000 * sgl = sglbuf = point to beginning of sg buffer
1001 * buflist_ent = 0 = first kernel structure
1002 * sg_spill = number of SGE that can be written before the first
1007 sg_spill = ((ioc->req_sz - sge_offset)/(sizeof(dma_addr_t) + sizeof(u32))) - 1;
1008 while (bytes_allocd < bytes) {
1009 this_alloc = min(alloc_sz, bytes-bytes_allocd);
1010 buflist[buflist_ent].len = this_alloc;
1011 buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
1014 if (buflist[buflist_ent].kptr == NULL) {
1015 alloc_sz = alloc_sz / 2;
1016 if (alloc_sz == 0) {
1017 printk(KERN_WARNING MYNAM "-SG: No can do - "
1018 "not enough memory! :-(\n");
1019 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
1025 dma_addr_t dma_addr;
1027 bytes_allocd += this_alloc;
1028 sgl->FlagsLength = (0x10000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|this_alloc);
1029 dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir);
1030 sgl->Address = dma_addr;
1038 if (bytes_allocd >= bytes)
1041 /* Need to chain? */
1042 if (fragcnt == sg_spill) {
1043 printk(KERN_WARNING MYNAM "-SG: No can do - " "Chain required! :-(\n");
1044 printk(KERN_WARNING MYNAM "(freeing %d frags)\n", numfrags);
1048 /* overflow check... */
1049 if (numfrags*8 > MAX_SGL_BYTES){
1051 printk(KERN_WARNING MYNAM "-SG: No can do - "
1052 "too many SG frags! :-(\n");
1053 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
1059 /* Last sge fixup: set LE+eol+eob bits */
1060 sgl[-1].FlagsLength |= 0xC1000000;
1065 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1066 "%d SG frags generated!\n", ioc->name, numfrags));
1068 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1069 "last (big) alloc_sz=%d\n", ioc->name, alloc_sz));
1074 if (sglbuf != NULL) {
1077 for (i = 0; i < numfrags; i++) {
1078 dma_addr_t dma_addr;
1082 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
1085 dma_addr = sglbuf[i].Address;
1086 kptr = buflist[i].kptr;
1087 len = buflist[i].len;
1089 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1091 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma);
1097 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1099 * Routine to free the SGL elements.
1102 kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
1105 struct buflist *bl = buflist;
1110 if (sg->FlagsLength & 0x04000000)
1111 dir = PCI_DMA_TODEVICE;
1113 dir = PCI_DMA_FROMDEVICE;
1115 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1116 while (! (nib & 0x4)) { /* eob */
1117 /* skip ignore/chain. */
1118 if (nib == 0 || nib == 3) {
1120 } else if (sg->Address) {
1121 dma_addr_t dma_addr;
1125 dma_addr = sg->Address;
1128 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1129 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1134 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1139 dma_addr_t dma_addr;
1143 dma_addr = sg->Address;
1146 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1147 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1151 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma);
1153 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: Free'd 1 SGL buf + %d kbufs!\n",
1157 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1159 * mptctl_getiocinfo - Query the host adapter for IOC information.
1160 * @arg: User space argument
1163 * Return: 0 if successful
1164 * -EFAULT if data unavailable
1165 * -ENODEV if no such device/adapter
1168 mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1170 struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
1171 struct mpt_ioctl_iocinfo *karg;
1173 struct pci_dev *pdev;
1178 struct scsi_device *sdev;
1181 /* Add of PCI INFO results in unaligned access for
1182 * IA64 and Sparc. Reset long to int. Return no PCI
1183 * data for obsolete format.
1185 if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
1187 else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
1189 else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
1191 else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
1192 cim_rev = 0; /* obsolete */
1196 karg = kmalloc(data_size, GFP_KERNEL);
1198 printk(KERN_ERR "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
1199 __FILE__, __LINE__);
1203 if (copy_from_user(karg, uarg, data_size)) {
1204 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1205 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1206 __FILE__, __LINE__, uarg);
1211 if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
1213 printk(KERN_DEBUG "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
1214 __FILE__, __LINE__, iocnum);
1219 /* Verify the data transfer size is correct. */
1220 if (karg->hdr.maxDataSize != data_size) {
1221 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1222 "Structure size mismatch. Command not completed.\n",
1223 __FILE__, __LINE__);
1228 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_getiocinfo called.\n",
1231 /* Fill in the data and return the structure to the calling
1234 if (ioc->bus_type == SAS)
1235 karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
1236 else if (ioc->bus_type == FC)
1237 karg->adapterType = MPT_IOCTL_INTERFACE_FC;
1239 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1241 if (karg->hdr.port > 1)
1243 port = karg->hdr.port;
1246 pdev = (struct pci_dev *) ioc->pcidev;
1248 karg->pciId = pdev->device;
1249 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1250 karg->hwRev = revision;
1251 karg->subSystemDevice = pdev->subsystem_device;
1252 karg->subSystemVendor = pdev->subsystem_vendor;
1255 /* Get the PCI bus, device, and function numbers for the IOC
1257 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1258 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1259 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1260 } else if (cim_rev == 2) {
1261 /* Get the PCI bus, device, function and segment ID numbers
1263 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1264 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1265 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1266 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
1269 /* Get number of devices
1271 karg->numDevices = 0;
1273 shost_for_each_device(sdev, ioc->sh) {
1274 vdev = sdev->hostdata;
1275 if (vdev->vtarget->tflags &
1276 MPT_TARGET_FLAGS_RAID_COMPONENT)
1282 /* Set the BIOS and FW Version
1284 karg->FWVersion = ioc->facts.FWVersion.Word;
1285 karg->BIOSVersion = ioc->biosVersion;
1287 /* Set the Version Strings.
1289 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
1290 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
1292 karg->busChangeEvent = 0;
1293 karg->hostId = ioc->pfacts[port].PortSCSIID;
1294 karg->rsvd[0] = karg->rsvd[1] = 0;
1296 /* Copy the data from kernel memory to user memory
1298 if (copy_to_user((char __user *)arg, karg, data_size)) {
1299 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1300 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1301 __FILE__, __LINE__, uarg);
1310 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1312 * mptctl_gettargetinfo - Query the host adapter for target information.
1313 * @arg: User space argument
1316 * Return: 0 if successful
1317 * -EFAULT if data unavailable
1318 * -ENODEV if no such device/adapter
1321 mptctl_gettargetinfo (unsigned long arg)
1323 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1324 struct mpt_ioctl_targetinfo karg;
1335 struct scsi_device *sdev;
1337 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
1338 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1339 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1340 __FILE__, __LINE__, uarg);
1344 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1346 printk(KERN_DEBUG "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
1347 __FILE__, __LINE__, iocnum);
1351 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_gettargetinfo called.\n",
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 = kzalloc(numBytes, GFP_KERNEL);
1383 printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1384 __FILE__, __LINE__);
1387 pdata = (int *) pmem;
1389 /* Get number of devices
1392 shost_for_each_device(sdev, ioc->sh) {
1395 vdev = sdev->hostdata;
1396 if (vdev->vtarget->tflags &
1397 MPT_TARGET_FLAGS_RAID_COMPONENT)
1399 lun = (vdev->vtarget->raidVolume) ? 0x80 : vdev->lun;
1400 *pdata = (((u8)lun << 16) + (vdev->vtarget->channel << 8) +
1401 (vdev->vtarget->id ));
1407 karg.numDevices = numDevices;
1409 /* Copy part of the data from kernel memory to user memory
1411 if (copy_to_user((char __user *)arg, &karg,
1412 sizeof(struct mpt_ioctl_targetinfo))) {
1413 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1414 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1415 __FILE__, __LINE__, uarg);
1420 /* Copy the remaining data from kernel memory to user memory
1422 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
1423 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1424 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1425 __FILE__, __LINE__, pdata);
1435 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1436 /* MPT IOCTL Test function.
1439 * Return: 0 if successful
1440 * -EFAULT if data unavailable
1441 * -ENODEV if no such device/adapter
1444 mptctl_readtest (unsigned long arg)
1446 struct mpt_ioctl_test __user *uarg = (void __user *) arg;
1447 struct mpt_ioctl_test karg;
1451 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
1452 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1453 "Unable to read in mpt_ioctl_test struct @ %p\n",
1454 __FILE__, __LINE__, uarg);
1458 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1460 printk(KERN_DEBUG "%s::mptctl_readtest() @%d - ioc%d not found!\n",
1461 __FILE__, __LINE__, iocnum);
1465 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_readtest called.\n",
1467 /* Fill in the data and return the structure to the calling
1472 karg.chip_type = ioc->mfcnt;
1474 karg.chip_type = ioc->pcidev->device;
1476 strncpy (karg.name, ioc->name, MPT_MAX_NAME);
1477 karg.name[MPT_MAX_NAME-1]='\0';
1478 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
1479 karg.product[MPT_PRODUCT_LENGTH-1]='\0';
1481 /* Copy the data from kernel memory to user memory
1483 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
1484 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1485 "Unable to write out mpt_ioctl_test struct @ %p\n",
1486 __FILE__, __LINE__, uarg);
1493 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1495 * mptctl_eventquery - Query the host adapter for the event types
1496 * that are being logged.
1497 * @arg: User space argument
1500 * Return: 0 if successful
1501 * -EFAULT if data unavailable
1502 * -ENODEV if no such device/adapter
1505 mptctl_eventquery (unsigned long arg)
1507 struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
1508 struct mpt_ioctl_eventquery karg;
1512 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
1513 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1514 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1515 __FILE__, __LINE__, uarg);
1519 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1521 printk(KERN_DEBUG "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
1522 __FILE__, __LINE__, iocnum);
1526 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventquery called.\n",
1528 karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
1529 karg.eventTypes = ioc->eventTypes;
1531 /* Copy the data from kernel memory to user memory
1533 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
1534 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1535 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1536 __FILE__, __LINE__, uarg);
1542 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1544 mptctl_eventenable (unsigned long arg)
1546 struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
1547 struct mpt_ioctl_eventenable karg;
1551 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
1552 printk(KERN_ERR "%s@%d::mptctl_eventenable - "
1553 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1554 __FILE__, __LINE__, uarg);
1558 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1560 printk(KERN_DEBUG "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
1561 __FILE__, __LINE__, iocnum);
1565 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventenable called.\n",
1567 if (ioc->events == NULL) {
1568 /* Have not yet allocated memory - do so now.
1570 int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1571 ioc->events = kzalloc(sz, GFP_KERNEL);
1573 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1576 ioc->alloc_total += sz;
1578 ioc->eventContext = 0;
1581 /* Update the IOC event logging flag.
1583 ioc->eventTypes = karg.eventTypes;
1588 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1590 mptctl_eventreport (unsigned long arg)
1592 struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
1593 struct mpt_ioctl_eventreport karg;
1596 int numBytes, maxEvents, max;
1598 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
1599 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1600 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1601 __FILE__, __LINE__, uarg);
1605 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1607 printk(KERN_DEBUG "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
1608 __FILE__, __LINE__, iocnum);
1611 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n",
1614 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1615 maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
1618 max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
1620 /* If fewer than 1 event is requested, there must have
1621 * been some type of error.
1623 if ((max < 1) || !ioc->events)
1626 /* reset this flag so SIGIO can restart */
1627 ioc->aen_event_read_flag=0;
1629 /* Copy the data from kernel memory to user memory
1631 numBytes = max * sizeof(MPT_IOCTL_EVENTS);
1632 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
1633 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1634 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1635 __FILE__, __LINE__, ioc->events);
1642 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1644 mptctl_replace_fw (unsigned long arg)
1646 struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
1647 struct mpt_ioctl_replace_fw karg;
1652 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
1653 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1654 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1655 __FILE__, __LINE__, uarg);
1659 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1661 printk(KERN_DEBUG "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
1662 __FILE__, __LINE__, iocnum);
1666 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_replace_fw called.\n",
1668 /* If caching FW, Free the old FW image
1670 if (ioc->cached_fw == NULL)
1673 mpt_free_fw_memory(ioc);
1675 /* Allocate memory for the new FW image
1677 newFwSize = karg.newImageSize;
1679 if (newFwSize & 0x01)
1681 if (newFwSize & 0x02)
1684 mpt_alloc_fw_memory(ioc, newFwSize);
1685 if (ioc->cached_fw == NULL)
1688 /* Copy the data from user memory to kernel space
1690 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
1691 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1692 "Unable to read in mpt_ioctl_replace_fw image "
1693 "@ %p\n", __FILE__, __LINE__, uarg);
1694 mpt_free_fw_memory(ioc);
1698 /* Update IOCFactsReply
1700 ioc->facts.FWImageSize = newFwSize;
1704 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1705 /* MPT IOCTL MPTCOMMAND function.
1706 * Cast the arg into the mpt_ioctl_mpt_command structure.
1709 * Return: 0 if successful
1710 * -EBUSY if previous command timout and IOC reset is not complete.
1711 * -EFAULT if data unavailable
1712 * -ENODEV if no such device/adapter
1713 * -ETIME if timer expires
1714 * -ENOMEM if memory allocation error
1717 mptctl_mpt_command (unsigned long arg)
1719 struct mpt_ioctl_command __user *uarg = (void __user *) arg;
1720 struct mpt_ioctl_command karg;
1726 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
1727 printk(KERN_ERR "%s@%d::mptctl_mpt_command - "
1728 "Unable to read in mpt_ioctl_command struct @ %p\n",
1729 __FILE__, __LINE__, uarg);
1733 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1735 printk(KERN_DEBUG "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
1736 __FILE__, __LINE__, iocnum);
1740 rc = mptctl_do_mpt_command (karg, &uarg->MF);
1745 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1746 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1749 * Return: 0 if successful
1750 * -EBUSY if previous command timout and IOC reset is not complete.
1751 * -EFAULT if data unavailable
1752 * -ENODEV if no such device/adapter
1753 * -ETIME if timer expires
1754 * -ENOMEM if memory allocation error
1755 * -EPERM if SCSI I/O and target is untagged
1758 mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1761 MPT_FRAME_HDR *mf = NULL;
1764 struct buflist bufIn; /* data In buffer */
1765 struct buflist bufOut; /* data Out buffer */
1766 dma_addr_t dma_addr_in;
1767 dma_addr_t dma_addr_out;
1768 int sgSize = 0; /* Num SG elements */
1769 int iocnum, flagsLength;
1774 struct scsi_device *sdev;
1776 bufIn.kptr = bufOut.kptr = NULL;
1778 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1780 printk(KERN_DEBUG "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
1781 __FILE__, __LINE__, iocnum);
1785 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1786 "No memory available during driver init.\n",
1787 __FILE__, __LINE__);
1789 } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) {
1790 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1791 "Busy with IOC Reset \n", __FILE__, __LINE__);
1795 /* Verify that the final request frame will not be too large.
1797 sz = karg.dataSgeOffset * 4;
1798 if (karg.dataInSize > 0)
1799 sz += sizeof(dma_addr_t) + sizeof(u32);
1800 if (karg.dataOutSize > 0)
1801 sz += sizeof(dma_addr_t) + sizeof(u32);
1803 if (sz > ioc->req_sz) {
1804 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1805 "Request frame too large (%d) maximum (%d)\n",
1806 __FILE__, __LINE__, sz, ioc->req_sz);
1810 /* Get a free request frame and save the message context.
1812 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
1815 hdr = (MPIHeader_t *) mf;
1816 msgContext = le32_to_cpu(hdr->MsgContext);
1817 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1819 /* Copy the request frame
1820 * Reset the saved message context.
1821 * Request frame in user space
1823 if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
1824 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1825 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1826 __FILE__, __LINE__, mfPtr);
1830 hdr->MsgContext = cpu_to_le32(msgContext);
1833 /* Verify that this request is allowed.
1835 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n",
1836 ioc->name, hdr->Function, mf));
1838 switch (hdr->Function) {
1839 case MPI_FUNCTION_IOC_FACTS:
1840 case MPI_FUNCTION_PORT_FACTS:
1841 karg.dataOutSize = karg.dataInSize = 0;
1844 case MPI_FUNCTION_CONFIG:
1846 Config_t *config_frame;
1847 config_frame = (Config_t *)mf;
1848 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\ttype=0x%02x ext_type=0x%02x "
1849 "number=0x%02x action=0x%02x\n", ioc->name,
1850 config_frame->Header.PageType,
1851 config_frame->ExtPageType,
1852 config_frame->Header.PageNumber,
1853 config_frame->Action));
1857 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
1858 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
1859 case MPI_FUNCTION_FW_UPLOAD:
1860 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
1861 case MPI_FUNCTION_FW_DOWNLOAD:
1862 case MPI_FUNCTION_FC_PRIMITIVE_SEND:
1863 case MPI_FUNCTION_TOOLBOX:
1864 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
1867 case MPI_FUNCTION_SCSI_IO_REQUEST:
1869 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1870 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1875 id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
1876 if (pScsiReq->TargetID > id) {
1877 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1878 "Target ID out of bounds. \n",
1879 __FILE__, __LINE__);
1884 if (pScsiReq->Bus >= ioc->number_of_buses) {
1885 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1886 "Target Bus out of bounds. \n",
1887 __FILE__, __LINE__);
1892 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1893 pScsiReq->MsgFlags |= mpt_msg_flags();
1896 /* verify that app has not requested
1897 * more sense data than driver
1898 * can provide, if so, reset this parameter
1899 * set the sense buffer pointer low address
1900 * update the control field to specify Q type
1902 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1903 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1905 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1907 pScsiReq->SenseBufferLowAddr =
1908 cpu_to_le32(ioc->sense_buf_low_dma
1909 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1911 shost_for_each_device(sdev, ioc->sh) {
1912 struct scsi_target *starget = scsi_target(sdev);
1913 VirtTarget *vtarget = starget->hostdata;
1915 if ((pScsiReq->TargetID == vtarget->id) &&
1916 (pScsiReq->Bus == vtarget->channel) &&
1917 (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1918 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1921 /* Have the IOCTL driver set the direction based
1922 * on the dataOutSize (ordering issue with Sparc).
1924 if (karg.dataOutSize > 0) {
1925 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1926 dataSize = karg.dataOutSize;
1928 scsidir = MPI_SCSIIO_CONTROL_READ;
1929 dataSize = karg.dataInSize;
1932 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1933 pScsiReq->DataLength = cpu_to_le32(dataSize);
1935 ioc->ioctl->reset = MPTCTL_RESET_OK;
1936 ioc->ioctl->id = pScsiReq->TargetID;
1939 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1940 "SCSI driver is not loaded. \n",
1941 __FILE__, __LINE__);
1947 case MPI_FUNCTION_SMP_PASSTHROUGH:
1948 /* Check mf->PassthruFlags to determine if
1949 * transfer is ImmediateMode or not.
1950 * Immediate mode returns data in the ReplyFrame.
1951 * Else, we are sending request and response data
1952 * in two SGLs at the end of the mf.
1956 case MPI_FUNCTION_SATA_PASSTHROUGH:
1958 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1959 "SCSI driver is not loaded. \n",
1960 __FILE__, __LINE__);
1966 case MPI_FUNCTION_RAID_ACTION:
1971 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1973 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1974 int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1975 int scsidir = MPI_SCSIIO_CONTROL_READ;
1978 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1979 pScsiReq->MsgFlags |= mpt_msg_flags();
1982 /* verify that app has not requested
1983 * more sense data than driver
1984 * can provide, if so, reset this parameter
1985 * set the sense buffer pointer low address
1986 * update the control field to specify Q type
1988 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1989 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1991 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1993 pScsiReq->SenseBufferLowAddr =
1994 cpu_to_le32(ioc->sense_buf_low_dma
1995 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1997 /* All commands to physical devices are tagged
2000 /* Have the IOCTL driver set the direction based
2001 * on the dataOutSize (ordering issue with Sparc).
2003 if (karg.dataOutSize > 0) {
2004 scsidir = MPI_SCSIIO_CONTROL_WRITE;
2005 dataSize = karg.dataOutSize;
2007 scsidir = MPI_SCSIIO_CONTROL_READ;
2008 dataSize = karg.dataInSize;
2011 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
2012 pScsiReq->DataLength = cpu_to_le32(dataSize);
2014 ioc->ioctl->reset = MPTCTL_RESET_OK;
2015 ioc->ioctl->id = pScsiReq->TargetID;
2017 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2018 "SCSI driver is not loaded. \n",
2019 __FILE__, __LINE__);
2025 case MPI_FUNCTION_SCSI_TASK_MGMT:
2027 MPT_SCSI_HOST *hd = NULL;
2028 if ((ioc->sh == NULL) || ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL)) {
2029 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2030 "SCSI driver not loaded or SCSI host not found. \n",
2031 __FILE__, __LINE__);
2034 } else if (mptctl_set_tm_flags(hd) != 0) {
2041 case MPI_FUNCTION_IOC_INIT:
2043 IOCInit_t *pInit = (IOCInit_t *) mf;
2044 u32 high_addr, sense_high;
2046 /* Verify that all entries in the IOC INIT match
2047 * existing setup (and in LE format).
2049 if (sizeof(dma_addr_t) == sizeof(u64)) {
2050 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
2051 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2057 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
2058 (pInit->MaxBuses != ioc->facts.MaxBuses) ||
2059 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
2060 (pInit->HostMfaHighAddr != high_addr) ||
2061 (pInit->SenseBufferHighAddr != sense_high)) {
2062 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2063 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2064 __FILE__, __LINE__);
2072 * MPI_FUNCTION_PORT_ENABLE
2073 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2074 * MPI_FUNCTION_TARGET_ASSIST
2075 * MPI_FUNCTION_TARGET_STATUS_SEND
2076 * MPI_FUNCTION_TARGET_MODE_ABORT
2077 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2078 * MPI_FUNCTION_IO_UNIT_RESET
2079 * MPI_FUNCTION_HANDSHAKE
2080 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2081 * MPI_FUNCTION_EVENT_NOTIFICATION
2082 * (driver handles event notification)
2083 * MPI_FUNCTION_EVENT_ACK
2086 /* What to do with these??? CHECK ME!!!
2087 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2088 MPI_FUNCTION_FC_LINK_SRVC_RSP
2089 MPI_FUNCTION_FC_ABORT
2090 MPI_FUNCTION_LAN_SEND
2091 MPI_FUNCTION_LAN_RECEIVE
2092 MPI_FUNCTION_LAN_RESET
2095 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2096 "Illegal request (function 0x%x) \n",
2097 __FILE__, __LINE__, hdr->Function);
2102 /* Add the SGL ( at most one data in SGE and one data out SGE )
2103 * In the case of two SGE's - the data out (write) will always
2104 * preceede the data in (read) SGE. psgList is used to free the
2107 psge = (char *) (((int *) mf) + karg.dataSgeOffset);
2110 /* bufIn and bufOut are used for user to kernel space transfers
2112 bufIn.kptr = bufOut.kptr = NULL;
2113 bufIn.len = bufOut.len = 0;
2115 if (karg.dataOutSize > 0)
2118 if (karg.dataInSize > 0)
2123 /* Set up the dataOut memory allocation */
2124 if (karg.dataOutSize > 0) {
2125 if (karg.dataInSize > 0) {
2126 flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2127 MPI_SGE_FLAGS_END_OF_BUFFER |
2128 MPI_SGE_FLAGS_DIRECTION |
2130 << MPI_SGE_FLAGS_SHIFT;
2132 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
2134 flagsLength |= karg.dataOutSize;
2135 bufOut.len = karg.dataOutSize;
2136 bufOut.kptr = pci_alloc_consistent(
2137 ioc->pcidev, bufOut.len, &dma_addr_out);
2139 if (bufOut.kptr == NULL) {
2144 * Copy to MF and to sglbuf
2146 mpt_add_sge(psge, flagsLength, dma_addr_out);
2147 psge += (sizeof(u32) + sizeof(dma_addr_t));
2149 /* Copy user data to kernel space.
2151 if (copy_from_user(bufOut.kptr,
2155 "%s@%d::mptctl_do_mpt_command - Unable "
2156 "to read user data "
2158 __FILE__, __LINE__,karg.dataOutBufPtr);
2165 if (karg.dataInSize > 0) {
2166 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2167 flagsLength |= karg.dataInSize;
2169 bufIn.len = karg.dataInSize;
2170 bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
2171 bufIn.len, &dma_addr_in);
2173 if (bufIn.kptr == NULL) {
2178 * Copy to MF and to sglbuf
2180 mpt_add_sge(psge, flagsLength, dma_addr_in);
2186 mpt_add_sge(psge, flagsLength, (dma_addr_t) -1);
2189 ioc->ioctl->wait_done = 0;
2190 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
2192 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
2194 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
2195 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
2196 mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
2198 rc =mpt_send_handshake_request(mptctl_id, ioc,
2199 sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
2201 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2202 "_send_handshake FAILED! (ioc %p, mf %p)\n",
2203 ioc->name, ioc, mf));
2204 mptctl_free_tm_flags(ioc);
2211 mpt_put_msg_frame(mptctl_id, ioc, mf);
2213 /* Now wait for the command to complete */
2214 timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
2215 timeout = wait_event_timeout(mptctl_wait,
2216 ioc->ioctl->wait_done == 1,
2219 if(timeout <=0 && (ioc->ioctl->wait_done != 1 )) {
2220 /* Now we need to reset the board */
2222 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT)
2223 mptctl_free_tm_flags(ioc);
2225 mptctl_timeout_expired(ioc->ioctl);
2232 /* If a valid reply frame, copy to the user.
2233 * Offset 2: reply length in U32's
2235 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) {
2236 if (karg.maxReplyBytes < ioc->reply_sz) {
2237 sz = min(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]);
2239 sz = min(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]);
2243 if (copy_to_user(karg.replyFrameBufPtr,
2244 &ioc->ioctl->ReplyFrame, sz)){
2246 "%s@%d::mptctl_do_mpt_command - "
2247 "Unable to write out reply frame %p\n",
2248 __FILE__, __LINE__, karg.replyFrameBufPtr);
2255 /* If valid sense data, copy to user.
2257 if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) {
2258 sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
2260 if (copy_to_user(karg.senseDataPtr, ioc->ioctl->sense, sz)) {
2261 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2262 "Unable to write sense data to user %p\n",
2271 /* If the overall status is _GOOD and data in, copy data
2274 if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) &&
2275 (karg.dataInSize > 0) && (bufIn.kptr)) {
2277 if (copy_to_user(karg.dataInBufPtr,
2278 bufIn.kptr, karg.dataInSize)) {
2279 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2280 "Unable to write data to user %p\n",
2289 ioc->ioctl->status &= ~(MPT_IOCTL_STATUS_COMMAND_GOOD |
2290 MPT_IOCTL_STATUS_SENSE_VALID |
2291 MPT_IOCTL_STATUS_RF_VALID );
2293 /* Free the allocated memory.
2295 if (bufOut.kptr != NULL) {
2296 pci_free_consistent(ioc->pcidev,
2297 bufOut.len, (void *) bufOut.kptr, dma_addr_out);
2300 if (bufIn.kptr != NULL) {
2301 pci_free_consistent(ioc->pcidev,
2302 bufIn.len, (void *) bufIn.kptr, dma_addr_in);
2305 /* mf is null if command issued successfully
2306 * otherwise, failure occured after mf acquired.
2309 mpt_free_msg_frame(ioc, mf);
2314 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2315 /* Prototype Routine for the HOST INFO command.
2318 * Return: 0 if successful
2319 * -EFAULT if data unavailable
2320 * -EBUSY if previous command timout and IOC reset is not complete.
2321 * -ENODEV if no such device/adapter
2322 * -ETIME if timer expires
2323 * -ENOMEM if memory allocation error
2326 mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2328 hp_host_info_t __user *uarg = (void __user *) arg;
2330 struct pci_dev *pdev;
2333 hp_host_info_t karg;
2335 ConfigPageHeader_t hdr;
2338 ToolboxIstwiReadWriteRequest_t *IstwiRWRequest;
2339 MPT_FRAME_HDR *mf = NULL;
2340 MPIHeader_t *mpi_hdr;
2342 /* Reset long to int. Should affect IA64 and SPARC only
2344 if (data_size == sizeof(hp_host_info_t))
2346 else if (data_size == sizeof(hp_host_info_rev0_t))
2347 cim_rev = 0; /* obsolete */
2351 if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
2352 printk(KERN_ERR "%s@%d::mptctl_hp_host_info - "
2353 "Unable to read in hp_host_info struct @ %p\n",
2354 __FILE__, __LINE__, uarg);
2358 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2360 printk(KERN_DEBUG "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
2361 __FILE__, __LINE__, iocnum);
2364 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n",
2367 /* Fill in the data and return the structure to the calling
2370 pdev = (struct pci_dev *) ioc->pcidev;
2372 karg.vendor = pdev->vendor;
2373 karg.device = pdev->device;
2374 karg.subsystem_id = pdev->subsystem_device;
2375 karg.subsystem_vendor = pdev->subsystem_vendor;
2376 karg.devfn = pdev->devfn;
2377 karg.bus = pdev->bus->number;
2379 /* Save the SCSI host no. if
2380 * SCSI driver loaded
2382 if (ioc->sh != NULL)
2383 karg.host_no = ioc->sh->host_no;
2387 /* Reformat the fw_version into a string
2389 karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
2390 ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
2391 karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
2392 karg.fw_version[2] = '.';
2393 karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
2394 ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
2395 karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
2396 karg.fw_version[5] = '.';
2397 karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
2398 ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
2399 karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
2400 karg.fw_version[8] = '.';
2401 karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
2402 ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
2403 karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
2404 karg.fw_version[11] = '\0';
2406 /* Issue a config request to get the device serial number
2408 hdr.PageVersion = 0;
2411 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2412 cfg.cfghdr.hdr = &hdr;
2415 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2416 cfg.dir = 0; /* read */
2419 strncpy(karg.serial_number, " ", 24);
2420 if (mpt_config(ioc, &cfg) == 0) {
2421 if (cfg.cfghdr.hdr->PageLength > 0) {
2422 /* Issue the second config page request */
2423 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2425 pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
2427 cfg.physAddr = buf_dma;
2428 if (mpt_config(ioc, &cfg) == 0) {
2429 ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
2430 if (strlen(pdata->BoardTracerNumber) > 1) {
2431 strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
2432 karg.serial_number[24-1]='\0';
2435 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
2440 rc = mpt_GetIocState(ioc, 1);
2442 case MPI_IOC_STATE_OPERATIONAL:
2443 karg.ioc_status = HP_STATUS_OK;
2446 case MPI_IOC_STATE_FAULT:
2447 karg.ioc_status = HP_STATUS_FAILED;
2450 case MPI_IOC_STATE_RESET:
2451 case MPI_IOC_STATE_READY:
2453 karg.ioc_status = HP_STATUS_OTHER;
2457 karg.base_io_addr = pci_resource_start(pdev, 0);
2459 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2460 karg.bus_phys_width = HP_BUS_WIDTH_UNK;
2462 karg.bus_phys_width = HP_BUS_WIDTH_16;
2464 karg.hard_resets = 0;
2465 karg.soft_resets = 0;
2467 if (ioc->sh != NULL) {
2468 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
2470 if (hd && (cim_rev == 1)) {
2471 karg.hard_resets = hd->hard_resets;
2472 karg.soft_resets = hd->soft_resets;
2473 karg.timeouts = hd->timeouts;
2478 * Gather ISTWI(Industry Standard Two Wire Interface) Data
2480 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
2481 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
2482 ioc->name,__FUNCTION__));
2486 IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
2487 mpi_hdr = (MPIHeader_t *) mf;
2488 memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
2489 IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
2490 IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
2491 IstwiRWRequest->MsgContext = mpi_hdr->MsgContext;
2492 IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
2493 IstwiRWRequest->NumAddressBytes = 0x01;
2494 IstwiRWRequest->DataLength = cpu_to_le16(0x04);
2495 if (pdev->devfn & 1)
2496 IstwiRWRequest->DeviceAddr = 0xB2;
2498 IstwiRWRequest->DeviceAddr = 0xB0;
2500 pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
2503 mpt_add_sge((char *)&IstwiRWRequest->SGL,
2504 (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
2506 ioc->ioctl->wait_done = 0;
2507 mpt_put_msg_frame(mptctl_id, ioc, mf);
2509 rc = wait_event_timeout(mptctl_wait,
2510 ioc->ioctl->wait_done == 1,
2511 HZ*MPT_IOCTL_DEFAULT_TIMEOUT /* 10 sec */);
2513 if(rc <=0 && (ioc->ioctl->wait_done != 1 )) {
2515 * Now we need to reset the board
2517 mpt_free_msg_frame(ioc, mf);
2518 mptctl_timeout_expired(ioc->ioctl);
2523 *ISTWI Data Definition
2524 * pbuf[0] = FW_VERSION = 0x4
2525 * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
2526 * the config, you should be seeing one out of these three values
2527 * pbuf[2] = Drive Installed Map = bit pattern depend on which
2528 * bays have drives in them
2529 * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
2531 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID)
2532 karg.rsvd = *(u32 *)pbuf;
2536 pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
2538 /* Copy the data from kernel memory to user memory
2540 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
2541 printk(KERN_ERR "%s@%d::mptctl_hpgethostinfo - "
2542 "Unable to write out hp_host_info @ %p\n",
2543 __FILE__, __LINE__, uarg);
2551 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2552 /* Prototype Routine for the TARGET INFO command.
2555 * Return: 0 if successful
2556 * -EFAULT if data unavailable
2557 * -EBUSY if previous command timout and IOC reset is not complete.
2558 * -ENODEV if no such device/adapter
2559 * -ETIME if timer expires
2560 * -ENOMEM if memory allocation error
2563 mptctl_hp_targetinfo(unsigned long arg)
2565 hp_target_info_t __user *uarg = (void __user *) arg;
2566 SCSIDevicePage0_t *pg0_alloc;
2567 SCSIDevicePage3_t *pg3_alloc;
2569 MPT_SCSI_HOST *hd = NULL;
2570 hp_target_info_t karg;
2573 dma_addr_t page_dma;
2575 ConfigPageHeader_t hdr;
2576 int tmp, np, rc = 0;
2578 if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
2579 printk(KERN_ERR "%s@%d::mptctl_hp_targetinfo - "
2580 "Unable to read in hp_host_targetinfo struct @ %p\n",
2581 __FILE__, __LINE__, uarg);
2585 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2587 printk(KERN_DEBUG "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
2588 __FILE__, __LINE__, iocnum);
2591 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_targetinfo called.\n",
2594 /* There is nothing to do for FCP parts.
2596 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2599 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
2602 if (ioc->sh->host_no != karg.hdr.host)
2605 /* Get the data transfer speeds
2607 data_sz = ioc->spi_data.sdp0length * 4;
2608 pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2610 hdr.PageVersion = ioc->spi_data.sdp0version;
2611 hdr.PageLength = data_sz;
2613 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2615 cfg.cfghdr.hdr = &hdr;
2616 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2619 cfg.physAddr = page_dma;
2621 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2623 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2624 np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
2625 karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
2626 HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
2628 if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
2629 tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
2631 karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
2632 else if (tmp <= 0x09)
2633 karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
2634 else if (tmp <= 0x0A)
2635 karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
2636 else if (tmp <= 0x0C)
2637 karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
2638 else if (tmp <= 0x25)
2639 karg.negotiated_speed = HP_DEV_SPEED_FAST;
2641 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2643 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2646 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
2651 karg.message_rejects = -1;
2652 karg.phase_errors = -1;
2653 karg.parity_errors = -1;
2654 karg.select_timeouts = -1;
2656 /* Get the target error parameters
2658 hdr.PageVersion = 0;
2661 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2663 cfg.cfghdr.hdr = &hdr;
2664 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2668 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2669 /* Issue the second config page request */
2670 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2671 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2672 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
2673 ioc->pcidev, data_sz, &page_dma);
2675 cfg.physAddr = page_dma;
2676 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2677 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2678 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
2679 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
2680 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
2682 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
2685 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
2687 karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
2689 /* Copy the data from kernel memory to user memory
2691 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
2692 printk(KERN_ERR "%s@%d::mptctl_hp_target_info - "
2693 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2694 __FILE__, __LINE__, uarg);
2701 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2703 static const struct file_operations mptctl_fops = {
2704 .owner = THIS_MODULE,
2705 .llseek = no_llseek,
2706 .release = mptctl_release,
2707 .fasync = mptctl_fasync,
2708 .unlocked_ioctl = mptctl_ioctl,
2709 #ifdef CONFIG_COMPAT
2710 .compat_ioctl = compat_mpctl_ioctl,
2714 static struct miscdevice mptctl_miscdev = {
2720 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2722 #ifdef CONFIG_COMPAT
2725 compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
2728 struct mpt_fw_xfer32 kfw32;
2729 struct mpt_fw_xfer kfw;
2730 MPT_ADAPTER *iocp = NULL;
2731 int iocnum, iocnumX;
2732 int nonblock = (filp->f_flags & O_NONBLOCK);
2736 if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
2739 /* Verify intended MPT adapter */
2740 iocnumX = kfw32.iocnum & 0xFF;
2741 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2743 printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2748 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2751 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mptfwxfer_ioctl() called\n",
2753 kfw.iocnum = iocnum;
2754 kfw.fwlen = kfw32.fwlen;
2755 kfw.bufp = compat_ptr(kfw32.bufp);
2757 ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
2759 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2765 compat_mpt_command(struct file *filp, unsigned int cmd,
2768 struct mpt_ioctl_command32 karg32;
2769 struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
2770 struct mpt_ioctl_command karg;
2771 MPT_ADAPTER *iocp = NULL;
2772 int iocnum, iocnumX;
2773 int nonblock = (filp->f_flags & O_NONBLOCK);
2776 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
2779 /* Verify intended MPT adapter */
2780 iocnumX = karg32.hdr.iocnum & 0xFF;
2781 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2783 printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
2788 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2791 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mpt_command() called\n",
2793 /* Copy data to karg */
2794 karg.hdr.iocnum = karg32.hdr.iocnum;
2795 karg.hdr.port = karg32.hdr.port;
2796 karg.timeout = karg32.timeout;
2797 karg.maxReplyBytes = karg32.maxReplyBytes;
2799 karg.dataInSize = karg32.dataInSize;
2800 karg.dataOutSize = karg32.dataOutSize;
2801 karg.maxSenseBytes = karg32.maxSenseBytes;
2802 karg.dataSgeOffset = karg32.dataSgeOffset;
2804 karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
2805 karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
2806 karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
2807 karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
2809 /* Pass new structure to do_mpt_command
2811 ret = mptctl_do_mpt_command (karg, &uarg->MF);
2813 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2818 static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2828 case MPTEVENTENABLE:
2829 case MPTEVENTREPORT:
2831 case HP_GETHOSTINFO:
2832 case HP_GETTARGETINFO:
2834 ret = __mptctl_ioctl(f, cmd, arg);
2837 ret = compat_mpt_command(f, cmd, arg);
2839 case MPTFWDOWNLOAD32:
2840 ret = compat_mptfwxfer_ioctl(f, cmd, arg);
2853 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2855 * mptctl_probe - Installs ioctl devices per bus.
2856 * @pdev: Pointer to pci_dev structure
2858 * Returns 0 for success, non-zero for failure.
2863 mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2866 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2869 * Allocate and inite a MPT_IOCTL structure
2871 mem = kzalloc(sizeof(MPT_IOCTL), GFP_KERNEL);
2873 mptctl_remove(pdev);
2878 ioc->ioctl->ioc = ioc;
2879 mutex_init(&ioc->ioctl->ioctl_mutex);
2883 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2885 * mptctl_remove - Removed ioctl devices
2886 * @pdev: Pointer to pci_dev structure
2891 mptctl_remove(struct pci_dev *pdev)
2893 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2895 kfree ( ioc->ioctl );
2898 static struct mpt_pci_driver mptctl_driver = {
2899 .probe = mptctl_probe,
2900 .remove = mptctl_remove,
2903 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2904 static int __init mptctl_init(void)
2909 show_mptmod_ver(my_NAME, my_VERSION);
2911 mpt_device_driver_register(&mptctl_driver, MPTCTL_DRIVER);
2913 /* Register this device */
2914 err = misc_register(&mptctl_miscdev);
2916 printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
2919 printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
2920 printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
2921 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2924 * Install our handler
2927 mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER);
2928 if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) {
2929 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2930 misc_deregister(&mptctl_miscdev);
2935 mpt_reset_register(mptctl_id, mptctl_ioc_reset);
2936 mpt_event_register(mptctl_id, mptctl_event_process);
2942 mpt_device_driver_deregister(MPTCTL_DRIVER);
2947 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2948 static void mptctl_exit(void)
2950 misc_deregister(&mptctl_miscdev);
2951 printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
2952 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2954 /* De-register reset handler from base module */
2955 mpt_reset_deregister(mptctl_id);
2957 /* De-register callback handler from base module */
2958 mpt_deregister(mptctl_id);
2960 mpt_device_driver_deregister(MPTCTL_DRIVER);
2964 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2966 module_init(mptctl_init);
2967 module_exit(mptctl_exit);