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;
87 static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS;
89 static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
91 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
99 * Function prototypes. Called from OS entry point mptctl_ioctl.
100 * arg contents specific to function.
102 static int mptctl_fw_download(unsigned long arg);
103 static int mptctl_getiocinfo(unsigned long arg, unsigned int cmd);
104 static int mptctl_gettargetinfo(unsigned long arg);
105 static int mptctl_readtest(unsigned long arg);
106 static int mptctl_mpt_command(unsigned long arg);
107 static int mptctl_eventquery(unsigned long arg);
108 static int mptctl_eventenable(unsigned long arg);
109 static int mptctl_eventreport(unsigned long arg);
110 static int mptctl_replace_fw(unsigned long arg);
112 static int mptctl_do_reset(unsigned long arg);
113 static int mptctl_hp_hostinfo(unsigned long arg, unsigned int cmd);
114 static int mptctl_hp_targetinfo(unsigned long arg);
116 static int mptctl_probe(struct pci_dev *, const struct pci_device_id *);
117 static void mptctl_remove(struct pci_dev *);
120 static long compat_mpctl_ioctl(struct file *f, unsigned cmd, unsigned long arg);
123 * Private function calls.
125 static int mptctl_do_mpt_command(struct mpt_ioctl_command karg, void __user *mfPtr);
126 static int mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen);
127 static MptSge_t *kbuf_alloc_2_sgl(int bytes, u32 dir, int sge_offset, int *frags,
128 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);
129 static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma,
130 struct buflist *buflist, MPT_ADAPTER *ioc);
131 static int mptctl_bus_reset(MPT_ADAPTER *ioc, u8 function);
134 * Reset Handler cleanup function
136 static int mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase);
139 * Event Handler function
141 static int mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
142 static struct fasync_struct *async_queue=NULL;
144 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
146 * Scatter gather list (SGL) sizes and limits...
148 //#define MAX_SCSI_FRAGS 9
149 #define MAX_FRAGS_SPILL1 9
150 #define MAX_FRAGS_SPILL2 15
151 #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1)
153 //#define MAX_CHAIN_FRAGS 64
154 //#define MAX_CHAIN_FRAGS (15+15+15+16)
155 #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1)
157 // Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each)
158 // Works out to: 592d bytes! (9+1)*8 + 4*(15+1)*8
159 // ^----------------- 80 + 512
160 #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)
162 /* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */
163 #define MAX_KMALLOC_SZ (128*1024)
165 #define MPT_IOCTL_DEFAULT_TIMEOUT 10 /* Default timeout value (seconds) */
167 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
169 * mptctl_syscall_down - Down the MPT adapter syscall semaphore.
170 * @ioc: Pointer to MPT adapter
171 * @nonblock: boolean, non-zero if O_NONBLOCK is set
173 * All of the ioctl commands can potentially sleep, which is illegal
174 * with a spinlock held, thus we perform mutual exclusion here.
176 * Returns negative errno on error, or zero for success.
179 mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock)
184 if (!mutex_trylock(&ioc->ioctl_cmds.mutex))
187 if (mutex_lock_interruptible(&ioc->ioctl_cmds.mutex))
193 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
195 * This is the callback for any message we have posted. The message itself
196 * will be returned to the message pool when we return from the IRQ
198 * This runs in irq context so be short and sweet.
201 mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
210 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "completing mpi function "
211 "(0x%02X), req=%p, reply=%p\n", ioc->name, req->u.hdr.Function,
215 * Handling continuation of the same reply. Processing the first
216 * reply, and eating the other replys that come later.
218 if (ioc->ioctl_cmds.msg_context != req->u.hdr.MsgContext)
219 goto out_continuation;
221 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
226 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
227 sz = min(ioc->reply_sz, 4*reply->u.reply.MsgLength);
228 memcpy(ioc->ioctl_cmds.reply, reply, sz);
230 if (reply->u.reply.IOCStatus || reply->u.reply.IOCLogInfo)
231 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
232 "iocstatus (0x%04X), loginfo (0x%08X)\n", ioc->name,
233 le16_to_cpu(reply->u.reply.IOCStatus),
234 le32_to_cpu(reply->u.reply.IOCLogInfo)));
236 if ((req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) ||
237 (req->u.hdr.Function ==
238 MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
240 if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
241 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
242 "scsi_status (0x%02x), scsi_state (0x%02x), "
243 "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name,
244 reply->u.sreply.SCSIStatus,
245 reply->u.sreply.SCSIState,
246 le16_to_cpu(reply->u.sreply.TaskTag),
247 le32_to_cpu(reply->u.sreply.TransferCount)));
249 if (reply->u.sreply.SCSIState &
250 MPI_SCSI_STATE_AUTOSENSE_VALID) {
251 sz = req->u.scsireq.SenseBufferLength;
253 le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
254 sense_data = ((u8 *)ioc->sense_buf_pool +
255 (req_index * MPT_SENSE_BUFFER_ALLOC));
256 memcpy(ioc->ioctl_cmds.sense, sense_data, sz);
257 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_SENSE_VALID;
262 /* We are done, issue wake up
264 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
265 if (req->u.hdr.Function == MPI_FUNCTION_SCSI_TASK_MGMT)
266 mpt_clear_taskmgmt_in_progress_flag(ioc);
267 ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
268 complete(&ioc->ioctl_cmds.done);
272 if (reply && (reply->u.reply.MsgFlags &
273 MPI_MSGFLAGS_CONTINUATION_REPLY))
278 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
279 /* mptctl_timeout_expired
281 * Expecting an interrupt, however timed out.
285 mptctl_timeout_expired(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
289 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": %s\n",
290 ioc->name, __func__));
292 if (mpt_fwfault_debug)
293 mpt_halt_firmware(ioc);
295 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
296 if (ioc->ioc_reset_in_progress) {
297 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
298 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
299 mpt_free_msg_frame(ioc, mf);
302 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
305 if (!mptctl_bus_reset(ioc, mf->u.hdr.Function))
308 /* Issue a reset for this device.
309 * The IOC is not responding.
311 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
313 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
314 mpt_HardResetHandler(ioc, CAN_SLEEP);
315 mpt_free_msg_frame(ioc, mf);
319 mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
324 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
325 "TaskMgmt completed (mf=%p, mr=%p)\n",
328 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
333 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
334 memcpy(ioc->taskmgmt_cmds.reply, mr,
335 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
337 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
338 mpt_clear_taskmgmt_in_progress_flag(ioc);
339 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
340 complete(&ioc->taskmgmt_cmds.done);
351 static int mptctl_bus_reset(MPT_ADAPTER *ioc, u8 function)
354 SCSITaskMgmt_t *pScsiTm;
355 SCSITaskMgmtReply_t *pScsiTmReply;
358 unsigned long timeout;
359 unsigned long time_count;
362 /* bus reset is only good for SCSI IO, RAID PASSTHRU */
363 if (!(function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) ||
364 (function == MPI_FUNCTION_SCSI_IO_REQUEST)) {
365 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
366 "TaskMgmt, not SCSI_IO!!\n", ioc->name));
370 mutex_lock(&ioc->taskmgmt_cmds.mutex);
371 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
372 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
380 mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc);
382 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
383 "TaskMgmt, no msg frames!!\n", ioc->name));
384 mpt_clear_taskmgmt_in_progress_flag(ioc);
386 goto mptctl_bus_reset_done;
389 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
392 pScsiTm = (SCSITaskMgmt_t *) mf;
393 memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
394 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
395 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
396 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
397 pScsiTm->TargetID = 0;
399 pScsiTm->ChainOffset = 0;
400 pScsiTm->Reserved = 0;
401 pScsiTm->Reserved1 = 0;
402 pScsiTm->TaskMsgContext = 0;
403 for (ii= 0; ii < 8; ii++)
404 pScsiTm->LUN[ii] = 0;
405 for (ii=0; ii < 7; ii++)
406 pScsiTm->Reserved2[ii] = 0;
408 switch (ioc->bus_type) {
421 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
422 "TaskMgmt type=%d timeout=%ld\n",
423 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout));
425 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
426 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
427 time_count = jiffies;
428 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
429 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
430 mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf);
432 retval = mpt_send_handshake_request(mptctl_taskmgmt_id, ioc,
433 sizeof(SCSITaskMgmt_t), (u32 *)pScsiTm, CAN_SLEEP);
435 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
436 "TaskMgmt send_handshake FAILED!"
437 " (ioc %p, mf %p, rc=%d) \n", ioc->name,
439 mpt_clear_taskmgmt_in_progress_flag(ioc);
440 goto mptctl_bus_reset_done;
444 /* Now wait for the command to complete */
445 ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
446 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
447 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
448 "TaskMgmt failed\n", ioc->name));
449 mpt_free_msg_frame(ioc, mf);
450 mpt_clear_taskmgmt_in_progress_flag(ioc);
451 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
454 retval = -1; /* return failure */
455 goto mptctl_bus_reset_done;
458 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
459 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
460 "TaskMgmt failed\n", ioc->name));
461 retval = -1; /* return failure */
462 goto mptctl_bus_reset_done;
465 pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
466 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
467 "TaskMgmt fw_channel = %d, fw_id = %d, task_type=0x%02X, "
468 "iocstatus=0x%04X\n\tloginfo=0x%08X, response_code=0x%02X, "
469 "term_cmnds=%d\n", ioc->name, pScsiTmReply->Bus,
470 pScsiTmReply->TargetID, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
471 le16_to_cpu(pScsiTmReply->IOCStatus),
472 le32_to_cpu(pScsiTmReply->IOCLogInfo),
473 pScsiTmReply->ResponseCode,
474 le32_to_cpu(pScsiTmReply->TerminationCount)));
476 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
478 if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
479 iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED ||
480 iocstatus == MPI_IOCSTATUS_SUCCESS)
483 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
484 "TaskMgmt failed\n", ioc->name));
485 retval = -1; /* return failure */
489 mptctl_bus_reset_done:
490 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
491 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
496 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
499 * Clean-up functionality. Used only if there has been a
500 * reload of the FW due.
504 mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
506 switch(reset_phase) {
507 case MPT_IOC_SETUP_RESET:
508 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
509 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
511 case MPT_IOC_PRE_RESET:
512 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
513 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
515 case MPT_IOC_POST_RESET:
516 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
517 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
518 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
519 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
520 complete(&ioc->ioctl_cmds.done);
530 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
531 /* ASYNC Event Notification Support */
533 mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
537 event = le32_to_cpu(pEvReply->Event) & 0xFF;
539 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n",
540 ioc->name, __func__));
541 if(async_queue == NULL)
544 /* Raise SIGIO for persistent events.
545 * TODO - this define is not in MPI spec yet,
546 * but they plan to set it to 0x21
548 if (event == 0x21 ) {
549 ioc->aen_event_read_flag=1;
550 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Raised SIGIO to application\n",
552 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
553 "Raised SIGIO to application\n", ioc->name));
554 kill_fasync(&async_queue, SIGIO, POLL_IN);
558 /* This flag is set after SIGIO was raised, and
559 * remains set until the application has read
560 * the event log via ioctl=MPTEVENTREPORT
562 if(ioc->aen_event_read_flag)
565 /* Signal only for the events that are
566 * requested for by the application
568 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
569 ioc->aen_event_read_flag=1;
570 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
571 "Raised SIGIO to application\n", ioc->name));
572 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
573 "Raised SIGIO to application\n", ioc->name));
574 kill_fasync(&async_queue, SIGIO, POLL_IN);
580 mptctl_release(struct inode *inode, struct file *filep)
582 fasync_helper(-1, filep, 0, &async_queue);
587 mptctl_fasync(int fd, struct file *filep, int mode)
593 list_for_each_entry(ioc, &ioc_list, list)
594 ioc->aen_event_read_flag=0;
596 ret = fasync_helper(fd, filep, mode, &async_queue);
601 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
604 * cmd - specify the particular IOCTL command to be issued
605 * arg - data specific to the command. Must not be null.
608 __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
610 mpt_ioctl_header __user *uhdr = (void __user *) arg;
611 mpt_ioctl_header khdr;
614 int nonblock = (file->f_flags & O_NONBLOCK);
616 MPT_ADAPTER *iocp = NULL;
618 if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
619 printk(KERN_ERR MYNAM "%s::mptctl_ioctl() @%d - "
620 "Unable to copy mpt_ioctl_header data @ %p\n",
621 __FILE__, __LINE__, uhdr);
624 ret = -ENXIO; /* (-6) No such device or address */
626 /* Verify intended MPT adapter - set iocnum and the adapter
629 iocnumX = khdr.iocnum & 0xFF;
630 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
635 printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - Controller disabled.\n",
640 /* Handle those commands that are just returning
641 * information stored in the driver.
642 * These commands should never time out and are unaffected
643 * by TM and FW reloads.
645 if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
646 return mptctl_getiocinfo(arg, _IOC_SIZE(cmd));
647 } else if (cmd == MPTTARGETINFO) {
648 return mptctl_gettargetinfo(arg);
649 } else if (cmd == MPTTEST) {
650 return mptctl_readtest(arg);
651 } else if (cmd == MPTEVENTQUERY) {
652 return mptctl_eventquery(arg);
653 } else if (cmd == MPTEVENTENABLE) {
654 return mptctl_eventenable(arg);
655 } else if (cmd == MPTEVENTREPORT) {
656 return mptctl_eventreport(arg);
657 } else if (cmd == MPTFWREPLACE) {
658 return mptctl_replace_fw(arg);
661 /* All of these commands require an interrupt or
662 * are unknown/illegal.
664 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
667 if (cmd == MPTFWDOWNLOAD)
668 ret = mptctl_fw_download(arg);
669 else if (cmd == MPTCOMMAND)
670 ret = mptctl_mpt_command(arg);
671 else if (cmd == MPTHARDRESET)
672 ret = mptctl_do_reset(arg);
673 else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
674 ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
675 else if (cmd == HP_GETTARGETINFO)
676 ret = mptctl_hp_targetinfo(arg);
680 mutex_unlock(&iocp->ioctl_cmds.mutex);
686 mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
690 ret = __mptctl_ioctl(file, cmd, arg);
695 static int mptctl_do_reset(unsigned long arg)
697 struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
698 struct mpt_ioctl_diag_reset krinfo;
701 if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
702 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_reset - "
703 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
704 __FILE__, __LINE__, urinfo);
708 if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
709 printk(KERN_DEBUG MYNAM "%s@%d::mptctl_do_reset - ioc%d not found!\n",
710 __FILE__, __LINE__, krinfo.hdr.iocnum);
711 return -ENODEV; /* (-6) No such device or address */
714 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "mptctl_do_reset called.\n",
717 if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
718 printk (MYIOC_s_ERR_FMT "%s@%d::mptctl_do_reset - reset failed.\n",
719 iocp->name, __FILE__, __LINE__);
726 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
728 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
729 * This structure contains: iocnum, firmware length (bytes),
730 * pointer to user space memory where the fw image is stored.
733 * Return: 0 if successful
734 * -EFAULT if data unavailable
735 * -ENXIO if no such device
736 * -EAGAIN if resource problem
737 * -ENOMEM if no memory for SGE
738 * -EMLINK if too many chain buffers required
739 * -EBADRQC if adapter does not support FW download
740 * -EBUSY if adapter is busy
741 * -ENOMSG if FW upload returned bad status
744 mptctl_fw_download(unsigned long arg)
746 struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
747 struct mpt_fw_xfer kfwdl;
749 if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
750 printk(KERN_ERR MYNAM "%s@%d::_ioctl_fwdl - "
751 "Unable to copy mpt_fw_xfer struct @ %p\n",
752 __FILE__, __LINE__, ufwdl);
756 return mptctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);
759 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
761 * FW Download engine.
763 * Return: 0 if successful
764 * -EFAULT if data unavailable
765 * -ENXIO if no such device
766 * -EAGAIN if resource problem
767 * -ENOMEM if no memory for SGE
768 * -EMLINK if too many chain buffers required
769 * -EBADRQC if adapter does not support FW download
770 * -EBUSY if adapter is busy
771 * -ENOMSG if FW upload returned bad status
774 mptctl_do_fw_download(int ioc, char __user *ufwbuf, size_t fwlen)
779 FWDownloadTCSGE_t *ptsge;
780 MptSge_t *sgl, *sgIn;
782 struct buflist *buflist;
791 int fw_bytes_copied = 0;
795 pFWDownloadReply_t ReplyMsg = NULL;
796 unsigned long timeleft;
798 if (mpt_verify_adapter(ioc, &iocp) < 0) {
799 printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n",
801 return -ENODEV; /* (-6) No such device or address */
804 /* Valid device. Get a message frame and construct the FW download message.
806 if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
810 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT
811 "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id));
812 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.bufp = %p\n",
813 iocp->name, ufwbuf));
814 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.fwlen = %d\n",
815 iocp->name, (int)fwlen));
816 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.ioc = %04xh\n",
819 dlmsg = (FWDownload_t*) mf;
820 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
821 sgOut = (char *) (ptsge + 1);
824 * Construct f/w download request
826 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
828 dlmsg->ChainOffset = 0;
829 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
830 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
831 if (iocp->facts.MsgVersion >= MPI_VERSION_01_05)
832 dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT;
837 /* Set up the Transaction SGE.
840 ptsge->ContextSize = 0;
841 ptsge->DetailsLength = 12;
842 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
843 ptsge->Reserved_0100_Checksum = 0;
844 ptsge->ImageOffset = 0;
845 ptsge->ImageSize = cpu_to_le32(fwlen);
851 * Need to kmalloc area(s) for holding firmware image bytes.
852 * But we need to do it piece meal, using a proper
853 * scatter gather list (with 128kB MAX hunks).
855 * A practical limit here might be # of sg hunks that fit into
856 * a single IOC request frame; 12 or 8 (see below), so:
857 * For FC9xx: 12 x 128kB == 1.5 mB (max)
858 * For C1030: 8 x 128kB == 1 mB (max)
859 * We could support chaining, but things get ugly(ier:)
861 * Set the sge_offset to the start of the sgl (bytes).
863 sgdir = 0x04000000; /* IOC will READ from sys mem */
864 sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
865 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
866 &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
870 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
871 * for FC9xx f/w image, but calculate max number of sge hunks
872 * we can fit into a request frame, and limit ourselves to that.
873 * (currently no chain support)
874 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
880 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) -
881 sizeof(FWDownloadTCSGE_t))
883 if (numfrags > maxfrags) {
888 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n",
889 iocp->name, sgl, numfrags));
892 * Parse SG list, copying sgl itself,
893 * plus f/w image hunks from user space as we go...
898 for (i=0; i < numfrags; i++) {
900 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
901 * Skip everything but Simple. If simple, copy from
902 * user space into kernel space.
903 * Note: we should not have anything but Simple as
904 * Chain SGE are illegal.
906 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
907 if (nib == 0 || nib == 3) {
909 } else if (sgIn->Address) {
910 iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
912 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
913 printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - "
914 "Unable to copy f/w buffer hunk#%d @ %p\n",
915 iocp->name, __FILE__, __LINE__, n, ufwbuf);
918 fw_bytes_copied += bl->len;
922 sgOut += iocp->SGE_size;
925 DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags);
928 * Finally, perform firmware download.
931 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->MsgContext);
932 INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status)
933 mpt_put_msg_frame(mptctl_id, iocp, mf);
935 /* Now wait for the command to complete */
937 timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60);
938 if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
940 printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
941 if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
942 mpt_free_msg_frame(iocp, mf);
946 mptctl_timeout_expired(iocp, mf);
952 if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
953 printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
954 mpt_free_msg_frame(iocp, mf);
960 kfree_sgl(sgl, sgl_dma, buflist, iocp);
962 ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply;
963 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
964 if (iocstat == MPI_IOCSTATUS_SUCCESS) {
965 printk(MYIOC_s_INFO_FMT "F/W update successfull!\n", iocp->name);
967 } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
968 printk(MYIOC_s_WARN_FMT "Hmmm... F/W download not supported!?!\n",
970 printk(MYIOC_s_WARN_FMT "(time to go bang on somebodies door)\n",
973 } else if (iocstat == MPI_IOCSTATUS_BUSY) {
974 printk(MYIOC_s_WARN_FMT "IOC_BUSY!\n", iocp->name);
975 printk(MYIOC_s_WARN_FMT "(try again later?)\n", iocp->name);
978 printk(MYIOC_s_WARN_FMT "ioctl_fwdl() returned [bad] status = %04xh\n",
979 iocp->name, iocstat);
980 printk(MYIOC_s_WARN_FMT "(bad VooDoo)\n", iocp->name);
987 CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status);
988 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0);
989 kfree_sgl(sgl, sgl_dma, buflist, iocp);
993 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
995 * SGE Allocation routine
997 * Inputs: bytes - number of bytes to be transferred
998 * sgdir - data direction
999 * sge_offset - offset (in bytes) from the start of the request
1000 * frame to the first SGE
1001 * ioc - pointer to the mptadapter
1002 * Outputs: frags - number of scatter gather elements
1003 * blp - point to the buflist pointer
1004 * sglbuf_dma - pointer to the (dma) sgl
1005 * Returns: Null if failes
1006 * pointer to the (virtual) sgl if successful.
1009 kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
1010 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
1012 MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
1013 /* and chain buffers */
1014 struct buflist *buflist = NULL; /* kernel routine */
1018 int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
1019 int bytes_allocd = 0;
1021 dma_addr_t pa; // phys addr
1023 int sg_spill = MAX_FRAGS_SPILL1;
1025 /* initialization */
1029 /* Allocate and initialize an array of kernel
1030 * structures for the SG elements.
1032 i = MAX_SGL_BYTES / 8;
1033 buflist = kzalloc(i, GFP_USER);
1038 /* Allocate a single block of memory to store the sg elements and
1039 * the chain buffers. The calling routine is responsible for
1040 * copying the data in this array into the correct place in the
1041 * request and chain buffers.
1043 sglbuf = pci_alloc_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf_dma);
1047 if (sgdir & 0x04000000)
1048 dir = PCI_DMA_TODEVICE;
1050 dir = PCI_DMA_FROMDEVICE;
1053 * sgl = sglbuf = point to beginning of sg buffer
1054 * buflist_ent = 0 = first kernel structure
1055 * sg_spill = number of SGE that can be written before the first
1060 sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1;
1061 while (bytes_allocd < bytes) {
1062 this_alloc = min(alloc_sz, bytes-bytes_allocd);
1063 buflist[buflist_ent].len = this_alloc;
1064 buflist[buflist_ent].kptr = pci_alloc_consistent(ioc->pcidev,
1067 if (buflist[buflist_ent].kptr == NULL) {
1068 alloc_sz = alloc_sz / 2;
1069 if (alloc_sz == 0) {
1070 printk(MYIOC_s_WARN_FMT "-SG: No can do - "
1071 "not enough memory! :-(\n", ioc->name);
1072 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
1073 ioc->name, numfrags);
1078 dma_addr_t dma_addr;
1080 bytes_allocd += this_alloc;
1081 sgl->FlagsLength = (0x10000000|sgdir|this_alloc);
1082 dma_addr = pci_map_single(ioc->pcidev,
1083 buflist[buflist_ent].kptr, this_alloc, dir);
1084 sgl->Address = dma_addr;
1092 if (bytes_allocd >= bytes)
1095 /* Need to chain? */
1096 if (fragcnt == sg_spill) {
1097 printk(MYIOC_s_WARN_FMT
1098 "-SG: No can do - " "Chain required! :-(\n", ioc->name);
1099 printk(MYIOC_s_WARN_FMT "(freeing %d frags)\n", ioc->name, numfrags);
1103 /* overflow check... */
1104 if (numfrags*8 > MAX_SGL_BYTES){
1106 printk(MYIOC_s_WARN_FMT "-SG: No can do - "
1107 "too many SG frags! :-(\n", ioc->name);
1108 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
1109 ioc->name, numfrags);
1114 /* Last sge fixup: set LE+eol+eob bits */
1115 sgl[-1].FlagsLength |= 0xC1000000;
1120 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1121 "%d SG frags generated!\n", ioc->name, numfrags));
1123 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1124 "last (big) alloc_sz=%d\n", ioc->name, alloc_sz));
1129 if (sglbuf != NULL) {
1130 for (i = 0; i < numfrags; i++) {
1131 dma_addr_t dma_addr;
1135 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
1138 dma_addr = sglbuf[i].Address;
1139 kptr = buflist[i].kptr;
1140 len = buflist[i].len;
1142 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1144 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sglbuf, *sglbuf_dma);
1150 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1152 * Routine to free the SGL elements.
1155 kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
1158 struct buflist *bl = buflist;
1163 if (sg->FlagsLength & 0x04000000)
1164 dir = PCI_DMA_TODEVICE;
1166 dir = PCI_DMA_FROMDEVICE;
1168 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1169 while (! (nib & 0x4)) { /* eob */
1170 /* skip ignore/chain. */
1171 if (nib == 0 || nib == 3) {
1173 } else if (sg->Address) {
1174 dma_addr_t dma_addr;
1178 dma_addr = sg->Address;
1181 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1182 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1187 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1192 dma_addr_t dma_addr;
1196 dma_addr = sg->Address;
1199 pci_unmap_single(ioc->pcidev, dma_addr, len, dir);
1200 pci_free_consistent(ioc->pcidev, len, kptr, dma_addr);
1204 pci_free_consistent(ioc->pcidev, MAX_SGL_BYTES, sgl, sgl_dma);
1206 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: Free'd 1 SGL buf + %d kbufs!\n",
1210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1212 * mptctl_getiocinfo - Query the host adapter for IOC information.
1213 * @arg: User space argument
1216 * Return: 0 if successful
1217 * -EFAULT if data unavailable
1218 * -ENODEV if no such device/adapter
1221 mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1223 struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
1224 struct mpt_ioctl_iocinfo *karg;
1226 struct pci_dev *pdev;
1231 struct scsi_device *sdev;
1232 VirtDevice *vdevice;
1234 /* Add of PCI INFO results in unaligned access for
1235 * IA64 and Sparc. Reset long to int. Return no PCI
1236 * data for obsolete format.
1238 if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
1240 else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
1242 else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
1244 else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
1245 cim_rev = 0; /* obsolete */
1249 karg = kmalloc(data_size, GFP_KERNEL);
1251 printk(KERN_ERR MYNAM "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
1252 __FILE__, __LINE__);
1256 if (copy_from_user(karg, uarg, data_size)) {
1257 printk(KERN_ERR MYNAM "%s@%d::mptctl_getiocinfo - "
1258 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1259 __FILE__, __LINE__, uarg);
1264 if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
1266 printk(KERN_DEBUG MYNAM "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
1267 __FILE__, __LINE__, iocnum);
1272 /* Verify the data transfer size is correct. */
1273 if (karg->hdr.maxDataSize != data_size) {
1274 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
1275 "Structure size mismatch. Command not completed.\n",
1276 ioc->name, __FILE__, __LINE__);
1281 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_getiocinfo called.\n",
1284 /* Fill in the data and return the structure to the calling
1287 if (ioc->bus_type == SAS)
1288 karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
1289 else if (ioc->bus_type == FC)
1290 karg->adapterType = MPT_IOCTL_INTERFACE_FC;
1292 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1294 if (karg->hdr.port > 1)
1296 port = karg->hdr.port;
1299 pdev = (struct pci_dev *) ioc->pcidev;
1301 karg->pciId = pdev->device;
1302 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1303 karg->hwRev = revision;
1304 karg->subSystemDevice = pdev->subsystem_device;
1305 karg->subSystemVendor = pdev->subsystem_vendor;
1308 /* Get the PCI bus, device, and function numbers for the IOC
1310 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1311 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1312 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1313 } else if (cim_rev == 2) {
1314 /* Get the PCI bus, device, function and segment ID numbers
1316 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1317 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1318 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1319 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
1322 /* Get number of devices
1324 karg->numDevices = 0;
1326 shost_for_each_device(sdev, ioc->sh) {
1327 vdevice = sdev->hostdata;
1328 if (vdevice->vtarget->tflags &
1329 MPT_TARGET_FLAGS_RAID_COMPONENT)
1335 /* Set the BIOS and FW Version
1337 karg->FWVersion = ioc->facts.FWVersion.Word;
1338 karg->BIOSVersion = ioc->biosVersion;
1340 /* Set the Version Strings.
1342 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
1343 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
1345 karg->busChangeEvent = 0;
1346 karg->hostId = ioc->pfacts[port].PortSCSIID;
1347 karg->rsvd[0] = karg->rsvd[1] = 0;
1349 /* Copy the data from kernel memory to user memory
1351 if (copy_to_user((char __user *)arg, karg, data_size)) {
1352 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
1353 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1354 ioc->name, __FILE__, __LINE__, uarg);
1363 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1365 * mptctl_gettargetinfo - Query the host adapter for target information.
1366 * @arg: User space argument
1369 * Return: 0 if successful
1370 * -EFAULT if data unavailable
1371 * -ENODEV if no such device/adapter
1374 mptctl_gettargetinfo (unsigned long arg)
1376 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1377 struct mpt_ioctl_targetinfo karg;
1379 VirtDevice *vdevice;
1388 struct scsi_device *sdev;
1390 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
1391 printk(KERN_ERR MYNAM "%s@%d::mptctl_gettargetinfo - "
1392 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1393 __FILE__, __LINE__, uarg);
1397 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1399 printk(KERN_DEBUG MYNAM "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
1400 __FILE__, __LINE__, iocnum);
1404 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_gettargetinfo called.\n",
1406 /* Get the port number and set the maximum number of bytes
1407 * in the returned structure.
1408 * Ignore the port setting.
1410 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1411 maxWordsLeft = numBytes/sizeof(int);
1412 port = karg.hdr.port;
1414 if (maxWordsLeft <= 0) {
1415 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1416 ioc->name, __FILE__, __LINE__);
1420 /* Fill in the data and return the structure to the calling
1424 /* struct mpt_ioctl_targetinfo does not contain sufficient space
1425 * for the target structures so when the IOCTL is called, there is
1426 * not sufficient stack space for the structure. Allocate memory,
1427 * populate the memory, copy back to the user, then free memory.
1428 * targetInfo format:
1429 * bits 31-24: reserved
1434 pmem = kzalloc(numBytes, GFP_KERNEL);
1436 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1437 ioc->name, __FILE__, __LINE__);
1440 pdata = (int *) pmem;
1442 /* Get number of devices
1445 shost_for_each_device(sdev, ioc->sh) {
1448 vdevice = sdev->hostdata;
1449 if (vdevice->vtarget->tflags &
1450 MPT_TARGET_FLAGS_RAID_COMPONENT)
1452 lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun;
1453 *pdata = (((u8)lun << 16) + (vdevice->vtarget->channel << 8) +
1454 (vdevice->vtarget->id ));
1460 karg.numDevices = numDevices;
1462 /* Copy part of the data from kernel memory to user memory
1464 if (copy_to_user((char __user *)arg, &karg,
1465 sizeof(struct mpt_ioctl_targetinfo))) {
1466 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
1467 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1468 ioc->name, __FILE__, __LINE__, uarg);
1473 /* Copy the remaining data from kernel memory to user memory
1475 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
1476 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
1477 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1478 ioc->name, __FILE__, __LINE__, pdata);
1488 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1489 /* MPT IOCTL Test function.
1492 * Return: 0 if successful
1493 * -EFAULT if data unavailable
1494 * -ENODEV if no such device/adapter
1497 mptctl_readtest (unsigned long arg)
1499 struct mpt_ioctl_test __user *uarg = (void __user *) arg;
1500 struct mpt_ioctl_test karg;
1504 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
1505 printk(KERN_ERR MYNAM "%s@%d::mptctl_readtest - "
1506 "Unable to read in mpt_ioctl_test struct @ %p\n",
1507 __FILE__, __LINE__, uarg);
1511 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1513 printk(KERN_DEBUG MYNAM "%s::mptctl_readtest() @%d - ioc%d not found!\n",
1514 __FILE__, __LINE__, iocnum);
1518 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_readtest called.\n",
1520 /* Fill in the data and return the structure to the calling
1525 karg.chip_type = ioc->mfcnt;
1527 karg.chip_type = ioc->pcidev->device;
1529 strncpy (karg.name, ioc->name, MPT_MAX_NAME);
1530 karg.name[MPT_MAX_NAME-1]='\0';
1531 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
1532 karg.product[MPT_PRODUCT_LENGTH-1]='\0';
1534 /* Copy the data from kernel memory to user memory
1536 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
1537 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_readtest - "
1538 "Unable to write out mpt_ioctl_test struct @ %p\n",
1539 ioc->name, __FILE__, __LINE__, uarg);
1546 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1548 * mptctl_eventquery - Query the host adapter for the event types
1549 * that are being logged.
1550 * @arg: User space argument
1553 * Return: 0 if successful
1554 * -EFAULT if data unavailable
1555 * -ENODEV if no such device/adapter
1558 mptctl_eventquery (unsigned long arg)
1560 struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
1561 struct mpt_ioctl_eventquery karg;
1565 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
1566 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventquery - "
1567 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1568 __FILE__, __LINE__, uarg);
1572 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1574 printk(KERN_DEBUG MYNAM "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
1575 __FILE__, __LINE__, iocnum);
1579 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventquery called.\n",
1581 karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
1582 karg.eventTypes = ioc->eventTypes;
1584 /* Copy the data from kernel memory to user memory
1586 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
1587 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventquery - "
1588 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1589 ioc->name, __FILE__, __LINE__, uarg);
1595 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1597 mptctl_eventenable (unsigned long arg)
1599 struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
1600 struct mpt_ioctl_eventenable karg;
1604 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
1605 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventenable - "
1606 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1607 __FILE__, __LINE__, uarg);
1611 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1613 printk(KERN_DEBUG MYNAM "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
1614 __FILE__, __LINE__, iocnum);
1618 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventenable called.\n",
1620 if (ioc->events == NULL) {
1621 /* Have not yet allocated memory - do so now.
1623 int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1624 ioc->events = kzalloc(sz, GFP_KERNEL);
1626 printk(MYIOC_s_ERR_FMT
1627 ": ERROR - Insufficient memory to add adapter!\n",
1631 ioc->alloc_total += sz;
1633 ioc->eventContext = 0;
1636 /* Update the IOC event logging flag.
1638 ioc->eventTypes = karg.eventTypes;
1643 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1645 mptctl_eventreport (unsigned long arg)
1647 struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
1648 struct mpt_ioctl_eventreport karg;
1651 int numBytes, maxEvents, max;
1653 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
1654 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventreport - "
1655 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1656 __FILE__, __LINE__, uarg);
1660 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1662 printk(KERN_DEBUG MYNAM "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
1663 __FILE__, __LINE__, iocnum);
1666 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n",
1669 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1670 maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
1673 max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
1675 /* If fewer than 1 event is requested, there must have
1676 * been some type of error.
1678 if ((max < 1) || !ioc->events)
1681 /* reset this flag so SIGIO can restart */
1682 ioc->aen_event_read_flag=0;
1684 /* Copy the data from kernel memory to user memory
1686 numBytes = max * sizeof(MPT_IOCTL_EVENTS);
1687 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
1688 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventreport - "
1689 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1690 ioc->name, __FILE__, __LINE__, ioc->events);
1697 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1699 mptctl_replace_fw (unsigned long arg)
1701 struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
1702 struct mpt_ioctl_replace_fw karg;
1707 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
1708 printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - "
1709 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1710 __FILE__, __LINE__, uarg);
1714 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1716 printk(KERN_DEBUG MYNAM "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
1717 __FILE__, __LINE__, iocnum);
1721 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_replace_fw called.\n",
1723 /* If caching FW, Free the old FW image
1725 if (ioc->cached_fw == NULL)
1728 mpt_free_fw_memory(ioc);
1730 /* Allocate memory for the new FW image
1732 newFwSize = karg.newImageSize;
1734 if (newFwSize & 0x01)
1736 if (newFwSize & 0x02)
1739 mpt_alloc_fw_memory(ioc, newFwSize);
1740 if (ioc->cached_fw == NULL)
1743 /* Copy the data from user memory to kernel space
1745 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
1746 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - "
1747 "Unable to read in mpt_ioctl_replace_fw image "
1748 "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
1749 mpt_free_fw_memory(ioc);
1753 /* Update IOCFactsReply
1755 ioc->facts.FWImageSize = newFwSize;
1759 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1760 /* MPT IOCTL MPTCOMMAND function.
1761 * Cast the arg into the mpt_ioctl_mpt_command structure.
1764 * Return: 0 if successful
1765 * -EBUSY if previous command timeout and IOC reset is not complete.
1766 * -EFAULT if data unavailable
1767 * -ENODEV if no such device/adapter
1768 * -ETIME if timer expires
1769 * -ENOMEM if memory allocation error
1772 mptctl_mpt_command (unsigned long arg)
1774 struct mpt_ioctl_command __user *uarg = (void __user *) arg;
1775 struct mpt_ioctl_command karg;
1781 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
1782 printk(KERN_ERR MYNAM "%s@%d::mptctl_mpt_command - "
1783 "Unable to read in mpt_ioctl_command struct @ %p\n",
1784 __FILE__, __LINE__, uarg);
1788 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1790 printk(KERN_DEBUG MYNAM "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
1791 __FILE__, __LINE__, iocnum);
1795 rc = mptctl_do_mpt_command (karg, &uarg->MF);
1800 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1801 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1804 * Return: 0 if successful
1805 * -EBUSY if previous command timeout and IOC reset is not complete.
1806 * -EFAULT if data unavailable
1807 * -ENODEV if no such device/adapter
1808 * -ETIME if timer expires
1809 * -ENOMEM if memory allocation error
1810 * -EPERM if SCSI I/O and target is untagged
1813 mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1816 MPT_FRAME_HDR *mf = NULL;
1819 struct buflist bufIn; /* data In buffer */
1820 struct buflist bufOut; /* data Out buffer */
1821 dma_addr_t dma_addr_in;
1822 dma_addr_t dma_addr_out;
1823 int sgSize = 0; /* Num SG elements */
1824 int iocnum, flagsLength;
1829 unsigned long timeleft;
1830 struct scsi_device *sdev;
1831 unsigned long flags;
1834 /* bufIn and bufOut are used for user to kernel space transfers
1836 bufIn.kptr = bufOut.kptr = NULL;
1837 bufIn.len = bufOut.len = 0;
1839 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
1841 printk(KERN_DEBUG MYNAM "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
1842 __FILE__, __LINE__, iocnum);
1846 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
1847 if (ioc->ioc_reset_in_progress) {
1848 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
1849 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
1850 "Busy with diagnostic reset\n", __FILE__, __LINE__);
1853 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
1855 /* Verify that the final request frame will not be too large.
1857 sz = karg.dataSgeOffset * 4;
1858 if (karg.dataInSize > 0)
1859 sz += ioc->SGE_size;
1860 if (karg.dataOutSize > 0)
1861 sz += ioc->SGE_size;
1863 if (sz > ioc->req_sz) {
1864 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1865 "Request frame too large (%d) maximum (%d)\n",
1866 ioc->name, __FILE__, __LINE__, sz, ioc->req_sz);
1870 /* Get a free request frame and save the message context.
1872 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
1875 hdr = (MPIHeader_t *) mf;
1876 msgContext = le32_to_cpu(hdr->MsgContext);
1877 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1879 /* Copy the request frame
1880 * Reset the saved message context.
1881 * Request frame in user space
1883 if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
1884 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1885 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1886 ioc->name, __FILE__, __LINE__, mfPtr);
1891 hdr->MsgContext = cpu_to_le32(msgContext);
1892 function = hdr->Function;
1895 /* Verify that this request is allowed.
1897 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n",
1898 ioc->name, hdr->Function, mf));
1901 case MPI_FUNCTION_IOC_FACTS:
1902 case MPI_FUNCTION_PORT_FACTS:
1903 karg.dataOutSize = karg.dataInSize = 0;
1906 case MPI_FUNCTION_CONFIG:
1908 Config_t *config_frame;
1909 config_frame = (Config_t *)mf;
1910 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\ttype=0x%02x ext_type=0x%02x "
1911 "number=0x%02x action=0x%02x\n", ioc->name,
1912 config_frame->Header.PageType,
1913 config_frame->ExtPageType,
1914 config_frame->Header.PageNumber,
1915 config_frame->Action));
1919 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
1920 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
1921 case MPI_FUNCTION_FW_UPLOAD:
1922 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
1923 case MPI_FUNCTION_FW_DOWNLOAD:
1924 case MPI_FUNCTION_FC_PRIMITIVE_SEND:
1925 case MPI_FUNCTION_TOOLBOX:
1926 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
1929 case MPI_FUNCTION_SCSI_IO_REQUEST:
1931 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1932 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1937 id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
1938 if (pScsiReq->TargetID > id) {
1939 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1940 "Target ID out of bounds. \n",
1941 ioc->name, __FILE__, __LINE__);
1946 if (pScsiReq->Bus >= ioc->number_of_buses) {
1947 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1948 "Target Bus out of bounds. \n",
1949 ioc->name, __FILE__, __LINE__);
1954 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1955 pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
1958 /* verify that app has not requested
1959 * more sense data than driver
1960 * can provide, if so, reset this parameter
1961 * set the sense buffer pointer low address
1962 * update the control field to specify Q type
1964 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1965 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1967 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1969 pScsiReq->SenseBufferLowAddr =
1970 cpu_to_le32(ioc->sense_buf_low_dma
1971 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1973 shost_for_each_device(sdev, ioc->sh) {
1974 struct scsi_target *starget = scsi_target(sdev);
1975 VirtTarget *vtarget = starget->hostdata;
1977 if ((pScsiReq->TargetID == vtarget->id) &&
1978 (pScsiReq->Bus == vtarget->channel) &&
1979 (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1980 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1983 /* Have the IOCTL driver set the direction based
1984 * on the dataOutSize (ordering issue with Sparc).
1986 if (karg.dataOutSize > 0) {
1987 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1988 dataSize = karg.dataOutSize;
1990 scsidir = MPI_SCSIIO_CONTROL_READ;
1991 dataSize = karg.dataInSize;
1994 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1995 pScsiReq->DataLength = cpu_to_le32(dataSize);
1999 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2000 "SCSI driver is not loaded. \n",
2001 ioc->name, __FILE__, __LINE__);
2007 case MPI_FUNCTION_SMP_PASSTHROUGH:
2008 /* Check mf->PassthruFlags to determine if
2009 * transfer is ImmediateMode or not.
2010 * Immediate mode returns data in the ReplyFrame.
2011 * Else, we are sending request and response data
2012 * in two SGLs at the end of the mf.
2016 case MPI_FUNCTION_SATA_PASSTHROUGH:
2018 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2019 "SCSI driver is not loaded. \n",
2020 ioc->name, __FILE__, __LINE__);
2026 case MPI_FUNCTION_RAID_ACTION:
2031 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
2033 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
2034 int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
2035 int scsidir = MPI_SCSIIO_CONTROL_READ;
2038 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
2039 pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
2042 /* verify that app has not requested
2043 * more sense data than driver
2044 * can provide, if so, reset this parameter
2045 * set the sense buffer pointer low address
2046 * update the control field to specify Q type
2048 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
2049 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
2051 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
2053 pScsiReq->SenseBufferLowAddr =
2054 cpu_to_le32(ioc->sense_buf_low_dma
2055 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
2057 /* All commands to physical devices are tagged
2060 /* Have the IOCTL driver set the direction based
2061 * on the dataOutSize (ordering issue with Sparc).
2063 if (karg.dataOutSize > 0) {
2064 scsidir = MPI_SCSIIO_CONTROL_WRITE;
2065 dataSize = karg.dataOutSize;
2067 scsidir = MPI_SCSIIO_CONTROL_READ;
2068 dataSize = karg.dataInSize;
2071 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
2072 pScsiReq->DataLength = cpu_to_le32(dataSize);
2075 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2076 "SCSI driver is not loaded. \n",
2077 ioc->name, __FILE__, __LINE__);
2083 case MPI_FUNCTION_SCSI_TASK_MGMT:
2085 SCSITaskMgmt_t *pScsiTm;
2086 pScsiTm = (SCSITaskMgmt_t *)mf;
2087 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2088 "\tTaskType=0x%x MsgFlags=0x%x "
2089 "TaskMsgContext=0x%x id=%d channel=%d\n",
2090 ioc->name, pScsiTm->TaskType, le32_to_cpu
2091 (pScsiTm->TaskMsgContext), pScsiTm->MsgFlags,
2092 pScsiTm->TargetID, pScsiTm->Bus));
2096 case MPI_FUNCTION_IOC_INIT:
2098 IOCInit_t *pInit = (IOCInit_t *) mf;
2099 u32 high_addr, sense_high;
2101 /* Verify that all entries in the IOC INIT match
2102 * existing setup (and in LE format).
2104 if (sizeof(dma_addr_t) == sizeof(u64)) {
2105 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
2106 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2112 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
2113 (pInit->MaxBuses != ioc->facts.MaxBuses) ||
2114 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
2115 (pInit->HostMfaHighAddr != high_addr) ||
2116 (pInit->SenseBufferHighAddr != sense_high)) {
2117 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2118 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2119 ioc->name, __FILE__, __LINE__);
2127 * MPI_FUNCTION_PORT_ENABLE
2128 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2129 * MPI_FUNCTION_TARGET_ASSIST
2130 * MPI_FUNCTION_TARGET_STATUS_SEND
2131 * MPI_FUNCTION_TARGET_MODE_ABORT
2132 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2133 * MPI_FUNCTION_IO_UNIT_RESET
2134 * MPI_FUNCTION_HANDSHAKE
2135 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2136 * MPI_FUNCTION_EVENT_NOTIFICATION
2137 * (driver handles event notification)
2138 * MPI_FUNCTION_EVENT_ACK
2141 /* What to do with these??? CHECK ME!!!
2142 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2143 MPI_FUNCTION_FC_LINK_SRVC_RSP
2144 MPI_FUNCTION_FC_ABORT
2145 MPI_FUNCTION_LAN_SEND
2146 MPI_FUNCTION_LAN_RECEIVE
2147 MPI_FUNCTION_LAN_RESET
2150 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2151 "Illegal request (function 0x%x) \n",
2152 ioc->name, __FILE__, __LINE__, hdr->Function);
2157 /* Add the SGL ( at most one data in SGE and one data out SGE )
2158 * In the case of two SGE's - the data out (write) will always
2159 * preceede the data in (read) SGE. psgList is used to free the
2162 psge = (char *) (((int *) mf) + karg.dataSgeOffset);
2165 if (karg.dataOutSize > 0)
2168 if (karg.dataInSize > 0)
2173 /* Set up the dataOut memory allocation */
2174 if (karg.dataOutSize > 0) {
2175 if (karg.dataInSize > 0) {
2176 flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2177 MPI_SGE_FLAGS_END_OF_BUFFER |
2178 MPI_SGE_FLAGS_DIRECTION)
2179 << MPI_SGE_FLAGS_SHIFT;
2181 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
2183 flagsLength |= karg.dataOutSize;
2184 bufOut.len = karg.dataOutSize;
2185 bufOut.kptr = pci_alloc_consistent(
2186 ioc->pcidev, bufOut.len, &dma_addr_out);
2188 if (bufOut.kptr == NULL) {
2193 * Copy to MF and to sglbuf
2195 ioc->add_sge(psge, flagsLength, dma_addr_out);
2196 psge += ioc->SGE_size;
2198 /* Copy user data to kernel space.
2200 if (copy_from_user(bufOut.kptr,
2203 printk(MYIOC_s_ERR_FMT
2204 "%s@%d::mptctl_do_mpt_command - Unable "
2205 "to read user data "
2207 ioc->name, __FILE__, __LINE__,karg.dataOutBufPtr);
2214 if (karg.dataInSize > 0) {
2215 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2216 flagsLength |= karg.dataInSize;
2218 bufIn.len = karg.dataInSize;
2219 bufIn.kptr = pci_alloc_consistent(ioc->pcidev,
2220 bufIn.len, &dma_addr_in);
2222 if (bufIn.kptr == NULL) {
2227 * Copy to MF and to sglbuf
2229 ioc->add_sge(psge, flagsLength, dma_addr_in);
2235 ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
2238 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext);
2239 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
2240 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
2242 mutex_lock(&ioc->taskmgmt_cmds.mutex);
2243 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
2244 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2248 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
2250 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
2251 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
2252 mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
2254 rc =mpt_send_handshake_request(mptctl_id, ioc,
2255 sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
2257 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2258 "send_handshake FAILED! (ioc %p, mf %p)\n",
2259 ioc->name, ioc, mf));
2260 mpt_clear_taskmgmt_in_progress_flag(ioc);
2262 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2268 mpt_put_msg_frame(mptctl_id, ioc, mf);
2270 /* Now wait for the command to complete */
2271 timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
2273 timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
2275 if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2277 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n",
2278 ioc->name, __func__));
2279 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
2280 if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
2281 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2285 if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
2286 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2287 mptctl_timeout_expired(ioc, mf);
2294 if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
2295 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2300 /* If a valid reply frame, copy to the user.
2301 * Offset 2: reply length in U32's
2303 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
2304 if (karg.maxReplyBytes < ioc->reply_sz) {
2305 sz = min(karg.maxReplyBytes,
2306 4*ioc->ioctl_cmds.reply[2]);
2308 sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]);
2311 if (copy_to_user(karg.replyFrameBufPtr,
2312 ioc->ioctl_cmds.reply, sz)){
2313 printk(MYIOC_s_ERR_FMT
2314 "%s@%d::mptctl_do_mpt_command - "
2315 "Unable to write out reply frame %p\n",
2316 ioc->name, __FILE__, __LINE__, karg.replyFrameBufPtr);
2323 /* If valid sense data, copy to user.
2325 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) {
2326 sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
2328 if (copy_to_user(karg.senseDataPtr,
2329 ioc->ioctl_cmds.sense, sz)) {
2330 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2331 "Unable to write sense data to user %p\n",
2332 ioc->name, __FILE__, __LINE__,
2340 /* If the overall status is _GOOD and data in, copy data
2343 if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) &&
2344 (karg.dataInSize > 0) && (bufIn.kptr)) {
2346 if (copy_to_user(karg.dataInBufPtr,
2347 bufIn.kptr, karg.dataInSize)) {
2348 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2349 "Unable to write data to user %p\n",
2350 ioc->name, __FILE__, __LINE__,
2358 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
2359 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
2361 /* Free the allocated memory.
2363 if (bufOut.kptr != NULL) {
2364 pci_free_consistent(ioc->pcidev,
2365 bufOut.len, (void *) bufOut.kptr, dma_addr_out);
2368 if (bufIn.kptr != NULL) {
2369 pci_free_consistent(ioc->pcidev,
2370 bufIn.len, (void *) bufIn.kptr, dma_addr_in);
2373 /* mf is null if command issued successfully
2374 * otherwise, failure occured after mf acquired.
2377 mpt_free_msg_frame(ioc, mf);
2382 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2383 /* Prototype Routine for the HOST INFO command.
2386 * Return: 0 if successful
2387 * -EFAULT if data unavailable
2388 * -EBUSY if previous command timeout and IOC reset is not complete.
2389 * -ENODEV if no such device/adapter
2390 * -ETIME if timer expires
2391 * -ENOMEM if memory allocation error
2394 mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2396 hp_host_info_t __user *uarg = (void __user *) arg;
2398 struct pci_dev *pdev;
2401 hp_host_info_t karg;
2403 ConfigPageHeader_t hdr;
2406 ToolboxIstwiReadWriteRequest_t *IstwiRWRequest;
2407 MPT_FRAME_HDR *mf = NULL;
2408 MPIHeader_t *mpi_hdr;
2409 unsigned long timeleft;
2412 /* Reset long to int. Should affect IA64 and SPARC only
2414 if (data_size == sizeof(hp_host_info_t))
2416 else if (data_size == sizeof(hp_host_info_rev0_t))
2417 cim_rev = 0; /* obsolete */
2421 if (copy_from_user(&karg, uarg, sizeof(hp_host_info_t))) {
2422 printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_host_info - "
2423 "Unable to read in hp_host_info struct @ %p\n",
2424 __FILE__, __LINE__, uarg);
2428 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2430 printk(KERN_DEBUG MYNAM "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
2431 __FILE__, __LINE__, iocnum);
2434 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n",
2437 /* Fill in the data and return the structure to the calling
2440 pdev = (struct pci_dev *) ioc->pcidev;
2442 karg.vendor = pdev->vendor;
2443 karg.device = pdev->device;
2444 karg.subsystem_id = pdev->subsystem_device;
2445 karg.subsystem_vendor = pdev->subsystem_vendor;
2446 karg.devfn = pdev->devfn;
2447 karg.bus = pdev->bus->number;
2449 /* Save the SCSI host no. if
2450 * SCSI driver loaded
2452 if (ioc->sh != NULL)
2453 karg.host_no = ioc->sh->host_no;
2457 /* Reformat the fw_version into a string
2459 karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ?
2460 ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0';
2461 karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0';
2462 karg.fw_version[2] = '.';
2463 karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ?
2464 ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0';
2465 karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0';
2466 karg.fw_version[5] = '.';
2467 karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ?
2468 ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0';
2469 karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0';
2470 karg.fw_version[8] = '.';
2471 karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ?
2472 ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0';
2473 karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
2474 karg.fw_version[11] = '\0';
2476 /* Issue a config request to get the device serial number
2478 hdr.PageVersion = 0;
2481 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2482 cfg.cfghdr.hdr = &hdr;
2485 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2486 cfg.dir = 0; /* read */
2489 strncpy(karg.serial_number, " ", 24);
2490 if (mpt_config(ioc, &cfg) == 0) {
2491 if (cfg.cfghdr.hdr->PageLength > 0) {
2492 /* Issue the second config page request */
2493 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2495 pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
2497 cfg.physAddr = buf_dma;
2498 if (mpt_config(ioc, &cfg) == 0) {
2499 ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
2500 if (strlen(pdata->BoardTracerNumber) > 1) {
2501 strncpy(karg.serial_number, pdata->BoardTracerNumber, 24);
2502 karg.serial_number[24-1]='\0';
2505 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
2510 rc = mpt_GetIocState(ioc, 1);
2512 case MPI_IOC_STATE_OPERATIONAL:
2513 karg.ioc_status = HP_STATUS_OK;
2516 case MPI_IOC_STATE_FAULT:
2517 karg.ioc_status = HP_STATUS_FAILED;
2520 case MPI_IOC_STATE_RESET:
2521 case MPI_IOC_STATE_READY:
2523 karg.ioc_status = HP_STATUS_OTHER;
2527 karg.base_io_addr = pci_resource_start(pdev, 0);
2529 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2530 karg.bus_phys_width = HP_BUS_WIDTH_UNK;
2532 karg.bus_phys_width = HP_BUS_WIDTH_16;
2534 karg.hard_resets = 0;
2535 karg.soft_resets = 0;
2537 if (ioc->sh != NULL) {
2538 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
2540 if (hd && (cim_rev == 1)) {
2541 karg.hard_resets = ioc->hard_resets;
2542 karg.soft_resets = ioc->soft_resets;
2543 karg.timeouts = ioc->timeouts;
2548 * Gather ISTWI(Industry Standard Two Wire Interface) Data
2550 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
2551 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
2552 "%s, no msg frames!!\n", ioc->name, __func__));
2556 IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
2557 mpi_hdr = (MPIHeader_t *) mf;
2558 memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
2559 IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
2560 IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
2561 IstwiRWRequest->MsgContext = mpi_hdr->MsgContext;
2562 IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
2563 IstwiRWRequest->NumAddressBytes = 0x01;
2564 IstwiRWRequest->DataLength = cpu_to_le16(0x04);
2565 if (pdev->devfn & 1)
2566 IstwiRWRequest->DeviceAddr = 0xB2;
2568 IstwiRWRequest->DeviceAddr = 0xB0;
2570 pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
2573 ioc->add_sge((char *)&IstwiRWRequest->SGL,
2574 (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
2577 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
2578 IstwiRWRequest->MsgContext);
2579 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
2580 mpt_put_msg_frame(mptctl_id, ioc, mf);
2583 timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
2584 HZ*MPT_IOCTL_DEFAULT_TIMEOUT);
2585 if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2587 printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__);
2588 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
2589 mpt_free_msg_frame(ioc, mf);
2593 mptctl_timeout_expired(ioc, mf);
2600 *ISTWI Data Definition
2601 * pbuf[0] = FW_VERSION = 0x4
2602 * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
2603 * the config, you should be seeing one out of these three values
2604 * pbuf[2] = Drive Installed Map = bit pattern depend on which
2605 * bays have drives in them
2606 * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
2608 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)
2609 karg.rsvd = *(u32 *)pbuf;
2612 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
2613 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
2616 pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
2618 /* Copy the data from kernel memory to user memory
2620 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
2621 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hpgethostinfo - "
2622 "Unable to write out hp_host_info @ %p\n",
2623 ioc->name, __FILE__, __LINE__, uarg);
2631 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2632 /* Prototype Routine for the TARGET INFO command.
2635 * Return: 0 if successful
2636 * -EFAULT if data unavailable
2637 * -EBUSY if previous command timeout and IOC reset is not complete.
2638 * -ENODEV if no such device/adapter
2639 * -ETIME if timer expires
2640 * -ENOMEM if memory allocation error
2643 mptctl_hp_targetinfo(unsigned long arg)
2645 hp_target_info_t __user *uarg = (void __user *) arg;
2646 SCSIDevicePage0_t *pg0_alloc;
2647 SCSIDevicePage3_t *pg3_alloc;
2649 MPT_SCSI_HOST *hd = NULL;
2650 hp_target_info_t karg;
2653 dma_addr_t page_dma;
2655 ConfigPageHeader_t hdr;
2656 int tmp, np, rc = 0;
2658 if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
2659 printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_targetinfo - "
2660 "Unable to read in hp_host_targetinfo struct @ %p\n",
2661 __FILE__, __LINE__, uarg);
2665 if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
2667 printk(KERN_DEBUG MYNAM "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
2668 __FILE__, __LINE__, iocnum);
2671 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
2674 /* There is nothing to do for FCP parts.
2676 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2679 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
2682 if (ioc->sh->host_no != karg.hdr.host)
2685 /* Get the data transfer speeds
2687 data_sz = ioc->spi_data.sdp0length * 4;
2688 pg0_alloc = (SCSIDevicePage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
2690 hdr.PageVersion = ioc->spi_data.sdp0version;
2691 hdr.PageLength = data_sz;
2693 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2695 cfg.cfghdr.hdr = &hdr;
2696 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2699 cfg.physAddr = page_dma;
2701 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2703 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2704 np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
2705 karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
2706 HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
2708 if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
2709 tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
2711 karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
2712 else if (tmp <= 0x09)
2713 karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
2714 else if (tmp <= 0x0A)
2715 karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
2716 else if (tmp <= 0x0C)
2717 karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
2718 else if (tmp <= 0x25)
2719 karg.negotiated_speed = HP_DEV_SPEED_FAST;
2721 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2723 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2726 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg0_alloc, page_dma);
2731 karg.message_rejects = -1;
2732 karg.phase_errors = -1;
2733 karg.parity_errors = -1;
2734 karg.select_timeouts = -1;
2736 /* Get the target error parameters
2738 hdr.PageVersion = 0;
2741 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2743 cfg.cfghdr.hdr = &hdr;
2744 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2748 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2749 /* Issue the second config page request */
2750 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2751 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2752 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
2753 ioc->pcidev, data_sz, &page_dma);
2755 cfg.physAddr = page_dma;
2756 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2757 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2758 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
2759 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
2760 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
2762 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
2765 hd = shost_priv(ioc->sh);
2767 karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
2769 /* Copy the data from kernel memory to user memory
2771 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
2772 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hp_target_info - "
2773 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2774 ioc->name, __FILE__, __LINE__, uarg);
2781 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2783 static const struct file_operations mptctl_fops = {
2784 .owner = THIS_MODULE,
2785 .llseek = no_llseek,
2786 .fasync = mptctl_fasync,
2787 .unlocked_ioctl = mptctl_ioctl,
2788 .release = mptctl_release,
2789 #ifdef CONFIG_COMPAT
2790 .compat_ioctl = compat_mpctl_ioctl,
2794 static struct miscdevice mptctl_miscdev = {
2800 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2802 #ifdef CONFIG_COMPAT
2805 compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
2808 struct mpt_fw_xfer32 kfw32;
2809 struct mpt_fw_xfer kfw;
2810 MPT_ADAPTER *iocp = NULL;
2811 int iocnum, iocnumX;
2812 int nonblock = (filp->f_flags & O_NONBLOCK);
2816 if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
2819 /* Verify intended MPT adapter */
2820 iocnumX = kfw32.iocnum & 0xFF;
2821 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2823 printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2828 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2831 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mptfwxfer_ioctl() called\n",
2833 kfw.iocnum = iocnum;
2834 kfw.fwlen = kfw32.fwlen;
2835 kfw.bufp = compat_ptr(kfw32.bufp);
2837 ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
2839 mutex_unlock(&iocp->ioctl_cmds.mutex);
2845 compat_mpt_command(struct file *filp, unsigned int cmd,
2848 struct mpt_ioctl_command32 karg32;
2849 struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
2850 struct mpt_ioctl_command karg;
2851 MPT_ADAPTER *iocp = NULL;
2852 int iocnum, iocnumX;
2853 int nonblock = (filp->f_flags & O_NONBLOCK);
2856 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
2859 /* Verify intended MPT adapter */
2860 iocnumX = karg32.hdr.iocnum & 0xFF;
2861 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2863 printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
2868 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2871 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mpt_command() called\n",
2873 /* Copy data to karg */
2874 karg.hdr.iocnum = karg32.hdr.iocnum;
2875 karg.hdr.port = karg32.hdr.port;
2876 karg.timeout = karg32.timeout;
2877 karg.maxReplyBytes = karg32.maxReplyBytes;
2879 karg.dataInSize = karg32.dataInSize;
2880 karg.dataOutSize = karg32.dataOutSize;
2881 karg.maxSenseBytes = karg32.maxSenseBytes;
2882 karg.dataSgeOffset = karg32.dataSgeOffset;
2884 karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
2885 karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
2886 karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
2887 karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
2889 /* Pass new structure to do_mpt_command
2891 ret = mptctl_do_mpt_command (karg, &uarg->MF);
2893 mutex_unlock(&iocp->ioctl_cmds.mutex);
2898 static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2908 case MPTEVENTENABLE:
2909 case MPTEVENTREPORT:
2911 case HP_GETHOSTINFO:
2912 case HP_GETTARGETINFO:
2914 ret = __mptctl_ioctl(f, cmd, arg);
2917 ret = compat_mpt_command(f, cmd, arg);
2919 case MPTFWDOWNLOAD32:
2920 ret = compat_mptfwxfer_ioctl(f, cmd, arg);
2933 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2935 * mptctl_probe - Installs ioctl devices per bus.
2936 * @pdev: Pointer to pci_dev structure
2938 * Returns 0 for success, non-zero for failure.
2943 mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2945 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2947 mutex_init(&ioc->ioctl_cmds.mutex);
2948 init_completion(&ioc->ioctl_cmds.done);
2952 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2954 * mptctl_remove - Removed ioctl devices
2955 * @pdev: Pointer to pci_dev structure
2960 mptctl_remove(struct pci_dev *pdev)
2964 static struct mpt_pci_driver mptctl_driver = {
2965 .probe = mptctl_probe,
2966 .remove = mptctl_remove,
2969 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2970 static int __init mptctl_init(void)
2975 show_mptmod_ver(my_NAME, my_VERSION);
2977 mpt_device_driver_register(&mptctl_driver, MPTCTL_DRIVER);
2979 /* Register this device */
2980 err = misc_register(&mptctl_miscdev);
2982 printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
2985 printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
2986 printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
2987 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2990 * Install our handler
2993 mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER);
2994 if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) {
2995 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2996 misc_deregister(&mptctl_miscdev);
3001 mptctl_taskmgmt_id = mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER);
3002 mpt_reset_register(mptctl_id, mptctl_ioc_reset);
3003 mpt_event_register(mptctl_id, mptctl_event_process);
3009 mpt_device_driver_deregister(MPTCTL_DRIVER);
3014 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3015 static void mptctl_exit(void)
3017 misc_deregister(&mptctl_miscdev);
3018 printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
3019 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
3021 /* De-register reset handler from base module */
3022 mpt_reset_deregister(mptctl_id);
3024 /* De-register callback handler from base module */
3025 mpt_deregister(mptctl_id);
3026 mpt_reset_deregister(mptctl_taskmgmt_id);
3028 mpt_device_driver_deregister(MPTCTL_DRIVER);
3032 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3034 module_init(mptctl_init);
3035 module_exit(mptctl_exit);