aacraid: 4KB sector support
[deliverable/linux.git] / drivers / scsi / aacraid / aachba.c
1 /*
2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
4 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 */
26
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/types.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/uaccess.h>
36 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 #include <linux/module.h>
38
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
43
44 #include "aacraid.h"
45
46 /* values for inqd_pdt: Peripheral device type in plain English */
47 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48 #define INQD_PDT_PROC 0x03 /* Processor device */
49 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53
54 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
56
57 /*
58 * Sense codes
59 */
60
61 #define SENCODE_NO_SENSE 0x00
62 #define SENCODE_END_OF_DATA 0x00
63 #define SENCODE_BECOMING_READY 0x04
64 #define SENCODE_INIT_CMD_REQUIRED 0x04
65 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
66 #define SENCODE_INVALID_COMMAND 0x20
67 #define SENCODE_LBA_OUT_OF_RANGE 0x21
68 #define SENCODE_INVALID_CDB_FIELD 0x24
69 #define SENCODE_LUN_NOT_SUPPORTED 0x25
70 #define SENCODE_INVALID_PARAM_FIELD 0x26
71 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
72 #define SENCODE_PARAM_VALUE_INVALID 0x26
73 #define SENCODE_RESET_OCCURRED 0x29
74 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
75 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
76 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
77 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
78 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
79 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
80 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
81 #define SENCODE_OVERLAPPED_COMMAND 0x4E
82
83 /*
84 * Additional sense codes
85 */
86
87 #define ASENCODE_NO_SENSE 0x00
88 #define ASENCODE_END_OF_DATA 0x05
89 #define ASENCODE_BECOMING_READY 0x01
90 #define ASENCODE_INIT_CMD_REQUIRED 0x02
91 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
92 #define ASENCODE_INVALID_COMMAND 0x00
93 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
94 #define ASENCODE_INVALID_CDB_FIELD 0x00
95 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
96 #define ASENCODE_INVALID_PARAM_FIELD 0x00
97 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
98 #define ASENCODE_PARAM_VALUE_INVALID 0x02
99 #define ASENCODE_RESET_OCCURRED 0x00
100 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
101 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
102 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
103 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
104 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
105 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
106 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107 #define ASENCODE_OVERLAPPED_COMMAND 0x00
108
109 #define BYTE0(x) (unsigned char)(x)
110 #define BYTE1(x) (unsigned char)((x) >> 8)
111 #define BYTE2(x) (unsigned char)((x) >> 16)
112 #define BYTE3(x) (unsigned char)((x) >> 24)
113
114 /* MODE_SENSE data format */
115 typedef struct {
116 struct {
117 u8 data_length;
118 u8 med_type;
119 u8 dev_par;
120 u8 bd_length;
121 } __attribute__((packed)) hd;
122 struct {
123 u8 dens_code;
124 u8 block_count[3];
125 u8 reserved;
126 u8 block_length[3];
127 } __attribute__((packed)) bd;
128 u8 mpc_buf[3];
129 } __attribute__((packed)) aac_modep_data;
130
131 /* MODE_SENSE_10 data format */
132 typedef struct {
133 struct {
134 u8 data_length[2];
135 u8 med_type;
136 u8 dev_par;
137 u8 rsrvd[2];
138 u8 bd_length[2];
139 } __attribute__((packed)) hd;
140 struct {
141 u8 dens_code;
142 u8 block_count[3];
143 u8 reserved;
144 u8 block_length[3];
145 } __attribute__((packed)) bd;
146 u8 mpc_buf[3];
147 } __attribute__((packed)) aac_modep10_data;
148
149 /*------------------------------------------------------------------------------
150 * S T R U C T S / T Y P E D E F S
151 *----------------------------------------------------------------------------*/
152 /* SCSI inquiry data */
153 struct inquiry_data {
154 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
155 u8 inqd_dtq; /* RMB | Device Type Qualifier */
156 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
157 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
158 u8 inqd_len; /* Additional length (n-4) */
159 u8 inqd_pad1[2];/* Reserved - must be zero */
160 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
161 u8 inqd_vid[8]; /* Vendor ID */
162 u8 inqd_pid[16];/* Product ID */
163 u8 inqd_prl[4]; /* Product Revision Level */
164 };
165
166 /*
167 * M O D U L E G L O B A L S
168 */
169
170 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
171 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
172 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
173 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
174 struct aac_raw_io2 *rio2, int sg_max);
175 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
176 int pages, int nseg, int nseg_new);
177 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
178 #ifdef AAC_DETAILED_STATUS_INFO
179 static char *aac_get_status_string(u32 status);
180 #endif
181
182 /*
183 * Non dasd selection is handled entirely in aachba now
184 */
185
186 static int nondasd = -1;
187 static int aac_cache = 2; /* WCE=0 to avoid performance problems */
188 static int dacmode = -1;
189 int aac_msi;
190 int aac_commit = -1;
191 int startup_timeout = 180;
192 int aif_timeout = 120;
193 int aac_sync_mode; /* Only Sync. transfer - disabled */
194 int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
195
196 module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
197 MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
198 " 0=off, 1=on");
199 module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
200 MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
201 " 0=off, 1=on");
202 module_param(nondasd, int, S_IRUGO|S_IWUSR);
203 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
204 " 0=off, 1=on");
205 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
206 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
207 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
208 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
209 "\tbit 2 - Disable only if Battery is protecting Cache");
210 module_param(dacmode, int, S_IRUGO|S_IWUSR);
211 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
212 " 0=off, 1=on");
213 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
214 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
215 " adapter for foreign arrays.\n"
216 "This is typically needed in systems that do not have a BIOS."
217 " 0=off, 1=on");
218 module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
219 MODULE_PARM_DESC(msi, "IRQ handling."
220 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
221 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
222 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
223 " adapter to have it's kernel up and\n"
224 "running. This is typically adjusted for large systems that do not"
225 " have a BIOS.");
226 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
227 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
228 " applications to pick up AIFs before\n"
229 "deregistering them. This is typically adjusted for heavily burdened"
230 " systems.");
231
232 int numacb = -1;
233 module_param(numacb, int, S_IRUGO|S_IWUSR);
234 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
235 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
236 " to use suggestion from Firmware.");
237
238 int acbsize = -1;
239 module_param(acbsize, int, S_IRUGO|S_IWUSR);
240 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
241 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
242 " suggestion from Firmware.");
243
244 int update_interval = 30 * 60;
245 module_param(update_interval, int, S_IRUGO|S_IWUSR);
246 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
247 " updates issued to adapter.");
248
249 int check_interval = 24 * 60 * 60;
250 module_param(check_interval, int, S_IRUGO|S_IWUSR);
251 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
252 " checks.");
253
254 int aac_check_reset = 1;
255 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
256 MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
257 " adapter. a value of -1 forces the reset to adapters programmed to"
258 " ignore it.");
259
260 int expose_physicals = -1;
261 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
262 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
263 " -1=protect 0=off, 1=on");
264
265 int aac_reset_devices;
266 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
267 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
268
269 int aac_wwn = 1;
270 module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
271 MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
272 "\t0 - Disable\n"
273 "\t1 - Array Meta Data Signature (default)\n"
274 "\t2 - Adapter Serial Number");
275
276
277 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
278 struct fib *fibptr) {
279 struct scsi_device *device;
280
281 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
282 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
283 aac_fib_complete(fibptr);
284 aac_fib_free(fibptr);
285 return 0;
286 }
287 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
288 device = scsicmd->device;
289 if (unlikely(!device || !scsi_device_online(device))) {
290 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
291 aac_fib_complete(fibptr);
292 aac_fib_free(fibptr);
293 return 0;
294 }
295 return 1;
296 }
297
298 /**
299 * aac_get_config_status - check the adapter configuration
300 * @common: adapter to query
301 *
302 * Query config status, and commit the configuration if needed.
303 */
304 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
305 {
306 int status = 0;
307 struct fib * fibptr;
308
309 if (!(fibptr = aac_fib_alloc(dev)))
310 return -ENOMEM;
311
312 aac_fib_init(fibptr);
313 {
314 struct aac_get_config_status *dinfo;
315 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
316
317 dinfo->command = cpu_to_le32(VM_ContainerConfig);
318 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
319 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
320 }
321
322 status = aac_fib_send(ContainerCommand,
323 fibptr,
324 sizeof (struct aac_get_config_status),
325 FsaNormal,
326 1, 1,
327 NULL, NULL);
328 if (status < 0) {
329 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
330 } else {
331 struct aac_get_config_status_resp *reply
332 = (struct aac_get_config_status_resp *) fib_data(fibptr);
333 dprintk((KERN_WARNING
334 "aac_get_config_status: response=%d status=%d action=%d\n",
335 le32_to_cpu(reply->response),
336 le32_to_cpu(reply->status),
337 le32_to_cpu(reply->data.action)));
338 if ((le32_to_cpu(reply->response) != ST_OK) ||
339 (le32_to_cpu(reply->status) != CT_OK) ||
340 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
341 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
342 status = -EINVAL;
343 }
344 }
345 /* Do not set XferState to zero unless receives a response from F/W */
346 if (status >= 0)
347 aac_fib_complete(fibptr);
348
349 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
350 if (status >= 0) {
351 if ((aac_commit == 1) || commit_flag) {
352 struct aac_commit_config * dinfo;
353 aac_fib_init(fibptr);
354 dinfo = (struct aac_commit_config *) fib_data(fibptr);
355
356 dinfo->command = cpu_to_le32(VM_ContainerConfig);
357 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
358
359 status = aac_fib_send(ContainerCommand,
360 fibptr,
361 sizeof (struct aac_commit_config),
362 FsaNormal,
363 1, 1,
364 NULL, NULL);
365 /* Do not set XferState to zero unless
366 * receives a response from F/W */
367 if (status >= 0)
368 aac_fib_complete(fibptr);
369 } else if (aac_commit == 0) {
370 printk(KERN_WARNING
371 "aac_get_config_status: Foreign device configurations are being ignored\n");
372 }
373 }
374 /* FIB should be freed only after getting the response from the F/W */
375 if (status != -ERESTARTSYS)
376 aac_fib_free(fibptr);
377 return status;
378 }
379
380 static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
381 {
382 char inq_data;
383 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
384 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
385 inq_data &= 0xdf;
386 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
387 }
388 }
389
390 /**
391 * aac_get_containers - list containers
392 * @common: adapter to probe
393 *
394 * Make a list of all containers on this controller
395 */
396 int aac_get_containers(struct aac_dev *dev)
397 {
398 struct fsa_dev_info *fsa_dev_ptr;
399 u32 index;
400 int status = 0;
401 struct fib * fibptr;
402 struct aac_get_container_count *dinfo;
403 struct aac_get_container_count_resp *dresp;
404 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
405
406 if (!(fibptr = aac_fib_alloc(dev)))
407 return -ENOMEM;
408
409 aac_fib_init(fibptr);
410 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
411 dinfo->command = cpu_to_le32(VM_ContainerConfig);
412 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
413
414 status = aac_fib_send(ContainerCommand,
415 fibptr,
416 sizeof (struct aac_get_container_count),
417 FsaNormal,
418 1, 1,
419 NULL, NULL);
420 if (status >= 0) {
421 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
422 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
423 aac_fib_complete(fibptr);
424 }
425 /* FIB should be freed only after getting the response from the F/W */
426 if (status != -ERESTARTSYS)
427 aac_fib_free(fibptr);
428
429 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
430 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
431 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
432 GFP_KERNEL);
433 if (!fsa_dev_ptr)
434 return -ENOMEM;
435
436 dev->fsa_dev = fsa_dev_ptr;
437 dev->maximum_num_containers = maximum_num_containers;
438
439 for (index = 0; index < dev->maximum_num_containers; ) {
440 fsa_dev_ptr[index].devname[0] = '\0';
441
442 status = aac_probe_container(dev, index);
443
444 if (status < 0) {
445 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
446 break;
447 }
448
449 /*
450 * If there are no more containers, then stop asking.
451 */
452 if (++index >= status)
453 break;
454 }
455 return status;
456 }
457
458 static void get_container_name_callback(void *context, struct fib * fibptr)
459 {
460 struct aac_get_name_resp * get_name_reply;
461 struct scsi_cmnd * scsicmd;
462
463 scsicmd = (struct scsi_cmnd *) context;
464
465 if (!aac_valid_context(scsicmd, fibptr))
466 return;
467
468 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
469 BUG_ON(fibptr == NULL);
470
471 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
472 /* Failure is irrelevant, using default value instead */
473 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
474 && (get_name_reply->data[0] != '\0')) {
475 char *sp = get_name_reply->data;
476 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)] = '\0';
477 while (*sp == ' ')
478 ++sp;
479 if (*sp) {
480 struct inquiry_data inq;
481 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
482 int count = sizeof(d);
483 char *dp = d;
484 do {
485 *dp++ = (*sp) ? *sp++ : ' ';
486 } while (--count > 0);
487
488 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
489 memcpy(inq.inqd_pid, d, sizeof(d));
490 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
491 }
492 }
493
494 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
495
496 aac_fib_complete(fibptr);
497 aac_fib_free(fibptr);
498 scsicmd->scsi_done(scsicmd);
499 }
500
501 /**
502 * aac_get_container_name - get container name, none blocking.
503 */
504 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
505 {
506 int status;
507 struct aac_get_name *dinfo;
508 struct fib * cmd_fibcontext;
509 struct aac_dev * dev;
510
511 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
512
513 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
514 return -ENOMEM;
515
516 aac_fib_init(cmd_fibcontext);
517 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
518
519 dinfo->command = cpu_to_le32(VM_ContainerConfig);
520 dinfo->type = cpu_to_le32(CT_READ_NAME);
521 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
522 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
523
524 status = aac_fib_send(ContainerCommand,
525 cmd_fibcontext,
526 sizeof (struct aac_get_name),
527 FsaNormal,
528 0, 1,
529 (fib_callback)get_container_name_callback,
530 (void *) scsicmd);
531
532 /*
533 * Check that the command queued to the controller
534 */
535 if (status == -EINPROGRESS) {
536 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
537 return 0;
538 }
539
540 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
541 aac_fib_complete(cmd_fibcontext);
542 aac_fib_free(cmd_fibcontext);
543 return -1;
544 }
545
546 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
547 {
548 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
549
550 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
551 return aac_scsi_cmd(scsicmd);
552
553 scsicmd->result = DID_NO_CONNECT << 16;
554 scsicmd->scsi_done(scsicmd);
555 return 0;
556 }
557
558 static void _aac_probe_container2(void * context, struct fib * fibptr)
559 {
560 struct fsa_dev_info *fsa_dev_ptr;
561 int (*callback)(struct scsi_cmnd *);
562 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
563
564
565 if (!aac_valid_context(scsicmd, fibptr))
566 return;
567
568 scsicmd->SCp.Status = 0;
569 fsa_dev_ptr = fibptr->dev->fsa_dev;
570 if (fsa_dev_ptr) {
571 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
572 fsa_dev_ptr += scmd_id(scsicmd);
573
574 if ((le32_to_cpu(dresp->status) == ST_OK) &&
575 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
576 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
577 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
578 AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
579 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
580 fsa_dev_ptr->block_size = 0x200;
581 } else {
582 fsa_dev_ptr->block_size =
583 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
584 }
585 fsa_dev_ptr->valid = 1;
586 /* sense_key holds the current state of the spin-up */
587 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
588 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
589 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
590 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
591 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
592 fsa_dev_ptr->size
593 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
594 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
595 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
596 }
597 if ((fsa_dev_ptr->valid & 1) == 0)
598 fsa_dev_ptr->valid = 0;
599 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
600 }
601 aac_fib_complete(fibptr);
602 aac_fib_free(fibptr);
603 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
604 scsicmd->SCp.ptr = NULL;
605 (*callback)(scsicmd);
606 return;
607 }
608
609 static void _aac_probe_container1(void * context, struct fib * fibptr)
610 {
611 struct scsi_cmnd * scsicmd;
612 struct aac_mount * dresp;
613 struct aac_query_mount *dinfo;
614 int status;
615
616 dresp = (struct aac_mount *) fib_data(fibptr);
617 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
618 AAC_OPTION_VARIABLE_BLOCK_SIZE))
619 dresp->mnt[0].capacityhigh = 0;
620 if ((le32_to_cpu(dresp->status) != ST_OK) ||
621 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
622 _aac_probe_container2(context, fibptr);
623 return;
624 }
625 scsicmd = (struct scsi_cmnd *) context;
626
627 if (!aac_valid_context(scsicmd, fibptr))
628 return;
629
630 aac_fib_init(fibptr);
631
632 dinfo = (struct aac_query_mount *)fib_data(fibptr);
633
634 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
635 AAC_OPTION_VARIABLE_BLOCK_SIZE)
636 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
637 else
638 dinfo->command = cpu_to_le32(VM_NameServe64);
639
640 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
641 dinfo->type = cpu_to_le32(FT_FILESYS);
642
643 status = aac_fib_send(ContainerCommand,
644 fibptr,
645 sizeof(struct aac_query_mount),
646 FsaNormal,
647 0, 1,
648 _aac_probe_container2,
649 (void *) scsicmd);
650 /*
651 * Check that the command queued to the controller
652 */
653 if (status == -EINPROGRESS)
654 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
655 else if (status < 0) {
656 /* Inherit results from VM_NameServe, if any */
657 dresp->status = cpu_to_le32(ST_OK);
658 _aac_probe_container2(context, fibptr);
659 }
660 }
661
662 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
663 {
664 struct fib * fibptr;
665 int status = -ENOMEM;
666
667 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
668 struct aac_query_mount *dinfo;
669
670 aac_fib_init(fibptr);
671
672 dinfo = (struct aac_query_mount *)fib_data(fibptr);
673
674 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
675 AAC_OPTION_VARIABLE_BLOCK_SIZE)
676 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
677 else
678 dinfo->command = cpu_to_le32(VM_NameServe);
679
680 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
681 dinfo->type = cpu_to_le32(FT_FILESYS);
682 scsicmd->SCp.ptr = (char *)callback;
683
684 status = aac_fib_send(ContainerCommand,
685 fibptr,
686 sizeof(struct aac_query_mount),
687 FsaNormal,
688 0, 1,
689 _aac_probe_container1,
690 (void *) scsicmd);
691 /*
692 * Check that the command queued to the controller
693 */
694 if (status == -EINPROGRESS) {
695 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
696 return 0;
697 }
698 if (status < 0) {
699 scsicmd->SCp.ptr = NULL;
700 aac_fib_complete(fibptr);
701 aac_fib_free(fibptr);
702 }
703 }
704 if (status < 0) {
705 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
706 if (fsa_dev_ptr) {
707 fsa_dev_ptr += scmd_id(scsicmd);
708 if ((fsa_dev_ptr->valid & 1) == 0) {
709 fsa_dev_ptr->valid = 0;
710 return (*callback)(scsicmd);
711 }
712 }
713 }
714 return status;
715 }
716
717 /**
718 * aac_probe_container - query a logical volume
719 * @dev: device to query
720 * @cid: container identifier
721 *
722 * Queries the controller about the given volume. The volume information
723 * is updated in the struct fsa_dev_info structure rather than returned.
724 */
725 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
726 {
727 scsicmd->device = NULL;
728 return 0;
729 }
730
731 int aac_probe_container(struct aac_dev *dev, int cid)
732 {
733 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
734 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
735 int status;
736
737 if (!scsicmd || !scsidev) {
738 kfree(scsicmd);
739 kfree(scsidev);
740 return -ENOMEM;
741 }
742 scsicmd->list.next = NULL;
743 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
744
745 scsicmd->device = scsidev;
746 scsidev->sdev_state = 0;
747 scsidev->id = cid;
748 scsidev->host = dev->scsi_host_ptr;
749
750 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
751 while (scsicmd->device == scsidev)
752 schedule();
753 kfree(scsidev);
754 status = scsicmd->SCp.Status;
755 kfree(scsicmd);
756 return status;
757 }
758
759 /* Local Structure to set SCSI inquiry data strings */
760 struct scsi_inq {
761 char vid[8]; /* Vendor ID */
762 char pid[16]; /* Product ID */
763 char prl[4]; /* Product Revision Level */
764 };
765
766 /**
767 * InqStrCopy - string merge
768 * @a: string to copy from
769 * @b: string to copy to
770 *
771 * Copy a String from one location to another
772 * without copying \0
773 */
774
775 static void inqstrcpy(char *a, char *b)
776 {
777
778 while (*a != (char)0)
779 *b++ = *a++;
780 }
781
782 static char *container_types[] = {
783 "None",
784 "Volume",
785 "Mirror",
786 "Stripe",
787 "RAID5",
788 "SSRW",
789 "SSRO",
790 "Morph",
791 "Legacy",
792 "RAID4",
793 "RAID10",
794 "RAID00",
795 "V-MIRRORS",
796 "PSEUDO R4",
797 "RAID50",
798 "RAID5D",
799 "RAID5D0",
800 "RAID1E",
801 "RAID6",
802 "RAID60",
803 "Unknown"
804 };
805
806 char * get_container_type(unsigned tindex)
807 {
808 if (tindex >= ARRAY_SIZE(container_types))
809 tindex = ARRAY_SIZE(container_types) - 1;
810 return container_types[tindex];
811 }
812
813 /* Function: setinqstr
814 *
815 * Arguments: [1] pointer to void [1] int
816 *
817 * Purpose: Sets SCSI inquiry data strings for vendor, product
818 * and revision level. Allows strings to be set in platform dependent
819 * files instead of in OS dependent driver source.
820 */
821
822 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
823 {
824 struct scsi_inq *str;
825
826 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
827 memset(str, ' ', sizeof(*str));
828
829 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
830 char * cp = dev->supplement_adapter_info.AdapterTypeText;
831 int c;
832 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
833 inqstrcpy("SMC", str->vid);
834 else {
835 c = sizeof(str->vid);
836 while (*cp && *cp != ' ' && --c)
837 ++cp;
838 c = *cp;
839 *cp = '\0';
840 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
841 str->vid);
842 *cp = c;
843 while (*cp && *cp != ' ')
844 ++cp;
845 }
846 while (*cp == ' ')
847 ++cp;
848 /* last six chars reserved for vol type */
849 c = 0;
850 if (strlen(cp) > sizeof(str->pid)) {
851 c = cp[sizeof(str->pid)];
852 cp[sizeof(str->pid)] = '\0';
853 }
854 inqstrcpy (cp, str->pid);
855 if (c)
856 cp[sizeof(str->pid)] = c;
857 } else {
858 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
859
860 inqstrcpy (mp->vname, str->vid);
861 /* last six chars reserved for vol type */
862 inqstrcpy (mp->model, str->pid);
863 }
864
865 if (tindex < ARRAY_SIZE(container_types)){
866 char *findit = str->pid;
867
868 for ( ; *findit != ' '; findit++); /* walk till we find a space */
869 /* RAID is superfluous in the context of a RAID device */
870 if (memcmp(findit-4, "RAID", 4) == 0)
871 *(findit -= 4) = ' ';
872 if (((findit - str->pid) + strlen(container_types[tindex]))
873 < (sizeof(str->pid) + sizeof(str->prl)))
874 inqstrcpy (container_types[tindex], findit + 1);
875 }
876 inqstrcpy ("V1.0", str->prl);
877 }
878
879 static void get_container_serial_callback(void *context, struct fib * fibptr)
880 {
881 struct aac_get_serial_resp * get_serial_reply;
882 struct scsi_cmnd * scsicmd;
883
884 BUG_ON(fibptr == NULL);
885
886 scsicmd = (struct scsi_cmnd *) context;
887 if (!aac_valid_context(scsicmd, fibptr))
888 return;
889
890 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
891 /* Failure is irrelevant, using default value instead */
892 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
893 char sp[13];
894 /* EVPD bit set */
895 sp[0] = INQD_PDT_DA;
896 sp[1] = scsicmd->cmnd[2];
897 sp[2] = 0;
898 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
899 le32_to_cpu(get_serial_reply->uid));
900 scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp));
901 }
902
903 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
904
905 aac_fib_complete(fibptr);
906 aac_fib_free(fibptr);
907 scsicmd->scsi_done(scsicmd);
908 }
909
910 /**
911 * aac_get_container_serial - get container serial, none blocking.
912 */
913 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
914 {
915 int status;
916 struct aac_get_serial *dinfo;
917 struct fib * cmd_fibcontext;
918 struct aac_dev * dev;
919
920 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
921
922 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
923 return -ENOMEM;
924
925 aac_fib_init(cmd_fibcontext);
926 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
927
928 dinfo->command = cpu_to_le32(VM_ContainerConfig);
929 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
930 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
931
932 status = aac_fib_send(ContainerCommand,
933 cmd_fibcontext,
934 sizeof (struct aac_get_serial),
935 FsaNormal,
936 0, 1,
937 (fib_callback) get_container_serial_callback,
938 (void *) scsicmd);
939
940 /*
941 * Check that the command queued to the controller
942 */
943 if (status == -EINPROGRESS) {
944 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
945 return 0;
946 }
947
948 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
949 aac_fib_complete(cmd_fibcontext);
950 aac_fib_free(cmd_fibcontext);
951 return -1;
952 }
953
954 /* Function: setinqserial
955 *
956 * Arguments: [1] pointer to void [1] int
957 *
958 * Purpose: Sets SCSI Unit Serial number.
959 * This is a fake. We should read a proper
960 * serial number from the container. <SuSE>But
961 * without docs it's quite hard to do it :-)
962 * So this will have to do in the meantime.</SuSE>
963 */
964
965 static int setinqserial(struct aac_dev *dev, void *data, int cid)
966 {
967 /*
968 * This breaks array migration.
969 */
970 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
971 le32_to_cpu(dev->adapter_info.serial[0]), cid);
972 }
973
974 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
975 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
976 {
977 u8 *sense_buf = (u8 *)sense_data;
978 /* Sense data valid, err code 70h */
979 sense_buf[0] = 0x70; /* No info field */
980 sense_buf[1] = 0; /* Segment number, always zero */
981
982 sense_buf[2] = sense_key; /* Sense key */
983
984 sense_buf[12] = sense_code; /* Additional sense code */
985 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
986
987 if (sense_key == ILLEGAL_REQUEST) {
988 sense_buf[7] = 10; /* Additional sense length */
989
990 sense_buf[15] = bit_pointer;
991 /* Illegal parameter is in the parameter block */
992 if (sense_code == SENCODE_INVALID_CDB_FIELD)
993 sense_buf[15] |= 0xc0;/* Std sense key specific field */
994 /* Illegal parameter is in the CDB block */
995 sense_buf[16] = field_pointer >> 8; /* MSB */
996 sense_buf[17] = field_pointer; /* LSB */
997 } else
998 sense_buf[7] = 6; /* Additional sense length */
999 }
1000
1001 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1002 {
1003 if (lba & 0xffffffff00000000LL) {
1004 int cid = scmd_id(cmd);
1005 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1006 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1007 SAM_STAT_CHECK_CONDITION;
1008 set_sense(&dev->fsa_dev[cid].sense_data,
1009 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1010 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1011 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1012 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1013 SCSI_SENSE_BUFFERSIZE));
1014 cmd->scsi_done(cmd);
1015 return 1;
1016 }
1017 return 0;
1018 }
1019
1020 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1021 {
1022 return 0;
1023 }
1024
1025 static void io_callback(void *context, struct fib * fibptr);
1026
1027 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1028 {
1029 struct aac_dev *dev = fib->dev;
1030 u16 fibsize, command;
1031 long ret;
1032
1033 aac_fib_init(fib);
1034 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1035 struct aac_raw_io2 *readcmd2;
1036 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1037 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1038 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1039 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1040 readcmd2->byteCount = cpu_to_le32(count *
1041 dev->fsa_dev[scmd_id(cmd)].block_size);
1042 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1043 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
1044 ret = aac_build_sgraw2(cmd, readcmd2,
1045 dev->scsi_host_ptr->sg_tablesize);
1046 if (ret < 0)
1047 return ret;
1048 command = ContainerRawIo2;
1049 fibsize = sizeof(struct aac_raw_io2) +
1050 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1051 } else {
1052 struct aac_raw_io *readcmd;
1053 readcmd = (struct aac_raw_io *) fib_data(fib);
1054 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1055 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1056 readcmd->count = cpu_to_le32(count *
1057 dev->fsa_dev[scmd_id(cmd)].block_size);
1058 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1059 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1060 readcmd->bpTotal = 0;
1061 readcmd->bpComplete = 0;
1062 ret = aac_build_sgraw(cmd, &readcmd->sg);
1063 if (ret < 0)
1064 return ret;
1065 command = ContainerRawIo;
1066 fibsize = sizeof(struct aac_raw_io) +
1067 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1068 }
1069
1070 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1071 /*
1072 * Now send the Fib to the adapter
1073 */
1074 return aac_fib_send(command,
1075 fib,
1076 fibsize,
1077 FsaNormal,
1078 0, 1,
1079 (fib_callback) io_callback,
1080 (void *) cmd);
1081 }
1082
1083 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1084 {
1085 u16 fibsize;
1086 struct aac_read64 *readcmd;
1087 long ret;
1088
1089 aac_fib_init(fib);
1090 readcmd = (struct aac_read64 *) fib_data(fib);
1091 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1092 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1093 readcmd->sector_count = cpu_to_le16(count);
1094 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1095 readcmd->pad = 0;
1096 readcmd->flags = 0;
1097
1098 ret = aac_build_sg64(cmd, &readcmd->sg);
1099 if (ret < 0)
1100 return ret;
1101 fibsize = sizeof(struct aac_read64) +
1102 ((le32_to_cpu(readcmd->sg.count) - 1) *
1103 sizeof (struct sgentry64));
1104 BUG_ON (fibsize > (fib->dev->max_fib_size -
1105 sizeof(struct aac_fibhdr)));
1106 /*
1107 * Now send the Fib to the adapter
1108 */
1109 return aac_fib_send(ContainerCommand64,
1110 fib,
1111 fibsize,
1112 FsaNormal,
1113 0, 1,
1114 (fib_callback) io_callback,
1115 (void *) cmd);
1116 }
1117
1118 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1119 {
1120 u16 fibsize;
1121 struct aac_read *readcmd;
1122 struct aac_dev *dev = fib->dev;
1123 long ret;
1124
1125 aac_fib_init(fib);
1126 readcmd = (struct aac_read *) fib_data(fib);
1127 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1128 readcmd->cid = cpu_to_le32(scmd_id(cmd));
1129 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1130 readcmd->count = cpu_to_le32(count *
1131 dev->fsa_dev[scmd_id(cmd)].block_size);
1132
1133 ret = aac_build_sg(cmd, &readcmd->sg);
1134 if (ret < 0)
1135 return ret;
1136 fibsize = sizeof(struct aac_read) +
1137 ((le32_to_cpu(readcmd->sg.count) - 1) *
1138 sizeof (struct sgentry));
1139 BUG_ON (fibsize > (fib->dev->max_fib_size -
1140 sizeof(struct aac_fibhdr)));
1141 /*
1142 * Now send the Fib to the adapter
1143 */
1144 return aac_fib_send(ContainerCommand,
1145 fib,
1146 fibsize,
1147 FsaNormal,
1148 0, 1,
1149 (fib_callback) io_callback,
1150 (void *) cmd);
1151 }
1152
1153 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1154 {
1155 struct aac_dev *dev = fib->dev;
1156 u16 fibsize, command;
1157 long ret;
1158
1159 aac_fib_init(fib);
1160 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1161 struct aac_raw_io2 *writecmd2;
1162 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1163 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1164 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1165 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1166 writecmd2->byteCount = cpu_to_le32(count *
1167 dev->fsa_dev[scmd_id(cmd)].block_size);
1168 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1169 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1170 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1171 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1172 cpu_to_le16(RIO2_IO_TYPE_WRITE);
1173 ret = aac_build_sgraw2(cmd, writecmd2,
1174 dev->scsi_host_ptr->sg_tablesize);
1175 if (ret < 0)
1176 return ret;
1177 command = ContainerRawIo2;
1178 fibsize = sizeof(struct aac_raw_io2) +
1179 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1180 } else {
1181 struct aac_raw_io *writecmd;
1182 writecmd = (struct aac_raw_io *) fib_data(fib);
1183 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1184 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1185 writecmd->count = cpu_to_le32(count *
1186 dev->fsa_dev[scmd_id(cmd)].block_size);
1187 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1188 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1189 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1190 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1191 cpu_to_le16(RIO_TYPE_WRITE);
1192 writecmd->bpTotal = 0;
1193 writecmd->bpComplete = 0;
1194 ret = aac_build_sgraw(cmd, &writecmd->sg);
1195 if (ret < 0)
1196 return ret;
1197 command = ContainerRawIo;
1198 fibsize = sizeof(struct aac_raw_io) +
1199 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1200 }
1201
1202 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1203 /*
1204 * Now send the Fib to the adapter
1205 */
1206 return aac_fib_send(command,
1207 fib,
1208 fibsize,
1209 FsaNormal,
1210 0, 1,
1211 (fib_callback) io_callback,
1212 (void *) cmd);
1213 }
1214
1215 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1216 {
1217 u16 fibsize;
1218 struct aac_write64 *writecmd;
1219 long ret;
1220
1221 aac_fib_init(fib);
1222 writecmd = (struct aac_write64 *) fib_data(fib);
1223 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1224 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1225 writecmd->sector_count = cpu_to_le16(count);
1226 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1227 writecmd->pad = 0;
1228 writecmd->flags = 0;
1229
1230 ret = aac_build_sg64(cmd, &writecmd->sg);
1231 if (ret < 0)
1232 return ret;
1233 fibsize = sizeof(struct aac_write64) +
1234 ((le32_to_cpu(writecmd->sg.count) - 1) *
1235 sizeof (struct sgentry64));
1236 BUG_ON (fibsize > (fib->dev->max_fib_size -
1237 sizeof(struct aac_fibhdr)));
1238 /*
1239 * Now send the Fib to the adapter
1240 */
1241 return aac_fib_send(ContainerCommand64,
1242 fib,
1243 fibsize,
1244 FsaNormal,
1245 0, 1,
1246 (fib_callback) io_callback,
1247 (void *) cmd);
1248 }
1249
1250 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1251 {
1252 u16 fibsize;
1253 struct aac_write *writecmd;
1254 struct aac_dev *dev = fib->dev;
1255 long ret;
1256
1257 aac_fib_init(fib);
1258 writecmd = (struct aac_write *) fib_data(fib);
1259 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1260 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1261 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1262 writecmd->count = cpu_to_le32(count *
1263 dev->fsa_dev[scmd_id(cmd)].block_size);
1264 writecmd->sg.count = cpu_to_le32(1);
1265 /* ->stable is not used - it did mean which type of write */
1266
1267 ret = aac_build_sg(cmd, &writecmd->sg);
1268 if (ret < 0)
1269 return ret;
1270 fibsize = sizeof(struct aac_write) +
1271 ((le32_to_cpu(writecmd->sg.count) - 1) *
1272 sizeof (struct sgentry));
1273 BUG_ON (fibsize > (fib->dev->max_fib_size -
1274 sizeof(struct aac_fibhdr)));
1275 /*
1276 * Now send the Fib to the adapter
1277 */
1278 return aac_fib_send(ContainerCommand,
1279 fib,
1280 fibsize,
1281 FsaNormal,
1282 0, 1,
1283 (fib_callback) io_callback,
1284 (void *) cmd);
1285 }
1286
1287 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1288 {
1289 struct aac_srb * srbcmd;
1290 u32 flag;
1291 u32 timeout;
1292
1293 aac_fib_init(fib);
1294 switch(cmd->sc_data_direction){
1295 case DMA_TO_DEVICE:
1296 flag = SRB_DataOut;
1297 break;
1298 case DMA_BIDIRECTIONAL:
1299 flag = SRB_DataIn | SRB_DataOut;
1300 break;
1301 case DMA_FROM_DEVICE:
1302 flag = SRB_DataIn;
1303 break;
1304 case DMA_NONE:
1305 default: /* shuts up some versions of gcc */
1306 flag = SRB_NoDataXfer;
1307 break;
1308 }
1309
1310 srbcmd = (struct aac_srb*) fib_data(fib);
1311 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1312 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1313 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1314 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1315 srbcmd->flags = cpu_to_le32(flag);
1316 timeout = cmd->request->timeout/HZ;
1317 if (timeout == 0)
1318 timeout = 1;
1319 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1320 srbcmd->retry_limit = 0; /* Obsolete parameter */
1321 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1322 return srbcmd;
1323 }
1324
1325 static void aac_srb_callback(void *context, struct fib * fibptr);
1326
1327 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1328 {
1329 u16 fibsize;
1330 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1331 long ret;
1332
1333 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1334 if (ret < 0)
1335 return ret;
1336 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1337
1338 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1339 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1340 /*
1341 * Build Scatter/Gather list
1342 */
1343 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1344 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1345 sizeof (struct sgentry64));
1346 BUG_ON (fibsize > (fib->dev->max_fib_size -
1347 sizeof(struct aac_fibhdr)));
1348
1349 /*
1350 * Now send the Fib to the adapter
1351 */
1352 return aac_fib_send(ScsiPortCommand64, fib,
1353 fibsize, FsaNormal, 0, 1,
1354 (fib_callback) aac_srb_callback,
1355 (void *) cmd);
1356 }
1357
1358 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1359 {
1360 u16 fibsize;
1361 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1362 long ret;
1363
1364 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1365 if (ret < 0)
1366 return ret;
1367 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1368
1369 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1370 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1371 /*
1372 * Build Scatter/Gather list
1373 */
1374 fibsize = sizeof (struct aac_srb) +
1375 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1376 sizeof (struct sgentry));
1377 BUG_ON (fibsize > (fib->dev->max_fib_size -
1378 sizeof(struct aac_fibhdr)));
1379
1380 /*
1381 * Now send the Fib to the adapter
1382 */
1383 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1384 (fib_callback) aac_srb_callback, (void *) cmd);
1385 }
1386
1387 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1388 {
1389 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1390 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1391 return FAILED;
1392 return aac_scsi_32(fib, cmd);
1393 }
1394
1395 int aac_get_adapter_info(struct aac_dev* dev)
1396 {
1397 struct fib* fibptr;
1398 int rcode;
1399 u32 tmp;
1400 struct aac_adapter_info *info;
1401 struct aac_bus_info *command;
1402 struct aac_bus_info_response *bus_info;
1403
1404 if (!(fibptr = aac_fib_alloc(dev)))
1405 return -ENOMEM;
1406
1407 aac_fib_init(fibptr);
1408 info = (struct aac_adapter_info *) fib_data(fibptr);
1409 memset(info,0,sizeof(*info));
1410
1411 rcode = aac_fib_send(RequestAdapterInfo,
1412 fibptr,
1413 sizeof(*info),
1414 FsaNormal,
1415 -1, 1, /* First `interrupt' command uses special wait */
1416 NULL,
1417 NULL);
1418
1419 if (rcode < 0) {
1420 /* FIB should be freed only after
1421 * getting the response from the F/W */
1422 if (rcode != -ERESTARTSYS) {
1423 aac_fib_complete(fibptr);
1424 aac_fib_free(fibptr);
1425 }
1426 return rcode;
1427 }
1428 memcpy(&dev->adapter_info, info, sizeof(*info));
1429
1430 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1431 struct aac_supplement_adapter_info * sinfo;
1432
1433 aac_fib_init(fibptr);
1434
1435 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1436
1437 memset(sinfo,0,sizeof(*sinfo));
1438
1439 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1440 fibptr,
1441 sizeof(*sinfo),
1442 FsaNormal,
1443 1, 1,
1444 NULL,
1445 NULL);
1446
1447 if (rcode >= 0)
1448 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
1449 if (rcode == -ERESTARTSYS) {
1450 fibptr = aac_fib_alloc(dev);
1451 if (!fibptr)
1452 return -ENOMEM;
1453 }
1454
1455 }
1456
1457
1458 /*
1459 * GetBusInfo
1460 */
1461
1462 aac_fib_init(fibptr);
1463
1464 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1465
1466 memset(bus_info, 0, sizeof(*bus_info));
1467
1468 command = (struct aac_bus_info *)bus_info;
1469
1470 command->Command = cpu_to_le32(VM_Ioctl);
1471 command->ObjType = cpu_to_le32(FT_DRIVE);
1472 command->MethodId = cpu_to_le32(1);
1473 command->CtlCmd = cpu_to_le32(GetBusInfo);
1474
1475 rcode = aac_fib_send(ContainerCommand,
1476 fibptr,
1477 sizeof (*bus_info),
1478 FsaNormal,
1479 1, 1,
1480 NULL, NULL);
1481
1482 /* reasoned default */
1483 dev->maximum_num_physicals = 16;
1484 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1485 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1486 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1487 }
1488
1489 if (!dev->in_reset) {
1490 char buffer[16];
1491 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1492 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1493 dev->name,
1494 dev->id,
1495 tmp>>24,
1496 (tmp>>16)&0xff,
1497 tmp&0xff,
1498 le32_to_cpu(dev->adapter_info.kernelbuild),
1499 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1500 dev->supplement_adapter_info.BuildDate);
1501 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1502 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1503 dev->name, dev->id,
1504 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1505 le32_to_cpu(dev->adapter_info.monitorbuild));
1506 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1507 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1508 dev->name, dev->id,
1509 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1510 le32_to_cpu(dev->adapter_info.biosbuild));
1511 buffer[0] = '\0';
1512 if (aac_get_serial_number(
1513 shost_to_class(dev->scsi_host_ptr), buffer))
1514 printk(KERN_INFO "%s%d: serial %s",
1515 dev->name, dev->id, buffer);
1516 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1517 printk(KERN_INFO "%s%d: TSID %.*s\n",
1518 dev->name, dev->id,
1519 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1520 dev->supplement_adapter_info.VpdInfo.Tsid);
1521 }
1522 if (!aac_check_reset || ((aac_check_reset == 1) &&
1523 (dev->supplement_adapter_info.SupportedOptions2 &
1524 AAC_OPTION_IGNORE_RESET))) {
1525 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1526 dev->name, dev->id);
1527 }
1528 }
1529
1530 dev->cache_protected = 0;
1531 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1532 AAC_FEATURE_JBOD) != 0);
1533 dev->nondasd_support = 0;
1534 dev->raid_scsi_mode = 0;
1535 if(dev->adapter_info.options & AAC_OPT_NONDASD)
1536 dev->nondasd_support = 1;
1537
1538 /*
1539 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1540 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1541 * force nondasd support on. If we decide to allow the non-dasd flag
1542 * additional changes changes will have to be made to support
1543 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1544 * changed to support the new dev->raid_scsi_mode flag instead of
1545 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1546 * function aac_detect will have to be modified where it sets up the
1547 * max number of channels based on the aac->nondasd_support flag only.
1548 */
1549 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1550 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1551 dev->nondasd_support = 1;
1552 dev->raid_scsi_mode = 1;
1553 }
1554 if (dev->raid_scsi_mode != 0)
1555 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1556 dev->name, dev->id);
1557
1558 if (nondasd != -1)
1559 dev->nondasd_support = (nondasd!=0);
1560 if (dev->nondasd_support && !dev->in_reset)
1561 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1562
1563 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
1564 dev->needs_dac = 1;
1565 dev->dac_support = 0;
1566 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
1567 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
1568 if (!dev->in_reset)
1569 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1570 dev->name, dev->id);
1571 dev->dac_support = 1;
1572 }
1573
1574 if(dacmode != -1) {
1575 dev->dac_support = (dacmode!=0);
1576 }
1577
1578 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1579 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
1580 & AAC_QUIRK_SCSI_32)) {
1581 dev->nondasd_support = 0;
1582 dev->jbod = 0;
1583 expose_physicals = 0;
1584 }
1585
1586 if(dev->dac_support != 0) {
1587 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) &&
1588 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
1589 if (!dev->in_reset)
1590 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1591 dev->name, dev->id);
1592 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) &&
1593 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
1594 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1595 dev->name, dev->id);
1596 dev->dac_support = 0;
1597 } else {
1598 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1599 dev->name, dev->id);
1600 rcode = -ENOMEM;
1601 }
1602 }
1603 /*
1604 * Deal with configuring for the individualized limits of each packet
1605 * interface.
1606 */
1607 dev->a_ops.adapter_scsi = (dev->dac_support)
1608 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1609 ? aac_scsi_32_64
1610 : aac_scsi_64)
1611 : aac_scsi_32;
1612 if (dev->raw_io_interface) {
1613 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1614 ? aac_bounds_64
1615 : aac_bounds_32;
1616 dev->a_ops.adapter_read = aac_read_raw_io;
1617 dev->a_ops.adapter_write = aac_write_raw_io;
1618 } else {
1619 dev->a_ops.adapter_bounds = aac_bounds_32;
1620 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1621 sizeof(struct aac_fibhdr) -
1622 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1623 sizeof(struct sgentry);
1624 if (dev->dac_support) {
1625 dev->a_ops.adapter_read = aac_read_block64;
1626 dev->a_ops.adapter_write = aac_write_block64;
1627 /*
1628 * 38 scatter gather elements
1629 */
1630 dev->scsi_host_ptr->sg_tablesize =
1631 (dev->max_fib_size -
1632 sizeof(struct aac_fibhdr) -
1633 sizeof(struct aac_write64) +
1634 sizeof(struct sgentry64)) /
1635 sizeof(struct sgentry64);
1636 } else {
1637 dev->a_ops.adapter_read = aac_read_block;
1638 dev->a_ops.adapter_write = aac_write_block;
1639 }
1640 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1641 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1642 /*
1643 * Worst case size that could cause sg overflow when
1644 * we break up SG elements that are larger than 64KB.
1645 * Would be nice if we could tell the SCSI layer what
1646 * the maximum SG element size can be. Worst case is
1647 * (sg_tablesize-1) 4KB elements with one 64KB
1648 * element.
1649 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1650 */
1651 dev->scsi_host_ptr->max_sectors =
1652 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1653 }
1654 }
1655 /* FIB should be freed only after getting the response from the F/W */
1656 if (rcode != -ERESTARTSYS) {
1657 aac_fib_complete(fibptr);
1658 aac_fib_free(fibptr);
1659 }
1660
1661 return rcode;
1662 }
1663
1664
1665 static void io_callback(void *context, struct fib * fibptr)
1666 {
1667 struct aac_dev *dev;
1668 struct aac_read_reply *readreply;
1669 struct scsi_cmnd *scsicmd;
1670 u32 cid;
1671
1672 scsicmd = (struct scsi_cmnd *) context;
1673
1674 if (!aac_valid_context(scsicmd, fibptr))
1675 return;
1676
1677 dev = fibptr->dev;
1678 cid = scmd_id(scsicmd);
1679
1680 if (nblank(dprintk(x))) {
1681 u64 lba;
1682 switch (scsicmd->cmnd[0]) {
1683 case WRITE_6:
1684 case READ_6:
1685 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1686 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1687 break;
1688 case WRITE_16:
1689 case READ_16:
1690 lba = ((u64)scsicmd->cmnd[2] << 56) |
1691 ((u64)scsicmd->cmnd[3] << 48) |
1692 ((u64)scsicmd->cmnd[4] << 40) |
1693 ((u64)scsicmd->cmnd[5] << 32) |
1694 ((u64)scsicmd->cmnd[6] << 24) |
1695 (scsicmd->cmnd[7] << 16) |
1696 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1697 break;
1698 case WRITE_12:
1699 case READ_12:
1700 lba = ((u64)scsicmd->cmnd[2] << 24) |
1701 (scsicmd->cmnd[3] << 16) |
1702 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1703 break;
1704 default:
1705 lba = ((u64)scsicmd->cmnd[2] << 24) |
1706 (scsicmd->cmnd[3] << 16) |
1707 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1708 break;
1709 }
1710 printk(KERN_DEBUG
1711 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1712 smp_processor_id(), (unsigned long long)lba, jiffies);
1713 }
1714
1715 BUG_ON(fibptr == NULL);
1716
1717 scsi_dma_unmap(scsicmd);
1718
1719 readreply = (struct aac_read_reply *)fib_data(fibptr);
1720 switch (le32_to_cpu(readreply->status)) {
1721 case ST_OK:
1722 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1723 SAM_STAT_GOOD;
1724 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
1725 break;
1726 case ST_NOT_READY:
1727 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1728 SAM_STAT_CHECK_CONDITION;
1729 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
1730 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
1731 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1732 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1733 SCSI_SENSE_BUFFERSIZE));
1734 break;
1735 default:
1736 #ifdef AAC_DETAILED_STATUS_INFO
1737 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1738 le32_to_cpu(readreply->status));
1739 #endif
1740 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1741 SAM_STAT_CHECK_CONDITION;
1742 set_sense(&dev->fsa_dev[cid].sense_data,
1743 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1744 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1745 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1746 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1747 SCSI_SENSE_BUFFERSIZE));
1748 break;
1749 }
1750 aac_fib_complete(fibptr);
1751 aac_fib_free(fibptr);
1752
1753 scsicmd->scsi_done(scsicmd);
1754 }
1755
1756 static int aac_read(struct scsi_cmnd * scsicmd)
1757 {
1758 u64 lba;
1759 u32 count;
1760 int status;
1761 struct aac_dev *dev;
1762 struct fib * cmd_fibcontext;
1763 int cid;
1764
1765 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1766 /*
1767 * Get block address and transfer length
1768 */
1769 switch (scsicmd->cmnd[0]) {
1770 case READ_6:
1771 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1772
1773 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1774 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1775 count = scsicmd->cmnd[4];
1776
1777 if (count == 0)
1778 count = 256;
1779 break;
1780 case READ_16:
1781 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1782
1783 lba = ((u64)scsicmd->cmnd[2] << 56) |
1784 ((u64)scsicmd->cmnd[3] << 48) |
1785 ((u64)scsicmd->cmnd[4] << 40) |
1786 ((u64)scsicmd->cmnd[5] << 32) |
1787 ((u64)scsicmd->cmnd[6] << 24) |
1788 (scsicmd->cmnd[7] << 16) |
1789 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1790 count = (scsicmd->cmnd[10] << 24) |
1791 (scsicmd->cmnd[11] << 16) |
1792 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1793 break;
1794 case READ_12:
1795 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1796
1797 lba = ((u64)scsicmd->cmnd[2] << 24) |
1798 (scsicmd->cmnd[3] << 16) |
1799 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1800 count = (scsicmd->cmnd[6] << 24) |
1801 (scsicmd->cmnd[7] << 16) |
1802 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1803 break;
1804 default:
1805 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1806
1807 lba = ((u64)scsicmd->cmnd[2] << 24) |
1808 (scsicmd->cmnd[3] << 16) |
1809 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1810 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1811 break;
1812 }
1813
1814 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1815 cid = scmd_id(scsicmd);
1816 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1817 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1818 SAM_STAT_CHECK_CONDITION;
1819 set_sense(&dev->fsa_dev[cid].sense_data,
1820 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1821 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1822 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1823 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1824 SCSI_SENSE_BUFFERSIZE));
1825 scsicmd->scsi_done(scsicmd);
1826 return 1;
1827 }
1828
1829 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1830 smp_processor_id(), (unsigned long long)lba, jiffies));
1831 if (aac_adapter_bounds(dev,scsicmd,lba))
1832 return 0;
1833 /*
1834 * Alocate and initialize a Fib
1835 */
1836 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1837 printk(KERN_WARNING "aac_read: fib allocation failed\n");
1838 return -1;
1839 }
1840
1841 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1842
1843 /*
1844 * Check that the command queued to the controller
1845 */
1846 if (status == -EINPROGRESS) {
1847 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1848 return 0;
1849 }
1850
1851 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1852 /*
1853 * For some reason, the Fib didn't queue, return QUEUE_FULL
1854 */
1855 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1856 scsicmd->scsi_done(scsicmd);
1857 aac_fib_complete(cmd_fibcontext);
1858 aac_fib_free(cmd_fibcontext);
1859 return 0;
1860 }
1861
1862 static int aac_write(struct scsi_cmnd * scsicmd)
1863 {
1864 u64 lba;
1865 u32 count;
1866 int fua;
1867 int status;
1868 struct aac_dev *dev;
1869 struct fib * cmd_fibcontext;
1870 int cid;
1871
1872 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1873 /*
1874 * Get block address and transfer length
1875 */
1876 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1877 {
1878 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1879 count = scsicmd->cmnd[4];
1880 if (count == 0)
1881 count = 256;
1882 fua = 0;
1883 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1884 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1885
1886 lba = ((u64)scsicmd->cmnd[2] << 56) |
1887 ((u64)scsicmd->cmnd[3] << 48) |
1888 ((u64)scsicmd->cmnd[4] << 40) |
1889 ((u64)scsicmd->cmnd[5] << 32) |
1890 ((u64)scsicmd->cmnd[6] << 24) |
1891 (scsicmd->cmnd[7] << 16) |
1892 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1893 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1894 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1895 fua = scsicmd->cmnd[1] & 0x8;
1896 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1897 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1898
1899 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1900 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1901 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1902 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1903 fua = scsicmd->cmnd[1] & 0x8;
1904 } else {
1905 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1906 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1907 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1908 fua = scsicmd->cmnd[1] & 0x8;
1909 }
1910
1911 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1912 cid = scmd_id(scsicmd);
1913 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1914 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1915 SAM_STAT_CHECK_CONDITION;
1916 set_sense(&dev->fsa_dev[cid].sense_data,
1917 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1918 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1919 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1920 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1921 SCSI_SENSE_BUFFERSIZE));
1922 scsicmd->scsi_done(scsicmd);
1923 return 1;
1924 }
1925
1926 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1927 smp_processor_id(), (unsigned long long)lba, jiffies));
1928 if (aac_adapter_bounds(dev,scsicmd,lba))
1929 return 0;
1930 /*
1931 * Allocate and initialize a Fib then setup a BlockWrite command
1932 */
1933 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1934 /* FIB temporarily unavailable,not catastrophic failure */
1935
1936 /* scsicmd->result = DID_ERROR << 16;
1937 * scsicmd->scsi_done(scsicmd);
1938 * return 0;
1939 */
1940 printk(KERN_WARNING "aac_write: fib allocation failed\n");
1941 return -1;
1942 }
1943
1944 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1945
1946 /*
1947 * Check that the command queued to the controller
1948 */
1949 if (status == -EINPROGRESS) {
1950 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1951 return 0;
1952 }
1953
1954 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1955 /*
1956 * For some reason, the Fib didn't queue, return QUEUE_FULL
1957 */
1958 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1959 scsicmd->scsi_done(scsicmd);
1960
1961 aac_fib_complete(cmd_fibcontext);
1962 aac_fib_free(cmd_fibcontext);
1963 return 0;
1964 }
1965
1966 static void synchronize_callback(void *context, struct fib *fibptr)
1967 {
1968 struct aac_synchronize_reply *synchronizereply;
1969 struct scsi_cmnd *cmd;
1970
1971 cmd = context;
1972
1973 if (!aac_valid_context(cmd, fibptr))
1974 return;
1975
1976 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1977 smp_processor_id(), jiffies));
1978 BUG_ON(fibptr == NULL);
1979
1980
1981 synchronizereply = fib_data(fibptr);
1982 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1983 cmd->result = DID_OK << 16 |
1984 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1985 else {
1986 struct scsi_device *sdev = cmd->device;
1987 struct aac_dev *dev = fibptr->dev;
1988 u32 cid = sdev_id(sdev);
1989 printk(KERN_WARNING
1990 "synchronize_callback: synchronize failed, status = %d\n",
1991 le32_to_cpu(synchronizereply->status));
1992 cmd->result = DID_OK << 16 |
1993 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1994 set_sense(&dev->fsa_dev[cid].sense_data,
1995 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1996 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1997 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1998 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1999 SCSI_SENSE_BUFFERSIZE));
2000 }
2001
2002 aac_fib_complete(fibptr);
2003 aac_fib_free(fibptr);
2004 cmd->scsi_done(cmd);
2005 }
2006
2007 static int aac_synchronize(struct scsi_cmnd *scsicmd)
2008 {
2009 int status;
2010 struct fib *cmd_fibcontext;
2011 struct aac_synchronize *synchronizecmd;
2012 struct scsi_cmnd *cmd;
2013 struct scsi_device *sdev = scsicmd->device;
2014 int active = 0;
2015 struct aac_dev *aac;
2016 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2017 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2018 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2019 unsigned long flags;
2020
2021 /*
2022 * Wait for all outstanding queued commands to complete to this
2023 * specific target (block).
2024 */
2025 spin_lock_irqsave(&sdev->list_lock, flags);
2026 list_for_each_entry(cmd, &sdev->cmd_list, list)
2027 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2028 u64 cmnd_lba;
2029 u32 cmnd_count;
2030
2031 if (cmd->cmnd[0] == WRITE_6) {
2032 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2033 (cmd->cmnd[2] << 8) |
2034 cmd->cmnd[3];
2035 cmnd_count = cmd->cmnd[4];
2036 if (cmnd_count == 0)
2037 cmnd_count = 256;
2038 } else if (cmd->cmnd[0] == WRITE_16) {
2039 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2040 ((u64)cmd->cmnd[3] << 48) |
2041 ((u64)cmd->cmnd[4] << 40) |
2042 ((u64)cmd->cmnd[5] << 32) |
2043 ((u64)cmd->cmnd[6] << 24) |
2044 (cmd->cmnd[7] << 16) |
2045 (cmd->cmnd[8] << 8) |
2046 cmd->cmnd[9];
2047 cmnd_count = (cmd->cmnd[10] << 24) |
2048 (cmd->cmnd[11] << 16) |
2049 (cmd->cmnd[12] << 8) |
2050 cmd->cmnd[13];
2051 } else if (cmd->cmnd[0] == WRITE_12) {
2052 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2053 (cmd->cmnd[3] << 16) |
2054 (cmd->cmnd[4] << 8) |
2055 cmd->cmnd[5];
2056 cmnd_count = (cmd->cmnd[6] << 24) |
2057 (cmd->cmnd[7] << 16) |
2058 (cmd->cmnd[8] << 8) |
2059 cmd->cmnd[9];
2060 } else if (cmd->cmnd[0] == WRITE_10) {
2061 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2062 (cmd->cmnd[3] << 16) |
2063 (cmd->cmnd[4] << 8) |
2064 cmd->cmnd[5];
2065 cmnd_count = (cmd->cmnd[7] << 8) |
2066 cmd->cmnd[8];
2067 } else
2068 continue;
2069 if (((cmnd_lba + cmnd_count) < lba) ||
2070 (count && ((lba + count) < cmnd_lba)))
2071 continue;
2072 ++active;
2073 break;
2074 }
2075
2076 spin_unlock_irqrestore(&sdev->list_lock, flags);
2077
2078 /*
2079 * Yield the processor (requeue for later)
2080 */
2081 if (active)
2082 return SCSI_MLQUEUE_DEVICE_BUSY;
2083
2084 aac = (struct aac_dev *)sdev->host->hostdata;
2085 if (aac->in_reset)
2086 return SCSI_MLQUEUE_HOST_BUSY;
2087
2088 /*
2089 * Allocate and initialize a Fib
2090 */
2091 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
2092 return SCSI_MLQUEUE_HOST_BUSY;
2093
2094 aac_fib_init(cmd_fibcontext);
2095
2096 synchronizecmd = fib_data(cmd_fibcontext);
2097 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2098 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
2099 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
2100 synchronizecmd->count =
2101 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2102
2103 /*
2104 * Now send the Fib to the adapter
2105 */
2106 status = aac_fib_send(ContainerCommand,
2107 cmd_fibcontext,
2108 sizeof(struct aac_synchronize),
2109 FsaNormal,
2110 0, 1,
2111 (fib_callback)synchronize_callback,
2112 (void *)scsicmd);
2113
2114 /*
2115 * Check that the command queued to the controller
2116 */
2117 if (status == -EINPROGRESS) {
2118 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2119 return 0;
2120 }
2121
2122 printk(KERN_WARNING
2123 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2124 aac_fib_complete(cmd_fibcontext);
2125 aac_fib_free(cmd_fibcontext);
2126 return SCSI_MLQUEUE_HOST_BUSY;
2127 }
2128
2129 static void aac_start_stop_callback(void *context, struct fib *fibptr)
2130 {
2131 struct scsi_cmnd *scsicmd = context;
2132
2133 if (!aac_valid_context(scsicmd, fibptr))
2134 return;
2135
2136 BUG_ON(fibptr == NULL);
2137
2138 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2139
2140 aac_fib_complete(fibptr);
2141 aac_fib_free(fibptr);
2142 scsicmd->scsi_done(scsicmd);
2143 }
2144
2145 static int aac_start_stop(struct scsi_cmnd *scsicmd)
2146 {
2147 int status;
2148 struct fib *cmd_fibcontext;
2149 struct aac_power_management *pmcmd;
2150 struct scsi_device *sdev = scsicmd->device;
2151 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2152
2153 if (!(aac->supplement_adapter_info.SupportedOptions2 &
2154 AAC_OPTION_POWER_MANAGEMENT)) {
2155 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2156 SAM_STAT_GOOD;
2157 scsicmd->scsi_done(scsicmd);
2158 return 0;
2159 }
2160
2161 if (aac->in_reset)
2162 return SCSI_MLQUEUE_HOST_BUSY;
2163
2164 /*
2165 * Allocate and initialize a Fib
2166 */
2167 cmd_fibcontext = aac_fib_alloc(aac);
2168 if (!cmd_fibcontext)
2169 return SCSI_MLQUEUE_HOST_BUSY;
2170
2171 aac_fib_init(cmd_fibcontext);
2172
2173 pmcmd = fib_data(cmd_fibcontext);
2174 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2175 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2176 /* Eject bit ignored, not relevant */
2177 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2178 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2179 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2180 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2181 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2182
2183 /*
2184 * Now send the Fib to the adapter
2185 */
2186 status = aac_fib_send(ContainerCommand,
2187 cmd_fibcontext,
2188 sizeof(struct aac_power_management),
2189 FsaNormal,
2190 0, 1,
2191 (fib_callback)aac_start_stop_callback,
2192 (void *)scsicmd);
2193
2194 /*
2195 * Check that the command queued to the controller
2196 */
2197 if (status == -EINPROGRESS) {
2198 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2199 return 0;
2200 }
2201
2202 aac_fib_complete(cmd_fibcontext);
2203 aac_fib_free(cmd_fibcontext);
2204 return SCSI_MLQUEUE_HOST_BUSY;
2205 }
2206
2207 /**
2208 * aac_scsi_cmd() - Process SCSI command
2209 * @scsicmd: SCSI command block
2210 *
2211 * Emulate a SCSI command and queue the required request for the
2212 * aacraid firmware.
2213 */
2214
2215 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2216 {
2217 u32 cid;
2218 struct Scsi_Host *host = scsicmd->device->host;
2219 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2220 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
2221
2222 if (fsa_dev_ptr == NULL)
2223 return -1;
2224 /*
2225 * If the bus, id or lun is out of range, return fail
2226 * Test does not apply to ID 16, the pseudo id for the controller
2227 * itself.
2228 */
2229 cid = scmd_id(scsicmd);
2230 if (cid != host->this_id) {
2231 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2232 if((cid >= dev->maximum_num_containers) ||
2233 (scsicmd->device->lun != 0)) {
2234 scsicmd->result = DID_NO_CONNECT << 16;
2235 scsicmd->scsi_done(scsicmd);
2236 return 0;
2237 }
2238
2239 /*
2240 * If the target container doesn't exist, it may have
2241 * been newly created
2242 */
2243 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2244 (fsa_dev_ptr[cid].sense_data.sense_key ==
2245 NOT_READY)) {
2246 switch (scsicmd->cmnd[0]) {
2247 case SERVICE_ACTION_IN_16:
2248 if (!(dev->raw_io_interface) ||
2249 !(dev->raw_io_64) ||
2250 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2251 break;
2252 case INQUIRY:
2253 case READ_CAPACITY:
2254 case TEST_UNIT_READY:
2255 if (dev->in_reset)
2256 return -1;
2257 return _aac_probe_container(scsicmd,
2258 aac_probe_container_callback2);
2259 default:
2260 break;
2261 }
2262 }
2263 } else { /* check for physical non-dasd devices */
2264 if (dev->nondasd_support || expose_physicals ||
2265 dev->jbod) {
2266 if (dev->in_reset)
2267 return -1;
2268 return aac_send_srb_fib(scsicmd);
2269 } else {
2270 scsicmd->result = DID_NO_CONNECT << 16;
2271 scsicmd->scsi_done(scsicmd);
2272 return 0;
2273 }
2274 }
2275 }
2276 /*
2277 * else Command for the controller itself
2278 */
2279 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
2280 (scsicmd->cmnd[0] != TEST_UNIT_READY))
2281 {
2282 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2283 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2284 set_sense(&dev->fsa_dev[cid].sense_data,
2285 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2286 ASENCODE_INVALID_COMMAND, 0, 0);
2287 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2288 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2289 SCSI_SENSE_BUFFERSIZE));
2290 scsicmd->scsi_done(scsicmd);
2291 return 0;
2292 }
2293
2294
2295 /* Handle commands here that don't really require going out to the adapter */
2296 switch (scsicmd->cmnd[0]) {
2297 case INQUIRY:
2298 {
2299 struct inquiry_data inq_data;
2300
2301 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
2302 memset(&inq_data, 0, sizeof (struct inquiry_data));
2303
2304 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
2305 char *arr = (char *)&inq_data;
2306
2307 /* EVPD bit set */
2308 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2309 INQD_PDT_PROC : INQD_PDT_DA;
2310 if (scsicmd->cmnd[2] == 0) {
2311 /* supported vital product data pages */
2312 arr[3] = 2;
2313 arr[4] = 0x0;
2314 arr[5] = 0x80;
2315 arr[1] = scsicmd->cmnd[2];
2316 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2317 sizeof(inq_data));
2318 scsicmd->result = DID_OK << 16 |
2319 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2320 } else if (scsicmd->cmnd[2] == 0x80) {
2321 /* unit serial number page */
2322 arr[3] = setinqserial(dev, &arr[4],
2323 scmd_id(scsicmd));
2324 arr[1] = scsicmd->cmnd[2];
2325 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2326 sizeof(inq_data));
2327 if (aac_wwn != 2)
2328 return aac_get_container_serial(
2329 scsicmd);
2330 /* SLES 10 SP1 special */
2331 scsicmd->result = DID_OK << 16 |
2332 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2333 } else {
2334 /* vpd page not implemented */
2335 scsicmd->result = DID_OK << 16 |
2336 COMMAND_COMPLETE << 8 |
2337 SAM_STAT_CHECK_CONDITION;
2338 set_sense(&dev->fsa_dev[cid].sense_data,
2339 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2340 ASENCODE_NO_SENSE, 7, 2);
2341 memcpy(scsicmd->sense_buffer,
2342 &dev->fsa_dev[cid].sense_data,
2343 min_t(size_t,
2344 sizeof(dev->fsa_dev[cid].sense_data),
2345 SCSI_SENSE_BUFFERSIZE));
2346 }
2347 scsicmd->scsi_done(scsicmd);
2348 return 0;
2349 }
2350 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
2351 inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
2352 inq_data.inqd_len = 31;
2353 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2354 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
2355 /*
2356 * Set the Vendor, Product, and Revision Level
2357 * see: <vendor>.c i.e. aac.c
2358 */
2359 if (cid == host->this_id) {
2360 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2361 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2362 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2363 sizeof(inq_data));
2364 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2365 scsicmd->scsi_done(scsicmd);
2366 return 0;
2367 }
2368 if (dev->in_reset)
2369 return -1;
2370 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2371 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2372 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
2373 return aac_get_container_name(scsicmd);
2374 }
2375 case SERVICE_ACTION_IN_16:
2376 if (!(dev->raw_io_interface) ||
2377 !(dev->raw_io_64) ||
2378 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2379 break;
2380 {
2381 u64 capacity;
2382 char cp[13];
2383 unsigned int alloc_len;
2384
2385 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2386 capacity = fsa_dev_ptr[cid].size - 1;
2387 cp[0] = (capacity >> 56) & 0xff;
2388 cp[1] = (capacity >> 48) & 0xff;
2389 cp[2] = (capacity >> 40) & 0xff;
2390 cp[3] = (capacity >> 32) & 0xff;
2391 cp[4] = (capacity >> 24) & 0xff;
2392 cp[5] = (capacity >> 16) & 0xff;
2393 cp[6] = (capacity >> 8) & 0xff;
2394 cp[7] = (capacity >> 0) & 0xff;
2395 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2396 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2397 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2398 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
2399 cp[12] = 0;
2400
2401 alloc_len = ((scsicmd->cmnd[10] << 24)
2402 + (scsicmd->cmnd[11] << 16)
2403 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2404
2405 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
2406 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
2407 if (alloc_len < scsi_bufflen(scsicmd))
2408 scsi_set_resid(scsicmd,
2409 scsi_bufflen(scsicmd) - alloc_len);
2410
2411 /* Do not cache partition table for arrays */
2412 scsicmd->device->removable = 1;
2413
2414 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2415 scsicmd->scsi_done(scsicmd);
2416
2417 return 0;
2418 }
2419
2420 case READ_CAPACITY:
2421 {
2422 u32 capacity;
2423 char cp[8];
2424
2425 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
2426 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2427 capacity = fsa_dev_ptr[cid].size - 1;
2428 else
2429 capacity = (u32)-1;
2430
2431 cp[0] = (capacity >> 24) & 0xff;
2432 cp[1] = (capacity >> 16) & 0xff;
2433 cp[2] = (capacity >> 8) & 0xff;
2434 cp[3] = (capacity >> 0) & 0xff;
2435 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2436 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2437 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2438 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
2439 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
2440 /* Do not cache partition table for arrays */
2441 scsicmd->device->removable = 1;
2442 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2443 SAM_STAT_GOOD;
2444 scsicmd->scsi_done(scsicmd);
2445
2446 return 0;
2447 }
2448
2449 case MODE_SENSE:
2450 {
2451 int mode_buf_length = 4;
2452 u32 capacity;
2453 aac_modep_data mpd;
2454
2455 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2456 capacity = fsa_dev_ptr[cid].size - 1;
2457 else
2458 capacity = (u32)-1;
2459
2460 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
2461 memset((char *)&mpd, 0, sizeof(aac_modep_data));
2462
2463 /* Mode data length */
2464 mpd.hd.data_length = sizeof(mpd.hd) - 1;
2465 /* Medium type - default */
2466 mpd.hd.med_type = 0;
2467 /* Device-specific param,
2468 bit 8: 0/1 = write enabled/protected
2469 bit 4: 0/1 = FUA enabled */
2470 mpd.hd.dev_par = 0;
2471
2472 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2473 mpd.hd.dev_par = 0x10;
2474 if (scsicmd->cmnd[1] & 0x8)
2475 mpd.hd.bd_length = 0; /* Block descriptor length */
2476 else {
2477 mpd.hd.bd_length = sizeof(mpd.bd);
2478 mpd.hd.data_length += mpd.hd.bd_length;
2479 mpd.bd.block_length[0] =
2480 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2481 mpd.bd.block_length[1] =
2482 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2483 mpd.bd.block_length[2] =
2484 fsa_dev_ptr[cid].block_size & 0xff;
2485 if (capacity > 0xffffff) {
2486 mpd.bd.block_count[0] = 0xff;
2487 mpd.bd.block_count[1] = 0xff;
2488 mpd.bd.block_count[2] = 0xff;
2489 } else {
2490 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
2491 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
2492 mpd.bd.block_count[2] = capacity & 0xff;
2493 }
2494 }
2495 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2496 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2497 mpd.hd.data_length += 3;
2498 mpd.mpc_buf[0] = 8;
2499 mpd.mpc_buf[1] = 1;
2500 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
2501 ? 0 : 0x04; /* WCE */
2502 mode_buf_length = sizeof(mpd);
2503 if (mode_buf_length > scsicmd->cmnd[4])
2504 mode_buf_length = scsicmd->cmnd[4];
2505 }
2506 scsi_sg_copy_from_buffer(scsicmd,
2507 (char *)&mpd,
2508 mode_buf_length);
2509 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2510 scsicmd->scsi_done(scsicmd);
2511
2512 return 0;
2513 }
2514 case MODE_SENSE_10:
2515 {
2516 u32 capacity;
2517 int mode_buf_length = 8;
2518 aac_modep10_data mpd10;
2519
2520 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2521 capacity = fsa_dev_ptr[cid].size - 1;
2522 else
2523 capacity = (u32)-1;
2524
2525 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
2526 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
2527 /* Mode data length (MSB) */
2528 mpd10.hd.data_length[0] = 0;
2529 /* Mode data length (LSB) */
2530 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
2531 /* Medium type - default */
2532 mpd10.hd.med_type = 0;
2533 /* Device-specific param,
2534 bit 8: 0/1 = write enabled/protected
2535 bit 4: 0/1 = FUA enabled */
2536 mpd10.hd.dev_par = 0;
2537
2538 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2539 mpd10.hd.dev_par = 0x10;
2540 mpd10.hd.rsrvd[0] = 0; /* reserved */
2541 mpd10.hd.rsrvd[1] = 0; /* reserved */
2542 if (scsicmd->cmnd[1] & 0x8) {
2543 /* Block descriptor length (MSB) */
2544 mpd10.hd.bd_length[0] = 0;
2545 /* Block descriptor length (LSB) */
2546 mpd10.hd.bd_length[1] = 0;
2547 } else {
2548 mpd10.hd.bd_length[0] = 0;
2549 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
2550
2551 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
2552
2553 mpd10.bd.block_length[0] =
2554 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2555 mpd10.bd.block_length[1] =
2556 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2557 mpd10.bd.block_length[2] =
2558 fsa_dev_ptr[cid].block_size & 0xff;
2559
2560 if (capacity > 0xffffff) {
2561 mpd10.bd.block_count[0] = 0xff;
2562 mpd10.bd.block_count[1] = 0xff;
2563 mpd10.bd.block_count[2] = 0xff;
2564 } else {
2565 mpd10.bd.block_count[0] =
2566 (capacity >> 16) & 0xff;
2567 mpd10.bd.block_count[1] =
2568 (capacity >> 8) & 0xff;
2569 mpd10.bd.block_count[2] =
2570 capacity & 0xff;
2571 }
2572 }
2573 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2574 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2575 mpd10.hd.data_length[1] += 3;
2576 mpd10.mpc_buf[0] = 8;
2577 mpd10.mpc_buf[1] = 1;
2578 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
2579 ? 0 : 0x04; /* WCE */
2580 mode_buf_length = sizeof(mpd10);
2581 if (mode_buf_length > scsicmd->cmnd[8])
2582 mode_buf_length = scsicmd->cmnd[8];
2583 }
2584 scsi_sg_copy_from_buffer(scsicmd,
2585 (char *)&mpd10,
2586 mode_buf_length);
2587
2588 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2589 scsicmd->scsi_done(scsicmd);
2590
2591 return 0;
2592 }
2593 case REQUEST_SENSE:
2594 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2595 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2596 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2597 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2598 scsicmd->scsi_done(scsicmd);
2599 return 0;
2600
2601 case ALLOW_MEDIUM_REMOVAL:
2602 dprintk((KERN_DEBUG "LOCK command.\n"));
2603 if (scsicmd->cmnd[4])
2604 fsa_dev_ptr[cid].locked = 1;
2605 else
2606 fsa_dev_ptr[cid].locked = 0;
2607
2608 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2609 scsicmd->scsi_done(scsicmd);
2610 return 0;
2611 /*
2612 * These commands are all No-Ops
2613 */
2614 case TEST_UNIT_READY:
2615 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
2616 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2617 SAM_STAT_CHECK_CONDITION;
2618 set_sense(&dev->fsa_dev[cid].sense_data,
2619 NOT_READY, SENCODE_BECOMING_READY,
2620 ASENCODE_BECOMING_READY, 0, 0);
2621 memcpy(scsicmd->sense_buffer,
2622 &dev->fsa_dev[cid].sense_data,
2623 min_t(size_t,
2624 sizeof(dev->fsa_dev[cid].sense_data),
2625 SCSI_SENSE_BUFFERSIZE));
2626 scsicmd->scsi_done(scsicmd);
2627 return 0;
2628 }
2629 /* FALLTHRU */
2630 case RESERVE:
2631 case RELEASE:
2632 case REZERO_UNIT:
2633 case REASSIGN_BLOCKS:
2634 case SEEK_10:
2635 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2636 scsicmd->scsi_done(scsicmd);
2637 return 0;
2638
2639 case START_STOP:
2640 return aac_start_stop(scsicmd);
2641 }
2642
2643 switch (scsicmd->cmnd[0])
2644 {
2645 case READ_6:
2646 case READ_10:
2647 case READ_12:
2648 case READ_16:
2649 if (dev->in_reset)
2650 return -1;
2651 /*
2652 * Hack to keep track of ordinal number of the device that
2653 * corresponds to a container. Needed to convert
2654 * containers to /dev/sd device names
2655 */
2656
2657 if (scsicmd->request->rq_disk)
2658 strlcpy(fsa_dev_ptr[cid].devname,
2659 scsicmd->request->rq_disk->disk_name,
2660 min(sizeof(fsa_dev_ptr[cid].devname),
2661 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2662
2663 return aac_read(scsicmd);
2664
2665 case WRITE_6:
2666 case WRITE_10:
2667 case WRITE_12:
2668 case WRITE_16:
2669 if (dev->in_reset)
2670 return -1;
2671 return aac_write(scsicmd);
2672
2673 case SYNCHRONIZE_CACHE:
2674 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2675 scsicmd->result = DID_OK << 16 |
2676 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2677 scsicmd->scsi_done(scsicmd);
2678 return 0;
2679 }
2680 /* Issue FIB to tell Firmware to flush it's cache */
2681 if ((aac_cache & 6) != 2)
2682 return aac_synchronize(scsicmd);
2683 /* FALLTHRU */
2684 default:
2685 /*
2686 * Unhandled commands
2687 */
2688 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2689 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2690 set_sense(&dev->fsa_dev[cid].sense_data,
2691 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2692 ASENCODE_INVALID_COMMAND, 0, 0);
2693 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2694 min_t(size_t,
2695 sizeof(dev->fsa_dev[cid].sense_data),
2696 SCSI_SENSE_BUFFERSIZE));
2697 scsicmd->scsi_done(scsicmd);
2698 return 0;
2699 }
2700 }
2701
2702 static int query_disk(struct aac_dev *dev, void __user *arg)
2703 {
2704 struct aac_query_disk qd;
2705 struct fsa_dev_info *fsa_dev_ptr;
2706
2707 fsa_dev_ptr = dev->fsa_dev;
2708 if (!fsa_dev_ptr)
2709 return -EBUSY;
2710 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2711 return -EFAULT;
2712 if (qd.cnum == -1)
2713 qd.cnum = qd.id;
2714 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2715 {
2716 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2717 return -EINVAL;
2718 qd.instance = dev->scsi_host_ptr->host_no;
2719 qd.bus = 0;
2720 qd.id = CONTAINER_TO_ID(qd.cnum);
2721 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2722 }
2723 else return -EINVAL;
2724
2725 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
2726 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2727 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2728
2729 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2730 qd.unmapped = 1;
2731 else
2732 qd.unmapped = 0;
2733
2734 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2735 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2736
2737 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2738 return -EFAULT;
2739 return 0;
2740 }
2741
2742 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2743 {
2744 struct aac_delete_disk dd;
2745 struct fsa_dev_info *fsa_dev_ptr;
2746
2747 fsa_dev_ptr = dev->fsa_dev;
2748 if (!fsa_dev_ptr)
2749 return -EBUSY;
2750
2751 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2752 return -EFAULT;
2753
2754 if (dd.cnum >= dev->maximum_num_containers)
2755 return -EINVAL;
2756 /*
2757 * Mark this container as being deleted.
2758 */
2759 fsa_dev_ptr[dd.cnum].deleted = 1;
2760 /*
2761 * Mark the container as no longer valid
2762 */
2763 fsa_dev_ptr[dd.cnum].valid = 0;
2764 return 0;
2765 }
2766
2767 static int delete_disk(struct aac_dev *dev, void __user *arg)
2768 {
2769 struct aac_delete_disk dd;
2770 struct fsa_dev_info *fsa_dev_ptr;
2771
2772 fsa_dev_ptr = dev->fsa_dev;
2773 if (!fsa_dev_ptr)
2774 return -EBUSY;
2775
2776 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2777 return -EFAULT;
2778
2779 if (dd.cnum >= dev->maximum_num_containers)
2780 return -EINVAL;
2781 /*
2782 * If the container is locked, it can not be deleted by the API.
2783 */
2784 if (fsa_dev_ptr[dd.cnum].locked)
2785 return -EBUSY;
2786 else {
2787 /*
2788 * Mark the container as no longer being valid.
2789 */
2790 fsa_dev_ptr[dd.cnum].valid = 0;
2791 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2792 return 0;
2793 }
2794 }
2795
2796 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2797 {
2798 switch (cmd) {
2799 case FSACTL_QUERY_DISK:
2800 return query_disk(dev, arg);
2801 case FSACTL_DELETE_DISK:
2802 return delete_disk(dev, arg);
2803 case FSACTL_FORCE_DELETE_DISK:
2804 return force_delete_disk(dev, arg);
2805 case FSACTL_GET_CONTAINERS:
2806 return aac_get_containers(dev);
2807 default:
2808 return -ENOTTY;
2809 }
2810 }
2811
2812 /**
2813 *
2814 * aac_srb_callback
2815 * @context: the context set in the fib - here it is scsi cmd
2816 * @fibptr: pointer to the fib
2817 *
2818 * Handles the completion of a scsi command to a non dasd device
2819 *
2820 */
2821
2822 static void aac_srb_callback(void *context, struct fib * fibptr)
2823 {
2824 struct aac_dev *dev;
2825 struct aac_srb_reply *srbreply;
2826 struct scsi_cmnd *scsicmd;
2827
2828 scsicmd = (struct scsi_cmnd *) context;
2829
2830 if (!aac_valid_context(scsicmd, fibptr))
2831 return;
2832
2833 BUG_ON(fibptr == NULL);
2834
2835 dev = fibptr->dev;
2836
2837 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2838
2839 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2840
2841 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
2842 /* fast response */
2843 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
2844 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
2845 } else {
2846 /*
2847 * Calculate resid for sg
2848 */
2849 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2850 - le32_to_cpu(srbreply->data_xfer_length));
2851 }
2852
2853 scsi_dma_unmap(scsicmd);
2854
2855 /* expose physical device if expose_physicald flag is on */
2856 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
2857 && expose_physicals > 0)
2858 aac_expose_phy_device(scsicmd);
2859
2860 /*
2861 * First check the fib status
2862 */
2863
2864 if (le32_to_cpu(srbreply->status) != ST_OK){
2865 int len;
2866 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2867 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2868 SCSI_SENSE_BUFFERSIZE);
2869 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2870 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2871 }
2872
2873 /*
2874 * Next check the srb status
2875 */
2876 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2877 case SRB_STATUS_ERROR_RECOVERY:
2878 case SRB_STATUS_PENDING:
2879 case SRB_STATUS_SUCCESS:
2880 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2881 break;
2882 case SRB_STATUS_DATA_OVERRUN:
2883 switch(scsicmd->cmnd[0]){
2884 case READ_6:
2885 case WRITE_6:
2886 case READ_10:
2887 case WRITE_10:
2888 case READ_12:
2889 case WRITE_12:
2890 case READ_16:
2891 case WRITE_16:
2892 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
2893 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2894 } else {
2895 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2896 }
2897 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2898 break;
2899 case INQUIRY: {
2900 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2901 break;
2902 }
2903 default:
2904 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2905 break;
2906 }
2907 break;
2908 case SRB_STATUS_ABORTED:
2909 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2910 break;
2911 case SRB_STATUS_ABORT_FAILED:
2912 // Not sure about this one - but assuming the hba was trying to abort for some reason
2913 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2914 break;
2915 case SRB_STATUS_PARITY_ERROR:
2916 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2917 break;
2918 case SRB_STATUS_NO_DEVICE:
2919 case SRB_STATUS_INVALID_PATH_ID:
2920 case SRB_STATUS_INVALID_TARGET_ID:
2921 case SRB_STATUS_INVALID_LUN:
2922 case SRB_STATUS_SELECTION_TIMEOUT:
2923 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2924 break;
2925
2926 case SRB_STATUS_COMMAND_TIMEOUT:
2927 case SRB_STATUS_TIMEOUT:
2928 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2929 break;
2930
2931 case SRB_STATUS_BUSY:
2932 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2933 break;
2934
2935 case SRB_STATUS_BUS_RESET:
2936 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2937 break;
2938
2939 case SRB_STATUS_MESSAGE_REJECTED:
2940 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2941 break;
2942 case SRB_STATUS_REQUEST_FLUSHED:
2943 case SRB_STATUS_ERROR:
2944 case SRB_STATUS_INVALID_REQUEST:
2945 case SRB_STATUS_REQUEST_SENSE_FAILED:
2946 case SRB_STATUS_NO_HBA:
2947 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2948 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2949 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2950 case SRB_STATUS_DELAYED_RETRY:
2951 case SRB_STATUS_BAD_FUNCTION:
2952 case SRB_STATUS_NOT_STARTED:
2953 case SRB_STATUS_NOT_IN_USE:
2954 case SRB_STATUS_FORCE_ABORT:
2955 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2956 default:
2957 #ifdef AAC_DETAILED_STATUS_INFO
2958 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2959 le32_to_cpu(srbreply->srb_status) & 0x3F,
2960 aac_get_status_string(
2961 le32_to_cpu(srbreply->srb_status) & 0x3F),
2962 scsicmd->cmnd[0],
2963 le32_to_cpu(srbreply->scsi_status));
2964 #endif
2965 if ((scsicmd->cmnd[0] == ATA_12)
2966 || (scsicmd->cmnd[0] == ATA_16)) {
2967 if (scsicmd->cmnd[2] & (0x01 << 5)) {
2968 scsicmd->result = DID_OK << 16
2969 | COMMAND_COMPLETE << 8;
2970 break;
2971 } else {
2972 scsicmd->result = DID_ERROR << 16
2973 | COMMAND_COMPLETE << 8;
2974 break;
2975 }
2976 } else {
2977 scsicmd->result = DID_ERROR << 16
2978 | COMMAND_COMPLETE << 8;
2979 break;
2980 }
2981 }
2982 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
2983 int len;
2984 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2985 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2986 SCSI_SENSE_BUFFERSIZE);
2987 #ifdef AAC_DETAILED_STATUS_INFO
2988 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2989 le32_to_cpu(srbreply->status), len);
2990 #endif
2991 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2992 }
2993 /*
2994 * OR in the scsi status (already shifted up a bit)
2995 */
2996 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2997
2998 aac_fib_complete(fibptr);
2999 aac_fib_free(fibptr);
3000 scsicmd->scsi_done(scsicmd);
3001 }
3002
3003 /**
3004 *
3005 * aac_send_scb_fib
3006 * @scsicmd: the scsi command block
3007 *
3008 * This routine will form a FIB and fill in the aac_srb from the
3009 * scsicmd passed in.
3010 */
3011
3012 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3013 {
3014 struct fib* cmd_fibcontext;
3015 struct aac_dev* dev;
3016 int status;
3017
3018 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3019 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3020 scsicmd->device->lun > 7) {
3021 scsicmd->result = DID_NO_CONNECT << 16;
3022 scsicmd->scsi_done(scsicmd);
3023 return 0;
3024 }
3025
3026 /*
3027 * Allocate and initialize a Fib then setup a BlockWrite command
3028 */
3029 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
3030 return -1;
3031 }
3032 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
3033
3034 /*
3035 * Check that the command queued to the controller
3036 */
3037 if (status == -EINPROGRESS) {
3038 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3039 return 0;
3040 }
3041
3042 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3043 aac_fib_complete(cmd_fibcontext);
3044 aac_fib_free(cmd_fibcontext);
3045
3046 return -1;
3047 }
3048
3049 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
3050 {
3051 struct aac_dev *dev;
3052 unsigned long byte_count = 0;
3053 int nseg;
3054
3055 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3056 // Get rid of old data
3057 psg->count = 0;
3058 psg->sg[0].addr = 0;
3059 psg->sg[0].count = 0;
3060
3061 nseg = scsi_dma_map(scsicmd);
3062 if (nseg < 0)
3063 return nseg;
3064 if (nseg) {
3065 struct scatterlist *sg;
3066 int i;
3067
3068 psg->count = cpu_to_le32(nseg);
3069
3070 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3071 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3072 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3073 byte_count += sg_dma_len(sg);
3074 }
3075 /* hba wants the size to be exact */
3076 if (byte_count > scsi_bufflen(scsicmd)) {
3077 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3078 (byte_count - scsi_bufflen(scsicmd));
3079 psg->sg[i-1].count = cpu_to_le32(temp);
3080 byte_count = scsi_bufflen(scsicmd);
3081 }
3082 /* Check for command underflow */
3083 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3084 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3085 byte_count, scsicmd->underflow);
3086 }
3087 }
3088 return byte_count;
3089 }
3090
3091
3092 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
3093 {
3094 struct aac_dev *dev;
3095 unsigned long byte_count = 0;
3096 u64 addr;
3097 int nseg;
3098
3099 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3100 // Get rid of old data
3101 psg->count = 0;
3102 psg->sg[0].addr[0] = 0;
3103 psg->sg[0].addr[1] = 0;
3104 psg->sg[0].count = 0;
3105
3106 nseg = scsi_dma_map(scsicmd);
3107 if (nseg < 0)
3108 return nseg;
3109 if (nseg) {
3110 struct scatterlist *sg;
3111 int i;
3112
3113 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3114 int count = sg_dma_len(sg);
3115 addr = sg_dma_address(sg);
3116 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3117 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
3118 psg->sg[i].count = cpu_to_le32(count);
3119 byte_count += count;
3120 }
3121 psg->count = cpu_to_le32(nseg);
3122 /* hba wants the size to be exact */
3123 if (byte_count > scsi_bufflen(scsicmd)) {
3124 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3125 (byte_count - scsi_bufflen(scsicmd));
3126 psg->sg[i-1].count = cpu_to_le32(temp);
3127 byte_count = scsi_bufflen(scsicmd);
3128 }
3129 /* Check for command underflow */
3130 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3131 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3132 byte_count, scsicmd->underflow);
3133 }
3134 }
3135 return byte_count;
3136 }
3137
3138 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
3139 {
3140 unsigned long byte_count = 0;
3141 int nseg;
3142
3143 // Get rid of old data
3144 psg->count = 0;
3145 psg->sg[0].next = 0;
3146 psg->sg[0].prev = 0;
3147 psg->sg[0].addr[0] = 0;
3148 psg->sg[0].addr[1] = 0;
3149 psg->sg[0].count = 0;
3150 psg->sg[0].flags = 0;
3151
3152 nseg = scsi_dma_map(scsicmd);
3153 if (nseg < 0)
3154 return nseg;
3155 if (nseg) {
3156 struct scatterlist *sg;
3157 int i;
3158
3159 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3160 int count = sg_dma_len(sg);
3161 u64 addr = sg_dma_address(sg);
3162 psg->sg[i].next = 0;
3163 psg->sg[i].prev = 0;
3164 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3165 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3166 psg->sg[i].count = cpu_to_le32(count);
3167 psg->sg[i].flags = 0;
3168 byte_count += count;
3169 }
3170 psg->count = cpu_to_le32(nseg);
3171 /* hba wants the size to be exact */
3172 if (byte_count > scsi_bufflen(scsicmd)) {
3173 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3174 (byte_count - scsi_bufflen(scsicmd));
3175 psg->sg[i-1].count = cpu_to_le32(temp);
3176 byte_count = scsi_bufflen(scsicmd);
3177 }
3178 /* Check for command underflow */
3179 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3180 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3181 byte_count, scsicmd->underflow);
3182 }
3183 }
3184 return byte_count;
3185 }
3186
3187 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3188 struct aac_raw_io2 *rio2, int sg_max)
3189 {
3190 unsigned long byte_count = 0;
3191 int nseg;
3192
3193 nseg = scsi_dma_map(scsicmd);
3194 if (nseg < 0)
3195 return nseg;
3196 if (nseg) {
3197 struct scatterlist *sg;
3198 int i, conformable = 0;
3199 u32 min_size = PAGE_SIZE, cur_size;
3200
3201 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3202 int count = sg_dma_len(sg);
3203 u64 addr = sg_dma_address(sg);
3204
3205 BUG_ON(i >= sg_max);
3206 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3207 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3208 cur_size = cpu_to_le32(count);
3209 rio2->sge[i].length = cur_size;
3210 rio2->sge[i].flags = 0;
3211 if (i == 0) {
3212 conformable = 1;
3213 rio2->sgeFirstSize = cur_size;
3214 } else if (i == 1) {
3215 rio2->sgeNominalSize = cur_size;
3216 min_size = cur_size;
3217 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3218 conformable = 0;
3219 if (cur_size < min_size)
3220 min_size = cur_size;
3221 }
3222 byte_count += count;
3223 }
3224
3225 /* hba wants the size to be exact */
3226 if (byte_count > scsi_bufflen(scsicmd)) {
3227 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3228 (byte_count - scsi_bufflen(scsicmd));
3229 rio2->sge[i-1].length = cpu_to_le32(temp);
3230 byte_count = scsi_bufflen(scsicmd);
3231 }
3232
3233 rio2->sgeCnt = cpu_to_le32(nseg);
3234 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3235 /* not conformable: evaluate required sg elements */
3236 if (!conformable) {
3237 int j, nseg_new = nseg, err_found;
3238 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3239 err_found = 0;
3240 nseg_new = 2;
3241 for (j = 1; j < nseg - 1; ++j) {
3242 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3243 err_found = 1;
3244 break;
3245 }
3246 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3247 }
3248 if (!err_found)
3249 break;
3250 }
3251 if (i > 0 && nseg_new <= sg_max)
3252 aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3253 } else
3254 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3255
3256 /* Check for command underflow */
3257 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3258 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3259 byte_count, scsicmd->underflow);
3260 }
3261 }
3262
3263 return byte_count;
3264 }
3265
3266 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3267 {
3268 struct sge_ieee1212 *sge;
3269 int i, j, pos;
3270 u32 addr_low;
3271
3272 if (aac_convert_sgl == 0)
3273 return 0;
3274
3275 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
3276 if (sge == NULL)
3277 return -1;
3278
3279 for (i = 1, pos = 1; i < nseg-1; ++i) {
3280 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
3281 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
3282 sge[pos].addrLow = addr_low;
3283 sge[pos].addrHigh = rio2->sge[i].addrHigh;
3284 if (addr_low < rio2->sge[i].addrLow)
3285 sge[pos].addrHigh++;
3286 sge[pos].length = pages * PAGE_SIZE;
3287 sge[pos].flags = 0;
3288 pos++;
3289 }
3290 }
3291 sge[pos] = rio2->sge[nseg-1];
3292 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
3293
3294 kfree(sge);
3295 rio2->sgeCnt = cpu_to_le32(nseg_new);
3296 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3297 rio2->sgeNominalSize = pages * PAGE_SIZE;
3298 return 0;
3299 }
3300
3301 #ifdef AAC_DETAILED_STATUS_INFO
3302
3303 struct aac_srb_status_info {
3304 u32 status;
3305 char *str;
3306 };
3307
3308
3309 static struct aac_srb_status_info srb_status_info[] = {
3310 { SRB_STATUS_PENDING, "Pending Status"},
3311 { SRB_STATUS_SUCCESS, "Success"},
3312 { SRB_STATUS_ABORTED, "Aborted Command"},
3313 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
3314 { SRB_STATUS_ERROR, "Error Event"},
3315 { SRB_STATUS_BUSY, "Device Busy"},
3316 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
3317 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
3318 { SRB_STATUS_NO_DEVICE, "No Device"},
3319 { SRB_STATUS_TIMEOUT, "Timeout"},
3320 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
3321 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
3322 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
3323 { SRB_STATUS_BUS_RESET, "Bus Reset"},
3324 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
3325 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
3326 { SRB_STATUS_NO_HBA, "No HBA"},
3327 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
3328 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
3329 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
3330 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
3331 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
3332 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
3333 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
3334 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
3335 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
3336 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
3337 { SRB_STATUS_NOT_STARTED, "Not Started"},
3338 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
3339 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
3340 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
3341 { 0xff, "Unknown Error"}
3342 };
3343
3344 char *aac_get_status_string(u32 status)
3345 {
3346 int i;
3347
3348 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
3349 if (srb_status_info[i].status == status)
3350 return srb_status_info[i].str;
3351
3352 return "Bad Status Code";
3353 }
3354
3355 #endif
This page took 0.1452 seconds and 5 git commands to generate.