2 * Disk Array driver for Compaq SA53xx Controllers, SCSI Tape module
3 * Copyright 2001 Compaq Computer Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Questions/Comments/Bugfixes to iss_storagedev@hp.com
21 * Author: Stephen M. Cameron
23 #ifdef CONFIG_CISS_SCSI_TAPE
25 /* Here we have code to present the driver as a scsi driver
26 as it is simultaneously presented as a block driver. The
27 reason for doing this is to allow access to SCSI tape drives
28 through the array controller. Note in particular, neither
29 physical nor logical disks are presented through the scsi layer. */
31 #include <linux/timer.h>
32 #include <linux/completion.h>
33 #include <linux/slab.h>
34 #include <linux/string.h>
36 #include <asm/atomic.h>
38 #include <scsi/scsi_cmnd.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_host.h>
42 #include "cciss_scsi.h"
44 #define CCISS_ABORT_MSG 0x00
45 #define CCISS_RESET_MSG 0x01
47 /* some prototypes... */
53 unsigned int use_unit_num
, /* 0: address the controller,
54 1: address logical volume log_unit,
55 2: address is in scsi3addr */
56 unsigned int log_unit
,
58 unsigned char *scsi3addr
,
62 static int cciss_scsi_proc_info(
64 char *buffer
, /* data buffer */
65 char **start
, /* where data in buffer starts */
66 off_t offset
, /* offset from start of imaginary file */
67 int length
, /* length of data in buffer */
68 int func
); /* 0 == read, 1 == write */
70 static int cciss_scsi_queue_command (struct scsi_cmnd
*cmd
,
71 void (* done
)(struct scsi_cmnd
*));
72 static int cciss_eh_device_reset_handler(struct scsi_cmnd
*);
73 static int cciss_eh_abort_handler(struct scsi_cmnd
*);
75 static struct cciss_scsi_hba_t ccissscsi
[MAX_CTLR
] = {
76 { .name
= "cciss0", .ndevices
= 0 },
77 { .name
= "cciss1", .ndevices
= 0 },
78 { .name
= "cciss2", .ndevices
= 0 },
79 { .name
= "cciss3", .ndevices
= 0 },
80 { .name
= "cciss4", .ndevices
= 0 },
81 { .name
= "cciss5", .ndevices
= 0 },
82 { .name
= "cciss6", .ndevices
= 0 },
83 { .name
= "cciss7", .ndevices
= 0 },
86 static struct scsi_host_template cciss_driver_template
= {
87 .module
= THIS_MODULE
,
90 .proc_info
= cciss_scsi_proc_info
,
91 .queuecommand
= cciss_scsi_queue_command
,
92 .can_queue
= SCSI_CCISS_CAN_QUEUE
,
94 .sg_tablesize
= MAXSGENTRIES
,
96 .use_clustering
= DISABLE_CLUSTERING
,
97 /* Can't have eh_bus_reset_handler or eh_host_reset_handler for cciss */
98 .eh_device_reset_handler
= cciss_eh_device_reset_handler
,
99 .eh_abort_handler
= cciss_eh_abort_handler
,
103 struct cciss_scsi_cmd_stack_elem_t
{
104 CommandList_struct cmd
;
105 ErrorInfo_struct Err
;
112 #define CMD_STACK_SIZE (SCSI_CCISS_CAN_QUEUE * \
113 CCISS_MAX_SCSI_DEVS_PER_HBA + 2)
114 // plus two for init time usage
117 struct cciss_scsi_cmd_stack_t
{
118 struct cciss_scsi_cmd_stack_elem_t
*pool
;
119 struct cciss_scsi_cmd_stack_elem_t
*elem
[CMD_STACK_SIZE
];
120 dma_addr_t cmd_pool_handle
;
125 struct cciss_scsi_adapter_data_t
{
126 struct Scsi_Host
*scsi_host
;
127 struct cciss_scsi_cmd_stack_t cmd_stack
;
129 spinlock_t lock
; // to protect ccissscsi[ctlr];
132 #define CPQ_TAPE_LOCK(ctlr, flags) spin_lock_irqsave( \
133 &(((struct cciss_scsi_adapter_data_t *) \
134 hba[ctlr]->scsi_ctlr)->lock), flags);
135 #define CPQ_TAPE_UNLOCK(ctlr, flags) spin_unlock_irqrestore( \
136 &(((struct cciss_scsi_adapter_data_t *) \
137 hba[ctlr]->scsi_ctlr)->lock), flags);
139 static CommandList_struct
*
140 scsi_cmd_alloc(ctlr_info_t
*h
)
142 /* assume only one process in here at a time, locking done by caller. */
143 /* use CCISS_LOCK(ctlr) */
144 /* might be better to rewrite how we allocate scsi commands in a way that */
145 /* needs no locking at all. */
147 /* take the top memory chunk off the stack and return it, if any. */
148 struct cciss_scsi_cmd_stack_elem_t
*c
;
149 struct cciss_scsi_adapter_data_t
*sa
;
150 struct cciss_scsi_cmd_stack_t
*stk
;
153 sa
= (struct cciss_scsi_adapter_data_t
*) h
->scsi_ctlr
;
154 stk
= &sa
->cmd_stack
;
158 c
= stk
->elem
[stk
->top
];
159 /* memset(c, 0, sizeof(*c)); */
160 memset(&c
->cmd
, 0, sizeof(c
->cmd
));
161 memset(&c
->Err
, 0, sizeof(c
->Err
));
162 /* set physical addr of cmd and addr of scsi parameters */
163 c
->cmd
.busaddr
= c
->busaddr
;
164 /* (__u32) (stk->cmd_pool_handle +
165 (sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top)); */
167 temp64
.val
= (__u64
) (c
->busaddr
+ sizeof(CommandList_struct
));
168 /* (__u64) (stk->cmd_pool_handle +
169 (sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top) +
170 sizeof(CommandList_struct)); */
172 c
->cmd
.ErrDesc
.Addr
.lower
= temp64
.val32
.lower
;
173 c
->cmd
.ErrDesc
.Addr
.upper
= temp64
.val32
.upper
;
174 c
->cmd
.ErrDesc
.Len
= sizeof(ErrorInfo_struct
);
176 c
->cmd
.ctlr
= h
->ctlr
;
177 c
->cmd
.err_info
= &c
->Err
;
179 return (CommandList_struct
*) c
;
183 scsi_cmd_free(ctlr_info_t
*h
, CommandList_struct
*cmd
)
185 /* assume only one process in here at a time, locking done by caller. */
186 /* use CCISS_LOCK(ctlr) */
187 /* drop the free memory chunk on top of the stack. */
189 struct cciss_scsi_adapter_data_t
*sa
;
190 struct cciss_scsi_cmd_stack_t
*stk
;
192 sa
= (struct cciss_scsi_adapter_data_t
*) h
->scsi_ctlr
;
193 stk
= &sa
->cmd_stack
;
194 if (stk
->top
>= CMD_STACK_SIZE
) {
195 printk("cciss: scsi_cmd_free called too many times.\n");
199 stk
->elem
[stk
->top
] = (struct cciss_scsi_cmd_stack_elem_t
*) cmd
;
203 scsi_cmd_stack_setup(int ctlr
, struct cciss_scsi_adapter_data_t
*sa
)
206 struct cciss_scsi_cmd_stack_t
*stk
;
209 stk
= &sa
->cmd_stack
;
210 size
= sizeof(struct cciss_scsi_cmd_stack_elem_t
) * CMD_STACK_SIZE
;
212 // pci_alloc_consistent guarantees 32-bit DMA address will
215 stk
->pool
= (struct cciss_scsi_cmd_stack_elem_t
*)
216 pci_alloc_consistent(hba
[ctlr
]->pdev
, size
, &stk
->cmd_pool_handle
);
218 if (stk
->pool
== NULL
) {
219 printk("stk->pool is null\n");
223 for (i
=0; i
<CMD_STACK_SIZE
; i
++) {
224 stk
->elem
[i
] = &stk
->pool
[i
];
225 stk
->elem
[i
]->busaddr
= (__u32
) (stk
->cmd_pool_handle
+
226 (sizeof(struct cciss_scsi_cmd_stack_elem_t
) * i
));
228 stk
->top
= CMD_STACK_SIZE
-1;
233 scsi_cmd_stack_free(int ctlr
)
235 struct cciss_scsi_adapter_data_t
*sa
;
236 struct cciss_scsi_cmd_stack_t
*stk
;
239 sa
= (struct cciss_scsi_adapter_data_t
*) hba
[ctlr
]->scsi_ctlr
;
240 stk
= &sa
->cmd_stack
;
241 if (stk
->top
!= CMD_STACK_SIZE
-1) {
242 printk( "cciss: %d scsi commands are still outstanding.\n",
243 CMD_STACK_SIZE
- stk
->top
);
245 printk("WE HAVE A BUG HERE!!! stk=0x%p\n", stk
);
247 size
= sizeof(struct cciss_scsi_cmd_stack_elem_t
) * CMD_STACK_SIZE
;
249 pci_free_consistent(hba
[ctlr
]->pdev
, size
, stk
->pool
, stk
->cmd_pool_handle
);
254 static int xmargin
=8;
255 static int amargin
=60;
258 print_bytes (unsigned char *c
, int len
, int hex
, int ascii
)
269 if ((i
% xmargin
) == 0 && i
>0) printk("\n");
270 if ((i
% xmargin
) == 0) printk("0x%04x:", i
);
281 if ((i
% amargin
) == 0 && i
>0) printk("\n");
282 if ((i
% amargin
) == 0) printk("0x%04x:", i
);
283 if (*x
> 26 && *x
< 128) printk("%c", *x
);
292 print_cmd(CommandList_struct
*cp
)
294 printk("queue:%d\n", cp
->Header
.ReplyQueue
);
295 printk("sglist:%d\n", cp
->Header
.SGList
);
296 printk("sgtot:%d\n", cp
->Header
.SGTotal
);
297 printk("Tag:0x%08x/0x%08x\n", cp
->Header
.Tag
.upper
,
298 cp
->Header
.Tag
.lower
);
299 printk("LUN:0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
300 cp
->Header
.LUN
.LunAddrBytes
[0],
301 cp
->Header
.LUN
.LunAddrBytes
[1],
302 cp
->Header
.LUN
.LunAddrBytes
[2],
303 cp
->Header
.LUN
.LunAddrBytes
[3],
304 cp
->Header
.LUN
.LunAddrBytes
[4],
305 cp
->Header
.LUN
.LunAddrBytes
[5],
306 cp
->Header
.LUN
.LunAddrBytes
[6],
307 cp
->Header
.LUN
.LunAddrBytes
[7]);
308 printk("CDBLen:%d\n", cp
->Request
.CDBLen
);
309 printk("Type:%d\n",cp
->Request
.Type
.Type
);
310 printk("Attr:%d\n",cp
->Request
.Type
.Attribute
);
311 printk(" Dir:%d\n",cp
->Request
.Type
.Direction
);
312 printk("Timeout:%d\n",cp
->Request
.Timeout
);
313 printk( "CDB: %02x %02x %02x %02x %02x %02x %02x %02x"
314 " %02x %02x %02x %02x %02x %02x %02x %02x\n",
315 cp
->Request
.CDB
[0], cp
->Request
.CDB
[1],
316 cp
->Request
.CDB
[2], cp
->Request
.CDB
[3],
317 cp
->Request
.CDB
[4], cp
->Request
.CDB
[5],
318 cp
->Request
.CDB
[6], cp
->Request
.CDB
[7],
319 cp
->Request
.CDB
[8], cp
->Request
.CDB
[9],
320 cp
->Request
.CDB
[10], cp
->Request
.CDB
[11],
321 cp
->Request
.CDB
[12], cp
->Request
.CDB
[13],
322 cp
->Request
.CDB
[14], cp
->Request
.CDB
[15]),
323 printk("edesc.Addr: 0x%08x/0%08x, Len = %d\n",
324 cp
->ErrDesc
.Addr
.upper
, cp
->ErrDesc
.Addr
.lower
,
326 printk("sgs..........Errorinfo:\n");
327 printk("scsistatus:%d\n", cp
->err_info
->ScsiStatus
);
328 printk("senselen:%d\n", cp
->err_info
->SenseLen
);
329 printk("cmd status:%d\n", cp
->err_info
->CommandStatus
);
330 printk("resid cnt:%d\n", cp
->err_info
->ResidualCnt
);
331 printk("offense size:%d\n", cp
->err_info
->MoreErrInfo
.Invalid_Cmd
.offense_size
);
332 printk("offense byte:%d\n", cp
->err_info
->MoreErrInfo
.Invalid_Cmd
.offense_num
);
333 printk("offense value:%d\n", cp
->err_info
->MoreErrInfo
.Invalid_Cmd
.offense_value
);
340 find_bus_target_lun(int ctlr
, int *bus
, int *target
, int *lun
)
342 /* finds an unused bus, target, lun for a new device */
343 /* assumes hba[ctlr]->scsi_ctlr->lock is held */
345 unsigned char target_taken
[CCISS_MAX_SCSI_DEVS_PER_HBA
];
347 memset(&target_taken
[0], 0, CCISS_MAX_SCSI_DEVS_PER_HBA
);
349 target_taken
[SELF_SCSI_ID
] = 1;
350 for (i
=0;i
<ccissscsi
[ctlr
].ndevices
;i
++)
351 target_taken
[ccissscsi
[ctlr
].dev
[i
].target
] = 1;
353 for (i
=0;i
<CCISS_MAX_SCSI_DEVS_PER_HBA
;i
++) {
354 if (!target_taken
[i
]) {
355 *bus
= 0; *target
=i
; *lun
= 0; found
=1;
363 cciss_scsi_add_entry(int ctlr
, int hostno
,
364 unsigned char *scsi3addr
, int devtype
)
366 /* assumes hba[ctlr]->scsi_ctlr->lock is held */
367 int n
= ccissscsi
[ctlr
].ndevices
;
368 struct cciss_scsi_dev_t
*sd
;
370 if (n
>= CCISS_MAX_SCSI_DEVS_PER_HBA
) {
371 printk("cciss%d: Too many devices, "
372 "some will be inaccessible.\n", ctlr
);
375 sd
= &ccissscsi
[ctlr
].dev
[n
];
376 if (find_bus_target_lun(ctlr
, &sd
->bus
, &sd
->target
, &sd
->lun
) != 0)
378 memcpy(&sd
->scsi3addr
[0], scsi3addr
, 8);
379 sd
->devtype
= devtype
;
380 ccissscsi
[ctlr
].ndevices
++;
382 /* initially, (before registering with scsi layer) we don't
383 know our hostno and we don't want to print anything first
384 time anyway (the scsi layer's inquiries will show that info) */
386 printk("cciss%d: %s device c%db%dt%dl%d added.\n",
387 ctlr
, scsi_device_type(sd
->devtype
), hostno
,
388 sd
->bus
, sd
->target
, sd
->lun
);
393 cciss_scsi_remove_entry(int ctlr
, int hostno
, int entry
)
395 /* assumes hba[ctlr]->scsi_ctlr->lock is held */
397 struct cciss_scsi_dev_t sd
;
399 if (entry
< 0 || entry
>= CCISS_MAX_SCSI_DEVS_PER_HBA
) return;
400 sd
= ccissscsi
[ctlr
].dev
[entry
];
401 for (i
=entry
;i
<ccissscsi
[ctlr
].ndevices
-1;i
++)
402 ccissscsi
[ctlr
].dev
[i
] = ccissscsi
[ctlr
].dev
[i
+1];
403 ccissscsi
[ctlr
].ndevices
--;
404 printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
405 ctlr
, scsi_device_type(sd
.devtype
), hostno
,
406 sd
.bus
, sd
.target
, sd
.lun
);
410 #define SCSI3ADDR_EQ(a,b) ( \
411 (a)[7] == (b)[7] && \
412 (a)[6] == (b)[6] && \
413 (a)[5] == (b)[5] && \
414 (a)[4] == (b)[4] && \
415 (a)[3] == (b)[3] && \
416 (a)[2] == (b)[2] && \
417 (a)[1] == (b)[1] && \
421 adjust_cciss_scsi_table(int ctlr
, int hostno
,
422 struct cciss_scsi_dev_t sd
[], int nsds
)
424 /* sd contains scsi3 addresses and devtypes, but
425 bus target and lun are not filled in. This funciton
426 takes what's in sd to be the current and adjusts
427 ccissscsi[] to be in line with what's in sd. */
429 int i
,j
, found
, changes
=0;
430 struct cciss_scsi_dev_t
*csd
;
433 CPQ_TAPE_LOCK(ctlr
, flags
);
435 /* find any devices in ccissscsi[] that are not in
436 sd[] and remove them from ccissscsi[] */
439 while(i
<ccissscsi
[ctlr
].ndevices
) {
440 csd
= &ccissscsi
[ctlr
].dev
[i
];
442 for (j
=0;j
<nsds
;j
++) {
443 if (SCSI3ADDR_EQ(sd
[j
].scsi3addr
,
445 if (sd
[j
].devtype
== csd
->devtype
)
453 if (found
== 0) { /* device no longer present. */
455 /* printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
456 ctlr, scsi_device_type(csd->devtype), hostno,
457 csd->bus, csd->target, csd->lun); */
458 cciss_scsi_remove_entry(ctlr
, hostno
, i
);
459 /* note, i not incremented */
461 else if (found
== 1) { /* device is different kind */
463 printk("cciss%d: device c%db%dt%dl%d type changed "
464 "(device type now %s).\n",
465 ctlr
, hostno
, csd
->bus
, csd
->target
, csd
->lun
,
466 scsi_device_type(csd
->devtype
));
467 csd
->devtype
= sd
[j
].devtype
;
468 i
++; /* so just move along. */
469 } else /* device is same as it ever was, */
470 i
++; /* so just move along. */
473 /* Now, make sure every device listed in sd[] is also
474 listed in ccissscsi[], adding them if they aren't found */
476 for (i
=0;i
<nsds
;i
++) {
478 for (j
=0;j
<ccissscsi
[ctlr
].ndevices
;j
++) {
479 csd
= &ccissscsi
[ctlr
].dev
[j
];
480 if (SCSI3ADDR_EQ(sd
[i
].scsi3addr
,
482 if (sd
[i
].devtype
== csd
->devtype
)
483 found
=2; /* found device */
485 found
=1; /* found a bug. */
491 if (cciss_scsi_add_entry(ctlr
, hostno
,
492 &sd
[i
].scsi3addr
[0], sd
[i
].devtype
) != 0)
494 } else if (found
== 1) {
495 /* should never happen... */
497 printk("cciss%d: device unexpectedly changed type\n",
499 /* but if it does happen, we just ignore that device */
502 CPQ_TAPE_UNLOCK(ctlr
, flags
);
505 printk("cciss%d: No device changes detected.\n", ctlr
);
511 lookup_scsi3addr(int ctlr
, int bus
, int target
, int lun
, char *scsi3addr
)
514 struct cciss_scsi_dev_t
*sd
;
517 CPQ_TAPE_LOCK(ctlr
, flags
);
518 for (i
=0;i
<ccissscsi
[ctlr
].ndevices
;i
++) {
519 sd
= &ccissscsi
[ctlr
].dev
[i
];
520 if (sd
->bus
== bus
&&
521 sd
->target
== target
&&
523 memcpy(scsi3addr
, &sd
->scsi3addr
[0], 8);
524 CPQ_TAPE_UNLOCK(ctlr
, flags
);
528 CPQ_TAPE_UNLOCK(ctlr
, flags
);
533 cciss_scsi_setup(int cntl_num
)
535 struct cciss_scsi_adapter_data_t
* shba
;
537 ccissscsi
[cntl_num
].ndevices
= 0;
538 shba
= (struct cciss_scsi_adapter_data_t
*)
539 kmalloc(sizeof(*shba
), GFP_KERNEL
);
542 shba
->scsi_host
= NULL
;
543 spin_lock_init(&shba
->lock
);
544 shba
->registered
= 0;
545 if (scsi_cmd_stack_setup(cntl_num
, shba
) != 0) {
549 hba
[cntl_num
]->scsi_ctlr
= (void *) shba
;
554 complete_scsi_command( CommandList_struct
*cp
, int timeout
, __u32 tag
)
556 struct scsi_cmnd
*cmd
;
559 ErrorInfo_struct
*ei
;
563 /* First, see if it was a message rather than a command */
564 if (cp
->Request
.Type
.Type
== TYPE_MSG
) {
565 cp
->cmd_type
= CMD_MSG_DONE
;
569 cmd
= (struct scsi_cmnd
*) cp
->scsi_cmd
;
570 ctlr
= hba
[cp
->ctlr
];
572 /* undo the DMA mappings */
575 pci_unmap_sg(ctlr
->pdev
,
576 cmd
->request_buffer
, cmd
->use_sg
,
577 cmd
->sc_data_direction
);
579 else if (cmd
->request_bufflen
) {
580 addr64
.val32
.lower
= cp
->SG
[0].Addr
.lower
;
581 addr64
.val32
.upper
= cp
->SG
[0].Addr
.upper
;
582 pci_unmap_single(ctlr
->pdev
, (dma_addr_t
) addr64
.val
,
583 cmd
->request_bufflen
,
584 cmd
->sc_data_direction
);
587 cmd
->result
= (DID_OK
<< 16); /* host byte */
588 cmd
->result
|= (COMMAND_COMPLETE
<< 8); /* msg byte */
589 /* cmd->result |= (GOOD < 1); */ /* status byte */
591 cmd
->result
|= (ei
->ScsiStatus
);
592 /* printk("Scsistatus is 0x%02x\n", ei->ScsiStatus); */
594 /* copy the sense data whether we need to or not. */
596 memcpy(cmd
->sense_buffer
, ei
->SenseInfo
,
597 ei
->SenseLen
> SCSI_SENSE_BUFFERSIZE
?
598 SCSI_SENSE_BUFFERSIZE
:
600 cmd
->resid
= ei
->ResidualCnt
;
602 if(ei
->CommandStatus
!= 0)
603 { /* an error has occurred */
604 switch(ei
->CommandStatus
)
606 case CMD_TARGET_STATUS
:
607 /* Pass it up to the upper layers... */
611 printk(KERN_WARNING
"cciss: cmd %p "
612 "has SCSI Status = %x\n",
616 cmd
->result
|= (ei
->ScsiStatus
< 1);
618 else { /* scsi status is zero??? How??? */
620 /* Ordinarily, this case should never happen, but there is a bug
621 in some released firmware revisions that allows it to happen
622 if, for example, a 4100 backplane loses power and the tape
623 drive is in it. We assume that it's a fatal error of some
624 kind because we can't show that it wasn't. We will make it
625 look like selection timeout since that is the most common
626 reason for this to occur, and it's severe enough. */
628 cmd
->result
= DID_NO_CONNECT
<< 16;
631 case CMD_DATA_UNDERRUN
: /* let mid layer handle it. */
633 case CMD_DATA_OVERRUN
:
634 printk(KERN_WARNING
"cciss: cp %p has"
635 " completed with data overrun "
639 /* print_bytes(cp, sizeof(*cp), 1, 0);
641 /* We get CMD_INVALID if you address a non-existent tape drive instead
642 of a selection timeout (no response). You will see this if you yank
643 out a tape drive, then try to access it. This is kind of a shame
644 because it means that any other CMD_INVALID (e.g. driver bug) will
645 get interpreted as a missing target. */
646 cmd
->result
= DID_NO_CONNECT
<< 16;
649 case CMD_PROTOCOL_ERR
:
650 printk(KERN_WARNING
"cciss: cp %p has "
651 "protocol error \n", cp
);
653 case CMD_HARDWARE_ERR
:
654 cmd
->result
= DID_ERROR
<< 16;
655 printk(KERN_WARNING
"cciss: cp %p had "
656 " hardware error\n", cp
);
658 case CMD_CONNECTION_LOST
:
659 cmd
->result
= DID_ERROR
<< 16;
660 printk(KERN_WARNING
"cciss: cp %p had "
661 "connection lost\n", cp
);
664 cmd
->result
= DID_ABORT
<< 16;
665 printk(KERN_WARNING
"cciss: cp %p was "
668 case CMD_ABORT_FAILED
:
669 cmd
->result
= DID_ERROR
<< 16;
670 printk(KERN_WARNING
"cciss: cp %p reports "
671 "abort failed\n", cp
);
673 case CMD_UNSOLICITED_ABORT
:
674 cmd
->result
= DID_ABORT
<< 16;
675 printk(KERN_WARNING
"cciss: cp %p aborted "
676 "do to an unsolicited abort\n", cp
);
679 cmd
->result
= DID_TIME_OUT
<< 16;
680 printk(KERN_WARNING
"cciss: cp %p timedout\n",
684 cmd
->result
= DID_ERROR
<< 16;
685 printk(KERN_WARNING
"cciss: cp %p returned "
686 "unknown status %x\n", cp
,
690 // printk("c:%p:c%db%dt%dl%d ", cmd, ctlr->ctlr, cmd->channel,
691 // cmd->target, cmd->lun);
693 scsi_cmd_free(ctlr
, cp
);
697 cciss_scsi_detect(int ctlr
)
699 struct Scsi_Host
*sh
;
702 sh
= scsi_host_alloc(&cciss_driver_template
, sizeof(struct ctlr_info
*));
705 sh
->io_port
= 0; // good enough? FIXME,
706 sh
->n_io_port
= 0; // I don't think we use these two...
707 sh
->this_id
= SELF_SCSI_ID
;
709 ((struct cciss_scsi_adapter_data_t
*)
710 hba
[ctlr
]->scsi_ctlr
)->scsi_host
= (void *) sh
;
711 sh
->hostdata
[0] = (unsigned long) hba
[ctlr
];
712 sh
->irq
= hba
[ctlr
]->intr
[SIMPLE_MODE_INT
];
713 sh
->unique_id
= sh
->irq
;
714 error
= scsi_add_host(sh
, &hba
[ctlr
]->pdev
->dev
);
727 cciss_unmap_one(struct pci_dev
*pdev
,
728 CommandList_struct
*cp
,
734 addr64
.val32
.lower
= cp
->SG
[0].Addr
.lower
;
735 addr64
.val32
.upper
= cp
->SG
[0].Addr
.upper
;
736 pci_unmap_single(pdev
, (dma_addr_t
) addr64
.val
, buflen
, data_direction
);
740 cciss_map_one(struct pci_dev
*pdev
,
741 CommandList_struct
*cp
,
748 addr64
= (__u64
) pci_map_single(pdev
, buf
, buflen
, data_direction
);
749 cp
->SG
[0].Addr
.lower
=
750 (__u32
) (addr64
& (__u64
) 0x00000000FFFFFFFF);
751 cp
->SG
[0].Addr
.upper
=
752 (__u32
) ((addr64
>> 32) & (__u64
) 0x00000000FFFFFFFF);
753 cp
->SG
[0].Len
= buflen
;
754 cp
->Header
.SGList
= (__u8
) 1; /* no. SGs contig in this cmd */
755 cp
->Header
.SGTotal
= (__u16
) 1; /* total sgs in this cmd list */
759 cciss_scsi_do_simple_cmd(ctlr_info_t
*c
,
760 CommandList_struct
*cp
,
761 unsigned char *scsi3addr
,
763 unsigned char cdblen
,
764 unsigned char *buf
, int bufsize
,
768 DECLARE_COMPLETION_ONSTACK(wait
);
770 cp
->cmd_type
= CMD_IOCTL_PEND
; // treat this like an ioctl
772 cp
->Header
.ReplyQueue
= 0; // unused in simple mode
773 memcpy(&cp
->Header
.LUN
, scsi3addr
, sizeof(cp
->Header
.LUN
));
774 cp
->Header
.Tag
.lower
= cp
->busaddr
; // Use k. address of cmd as tag
775 // Fill in the request block...
777 /* printk("Using scsi3addr 0x%02x%0x2%0x2%0x2%0x2%0x2%0x2%0x2\n",
778 scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3],
779 scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); */
781 memset(cp
->Request
.CDB
, 0, sizeof(cp
->Request
.CDB
));
782 memcpy(cp
->Request
.CDB
, cdb
, cdblen
);
783 cp
->Request
.Timeout
= 0;
784 cp
->Request
.CDBLen
= cdblen
;
785 cp
->Request
.Type
.Type
= TYPE_CMD
;
786 cp
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
787 cp
->Request
.Type
.Direction
= direction
;
789 /* Fill in the SG list and do dma mapping */
790 cciss_map_one(c
->pdev
, cp
, (unsigned char *) buf
,
791 bufsize
, DMA_FROM_DEVICE
);
795 /* Put the request on the tail of the request queue */
796 spin_lock_irqsave(CCISS_LOCK(c
->ctlr
), flags
);
800 spin_unlock_irqrestore(CCISS_LOCK(c
->ctlr
), flags
);
802 wait_for_completion(&wait
);
804 /* undo the dma mapping */
805 cciss_unmap_one(c
->pdev
, cp
, bufsize
, DMA_FROM_DEVICE
);
810 cciss_scsi_interpret_error(CommandList_struct
*cp
)
812 ErrorInfo_struct
*ei
;
815 switch(ei
->CommandStatus
)
817 case CMD_TARGET_STATUS
:
818 printk(KERN_WARNING
"cciss: cmd %p has "
819 "completed with errors\n", cp
);
820 printk(KERN_WARNING
"cciss: cmd %p "
821 "has SCSI Status = %x\n",
824 if (ei
->ScsiStatus
== 0)
826 "cciss:SCSI status is abnormally zero. "
827 "(probably indicates selection timeout "
828 "reported incorrectly due to a known "
829 "firmware bug, circa July, 2001.)\n");
831 case CMD_DATA_UNDERRUN
: /* let mid layer handle it. */
832 printk("UNDERRUN\n");
834 case CMD_DATA_OVERRUN
:
835 printk(KERN_WARNING
"cciss: cp %p has"
836 " completed with data overrun "
840 /* controller unfortunately reports SCSI passthru's */
841 /* to non-existent targets as invalid commands. */
842 printk(KERN_WARNING
"cciss: cp %p is "
843 "reported invalid (probably means "
844 "target device no longer present)\n",
846 /* print_bytes((unsigned char *) cp, sizeof(*cp), 1, 0);
850 case CMD_PROTOCOL_ERR
:
851 printk(KERN_WARNING
"cciss: cp %p has "
852 "protocol error \n", cp
);
854 case CMD_HARDWARE_ERR
:
855 /* cmd->result = DID_ERROR << 16; */
856 printk(KERN_WARNING
"cciss: cp %p had "
857 " hardware error\n", cp
);
859 case CMD_CONNECTION_LOST
:
860 printk(KERN_WARNING
"cciss: cp %p had "
861 "connection lost\n", cp
);
864 printk(KERN_WARNING
"cciss: cp %p was "
867 case CMD_ABORT_FAILED
:
868 printk(KERN_WARNING
"cciss: cp %p reports "
869 "abort failed\n", cp
);
871 case CMD_UNSOLICITED_ABORT
:
872 printk(KERN_WARNING
"cciss: cp %p aborted "
873 "do to an unsolicited abort\n", cp
);
876 printk(KERN_WARNING
"cciss: cp %p timedout\n",
880 printk(KERN_WARNING
"cciss: cp %p returned "
881 "unknown status %x\n", cp
,
887 cciss_scsi_do_inquiry(ctlr_info_t
*c
, unsigned char *scsi3addr
,
888 unsigned char *buf
, unsigned char bufsize
)
891 CommandList_struct
*cp
;
893 ErrorInfo_struct
*ei
;
896 spin_lock_irqsave(CCISS_LOCK(c
->ctlr
), flags
);
897 cp
= scsi_cmd_alloc(c
);
898 spin_unlock_irqrestore(CCISS_LOCK(c
->ctlr
), flags
);
900 if (cp
== NULL
) { /* trouble... */
901 printk("cmd_alloc returned NULL!\n");
907 cdb
[0] = CISS_INQUIRY
;
913 rc
= cciss_scsi_do_simple_cmd(c
, cp
, scsi3addr
, cdb
,
914 6, buf
, bufsize
, XFER_READ
);
916 if (rc
!= 0) return rc
; /* something went wrong */
918 if (ei
->CommandStatus
!= 0 &&
919 ei
->CommandStatus
!= CMD_DATA_UNDERRUN
) {
920 cciss_scsi_interpret_error(cp
);
923 spin_lock_irqsave(CCISS_LOCK(c
->ctlr
), flags
);
924 scsi_cmd_free(c
, cp
);
925 spin_unlock_irqrestore(CCISS_LOCK(c
->ctlr
), flags
);
930 cciss_scsi_do_report_phys_luns(ctlr_info_t
*c
,
931 ReportLunData_struct
*buf
, int bufsize
)
934 CommandList_struct
*cp
;
935 unsigned char cdb
[12];
936 unsigned char scsi3addr
[8];
937 ErrorInfo_struct
*ei
;
940 spin_lock_irqsave(CCISS_LOCK(c
->ctlr
), flags
);
941 cp
= scsi_cmd_alloc(c
);
942 spin_unlock_irqrestore(CCISS_LOCK(c
->ctlr
), flags
);
943 if (cp
== NULL
) { /* trouble... */
944 printk("cmd_alloc returned NULL!\n");
948 memset(&scsi3addr
[0], 0, 8); /* address the controller */
949 cdb
[0] = CISS_REPORT_PHYS
;
955 cdb
[6] = (bufsize
>> 24) & 0xFF; //MSB
956 cdb
[7] = (bufsize
>> 16) & 0xFF;
957 cdb
[8] = (bufsize
>> 8) & 0xFF;
958 cdb
[9] = bufsize
& 0xFF;
962 rc
= cciss_scsi_do_simple_cmd(c
, cp
, scsi3addr
,
964 (unsigned char *) buf
,
967 if (rc
!= 0) return rc
; /* something went wrong */
970 if (ei
->CommandStatus
!= 0 &&
971 ei
->CommandStatus
!= CMD_DATA_UNDERRUN
) {
972 cciss_scsi_interpret_error(cp
);
975 spin_lock_irqsave(CCISS_LOCK(c
->ctlr
), flags
);
976 scsi_cmd_free(c
, cp
);
977 spin_unlock_irqrestore(CCISS_LOCK(c
->ctlr
), flags
);
982 cciss_update_non_disk_devices(int cntl_num
, int hostno
)
984 /* the idea here is we could get notified from /proc
985 that some devices have changed, so we do a report
986 physical luns cmd, and adjust our list of devices
987 accordingly. (We can't rely on the scsi-mid layer just
988 doing inquiries, because the "busses" that the scsi
989 mid-layer probes are totally fabricated by this driver,
990 so new devices wouldn't show up.
992 the scsi3addr's of devices won't change so long as the
993 adapter is not reset. That means we can rescan and
994 tell which devices we already know about, vs. new
995 devices, vs. disappearing devices.
997 Also, if you yank out a tape drive, then put in a disk
998 in it's place, (say, a configured volume from another
999 array controller for instance) _don't_ poke this driver
1000 (so it thinks it's still a tape, but _do_ poke the scsi
1001 mid layer, so it does an inquiry... the scsi mid layer
1002 will see the physical disk. This would be bad. Need to
1003 think about how to prevent that. One idea would be to
1004 snoop all scsi responses and if an inquiry repsonse comes
1005 back that reports a disk, chuck it an return selection
1006 timeout instead and adjust our table... Not sure i like
1010 #define OBDR_TAPE_INQ_SIZE 49
1011 #define OBDR_TAPE_SIG "$DR-10"
1012 ReportLunData_struct
*ld_buff
;
1013 unsigned char *inq_buff
;
1014 unsigned char scsi3addr
[8];
1018 /* unsigned char found[CCISS_MAX_SCSI_DEVS_PER_HBA]; */
1019 struct cciss_scsi_dev_t currentsd
[CCISS_MAX_SCSI_DEVS_PER_HBA
];
1021 int reportlunsize
= sizeof(*ld_buff
) + CISS_MAX_PHYS_LUN
* 8;
1024 c
= (ctlr_info_t
*) hba
[cntl_num
];
1025 ld_buff
= kzalloc(reportlunsize
, GFP_KERNEL
);
1026 if (ld_buff
== NULL
) {
1027 printk(KERN_ERR
"cciss: out of memory\n");
1030 inq_buff
= kmalloc(OBDR_TAPE_INQ_SIZE
, GFP_KERNEL
);
1031 if (inq_buff
== NULL
) {
1032 printk(KERN_ERR
"cciss: out of memory\n");
1037 if (cciss_scsi_do_report_phys_luns(c
, ld_buff
, reportlunsize
) == 0) {
1038 ch
= &ld_buff
->LUNListLength
[0];
1039 num_luns
= ((ch
[0]<<24) | (ch
[1]<<16) | (ch
[2]<<8) | ch
[3]) / 8;
1040 if (num_luns
> CISS_MAX_PHYS_LUN
) {
1042 "cciss: Maximum physical LUNs (%d) exceeded. "
1043 "%d LUNs ignored.\n", CISS_MAX_PHYS_LUN
,
1044 num_luns
- CISS_MAX_PHYS_LUN
);
1045 num_luns
= CISS_MAX_PHYS_LUN
;
1049 printk(KERN_ERR
"cciss: Report physical LUNs failed.\n");
1054 /* adjust our table of devices */
1055 for(i
=0; i
<num_luns
; i
++)
1059 /* for each physical lun, do an inquiry */
1060 if (ld_buff
->LUN
[i
][3] & 0xC0) continue;
1061 memset(inq_buff
, 0, OBDR_TAPE_INQ_SIZE
);
1062 memcpy(&scsi3addr
[0], &ld_buff
->LUN
[i
][0], 8);
1064 if (cciss_scsi_do_inquiry(hba
[cntl_num
], scsi3addr
, inq_buff
,
1065 (unsigned char) OBDR_TAPE_INQ_SIZE
) != 0) {
1066 /* Inquiry failed (msg printed already) */
1067 devtype
= 0; /* so we will skip this device. */
1068 } else /* what kind of device is this? */
1069 devtype
= (inq_buff
[0] & 0x1f);
1073 case 0x05: /* CD-ROM */ {
1075 /* We don't *really* support actual CD-ROM devices,
1076 * just this "One Button Disaster Recovery" tape drive
1077 * which temporarily pretends to be a CD-ROM drive.
1078 * So we check that the device is really an OBDR tape
1079 * device by checking for "$DR-10" in bytes 43-48 of
1084 strncpy(obdr_sig
, &inq_buff
[43], 6);
1086 if (strncmp(obdr_sig
, OBDR_TAPE_SIG
, 6) != 0)
1087 /* Not OBDR device, ignore it. */
1090 /* fall through . . . */
1091 case 0x01: /* sequential access, (tape) */
1092 case 0x08: /* medium changer */
1093 if (ncurrent
>= CCISS_MAX_SCSI_DEVS_PER_HBA
) {
1094 printk(KERN_INFO
"cciss%d: %s ignored, "
1095 "too many devices.\n", cntl_num
,
1096 scsi_device_type(devtype
));
1099 memcpy(¤tsd
[ncurrent
].scsi3addr
[0],
1101 currentsd
[ncurrent
].devtype
= devtype
;
1102 currentsd
[ncurrent
].bus
= -1;
1103 currentsd
[ncurrent
].target
= -1;
1104 currentsd
[ncurrent
].lun
= -1;
1112 adjust_cciss_scsi_table(cntl_num
, hostno
, currentsd
, ncurrent
);
1120 is_keyword(char *ptr
, int len
, char *verb
) // Thanks to ncr53c8xx.c
1122 int verb_len
= strlen(verb
);
1123 if (len
>= verb_len
&& !memcmp(verb
,ptr
,verb_len
))
1130 cciss_scsi_user_command(int ctlr
, int hostno
, char *buffer
, int length
)
1134 if ((arg_len
= is_keyword(buffer
, length
, "rescan")) != 0)
1135 cciss_update_non_disk_devices(ctlr
, hostno
);
1143 cciss_scsi_proc_info(struct Scsi_Host
*sh
,
1144 char *buffer
, /* data buffer */
1145 char **start
, /* where data in buffer starts */
1146 off_t offset
, /* offset from start of imaginary file */
1147 int length
, /* length of data in buffer */
1148 int func
) /* 0 == read, 1 == write */
1151 int buflen
, datalen
;
1157 ci
= (ctlr_info_t
*) sh
->hostdata
[0];
1158 if (ci
== NULL
) /* This really shouldn't ever happen. */
1161 cntl_num
= ci
->ctlr
; /* Get our index into the hba[] array */
1163 if (func
== 0) { /* User is reading from /proc/scsi/ciss*?/?* */
1164 buflen
= sprintf(buffer
, "cciss%d: SCSI host: %d\n",
1165 cntl_num
, sh
->host_no
);
1167 /* this information is needed by apps to know which cciss
1168 device corresponds to which scsi host number without
1169 having to open a scsi target device node. The device
1170 information is not a duplicate of /proc/scsi/scsi because
1171 the two may be out of sync due to scsi hotplug, rather
1172 this info is for an app to be able to use to know how to
1173 get them back in sync. */
1175 for (i
=0;i
<ccissscsi
[cntl_num
].ndevices
;i
++) {
1176 struct cciss_scsi_dev_t
*sd
= &ccissscsi
[cntl_num
].dev
[i
];
1177 buflen
+= sprintf(&buffer
[buflen
], "c%db%dt%dl%d %02d "
1178 "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
1179 sh
->host_no
, sd
->bus
, sd
->target
, sd
->lun
,
1181 sd
->scsi3addr
[0], sd
->scsi3addr
[1],
1182 sd
->scsi3addr
[2], sd
->scsi3addr
[3],
1183 sd
->scsi3addr
[4], sd
->scsi3addr
[5],
1184 sd
->scsi3addr
[6], sd
->scsi3addr
[7]);
1186 datalen
= buflen
- offset
;
1187 if (datalen
< 0) { /* they're reading past EOF. */
1189 *start
= buffer
+buflen
;
1191 *start
= buffer
+ offset
;
1193 } else /* User is writing to /proc/scsi/cciss*?/?* ... */
1194 return cciss_scsi_user_command(cntl_num
, sh
->host_no
,
1198 /* cciss_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci
1199 dma mapping and fills in the scatter gather entries of the
1200 cciss command, cp. */
1203 cciss_scatter_gather(struct pci_dev
*pdev
,
1204 CommandList_struct
*cp
,
1205 struct scsi_cmnd
*cmd
)
1207 unsigned int use_sg
, nsegs
=0, len
;
1208 struct scatterlist
*scatter
= (struct scatterlist
*) cmd
->request_buffer
;
1211 /* is it just one virtual address? */
1213 if (cmd
->request_bufflen
) { /* anything to xfer? */
1215 addr64
= (__u64
) pci_map_single(pdev
,
1216 cmd
->request_buffer
,
1217 cmd
->request_bufflen
,
1218 cmd
->sc_data_direction
);
1220 cp
->SG
[0].Addr
.lower
=
1221 (__u32
) (addr64
& (__u64
) 0x00000000FFFFFFFF);
1222 cp
->SG
[0].Addr
.upper
=
1223 (__u32
) ((addr64
>> 32) & (__u64
) 0x00000000FFFFFFFF);
1224 cp
->SG
[0].Len
= cmd
->request_bufflen
;
1227 } /* else, must be a list of virtual addresses.... */
1228 else if (cmd
->use_sg
<= MAXSGENTRIES
) { /* not too many addrs? */
1230 use_sg
= pci_map_sg(pdev
, cmd
->request_buffer
, cmd
->use_sg
,
1231 cmd
->sc_data_direction
);
1233 for (nsegs
=0; nsegs
< use_sg
; nsegs
++) {
1234 addr64
= (__u64
) sg_dma_address(&scatter
[nsegs
]);
1235 len
= sg_dma_len(&scatter
[nsegs
]);
1236 cp
->SG
[nsegs
].Addr
.lower
=
1237 (__u32
) (addr64
& (__u64
) 0x00000000FFFFFFFF);
1238 cp
->SG
[nsegs
].Addr
.upper
=
1239 (__u32
) ((addr64
>> 32) & (__u64
) 0x00000000FFFFFFFF);
1240 cp
->SG
[nsegs
].Len
= len
;
1241 cp
->SG
[nsegs
].Ext
= 0; // we are not chaining
1245 cp
->Header
.SGList
= (__u8
) nsegs
; /* no. SGs contig in this cmd */
1246 cp
->Header
.SGTotal
= (__u16
) nsegs
; /* total sgs in this cmd list */
1252 cciss_scsi_queue_command (struct scsi_cmnd
*cmd
, void (* done
)(struct scsi_cmnd
*))
1256 unsigned char scsi3addr
[8];
1257 CommandList_struct
*cp
;
1258 unsigned long flags
;
1260 // Get the ptr to our adapter structure (hba[i]) out of cmd->host.
1261 // We violate cmd->host privacy here. (Is there another way?)
1262 c
= (ctlr_info_t
**) &cmd
->device
->host
->hostdata
[0];
1265 rc
= lookup_scsi3addr(ctlr
, cmd
->device
->channel
, cmd
->device
->id
,
1266 cmd
->device
->lun
, scsi3addr
);
1268 /* the scsi nexus does not match any that we presented... */
1269 /* pretend to mid layer that we got selection timeout */
1270 cmd
->result
= DID_NO_CONNECT
<< 16;
1272 /* we might want to think about registering controller itself
1273 as a processor device on the bus so sg binds to it. */
1277 /* printk("cciss_queue_command, p=%p, cmd=0x%02x, c%db%dt%dl%d\n",
1278 cmd, cmd->cmnd[0], ctlr, cmd->channel, cmd->target, cmd->lun);*/
1279 // printk("q:%p:c%db%dt%dl%d ", cmd, ctlr, cmd->channel,
1280 // cmd->target, cmd->lun);
1282 /* Ok, we have a reasonable scsi nexus, so send the cmd down, and
1283 see what the device thinks of it. */
1285 spin_lock_irqsave(CCISS_LOCK(ctlr
), flags
);
1286 cp
= scsi_cmd_alloc(*c
);
1287 spin_unlock_irqrestore(CCISS_LOCK(ctlr
), flags
);
1288 if (cp
== NULL
) { /* trouble... */
1289 printk("scsi_cmd_alloc returned NULL!\n");
1290 /* FIXME: next 3 lines are -> BAD! <- */
1291 cmd
->result
= DID_NO_CONNECT
<< 16;
1296 // Fill in the command list header
1298 cmd
->scsi_done
= done
; // save this for use by completion code
1300 // save cp in case we have to abort it
1301 cmd
->host_scribble
= (unsigned char *) cp
;
1303 cp
->cmd_type
= CMD_SCSI
;
1305 cp
->Header
.ReplyQueue
= 0; // unused in simple mode
1306 memcpy(&cp
->Header
.LUN
.LunAddrBytes
[0], &scsi3addr
[0], 8);
1307 cp
->Header
.Tag
.lower
= cp
->busaddr
; // Use k. address of cmd as tag
1309 // Fill in the request block...
1311 cp
->Request
.Timeout
= 0;
1312 memset(cp
->Request
.CDB
, 0, sizeof(cp
->Request
.CDB
));
1313 BUG_ON(cmd
->cmd_len
> sizeof(cp
->Request
.CDB
));
1314 cp
->Request
.CDBLen
= cmd
->cmd_len
;
1315 memcpy(cp
->Request
.CDB
, cmd
->cmnd
, cmd
->cmd_len
);
1316 cp
->Request
.Type
.Type
= TYPE_CMD
;
1317 cp
->Request
.Type
.Attribute
= ATTR_SIMPLE
;
1318 switch(cmd
->sc_data_direction
)
1320 case DMA_TO_DEVICE
: cp
->Request
.Type
.Direction
= XFER_WRITE
; break;
1321 case DMA_FROM_DEVICE
: cp
->Request
.Type
.Direction
= XFER_READ
; break;
1322 case DMA_NONE
: cp
->Request
.Type
.Direction
= XFER_NONE
; break;
1323 case DMA_BIDIRECTIONAL
:
1324 // This can happen if a buggy application does a scsi passthru
1325 // and sets both inlen and outlen to non-zero. ( see
1326 // ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
1328 cp
->Request
.Type
.Direction
= XFER_RSVD
;
1329 // This is technically wrong, and cciss controllers should
1330 // reject it with CMD_INVALID, which is the most correct
1331 // response, but non-fibre backends appear to let it
1332 // slide by, and give the same results as if this field
1333 // were set correctly. Either way is acceptable for
1334 // our purposes here.
1339 printk("cciss: unknown data direction: %d\n",
1340 cmd
->sc_data_direction
);
1345 cciss_scatter_gather((*c
)->pdev
, cp
, cmd
); // Fill the SG list
1347 /* Put the request on the tail of the request queue */
1349 spin_lock_irqsave(CCISS_LOCK(ctlr
), flags
);
1350 addQ(&(*c
)->reqQ
, cp
);
1353 spin_unlock_irqrestore(CCISS_LOCK(ctlr
), flags
);
1355 /* the cmd'll come back via intr handler in complete_scsi_command() */
1360 cciss_unregister_scsi(int ctlr
)
1362 struct cciss_scsi_adapter_data_t
*sa
;
1363 struct cciss_scsi_cmd_stack_t
*stk
;
1364 unsigned long flags
;
1366 /* we are being forcibly unloaded, and may not refuse. */
1368 spin_lock_irqsave(CCISS_LOCK(ctlr
), flags
);
1369 sa
= (struct cciss_scsi_adapter_data_t
*) hba
[ctlr
]->scsi_ctlr
;
1370 stk
= &sa
->cmd_stack
;
1372 /* if we weren't ever actually registered, don't unregister */
1373 if (sa
->registered
) {
1374 spin_unlock_irqrestore(CCISS_LOCK(ctlr
), flags
);
1375 scsi_remove_host(sa
->scsi_host
);
1376 scsi_host_put(sa
->scsi_host
);
1377 spin_lock_irqsave(CCISS_LOCK(ctlr
), flags
);
1380 /* set scsi_host to NULL so our detect routine will
1381 find us on register */
1382 sa
->scsi_host
= NULL
;
1383 scsi_cmd_stack_free(ctlr
);
1385 spin_unlock_irqrestore(CCISS_LOCK(ctlr
), flags
);
1389 cciss_register_scsi(int ctlr
)
1391 unsigned long flags
;
1393 CPQ_TAPE_LOCK(ctlr
, flags
);
1395 /* Since this is really a block driver, the SCSI core may not be
1396 initialized at init time, in which case, calling scsi_register_host
1397 would hang. Instead, we do it later, via /proc filesystem
1398 and rc scripts, when we know SCSI core is good to go. */
1400 /* Only register if SCSI devices are detected. */
1401 if (ccissscsi
[ctlr
].ndevices
!= 0) {
1402 ((struct cciss_scsi_adapter_data_t
*)
1403 hba
[ctlr
]->scsi_ctlr
)->registered
= 1;
1404 CPQ_TAPE_UNLOCK(ctlr
, flags
);
1405 return cciss_scsi_detect(ctlr
);
1407 CPQ_TAPE_UNLOCK(ctlr
, flags
);
1409 "cciss%d: No appropriate SCSI device detected, "
1410 "SCSI subsystem not engaged.\n", ctlr
);
1415 cciss_engage_scsi(int ctlr
)
1417 struct cciss_scsi_adapter_data_t
*sa
;
1418 struct cciss_scsi_cmd_stack_t
*stk
;
1419 unsigned long flags
;
1421 spin_lock_irqsave(CCISS_LOCK(ctlr
), flags
);
1422 sa
= (struct cciss_scsi_adapter_data_t
*) hba
[ctlr
]->scsi_ctlr
;
1423 stk
= &sa
->cmd_stack
;
1425 if (((struct cciss_scsi_adapter_data_t
*)
1426 hba
[ctlr
]->scsi_ctlr
)->registered
) {
1427 printk("cciss%d: SCSI subsystem already engaged.\n", ctlr
);
1428 spin_unlock_irqrestore(CCISS_LOCK(ctlr
), flags
);
1431 spin_unlock_irqrestore(CCISS_LOCK(ctlr
), flags
);
1432 cciss_update_non_disk_devices(ctlr
, -1);
1433 cciss_register_scsi(ctlr
);
1438 cciss_proc_tape_report(int ctlr
, unsigned char *buffer
, off_t
*pos
, off_t
*len
)
1440 unsigned long flags
;
1443 *pos
= *pos
-1; *len
= *len
- 1; // cut off the last trailing newline
1445 CPQ_TAPE_LOCK(ctlr
, flags
);
1446 size
= sprintf(buffer
+ *len
,
1447 "Sequential access devices: %d\n\n",
1448 ccissscsi
[ctlr
].ndevices
);
1449 CPQ_TAPE_UNLOCK(ctlr
, flags
);
1450 *pos
+= size
; *len
+= size
;
1453 /* Need at least one of these error handlers to keep ../scsi/hosts.c from
1454 * complaining. Doing a host- or bus-reset can't do anything good here.
1455 * Despite what it might say in scsi_error.c, there may well be commands
1456 * on the controller, as the cciss driver registers twice, once as a block
1457 * device for the logical drives, and once as a scsi device, for any tape
1458 * drives. So we know there are no commands out on the tape drives, but we
1459 * don't know there are no commands on the controller, and it is likely
1460 * that there probably are, as the cciss block device is most commonly used
1461 * as a boot device (embedded controller on HP/Compaq systems.)
1464 static int cciss_eh_device_reset_handler(struct scsi_cmnd
*scsicmd
)
1467 CommandList_struct
*cmd_in_trouble
;
1471 /* find the controller to which the command to be aborted was sent */
1472 c
= (ctlr_info_t
**) &scsicmd
->device
->host
->hostdata
[0];
1473 if (c
== NULL
) /* paranoia */
1476 printk(KERN_WARNING
"cciss%d: resetting tape drive or medium changer.\n", ctlr
);
1478 /* find the command that's giving us trouble */
1479 cmd_in_trouble
= (CommandList_struct
*) scsicmd
->host_scribble
;
1480 if (cmd_in_trouble
== NULL
) { /* paranoia */
1483 /* send a reset to the SCSI LUN which the command was sent to */
1484 rc
= sendcmd(CCISS_RESET_MSG
, ctlr
, NULL
, 0, 2, 0, 0,
1485 (unsigned char *) &cmd_in_trouble
->Header
.LUN
.LunAddrBytes
[0],
1487 /* sendcmd turned off interrputs on the board, turn 'em back on. */
1488 (*c
)->access
.set_intr_mask(*c
, CCISS_INTR_ON
);
1491 printk(KERN_WARNING
"cciss%d: resetting device failed.\n", ctlr
);
1495 static int cciss_eh_abort_handler(struct scsi_cmnd
*scsicmd
)
1498 CommandList_struct
*cmd_to_abort
;
1502 /* find the controller to which the command to be aborted was sent */
1503 c
= (ctlr_info_t
**) &scsicmd
->device
->host
->hostdata
[0];
1504 if (c
== NULL
) /* paranoia */
1507 printk(KERN_WARNING
"cciss%d: aborting tardy SCSI cmd\n", ctlr
);
1509 /* find the command to be aborted */
1510 cmd_to_abort
= (CommandList_struct
*) scsicmd
->host_scribble
;
1511 if (cmd_to_abort
== NULL
) /* paranoia */
1513 rc
= sendcmd(CCISS_ABORT_MSG
, ctlr
, &cmd_to_abort
->Header
.Tag
,
1515 (unsigned char *) &cmd_to_abort
->Header
.LUN
.LunAddrBytes
[0],
1517 /* sendcmd turned off interrputs on the board, turn 'em back on. */
1518 (*c
)->access
.set_intr_mask(*c
, CCISS_INTR_ON
);
1525 #else /* no CONFIG_CISS_SCSI_TAPE */
1527 /* If no tape support, then these become defined out of existence */
1529 #define cciss_scsi_setup(cntl_num)
1530 #define cciss_unregister_scsi(ctlr)
1531 #define cciss_register_scsi(ctlr)
1532 #define cciss_proc_tape_report(ctlr, buffer, pos, len)
1534 #endif /* CONFIG_CISS_SCSI_TAPE */