blob: 1a5bf5724750e95c269a2222ef9dc68539d5f0ee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00003 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mark Haverkampf2b1a062007-03-15 10:27:32 -07008 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * Module Name:
25 * commctrl.c
26 *
27 * Abstract: Contains all routines for control of the AFA comm layer
28 *
29 */
30
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/pci.h>
35#include <linux/spinlock.h>
36#include <linux/slab.h>
37#include <linux/completion.h>
38#include <linux/dma-mapping.h>
39#include <linux/blkdev.h>
Mark Haverkampc8f7b072006-08-03 08:02:24 -070040#include <linux/delay.h> /* ssleep prototype */
Mark Haverkampdc4adbf2006-03-27 09:44:26 -080041#include <linux/kthread.h>
Matthew Wilcox6188e102008-04-18 22:21:05 -040042#include <linux/semaphore.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/uaccess.h>
Mark Salyzyn09050712008-05-28 15:32:55 -040044#include <scsi/scsi_host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46#include "aacraid.h"
47
48/**
49 * ioctl_send_fib - send a FIB from userspace
50 * @dev: adapter is being processed
51 * @arg: arguments to the ioctl call
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080052 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * This routine sends a fib to the adapter on behalf of a user level
54 * program.
55 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070056# define AAC_DEBUG_PREAMBLE KERN_INFO
57# define AAC_DEBUG_POSTAMBLE
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
60{
61 struct hw_fib * kfib;
62 struct fib *fibptr;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070063 struct hw_fib * hw_fib = (struct hw_fib *)0;
64 dma_addr_t hw_fib_pa = (dma_addr_t)0LL;
65 unsigned size;
66 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Mark Haverkamp33bb3b22007-03-15 10:27:21 -070068 if (dev->in_reset) {
69 return -EBUSY;
70 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -080071 fibptr = aac_fib_alloc(dev);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070072 if(fibptr == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return -ENOMEM;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070074 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080075
Mark Haverkampa8166a52007-03-15 10:26:22 -070076 kfib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /*
78 * First copy in the header so that we can check the size field.
79 */
80 if (copy_from_user((void *)kfib, arg, sizeof(struct aac_fibhdr))) {
Mark Haverkampbfb35aa82006-02-01 09:30:55 -080081 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return -EFAULT;
83 }
84 /*
85 * Since we copy based on the fib header size, make sure that we
86 * will not overrun the buffer when we copy the memory. Return
87 * an error if we would.
88 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070089 size = le16_to_cpu(kfib->header.Size) + sizeof(struct aac_fibhdr);
90 if (size < le16_to_cpu(kfib->header.SenderSize))
91 size = le16_to_cpu(kfib->header.SenderSize);
92 if (size > dev->max_fib_size) {
FUJITA Tomonorie9899112008-10-23 17:36:08 +090093 dma_addr_t daddr;
94
Mark Haverkamp6e289a92006-01-11 09:28:07 -080095 if (size > 2048) {
96 retval = -EINVAL;
97 goto cleanup;
98 }
FUJITA Tomonorie9899112008-10-23 17:36:08 +090099
100 kfib = pci_alloc_consistent(dev->pdev, size, &daddr);
101 if (!kfib) {
102 retval = -ENOMEM;
103 goto cleanup;
104 }
105
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700106 /* Highjack the hw_fib */
Mark Haverkampa8166a52007-03-15 10:26:22 -0700107 hw_fib = fibptr->hw_fib_va;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700108 hw_fib_pa = fibptr->hw_fib_pa;
FUJITA Tomonorie9899112008-10-23 17:36:08 +0900109 fibptr->hw_fib_va = kfib;
110 fibptr->hw_fib_pa = daddr;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700111 memset(((char *)kfib) + dev->max_fib_size, 0, size - dev->max_fib_size);
112 memcpy(kfib, hw_fib, dev->max_fib_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700115 if (copy_from_user(kfib, arg, size)) {
116 retval = -EFAULT;
117 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700120 if (kfib->header.Command == cpu_to_le16(TakeABreakPt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 aac_adapter_interrupt(dev);
122 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800123 * Since we didn't really send a fib, zero out the state to allow
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 * cleanup code not to assert.
125 */
126 kfib->header.XferState = 0;
127 } else {
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800128 retval = aac_fib_send(le16_to_cpu(kfib->header.Command), fibptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 le16_to_cpu(kfib->header.Size) , FsaNormal,
130 1, 1, NULL, NULL);
131 if (retval) {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700132 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800134 if (aac_fib_complete(fibptr) != 0) {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700135 retval = -EINVAL;
136 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138 }
139 /*
140 * Make sure that the size returned by the adapter (which includes
141 * the header) is less than or equal to the size of a fib, so we
142 * don't corrupt application data. Then copy that size to the user
143 * buffer. (Don't try to add the header information again, since it
144 * was already included by the adapter.)
145 */
146
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700147 retval = 0;
148 if (copy_to_user(arg, (void *)kfib, size))
149 retval = -EFAULT;
150cleanup:
151 if (hw_fib) {
152 pci_free_consistent(dev->pdev, size, kfib, fibptr->hw_fib_pa);
153 fibptr->hw_fib_pa = hw_fib_pa;
Mark Haverkampa8166a52007-03-15 10:26:22 -0700154 fibptr->hw_fib_va = hw_fib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530156 if (retval != -ERESTARTSYS)
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700157 aac_fib_free(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700158 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161/**
162 * open_getadapter_fib - Get the next fib
163 *
164 * This routine will get the next Fib, if available, from the AdapterFibContext
165 * passed in from the user.
166 */
167
168static int open_getadapter_fib(struct aac_dev * dev, void __user *arg)
169{
170 struct aac_fib_context * fibctx;
171 int status;
172
173 fibctx = kmalloc(sizeof(struct aac_fib_context), GFP_KERNEL);
174 if (fibctx == NULL) {
175 status = -ENOMEM;
176 } else {
177 unsigned long flags;
178 struct list_head * entry;
179 struct aac_fib_context * context;
180
181 fibctx->type = FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT;
182 fibctx->size = sizeof(struct aac_fib_context);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800183 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 * Yes yes, I know this could be an index, but we have a
185 * better guarantee of uniqueness for the locked loop below.
186 * Without the aid of a persistent history, this also helps
187 * reduce the chance that the opaque context would be reused.
188 */
189 fibctx->unique = (u32)((ulong)fibctx & 0xFFFFFFFF);
190 /*
191 * Initialize the mutex used to wait for the next AIF.
192 */
193 init_MUTEX_LOCKED(&fibctx->wait_sem);
194 fibctx->wait = 0;
195 /*
196 * Initialize the fibs and set the count of fibs on
197 * the list to 0.
198 */
199 fibctx->count = 0;
200 INIT_LIST_HEAD(&fibctx->fib_list);
201 fibctx->jiffies = jiffies/HZ;
202 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800203 * Now add this context onto the adapter's
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 * AdapterFibContext list.
205 */
206 spin_lock_irqsave(&dev->fib_lock, flags);
207 /* Ensure that we have a unique identifier */
208 entry = dev->fib_list.next;
209 while (entry != &dev->fib_list) {
210 context = list_entry(entry, struct aac_fib_context, next);
211 if (context->unique == fibctx->unique) {
212 /* Not unique (32 bits) */
213 fibctx->unique++;
214 entry = dev->fib_list.next;
215 } else {
216 entry = entry->next;
217 }
218 }
219 list_add_tail(&fibctx->next, &dev->fib_list);
220 spin_unlock_irqrestore(&dev->fib_lock, flags);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800221 if (copy_to_user(arg, &fibctx->unique,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 sizeof(fibctx->unique))) {
223 status = -EFAULT;
224 } else {
225 status = 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228 return status;
229}
230
231/**
232 * next_getadapter_fib - get the next fib
233 * @dev: adapter to use
234 * @arg: ioctl argument
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800235 *
236 * This routine will get the next Fib, if available, from the AdapterFibContext
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 * passed in from the user.
238 */
239
240static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
241{
242 struct fib_ioctl f;
243 struct fib *fib;
244 struct aac_fib_context *fibctx;
245 int status;
246 struct list_head * entry;
247 unsigned long flags;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if(copy_from_user((void *)&f, arg, sizeof(struct fib_ioctl)))
250 return -EFAULT;
251 /*
252 * Verify that the HANDLE passed in was a valid AdapterFibContext
253 *
254 * Search the list of AdapterFibContext addresses on the adapter
255 * to be sure this is a valid address
256 */
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800257 spin_lock_irqsave(&dev->fib_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 entry = dev->fib_list.next;
259 fibctx = NULL;
260
261 while (entry != &dev->fib_list) {
262 fibctx = list_entry(entry, struct aac_fib_context, next);
263 /*
264 * Extract the AdapterFibContext from the Input parameters.
265 */
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800266 if (fibctx->unique == f.fibctx) { /* We found a winner */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 break;
268 }
269 entry = entry->next;
270 fibctx = NULL;
271 }
272 if (!fibctx) {
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800273 spin_unlock_irqrestore(&dev->fib_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 dprintk ((KERN_INFO "Fib Context not found\n"));
275 return -EINVAL;
276 }
277
278 if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
279 (fibctx->size != sizeof(struct aac_fib_context))) {
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800280 spin_unlock_irqrestore(&dev->fib_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 dprintk ((KERN_INFO "Fib Context corrupt?\n"));
282 return -EINVAL;
283 }
284 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 /*
286 * If there are no fibs to send back, then either wait or return
287 * -EAGAIN
288 */
289return_fib:
290 if (!list_empty(&fibctx->fib_list)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /*
292 * Pull the next fib from the fibs
293 */
294 entry = fibctx->fib_list.next;
295 list_del(entry);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 fib = list_entry(entry, struct fib, fiblink);
298 fibctx->count--;
299 spin_unlock_irqrestore(&dev->fib_lock, flags);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700300 if (copy_to_user(f.fib, fib->hw_fib_va, sizeof(struct hw_fib))) {
301 kfree(fib->hw_fib_va);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 kfree(fib);
303 return -EFAULT;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /*
306 * Free the space occupied by this copy of the fib.
307 */
Mark Haverkampa8166a52007-03-15 10:26:22 -0700308 kfree(fib->hw_fib_va);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 kfree(fib);
310 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 } else {
312 spin_unlock_irqrestore(&dev->fib_lock, flags);
Mark Haverkampdc4adbf2006-03-27 09:44:26 -0800313 /* If someone killed the AIF aacraid thread, restart it */
314 status = !dev->aif_thread;
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700315 if (status && !dev->in_reset && dev->queues && dev->fsa_dev) {
Mark Haverkampdc4adbf2006-03-27 09:44:26 -0800316 /* Be paranoid, be very paranoid! */
317 kthread_stop(dev->thread);
318 ssleep(1);
319 dev->aif_thread = 0;
320 dev->thread = kthread_run(aac_command_thread, dev, dev->name);
321 ssleep(1);
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (f.wait) {
324 if(down_interruptible(&fibctx->wait_sem) < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530325 status = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 } else {
327 /* Lock again and retry */
328 spin_lock_irqsave(&dev->fib_lock, flags);
329 goto return_fib;
330 }
331 } else {
332 status = -EAGAIN;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 }
Mark Haverkamp12a26d02005-08-03 15:39:25 -0700335 fibctx->jiffies = jiffies/HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return status;
337}
338
339int aac_close_fib_context(struct aac_dev * dev, struct aac_fib_context * fibctx)
340{
341 struct fib *fib;
342
343 /*
344 * First free any FIBs that have not been consumed.
345 */
346 while (!list_empty(&fibctx->fib_list)) {
347 struct list_head * entry;
348 /*
349 * Pull the next fib from the fibs
350 */
351 entry = fibctx->fib_list.next;
352 list_del(entry);
353 fib = list_entry(entry, struct fib, fiblink);
354 fibctx->count--;
355 /*
356 * Free the space occupied by this copy of the fib.
357 */
Mark Haverkampa8166a52007-03-15 10:26:22 -0700358 kfree(fib->hw_fib_va);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 kfree(fib);
360 }
361 /*
362 * Remove the Context from the AdapterFibContext List
363 */
364 list_del(&fibctx->next);
365 /*
366 * Invalidate context
367 */
368 fibctx->type = 0;
369 /*
370 * Free the space occupied by the Context
371 */
372 kfree(fibctx);
373 return 0;
374}
375
376/**
377 * close_getadapter_fib - close down user fib context
378 * @dev: adapter
379 * @arg: ioctl arguments
380 *
381 * This routine will close down the fibctx passed in from the user.
382 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
385{
386 struct aac_fib_context *fibctx;
387 int status;
388 unsigned long flags;
389 struct list_head * entry;
390
391 /*
392 * Verify that the HANDLE passed in was a valid AdapterFibContext
393 *
394 * Search the list of AdapterFibContext addresses on the adapter
395 * to be sure this is a valid address
396 */
397
398 entry = dev->fib_list.next;
399 fibctx = NULL;
400
401 while(entry != &dev->fib_list) {
402 fibctx = list_entry(entry, struct aac_fib_context, next);
403 /*
404 * Extract the fibctx from the input parameters
405 */
Al Viro142956a2007-10-29 05:11:28 +0000406 if (fibctx->unique == (u32)(uintptr_t)arg) /* We found a winner */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 entry = entry->next;
409 fibctx = NULL;
410 }
411
412 if (!fibctx)
413 return 0; /* Already gone */
414
415 if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
416 (fibctx->size != sizeof(struct aac_fib_context)))
417 return -EINVAL;
418 spin_lock_irqsave(&dev->fib_lock, flags);
419 status = aac_close_fib_context(dev, fibctx);
420 spin_unlock_irqrestore(&dev->fib_lock, flags);
421 return status;
422}
423
424/**
425 * check_revision - close down user fib context
426 * @dev: adapter
427 * @arg: ioctl arguments
428 *
429 * This routine returns the driver version.
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800430 * Under Linux, there have been no version incompatibilities, so this is
431 * simple!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 */
433
434static int check_revision(struct aac_dev *dev, void __user *arg)
435{
436 struct revision response;
Mark Haverkampc7f47602005-08-03 15:38:55 -0700437 char *driver_version = aac_driver_version;
438 u32 version;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Mark Haverkamp9f30a322005-10-24 10:52:02 -0700440 response.compat = 1;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800441 version = (simple_strtol(driver_version,
Mark Haverkampc7f47602005-08-03 15:38:55 -0700442 &driver_version, 10) << 24) | 0x00000400;
443 version += simple_strtol(driver_version + 1, &driver_version, 10) << 16;
444 version += simple_strtol(driver_version + 1, NULL, 10);
445 response.version = cpu_to_le32(version);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800446# ifdef AAC_DRIVER_BUILD
Mark Haverkampc7f47602005-08-03 15:38:55 -0700447 response.build = cpu_to_le32(AAC_DRIVER_BUILD);
448# else
449 response.build = cpu_to_le32(9999);
450# endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 if (copy_to_user(arg, &response, sizeof(response)))
453 return -EFAULT;
454 return 0;
455}
456
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458/**
459 *
460 * aac_send_raw_scb
461 *
462 */
463
Adrian Bunk 48338692005-04-25 19:45:58 -0700464static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
466 struct fib* srbfib;
467 int status;
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700468 struct aac_srb *srbcmd = NULL;
469 struct user_aac_srb *user_srbcmd = NULL;
470 struct user_aac_srb __user *user_srb = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 struct aac_srb_reply __user *user_reply;
472 struct aac_srb_reply* reply;
473 u32 fibsize = 0;
474 u32 flags = 0;
475 s32 rcode = 0;
476 u32 data_dir;
477 void __user *sg_user[32];
478 void *sg_list[32];
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800479 u32 sg_indx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 u32 byte_count = 0;
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700481 u32 actual_fibsize64, actual_fibsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 int i;
483
484
Mark Haverkamp33bb3b22007-03-15 10:27:21 -0700485 if (dev->in_reset) {
486 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
487 return -EBUSY;
488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (!capable(CAP_SYS_ADMIN)){
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800490 dprintk((KERN_DEBUG"aacraid: No permission to send raw srb\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 return -EPERM;
492 }
493 /*
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700494 * Allocate and initialize a Fib then setup a SRB command
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800496 if (!(srbfib = aac_fib_alloc(dev))) {
Mark Haverkamp5d497ce2005-06-17 13:38:04 -0700497 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800499 aac_fib_init(srbfib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 srbcmd = (struct aac_srb*) fib_data(srbfib);
502
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700503 memset(sg_list, 0, sizeof(sg_list)); /* cleanup may take issue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if(copy_from_user(&fibsize, &user_srb->count,sizeof(u32))){
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800505 dprintk((KERN_DEBUG"aacraid: Could not copy data size from user\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 rcode = -EFAULT;
507 goto cleanup;
508 }
509
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700510 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 rcode = -EINVAL;
512 goto cleanup;
513 }
514
Dave Jones4645df12005-07-12 13:58:08 -0700515 user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700516 if (!user_srbcmd) {
517 dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
518 rcode = -ENOMEM;
519 goto cleanup;
520 }
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700521 if(copy_from_user(user_srbcmd, user_srb,fibsize)){
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800522 dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 rcode = -EFAULT;
524 goto cleanup;
525 }
526
527 user_reply = arg+fibsize;
528
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700529 flags = user_srbcmd->flags; /* from user in cpu order */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 // Fix up srb for endian and force some values
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); // Force this
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800533 srbcmd->channel = cpu_to_le32(user_srbcmd->channel);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700534 srbcmd->id = cpu_to_le32(user_srbcmd->id);
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800535 srbcmd->lun = cpu_to_le32(user_srbcmd->lun);
536 srbcmd->timeout = cpu_to_le32(user_srbcmd->timeout);
537 srbcmd->flags = cpu_to_le32(flags);
Mark Haverkamp5d497ce2005-06-17 13:38:04 -0700538 srbcmd->retry_limit = 0; // Obsolete parameter
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700539 srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size);
Mark Haverkamp5d497ce2005-06-17 13:38:04 -0700540 memcpy(srbcmd->cdb, user_srbcmd->cdb, sizeof(srbcmd->cdb));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800541
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700542 switch (flags & (SRB_DataIn | SRB_DataOut)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 case SRB_DataOut:
544 data_dir = DMA_TO_DEVICE;
545 break;
546 case (SRB_DataIn | SRB_DataOut):
547 data_dir = DMA_BIDIRECTIONAL;
548 break;
549 case SRB_DataIn:
550 data_dir = DMA_FROM_DEVICE;
551 break;
552 default:
553 data_dir = DMA_NONE;
554 }
Tobias Klauser6391a112006-06-08 22:23:48 -0700555 if (user_srbcmd->sg.count > ARRAY_SIZE(sg_list)) {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700556 dprintk((KERN_DEBUG"aacraid: too many sg entries %d\n",
557 le32_to_cpu(srbcmd->sg.count)));
558 rcode = -EINVAL;
559 goto cleanup;
560 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700561 actual_fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
562 ((user_srbcmd->sg.count & 0xff) * sizeof(struct sgentry));
563 actual_fibsize64 = actual_fibsize + (user_srbcmd->sg.count & 0xff) *
564 (sizeof(struct sgentry64) - sizeof(struct sgentry));
565 /* User made a mistake - should not continue */
566 if ((actual_fibsize != fibsize) && (actual_fibsize64 != fibsize)) {
567 dprintk((KERN_DEBUG"aacraid: Bad Size specified in "
568 "Raw SRB command calculated fibsize=%lu;%lu "
569 "user_srbcmd->sg.count=%d aac_srb=%lu sgentry=%lu;%lu "
570 "issued fibsize=%d\n",
571 actual_fibsize, actual_fibsize64, user_srbcmd->sg.count,
572 sizeof(struct aac_srb), sizeof(struct sgentry),
573 sizeof(struct sgentry64), fibsize));
574 rcode = -EINVAL;
575 goto cleanup;
576 }
577 if ((data_dir == DMA_NONE) && user_srbcmd->sg.count) {
578 dprintk((KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n"));
579 rcode = -EINVAL;
580 goto cleanup;
581 }
582 byte_count = 0;
583 if (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64) {
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700584 struct user_sgmap64* upsg = (struct user_sgmap64*)&user_srbcmd->sg;
Mark Haverkamp84e29302005-07-07 13:40:00 -0700585 struct sgmap64* psg = (struct sgmap64*)&srbcmd->sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 /*
588 * This should also catch if user used the 32 bit sgmap
589 */
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700590 if (actual_fibsize64 == fibsize) {
591 actual_fibsize = actual_fibsize64;
592 for (i = 0; i < upsg->count; i++) {
593 u64 addr;
594 void* p;
Mark Salyzyn09050712008-05-28 15:32:55 -0400595 if (upsg->sg[i].count >
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530596 ((dev->adapter_info.options &
Mark Salyzyn09050712008-05-28 15:32:55 -0400597 AAC_OPT_NEW_COMM) ?
598 (dev->scsi_host_ptr->max_sectors << 9) :
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530599 65536)) {
Mark Salyzyn09050712008-05-28 15:32:55 -0400600 rcode = -EINVAL;
601 goto cleanup;
602 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700603 /* Does this really need to be GFP_DMA? */
604 p = kmalloc(upsg->sg[i].count,GFP_KERNEL|__GFP_DMA);
Salyzyn, Mark6dcd4a72008-01-08 13:08:04 -0800605 if(!p) {
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700606 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
607 upsg->sg[i].count,i,upsg->count));
608 rcode = -ENOMEM;
609 goto cleanup;
610 }
611 addr = (u64)upsg->sg[i].addr[0];
612 addr += ((u64)upsg->sg[i].addr[1]) << 32;
Al Viro142956a2007-10-29 05:11:28 +0000613 sg_user[i] = (void __user *)(uintptr_t)addr;
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700614 sg_list[i] = p; // save so we can clean up later
615 sg_indx = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800617 if (flags & SRB_DataOut) {
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700618 if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
619 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
620 rcode = -EFAULT;
621 goto cleanup;
622 }
623 }
624 addr = pci_map_single(dev->pdev, p, upsg->sg[i].count, data_dir);
625
626 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
627 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
628 byte_count += upsg->sg[i].count;
629 psg->sg[i].count = cpu_to_le32(upsg->sg[i].count);
630 }
631 } else {
632 struct user_sgmap* usg;
633 usg = kmalloc(actual_fibsize - sizeof(struct aac_srb)
634 + sizeof(struct sgmap), GFP_KERNEL);
635 if (!usg) {
636 dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB command\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 rcode = -ENOMEM;
638 goto cleanup;
639 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700640 memcpy (usg, upsg, actual_fibsize - sizeof(struct aac_srb)
641 + sizeof(struct sgmap));
642 actual_fibsize = actual_fibsize64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700644 for (i = 0; i < usg->count; i++) {
645 u64 addr;
646 void* p;
Mark Salyzyn09050712008-05-28 15:32:55 -0400647 if (usg->sg[i].count >
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530648 ((dev->adapter_info.options &
Mark Salyzyn09050712008-05-28 15:32:55 -0400649 AAC_OPT_NEW_COMM) ?
650 (dev->scsi_host_ptr->max_sectors << 9) :
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530651 65536)) {
Mark Salyzyn09050712008-05-28 15:32:55 -0400652 rcode = -EINVAL;
653 goto cleanup;
654 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700655 /* Does this really need to be GFP_DMA? */
656 p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
Salyzyn, Mark6dcd4a72008-01-08 13:08:04 -0800657 if(!p) {
Julia Lawall8a52da62010-05-15 11:46:12 +0200658 dprintk((KERN_DEBUG "aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700659 usg->sg[i].count,i,usg->count));
Julia Lawall8a52da62010-05-15 11:46:12 +0200660 kfree(usg);
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700661 rcode = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 goto cleanup;
663 }
Al Viro142956a2007-10-29 05:11:28 +0000664 sg_user[i] = (void __user *)(uintptr_t)usg->sg[i].addr;
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700665 sg_list[i] = p; // save so we can clean up later
666 sg_indx = i;
667
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800668 if (flags & SRB_DataOut) {
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700669 if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
670 kfree (usg);
671 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
672 rcode = -EFAULT;
673 goto cleanup;
674 }
675 }
676 addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
677
678 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
679 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
680 byte_count += usg->sg[i].count;
681 psg->sg[i].count = cpu_to_le32(usg->sg[i].count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700683 kfree (usg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 srbcmd->count = cpu_to_le32(byte_count);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700686 psg->count = cpu_to_le32(sg_indx+1);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800687 status = aac_fib_send(ScsiPortCommand64, srbfib, actual_fibsize, FsaNormal, 1, 1,NULL,NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 } else {
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700689 struct user_sgmap* upsg = &user_srbcmd->sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 struct sgmap* psg = &srbcmd->sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700692 if (actual_fibsize64 == fibsize) {
693 struct user_sgmap64* usg = (struct user_sgmap64 *)upsg;
694 for (i = 0; i < upsg->count; i++) {
Al Viro142956a2007-10-29 05:11:28 +0000695 uintptr_t addr;
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700696 void* p;
Mark Salyzyn09050712008-05-28 15:32:55 -0400697 if (usg->sg[i].count >
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530698 ((dev->adapter_info.options &
Mark Salyzyn09050712008-05-28 15:32:55 -0400699 AAC_OPT_NEW_COMM) ?
700 (dev->scsi_host_ptr->max_sectors << 9) :
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530701 65536)) {
Mark Salyzyn09050712008-05-28 15:32:55 -0400702 rcode = -EINVAL;
703 goto cleanup;
704 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700705 /* Does this really need to be GFP_DMA? */
706 p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
Salyzyn, Mark6dcd4a72008-01-08 13:08:04 -0800707 if(!p) {
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700708 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
709 usg->sg[i].count,i,usg->count));
710 rcode = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 goto cleanup;
712 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700713 addr = (u64)usg->sg[i].addr[0];
714 addr += ((u64)usg->sg[i].addr[1]) << 32;
Al Viro142956a2007-10-29 05:11:28 +0000715 sg_user[i] = (void __user *)addr;
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700716 sg_list[i] = p; // save so we can clean up later
717 sg_indx = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800719 if (flags & SRB_DataOut) {
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700720 if(copy_from_user(p,sg_user[i],usg->sg[i].count)){
721 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
722 rcode = -EFAULT;
723 goto cleanup;
724 }
725 }
726 addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
727
728 psg->sg[i].addr = cpu_to_le32(addr & 0xffffffff);
729 byte_count += usg->sg[i].count;
730 psg->sg[i].count = cpu_to_le32(usg->sg[i].count);
731 }
732 } else {
733 for (i = 0; i < upsg->count; i++) {
734 dma_addr_t addr;
735 void* p;
Mark Salyzyn09050712008-05-28 15:32:55 -0400736 if (upsg->sg[i].count >
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530737 ((dev->adapter_info.options &
Mark Salyzyn09050712008-05-28 15:32:55 -0400738 AAC_OPT_NEW_COMM) ?
739 (dev->scsi_host_ptr->max_sectors << 9) :
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530740 65536)) {
Mark Salyzyn09050712008-05-28 15:32:55 -0400741 rcode = -EINVAL;
742 goto cleanup;
743 }
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700744 p = kmalloc(upsg->sg[i].count, GFP_KERNEL);
Salyzyn, Mark6dcd4a72008-01-08 13:08:04 -0800745 if (!p) {
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700746 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
747 upsg->sg[i].count, i, upsg->count));
748 rcode = -ENOMEM;
749 goto cleanup;
750 }
Al Viro142956a2007-10-29 05:11:28 +0000751 sg_user[i] = (void __user *)(uintptr_t)upsg->sg[i].addr;
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700752 sg_list[i] = p; // save so we can clean up later
753 sg_indx = i;
754
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800755 if (flags & SRB_DataOut) {
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700756 if(copy_from_user(p, sg_user[i],
757 upsg->sg[i].count)) {
758 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
759 rcode = -EFAULT;
760 goto cleanup;
761 }
762 }
763 addr = pci_map_single(dev->pdev, p,
764 upsg->sg[i].count, data_dir);
765
766 psg->sg[i].addr = cpu_to_le32(addr);
767 byte_count += upsg->sg[i].count;
768 psg->sg[i].count = cpu_to_le32(upsg->sg[i].count);
769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
771 srbcmd->count = cpu_to_le32(byte_count);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700772 psg->count = cpu_to_le32(sg_indx+1);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800773 status = aac_fib_send(ScsiPortCommand, srbfib, actual_fibsize, FsaNormal, 1, 1, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530775 if (status == -ERESTARTSYS) {
776 rcode = -ERESTARTSYS;
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700777 goto cleanup;
778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 if (status != 0){
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800781 dprintk((KERN_DEBUG"aacraid: Could not send raw srb fib to hba\n"));
Mark Haverkamp5d497ce2005-06-17 13:38:04 -0700782 rcode = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 goto cleanup;
784 }
785
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800786 if (flags & SRB_DataIn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 for(i = 0 ; i <= sg_indx; i++){
Mark Haverkampf2b1a062007-03-15 10:27:32 -0700788 byte_count = le32_to_cpu(
789 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700790 ? ((struct sgmap64*)&srbcmd->sg)->sg[i].count
791 : srbcmd->sg.sg[i].count);
792 if(copy_to_user(sg_user[i], sg_list[i], byte_count)){
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800793 dprintk((KERN_DEBUG"aacraid: Could not copy sg data to user\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 rcode = -EFAULT;
795 goto cleanup;
796
797 }
798 }
799 }
800
801 reply = (struct aac_srb_reply *) fib_data(srbfib);
802 if(copy_to_user(user_reply,reply,sizeof(struct aac_srb_reply))){
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800803 dprintk((KERN_DEBUG"aacraid: Could not copy reply to user\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 rcode = -EFAULT;
805 goto cleanup;
806 }
807
808cleanup:
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700809 kfree(user_srbcmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 for(i=0; i <= sg_indx; i++){
811 kfree(sg_list[i]);
812 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530813 if (rcode != -ERESTARTSYS) {
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700814 aac_fib_complete(srbfib);
815 aac_fib_free(srbfib);
816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 return rcode;
819}
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821struct aac_pci_info {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800822 u32 bus;
823 u32 slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824};
825
826
Adrian Bunk 48338692005-04-25 19:45:58 -0700827static int aac_get_pci_info(struct aac_dev* dev, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800829 struct aac_pci_info pci_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 pci_info.bus = dev->pdev->bus->number;
832 pci_info.slot = PCI_SLOT(dev->pdev->devfn);
833
Salyzyn, Mark5234e252008-01-28 12:16:52 -0800834 if (copy_to_user(arg, &pci_info, sizeof(struct aac_pci_info))) {
835 dprintk((KERN_DEBUG "aacraid: Could not copy pci info\n"));
836 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800838 return 0;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700839}
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg)
843{
844 int status;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 /*
847 * HBA gets first crack
848 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 status = aac_dev_ioctl(dev, cmd, arg);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530851 if (status != -ENOTTY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 return status;
853
854 switch (cmd) {
855 case FSACTL_MINIPORT_REV_CHECK:
856 status = check_revision(dev, arg);
857 break;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700858 case FSACTL_SEND_LARGE_FIB:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 case FSACTL_SENDFIB:
860 status = ioctl_send_fib(dev, arg);
861 break;
862 case FSACTL_OPEN_GET_ADAPTER_FIB:
863 status = open_getadapter_fib(dev, arg);
864 break;
865 case FSACTL_GET_NEXT_ADAPTER_FIB:
866 status = next_getadapter_fib(dev, arg);
867 break;
868 case FSACTL_CLOSE_GET_ADAPTER_FIB:
869 status = close_getadapter_fib(dev, arg);
870 break;
871 case FSACTL_SEND_RAW_SRB:
872 status = aac_send_raw_srb(dev,arg);
873 break;
874 case FSACTL_GET_PCI_INFO:
875 status = aac_get_pci_info(dev,arg);
876 break;
877 default:
878 status = -ENOTTY;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800879 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881 return status;
882}
883