Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ryusuke...
[linux-2.6-block.git] / drivers / scsi / device_handler / scsi_dh_rdac.c
CommitLineData
fbd7ab3e
CS
1/*
2 * Engenio/LSI RDAC SCSI Device Handler
3 *
4 * Copyright (C) 2005 Mike Christie. All rights reserved.
5 * Copyright (C) Chandra Seetharaman, IBM Corp. 2007
6 *
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.
11 *
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.
16 *
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.
20 *
21 */
22#include <scsi/scsi.h>
23#include <scsi/scsi_eh.h>
24#include <scsi/scsi_dh.h>
25
26#define RDAC_NAME "rdac"
c85f8cb9 27#define RDAC_RETRY_COUNT 5
fbd7ab3e
CS
28
29/*
30 * LSI mode page stuff
31 *
32 * These struct definitions and the forming of the
33 * mode page were taken from the LSI RDAC 2.4 GPL'd
34 * driver, and then converted to Linux conventions.
35 */
36#define RDAC_QUIESCENCE_TIME 20;
37/*
38 * Page Codes
39 */
40#define RDAC_PAGE_CODE_REDUNDANT_CONTROLLER 0x2c
41
42/*
43 * Controller modes definitions
44 */
45#define RDAC_MODE_TRANSFER_SPECIFIED_LUNS 0x02
46
47/*
48 * RDAC Options field
49 */
50#define RDAC_FORCED_QUIESENCE 0x02
51
52#define RDAC_TIMEOUT (60 * HZ)
53#define RDAC_RETRIES 3
54
55struct rdac_mode_6_hdr {
56 u8 data_len;
57 u8 medium_type;
58 u8 device_params;
59 u8 block_desc_len;
60};
61
62struct rdac_mode_10_hdr {
63 u16 data_len;
64 u8 medium_type;
65 u8 device_params;
66 u16 reserved;
67 u16 block_desc_len;
68};
69
70struct rdac_mode_common {
71 u8 controller_serial[16];
72 u8 alt_controller_serial[16];
73 u8 rdac_mode[2];
74 u8 alt_rdac_mode[2];
75 u8 quiescence_timeout;
76 u8 rdac_options;
77};
78
79struct rdac_pg_legacy {
80 struct rdac_mode_6_hdr hdr;
81 u8 page_code;
82 u8 page_len;
83 struct rdac_mode_common common;
84#define MODE6_MAX_LUN 32
85 u8 lun_table[MODE6_MAX_LUN];
86 u8 reserved2[32];
87 u8 reserved3;
88 u8 reserved4;
89};
90
91struct rdac_pg_expanded {
92 struct rdac_mode_10_hdr hdr;
93 u8 page_code;
94 u8 subpage_code;
95 u8 page_len[2];
96 struct rdac_mode_common common;
97 u8 lun_table[256];
98 u8 reserved3;
99 u8 reserved4;
100};
101
102struct c9_inquiry {
103 u8 peripheral_info;
104 u8 page_code; /* 0xC9 */
105 u8 reserved1;
106 u8 page_len;
107 u8 page_id[4]; /* "vace" */
108 u8 avte_cvp;
109 u8 path_prio;
110 u8 reserved2[38];
111};
112
113#define SUBSYS_ID_LEN 16
114#define SLOT_ID_LEN 2
115
116struct c4_inquiry {
117 u8 peripheral_info;
118 u8 page_code; /* 0xC4 */
119 u8 reserved1;
120 u8 page_len;
121 u8 page_id[4]; /* "subs" */
122 u8 subsys_id[SUBSYS_ID_LEN];
123 u8 revision[4];
124 u8 slot_id[SLOT_ID_LEN];
125 u8 reserved[2];
126};
127
128struct rdac_controller {
129 u8 subsys_id[SUBSYS_ID_LEN];
130 u8 slot_id[SLOT_ID_LEN];
131 int use_ms10;
132 struct kref kref;
133 struct list_head node; /* list of all controllers */
134 union {
135 struct rdac_pg_legacy legacy;
136 struct rdac_pg_expanded expanded;
137 } mode_select;
138};
139struct c8_inquiry {
140 u8 peripheral_info;
141 u8 page_code; /* 0xC8 */
142 u8 reserved1;
143 u8 page_len;
144 u8 page_id[4]; /* "edid" */
145 u8 reserved2[3];
146 u8 vol_uniq_id_len;
147 u8 vol_uniq_id[16];
148 u8 vol_user_label_len;
149 u8 vol_user_label[60];
150 u8 array_uniq_id_len;
151 u8 array_unique_id[16];
152 u8 array_user_label_len;
153 u8 array_user_label[60];
154 u8 lun[8];
155};
156
157struct c2_inquiry {
158 u8 peripheral_info;
159 u8 page_code; /* 0xC2 */
160 u8 reserved1;
161 u8 page_len;
162 u8 page_id[4]; /* "swr4" */
163 u8 sw_version[3];
164 u8 sw_date[3];
165 u8 features_enabled;
166 u8 max_lun_supported;
167 u8 partitions[239]; /* Total allocation length should be 0xFF */
168};
169
170struct rdac_dh_data {
171 struct rdac_controller *ctlr;
172#define UNINITIALIZED_LUN (1 << 8)
173 unsigned lun;
174#define RDAC_STATE_ACTIVE 0
175#define RDAC_STATE_PASSIVE 1
176 unsigned char state;
ca9f0089
HR
177
178#define RDAC_LUN_UNOWNED 0
179#define RDAC_LUN_OWNED 1
180#define RDAC_LUN_AVT 2
181 char lun_state;
fbd7ab3e
CS
182 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
183 union {
184 struct c2_inquiry c2;
185 struct c4_inquiry c4;
186 struct c8_inquiry c8;
187 struct c9_inquiry c9;
188 } inq;
189};
190
ca9f0089
HR
191static const char *lun_state[] =
192{
193 "unowned",
194 "owned",
195 "owned (AVT mode)",
196};
197
fbd7ab3e
CS
198static LIST_HEAD(ctlr_list);
199static DEFINE_SPINLOCK(list_lock);
200
201static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
202{
203 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data;
204 BUG_ON(scsi_dh_data == NULL);
205 return ((struct rdac_dh_data *) scsi_dh_data->buf);
206}
207
208static struct request *get_rdac_req(struct scsi_device *sdev,
209 void *buffer, unsigned buflen, int rw)
210{
211 struct request *rq;
212 struct request_queue *q = sdev->request_queue;
fbd7ab3e 213
ca9f0089 214 rq = blk_get_request(q, rw, GFP_NOIO);
fbd7ab3e
CS
215
216 if (!rq) {
217 sdev_printk(KERN_INFO, sdev,
218 "get_rdac_req: blk_get_request failed.\n");
219 return NULL;
220 }
221
ca9f0089 222 if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) {
fbd7ab3e
CS
223 blk_put_request(rq);
224 sdev_printk(KERN_INFO, sdev,
225 "get_rdac_req: blk_rq_map_kern failed.\n");
226 return NULL;
227 }
228
fbd7ab3e 229 rq->cmd_type = REQ_TYPE_BLOCK_PC;
6000a368
MC
230 rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
231 REQ_FAILFAST_DRIVER;
fbd7ab3e
CS
232 rq->retries = RDAC_RETRIES;
233 rq->timeout = RDAC_TIMEOUT;
234
235 return rq;
236}
237
ca9f0089
HR
238static struct request *rdac_failover_get(struct scsi_device *sdev,
239 struct rdac_dh_data *h)
fbd7ab3e
CS
240{
241 struct request *rq;
242 struct rdac_mode_common *common;
243 unsigned data_size;
fbd7ab3e
CS
244
245 if (h->ctlr->use_ms10) {
246 struct rdac_pg_expanded *rdac_pg;
247
248 data_size = sizeof(struct rdac_pg_expanded);
249 rdac_pg = &h->ctlr->mode_select.expanded;
250 memset(rdac_pg, 0, data_size);
251 common = &rdac_pg->common;
252 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER + 0x40;
253 rdac_pg->subpage_code = 0x1;
254 rdac_pg->page_len[0] = 0x01;
255 rdac_pg->page_len[1] = 0x28;
256 rdac_pg->lun_table[h->lun] = 0x81;
257 } else {
258 struct rdac_pg_legacy *rdac_pg;
259
260 data_size = sizeof(struct rdac_pg_legacy);
261 rdac_pg = &h->ctlr->mode_select.legacy;
262 memset(rdac_pg, 0, data_size);
263 common = &rdac_pg->common;
264 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER;
265 rdac_pg->page_len = 0x68;
266 rdac_pg->lun_table[h->lun] = 0x81;
267 }
268 common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS;
269 common->quiescence_timeout = RDAC_QUIESCENCE_TIME;
270 common->rdac_options = RDAC_FORCED_QUIESENCE;
271
272 /* get request for block layer packet command */
273 rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE);
274 if (!rq)
275 return NULL;
276
277 /* Prepare the command. */
278 if (h->ctlr->use_ms10) {
279 rq->cmd[0] = MODE_SELECT_10;
280 rq->cmd[7] = data_size >> 8;
281 rq->cmd[8] = data_size & 0xff;
282 } else {
283 rq->cmd[0] = MODE_SELECT;
284 rq->cmd[4] = data_size;
285 }
286 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
287
ca9f0089
HR
288 rq->sense = h->sense;
289 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
290 rq->sense_len = 0;
291
fbd7ab3e
CS
292 return rq;
293}
294
295static void release_controller(struct kref *kref)
296{
297 struct rdac_controller *ctlr;
298 ctlr = container_of(kref, struct rdac_controller, kref);
299
300 spin_lock(&list_lock);
301 list_del(&ctlr->node);
302 spin_unlock(&list_lock);
303 kfree(ctlr);
304}
305
306static struct rdac_controller *get_controller(u8 *subsys_id, u8 *slot_id)
307{
308 struct rdac_controller *ctlr, *tmp;
309
310 spin_lock(&list_lock);
311
312 list_for_each_entry(tmp, &ctlr_list, node) {
313 if ((memcmp(tmp->subsys_id, subsys_id, SUBSYS_ID_LEN) == 0) &&
314 (memcmp(tmp->slot_id, slot_id, SLOT_ID_LEN) == 0)) {
315 kref_get(&tmp->kref);
316 spin_unlock(&list_lock);
317 return tmp;
318 }
319 }
320 ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC);
321 if (!ctlr)
322 goto done;
323
324 /* initialize fields of controller */
325 memcpy(ctlr->subsys_id, subsys_id, SUBSYS_ID_LEN);
326 memcpy(ctlr->slot_id, slot_id, SLOT_ID_LEN);
327 kref_init(&ctlr->kref);
328 ctlr->use_ms10 = -1;
329 list_add(&ctlr->node, &ctlr_list);
330done:
331 spin_unlock(&list_lock);
332 return ctlr;
333}
334
335static int submit_inquiry(struct scsi_device *sdev, int page_code,
ca9f0089 336 unsigned int len, struct rdac_dh_data *h)
fbd7ab3e
CS
337{
338 struct request *rq;
339 struct request_queue *q = sdev->request_queue;
fbd7ab3e
CS
340 int err = SCSI_DH_RES_TEMP_UNAVAIL;
341
342 rq = get_rdac_req(sdev, &h->inq, len, READ);
343 if (!rq)
344 goto done;
345
346 /* Prepare the command. */
347 rq->cmd[0] = INQUIRY;
348 rq->cmd[1] = 1;
349 rq->cmd[2] = page_code;
350 rq->cmd[4] = len;
351 rq->cmd_len = COMMAND_SIZE(INQUIRY);
ca9f0089
HR
352
353 rq->sense = h->sense;
354 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
355 rq->sense_len = 0;
356
fbd7ab3e
CS
357 err = blk_execute_rq(q, NULL, rq, 1);
358 if (err == -EIO)
359 err = SCSI_DH_IO;
ca9f0089
HR
360
361 blk_put_request(rq);
fbd7ab3e
CS
362done:
363 return err;
364}
365
ca9f0089 366static int get_lun(struct scsi_device *sdev, struct rdac_dh_data *h)
fbd7ab3e
CS
367{
368 int err;
369 struct c8_inquiry *inqp;
fbd7ab3e 370
ca9f0089 371 err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h);
fbd7ab3e
CS
372 if (err == SCSI_DH_OK) {
373 inqp = &h->inq.c8;
ca9f0089
HR
374 if (inqp->page_code != 0xc8)
375 return SCSI_DH_NOSYS;
376 if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' ||
377 inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd')
378 return SCSI_DH_NOSYS;
8479fca1 379 h->lun = inqp->lun[7]; /* Uses only the last byte */
fbd7ab3e
CS
380 }
381 return err;
382}
383
ca9f0089 384static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
fbd7ab3e
CS
385{
386 int err;
387 struct c9_inquiry *inqp;
fbd7ab3e 388
fe42625c 389 h->lun_state = RDAC_LUN_UNOWNED;
9eece961 390 h->state = RDAC_STATE_ACTIVE;
ca9f0089 391 err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h);
fbd7ab3e 392 if (err == SCSI_DH_OK) {
fbd7ab3e 393 inqp = &h->inq.c9;
ca9f0089
HR
394 if ((inqp->avte_cvp >> 7) == 0x1) {
395 /* LUN in AVT mode */
396 sdev_printk(KERN_NOTICE, sdev,
397 "%s: AVT mode detected\n",
398 RDAC_NAME);
399 h->lun_state = RDAC_LUN_AVT;
400 } else if ((inqp->avte_cvp & 0x1) != 0) {
401 /* LUN was owned by the controller */
402 h->lun_state = RDAC_LUN_OWNED;
403 }
404 }
405
5a36756b
CS
406 if (h->lun_state == RDAC_LUN_UNOWNED)
407 h->state = RDAC_STATE_PASSIVE;
408
fbd7ab3e
CS
409 return err;
410}
411
ca9f0089
HR
412static int initialize_controller(struct scsi_device *sdev,
413 struct rdac_dh_data *h)
fbd7ab3e
CS
414{
415 int err;
416 struct c4_inquiry *inqp;
fbd7ab3e 417
ca9f0089 418 err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h);
fbd7ab3e
CS
419 if (err == SCSI_DH_OK) {
420 inqp = &h->inq.c4;
421 h->ctlr = get_controller(inqp->subsys_id, inqp->slot_id);
422 if (!h->ctlr)
423 err = SCSI_DH_RES_TEMP_UNAVAIL;
424 }
425 return err;
426}
427
ca9f0089 428static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
fbd7ab3e
CS
429{
430 int err;
431 struct c2_inquiry *inqp;
fbd7ab3e 432
ca9f0089 433 err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h);
fbd7ab3e
CS
434 if (err == SCSI_DH_OK) {
435 inqp = &h->inq.c2;
436 /*
437 * If more than MODE6_MAX_LUN luns are supported, use
438 * mode select 10
439 */
440 if (inqp->max_lun_supported >= MODE6_MAX_LUN)
441 h->ctlr->use_ms10 = 1;
442 else
443 h->ctlr->use_ms10 = 0;
444 }
445 return err;
446}
447
ca9f0089
HR
448static int mode_select_handle_sense(struct scsi_device *sdev,
449 unsigned char *sensebuf)
fbd7ab3e
CS
450{
451 struct scsi_sense_hdr sense_hdr;
7687fb92 452 int err = SCSI_DH_IO, ret;
fbd7ab3e 453
ca9f0089 454 ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
fbd7ab3e
CS
455 if (!ret)
456 goto done;
457
458 err = SCSI_DH_OK;
7687fb92
CV
459
460 switch (sense_hdr.sense_key) {
461 case NO_SENSE:
462 case ABORTED_COMMAND:
463 case UNIT_ATTENTION:
fbd7ab3e 464 err = SCSI_DH_RETRY;
7687fb92
CV
465 break;
466 case NOT_READY:
467 if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01)
468 /* LUN Not Ready and is in the Process of Becoming
469 * Ready
470 */
471 err = SCSI_DH_RETRY;
472 break;
473 case ILLEGAL_REQUEST:
474 if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36)
475 /*
476 * Command Lock contention
477 */
478 err = SCSI_DH_RETRY;
479 break;
480 default:
481 sdev_printk(KERN_INFO, sdev,
482 "MODE_SELECT failed with sense %02x/%02x/%02x.\n",
483 sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq);
fbd7ab3e
CS
484 }
485
fbd7ab3e
CS
486done:
487 return err;
488}
489
ca9f0089 490static int send_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
fbd7ab3e
CS
491{
492 struct request *rq;
493 struct request_queue *q = sdev->request_queue;
c85f8cb9 494 int err, retry_cnt = RDAC_RETRY_COUNT;
fbd7ab3e 495
c85f8cb9
CS
496retry:
497 err = SCSI_DH_RES_TEMP_UNAVAIL;
ca9f0089 498 rq = rdac_failover_get(sdev, h);
fbd7ab3e
CS
499 if (!rq)
500 goto done;
501
c85f8cb9
CS
502 sdev_printk(KERN_INFO, sdev, "%s MODE_SELECT command.\n",
503 (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying");
fbd7ab3e
CS
504
505 err = blk_execute_rq(q, NULL, rq, 1);
c85f8cb9
CS
506 blk_put_request(rq);
507 if (err != SCSI_DH_OK) {
ca9f0089 508 err = mode_select_handle_sense(sdev, h->sense);
c85f8cb9
CS
509 if (err == SCSI_DH_RETRY && retry_cnt--)
510 goto retry;
511 }
fbd7ab3e
CS
512 if (err == SCSI_DH_OK)
513 h->state = RDAC_STATE_ACTIVE;
ca9f0089 514
fbd7ab3e
CS
515done:
516 return err;
517}
518
519static int rdac_activate(struct scsi_device *sdev)
520{
521 struct rdac_dh_data *h = get_rdac_data(sdev);
522 int err = SCSI_DH_OK;
523
ca9f0089
HR
524 err = check_ownership(sdev, h);
525 if (err != SCSI_DH_OK)
fbd7ab3e 526 goto done;
fbd7ab3e
CS
527
528 if (!h->ctlr) {
ca9f0089 529 err = initialize_controller(sdev, h);
fbd7ab3e
CS
530 if (err != SCSI_DH_OK)
531 goto done;
532 }
533
534 if (h->ctlr->use_ms10 == -1) {
ca9f0089 535 err = set_mode_select(sdev, h);
fbd7ab3e
CS
536 if (err != SCSI_DH_OK)
537 goto done;
538 }
ca9f0089
HR
539 if (h->lun_state == RDAC_LUN_UNOWNED)
540 err = send_mode_select(sdev, h);
fbd7ab3e
CS
541done:
542 return err;
543}
544
545static int rdac_prep_fn(struct scsi_device *sdev, struct request *req)
546{
547 struct rdac_dh_data *h = get_rdac_data(sdev);
548 int ret = BLKPREP_OK;
549
550 if (h->state != RDAC_STATE_ACTIVE) {
551 ret = BLKPREP_KILL;
552 req->cmd_flags |= REQ_QUIET;
553 }
554 return ret;
555
556}
557
558static int rdac_check_sense(struct scsi_device *sdev,
559 struct scsi_sense_hdr *sense_hdr)
560{
561 struct rdac_dh_data *h = get_rdac_data(sdev);
562 switch (sense_hdr->sense_key) {
563 case NOT_READY:
8f032263
CV
564 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01)
565 /* LUN Not Ready - Logical Unit Not Ready and is in
566 * the process of becoming ready
567 * Just retry.
568 */
569 return ADD_TO_MLQUEUE;
fbd7ab3e
CS
570 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81)
571 /* LUN Not Ready - Storage firmware incompatible
572 * Manual code synchonisation required.
573 *
574 * Nothing we can do here. Try to bypass the path.
575 */
576 return SUCCESS;
577 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1)
578 /* LUN Not Ready - Quiescense in progress
579 *
580 * Just retry and wait.
581 */
c7dbb627 582 return ADD_TO_MLQUEUE;
af50bb99
CV
583 if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02)
584 /* LUN Not Ready - Quiescense in progress
585 * or has been achieved
586 * Just retry.
587 */
588 return ADD_TO_MLQUEUE;
fbd7ab3e
CS
589 break;
590 case ILLEGAL_REQUEST:
591 if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) {
592 /* Invalid Request - Current Logical Unit Ownership.
593 * Controller is not the current owner of the LUN,
594 * Fail the path, so that the other path be used.
595 */
596 h->state = RDAC_STATE_PASSIVE;
597 return SUCCESS;
598 }
599 break;
600 case UNIT_ATTENTION:
601 if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00)
602 /*
603 * Power On, Reset, or Bus Device Reset, just retry.
ea41e415
CV
604 */
605 return ADD_TO_MLQUEUE;
606 if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02)
607 /*
608 * Quiescence in progress , just retry.
fbd7ab3e 609 */
c7dbb627 610 return ADD_TO_MLQUEUE;
fbd7ab3e
CS
611 break;
612 }
613 /* success just means we do not care what scsi-ml does */
614 return SCSI_RETURN_NOT_HANDLED;
615}
616
f08c0761 617static const struct scsi_dh_devlist rdac_dev_list[] = {
fbd7ab3e
CS
618 {"IBM", "1722"},
619 {"IBM", "1724"},
620 {"IBM", "1726"},
621 {"IBM", "1742"},
622 {"IBM", "1814"},
623 {"IBM", "1815"},
624 {"IBM", "1818"},
625 {"IBM", "3526"},
626 {"SGI", "TP9400"},
627 {"SGI", "TP9500"},
628 {"SGI", "IS"},
629 {"STK", "OPENstorage D280"},
630 {"SUN", "CSM200_R"},
631 {"SUN", "LCSM100_F"},
650849d7
YD
632 {"DELL", "MD3000"},
633 {"DELL", "MD3000i"},
273c4781
BM
634 {"LSI", "INF-01-00"},
635 {"ENGENIO", "INF-01-00"},
fbd7ab3e
CS
636 {NULL, NULL},
637};
638
765cbc6d
HR
639static int rdac_bus_attach(struct scsi_device *sdev);
640static void rdac_bus_detach(struct scsi_device *sdev);
fbd7ab3e
CS
641
642static struct scsi_device_handler rdac_dh = {
643 .name = RDAC_NAME,
644 .module = THIS_MODULE,
765cbc6d 645 .devlist = rdac_dev_list,
fbd7ab3e
CS
646 .prep_fn = rdac_prep_fn,
647 .check_sense = rdac_check_sense,
765cbc6d
HR
648 .attach = rdac_bus_attach,
649 .detach = rdac_bus_detach,
fbd7ab3e
CS
650 .activate = rdac_activate,
651};
652
765cbc6d 653static int rdac_bus_attach(struct scsi_device *sdev)
fbd7ab3e 654{
fbd7ab3e
CS
655 struct scsi_dh_data *scsi_dh_data;
656 struct rdac_dh_data *h;
fbd7ab3e 657 unsigned long flags;
ca9f0089 658 int err;
fbd7ab3e 659
765cbc6d
HR
660 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *)
661 + sizeof(*h) , GFP_KERNEL);
662 if (!scsi_dh_data) {
ca9f0089 663 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
765cbc6d 664 RDAC_NAME);
33af79d1 665 return 0;
765cbc6d 666 }
33af79d1 667
765cbc6d
HR
668 scsi_dh_data->scsi_dh = &rdac_dh;
669 h = (struct rdac_dh_data *) scsi_dh_data->buf;
670 h->lun = UNINITIALIZED_LUN;
671 h->state = RDAC_STATE_ACTIVE;
ca9f0089
HR
672
673 err = get_lun(sdev, h);
674 if (err != SCSI_DH_OK)
675 goto failed;
676
677 err = check_ownership(sdev, h);
678 if (err != SCSI_DH_OK)
679 goto failed;
680
681 if (!try_module_get(THIS_MODULE))
682 goto failed;
683
765cbc6d
HR
684 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
685 sdev->scsi_dh_data = scsi_dh_data;
686 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
fbd7ab3e 687
ca9f0089
HR
688 sdev_printk(KERN_NOTICE, sdev,
689 "%s: LUN %d (%s)\n",
690 RDAC_NAME, h->lun, lun_state[(int)h->lun_state]);
fbd7ab3e 691
fbd7ab3e 692 return 0;
ca9f0089
HR
693
694failed:
695 kfree(scsi_dh_data);
696 sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
697 RDAC_NAME);
698 return -EINVAL;
fbd7ab3e
CS
699}
700
765cbc6d
HR
701static void rdac_bus_detach( struct scsi_device *sdev )
702{
703 struct scsi_dh_data *scsi_dh_data;
704 struct rdac_dh_data *h;
705 unsigned long flags;
706
707 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
708 scsi_dh_data = sdev->scsi_dh_data;
709 sdev->scsi_dh_data = NULL;
710 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
711
712 h = (struct rdac_dh_data *) scsi_dh_data->buf;
713 if (h->ctlr)
714 kref_put(&h->ctlr->kref, release_controller);
715 kfree(scsi_dh_data);
716 module_put(THIS_MODULE);
ca9f0089 717 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
765cbc6d
HR
718}
719
720
721
fbd7ab3e
CS
722static int __init rdac_init(void)
723{
724 int r;
725
726 r = scsi_register_device_handler(&rdac_dh);
727 if (r != 0)
728 printk(KERN_ERR "Failed to register scsi device handler.");
729 return r;
730}
731
732static void __exit rdac_exit(void)
733{
734 scsi_unregister_device_handler(&rdac_dh);
735}
736
737module_init(rdac_init);
738module_exit(rdac_exit);
739
740MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver");
741MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
742MODULE_LICENSE("GPL");