22 #include <scsi/scsi.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
29 #define RDAC_NAME "rdac"
30 #define RDAC_RETRY_COUNT 5
39 #define RDAC_QUIESCENCE_TIME 20
43 #define RDAC_PAGE_CODE_REDUNDANT_CONTROLLER 0x2c
48 #define RDAC_MODE_TRANSFER_SPECIFIED_LUNS 0x02
53 #define RDAC_FORCED_QUIESENCE 0x02
55 #define RDAC_TIMEOUT (60 * HZ)
56 #define RDAC_RETRIES 3
87 #define MODE6_MAX_LUN 32
116 #define SUBSYS_ID_LEN 16
117 #define SLOT_ID_LEN 2
118 #define ARRAY_LABEL_LEN 31
132 #define UNIQUE_ID_LEN 16
185 #define UNINITIALIZED_LUN (1 << 8)
189 #define RDAC_MODE_AVT 1
190 #define RDAC_MODE_IOSHIP 2
193 #define RDAC_STATE_ACTIVE 0
194 #define RDAC_STATE_PASSIVE 1
197 #define RDAC_LUN_UNOWNED 0
198 #define RDAC_LUN_OWNED 1
201 #define RDAC_PREFERRED 0
202 #define RDAC_NON_PREFERRED 1
214 static const char *
mode[] = {
219 static const char *lun_state[] =
242 static int rdac_logging = 1;
245 "Default is 1 - failover logging enabled, "
246 "set it to 0xF to enable all the logs");
248 #define RDAC_LOG_FAILOVER 0
249 #define RDAC_LOG_SENSE 2
251 #define RDAC_LOG_BITS 2
253 #define RDAC_LOG_LEVEL(SHIFT) \
254 ((rdac_logging >> (SHIFT)) & ((1 << (RDAC_LOG_BITS)) - 1))
256 #define RDAC_LOG(SHIFT, sdev, f, arg...) \
258 if (unlikely(RDAC_LOG_LEVEL(SHIFT))) \
259 sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \
279 "get_rdac_req: blk_get_request failed.\n");
286 "get_rdac_req: blk_rq_map_kern failed.\n");
290 rq->cmd_type = REQ_TYPE_BLOCK_PC;
308 if (h->
ctlr->use_ms10) {
312 rdac_pg = &h->
ctlr->mode_select.expanded;
313 memset(rdac_pg, 0, data_size);
314 common = &rdac_pg->
common;
324 rdac_pg = &h->
ctlr->mode_select.legacy;
325 memset(rdac_pg, 0, data_size);
326 common = &rdac_pg->
common;
336 lun_table[qdata->
h->lun] = 0x81;
340 rq = get_rdac_req(sdev, &h->
ctlr->mode_select, data_size,
WRITE);
345 if (h->
ctlr->use_ms10) {
347 rq->cmd[7] = data_size >> 8;
348 rq->cmd[8] = data_size & 0xff;
355 rq->sense = h->
sense;
362 static void release_controller(
struct kref *
kref)
378 (tmp->
index == index) &&
380 kref_get(&tmp->
kref);
394 kref_init(&ctlr->
kref);
400 INIT_LIST_HEAD(&ctlr->
ms_head);
401 list_add(&ctlr->
node, &ctlr_list);
413 rq = get_rdac_req(sdev, &h->
inq, len,
READ);
424 rq->sense = h->
sense;
438 char *array_name,
u8 *array_id)
443 err = submit_inquiry(sdev, 0xC8,
sizeof(
struct c8_inquiry), h);
456 *(array_name+ARRAY_LABEL_LEN-1) =
'\0';
469 err = submit_inquiry(sdev, 0xC9,
sizeof(
struct c9_inquiry), h);
499 static int initialize_controller(
struct scsi_device *sdev,
505 err = submit_inquiry(sdev, 0xC4,
sizeof(
struct c4_inquiry), h);
515 h->
ctlr = get_controller(index, array_name, array_id, sdev);
528 err = submit_inquiry(sdev, 0xC2,
sizeof(
struct c2_inquiry), h);
536 h->
ctlr->use_ms10 = 1;
538 h->
ctlr->use_ms10 = 0;
543 static int mode_select_handle_sense(
struct scsi_device *sdev,
544 unsigned char *sensebuf)
554 switch (sense_hdr.sense_key) {
561 if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01)
568 if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36)
579 "MODE_SELECT returned with sense %02x/%02x/%02x",
580 (
char *) h->
ctlr->array_name, h->
ctlr->index,
581 sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq);
600 list_splice_init(&ctlr->
ms_head, &list);
607 rq = rdac_failover_get(sdev, h, &list);
612 "%s MODE_SELECT command",
613 (
char *) h->
ctlr->array_name, h->
ctlr->index,
619 err = mode_select_handle_sense(sdev, h->
sense);
626 "MODE_SELECT completed",
627 (
char *) h->
ctlr->array_name, h->
ctlr->index);
642 static int queue_mode_select(
struct scsi_device *sdev,
652 qdata->
h = get_rdac_data(sdev);
656 ctlr = qdata->
h->ctlr;
675 err = check_ownership(sdev, h);
694 err = queue_mode_select(sdev, fn, data);
707 int ret = BLKPREP_OK;
717 static int rdac_check_sense(
struct scsi_device *sdev,
723 "I/O returned with sense %02x/%02x/%02x",
724 (
char *) h->
ctlr->array_name, h->
ctlr->index,
729 if (sense_hdr->
asc == 0x04 && sense_hdr->
ascq == 0x01)
735 if (sense_hdr->
asc == 0x04 && sense_hdr->
ascq == 0x81)
742 if (sense_hdr->
asc == 0x04 && sense_hdr->
ascq == 0xA1)
748 if (sense_hdr->
asc == 0xA1 && sense_hdr->
ascq == 0x02)
756 if (sense_hdr->
asc == 0x94 && sense_hdr->
ascq == 0x01) {
766 if (sense_hdr->
asc == 0x29 && sense_hdr->
ascq == 0x00)
771 if (sense_hdr->
asc == 0x8b && sense_hdr->
ascq == 0x02)
795 {
"STK",
"OPENstorage D280"},
796 {
"STK",
"FLEXLINE 380"},
799 {
"SUN",
"STK6580_6780"},
801 {
"SUN",
"ArrayStorage"},
803 {
"NETAPP",
"INF-01-00"},
804 {
"LSI",
"INF-01-00"},
805 {
"ENGENIO",
"INF-01-00"},
813 if (scsi_device_tpgs(sdev))
816 for (i = 0; rdac_dev_list[
i].
vendor; i++) {
827 static int rdac_bus_attach(
struct scsi_device *sdev);
828 static void rdac_bus_detach(
struct scsi_device *sdev);
833 .devlist = rdac_dev_list,
834 .prep_fn = rdac_prep_fn,
835 .check_sense = rdac_check_sense,
836 .attach = rdac_bus_attach,
837 .detach = rdac_bus_detach,
838 .activate = rdac_activate,
842 static int rdac_bus_attach(
struct scsi_device *sdev)
851 scsi_dh_data = kzalloc(
sizeof(*scsi_dh_data)
859 scsi_dh_data->
scsi_dh = &rdac_dh;
864 err = get_lun_info(sdev, h, array_name, array_id);
868 err = initialize_controller(sdev, h, array_name, array_id);
872 err = check_ownership(sdev, h);
876 err = set_mode_select(sdev, h);
885 spin_unlock_irqrestore(sdev->
request_queue->queue_lock, flags);
888 "%s: LUN %d (%s) (%s)\n",
896 kref_put(&h->
ctlr->kref, release_controller);
906 static void rdac_bus_detach(
struct scsi_device *sdev )
919 spin_unlock_irqrestore(sdev->
request_queue->queue_lock, flags);
923 kref_put(&h->
ctlr->kref, release_controller);
932 static int __init rdac_init(
void)
956 static void __exit rdac_exit(
void)