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/mutex.h>
58 #include <linux/compat.h>
61 #include <linux/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 DEFINE_MUTEX(mpctl_mutex);
87 static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
88 static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS;
90 static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
92 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
100 * Function prototypes. Called from OS entry point mptctl_ioctl.
101 * arg contents specific to function.
103 static int mptctl_fw_download(MPT_ADAPTER *iocp, unsigned long arg);
104 static int mptctl_getiocinfo(MPT_ADAPTER *iocp, unsigned long arg, unsigned int cmd);
105 static int mptctl_gettargetinfo(MPT_ADAPTER *iocp, unsigned long arg);
106 static int mptctl_readtest(MPT_ADAPTER *iocp, unsigned long arg);
107 static int mptctl_mpt_command(MPT_ADAPTER *iocp, unsigned long arg);
108 static int mptctl_eventquery(MPT_ADAPTER *iocp, unsigned long arg);
109 static int mptctl_eventenable(MPT_ADAPTER *iocp, unsigned long arg);
110 static int mptctl_eventreport(MPT_ADAPTER *iocp, unsigned long arg);
111 static int mptctl_replace_fw(MPT_ADAPTER *iocp, unsigned long arg);
113 static int mptctl_do_reset(MPT_ADAPTER *iocp, unsigned long arg);
114 static int mptctl_hp_hostinfo(MPT_ADAPTER *iocp, unsigned long arg, unsigned int cmd);
115 static int mptctl_hp_targetinfo(MPT_ADAPTER *iocp, unsigned long arg);
117 static int mptctl_probe(struct pci_dev *);
118 static void mptctl_remove(struct pci_dev *);
121 static long compat_mpctl_ioctl(struct file *f, unsigned cmd, unsigned long arg);
124 * Private function calls.
126 static int mptctl_do_mpt_command(MPT_ADAPTER *iocp, struct mpt_ioctl_command karg, void __user *mfPtr);
127 static int mptctl_do_fw_download(MPT_ADAPTER *iocp, char __user *ufwbuf, size_t fwlen);
128 static MptSge_t *kbuf_alloc_2_sgl(int bytes, u32 dir, int sge_offset, int *frags,
129 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);
130 static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma,
131 struct buflist *buflist, MPT_ADAPTER *ioc);
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);
269 if (ioc->bus_type == SAS)
270 ioc->schedule_target_reset(ioc);
272 ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
273 complete(&ioc->ioctl_cmds.done);
278 if (reply && (reply->u.reply.MsgFlags &
279 MPI_MSGFLAGS_CONTINUATION_REPLY))
286 mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
291 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
292 "TaskMgmt completed (mf=%p, mr=%p)\n",
295 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
300 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
301 memcpy(ioc->taskmgmt_cmds.reply, mr,
302 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
304 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
305 mpt_clear_taskmgmt_in_progress_flag(ioc);
306 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
307 complete(&ioc->taskmgmt_cmds.done);
308 if (ioc->bus_type == SAS)
309 ioc->schedule_target_reset(ioc);
316 mptctl_do_taskmgmt(MPT_ADAPTER *ioc, u8 tm_type, u8 bus_id, u8 target_id)
319 SCSITaskMgmt_t *pScsiTm;
320 SCSITaskMgmtReply_t *pScsiTmReply;
323 unsigned long timeout;
327 mutex_lock(&ioc->taskmgmt_cmds.mutex);
328 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
329 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
335 mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc);
338 printk(MYIOC_s_WARN_FMT "TaskMgmt, no msg frames!!\n",
340 mpt_clear_taskmgmt_in_progress_flag(ioc);
345 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
348 pScsiTm = (SCSITaskMgmt_t *) mf;
349 memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
350 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
351 pScsiTm->TaskType = tm_type;
352 if ((tm_type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) &&
353 (ioc->bus_type == FC))
355 MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
356 pScsiTm->TargetID = target_id;
357 pScsiTm->Bus = bus_id;
358 pScsiTm->ChainOffset = 0;
359 pScsiTm->Reserved = 0;
360 pScsiTm->Reserved1 = 0;
361 pScsiTm->TaskMsgContext = 0;
362 for (ii= 0; ii < 8; ii++)
363 pScsiTm->LUN[ii] = 0;
364 for (ii=0; ii < 7; ii++)
365 pScsiTm->Reserved2[ii] = 0;
367 switch (ioc->bus_type) {
381 printk(MYIOC_s_DEBUG_FMT "TaskMgmt type=%d timeout=%ld\n",
382 ioc->name, tm_type, timeout));
384 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
385 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
386 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
387 mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf);
389 retval = mpt_send_handshake_request(mptctl_taskmgmt_id, ioc,
390 sizeof(SCSITaskMgmt_t), (u32 *)pScsiTm, CAN_SLEEP);
393 printk(MYIOC_s_ERR_FMT
394 "TaskMgmt send_handshake FAILED!"
395 " (ioc %p, mf %p, rc=%d) \n", ioc->name,
397 mpt_free_msg_frame(ioc, mf);
398 mpt_clear_taskmgmt_in_progress_flag(ioc);
403 /* Now wait for the command to complete */
404 ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
406 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
407 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
408 "TaskMgmt failed\n", ioc->name));
409 mpt_free_msg_frame(ioc, mf);
410 mpt_clear_taskmgmt_in_progress_flag(ioc);
411 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
414 retval = -1; /* return failure */
418 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
419 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
420 "TaskMgmt failed\n", ioc->name));
421 retval = -1; /* return failure */
425 pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
426 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
427 "TaskMgmt fw_channel = %d, fw_id = %d, task_type=0x%02X, "
428 "iocstatus=0x%04X\n\tloginfo=0x%08X, response_code=0x%02X, "
429 "term_cmnds=%d\n", ioc->name, pScsiTmReply->Bus,
430 pScsiTmReply->TargetID, tm_type,
431 le16_to_cpu(pScsiTmReply->IOCStatus),
432 le32_to_cpu(pScsiTmReply->IOCLogInfo),
433 pScsiTmReply->ResponseCode,
434 le32_to_cpu(pScsiTmReply->TerminationCount)));
436 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
438 if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
439 iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED ||
440 iocstatus == MPI_IOCSTATUS_SUCCESS)
443 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
444 "TaskMgmt failed\n", ioc->name));
445 retval = -1; /* return failure */
449 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
450 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
454 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
455 /* mptctl_timeout_expired
457 * Expecting an interrupt, however timed out.
461 mptctl_timeout_expired(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
465 SCSIIORequest_t *scsi_req = (SCSIIORequest_t *) mf;
466 u8 function = mf->u.hdr.Function;
468 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": %s\n",
469 ioc->name, __func__));
471 if (mpt_fwfault_debug)
472 mpt_halt_firmware(ioc);
474 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
475 if (ioc->ioc_reset_in_progress) {
476 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
477 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
478 mpt_free_msg_frame(ioc, mf);
481 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
484 CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
486 if (ioc->bus_type == SAS) {
487 if (function == MPI_FUNCTION_SCSI_IO_REQUEST)
488 ret_val = mptctl_do_taskmgmt(ioc,
489 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
490 scsi_req->Bus, scsi_req->TargetID);
491 else if (function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
492 ret_val = mptctl_do_taskmgmt(ioc,
493 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
498 if ((function == MPI_FUNCTION_SCSI_IO_REQUEST) ||
499 (function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH))
500 ret_val = mptctl_do_taskmgmt(ioc,
501 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
507 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling Reset! \n",
509 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
510 mpt_free_msg_frame(ioc, mf);
514 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
517 * Clean-up functionality. Used only if there has been a
518 * reload of the FW due.
522 mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
524 switch(reset_phase) {
525 case MPT_IOC_SETUP_RESET:
526 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
527 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
529 case MPT_IOC_PRE_RESET:
530 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
531 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
533 case MPT_IOC_POST_RESET:
534 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
535 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
536 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
537 ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
538 complete(&ioc->ioctl_cmds.done);
548 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
549 /* ASYNC Event Notification Support */
551 mptctl_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
555 event = le32_to_cpu(pEvReply->Event) & 0xFF;
557 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n",
558 ioc->name, __func__));
559 if(async_queue == NULL)
562 /* Raise SIGIO for persistent events.
563 * TODO - this define is not in MPI spec yet,
564 * but they plan to set it to 0x21
567 ioc->aen_event_read_flag=1;
568 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Raised SIGIO to application\n",
570 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
571 "Raised SIGIO to application\n", ioc->name));
572 kill_fasync(&async_queue, SIGIO, POLL_IN);
576 /* This flag is set after SIGIO was raised, and
577 * remains set until the application has read
578 * the event log via ioctl=MPTEVENTREPORT
580 if(ioc->aen_event_read_flag)
583 /* Signal only for the events that are
584 * requested for by the application
586 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
587 ioc->aen_event_read_flag=1;
588 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
589 "Raised SIGIO to application\n", ioc->name));
590 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
591 "Raised SIGIO to application\n", ioc->name));
592 kill_fasync(&async_queue, SIGIO, POLL_IN);
598 mptctl_fasync(int fd, struct file *filep, int mode)
603 mutex_lock(&mpctl_mutex);
604 list_for_each_entry(ioc, &ioc_list, list)
605 ioc->aen_event_read_flag=0;
607 ret = fasync_helper(fd, filep, mode, &async_queue);
608 mutex_unlock(&mpctl_mutex);
612 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
615 * cmd - specify the particular IOCTL command to be issued
616 * arg - data specific to the command. Must not be null.
619 __mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
621 mpt_ioctl_header __user *uhdr = (void __user *) arg;
622 mpt_ioctl_header khdr;
625 int nonblock = (file->f_flags & O_NONBLOCK);
627 MPT_ADAPTER *iocp = NULL;
629 if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
630 printk(KERN_ERR MYNAM "%s::mptctl_ioctl() @%d - "
631 "Unable to copy mpt_ioctl_header data @ %p\n",
632 __FILE__, __LINE__, uhdr);
635 ret = -ENXIO; /* (-6) No such device or address */
637 /* Verify intended MPT adapter - set iocnum and the adapter
640 iocnumX = khdr.iocnum & 0xFF;
641 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
646 printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - Controller disabled.\n",
651 /* Handle those commands that are just returning
652 * information stored in the driver.
653 * These commands should never time out and are unaffected
654 * by TM and FW reloads.
656 if ((cmd & ~IOCSIZE_MASK) == (MPTIOCINFO & ~IOCSIZE_MASK)) {
657 return mptctl_getiocinfo(iocp, arg, _IOC_SIZE(cmd));
658 } else if (cmd == MPTTARGETINFO) {
659 return mptctl_gettargetinfo(iocp, arg);
660 } else if (cmd == MPTTEST) {
661 return mptctl_readtest(iocp, arg);
662 } else if (cmd == MPTEVENTQUERY) {
663 return mptctl_eventquery(iocp, arg);
664 } else if (cmd == MPTEVENTENABLE) {
665 return mptctl_eventenable(iocp, arg);
666 } else if (cmd == MPTEVENTREPORT) {
667 return mptctl_eventreport(iocp, arg);
668 } else if (cmd == MPTFWREPLACE) {
669 return mptctl_replace_fw(iocp, arg);
672 /* All of these commands require an interrupt or
673 * are unknown/illegal.
675 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
678 if (cmd == MPTFWDOWNLOAD)
679 ret = mptctl_fw_download(iocp, arg);
680 else if (cmd == MPTCOMMAND)
681 ret = mptctl_mpt_command(iocp, arg);
682 else if (cmd == MPTHARDRESET)
683 ret = mptctl_do_reset(iocp, arg);
684 else if ((cmd & ~IOCSIZE_MASK) == (HP_GETHOSTINFO & ~IOCSIZE_MASK))
685 ret = mptctl_hp_hostinfo(iocp, arg, _IOC_SIZE(cmd));
686 else if (cmd == HP_GETTARGETINFO)
687 ret = mptctl_hp_targetinfo(iocp, arg);
691 mutex_unlock(&iocp->ioctl_cmds.mutex);
697 mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
700 mutex_lock(&mpctl_mutex);
701 ret = __mptctl_ioctl(file, cmd, arg);
702 mutex_unlock(&mpctl_mutex);
706 static int mptctl_do_reset(MPT_ADAPTER *iocp, unsigned long arg)
708 struct mpt_ioctl_diag_reset __user *urinfo = (void __user *) arg;
709 struct mpt_ioctl_diag_reset krinfo;
711 if (copy_from_user(&krinfo, urinfo, sizeof(struct mpt_ioctl_diag_reset))) {
712 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_reset - "
713 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
714 __FILE__, __LINE__, urinfo);
718 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "mptctl_do_reset called.\n",
721 if (mpt_HardResetHandler(iocp, CAN_SLEEP) != 0) {
722 printk (MYIOC_s_ERR_FMT "%s@%d::mptctl_do_reset - reset failed.\n",
723 iocp->name, __FILE__, __LINE__);
730 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
732 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
733 * This structure contains: iocnum, firmware length (bytes),
734 * pointer to user space memory where the fw image is stored.
737 * Return: 0 if successful
738 * -EFAULT if data unavailable
739 * -ENXIO if no such device
740 * -EAGAIN if resource problem
741 * -ENOMEM if no memory for SGE
742 * -EMLINK if too many chain buffers required
743 * -EBADRQC if adapter does not support FW download
744 * -EBUSY if adapter is busy
745 * -ENOMSG if FW upload returned bad status
748 mptctl_fw_download(MPT_ADAPTER *iocp, unsigned long arg)
750 struct mpt_fw_xfer __user *ufwdl = (void __user *) arg;
751 struct mpt_fw_xfer kfwdl;
753 if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {
754 printk(KERN_ERR MYNAM "%s@%d::_ioctl_fwdl - "
755 "Unable to copy mpt_fw_xfer struct @ %p\n",
756 __FILE__, __LINE__, ufwdl);
760 return mptctl_do_fw_download(iocp, kfwdl.bufp, kfwdl.fwlen);
763 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
765 * FW Download engine.
767 * Return: 0 if successful
768 * -EFAULT if data unavailable
769 * -ENXIO if no such device
770 * -EAGAIN if resource problem
771 * -ENOMEM if no memory for SGE
772 * -EMLINK if too many chain buffers required
773 * -EBADRQC if adapter does not support FW download
774 * -EBUSY if adapter is busy
775 * -ENOMSG if FW upload returned bad status
778 mptctl_do_fw_download(MPT_ADAPTER *iocp, char __user *ufwbuf, size_t fwlen)
782 FWDownloadTCSGE_t *ptsge;
783 MptSge_t *sgl, *sgIn;
785 struct buflist *buflist;
794 int fw_bytes_copied = 0;
798 pFWDownloadReply_t ReplyMsg = NULL;
799 unsigned long timeleft;
801 /* Valid device. Get a message frame and construct the FW download message.
803 if ((mf = mpt_get_msg_frame(mptctl_id, iocp)) == NULL)
806 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT
807 "mptctl_do_fwdl called. mptctl_id = %xh.\n", iocp->name, mptctl_id));
808 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.bufp = %p\n",
809 iocp->name, ufwbuf));
810 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: kfwdl.fwlen = %d\n",
811 iocp->name, (int)fwlen));
813 dlmsg = (FWDownload_t*) mf;
814 ptsge = (FWDownloadTCSGE_t *) &dlmsg->SGL;
815 sgOut = (char *) (ptsge + 1);
818 * Construct f/w download request
820 dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;
822 dlmsg->ChainOffset = 0;
823 dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;
824 dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;
825 if (iocp->facts.MsgVersion >= MPI_VERSION_01_05)
826 dlmsg->MsgFlags = MPI_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT;
831 /* Set up the Transaction SGE.
834 ptsge->ContextSize = 0;
835 ptsge->DetailsLength = 12;
836 ptsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
837 ptsge->Reserved_0100_Checksum = 0;
838 ptsge->ImageOffset = 0;
839 ptsge->ImageSize = cpu_to_le32(fwlen);
845 * Need to kmalloc area(s) for holding firmware image bytes.
846 * But we need to do it piece meal, using a proper
847 * scatter gather list (with 128kB MAX hunks).
849 * A practical limit here might be # of sg hunks that fit into
850 * a single IOC request frame; 12 or 8 (see below), so:
851 * For FC9xx: 12 x 128kB == 1.5 mB (max)
852 * For C1030: 8 x 128kB == 1 mB (max)
853 * We could support chaining, but things get ugly(ier:)
855 * Set the sge_offset to the start of the sgl (bytes).
857 sgdir = 0x04000000; /* IOC will READ from sys mem */
858 sge_offset = sizeof(MPIHeader_t) + sizeof(FWDownloadTCSGE_t);
859 if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, sge_offset,
860 &numfrags, &buflist, &sgl_dma, iocp)) == NULL)
864 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
865 * for FC9xx f/w image, but calculate max number of sge hunks
866 * we can fit into a request frame, and limit ourselves to that.
867 * (currently no chain support)
868 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
874 maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) -
875 sizeof(FWDownloadTCSGE_t))
877 if (numfrags > maxfrags) {
882 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n",
883 iocp->name, sgl, numfrags));
886 * Parse SG list, copying sgl itself,
887 * plus f/w image hunks from user space as we go...
892 for (i=0; i < numfrags; i++) {
894 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
895 * Skip everything but Simple. If simple, copy from
896 * user space into kernel space.
897 * Note: we should not have anything but Simple as
898 * Chain SGE are illegal.
900 nib = (sgIn->FlagsLength & 0x30000000) >> 28;
901 if (nib == 0 || nib == 3) {
903 } else if (sgIn->Address) {
904 iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
906 if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
907 printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - "
908 "Unable to copy f/w buffer hunk#%d @ %p\n",
909 iocp->name, __FILE__, __LINE__, n, ufwbuf);
912 fw_bytes_copied += bl->len;
916 sgOut += iocp->SGE_size;
919 DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags);
922 * Finally, perform firmware download.
925 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->MsgContext);
926 INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status)
927 mpt_put_msg_frame(mptctl_id, iocp, mf);
929 /* Now wait for the command to complete */
931 timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60);
932 if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
934 printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
935 if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
936 mpt_free_msg_frame(iocp, mf);
940 printk(MYIOC_s_WARN_FMT
941 "FW download timeout, doorbell=0x%08x\n",
942 iocp->name, mpt_GetIocState(iocp, 0));
943 mptctl_timeout_expired(iocp, mf);
949 if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
950 printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
951 mpt_free_msg_frame(iocp, mf);
957 kfree_sgl(sgl, sgl_dma, buflist, iocp);
959 ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply;
960 iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
961 if (iocstat == MPI_IOCSTATUS_SUCCESS) {
962 printk(MYIOC_s_INFO_FMT "F/W update successful!\n", iocp->name);
964 } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
965 printk(MYIOC_s_WARN_FMT "Hmmm... F/W download not supported!?!\n",
967 printk(MYIOC_s_WARN_FMT "(time to go bang on somebodies door)\n",
970 } else if (iocstat == MPI_IOCSTATUS_BUSY) {
971 printk(MYIOC_s_WARN_FMT "IOC_BUSY!\n", iocp->name);
972 printk(MYIOC_s_WARN_FMT "(try again later?)\n", iocp->name);
975 printk(MYIOC_s_WARN_FMT "ioctl_fwdl() returned [bad] status = %04xh\n",
976 iocp->name, iocstat);
977 printk(MYIOC_s_WARN_FMT "(bad VooDoo)\n", iocp->name);
984 CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status);
985 SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0);
986 kfree_sgl(sgl, sgl_dma, buflist, iocp);
990 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
992 * SGE Allocation routine
994 * Inputs: bytes - number of bytes to be transferred
995 * sgdir - data direction
996 * sge_offset - offset (in bytes) from the start of the request
997 * frame to the first SGE
998 * ioc - pointer to the mptadapter
999 * Outputs: frags - number of scatter gather elements
1000 * blp - point to the buflist pointer
1001 * sglbuf_dma - pointer to the (dma) sgl
1002 * Returns: Null if failes
1003 * pointer to the (virtual) sgl if successful.
1006 kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
1007 struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc)
1009 MptSge_t *sglbuf = NULL; /* pointer to array of SGE */
1010 /* and chain buffers */
1011 struct buflist *buflist = NULL; /* kernel routine */
1015 int alloc_sz = min(bytes,MAX_KMALLOC_SZ); // avoid kernel warning msg!
1016 int bytes_allocd = 0;
1018 dma_addr_t pa; // phys addr
1020 int sg_spill = MAX_FRAGS_SPILL1;
1026 /* initialization */
1030 /* Allocate and initialize an array of kernel
1031 * structures for the SG elements.
1033 i = MAX_SGL_BYTES / 8;
1034 buflist = kzalloc(i, GFP_USER);
1039 /* Allocate a single block of memory to store the sg elements and
1040 * the chain buffers. The calling routine is responsible for
1041 * copying the data in this array into the correct place in the
1042 * request and chain buffers.
1044 sglbuf = dma_alloc_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES,
1045 sglbuf_dma, GFP_KERNEL);
1049 if (sgdir & 0x04000000)
1050 dir = DMA_TO_DEVICE;
1052 dir = DMA_FROM_DEVICE;
1055 * sgl = sglbuf = point to beginning of sg buffer
1056 * buflist_ent = 0 = first kernel structure
1057 * sg_spill = number of SGE that can be written before the first
1062 sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1;
1063 while (bytes_allocd < bytes) {
1064 this_alloc = min(alloc_sz, bytes-bytes_allocd);
1065 buflist[buflist_ent].len = this_alloc;
1066 buflist[buflist_ent].kptr = dma_alloc_coherent(&ioc->pcidev->dev,
1069 if (buflist[buflist_ent].kptr == NULL) {
1070 alloc_sz = alloc_sz / 2;
1071 if (alloc_sz == 0) {
1072 printk(MYIOC_s_WARN_FMT "-SG: No can do - "
1073 "not enough memory! :-(\n", ioc->name);
1074 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
1075 ioc->name, numfrags);
1080 dma_addr_t dma_addr;
1082 bytes_allocd += this_alloc;
1083 sgl->FlagsLength = (0x10000000|sgdir|this_alloc);
1084 dma_addr = dma_map_single(&ioc->pcidev->dev,
1085 buflist[buflist_ent].kptr,
1087 sgl->Address = dma_addr;
1095 if (bytes_allocd >= bytes)
1098 /* Need to chain? */
1099 if (fragcnt == sg_spill) {
1100 printk(MYIOC_s_WARN_FMT
1101 "-SG: No can do - " "Chain required! :-(\n", ioc->name);
1102 printk(MYIOC_s_WARN_FMT "(freeing %d frags)\n", ioc->name, numfrags);
1106 /* overflow check... */
1107 if (numfrags*8 > MAX_SGL_BYTES){
1109 printk(MYIOC_s_WARN_FMT "-SG: No can do - "
1110 "too many SG frags! :-(\n", ioc->name);
1111 printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
1112 ioc->name, numfrags);
1117 /* Last sge fixup: set LE+eol+eob bits */
1118 sgl[-1].FlagsLength |= 0xC1000000;
1123 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1124 "%d SG frags generated!\n", ioc->name, numfrags));
1126 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: kbuf_alloc_2_sgl() - "
1127 "last (big) alloc_sz=%d\n", ioc->name, alloc_sz));
1132 if (sglbuf != NULL) {
1133 for (i = 0; i < numfrags; i++) {
1134 dma_addr_t dma_addr;
1138 if ((sglbuf[i].FlagsLength >> 24) == 0x30)
1141 dma_addr = sglbuf[i].Address;
1142 kptr = buflist[i].kptr;
1143 len = buflist[i].len;
1145 dma_free_coherent(&ioc->pcidev->dev, len, kptr,
1148 dma_free_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES, sglbuf,
1155 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1157 * Routine to free the SGL elements.
1160 kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma, struct buflist *buflist, MPT_ADAPTER *ioc)
1163 struct buflist *bl = buflist;
1168 if (sg->FlagsLength & 0x04000000)
1169 dir = DMA_TO_DEVICE;
1171 dir = DMA_FROM_DEVICE;
1173 nib = (sg->FlagsLength & 0xF0000000) >> 28;
1174 while (! (nib & 0x4)) { /* eob */
1175 /* skip ignore/chain. */
1176 if (nib == 0 || nib == 3) {
1178 } else if (sg->Address) {
1179 dma_addr_t dma_addr;
1183 dma_addr = sg->Address;
1186 dma_unmap_single(&ioc->pcidev->dev, dma_addr, len,
1188 dma_free_coherent(&ioc->pcidev->dev, len, kptr,
1194 nib = (le32_to_cpu(sg->FlagsLength) & 0xF0000000) >> 28;
1199 dma_addr_t dma_addr;
1203 dma_addr = sg->Address;
1206 dma_unmap_single(&ioc->pcidev->dev, dma_addr, len, dir);
1207 dma_free_coherent(&ioc->pcidev->dev, len, kptr, dma_addr);
1211 dma_free_coherent(&ioc->pcidev->dev, MAX_SGL_BYTES, sgl, sgl_dma);
1213 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "-SG: Free'd 1 SGL buf + %d kbufs!\n",
1217 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1219 * mptctl_getiocinfo - Query the host adapter for IOC information.
1220 * @arg: User space argument
1223 * Return: 0 if successful
1224 * -EFAULT if data unavailable
1225 * -ENODEV if no such device/adapter
1228 mptctl_getiocinfo (MPT_ADAPTER *ioc, unsigned long arg, unsigned int data_size)
1230 struct mpt_ioctl_iocinfo __user *uarg = (void __user *) arg;
1231 struct mpt_ioctl_iocinfo *karg;
1232 struct pci_dev *pdev;
1235 struct scsi_device *sdev;
1236 VirtDevice *vdevice;
1238 /* Add of PCI INFO results in unaligned access for
1239 * IA64 and Sparc. Reset long to int. Return no PCI
1240 * data for obsolete format.
1242 if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev0))
1244 else if (data_size == sizeof(struct mpt_ioctl_iocinfo_rev1))
1246 else if (data_size == sizeof(struct mpt_ioctl_iocinfo))
1248 else if (data_size == (sizeof(struct mpt_ioctl_iocinfo_rev0)+12))
1249 cim_rev = 0; /* obsolete */
1253 karg = memdup_user(uarg, data_size);
1255 printk(KERN_ERR MYNAM "%s@%d::mpt_ioctl_iocinfo() - memdup_user returned error [%ld]\n",
1256 __FILE__, __LINE__, PTR_ERR(karg));
1257 return PTR_ERR(karg);
1260 /* Verify the data transfer size is correct. */
1261 if (karg->hdr.maxDataSize != data_size) {
1262 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
1263 "Structure size mismatch. Command not completed.\n",
1264 ioc->name, __FILE__, __LINE__);
1269 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_getiocinfo called.\n",
1272 /* Fill in the data and return the structure to the calling
1275 if (ioc->bus_type == SAS)
1276 karg->adapterType = MPT_IOCTL_INTERFACE_SAS;
1277 else if (ioc->bus_type == FC)
1278 karg->adapterType = MPT_IOCTL_INTERFACE_FC;
1280 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1282 if (karg->hdr.port > 1) {
1286 port = karg->hdr.port;
1289 pdev = (struct pci_dev *) ioc->pcidev;
1291 karg->pciId = pdev->device;
1292 karg->hwRev = pdev->revision;
1293 karg->subSystemDevice = pdev->subsystem_device;
1294 karg->subSystemVendor = pdev->subsystem_vendor;
1297 /* Get the PCI bus, device, and function numbers for the IOC
1299 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1300 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1301 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1302 } else if (cim_rev == 2) {
1303 /* Get the PCI bus, device, function and segment ID numbers
1305 karg->pciInfo.u.bits.busNumber = pdev->bus->number;
1306 karg->pciInfo.u.bits.deviceNumber = PCI_SLOT( pdev->devfn );
1307 karg->pciInfo.u.bits.functionNumber = PCI_FUNC( pdev->devfn );
1308 karg->pciInfo.segmentID = pci_domain_nr(pdev->bus);
1311 /* Get number of devices
1313 karg->numDevices = 0;
1315 shost_for_each_device(sdev, ioc->sh) {
1316 vdevice = sdev->hostdata;
1317 if (vdevice == NULL || vdevice->vtarget == NULL)
1319 if (vdevice->vtarget->tflags &
1320 MPT_TARGET_FLAGS_RAID_COMPONENT)
1326 /* Set the BIOS and FW Version
1328 karg->FWVersion = ioc->facts.FWVersion.Word;
1329 karg->BIOSVersion = ioc->biosVersion;
1331 /* Set the Version Strings.
1333 strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH);
1334 karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0';
1336 karg->busChangeEvent = 0;
1337 karg->hostId = ioc->pfacts[port].PortSCSIID;
1338 karg->rsvd[0] = karg->rsvd[1] = 0;
1340 /* Copy the data from kernel memory to user memory
1342 if (copy_to_user((char __user *)arg, karg, data_size)) {
1343 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
1344 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1345 ioc->name, __FILE__, __LINE__, uarg);
1354 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1356 * mptctl_gettargetinfo - Query the host adapter for target information.
1357 * @arg: User space argument
1360 * Return: 0 if successful
1361 * -EFAULT if data unavailable
1362 * -ENODEV if no such device/adapter
1365 mptctl_gettargetinfo (MPT_ADAPTER *ioc, unsigned long arg)
1367 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1368 struct mpt_ioctl_targetinfo karg;
1369 VirtDevice *vdevice;
1376 struct scsi_device *sdev;
1378 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
1379 printk(KERN_ERR MYNAM "%s@%d::mptctl_gettargetinfo - "
1380 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1381 __FILE__, __LINE__, uarg);
1385 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_gettargetinfo called.\n",
1387 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1388 maxWordsLeft = numBytes/sizeof(int);
1390 if (maxWordsLeft <= 0) {
1391 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1392 ioc->name, __FILE__, __LINE__);
1396 /* Fill in the data and return the structure to the calling
1400 /* struct mpt_ioctl_targetinfo does not contain sufficient space
1401 * for the target structures so when the IOCTL is called, there is
1402 * not sufficient stack space for the structure. Allocate memory,
1403 * populate the memory, copy back to the user, then free memory.
1404 * targetInfo format:
1405 * bits 31-24: reserved
1410 pmem = kzalloc(numBytes, GFP_KERNEL);
1412 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
1413 ioc->name, __FILE__, __LINE__);
1416 pdata = (int *) pmem;
1418 /* Get number of devices
1421 shost_for_each_device(sdev, ioc->sh) {
1424 vdevice = sdev->hostdata;
1425 if (vdevice == NULL || vdevice->vtarget == NULL)
1427 if (vdevice->vtarget->tflags &
1428 MPT_TARGET_FLAGS_RAID_COMPONENT)
1430 lun = (vdevice->vtarget->raidVolume) ? 0x80 : vdevice->lun;
1431 *pdata = (((u8)lun << 16) + (vdevice->vtarget->channel << 8) +
1432 (vdevice->vtarget->id ));
1438 karg.numDevices = numDevices;
1440 /* Copy part of the data from kernel memory to user memory
1442 if (copy_to_user((char __user *)arg, &karg,
1443 sizeof(struct mpt_ioctl_targetinfo))) {
1444 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
1445 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1446 ioc->name, __FILE__, __LINE__, uarg);
1451 /* Copy the remaining data from kernel memory to user memory
1453 if (copy_to_user(uarg->targetInfo, pmem, numBytes)) {
1454 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo - "
1455 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1456 ioc->name, __FILE__, __LINE__, pdata);
1466 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1467 /* MPT IOCTL Test function.
1470 * Return: 0 if successful
1471 * -EFAULT if data unavailable
1472 * -ENODEV if no such device/adapter
1475 mptctl_readtest (MPT_ADAPTER *ioc, unsigned long arg)
1477 struct mpt_ioctl_test __user *uarg = (void __user *) arg;
1478 struct mpt_ioctl_test karg;
1480 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_test))) {
1481 printk(KERN_ERR MYNAM "%s@%d::mptctl_readtest - "
1482 "Unable to read in mpt_ioctl_test struct @ %p\n",
1483 __FILE__, __LINE__, uarg);
1487 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_readtest called.\n",
1489 /* Fill in the data and return the structure to the calling
1494 karg.chip_type = ioc->mfcnt;
1496 karg.chip_type = ioc->pcidev->device;
1498 strncpy (karg.name, ioc->name, MPT_MAX_NAME);
1499 karg.name[MPT_MAX_NAME-1]='\0';
1500 strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH);
1501 karg.product[MPT_PRODUCT_LENGTH-1]='\0';
1503 /* Copy the data from kernel memory to user memory
1505 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_test))) {
1506 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_readtest - "
1507 "Unable to write out mpt_ioctl_test struct @ %p\n",
1508 ioc->name, __FILE__, __LINE__, uarg);
1515 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1517 * mptctl_eventquery - Query the host adapter for the event types
1518 * that are being logged.
1519 * @arg: User space argument
1522 * Return: 0 if successful
1523 * -EFAULT if data unavailable
1524 * -ENODEV if no such device/adapter
1527 mptctl_eventquery (MPT_ADAPTER *ioc, unsigned long arg)
1529 struct mpt_ioctl_eventquery __user *uarg = (void __user *) arg;
1530 struct mpt_ioctl_eventquery karg;
1532 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventquery))) {
1533 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventquery - "
1534 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1535 __FILE__, __LINE__, uarg);
1539 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventquery called.\n",
1541 karg.eventEntries = MPTCTL_EVENT_LOG_SIZE;
1542 karg.eventTypes = ioc->eventTypes;
1544 /* Copy the data from kernel memory to user memory
1546 if (copy_to_user((char __user *)arg, &karg, sizeof(struct mpt_ioctl_eventquery))) {
1547 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventquery - "
1548 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1549 ioc->name, __FILE__, __LINE__, uarg);
1555 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1557 mptctl_eventenable (MPT_ADAPTER *ioc, unsigned long arg)
1559 struct mpt_ioctl_eventenable __user *uarg = (void __user *) arg;
1560 struct mpt_ioctl_eventenable karg;
1562 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventenable))) {
1563 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventenable - "
1564 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1565 __FILE__, __LINE__, uarg);
1569 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventenable called.\n",
1571 if (ioc->events == NULL) {
1572 /* Have not yet allocated memory - do so now.
1574 int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1575 ioc->events = kzalloc(sz, GFP_KERNEL);
1577 printk(MYIOC_s_ERR_FMT
1578 ": ERROR - Insufficient memory to add adapter!\n",
1582 ioc->alloc_total += sz;
1584 ioc->eventContext = 0;
1587 /* Update the IOC event logging flag.
1589 ioc->eventTypes = karg.eventTypes;
1594 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1596 mptctl_eventreport (MPT_ADAPTER *ioc, unsigned long arg)
1598 struct mpt_ioctl_eventreport __user *uarg = (void __user *) arg;
1599 struct mpt_ioctl_eventreport karg;
1600 int numBytes, maxEvents, max;
1602 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_eventreport))) {
1603 printk(KERN_ERR MYNAM "%s@%d::mptctl_eventreport - "
1604 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1605 __FILE__, __LINE__, uarg);
1609 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n",
1612 numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
1613 maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
1616 max = MPTCTL_EVENT_LOG_SIZE < maxEvents ? MPTCTL_EVENT_LOG_SIZE : maxEvents;
1618 /* If fewer than 1 event is requested, there must have
1619 * been some type of error.
1621 if ((max < 1) || !ioc->events)
1624 /* reset this flag so SIGIO can restart */
1625 ioc->aen_event_read_flag=0;
1627 /* Copy the data from kernel memory to user memory
1629 numBytes = max * sizeof(MPT_IOCTL_EVENTS);
1630 if (copy_to_user(uarg->eventData, ioc->events, numBytes)) {
1631 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_eventreport - "
1632 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1633 ioc->name, __FILE__, __LINE__, ioc->events);
1640 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1642 mptctl_replace_fw (MPT_ADAPTER *ioc, unsigned long arg)
1644 struct mpt_ioctl_replace_fw __user *uarg = (void __user *) arg;
1645 struct mpt_ioctl_replace_fw karg;
1648 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
1649 printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - "
1650 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1651 __FILE__, __LINE__, uarg);
1655 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_replace_fw called.\n",
1657 /* If caching FW, Free the old FW image
1659 if (ioc->cached_fw == NULL)
1662 mpt_free_fw_memory(ioc);
1664 /* Allocate memory for the new FW image
1666 newFwSize = ALIGN(karg.newImageSize, 4);
1668 mpt_alloc_fw_memory(ioc, newFwSize);
1669 if (ioc->cached_fw == NULL)
1672 /* Copy the data from user memory to kernel space
1674 if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
1675 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - "
1676 "Unable to read in mpt_ioctl_replace_fw image "
1677 "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
1678 mpt_free_fw_memory(ioc);
1682 /* Update IOCFactsReply
1684 ioc->facts.FWImageSize = newFwSize;
1688 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1689 /* MPT IOCTL MPTCOMMAND function.
1690 * Cast the arg into the mpt_ioctl_mpt_command structure.
1693 * Return: 0 if successful
1694 * -EBUSY if previous command timeout and IOC reset is not complete.
1695 * -EFAULT if data unavailable
1696 * -ENODEV if no such device/adapter
1697 * -ETIME if timer expires
1698 * -ENOMEM if memory allocation error
1701 mptctl_mpt_command (MPT_ADAPTER *ioc, unsigned long arg)
1703 struct mpt_ioctl_command __user *uarg = (void __user *) arg;
1704 struct mpt_ioctl_command karg;
1708 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_command))) {
1709 printk(KERN_ERR MYNAM "%s@%d::mptctl_mpt_command - "
1710 "Unable to read in mpt_ioctl_command struct @ %p\n",
1711 __FILE__, __LINE__, uarg);
1715 rc = mptctl_do_mpt_command (ioc, karg, &uarg->MF);
1720 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1721 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1724 * Return: 0 if successful
1725 * -EBUSY if previous command timeout and IOC reset is not complete.
1726 * -EFAULT if data unavailable
1727 * -ENODEV if no such device/adapter
1728 * -ETIME if timer expires
1729 * -ENOMEM if memory allocation error
1730 * -EPERM if SCSI I/O and target is untagged
1733 mptctl_do_mpt_command (MPT_ADAPTER *ioc, struct mpt_ioctl_command karg, void __user *mfPtr)
1735 MPT_FRAME_HDR *mf = NULL;
1738 struct buflist bufIn; /* data In buffer */
1739 struct buflist bufOut; /* data Out buffer */
1740 dma_addr_t dma_addr_in;
1741 dma_addr_t dma_addr_out;
1742 int sgSize = 0; /* Num SG elements */
1748 unsigned long timeleft;
1749 struct scsi_device *sdev;
1750 unsigned long flags;
1753 /* bufIn and bufOut are used for user to kernel space transfers
1755 bufIn.kptr = bufOut.kptr = NULL;
1756 bufIn.len = bufOut.len = 0;
1758 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
1759 if (ioc->ioc_reset_in_progress) {
1760 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
1761 printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
1762 "Busy with diagnostic reset\n", __FILE__, __LINE__);
1765 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
1767 /* Basic sanity checks to prevent underflows or integer overflows */
1768 if (karg.maxReplyBytes < 0 ||
1769 karg.dataInSize < 0 ||
1770 karg.dataOutSize < 0 ||
1771 karg.dataSgeOffset < 0 ||
1772 karg.maxSenseBytes < 0 ||
1773 karg.dataSgeOffset > ioc->req_sz / 4)
1776 /* Verify that the final request frame will not be too large.
1778 sz = karg.dataSgeOffset * 4;
1779 if (karg.dataInSize > 0)
1780 sz += ioc->SGE_size;
1781 if (karg.dataOutSize > 0)
1782 sz += ioc->SGE_size;
1784 if (sz > ioc->req_sz) {
1785 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1786 "Request frame too large (%d) maximum (%d)\n",
1787 ioc->name, __FILE__, __LINE__, sz, ioc->req_sz);
1791 /* Get a free request frame and save the message context.
1793 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
1796 hdr = (MPIHeader_t *) mf;
1797 msgContext = le32_to_cpu(hdr->MsgContext);
1798 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1800 /* Copy the request frame
1801 * Reset the saved message context.
1802 * Request frame in user space
1804 if (copy_from_user(mf, mfPtr, karg.dataSgeOffset * 4)) {
1805 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1806 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1807 ioc->name, __FILE__, __LINE__, mfPtr);
1812 hdr->MsgContext = cpu_to_le32(msgContext);
1813 function = hdr->Function;
1816 /* Verify that this request is allowed.
1818 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n",
1819 ioc->name, hdr->Function, mf));
1822 case MPI_FUNCTION_IOC_FACTS:
1823 case MPI_FUNCTION_PORT_FACTS:
1824 karg.dataOutSize = karg.dataInSize = 0;
1827 case MPI_FUNCTION_CONFIG:
1829 Config_t *config_frame;
1830 config_frame = (Config_t *)mf;
1831 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\ttype=0x%02x ext_type=0x%02x "
1832 "number=0x%02x action=0x%02x\n", ioc->name,
1833 config_frame->Header.PageType,
1834 config_frame->ExtPageType,
1835 config_frame->Header.PageNumber,
1836 config_frame->Action));
1840 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND:
1841 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND:
1842 case MPI_FUNCTION_FW_UPLOAD:
1843 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
1844 case MPI_FUNCTION_FW_DOWNLOAD:
1845 case MPI_FUNCTION_FC_PRIMITIVE_SEND:
1846 case MPI_FUNCTION_TOOLBOX:
1847 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
1850 case MPI_FUNCTION_SCSI_IO_REQUEST:
1852 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1853 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1858 id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
1859 if (pScsiReq->TargetID > id) {
1860 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1861 "Target ID out of bounds. \n",
1862 ioc->name, __FILE__, __LINE__);
1867 if (pScsiReq->Bus >= ioc->number_of_buses) {
1868 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1869 "Target Bus out of bounds. \n",
1870 ioc->name, __FILE__, __LINE__);
1875 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1876 pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
1879 /* verify that app has not requested
1880 * more sense data than driver
1881 * can provide, if so, reset this parameter
1882 * set the sense buffer pointer low address
1883 * update the control field to specify Q type
1885 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1886 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1888 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1890 pScsiReq->SenseBufferLowAddr =
1891 cpu_to_le32(ioc->sense_buf_low_dma
1892 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1894 shost_for_each_device(sdev, ioc->sh) {
1895 struct scsi_target *starget = scsi_target(sdev);
1896 VirtTarget *vtarget = starget->hostdata;
1898 if (vtarget == NULL)
1901 if ((pScsiReq->TargetID == vtarget->id) &&
1902 (pScsiReq->Bus == vtarget->channel) &&
1903 (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1904 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1907 /* Have the IOCTL driver set the direction based
1908 * on the dataOutSize (ordering issue with Sparc).
1910 if (karg.dataOutSize > 0) {
1911 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1912 dataSize = karg.dataOutSize;
1914 scsidir = MPI_SCSIIO_CONTROL_READ;
1915 dataSize = karg.dataInSize;
1918 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1919 pScsiReq->DataLength = cpu_to_le32(dataSize);
1923 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1924 "SCSI driver is not loaded. \n",
1925 ioc->name, __FILE__, __LINE__);
1931 case MPI_FUNCTION_SMP_PASSTHROUGH:
1932 /* Check mf->PassthruFlags to determine if
1933 * transfer is ImmediateMode or not.
1934 * Immediate mode returns data in the ReplyFrame.
1935 * Else, we are sending request and response data
1936 * in two SGLs at the end of the mf.
1940 case MPI_FUNCTION_SATA_PASSTHROUGH:
1942 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
1943 "SCSI driver is not loaded. \n",
1944 ioc->name, __FILE__, __LINE__);
1950 case MPI_FUNCTION_RAID_ACTION:
1955 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
1957 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1958 int qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1959 int scsidir = MPI_SCSIIO_CONTROL_READ;
1962 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1963 pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
1966 /* verify that app has not requested
1967 * more sense data than driver
1968 * can provide, if so, reset this parameter
1969 * set the sense buffer pointer low address
1970 * update the control field to specify Q type
1972 if (karg.maxSenseBytes > MPT_SENSE_BUFFER_SIZE)
1973 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1975 pScsiReq->SenseBufferLength = karg.maxSenseBytes;
1977 pScsiReq->SenseBufferLowAddr =
1978 cpu_to_le32(ioc->sense_buf_low_dma
1979 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1981 /* All commands to physical devices are tagged
1984 /* Have the IOCTL driver set the direction based
1985 * on the dataOutSize (ordering issue with Sparc).
1987 if (karg.dataOutSize > 0) {
1988 scsidir = MPI_SCSIIO_CONTROL_WRITE;
1989 dataSize = karg.dataOutSize;
1991 scsidir = MPI_SCSIIO_CONTROL_READ;
1992 dataSize = karg.dataInSize;
1995 pScsiReq->Control = cpu_to_le32(scsidir | qtag);
1996 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_SCSI_TASK_MGMT:
2009 SCSITaskMgmt_t *pScsiTm;
2010 pScsiTm = (SCSITaskMgmt_t *)mf;
2011 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2012 "\tTaskType=0x%x MsgFlags=0x%x "
2013 "TaskMsgContext=0x%x id=%d channel=%d\n",
2014 ioc->name, pScsiTm->TaskType, le32_to_cpu
2015 (pScsiTm->TaskMsgContext), pScsiTm->MsgFlags,
2016 pScsiTm->TargetID, pScsiTm->Bus));
2020 case MPI_FUNCTION_IOC_INIT:
2022 IOCInit_t *pInit = (IOCInit_t *) mf;
2023 u32 high_addr, sense_high;
2025 /* Verify that all entries in the IOC INIT match
2026 * existing setup (and in LE format).
2028 if (sizeof(dma_addr_t) == sizeof(u64)) {
2029 high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
2030 sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2036 if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
2037 (pInit->MaxBuses != ioc->facts.MaxBuses) ||
2038 (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
2039 (pInit->HostMfaHighAddr != high_addr) ||
2040 (pInit->SenseBufferHighAddr != sense_high)) {
2041 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2042 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2043 ioc->name, __FILE__, __LINE__);
2051 * MPI_FUNCTION_PORT_ENABLE
2052 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2053 * MPI_FUNCTION_TARGET_ASSIST
2054 * MPI_FUNCTION_TARGET_STATUS_SEND
2055 * MPI_FUNCTION_TARGET_MODE_ABORT
2056 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2057 * MPI_FUNCTION_IO_UNIT_RESET
2058 * MPI_FUNCTION_HANDSHAKE
2059 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2060 * MPI_FUNCTION_EVENT_NOTIFICATION
2061 * (driver handles event notification)
2062 * MPI_FUNCTION_EVENT_ACK
2065 /* What to do with these??? CHECK ME!!!
2066 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2067 MPI_FUNCTION_FC_LINK_SRVC_RSP
2068 MPI_FUNCTION_FC_ABORT
2069 MPI_FUNCTION_LAN_SEND
2070 MPI_FUNCTION_LAN_RECEIVE
2071 MPI_FUNCTION_LAN_RESET
2074 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2075 "Illegal request (function 0x%x) \n",
2076 ioc->name, __FILE__, __LINE__, hdr->Function);
2081 /* Add the SGL ( at most one data in SGE and one data out SGE )
2082 * In the case of two SGE's - the data out (write) will always
2083 * preceede the data in (read) SGE. psgList is used to free the
2086 psge = (char *) (((int *) mf) + karg.dataSgeOffset);
2089 if (karg.dataOutSize > 0)
2092 if (karg.dataInSize > 0)
2097 /* Set up the dataOut memory allocation */
2098 if (karg.dataOutSize > 0) {
2099 if (karg.dataInSize > 0) {
2100 flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2101 MPI_SGE_FLAGS_END_OF_BUFFER |
2102 MPI_SGE_FLAGS_DIRECTION)
2103 << MPI_SGE_FLAGS_SHIFT;
2105 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
2107 flagsLength |= karg.dataOutSize;
2108 bufOut.len = karg.dataOutSize;
2109 bufOut.kptr = dma_alloc_coherent(&ioc->pcidev->dev,
2111 &dma_addr_out, GFP_KERNEL);
2113 if (bufOut.kptr == NULL) {
2118 * Copy to MF and to sglbuf
2120 ioc->add_sge(psge, flagsLength, dma_addr_out);
2121 psge += ioc->SGE_size;
2123 /* Copy user data to kernel space.
2125 if (copy_from_user(bufOut.kptr,
2128 printk(MYIOC_s_ERR_FMT
2129 "%s@%d::mptctl_do_mpt_command - Unable "
2130 "to read user data "
2132 ioc->name, __FILE__, __LINE__,karg.dataOutBufPtr);
2139 if (karg.dataInSize > 0) {
2140 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2141 flagsLength |= karg.dataInSize;
2143 bufIn.len = karg.dataInSize;
2144 bufIn.kptr = dma_alloc_coherent(&ioc->pcidev->dev,
2146 &dma_addr_in, GFP_KERNEL);
2148 if (bufIn.kptr == NULL) {
2153 * Copy to MF and to sglbuf
2155 ioc->add_sge(psge, flagsLength, dma_addr_in);
2161 ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
2164 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext);
2165 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
2166 if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
2168 mutex_lock(&ioc->taskmgmt_cmds.mutex);
2169 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
2170 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2174 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
2176 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
2177 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
2178 mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
2180 rc =mpt_send_handshake_request(mptctl_id, ioc,
2181 sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
2183 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2184 "send_handshake FAILED! (ioc %p, mf %p)\n",
2185 ioc->name, ioc, mf));
2186 mpt_clear_taskmgmt_in_progress_flag(ioc);
2188 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2194 mpt_put_msg_frame(mptctl_id, ioc, mf);
2196 /* Now wait for the command to complete */
2197 timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
2199 timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
2201 if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2203 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n",
2204 ioc->name, __func__));
2205 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
2206 if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
2207 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2211 printk(MYIOC_s_WARN_FMT
2212 "mpt cmd timeout, doorbell=0x%08x"
2214 ioc->name, mpt_GetIocState(ioc, 0), function);
2215 if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
2216 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2217 mptctl_timeout_expired(ioc, mf);
2224 if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
2225 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
2230 /* If a valid reply frame, copy to the user.
2231 * Offset 2: reply length in U32's
2233 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
2234 if (karg.maxReplyBytes < ioc->reply_sz) {
2235 sz = min(karg.maxReplyBytes,
2236 4*ioc->ioctl_cmds.reply[2]);
2238 sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]);
2241 if (copy_to_user(karg.replyFrameBufPtr,
2242 ioc->ioctl_cmds.reply, sz)){
2243 printk(MYIOC_s_ERR_FMT
2244 "%s@%d::mptctl_do_mpt_command - "
2245 "Unable to write out reply frame %p\n",
2246 ioc->name, __FILE__, __LINE__, karg.replyFrameBufPtr);
2253 /* If valid sense data, copy to user.
2255 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) {
2256 sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
2258 if (copy_to_user(karg.senseDataPtr,
2259 ioc->ioctl_cmds.sense, sz)) {
2260 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2261 "Unable to write sense data to user %p\n",
2262 ioc->name, __FILE__, __LINE__,
2270 /* If the overall status is _GOOD and data in, copy data
2273 if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) &&
2274 (karg.dataInSize > 0) && (bufIn.kptr)) {
2276 if (copy_to_user(karg.dataInBufPtr,
2277 bufIn.kptr, karg.dataInSize)) {
2278 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
2279 "Unable to write data to user %p\n",
2280 ioc->name, __FILE__, __LINE__,
2288 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
2289 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
2291 /* Free the allocated memory.
2293 if (bufOut.kptr != NULL) {
2294 dma_free_coherent(&ioc->pcidev->dev, bufOut.len,
2295 (void *)bufOut.kptr, dma_addr_out);
2298 if (bufIn.kptr != NULL) {
2299 dma_free_coherent(&ioc->pcidev->dev, bufIn.len,
2300 (void *)bufIn.kptr, dma_addr_in);
2303 /* mf is null if command issued successfully
2304 * otherwise, failure occurred after mf acquired.
2307 mpt_free_msg_frame(ioc, mf);
2312 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2313 /* Prototype Routine for the HOST INFO command.
2316 * Return: 0 if successful
2317 * -EFAULT if data unavailable
2318 * -EBUSY if previous command timeout and IOC reset is not complete.
2319 * -ENODEV if no such device/adapter
2320 * -ETIME if timer expires
2321 * -ENOMEM if memory allocation error
2324 mptctl_hp_hostinfo(MPT_ADAPTER *ioc, unsigned long arg, unsigned int data_size)
2326 hp_host_info_t __user *uarg = (void __user *) arg;
2327 struct pci_dev *pdev;
2330 hp_host_info_t karg;
2332 ConfigPageHeader_t hdr;
2334 ToolboxIstwiReadWriteRequest_t *IstwiRWRequest;
2335 MPT_FRAME_HDR *mf = NULL;
2336 unsigned long timeleft;
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 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n",
2358 /* Fill in the data and return the structure to the calling
2361 pdev = (struct pci_dev *) ioc->pcidev;
2363 karg.vendor = pdev->vendor;
2364 karg.device = pdev->device;
2365 karg.subsystem_id = pdev->subsystem_device;
2366 karg.subsystem_vendor = pdev->subsystem_vendor;
2367 karg.devfn = pdev->devfn;
2368 karg.bus = pdev->bus->number;
2370 /* Save the SCSI host no. if
2371 * SCSI driver loaded
2373 if (ioc->sh != NULL)
2374 karg.host_no = ioc->sh->host_no;
2378 /* Reformat the fw_version into a string */
2379 snprintf(karg.fw_version, sizeof(karg.fw_version),
2380 "%.2hhu.%.2hhu.%.2hhu.%.2hhu",
2381 ioc->facts.FWVersion.Struct.Major,
2382 ioc->facts.FWVersion.Struct.Minor,
2383 ioc->facts.FWVersion.Struct.Unit,
2384 ioc->facts.FWVersion.Struct.Dev);
2386 /* Issue a config request to get the device serial number
2388 hdr.PageVersion = 0;
2391 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2392 cfg.cfghdr.hdr = &hdr;
2395 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2396 cfg.dir = 0; /* read */
2399 strncpy(karg.serial_number, " ", 24);
2400 if (mpt_config(ioc, &cfg) == 0) {
2401 if (cfg.cfghdr.hdr->PageLength > 0) {
2402 /* Issue the second config page request */
2403 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2405 pbuf = dma_alloc_coherent(&ioc->pcidev->dev,
2407 &buf_dma, GFP_KERNEL);
2409 cfg.physAddr = buf_dma;
2410 if (mpt_config(ioc, &cfg) == 0) {
2411 ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
2412 if (strlen(pdata->BoardTracerNumber) > 1) {
2413 strlcpy(karg.serial_number,
2414 pdata->BoardTracerNumber, 24);
2417 dma_free_coherent(&ioc->pcidev->dev,
2418 hdr.PageLength * 4, pbuf,
2424 rc = mpt_GetIocState(ioc, 1);
2426 case MPI_IOC_STATE_OPERATIONAL:
2427 karg.ioc_status = HP_STATUS_OK;
2430 case MPI_IOC_STATE_FAULT:
2431 karg.ioc_status = HP_STATUS_FAILED;
2434 case MPI_IOC_STATE_RESET:
2435 case MPI_IOC_STATE_READY:
2437 karg.ioc_status = HP_STATUS_OTHER;
2441 karg.base_io_addr = pci_resource_start(pdev, 0);
2443 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2444 karg.bus_phys_width = HP_BUS_WIDTH_UNK;
2446 karg.bus_phys_width = HP_BUS_WIDTH_16;
2448 karg.hard_resets = 0;
2449 karg.soft_resets = 0;
2451 if (ioc->sh != NULL) {
2452 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
2454 if (hd && (cim_rev == 1)) {
2455 karg.hard_resets = ioc->hard_resets;
2456 karg.soft_resets = ioc->soft_resets;
2457 karg.timeouts = ioc->timeouts;
2462 * Gather ISTWI(Industry Standard Two Wire Interface) Data
2464 if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
2465 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
2466 "%s, no msg frames!!\n", ioc->name, __func__));
2470 IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
2471 msgcontext = IstwiRWRequest->MsgContext;
2472 memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
2473 IstwiRWRequest->MsgContext = msgcontext;
2474 IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
2475 IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
2476 IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
2477 IstwiRWRequest->NumAddressBytes = 0x01;
2478 IstwiRWRequest->DataLength = cpu_to_le16(0x04);
2479 if (pdev->devfn & 1)
2480 IstwiRWRequest->DeviceAddr = 0xB2;
2482 IstwiRWRequest->DeviceAddr = 0xB0;
2484 pbuf = dma_alloc_coherent(&ioc->pcidev->dev, 4, &buf_dma, GFP_KERNEL);
2487 ioc->add_sge((char *)&IstwiRWRequest->SGL,
2488 (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
2490 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
2491 IstwiRWRequest->MsgContext);
2492 INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
2493 mpt_put_msg_frame(mptctl_id, ioc, mf);
2496 timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
2497 HZ*MPT_IOCTL_DEFAULT_TIMEOUT);
2498 if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2499 printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__);
2500 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
2501 mpt_free_msg_frame(ioc, mf);
2505 printk(MYIOC_s_WARN_FMT
2506 "HOST INFO command timeout, doorbell=0x%08x\n",
2507 ioc->name, mpt_GetIocState(ioc, 0));
2508 mptctl_timeout_expired(ioc, mf);
2515 *ISTWI Data Definition
2516 * pbuf[0] = FW_VERSION = 0x4
2517 * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
2518 * the config, you should be seeing one out of these three values
2519 * pbuf[2] = Drive Installed Map = bit pattern depend on which
2520 * bays have drives in them
2521 * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
2523 if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)
2524 karg.rsvd = *(u32 *)pbuf;
2527 CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
2528 SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
2531 dma_free_coherent(&ioc->pcidev->dev, 4, pbuf, buf_dma);
2533 /* Copy the data from kernel memory to user memory
2535 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_host_info_t))) {
2536 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hpgethostinfo - "
2537 "Unable to write out hp_host_info @ %p\n",
2538 ioc->name, __FILE__, __LINE__, uarg);
2546 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2547 /* Prototype Routine for the TARGET INFO command.
2550 * Return: 0 if successful
2551 * -EFAULT if data unavailable
2552 * -EBUSY if previous command timeout and IOC reset is not complete.
2553 * -ENODEV if no such device/adapter
2554 * -ETIME if timer expires
2555 * -ENOMEM if memory allocation error
2558 mptctl_hp_targetinfo(MPT_ADAPTER *ioc, unsigned long arg)
2560 hp_target_info_t __user *uarg = (void __user *) arg;
2561 SCSIDevicePage0_t *pg0_alloc;
2562 SCSIDevicePage3_t *pg3_alloc;
2563 MPT_SCSI_HOST *hd = NULL;
2564 hp_target_info_t karg;
2566 dma_addr_t page_dma;
2568 ConfigPageHeader_t hdr;
2569 int tmp, np, rc = 0;
2571 if (copy_from_user(&karg, uarg, sizeof(hp_target_info_t))) {
2572 printk(KERN_ERR MYNAM "%s@%d::mptctl_hp_targetinfo - "
2573 "Unable to read in hp_host_targetinfo struct @ %p\n",
2574 __FILE__, __LINE__, uarg);
2578 if (karg.hdr.id >= MPT_MAX_FC_DEVICES)
2580 dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
2583 /* There is nothing to do for FCP parts.
2585 if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
2588 if ((ioc->spi_data.sdp0length == 0) || (ioc->sh == NULL))
2591 if (ioc->sh->host_no != karg.hdr.host)
2594 /* Get the data transfer speeds
2596 data_sz = ioc->spi_data.sdp0length * 4;
2597 pg0_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz, &page_dma,
2600 hdr.PageVersion = ioc->spi_data.sdp0version;
2601 hdr.PageLength = data_sz;
2603 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2605 cfg.cfghdr.hdr = &hdr;
2606 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2609 cfg.physAddr = page_dma;
2611 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2613 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2614 np = le32_to_cpu(pg0_alloc->NegotiatedParameters);
2615 karg.negotiated_width = np & MPI_SCSIDEVPAGE0_NP_WIDE ?
2616 HP_BUS_WIDTH_16 : HP_BUS_WIDTH_8;
2618 if (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) {
2619 tmp = (np & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
2621 karg.negotiated_speed = HP_DEV_SPEED_ULTRA320;
2622 else if (tmp <= 0x09)
2623 karg.negotiated_speed = HP_DEV_SPEED_ULTRA160;
2624 else if (tmp <= 0x0A)
2625 karg.negotiated_speed = HP_DEV_SPEED_ULTRA2;
2626 else if (tmp <= 0x0C)
2627 karg.negotiated_speed = HP_DEV_SPEED_ULTRA;
2628 else if (tmp <= 0x25)
2629 karg.negotiated_speed = HP_DEV_SPEED_FAST;
2631 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2633 karg.negotiated_speed = HP_DEV_SPEED_ASYNC;
2636 dma_free_coherent(&ioc->pcidev->dev, data_sz, (u8 *)pg0_alloc,
2642 karg.message_rejects = -1;
2643 karg.phase_errors = -1;
2644 karg.parity_errors = -1;
2645 karg.select_timeouts = -1;
2647 /* Get the target error parameters
2649 hdr.PageVersion = 0;
2652 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2654 cfg.cfghdr.hdr = &hdr;
2655 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2659 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2660 /* Issue the second config page request */
2661 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2662 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2663 pg3_alloc = dma_alloc_coherent(&ioc->pcidev->dev, data_sz,
2664 &page_dma, GFP_KERNEL);
2666 cfg.physAddr = page_dma;
2667 cfg.pageAddr = (karg.hdr.channel << 8) | karg.hdr.id;
2668 if ((rc = mpt_config(ioc, &cfg)) == 0) {
2669 karg.message_rejects = (u32) le16_to_cpu(pg3_alloc->MsgRejectCount);
2670 karg.phase_errors = (u32) le16_to_cpu(pg3_alloc->PhaseErrorCount);
2671 karg.parity_errors = (u32) le16_to_cpu(pg3_alloc->ParityErrorCount);
2673 dma_free_coherent(&ioc->pcidev->dev, data_sz,
2674 (u8 *)pg3_alloc, page_dma);
2677 hd = shost_priv(ioc->sh);
2679 karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
2681 /* Copy the data from kernel memory to user memory
2683 if (copy_to_user((char __user *)arg, &karg, sizeof(hp_target_info_t))) {
2684 printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_hp_target_info - "
2685 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2686 ioc->name, __FILE__, __LINE__, uarg);
2693 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2695 static const struct file_operations mptctl_fops = {
2696 .owner = THIS_MODULE,
2697 .llseek = no_llseek,
2698 .fasync = mptctl_fasync,
2699 .unlocked_ioctl = mptctl_ioctl,
2700 #ifdef CONFIG_COMPAT
2701 .compat_ioctl = compat_mpctl_ioctl,
2705 static struct miscdevice mptctl_miscdev = {
2711 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2713 #ifdef CONFIG_COMPAT
2716 compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
2719 struct mpt_fw_xfer32 kfw32;
2720 struct mpt_fw_xfer kfw;
2721 MPT_ADAPTER *iocp = NULL;
2722 int iocnum, iocnumX;
2723 int nonblock = (filp->f_flags & O_NONBLOCK);
2727 if (copy_from_user(&kfw32, (char __user *)arg, sizeof(kfw32)))
2730 /* Verify intended MPT adapter */
2731 iocnumX = kfw32.iocnum & 0xFF;
2732 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2734 printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2739 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2742 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mptfwxfer_ioctl() called\n",
2744 kfw.iocnum = iocnum;
2745 kfw.fwlen = kfw32.fwlen;
2746 kfw.bufp = compat_ptr(kfw32.bufp);
2748 ret = mptctl_do_fw_download(iocp, kfw.bufp, kfw.fwlen);
2750 mutex_unlock(&iocp->ioctl_cmds.mutex);
2756 compat_mpt_command(struct file *filp, unsigned int cmd,
2759 struct mpt_ioctl_command32 karg32;
2760 struct mpt_ioctl_command32 __user *uarg = (struct mpt_ioctl_command32 __user *) arg;
2761 struct mpt_ioctl_command karg;
2762 MPT_ADAPTER *iocp = NULL;
2763 int iocnum, iocnumX;
2764 int nonblock = (filp->f_flags & O_NONBLOCK);
2767 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32)))
2770 /* Verify intended MPT adapter */
2771 iocnumX = karg32.hdr.iocnum & 0xFF;
2772 if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
2774 printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
2779 if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
2782 dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "compat_mpt_command() called\n",
2784 /* Copy data to karg */
2785 karg.hdr.iocnum = karg32.hdr.iocnum;
2786 karg.hdr.port = karg32.hdr.port;
2787 karg.timeout = karg32.timeout;
2788 karg.maxReplyBytes = karg32.maxReplyBytes;
2790 karg.dataInSize = karg32.dataInSize;
2791 karg.dataOutSize = karg32.dataOutSize;
2792 karg.maxSenseBytes = karg32.maxSenseBytes;
2793 karg.dataSgeOffset = karg32.dataSgeOffset;
2795 karg.replyFrameBufPtr = (char __user *)(unsigned long)karg32.replyFrameBufPtr;
2796 karg.dataInBufPtr = (char __user *)(unsigned long)karg32.dataInBufPtr;
2797 karg.dataOutBufPtr = (char __user *)(unsigned long)karg32.dataOutBufPtr;
2798 karg.senseDataPtr = (char __user *)(unsigned long)karg32.senseDataPtr;
2800 /* Pass new structure to do_mpt_command
2802 ret = mptctl_do_mpt_command (iocp, karg, &uarg->MF);
2804 mutex_unlock(&iocp->ioctl_cmds.mutex);
2809 static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2812 mutex_lock(&mpctl_mutex);
2819 case MPTEVENTENABLE:
2820 case MPTEVENTREPORT:
2822 case HP_GETHOSTINFO:
2823 case HP_GETTARGETINFO:
2825 ret = __mptctl_ioctl(f, cmd, arg);
2828 ret = compat_mpt_command(f, cmd, arg);
2830 case MPTFWDOWNLOAD32:
2831 ret = compat_mptfwxfer_ioctl(f, cmd, arg);
2837 mutex_unlock(&mpctl_mutex);
2844 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2846 * mptctl_probe - Installs ioctl devices per bus.
2847 * @pdev: Pointer to pci_dev structure
2849 * Returns 0 for success, non-zero for failure.
2854 mptctl_probe(struct pci_dev *pdev)
2856 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2858 mutex_init(&ioc->ioctl_cmds.mutex);
2859 init_completion(&ioc->ioctl_cmds.done);
2863 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2865 * mptctl_remove - Removed ioctl devices
2866 * @pdev: Pointer to pci_dev structure
2871 mptctl_remove(struct pci_dev *pdev)
2875 static struct mpt_pci_driver mptctl_driver = {
2876 .probe = mptctl_probe,
2877 .remove = mptctl_remove,
2880 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2881 static int __init mptctl_init(void)
2886 show_mptmod_ver(my_NAME, my_VERSION);
2888 mpt_device_driver_register(&mptctl_driver, MPTCTL_DRIVER);
2890 /* Register this device */
2891 err = misc_register(&mptctl_miscdev);
2893 printk(KERN_ERR MYNAM ": Can't register misc device [minor=%d].\n", MPT_MINOR);
2896 printk(KERN_INFO MYNAM ": Registered with Fusion MPT base driver\n");
2897 printk(KERN_INFO MYNAM ": /dev/%s @ (major,minor=%d,%d)\n",
2898 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2901 * Install our handler
2904 mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER,
2906 if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) {
2907 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2908 misc_deregister(&mptctl_miscdev);
2913 mptctl_taskmgmt_id = mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER,
2914 "mptctl_taskmgmt_reply");
2915 if (!mptctl_taskmgmt_id || mptctl_taskmgmt_id >= MPT_MAX_PROTOCOL_DRIVERS) {
2916 printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
2917 mpt_deregister(mptctl_id);
2918 misc_deregister(&mptctl_miscdev);
2923 mpt_reset_register(mptctl_id, mptctl_ioc_reset);
2924 mpt_event_register(mptctl_id, mptctl_event_process);
2930 mpt_device_driver_deregister(MPTCTL_DRIVER);
2935 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2936 static void mptctl_exit(void)
2938 misc_deregister(&mptctl_miscdev);
2939 printk(KERN_INFO MYNAM ": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
2940 mptctl_miscdev.name, MISC_MAJOR, mptctl_miscdev.minor);
2942 /* De-register event handler from base module */
2943 mpt_event_deregister(mptctl_id);
2945 /* De-register reset handler from base module */
2946 mpt_reset_deregister(mptctl_id);
2948 /* De-register callback handler from base module */
2949 mpt_deregister(mptctl_taskmgmt_id);
2950 mpt_deregister(mptctl_id);
2952 mpt_device_driver_deregister(MPTCTL_DRIVER);
2956 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2958 module_init(mptctl_init);
2959 module_exit(mptctl_exit);