1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Adaptec AAC series RAID controller driver
4 * (c) Copyright 2001 Red Hat Inc.
6 * based on the old aacraid driver that is..
7 * Adaptec aacraid device driver for Linux.
9 * Copyright (c) 2000-2010 Adaptec, Inc.
10 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
16 * Abstract: Contains all routines for control of the AFA comm layer
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/spinlock.h>
24 #include <linux/slab.h>
25 #include <linux/completion.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/blkdev.h>
28 #include <linux/delay.h> /* ssleep prototype */
29 #include <linux/kthread.h>
30 #include <linux/uaccess.h>
31 #include <scsi/scsi_host.h>
36 * ioctl_send_fib - send a FIB from userspace
37 * @dev: adapter is being processed
38 * @arg: arguments to the ioctl call
40 * This routine sends a fib to the adapter on behalf of a user level
43 # define AAC_DEBUG_PREAMBLE KERN_INFO
44 # define AAC_DEBUG_POSTAMBLE
46 static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
50 struct hw_fib * hw_fib = (struct hw_fib *)0;
51 dma_addr_t hw_fib_pa = (dma_addr_t)0LL;
52 unsigned int size, osize;
58 fibptr = aac_fib_alloc(dev);
63 kfib = fibptr->hw_fib_va;
65 * First copy in the header so that we can check the size field.
67 if (copy_from_user((void *)kfib, arg, sizeof(struct aac_fibhdr))) {
72 * Since we copy based on the fib header size, make sure that we
73 * will not overrun the buffer when we copy the memory. Return
74 * an error if we would.
76 osize = size = le16_to_cpu(kfib->header.Size) +
77 sizeof(struct aac_fibhdr);
78 if (size < le16_to_cpu(kfib->header.SenderSize))
79 size = le16_to_cpu(kfib->header.SenderSize);
80 if (size > dev->max_fib_size) {
88 kfib = dma_alloc_coherent(&dev->pdev->dev, size, &daddr,
95 /* Highjack the hw_fib */
96 hw_fib = fibptr->hw_fib_va;
97 hw_fib_pa = fibptr->hw_fib_pa;
98 fibptr->hw_fib_va = kfib;
99 fibptr->hw_fib_pa = daddr;
100 memset(((char *)kfib) + dev->max_fib_size, 0, size - dev->max_fib_size);
101 memcpy(kfib, hw_fib, dev->max_fib_size);
104 if (copy_from_user(kfib, arg, size)) {
109 /* Sanity check the second copy */
110 if ((osize != le16_to_cpu(kfib->header.Size) +
111 sizeof(struct aac_fibhdr))
112 || (size < le16_to_cpu(kfib->header.SenderSize))) {
117 if (kfib->header.Command == cpu_to_le16(TakeABreakPt)) {
118 aac_adapter_interrupt(dev);
120 * Since we didn't really send a fib, zero out the state to allow
121 * cleanup code not to assert.
123 kfib->header.XferState = 0;
125 retval = aac_fib_send(le16_to_cpu(kfib->header.Command), fibptr,
126 le16_to_cpu(kfib->header.Size) , FsaNormal,
131 if (aac_fib_complete(fibptr) != 0) {
137 * Make sure that the size returned by the adapter (which includes
138 * the header) is less than or equal to the size of a fib, so we
139 * don't corrupt application data. Then copy that size to the user
140 * buffer. (Don't try to add the header information again, since it
141 * was already included by the adapter.)
145 if (copy_to_user(arg, (void *)kfib, size))
149 dma_free_coherent(&dev->pdev->dev, size, kfib,
151 fibptr->hw_fib_pa = hw_fib_pa;
152 fibptr->hw_fib_va = hw_fib;
154 if (retval != -ERESTARTSYS)
155 aac_fib_free(fibptr);
160 * open_getadapter_fib - Get the next fib
162 * This routine will get the next Fib, if available, from the AdapterFibContext
163 * passed in from the user.
166 static int open_getadapter_fib(struct aac_dev * dev, void __user *arg)
168 struct aac_fib_context * fibctx;
171 fibctx = kmalloc(sizeof(struct aac_fib_context), GFP_KERNEL);
172 if (fibctx == NULL) {
176 struct list_head * entry;
177 struct aac_fib_context * context;
179 fibctx->type = FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT;
180 fibctx->size = sizeof(struct aac_fib_context);
182 * Yes yes, I know this could be an index, but we have a
183 * better guarantee of uniqueness for the locked loop below.
184 * Without the aid of a persistent history, this also helps
185 * reduce the chance that the opaque context would be reused.
187 fibctx->unique = (u32)((ulong)fibctx & 0xFFFFFFFF);
189 * Initialize the mutex used to wait for the next AIF.
191 init_completion(&fibctx->completion);
194 * Initialize the fibs and set the count of fibs on
198 INIT_LIST_HEAD(&fibctx->fib_list);
199 fibctx->jiffies = jiffies/HZ;
201 * Now add this context onto the adapter's
202 * AdapterFibContext list.
204 spin_lock_irqsave(&dev->fib_lock, flags);
205 /* Ensure that we have a unique identifier */
206 entry = dev->fib_list.next;
207 while (entry != &dev->fib_list) {
208 context = list_entry(entry, struct aac_fib_context, next);
209 if (context->unique == fibctx->unique) {
210 /* Not unique (32 bits) */
212 entry = dev->fib_list.next;
217 list_add_tail(&fibctx->next, &dev->fib_list);
218 spin_unlock_irqrestore(&dev->fib_lock, flags);
219 if (copy_to_user(arg, &fibctx->unique,
220 sizeof(fibctx->unique))) {
230 * next_getadapter_fib - get the next fib
231 * @dev: adapter to use
232 * @arg: ioctl argument
234 * This routine will get the next Fib, if available, from the AdapterFibContext
235 * passed in from the user.
238 static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
242 struct aac_fib_context *fibctx;
244 struct list_head * entry;
247 if(copy_from_user((void *)&f, arg, sizeof(struct fib_ioctl)))
250 * Verify that the HANDLE passed in was a valid AdapterFibContext
252 * Search the list of AdapterFibContext addresses on the adapter
253 * to be sure this is a valid address
255 spin_lock_irqsave(&dev->fib_lock, flags);
256 entry = dev->fib_list.next;
259 while (entry != &dev->fib_list) {
260 fibctx = list_entry(entry, struct aac_fib_context, next);
262 * Extract the AdapterFibContext from the Input parameters.
264 if (fibctx->unique == f.fibctx) { /* We found a winner */
271 spin_unlock_irqrestore(&dev->fib_lock, flags);
272 dprintk ((KERN_INFO "Fib Context not found\n"));
276 if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
277 (fibctx->size != sizeof(struct aac_fib_context))) {
278 spin_unlock_irqrestore(&dev->fib_lock, flags);
279 dprintk ((KERN_INFO "Fib Context corrupt?\n"));
284 * If there are no fibs to send back, then either wait or return
288 if (!list_empty(&fibctx->fib_list)) {
290 * Pull the next fib from the fibs
292 entry = fibctx->fib_list.next;
295 fib = list_entry(entry, struct fib, fiblink);
297 spin_unlock_irqrestore(&dev->fib_lock, flags);
298 if (copy_to_user(f.fib, fib->hw_fib_va, sizeof(struct hw_fib))) {
299 kfree(fib->hw_fib_va);
304 * Free the space occupied by this copy of the fib.
306 kfree(fib->hw_fib_va);
310 spin_unlock_irqrestore(&dev->fib_lock, flags);
311 /* If someone killed the AIF aacraid thread, restart it */
312 status = !dev->aif_thread;
313 if (status && !dev->in_reset && dev->queues && dev->fsa_dev) {
314 /* Be paranoid, be very paranoid! */
315 kthread_stop(dev->thread);
318 dev->thread = kthread_run(aac_command_thread, dev,
323 if (wait_for_completion_interruptible(&fibctx->completion) < 0) {
324 status = -ERESTARTSYS;
326 /* Lock again and retry */
327 spin_lock_irqsave(&dev->fib_lock, flags);
334 fibctx->jiffies = jiffies/HZ;
338 int aac_close_fib_context(struct aac_dev * dev, struct aac_fib_context * fibctx)
343 * First free any FIBs that have not been consumed.
345 while (!list_empty(&fibctx->fib_list)) {
346 struct list_head * entry;
348 * Pull the next fib from the fibs
350 entry = fibctx->fib_list.next;
352 fib = list_entry(entry, struct fib, fiblink);
355 * Free the space occupied by this copy of the fib.
357 kfree(fib->hw_fib_va);
361 * Remove the Context from the AdapterFibContext List
363 list_del(&fibctx->next);
369 * Free the space occupied by the Context
376 * close_getadapter_fib - close down user fib context
378 * @arg: ioctl arguments
380 * This routine will close down the fibctx passed in from the user.
383 static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
385 struct aac_fib_context *fibctx;
388 struct list_head * entry;
391 * Verify that the HANDLE passed in was a valid AdapterFibContext
393 * Search the list of AdapterFibContext addresses on the adapter
394 * to be sure this is a valid address
397 entry = dev->fib_list.next;
400 while(entry != &dev->fib_list) {
401 fibctx = list_entry(entry, struct aac_fib_context, next);
403 * Extract the fibctx from the input parameters
405 if (fibctx->unique == (u32)(uintptr_t)arg) /* We found a winner */
412 return 0; /* Already gone */
414 if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
415 (fibctx->size != sizeof(struct aac_fib_context)))
417 spin_lock_irqsave(&dev->fib_lock, flags);
418 status = aac_close_fib_context(dev, fibctx);
419 spin_unlock_irqrestore(&dev->fib_lock, flags);
424 * check_revision - close down user fib context
426 * @arg: ioctl arguments
428 * This routine returns the driver version.
429 * Under Linux, there have been no version incompatibilities, so this is
433 static int check_revision(struct aac_dev *dev, void __user *arg)
435 struct revision response;
436 char *driver_version = aac_driver_version;
440 version = (simple_strtol(driver_version,
441 &driver_version, 10) << 24) | 0x00000400;
442 version += simple_strtol(driver_version + 1, &driver_version, 10) << 16;
443 version += simple_strtol(driver_version + 1, NULL, 10);
444 response.version = cpu_to_le32(version);
445 # ifdef AAC_DRIVER_BUILD
446 response.build = cpu_to_le32(AAC_DRIVER_BUILD);
448 response.build = cpu_to_le32(9999);
451 if (copy_to_user(arg, &response, sizeof(response)))
463 static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
467 struct aac_srb *srbcmd = NULL;
468 struct aac_hba_cmd_req *hbacmd = NULL;
469 struct user_aac_srb *user_srbcmd = NULL;
470 struct user_aac_srb __user *user_srb = arg;
471 struct aac_srb_reply __user *user_reply;
477 void __user *sg_user[HBA_MAX_SG_EMBEDDED];
478 void *sg_list[HBA_MAX_SG_EMBEDDED];
479 u32 sg_count[HBA_MAX_SG_EMBEDDED];
482 u32 actual_fibsize64, actual_fibsize = 0;
484 int is_native_device;
489 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
492 if (!capable(CAP_SYS_ADMIN)){
493 dprintk((KERN_DEBUG"aacraid: No permission to send raw srb\n"));
497 * Allocate and initialize a Fib then setup a SRB command
499 if (!(srbfib = aac_fib_alloc(dev))) {
503 memset(sg_list, 0, sizeof(sg_list)); /* cleanup may take issue */
504 if(copy_from_user(&fibsize, &user_srb->count,sizeof(u32))){
505 dprintk((KERN_DEBUG"aacraid: Could not copy data size from user\n"));
510 if ((fibsize < (sizeof(struct user_aac_srb) - sizeof(struct user_sgentry))) ||
511 (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))) {
516 user_srbcmd = memdup_user(user_srb, fibsize);
517 if (IS_ERR(user_srbcmd)) {
518 rcode = PTR_ERR(user_srbcmd);
523 flags = user_srbcmd->flags; /* from user in cpu order */
524 switch (flags & (SRB_DataIn | SRB_DataOut)) {
526 data_dir = DMA_TO_DEVICE;
528 case (SRB_DataIn | SRB_DataOut):
529 data_dir = DMA_BIDIRECTIONAL;
532 data_dir = DMA_FROM_DEVICE;
537 if (user_srbcmd->sg.count > ARRAY_SIZE(sg_list)) {
538 dprintk((KERN_DEBUG"aacraid: too many sg entries %d\n",
539 user_srbcmd->sg.count));
543 if ((data_dir == DMA_NONE) && user_srbcmd->sg.count) {
544 dprintk((KERN_DEBUG"aacraid:SG with no direction specified\n"));
548 actual_fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
549 ((user_srbcmd->sg.count & 0xff) * sizeof(struct sgentry));
550 actual_fibsize64 = actual_fibsize + (user_srbcmd->sg.count & 0xff) *
551 (sizeof(struct sgentry64) - sizeof(struct sgentry));
552 /* User made a mistake - should not continue */
553 if ((actual_fibsize != fibsize) && (actual_fibsize64 != fibsize)) {
554 dprintk((KERN_DEBUG"aacraid: Bad Size specified in "
555 "Raw SRB command calculated fibsize=%lu;%lu "
556 "user_srbcmd->sg.count=%d aac_srb=%lu sgentry=%lu;%lu "
557 "issued fibsize=%d\n",
558 actual_fibsize, actual_fibsize64, user_srbcmd->sg.count,
559 sizeof(struct aac_srb), sizeof(struct sgentry),
560 sizeof(struct sgentry64), fibsize));
565 chn = user_srbcmd->channel;
566 if (chn < AAC_MAX_BUSES && user_srbcmd->id < AAC_MAX_TARGETS &&
567 dev->hba_map[chn][user_srbcmd->id].devtype ==
568 AAC_DEVTYPE_NATIVE_RAW) {
569 is_native_device = 1;
570 hbacmd = (struct aac_hba_cmd_req *)srbfib->hw_fib_va;
571 memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
573 /* iu_type is a parameter of aac_hba_send */
578 case DMA_FROM_DEVICE:
579 case DMA_BIDIRECTIONAL:
586 hbacmd->lun[1] = cpu_to_le32(user_srbcmd->lun);
587 hbacmd->it_nexus = dev->hba_map[chn][user_srbcmd->id].rmw_nexus;
590 * we fill in reply_qid later in aac_src_deliver_message
591 * we fill in iu_type, request_id later in aac_hba_send
592 * we fill in emb_data_desc_count, data_length later
596 memcpy(hbacmd->cdb, user_srbcmd->cdb, sizeof(hbacmd->cdb));
598 address = (u64)srbfib->hw_error_pa;
599 hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
600 hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
601 hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
602 hbacmd->emb_data_desc_count =
603 cpu_to_le32(user_srbcmd->sg.count);
604 srbfib->hbacmd_size = 64 +
605 user_srbcmd->sg.count * sizeof(struct aac_hba_sgl);
608 is_native_device = 0;
609 aac_fib_init(srbfib);
611 /* raw_srb FIB is not FastResponseCapable */
612 srbfib->hw_fib_va->header.XferState &=
613 ~cpu_to_le32(FastResponseCapable);
615 srbcmd = (struct aac_srb *) fib_data(srbfib);
617 // Fix up srb for endian and force some values
619 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); // Force this
620 srbcmd->channel = cpu_to_le32(user_srbcmd->channel);
621 srbcmd->id = cpu_to_le32(user_srbcmd->id);
622 srbcmd->lun = cpu_to_le32(user_srbcmd->lun);
623 srbcmd->timeout = cpu_to_le32(user_srbcmd->timeout);
624 srbcmd->flags = cpu_to_le32(flags);
625 srbcmd->retry_limit = 0; // Obsolete parameter
626 srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size);
627 memcpy(srbcmd->cdb, user_srbcmd->cdb, sizeof(srbcmd->cdb));
631 if (is_native_device) {
632 struct user_sgmap *usg32 = &user_srbcmd->sg;
633 struct user_sgmap64 *usg64 =
634 (struct user_sgmap64 *)&user_srbcmd->sg;
636 for (i = 0; i < usg32->count; i++) {
640 sg_count[i] = (actual_fibsize64 == fibsize) ?
641 usg64->sg[i].count : usg32->sg[i].count;
643 (dev->scsi_host_ptr->max_sectors << 9)) {
644 pr_err("aacraid: upsg->sg[%d].count=%u>%u\n",
646 dev->scsi_host_ptr->max_sectors << 9);
651 p = kmalloc(sg_count[i], GFP_KERNEL);
657 if (actual_fibsize64 == fibsize) {
658 addr = (u64)usg64->sg[i].addr[0];
659 addr += ((u64)usg64->sg[i].addr[1]) << 32;
661 addr = (u64)usg32->sg[i].addr;
664 sg_user[i] = (void __user *)(uintptr_t)addr;
665 sg_list[i] = p; // save so we can clean up later
668 if (flags & SRB_DataOut) {
669 if (copy_from_user(p, sg_user[i],
675 addr = pci_map_single(dev->pdev, p, sg_count[i],
677 hbacmd->sge[i].addr_hi = cpu_to_le32((u32)(addr>>32));
678 hbacmd->sge[i].addr_lo = cpu_to_le32(
679 (u32)(addr & 0xffffffff));
680 hbacmd->sge[i].len = cpu_to_le32(sg_count[i]);
681 hbacmd->sge[i].flags = 0;
682 byte_count += sg_count[i];
685 if (usg32->count > 0) /* embedded sglist */
686 hbacmd->sge[usg32->count-1].flags =
687 cpu_to_le32(0x40000000);
688 hbacmd->data_length = cpu_to_le32(byte_count);
690 status = aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, srbfib,
693 } else if (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64) {
694 struct user_sgmap64* upsg = (struct user_sgmap64*)&user_srbcmd->sg;
695 struct sgmap64* psg = (struct sgmap64*)&srbcmd->sg;
698 * This should also catch if user used the 32 bit sgmap
700 if (actual_fibsize64 == fibsize) {
701 actual_fibsize = actual_fibsize64;
702 for (i = 0; i < upsg->count; i++) {
706 sg_count[i] = upsg->sg[i].count;
708 ((dev->adapter_info.options &
710 (dev->scsi_host_ptr->max_sectors << 9) :
716 p = kmalloc(sg_count[i], GFP_KERNEL);
718 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
719 sg_count[i], i, upsg->count));
723 addr = (u64)upsg->sg[i].addr[0];
724 addr += ((u64)upsg->sg[i].addr[1]) << 32;
725 sg_user[i] = (void __user *)(uintptr_t)addr;
726 sg_list[i] = p; // save so we can clean up later
729 if (flags & SRB_DataOut) {
730 if (copy_from_user(p, sg_user[i],
732 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
737 addr = pci_map_single(dev->pdev, p,
738 sg_count[i], data_dir);
740 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
741 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
742 byte_count += sg_count[i];
743 psg->sg[i].count = cpu_to_le32(sg_count[i]);
746 struct user_sgmap* usg;
748 actual_fibsize - sizeof(struct aac_srb)
749 + sizeof(struct sgmap), GFP_KERNEL);
751 dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB command\n"));
755 actual_fibsize = actual_fibsize64;
757 for (i = 0; i < usg->count; i++) {
761 sg_count[i] = usg->sg[i].count;
763 ((dev->adapter_info.options &
765 (dev->scsi_host_ptr->max_sectors << 9) :
772 p = kmalloc(sg_count[i], GFP_KERNEL);
774 dprintk((KERN_DEBUG "aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
775 sg_count[i], i, usg->count));
780 sg_user[i] = (void __user *)(uintptr_t)usg->sg[i].addr;
781 sg_list[i] = p; // save so we can clean up later
784 if (flags & SRB_DataOut) {
785 if (copy_from_user(p, sg_user[i],
788 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
793 addr = pci_map_single(dev->pdev, p,
794 sg_count[i], data_dir);
796 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
797 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
798 byte_count += sg_count[i];
799 psg->sg[i].count = cpu_to_le32(sg_count[i]);
803 srbcmd->count = cpu_to_le32(byte_count);
804 if (user_srbcmd->sg.count)
805 psg->count = cpu_to_le32(sg_indx+1);
808 status = aac_fib_send(ScsiPortCommand64, srbfib, actual_fibsize, FsaNormal, 1, 1,NULL,NULL);
810 struct user_sgmap* upsg = &user_srbcmd->sg;
811 struct sgmap* psg = &srbcmd->sg;
813 if (actual_fibsize64 == fibsize) {
814 struct user_sgmap64* usg = (struct user_sgmap64 *)upsg;
815 for (i = 0; i < upsg->count; i++) {
819 sg_count[i] = usg->sg[i].count;
821 ((dev->adapter_info.options &
823 (dev->scsi_host_ptr->max_sectors << 9) :
828 p = kmalloc(sg_count[i], GFP_KERNEL);
830 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
831 sg_count[i], i, usg->count));
835 addr = (u64)usg->sg[i].addr[0];
836 addr += ((u64)usg->sg[i].addr[1]) << 32;
837 sg_user[i] = (void __user *)addr;
838 sg_list[i] = p; // save so we can clean up later
841 if (flags & SRB_DataOut) {
842 if (copy_from_user(p, sg_user[i],
844 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
849 addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
851 psg->sg[i].addr = cpu_to_le32(addr & 0xffffffff);
852 byte_count += usg->sg[i].count;
853 psg->sg[i].count = cpu_to_le32(sg_count[i]);
856 for (i = 0; i < upsg->count; i++) {
860 sg_count[i] = upsg->sg[i].count;
862 ((dev->adapter_info.options &
864 (dev->scsi_host_ptr->max_sectors << 9) :
869 p = kmalloc(sg_count[i], GFP_KERNEL);
871 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
872 sg_count[i], i, upsg->count));
876 sg_user[i] = (void __user *)(uintptr_t)upsg->sg[i].addr;
877 sg_list[i] = p; // save so we can clean up later
880 if (flags & SRB_DataOut) {
881 if (copy_from_user(p, sg_user[i],
883 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
888 addr = pci_map_single(dev->pdev, p,
889 sg_count[i], data_dir);
891 psg->sg[i].addr = cpu_to_le32(addr);
892 byte_count += sg_count[i];
893 psg->sg[i].count = cpu_to_le32(sg_count[i]);
896 srbcmd->count = cpu_to_le32(byte_count);
897 if (user_srbcmd->sg.count)
898 psg->count = cpu_to_le32(sg_indx+1);
901 status = aac_fib_send(ScsiPortCommand, srbfib, actual_fibsize, FsaNormal, 1, 1, NULL, NULL);
904 if (status == -ERESTARTSYS) {
905 rcode = -ERESTARTSYS;
910 dprintk((KERN_DEBUG"aacraid: Could not send raw srb fib to hba\n"));
915 if (flags & SRB_DataIn) {
916 for(i = 0 ; i <= sg_indx; i++){
917 if (copy_to_user(sg_user[i], sg_list[i], sg_count[i])) {
918 dprintk((KERN_DEBUG"aacraid: Could not copy sg data to user\n"));
926 user_reply = arg + fibsize;
927 if (is_native_device) {
928 struct aac_hba_resp *err =
929 &((struct aac_native_hba *)srbfib->hw_fib_va)->resp.err;
930 struct aac_srb_reply reply;
932 memset(&reply, 0, sizeof(reply));
933 reply.status = ST_OK;
934 if (srbfib->flags & FIB_CONTEXT_FLAG_FASTRESP) {
936 reply.srb_status = SRB_STATUS_SUCCESS;
937 reply.scsi_status = 0;
938 reply.data_xfer_length = byte_count;
939 reply.sense_data_size = 0;
940 memset(reply.sense_data, 0, AAC_SENSE_BUFFERSIZE);
942 reply.srb_status = err->service_response;
943 reply.scsi_status = err->status;
944 reply.data_xfer_length = byte_count -
945 le32_to_cpu(err->residual_count);
946 reply.sense_data_size = err->sense_response_data_len;
947 memcpy(reply.sense_data, err->sense_response_buf,
948 AAC_SENSE_BUFFERSIZE);
950 if (copy_to_user(user_reply, &reply,
951 sizeof(struct aac_srb_reply))) {
952 dprintk((KERN_DEBUG"aacraid: Copy to user failed\n"));
957 struct aac_srb_reply *reply;
959 reply = (struct aac_srb_reply *) fib_data(srbfib);
960 if (copy_to_user(user_reply, reply,
961 sizeof(struct aac_srb_reply))) {
962 dprintk((KERN_DEBUG"aacraid: Copy to user failed\n"));
970 if (rcode != -ERESTARTSYS) {
971 for (i = 0; i <= sg_indx; i++)
973 aac_fib_complete(srbfib);
974 aac_fib_free(srbfib);
980 struct aac_pci_info {
986 static int aac_get_pci_info(struct aac_dev* dev, void __user *arg)
988 struct aac_pci_info pci_info;
990 pci_info.bus = dev->pdev->bus->number;
991 pci_info.slot = PCI_SLOT(dev->pdev->devfn);
993 if (copy_to_user(arg, &pci_info, sizeof(struct aac_pci_info))) {
994 dprintk((KERN_DEBUG "aacraid: Could not copy pci info\n"));
1000 static int aac_get_hba_info(struct aac_dev *dev, void __user *arg)
1002 struct aac_hba_info hbainfo;
1004 memset(&hbainfo, 0, sizeof(hbainfo));
1005 hbainfo.adapter_number = (u8) dev->id;
1006 hbainfo.system_io_bus_number = dev->pdev->bus->number;
1007 hbainfo.device_number = (dev->pdev->devfn >> 3);
1008 hbainfo.function_number = (dev->pdev->devfn & 0x0007);
1010 hbainfo.vendor_id = dev->pdev->vendor;
1011 hbainfo.device_id = dev->pdev->device;
1012 hbainfo.sub_vendor_id = dev->pdev->subsystem_vendor;
1013 hbainfo.sub_system_id = dev->pdev->subsystem_device;
1015 if (copy_to_user(arg, &hbainfo, sizeof(struct aac_hba_info))) {
1016 dprintk((KERN_DEBUG "aacraid: Could not copy hba info\n"));
1023 struct aac_reset_iop {
1027 static int aac_send_reset_adapter(struct aac_dev *dev, void __user *arg)
1029 struct aac_reset_iop reset;
1032 if (copy_from_user((void *)&reset, arg, sizeof(struct aac_reset_iop)))
1035 dev->adapter_shutdown = 1;
1037 mutex_unlock(&dev->ioctl_mutex);
1038 retval = aac_reset_adapter(dev, 0, reset.reset_type);
1039 mutex_lock(&dev->ioctl_mutex);
1044 int aac_do_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg)
1048 mutex_lock(&dev->ioctl_mutex);
1050 if (dev->adapter_shutdown) {
1056 * HBA gets first crack
1059 status = aac_dev_ioctl(dev, cmd, arg);
1060 if (status != -ENOTTY)
1064 case FSACTL_MINIPORT_REV_CHECK:
1065 status = check_revision(dev, arg);
1067 case FSACTL_SEND_LARGE_FIB:
1068 case FSACTL_SENDFIB:
1069 status = ioctl_send_fib(dev, arg);
1071 case FSACTL_OPEN_GET_ADAPTER_FIB:
1072 status = open_getadapter_fib(dev, arg);
1074 case FSACTL_GET_NEXT_ADAPTER_FIB:
1075 status = next_getadapter_fib(dev, arg);
1077 case FSACTL_CLOSE_GET_ADAPTER_FIB:
1078 status = close_getadapter_fib(dev, arg);
1080 case FSACTL_SEND_RAW_SRB:
1081 status = aac_send_raw_srb(dev,arg);
1083 case FSACTL_GET_PCI_INFO:
1084 status = aac_get_pci_info(dev,arg);
1086 case FSACTL_GET_HBA_INFO:
1087 status = aac_get_hba_info(dev, arg);
1089 case FSACTL_RESET_IOP:
1090 status = aac_send_reset_adapter(dev, arg);
1099 mutex_unlock(&dev->ioctl_mutex);