[SCSI] scsi_dh_rdac : Add definitions for different RDAC operating modes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / device_handler / scsi_dh_rdac.c
blobafb2fb1a5186a4f7cf16c7775691644b39a1b96f
1 /*
2 * Engenio/LSI RDAC SCSI Device Handler
4 * Copyright (C) 2005 Mike Christie. All rights reserved.
5 * Copyright (C) Chandra Seetharaman, IBM Corp. 2007
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <scsi/scsi.h>
23 #include <scsi/scsi_eh.h>
24 #include <scsi/scsi_dh.h>
25 #include <linux/workqueue.h>
26 #include <linux/slab.h>
28 #define RDAC_NAME "rdac"
29 #define RDAC_RETRY_COUNT 5
32 * LSI mode page stuff
34 * These struct definitions and the forming of the
35 * mode page were taken from the LSI RDAC 2.4 GPL'd
36 * driver, and then converted to Linux conventions.
38 #define RDAC_QUIESCENCE_TIME 20;
40 * Page Codes
42 #define RDAC_PAGE_CODE_REDUNDANT_CONTROLLER 0x2c
45 * Controller modes definitions
47 #define RDAC_MODE_TRANSFER_SPECIFIED_LUNS 0x02
50 * RDAC Options field
52 #define RDAC_FORCED_QUIESENCE 0x02
54 #define RDAC_TIMEOUT (60 * HZ)
55 #define RDAC_RETRIES 3
57 struct rdac_mode_6_hdr {
58 u8 data_len;
59 u8 medium_type;
60 u8 device_params;
61 u8 block_desc_len;
64 struct rdac_mode_10_hdr {
65 u16 data_len;
66 u8 medium_type;
67 u8 device_params;
68 u16 reserved;
69 u16 block_desc_len;
72 struct rdac_mode_common {
73 u8 controller_serial[16];
74 u8 alt_controller_serial[16];
75 u8 rdac_mode[2];
76 u8 alt_rdac_mode[2];
77 u8 quiescence_timeout;
78 u8 rdac_options;
81 struct rdac_pg_legacy {
82 struct rdac_mode_6_hdr hdr;
83 u8 page_code;
84 u8 page_len;
85 struct rdac_mode_common common;
86 #define MODE6_MAX_LUN 32
87 u8 lun_table[MODE6_MAX_LUN];
88 u8 reserved2[32];
89 u8 reserved3;
90 u8 reserved4;
93 struct rdac_pg_expanded {
94 struct rdac_mode_10_hdr hdr;
95 u8 page_code;
96 u8 subpage_code;
97 u8 page_len[2];
98 struct rdac_mode_common common;
99 u8 lun_table[256];
100 u8 reserved3;
101 u8 reserved4;
104 struct c9_inquiry {
105 u8 peripheral_info;
106 u8 page_code; /* 0xC9 */
107 u8 reserved1;
108 u8 page_len;
109 u8 page_id[4]; /* "vace" */
110 u8 avte_cvp;
111 u8 path_prio;
112 u8 reserved2[38];
115 #define SUBSYS_ID_LEN 16
116 #define SLOT_ID_LEN 2
117 #define ARRAY_LABEL_LEN 31
119 struct c4_inquiry {
120 u8 peripheral_info;
121 u8 page_code; /* 0xC4 */
122 u8 reserved1;
123 u8 page_len;
124 u8 page_id[4]; /* "subs" */
125 u8 subsys_id[SUBSYS_ID_LEN];
126 u8 revision[4];
127 u8 slot_id[SLOT_ID_LEN];
128 u8 reserved[2];
131 struct rdac_controller {
132 u8 subsys_id[SUBSYS_ID_LEN];
133 u8 slot_id[SLOT_ID_LEN];
134 int use_ms10;
135 struct kref kref;
136 struct list_head node; /* list of all controllers */
137 union {
138 struct rdac_pg_legacy legacy;
139 struct rdac_pg_expanded expanded;
140 } mode_select;
141 u8 index;
142 u8 array_name[ARRAY_LABEL_LEN];
143 spinlock_t ms_lock;
144 int ms_queued;
145 struct work_struct ms_work;
146 struct scsi_device *ms_sdev;
147 struct list_head ms_head;
150 struct c8_inquiry {
151 u8 peripheral_info;
152 u8 page_code; /* 0xC8 */
153 u8 reserved1;
154 u8 page_len;
155 u8 page_id[4]; /* "edid" */
156 u8 reserved2[3];
157 u8 vol_uniq_id_len;
158 u8 vol_uniq_id[16];
159 u8 vol_user_label_len;
160 u8 vol_user_label[60];
161 u8 array_uniq_id_len;
162 u8 array_unique_id[16];
163 u8 array_user_label_len;
164 u8 array_user_label[60];
165 u8 lun[8];
168 struct c2_inquiry {
169 u8 peripheral_info;
170 u8 page_code; /* 0xC2 */
171 u8 reserved1;
172 u8 page_len;
173 u8 page_id[4]; /* "swr4" */
174 u8 sw_version[3];
175 u8 sw_date[3];
176 u8 features_enabled;
177 u8 max_lun_supported;
178 u8 partitions[239]; /* Total allocation length should be 0xFF */
181 struct rdac_dh_data {
182 struct rdac_controller *ctlr;
183 #define UNINITIALIZED_LUN (1 << 8)
184 unsigned lun;
186 #define RDAC_MODE 0
187 #define RDAC_MODE_AVT 1
188 #define RDAC_MODE_IOSHIP 2
189 unsigned char mode;
191 #define RDAC_STATE_ACTIVE 0
192 #define RDAC_STATE_PASSIVE 1
193 unsigned char state;
195 #define RDAC_LUN_UNOWNED 0
196 #define RDAC_LUN_OWNED 1
197 #define RDAC_LUN_AVT 2
198 char lun_state;
200 #define RDAC_PREFERRED 0
201 #define RDAC_NON_PREFERRED 1
202 char preferred;
204 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
205 union {
206 struct c2_inquiry c2;
207 struct c4_inquiry c4;
208 struct c8_inquiry c8;
209 struct c9_inquiry c9;
210 } inq;
213 static const char *mode[] = {
214 "RDAC",
215 "AVT",
216 "IOSHIP",
218 static const char *lun_state[] =
220 "unowned",
221 "owned",
224 struct rdac_queue_data {
225 struct list_head entry;
226 struct rdac_dh_data *h;
227 activate_complete callback_fn;
228 void *callback_data;
231 static LIST_HEAD(ctlr_list);
232 static DEFINE_SPINLOCK(list_lock);
233 static struct workqueue_struct *kmpath_rdacd;
234 static void send_mode_select(struct work_struct *work);
237 * module parameter to enable rdac debug logging.
238 * 2 bits for each type of logging, only two types defined for now
239 * Can be enhanced if required at later point
241 static int rdac_logging = 1;
242 module_param(rdac_logging, int, S_IRUGO|S_IWUSR);
243 MODULE_PARM_DESC(rdac_logging, "A bit mask of rdac logging levels, "
244 "Default is 1 - failover logging enabled, "
245 "set it to 0xF to enable all the logs");
247 #define RDAC_LOG_FAILOVER 0
248 #define RDAC_LOG_SENSE 2
250 #define RDAC_LOG_BITS 2
252 #define RDAC_LOG_LEVEL(SHIFT) \
253 ((rdac_logging >> (SHIFT)) & ((1 << (RDAC_LOG_BITS)) - 1))
255 #define RDAC_LOG(SHIFT, sdev, f, arg...) \
256 do { \
257 if (unlikely(RDAC_LOG_LEVEL(SHIFT))) \
258 sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \
259 } while (0);
261 static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
263 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data;
264 BUG_ON(scsi_dh_data == NULL);
265 return ((struct rdac_dh_data *) scsi_dh_data->buf);
268 static struct request *get_rdac_req(struct scsi_device *sdev,
269 void *buffer, unsigned buflen, int rw)
271 struct request *rq;
272 struct request_queue *q = sdev->request_queue;
274 rq = blk_get_request(q, rw, GFP_NOIO);
276 if (!rq) {
277 sdev_printk(KERN_INFO, sdev,
278 "get_rdac_req: blk_get_request failed.\n");
279 return NULL;
282 if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) {
283 blk_put_request(rq);
284 sdev_printk(KERN_INFO, sdev,
285 "get_rdac_req: blk_rq_map_kern failed.\n");
286 return NULL;
289 rq->cmd_type = REQ_TYPE_BLOCK_PC;
290 rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
291 REQ_FAILFAST_DRIVER;
292 rq->retries = RDAC_RETRIES;
293 rq->timeout = RDAC_TIMEOUT;
295 return rq;
298 static struct request *rdac_failover_get(struct scsi_device *sdev,
299 struct rdac_dh_data *h, struct list_head *list)
301 struct request *rq;
302 struct rdac_mode_common *common;
303 unsigned data_size;
304 struct rdac_queue_data *qdata;
305 u8 *lun_table;
307 if (h->ctlr->use_ms10) {
308 struct rdac_pg_expanded *rdac_pg;
310 data_size = sizeof(struct rdac_pg_expanded);
311 rdac_pg = &h->ctlr->mode_select.expanded;
312 memset(rdac_pg, 0, data_size);
313 common = &rdac_pg->common;
314 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER + 0x40;
315 rdac_pg->subpage_code = 0x1;
316 rdac_pg->page_len[0] = 0x01;
317 rdac_pg->page_len[1] = 0x28;
318 lun_table = rdac_pg->lun_table;
319 } else {
320 struct rdac_pg_legacy *rdac_pg;
322 data_size = sizeof(struct rdac_pg_legacy);
323 rdac_pg = &h->ctlr->mode_select.legacy;
324 memset(rdac_pg, 0, data_size);
325 common = &rdac_pg->common;
326 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER;
327 rdac_pg->page_len = 0x68;
328 lun_table = rdac_pg->lun_table;
330 common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS;
331 common->quiescence_timeout = RDAC_QUIESCENCE_TIME;
332 common->rdac_options = RDAC_FORCED_QUIESENCE;
334 list_for_each_entry(qdata, list, entry) {
335 lun_table[qdata->h->lun] = 0x81;
338 /* get request for block layer packet command */
339 rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE);
340 if (!rq)
341 return NULL;
343 /* Prepare the command. */
344 if (h->ctlr->use_ms10) {
345 rq->cmd[0] = MODE_SELECT_10;
346 rq->cmd[7] = data_size >> 8;
347 rq->cmd[8] = data_size & 0xff;
348 } else {
349 rq->cmd[0] = MODE_SELECT;
350 rq->cmd[4] = data_size;
352 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
354 rq->sense = h->sense;
355 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
356 rq->sense_len = 0;
358 return rq;
361 static void release_controller(struct kref *kref)
363 struct rdac_controller *ctlr;
364 ctlr = container_of(kref, struct rdac_controller, kref);
366 flush_workqueue(kmpath_rdacd);
367 spin_lock(&list_lock);
368 list_del(&ctlr->node);
369 spin_unlock(&list_lock);
370 kfree(ctlr);
373 static struct rdac_controller *get_controller(u8 *subsys_id, u8 *slot_id,
374 char *array_name)
376 struct rdac_controller *ctlr, *tmp;
378 spin_lock(&list_lock);
380 list_for_each_entry(tmp, &ctlr_list, node) {
381 if ((memcmp(tmp->subsys_id, subsys_id, SUBSYS_ID_LEN) == 0) &&
382 (memcmp(tmp->slot_id, slot_id, SLOT_ID_LEN) == 0)) {
383 kref_get(&tmp->kref);
384 spin_unlock(&list_lock);
385 return tmp;
388 ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC);
389 if (!ctlr)
390 goto done;
392 /* initialize fields of controller */
393 memcpy(ctlr->subsys_id, subsys_id, SUBSYS_ID_LEN);
394 memcpy(ctlr->slot_id, slot_id, SLOT_ID_LEN);
395 memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN);
397 /* update the controller index */
398 if (slot_id[1] == 0x31)
399 ctlr->index = 0;
400 else
401 ctlr->index = 1;
403 kref_init(&ctlr->kref);
404 ctlr->use_ms10 = -1;
405 ctlr->ms_queued = 0;
406 ctlr->ms_sdev = NULL;
407 spin_lock_init(&ctlr->ms_lock);
408 INIT_WORK(&ctlr->ms_work, send_mode_select);
409 INIT_LIST_HEAD(&ctlr->ms_head);
410 list_add(&ctlr->node, &ctlr_list);
411 done:
412 spin_unlock(&list_lock);
413 return ctlr;
416 static int submit_inquiry(struct scsi_device *sdev, int page_code,
417 unsigned int len, struct rdac_dh_data *h)
419 struct request *rq;
420 struct request_queue *q = sdev->request_queue;
421 int err = SCSI_DH_RES_TEMP_UNAVAIL;
423 rq = get_rdac_req(sdev, &h->inq, len, READ);
424 if (!rq)
425 goto done;
427 /* Prepare the command. */
428 rq->cmd[0] = INQUIRY;
429 rq->cmd[1] = 1;
430 rq->cmd[2] = page_code;
431 rq->cmd[4] = len;
432 rq->cmd_len = COMMAND_SIZE(INQUIRY);
434 rq->sense = h->sense;
435 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
436 rq->sense_len = 0;
438 err = blk_execute_rq(q, NULL, rq, 1);
439 if (err == -EIO)
440 err = SCSI_DH_IO;
442 blk_put_request(rq);
443 done:
444 return err;
447 static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h,
448 char *array_name)
450 int err, i;
451 struct c8_inquiry *inqp;
453 err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h);
454 if (err == SCSI_DH_OK) {
455 inqp = &h->inq.c8;
456 if (inqp->page_code != 0xc8)
457 return SCSI_DH_NOSYS;
458 if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' ||
459 inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd')
460 return SCSI_DH_NOSYS;
461 h->lun = inqp->lun[7]; /* Uses only the last byte */
463 for(i=0; i<ARRAY_LABEL_LEN-1; ++i)
464 *(array_name+i) = inqp->array_user_label[(2*i)+1];
466 *(array_name+ARRAY_LABEL_LEN-1) = '\0';
468 return err;
471 static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
473 int err;
474 struct c9_inquiry *inqp;
476 h->lun_state = RDAC_LUN_UNOWNED;
477 h->state = RDAC_STATE_ACTIVE;
478 err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h);
479 if (err == SCSI_DH_OK) {
480 inqp = &h->inq.c9;
481 if ((inqp->avte_cvp >> 7) == 0x1) {
482 /* LUN in AVT mode */
483 sdev_printk(KERN_NOTICE, sdev,
484 "%s: AVT mode detected\n",
485 RDAC_NAME);
486 h->lun_state = RDAC_LUN_AVT;
487 } else if ((inqp->avte_cvp & 0x1) != 0) {
488 /* LUN was owned by the controller */
489 h->lun_state = RDAC_LUN_OWNED;
493 if (h->lun_state == RDAC_LUN_UNOWNED)
494 h->state = RDAC_STATE_PASSIVE;
496 return err;
499 static int initialize_controller(struct scsi_device *sdev,
500 struct rdac_dh_data *h, char *array_name)
502 int err;
503 struct c4_inquiry *inqp;
505 err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h);
506 if (err == SCSI_DH_OK) {
507 inqp = &h->inq.c4;
508 h->ctlr = get_controller(inqp->subsys_id, inqp->slot_id,
509 array_name);
510 if (!h->ctlr)
511 err = SCSI_DH_RES_TEMP_UNAVAIL;
513 return err;
516 static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
518 int err;
519 struct c2_inquiry *inqp;
521 err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h);
522 if (err == SCSI_DH_OK) {
523 inqp = &h->inq.c2;
525 * If more than MODE6_MAX_LUN luns are supported, use
526 * mode select 10
528 if (inqp->max_lun_supported >= MODE6_MAX_LUN)
529 h->ctlr->use_ms10 = 1;
530 else
531 h->ctlr->use_ms10 = 0;
533 return err;
536 static int mode_select_handle_sense(struct scsi_device *sdev,
537 unsigned char *sensebuf)
539 struct scsi_sense_hdr sense_hdr;
540 int err = SCSI_DH_IO, ret;
541 struct rdac_dh_data *h = get_rdac_data(sdev);
543 ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
544 if (!ret)
545 goto done;
547 switch (sense_hdr.sense_key) {
548 case NO_SENSE:
549 case ABORTED_COMMAND:
550 case UNIT_ATTENTION:
551 err = SCSI_DH_RETRY;
552 break;
553 case NOT_READY:
554 if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01)
555 /* LUN Not Ready and is in the Process of Becoming
556 * Ready
558 err = SCSI_DH_RETRY;
559 break;
560 case ILLEGAL_REQUEST:
561 if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36)
563 * Command Lock contention
565 err = SCSI_DH_RETRY;
566 break;
567 default:
568 break;
571 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
572 "MODE_SELECT returned with sense %02x/%02x/%02x",
573 (char *) h->ctlr->array_name, h->ctlr->index,
574 sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq);
576 done:
577 return err;
580 static void send_mode_select(struct work_struct *work)
582 struct rdac_controller *ctlr =
583 container_of(work, struct rdac_controller, ms_work);
584 struct request *rq;
585 struct scsi_device *sdev = ctlr->ms_sdev;
586 struct rdac_dh_data *h = get_rdac_data(sdev);
587 struct request_queue *q = sdev->request_queue;
588 int err, retry_cnt = RDAC_RETRY_COUNT;
589 struct rdac_queue_data *tmp, *qdata;
590 LIST_HEAD(list);
592 spin_lock(&ctlr->ms_lock);
593 list_splice_init(&ctlr->ms_head, &list);
594 ctlr->ms_queued = 0;
595 ctlr->ms_sdev = NULL;
596 spin_unlock(&ctlr->ms_lock);
598 retry:
599 err = SCSI_DH_RES_TEMP_UNAVAIL;
600 rq = rdac_failover_get(sdev, h, &list);
601 if (!rq)
602 goto done;
604 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
605 "%s MODE_SELECT command",
606 (char *) h->ctlr->array_name, h->ctlr->index,
607 (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying");
609 err = blk_execute_rq(q, NULL, rq, 1);
610 blk_put_request(rq);
611 if (err != SCSI_DH_OK) {
612 err = mode_select_handle_sense(sdev, h->sense);
613 if (err == SCSI_DH_RETRY && retry_cnt--)
614 goto retry;
616 if (err == SCSI_DH_OK) {
617 h->state = RDAC_STATE_ACTIVE;
618 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
619 "MODE_SELECT completed",
620 (char *) h->ctlr->array_name, h->ctlr->index);
623 done:
624 list_for_each_entry_safe(qdata, tmp, &list, entry) {
625 list_del(&qdata->entry);
626 if (err == SCSI_DH_OK)
627 qdata->h->state = RDAC_STATE_ACTIVE;
628 if (qdata->callback_fn)
629 qdata->callback_fn(qdata->callback_data, err);
630 kfree(qdata);
632 return;
635 static int queue_mode_select(struct scsi_device *sdev,
636 activate_complete fn, void *data)
638 struct rdac_queue_data *qdata;
639 struct rdac_controller *ctlr;
641 qdata = kzalloc(sizeof(*qdata), GFP_KERNEL);
642 if (!qdata)
643 return SCSI_DH_RETRY;
645 qdata->h = get_rdac_data(sdev);
646 qdata->callback_fn = fn;
647 qdata->callback_data = data;
649 ctlr = qdata->h->ctlr;
650 spin_lock(&ctlr->ms_lock);
651 list_add_tail(&qdata->entry, &ctlr->ms_head);
652 if (!ctlr->ms_queued) {
653 ctlr->ms_queued = 1;
654 ctlr->ms_sdev = sdev;
655 queue_work(kmpath_rdacd, &ctlr->ms_work);
657 spin_unlock(&ctlr->ms_lock);
658 return SCSI_DH_OK;
661 static int rdac_activate(struct scsi_device *sdev,
662 activate_complete fn, void *data)
664 struct rdac_dh_data *h = get_rdac_data(sdev);
665 int err = SCSI_DH_OK;
667 err = check_ownership(sdev, h);
668 if (err != SCSI_DH_OK)
669 goto done;
671 if (h->lun_state == RDAC_LUN_UNOWNED) {
672 err = queue_mode_select(sdev, fn, data);
673 if (err == SCSI_DH_OK)
674 return 0;
676 done:
677 if (fn)
678 fn(data, err);
679 return 0;
682 static int rdac_prep_fn(struct scsi_device *sdev, struct request *req)
684 struct rdac_dh_data *h = get_rdac_data(sdev);
685 int ret = BLKPREP_OK;
687 if (h->state != RDAC_STATE_ACTIVE) {
688 ret = BLKPREP_KILL;
689 req->cmd_flags |= REQ_QUIET;
691 return ret;
695 static int rdac_check_sense(struct scsi_device *sdev,
696 struct scsi_sense_hdr *sense_hdr)
698 struct rdac_dh_data *h = get_rdac_data(sdev);
700 RDAC_LOG(RDAC_LOG_SENSE, sdev, "array %s, ctlr %d, "
701 "I/O returned with sense %02x/%02x/%02x",
702 (char *) h->ctlr->array_name, h->ctlr->index,
703 sense_hdr->sense_key, sense_hdr->asc, sense_hdr->ascq);
705 switch (sense_hdr->sense_key) {
706 case NOT_READY:
707 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01)
708 /* LUN Not Ready - Logical Unit Not Ready and is in
709 * the process of becoming ready
710 * Just retry.
712 return ADD_TO_MLQUEUE;
713 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81)
714 /* LUN Not Ready - Storage firmware incompatible
715 * Manual code synchonisation required.
717 * Nothing we can do here. Try to bypass the path.
719 return SUCCESS;
720 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1)
721 /* LUN Not Ready - Quiescense in progress
723 * Just retry and wait.
725 return ADD_TO_MLQUEUE;
726 if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02)
727 /* LUN Not Ready - Quiescense in progress
728 * or has been achieved
729 * Just retry.
731 return ADD_TO_MLQUEUE;
732 break;
733 case ILLEGAL_REQUEST:
734 if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) {
735 /* Invalid Request - Current Logical Unit Ownership.
736 * Controller is not the current owner of the LUN,
737 * Fail the path, so that the other path be used.
739 h->state = RDAC_STATE_PASSIVE;
740 return SUCCESS;
742 break;
743 case UNIT_ATTENTION:
744 if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00)
746 * Power On, Reset, or Bus Device Reset, just retry.
748 return ADD_TO_MLQUEUE;
749 if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02)
751 * Quiescence in progress , just retry.
753 return ADD_TO_MLQUEUE;
754 break;
756 /* success just means we do not care what scsi-ml does */
757 return SCSI_RETURN_NOT_HANDLED;
760 static const struct scsi_dh_devlist rdac_dev_list[] = {
761 {"IBM", "1722"},
762 {"IBM", "1724"},
763 {"IBM", "1726"},
764 {"IBM", "1742"},
765 {"IBM", "1745"},
766 {"IBM", "1746"},
767 {"IBM", "1814"},
768 {"IBM", "1815"},
769 {"IBM", "1818"},
770 {"IBM", "3526"},
771 {"SGI", "TP9400"},
772 {"SGI", "TP9500"},
773 {"SGI", "IS"},
774 {"STK", "OPENstorage D280"},
775 {"SUN", "CSM200_R"},
776 {"SUN", "LCSM100_I"},
777 {"SUN", "LCSM100_S"},
778 {"SUN", "LCSM100_E"},
779 {"SUN", "LCSM100_F"},
780 {"DELL", "MD3000"},
781 {"DELL", "MD3000i"},
782 {"DELL", "MD32xx"},
783 {"DELL", "MD32xxi"},
784 {"DELL", "MD36xxi"},
785 {"DELL", "MD36xxf"},
786 {"LSI", "INF-01-00"},
787 {"ENGENIO", "INF-01-00"},
788 {"STK", "FLEXLINE 380"},
789 {"SUN", "CSM100_R_FC"},
790 {"SUN", "STK6580_6780"},
791 {"SUN", "SUN_6180"},
792 {NULL, NULL},
795 static int rdac_bus_attach(struct scsi_device *sdev);
796 static void rdac_bus_detach(struct scsi_device *sdev);
798 static struct scsi_device_handler rdac_dh = {
799 .name = RDAC_NAME,
800 .module = THIS_MODULE,
801 .devlist = rdac_dev_list,
802 .prep_fn = rdac_prep_fn,
803 .check_sense = rdac_check_sense,
804 .attach = rdac_bus_attach,
805 .detach = rdac_bus_detach,
806 .activate = rdac_activate,
809 static int rdac_bus_attach(struct scsi_device *sdev)
811 struct scsi_dh_data *scsi_dh_data;
812 struct rdac_dh_data *h;
813 unsigned long flags;
814 int err;
815 char array_name[ARRAY_LABEL_LEN];
817 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
818 + sizeof(*h) , GFP_KERNEL);
819 if (!scsi_dh_data) {
820 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
821 RDAC_NAME);
822 return 0;
825 scsi_dh_data->scsi_dh = &rdac_dh;
826 h = (struct rdac_dh_data *) scsi_dh_data->buf;
827 h->lun = UNINITIALIZED_LUN;
828 h->state = RDAC_STATE_ACTIVE;
830 err = get_lun_info(sdev, h, array_name);
831 if (err != SCSI_DH_OK)
832 goto failed;
834 err = initialize_controller(sdev, h, array_name);
835 if (err != SCSI_DH_OK)
836 goto failed;
838 err = check_ownership(sdev, h);
839 if (err != SCSI_DH_OK)
840 goto clean_ctlr;
842 err = set_mode_select(sdev, h);
843 if (err != SCSI_DH_OK)
844 goto clean_ctlr;
846 if (!try_module_get(THIS_MODULE))
847 goto clean_ctlr;
849 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
850 sdev->scsi_dh_data = scsi_dh_data;
851 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
853 sdev_printk(KERN_NOTICE, sdev,
854 "%s: LUN %d (%s) (%s)\n",
855 RDAC_NAME, h->lun, mode[(int)h->mode],
856 lun_state[(int)h->lun_state]);
858 return 0;
860 clean_ctlr:
861 kref_put(&h->ctlr->kref, release_controller);
863 failed:
864 kfree(scsi_dh_data);
865 sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
866 RDAC_NAME);
867 return -EINVAL;
870 static void rdac_bus_detach( struct scsi_device *sdev )
872 struct scsi_dh_data *scsi_dh_data;
873 struct rdac_dh_data *h;
874 unsigned long flags;
876 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
877 scsi_dh_data = sdev->scsi_dh_data;
878 sdev->scsi_dh_data = NULL;
879 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
881 h = (struct rdac_dh_data *) scsi_dh_data->buf;
882 if (h->ctlr)
883 kref_put(&h->ctlr->kref, release_controller);
884 kfree(scsi_dh_data);
885 module_put(THIS_MODULE);
886 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
891 static int __init rdac_init(void)
893 int r;
895 r = scsi_register_device_handler(&rdac_dh);
896 if (r != 0) {
897 printk(KERN_ERR "Failed to register scsi device handler.");
898 goto done;
902 * Create workqueue to handle mode selects for rdac
904 kmpath_rdacd = create_singlethread_workqueue("kmpath_rdacd");
905 if (!kmpath_rdacd) {
906 scsi_unregister_device_handler(&rdac_dh);
907 printk(KERN_ERR "kmpath_rdacd creation failed.\n");
909 done:
910 return r;
913 static void __exit rdac_exit(void)
915 destroy_workqueue(kmpath_rdacd);
916 scsi_unregister_device_handler(&rdac_dh);
919 module_init(rdac_init);
920 module_exit(rdac_exit);
922 MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver");
923 MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
924 MODULE_VERSION("01.00.0000.0000");
925 MODULE_LICENSE("GPL");