2 * linux/drivers/message/fusion/mptctl.c
3 * Fusion MPT misc device (ioctl) driver.
4 * For use with PCI chip/adapter(s):
5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
9 * This driver would not exist if not for Alan Cox's development
10 * of the linux i2o driver.
12 * A special thanks to Pamela Delaney (LSI Logic) for tons of work
13 * and countless enhancements while adding support for the 1030
14 * chip family. Pam has been instrumental in the development of
15 * of the 2.xx.xx series fusion drivers, and her contributions are
16 * far too numerous to hope to list in one place.
18 * A huge debt of gratitude is owed to David S. Miller (DaveM)
19 * for fixing much of the stupid and broken stuff in the early
20 * driver while porting to sparc64 platform. THANK YOU!
22 * A big THANKS to Eddie C. Dost for fixing the ioctl path
23 * and most importantly f/w download on sparc64 platform!
24 * (plus Eddie's other helpful hints and insights)
26 * Thanks to Arnaldo Carvalho de Melo for finding and patching
27 * a potential memory leak in mptctl_do_fw_download(),
28 * and for some kmalloc insight:-)
30 * (see also mptbase.c)
32 * Copyright (c) 1999-2004 LSI Logic Corporation
33 * Originally By: Steven J. Ralston, Noah Romer
34 * (mailto:sjralston1@netscape.net)
35 * (mailto:mpt_linux_developer@lsil.com)
37 * $Id: mptctl.c,v 1.63 2002/12/03 21:26:33 pdelaney Exp $
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
41 This program is free software; you can redistribute it and/or modify
42 it under the terms of the GNU General Public License as published by
43 the Free Software Foundation; version 2 of the License.
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
51 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
52 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
53 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
54 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
55 solely responsible for determining the appropriateness of using and
56 distributing the Program and assumes all risks associated with its
57 exercise of rights under this Agreement, including but not limited to
58 the risks and costs of program errors, damage to or loss of data,
59 programs or equipment, and unavailability or interruption of operations.
61 DISCLAIMER OF LIABILITY
62 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
63 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
65 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
66 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
67 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
68 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
70 You should have received a copy of the GNU General Public License
71 along with this program; if not, write to the Free Software
72 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
76 #include <linux/version.h>
77 #include <linux/kernel.h>
78 #include <linux/module.h>
79 #include <linux/errno.h>
80 #include <linux/init.h>
81 #include <linux/slab.h>
82 #include <linux/types.h>
83 #include <linux/pci.h>
84 #include <linux/miscdevice.h>
85 #include <linux/smp_lock.h>
86 #include <linux/compat.h>
89 #include <asm/uaccess.h>
91 #include <scsi/scsi.h>
92 #include <scsi/scsi_cmnd.h>
93 #include <scsi/scsi_device.h>
94 #include <scsi/scsi_host.h>
95 #include <scsi/scsi_tcq.h>
97 #define COPYRIGHT "Copyright (c) 1999-2004 LSI Logic Corporation"
98 #define MODULEAUTHOR "Steven J. Ralston, Noah Romer, Pamela Delaney"
102 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
103 #define my_NAME "Fusion MPT misc device (ioctl) driver"
104 #define my_VERSION MPT_LINUX_VERSION_COMMON
105 #define MYNAM "mptctl"
107 MODULE_AUTHOR(MODULEAUTHOR
);
108 MODULE_DESCRIPTION(my_NAME
);
109 MODULE_LICENSE("GPL");
111 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
113 static int mptctl_id
= -1;
115 static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait
);
117 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
125 * Function prototypes. Called from OS entry point mptctl_ioctl.
126 * arg contents specific to function.
128 static int mptctl_fw_download(unsigned long arg
);
129 static int mptctl_getiocinfo (unsigned long arg
, unsigned int cmd
);
130 static int mptctl_gettargetinfo (unsigned long arg
);
131 static int mptctl_readtest (unsigned long arg
);
132 static int mptctl_mpt_command (unsigned long arg
);
133 static int mptctl_eventquery (unsigned long arg
);
134 static int mptctl_eventenable (unsigned long arg
);
135 static int mptctl_eventreport (unsigned long arg
);
136 static int mptctl_replace_fw (unsigned long arg
);
138 static int mptctl_do_reset(unsigned long arg
);
139 static int mptctl_hp_hostinfo(unsigned long arg
, unsigned int cmd
);
140 static int mptctl_hp_targetinfo(unsigned long arg
);
142 static int mptctl_probe(struct pci_dev
*, const struct pci_device_id
*);
143 static void mptctl_remove(struct pci_dev
*);
146 * Private function calls.
148 static int mptctl_do_mpt_command (struct mpt_ioctl_command karg
, void __user
*mfPtr
);
149 static int mptctl_do_fw_download(int ioc
, char __user
*ufwbuf
, size_t fwlen
);
150 static MptSge_t
*kbuf_alloc_2_sgl( int bytes
, u32 dir
, int sge_offset
, int *frags
,
151 struct buflist
**blp
, dma_addr_t
*sglbuf_dma
, MPT_ADAPTER
*ioc
);
152 static void kfree_sgl( MptSge_t
*sgl
, dma_addr_t sgl_dma
,
153 struct buflist
*buflist
, MPT_ADAPTER
*ioc
);
154 static void mptctl_timer_expired (unsigned long data
);
155 static int mptctl_bus_reset(MPT_IOCTL
*ioctl
);
156 static int mptctl_set_tm_flags(MPT_SCSI_HOST
*hd
);
157 static void mptctl_free_tm_flags(MPT_ADAPTER
*ioc
);
160 * Reset Handler cleanup function
162 static int mptctl_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
);
164 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
166 * Scatter gather list (SGL) sizes and limits...
168 //#define MAX_SCSI_FRAGS 9
169 #define MAX_FRAGS_SPILL1 9
170 #define MAX_FRAGS_SPILL2 15
171 #define FRAGS_PER_BUCKET (MAX_FRAGS_SPILL2 + 1)
173 //#define MAX_CHAIN_FRAGS 64
174 //#define MAX_CHAIN_FRAGS (15+15+15+16)
175 #define MAX_CHAIN_FRAGS (4 * MAX_FRAGS_SPILL2 + 1)
177 // Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each)
178 // Works out to: 592d bytes! (9+1)*8 + 4*(15+1)*8
179 // ^----------------- 80 + 512
180 #define MAX_SGL_BYTES ((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)
182 /* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */
183 #define MAX_KMALLOC_SZ (128*1024)
185 #define MPT_IOCTL_DEFAULT_TIMEOUT 10 /* Default timeout value (seconds) */
187 static u32 fwReplyBuffer
[16];
188 static pMPIDefaultReply_t ReplyMsg
= NULL
;
190 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
192 * mptctl_syscall_down - Down the MPT adapter syscall semaphore.
193 * @ioc: Pointer to MPT adapter
194 * @nonblock: boolean, non-zero if O_NONBLOCK is set
196 * All of the ioctl commands can potentially sleep, which is illegal
197 * with a spinlock held, thus we perform mutual exclusion here.
199 * Returns negative errno on error, or zero for success.
202 mptctl_syscall_down(MPT_ADAPTER
*ioc
, int nonblock
)
205 dctlprintk((KERN_INFO MYNAM
"::mptctl_syscall_down(%p,%d) called\n", ioc
, nonblock
));
207 if (ioc
->ioctl
->tmPtr
!= NULL
) {
208 dctlprintk((KERN_INFO MYNAM
"::mptctl_syscall_down BUSY\n"));
213 if (down_trylock(&ioc
->ioctl
->sem_ioc
))
216 if (down_interruptible(&ioc
->ioctl
->sem_ioc
))
219 dctlprintk((KERN_INFO MYNAM
"::mptctl_syscall_down return %d\n", rc
));
223 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
225 * This is the callback for any message we have posted. The message itself
226 * will be returned to the message pool when we return from the IRQ
228 * This runs in irq context so be short and sweet.
231 mptctl_reply(MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*req
, MPT_FRAME_HDR
*reply
)
238 dctlprintk((MYIOC_s_INFO_FMT
": mptctl_reply()!\n", ioc
->name
));
240 cmd
= req
->u
.hdr
.Function
;
245 /* If timer is not running, then an error occurred.
246 * A timeout will call the reset routine to reload the messaging
248 * Main callback will free message and reply frames.
250 if (reply
&& (cmd
== MPI_FUNCTION_SCSI_TASK_MGMT
) &&
251 (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_TMTIMER_ACTIVE
)) {
252 /* This is internally generated TM
254 del_timer (&ioc
->ioctl
->TMtimer
);
255 ioc
->ioctl
->status
&= ~MPT_IOCTL_STATUS_TMTIMER_ACTIVE
;
257 mptctl_free_tm_flags(ioc
);
259 /* If TM failed, reset the timer on the existing command,
260 * will trigger an adapter reset.
262 iocStatus
= reply
->u
.reply
.IOCStatus
& MPI_IOCSTATUS_MASK
;
263 if (iocStatus
== MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED
) {
264 if (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_TIMER_ACTIVE
) {
265 ioc
->ioctl
->reset
&= ~MPTCTL_RESET_OK
;
266 del_timer (&ioc
->ioctl
->timer
);
267 ioc
->ioctl
->timer
.expires
= jiffies
+ HZ
;
268 add_timer(&ioc
->ioctl
->timer
);
271 ioc
->ioctl
->tmPtr
= NULL
;
273 } else if (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_TIMER_ACTIVE
) {
276 del_timer (&ioc
->ioctl
->timer
);
277 ioc
->ioctl
->status
&= ~MPT_IOCTL_STATUS_TIMER_ACTIVE
;
279 /* Set the overall status byte. Good if:
280 * IOC status is good OR if no reply and a SCSI IO request
283 /* Copy the reply frame (which much exist
284 * for non-SCSI I/O) to the IOC structure.
286 dctlprintk((MYIOC_s_INFO_FMT
": Copying Reply Frame @%p to IOC!\n",
288 memcpy(ioc
->ioctl
->ReplyFrame
, reply
,
289 min(ioc
->reply_sz
, 4*reply
->u
.reply
.MsgLength
));
290 ioc
->ioctl
->status
|= MPT_IOCTL_STATUS_RF_VALID
;
292 /* Set the command status to GOOD if IOC Status is GOOD
293 * OR if SCSI I/O cmd and data underrun or recovered error.
295 iocStatus
= reply
->u
.reply
.IOCStatus
& MPI_IOCSTATUS_MASK
;
296 if (iocStatus
== MPI_IOCSTATUS_SUCCESS
)
297 ioc
->ioctl
->status
|= MPT_IOCTL_STATUS_COMMAND_GOOD
;
299 if ((cmd
== MPI_FUNCTION_SCSI_IO_REQUEST
) ||
300 (cmd
== MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
301 ioc
->ioctl
->reset
&= ~MPTCTL_RESET_OK
;
303 if ((iocStatus
== MPI_IOCSTATUS_SCSI_DATA_UNDERRUN
) ||
304 (iocStatus
== MPI_IOCSTATUS_SCSI_RECOVERED_ERROR
)) {
305 ioc
->ioctl
->status
|= MPT_IOCTL_STATUS_COMMAND_GOOD
;
309 /* Copy the sense data - if present
311 if ((cmd
== MPI_FUNCTION_SCSI_IO_REQUEST
) &&
312 (reply
->u
.sreply
.SCSIState
& MPI_SCSI_STATE_AUTOSENSE_VALID
)){
314 sz
= req
->u
.scsireq
.SenseBufferLength
;
315 req_index
= le16_to_cpu(req
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
);
316 sense_data
= ((u8
*)ioc
->sense_buf_pool
+ (req_index
* MPT_SENSE_BUFFER_ALLOC
));
317 memcpy(ioc
->ioctl
->sense
, sense_data
, sz
);
318 ioc
->ioctl
->status
|= MPT_IOCTL_STATUS_SENSE_VALID
;
321 if (cmd
== MPI_FUNCTION_SCSI_TASK_MGMT
)
322 mptctl_free_tm_flags(ioc
);
325 } else if ((cmd
== MPI_FUNCTION_SCSI_IO_REQUEST
) ||
326 (cmd
== MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
327 ioc
->ioctl
->status
|= MPT_IOCTL_STATUS_COMMAND_GOOD
;
328 ioc
->ioctl
->reset
&= ~MPTCTL_RESET_OK
;
331 /* We are done, issue wake up
333 ioc
->ioctl
->wait_done
= 1;
334 wake_up (&mptctl_wait
);
335 } else if (reply
&& cmd
== MPI_FUNCTION_FW_DOWNLOAD
) {
336 /* Two paths to FW DOWNLOAD! */
337 // NOTE: Expects/requires non-Turbo reply!
338 dctlprintk((MYIOC_s_INFO_FMT
":Caching MPI_FUNCTION_FW_DOWNLOAD reply!\n",
340 memcpy(fwReplyBuffer
, reply
, min_t(int, sizeof(fwReplyBuffer
), 4*reply
->u
.reply
.MsgLength
));
341 ReplyMsg
= (pMPIDefaultReply_t
) fwReplyBuffer
;
347 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
348 /* mptctl_timer_expired
350 * Call back for timer process. Used only for ioctl functionality.
353 static void mptctl_timer_expired (unsigned long data
)
355 MPT_IOCTL
*ioctl
= (MPT_IOCTL
*) data
;
358 dctlprintk((KERN_NOTICE MYNAM
": Timer Expired! Host %d\n",
363 if (ioctl
->reset
& MPTCTL_RESET_OK
)
364 rc
= mptctl_bus_reset(ioctl
);
367 /* Issue a reset for this device.
368 * The IOC is not responding.
370 mpt_HardResetHandler(ioctl
->ioc
, NO_SLEEP
);
381 static int mptctl_bus_reset(MPT_IOCTL
*ioctl
)
384 SCSITaskMgmt_t
*pScsiTm
;
390 ioctl
->reset
&= ~MPTCTL_RESET_OK
;
392 if (ioctl
->ioc
->sh
== NULL
)
395 hd
= (MPT_SCSI_HOST
*) ioctl
->ioc
->sh
->hostdata
;
399 /* Single threading ....
401 if (mptctl_set_tm_flags(hd
) != 0)
406 if ((mf
= mpt_get_msg_frame(mptctl_id
, ioctl
->ioc
)) == NULL
) {
407 dctlprintk((MYIOC_s_WARN_FMT
"IssueTaskMgmt, no msg frames!!\n",
410 mptctl_free_tm_flags(ioctl
->ioc
);
414 dtmprintk((MYIOC_s_INFO_FMT
"IssueTaskMgmt request @ %p\n",
415 ioctl
->ioc
->name
, mf
));
417 pScsiTm
= (SCSITaskMgmt_t
*) mf
;
418 pScsiTm
->TargetID
= ioctl
->target
;
419 pScsiTm
->Bus
= hd
->port
; /* 0 */
420 pScsiTm
->ChainOffset
= 0;
421 pScsiTm
->Function
= MPI_FUNCTION_SCSI_TASK_MGMT
;
422 pScsiTm
->Reserved
= 0;
423 pScsiTm
->TaskType
= MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS
;
424 pScsiTm
->Reserved1
= 0;
425 pScsiTm
->MsgFlags
= MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION
;
427 for (ii
= 0; ii
< 8; ii
++)
428 pScsiTm
->LUN
[ii
] = 0;
430 for (ii
=0; ii
< 7; ii
++)
431 pScsiTm
->Reserved2
[ii
] = 0;
433 pScsiTm
->TaskMsgContext
= 0;
434 dtmprintk((MYIOC_s_INFO_FMT
"mptctl_bus_reset: issued.\n", ioctl
->ioc
->name
));
437 ioctl
->TMtimer
.expires
= jiffies
+ HZ
* 20; /* 20 seconds */
438 ioctl
->status
|= MPT_IOCTL_STATUS_TMTIMER_ACTIVE
;
439 add_timer(&ioctl
->TMtimer
);
441 retval
= mpt_send_handshake_request(mptctl_id
, ioctl
->ioc
,
442 sizeof(SCSITaskMgmt_t
), (u32
*)pScsiTm
, NO_SLEEP
);
445 dtmprintk((MYIOC_s_WARN_FMT
"_send_handshake FAILED!"
446 " (hd %p, ioc %p, mf %p) \n", ioctl
->ioc
->name
, hd
, hd
->ioc
, mf
));
448 mptctl_free_tm_flags(ioctl
->ioc
);
449 del_timer(&ioctl
->TMtimer
);
450 mpt_free_msg_frame(ioctl
->ioc
, mf
);
458 mptctl_set_tm_flags(MPT_SCSI_HOST
*hd
) {
461 spin_lock_irqsave(&hd
->ioc
->FreeQlock
, flags
);
463 if (hd
->tmState
== TM_STATE_NONE
) {
464 hd
->tmState
= TM_STATE_IN_PROGRESS
;
466 spin_unlock_irqrestore(&hd
->ioc
->FreeQlock
, flags
);
468 spin_unlock_irqrestore(&hd
->ioc
->FreeQlock
, flags
);
476 mptctl_free_tm_flags(MPT_ADAPTER
*ioc
)
481 hd
= (MPT_SCSI_HOST
*) ioc
->sh
->hostdata
;
485 spin_lock_irqsave(&ioc
->FreeQlock
, flags
);
487 hd
->tmState
= TM_STATE_NONE
;
489 spin_unlock_irqrestore(&ioc
->FreeQlock
, flags
);
495 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
498 * Clean-up functionality. Used only if there has been a
499 * reload of the FW due.
503 mptctl_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
)
505 MPT_IOCTL
*ioctl
= ioc
->ioctl
;
506 dctlprintk((KERN_INFO MYNAM
": IOC %s_reset routed to IOCTL driver!\n",
507 reset_phase
==MPT_IOC_SETUP_RESET
? "setup" : (
508 reset_phase
==MPT_IOC_PRE_RESET
? "pre" : "post")));
510 if (reset_phase
== MPT_IOC_SETUP_RESET
){
512 } else if (reset_phase
== MPT_IOC_PRE_RESET
){
514 /* Someone has called the reset handler to
515 * do a hard reset. No more replies from the FW.
516 * Delete the timer. TM flags cleaned up by SCSI driver.
517 * Do not need to free msg frame, as re-initialized
519 if (ioctl
&& (ioctl
->status
& MPT_IOCTL_STATUS_TIMER_ACTIVE
)){
520 del_timer(&ioctl
->timer
);
522 if (ioctl
&& (ioctl
->status
& MPT_IOCTL_STATUS_TMTIMER_ACTIVE
)){
523 ioctl
->status
&= ~MPT_IOCTL_STATUS_TMTIMER_ACTIVE
;
524 del_timer(&ioctl
->TMtimer
);
525 mpt_free_msg_frame(ioc
, ioctl
->tmPtr
);
531 /* Set the status and continue IOCTL
532 * processing. All memory will be free'd
533 * by originating thread after wake_up is
536 if (ioctl
&& (ioctl
->status
& MPT_IOCTL_STATUS_TIMER_ACTIVE
)){
537 ioctl
->status
|= MPT_IOCTL_STATUS_DID_IOCRESET
;
539 /* Wake up the calling process
541 ioctl
->wait_done
= 1;
542 wake_up(&mptctl_wait
);
549 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
552 * cmd - specify the particular IOCTL command to be issued
553 * arg - data specific to the command. Must not be null.
556 mptctl_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
558 mpt_ioctl_header __user
*uhdr
= (void __user
*) arg
;
559 mpt_ioctl_header khdr
;
562 int nonblock
= (file
->f_flags
& O_NONBLOCK
);
564 MPT_ADAPTER
*iocp
= NULL
;
566 dctlprintk(("mptctl_ioctl() called\n"));
568 if (copy_from_user(&khdr
, uhdr
, sizeof(khdr
))) {
569 printk(KERN_ERR
"%s::mptctl_ioctl() @%d - "
570 "Unable to copy mpt_ioctl_header data @ %p\n",
571 __FILE__
, __LINE__
, uhdr
);
574 ret
= -ENXIO
; /* (-6) No such device or address */
576 /* Verify intended MPT adapter - set iocnum and the adapter
579 iocnumX
= khdr
.iocnum
& 0xFF;
580 if (((iocnum
= mpt_verify_adapter(iocnumX
, &iocp
)) < 0) ||
582 dctlprintk((KERN_ERR
"%s::mptctl_ioctl() @%d - ioc%d not found!\n",
583 __FILE__
, __LINE__
, iocnumX
));
588 printk(KERN_ERR
"%s::mptctl_ioctl() @%d - Controller disabled.\n",
593 /* Handle those commands that are just returning
594 * information stored in the driver.
595 * These commands should never time out and are unaffected
596 * by TM and FW reloads.
598 if ((cmd
& ~IOCSIZE_MASK
) == (MPTIOCINFO
& ~IOCSIZE_MASK
)) {
599 return mptctl_getiocinfo(arg
, _IOC_SIZE(cmd
));
600 } else if (cmd
== MPTTARGETINFO
) {
601 return mptctl_gettargetinfo(arg
);
602 } else if (cmd
== MPTTEST
) {
603 return mptctl_readtest(arg
);
604 } else if (cmd
== MPTEVENTQUERY
) {
605 return mptctl_eventquery(arg
);
606 } else if (cmd
== MPTEVENTENABLE
) {
607 return mptctl_eventenable(arg
);
608 } else if (cmd
== MPTEVENTREPORT
) {
609 return mptctl_eventreport(arg
);
610 } else if (cmd
== MPTFWREPLACE
) {
611 return mptctl_replace_fw(arg
);
614 /* All of these commands require an interrupt or
615 * are unknown/illegal.
617 if ((ret
= mptctl_syscall_down(iocp
, nonblock
)) != 0)
620 dctlprintk((MYIOC_s_INFO_FMT
": mptctl_ioctl()\n", iocp
->name
));
622 if (cmd
== MPTFWDOWNLOAD
)
623 ret
= mptctl_fw_download(arg
);
624 else if (cmd
== MPTCOMMAND
)
625 ret
= mptctl_mpt_command(arg
);
626 else if (cmd
== MPTHARDRESET
)
627 ret
= mptctl_do_reset(arg
);
628 else if ((cmd
& ~IOCSIZE_MASK
) == (HP_GETHOSTINFO
& ~IOCSIZE_MASK
))
629 ret
= mptctl_hp_hostinfo(arg
, _IOC_SIZE(cmd
));
630 else if (cmd
== HP_GETTARGETINFO
)
631 ret
= mptctl_hp_targetinfo(arg
);
635 up(&iocp
->ioctl
->sem_ioc
);
640 static int mptctl_do_reset(unsigned long arg
)
642 struct mpt_ioctl_diag_reset __user
*urinfo
= (void __user
*) arg
;
643 struct mpt_ioctl_diag_reset krinfo
;
646 dctlprintk((KERN_INFO
"mptctl_do_reset called.\n"));
648 if (copy_from_user(&krinfo
, urinfo
, sizeof(struct mpt_ioctl_diag_reset
))) {
649 printk(KERN_ERR
"%s@%d::mptctl_do_reset - "
650 "Unable to copy mpt_ioctl_diag_reset struct @ %p\n",
651 __FILE__
, __LINE__
, urinfo
);
655 if (mpt_verify_adapter(krinfo
.hdr
.iocnum
, &iocp
) < 0) {
656 dctlprintk((KERN_ERR
"%s@%d::mptctl_do_reset - ioc%d not found!\n",
657 __FILE__
, __LINE__
, krinfo
.hdr
.iocnum
));
658 return -ENODEV
; /* (-6) No such device or address */
661 if (mpt_HardResetHandler(iocp
, CAN_SLEEP
) != 0) {
662 printk (KERN_ERR
"%s@%d::mptctl_do_reset - reset failed.\n",
670 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
672 * MPT FW download function. Cast the arg into the mpt_fw_xfer structure.
673 * This structure contains: iocnum, firmware length (bytes),
674 * pointer to user space memory where the fw image is stored.
677 * Return: 0 if successful
678 * -EFAULT if data unavailable
679 * -ENXIO if no such device
680 * -EAGAIN if resource problem
681 * -ENOMEM if no memory for SGE
682 * -EMLINK if too many chain buffers required
683 * -EBADRQC if adapter does not support FW download
684 * -EBUSY if adapter is busy
685 * -ENOMSG if FW upload returned bad status
688 mptctl_fw_download(unsigned long arg
)
690 struct mpt_fw_xfer __user
*ufwdl
= (void __user
*) arg
;
691 struct mpt_fw_xfer kfwdl
;
693 dctlprintk((KERN_INFO
"mptctl_fwdl called. mptctl_id = %xh\n", mptctl_id
)); //tc
694 if (copy_from_user(&kfwdl
, ufwdl
, sizeof(struct mpt_fw_xfer
))) {
695 printk(KERN_ERR
"%s@%d::_ioctl_fwdl - "
696 "Unable to copy mpt_fw_xfer struct @ %p\n",
697 __FILE__
, __LINE__
, ufwdl
);
701 return mptctl_do_fw_download(kfwdl
.iocnum
, kfwdl
.bufp
, kfwdl
.fwlen
);
704 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
706 * FW Download engine.
708 * Return: 0 if successful
709 * -EFAULT if data unavailable
710 * -ENXIO if no such device
711 * -EAGAIN if resource problem
712 * -ENOMEM if no memory for SGE
713 * -EMLINK if too many chain buffers required
714 * -EBADRQC if adapter does not support FW download
715 * -EBUSY if adapter is busy
716 * -ENOMSG if FW upload returned bad status
719 mptctl_do_fw_download(int ioc
, char __user
*ufwbuf
, size_t fwlen
)
724 FWDownloadTCSGE_t
*ptsge
;
725 MptSge_t
*sgl
, *sgIn
;
727 struct buflist
*buflist
;
736 int fw_bytes_copied
= 0;
742 dctlprintk((KERN_INFO
"mptctl_do_fwdl called. mptctl_id = %xh.\n", mptctl_id
));
744 dctlprintk((KERN_INFO
"DbG: kfwdl.bufp = %p\n", ufwbuf
));
745 dctlprintk((KERN_INFO
"DbG: kfwdl.fwlen = %d\n", (int)fwlen
));
746 dctlprintk((KERN_INFO
"DbG: kfwdl.ioc = %04xh\n", ioc
));
748 if ((ioc
= mpt_verify_adapter(ioc
, &iocp
)) < 0) {
749 dctlprintk(("%s@%d::_ioctl_fwdl - ioc%d not found!\n",
750 __FILE__
, __LINE__
, ioc
));
751 return -ENODEV
; /* (-6) No such device or address */
754 /* Valid device. Get a message frame and construct the FW download message.
756 if ((mf
= mpt_get_msg_frame(mptctl_id
, iocp
)) == NULL
)
758 dlmsg
= (FWDownload_t
*) mf
;
759 ptsge
= (FWDownloadTCSGE_t
*) &dlmsg
->SGL
;
760 sgOut
= (char *) (ptsge
+ 1);
763 * Construct f/w download request
765 dlmsg
->ImageType
= MPI_FW_DOWNLOAD_ITYPE_FW
;
767 dlmsg
->ChainOffset
= 0;
768 dlmsg
->Function
= MPI_FUNCTION_FW_DOWNLOAD
;
769 dlmsg
->Reserved1
[0] = dlmsg
->Reserved1
[1] = dlmsg
->Reserved1
[2] = 0;
772 /* Set up the Transaction SGE.
775 ptsge
->ContextSize
= 0;
776 ptsge
->DetailsLength
= 12;
777 ptsge
->Flags
= MPI_SGE_FLAGS_TRANSACTION_ELEMENT
;
778 ptsge
->Reserved_0100_Checksum
= 0;
779 ptsge
->ImageOffset
= 0;
780 ptsge
->ImageSize
= cpu_to_le32(fwlen
);
786 * Need to kmalloc area(s) for holding firmware image bytes.
787 * But we need to do it piece meal, using a proper
788 * scatter gather list (with 128kB MAX hunks).
790 * A practical limit here might be # of sg hunks that fit into
791 * a single IOC request frame; 12 or 8 (see below), so:
792 * For FC9xx: 12 x 128kB == 1.5 mB (max)
793 * For C1030: 8 x 128kB == 1 mB (max)
794 * We could support chaining, but things get ugly(ier:)
796 * Set the sge_offset to the start of the sgl (bytes).
798 sgdir
= 0x04000000; /* IOC will READ from sys mem */
799 sge_offset
= sizeof(MPIHeader_t
) + sizeof(FWDownloadTCSGE_t
);
800 if ((sgl
= kbuf_alloc_2_sgl(fwlen
, sgdir
, sge_offset
,
801 &numfrags
, &buflist
, &sgl_dma
, iocp
)) == NULL
)
805 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)
806 * for FC9xx f/w image, but calculate max number of sge hunks
807 * we can fit into a request frame, and limit ourselves to that.
808 * (currently no chain support)
809 * maxfrags = (Request Size - FWdownload Size ) / Size of 32 bit SGE
815 maxfrags
= (iocp
->req_sz
- sizeof(MPIHeader_t
) - sizeof(FWDownloadTCSGE_t
))
816 / (sizeof(dma_addr_t
) + sizeof(u32
));
817 if (numfrags
> maxfrags
) {
822 dctlprintk((KERN_INFO
"DbG: sgl buffer = %p, sgfrags = %d\n", sgl
, numfrags
));
825 * Parse SG list, copying sgl itself,
826 * plus f/w image hunks from user space as we go...
831 for (i
=0; i
< numfrags
; i
++) {
833 /* Get the SGE type: 0 - TCSGE, 3 - Chain, 1 - Simple SGE
834 * Skip everything but Simple. If simple, copy from
835 * user space into kernel space.
836 * Note: we should not have anything but Simple as
837 * Chain SGE are illegal.
839 nib
= (sgIn
->FlagsLength
& 0x30000000) >> 28;
840 if (nib
== 0 || nib
== 3) {
842 } else if (sgIn
->Address
) {
843 mpt_add_sge(sgOut
, sgIn
->FlagsLength
, sgIn
->Address
);
845 if (copy_from_user(bl
->kptr
, ufwbuf
+fw_bytes_copied
, bl
->len
)) {
846 printk(KERN_ERR
"%s@%d::_ioctl_fwdl - "
847 "Unable to copy f/w buffer hunk#%d @ %p\n",
848 __FILE__
, __LINE__
, n
, ufwbuf
);
851 fw_bytes_copied
+= bl
->len
;
855 sgOut
+= (sizeof(dma_addr_t
) + sizeof(u32
));
861 printk(KERN_INFO MYNAM
": F/W download request:\n" KERN_INFO
" ");
862 for (i
=0; i
< 7+numfrags
*2; i
++)
863 printk(" %08x", le32_to_cpu(m
[i
]));
869 * Finally, perform firmware download.
872 mpt_put_msg_frame(mptctl_id
, iocp
, mf
);
875 * Wait until the reply has been received
877 for (cntdn
=HZ
*60, i
=1; ReplyMsg
== NULL
; cntdn
--, i
++) {
884 dctlprintk((KERN_INFO
"DbG::_do_fwdl: "
885 "In ReplyMsg loop - iteration %d\n",
889 set_current_state(TASK_INTERRUPTIBLE
);
894 kfree_sgl(sgl
, sgl_dma
, buflist
, iocp
);
896 iocstat
= le16_to_cpu(ReplyMsg
->IOCStatus
) & MPI_IOCSTATUS_MASK
;
897 if (iocstat
== MPI_IOCSTATUS_SUCCESS
) {
898 printk(KERN_INFO MYNAM
": F/W update successfully sent to %s!\n", iocp
->name
);
900 } else if (iocstat
== MPI_IOCSTATUS_INVALID_FUNCTION
) {
901 printk(KERN_WARNING MYNAM
": ?Hmmm... %s says it doesn't support F/W download!?!\n",
903 printk(KERN_WARNING MYNAM
": (time to go bang on somebodies door)\n");
905 } else if (iocstat
== MPI_IOCSTATUS_BUSY
) {
906 printk(KERN_WARNING MYNAM
": Warning! %s says: IOC_BUSY!\n", iocp
->name
);
907 printk(KERN_WARNING MYNAM
": (try again later?)\n");
910 printk(KERN_WARNING MYNAM
"::ioctl_fwdl() ERROR! %s returned [bad] status = %04xh\n",
911 iocp
->name
, iocstat
);
912 printk(KERN_WARNING MYNAM
": (bad VooDoo)\n");
918 kfree_sgl(sgl
, sgl_dma
, buflist
, iocp
);
922 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
924 * SGE Allocation routine
926 * Inputs: bytes - number of bytes to be transferred
927 * sgdir - data direction
928 * sge_offset - offset (in bytes) from the start of the request
929 * frame to the first SGE
930 * ioc - pointer to the mptadapter
931 * Outputs: frags - number of scatter gather elements
932 * blp - point to the buflist pointer
933 * sglbuf_dma - pointer to the (dma) sgl
934 * Returns: Null if failes
935 * pointer to the (virtual) sgl if successful.
938 kbuf_alloc_2_sgl(int bytes
, u32 sgdir
, int sge_offset
, int *frags
,
939 struct buflist
**blp
, dma_addr_t
*sglbuf_dma
, MPT_ADAPTER
*ioc
)
941 MptSge_t
*sglbuf
= NULL
; /* pointer to array of SGE */
942 /* and chain buffers */
943 struct buflist
*buflist
= NULL
; /* kernel routine */
947 int alloc_sz
= min(bytes
,MAX_KMALLOC_SZ
); // avoid kernel warning msg!
948 int bytes_allocd
= 0;
950 dma_addr_t pa
; // phys addr
952 int sg_spill
= MAX_FRAGS_SPILL1
;
958 /* Allocate and initialize an array of kernel
959 * structures for the SG elements.
961 i
= MAX_SGL_BYTES
/ 8;
962 buflist
= kmalloc(i
, GFP_USER
);
965 memset(buflist
, 0, i
);
968 /* Allocate a single block of memory to store the sg elements and
969 * the chain buffers. The calling routine is responsible for
970 * copying the data in this array into the correct place in the
971 * request and chain buffers.
973 sglbuf
= pci_alloc_consistent(ioc
->pcidev
, MAX_SGL_BYTES
, sglbuf_dma
);
977 if (sgdir
& 0x04000000)
978 dir
= PCI_DMA_TODEVICE
;
980 dir
= PCI_DMA_FROMDEVICE
;
983 * sgl = sglbuf = point to beginning of sg buffer
984 * buflist_ent = 0 = first kernel structure
985 * sg_spill = number of SGE that can be written before the first
990 sg_spill
= ((ioc
->req_sz
- sge_offset
)/(sizeof(dma_addr_t
) + sizeof(u32
))) - 1;
991 while (bytes_allocd
< bytes
) {
992 this_alloc
= min(alloc_sz
, bytes
-bytes_allocd
);
993 buflist
[buflist_ent
].len
= this_alloc
;
994 buflist
[buflist_ent
].kptr
= pci_alloc_consistent(ioc
->pcidev
,
997 if (buflist
[buflist_ent
].kptr
== NULL
) {
998 alloc_sz
= alloc_sz
/ 2;
1000 printk(KERN_WARNING MYNAM
"-SG: No can do - "
1001 "not enough memory! :-(\n");
1002 printk(KERN_WARNING MYNAM
"-SG: (freeing %d frags)\n",
1008 dma_addr_t dma_addr
;
1010 bytes_allocd
+= this_alloc
;
1011 sgl
->FlagsLength
= (0x10000000|MPT_SGE_FLAGS_ADDRESSING
|sgdir
|this_alloc
);
1012 dma_addr
= pci_map_single(ioc
->pcidev
, buflist
[buflist_ent
].kptr
, this_alloc
, dir
);
1013 sgl
->Address
= dma_addr
;
1021 if (bytes_allocd
>= bytes
)
1024 /* Need to chain? */
1025 if (fragcnt
== sg_spill
) {
1026 printk(KERN_WARNING MYNAM
"-SG: No can do - " "Chain required! :-(\n");
1027 printk(KERN_WARNING MYNAM
"(freeing %d frags)\n", numfrags
);
1031 /* overflow check... */
1032 if (numfrags
*8 > MAX_SGL_BYTES
){
1034 printk(KERN_WARNING MYNAM
"-SG: No can do - "
1035 "too many SG frags! :-(\n");
1036 printk(KERN_WARNING MYNAM
"-SG: (freeing %d frags)\n",
1042 /* Last sge fixup: set LE+eol+eob bits */
1043 sgl
[-1].FlagsLength
|= 0xC1000000;
1048 dctlprintk((KERN_INFO MYNAM
"-SG: kbuf_alloc_2_sgl() - "
1049 "%d SG frags generated!\n",
1052 dctlprintk((KERN_INFO MYNAM
"-SG: kbuf_alloc_2_sgl() - "
1053 "last (big) alloc_sz=%d\n",
1059 if (sglbuf
!= NULL
) {
1062 for (i
= 0; i
< numfrags
; i
++) {
1063 dma_addr_t dma_addr
;
1067 if ((sglbuf
[i
].FlagsLength
>> 24) == 0x30)
1070 dma_addr
= sglbuf
[i
].Address
;
1071 kptr
= buflist
[i
].kptr
;
1072 len
= buflist
[i
].len
;
1074 pci_free_consistent(ioc
->pcidev
, len
, kptr
, dma_addr
);
1076 pci_free_consistent(ioc
->pcidev
, MAX_SGL_BYTES
, sglbuf
, *sglbuf_dma
);
1082 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1084 * Routine to free the SGL elements.
1087 kfree_sgl(MptSge_t
*sgl
, dma_addr_t sgl_dma
, struct buflist
*buflist
, MPT_ADAPTER
*ioc
)
1090 struct buflist
*bl
= buflist
;
1095 if (sg
->FlagsLength
& 0x04000000)
1096 dir
= PCI_DMA_TODEVICE
;
1098 dir
= PCI_DMA_FROMDEVICE
;
1100 nib
= (sg
->FlagsLength
& 0xF0000000) >> 28;
1101 while (! (nib
& 0x4)) { /* eob */
1102 /* skip ignore/chain. */
1103 if (nib
== 0 || nib
== 3) {
1105 } else if (sg
->Address
) {
1106 dma_addr_t dma_addr
;
1110 dma_addr
= sg
->Address
;
1113 pci_unmap_single(ioc
->pcidev
, dma_addr
, len
, dir
);
1114 pci_free_consistent(ioc
->pcidev
, len
, kptr
, dma_addr
);
1119 nib
= (le32_to_cpu(sg
->FlagsLength
) & 0xF0000000) >> 28;
1124 dma_addr_t dma_addr
;
1128 dma_addr
= sg
->Address
;
1131 pci_unmap_single(ioc
->pcidev
, dma_addr
, len
, dir
);
1132 pci_free_consistent(ioc
->pcidev
, len
, kptr
, dma_addr
);
1136 pci_free_consistent(ioc
->pcidev
, MAX_SGL_BYTES
, sgl
, sgl_dma
);
1138 dctlprintk((KERN_INFO MYNAM
"-SG: Free'd 1 SGL buf + %d kbufs!\n", n
));
1141 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1143 * mptctl_getiocinfo - Query the host adapter for IOC information.
1144 * @arg: User space argument
1147 * Return: 0 if successful
1148 * -EFAULT if data unavailable
1149 * -ENODEV if no such device/adapter
1152 mptctl_getiocinfo (unsigned long arg
, unsigned int data_size
)
1154 struct mpt_ioctl_iocinfo __user
*uarg
= (void __user
*) arg
;
1155 struct mpt_ioctl_iocinfo
*karg
;
1157 struct pci_dev
*pdev
;
1158 struct Scsi_Host
*sh
;
1162 unsigned int max_id
;
1168 dctlprintk((": mptctl_getiocinfo called.\n"));
1169 /* Add of PCI INFO results in unaligned access for
1170 * IA64 and Sparc. Reset long to int. Return no PCI
1171 * data for obsolete format.
1173 if (data_size
== sizeof(struct mpt_ioctl_iocinfo_rev0
))
1175 else if (data_size
== sizeof(struct mpt_ioctl_iocinfo_rev1
))
1177 else if (data_size
== sizeof(struct mpt_ioctl_iocinfo
))
1179 else if (data_size
== (sizeof(struct mpt_ioctl_iocinfo_rev0
)+12))
1180 cim_rev
= 0; /* obsolete */
1184 karg
= kmalloc(data_size
, GFP_KERNEL
);
1186 printk(KERN_ERR
"%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
1187 __FILE__
, __LINE__
);
1191 if (copy_from_user(karg
, uarg
, data_size
)) {
1192 printk(KERN_ERR
"%s@%d::mptctl_getiocinfo - "
1193 "Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
1194 __FILE__
, __LINE__
, uarg
);
1199 if (((iocnum
= mpt_verify_adapter(karg
->hdr
.iocnum
, &ioc
)) < 0) ||
1201 dctlprintk((KERN_ERR
"%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
1202 __FILE__
, __LINE__
, iocnum
));
1207 /* Verify the data transfer size is correct.
1208 * Ignore the port setting.
1210 if (karg
->hdr
.maxDataSize
!= data_size
) {
1211 printk(KERN_ERR
"%s@%d::mptctl_getiocinfo - "
1212 "Structure size mismatch. Command not completed.\n",
1213 __FILE__
, __LINE__
);
1218 /* Fill in the data and return the structure to the calling
1221 if ((int)ioc
->chip_type
<= (int) FC929
)
1222 karg
->adapterType
= MPT_IOCTL_INTERFACE_FC
;
1224 karg
->adapterType
= MPT_IOCTL_INTERFACE_SCSI
;
1226 port
= karg
->hdr
.port
;
1229 pdev
= (struct pci_dev
*) ioc
->pcidev
;
1231 karg
->pciId
= pdev
->device
;
1232 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
);
1233 karg
->hwRev
= revision
;
1234 karg
->subSystemDevice
= pdev
->subsystem_device
;
1235 karg
->subSystemVendor
= pdev
->subsystem_vendor
;
1238 /* Get the PCI bus, device, and function numbers for the IOC
1240 karg
->pciInfo
.u
.bits
.busNumber
= pdev
->bus
->number
;
1241 karg
->pciInfo
.u
.bits
.deviceNumber
= PCI_SLOT( pdev
->devfn
);
1242 karg
->pciInfo
.u
.bits
.functionNumber
= PCI_FUNC( pdev
->devfn
);
1243 } else if (cim_rev
== 2) {
1244 /* Get the PCI bus, device, function and segment ID numbers
1246 karg
->pciInfo
.u
.bits
.busNumber
= pdev
->bus
->number
;
1247 karg
->pciInfo
.u
.bits
.deviceNumber
= PCI_SLOT( pdev
->devfn
);
1248 karg
->pciInfo
.u
.bits
.functionNumber
= PCI_FUNC( pdev
->devfn
);
1249 karg
->pciInfo
.u
.bits
.functionNumber
= PCI_FUNC( pdev
->devfn
);
1250 karg
->pciInfo
.segmentID
= pci_domain_nr(pdev
->bus
);
1253 /* Get number of devices
1255 if ((sh
= ioc
->sh
) != NULL
) {
1256 /* sh->max_id = maximum target ID + 1
1258 max_id
= sh
->max_id
- 1;
1259 hd
= (MPT_SCSI_HOST
*) sh
->hostdata
;
1261 /* Check all of the target structures and
1264 if (hd
&& hd
->Targets
) {
1265 for (ii
= 0; ii
<= max_id
; ii
++) {
1266 if (hd
->Targets
[ii
])
1271 karg
->numDevices
= numDevices
;
1273 /* Set the BIOS and FW Version
1275 karg
->FWVersion
= ioc
->facts
.FWVersion
.Word
;
1276 karg
->BIOSVersion
= ioc
->biosVersion
;
1278 /* Set the Version Strings.
1280 strncpy (karg
->driverVersion
, MPT_LINUX_PACKAGE_NAME
, MPT_IOCTL_VERSION_LENGTH
);
1281 karg
->driverVersion
[MPT_IOCTL_VERSION_LENGTH
-1]='\0';
1283 karg
->busChangeEvent
= 0;
1284 karg
->hostId
= ioc
->pfacts
[port
].PortSCSIID
;
1285 karg
->rsvd
[0] = karg
->rsvd
[1] = 0;
1287 /* Copy the data from kernel memory to user memory
1289 if (copy_to_user((char __user
*)arg
, karg
, data_size
)) {
1290 printk(KERN_ERR
"%s@%d::mptctl_getiocinfo - "
1291 "Unable to write out mpt_ioctl_iocinfo struct @ %p\n",
1292 __FILE__
, __LINE__
, uarg
);
1301 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1303 * mptctl_gettargetinfo - Query the host adapter for target information.
1304 * @arg: User space argument
1307 * Return: 0 if successful
1308 * -EFAULT if data unavailable
1309 * -ENODEV if no such device/adapter
1312 mptctl_gettargetinfo (unsigned long arg
)
1314 struct mpt_ioctl_targetinfo __user
*uarg
= (void __user
*) arg
;
1315 struct mpt_ioctl_targetinfo karg
;
1317 struct Scsi_Host
*sh
;
1326 unsigned int max_id
;
1327 int id
, jj
, indexed_lun
, lun_index
;
1331 u8 port
, devType
, bus_id
;
1333 dctlprintk(("mptctl_gettargetinfo called.\n"));
1334 if (copy_from_user(&karg
, uarg
, sizeof(struct mpt_ioctl_targetinfo
))) {
1335 printk(KERN_ERR
"%s@%d::mptctl_gettargetinfo - "
1336 "Unable to read in mpt_ioctl_targetinfo struct @ %p\n",
1337 __FILE__
, __LINE__
, uarg
);
1341 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1343 dctlprintk((KERN_ERR
"%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
1344 __FILE__
, __LINE__
, iocnum
));
1348 /* Get the port number and set the maximum number of bytes
1349 * in the returned structure.
1350 * Ignore the port setting.
1352 numBytes
= karg
.hdr
.maxDataSize
- sizeof(mpt_ioctl_header
);
1353 maxWordsLeft
= numBytes
/sizeof(int);
1354 port
= karg
.hdr
.port
;
1356 if (maxWordsLeft
<= 0) {
1357 printk(KERN_ERR
"%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1358 __FILE__
, __LINE__
);
1362 /* Fill in the data and return the structure to the calling
1366 /* struct mpt_ioctl_targetinfo does not contain sufficient space
1367 * for the target structures so when the IOCTL is called, there is
1368 * not sufficient stack space for the structure. Allocate memory,
1369 * populate the memory, copy back to the user, then free memory.
1370 * targetInfo format:
1371 * bits 31-24: reserved
1376 pmem
= kmalloc(numBytes
, GFP_KERNEL
);
1378 printk(KERN_ERR
"%s::mptctl_gettargetinfo() @%d - no memory available!\n",
1379 __FILE__
, __LINE__
);
1382 memset(pmem
, 0, numBytes
);
1383 pdata
= (int *) pmem
;
1385 /* Get number of devices
1387 if ((sh
= ioc
->sh
) != NULL
) {
1389 max_id
= sh
->max_id
- 1;
1390 hd
= (MPT_SCSI_HOST
*) sh
->hostdata
;
1392 /* Check all of the target structures.
1393 * Save the Id and increment the counter,
1395 * sh->max_id = maximum target ID + 1
1397 if (hd
&& hd
->Targets
) {
1398 mpt_findImVolumes(ioc
);
1399 pIoc2
= ioc
->spi_data
.pIocPg2
;
1400 for ( id
= 0; id
<= max_id
; ) {
1401 if ( pIoc2
&& pIoc2
->NumActiveVolumes
) {
1402 if ( id
== pIoc2
->RaidVolume
[0].VolumeID
) {
1403 if (maxWordsLeft
<= 0) {
1404 printk(KERN_ERR
"mptctl_gettargetinfo - "
1405 "buffer is full but volume is available on ioc %d\n, numDevices=%d", iocnum
, numDevices
);
1406 goto data_space_full
;
1408 if ( ( pIoc2
->RaidVolume
[0].Flags
& MPI_IOCPAGE2_FLAG_VOLUME_INACTIVE
) == 0 )
1412 bus_id
= pIoc2
->RaidVolume
[0].VolumeBus
;
1414 *pdata
= ( (devType
<< 24) | (bus_id
<< 8) | id
);
1415 dctlprintk((KERN_ERR
"mptctl_gettargetinfo - "
1416 "volume ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum
, *pdata
, numDevices
, pdata
));
1421 pIoc3
= ioc
->spi_data
.pIocPg3
;
1422 for ( jj
= 0; jj
< pIoc3
->NumPhysDisks
; jj
++ ) {
1423 if ( pIoc3
->PhysDisk
[jj
].PhysDiskID
== id
)
1428 if ( (vdev
= hd
->Targets
[id
]) ) {
1429 for (jj
= 0; jj
<= MPT_LAST_LUN
; jj
++) {
1430 lun_index
= (jj
>> 5);
1431 indexed_lun
= (jj
% 32);
1432 lun
= (1 << indexed_lun
);
1433 if (vdev
->luns
[lun_index
] & lun
) {
1434 if (maxWordsLeft
<= 0) {
1435 printk(KERN_ERR
"mptctl_gettargetinfo - "
1436 "buffer is full but more targets are available on ioc %d numDevices=%d\n", iocnum
, numDevices
);
1437 goto data_space_full
;
1439 bus_id
= vdev
->bus_id
;
1441 *pdata
= ( (jj
<< 16) | (bus_id
<< 8) | id
);
1442 dctlprintk((KERN_ERR
"mptctl_gettargetinfo - "
1443 "target ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum
, *pdata
, numDevices
, pdata
));
1455 karg
.numDevices
= numDevices
;
1457 /* Copy part of the data from kernel memory to user memory
1459 if (copy_to_user((char __user
*)arg
, &karg
,
1460 sizeof(struct mpt_ioctl_targetinfo
))) {
1461 printk(KERN_ERR
"%s@%d::mptctl_gettargetinfo - "
1462 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1463 __FILE__
, __LINE__
, uarg
);
1468 /* Copy the remaining data from kernel memory to user memory
1470 if (copy_to_user(uarg
->targetInfo
, pmem
, numBytes
)) {
1471 printk(KERN_ERR
"%s@%d::mptctl_gettargetinfo - "
1472 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
1473 __FILE__
, __LINE__
, pdata
);
1483 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1484 /* MPT IOCTL Test function.
1487 * Return: 0 if successful
1488 * -EFAULT if data unavailable
1489 * -ENODEV if no such device/adapter
1492 mptctl_readtest (unsigned long arg
)
1494 struct mpt_ioctl_test __user
*uarg
= (void __user
*) arg
;
1495 struct mpt_ioctl_test karg
;
1499 dctlprintk(("mptctl_readtest called.\n"));
1500 if (copy_from_user(&karg
, uarg
, sizeof(struct mpt_ioctl_test
))) {
1501 printk(KERN_ERR
"%s@%d::mptctl_readtest - "
1502 "Unable to read in mpt_ioctl_test struct @ %p\n",
1503 __FILE__
, __LINE__
, uarg
);
1507 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1509 dctlprintk((KERN_ERR
"%s::mptctl_readtest() @%d - ioc%d not found!\n",
1510 __FILE__
, __LINE__
, iocnum
));
1514 /* Fill in the data and return the structure to the calling
1519 karg
.chip_type
= ioc
->mfcnt
;
1521 karg
.chip_type
= ioc
->chip_type
;
1523 strncpy (karg
.name
, ioc
->name
, MPT_MAX_NAME
);
1524 karg
.name
[MPT_MAX_NAME
-1]='\0';
1525 strncpy (karg
.product
, ioc
->prod_name
, MPT_PRODUCT_LENGTH
);
1526 karg
.product
[MPT_PRODUCT_LENGTH
-1]='\0';
1528 /* Copy the data from kernel memory to user memory
1530 if (copy_to_user((char __user
*)arg
, &karg
, sizeof(struct mpt_ioctl_test
))) {
1531 printk(KERN_ERR
"%s@%d::mptctl_readtest - "
1532 "Unable to write out mpt_ioctl_test struct @ %p\n",
1533 __FILE__
, __LINE__
, uarg
);
1540 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1542 * mptctl_eventquery - Query the host adapter for the event types
1543 * that are being logged.
1544 * @arg: User space argument
1547 * Return: 0 if successful
1548 * -EFAULT if data unavailable
1549 * -ENODEV if no such device/adapter
1552 mptctl_eventquery (unsigned long arg
)
1554 struct mpt_ioctl_eventquery __user
*uarg
= (void __user
*) arg
;
1555 struct mpt_ioctl_eventquery karg
;
1559 dctlprintk(("mptctl_eventquery called.\n"));
1560 if (copy_from_user(&karg
, uarg
, sizeof(struct mpt_ioctl_eventquery
))) {
1561 printk(KERN_ERR
"%s@%d::mptctl_eventquery - "
1562 "Unable to read in mpt_ioctl_eventquery struct @ %p\n",
1563 __FILE__
, __LINE__
, uarg
);
1567 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1569 dctlprintk((KERN_ERR
"%s::mptctl_eventquery() @%d - ioc%d not found!\n",
1570 __FILE__
, __LINE__
, iocnum
));
1574 karg
.eventEntries
= ioc
->eventLogSize
;
1575 karg
.eventTypes
= ioc
->eventTypes
;
1577 /* Copy the data from kernel memory to user memory
1579 if (copy_to_user((char __user
*)arg
, &karg
, sizeof(struct mpt_ioctl_eventquery
))) {
1580 printk(KERN_ERR
"%s@%d::mptctl_eventquery - "
1581 "Unable to write out mpt_ioctl_eventquery struct @ %p\n",
1582 __FILE__
, __LINE__
, uarg
);
1588 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1590 mptctl_eventenable (unsigned long arg
)
1592 struct mpt_ioctl_eventenable __user
*uarg
= (void __user
*) arg
;
1593 struct mpt_ioctl_eventenable karg
;
1597 dctlprintk(("mptctl_eventenable called.\n"));
1598 if (copy_from_user(&karg
, uarg
, sizeof(struct mpt_ioctl_eventenable
))) {
1599 printk(KERN_ERR
"%s@%d::mptctl_eventenable - "
1600 "Unable to read in mpt_ioctl_eventenable struct @ %p\n",
1601 __FILE__
, __LINE__
, uarg
);
1605 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1607 dctlprintk((KERN_ERR
"%s::mptctl_eventenable() @%d - ioc%d not found!\n",
1608 __FILE__
, __LINE__
, iocnum
));
1612 if (ioc
->events
== NULL
) {
1613 /* Have not yet allocated memory - do so now.
1615 int sz
= MPTCTL_EVENT_LOG_SIZE
* sizeof(MPT_IOCTL_EVENTS
);
1616 ioc
->events
= kmalloc(sz
, GFP_KERNEL
);
1617 if (ioc
->events
== NULL
) {
1618 printk(KERN_ERR MYNAM
": ERROR - Insufficient memory to add adapter!\n");
1621 memset(ioc
->events
, 0, sz
);
1622 ioc
->alloc_total
+= sz
;
1624 ioc
->eventLogSize
= MPTCTL_EVENT_LOG_SIZE
;
1625 ioc
->eventContext
= 0;
1628 /* Update the IOC event logging flag.
1630 ioc
->eventTypes
= karg
.eventTypes
;
1635 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1637 mptctl_eventreport (unsigned long arg
)
1639 struct mpt_ioctl_eventreport __user
*uarg
= (void __user
*) arg
;
1640 struct mpt_ioctl_eventreport karg
;
1643 int numBytes
, maxEvents
, max
;
1645 dctlprintk(("mptctl_eventreport called.\n"));
1646 if (copy_from_user(&karg
, uarg
, sizeof(struct mpt_ioctl_eventreport
))) {
1647 printk(KERN_ERR
"%s@%d::mptctl_eventreport - "
1648 "Unable to read in mpt_ioctl_eventreport struct @ %p\n",
1649 __FILE__
, __LINE__
, uarg
);
1653 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1655 dctlprintk((KERN_ERR
"%s::mptctl_eventreport() @%d - ioc%d not found!\n",
1656 __FILE__
, __LINE__
, iocnum
));
1660 numBytes
= karg
.hdr
.maxDataSize
- sizeof(mpt_ioctl_header
);
1661 maxEvents
= numBytes
/sizeof(MPT_IOCTL_EVENTS
);
1664 max
= ioc
->eventLogSize
< maxEvents
? ioc
->eventLogSize
: maxEvents
;
1666 /* If fewer than 1 event is requested, there must have
1667 * been some type of error.
1669 if ((max
< 1) || !ioc
->events
)
1672 /* Copy the data from kernel memory to user memory
1674 numBytes
= max
* sizeof(MPT_IOCTL_EVENTS
);
1675 if (copy_to_user(uarg
->eventData
, ioc
->events
, numBytes
)) {
1676 printk(KERN_ERR
"%s@%d::mptctl_eventreport - "
1677 "Unable to write out mpt_ioctl_eventreport struct @ %p\n",
1678 __FILE__
, __LINE__
, ioc
->events
);
1685 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1687 mptctl_replace_fw (unsigned long arg
)
1689 struct mpt_ioctl_replace_fw __user
*uarg
= (void __user
*) arg
;
1690 struct mpt_ioctl_replace_fw karg
;
1695 dctlprintk(("mptctl_replace_fw called.\n"));
1696 if (copy_from_user(&karg
, uarg
, sizeof(struct mpt_ioctl_replace_fw
))) {
1697 printk(KERN_ERR
"%s@%d::mptctl_replace_fw - "
1698 "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
1699 __FILE__
, __LINE__
, uarg
);
1703 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1705 dctlprintk((KERN_ERR
"%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
1706 __FILE__
, __LINE__
, iocnum
));
1710 /* If caching FW, Free the old FW image
1712 if (ioc
->cached_fw
== NULL
)
1715 mpt_free_fw_memory(ioc
);
1717 /* Allocate memory for the new FW image
1719 newFwSize
= karg
.newImageSize
;
1721 if (newFwSize
& 0x01)
1723 if (newFwSize
& 0x02)
1726 mpt_alloc_fw_memory(ioc
, newFwSize
);
1727 if (ioc
->cached_fw
== NULL
)
1730 /* Copy the data from user memory to kernel space
1732 if (copy_from_user(ioc
->cached_fw
, uarg
->newImage
, newFwSize
)) {
1733 printk(KERN_ERR
"%s@%d::mptctl_replace_fw - "
1734 "Unable to read in mpt_ioctl_replace_fw image "
1735 "@ %p\n", __FILE__
, __LINE__
, uarg
);
1736 mpt_free_fw_memory(ioc
);
1740 /* Update IOCFactsReply
1742 ioc
->facts
.FWImageSize
= newFwSize
;
1746 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1747 /* MPT IOCTL MPTCOMMAND function.
1748 * Cast the arg into the mpt_ioctl_mpt_command structure.
1751 * Return: 0 if successful
1752 * -EBUSY if previous command timout and IOC reset is not complete.
1753 * -EFAULT if data unavailable
1754 * -ENODEV if no such device/adapter
1755 * -ETIME if timer expires
1756 * -ENOMEM if memory allocation error
1759 mptctl_mpt_command (unsigned long arg
)
1761 struct mpt_ioctl_command __user
*uarg
= (void __user
*) arg
;
1762 struct mpt_ioctl_command karg
;
1767 dctlprintk(("mptctl_command called.\n"));
1769 if (copy_from_user(&karg
, uarg
, sizeof(struct mpt_ioctl_command
))) {
1770 printk(KERN_ERR
"%s@%d::mptctl_mpt_command - "
1771 "Unable to read in mpt_ioctl_command struct @ %p\n",
1772 __FILE__
, __LINE__
, uarg
);
1776 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1778 dctlprintk((KERN_ERR
"%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
1779 __FILE__
, __LINE__
, iocnum
));
1783 rc
= mptctl_do_mpt_command (karg
, &uarg
->MF
);
1788 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1789 /* Worker routine for the IOCTL MPTCOMMAND and MPTCOMMAND32 (sparc) commands.
1792 * Return: 0 if successful
1793 * -EBUSY if previous command timout and IOC reset is not complete.
1794 * -EFAULT if data unavailable
1795 * -ENODEV if no such device/adapter
1796 * -ETIME if timer expires
1797 * -ENOMEM if memory allocation error
1798 * -EPERM if SCSI I/O and target is untagged
1801 mptctl_do_mpt_command (struct mpt_ioctl_command karg
, void __user
*mfPtr
)
1804 MPT_FRAME_HDR
*mf
= NULL
;
1807 struct buflist bufIn
; /* data In buffer */
1808 struct buflist bufOut
; /* data Out buffer */
1809 dma_addr_t dma_addr_in
;
1810 dma_addr_t dma_addr_out
;
1811 int sgSize
= 0; /* Num SG elements */
1812 int iocnum
, flagsLength
;
1815 int tm_flags_set
= 0;
1818 dctlprintk(("mptctl_do_mpt_command called.\n"));
1819 bufIn
.kptr
= bufOut
.kptr
= NULL
;
1821 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
1823 dctlprintk((KERN_ERR
"%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
1824 __FILE__
, __LINE__
, iocnum
));
1828 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
1829 "No memory available during driver init.\n",
1830 __FILE__
, __LINE__
);
1832 } else if (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_DID_IOCRESET
) {
1833 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
1834 "Busy with IOC Reset \n", __FILE__
, __LINE__
);
1838 /* Verify that the final request frame will not be too large.
1840 sz
= karg
.dataSgeOffset
* 4;
1841 if (karg
.dataInSize
> 0)
1842 sz
+= sizeof(dma_addr_t
) + sizeof(u32
);
1843 if (karg
.dataOutSize
> 0)
1844 sz
+= sizeof(dma_addr_t
) + sizeof(u32
);
1846 if (sz
> ioc
->req_sz
) {
1847 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
1848 "Request frame too large (%d) maximum (%d)\n",
1849 __FILE__
, __LINE__
, sz
, ioc
->req_sz
);
1853 /* Get a free request frame and save the message context.
1855 if ((mf
= mpt_get_msg_frame(mptctl_id
, ioc
)) == NULL
)
1858 hdr
= (MPIHeader_t
*) mf
;
1859 msgContext
= le32_to_cpu(hdr
->MsgContext
);
1860 req_idx
= le16_to_cpu(mf
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
);
1862 /* Copy the request frame
1863 * Reset the saved message context.
1864 * Request frame in user space
1866 if (copy_from_user(mf
, mfPtr
, karg
.dataSgeOffset
* 4)) {
1867 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
1868 "Unable to read MF from mpt_ioctl_command struct @ %p\n",
1869 __FILE__
, __LINE__
, mfPtr
);
1873 hdr
->MsgContext
= cpu_to_le32(msgContext
);
1876 /* Verify that this request is allowed.
1878 switch (hdr
->Function
) {
1879 case MPI_FUNCTION_IOC_FACTS
:
1880 case MPI_FUNCTION_PORT_FACTS
:
1881 karg
.dataOutSize
= karg
.dataInSize
= 0;
1884 case MPI_FUNCTION_CONFIG
:
1885 case MPI_FUNCTION_FC_COMMON_TRANSPORT_SEND
:
1886 case MPI_FUNCTION_FC_EX_LINK_SRVC_SEND
:
1887 case MPI_FUNCTION_FW_UPLOAD
:
1888 case MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
1889 case MPI_FUNCTION_FW_DOWNLOAD
:
1890 case MPI_FUNCTION_FC_PRIMITIVE_SEND
:
1893 case MPI_FUNCTION_SCSI_IO_REQUEST
:
1895 SCSIIORequest_t
*pScsiReq
= (SCSIIORequest_t
*) mf
;
1896 VirtDevice
*pTarget
= NULL
;
1897 MPT_SCSI_HOST
*hd
= NULL
;
1898 int qtag
= MPI_SCSIIO_CONTROL_UNTAGGED
;
1900 int target
= (int) pScsiReq
->TargetID
;
1903 if ((target
< 0) || (target
>= ioc
->sh
->max_id
)) {
1904 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
1905 "Target ID out of bounds. \n",
1906 __FILE__
, __LINE__
);
1911 pScsiReq
->MsgFlags
= mpt_msg_flags();
1913 /* verify that app has not requested
1914 * more sense data than driver
1915 * can provide, if so, reset this parameter
1916 * set the sense buffer pointer low address
1917 * update the control field to specify Q type
1919 if (karg
.maxSenseBytes
> MPT_SENSE_BUFFER_SIZE
)
1920 pScsiReq
->SenseBufferLength
= MPT_SENSE_BUFFER_SIZE
;
1922 pScsiReq
->SenseBufferLength
= karg
.maxSenseBytes
;
1924 pScsiReq
->SenseBufferLowAddr
=
1925 cpu_to_le32(ioc
->sense_buf_low_dma
1926 + (req_idx
* MPT_SENSE_BUFFER_ALLOC
));
1928 if ((hd
= (MPT_SCSI_HOST
*) ioc
->sh
->hostdata
)) {
1930 pTarget
= hd
->Targets
[target
];
1933 if (pTarget
&&(pTarget
->tflags
& MPT_TARGET_FLAGS_Q_YES
))
1934 qtag
= MPI_SCSIIO_CONTROL_SIMPLEQ
;
1936 /* Have the IOCTL driver set the direction based
1937 * on the dataOutSize (ordering issue with Sparc).
1939 if (karg
.dataOutSize
> 0) {
1940 scsidir
= MPI_SCSIIO_CONTROL_WRITE
;
1941 dataSize
= karg
.dataOutSize
;
1943 scsidir
= MPI_SCSIIO_CONTROL_READ
;
1944 dataSize
= karg
.dataInSize
;
1947 pScsiReq
->Control
= cpu_to_le32(scsidir
| qtag
);
1948 pScsiReq
->DataLength
= cpu_to_le32(dataSize
);
1950 ioc
->ioctl
->reset
= MPTCTL_RESET_OK
;
1951 ioc
->ioctl
->target
= target
;
1954 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
1955 "SCSI driver is not loaded. \n",
1956 __FILE__
, __LINE__
);
1962 case MPI_FUNCTION_RAID_ACTION
:
1967 case MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
1969 SCSIIORequest_t
*pScsiReq
= (SCSIIORequest_t
*) mf
;
1970 int qtag
= MPI_SCSIIO_CONTROL_SIMPLEQ
;
1971 int scsidir
= MPI_SCSIIO_CONTROL_READ
;
1974 pScsiReq
->MsgFlags
= mpt_msg_flags();
1976 /* verify that app has not requested
1977 * more sense data than driver
1978 * can provide, if so, reset this parameter
1979 * set the sense buffer pointer low address
1980 * update the control field to specify Q type
1982 if (karg
.maxSenseBytes
> MPT_SENSE_BUFFER_SIZE
)
1983 pScsiReq
->SenseBufferLength
= MPT_SENSE_BUFFER_SIZE
;
1985 pScsiReq
->SenseBufferLength
= karg
.maxSenseBytes
;
1987 pScsiReq
->SenseBufferLowAddr
=
1988 cpu_to_le32(ioc
->sense_buf_low_dma
1989 + (req_idx
* MPT_SENSE_BUFFER_ALLOC
));
1991 /* All commands to physical devices are tagged
1994 /* Have the IOCTL driver set the direction based
1995 * on the dataOutSize (ordering issue with Sparc).
1997 if (karg
.dataOutSize
> 0) {
1998 scsidir
= MPI_SCSIIO_CONTROL_WRITE
;
1999 dataSize
= karg
.dataOutSize
;
2001 scsidir
= MPI_SCSIIO_CONTROL_READ
;
2002 dataSize
= karg
.dataInSize
;
2005 pScsiReq
->Control
= cpu_to_le32(scsidir
| qtag
);
2006 pScsiReq
->DataLength
= cpu_to_le32(dataSize
);
2008 ioc
->ioctl
->reset
= MPTCTL_RESET_OK
;
2009 ioc
->ioctl
->target
= pScsiReq
->TargetID
;
2011 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
2012 "SCSI driver is not loaded. \n",
2013 __FILE__
, __LINE__
);
2019 case MPI_FUNCTION_SCSI_TASK_MGMT
:
2021 MPT_SCSI_HOST
*hd
= NULL
;
2022 if ((ioc
->sh
== NULL
) || ((hd
= (MPT_SCSI_HOST
*)ioc
->sh
->hostdata
) == NULL
)) {
2023 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
2024 "SCSI driver not loaded or SCSI host not found. \n",
2025 __FILE__
, __LINE__
);
2028 } else if (mptctl_set_tm_flags(hd
) != 0) {
2036 case MPI_FUNCTION_IOC_INIT
:
2038 IOCInit_t
*pInit
= (IOCInit_t
*) mf
;
2039 u32 high_addr
, sense_high
;
2041 /* Verify that all entries in the IOC INIT match
2042 * existing setup (and in LE format).
2044 if (sizeof(dma_addr_t
) == sizeof(u64
)) {
2045 high_addr
= cpu_to_le32((u32
)((u64
)ioc
->req_frames_dma
>> 32));
2046 sense_high
= cpu_to_le32((u32
)((u64
)ioc
->sense_buf_pool_dma
>> 32));
2052 if ((pInit
->Flags
!= 0) || (pInit
->MaxDevices
!= ioc
->facts
.MaxDevices
) ||
2053 (pInit
->MaxBuses
!= ioc
->facts
.MaxBuses
) ||
2054 (pInit
->ReplyFrameSize
!= cpu_to_le16(ioc
->reply_sz
)) ||
2055 (pInit
->HostMfaHighAddr
!= high_addr
) ||
2056 (pInit
->SenseBufferHighAddr
!= sense_high
)) {
2057 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
2058 "IOC_INIT issued with 1 or more incorrect parameters. Rejected.\n",
2059 __FILE__
, __LINE__
);
2067 * MPI_FUNCTION_PORT_ENABLE
2068 * MPI_FUNCTION_TARGET_CMD_BUFFER_POST
2069 * MPI_FUNCTION_TARGET_ASSIST
2070 * MPI_FUNCTION_TARGET_STATUS_SEND
2071 * MPI_FUNCTION_TARGET_MODE_ABORT
2072 * MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
2073 * MPI_FUNCTION_IO_UNIT_RESET
2074 * MPI_FUNCTION_HANDSHAKE
2075 * MPI_FUNCTION_REPLY_FRAME_REMOVAL
2076 * MPI_FUNCTION_EVENT_NOTIFICATION
2077 * (driver handles event notification)
2078 * MPI_FUNCTION_EVENT_ACK
2081 /* What to do with these??? CHECK ME!!!
2082 MPI_FUNCTION_FC_LINK_SRVC_BUF_POST
2083 MPI_FUNCTION_FC_LINK_SRVC_RSP
2084 MPI_FUNCTION_FC_ABORT
2085 MPI_FUNCTION_LAN_SEND
2086 MPI_FUNCTION_LAN_RECEIVE
2087 MPI_FUNCTION_LAN_RESET
2090 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
2091 "Illegal request (function 0x%x) \n",
2092 __FILE__
, __LINE__
, hdr
->Function
);
2097 /* Add the SGL ( at most one data in SGE and one data out SGE )
2098 * In the case of two SGE's - the data out (write) will always
2099 * preceede the data in (read) SGE. psgList is used to free the
2102 psge
= (char *) (((int *) mf
) + karg
.dataSgeOffset
);
2105 /* bufIn and bufOut are used for user to kernel space transfers
2107 bufIn
.kptr
= bufOut
.kptr
= NULL
;
2108 bufIn
.len
= bufOut
.len
= 0;
2110 if (karg
.dataOutSize
> 0)
2113 if (karg
.dataInSize
> 0)
2118 /* Set up the dataOut memory allocation */
2119 if (karg
.dataOutSize
> 0) {
2120 if (karg
.dataInSize
> 0) {
2121 flagsLength
= ( MPI_SGE_FLAGS_SIMPLE_ELEMENT
|
2122 MPI_SGE_FLAGS_END_OF_BUFFER
|
2123 MPI_SGE_FLAGS_DIRECTION
|
2125 << MPI_SGE_FLAGS_SHIFT
;
2127 flagsLength
= MPT_SGE_FLAGS_SSIMPLE_WRITE
;
2129 flagsLength
|= karg
.dataOutSize
;
2130 bufOut
.len
= karg
.dataOutSize
;
2131 bufOut
.kptr
= pci_alloc_consistent(
2132 ioc
->pcidev
, bufOut
.len
, &dma_addr_out
);
2134 if (bufOut
.kptr
== NULL
) {
2139 * Copy to MF and to sglbuf
2141 mpt_add_sge(psge
, flagsLength
, dma_addr_out
);
2142 psge
+= (sizeof(u32
) + sizeof(dma_addr_t
));
2144 /* Copy user data to kernel space.
2146 if (copy_from_user(bufOut
.kptr
,
2150 "%s@%d::mptctl_do_mpt_command - Unable "
2151 "to read user data "
2153 __FILE__
, __LINE__
,karg
.dataOutBufPtr
);
2160 if (karg
.dataInSize
> 0) {
2161 flagsLength
= MPT_SGE_FLAGS_SSIMPLE_READ
;
2162 flagsLength
|= karg
.dataInSize
;
2164 bufIn
.len
= karg
.dataInSize
;
2165 bufIn
.kptr
= pci_alloc_consistent(ioc
->pcidev
,
2166 bufIn
.len
, &dma_addr_in
);
2168 if (bufIn
.kptr
== NULL
) {
2173 * Copy to MF and to sglbuf
2175 mpt_add_sge(psge
, flagsLength
, dma_addr_in
);
2181 mpt_add_sge(psge
, flagsLength
, (dma_addr_t
) -1);
2184 /* The request is complete. Set the timer parameters
2185 * and issue the request.
2187 if (karg
.timeout
> 0) {
2188 ioc
->ioctl
->timer
.expires
= jiffies
+ HZ
*karg
.timeout
;
2190 ioc
->ioctl
->timer
.expires
= jiffies
+ HZ
*MPT_IOCTL_DEFAULT_TIMEOUT
;
2193 ioc
->ioctl
->wait_done
= 0;
2194 ioc
->ioctl
->status
|= MPT_IOCTL_STATUS_TIMER_ACTIVE
;
2195 add_timer(&ioc
->ioctl
->timer
);
2197 if (hdr
->Function
== MPI_FUNCTION_SCSI_TASK_MGMT
) {
2198 DBG_DUMP_TM_REQUEST_FRAME((u32
*)mf
);
2199 rc
= mpt_send_handshake_request(mptctl_id
, ioc
,
2200 sizeof(SCSITaskMgmt_t
), (u32
*)mf
, CAN_SLEEP
);
2202 wait_event(mptctl_wait
, ioc
->ioctl
->wait_done
);
2204 mptctl_free_tm_flags(ioc
);
2206 del_timer(&ioc
->ioctl
->timer
);
2207 ioc
->ioctl
->status
&= ~MPT_IOCTL_STATUS_TIMER_ACTIVE
;
2208 ioc
->ioctl
->status
|= MPT_IOCTL_STATUS_TM_FAILED
;
2209 mpt_free_msg_frame(ioc
, mf
);
2212 mpt_put_msg_frame(mptctl_id
, ioc
, mf
);
2213 wait_event(mptctl_wait
, ioc
->ioctl
->wait_done
);
2219 * If command failed and failure triggered a diagnostic reset
2220 * OR a diagnostic reset happens during command processing,
2221 * no data, messaging queues are reset (mf cannot be accessed),
2222 * and status is DID_IOCRESET
2224 * If a user-requested bus reset fails to be handshaked, then
2225 * mf is returned to free queue and status is TM_FAILED.
2227 * Otherise, the command completed and the mf was freed
2228 # by ISR (mf cannot be touched).
2230 if (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_DID_IOCRESET
) {
2231 /* The timer callback deleted the
2232 * timer and reset the adapter queues.
2234 printk(KERN_WARNING
"%s@%d::mptctl_do_mpt_command - "
2235 "Timeout Occurred on IOCTL! Reset IOC.\n", __FILE__
, __LINE__
);
2238 } else if (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_TM_FAILED
) {
2239 /* User TM request failed! mf has not been freed.
2243 /* If a valid reply frame, copy to the user.
2244 * Offset 2: reply length in U32's
2246 if (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_RF_VALID
) {
2247 if (karg
.maxReplyBytes
< ioc
->reply_sz
) {
2248 sz
= min(karg
.maxReplyBytes
, 4*ioc
->ioctl
->ReplyFrame
[2]);
2250 sz
= min(ioc
->reply_sz
, 4*ioc
->ioctl
->ReplyFrame
[2]);
2254 if (copy_to_user(karg
.replyFrameBufPtr
,
2255 &ioc
->ioctl
->ReplyFrame
, sz
)){
2257 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
2258 "Unable to write out reply frame %p\n",
2259 __FILE__
, __LINE__
, karg
.replyFrameBufPtr
);
2266 /* If valid sense data, copy to user.
2268 if (ioc
->ioctl
->status
& MPT_IOCTL_STATUS_SENSE_VALID
) {
2269 sz
= min(karg
.maxSenseBytes
, MPT_SENSE_BUFFER_SIZE
);
2271 if (copy_to_user(karg
.senseDataPtr
, ioc
->ioctl
->sense
, sz
)) {
2272 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
2273 "Unable to write sense data to user %p\n",
2282 /* If the overall status is _GOOD and data in, copy data
2285 if ((ioc
->ioctl
->status
& MPT_IOCTL_STATUS_COMMAND_GOOD
) &&
2286 (karg
.dataInSize
> 0) && (bufIn
.kptr
)) {
2288 if (copy_to_user(karg
.dataInBufPtr
,
2289 bufIn
.kptr
, karg
.dataInSize
)) {
2290 printk(KERN_ERR
"%s@%d::mptctl_do_mpt_command - "
2291 "Unable to write data to user %p\n",
2300 /* Clear all status bits except TMTIMER_ACTIVE, this bit is cleared
2301 * upon completion of the TM command.
2302 * ioc->ioctl->status = 0;
2304 ioc
->ioctl
->status
&= ~(MPT_IOCTL_STATUS_TIMER_ACTIVE
| MPT_IOCTL_STATUS_TM_FAILED
|
2305 MPT_IOCTL_STATUS_COMMAND_GOOD
| MPT_IOCTL_STATUS_SENSE_VALID
|
2306 MPT_IOCTL_STATUS_RF_VALID
| MPT_IOCTL_STATUS_DID_IOCRESET
);
2309 mptctl_free_tm_flags(ioc
);
2311 /* Free the allocated memory.
2313 if (bufOut
.kptr
!= NULL
) {
2314 pci_free_consistent(ioc
->pcidev
,
2315 bufOut
.len
, (void *) bufOut
.kptr
, dma_addr_out
);
2318 if (bufIn
.kptr
!= NULL
) {
2319 pci_free_consistent(ioc
->pcidev
,
2320 bufIn
.len
, (void *) bufIn
.kptr
, dma_addr_in
);
2323 /* mf is null if command issued successfully
2324 * otherwise, failure occured after mf acquired.
2327 mpt_free_msg_frame(ioc
, mf
);
2332 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2333 /* Prototype Routine for the HP HOST INFO command.
2336 * Return: 0 if successful
2337 * -EFAULT if data unavailable
2338 * -EBUSY if previous command timout and IOC reset is not complete.
2339 * -ENODEV if no such device/adapter
2340 * -ETIME if timer expires
2341 * -ENOMEM if memory allocation error
2344 mptctl_hp_hostinfo(unsigned long arg
, unsigned int data_size
)
2346 hp_host_info_t __user
*uarg
= (void __user
*) arg
;
2348 struct pci_dev
*pdev
;
2351 hp_host_info_t karg
;
2353 ConfigPageHeader_t hdr
;
2357 dctlprintk((": mptctl_hp_hostinfo called.\n"));
2358 /* Reset long to int. Should affect IA64 and SPARC only
2360 if (data_size
== sizeof(hp_host_info_t
))
2362 else if (data_size
== sizeof(hp_host_info_rev0_t
))
2363 cim_rev
= 0; /* obsolete */
2367 if (copy_from_user(&karg
, uarg
, sizeof(hp_host_info_t
))) {
2368 printk(KERN_ERR
"%s@%d::mptctl_hp_host_info - "
2369 "Unable to read in hp_host_info struct @ %p\n",
2370 __FILE__
, __LINE__
, uarg
);
2374 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
2376 dctlprintk((KERN_ERR
"%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
2377 __FILE__
, __LINE__
, iocnum
));
2381 /* Fill in the data and return the structure to the calling
2384 pdev
= (struct pci_dev
*) ioc
->pcidev
;
2386 karg
.vendor
= pdev
->vendor
;
2387 karg
.device
= pdev
->device
;
2388 karg
.subsystem_id
= pdev
->subsystem_device
;
2389 karg
.subsystem_vendor
= pdev
->subsystem_vendor
;
2390 karg
.devfn
= pdev
->devfn
;
2391 karg
.bus
= pdev
->bus
->number
;
2393 /* Save the SCSI host no. if
2394 * SCSI driver loaded
2396 if (ioc
->sh
!= NULL
)
2397 karg
.host_no
= ioc
->sh
->host_no
;
2401 /* Reformat the fw_version into a string
2403 karg
.fw_version
[0] = ioc
->facts
.FWVersion
.Struct
.Major
>= 10 ?
2404 ((ioc
->facts
.FWVersion
.Struct
.Major
/ 10) + '0') : '0';
2405 karg
.fw_version
[1] = (ioc
->facts
.FWVersion
.Struct
.Major
% 10 ) + '0';
2406 karg
.fw_version
[2] = '.';
2407 karg
.fw_version
[3] = ioc
->facts
.FWVersion
.Struct
.Minor
>= 10 ?
2408 ((ioc
->facts
.FWVersion
.Struct
.Minor
/ 10) + '0') : '0';
2409 karg
.fw_version
[4] = (ioc
->facts
.FWVersion
.Struct
.Minor
% 10 ) + '0';
2410 karg
.fw_version
[5] = '.';
2411 karg
.fw_version
[6] = ioc
->facts
.FWVersion
.Struct
.Unit
>= 10 ?
2412 ((ioc
->facts
.FWVersion
.Struct
.Unit
/ 10) + '0') : '0';
2413 karg
.fw_version
[7] = (ioc
->facts
.FWVersion
.Struct
.Unit
% 10 ) + '0';
2414 karg
.fw_version
[8] = '.';
2415 karg
.fw_version
[9] = ioc
->facts
.FWVersion
.Struct
.Dev
>= 10 ?
2416 ((ioc
->facts
.FWVersion
.Struct
.Dev
/ 10) + '0') : '0';
2417 karg
.fw_version
[10] = (ioc
->facts
.FWVersion
.Struct
.Dev
% 10 ) + '0';
2418 karg
.fw_version
[11] = '\0';
2420 /* Issue a config request to get the device serial number
2422 hdr
.PageVersion
= 0;
2425 hdr
.PageType
= MPI_CONFIG_PAGETYPE_MANUFACTURING
;
2429 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
2430 cfg
.dir
= 0; /* read */
2433 strncpy(karg
.serial_number
, " ", 24);
2434 if (mpt_config(ioc
, &cfg
) == 0) {
2435 if (cfg
.hdr
->PageLength
> 0) {
2436 /* Issue the second config page request */
2437 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
2439 pbuf
= pci_alloc_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, &buf_dma
);
2441 cfg
.physAddr
= buf_dma
;
2442 if (mpt_config(ioc
, &cfg
) == 0) {
2443 ManufacturingPage0_t
*pdata
= (ManufacturingPage0_t
*) pbuf
;
2444 if (strlen(pdata
->BoardTracerNumber
) > 1) {
2445 strncpy(karg
.serial_number
, pdata
->BoardTracerNumber
, 24);
2446 karg
.serial_number
[24-1]='\0';
2449 pci_free_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, pbuf
, buf_dma
);
2454 rc
= mpt_GetIocState(ioc
, 1);
2456 case MPI_IOC_STATE_OPERATIONAL
:
2457 karg
.ioc_status
= HP_STATUS_OK
;
2460 case MPI_IOC_STATE_FAULT
:
2461 karg
.ioc_status
= HP_STATUS_FAILED
;
2464 case MPI_IOC_STATE_RESET
:
2465 case MPI_IOC_STATE_READY
:
2467 karg
.ioc_status
= HP_STATUS_OTHER
;
2471 karg
.base_io_addr
= pci_resource_start(pdev
, 0);
2473 if ((int)ioc
->chip_type
<= (int) FC929
)
2474 karg
.bus_phys_width
= HP_BUS_WIDTH_UNK
;
2476 karg
.bus_phys_width
= HP_BUS_WIDTH_16
;
2478 karg
.hard_resets
= 0;
2479 karg
.soft_resets
= 0;
2481 if (ioc
->sh
!= NULL
) {
2482 MPT_SCSI_HOST
*hd
= (MPT_SCSI_HOST
*)ioc
->sh
->hostdata
;
2484 if (hd
&& (cim_rev
== 1)) {
2485 karg
.hard_resets
= hd
->hard_resets
;
2486 karg
.soft_resets
= hd
->soft_resets
;
2487 karg
.timeouts
= hd
->timeouts
;
2492 cfg
.action
= MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL
;
2493 cfg
.dir
= MPI_TB_ISTWI_FLAGS_READ
;
2495 pbuf
= pci_alloc_consistent(ioc
->pcidev
, 4, &buf_dma
);
2497 cfg
.physAddr
= buf_dma
;
2498 if ((mpt_toolbox(ioc
, &cfg
)) == 0) {
2499 karg
.rsvd
= *(u32
*)pbuf
;
2501 pci_free_consistent(ioc
->pcidev
, 4, pbuf
, buf_dma
);
2505 /* Copy the data from kernel memory to user memory
2507 if (copy_to_user((char __user
*)arg
, &karg
, sizeof(hp_host_info_t
))) {
2508 printk(KERN_ERR
"%s@%d::mptctl_hpgethostinfo - "
2509 "Unable to write out hp_host_info @ %p\n",
2510 __FILE__
, __LINE__
, uarg
);
2518 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2519 /* Prototype Routine for the HP TARGET INFO command.
2522 * Return: 0 if successful
2523 * -EFAULT if data unavailable
2524 * -EBUSY if previous command timout and IOC reset is not complete.
2525 * -ENODEV if no such device/adapter
2526 * -ETIME if timer expires
2527 * -ENOMEM if memory allocation error
2530 mptctl_hp_targetinfo(unsigned long arg
)
2532 hp_target_info_t __user
*uarg
= (void __user
*) arg
;
2533 SCSIDevicePage0_t
*pg0_alloc
;
2534 SCSIDevicePage3_t
*pg3_alloc
;
2536 MPT_SCSI_HOST
*hd
= NULL
;
2537 hp_target_info_t karg
;
2540 dma_addr_t page_dma
;
2542 ConfigPageHeader_t hdr
;
2543 int tmp
, np
, rc
= 0;
2545 dctlprintk((": mptctl_hp_targetinfo called.\n"));
2546 if (copy_from_user(&karg
, uarg
, sizeof(hp_target_info_t
))) {
2547 printk(KERN_ERR
"%s@%d::mptctl_hp_targetinfo - "
2548 "Unable to read in hp_host_targetinfo struct @ %p\n",
2549 __FILE__
, __LINE__
, uarg
);
2553 if (((iocnum
= mpt_verify_adapter(karg
.hdr
.iocnum
, &ioc
)) < 0) ||
2555 dctlprintk((KERN_ERR
"%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
2556 __FILE__
, __LINE__
, iocnum
));
2560 /* There is nothing to do for FCP parts.
2562 if ((int) ioc
->chip_type
<= (int) FC929
)
2565 if ((ioc
->spi_data
.sdp0length
== 0) || (ioc
->sh
== NULL
))
2568 if (ioc
->sh
->host_no
!= karg
.hdr
.host
)
2571 /* Get the data transfer speeds
2573 data_sz
= ioc
->spi_data
.sdp0length
* 4;
2574 pg0_alloc
= (SCSIDevicePage0_t
*) pci_alloc_consistent(ioc
->pcidev
, data_sz
, &page_dma
);
2576 hdr
.PageVersion
= ioc
->spi_data
.sdp0version
;
2577 hdr
.PageLength
= data_sz
;
2579 hdr
.PageType
= MPI_CONFIG_PAGETYPE_SCSI_DEVICE
;
2582 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
2585 cfg
.physAddr
= page_dma
;
2587 cfg
.pageAddr
= (karg
.hdr
.channel
<< 8) | karg
.hdr
.id
;
2589 if ((rc
= mpt_config(ioc
, &cfg
)) == 0) {
2590 np
= le32_to_cpu(pg0_alloc
->NegotiatedParameters
);
2591 karg
.negotiated_width
= np
& MPI_SCSIDEVPAGE0_NP_WIDE
?
2592 HP_BUS_WIDTH_16
: HP_BUS_WIDTH_8
;
2594 if (np
& MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK
) {
2595 tmp
= (np
& MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK
) >> 8;
2597 karg
.negotiated_speed
= HP_DEV_SPEED_ULTRA320
;
2598 else if (tmp
<= 0x09)
2599 karg
.negotiated_speed
= HP_DEV_SPEED_ULTRA160
;
2600 else if (tmp
<= 0x0A)
2601 karg
.negotiated_speed
= HP_DEV_SPEED_ULTRA2
;
2602 else if (tmp
<= 0x0C)
2603 karg
.negotiated_speed
= HP_DEV_SPEED_ULTRA
;
2604 else if (tmp
<= 0x25)
2605 karg
.negotiated_speed
= HP_DEV_SPEED_FAST
;
2607 karg
.negotiated_speed
= HP_DEV_SPEED_ASYNC
;
2609 karg
.negotiated_speed
= HP_DEV_SPEED_ASYNC
;
2612 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*) pg0_alloc
, page_dma
);
2617 karg
.message_rejects
= -1;
2618 karg
.phase_errors
= -1;
2619 karg
.parity_errors
= -1;
2620 karg
.select_timeouts
= -1;
2622 /* Get the target error parameters
2624 hdr
.PageVersion
= 0;
2627 hdr
.PageType
= MPI_CONFIG_PAGETYPE_SCSI_DEVICE
;
2630 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
2634 if ((mpt_config(ioc
, &cfg
) == 0) && (cfg
.hdr
->PageLength
> 0)) {
2635 /* Issue the second config page request */
2636 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
2637 data_sz
= (int) cfg
.hdr
->PageLength
* 4;
2638 pg3_alloc
= (SCSIDevicePage3_t
*) pci_alloc_consistent(
2639 ioc
->pcidev
, data_sz
, &page_dma
);
2641 cfg
.physAddr
= page_dma
;
2642 cfg
.pageAddr
= (karg
.hdr
.channel
<< 8) | karg
.hdr
.id
;
2643 if ((rc
= mpt_config(ioc
, &cfg
)) == 0) {
2644 karg
.message_rejects
= (u32
) le16_to_cpu(pg3_alloc
->MsgRejectCount
);
2645 karg
.phase_errors
= (u32
) le16_to_cpu(pg3_alloc
->PhaseErrorCount
);
2646 karg
.parity_errors
= (u32
) le16_to_cpu(pg3_alloc
->ParityErrorCount
);
2648 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*) pg3_alloc
, page_dma
);
2651 hd
= (MPT_SCSI_HOST
*) ioc
->sh
->hostdata
;
2653 karg
.select_timeouts
= hd
->sel_timeout
[karg
.hdr
.id
];
2655 /* Copy the data from kernel memory to user memory
2657 if (copy_to_user((char __user
*)arg
, &karg
, sizeof(hp_target_info_t
))) {
2658 printk(KERN_ERR
"%s@%d::mptctl_hp_target_info - "
2659 "Unable to write out mpt_ioctl_targetinfo struct @ %p\n",
2660 __FILE__
, __LINE__
, uarg
);
2667 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2669 static struct file_operations mptctl_fops
= {
2670 .owner
= THIS_MODULE
,
2671 .llseek
= no_llseek
,
2672 .ioctl
= mptctl_ioctl
,
2675 static struct miscdevice mptctl_miscdev
= {
2681 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2683 #ifdef CONFIG_COMPAT
2685 #include <linux/ioctl32.h>
2687 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2688 /* compat_XXX functions are used to provide a conversion between
2689 * pointers and u32's. If the arg does not contain any pointers, then
2690 * a specialized function (compat_XXX) is not needed. If the arg
2691 * does contain pointer(s), then the specialized function is used
2692 * to ensure the structure contents is properly processed by mptctl.
2695 compat_mptctl_ioctl(unsigned int fd
, unsigned int cmd
,
2696 unsigned long arg
, struct file
*filp
)
2701 dctlprintk((KERN_INFO MYNAM
"::compat_mptctl_ioctl() called\n"));
2702 ret
= mptctl_ioctl(filp
->f_dentry
->d_inode
, filp
, cmd
, arg
);
2708 compat_mptfwxfer_ioctl(unsigned int fd
, unsigned int cmd
,
2709 unsigned long arg
, struct file
*filp
)
2711 struct mpt_fw_xfer32 kfw32
;
2712 struct mpt_fw_xfer kfw
;
2713 MPT_ADAPTER
*iocp
= NULL
;
2714 int iocnum
, iocnumX
;
2715 int nonblock
= (filp
->f_flags
& O_NONBLOCK
);
2718 dctlprintk((KERN_INFO MYNAM
"::compat_mptfwxfer_ioctl() called\n"));
2720 if (copy_from_user(&kfw32
, (char __user
*)arg
, sizeof(kfw32
)))
2723 /* Verify intended MPT adapter */
2724 iocnumX
= kfw32
.iocnum
& 0xFF;
2725 if (((iocnum
= mpt_verify_adapter(iocnumX
, &iocp
)) < 0) ||
2727 dctlprintk((KERN_ERR MYNAM
"::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
2728 __LINE__
, iocnumX
));
2732 if ((ret
= mptctl_syscall_down(iocp
, nonblock
)) != 0)
2735 kfw
.iocnum
= iocnum
;
2736 kfw
.fwlen
= kfw32
.fwlen
;
2737 kfw
.bufp
= compat_ptr(kfw32
.bufp
);
2739 ret
= mptctl_do_fw_download(kfw
.iocnum
, kfw
.bufp
, kfw
.fwlen
);
2741 up(&iocp
->ioctl
->sem_ioc
);
2747 compat_mpt_command(unsigned int fd
, unsigned int cmd
,
2748 unsigned long arg
, struct file
*filp
)
2750 struct mpt_ioctl_command32 karg32
;
2751 struct mpt_ioctl_command32 __user
*uarg
= (struct mpt_ioctl_command32 __user
*) arg
;
2752 struct mpt_ioctl_command karg
;
2753 MPT_ADAPTER
*iocp
= NULL
;
2754 int iocnum
, iocnumX
;
2755 int nonblock
= (filp
->f_flags
& O_NONBLOCK
);
2758 dctlprintk((KERN_INFO MYNAM
"::compat_mpt_command() called\n"));
2760 if (copy_from_user(&karg32
, (char __user
*)arg
, sizeof(karg32
)))
2763 /* Verify intended MPT adapter */
2764 iocnumX
= karg32
.hdr
.iocnum
& 0xFF;
2765 if (((iocnum
= mpt_verify_adapter(iocnumX
, &iocp
)) < 0) ||
2767 dctlprintk((KERN_ERR MYNAM
"::compat_mpt_command @%d - ioc%d not found!\n",
2768 __LINE__
, iocnumX
));
2772 if ((ret
= mptctl_syscall_down(iocp
, nonblock
)) != 0)
2775 /* Copy data to karg */
2776 karg
.hdr
.iocnum
= karg32
.hdr
.iocnum
;
2777 karg
.hdr
.port
= karg32
.hdr
.port
;
2778 karg
.timeout
= karg32
.timeout
;
2779 karg
.maxReplyBytes
= karg32
.maxReplyBytes
;
2781 karg
.dataInSize
= karg32
.dataInSize
;
2782 karg
.dataOutSize
= karg32
.dataOutSize
;
2783 karg
.maxSenseBytes
= karg32
.maxSenseBytes
;
2784 karg
.dataSgeOffset
= karg32
.dataSgeOffset
;
2786 karg
.replyFrameBufPtr
= (char __user
*)(unsigned long)karg32
.replyFrameBufPtr
;
2787 karg
.dataInBufPtr
= (char __user
*)(unsigned long)karg32
.dataInBufPtr
;
2788 karg
.dataOutBufPtr
= (char __user
*)(unsigned long)karg32
.dataOutBufPtr
;
2789 karg
.senseDataPtr
= (char __user
*)(unsigned long)karg32
.senseDataPtr
;
2791 /* Pass new structure to do_mpt_command
2793 ret
= mptctl_do_mpt_command (karg
, &uarg
->MF
);
2795 up(&iocp
->ioctl
->sem_ioc
);
2803 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2805 * mptctl_probe - Installs ioctl devices per bus.
2806 * @pdev: Pointer to pci_dev structure
2808 * Returns 0 for success, non-zero for failure.
2813 mptctl_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2818 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
2821 * Allocate and inite a MPT_IOCTL structure
2823 sz
= sizeof (MPT_IOCTL
);
2824 mem
= kmalloc(sz
, GFP_KERNEL
);
2831 ioc
->ioctl
= (MPT_IOCTL
*) mem
;
2832 ioc
->ioctl
->ioc
= ioc
;
2833 init_timer (&ioc
->ioctl
->timer
);
2834 ioc
->ioctl
->timer
.data
= (unsigned long) ioc
->ioctl
;
2835 ioc
->ioctl
->timer
.function
= mptctl_timer_expired
;
2836 init_timer (&ioc
->ioctl
->TMtimer
);
2837 ioc
->ioctl
->TMtimer
.data
= (unsigned long) ioc
->ioctl
;
2838 ioc
->ioctl
->TMtimer
.function
= mptctl_timer_expired
;
2839 sema_init(&ioc
->ioctl
->sem_ioc
, 1);
2844 mptctl_remove(pdev
);
2848 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2850 * mptctl_remove - Removed ioctl devices
2851 * @pdev: Pointer to pci_dev structure
2856 mptctl_remove(struct pci_dev
*pdev
)
2858 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
2860 kfree ( ioc
->ioctl
);
2863 static struct mpt_pci_driver mptctl_driver
= {
2864 .probe
= mptctl_probe
,
2865 .remove
= mptctl_remove
,
2868 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2869 static int __init
mptctl_init(void)
2874 show_mptmod_ver(my_NAME
, my_VERSION
);
2876 if(mpt_device_driver_register(&mptctl_driver
,
2877 MPTCTL_DRIVER
) != 0 ) {
2878 dprintk((KERN_INFO MYNAM
2879 ": failed to register dd callbacks\n"));
2882 #ifdef CONFIG_COMPAT
2883 err
= register_ioctl32_conversion(MPTIOCINFO
, compat_mptctl_ioctl
);
2884 if (++where
&& err
) goto out_fail
;
2885 err
= register_ioctl32_conversion(MPTIOCINFO1
, compat_mptctl_ioctl
);
2886 if (++where
&& err
) goto out_fail
;
2887 err
= register_ioctl32_conversion(MPTIOCINFO2
, compat_mptctl_ioctl
);
2888 if (++where
&& err
) goto out_fail
;
2889 err
= register_ioctl32_conversion(MPTTARGETINFO
, compat_mptctl_ioctl
);
2890 if (++where
&& err
) goto out_fail
;
2891 err
= register_ioctl32_conversion(MPTTEST
, compat_mptctl_ioctl
);
2892 if (++where
&& err
) goto out_fail
;
2893 err
= register_ioctl32_conversion(MPTEVENTQUERY
, compat_mptctl_ioctl
);
2894 if (++where
&& err
) goto out_fail
;
2895 err
= register_ioctl32_conversion(MPTEVENTENABLE
, compat_mptctl_ioctl
);
2896 if (++where
&& err
) goto out_fail
;
2897 err
= register_ioctl32_conversion(MPTEVENTREPORT
, compat_mptctl_ioctl
);
2898 if (++where
&& err
) goto out_fail
;
2899 err
= register_ioctl32_conversion(MPTHARDRESET
, compat_mptctl_ioctl
);
2900 if (++where
&& err
) goto out_fail
;
2901 err
= register_ioctl32_conversion(MPTCOMMAND32
, compat_mpt_command
);
2902 if (++where
&& err
) goto out_fail
;
2903 err
= register_ioctl32_conversion(MPTFWDOWNLOAD32
,
2904 compat_mptfwxfer_ioctl
);
2905 if (++where
&& err
) goto out_fail
;
2906 err
= register_ioctl32_conversion(HP_GETHOSTINFO
, compat_mptctl_ioctl
);
2907 if (++where
&& err
) goto out_fail
;
2908 err
= register_ioctl32_conversion(HP_GETTARGETINFO
, compat_mptctl_ioctl
);
2909 if (++where
&& err
) goto out_fail
;
2912 /* Register this device */
2913 err
= misc_register(&mptctl_miscdev
);
2915 printk(KERN_ERR MYNAM
": Can't register misc device [minor=%d].\n", MPT_MINOR
);
2918 printk(KERN_INFO MYNAM
": Registered with Fusion MPT base driver\n");
2919 printk(KERN_INFO MYNAM
": /dev/%s @ (major,minor=%d,%d)\n",
2920 mptctl_miscdev
.name
, MISC_MAJOR
, mptctl_miscdev
.minor
);
2923 * Install our handler
2926 if ((mptctl_id
= mpt_register(mptctl_reply
, MPTCTL_DRIVER
)) < 0) {
2927 printk(KERN_ERR MYNAM
": ERROR: Failed to register with Fusion MPT base driver\n");
2928 misc_deregister(&mptctl_miscdev
);
2933 if (mpt_reset_register(mptctl_id
, mptctl_ioc_reset
) == 0) {
2934 dprintk((KERN_INFO MYNAM
": Registered for IOC reset notifications\n"));
2943 #ifdef CONFIG_COMPAT
2944 printk(KERN_ERR MYNAM
": ERROR: Failed to register ioctl32_conversion!"
2945 " (%d:err=%d)\n", where
, err
);
2946 unregister_ioctl32_conversion(MPTIOCINFO
);
2947 unregister_ioctl32_conversion(MPTIOCINFO1
);
2948 unregister_ioctl32_conversion(MPTIOCINFO2
);
2949 unregister_ioctl32_conversion(MPTTARGETINFO
);
2950 unregister_ioctl32_conversion(MPTTEST
);
2951 unregister_ioctl32_conversion(MPTEVENTQUERY
);
2952 unregister_ioctl32_conversion(MPTEVENTENABLE
);
2953 unregister_ioctl32_conversion(MPTEVENTREPORT
);
2954 unregister_ioctl32_conversion(MPTHARDRESET
);
2955 unregister_ioctl32_conversion(MPTCOMMAND32
);
2956 unregister_ioctl32_conversion(MPTFWDOWNLOAD32
);
2957 unregister_ioctl32_conversion(HP_GETHOSTINFO
);
2958 unregister_ioctl32_conversion(HP_GETTARGETINFO
);
2961 mpt_device_driver_deregister(MPTCTL_DRIVER
);
2966 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2967 static void mptctl_exit(void)
2969 misc_deregister(&mptctl_miscdev
);
2970 printk(KERN_INFO MYNAM
": Deregistered /dev/%s @ (major,minor=%d,%d)\n",
2971 mptctl_miscdev
.name
, MISC_MAJOR
, mptctl_miscdev
.minor
);
2973 /* De-register reset handler from base module */
2974 mpt_reset_deregister(mptctl_id
);
2975 dprintk((KERN_INFO MYNAM
": Deregistered for IOC reset notifications\n"));
2977 /* De-register callback handler from base module */
2978 mpt_deregister(mptctl_id
);
2979 printk(KERN_INFO MYNAM
": Deregistered from Fusion MPT base driver\n");
2981 mpt_device_driver_deregister(MPTCTL_DRIVER
);
2983 #ifdef CONFIG_COMPAT
2984 unregister_ioctl32_conversion(MPTIOCINFO
);
2985 unregister_ioctl32_conversion(MPTIOCINFO1
);
2986 unregister_ioctl32_conversion(MPTIOCINFO2
);
2987 unregister_ioctl32_conversion(MPTTARGETINFO
);
2988 unregister_ioctl32_conversion(MPTTEST
);
2989 unregister_ioctl32_conversion(MPTEVENTQUERY
);
2990 unregister_ioctl32_conversion(MPTEVENTENABLE
);
2991 unregister_ioctl32_conversion(MPTEVENTREPORT
);
2992 unregister_ioctl32_conversion(MPTHARDRESET
);
2993 unregister_ioctl32_conversion(MPTCOMMAND32
);
2994 unregister_ioctl32_conversion(MPTFWDOWNLOAD32
);
2995 unregister_ioctl32_conversion(HP_GETHOSTINFO
);
2996 unregister_ioctl32_conversion(HP_GETTARGETINFO
);
3001 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3003 module_init(mptctl_init
);
3004 module_exit(mptctl_exit
);