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-2008 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-2008 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)
186 if (!mutex_trylock(&ioc->ioctl->ioctl_mutex))
189 if (mutex_lock_interruptible(&ioc->ioctl->ioctl_mutex))
195 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
197 * This is the callback for any message we have posted. The message itself
198 * will be returned to the message pool when we return from the IRQ
200 * This runs in irq context so be short and sweet.
203 mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
211 cmd = req->u.hdr.Function;
214 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tcompleting mpi function (0x%02X), req=%p, "
215 "reply=%p\n", ioc->name, req->u.hdr.Function, req, reply));
221 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_reply() NULL Reply "
222 "Function=%x!\n", ioc->name, cmd));
224 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
225 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
227 /* We are done, issue wake up
229 ioc->ioctl->wait_done = 1;
230 wake_up (&mptctl_wait);
235 /* Copy the reply frame (which much exist
236 * for non-SCSI I/O) to the IOC structure.
238 memcpy(ioc->ioctl->ReplyFrame, reply,
239 min(ioc->reply_sz, 4*reply->u.reply.MsgLength));
240 ioc->ioctl->status |= MPT_IOCTL_STATUS_RF_VALID;
242 /* Set the command status to GOOD if IOC Status is GOOD
243 * OR if SCSI I/O cmd and data underrun or recovered error.
245 iocStatus = le16_to_cpu(reply->u.reply.IOCStatus) & MPI_IOCSTATUS_MASK;
246 if (iocStatus == MPI_IOCSTATUS_SUCCESS)
247 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
249 if (iocStatus || reply->u.reply.IOCLogInfo)
250 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tiocstatus (0x%04X), "
251 "loginfo (0x%08X)\n", ioc->name,
253 le32_to_cpu(reply->u.reply.IOCLogInfo)));
255 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
256 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
258 if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
259 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
260 "\tscsi_status (0x%02x), scsi_state (0x%02x), "
261 "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name,
262 reply->u.sreply.SCSIStatus,
263 reply->u.sreply.SCSIState,
264 le16_to_cpu(reply->u.sreply.TaskTag),
265 le32_to_cpu(reply->u.sreply.TransferCount)));
267 ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
269 if ((iocStatus == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) ||
270 (iocStatus == MPI_IOCSTATUS_SCSI_RECOVERED_ERROR)) {
271 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
275 /* Copy the sense data - if present
277 if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) &&
278 (reply->u.sreply.SCSIState &
279 MPI_SCSI_STATE_AUTOSENSE_VALID)){
280 sz = req->u.scsireq.SenseBufferLength;
282 le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
284 ((u8 *)ioc->sense_buf_pool +
285 (req_index * MPT_SENSE_BUFFER_ALLOC));
286 memcpy(ioc->ioctl->sense, sense_data, sz);
287 ioc->ioctl->status |= MPT_IOCTL_STATUS_SENSE_VALID;
290 if (cmd == MPI_FUNCTION_SCSI_TASK_MGMT)
291 mptctl_free_tm_flags(ioc);
293 /* We are done, issue wake up
295 ioc->ioctl->wait_done = 1;
296 wake_up (&mptctl_wait);
301 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
302 /* mptctl_timeout_expired
304 * Expecting an interrupt, however timed out.
307 static void mptctl_timeout_expired (MPT_IOCTL *ioctl)
311 dctlprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT ": Timeout Expired! Host %d\n",
312 ioctl->ioc->name, ioctl->ioc->id));
316 ioctl->wait_done = 0;
317 if (ioctl->reset & MPTCTL_RESET_OK)
318 rc = mptctl_bus_reset(ioctl);
321 /* Issue a reset for this device.
322 * The IOC is not responding.
324 dctlprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
326 mpt_HardResetHandler(ioctl->ioc, CAN_SLEEP);
337 static int mptctl_bus_reset(MPT_IOCTL *ioctl)
340 SCSITaskMgmt_t *pScsiTm;
346 ioctl->reset &= ~MPTCTL_RESET_OK;
348 if (ioctl->ioc->sh == NULL)
351 hd = shost_priv(ioctl->ioc->sh);
355 /* Single threading ....
357 if (mptctl_set_tm_flags(hd) != 0)
362 if ((mf = mpt_get_msg_frame(mptctl_id, ioctl->ioc)) == NULL) {
363 dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt, no msg frames!!\n",
366 mptctl_free_tm_flags(ioctl->ioc);
370 dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt request @ %p\n",
371 ioctl->ioc->name, mf));
373 pScsiTm = (SCSITaskMgmt_t *) mf;
374 pScsiTm->TargetID = ioctl->id;
375 pScsiTm->Bus = hd->port; /* 0 */
376 pScsiTm->ChainOffset = 0;
377 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
378 pScsiTm->Reserved = 0;
379 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
380 pScsiTm->Reserved1 = 0;
381 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
383 for (ii= 0; ii < 8; ii++)
384 pScsiTm->LUN[ii] = 0;
386 for (ii=0; ii < 7; ii++)
387 pScsiTm->Reserved2[ii] = 0;
389 pScsiTm->TaskMsgContext = 0;
390 dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT
391 "mptctl_bus_reset: issued.\n", ioctl->ioc->name));
393 DBG_DUMP_TM_REQUEST_FRAME(ioctl->ioc, (u32 *)mf);
397 if ((ioctl->ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
398 (ioctl->ioc->facts.MsgVersion >= MPI_VERSION_01_05))
399 mpt_put_msg_frame_hi_pri(mptctl_id, ioctl->ioc, mf);
401 retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
402 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
404 dfailprintk(ioctl->ioc, printk(MYIOC_s_ERR_FMT "_send_handshake FAILED!"
405 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
407 goto mptctl_bus_reset_done;
411 /* Now wait for the command to complete */
412 ii = wait_event_timeout(mptctl_wait,
413 ioctl->wait_done == 1,
414 HZ*5 /* 5 second timeout */);
416 if(ii <=0 && (ioctl->wait_done != 1 )) {
417 mpt_free_msg_frame(hd->ioc, mf);
418 ioctl->wait_done = 0;
419 retval = -1; /* return failure */
422 mptctl_bus_reset_done:
424 mptctl_free_tm_flags(ioctl->ioc);
429 mptctl_set_tm_flags(MPT_SCSI_HOST *hd) {
432 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
434 if (hd->tmState == TM_STATE_NONE) {
435 hd->tmState = TM_STATE_IN_PROGRESS;
437 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
439 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
447 mptctl_free_tm_flags(MPT_ADAPTER *ioc)
452 hd = shost_priv(ioc->sh);
456 spin_lock_irqsave(&ioc->FreeQlock, flags);
458 hd->tmState = TM_STATE_NONE;
460 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
465 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
468 * Clean-up functionality. Used only if there has been a
469 * reload of the FW due.
473 mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
475 MPT_IOCTL *ioctl = ioc->ioctl;
476 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOC %s_reset routed to IOCTL driver!\n", ioc->name,
477 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
478 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
483 switch(reset_phase) {
484 case MPT_IOC_SETUP_RESET:
485 ioctl->status |= MPT_IOCTL_STATUS_DID_IOCRESET;
487 case MPT_IOC_POST_RESET:
488 ioctl->status &= ~MPT_IOCTL_STATUS_DID_IOCRESET;
490 case MPT_IOC_PRE_RESET:
498 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
499 /* ASYNC Event Notification Support */
501 mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
505 event = le32_to_cpu(pEvReply->Event) & 0xFF;
507 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n",
508 ioc->name, __func__));
509 if(async_queue == NULL)
512 /* Raise SIGIO for persistent events.
513 * TODO - this define is not in MPI spec yet,
514 * but they plan to set it to 0x21
516 if (event == 0x21 ) {
517 ioc->aen_event_read_flag=1;
518 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Raised SIGIO to application\n",
520 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
521 "Raised SIGIO to application\n", ioc->name));
522 kill_fasync(&async_queue, SIGIO, POLL_IN);
526 /* This flag is set after SIGIO was raised, and
527 * remains set until the application has read
528 * the event log via ioctl=MPTEVENTREPORT
530 if(ioc->aen_event_read_flag)
533 /* Signal only for the events that are
534 * requested for by the application
536 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
537 ioc->aen_event_read_flag=1;
538 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
539 "Raised SIGIO to application\n", ioc->name));
540 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
541 "Raised SIGIO to application\n", ioc->name));
542 kill_fasync(&async_queue, SIGIO, POLL_IN);
548 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 ret = fasync_helper(fd, filep, mode, &async_queue);
562 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
565 * cmd - specify the particular IOCTL command to be issued
566 * arg - data specific to the command. Must not be null.
569 __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
571 mpt_ioctl_header __user *uhdr = (void __user *) arg;
572 mpt_ioctl_header khdr;
575 int nonblock = (file->f_flags & O_NONBLOCK);
577 MPT_ADAPTER *iocp = NULL;
579 if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
580 printk(KERN_ERR MYNAM "%s::mptctl_ioctl() @%d - "
581 "Unable to copy mpt_ioctl_header data @ %p\n",
582 __FILE__, __LINE__, uhdr);
585 ret = -ENXIO; /* (-6) No such device or address */
587 /* Verify intended MPT adapter - set iocnum and the adapter
590 iocnumX = khdr.iocnum & 0xFF;
591 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
593 printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - ioc%d not found!\n",
594 __FILE__, __LINE__, iocnumX);
599 printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - Controller disabled.\n",
604 /* Handle those commands that are just returning
605 * information stored in the driver.
606 * These commands should never time out and are unaffected
607 * by TM and FW reloads.
609 if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
610 return mptctl_getiocinfo(arg, _IOC_SIZE(cmd));
611 } else if (cmd == MPTTARGETINFO) {
612 return mptctl_gettargetinfo(arg);
613 } else if (cmd == MPTTEST) {
614 return mptctl_readtest(arg);
615 } else if (cmd == MPTEVENTQUERY) {
616 return mptctl_eventquery(arg);
617 } else if (cmd == MPTEVENTENABLE) {
618 return mptctl_eventenable(arg);
619 } else if (cmd == MPTEVENTREPORT) {
620 return mptctl_eventreport(arg);
621 } else if (cmd == MPTFWREPLACE) {
622 return mptctl_replace_fw(arg);
625 /* All of these commands require an interrupt or
626 * are unknown/illegal.
628 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
631 if (cmd == MPTFWDOWNLOAD)
632 ret = mptctl_fw_download(arg);
633 else if (cmd == MPTCOMMAND)
634 ret = mptctl_mpt_command(arg);
635 else if (cmd == MPTHARDRESET)
636 ret = mptctl_do_reset(arg);
637 else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
638 ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
639 else if (cmd == HP_GETTARGETINFO)
640 ret = mptctl_hp_targetinfo(arg);
644 mutex_unlock(&iocp->ioctl->ioctl_mutex);
650 mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
654 ret = __mptctl_ioctl(file, cmd, arg);
659 static int mptctl_do_reset(unsigned long arg)
661 struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
662 struct mpt_ioctl_diag_reset krinfo;
665 if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
666 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_reset - "
667 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
668 __FILE__, __LINE__, urinfo);
672 if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
673 printk(KERN_DEBUG MYNAM "%s@%d::mptctl_do_reset - ioc%d not found!\n",
674 __FILE__, __LINE__, krinfo.hdr.iocnum);
675 return -ENODEV; /* (-6) No such device or address */
678 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "mptctl_do_reset called.\n",
681 if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
682 printk (MYIOC_s_ERR_FMT "%s@%d::mptctl_do_reset - reset failed.\n",
683 iocp->name, __FILE__, __LINE__);
690 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
692 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
693 * This structure contains: iocnum, firmware length (bytes),
694 * pointer to user space memory where the fw image is stored.
697 * Return: 0 if successful
698 * -EFAULT if data unavailable
699 * -ENXIO if no such device
700 * -EAGAIN if resource problem
701 * -ENOMEM if no memory for SGE
702 * -EMLINK if too many chain buffers required
703 * -EBADRQC if adapter does not support FW download
704 * -EBUSY if adapter is busy
705 * -ENOMSG if FW upload returned bad status
708 mptctl_fw_download(unsigned long arg)
710 struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
711 struct mpt_fw_xfer kfwdl;
713 if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
714 printk(KERN_ERR MYNAM "%s@%d::_ioctl_fwdl - "
715 "Unable to copy mpt_fw_xfer struct @ %p\n",
716 __FILE__, __LINE__, ufwdl);
720 return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
723 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
725 * FW Download engine.
727 * Return: 0 if successful
728 * -EFAULT if data unavailable
729 * -ENXIO if no such device
730 * -EAGAIN if resource problem
731 * -ENOMEM if no memory for SGE
732 * -EMLINK if too many chain buffers required
733 * -EBADRQC if adapter does not support FW download
734 * -EBUSY if adapter is busy
735 * -ENOMSG if FW upload returned bad status
738 mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen)
743 FWDownloadTCSGE_t *ptsge;
744 MptSge_t *sgl, *sgIn;
746 struct buflist *buflist;
755 int fw_bytes_copied = 0;
759 pFWDownloadReply_t ReplyMsg = NULL;
761 if (mpt_verify_adapter(ioc, &iocp) < 0) {
762 printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n",
764 return -ENODEV; /* (-6) No such device or address */
767 /* Valid device. Get a message frame and construct the FW download message.
769 if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
773 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT
774 "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id));
775 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.bufp = %p\n",
776 iocp->name, ufwbuf));
777 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.fwlen = %d\n",
778 iocp->name, (int)fwlen));
779 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.ioc = %04xh\n",
782 dlmsg = (FWDownload_t*) mf;
783 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
784 sgOut = (char *) (ptsge + 1);
787 * Construct f/w download request
789 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
791 dlmsg->ChainOffset = 0;
792 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
793 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
794 if (iocp->facts.MsgVersion >= MPI_VERSION_01_05)
795 dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT;
800 /* Set up the Transaction SGE.
803 ptsge->ContextSize = 0;
804 ptsge->DetailsLength = 12;
805 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
806 ptsge->Reserved_0100_Checksum = 0;
807 ptsge->ImageOffset = 0;
808 ptsge->ImageSize = cpu_to_le32(fwlen);
814 * Need to kmalloc area(s) for holding firmware image bytes.
815 * But we need to do it piece meal, using a proper
816 * scatter gather list (with 128kB MAX hunks).
818 * A practical limit here might be # of sg hunks that fit into
819 * a single IOC request frame; 12 or 8 (see below), so:
820 * For FC9xx: 12 x 128kB == 1.5 mB (max)
821 * For C1030: 8 x 128kB == 1 mB (max)
822 * We could support chaining, but things get ugly(ier:)
824 * Set the sge_offset to the start of the sgl (bytes).
826 sgdir = 0x04000000; /* IOC will READ from sys mem */
827 sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
828 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
829 &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
833 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
834 * for FC9xx f/w image, but calculate max number of sge hunks
835 * we can fit into a request frame, and limit ourselves to that.
836 * (currently no chain support)
837 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
843 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t))
844 / (sizeof(dma_addr_t) + sizeof(u32));
845 if (numfrags > maxfrags) {
850 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n",
851 iocp->name, sgl, numfrags));
854 * Parse SG list, copying sgl itself,
855 * plus f/w image hunks from user space as we go...
860 for (i=0; i < numfrags; i++) {
862 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
863 * Skip everything but Simple. If simple, copy from
864 * user space into kernel space.
865 * Note: we should not have anything but Simple as
866 * Chain SGE are illegal.
868 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
869 if (nib == 0 || nib == 3) {
871 } else if (sgIn->Address) {
872 mpt_add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
874 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
875 printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - "
876 "Unable to copy f/w buffer hunk#%d @ %p\n",
877 iocp->name, __FILE__, __LINE__, n, ufwbuf);
880 fw_bytes_copied += bl->len;
884 sgOut += (sizeof(dma_addr_t) + sizeof(u32));
887 DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags);
890 * Finally, perform firmware download.
893 mpt_put_msg_frame(mptctl_id, iocp, mf);
895 /* Now wait for the command to complete */
896 ret = wait_event_timeout(mptctl_wait,
897 iocp->ioctl->wait_done == 1,
900 if(ret <=0 && (iocp->ioctl->wait_done != 1 )) {
901 /* Now we need to reset the board */
902 mptctl_timeout_expired(iocp->ioctl);
908 kfree_sgl(sgl, sgl_dma, buflist, iocp);
910 ReplyMsg = (pFWDownloadReply_t)iocp->ioctl->ReplyFrame;
911 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
912 if (iocstat == MPI_IOCSTATUS_SUCCESS) {
913 printk(MYIOC_s_INFO_FMT "F/W update successfull!\n", iocp->name);
915 } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
916 printk(MYIOC_s_WARN_FMT "Hmmm... F/W download not supported!?!\n",
918 printk(MYIOC_s_WARN_FMT "(time to go bang on somebodies door)\n",
921 } else if (iocstat == MPI_IOCSTATUS_BUSY) {
922 printk(MYIOC_s_WARN_FMT "IOC_BUSY!\n", iocp->name);
923 printk(MYIOC_s_WARN_FMT "(try again later?)\n", iocp->name);
926 printk(MYIOC_s_WARN_FMT "ioctl_fwdl() returned [bad] status = %04xh\n",
927 iocp->name, iocstat);
928 printk(MYIOC_s_WARN_FMT "(bad VooDoo)\n", iocp->name);
934 kfree_sgl(sgl, sgl_dma, buflist, iocp);
938 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
940 * SGE Allocation routine
942 * Inputs: bytes - number of bytes to be transferred
943 * sgdir - data direction
944 * sge_offset - offset (in bytes) from the start of the request
945 * frame to the first SGE
946 * ioc - pointer to the mptadapter
947 * Outputs: frags - number of scatter gather elements
948 * blp - point to the buflist pointer
949 * sglbuf_dma - pointer to the (dma) sgl
950 * Returns: Null if failes
951 * pointer to the (virtual) sgl if successful.
954 kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
955 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
957 MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
958 /* and chain buffers */
959 struct buflist *buflist = NULL; /* kernel routine */
963 int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
964 int bytes_allocd = 0;
966 dma_addr_t pa; // phys addr
968 int sg_spill = MAX_FRAGS_SPILL1;
974 /* Allocate and initialize an array of kernel
975 * structures for the SG elements.
977 i = MAX_SGL_BYTES / 8;
978 buflist = kzalloc(i, GFP_USER);
983 /* Allocate a single block of memory to store the sg elements and
984 * the chain buffers. The calling routine is responsible for
985 * copying the data in this array into the correct place in the
986 * request and chain buffers.
988 sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
992 if (sgdir & 0x04000000)
993 dir = PCI_DMA_TODEVICE;
995 dir = PCI_DMA_FROMDEVICE;
998 * sgl = sglbuf = point to beginning of sg buffer
999 * buflist_ent = 0 = first kernel structure
1000 * sg_spill = number of SGE that can be written before the first
1005 sg_spill = ((ioc->req_sz - sge_offset)/(sizeof(dma_addr_t) + sizeof(u32))) - 1;
1006 while (bytes_allocd < bytes) {
1007 this_alloc = min(alloc_sz, bytes-bytes_allocd);
1008 buflist[buflist_ent].len = this_alloc;
1009 buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
1012 if (buflist[buflist_ent].kptr == NULL) {
1013 alloc_sz = alloc_sz / 2;
1014 if (alloc_sz == 0) {
1015 printk(MYIOC_s_WARN_FMT "-SG: No can do - "
1016 "not enough memory! :-(\n", ioc->name);
1017 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
1018 ioc->name, numfrags);
1023 dma_addr_t dma_addr;
1025 bytes_allocd += this_alloc;
1026 sgl->FlagsLength = (0x10000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|this_alloc);
1027 dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir);
1028 sgl->Address = dma_addr;
1036 if (bytes_allocd >= bytes)
1039 /* Need to chain? */
1040 if (fragcnt == sg_spill) {
1041 printk(MYIOC_s_WARN_FMT
1042 "-SG: No can do - " "Chain required! :-(\n", ioc->name);
1043 printk(MYIOC_s_WARN_FMT "(freeing %d frags)\n", ioc->name, numfrags);
1047 /* overflow check... */
1048 if (numfrags*8 > MAX_SGL_BYTES){
1050 printk(MYIOC_s_WARN_FMT "-SG: No can do - "
1051 "too many SG frags! :-(\n", ioc->name);
1052 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
1053 ioc->name, numfrags);
1058 /* Last sge fixup: set LE+eol+eob bits */
1059 sgl[-1].FlagsLength |= 0xC1000000;
1064 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1065 "%d SG frags generated!\n", ioc->name, numfrags));
1067 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1068 "last (big) alloc_sz=%d\n", ioc->name, alloc_sz));
1073 if (sglbuf != NULL) {
1074 for (i = 0; i < numfrags; i++) {
1075 dma_addr_t dma_addr;
1079 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
1082 dma_addr = sglbuf[i].Address;
1083 kptr = buflist[i].kptr;
1084 len = buflist[i].len;
1086 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1088 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma);
1094 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1096 * Routine to free the SGL elements.
1099 kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
1102 struct buflist *bl = buflist;
1107 if (sg->FlagsLength & 0x04000000)
1108 dir = PCI_DMA_TODEVICE;
1110 dir = PCI_DMA_FROMDEVICE;
1112 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1113 while (! (nib & 0x4)) { /* eob */
1114 /* skip ignore/chain. */
1115 if (nib == 0 || nib == 3) {
1117 } else if (sg->Address) {
1118 dma_addr_t dma_addr;
1122 dma_addr = sg->Address;
1125 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1126 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1131 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1136 dma_addr_t dma_addr;
1140 dma_addr = sg->Address;
1143 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1144 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1148 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma);
1150 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: Free'd 1 SGL buf + %d kbufs!\n",
1154 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1156 * mptctl_getiocinfo - Query the host adapter for IOC information.
1157 * @arg: User space argument
1160 * Return: 0 if successful
1161 * -EFAULT if data unavailable
1162 * -ENODEV if no such device/adapter
1165 mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1167 struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
1168 struct mpt_ioctl_iocinfo *karg;
1170 struct pci_dev *pdev;
1175 struct scsi_device *sdev;
1176 VirtDevice *vdevice;
1178 /* Add of PCI INFO results in unaligned access for
1179 * IA64 and Sparc. Reset long to int. Return no PCI
1180 * data for obsolete format.
1182 if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
1184 else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
1186 else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
1188 else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
1189 cim_rev = 0; /* obsolete */
1193 karg = kmalloc(data_size, GFP_KERNEL);
1195 printk(KERN_ERR MYNAM "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
1196 __FILE__, __LINE__);
1200 if (copy_from_user(karg, uarg, data_size)) {
1201 printk(KERN_ERR MYNAM "%s@%d::mptctl_getiocinfo - "
1202 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1203 __FILE__, __LINE__, uarg);
1208 if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
1210 printk(KERN_DEBUG MYNAM "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
1211 __FILE__, __LINE__, iocnum);
1216 /* Verify the data transfer size is correct. */
1217 if (karg->hdr.maxDataSize != data_size) {
1218 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
1219 "Structure size mismatch. Command not completed.\n",
1220 ioc->name, __FILE__, __LINE__);
1225 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_getiocinfo called.\n",
1228 /* Fill in the data and return the structure to the calling
1231 if (ioc->bus_type == SAS)
1232 karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
1233 else if (ioc->bus_type == FC)
1234 karg->adapterType = MPT_IOCTL_INTERFACE_FC;
1236 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1238 if (karg->hdr.port > 1)
1240 port = karg->hdr.port;
1243 pdev = (struct pci_dev *) ioc->pcidev;
1245 karg->pciId = pdev->device;
1246 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1247 karg->hwRev = revision;
1248 karg->subSystemDevice = pdev->subsystem_device;
1249 karg->subSystemVendor = pdev->subsystem_vendor;
1252 /* Get the PCI bus, device, and function numbers for the IOC
1254 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1255 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1256 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1257 } else if (cim_rev == 2) {
1258 /* Get the PCI bus, device, function and segment ID numbers
1260 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1261 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1262 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1263 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
1266 /* Get number of devices
1268 karg->numDevices = 0;
1270 shost_for_each_device(sdev, ioc->sh) {
1271 vdevice = sdev->hostdata;
1272 if (vdevice->vtarget->tflags &
1273 MPT_TARGET_FLAGS_RAID_COMPONENT)
1279 /* Set the BIOS and FW Version
1281 karg->FWVersion = ioc->facts.FWVersion.Word;
1282 karg->BIOSVersion = ioc->biosVersion;
1284 /* Set the Version Strings.
1286 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
1287 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
1289 karg->busChangeEvent = 0;
1290 karg->hostId = ioc->pfacts[port].PortSCSIID;
1291 karg->rsvd[0] = karg->rsvd[1] = 0;
1293 /* Copy the data from kernel memory to user memory
1295 if (copy_to_user((char __user *)arg, karg, data_size)) {
1296 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
1297 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1298 ioc->name, __FILE__, __LINE__, uarg);
1307 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1309 * mptctl_gettargetinfo - Query the host adapter for target information.
1310 * @arg: User space argument
1313 * Return: 0 if successful
1314 * -EFAULT if data unavailable
1315 * -ENODEV if no such device/adapter
1318 mptctl_gettargetinfo (unsigned long arg)
1320 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1321 struct mpt_ioctl_targetinfo karg;
1323 VirtDevice *vdevice;
1332 struct scsi_device *sdev;
1334 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
1335 printk(KERN_ERR MYNAM "%s@%d::mptctl_gettargetinfo - "
1336 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1337 __FILE__, __LINE__, uarg);
1341 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1343 printk(KERN_DEBUG MYNAM "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
1344 __FILE__, __LINE__, iocnum);
1348 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_gettargetinfo called.\n",
1350 /* Get the port number and set the maximum number of bytes
1351 * in the returned structure.
1352 * Ignore the port setting.
1354 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1355 maxWordsLeft = numBytes/sizeof(int);
1356 port = karg.hdr.port;
1358 if (maxWordsLeft <= 0) {
1359 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1360 ioc->name, __FILE__, __LINE__);
1364 /* Fill in the data and return the structure to the calling
1368 /* struct mpt_ioctl_targetinfo does not contain sufficient space
1369 * for the target structures so when the IOCTL is called, there is
1370 * not sufficient stack space for the structure. Allocate memory,
1371 * populate the memory, copy back to the user, then free memory.
1372 * targetInfo format:
1373 * bits 31-24: reserved
1378 pmem = kzalloc(numBytes, GFP_KERNEL);
1380 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1381 ioc->name, __FILE__, __LINE__);
1384 pdata = (int *) pmem;
1386 /* Get number of devices
1389 shost_for_each_device(sdev, ioc->sh) {
1392 vdevice = sdev->hostdata;
1393 if (vdevice->vtarget->tflags &
1394 MPT_TARGET_FLAGS_RAID_COMPONENT)
1396 lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun;
1397 *pdata = (((u8)lun << 16) + (vdevice->vtarget->channel << 8) +
1398 (vdevice->vtarget->id ));
1404 karg.numDevices = numDevices;
1406 /* Copy part of the data from kernel memory to user memory
1408 if (copy_to_user((char __user *)arg, &karg,
1409 sizeof(struct mpt_ioctl_targetinfo))) {
1410 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
1411 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1412 ioc->name, __FILE__, __LINE__, uarg);
1417 /* Copy the remaining data from kernel memory to user memory
1419 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
1420 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
1421 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1422 ioc->name, __FILE__, __LINE__, pdata);
1432 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1433 /* MPT IOCTL Test function.
1436 * Return: 0 if successful
1437 * -EFAULT if data unavailable
1438 * -ENODEV if no such device/adapter
1441 mptctl_readtest (unsigned long arg)
1443 struct mpt_ioctl_test __user *uarg = (void __user *) arg;
1444 struct mpt_ioctl_test karg;
1448 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
1449 printk(KERN_ERR MYNAM "%s@%d::mptctl_readtest - "
1450 "Unable to read in mpt_ioctl_test struct @ %p\n",
1451 __FILE__, __LINE__, uarg);
1455 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1457 printk(KERN_DEBUG MYNAM "%s::mptctl_readtest() @%d - ioc%d not found!\n",
1458 __FILE__, __LINE__, iocnum);
1462 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_readtest called.\n",
1464 /* Fill in the data and return the structure to the calling
1469 karg.chip_type = ioc->mfcnt;
1471 karg.chip_type = ioc->pcidev->device;
1473 strncpy (karg.name, ioc->name, MPT_MAX_NAME);
1474 karg.name[MPT_MAX_NAME-1]='\0';
1475 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
1476 karg.product[MPT_PRODUCT_LENGTH-1]='\0';
1478 /* Copy the data from kernel memory to user memory
1480 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
1481 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_readtest - "
1482 "Unable to write out mpt_ioctl_test struct @ %p\n",
1483 ioc->name, __FILE__, __LINE__, uarg);
1490 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1492 * mptctl_eventquery - Query the host adapter for the event types
1493 * that are being logged.
1494 * @arg: User space argument
1497 * Return: 0 if successful
1498 * -EFAULT if data unavailable
1499 * -ENODEV if no such device/adapter
1502 mptctl_eventquery (unsigned long arg)
1504 struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
1505 struct mpt_ioctl_eventquery karg;
1509 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
1510 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventquery - "
1511 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1512 __FILE__, __LINE__, uarg);
1516 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1518 printk(KERN_DEBUG MYNAM "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
1519 __FILE__, __LINE__, iocnum);
1523 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventquery called.\n",
1525 karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
1526 karg.eventTypes = ioc->eventTypes;
1528 /* Copy the data from kernel memory to user memory
1530 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
1531 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventquery - "
1532 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1533 ioc->name, __FILE__, __LINE__, uarg);
1539 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1541 mptctl_eventenable (unsigned long arg)
1543 struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
1544 struct mpt_ioctl_eventenable karg;
1548 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
1549 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventenable - "
1550 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1551 __FILE__, __LINE__, uarg);
1555 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1557 printk(KERN_DEBUG MYNAM "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
1558 __FILE__, __LINE__, iocnum);
1562 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventenable called.\n",
1564 if (ioc->events == NULL) {
1565 /* Have not yet allocated memory - do so now.
1567 int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1568 ioc->events = kzalloc(sz, GFP_KERNEL);
1570 printk(MYIOC_s_ERR_FMT
1571 ": ERROR - Insufficient memory to add adapter!\n",
1575 ioc->alloc_total += sz;
1577 ioc->eventContext = 0;
1580 /* Update the IOC event logging flag.
1582 ioc->eventTypes = karg.eventTypes;
1587 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1589 mptctl_eventreport (unsigned long arg)
1591 struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
1592 struct mpt_ioctl_eventreport karg;
1595 int numBytes, maxEvents, max;
1597 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
1598 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventreport - "
1599 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1600 __FILE__, __LINE__, uarg);
1604 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1606 printk(KERN_DEBUG MYNAM "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
1607 __FILE__, __LINE__, iocnum);
1610 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n",
1613 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1614 maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
1617 max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
1619 /* If fewer than 1 event is requested, there must have
1620 * been some type of error.
1622 if ((max < 1) || !ioc->events)
1625 /* reset this flag so SIGIO can restart */
1626 ioc->aen_event_read_flag=0;
1628 /* Copy the data from kernel memory to user memory
1630 numBytes = max * sizeof(MPT_IOCTL_EVENTS);
1631 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
1632 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventreport - "
1633 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1634 ioc->name, __FILE__, __LINE__, ioc->events);
1641 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1643 mptctl_replace_fw (unsigned long arg)
1645 struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
1646 struct mpt_ioctl_replace_fw karg;
1651 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
1652 printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - "
1653 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1654 __FILE__, __LINE__, uarg);
1658 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1660 printk(KERN_DEBUG MYNAM "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
1661 __FILE__, __LINE__, iocnum);
1665 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_replace_fw called.\n",
1667 /* If caching FW, Free the old FW image
1669 if (ioc->cached_fw == NULL)
1672 mpt_free_fw_memory(ioc);
1674 /* Allocate memory for the new FW image
1676 newFwSize = karg.newImageSize;
1678 if (newFwSize & 0x01)
1680 if (newFwSize & 0x02)
1683 mpt_alloc_fw_memory(ioc, newFwSize);
1684 if (ioc->cached_fw == NULL)
1687 /* Copy the data from user memory to kernel space
1689 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
1690 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - "
1691 "Unable to read in mpt_ioctl_replace_fw image "
1692 "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
1693 mpt_free_fw_memory(ioc);
1697 /* Update IOCFactsReply
1699 ioc->facts.FWImageSize = newFwSize;
1703 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1704 /* MPT IOCTL MPTCOMMAND function.
1705 * Cast the arg into the mpt_ioctl_mpt_command structure.
1708 * Return: 0 if successful
1709 * -EBUSY if previous command timeout and IOC reset is not complete.
1710 * -EFAULT if data unavailable
1711 * -ENODEV if no such device/adapter
1712 * -ETIME if timer expires
1713 * -ENOMEM if memory allocation error
1716 mptctl_mpt_command (unsigned long arg)
1718 struct mpt_ioctl_command __user *uarg = (void __user *) arg;
1719 struct mpt_ioctl_command karg;
1725 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
1726 printk(KERN_ERR MYNAM "%s@%d::mptctl_mpt_command - "
1727 "Unable to read in mpt_ioctl_command struct @ %p\n",
1728 __FILE__, __LINE__, uarg);
1732 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1734 printk(KERN_DEBUG MYNAM "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
1735 __FILE__, __LINE__, iocnum);
1739 rc = mptctl_do_mpt_command (karg, &uarg->MF);
1744 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1745 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1748 * Return: 0 if successful
1749 * -EBUSY if previous command timeout and IOC reset is not complete.
1750 * -EFAULT if data unavailable
1751 * -ENODEV if no such device/adapter
1752 * -ETIME if timer expires
1753 * -ENOMEM if memory allocation error
1754 * -EPERM if SCSI I/O and target is untagged
1757 mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1760 MPT_FRAME_HDR *mf = NULL;
1763 struct buflist bufIn; /* data In buffer */
1764 struct buflist bufOut; /* data Out buffer */
1765 dma_addr_t dma_addr_in;
1766 dma_addr_t dma_addr_out;
1767 int sgSize = 0; /* Num SG elements */
1768 int iocnum, flagsLength;
1773 struct scsi_device *sdev;
1775 /* bufIn and bufOut are used for user to kernel space transfers
1777 bufIn.kptr = bufOut.kptr = NULL;
1778 bufIn.len = bufOut.len = 0;
1780 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1782 printk(KERN_DEBUG MYNAM "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
1783 __FILE__, __LINE__, iocnum);
1787 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
1788 "No memory available during driver init.\n",
1789 __FILE__, __LINE__);
1791 } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) {
1792 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
1793 "Busy with IOC Reset \n", __FILE__, __LINE__);
1797 /* Verify that the final request frame will not be too large.
1799 sz = karg.dataSgeOffset * 4;
1800 if (karg.dataInSize > 0)
1801 sz += sizeof(dma_addr_t) + sizeof(u32);
1802 if (karg.dataOutSize > 0)
1803 sz += sizeof(dma_addr_t) + sizeof(u32);
1805 if (sz > ioc->req_sz) {
1806 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1807 "Request frame too large (%d) maximum (%d)\n",
1808 ioc->name, __FILE__, __LINE__, sz, ioc->req_sz);
1812 /* Get a free request frame and save the message context.
1814 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
1817 hdr = (MPIHeader_t *) mf;
1818 msgContext = le32_to_cpu(hdr->MsgContext);
1819 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1821 /* Copy the request frame
1822 * Reset the saved message context.
1823 * Request frame in user space
1825 if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
1826 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1827 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1828 ioc->name, __FILE__, __LINE__, mfPtr);
1832 hdr->MsgContext = cpu_to_le32(msgContext);
1835 /* Verify that this request is allowed.
1837 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n",
1838 ioc->name, hdr->Function, mf));
1840 switch (hdr->Function) {
1841 case MPI_FUNCTION_IOC_FACTS:
1842 case MPI_FUNCTION_PORT_FACTS:
1843 karg.dataOutSize = karg.dataInSize = 0;
1846 case MPI_FUNCTION_CONFIG:
1848 Config_t *config_frame;
1849 config_frame = (Config_t *)mf;
1850 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\ttype=0x%02x ext_type=0x%02x "
1851 "number=0x%02x action=0x%02x\n", ioc->name,
1852 config_frame->Header.PageType,
1853 config_frame->ExtPageType,
1854 config_frame->Header.PageNumber,
1855 config_frame->Action));
1859 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
1860 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
1861 case MPI_FUNCTION_FW_UPLOAD:
1862 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
1863 case MPI_FUNCTION_FW_DOWNLOAD:
1864 case MPI_FUNCTION_FC_PRIMITIVE_SEND:
1865 case MPI_FUNCTION_TOOLBOX:
1866 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
1869 case MPI_FUNCTION_SCSI_IO_REQUEST:
1871 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1872 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1877 id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
1878 if (pScsiReq->TargetID > id) {
1879 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1880 "Target ID out of bounds. \n",
1881 ioc->name, __FILE__, __LINE__);
1886 if (pScsiReq->Bus >= ioc->number_of_buses) {
1887 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1888 "Target Bus out of bounds. \n",
1889 ioc->name, __FILE__, __LINE__);
1894 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1895 pScsiReq->MsgFlags |= mpt_msg_flags();
1898 /* verify that app has not requested
1899 * more sense data than driver
1900 * can provide, if so, reset this parameter
1901 * set the sense buffer pointer low address
1902 * update the control field to specify Q type
1904 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1905 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1907 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1909 pScsiReq->SenseBufferLowAddr =
1910 cpu_to_le32(ioc->sense_buf_low_dma
1911 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1913 shost_for_each_device(sdev, ioc->sh) {
1914 struct scsi_target *starget = scsi_target(sdev);
1915 VirtTarget *vtarget = starget->hostdata;
1917 if ((pScsiReq->TargetID == vtarget->id) &&
1918 (pScsiReq->Bus == vtarget->channel) &&
1919 (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1920 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1923 /* Have the IOCTL driver set the direction based
1924 * on the dataOutSize (ordering issue with Sparc).
1926 if (karg.dataOutSize > 0) {
1927 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1928 dataSize = karg.dataOutSize;
1930 scsidir = MPI_SCSIIO_CONTROL_READ;
1931 dataSize = karg.dataInSize;
1934 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1935 pScsiReq->DataLength = cpu_to_le32(dataSize);
1937 ioc->ioctl->reset = MPTCTL_RESET_OK;
1938 ioc->ioctl->id = pScsiReq->TargetID;
1941 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1942 "SCSI driver is not loaded. \n",
1943 ioc->name, __FILE__, __LINE__);
1949 case MPI_FUNCTION_SMP_PASSTHROUGH:
1950 /* Check mf->PassthruFlags to determine if
1951 * transfer is ImmediateMode or not.
1952 * Immediate mode returns data in the ReplyFrame.
1953 * Else, we are sending request and response data
1954 * in two SGLs at the end of the mf.
1958 case MPI_FUNCTION_SATA_PASSTHROUGH:
1960 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1961 "SCSI driver is not loaded. \n",
1962 ioc->name, __FILE__, __LINE__);
1968 case MPI_FUNCTION_RAID_ACTION:
1973 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1975 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1976 int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1977 int scsidir = MPI_SCSIIO_CONTROL_READ;
1980 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1981 pScsiReq->MsgFlags |= mpt_msg_flags();
1984 /* verify that app has not requested
1985 * more sense data than driver
1986 * can provide, if so, reset this parameter
1987 * set the sense buffer pointer low address
1988 * update the control field to specify Q type
1990 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1991 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1993 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1995 pScsiReq->SenseBufferLowAddr =
1996 cpu_to_le32(ioc->sense_buf_low_dma
1997 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1999 /* All commands to physical devices are tagged
2002 /* Have the IOCTL driver set the direction based
2003 * on the dataOutSize (ordering issue with Sparc).
2005 if (karg.dataOutSize > 0) {
2006 scsidir = MPI_SCSIIO_CONTROL_WRITE;
2007 dataSize = karg.dataOutSize;
2009 scsidir = MPI_SCSIIO_CONTROL_READ;
2010 dataSize = karg.dataInSize;
2013 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
2014 pScsiReq->DataLength = cpu_to_le32(dataSize);
2016 ioc->ioctl->reset = MPTCTL_RESET_OK;
2017 ioc->ioctl->id = pScsiReq->TargetID;
2019 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2020 "SCSI driver is not loaded. \n",
2021 ioc->name, __FILE__, __LINE__);
2027 case MPI_FUNCTION_SCSI_TASK_MGMT:
2029 MPT_SCSI_HOST *hd = NULL;
2030 if ((ioc->sh == NULL) || ((hd = shost_priv(ioc->sh)) == NULL)) {
2031 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2032 "SCSI driver not loaded or SCSI host not found. \n",
2033 ioc->name, __FILE__, __LINE__);
2036 } else if (mptctl_set_tm_flags(hd) != 0) {
2043 case MPI_FUNCTION_IOC_INIT:
2045 IOCInit_t *pInit = (IOCInit_t *) mf;
2046 u32 high_addr, sense_high;
2048 /* Verify that all entries in the IOC INIT match
2049 * existing setup (and in LE format).
2051 if (sizeof(dma_addr_t) == sizeof(u64)) {
2052 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
2053 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2059 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
2060 (pInit->MaxBuses != ioc->facts.MaxBuses) ||
2061 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
2062 (pInit->HostMfaHighAddr != high_addr) ||
2063 (pInit->SenseBufferHighAddr != sense_high)) {
2064 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2065 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2066 ioc->name, __FILE__, __LINE__);
2074 * MPI_FUNCTION_PORT_ENABLE
2075 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2076 * MPI_FUNCTION_TARGET_ASSIST
2077 * MPI_FUNCTION_TARGET_STATUS_SEND
2078 * MPI_FUNCTION_TARGET_MODE_ABORT
2079 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2080 * MPI_FUNCTION_IO_UNIT_RESET
2081 * MPI_FUNCTION_HANDSHAKE
2082 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2083 * MPI_FUNCTION_EVENT_NOTIFICATION
2084 * (driver handles event notification)
2085 * MPI_FUNCTION_EVENT_ACK
2088 /* What to do with these??? CHECK ME!!!
2089 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2090 MPI_FUNCTION_FC_LINK_SRVC_RSP
2091 MPI_FUNCTION_FC_ABORT
2092 MPI_FUNCTION_LAN_SEND
2093 MPI_FUNCTION_LAN_RECEIVE
2094 MPI_FUNCTION_LAN_RESET
2097 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2098 "Illegal request (function 0x%x) \n",
2099 ioc->name, __FILE__, __LINE__, hdr->Function);
2104 /* Add the SGL ( at most one data in SGE and one data out SGE )
2105 * In the case of two SGE's - the data out (write) will always
2106 * preceede the data in (read) SGE. psgList is used to free the
2109 psge = (char *) (((int *) mf) + karg.dataSgeOffset);
2112 if (karg.dataOutSize > 0)
2115 if (karg.dataInSize > 0)
2120 /* Set up the dataOut memory allocation */
2121 if (karg.dataOutSize > 0) {
2122 if (karg.dataInSize > 0) {
2123 flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2124 MPI_SGE_FLAGS_END_OF_BUFFER |
2125 MPI_SGE_FLAGS_DIRECTION |
2127 << MPI_SGE_FLAGS_SHIFT;
2129 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
2131 flagsLength |= karg.dataOutSize;
2132 bufOut.len = karg.dataOutSize;
2133 bufOut.kptr = pci_alloc_consistent(
2134 ioc->pcidev, bufOut.len, &dma_addr_out);
2136 if (bufOut.kptr == NULL) {
2141 * Copy to MF and to sglbuf
2143 mpt_add_sge(psge, flagsLength, dma_addr_out);
2144 psge += (sizeof(u32) + sizeof(dma_addr_t));
2146 /* Copy user data to kernel space.
2148 if (copy_from_user(bufOut.kptr,
2151 printk(MYIOC_s_ERR_FMT
2152 "%s@%d::mptctl_do_mpt_command - Unable "
2153 "to read user data "
2155 ioc->name, __FILE__, __LINE__,karg.dataOutBufPtr);
2162 if (karg.dataInSize > 0) {
2163 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2164 flagsLength |= karg.dataInSize;
2166 bufIn.len = karg.dataInSize;
2167 bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
2168 bufIn.len, &dma_addr_in);
2170 if (bufIn.kptr == NULL) {
2175 * Copy to MF and to sglbuf
2177 mpt_add_sge(psge, flagsLength, dma_addr_in);
2183 mpt_add_sge(psge, flagsLength, (dma_addr_t) -1);
2186 ioc->ioctl->wait_done = 0;
2187 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
2189 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
2191 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
2192 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
2193 mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
2195 rc =mpt_send_handshake_request(mptctl_id, ioc,
2196 sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
2198 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2199 "_send_handshake FAILED! (ioc %p, mf %p)\n",
2200 ioc->name, ioc, mf));
2201 mptctl_free_tm_flags(ioc);
2208 mpt_put_msg_frame(mptctl_id, ioc, mf);
2210 /* Now wait for the command to complete */
2211 timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
2212 timeout = wait_event_timeout(mptctl_wait,
2213 ioc->ioctl->wait_done == 1,
2216 if(timeout <=0 && (ioc->ioctl->wait_done != 1 )) {
2217 /* Now we need to reset the board */
2219 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT)
2220 mptctl_free_tm_flags(ioc);
2222 mptctl_timeout_expired(ioc->ioctl);
2229 /* If a valid reply frame, copy to the user.
2230 * Offset 2: reply length in U32's
2232 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) {
2233 if (karg.maxReplyBytes < ioc->reply_sz) {
2234 sz = min(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]);
2236 sz = min(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]);
2240 if (copy_to_user(karg.replyFrameBufPtr,
2241 &ioc->ioctl->ReplyFrame, sz)){
2242 printk(MYIOC_s_ERR_FMT
2243 "%s@%d::mptctl_do_mpt_command - "
2244 "Unable to write out reply frame %p\n",
2245 ioc->name, __FILE__, __LINE__, karg.replyFrameBufPtr);
2252 /* If valid sense data, copy to user.
2254 if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) {
2255 sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
2257 if (copy_to_user(karg.senseDataPtr, ioc->ioctl->sense, sz)) {
2258 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2259 "Unable to write sense data to user %p\n",
2260 ioc->name, __FILE__, __LINE__,
2268 /* If the overall status is _GOOD and data in, copy data
2271 if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) &&
2272 (karg.dataInSize > 0) && (bufIn.kptr)) {
2274 if (copy_to_user(karg.dataInBufPtr,
2275 bufIn.kptr, karg.dataInSize)) {
2276 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2277 "Unable to write data to user %p\n",
2278 ioc->name, __FILE__, __LINE__,
2286 ioc->ioctl->status &= ~(MPT_IOCTL_STATUS_COMMAND_GOOD |
2287 MPT_IOCTL_STATUS_SENSE_VALID |
2288 MPT_IOCTL_STATUS_RF_VALID );
2290 /* Free the allocated memory.
2292 if (bufOut.kptr != NULL) {
2293 pci_free_consistent(ioc->pcidev,
2294 bufOut.len, (void *) bufOut.kptr, dma_addr_out);
2297 if (bufIn.kptr != NULL) {
2298 pci_free_consistent(ioc->pcidev,
2299 bufIn.len, (void *) bufIn.kptr, dma_addr_in);
2302 /* mf is null if command issued successfully
2303 * otherwise, failure occured after mf acquired.
2306 mpt_free_msg_frame(ioc, mf);
2311 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2312 /* Prototype Routine for the HOST INFO command.
2315 * Return: 0 if successful
2316 * -EFAULT if data unavailable
2317 * -EBUSY if previous command timeout and IOC reset is not complete.
2318 * -ENODEV if no such device/adapter
2319 * -ETIME if timer expires
2320 * -ENOMEM if memory allocation error
2323 mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2325 hp_host_info_t __user *uarg = (void __user *) arg;
2327 struct pci_dev *pdev;
2330 hp_host_info_t karg;
2332 ConfigPageHeader_t hdr;
2335 ToolboxIstwiReadWriteRequest_t *IstwiRWRequest;
2336 MPT_FRAME_HDR *mf = NULL;
2337 MPIHeader_t *mpi_hdr;
2339 /* Reset long to int. Should affect IA64 and SPARC only
2341 if (data_size == sizeof(hp_host_info_t))
2343 else if (data_size == sizeof(hp_host_info_rev0_t))
2344 cim_rev = 0; /* obsolete */
2348 if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
2349 printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_host_info - "
2350 "Unable to read in hp_host_info struct @ %p\n",
2351 __FILE__, __LINE__, uarg);
2355 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2357 printk(KERN_DEBUG MYNAM "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
2358 __FILE__, __LINE__, iocnum);
2361 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n",
2364 /* Fill in the data and return the structure to the calling
2367 pdev = (struct pci_dev *) ioc->pcidev;
2369 karg.vendor = pdev->vendor;
2370 karg.device = pdev->device;
2371 karg.subsystem_id = pdev->subsystem_device;
2372 karg.subsystem_vendor = pdev->subsystem_vendor;
2373 karg.devfn = pdev->devfn;
2374 karg.bus = pdev->bus->number;
2376 /* Save the SCSI host no. if
2377 * SCSI driver loaded
2379 if (ioc->sh != NULL)
2380 karg.host_no = ioc->sh->host_no;
2384 /* Reformat the fw_version into a string
2386 karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
2387 ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
2388 karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
2389 karg.fw_version[2] = '.';
2390 karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
2391 ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
2392 karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
2393 karg.fw_version[5] = '.';
2394 karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
2395 ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
2396 karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
2397 karg.fw_version[8] = '.';
2398 karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
2399 ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
2400 karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
2401 karg.fw_version[11] = '\0';
2403 /* Issue a config request to get the device serial number
2405 hdr.PageVersion = 0;
2408 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2409 cfg.cfghdr.hdr = &hdr;
2412 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2413 cfg.dir = 0; /* read */
2416 strncpy(karg.serial_number, " ", 24);
2417 if (mpt_config(ioc, &cfg) == 0) {
2418 if (cfg.cfghdr.hdr->PageLength > 0) {
2419 /* Issue the second config page request */
2420 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2422 pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
2424 cfg.physAddr = buf_dma;
2425 if (mpt_config(ioc, &cfg) == 0) {
2426 ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
2427 if (strlen(pdata->BoardTracerNumber) > 1) {
2428 strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
2429 karg.serial_number[24-1]='\0';
2432 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
2437 rc = mpt_GetIocState(ioc, 1);
2439 case MPI_IOC_STATE_OPERATIONAL:
2440 karg.ioc_status = HP_STATUS_OK;
2443 case MPI_IOC_STATE_FAULT:
2444 karg.ioc_status = HP_STATUS_FAILED;
2447 case MPI_IOC_STATE_RESET:
2448 case MPI_IOC_STATE_READY:
2450 karg.ioc_status = HP_STATUS_OTHER;
2454 karg.base_io_addr = pci_resource_start(pdev, 0);
2456 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2457 karg.bus_phys_width = HP_BUS_WIDTH_UNK;
2459 karg.bus_phys_width = HP_BUS_WIDTH_16;
2461 karg.hard_resets = 0;
2462 karg.soft_resets = 0;
2464 if (ioc->sh != NULL) {
2465 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
2467 if (hd && (cim_rev == 1)) {
2468 karg.hard_resets = hd->hard_resets;
2469 karg.soft_resets = hd->soft_resets;
2470 karg.timeouts = hd->timeouts;
2475 * Gather ISTWI(Industry Standard Two Wire Interface) Data
2477 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
2478 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
2479 ioc->name,__func__));
2483 IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
2484 mpi_hdr = (MPIHeader_t *) mf;
2485 memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
2486 IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
2487 IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
2488 IstwiRWRequest->MsgContext = mpi_hdr->MsgContext;
2489 IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
2490 IstwiRWRequest->NumAddressBytes = 0x01;
2491 IstwiRWRequest->DataLength = cpu_to_le16(0x04);
2492 if (pdev->devfn & 1)
2493 IstwiRWRequest->DeviceAddr = 0xB2;
2495 IstwiRWRequest->DeviceAddr = 0xB0;
2497 pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
2500 mpt_add_sge((char *)&IstwiRWRequest->SGL,
2501 (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
2503 ioc->ioctl->wait_done = 0;
2504 mpt_put_msg_frame(mptctl_id, ioc, mf);
2506 rc = wait_event_timeout(mptctl_wait,
2507 ioc->ioctl->wait_done == 1,
2508 HZ*MPT_IOCTL_DEFAULT_TIMEOUT /* 10 sec */);
2510 if(rc <=0 && (ioc->ioctl->wait_done != 1 )) {
2512 * Now we need to reset the board
2514 mpt_free_msg_frame(ioc, mf);
2515 mptctl_timeout_expired(ioc->ioctl);
2520 *ISTWI Data Definition
2521 * pbuf[0] = FW_VERSION = 0x4
2522 * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
2523 * the config, you should be seeing one out of these three values
2524 * pbuf[2] = Drive Installed Map = bit pattern depend on which
2525 * bays have drives in them
2526 * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
2528 if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID)
2529 karg.rsvd = *(u32 *)pbuf;
2533 pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
2535 /* Copy the data from kernel memory to user memory
2537 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
2538 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hpgethostinfo - "
2539 "Unable to write out hp_host_info @ %p\n",
2540 ioc->name, __FILE__, __LINE__, uarg);
2548 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2549 /* Prototype Routine for the TARGET INFO command.
2552 * Return: 0 if successful
2553 * -EFAULT if data unavailable
2554 * -EBUSY if previous command timeout and IOC reset is not complete.
2555 * -ENODEV if no such device/adapter
2556 * -ETIME if timer expires
2557 * -ENOMEM if memory allocation error
2560 mptctl_hp_targetinfo(unsigned long arg)
2562 hp_target_info_t __user *uarg = (void __user *) arg;
2563 SCSIDevicePage0_t *pg0_alloc;
2564 SCSIDevicePage3_t *pg3_alloc;
2566 MPT_SCSI_HOST *hd = NULL;
2567 hp_target_info_t karg;
2570 dma_addr_t page_dma;
2572 ConfigPageHeader_t hdr;
2573 int tmp, np, rc = 0;
2575 if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
2576 printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_targetinfo - "
2577 "Unable to read in hp_host_targetinfo struct @ %p\n",
2578 __FILE__, __LINE__, uarg);
2582 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2584 printk(KERN_DEBUG MYNAM "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
2585 __FILE__, __LINE__, iocnum);
2588 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
2591 /* There is nothing to do for FCP parts.
2593 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2596 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
2599 if (ioc->sh->host_no != karg.hdr.host)
2602 /* Get the data transfer speeds
2604 data_sz = ioc->spi_data.sdp0length * 4;
2605 pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2607 hdr.PageVersion = ioc->spi_data.sdp0version;
2608 hdr.PageLength = data_sz;
2610 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2612 cfg.cfghdr.hdr = &hdr;
2613 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2616 cfg.physAddr = page_dma;
2618 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2620 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2621 np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
2622 karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
2623 HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
2625 if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
2626 tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
2628 karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
2629 else if (tmp <= 0x09)
2630 karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
2631 else if (tmp <= 0x0A)
2632 karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
2633 else if (tmp <= 0x0C)
2634 karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
2635 else if (tmp <= 0x25)
2636 karg.negotiated_speed = HP_DEV_SPEED_FAST;
2638 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2640 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2643 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
2648 karg.message_rejects = -1;
2649 karg.phase_errors = -1;
2650 karg.parity_errors = -1;
2651 karg.select_timeouts = -1;
2653 /* Get the target error parameters
2655 hdr.PageVersion = 0;
2658 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2660 cfg.cfghdr.hdr = &hdr;
2661 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2665 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2666 /* Issue the second config page request */
2667 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2668 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2669 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
2670 ioc->pcidev, data_sz, &page_dma);
2672 cfg.physAddr = page_dma;
2673 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2674 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2675 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
2676 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
2677 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
2679 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
2682 hd = shost_priv(ioc->sh);
2684 karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
2686 /* Copy the data from kernel memory to user memory
2688 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
2689 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hp_target_info - "
2690 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2691 ioc->name, __FILE__, __LINE__, uarg);
2698 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2700 static const struct file_operations mptctl_fops = {
2701 .owner = THIS_MODULE,
2702 .llseek = no_llseek,
2703 .fasync = mptctl_fasync,
2704 .unlocked_ioctl = mptctl_ioctl,
2705 #ifdef CONFIG_COMPAT
2706 .compat_ioctl = compat_mpctl_ioctl,
2710 static struct miscdevice mptctl_miscdev = {
2716 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2718 #ifdef CONFIG_COMPAT
2721 compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
2724 struct mpt_fw_xfer32 kfw32;
2725 struct mpt_fw_xfer kfw;
2726 MPT_ADAPTER *iocp = NULL;
2727 int iocnum, iocnumX;
2728 int nonblock = (filp->f_flags & O_NONBLOCK);
2732 if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
2735 /* Verify intended MPT adapter */
2736 iocnumX = kfw32.iocnum & 0xFF;
2737 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2739 printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2744 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2747 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mptfwxfer_ioctl() called\n",
2749 kfw.iocnum = iocnum;
2750 kfw.fwlen = kfw32.fwlen;
2751 kfw.bufp = compat_ptr(kfw32.bufp);
2753 ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
2755 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2761 compat_mpt_command(struct file *filp, unsigned int cmd,
2764 struct mpt_ioctl_command32 karg32;
2765 struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
2766 struct mpt_ioctl_command karg;
2767 MPT_ADAPTER *iocp = NULL;
2768 int iocnum, iocnumX;
2769 int nonblock = (filp->f_flags & O_NONBLOCK);
2772 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
2775 /* Verify intended MPT adapter */
2776 iocnumX = karg32.hdr.iocnum & 0xFF;
2777 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2779 printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
2784 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2787 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mpt_command() called\n",
2789 /* Copy data to karg */
2790 karg.hdr.iocnum = karg32.hdr.iocnum;
2791 karg.hdr.port = karg32.hdr.port;
2792 karg.timeout = karg32.timeout;
2793 karg.maxReplyBytes = karg32.maxReplyBytes;
2795 karg.dataInSize = karg32.dataInSize;
2796 karg.dataOutSize = karg32.dataOutSize;
2797 karg.maxSenseBytes = karg32.maxSenseBytes;
2798 karg.dataSgeOffset = karg32.dataSgeOffset;
2800 karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
2801 karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
2802 karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
2803 karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
2805 /* Pass new structure to do_mpt_command
2807 ret = mptctl_do_mpt_command (karg, &uarg->MF);
2809 mutex_unlock(&iocp->ioctl->ioctl_mutex);
2814 static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2824 case MPTEVENTENABLE:
2825 case MPTEVENTREPORT:
2827 case HP_GETHOSTINFO:
2828 case HP_GETTARGETINFO:
2830 ret = __mptctl_ioctl(f, cmd, arg);
2833 ret = compat_mpt_command(f, cmd, arg);
2835 case MPTFWDOWNLOAD32:
2836 ret = compat_mptfwxfer_ioctl(f, cmd, arg);
2849 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2851 * mptctl_probe - Installs ioctl devices per bus.
2852 * @pdev: Pointer to pci_dev structure
2854 * Returns 0 for success, non-zero for failure.
2859 mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2862 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2865 * Allocate and inite a MPT_IOCTL structure
2867 mem = kzalloc(sizeof(MPT_IOCTL), GFP_KERNEL);
2869 mptctl_remove(pdev);
2874 ioc->ioctl->ioc = ioc;
2875 mutex_init(&ioc->ioctl->ioctl_mutex);
2879 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2881 * mptctl_remove - Removed ioctl devices
2882 * @pdev: Pointer to pci_dev structure
2887 mptctl_remove(struct pci_dev *pdev)
2889 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2891 kfree ( ioc->ioctl );
2894 static struct mpt_pci_driver mptctl_driver = {
2895 .probe = mptctl_probe,
2896 .remove = mptctl_remove,
2899 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2900 static int __init mptctl_init(void)
2905 show_mptmod_ver(my_NAME, my_VERSION);
2907 mpt_device_driver_register(&mptctl_driver, MPTCTL_DRIVER);
2909 /* Register this device */
2910 err = misc_register(&mptctl_miscdev);
2912 printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
2915 printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
2916 printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
2917 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2920 * Install our handler
2923 mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER);
2924 if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) {
2925 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2926 misc_deregister(&mptctl_miscdev);
2931 mpt_reset_register(mptctl_id, mptctl_ioc_reset);
2932 mpt_event_register(mptctl_id, mptctl_event_process);
2938 mpt_device_driver_deregister(MPTCTL_DRIVER);
2943 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2944 static void mptctl_exit(void)
2946 misc_deregister(&mptctl_miscdev);
2947 printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
2948 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2950 /* De-register reset handler from base module */
2951 mpt_reset_deregister(mptctl_id);
2953 /* De-register callback handler from base module */
2954 mpt_deregister(mptctl_id);
2956 mpt_device_driver_deregister(MPTCTL_DRIVER);
2960 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2962 module_init(mptctl_init);
2963 module_exit(mptctl_exit);