[SCSI] aacraid: sgraw command support
[safe/jmp/linux-2.6] / drivers / scsi / aacraid / aachba.c
1 /*
2  *      Adaptec AAC series RAID controller driver
3  *      (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
4  *
5  * based on the old aacraid driver that is..
6  * Adaptec aacraid device driver for Linux.
7  *
8  * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com)
9  *
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  */
25
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/sched.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/slab.h>
33 #include <linux/completion.h>
34 #include <linux/blkdev.h>
35 #include <asm/semaphore.h>
36 #include <asm/uaccess.h>
37
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
42
43 #include "aacraid.h"
44
45 /* values for inqd_pdt: Peripheral device type in plain English */
46 #define INQD_PDT_DA     0x00    /* Direct-access (DISK) device */
47 #define INQD_PDT_PROC   0x03    /* Processor device */
48 #define INQD_PDT_CHNGR  0x08    /* Changer (jukebox, scsi2) */
49 #define INQD_PDT_COMM   0x09    /* Communication device (scsi2) */
50 #define INQD_PDT_NOLUN2 0x1f    /* Unknown Device (scsi2) */
51 #define INQD_PDT_NOLUN  0x7f    /* Logical Unit Not Present */
52
53 #define INQD_PDT_DMASK  0x1F    /* Peripheral Device Type Mask */
54 #define INQD_PDT_QMASK  0xE0    /* Peripheral Device Qualifer Mask */
55
56 /*
57  *      Sense codes
58  */
59  
60 #define SENCODE_NO_SENSE                        0x00
61 #define SENCODE_END_OF_DATA                     0x00
62 #define SENCODE_BECOMING_READY                  0x04
63 #define SENCODE_INIT_CMD_REQUIRED               0x04
64 #define SENCODE_PARAM_LIST_LENGTH_ERROR         0x1A
65 #define SENCODE_INVALID_COMMAND                 0x20
66 #define SENCODE_LBA_OUT_OF_RANGE                0x21
67 #define SENCODE_INVALID_CDB_FIELD               0x24
68 #define SENCODE_LUN_NOT_SUPPORTED               0x25
69 #define SENCODE_INVALID_PARAM_FIELD             0x26
70 #define SENCODE_PARAM_NOT_SUPPORTED             0x26
71 #define SENCODE_PARAM_VALUE_INVALID             0x26
72 #define SENCODE_RESET_OCCURRED                  0x29
73 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET     0x3E
74 #define SENCODE_INQUIRY_DATA_CHANGED            0x3F
75 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED     0x39
76 #define SENCODE_DIAGNOSTIC_FAILURE              0x40
77 #define SENCODE_INTERNAL_TARGET_FAILURE         0x44
78 #define SENCODE_INVALID_MESSAGE_ERROR           0x49
79 #define SENCODE_LUN_FAILED_SELF_CONFIG          0x4c
80 #define SENCODE_OVERLAPPED_COMMAND              0x4E
81
82 /*
83  *      Additional sense codes
84  */
85  
86 #define ASENCODE_NO_SENSE                       0x00
87 #define ASENCODE_END_OF_DATA                    0x05
88 #define ASENCODE_BECOMING_READY                 0x01
89 #define ASENCODE_INIT_CMD_REQUIRED              0x02
90 #define ASENCODE_PARAM_LIST_LENGTH_ERROR        0x00
91 #define ASENCODE_INVALID_COMMAND                0x00
92 #define ASENCODE_LBA_OUT_OF_RANGE               0x00
93 #define ASENCODE_INVALID_CDB_FIELD              0x00
94 #define ASENCODE_LUN_NOT_SUPPORTED              0x00
95 #define ASENCODE_INVALID_PARAM_FIELD            0x00
96 #define ASENCODE_PARAM_NOT_SUPPORTED            0x01
97 #define ASENCODE_PARAM_VALUE_INVALID            0x02
98 #define ASENCODE_RESET_OCCURRED                 0x00
99 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET    0x00
100 #define ASENCODE_INQUIRY_DATA_CHANGED           0x03
101 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED    0x00
102 #define ASENCODE_DIAGNOSTIC_FAILURE             0x80
103 #define ASENCODE_INTERNAL_TARGET_FAILURE        0x00
104 #define ASENCODE_INVALID_MESSAGE_ERROR          0x00
105 #define ASENCODE_LUN_FAILED_SELF_CONFIG         0x00
106 #define ASENCODE_OVERLAPPED_COMMAND             0x00
107
108 #define BYTE0(x) (unsigned char)(x)
109 #define BYTE1(x) (unsigned char)((x) >> 8)
110 #define BYTE2(x) (unsigned char)((x) >> 16)
111 #define BYTE3(x) (unsigned char)((x) >> 24)
112
113 /*------------------------------------------------------------------------------
114  *              S T R U C T S / T Y P E D E F S
115  *----------------------------------------------------------------------------*/
116 /* SCSI inquiry data */
117 struct inquiry_data {
118         u8 inqd_pdt;    /* Peripheral qualifier | Peripheral Device Type  */
119         u8 inqd_dtq;    /* RMB | Device Type Qualifier  */
120         u8 inqd_ver;    /* ISO version | ECMA version | ANSI-approved version */
121         u8 inqd_rdf;    /* AENC | TrmIOP | Response data format */
122         u8 inqd_len;    /* Additional length (n-4) */
123         u8 inqd_pad1[2];/* Reserved - must be zero */
124         u8 inqd_pad2;   /* RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe */
125         u8 inqd_vid[8]; /* Vendor ID */
126         u8 inqd_pid[16];/* Product ID */
127         u8 inqd_prl[4]; /* Product Revision Level */
128 };
129
130 /*
131  *              M O D U L E   G L O B A L S
132  */
133  
134 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
136 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
137 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
138 #ifdef AAC_DETAILED_STATUS_INFO
139 static char *aac_get_status_string(u32 status);
140 #endif
141
142 /*
143  *      Non dasd selection is handled entirely in aachba now
144  */     
145  
146 static int nondasd = -1;
147 static int dacmode = -1;
148
149 static int commit = -1;
150
151 module_param(nondasd, int, 0);
152 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
153 module_param(dacmode, int, 0);
154 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
155 module_param(commit, int, 0);
156 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
157
158 int numacb = -1;
159 module_param(numacb, int, S_IRUGO|S_IWUSR);
160 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid\nvalues are 512 and down. Default is to use suggestion from Firmware.");
161
162 int acbsize = -1;
163 module_param(acbsize, int, S_IRUGO|S_IWUSR);
164 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512,\n2048, 4096 and 8192. Default is to use suggestion from Firmware.");
165 /**
166  *      aac_get_config_status   -       check the adapter configuration
167  *      @common: adapter to query
168  *
169  *      Query config status, and commit the configuration if needed.
170  */
171 int aac_get_config_status(struct aac_dev *dev)
172 {
173         int status = 0;
174         struct fib * fibptr;
175
176         if (!(fibptr = fib_alloc(dev)))
177                 return -ENOMEM;
178
179         fib_init(fibptr);
180         {
181                 struct aac_get_config_status *dinfo;
182                 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
183
184                 dinfo->command = cpu_to_le32(VM_ContainerConfig);
185                 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
186                 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
187         }
188
189         status = fib_send(ContainerCommand,
190                             fibptr,
191                             sizeof (struct aac_get_config_status),
192                             FsaNormal,
193                             1, 1,
194                             NULL, NULL);
195         if (status < 0 ) {
196                 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
197         } else {
198                 struct aac_get_config_status_resp *reply
199                   = (struct aac_get_config_status_resp *) fib_data(fibptr);
200                 dprintk((KERN_WARNING
201                   "aac_get_config_status: response=%d status=%d action=%d\n",
202                   le32_to_cpu(reply->response),
203                   le32_to_cpu(reply->status),
204                   le32_to_cpu(reply->data.action)));
205                 if ((le32_to_cpu(reply->response) != ST_OK) ||
206                      (le32_to_cpu(reply->status) != CT_OK) ||
207                      (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
208                         printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
209                         status = -EINVAL;
210                 }
211         }
212         fib_complete(fibptr);
213         /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
214         if (status >= 0) {
215                 if (commit == 1) {
216                         struct aac_commit_config * dinfo;
217                         fib_init(fibptr);
218                         dinfo = (struct aac_commit_config *) fib_data(fibptr);
219         
220                         dinfo->command = cpu_to_le32(VM_ContainerConfig);
221                         dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
222         
223                         status = fib_send(ContainerCommand,
224                                     fibptr,
225                                     sizeof (struct aac_commit_config),
226                                     FsaNormal,
227                                     1, 1,
228                                     NULL, NULL);
229                         fib_complete(fibptr);
230                 } else if (commit == 0) {
231                         printk(KERN_WARNING
232                           "aac_get_config_status: Foreign device configurations are being ignored\n");
233                 }
234         }
235         fib_free(fibptr);
236         return status;
237 }
238
239 /**
240  *      aac_get_containers      -       list containers
241  *      @common: adapter to probe
242  *
243  *      Make a list of all containers on this controller
244  */
245 int aac_get_containers(struct aac_dev *dev)
246 {
247         struct fsa_dev_info *fsa_dev_ptr;
248         u32 index; 
249         int status = 0;
250         struct fib * fibptr;
251         unsigned instance;
252         struct aac_get_container_count *dinfo;
253         struct aac_get_container_count_resp *dresp;
254         int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
255
256         instance = dev->scsi_host_ptr->unique_id;
257
258         if (!(fibptr = fib_alloc(dev)))
259                 return -ENOMEM;
260
261         fib_init(fibptr);
262         dinfo = (struct aac_get_container_count *) fib_data(fibptr);
263         dinfo->command = cpu_to_le32(VM_ContainerConfig);
264         dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
265
266         status = fib_send(ContainerCommand,
267                     fibptr,
268                     sizeof (struct aac_get_container_count),
269                     FsaNormal,
270                     1, 1,
271                     NULL, NULL);
272         if (status >= 0) {
273                 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
274                 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
275                 fib_complete(fibptr);
276         }
277
278         if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
279                 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
280         fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
281           sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
282         if (!fsa_dev_ptr) {
283                 fib_free(fibptr);
284                 return -ENOMEM;
285         }
286         memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
287
288         dev->fsa_dev = fsa_dev_ptr;
289         dev->maximum_num_containers = maximum_num_containers;
290
291         for (index = 0; index < dev->maximum_num_containers; index++) {
292                 struct aac_query_mount *dinfo;
293                 struct aac_mount *dresp;
294
295                 fsa_dev_ptr[index].devname[0] = '\0';
296
297                 fib_init(fibptr);
298                 dinfo = (struct aac_query_mount *) fib_data(fibptr);
299
300                 dinfo->command = cpu_to_le32(VM_NameServe);
301                 dinfo->count = cpu_to_le32(index);
302                 dinfo->type = cpu_to_le32(FT_FILESYS);
303
304                 status = fib_send(ContainerCommand,
305                                     fibptr,
306                                     sizeof (struct aac_query_mount),
307                                     FsaNormal,
308                                     1, 1,
309                                     NULL, NULL);
310                 if (status < 0 ) {
311                         printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
312                         break;
313                 }
314                 dresp = (struct aac_mount *)fib_data(fibptr);
315
316                 dprintk ((KERN_DEBUG
317                   "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%u\n",
318                   (int)index, (int)le32_to_cpu(dresp->status),
319                   (int)le32_to_cpu(dresp->mnt[0].vol),
320                   (int)le32_to_cpu(dresp->mnt[0].state),
321                   (unsigned)le32_to_cpu(dresp->mnt[0].capacity)));
322                 if ((le32_to_cpu(dresp->status) == ST_OK) &&
323                     (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
324                     (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
325                         fsa_dev_ptr[index].valid = 1;
326                         fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
327                         fsa_dev_ptr[index].size = le32_to_cpu(dresp->mnt[0].capacity);
328                         if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
329                                     fsa_dev_ptr[index].ro = 1;
330                 }
331                 fib_complete(fibptr);
332                 /*
333                  *      If there are no more containers, then stop asking.
334                  */
335                 if ((index + 1) >= le32_to_cpu(dresp->count)){
336                         break;
337                 }
338         }
339         fib_free(fibptr);
340         return status;
341 }
342
343 static void aac_io_done(struct scsi_cmnd * scsicmd)
344 {
345         unsigned long cpu_flags;
346         struct Scsi_Host *host = scsicmd->device->host;
347         spin_lock_irqsave(host->host_lock, cpu_flags);
348         scsicmd->scsi_done(scsicmd);
349         spin_unlock_irqrestore(host->host_lock, cpu_flags);
350 }
351
352 static void get_container_name_callback(void *context, struct fib * fibptr)
353 {
354         struct aac_get_name_resp * get_name_reply;
355         struct scsi_cmnd * scsicmd;
356
357         scsicmd = (struct scsi_cmnd *) context;
358
359         dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
360         if (fibptr == NULL)
361                 BUG();
362
363         get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
364         /* Failure is irrelevant, using default value instead */
365         if ((le32_to_cpu(get_name_reply->status) == CT_OK)
366          && (get_name_reply->data[0] != '\0')) {
367                 int    count;
368                 char * dp;
369                 char * sp = get_name_reply->data;
370                 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
371                 while (*sp == ' ')
372                         ++sp;
373                 count = sizeof(((struct inquiry_data *)NULL)->inqd_pid);
374                 dp = ((struct inquiry_data *)scsicmd->request_buffer)->inqd_pid;
375                 if (*sp) do {
376                         *dp++ = (*sp) ? *sp++ : ' ';
377                 } while (--count > 0);
378         }
379         scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
380
381         fib_complete(fibptr);
382         fib_free(fibptr);
383         aac_io_done(scsicmd);
384 }
385
386 /**
387  *      aac_get_container_name  -       get container name, none blocking.
388  */
389 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
390 {
391         int status;
392         struct aac_get_name *dinfo;
393         struct fib * cmd_fibcontext;
394         struct aac_dev * dev;
395
396         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
397
398         if (!(cmd_fibcontext = fib_alloc(dev)))
399                 return -ENOMEM;
400
401         fib_init(cmd_fibcontext);
402         dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
403
404         dinfo->command = cpu_to_le32(VM_ContainerConfig);
405         dinfo->type = cpu_to_le32(CT_READ_NAME);
406         dinfo->cid = cpu_to_le32(cid);
407         dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
408
409         status = fib_send(ContainerCommand, 
410                   cmd_fibcontext, 
411                   sizeof (struct aac_get_name),
412                   FsaNormal, 
413                   0, 1, 
414                   (fib_callback) get_container_name_callback, 
415                   (void *) scsicmd);
416         
417         /*
418          *      Check that the command queued to the controller
419          */
420         if (status == -EINPROGRESS) 
421                 return 0;
422                 
423         printk(KERN_WARNING "aac_get_container_name: fib_send failed with status: %d.\n", status);
424         fib_complete(cmd_fibcontext);
425         fib_free(cmd_fibcontext);
426         return -1;
427 }
428
429 /**
430  *      probe_container         -       query a logical volume
431  *      @dev: device to query
432  *      @cid: container identifier
433  *
434  *      Queries the controller about the given volume. The volume information
435  *      is updated in the struct fsa_dev_info structure rather than returned.
436  */
437  
438 static int probe_container(struct aac_dev *dev, int cid)
439 {
440         struct fsa_dev_info *fsa_dev_ptr;
441         int status;
442         struct aac_query_mount *dinfo;
443         struct aac_mount *dresp;
444         struct fib * fibptr;
445         unsigned instance;
446
447         fsa_dev_ptr = dev->fsa_dev;
448         instance = dev->scsi_host_ptr->unique_id;
449
450         if (!(fibptr = fib_alloc(dev)))
451                 return -ENOMEM;
452
453         fib_init(fibptr);
454
455         dinfo = (struct aac_query_mount *)fib_data(fibptr);
456
457         dinfo->command = cpu_to_le32(VM_NameServe);
458         dinfo->count = cpu_to_le32(cid);
459         dinfo->type = cpu_to_le32(FT_FILESYS);
460
461         status = fib_send(ContainerCommand,
462                             fibptr,
463                             sizeof(struct aac_query_mount),
464                             FsaNormal,
465                             1, 1,
466                             NULL, NULL);
467         if (status < 0) {
468                 printk(KERN_WARNING "aacraid: probe_container query failed.\n");
469                 goto error;
470         }
471
472         dresp = (struct aac_mount *) fib_data(fibptr);
473
474         if ((le32_to_cpu(dresp->status) == ST_OK) &&
475             (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
476             (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
477                 fsa_dev_ptr[cid].valid = 1;
478                 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
479                 fsa_dev_ptr[cid].size = le32_to_cpu(dresp->mnt[0].capacity);
480                 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
481                         fsa_dev_ptr[cid].ro = 1;
482         }
483
484 error:
485         fib_complete(fibptr);
486         fib_free(fibptr);
487
488         return status;
489 }
490
491 /* Local Structure to set SCSI inquiry data strings */
492 struct scsi_inq {
493         char vid[8];         /* Vendor ID */
494         char pid[16];        /* Product ID */
495         char prl[4];         /* Product Revision Level */
496 };
497
498 /**
499  *      InqStrCopy      -       string merge
500  *      @a:     string to copy from
501  *      @b:     string to copy to
502  *
503  *      Copy a String from one location to another
504  *      without copying \0
505  */
506
507 static void inqstrcpy(char *a, char *b)
508 {
509
510         while(*a != (char)0) 
511                 *b++ = *a++;
512 }
513
514 static char *container_types[] = {
515         "None",
516         "Volume",
517         "Mirror",
518         "Stripe",
519         "RAID5",
520         "SSRW",
521         "SSRO",
522         "Morph",
523         "Legacy",
524         "RAID4",
525         "RAID10",             
526         "RAID00",             
527         "V-MIRRORS",          
528         "PSEUDO R4",          
529         "RAID50",
530         "RAID5D",
531         "RAID5D0",
532         "RAID1E",
533         "RAID6",
534         "RAID60",
535         "Unknown"
536 };
537
538
539
540 /* Function: setinqstr
541  *
542  * Arguments: [1] pointer to void [1] int
543  *
544  * Purpose: Sets SCSI inquiry data strings for vendor, product
545  * and revision level. Allows strings to be set in platform dependant
546  * files instead of in OS dependant driver source.
547  */
548
549 static void setinqstr(int devtype, void *data, int tindex)
550 {
551         struct scsi_inq *str;
552         struct aac_driver_ident *mp;
553
554         mp = aac_get_driver_ident(devtype);
555    
556         str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
557
558         inqstrcpy (mp->vname, str->vid); 
559         inqstrcpy (mp->model, str->pid); /* last six chars reserved for vol type */
560
561         if (tindex < (sizeof(container_types)/sizeof(char *))){
562                 char *findit = str->pid;
563
564                 for ( ; *findit != ' '; findit++); /* walk till we find a space */
565                 /* RAID is superfluous in the context of a RAID device */
566                 if (memcmp(findit-4, "RAID", 4) == 0)
567                         *(findit -= 4) = ' ';
568                 inqstrcpy (container_types[tindex], findit + 1);
569         }
570         inqstrcpy ("V1.0", str->prl);
571 }
572
573 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
574                       u8 a_sense_code, u8 incorrect_length,
575                       u8 bit_pointer, u16 field_pointer,
576                       u32 residue)
577 {
578         sense_buf[0] = 0xF0;    /* Sense data valid, err code 70h (current error) */
579         sense_buf[1] = 0;       /* Segment number, always zero */
580
581         if (incorrect_length) {
582                 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
583                 sense_buf[3] = BYTE3(residue);
584                 sense_buf[4] = BYTE2(residue);
585                 sense_buf[5] = BYTE1(residue);
586                 sense_buf[6] = BYTE0(residue);
587         } else
588                 sense_buf[2] = sense_key;       /* Sense key */
589
590         if (sense_key == ILLEGAL_REQUEST)
591                 sense_buf[7] = 10;      /* Additional sense length */
592         else
593                 sense_buf[7] = 6;       /* Additional sense length */
594
595         sense_buf[12] = sense_code;     /* Additional sense code */
596         sense_buf[13] = a_sense_code;   /* Additional sense code qualifier */
597         if (sense_key == ILLEGAL_REQUEST) {
598                 sense_buf[15] = 0;
599
600                 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
601                         sense_buf[15] = 0x80;/* Std sense key specific field */
602                 /* Illegal parameter is in the parameter block */
603
604                 if (sense_code == SENCODE_INVALID_CDB_FIELD)
605                         sense_buf[15] = 0xc0;/* Std sense key specific field */
606                 /* Illegal parameter is in the CDB block */
607                 sense_buf[15] |= bit_pointer;
608                 sense_buf[16] = field_pointer >> 8;     /* MSB */
609                 sense_buf[17] = field_pointer;          /* LSB */
610         }
611 }
612
613 int aac_get_adapter_info(struct aac_dev* dev)
614 {
615         struct fib* fibptr;
616         int rcode;
617         u32 tmp;
618         struct aac_adapter_info *info;
619         struct aac_bus_info *command;
620         struct aac_bus_info_response *bus_info;
621
622         if (!(fibptr = fib_alloc(dev)))
623                 return -ENOMEM;
624
625         fib_init(fibptr);
626         info = (struct aac_adapter_info *) fib_data(fibptr);
627         memset(info,0,sizeof(*info));
628
629         rcode = fib_send(RequestAdapterInfo,
630                          fibptr, 
631                          sizeof(*info),
632                          FsaNormal, 
633                          1, 1, 
634                          NULL, 
635                          NULL);
636
637         if (rcode < 0) {
638                 fib_complete(fibptr);
639                 fib_free(fibptr);
640                 return rcode;
641         }
642         memcpy(&dev->adapter_info, info, sizeof(*info));
643
644         if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
645                 struct aac_supplement_adapter_info * info;
646
647                 fib_init(fibptr);
648
649                 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
650
651                 memset(info,0,sizeof(*info));
652
653                 rcode = fib_send(RequestSupplementAdapterInfo,
654                                  fibptr,
655                                  sizeof(*info),
656                                  FsaNormal,
657                                  1, 1,
658                                  NULL,
659                                  NULL);
660
661                 if (rcode >= 0)
662                         memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
663         }
664
665
666         /* 
667          * GetBusInfo 
668          */
669
670         fib_init(fibptr);
671
672         bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
673
674         memset(bus_info, 0, sizeof(*bus_info));
675
676         command = (struct aac_bus_info *)bus_info;
677
678         command->Command = cpu_to_le32(VM_Ioctl);
679         command->ObjType = cpu_to_le32(FT_DRIVE);
680         command->MethodId = cpu_to_le32(1);
681         command->CtlCmd = cpu_to_le32(GetBusInfo);
682
683         rcode = fib_send(ContainerCommand,
684                          fibptr,
685                          sizeof (*bus_info),
686                          FsaNormal,
687                          1, 1,
688                          NULL, NULL);
689
690         if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
691                 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
692                 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
693         }
694
695         tmp = le32_to_cpu(dev->adapter_info.kernelrev);
696         printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n", 
697                         dev->name, 
698                         dev->id,
699                         tmp>>24,
700                         (tmp>>16)&0xff,
701                         tmp&0xff,
702                         le32_to_cpu(dev->adapter_info.kernelbuild),
703                         (int)sizeof(dev->supplement_adapter_info.BuildDate),
704                         dev->supplement_adapter_info.BuildDate);
705         tmp = le32_to_cpu(dev->adapter_info.monitorrev);
706         printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n", 
707                         dev->name, dev->id,
708                         tmp>>24,(tmp>>16)&0xff,tmp&0xff,
709                         le32_to_cpu(dev->adapter_info.monitorbuild));
710         tmp = le32_to_cpu(dev->adapter_info.biosrev);
711         printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n", 
712                         dev->name, dev->id,
713                         tmp>>24,(tmp>>16)&0xff,tmp&0xff,
714                         le32_to_cpu(dev->adapter_info.biosbuild));
715         if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
716                 printk(KERN_INFO "%s%d: serial %x\n",
717                         dev->name, dev->id,
718                         le32_to_cpu(dev->adapter_info.serial[0]));
719
720         dev->nondasd_support = 0;
721         dev->raid_scsi_mode = 0;
722         if(dev->adapter_info.options & AAC_OPT_NONDASD){
723                 dev->nondasd_support = 1;
724         }
725
726         /*
727          * If the firmware supports ROMB RAID/SCSI mode and we are currently
728          * in RAID/SCSI mode, set the flag. For now if in this mode we will
729          * force nondasd support on. If we decide to allow the non-dasd flag
730          * additional changes changes will have to be made to support
731          * RAID/SCSI.  the function aac_scsi_cmd in this module will have to be
732          * changed to support the new dev->raid_scsi_mode flag instead of
733          * leaching off of the dev->nondasd_support flag. Also in linit.c the
734          * function aac_detect will have to be modified where it sets up the
735          * max number of channels based on the aac->nondasd_support flag only.
736          */
737         if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
738             (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
739                 dev->nondasd_support = 1;
740                 dev->raid_scsi_mode = 1;
741         }
742         if (dev->raid_scsi_mode != 0)
743                 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
744                                 dev->name, dev->id);
745                 
746         if(nondasd != -1) {  
747                 dev->nondasd_support = (nondasd!=0);
748         }
749         if(dev->nondasd_support != 0){
750                 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
751         }
752
753         dev->dac_support = 0;
754         if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
755                 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
756                 dev->dac_support = 1;
757         }
758
759         if(dacmode != -1) {
760                 dev->dac_support = (dacmode!=0);
761         }
762         if(dev->dac_support != 0) {
763                 if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL) &&
764                         !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL)) {
765                         printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
766                                 dev->name, dev->id);
767                 } else if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFULL) &&
768                         !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFULL)) {
769                         printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
770                                 dev->name, dev->id);
771                         dev->dac_support = 0;
772                 } else {
773                         printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
774                                 dev->name, dev->id);
775                         rcode = -ENOMEM;
776                 }
777         }
778         /* 
779          * 57 scatter gather elements 
780          */
781         if (!(dev->raw_io_interface)) {
782                 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
783                         sizeof(struct aac_fibhdr) -
784                         sizeof(struct aac_write) + sizeof(struct sgmap)) /
785                                 sizeof(struct sgmap);
786                 if (dev->dac_support) {
787                         /* 
788                          * 38 scatter gather elements 
789                          */
790                         dev->scsi_host_ptr->sg_tablesize =
791                                 (dev->max_fib_size -
792                                 sizeof(struct aac_fibhdr) -
793                                 sizeof(struct aac_write64) +
794                                 sizeof(struct sgmap64)) /
795                                         sizeof(struct sgmap64);
796                 }
797                 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
798                 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
799                         /*
800                          * Worst case size that could cause sg overflow when
801                          * we break up SG elements that are larger than 64KB.
802                          * Would be nice if we could tell the SCSI layer what
803                          * the maximum SG element size can be. Worst case is
804                          * (sg_tablesize-1) 4KB elements with one 64KB
805                          * element.
806                          *      32bit -> 468 or 238KB   64bit -> 424 or 212KB
807                          */
808                         dev->scsi_host_ptr->max_sectors =
809                           (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
810                 }
811         }
812
813         fib_complete(fibptr);
814         fib_free(fibptr);
815
816         return rcode;
817 }
818
819
820 static void io_callback(void *context, struct fib * fibptr)
821 {
822         struct aac_dev *dev;
823         struct aac_read_reply *readreply;
824         struct scsi_cmnd *scsicmd;
825         u32 cid;
826
827         scsicmd = (struct scsi_cmnd *) context;
828
829         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
830         cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
831
832         dprintk((KERN_DEBUG "io_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3], jiffies));
833
834         if (fibptr == NULL)
835                 BUG();
836                 
837         if(scsicmd->use_sg)
838                 pci_unmap_sg(dev->pdev, 
839                         (struct scatterlist *)scsicmd->buffer,
840                         scsicmd->use_sg,
841                         scsicmd->sc_data_direction);
842         else if(scsicmd->request_bufflen)
843                 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
844                                  scsicmd->request_bufflen,
845                                  scsicmd->sc_data_direction);
846         readreply = (struct aac_read_reply *)fib_data(fibptr);
847         if (le32_to_cpu(readreply->status) == ST_OK)
848                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
849         else {
850 #ifdef AAC_DETAILED_STATUS_INFO
851                 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
852                   le32_to_cpu(readreply->status));
853 #endif
854                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
855                 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
856                                     HARDWARE_ERROR,
857                                     SENCODE_INTERNAL_TARGET_FAILURE,
858                                     ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
859                                     0, 0);
860                 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
861                   (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
862                     ? sizeof(scsicmd->sense_buffer)
863                     : sizeof(dev->fsa_dev[cid].sense_data));
864         }
865         fib_complete(fibptr);
866         fib_free(fibptr);
867
868         aac_io_done(scsicmd);
869 }
870
871 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
872 {
873         u32 lba;
874         u32 count;
875         int status;
876
877         u16 fibsize;
878         struct aac_dev *dev;
879         struct fib * cmd_fibcontext;
880
881         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
882         /*
883          *      Get block address and transfer length
884          */
885         if (scsicmd->cmnd[0] == READ_6) /* 6 byte command */
886         {
887                 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
888
889                 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
890                 count = scsicmd->cmnd[4];
891
892                 if (count == 0)
893                         count = 256;
894         } else {
895                 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
896
897                 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
898                 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
899         }
900         dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n",
901           smp_processor_id(), (unsigned long long)lba, jiffies));
902         /*
903          *      Alocate and initialize a Fib
904          */
905         if (!(cmd_fibcontext = fib_alloc(dev))) {
906                 return -1;
907         }
908
909         fib_init(cmd_fibcontext);
910
911         if (dev->raw_io_interface) {
912                 struct aac_raw_io *readcmd;
913                 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
914                 readcmd->block[0] = cpu_to_le32(lba);
915                 readcmd->block[1] = 0;
916                 readcmd->count = cpu_to_le32(count<<9);
917                 readcmd->cid = cpu_to_le16(cid);
918                 readcmd->flags = cpu_to_le16(1);
919                 readcmd->bpTotal = 0;
920                 readcmd->bpComplete = 0;
921                 
922                 aac_build_sgraw(scsicmd, &readcmd->sg);
923                 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
924                 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
925                         BUG();
926                 /*
927                  *      Now send the Fib to the adapter
928                  */
929                 status = fib_send(ContainerRawIo,
930                           cmd_fibcontext, 
931                           fibsize, 
932                           FsaNormal, 
933                           0, 1, 
934                           (fib_callback) io_callback, 
935                           (void *) scsicmd);
936         } else if (dev->dac_support == 1) {
937                 struct aac_read64 *readcmd;
938                 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
939                 readcmd->command = cpu_to_le32(VM_CtHostRead64);
940                 readcmd->cid = cpu_to_le16(cid);
941                 readcmd->sector_count = cpu_to_le16(count);
942                 readcmd->block = cpu_to_le32(lba);
943                 readcmd->pad   = 0;
944                 readcmd->flags = 0; 
945
946                 aac_build_sg64(scsicmd, &readcmd->sg);
947                 fibsize = sizeof(struct aac_read64) + 
948                         ((le32_to_cpu(readcmd->sg.count) - 1) * 
949                          sizeof (struct sgentry64));
950                 BUG_ON (fibsize > (sizeof(struct hw_fib) - 
951                                         sizeof(struct aac_fibhdr)));
952                 /*
953                  *      Now send the Fib to the adapter
954                  */
955                 status = fib_send(ContainerCommand64, 
956                           cmd_fibcontext, 
957                           fibsize, 
958                           FsaNormal, 
959                           0, 1, 
960                           (fib_callback) io_callback, 
961                           (void *) scsicmd);
962         } else {
963                 struct aac_read *readcmd;
964                 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
965                 readcmd->command = cpu_to_le32(VM_CtBlockRead);
966                 readcmd->cid = cpu_to_le32(cid);
967                 readcmd->block = cpu_to_le32(lba);
968                 readcmd->count = cpu_to_le32(count * 512);
969
970                 aac_build_sg(scsicmd, &readcmd->sg);
971                 fibsize = sizeof(struct aac_read) + 
972                         ((le32_to_cpu(readcmd->sg.count) - 1) * 
973                          sizeof (struct sgentry));
974                 BUG_ON (fibsize > (dev->max_fib_size -
975                                         sizeof(struct aac_fibhdr)));
976                 /*
977                  *      Now send the Fib to the adapter
978                  */
979                 status = fib_send(ContainerCommand, 
980                           cmd_fibcontext, 
981                           fibsize, 
982                           FsaNormal, 
983                           0, 1, 
984                           (fib_callback) io_callback, 
985                           (void *) scsicmd);
986         }
987
988         
989
990         /*
991          *      Check that the command queued to the controller
992          */
993         if (status == -EINPROGRESS) 
994                 return 0;
995                 
996         printk(KERN_WARNING "aac_read: fib_send failed with status: %d.\n", status);
997         /*
998          *      For some reason, the Fib didn't queue, return QUEUE_FULL
999          */
1000         scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1001         aac_io_done(scsicmd);
1002         fib_complete(cmd_fibcontext);
1003         fib_free(cmd_fibcontext);
1004         return 0;
1005 }
1006
1007 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1008 {
1009         u32 lba;
1010         u32 count;
1011         int status;
1012         u16 fibsize;
1013         struct aac_dev *dev;
1014         struct fib * cmd_fibcontext;
1015
1016         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1017         /*
1018          *      Get block address and transfer length
1019          */
1020         if (scsicmd->cmnd[0] == WRITE_6)        /* 6 byte command */
1021         {
1022                 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1023                 count = scsicmd->cmnd[4];
1024                 if (count == 0)
1025                         count = 256;
1026         } else {
1027                 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1028                 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1029                 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1030         }
1031         dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n",
1032           smp_processor_id(), (unsigned long long)lba, jiffies));
1033         /*
1034          *      Allocate and initialize a Fib then setup a BlockWrite command
1035          */
1036         if (!(cmd_fibcontext = fib_alloc(dev))) {
1037                 scsicmd->result = DID_ERROR << 16;
1038                 aac_io_done(scsicmd);
1039                 return 0;
1040         }
1041         fib_init(cmd_fibcontext);
1042
1043         if (dev->raw_io_interface) {
1044                 struct aac_raw_io *writecmd;
1045                 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1046                 writecmd->block[0] = cpu_to_le32(lba);
1047                 writecmd->block[1] = 0;
1048                 writecmd->count = cpu_to_le32(count<<9);
1049                 writecmd->cid = cpu_to_le16(cid);
1050                 writecmd->flags = 0; 
1051                 writecmd->bpTotal = 0;
1052                 writecmd->bpComplete = 0;
1053                 
1054                 aac_build_sgraw(scsicmd, &writecmd->sg);
1055                 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1056                 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1057                         BUG();
1058                 /*
1059                  *      Now send the Fib to the adapter
1060                  */
1061                 status = fib_send(ContainerRawIo,
1062                           cmd_fibcontext, 
1063                           fibsize, 
1064                           FsaNormal, 
1065                           0, 1, 
1066                           (fib_callback) io_callback, 
1067                           (void *) scsicmd);
1068         } else if (dev->dac_support == 1) {
1069                 struct aac_write64 *writecmd;
1070                 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1071                 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1072                 writecmd->cid = cpu_to_le16(cid);
1073                 writecmd->sector_count = cpu_to_le16(count); 
1074                 writecmd->block = cpu_to_le32(lba);
1075                 writecmd->pad   = 0;
1076                 writecmd->flags = 0;
1077
1078                 aac_build_sg64(scsicmd, &writecmd->sg);
1079                 fibsize = sizeof(struct aac_write64) + 
1080                         ((le32_to_cpu(writecmd->sg.count) - 1) * 
1081                          sizeof (struct sgentry64));
1082                 BUG_ON (fibsize > (dev->max_fib_size -
1083                                         sizeof(struct aac_fibhdr)));
1084                 /*
1085                  *      Now send the Fib to the adapter
1086                  */
1087                 status = fib_send(ContainerCommand64, 
1088                           cmd_fibcontext, 
1089                           fibsize, 
1090                           FsaNormal, 
1091                           0, 1, 
1092                           (fib_callback) io_callback, 
1093                           (void *) scsicmd);
1094         } else {
1095                 struct aac_write *writecmd;
1096                 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1097                 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1098                 writecmd->cid = cpu_to_le32(cid);
1099                 writecmd->block = cpu_to_le32(lba);
1100                 writecmd->count = cpu_to_le32(count * 512);
1101                 writecmd->sg.count = cpu_to_le32(1);
1102                 /* ->stable is not used - it did mean which type of write */
1103
1104                 aac_build_sg(scsicmd, &writecmd->sg);
1105                 fibsize = sizeof(struct aac_write) + 
1106                         ((le32_to_cpu(writecmd->sg.count) - 1) * 
1107                          sizeof (struct sgentry));
1108                 BUG_ON (fibsize > (dev->max_fib_size -
1109                                         sizeof(struct aac_fibhdr)));
1110                 /*
1111                  *      Now send the Fib to the adapter
1112                  */
1113                 status = fib_send(ContainerCommand, 
1114                           cmd_fibcontext, 
1115                           fibsize, 
1116                           FsaNormal, 
1117                           0, 1, 
1118                           (fib_callback) io_callback, 
1119                           (void *) scsicmd);
1120         }
1121
1122         /*
1123          *      Check that the command queued to the controller
1124          */
1125         if (status == -EINPROGRESS)
1126         {
1127                 return 0;
1128         }
1129
1130         printk(KERN_WARNING "aac_write: fib_send failed with status: %d\n", status);
1131         /*
1132          *      For some reason, the Fib didn't queue, return QUEUE_FULL
1133          */
1134         scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1135         aac_io_done(scsicmd);
1136
1137         fib_complete(cmd_fibcontext);
1138         fib_free(cmd_fibcontext);
1139         return 0;
1140 }
1141
1142 static void synchronize_callback(void *context, struct fib *fibptr)
1143 {
1144         struct aac_synchronize_reply *synchronizereply;
1145         struct scsi_cmnd *cmd;
1146
1147         cmd = context;
1148
1149         dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n", 
1150                                 smp_processor_id(), jiffies));
1151         BUG_ON(fibptr == NULL);
1152
1153
1154         synchronizereply = fib_data(fibptr);
1155         if (le32_to_cpu(synchronizereply->status) == CT_OK)
1156                 cmd->result = DID_OK << 16 | 
1157                         COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1158         else {
1159                 struct scsi_device *sdev = cmd->device;
1160                 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1161                 u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun);
1162                 printk(KERN_WARNING 
1163                      "synchronize_callback: synchronize failed, status = %d\n",
1164                      le32_to_cpu(synchronizereply->status));
1165                 cmd->result = DID_OK << 16 | 
1166                         COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1167                 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1168                                     HARDWARE_ERROR,
1169                                     SENCODE_INTERNAL_TARGET_FAILURE,
1170                                     ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1171                                     0, 0);
1172                 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1173                   min(sizeof(dev->fsa_dev[cid].sense_data), 
1174                           sizeof(cmd->sense_buffer)));
1175         }
1176
1177         fib_complete(fibptr);
1178         fib_free(fibptr);
1179         aac_io_done(cmd);
1180 }
1181
1182 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1183 {
1184         int status;
1185         struct fib *cmd_fibcontext;
1186         struct aac_synchronize *synchronizecmd;
1187         struct scsi_cmnd *cmd;
1188         struct scsi_device *sdev = scsicmd->device;
1189         int active = 0;
1190         unsigned long flags;
1191
1192         /*
1193          * Wait for all commands to complete to this specific
1194          * target (block).
1195          */
1196         spin_lock_irqsave(&sdev->list_lock, flags);
1197         list_for_each_entry(cmd, &sdev->cmd_list, list)
1198                 if (cmd != scsicmd && cmd->serial_number != 0) {
1199                         ++active;
1200                         break;
1201                 }
1202
1203         spin_unlock_irqrestore(&sdev->list_lock, flags);
1204
1205         /*
1206          *      Yield the processor (requeue for later)
1207          */
1208         if (active)
1209                 return SCSI_MLQUEUE_DEVICE_BUSY;
1210
1211         /*
1212          *      Allocate and initialize a Fib
1213          */
1214         if (!(cmd_fibcontext = 
1215             fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) 
1216                 return SCSI_MLQUEUE_HOST_BUSY;
1217
1218         fib_init(cmd_fibcontext);
1219
1220         synchronizecmd = fib_data(cmd_fibcontext);
1221         synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1222         synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1223         synchronizecmd->cid = cpu_to_le32(cid);
1224         synchronizecmd->count = 
1225              cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1226
1227         /*
1228          *      Now send the Fib to the adapter
1229          */
1230         status = fib_send(ContainerCommand,
1231                   cmd_fibcontext,
1232                   sizeof(struct aac_synchronize),
1233                   FsaNormal,
1234                   0, 1,
1235                   (fib_callback)synchronize_callback,
1236                   (void *)scsicmd);
1237
1238         /*
1239          *      Check that the command queued to the controller
1240          */
1241         if (status == -EINPROGRESS)
1242                 return 0;
1243
1244         printk(KERN_WARNING 
1245                 "aac_synchronize: fib_send failed with status: %d.\n", status);
1246         fib_complete(cmd_fibcontext);
1247         fib_free(cmd_fibcontext);
1248         return SCSI_MLQUEUE_HOST_BUSY;
1249 }
1250
1251 /**
1252  *      aac_scsi_cmd()          -       Process SCSI command
1253  *      @scsicmd:               SCSI command block
1254  *
1255  *      Emulate a SCSI command and queue the required request for the
1256  *      aacraid firmware.
1257  */
1258  
1259 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1260 {
1261         u32 cid = 0;
1262         struct Scsi_Host *host = scsicmd->device->host;
1263         struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1264         struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1265         int cardtype = dev->cardtype;
1266         int ret;
1267         
1268         /*
1269          *      If the bus, id or lun is out of range, return fail
1270          *      Test does not apply to ID 16, the pseudo id for the controller
1271          *      itself.
1272          */
1273         if (scsicmd->device->id != host->this_id) {
1274                 if ((scsicmd->device->channel == 0) ){
1275                         if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){ 
1276                                 scsicmd->result = DID_NO_CONNECT << 16;
1277                                 scsicmd->scsi_done(scsicmd);
1278                                 return 0;
1279                         }
1280                         cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
1281
1282                         /*
1283                          *      If the target container doesn't exist, it may have
1284                          *      been newly created
1285                          */
1286                         if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1287                                 switch (scsicmd->cmnd[0]) {
1288                                 case INQUIRY:
1289                                 case READ_CAPACITY:
1290                                 case TEST_UNIT_READY:
1291                                         spin_unlock_irq(host->host_lock);
1292                                         probe_container(dev, cid);
1293                                         spin_lock_irq(host->host_lock);
1294                                         if (fsa_dev_ptr[cid].valid == 0) {
1295                                                 scsicmd->result = DID_NO_CONNECT << 16;
1296                                                 scsicmd->scsi_done(scsicmd);
1297                                                 return 0;
1298                                         }
1299                                 default:
1300                                         break;
1301                                 }
1302                         }
1303                         /*
1304                          *      If the target container still doesn't exist, 
1305                          *      return failure
1306                          */
1307                         if (fsa_dev_ptr[cid].valid == 0) {
1308                                 scsicmd->result = DID_BAD_TARGET << 16;
1309                                 scsicmd->scsi_done(scsicmd);
1310                                 return 0;
1311                         }
1312                 } else {  /* check for physical non-dasd devices */
1313                         if(dev->nondasd_support == 1){
1314                                 return aac_send_srb_fib(scsicmd);
1315                         } else {
1316                                 scsicmd->result = DID_NO_CONNECT << 16;
1317                                 scsicmd->scsi_done(scsicmd);
1318                                 return 0;
1319                         }
1320                 }
1321         }
1322         /*
1323          * else Command for the controller itself
1324          */
1325         else if ((scsicmd->cmnd[0] != INQUIRY) &&       /* only INQUIRY & TUR cmnd supported for controller */
1326                 (scsicmd->cmnd[0] != TEST_UNIT_READY)) 
1327         {
1328                 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1329                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1330                 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1331                             ILLEGAL_REQUEST,
1332                             SENCODE_INVALID_COMMAND,
1333                             ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1334                 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1335                   (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1336                     ? sizeof(scsicmd->sense_buffer)
1337                     : sizeof(dev->fsa_dev[cid].sense_data));
1338                 scsicmd->scsi_done(scsicmd);
1339                 return 0;
1340         }
1341
1342
1343         /* Handle commands here that don't really require going out to the adapter */
1344         switch (scsicmd->cmnd[0]) {
1345         case INQUIRY:
1346         {
1347                 struct inquiry_data *inq_data_ptr;
1348
1349                 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
1350                 inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer;
1351                 memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
1352
1353                 inq_data_ptr->inqd_ver = 2;     /* claim compliance to SCSI-2 */
1354                 inq_data_ptr->inqd_dtq = 0x80;  /* set RMB bit to one indicating that the medium is removable */
1355                 inq_data_ptr->inqd_rdf = 2;     /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
1356                 inq_data_ptr->inqd_len = 31;
1357                 /*Format for "pad2" is  RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe */
1358                 inq_data_ptr->inqd_pad2= 0x32 ;  /*WBus16|Sync|CmdQue */
1359                 /*
1360                  *      Set the Vendor, Product, and Revision Level
1361                  *      see: <vendor>.c i.e. aac.c
1362                  */
1363                 if (scsicmd->device->id == host->this_id) {
1364                         setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *)));
1365                         inq_data_ptr->inqd_pdt = INQD_PDT_PROC; /* Processor device */
1366                         scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1367                         scsicmd->scsi_done(scsicmd);
1368                         return 0;
1369                 }
1370                 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr[cid].type);
1371                 inq_data_ptr->inqd_pdt = INQD_PDT_DA;   /* Direct/random access device */
1372                 return aac_get_container_name(scsicmd, cid);
1373         }
1374         case READ_CAPACITY:
1375         {
1376                 u32 capacity;
1377                 char *cp;
1378
1379                 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1380                 if (fsa_dev_ptr[cid].size <= 0x100000000LL)
1381                         capacity = fsa_dev_ptr[cid].size - 1;
1382                 else
1383                         capacity = (u32)-1;
1384                 cp = scsicmd->request_buffer;
1385                 cp[0] = (capacity >> 24) & 0xff;
1386                 cp[1] = (capacity >> 16) & 0xff;
1387                 cp[2] = (capacity >> 8) & 0xff;
1388                 cp[3] = (capacity >> 0) & 0xff;
1389                 cp[4] = 0;
1390                 cp[5] = 0;
1391                 cp[6] = 2;
1392                 cp[7] = 0;
1393
1394                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1395                 scsicmd->scsi_done(scsicmd);
1396
1397                 return 0;
1398         }
1399
1400         case MODE_SENSE:
1401         {
1402                 char *mode_buf;
1403
1404                 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1405                 mode_buf = scsicmd->request_buffer;
1406                 mode_buf[0] = 3;        /* Mode data length */
1407                 mode_buf[1] = 0;        /* Medium type - default */
1408                 mode_buf[2] = 0;        /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1409                 mode_buf[3] = 0;        /* Block descriptor length */
1410
1411                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1412                 scsicmd->scsi_done(scsicmd);
1413
1414                 return 0;
1415         }
1416         case MODE_SENSE_10:
1417         {
1418                 char *mode_buf;
1419
1420                 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1421                 mode_buf = scsicmd->request_buffer;
1422                 mode_buf[0] = 0;        /* Mode data length (MSB) */
1423                 mode_buf[1] = 6;        /* Mode data length (LSB) */
1424                 mode_buf[2] = 0;        /* Medium type - default */
1425                 mode_buf[3] = 0;        /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1426                 mode_buf[4] = 0;        /* reserved */
1427                 mode_buf[5] = 0;        /* reserved */
1428                 mode_buf[6] = 0;        /* Block descriptor length (MSB) */
1429                 mode_buf[7] = 0;        /* Block descriptor length (LSB) */
1430
1431                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1432                 scsicmd->scsi_done(scsicmd);
1433
1434                 return 0;
1435         }
1436         case REQUEST_SENSE:
1437                 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1438                 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1439                 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1440                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1441                 scsicmd->scsi_done(scsicmd);
1442                 return 0;
1443
1444         case ALLOW_MEDIUM_REMOVAL:
1445                 dprintk((KERN_DEBUG "LOCK command.\n"));
1446                 if (scsicmd->cmnd[4])
1447                         fsa_dev_ptr[cid].locked = 1;
1448                 else
1449                         fsa_dev_ptr[cid].locked = 0;
1450
1451                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1452                 scsicmd->scsi_done(scsicmd);
1453                 return 0;
1454         /*
1455          *      These commands are all No-Ops
1456          */
1457         case TEST_UNIT_READY:
1458         case RESERVE:
1459         case RELEASE:
1460         case REZERO_UNIT:
1461         case REASSIGN_BLOCKS:
1462         case SEEK_10:
1463         case START_STOP:
1464                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1465                 scsicmd->scsi_done(scsicmd);
1466                 return 0;
1467         }
1468
1469         switch (scsicmd->cmnd[0]) 
1470         {
1471                 case READ_6:
1472                 case READ_10:
1473                         /*
1474                          *      Hack to keep track of ordinal number of the device that
1475                          *      corresponds to a container. Needed to convert
1476                          *      containers to /dev/sd device names
1477                          */
1478                          
1479                         spin_unlock_irq(host->host_lock);
1480                         if  (scsicmd->request->rq_disk)
1481                                 memcpy(fsa_dev_ptr[cid].devname,
1482                                         scsicmd->request->rq_disk->disk_name,
1483                                         8);
1484
1485                         ret = aac_read(scsicmd, cid);
1486                         spin_lock_irq(host->host_lock);
1487                         return ret;
1488
1489                 case WRITE_6:
1490                 case WRITE_10:
1491                         spin_unlock_irq(host->host_lock);
1492                         ret = aac_write(scsicmd, cid);
1493                         spin_lock_irq(host->host_lock);
1494                         return ret;
1495
1496                 case SYNCHRONIZE_CACHE:
1497                         /* Issue FIB to tell Firmware to flush it's cache */
1498                         return aac_synchronize(scsicmd, cid);
1499                         
1500                 default:
1501                         /*
1502                          *      Unhandled commands
1503                          */
1504                         dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1505                         scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1506                         set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1507                                 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1508                                 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1509                         memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1510                           (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1511                             ? sizeof(scsicmd->sense_buffer)
1512                             : sizeof(dev->fsa_dev[cid].sense_data));
1513                         scsicmd->scsi_done(scsicmd);
1514                         return 0;
1515         }
1516 }
1517
1518 static int query_disk(struct aac_dev *dev, void __user *arg)
1519 {
1520         struct aac_query_disk qd;
1521         struct fsa_dev_info *fsa_dev_ptr;
1522
1523         fsa_dev_ptr = dev->fsa_dev;
1524         if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1525                 return -EFAULT;
1526         if (qd.cnum == -1)
1527                 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
1528         else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) 
1529         {
1530                 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1531                         return -EINVAL;
1532                 qd.instance = dev->scsi_host_ptr->host_no;
1533                 qd.bus = 0;
1534                 qd.id = CONTAINER_TO_ID(qd.cnum);
1535                 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1536         }
1537         else return -EINVAL;
1538
1539         qd.valid = fsa_dev_ptr[qd.cnum].valid;
1540         qd.locked = fsa_dev_ptr[qd.cnum].locked;
1541         qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1542
1543         if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1544                 qd.unmapped = 1;
1545         else
1546                 qd.unmapped = 0;
1547
1548         strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1549           min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1550
1551         if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1552                 return -EFAULT;
1553         return 0;
1554 }
1555
1556 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1557 {
1558         struct aac_delete_disk dd;
1559         struct fsa_dev_info *fsa_dev_ptr;
1560
1561         fsa_dev_ptr = dev->fsa_dev;
1562
1563         if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1564                 return -EFAULT;
1565
1566         if (dd.cnum >= dev->maximum_num_containers)
1567                 return -EINVAL;
1568         /*
1569          *      Mark this container as being deleted.
1570          */
1571         fsa_dev_ptr[dd.cnum].deleted = 1;
1572         /*
1573          *      Mark the container as no longer valid
1574          */
1575         fsa_dev_ptr[dd.cnum].valid = 0;
1576         return 0;
1577 }
1578
1579 static int delete_disk(struct aac_dev *dev, void __user *arg)
1580 {
1581         struct aac_delete_disk dd;
1582         struct fsa_dev_info *fsa_dev_ptr;
1583
1584         fsa_dev_ptr = dev->fsa_dev;
1585
1586         if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1587                 return -EFAULT;
1588
1589         if (dd.cnum >= dev->maximum_num_containers)
1590                 return -EINVAL;
1591         /*
1592          *      If the container is locked, it can not be deleted by the API.
1593          */
1594         if (fsa_dev_ptr[dd.cnum].locked)
1595                 return -EBUSY;
1596         else {
1597                 /*
1598                  *      Mark the container as no longer being valid.
1599                  */
1600                 fsa_dev_ptr[dd.cnum].valid = 0;
1601                 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1602                 return 0;
1603         }
1604 }
1605
1606 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1607 {
1608         switch (cmd) {
1609         case FSACTL_QUERY_DISK:
1610                 return query_disk(dev, arg);
1611         case FSACTL_DELETE_DISK:
1612                 return delete_disk(dev, arg);
1613         case FSACTL_FORCE_DELETE_DISK:
1614                 return force_delete_disk(dev, arg);
1615         case FSACTL_GET_CONTAINERS:
1616                 return aac_get_containers(dev);
1617         default:
1618                 return -ENOTTY;
1619         }
1620 }
1621
1622 /**
1623  *
1624  * aac_srb_callback
1625  * @context: the context set in the fib - here it is scsi cmd
1626  * @fibptr: pointer to the fib
1627  *
1628  * Handles the completion of a scsi command to a non dasd device
1629  *
1630  */
1631
1632 static void aac_srb_callback(void *context, struct fib * fibptr)
1633 {
1634         struct aac_dev *dev;
1635         struct aac_srb_reply *srbreply;
1636         struct scsi_cmnd *scsicmd;
1637
1638         scsicmd = (struct scsi_cmnd *) context;
1639         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1640
1641         if (fibptr == NULL)
1642                 BUG();
1643
1644         srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1645
1646         scsicmd->sense_buffer[0] = '\0';  /* Initialize sense valid flag to false */
1647         /*
1648          *      Calculate resid for sg 
1649          */
1650          
1651         scsicmd->resid = scsicmd->request_bufflen - 
1652                 le32_to_cpu(srbreply->data_xfer_length);
1653
1654         if(scsicmd->use_sg)
1655                 pci_unmap_sg(dev->pdev, 
1656                         (struct scatterlist *)scsicmd->buffer,
1657                         scsicmd->use_sg,
1658                         scsicmd->sc_data_direction);
1659         else if(scsicmd->request_bufflen)
1660                 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1661                         scsicmd->sc_data_direction);
1662
1663         /*
1664          * First check the fib status
1665          */
1666
1667         if (le32_to_cpu(srbreply->status) != ST_OK){
1668                 int len;
1669                 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1670                 len = (le32_to_cpu(srbreply->sense_data_size) > 
1671                                 sizeof(scsicmd->sense_buffer)) ?
1672                                 sizeof(scsicmd->sense_buffer) : 
1673                                 le32_to_cpu(srbreply->sense_data_size);
1674                 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1675                 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1676         }
1677
1678         /*
1679          * Next check the srb status
1680          */
1681         switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1682         case SRB_STATUS_ERROR_RECOVERY:
1683         case SRB_STATUS_PENDING:
1684         case SRB_STATUS_SUCCESS:
1685                 if(scsicmd->cmnd[0] == INQUIRY ){
1686                         u8 b;
1687                         u8 b1;
1688                         /* We can't expose disk devices because we can't tell whether they
1689                          * are the raw container drives or stand alone drives.  If they have
1690                          * the removable bit set then we should expose them though.
1691                          */
1692                         b = (*(u8*)scsicmd->buffer)&0x1f;
1693                         b1 = ((u8*)scsicmd->buffer)[1];
1694                         if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER 
1695                                         || (b==TYPE_DISK && (b1&0x80)) ){
1696                                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1697                         /*
1698                          * We will allow disk devices if in RAID/SCSI mode and
1699                          * the channel is 2
1700                          */
1701                         } else if ((dev->raid_scsi_mode) &&
1702                                         (scsicmd->device->channel == 2)) {
1703                                 scsicmd->result = DID_OK << 16 | 
1704                                                 COMMAND_COMPLETE << 8;
1705                         } else {
1706                                 scsicmd->result = DID_NO_CONNECT << 16 | 
1707                                                 COMMAND_COMPLETE << 8;
1708                         }
1709                 } else {
1710                         scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1711                 }
1712                 break;
1713         case SRB_STATUS_DATA_OVERRUN:
1714                 switch(scsicmd->cmnd[0]){
1715                 case  READ_6:
1716                 case  WRITE_6:
1717                 case  READ_10:
1718                 case  WRITE_10:
1719                 case  READ_12:
1720                 case  WRITE_12:
1721                         if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1722                                 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1723                         } else {
1724                                 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1725                         }
1726                         scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1727                         break;
1728                 case INQUIRY: {
1729                         u8 b;
1730                         u8 b1;
1731                         /* We can't expose disk devices because we can't tell whether they
1732                         * are the raw container drives or stand alone drives
1733                         */
1734                         b = (*(u8*)scsicmd->buffer)&0x0f;
1735                         b1 = ((u8*)scsicmd->buffer)[1];
1736                         if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1737                                         || (b==TYPE_DISK && (b1&0x80)) ){
1738                                 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1739                         /*
1740                          * We will allow disk devices if in RAID/SCSI mode and
1741                          * the channel is 2
1742                          */
1743                         } else if ((dev->raid_scsi_mode) &&
1744                                         (scsicmd->device->channel == 2)) {
1745                                 scsicmd->result = DID_OK << 16 | 
1746                                                 COMMAND_COMPLETE << 8;
1747                         } else {
1748                                 scsicmd->result = DID_NO_CONNECT << 16 | 
1749                                                 COMMAND_COMPLETE << 8;
1750                         }
1751                         break;
1752                 }
1753                 default:
1754                         scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1755                         break;
1756                 }
1757                 break;
1758         case SRB_STATUS_ABORTED:
1759                 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1760                 break;
1761         case SRB_STATUS_ABORT_FAILED:
1762                 // Not sure about this one - but assuming the hba was trying to abort for some reason
1763                 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1764                 break;
1765         case SRB_STATUS_PARITY_ERROR:
1766                 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1767                 break;
1768         case SRB_STATUS_NO_DEVICE:
1769         case SRB_STATUS_INVALID_PATH_ID:
1770         case SRB_STATUS_INVALID_TARGET_ID:
1771         case SRB_STATUS_INVALID_LUN:
1772         case SRB_STATUS_SELECTION_TIMEOUT:
1773                 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1774                 break;
1775
1776         case SRB_STATUS_COMMAND_TIMEOUT:
1777         case SRB_STATUS_TIMEOUT:
1778                 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1779                 break;
1780
1781         case SRB_STATUS_BUSY:
1782                 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1783                 break;
1784
1785         case SRB_STATUS_BUS_RESET:
1786                 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
1787                 break;
1788
1789         case SRB_STATUS_MESSAGE_REJECTED:
1790                 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
1791                 break;
1792         case SRB_STATUS_REQUEST_FLUSHED:
1793         case SRB_STATUS_ERROR:
1794         case SRB_STATUS_INVALID_REQUEST:
1795         case SRB_STATUS_REQUEST_SENSE_FAILED:
1796         case SRB_STATUS_NO_HBA:
1797         case SRB_STATUS_UNEXPECTED_BUS_FREE:
1798         case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
1799         case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
1800         case SRB_STATUS_DELAYED_RETRY:
1801         case SRB_STATUS_BAD_FUNCTION:
1802         case SRB_STATUS_NOT_STARTED:
1803         case SRB_STATUS_NOT_IN_USE:
1804         case SRB_STATUS_FORCE_ABORT:
1805         case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
1806         default:
1807 #ifdef AAC_DETAILED_STATUS_INFO
1808                 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
1809                         le32_to_cpu(srbreply->srb_status) & 0x3F,
1810                         aac_get_status_string(
1811                                 le32_to_cpu(srbreply->srb_status) & 0x3F), 
1812                         scsicmd->cmnd[0], 
1813                         le32_to_cpu(srbreply->scsi_status));
1814 #endif
1815                 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1816                 break;
1817         }
1818         if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){  // Check Condition
1819                 int len;
1820                 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
1821                 len = (le32_to_cpu(srbreply->sense_data_size) > 
1822                                 sizeof(scsicmd->sense_buffer)) ?
1823                                 sizeof(scsicmd->sense_buffer) :
1824                                 le32_to_cpu(srbreply->sense_data_size);
1825 #ifdef AAC_DETAILED_STATUS_INFO
1826                 dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", 
1827                                         le32_to_cpu(srbreply->status), len));
1828 #endif
1829                 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1830                 
1831         }
1832         /*
1833          * OR in the scsi status (already shifted up a bit)
1834          */
1835         scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
1836
1837         fib_complete(fibptr);
1838         fib_free(fibptr);
1839         aac_io_done(scsicmd);
1840 }
1841
1842 /**
1843  *
1844  * aac_send_scb_fib
1845  * @scsicmd: the scsi command block
1846  *
1847  * This routine will form a FIB and fill in the aac_srb from the 
1848  * scsicmd passed in.
1849  */
1850
1851 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
1852 {
1853         struct fib* cmd_fibcontext;
1854         struct aac_dev* dev;
1855         int status;
1856         struct aac_srb *srbcmd;
1857         u16 fibsize;
1858         u32 flag;
1859         u32 timeout;
1860
1861         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1862         if (scsicmd->device->id >= dev->maximum_num_physicals || 
1863                         scsicmd->device->lun > 7) {
1864                 scsicmd->result = DID_NO_CONNECT << 16;
1865                 scsicmd->scsi_done(scsicmd);
1866                 return 0;
1867         }
1868
1869         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1870         switch(scsicmd->sc_data_direction){
1871         case DMA_TO_DEVICE:
1872                 flag = SRB_DataOut;
1873                 break;
1874         case DMA_BIDIRECTIONAL:
1875                 flag = SRB_DataIn | SRB_DataOut;
1876                 break;
1877         case DMA_FROM_DEVICE:
1878                 flag = SRB_DataIn;
1879                 break;
1880         case DMA_NONE:
1881         default:        /* shuts up some versions of gcc */
1882                 flag = SRB_NoDataXfer;
1883                 break;
1884         }
1885
1886
1887         /*
1888          *      Allocate and initialize a Fib then setup a BlockWrite command
1889          */
1890         if (!(cmd_fibcontext = fib_alloc(dev))) {
1891                 return -1;
1892         }
1893         fib_init(cmd_fibcontext);
1894
1895         srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
1896         srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1897         srbcmd->channel  = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
1898         srbcmd->id   = cpu_to_le32(scsicmd->device->id);
1899         srbcmd->lun      = cpu_to_le32(scsicmd->device->lun);
1900         srbcmd->flags    = cpu_to_le32(flag);
1901         timeout = (scsicmd->timeout-jiffies)/HZ;
1902         if(timeout == 0){
1903                 timeout = 1;
1904         }
1905         srbcmd->timeout  = cpu_to_le32(timeout);  // timeout in seconds
1906         srbcmd->retry_limit = 0; /* Obsolete parameter */
1907         srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
1908         
1909         if( dev->dac_support == 1 ) {
1910                 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
1911                 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1912
1913                 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1914                 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1915                 /*
1916                  *      Build Scatter/Gather list
1917                  */
1918                 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1919                         ((le32_to_cpu(srbcmd->sg.count) & 0xff) * 
1920                          sizeof (struct sgentry64));
1921                 BUG_ON (fibsize > (dev->max_fib_size -
1922                                         sizeof(struct aac_fibhdr)));
1923
1924                 /*
1925                  *      Now send the Fib to the adapter
1926                  */
1927                 status = fib_send(ScsiPortCommand64, cmd_fibcontext, 
1928                                 fibsize, FsaNormal, 0, 1,
1929                                   (fib_callback) aac_srb_callback, 
1930                                   (void *) scsicmd);
1931         } else {
1932                 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
1933                 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1934
1935                 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1936                 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1937                 /*
1938                  *      Build Scatter/Gather list
1939                  */
1940                 fibsize = sizeof (struct aac_srb) + 
1941                         (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) * 
1942                          sizeof (struct sgentry));
1943                 BUG_ON (fibsize > (dev->max_fib_size -
1944                                         sizeof(struct aac_fibhdr)));
1945
1946                 /*
1947                  *      Now send the Fib to the adapter
1948                  */
1949                 status = fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
1950                                   (fib_callback) aac_srb_callback, (void *) scsicmd);
1951         }
1952         /*
1953          *      Check that the command queued to the controller
1954          */
1955         if (status == -EINPROGRESS){
1956                 return 0;
1957         }
1958
1959         printk(KERN_WARNING "aac_srb: fib_send failed with status: %d\n", status);
1960         fib_complete(cmd_fibcontext);
1961         fib_free(cmd_fibcontext);
1962
1963         return -1;
1964 }
1965
1966 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
1967 {
1968         struct aac_dev *dev;
1969         unsigned long byte_count = 0;
1970
1971         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1972         // Get rid of old data
1973         psg->count = 0;
1974         psg->sg[0].addr = 0;
1975         psg->sg[0].count = 0;  
1976         if (scsicmd->use_sg) {
1977                 struct scatterlist *sg;
1978                 int i;
1979                 int sg_count;
1980                 sg = (struct scatterlist *) scsicmd->request_buffer;
1981
1982                 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
1983                         scsicmd->sc_data_direction);
1984                 psg->count = cpu_to_le32(sg_count);
1985
1986                 byte_count = 0;
1987
1988                 for (i = 0; i < sg_count; i++) {
1989                         psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
1990                         psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
1991                         byte_count += sg_dma_len(sg);
1992                         sg++;
1993                 }
1994                 /* hba wants the size to be exact */
1995                 if(byte_count > scsicmd->request_bufflen){
1996                         u32 temp = le32_to_cpu(psg->sg[i-1].count) - 
1997                                 (byte_count - scsicmd->request_bufflen);
1998                         psg->sg[i-1].count = cpu_to_le32(temp);
1999                         byte_count = scsicmd->request_bufflen;
2000                 }
2001                 /* Check for command underflow */
2002                 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2003                         printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2004                                         byte_count, scsicmd->underflow);
2005                 }
2006         }
2007         else if(scsicmd->request_bufflen) {
2008                 dma_addr_t addr; 
2009                 addr = pci_map_single(dev->pdev,
2010                                 scsicmd->request_buffer,
2011                                 scsicmd->request_bufflen,
2012                                 scsicmd->sc_data_direction);
2013                 psg->count = cpu_to_le32(1);
2014                 psg->sg[0].addr = cpu_to_le32(addr);
2015                 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);  
2016                 scsicmd->SCp.dma_handle = addr;
2017                 byte_count = scsicmd->request_bufflen;
2018         }
2019         return byte_count;
2020 }
2021
2022
2023 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2024 {
2025         struct aac_dev *dev;
2026         unsigned long byte_count = 0;
2027         u64 addr;
2028
2029         dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2030         // Get rid of old data
2031         psg->count = 0;
2032         psg->sg[0].addr[0] = 0;
2033         psg->sg[0].addr[1] = 0;
2034         psg->sg[0].count = 0;
2035         if (scsicmd->use_sg) {
2036                 struct scatterlist *sg;
2037                 int i;
2038                 int sg_count;
2039                 sg = (struct scatterlist *) scsicmd->request_buffer;
2040
2041                 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2042                         scsicmd->sc_data_direction);
2043                 psg->count = cpu_to_le32(sg_count);
2044
2045                 byte_count = 0;
2046
2047                 for (i = 0; i < sg_count; i++) {
2048                         addr = sg_dma_address(sg);
2049                         psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2050                         psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2051                         psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2052                         byte_count += sg_dma_len(sg);
2053                         sg++;
2054                 }
2055                 /* hba wants the size to be exact */
2056                 if(byte_count > scsicmd->request_bufflen){
2057                         u32 temp = le32_to_cpu(psg->sg[i-1].count) - 
2058                                 (byte_count - scsicmd->request_bufflen);
2059                         psg->sg[i-1].count = cpu_to_le32(temp);
2060                         byte_count = scsicmd->request_bufflen;
2061                 }
2062                 /* Check for command underflow */
2063                 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2064                         printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2065                                         byte_count, scsicmd->underflow);
2066                 }
2067         }
2068         else if(scsicmd->request_bufflen) {
2069                 u64 addr; 
2070                 addr = pci_map_single(dev->pdev,
2071                                 scsicmd->request_buffer,
2072                                 scsicmd->request_bufflen,
2073                                 scsicmd->sc_data_direction);
2074                 psg->count = cpu_to_le32(1);
2075                 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2076                 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2077                 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);  
2078                 scsicmd->SCp.dma_handle = addr;
2079                 byte_count = scsicmd->request_bufflen;
2080         }
2081         return byte_count;
2082 }
2083
2084 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2085 {
2086         struct Scsi_Host *host = scsicmd->device->host;
2087         struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2088         unsigned long byte_count = 0;
2089
2090         // Get rid of old data
2091         psg->count = 0;
2092         psg->sg[0].next = 0;
2093         psg->sg[0].prev = 0;
2094         psg->sg[0].addr[0] = 0;
2095         psg->sg[0].addr[1] = 0;
2096         psg->sg[0].count = 0;
2097         psg->sg[0].flags = 0;
2098         if (scsicmd->use_sg) {
2099                 struct scatterlist *sg;
2100                 int i;
2101                 int sg_count;
2102                 sg = (struct scatterlist *) scsicmd->request_buffer;
2103
2104                 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2105                         scsicmd->sc_data_direction);
2106
2107                 for (i = 0; i < sg_count; i++) {
2108                         int count = sg_dma_len(sg);
2109                         u64 addr = sg_dma_address(sg);
2110                         psg->sg[i].next = 0;
2111                         psg->sg[i].prev = 0;
2112                         psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2113                         psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2114                         psg->sg[i].count = cpu_to_le32(count);
2115                         psg->sg[i].flags = 0;
2116                         byte_count += count;
2117                         sg++;
2118                 }
2119                 psg->count = cpu_to_le32(sg_count);
2120                 /* hba wants the size to be exact */
2121                 if(byte_count > scsicmd->request_bufflen){
2122                         u32 temp = le32_to_cpu(psg->sg[i-1].count) - 
2123                                 (byte_count - scsicmd->request_bufflen);
2124                         psg->sg[i-1].count = cpu_to_le32(temp);
2125                         byte_count = scsicmd->request_bufflen;
2126                 }
2127                 /* Check for command underflow */
2128                 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2129                         printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2130                                         byte_count, scsicmd->underflow);
2131                 }
2132         }
2133         else if(scsicmd->request_bufflen) {
2134                 int count;
2135                 u64 addr;
2136                 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2137                                 scsicmd->request_buffer,
2138                                 scsicmd->request_bufflen,
2139                                 scsicmd->sc_data_direction);
2140                 addr = scsicmd->SCp.dma_handle;
2141                 count = scsicmd->request_bufflen;
2142                 psg->count = cpu_to_le32(1);
2143                 psg->sg[0].next = 0;
2144                 psg->sg[0].prev = 0;
2145                 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2146                 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2147                 psg->sg[0].count = cpu_to_le32(count);
2148                 psg->sg[0].flags = 0;
2149                 byte_count = scsicmd->request_bufflen;
2150         }
2151         return byte_count;
2152 }
2153
2154 #ifdef AAC_DETAILED_STATUS_INFO
2155
2156 struct aac_srb_status_info {
2157         u32     status;
2158         char    *str;
2159 };
2160
2161
2162 static struct aac_srb_status_info srb_status_info[] = {
2163         { SRB_STATUS_PENDING,           "Pending Status"},
2164         { SRB_STATUS_SUCCESS,           "Success"},
2165         { SRB_STATUS_ABORTED,           "Aborted Command"},
2166         { SRB_STATUS_ABORT_FAILED,      "Abort Failed"},
2167         { SRB_STATUS_ERROR,             "Error Event"}, 
2168         { SRB_STATUS_BUSY,              "Device Busy"},
2169         { SRB_STATUS_INVALID_REQUEST,   "Invalid Request"},
2170         { SRB_STATUS_INVALID_PATH_ID,   "Invalid Path ID"},
2171         { SRB_STATUS_NO_DEVICE,         "No Device"},
2172         { SRB_STATUS_TIMEOUT,           "Timeout"},
2173         { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2174         { SRB_STATUS_COMMAND_TIMEOUT,   "Command Timeout"},
2175         { SRB_STATUS_MESSAGE_REJECTED,  "Message Rejected"},
2176         { SRB_STATUS_BUS_RESET,         "Bus Reset"},
2177         { SRB_STATUS_PARITY_ERROR,      "Parity Error"},
2178         { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2179         { SRB_STATUS_NO_HBA,            "No HBA"},
2180         { SRB_STATUS_DATA_OVERRUN,      "Data Overrun/Data Underrun"},
2181         { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2182         { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2183         { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2184         { SRB_STATUS_REQUEST_FLUSHED,   "Request Flushed"},
2185         { SRB_STATUS_DELAYED_RETRY,     "Delayed Retry"},
2186         { SRB_STATUS_INVALID_LUN,       "Invalid LUN"}, 
2187         { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2188         { SRB_STATUS_BAD_FUNCTION,      "Bad Function"},
2189         { SRB_STATUS_ERROR_RECOVERY,    "Error Recovery"},
2190         { SRB_STATUS_NOT_STARTED,       "Not Started"},
2191         { SRB_STATUS_NOT_IN_USE,        "Not In Use"},
2192         { SRB_STATUS_FORCE_ABORT,       "Force Abort"},
2193         { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2194         { 0xff,                         "Unknown Error"}
2195 };
2196
2197 char *aac_get_status_string(u32 status)
2198 {
2199         int i;
2200
2201         for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
2202                 if(srb_status_info[i].status == status){
2203                         return srb_status_info[i].str;
2204                 }
2205         }
2206
2207         return "Bad Status Code";
2208 }
2209
2210 #endif