2 * linux/drivers/message/fusion/mptctl.c
4 * For use with LSI Logic PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * Copyright (c) 1999-2005 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsil.com)
11 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; version 2 of the License.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
23 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
24 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
25 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
26 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
27 solely responsible for determining the appropriateness of using and
28 distributing the Program and assumes all risks associated with its
29 exercise of rights under this Agreement, including but not limited to
30 the risks and costs of program errors, damage to or loss of data,
31 programs or equipment, and unavailability or interruption of operations.
33 DISCLAIMER OF LIABILITY
34 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
35 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
37 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
39 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
40 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, write to the Free Software
44 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
48 #include <linux/kernel.h>
49 #include <linux/module.h>
50 #include <linux/errno.h>
51 #include <linux/init.h>
52 #include <linux/slab.h>
53 #include <linux/types.h>
54 #include <linux/pci.h>
55 #include <linux/delay.h> /* for mdelay */
56 #include <linux/miscdevice.h>
57 #include <linux/smp_lock.h>
58 #include <linux/compat.h>
61 #include <asm/uaccess.h>
63 #include <scsi/scsi.h>
64 #include <scsi/scsi_cmnd.h>
65 #include <scsi/scsi_device.h>
66 #include <scsi/scsi_host.h>
67 #include <scsi/scsi_tcq.h>
69 #define COPYRIGHT "Copyright (c) 1999-2005 LSI Logic Corporation"
70 #define MODULEAUTHOR "LSI Logic Corporation"
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
75 #define my_NAME "Fusion MPT misc device (ioctl) driver"
76 #define my_VERSION MPT_LINUX_VERSION_COMMON
77 #define MYNAM "mptctl"
79 MODULE_AUTHOR(MODULEAUTHOR);
80 MODULE_DESCRIPTION(my_NAME);
81 MODULE_LICENSE("GPL");
83 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
85 static int mptctl_id = -1;
87 static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
89 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
97 * Function prototypes. Called from OS entry point mptctl_ioctl.
98 * arg contents specific to function.
100 static int mptctl_fw_download(unsigned long arg);
101 static int mptctl_getiocinfo(unsigned long arg, unsigned int cmd);
102 static int mptctl_gettargetinfo(unsigned long arg);
103 static int mptctl_readtest(unsigned long arg);
104 static int mptctl_mpt_command(unsigned long arg);
105 static int mptctl_eventquery(unsigned long arg);
106 static int mptctl_eventenable(unsigned long arg);
107 static int mptctl_eventreport(unsigned long arg);
108 static int mptctl_replace_fw(unsigned long arg);
110 static int mptctl_do_reset(unsigned long arg);
111 static int mptctl_hp_hostinfo(unsigned long arg, unsigned int cmd);
112 static int mptctl_hp_targetinfo(unsigned long arg);
114 static int mptctl_probe(struct pci_dev *, const struct pci_device_id *);
115 static void mptctl_remove(struct pci_dev *);
118 static long compat_mpctl_ioctl(struct file *f, unsigned cmd, unsigned long arg);
121 * Private function calls.
123 static int mptctl_do_mpt_command(struct mpt_ioctl_command karg, void __user *mfPtr);
124 static int mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen);
125 static MptSge_t *kbuf_alloc_2_sgl(int bytes, u32 dir, int sge_offset, int *frags,
126 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);
127 static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma,
128 struct buflist *buflist, MPT_ADAPTER *ioc);
129 static void mptctl_timeout_expired (MPT_IOCTL *ioctl);
130 static int mptctl_bus_reset(MPT_IOCTL *ioctl);
131 static int mptctl_set_tm_flags(MPT_SCSI_HOST *hd);
132 static void mptctl_free_tm_flags(MPT_ADAPTER *ioc);
135 * Reset Handler cleanup function
137 static int mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase);
139 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
141 * Scatter gather list (SGL) sizes and limits...
143 //#define MAX_SCSI_FRAGS 9
144 #define MAX_FRAGS_SPILL1 9
145 #define MAX_FRAGS_SPILL2 15
146 #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1)
148 //#define MAX_CHAIN_FRAGS 64
149 //#define MAX_CHAIN_FRAGS (15+15+15+16)
150 #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1)
152 // Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each)
153 // Works out to: 592d bytes! (9+1)*8 + 4*(15+1)*8
154 // ^----------------- 80 + 512
155 #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)
157 /* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */
158 #define MAX_KMALLOC_SZ (128*1024)
160 #define MPT_IOCTL_DEFAULT_TIMEOUT 10 /* Default timeout value (seconds) */
162 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
164 * mptctl_syscall_down - Down the MPT adapter syscall semaphore.
165 * @ioc: Pointer to MPT adapter
166 * @nonblock: boolean, non-zero if O_NONBLOCK is set
168 * All of the ioctl commands can potentially sleep, which is illegal
169 * with a spinlock held, thus we perform mutual exclusion here.
171 * Returns negative errno on error, or zero for success.
174 mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock)
177 dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down(%p,%d) called\n", ioc, nonblock));
180 if (!mutex_trylock(&ioc->ioctl->ioctl_mutex))
183 if (mutex_lock_interruptible(&ioc->ioctl->ioctl_mutex))
186 dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down return %d\n", rc));
190 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
192 * This is the callback for any message we have posted. The message itself
193 * will be returned to the message pool when we return from the IRQ
195 * This runs in irq context so be short and sweet.
198 mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
205 dctlprintk(("mptctl_reply()!\n"));
207 cmd = req->u.hdr.Function;
215 dctlprintk(("mptctl_reply() NULL Reply "
216 "Function=%x!\n", cmd));
218 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
219 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
221 /* We are done, issue wake up
223 ioc->ioctl->wait_done = 1;
224 wake_up (&mptctl_wait);
229 dctlprintk(("mptctl_reply() with req=%p "
230 "reply=%p Function=%x!\n", req, reply, cmd));
232 /* Copy the reply frame (which much exist
233 * for non-SCSI I/O) to the IOC structure.
235 dctlprintk(("Copying Reply Frame @%p to ioc%d!\n",
237 memcpy(ioc->ioctl->ReplyFrame, reply,
238 min(ioc->reply_sz, 4*reply->u.reply.MsgLength));
239 ioc->ioctl->status |= MPT_IOCTL_STATUS_RF_VALID;
241 /* Set the command status to GOOD if IOC Status is GOOD
242 * OR if SCSI I/O cmd and data underrun or recovered error.
244 iocStatus = le16_to_cpu(reply->u.reply.IOCStatus) & MPI_IOCSTATUS_MASK;
245 if (iocStatus == MPI_IOCSTATUS_SUCCESS)
246 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
248 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
249 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
250 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
252 if ((iocStatus == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) ||
253 (iocStatus == MPI_IOCSTATUS_SCSI_RECOVERED_ERROR)) {
254 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
258 /* Copy the sense data - if present
260 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) &&
261 (reply->u.sreply.SCSIState &
262 MPI_SCSI_STATE_AUTOSENSE_VALID)){
263 sz = req->u.scsireq.SenseBufferLength;
265 le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
267 ((u8 *)ioc->sense_buf_pool +
268 (req_index * MPT_SENSE_BUFFER_ALLOC));
269 memcpy(ioc->ioctl->sense, sense_data, sz);
270 ioc->ioctl->status |= MPT_IOCTL_STATUS_SENSE_VALID;
273 if (cmd == MPI_FUNCTION_SCSI_TASK_MGMT)
274 mptctl_free_tm_flags(ioc);
276 /* We are done, issue wake up
278 ioc->ioctl->wait_done = 1;
279 wake_up (&mptctl_wait);
284 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
285 /* mptctl_timeout_expired
287 * Expecting an interrupt, however timed out.
290 static void mptctl_timeout_expired (MPT_IOCTL *ioctl)
294 dctlprintk((KERN_NOTICE MYNAM ": Timeout Expired! Host %d\n",
299 ioctl->wait_done = 0;
300 if (ioctl->reset & MPTCTL_RESET_OK)
301 rc = mptctl_bus_reset(ioctl);
304 /* Issue a reset for this device.
305 * The IOC is not responding.
307 dctlprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
309 mpt_HardResetHandler(ioctl->ioc, NO_SLEEP);
320 static int mptctl_bus_reset(MPT_IOCTL *ioctl)
323 SCSITaskMgmt_t *pScsiTm;
329 ioctl->reset &= ~MPTCTL_RESET_OK;
331 if (ioctl->ioc->sh == NULL)
334 hd = (MPT_SCSI_HOST *) ioctl->ioc->sh->hostdata;
338 /* Single threading ....
340 if (mptctl_set_tm_flags(hd) != 0)
345 if ((mf = mpt_get_msg_frame(mptctl_id, ioctl->ioc)) == NULL) {
346 dctlprintk((MYIOC_s_WARN_FMT "IssueTaskMgmt, no msg frames!!\n",
349 mptctl_free_tm_flags(ioctl->ioc);
353 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
354 ioctl->ioc->name, mf));
356 pScsiTm = (SCSITaskMgmt_t *) mf;
357 pScsiTm->TargetID = ioctl->target;
358 pScsiTm->Bus = hd->port; /* 0 */
359 pScsiTm->ChainOffset = 0;
360 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
361 pScsiTm->Reserved = 0;
362 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
363 pScsiTm->Reserved1 = 0;
364 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
366 for (ii= 0; ii < 8; ii++)
367 pScsiTm->LUN[ii] = 0;
369 for (ii=0; ii < 7; ii++)
370 pScsiTm->Reserved2[ii] = 0;
372 pScsiTm->TaskMsgContext = 0;
373 dtmprintk((MYIOC_s_INFO_FMT
374 "mptctl_bus_reset: issued.\n", ioctl->ioc->name));
376 DBG_DUMP_TM_REQUEST_FRAME((u32 *)mf);
379 if ((retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
380 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP)) != 0) {
381 dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!"
382 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
384 goto mptctl_bus_reset_done;
387 /* Now wait for the command to complete */
388 ii = wait_event_interruptible_timeout(mptctl_wait,
389 ioctl->wait_done == 1,
390 HZ*5 /* 5 second timeout */);
392 if(ii <=0 && (ioctl->wait_done != 1 )) {
393 ioctl->wait_done = 0;
394 retval = -1; /* return failure */
397 mptctl_bus_reset_done:
399 mpt_free_msg_frame(hd->ioc, mf);
400 mptctl_free_tm_flags(ioctl->ioc);
405 mptctl_set_tm_flags(MPT_SCSI_HOST *hd) {
408 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
410 if (hd->tmState == TM_STATE_NONE) {
411 hd->tmState = TM_STATE_IN_PROGRESS;
413 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
415 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
423 mptctl_free_tm_flags(MPT_ADAPTER *ioc)
428 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
432 spin_lock_irqsave(&ioc->FreeQlock, flags);
434 hd->tmState = TM_STATE_NONE;
436 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
441 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
444 * Clean-up functionality. Used only if there has been a
445 * reload of the FW due.
449 mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
451 MPT_IOCTL *ioctl = ioc->ioctl;
452 dctlprintk((KERN_INFO MYNAM ": IOC %s_reset routed to IOCTL driver!\n",
453 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
454 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
459 switch(reset_phase) {
460 case MPT_IOC_SETUP_RESET:
461 ioctl->status |= MPT_IOCTL_STATUS_DID_IOCRESET;
463 case MPT_IOC_POST_RESET:
464 ioctl->status &= ~MPT_IOCTL_STATUS_DID_IOCRESET;
466 case MPT_IOC_PRE_RESET:
474 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
477 * cmd - specify the particular IOCTL command to be issued
478 * arg - data specific to the command. Must not be null.
481 __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
483 mpt_ioctl_header __user *uhdr = (void __user *) arg;
484 mpt_ioctl_header khdr;
487 int nonblock = (file->f_flags & O_NONBLOCK);
489 MPT_ADAPTER *iocp = NULL;
491 dctlprintk(("mptctl_ioctl() called\n"));
493 if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
494 printk(KERN_ERR "%s::mptctl_ioctl() @%d - "
495 "Unable to copy mpt_ioctl_header data @ %p\n",
496 __FILE__, __LINE__, uhdr);
499 ret = -ENXIO; /* (-6) No such device or address */
501 /* Verify intended MPT adapter - set iocnum and the adapter
504 iocnumX = khdr.iocnum & 0xFF;
505 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
507 dctlprintk((KERN_ERR "%s::mptctl_ioctl() @%d - ioc%d not found!\n",
508 __FILE__, __LINE__, iocnumX));
513 printk(KERN_ERR "%s::mptctl_ioctl() @%d - Controller disabled.\n",
518 /* Handle those commands that are just returning
519 * information stored in the driver.
520 * These commands should never time out and are unaffected
521 * by TM and FW reloads.
523 if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
524 return mptctl_getiocinfo(arg, _IOC_SIZE(cmd));
525 } else if (cmd == MPTTARGETINFO) {
526 return mptctl_gettargetinfo(arg);
527 } else if (cmd == MPTTEST) {
528 return mptctl_readtest(arg);
529 } else if (cmd == MPTEVENTQUERY) {
530 return mptctl_eventquery(arg);
531 } else if (cmd == MPTEVENTENABLE) {
532 return mptctl_eventenable(arg);
533 } else if (cmd == MPTEVENTREPORT) {
534 return mptctl_eventreport(arg);
535 } else if (cmd == MPTFWREPLACE) {
536 return mptctl_replace_fw(arg);
539 /* All of these commands require an interrupt or
540 * are unknown/illegal.
542 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
545 dctlprintk((MYIOC_s_INFO_FMT ": mptctl_ioctl()\n", iocp->name));
547 if (cmd == MPTFWDOWNLOAD)
548 ret = mptctl_fw_download(arg);
549 else if (cmd == MPTCOMMAND)
550 ret = mptctl_mpt_command(arg);
551 else if (cmd == MPTHARDRESET)
552 ret = mptctl_do_reset(arg);
553 else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
554 ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
555 else if (cmd == HP_GETTARGETINFO)
556 ret = mptctl_hp_targetinfo(arg);
560 mutex_unlock(&iocp->ioctl->ioctl_mutex);
566 mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
570 ret = __mptctl_ioctl(file, cmd, arg);
575 static int mptctl_do_reset(unsigned long arg)
577 struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
578 struct mpt_ioctl_diag_reset krinfo;
581 dctlprintk((KERN_INFO "mptctl_do_reset called.\n"));
583 if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
584 printk(KERN_ERR "%s@%d::mptctl_do_reset - "
585 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
586 __FILE__, __LINE__, urinfo);
590 if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
591 dctlprintk((KERN_ERR "%s@%d::mptctl_do_reset - ioc%d not found!\n",
592 __FILE__, __LINE__, krinfo.hdr.iocnum));
593 return -ENODEV; /* (-6) No such device or address */
596 if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
597 printk (KERN_ERR "%s@%d::mptctl_do_reset - reset failed.\n",
605 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
607 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
608 * This structure contains: iocnum, firmware length (bytes),
609 * pointer to user space memory where the fw image is stored.
612 * Return: 0 if successful
613 * -EFAULT if data unavailable
614 * -ENXIO if no such device
615 * -EAGAIN if resource problem
616 * -ENOMEM if no memory for SGE
617 * -EMLINK if too many chain buffers required
618 * -EBADRQC if adapter does not support FW download
619 * -EBUSY if adapter is busy
620 * -ENOMSG if FW upload returned bad status
623 mptctl_fw_download(unsigned long arg)
625 struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
626 struct mpt_fw_xfer kfwdl;
628 dctlprintk((KERN_INFO "mptctl_fwdl called. mptctl_id = %xh\n", mptctl_id)); //tc
629 if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
630 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
631 "Unable to copy mpt_fw_xfer struct @ %p\n",
632 __FILE__, __LINE__, ufwdl);
636 return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
639 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
641 * FW Download engine.
643 * Return: 0 if successful
644 * -EFAULT if data unavailable
645 * -ENXIO if no such device
646 * -EAGAIN if resource problem
647 * -ENOMEM if no memory for SGE
648 * -EMLINK if too many chain buffers required
649 * -EBADRQC if adapter does not support FW download
650 * -EBUSY if adapter is busy
651 * -ENOMSG if FW upload returned bad status
654 mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen)
659 FWDownloadTCSGE_t *ptsge;
660 MptSge_t *sgl, *sgIn;
662 struct buflist *buflist;
671 int fw_bytes_copied = 0;
675 pFWDownloadReply_t ReplyMsg = NULL;
677 dctlprintk((KERN_INFO "mptctl_do_fwdl called. mptctl_id = %xh.\n", mptctl_id));
679 dctlprintk((KERN_INFO "DbG: kfwdl.bufp = %p\n", ufwbuf));
680 dctlprintk((KERN_INFO "DbG: kfwdl.fwlen = %d\n", (int)fwlen));
681 dctlprintk((KERN_INFO "DbG: kfwdl.ioc = %04xh\n", ioc));
683 if ((ioc = mpt_verify_adapter(ioc, &iocp)) < 0) {
684 dctlprintk(("%s@%d::_ioctl_fwdl - ioc%d not found!\n",
685 __FILE__, __LINE__, ioc));
686 return -ENODEV; /* (-6) No such device or address */
689 /* Valid device. Get a message frame and construct the FW download message.
691 if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
693 dlmsg = (FWDownload_t*) mf;
694 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
695 sgOut = (char *) (ptsge + 1);
698 * Construct f/w download request
700 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
702 dlmsg->ChainOffset = 0;
703 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
704 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
707 /* Set up the Transaction SGE.
710 ptsge->ContextSize = 0;
711 ptsge->DetailsLength = 12;
712 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
713 ptsge->Reserved_0100_Checksum = 0;
714 ptsge->ImageOffset = 0;
715 ptsge->ImageSize = cpu_to_le32(fwlen);
721 * Need to kmalloc area(s) for holding firmware image bytes.
722 * But we need to do it piece meal, using a proper
723 * scatter gather list (with 128kB MAX hunks).
725 * A practical limit here might be # of sg hunks that fit into
726 * a single IOC request frame; 12 or 8 (see below), so:
727 * For FC9xx: 12 x 128kB == 1.5 mB (max)
728 * For C1030: 8 x 128kB == 1 mB (max)
729 * We could support chaining, but things get ugly(ier:)
731 * Set the sge_offset to the start of the sgl (bytes).
733 sgdir = 0x04000000; /* IOC will READ from sys mem */
734 sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
735 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
736 &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
740 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
741 * for FC9xx f/w image, but calculate max number of sge hunks
742 * we can fit into a request frame, and limit ourselves to that.
743 * (currently no chain support)
744 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
750 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t))
751 / (sizeof(dma_addr_t) + sizeof(u32));
752 if (numfrags > maxfrags) {
757 dctlprintk((KERN_INFO "DbG: sgl buffer = %p, sgfrags = %d\n", sgl, numfrags));
760 * Parse SG list, copying sgl itself,
761 * plus f/w image hunks from user space as we go...
766 for (i=0; i < numfrags; i++) {
768 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
769 * Skip everything but Simple. If simple, copy from
770 * user space into kernel space.
771 * Note: we should not have anything but Simple as
772 * Chain SGE are illegal.
774 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
775 if (nib == 0 || nib == 3) {
777 } else if (sgIn->Address) {
778 mpt_add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
780 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
781 printk(KERN_ERR "%s@%d::_ioctl_fwdl - "
782 "Unable to copy f/w buffer hunk#%d @ %p\n",
783 __FILE__, __LINE__, n, ufwbuf);
786 fw_bytes_copied += bl->len;
790 sgOut += (sizeof(dma_addr_t) + sizeof(u32));
796 printk(KERN_INFO MYNAM ": F/W download request:\n" KERN_INFO " ");
797 for (i=0; i < 7+numfrags*2; i++)
798 printk(" %08x", le32_to_cpu(m[i]));
804 * Finally, perform firmware download.
806 iocp->ioctl->wait_done = 0;
807 mpt_put_msg_frame(mptctl_id, iocp, mf);
809 /* Now wait for the command to complete */
810 ret = wait_event_interruptible_timeout(mptctl_wait,
811 iocp->ioctl->wait_done == 1,
814 if(ret <=0 && (iocp->ioctl->wait_done != 1 )) {
815 /* Now we need to reset the board */
816 mptctl_timeout_expired(iocp->ioctl);
822 kfree_sgl(sgl, sgl_dma, buflist, iocp);
824 ReplyMsg = (pFWDownloadReply_t)iocp->ioctl->ReplyFrame;
825 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
826 if (iocstat == MPI_IOCSTATUS_SUCCESS) {
827 printk(KERN_INFO MYNAM ": F/W update successfully sent to %s!\n", iocp->name);
829 } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
830 printk(KERN_WARNING MYNAM ": ?Hmmm... %s says it doesn't support F/W download!?!\n",
832 printk(KERN_WARNING MYNAM ": (time to go bang on somebodies door)\n");
834 } else if (iocstat == MPI_IOCSTATUS_BUSY) {
835 printk(KERN_WARNING MYNAM ": Warning! %s says: IOC_BUSY!\n", iocp->name);
836 printk(KERN_WARNING MYNAM ": (try again later?)\n");
839 printk(KERN_WARNING MYNAM "::ioctl_fwdl() ERROR! %s returned [bad] status = %04xh\n",
840 iocp->name, iocstat);
841 printk(KERN_WARNING MYNAM ": (bad VooDoo)\n");
847 kfree_sgl(sgl, sgl_dma, buflist, iocp);
851 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
853 * SGE Allocation routine
855 * Inputs: bytes - number of bytes to be transferred
856 * sgdir - data direction
857 * sge_offset - offset (in bytes) from the start of the request
858 * frame to the first SGE
859 * ioc - pointer to the mptadapter
860 * Outputs: frags - number of scatter gather elements
861 * blp - point to the buflist pointer
862 * sglbuf_dma - pointer to the (dma) sgl
863 * Returns: Null if failes
864 * pointer to the (virtual) sgl if successful.
867 kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
868 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
870 MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
871 /* and chain buffers */
872 struct buflist *buflist = NULL; /* kernel routine */
876 int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
877 int bytes_allocd = 0;
879 dma_addr_t pa; // phys addr
881 int sg_spill = MAX_FRAGS_SPILL1;
887 /* Allocate and initialize an array of kernel
888 * structures for the SG elements.
890 i = MAX_SGL_BYTES / 8;
891 buflist = kmalloc(i, GFP_USER);
894 memset(buflist, 0, i);
897 /* Allocate a single block of memory to store the sg elements and
898 * the chain buffers. The calling routine is responsible for
899 * copying the data in this array into the correct place in the
900 * request and chain buffers.
902 sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
906 if (sgdir & 0x04000000)
907 dir = PCI_DMA_TODEVICE;
909 dir = PCI_DMA_FROMDEVICE;
912 * sgl = sglbuf = point to beginning of sg buffer
913 * buflist_ent = 0 = first kernel structure
914 * sg_spill = number of SGE that can be written before the first
919 sg_spill = ((ioc->req_sz - sge_offset)/(sizeof(dma_addr_t) + sizeof(u32))) - 1;
920 while (bytes_allocd < bytes) {
921 this_alloc = min(alloc_sz, bytes-bytes_allocd);
922 buflist[buflist_ent].len = this_alloc;
923 buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
926 if (buflist[buflist_ent].kptr == NULL) {
927 alloc_sz = alloc_sz / 2;
929 printk(KERN_WARNING MYNAM "-SG: No can do - "
930 "not enough memory! :-(\n");
931 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
939 bytes_allocd += this_alloc;
940 sgl->FlagsLength = (0x10000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|this_alloc);
941 dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir);
942 sgl->Address = dma_addr;
950 if (bytes_allocd >= bytes)
954 if (fragcnt == sg_spill) {
955 printk(KERN_WARNING MYNAM "-SG: No can do - " "Chain required! :-(\n");
956 printk(KERN_WARNING MYNAM "(freeing %d frags)\n", numfrags);
960 /* overflow check... */
961 if (numfrags*8 > MAX_SGL_BYTES){
963 printk(KERN_WARNING MYNAM "-SG: No can do - "
964 "too many SG frags! :-(\n");
965 printk(KERN_WARNING MYNAM "-SG: (freeing %d frags)\n",
971 /* Last sge fixup: set LE+eol+eob bits */
972 sgl[-1].FlagsLength |= 0xC1000000;
977 dctlprintk((KERN_INFO MYNAM "-SG: kbuf_alloc_2_sgl() - "
978 "%d SG frags generated!\n",
981 dctlprintk((KERN_INFO MYNAM "-SG: kbuf_alloc_2_sgl() - "
982 "last (big) alloc_sz=%d\n",
988 if (sglbuf != NULL) {
991 for (i = 0; i < numfrags; i++) {
996 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
999 dma_addr = sglbuf[i].Address;
1000 kptr = buflist[i].kptr;
1001 len = buflist[i].len;
1003 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1005 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma);
1011 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1013 * Routine to free the SGL elements.
1016 kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
1019 struct buflist *bl = buflist;
1024 if (sg->FlagsLength & 0x04000000)
1025 dir = PCI_DMA_TODEVICE;
1027 dir = PCI_DMA_FROMDEVICE;
1029 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1030 while (! (nib & 0x4)) { /* eob */
1031 /* skip ignore/chain. */
1032 if (nib == 0 || nib == 3) {
1034 } else if (sg->Address) {
1035 dma_addr_t dma_addr;
1039 dma_addr = sg->Address;
1042 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1043 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1048 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1053 dma_addr_t dma_addr;
1057 dma_addr = sg->Address;
1060 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1061 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1065 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma);
1067 dctlprintk((KERN_INFO MYNAM "-SG: Free'd 1 SGL buf + %d kbufs!\n", n));
1070 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1072 * mptctl_getiocinfo - Query the host adapter for IOC information.
1073 * @arg: User space argument
1076 * Return: 0 if successful
1077 * -EFAULT if data unavailable
1078 * -ENODEV if no such device/adapter
1081 mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1083 struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
1084 struct mpt_ioctl_iocinfo *karg;
1086 struct pci_dev *pdev;
1087 struct Scsi_Host *sh;
1091 unsigned int max_id;
1097 dctlprintk((": mptctl_getiocinfo called.\n"));
1098 /* Add of PCI INFO results in unaligned access for
1099 * IA64 and Sparc. Reset long to int. Return no PCI
1100 * data for obsolete format.
1102 if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
1104 else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
1106 else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
1108 else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
1109 cim_rev = 0; /* obsolete */
1113 karg = kmalloc(data_size, GFP_KERNEL);
1115 printk(KERN_ERR "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
1116 __FILE__, __LINE__);
1120 if (copy_from_user(karg, uarg, data_size)) {
1121 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1122 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1123 __FILE__, __LINE__, uarg);
1128 if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
1130 dctlprintk((KERN_ERR "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
1131 __FILE__, __LINE__, iocnum));
1136 /* Verify the data transfer size is correct. */
1137 if (karg->hdr.maxDataSize != data_size) {
1138 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1139 "Structure size mismatch. Command not completed.\n",
1140 __FILE__, __LINE__);
1145 /* Fill in the data and return the structure to the calling
1148 if (ioc->bus_type == SAS)
1149 karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
1150 else if (ioc->bus_type == FC)
1151 karg->adapterType = MPT_IOCTL_INTERFACE_FC;
1153 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1155 if (karg->hdr.port > 1)
1157 port = karg->hdr.port;
1160 pdev = (struct pci_dev *) ioc->pcidev;
1162 karg->pciId = pdev->device;
1163 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1164 karg->hwRev = revision;
1165 karg->subSystemDevice = pdev->subsystem_device;
1166 karg->subSystemVendor = pdev->subsystem_vendor;
1169 /* Get the PCI bus, device, and function numbers for the IOC
1171 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1172 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1173 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1174 } else if (cim_rev == 2) {
1175 /* Get the PCI bus, device, function and segment ID numbers
1177 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1178 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1179 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1180 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1181 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
1184 /* Get number of devices
1186 if ((sh = ioc->sh) != NULL) {
1187 /* sh->max_id = maximum target ID + 1
1189 max_id = sh->max_id - 1;
1190 hd = (MPT_SCSI_HOST *) sh->hostdata;
1192 /* Check all of the target structures and
1195 if (hd && hd->Targets) {
1196 for (ii = 0; ii <= max_id; ii++) {
1197 if (hd->Targets[ii])
1202 karg->numDevices = numDevices;
1204 /* Set the BIOS and FW Version
1206 karg->FWVersion = ioc->facts.FWVersion.Word;
1207 karg->BIOSVersion = ioc->biosVersion;
1209 /* Set the Version Strings.
1211 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
1212 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
1214 karg->busChangeEvent = 0;
1215 karg->hostId = ioc->pfacts[port].PortSCSIID;
1216 karg->rsvd[0] = karg->rsvd[1] = 0;
1218 /* Copy the data from kernel memory to user memory
1220 if (copy_to_user((char __user *)arg, karg, data_size)) {
1221 printk(KERN_ERR "%s@%d::mptctl_getiocinfo - "
1222 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1223 __FILE__, __LINE__, uarg);
1232 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1234 * mptctl_gettargetinfo - Query the host adapter for target information.
1235 * @arg: User space argument
1238 * Return: 0 if successful
1239 * -EFAULT if data unavailable
1240 * -ENODEV if no such device/adapter
1243 mptctl_gettargetinfo (unsigned long arg)
1245 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1246 struct mpt_ioctl_targetinfo karg;
1248 struct Scsi_Host *sh;
1257 unsigned int max_id;
1258 int id, jj, indexed_lun, lun_index;
1262 u8 port, devType, bus_id;
1264 dctlprintk(("mptctl_gettargetinfo called.\n"));
1265 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
1266 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1267 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1268 __FILE__, __LINE__, uarg);
1272 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1274 dctlprintk((KERN_ERR "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
1275 __FILE__, __LINE__, iocnum));
1279 /* Get the port number and set the maximum number of bytes
1280 * in the returned structure.
1281 * Ignore the port setting.
1283 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1284 maxWordsLeft = numBytes/sizeof(int);
1285 port = karg.hdr.port;
1287 if (maxWordsLeft <= 0) {
1288 printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1289 __FILE__, __LINE__);
1293 /* Fill in the data and return the structure to the calling
1297 /* struct mpt_ioctl_targetinfo does not contain sufficient space
1298 * for the target structures so when the IOCTL is called, there is
1299 * not sufficient stack space for the structure. Allocate memory,
1300 * populate the memory, copy back to the user, then free memory.
1301 * targetInfo format:
1302 * bits 31-24: reserved
1307 pmem = kmalloc(numBytes, GFP_KERNEL);
1309 printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1310 __FILE__, __LINE__);
1313 memset(pmem, 0, numBytes);
1314 pdata = (int *) pmem;
1316 /* Get number of devices
1318 if ((sh = ioc->sh) != NULL) {
1320 max_id = sh->max_id - 1;
1321 hd = (MPT_SCSI_HOST *) sh->hostdata;
1323 /* Check all of the target structures.
1324 * Save the Id and increment the counter,
1326 * sh->max_id = maximum target ID + 1
1328 if (hd && hd->Targets) {
1329 mpt_findImVolumes(ioc);
1330 pIoc2 = ioc->raid_data.pIocPg2;
1331 for ( id = 0; id <= max_id; ) {
1332 if ( pIoc2 && pIoc2->NumActiveVolumes ) {
1333 if ( id == pIoc2->RaidVolume[0].VolumeID ) {
1334 if (maxWordsLeft <= 0) {
1335 printk(KERN_ERR "mptctl_gettargetinfo - "
1336 "buffer is full but volume is available on ioc %d\n, numDevices=%d", iocnum, numDevices);
1337 goto data_space_full;
1339 if ( ( pIoc2->RaidVolume[0].Flags & MPI_IOCPAGE2_FLAG_VOLUME_INACTIVE ) == 0 )
1343 bus_id = pIoc2->RaidVolume[0].VolumeBus;
1345 *pdata = ( (devType << 24) | (bus_id << 8) | id );
1346 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1347 "volume ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1352 pIoc3 = ioc->raid_data.pIocPg3;
1353 for ( jj = 0; jj < pIoc3->NumPhysDisks; jj++ ) {
1354 if ( pIoc3->PhysDisk[jj].PhysDiskID == id )
1359 if ( (vdev = hd->Targets[id]) ) {
1360 for (jj = 0; jj <= MPT_LAST_LUN; jj++) {
1361 lun_index = (jj >> 5);
1362 indexed_lun = (jj % 32);
1363 lun = (1 << indexed_lun);
1364 if (vdev->luns[lun_index] & lun) {
1365 if (maxWordsLeft <= 0) {
1366 printk(KERN_ERR "mptctl_gettargetinfo - "
1367 "buffer is full but more targets are available on ioc %d numDevices=%d\n", iocnum, numDevices);
1368 goto data_space_full;
1370 bus_id = vdev->bus_id;
1372 *pdata = ( (jj << 16) | (bus_id << 8) | id );
1373 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1374 "target ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1386 karg.numDevices = numDevices;
1388 /* Copy part of the data from kernel memory to user memory
1390 if (copy_to_user((char __user *)arg, &karg,
1391 sizeof(struct mpt_ioctl_targetinfo))) {
1392 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1393 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1394 __FILE__, __LINE__, uarg);
1399 /* Copy the remaining data from kernel memory to user memory
1401 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
1402 printk(KERN_ERR "%s@%d::mptctl_gettargetinfo - "
1403 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1404 __FILE__, __LINE__, pdata);
1414 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1415 /* MPT IOCTL Test function.
1418 * Return: 0 if successful
1419 * -EFAULT if data unavailable
1420 * -ENODEV if no such device/adapter
1423 mptctl_readtest (unsigned long arg)
1425 struct mpt_ioctl_test __user *uarg = (void __user *) arg;
1426 struct mpt_ioctl_test karg;
1430 dctlprintk(("mptctl_readtest called.\n"));
1431 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
1432 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1433 "Unable to read in mpt_ioctl_test struct @ %p\n",
1434 __FILE__, __LINE__, uarg);
1438 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1440 dctlprintk((KERN_ERR "%s::mptctl_readtest() @%d - ioc%d not found!\n",
1441 __FILE__, __LINE__, iocnum));
1445 /* Fill in the data and return the structure to the calling
1450 karg.chip_type = ioc->mfcnt;
1452 karg.chip_type = ioc->pcidev->device;
1454 strncpy (karg.name, ioc->name, MPT_MAX_NAME);
1455 karg.name[MPT_MAX_NAME-1]='\0';
1456 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
1457 karg.product[MPT_PRODUCT_LENGTH-1]='\0';
1459 /* Copy the data from kernel memory to user memory
1461 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
1462 printk(KERN_ERR "%s@%d::mptctl_readtest - "
1463 "Unable to write out mpt_ioctl_test struct @ %p\n",
1464 __FILE__, __LINE__, uarg);
1471 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1473 * mptctl_eventquery - Query the host adapter for the event types
1474 * that are being logged.
1475 * @arg: User space argument
1478 * Return: 0 if successful
1479 * -EFAULT if data unavailable
1480 * -ENODEV if no such device/adapter
1483 mptctl_eventquery (unsigned long arg)
1485 struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
1486 struct mpt_ioctl_eventquery karg;
1490 dctlprintk(("mptctl_eventquery called.\n"));
1491 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
1492 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1493 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1494 __FILE__, __LINE__, uarg);
1498 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1500 dctlprintk((KERN_ERR "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
1501 __FILE__, __LINE__, iocnum));
1505 karg.eventEntries = ioc->eventLogSize;
1506 karg.eventTypes = ioc->eventTypes;
1508 /* Copy the data from kernel memory to user memory
1510 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
1511 printk(KERN_ERR "%s@%d::mptctl_eventquery - "
1512 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1513 __FILE__, __LINE__, uarg);
1519 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1521 mptctl_eventenable (unsigned long arg)
1523 struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
1524 struct mpt_ioctl_eventenable karg;
1528 dctlprintk(("mptctl_eventenable called.\n"));
1529 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
1530 printk(KERN_ERR "%s@%d::mptctl_eventenable - "
1531 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1532 __FILE__, __LINE__, uarg);
1536 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1538 dctlprintk((KERN_ERR "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
1539 __FILE__, __LINE__, iocnum));
1543 if (ioc->events == NULL) {
1544 /* Have not yet allocated memory - do so now.
1546 int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1547 ioc->events = kmalloc(sz, GFP_KERNEL);
1548 if (ioc->events == NULL) {
1549 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1552 memset(ioc->events, 0, sz);
1553 ioc->alloc_total += sz;
1555 ioc->eventLogSize = MPTCTL_EVENT_LOG_SIZE;
1556 ioc->eventContext = 0;
1559 /* Update the IOC event logging flag.
1561 ioc->eventTypes = karg.eventTypes;
1566 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1568 mptctl_eventreport (unsigned long arg)
1570 struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
1571 struct mpt_ioctl_eventreport karg;
1574 int numBytes, maxEvents, max;
1576 dctlprintk(("mptctl_eventreport called.\n"));
1577 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
1578 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1579 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1580 __FILE__, __LINE__, uarg);
1584 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1586 dctlprintk((KERN_ERR "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
1587 __FILE__, __LINE__, iocnum));
1591 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1592 maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
1595 max = ioc->eventLogSize < maxEvents ? ioc->eventLogSize : maxEvents;
1597 /* If fewer than 1 event is requested, there must have
1598 * been some type of error.
1600 if ((max < 1) || !ioc->events)
1603 /* Copy the data from kernel memory to user memory
1605 numBytes = max * sizeof(MPT_IOCTL_EVENTS);
1606 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
1607 printk(KERN_ERR "%s@%d::mptctl_eventreport - "
1608 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1609 __FILE__, __LINE__, ioc->events);
1616 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1618 mptctl_replace_fw (unsigned long arg)
1620 struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
1621 struct mpt_ioctl_replace_fw karg;
1626 dctlprintk(("mptctl_replace_fw called.\n"));
1627 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
1628 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1629 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1630 __FILE__, __LINE__, uarg);
1634 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1636 dctlprintk((KERN_ERR "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
1637 __FILE__, __LINE__, iocnum));
1641 /* If caching FW, Free the old FW image
1643 if (ioc->cached_fw == NULL)
1646 mpt_free_fw_memory(ioc);
1648 /* Allocate memory for the new FW image
1650 newFwSize = karg.newImageSize;
1652 if (newFwSize & 0x01)
1654 if (newFwSize & 0x02)
1657 mpt_alloc_fw_memory(ioc, newFwSize);
1658 if (ioc->cached_fw == NULL)
1661 /* Copy the data from user memory to kernel space
1663 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
1664 printk(KERN_ERR "%s@%d::mptctl_replace_fw - "
1665 "Unable to read in mpt_ioctl_replace_fw image "
1666 "@ %p\n", __FILE__, __LINE__, uarg);
1667 mpt_free_fw_memory(ioc);
1671 /* Update IOCFactsReply
1673 ioc->facts.FWImageSize = newFwSize;
1677 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1678 /* MPT IOCTL MPTCOMMAND function.
1679 * Cast the arg into the mpt_ioctl_mpt_command structure.
1682 * Return: 0 if successful
1683 * -EBUSY if previous command timout and IOC reset is not complete.
1684 * -EFAULT if data unavailable
1685 * -ENODEV if no such device/adapter
1686 * -ETIME if timer expires
1687 * -ENOMEM if memory allocation error
1690 mptctl_mpt_command (unsigned long arg)
1692 struct mpt_ioctl_command __user *uarg = (void __user *) arg;
1693 struct mpt_ioctl_command karg;
1698 dctlprintk(("mptctl_command called.\n"));
1700 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
1701 printk(KERN_ERR "%s@%d::mptctl_mpt_command - "
1702 "Unable to read in mpt_ioctl_command struct @ %p\n",
1703 __FILE__, __LINE__, uarg);
1707 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1709 dctlprintk((KERN_ERR "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
1710 __FILE__, __LINE__, iocnum));
1714 rc = mptctl_do_mpt_command (karg, &uarg->MF);
1719 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1720 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1723 * Return: 0 if successful
1724 * -EBUSY if previous command timout and IOC reset is not complete.
1725 * -EFAULT if data unavailable
1726 * -ENODEV if no such device/adapter
1727 * -ETIME if timer expires
1728 * -ENOMEM if memory allocation error
1729 * -EPERM if SCSI I/O and target is untagged
1732 mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1735 MPT_FRAME_HDR *mf = NULL;
1738 struct buflist bufIn; /* data In buffer */
1739 struct buflist bufOut; /* data Out buffer */
1740 dma_addr_t dma_addr_in;
1741 dma_addr_t dma_addr_out;
1742 int sgSize = 0; /* Num SG elements */
1743 int iocnum, flagsLength;
1749 dctlprintk(("mptctl_do_mpt_command called.\n"));
1750 bufIn.kptr = bufOut.kptr = NULL;
1752 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1754 dctlprintk((KERN_ERR "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
1755 __FILE__, __LINE__, iocnum));
1759 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1760 "No memory available during driver init.\n",
1761 __FILE__, __LINE__);
1763 } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) {
1764 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1765 "Busy with IOC Reset \n", __FILE__, __LINE__);
1769 /* Verify that the final request frame will not be too large.
1771 sz = karg.dataSgeOffset * 4;
1772 if (karg.dataInSize > 0)
1773 sz += sizeof(dma_addr_t) + sizeof(u32);
1774 if (karg.dataOutSize > 0)
1775 sz += sizeof(dma_addr_t) + sizeof(u32);
1777 if (sz > ioc->req_sz) {
1778 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1779 "Request frame too large (%d) maximum (%d)\n",
1780 __FILE__, __LINE__, sz, ioc->req_sz);
1784 /* Get a free request frame and save the message context.
1786 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
1789 hdr = (MPIHeader_t *) mf;
1790 msgContext = le32_to_cpu(hdr->MsgContext);
1791 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1793 /* Copy the request frame
1794 * Reset the saved message context.
1795 * Request frame in user space
1797 if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
1798 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1799 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1800 __FILE__, __LINE__, mfPtr);
1804 hdr->MsgContext = cpu_to_le32(msgContext);
1807 /* Verify that this request is allowed.
1809 switch (hdr->Function) {
1810 case MPI_FUNCTION_IOC_FACTS:
1811 case MPI_FUNCTION_PORT_FACTS:
1812 karg.dataOutSize = karg.dataInSize = 0;
1815 case MPI_FUNCTION_CONFIG:
1816 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
1817 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
1818 case MPI_FUNCTION_FW_UPLOAD:
1819 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
1820 case MPI_FUNCTION_FW_DOWNLOAD:
1821 case MPI_FUNCTION_FC_PRIMITIVE_SEND:
1822 case MPI_FUNCTION_TOOLBOX:
1823 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
1826 case MPI_FUNCTION_SCSI_IO_REQUEST:
1828 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1829 VirtTarget *pTarget = NULL;
1830 MPT_SCSI_HOST *hd = NULL;
1831 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1833 int target = (int) pScsiReq->TargetID;
1836 if ((target < 0) || (target >= ioc->sh->max_id)) {
1837 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1838 "Target ID out of bounds. \n",
1839 __FILE__, __LINE__);
1844 pScsiReq->MsgFlags = mpt_msg_flags();
1846 /* verify that app has not requested
1847 * more sense data than driver
1848 * can provide, if so, reset this parameter
1849 * set the sense buffer pointer low address
1850 * update the control field to specify Q type
1852 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1853 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1855 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1857 pScsiReq->SenseBufferLowAddr =
1858 cpu_to_le32(ioc->sense_buf_low_dma
1859 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1861 if ((hd = (MPT_SCSI_HOST *) ioc->sh->hostdata)) {
1863 pTarget = hd->Targets[target];
1866 if (pTarget &&(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1867 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1869 /* Have the IOCTL driver set the direction based
1870 * on the dataOutSize (ordering issue with Sparc).
1872 if (karg.dataOutSize > 0) {
1873 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1874 dataSize = karg.dataOutSize;
1876 scsidir = MPI_SCSIIO_CONTROL_READ;
1877 dataSize = karg.dataInSize;
1880 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1881 pScsiReq->DataLength = cpu_to_le32(dataSize);
1883 ioc->ioctl->reset = MPTCTL_RESET_OK;
1884 ioc->ioctl->target = target;
1887 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1888 "SCSI driver is not loaded. \n",
1889 __FILE__, __LINE__);
1895 case MPI_FUNCTION_SMP_PASSTHROUGH:
1896 /* Check mf->PassthruFlags to determine if
1897 * transfer is ImmediateMode or not.
1898 * Immediate mode returns data in the ReplyFrame.
1899 * Else, we are sending request and response data
1900 * in two SGLs at the end of the mf.
1904 case MPI_FUNCTION_SATA_PASSTHROUGH:
1906 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1907 "SCSI driver is not loaded. \n",
1908 __FILE__, __LINE__);
1914 case MPI_FUNCTION_RAID_ACTION:
1919 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1921 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1922 int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1923 int scsidir = MPI_SCSIIO_CONTROL_READ;
1926 pScsiReq->MsgFlags = mpt_msg_flags();
1928 /* verify that app has not requested
1929 * more sense data than driver
1930 * can provide, if so, reset this parameter
1931 * set the sense buffer pointer low address
1932 * update the control field to specify Q type
1934 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1935 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1937 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1939 pScsiReq->SenseBufferLowAddr =
1940 cpu_to_le32(ioc->sense_buf_low_dma
1941 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1943 /* All commands to physical devices are tagged
1946 /* Have the IOCTL driver set the direction based
1947 * on the dataOutSize (ordering issue with Sparc).
1949 if (karg.dataOutSize > 0) {
1950 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1951 dataSize = karg.dataOutSize;
1953 scsidir = MPI_SCSIIO_CONTROL_READ;
1954 dataSize = karg.dataInSize;
1957 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1958 pScsiReq->DataLength = cpu_to_le32(dataSize);
1960 ioc->ioctl->reset = MPTCTL_RESET_OK;
1961 ioc->ioctl->target = pScsiReq->TargetID;
1963 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1964 "SCSI driver is not loaded. \n",
1965 __FILE__, __LINE__);
1971 case MPI_FUNCTION_SCSI_TASK_MGMT:
1973 MPT_SCSI_HOST *hd = NULL;
1974 if ((ioc->sh == NULL) || ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL)) {
1975 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1976 "SCSI driver not loaded or SCSI host not found. \n",
1977 __FILE__, __LINE__);
1980 } else if (mptctl_set_tm_flags(hd) != 0) {
1987 case MPI_FUNCTION_IOC_INIT:
1989 IOCInit_t *pInit = (IOCInit_t *) mf;
1990 u32 high_addr, sense_high;
1992 /* Verify that all entries in the IOC INIT match
1993 * existing setup (and in LE format).
1995 if (sizeof(dma_addr_t) == sizeof(u64)) {
1996 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
1997 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2003 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
2004 (pInit->MaxBuses != ioc->facts.MaxBuses) ||
2005 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
2006 (pInit->HostMfaHighAddr != high_addr) ||
2007 (pInit->SenseBufferHighAddr != sense_high)) {
2008 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2009 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2010 __FILE__, __LINE__);
2018 * MPI_FUNCTION_PORT_ENABLE
2019 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2020 * MPI_FUNCTION_TARGET_ASSIST
2021 * MPI_FUNCTION_TARGET_STATUS_SEND
2022 * MPI_FUNCTION_TARGET_MODE_ABORT
2023 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2024 * MPI_FUNCTION_IO_UNIT_RESET
2025 * MPI_FUNCTION_HANDSHAKE
2026 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2027 * MPI_FUNCTION_EVENT_NOTIFICATION
2028 * (driver handles event notification)
2029 * MPI_FUNCTION_EVENT_ACK
2032 /* What to do with these??? CHECK ME!!!
2033 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2034 MPI_FUNCTION_FC_LINK_SRVC_RSP
2035 MPI_FUNCTION_FC_ABORT
2036 MPI_FUNCTION_LAN_SEND
2037 MPI_FUNCTION_LAN_RECEIVE
2038 MPI_FUNCTION_LAN_RESET
2041 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2042 "Illegal request (function 0x%x) \n",
2043 __FILE__, __LINE__, hdr->Function);
2048 /* Add the SGL ( at most one data in SGE and one data out SGE )
2049 * In the case of two SGE's - the data out (write) will always
2050 * preceede the data in (read) SGE. psgList is used to free the
2053 psge = (char *) (((int *) mf) + karg.dataSgeOffset);
2056 /* bufIn and bufOut are used for user to kernel space transfers
2058 bufIn.kptr = bufOut.kptr = NULL;
2059 bufIn.len = bufOut.len = 0;
2061 if (karg.dataOutSize > 0)
2064 if (karg.dataInSize > 0)
2069 /* Set up the dataOut memory allocation */
2070 if (karg.dataOutSize > 0) {
2071 if (karg.dataInSize > 0) {
2072 flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2073 MPI_SGE_FLAGS_END_OF_BUFFER |
2074 MPI_SGE_FLAGS_DIRECTION |
2076 << MPI_SGE_FLAGS_SHIFT;
2078 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
2080 flagsLength |= karg.dataOutSize;
2081 bufOut.len = karg.dataOutSize;
2082 bufOut.kptr = pci_alloc_consistent(
2083 ioc->pcidev, bufOut.len, &dma_addr_out);
2085 if (bufOut.kptr == NULL) {
2090 * Copy to MF and to sglbuf
2092 mpt_add_sge(psge, flagsLength, dma_addr_out);
2093 psge += (sizeof(u32) + sizeof(dma_addr_t));
2095 /* Copy user data to kernel space.
2097 if (copy_from_user(bufOut.kptr,
2101 "%s@%d::mptctl_do_mpt_command - Unable "
2102 "to read user data "
2104 __FILE__, __LINE__,karg.dataOutBufPtr);
2111 if (karg.dataInSize > 0) {
2112 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2113 flagsLength |= karg.dataInSize;
2115 bufIn.len = karg.dataInSize;
2116 bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
2117 bufIn.len, &dma_addr_in);
2119 if (bufIn.kptr == NULL) {
2124 * Copy to MF and to sglbuf
2126 mpt_add_sge(psge, flagsLength, dma_addr_in);
2132 mpt_add_sge(psge, flagsLength, (dma_addr_t) -1);
2135 ioc->ioctl->wait_done = 0;
2136 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
2138 DBG_DUMP_TM_REQUEST_FRAME((u32 *)mf);
2140 if (mpt_send_handshake_request(mptctl_id, ioc,
2141 sizeof(SCSITaskMgmt_t), (u32*)mf,
2143 dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!"
2144 " (ioc %p, mf %p) \n", ioc->name,
2146 mptctl_free_tm_flags(ioc);
2152 mpt_put_msg_frame(mptctl_id, ioc, mf);
2154 /* Now wait for the command to complete */
2155 timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
2156 timeout = wait_event_interruptible_timeout(mptctl_wait,
2157 ioc->ioctl->wait_done == 1,
2160 if(timeout <=0 && (ioc->ioctl->wait_done != 1 )) {
2161 /* Now we need to reset the board */
2163 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT)
2164 mptctl_free_tm_flags(ioc);
2166 mptctl_timeout_expired(ioc->ioctl);
2173 /* If a valid reply frame, copy to the user.
2174 * Offset 2: reply length in U32's
2176 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) {
2177 if (karg.maxReplyBytes < ioc->reply_sz) {
2178 sz = min(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]);
2180 sz = min(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]);
2184 if (copy_to_user(karg.replyFrameBufPtr,
2185 &ioc->ioctl->ReplyFrame, sz)){
2187 "%s@%d::mptctl_do_mpt_command - "
2188 "Unable to write out reply frame %p\n",
2189 __FILE__, __LINE__, karg.replyFrameBufPtr);
2196 /* If valid sense data, copy to user.
2198 if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) {
2199 sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
2201 if (copy_to_user(karg.senseDataPtr, ioc->ioctl->sense, sz)) {
2202 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2203 "Unable to write sense data to user %p\n",
2212 /* If the overall status is _GOOD and data in, copy data
2215 if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) &&
2216 (karg.dataInSize > 0) && (bufIn.kptr)) {
2218 if (copy_to_user(karg.dataInBufPtr,
2219 bufIn.kptr, karg.dataInSize)) {
2220 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2221 "Unable to write data to user %p\n",
2230 ioc->ioctl->status &= ~(MPT_IOCTL_STATUS_COMMAND_GOOD |
2231 MPT_IOCTL_STATUS_SENSE_VALID |
2232 MPT_IOCTL_STATUS_RF_VALID );
2234 /* Free the allocated memory.
2236 if (bufOut.kptr != NULL) {
2237 pci_free_consistent(ioc->pcidev,
2238 bufOut.len, (void *) bufOut.kptr, dma_addr_out);
2241 if (bufIn.kptr != NULL) {
2242 pci_free_consistent(ioc->pcidev,
2243 bufIn.len, (void *) bufIn.kptr, dma_addr_in);
2246 /* mf is null if command issued successfully
2247 * otherwise, failure occured after mf acquired.
2250 mpt_free_msg_frame(ioc, mf);
2255 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2256 /* Prototype Routine for the HP HOST INFO command.
2259 * Return: 0 if successful
2260 * -EFAULT if data unavailable
2261 * -EBUSY if previous command timout and IOC reset is not complete.
2262 * -ENODEV if no such device/adapter
2263 * -ETIME if timer expires
2264 * -ENOMEM if memory allocation error
2267 mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2269 hp_host_info_t __user *uarg = (void __user *) arg;
2271 struct pci_dev *pdev;
2274 hp_host_info_t karg;
2276 ConfigPageHeader_t hdr;
2280 dctlprintk((": mptctl_hp_hostinfo called.\n"));
2281 /* Reset long to int. Should affect IA64 and SPARC only
2283 if (data_size == sizeof(hp_host_info_t))
2285 else if (data_size == sizeof(hp_host_info_rev0_t))
2286 cim_rev = 0; /* obsolete */
2290 if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
2291 printk(KERN_ERR "%s@%d::mptctl_hp_host_info - "
2292 "Unable to read in hp_host_info struct @ %p\n",
2293 __FILE__, __LINE__, uarg);
2297 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2299 dctlprintk((KERN_ERR "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
2300 __FILE__, __LINE__, iocnum));
2304 /* Fill in the data and return the structure to the calling
2307 pdev = (struct pci_dev *) ioc->pcidev;
2309 karg.vendor = pdev->vendor;
2310 karg.device = pdev->device;
2311 karg.subsystem_id = pdev->subsystem_device;
2312 karg.subsystem_vendor = pdev->subsystem_vendor;
2313 karg.devfn = pdev->devfn;
2314 karg.bus = pdev->bus->number;
2316 /* Save the SCSI host no. if
2317 * SCSI driver loaded
2319 if (ioc->sh != NULL)
2320 karg.host_no = ioc->sh->host_no;
2324 /* Reformat the fw_version into a string
2326 karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
2327 ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
2328 karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
2329 karg.fw_version[2] = '.';
2330 karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
2331 ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
2332 karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
2333 karg.fw_version[5] = '.';
2334 karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
2335 ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
2336 karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
2337 karg.fw_version[8] = '.';
2338 karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
2339 ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
2340 karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
2341 karg.fw_version[11] = '\0';
2343 /* Issue a config request to get the device serial number
2345 hdr.PageVersion = 0;
2348 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2349 cfg.cfghdr.hdr = &hdr;
2352 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2353 cfg.dir = 0; /* read */
2356 strncpy(karg.serial_number, " ", 24);
2357 if (mpt_config(ioc, &cfg) == 0) {
2358 if (cfg.cfghdr.hdr->PageLength > 0) {
2359 /* Issue the second config page request */
2360 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2362 pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
2364 cfg.physAddr = buf_dma;
2365 if (mpt_config(ioc, &cfg) == 0) {
2366 ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
2367 if (strlen(pdata->BoardTracerNumber) > 1) {
2368 strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
2369 karg.serial_number[24-1]='\0';
2372 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
2377 rc = mpt_GetIocState(ioc, 1);
2379 case MPI_IOC_STATE_OPERATIONAL:
2380 karg.ioc_status = HP_STATUS_OK;
2383 case MPI_IOC_STATE_FAULT:
2384 karg.ioc_status = HP_STATUS_FAILED;
2387 case MPI_IOC_STATE_RESET:
2388 case MPI_IOC_STATE_READY:
2390 karg.ioc_status = HP_STATUS_OTHER;
2394 karg.base_io_addr = pci_resource_start(pdev, 0);
2396 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2397 karg.bus_phys_width = HP_BUS_WIDTH_UNK;
2399 karg.bus_phys_width = HP_BUS_WIDTH_16;
2401 karg.hard_resets = 0;
2402 karg.soft_resets = 0;
2404 if (ioc->sh != NULL) {
2405 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
2407 if (hd && (cim_rev == 1)) {
2408 karg.hard_resets = hd->hard_resets;
2409 karg.soft_resets = hd->soft_resets;
2410 karg.timeouts = hd->timeouts;
2415 cfg.action = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
2416 cfg.dir = MPI_TB_ISTWI_FLAGS_READ;
2418 pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
2420 cfg.physAddr = buf_dma;
2421 if ((mpt_toolbox(ioc, &cfg)) == 0) {
2422 karg.rsvd = *(u32 *)pbuf;
2424 pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
2428 /* Copy the data from kernel memory to user memory
2430 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
2431 printk(KERN_ERR "%s@%d::mptctl_hpgethostinfo - "
2432 "Unable to write out hp_host_info @ %p\n",
2433 __FILE__, __LINE__, uarg);
2441 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2442 /* Prototype Routine for the HP TARGET INFO command.
2445 * Return: 0 if successful
2446 * -EFAULT if data unavailable
2447 * -EBUSY if previous command timout and IOC reset is not complete.
2448 * -ENODEV if no such device/adapter
2449 * -ETIME if timer expires
2450 * -ENOMEM if memory allocation error
2453 mptctl_hp_targetinfo(unsigned long arg)
2455 hp_target_info_t __user *uarg = (void __user *) arg;
2456 SCSIDevicePage0_t *pg0_alloc;
2457 SCSIDevicePage3_t *pg3_alloc;
2459 MPT_SCSI_HOST *hd = NULL;
2460 hp_target_info_t karg;
2463 dma_addr_t page_dma;
2465 ConfigPageHeader_t hdr;
2466 int tmp, np, rc = 0;
2468 dctlprintk((": mptctl_hp_targetinfo called.\n"));
2469 if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
2470 printk(KERN_ERR "%s@%d::mptctl_hp_targetinfo - "
2471 "Unable to read in hp_host_targetinfo struct @ %p\n",
2472 __FILE__, __LINE__, uarg);
2476 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2478 dctlprintk((KERN_ERR "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
2479 __FILE__, __LINE__, iocnum));
2483 /* There is nothing to do for FCP parts.
2485 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2488 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
2491 if (ioc->sh->host_no != karg.hdr.host)
2494 /* Get the data transfer speeds
2496 data_sz = ioc->spi_data.sdp0length * 4;
2497 pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2499 hdr.PageVersion = ioc->spi_data.sdp0version;
2500 hdr.PageLength = data_sz;
2502 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2504 cfg.cfghdr.hdr = &hdr;
2505 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2508 cfg.physAddr = page_dma;
2510 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2512 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2513 np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
2514 karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
2515 HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
2517 if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
2518 tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
2520 karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
2521 else if (tmp <= 0x09)
2522 karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
2523 else if (tmp <= 0x0A)
2524 karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
2525 else if (tmp <= 0x0C)
2526 karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
2527 else if (tmp <= 0x25)
2528 karg.negotiated_speed = HP_DEV_SPEED_FAST;
2530 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2532 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2535 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
2540 karg.message_rejects = -1;
2541 karg.phase_errors = -1;
2542 karg.parity_errors = -1;
2543 karg.select_timeouts = -1;
2545 /* Get the target error parameters
2547 hdr.PageVersion = 0;
2550 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2552 cfg.cfghdr.hdr = &hdr;
2553 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2557 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2558 /* Issue the second config page request */
2559 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2560 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2561 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
2562 ioc->pcidev, data_sz, &page_dma);
2564 cfg.physAddr = page_dma;
2565 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2566 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2567 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
2568 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
2569 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
2571 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
2574 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
2576 karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
2578 /* Copy the data from kernel memory to user memory
2580 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
2581 printk(KERN_ERR "%s@%d::mptctl_hp_target_info - "
2582 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2583 __FILE__, __LINE__, uarg);
2590 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2592 static struct file_operations mptctl_fops = {
2593 .owner = THIS_MODULE,
2594 .llseek = no_llseek,
2595 .unlocked_ioctl = mptctl_ioctl,
2596 #ifdef CONFIG_COMPAT
2597 .compat_ioctl = compat_mpctl_ioctl,
2601 static struct miscdevice mptctl_miscdev = {
2607 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2609 #ifdef CONFIG_COMPAT
2612 compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
2615 struct mpt_fw_xfer32 kfw32;
2616 struct mpt_fw_xfer kfw;
2617 MPT_ADAPTER *iocp = NULL;
2618 int iocnum, iocnumX;
2619 int nonblock = (filp->f_flags & O_NONBLOCK);
2622 dctlprintk((KERN_INFO MYNAM "::compat_mptfwxfer_ioctl() called\n"));
2624 if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
2627 /* Verify intended MPT adapter */
2628 iocnumX = kfw32.iocnum & 0xFF;
2629 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2631 dctlprintk((KERN_ERR MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2632 __LINE__, iocnumX));
2636 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2639 kfw.iocnum = iocnum;
2640 kfw.fwlen = kfw32.fwlen;
2641 kfw.bufp = compat_ptr(kfw32.bufp);
2643 ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
2645 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2651 compat_mpt_command(struct file *filp, unsigned int cmd,
2654 struct mpt_ioctl_command32 karg32;
2655 struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
2656 struct mpt_ioctl_command karg;
2657 MPT_ADAPTER *iocp = NULL;
2658 int iocnum, iocnumX;
2659 int nonblock = (filp->f_flags & O_NONBLOCK);
2662 dctlprintk((KERN_INFO MYNAM "::compat_mpt_command() called\n"));
2664 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
2667 /* Verify intended MPT adapter */
2668 iocnumX = karg32.hdr.iocnum & 0xFF;
2669 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2671 dctlprintk((KERN_ERR MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
2672 __LINE__, iocnumX));
2676 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2679 /* Copy data to karg */
2680 karg.hdr.iocnum = karg32.hdr.iocnum;
2681 karg.hdr.port = karg32.hdr.port;
2682 karg.timeout = karg32.timeout;
2683 karg.maxReplyBytes = karg32.maxReplyBytes;
2685 karg.dataInSize = karg32.dataInSize;
2686 karg.dataOutSize = karg32.dataOutSize;
2687 karg.maxSenseBytes = karg32.maxSenseBytes;
2688 karg.dataSgeOffset = karg32.dataSgeOffset;
2690 karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
2691 karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
2692 karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
2693 karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
2695 /* Pass new structure to do_mpt_command
2697 ret = mptctl_do_mpt_command (karg, &uarg->MF);
2699 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2704 static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2714 case MPTEVENTENABLE:
2715 case MPTEVENTREPORT:
2717 case HP_GETHOSTINFO:
2718 case HP_GETTARGETINFO:
2720 ret = __mptctl_ioctl(f, cmd, arg);
2723 ret = compat_mpt_command(f, cmd, arg);
2725 case MPTFWDOWNLOAD32:
2726 ret = compat_mptfwxfer_ioctl(f, cmd, arg);
2739 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2741 * mptctl_probe - Installs ioctl devices per bus.
2742 * @pdev: Pointer to pci_dev structure
2744 * Returns 0 for success, non-zero for failure.
2749 mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2754 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2757 * Allocate and inite a MPT_IOCTL structure
2759 sz = sizeof (MPT_IOCTL);
2760 mem = kmalloc(sz, GFP_KERNEL);
2767 ioc->ioctl = (MPT_IOCTL *) mem;
2768 ioc->ioctl->ioc = ioc;
2769 mutex_init(&ioc->ioctl->ioctl_mutex);
2774 mptctl_remove(pdev);
2778 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2780 * mptctl_remove - Removed ioctl devices
2781 * @pdev: Pointer to pci_dev structure
2786 mptctl_remove(struct pci_dev *pdev)
2788 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2790 kfree ( ioc->ioctl );
2793 static struct mpt_pci_driver mptctl_driver = {
2794 .probe = mptctl_probe,
2795 .remove = mptctl_remove,
2798 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2799 static int __init mptctl_init(void)
2804 show_mptmod_ver(my_NAME, my_VERSION);
2806 if(mpt_device_driver_register(&mptctl_driver,
2807 MPTCTL_DRIVER) != 0 ) {
2808 dprintk((KERN_INFO MYNAM
2809 ": failed to register dd callbacks\n"));
2812 /* Register this device */
2813 err = misc_register(&mptctl_miscdev);
2815 printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
2818 printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
2819 printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
2820 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2823 * Install our handler
2826 if ((mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER)) < 0) {
2827 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2828 misc_deregister(&mptctl_miscdev);
2833 if (mpt_reset_register(mptctl_id, mptctl_ioc_reset) == 0) {
2834 dprintk((KERN_INFO MYNAM ": Registered for IOC reset notifications\n"));
2843 mpt_device_driver_deregister(MPTCTL_DRIVER);
2848 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2849 static void mptctl_exit(void)
2851 misc_deregister(&mptctl_miscdev);
2852 printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
2853 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2855 /* De-register reset handler from base module */
2856 mpt_reset_deregister(mptctl_id);
2857 dprintk((KERN_INFO MYNAM ": Deregistered for IOC reset notifications\n"));
2859 /* De-register callback handler from base module */
2860 mpt_deregister(mptctl_id);
2861 printk(KERN_INFO MYNAM ": Deregistered from Fusion MPT base driver\n");
2863 mpt_device_driver_deregister(MPTCTL_DRIVER);
2867 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2869 module_init(mptctl_init);
2870 module_exit(mptctl_exit);