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 <asm/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;
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 size
= le16_to_cpu(kfib
->header
.Size
) + sizeof(struct aac_fibhdr
);
91 if (size
< le16_to_cpu(kfib
->header
.SenderSize
))
92 size
= le16_to_cpu(kfib
->header
.SenderSize
);
93 if (size
> dev
->max_fib_size
) {
101 kfib
= pci_alloc_consistent(dev
->pdev
, size
, &daddr
);
107 /* Highjack the hw_fib */
108 hw_fib
= fibptr
->hw_fib_va
;
109 hw_fib_pa
= fibptr
->hw_fib_pa
;
110 fibptr
->hw_fib_va
= kfib
;
111 fibptr
->hw_fib_pa
= daddr
;
112 memset(((char *)kfib
) + dev
->max_fib_size
, 0, size
- dev
->max_fib_size
);
113 memcpy(kfib
, hw_fib
, dev
->max_fib_size
);
116 if (copy_from_user(kfib
, arg
, size
)) {
121 if (kfib
->header
.Command
== cpu_to_le16(TakeABreakPt
)) {
122 aac_adapter_interrupt(dev
);
124 * Since we didn't really send a fib, zero out the state to allow
125 * cleanup code not to assert.
127 kfib
->header
.XferState
= 0;
129 retval
= aac_fib_send(le16_to_cpu(kfib
->header
.Command
), fibptr
,
130 le16_to_cpu(kfib
->header
.Size
) , FsaNormal
,
135 if (aac_fib_complete(fibptr
) != 0) {
141 * Make sure that the size returned by the adapter (which includes
142 * the header) is less than or equal to the size of a fib, so we
143 * don't corrupt application data. Then copy that size to the user
144 * buffer. (Don't try to add the header information again, since it
145 * was already included by the adapter.)
149 if (copy_to_user(arg
, (void *)kfib
, size
))
153 pci_free_consistent(dev
->pdev
, size
, kfib
, fibptr
->hw_fib_pa
);
154 fibptr
->hw_fib_pa
= hw_fib_pa
;
155 fibptr
->hw_fib_va
= hw_fib
;
157 if (retval
!= -ERESTARTSYS
)
158 aac_fib_free(fibptr
);
163 * open_getadapter_fib - Get the next fib
165 * This routine will get the next Fib, if available, from the AdapterFibContext
166 * passed in from the user.
169 static int open_getadapter_fib(struct aac_dev
* dev
, void __user
*arg
)
171 struct aac_fib_context
* fibctx
;
174 fibctx
= kmalloc(sizeof(struct aac_fib_context
), GFP_KERNEL
);
175 if (fibctx
== NULL
) {
179 struct list_head
* entry
;
180 struct aac_fib_context
* context
;
182 fibctx
->type
= FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT
;
183 fibctx
->size
= sizeof(struct aac_fib_context
);
185 * Yes yes, I know this could be an index, but we have a
186 * better guarantee of uniqueness for the locked loop below.
187 * Without the aid of a persistent history, this also helps
188 * reduce the chance that the opaque context would be reused.
190 fibctx
->unique
= (u32
)((ulong
)fibctx
& 0xFFFFFFFF);
192 * Initialize the mutex used to wait for the next AIF.
194 sema_init(&fibctx
->wait_sem
, 0);
197 * Initialize the fibs and set the count of fibs on
201 INIT_LIST_HEAD(&fibctx
->fib_list
);
202 fibctx
->jiffies
= jiffies
/HZ
;
204 * Now add this context onto the adapter's
205 * AdapterFibContext list.
207 spin_lock_irqsave(&dev
->fib_lock
, flags
);
208 /* Ensure that we have a unique identifier */
209 entry
= dev
->fib_list
.next
;
210 while (entry
!= &dev
->fib_list
) {
211 context
= list_entry(entry
, struct aac_fib_context
, next
);
212 if (context
->unique
== fibctx
->unique
) {
213 /* Not unique (32 bits) */
215 entry
= dev
->fib_list
.next
;
220 list_add_tail(&fibctx
->next
, &dev
->fib_list
);
221 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
222 if (copy_to_user(arg
, &fibctx
->unique
,
223 sizeof(fibctx
->unique
))) {
233 * next_getadapter_fib - get the next fib
234 * @dev: adapter to use
235 * @arg: ioctl argument
237 * This routine will get the next Fib, if available, from the AdapterFibContext
238 * passed in from the user.
241 static int next_getadapter_fib(struct aac_dev
* dev
, void __user
*arg
)
245 struct aac_fib_context
*fibctx
;
247 struct list_head
* entry
;
250 if(copy_from_user((void *)&f
, arg
, sizeof(struct fib_ioctl
)))
253 * Verify that the HANDLE passed in was a valid AdapterFibContext
255 * Search the list of AdapterFibContext addresses on the adapter
256 * to be sure this is a valid address
258 spin_lock_irqsave(&dev
->fib_lock
, flags
);
259 entry
= dev
->fib_list
.next
;
262 while (entry
!= &dev
->fib_list
) {
263 fibctx
= list_entry(entry
, struct aac_fib_context
, next
);
265 * Extract the AdapterFibContext from the Input parameters.
267 if (fibctx
->unique
== f
.fibctx
) { /* We found a winner */
274 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
275 dprintk ((KERN_INFO
"Fib Context not found\n"));
279 if((fibctx
->type
!= FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT
) ||
280 (fibctx
->size
!= sizeof(struct aac_fib_context
))) {
281 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
282 dprintk ((KERN_INFO
"Fib Context corrupt?\n"));
287 * If there are no fibs to send back, then either wait or return
291 if (!list_empty(&fibctx
->fib_list
)) {
293 * Pull the next fib from the fibs
295 entry
= fibctx
->fib_list
.next
;
298 fib
= list_entry(entry
, struct fib
, fiblink
);
300 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
301 if (copy_to_user(f
.fib
, fib
->hw_fib_va
, sizeof(struct hw_fib
))) {
302 kfree(fib
->hw_fib_va
);
307 * Free the space occupied by this copy of the fib.
309 kfree(fib
->hw_fib_va
);
313 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
314 /* If someone killed the AIF aacraid thread, restart it */
315 status
= !dev
->aif_thread
;
316 if (status
&& !dev
->in_reset
&& dev
->queues
&& dev
->fsa_dev
) {
317 /* Be paranoid, be very paranoid! */
318 kthread_stop(dev
->thread
);
321 dev
->thread
= kthread_run(aac_command_thread
, dev
, dev
->name
);
325 if(down_interruptible(&fibctx
->wait_sem
) < 0) {
326 status
= -ERESTARTSYS
;
328 /* Lock again and retry */
329 spin_lock_irqsave(&dev
->fib_lock
, flags
);
336 fibctx
->jiffies
= jiffies
/HZ
;
340 int aac_close_fib_context(struct aac_dev
* dev
, struct aac_fib_context
* fibctx
)
345 * First free any FIBs that have not been consumed.
347 while (!list_empty(&fibctx
->fib_list
)) {
348 struct list_head
* entry
;
350 * Pull the next fib from the fibs
352 entry
= fibctx
->fib_list
.next
;
354 fib
= list_entry(entry
, struct fib
, fiblink
);
357 * Free the space occupied by this copy of the fib.
359 kfree(fib
->hw_fib_va
);
363 * Remove the Context from the AdapterFibContext List
365 list_del(&fibctx
->next
);
371 * Free the space occupied by the Context
378 * close_getadapter_fib - close down user fib context
380 * @arg: ioctl arguments
382 * This routine will close down the fibctx passed in from the user.
385 static int close_getadapter_fib(struct aac_dev
* dev
, void __user
*arg
)
387 struct aac_fib_context
*fibctx
;
390 struct list_head
* entry
;
393 * Verify that the HANDLE passed in was a valid AdapterFibContext
395 * Search the list of AdapterFibContext addresses on the adapter
396 * to be sure this is a valid address
399 entry
= dev
->fib_list
.next
;
402 while(entry
!= &dev
->fib_list
) {
403 fibctx
= list_entry(entry
, struct aac_fib_context
, next
);
405 * Extract the fibctx from the input parameters
407 if (fibctx
->unique
== (u32
)(uintptr_t)arg
) /* We found a winner */
414 return 0; /* Already gone */
416 if((fibctx
->type
!= FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT
) ||
417 (fibctx
->size
!= sizeof(struct aac_fib_context
)))
419 spin_lock_irqsave(&dev
->fib_lock
, flags
);
420 status
= aac_close_fib_context(dev
, fibctx
);
421 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
426 * check_revision - close down user fib context
428 * @arg: ioctl arguments
430 * This routine returns the driver version.
431 * Under Linux, there have been no version incompatibilities, so this is
435 static int check_revision(struct aac_dev
*dev
, void __user
*arg
)
437 struct revision response
;
438 char *driver_version
= aac_driver_version
;
442 version
= (simple_strtol(driver_version
,
443 &driver_version
, 10) << 24) | 0x00000400;
444 version
+= simple_strtol(driver_version
+ 1, &driver_version
, 10) << 16;
445 version
+= simple_strtol(driver_version
+ 1, NULL
, 10);
446 response
.version
= cpu_to_le32(version
);
447 # ifdef AAC_DRIVER_BUILD
448 response
.build
= cpu_to_le32(AAC_DRIVER_BUILD
);
450 response
.build
= cpu_to_le32(9999);
453 if (copy_to_user(arg
, &response
, sizeof(response
)))
465 static int aac_send_raw_srb(struct aac_dev
* dev
, void __user
* arg
)
469 struct aac_srb
*srbcmd
= NULL
;
470 struct user_aac_srb
*user_srbcmd
= NULL
;
471 struct user_aac_srb __user
*user_srb
= arg
;
472 struct aac_srb_reply __user
*user_reply
;
473 struct aac_srb_reply
* reply
;
478 void __user
*sg_user
[32];
482 u32 actual_fibsize64
, actual_fibsize
= 0;
487 dprintk((KERN_DEBUG
"aacraid: send raw srb -EBUSY\n"));
490 if (!capable(CAP_SYS_ADMIN
)){
491 dprintk((KERN_DEBUG
"aacraid: No permission to send raw srb\n"));
495 * Allocate and initialize a Fib then setup a SRB command
497 if (!(srbfib
= aac_fib_alloc(dev
))) {
500 aac_fib_init(srbfib
);
502 srbcmd
= (struct aac_srb
*) fib_data(srbfib
);
504 memset(sg_list
, 0, sizeof(sg_list
)); /* cleanup may take issue */
505 if(copy_from_user(&fibsize
, &user_srb
->count
,sizeof(u32
))){
506 dprintk((KERN_DEBUG
"aacraid: Could not copy data size from user\n"));
511 if (fibsize
> (dev
->max_fib_size
- sizeof(struct aac_fibhdr
))) {
516 user_srbcmd
= kmalloc(fibsize
, GFP_KERNEL
);
518 dprintk((KERN_DEBUG
"aacraid: Could not make a copy of the srb\n"));
522 if(copy_from_user(user_srbcmd
, user_srb
,fibsize
)){
523 dprintk((KERN_DEBUG
"aacraid: Could not copy srb from user\n"));
528 user_reply
= arg
+fibsize
;
530 flags
= user_srbcmd
->flags
; /* from user in cpu order */
531 // Fix up srb for endian and force some values
533 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
); // Force this
534 srbcmd
->channel
= cpu_to_le32(user_srbcmd
->channel
);
535 srbcmd
->id
= cpu_to_le32(user_srbcmd
->id
);
536 srbcmd
->lun
= cpu_to_le32(user_srbcmd
->lun
);
537 srbcmd
->timeout
= cpu_to_le32(user_srbcmd
->timeout
);
538 srbcmd
->flags
= cpu_to_le32(flags
);
539 srbcmd
->retry_limit
= 0; // Obsolete parameter
540 srbcmd
->cdb_size
= cpu_to_le32(user_srbcmd
->cdb_size
);
541 memcpy(srbcmd
->cdb
, user_srbcmd
->cdb
, sizeof(srbcmd
->cdb
));
543 switch (flags
& (SRB_DataIn
| SRB_DataOut
)) {
545 data_dir
= DMA_TO_DEVICE
;
547 case (SRB_DataIn
| SRB_DataOut
):
548 data_dir
= DMA_BIDIRECTIONAL
;
551 data_dir
= DMA_FROM_DEVICE
;
556 if (user_srbcmd
->sg
.count
> ARRAY_SIZE(sg_list
)) {
557 dprintk((KERN_DEBUG
"aacraid: too many sg entries %d\n",
558 le32_to_cpu(srbcmd
->sg
.count
)));
562 actual_fibsize
= sizeof(struct aac_srb
) - sizeof(struct sgentry
) +
563 ((user_srbcmd
->sg
.count
& 0xff) * sizeof(struct sgentry
));
564 actual_fibsize64
= actual_fibsize
+ (user_srbcmd
->sg
.count
& 0xff) *
565 (sizeof(struct sgentry64
) - sizeof(struct sgentry
));
566 /* User made a mistake - should not continue */
567 if ((actual_fibsize
!= fibsize
) && (actual_fibsize64
!= fibsize
)) {
568 dprintk((KERN_DEBUG
"aacraid: Bad Size specified in "
569 "Raw SRB command calculated fibsize=%lu;%lu "
570 "user_srbcmd->sg.count=%d aac_srb=%lu sgentry=%lu;%lu "
571 "issued fibsize=%d\n",
572 actual_fibsize
, actual_fibsize64
, user_srbcmd
->sg
.count
,
573 sizeof(struct aac_srb
), sizeof(struct sgentry
),
574 sizeof(struct sgentry64
), fibsize
));
578 if ((data_dir
== DMA_NONE
) && user_srbcmd
->sg
.count
) {
579 dprintk((KERN_DEBUG
"aacraid: SG with no direction specified in Raw SRB command\n"));
584 if (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
) {
585 struct user_sgmap64
* upsg
= (struct user_sgmap64
*)&user_srbcmd
->sg
;
586 struct sgmap64
* psg
= (struct sgmap64
*)&srbcmd
->sg
;
589 * This should also catch if user used the 32 bit sgmap
591 if (actual_fibsize64
== fibsize
) {
592 actual_fibsize
= actual_fibsize64
;
593 for (i
= 0; i
< upsg
->count
; i
++) {
596 if (upsg
->sg
[i
].count
>
597 ((dev
->adapter_info
.options
&
599 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
604 /* Does this really need to be GFP_DMA? */
605 p
= kmalloc(upsg
->sg
[i
].count
,GFP_KERNEL
|__GFP_DMA
);
607 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
608 upsg
->sg
[i
].count
,i
,upsg
->count
));
612 addr
= (u64
)upsg
->sg
[i
].addr
[0];
613 addr
+= ((u64
)upsg
->sg
[i
].addr
[1]) << 32;
614 sg_user
[i
] = (void __user
*)(uintptr_t)addr
;
615 sg_list
[i
] = p
; // save so we can clean up later
618 if (flags
& SRB_DataOut
) {
619 if(copy_from_user(p
,sg_user
[i
],upsg
->sg
[i
].count
)){
620 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
625 addr
= pci_map_single(dev
->pdev
, p
, upsg
->sg
[i
].count
, data_dir
);
627 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
628 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
629 byte_count
+= upsg
->sg
[i
].count
;
630 psg
->sg
[i
].count
= cpu_to_le32(upsg
->sg
[i
].count
);
633 struct user_sgmap
* usg
;
634 usg
= kmalloc(actual_fibsize
- sizeof(struct aac_srb
)
635 + sizeof(struct sgmap
), GFP_KERNEL
);
637 dprintk((KERN_DEBUG
"aacraid: Allocation error in Raw SRB command\n"));
641 memcpy (usg
, upsg
, actual_fibsize
- sizeof(struct aac_srb
)
642 + sizeof(struct sgmap
));
643 actual_fibsize
= actual_fibsize64
;
645 for (i
= 0; i
< usg
->count
; i
++) {
648 if (usg
->sg
[i
].count
>
649 ((dev
->adapter_info
.options
&
651 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
656 /* Does this really need to be GFP_DMA? */
657 p
= kmalloc(usg
->sg
[i
].count
,GFP_KERNEL
|__GFP_DMA
);
659 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
660 usg
->sg
[i
].count
,i
,usg
->count
));
665 sg_user
[i
] = (void __user
*)(uintptr_t)usg
->sg
[i
].addr
;
666 sg_list
[i
] = p
; // save so we can clean up later
669 if (flags
& SRB_DataOut
) {
670 if(copy_from_user(p
,sg_user
[i
],upsg
->sg
[i
].count
)){
672 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
677 addr
= pci_map_single(dev
->pdev
, p
, usg
->sg
[i
].count
, data_dir
);
679 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
680 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
681 byte_count
+= usg
->sg
[i
].count
;
682 psg
->sg
[i
].count
= cpu_to_le32(usg
->sg
[i
].count
);
686 srbcmd
->count
= cpu_to_le32(byte_count
);
687 psg
->count
= cpu_to_le32(sg_indx
+1);
688 status
= aac_fib_send(ScsiPortCommand64
, srbfib
, actual_fibsize
, FsaNormal
, 1, 1,NULL
,NULL
);
690 struct user_sgmap
* upsg
= &user_srbcmd
->sg
;
691 struct sgmap
* psg
= &srbcmd
->sg
;
693 if (actual_fibsize64
== fibsize
) {
694 struct user_sgmap64
* usg
= (struct user_sgmap64
*)upsg
;
695 for (i
= 0; i
< upsg
->count
; i
++) {
698 if (usg
->sg
[i
].count
>
699 ((dev
->adapter_info
.options
&
701 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
706 /* Does this really need to be GFP_DMA? */
707 p
= kmalloc(usg
->sg
[i
].count
,GFP_KERNEL
|__GFP_DMA
);
709 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
710 usg
->sg
[i
].count
,i
,usg
->count
));
714 addr
= (u64
)usg
->sg
[i
].addr
[0];
715 addr
+= ((u64
)usg
->sg
[i
].addr
[1]) << 32;
716 sg_user
[i
] = (void __user
*)addr
;
717 sg_list
[i
] = p
; // save so we can clean up later
720 if (flags
& SRB_DataOut
) {
721 if(copy_from_user(p
,sg_user
[i
],usg
->sg
[i
].count
)){
722 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
727 addr
= pci_map_single(dev
->pdev
, p
, usg
->sg
[i
].count
, data_dir
);
729 psg
->sg
[i
].addr
= cpu_to_le32(addr
& 0xffffffff);
730 byte_count
+= usg
->sg
[i
].count
;
731 psg
->sg
[i
].count
= cpu_to_le32(usg
->sg
[i
].count
);
734 for (i
= 0; i
< upsg
->count
; i
++) {
737 if (upsg
->sg
[i
].count
>
738 ((dev
->adapter_info
.options
&
740 (dev
->scsi_host_ptr
->max_sectors
<< 9) :
745 p
= kmalloc(upsg
->sg
[i
].count
, GFP_KERNEL
);
747 dprintk((KERN_DEBUG
"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
748 upsg
->sg
[i
].count
, i
, upsg
->count
));
752 sg_user
[i
] = (void __user
*)(uintptr_t)upsg
->sg
[i
].addr
;
753 sg_list
[i
] = p
; // save so we can clean up later
756 if (flags
& SRB_DataOut
) {
757 if(copy_from_user(p
, sg_user
[i
],
758 upsg
->sg
[i
].count
)) {
759 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data from user\n"));
764 addr
= pci_map_single(dev
->pdev
, p
,
765 upsg
->sg
[i
].count
, data_dir
);
767 psg
->sg
[i
].addr
= cpu_to_le32(addr
);
768 byte_count
+= upsg
->sg
[i
].count
;
769 psg
->sg
[i
].count
= cpu_to_le32(upsg
->sg
[i
].count
);
772 srbcmd
->count
= cpu_to_le32(byte_count
);
773 psg
->count
= cpu_to_le32(sg_indx
+1);
774 status
= aac_fib_send(ScsiPortCommand
, srbfib
, actual_fibsize
, FsaNormal
, 1, 1, NULL
, NULL
);
776 if (status
== -ERESTARTSYS
) {
777 rcode
= -ERESTARTSYS
;
782 dprintk((KERN_DEBUG
"aacraid: Could not send raw srb fib to hba\n"));
787 if (flags
& SRB_DataIn
) {
788 for(i
= 0 ; i
<= sg_indx
; i
++){
789 byte_count
= le32_to_cpu(
790 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)
791 ? ((struct sgmap64
*)&srbcmd
->sg
)->sg
[i
].count
792 : srbcmd
->sg
.sg
[i
].count
);
793 if(copy_to_user(sg_user
[i
], sg_list
[i
], byte_count
)){
794 dprintk((KERN_DEBUG
"aacraid: Could not copy sg data to user\n"));
802 reply
= (struct aac_srb_reply
*) fib_data(srbfib
);
803 if(copy_to_user(user_reply
,reply
,sizeof(struct aac_srb_reply
))){
804 dprintk((KERN_DEBUG
"aacraid: Could not copy reply to user\n"));
811 for(i
=0; i
<= sg_indx
; i
++){
814 if (rcode
!= -ERESTARTSYS
) {
815 aac_fib_complete(srbfib
);
816 aac_fib_free(srbfib
);
822 struct aac_pci_info
{
828 static int aac_get_pci_info(struct aac_dev
* dev
, void __user
*arg
)
830 struct aac_pci_info pci_info
;
832 pci_info
.bus
= dev
->pdev
->bus
->number
;
833 pci_info
.slot
= PCI_SLOT(dev
->pdev
->devfn
);
835 if (copy_to_user(arg
, &pci_info
, sizeof(struct aac_pci_info
))) {
836 dprintk((KERN_DEBUG
"aacraid: Could not copy pci info\n"));
843 int aac_do_ioctl(struct aac_dev
* dev
, int cmd
, void __user
*arg
)
848 * HBA gets first crack
851 status
= aac_dev_ioctl(dev
, cmd
, arg
);
852 if (status
!= -ENOTTY
)
856 case FSACTL_MINIPORT_REV_CHECK
:
857 status
= check_revision(dev
, arg
);
859 case FSACTL_SEND_LARGE_FIB
:
861 status
= ioctl_send_fib(dev
, arg
);
863 case FSACTL_OPEN_GET_ADAPTER_FIB
:
864 status
= open_getadapter_fib(dev
, arg
);
866 case FSACTL_GET_NEXT_ADAPTER_FIB
:
867 status
= next_getadapter_fib(dev
, arg
);
869 case FSACTL_CLOSE_GET_ADAPTER_FIB
:
870 status
= close_getadapter_fib(dev
, arg
);
872 case FSACTL_SEND_RAW_SRB
:
873 status
= aac_send_raw_srb(dev
,arg
);
875 case FSACTL_GET_PCI_INFO
:
876 status
= aac_get_pci_info(dev
,arg
);