2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Abstract: Contains all routines for control of the AFA comm layer
32 #include <linux/kernel.h>
33 #include <linux/init.h>
34 #include <linux/types.h>
35 #include <linux/pci.h>
36 #include <linux/spinlock.h>
37 #include <linux/slab.h>
38 #include <linux/completion.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/blkdev.h>
41 #include <linux/delay.h> /* ssleep prototype */
42 #include <linux/kthread.h>
43 #include <linux/semaphore.h>
44 #include <linux/uaccess.h>
45 #include <scsi/scsi_host.h>
50 * ioctl_send_fib - send a FIB from userspace
51 * @dev: adapter is being processed
52 * @arg: arguments to the ioctl call
54 * This routine sends a fib to the adapter on behalf of a user level
57 # define AAC_DEBUG_PREAMBLE KERN_INFO
58 # define AAC_DEBUG_POSTAMBLE
60 static int ioctl_send_fib(struct aac_dev
* dev
, void __user
*arg
)
64 struct hw_fib
* hw_fib
= (struct hw_fib
*)0;
65 dma_addr_t hw_fib_pa
= (dma_addr_t
)0LL;
66 unsigned int size
, osize
;
72 fibptr
= aac_fib_alloc(dev
);
77 kfib
= fibptr
->hw_fib_va
;
79 * First copy in the header so that we can check the size field.
81 if (copy_from_user((void *)kfib
, arg
, sizeof(struct aac_fibhdr
))) {
86 * Since we copy based on the fib header size, make sure that we
87 * will not overrun the buffer when we copy the memory. Return
88 * an error if we would.
90 osize
= size
= le16_to_cpu(kfib
->header
.Size
) +
91 sizeof(struct aac_fibhdr
);
92 if (size
< le16_to_cpu(kfib
->header
.SenderSize
))
93 size
= le16_to_cpu(kfib
->header
.SenderSize
);
94 if (size
> dev
->max_fib_size
) {
102 kfib
= pci_alloc_consistent(dev
->pdev
, size
, &daddr
);
108 /* Highjack the hw_fib */
109 hw_fib
= fibptr
->hw_fib_va
;
110 hw_fib_pa
= fibptr
->hw_fib_pa
;
111 fibptr
->hw_fib_va
= kfib
;
112 fibptr
->hw_fib_pa
= daddr
;
113 memset(((char *)kfib
) + dev
->max_fib_size
, 0, size
- dev
->max_fib_size
);
114 memcpy(kfib
, hw_fib
, dev
->max_fib_size
);
117 if (copy_from_user(kfib
, arg
, size
)) {
122 /* Sanity check the second copy */
123 if ((osize
!= le16_to_cpu(kfib
->header
.Size
) +
124 sizeof(struct aac_fibhdr
))
125 || (size
< le16_to_cpu(kfib
->header
.SenderSize
))) {
130 if (kfib
->header
.Command
== cpu_to_le16(TakeABreakPt
)) {
131 aac_adapter_interrupt(dev
);
133 * Since we didn't really send a fib, zero out the state to allow
134 * cleanup code not to assert.
136 kfib
->header
.XferState
= 0;
138 retval
= aac_fib_send(le16_to_cpu(kfib
->header
.Command
), fibptr
,
139 le16_to_cpu(kfib
->header
.Size
) , FsaNormal
,
144 if (aac_fib_complete(fibptr
) != 0) {
150 * Make sure that the size returned by the adapter (which includes
151 * the header) is less than or equal to the size of a fib, so we
152 * don't corrupt application data. Then copy that size to the user
153 * buffer. (Don't try to add the header information again, since it
154 * was already included by the adapter.)
158 if (copy_to_user(arg
, (void *)kfib
, size
))
162 pci_free_consistent(dev
->pdev
, size
, kfib
, fibptr
->hw_fib_pa
);
163 fibptr
->hw_fib_pa
= hw_fib_pa
;
164 fibptr
->hw_fib_va
= hw_fib
;
166 if (retval
!= -ERESTARTSYS
)
167 aac_fib_free(fibptr
);
172 * open_getadapter_fib - Get the next fib
174 * This routine will get the next Fib, if available, from the AdapterFibContext
175 * passed in from the user.
178 static int open_getadapter_fib(struct aac_dev
* dev
, void __user
*arg
)
180 struct aac_fib_context
* fibctx
;
183 fibctx
= kmalloc(sizeof(struct aac_fib_context
), GFP_KERNEL
);
184 if (fibctx
== NULL
) {
188 struct list_head
* entry
;
189 struct aac_fib_context
* context
;
191 fibctx
->type
= FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT
;
192 fibctx
->size
= sizeof(struct aac_fib_context
);
194 * Yes yes, I know this could be an index, but we have a
195 * better guarantee of uniqueness for the locked loop below.
196 * Without the aid of a persistent history, this also helps
197 * reduce the chance that the opaque context would be reused.
199 fibctx
->unique
= (u32
)((ulong
)fibctx
& 0xFFFFFFFF);
201 * Initialize the mutex used to wait for the next AIF.
203 sema_init(&fibctx
->wait_sem
, 0);
206 * Initialize the fibs and set the count of fibs on
210 INIT_LIST_HEAD(&fibctx
->fib_list
);
211 fibctx
->jiffies
= jiffies
/HZ
;
213 * Now add this context onto the adapter's
214 * AdapterFibContext list.
216 spin_lock_irqsave(&dev
->fib_lock
, flags
);
217 /* Ensure that we have a unique identifier */
218 entry
= dev
->fib_list
.next
;
219 while (entry
!= &dev
->fib_list
) {
220 context
= list_entry(entry
, struct aac_fib_context
, next
);
221 if (context
->unique
== fibctx
->unique
) {
222 /* Not unique (32 bits) */
224 entry
= dev
->fib_list
.next
;
229 list_add_tail(&fibctx
->next
, &dev
->fib_list
);
230 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
231 if (copy_to_user(arg
, &fibctx
->unique
,
232 sizeof(fibctx
->unique
))) {
242 * next_getadapter_fib - get the next fib
243 * @dev: adapter to use
244 * @arg: ioctl argument
246 * This routine will get the next Fib, if available, from the AdapterFibContext
247 * passed in from the user.
250 static int next_getadapter_fib(struct aac_dev
* dev
, void __user
*arg
)
254 struct aac_fib_context
*fibctx
;
256 struct list_head
* entry
;
259 if(copy_from_user((void *)&f
, arg
, sizeof(struct fib_ioctl
)))
262 * Verify that the HANDLE passed in was a valid AdapterFibContext
264 * Search the list of AdapterFibContext addresses on the adapter
265 * to be sure this is a valid address
267 spin_lock_irqsave(&dev
->fib_lock
, flags
);
268 entry
= dev
->fib_list
.next
;
271 while (entry
!= &dev
->fib_list
) {
272 fibctx
= list_entry(entry
, struct aac_fib_context
, next
);
274 * Extract the AdapterFibContext from the Input parameters.
276 if (fibctx
->unique
== f
.fibctx
) { /* We found a winner */
283 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
284 dprintk ((KERN_INFO
"Fib Context not found\n"));
288 if((fibctx
->type
!= FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT
) ||
289 (fibctx
->size
!= sizeof(struct aac_fib_context
))) {
290 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
291 dprintk ((KERN_INFO
"Fib Context corrupt?\n"));
296 * If there are no fibs to send back, then either wait or return
300 if (!list_empty(&fibctx
->fib_list
)) {
302 * Pull the next fib from the fibs
304 entry
= fibctx
->fib_list
.next
;
307 fib
= list_entry(entry
, struct fib
, fiblink
);
309 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
310 if (copy_to_user(f
.fib
, fib
->hw_fib_va
, sizeof(struct hw_fib
))) {
311 kfree(fib
->hw_fib_va
);
316 * Free the space occupied by this copy of the fib.
318 kfree(fib
->hw_fib_va
);
322 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
323 /* If someone killed the AIF aacraid thread, restart it */
324 status
= !dev
->aif_thread
;
325 if (status
&& !dev
->in_reset
&& dev
->queues
&& dev
->fsa_dev
) {
326 /* Be paranoid, be very paranoid! */
327 kthread_stop(dev
->thread
);
330 dev
->thread
= kthread_run(aac_command_thread
, dev
,
335 if(down_interruptible(&fibctx
->wait_sem
) < 0) {
336 status
= -ERESTARTSYS
;
338 /* Lock again and retry */
339 spin_lock_irqsave(&dev
->fib_lock
, flags
);
346 fibctx
->jiffies
= jiffies
/HZ
;
350 int aac_close_fib_context(struct aac_dev
* dev
, struct aac_fib_context
* fibctx
)
355 * First free any FIBs that have not been consumed.
357 while (!list_empty(&fibctx
->fib_list
)) {
358 struct list_head
* entry
;
360 * Pull the next fib from the fibs
362 entry
= fibctx
->fib_list
.next
;
364 fib
= list_entry(entry
, struct fib
, fiblink
);
367 * Free the space occupied by this copy of the fib.
369 kfree(fib
->hw_fib_va
);
373 * Remove the Context from the AdapterFibContext List
375 list_del(&fibctx
->next
);
381 * Free the space occupied by the Context
388 * close_getadapter_fib - close down user fib context
390 * @arg: ioctl arguments
392 * This routine will close down the fibctx passed in from the user.
395 static int close_getadapter_fib(struct aac_dev
* dev
, void __user
*arg
)
397 struct aac_fib_context
*fibctx
;
400 struct list_head
* entry
;
403 * Verify that the HANDLE passed in was a valid AdapterFibContext
405 * Search the list of AdapterFibContext addresses on the adapter
406 * to be sure this is a valid address
409 entry
= dev
->fib_list
.next
;
412 while(entry
!= &dev
->fib_list
) {
413 fibctx
= list_entry(entry
, struct aac_fib_context
, next
);
415 * Extract the fibctx from the input parameters
417 if (fibctx
->unique
== (u32
)(uintptr_t)arg
) /* We found a winner */
424 return 0; /* Already gone */
426 if((fibctx
->type
!= FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT
) ||
427 (fibctx
->size
!= sizeof(struct aac_fib_context
)))
429 spin_lock_irqsave(&dev
->fib_lock
, flags
);
430 status
= aac_close_fib_context(dev
, fibctx
);
431 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
436 * check_revision - close down user fib context
438 * @arg: ioctl arguments
440 * This routine returns the driver version.
441 * Under Linux, there have been no version incompatibilities, so this is
445 static int check_revision(struct aac_dev
*dev
, void __user
*arg
)
447 struct revision response
;
448 char *driver_version
= aac_driver_version
;
452 version
= (simple_strtol(driver_version
,
453 &driver_version
, 10) << 24) | 0x00000400;
454 version
+= simple_strtol(driver_version
+ 1, &driver_version
, 10) << 16;
455 version
+= simple_strtol(driver_version
+ 1, NULL
, 10);
456 response
.version
= cpu_to_le32(version
);
457 # ifdef AAC_DRIVER_BUILD
458 response
.build
= cpu_to_le32(AAC_DRIVER_BUILD
);
460 response
.build
= cpu_to_le32(9999);
463 if (copy_to_user(arg
, &response
, sizeof(response
)))
475 static int aac_send_raw_srb(struct aac_dev
* dev
, void __user
* arg
)
479 struct aac_srb
*srbcmd
= NULL
;
480 struct user_aac_srb
*user_srbcmd
= NULL
;
481 struct user_aac_srb __user
*user_srb
= arg
;
482 struct aac_srb_reply __user
*user_reply
;
483 struct aac_srb_reply
* reply
;
488 void __user
*sg_user
[32];
492 u32 actual_fibsize64
, actual_fibsize
= 0;
497 dprintk((KERN_DEBUG
"aacraid: send raw srb -EBUSY\n"));
500 if (!capable(CAP_SYS_ADMIN
)){
501 dprintk((KERN_DEBUG
"aacraid: No permission to send raw srb\n"));
505 * Allocate and initialize a Fib then setup a SRB command
507 if (!(srbfib
= aac_fib_alloc(dev
))) {
510 aac_fib_init(srbfib
);
511 /* raw_srb FIB is not FastResponseCapable */
512 srbfib
->hw_fib_va
->header
.XferState
&= ~cpu_to_le32(FastResponseCapable
);
514 srbcmd
= (struct aac_srb
*) fib_data(srbfib
);
516 memset(sg_list
, 0, sizeof(sg_list
)); /* cleanup may take issue */
517 if(copy_from_user(&fibsize
, &user_srb
->count
,sizeof(u32
))){
518 dprintk((KERN_DEBUG
"aacraid: Could not copy data size from user\n"));
523 if ((fibsize
< (sizeof(struct user_aac_srb
) - sizeof(struct user_sgentry
))) ||
524 (fibsize
> (dev
->max_fib_size
- sizeof(struct aac_fibhdr
)))) {
529 user_srbcmd
= kmalloc(fibsize
, GFP_KERNEL
);
531 dprintk((KERN_DEBUG
"aacraid: Could not make a copy of the srb\n"));
535 if(copy_from_user(user_srbcmd
, user_srb
,fibsize
)){
536 dprintk((KERN_DEBUG
"aacraid: Could not copy srb from user\n"));
541 user_reply
= arg
+fibsize
;
543 flags
= user_srbcmd
->flags
; /* from user in cpu order */
544 // Fix up srb for endian and force some values
546 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
); // Force this
547 srbcmd
->channel
= cpu_to_le32(user_srbcmd
->channel
);
548 srbcmd
->id
= cpu_to_le32(user_srbcmd
->id
);
549 srbcmd
->lun
= cpu_to_le32(user_srbcmd
->lun
);
550 srbcmd
->timeout
= cpu_to_le32(user_srbcmd
->timeout
);
551 srbcmd
->flags
= cpu_to_le32(flags
);
552 srbcmd
->retry_limit
= 0; // Obsolete parameter
553 srbcmd
->cdb_size
= cpu_to_le32(user_srbcmd
->cdb_size
);
554 memcpy(srbcmd
->cdb
, user_srbcmd
->cdb
, sizeof(srbcmd
->cdb
));
556 switch (flags
& (SRB_DataIn
| SRB_DataOut
)) {
558 data_dir
= DMA_TO_DEVICE
;
560 case (SRB_DataIn
| SRB_DataOut
):
561 data_dir
= DMA_BIDIRECTIONAL
;
564 data_dir
= DMA_FROM_DEVICE
;
569 if (user_srbcmd
->sg
.count
> ARRAY_SIZE(sg_list
)) {
570 dprintk((KERN_DEBUG
"aacraid: too many sg entries %d\n",
571 le32_to_cpu(srbcmd
->sg
.count
)));
575 actual_fibsize
= sizeof(struct aac_srb
) - sizeof(struct sgentry
) +
576 ((user_srbcmd
->sg
.count
& 0xff) * sizeof(struct sgentry
));
577 actual_fibsize64
= actual_fibsize
+ (user_srbcmd
->sg
.count
& 0xff) *
578 (sizeof(struct sgentry64
) - sizeof(struct sgentry
));
579 /* User made a mistake - should not continue */
580 if ((actual_fibsize
!= fibsize
) && (actual_fibsize64
!= fibsize
)) {
581 dprintk((KERN_DEBUG
"aacraid: Bad Size specified in "
582 "Raw SRB command calculated fibsize=%lu;%lu "
583 "user_srbcmd->sg.count=%d aac_srb=%lu sgentry=%lu;%lu "
584 "issued fibsize=%d\n",
585 actual_fibsize
, actual_fibsize64
, user_srbcmd
->sg
.count
,
586 sizeof(struct aac_srb
), sizeof(struct sgentry
),
587 sizeof(struct sgentry64
), fibsize
));
591 if ((data_dir
== DMA_NONE
) && user_srbcmd
->sg
.count
) {
592 dprintk((KERN_DEBUG
"aacraid: SG with no direction specified in Raw SRB command\n"));
597 if (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
) {
598 struct user_sgmap64
* upsg
= (struct user_sgmap64
*)&user_srbcmd
->sg
;
599 struct sgmap64
* psg
= (struct sgmap64
*)&srbcmd
->sg
;
602 * This should also catch if user used the 32 bit sgmap
604 if (actual_fibsize64
== fibsize
) {
605 actual_fibsize
= actual_fibsize64
;
606 for (i
= 0; i
< upsg
->count
; i
++) {
609 if (upsg
->sg
[i
].count
>
610 ((dev
->adapter_info
.options
&
612 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
617 /* Does this really need to be GFP_DMA? */
618 p
= kmalloc(upsg
->sg
[i
].count
,GFP_KERNEL
|__GFP_DMA
);
620 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
621 upsg
->sg
[i
].count
,i
,upsg
->count
));
625 addr
= (u64
)upsg
->sg
[i
].addr
[0];
626 addr
+= ((u64
)upsg
->sg
[i
].addr
[1]) << 32;
627 sg_user
[i
] = (void __user
*)(uintptr_t)addr
;
628 sg_list
[i
] = p
; // save so we can clean up later
631 if (flags
& SRB_DataOut
) {
632 if(copy_from_user(p
,sg_user
[i
],upsg
->sg
[i
].count
)){
633 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
638 addr
= pci_map_single(dev
->pdev
, p
, upsg
->sg
[i
].count
, data_dir
);
640 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
641 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
642 byte_count
+= upsg
->sg
[i
].count
;
643 psg
->sg
[i
].count
= cpu_to_le32(upsg
->sg
[i
].count
);
646 struct user_sgmap
* usg
;
648 actual_fibsize
- sizeof(struct aac_srb
)
649 + sizeof(struct sgmap
), GFP_KERNEL
);
651 dprintk((KERN_DEBUG
"aacraid: Allocation error in Raw SRB command\n"));
655 actual_fibsize
= actual_fibsize64
;
657 for (i
= 0; i
< usg
->count
; i
++) {
660 if (usg
->sg
[i
].count
>
661 ((dev
->adapter_info
.options
&
663 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
669 /* Does this really need to be GFP_DMA? */
670 p
= kmalloc(usg
->sg
[i
].count
,GFP_KERNEL
|__GFP_DMA
);
672 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
673 usg
->sg
[i
].count
,i
,usg
->count
));
678 sg_user
[i
] = (void __user
*)(uintptr_t)usg
->sg
[i
].addr
;
679 sg_list
[i
] = p
; // save so we can clean up later
682 if (flags
& SRB_DataOut
) {
683 if(copy_from_user(p
,sg_user
[i
],upsg
->sg
[i
].count
)){
685 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
690 addr
= pci_map_single(dev
->pdev
, p
, usg
->sg
[i
].count
, data_dir
);
692 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
693 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
694 byte_count
+= usg
->sg
[i
].count
;
695 psg
->sg
[i
].count
= cpu_to_le32(usg
->sg
[i
].count
);
699 srbcmd
->count
= cpu_to_le32(byte_count
);
700 if (user_srbcmd
->sg
.count
)
701 psg
->count
= cpu_to_le32(sg_indx
+1);
704 status
= aac_fib_send(ScsiPortCommand64
, srbfib
, actual_fibsize
, FsaNormal
, 1, 1,NULL
,NULL
);
706 struct user_sgmap
* upsg
= &user_srbcmd
->sg
;
707 struct sgmap
* psg
= &srbcmd
->sg
;
709 if (actual_fibsize64
== fibsize
) {
710 struct user_sgmap64
* usg
= (struct user_sgmap64
*)upsg
;
711 for (i
= 0; i
< upsg
->count
; i
++) {
714 if (usg
->sg
[i
].count
>
715 ((dev
->adapter_info
.options
&
717 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
722 /* Does this really need to be GFP_DMA? */
723 p
= kmalloc(usg
->sg
[i
].count
,GFP_KERNEL
|__GFP_DMA
);
725 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
726 usg
->sg
[i
].count
,i
,usg
->count
));
730 addr
= (u64
)usg
->sg
[i
].addr
[0];
731 addr
+= ((u64
)usg
->sg
[i
].addr
[1]) << 32;
732 sg_user
[i
] = (void __user
*)addr
;
733 sg_list
[i
] = p
; // save so we can clean up later
736 if (flags
& SRB_DataOut
) {
737 if(copy_from_user(p
,sg_user
[i
],usg
->sg
[i
].count
)){
738 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
743 addr
= pci_map_single(dev
->pdev
, p
, usg
->sg
[i
].count
, data_dir
);
745 psg
->sg
[i
].addr
= cpu_to_le32(addr
& 0xffffffff);
746 byte_count
+= usg
->sg
[i
].count
;
747 psg
->sg
[i
].count
= cpu_to_le32(usg
->sg
[i
].count
);
750 for (i
= 0; i
< upsg
->count
; i
++) {
753 if (upsg
->sg
[i
].count
>
754 ((dev
->adapter_info
.options
&
756 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
761 p
= kmalloc(upsg
->sg
[i
].count
, GFP_KERNEL
);
763 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
764 upsg
->sg
[i
].count
, i
, upsg
->count
));
768 sg_user
[i
] = (void __user
*)(uintptr_t)upsg
->sg
[i
].addr
;
769 sg_list
[i
] = p
; // save so we can clean up later
772 if (flags
& SRB_DataOut
) {
773 if(copy_from_user(p
, sg_user
[i
],
774 upsg
->sg
[i
].count
)) {
775 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
780 addr
= pci_map_single(dev
->pdev
, p
,
781 upsg
->sg
[i
].count
, data_dir
);
783 psg
->sg
[i
].addr
= cpu_to_le32(addr
);
784 byte_count
+= upsg
->sg
[i
].count
;
785 psg
->sg
[i
].count
= cpu_to_le32(upsg
->sg
[i
].count
);
788 srbcmd
->count
= cpu_to_le32(byte_count
);
789 if (user_srbcmd
->sg
.count
)
790 psg
->count
= cpu_to_le32(sg_indx
+1);
793 status
= aac_fib_send(ScsiPortCommand
, srbfib
, actual_fibsize
, FsaNormal
, 1, 1, NULL
, NULL
);
795 if (status
== -ERESTARTSYS
) {
796 rcode
= -ERESTARTSYS
;
801 dprintk((KERN_DEBUG
"aacraid: Could not send raw srb fib to hba\n"));
806 if (flags
& SRB_DataIn
) {
807 for(i
= 0 ; i
<= sg_indx
; i
++){
808 byte_count
= le32_to_cpu(
809 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)
810 ? ((struct sgmap64
*)&srbcmd
->sg
)->sg
[i
].count
811 : srbcmd
->sg
.sg
[i
].count
);
812 if(copy_to_user(sg_user
[i
], sg_list
[i
], byte_count
)){
813 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data to user\n"));
821 reply
= (struct aac_srb_reply
*) fib_data(srbfib
);
822 if(copy_to_user(user_reply
,reply
,sizeof(struct aac_srb_reply
))){
823 dprintk((KERN_DEBUG
"aacraid: Could not copy reply to user\n"));
830 for(i
=0; i
<= sg_indx
; i
++){
833 if (rcode
!= -ERESTARTSYS
) {
834 aac_fib_complete(srbfib
);
835 aac_fib_free(srbfib
);
841 struct aac_pci_info
{
847 static int aac_get_pci_info(struct aac_dev
* dev
, void __user
*arg
)
849 struct aac_pci_info pci_info
;
851 pci_info
.bus
= dev
->pdev
->bus
->number
;
852 pci_info
.slot
= PCI_SLOT(dev
->pdev
->devfn
);
854 if (copy_to_user(arg
, &pci_info
, sizeof(struct aac_pci_info
))) {
855 dprintk((KERN_DEBUG
"aacraid: Could not copy pci info\n"));
862 int aac_do_ioctl(struct aac_dev
* dev
, int cmd
, void __user
*arg
)
866 mutex_lock(&dev
->ioctl_mutex
);
868 if (dev
->adapter_shutdown
) {
874 * HBA gets first crack
877 status
= aac_dev_ioctl(dev
, cmd
, arg
);
878 if (status
!= -ENOTTY
)
882 case FSACTL_MINIPORT_REV_CHECK
:
883 status
= check_revision(dev
, arg
);
885 case FSACTL_SEND_LARGE_FIB
:
887 status
= ioctl_send_fib(dev
, arg
);
889 case FSACTL_OPEN_GET_ADAPTER_FIB
:
890 status
= open_getadapter_fib(dev
, arg
);
892 case FSACTL_GET_NEXT_ADAPTER_FIB
:
893 status
= next_getadapter_fib(dev
, arg
);
895 case FSACTL_CLOSE_GET_ADAPTER_FIB
:
896 status
= close_getadapter_fib(dev
, arg
);
898 case FSACTL_SEND_RAW_SRB
:
899 status
= aac_send_raw_srb(dev
,arg
);
901 case FSACTL_GET_PCI_INFO
:
902 status
= aac_get_pci_info(dev
,arg
);
910 mutex_unlock(&dev
->ioctl_mutex
);