Merge with upstream to accommodate with thermal changes
[deliverable/linux.git] / drivers / scsi / device_handler / scsi_dh_rdac.c
CommitLineData
fbd7ab3e 1/*
5f7a6433 2 * LSI/Engenio/NetApp E-Series RDAC SCSI Device Handler
fbd7ab3e
CS
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>
970f3f47 25#include <linux/workqueue.h>
5a0e3ad6 26#include <linux/slab.h>
acf3368f 27#include <linux/module.h>
fbd7ab3e
CS
28
29#define RDAC_NAME "rdac"
c85f8cb9 30#define RDAC_RETRY_COUNT 5
fbd7ab3e
CS
31
32/*
33 * LSI mode page stuff
34 *
35 * These struct definitions and the forming of the
36 * mode page were taken from the LSI RDAC 2.4 GPL'd
37 * driver, and then converted to Linux conventions.
38 */
497888cf 39#define RDAC_QUIESCENCE_TIME 20
fbd7ab3e
CS
40/*
41 * Page Codes
42 */
43#define RDAC_PAGE_CODE_REDUNDANT_CONTROLLER 0x2c
44
45/*
46 * Controller modes definitions
47 */
48#define RDAC_MODE_TRANSFER_SPECIFIED_LUNS 0x02
49
50/*
51 * RDAC Options field
52 */
53#define RDAC_FORCED_QUIESENCE 0x02
54
55#define RDAC_TIMEOUT (60 * HZ)
56#define RDAC_RETRIES 3
57
58struct rdac_mode_6_hdr {
59 u8 data_len;
60 u8 medium_type;
61 u8 device_params;
62 u8 block_desc_len;
63};
64
65struct rdac_mode_10_hdr {
66 u16 data_len;
67 u8 medium_type;
68 u8 device_params;
69 u16 reserved;
70 u16 block_desc_len;
71};
72
73struct rdac_mode_common {
74 u8 controller_serial[16];
75 u8 alt_controller_serial[16];
76 u8 rdac_mode[2];
77 u8 alt_rdac_mode[2];
78 u8 quiescence_timeout;
79 u8 rdac_options;
80};
81
82struct rdac_pg_legacy {
83 struct rdac_mode_6_hdr hdr;
84 u8 page_code;
85 u8 page_len;
86 struct rdac_mode_common common;
87#define MODE6_MAX_LUN 32
88 u8 lun_table[MODE6_MAX_LUN];
89 u8 reserved2[32];
90 u8 reserved3;
91 u8 reserved4;
92};
93
94struct rdac_pg_expanded {
95 struct rdac_mode_10_hdr hdr;
96 u8 page_code;
97 u8 subpage_code;
98 u8 page_len[2];
99 struct rdac_mode_common common;
100 u8 lun_table[256];
101 u8 reserved3;
102 u8 reserved4;
103};
104
105struct c9_inquiry {
106 u8 peripheral_info;
107 u8 page_code; /* 0xC9 */
108 u8 reserved1;
109 u8 page_len;
110 u8 page_id[4]; /* "vace" */
111 u8 avte_cvp;
112 u8 path_prio;
113 u8 reserved2[38];
114};
115
116#define SUBSYS_ID_LEN 16
117#define SLOT_ID_LEN 2
1527666e 118#define ARRAY_LABEL_LEN 31
fbd7ab3e
CS
119
120struct c4_inquiry {
121 u8 peripheral_info;
122 u8 page_code; /* 0xC4 */
123 u8 reserved1;
124 u8 page_len;
125 u8 page_id[4]; /* "subs" */
126 u8 subsys_id[SUBSYS_ID_LEN];
127 u8 revision[4];
128 u8 slot_id[SLOT_ID_LEN];
129 u8 reserved[2];
130};
131
a53becc9 132#define UNIQUE_ID_LEN 16
fbd7ab3e
CS
133struct c8_inquiry {
134 u8 peripheral_info;
135 u8 page_code; /* 0xC8 */
136 u8 reserved1;
137 u8 page_len;
138 u8 page_id[4]; /* "edid" */
139 u8 reserved2[3];
140 u8 vol_uniq_id_len;
141 u8 vol_uniq_id[16];
142 u8 vol_user_label_len;
143 u8 vol_user_label[60];
144 u8 array_uniq_id_len;
a53becc9 145 u8 array_unique_id[UNIQUE_ID_LEN];
fbd7ab3e
CS
146 u8 array_user_label_len;
147 u8 array_user_label[60];
148 u8 lun[8];
149};
150
a53becc9
CS
151struct rdac_controller {
152 u8 array_id[UNIQUE_ID_LEN];
153 int use_ms10;
154 struct kref kref;
155 struct list_head node; /* list of all controllers */
156 union {
157 struct rdac_pg_legacy legacy;
158 struct rdac_pg_expanded expanded;
159 } mode_select;
160 u8 index;
161 u8 array_name[ARRAY_LABEL_LEN];
d6857595 162 struct Scsi_Host *host;
a53becc9
CS
163 spinlock_t ms_lock;
164 int ms_queued;
165 struct work_struct ms_work;
166 struct scsi_device *ms_sdev;
167 struct list_head ms_head;
168};
169
fbd7ab3e
CS
170struct c2_inquiry {
171 u8 peripheral_info;
172 u8 page_code; /* 0xC2 */
173 u8 reserved1;
174 u8 page_len;
175 u8 page_id[4]; /* "swr4" */
176 u8 sw_version[3];
177 u8 sw_date[3];
178 u8 features_enabled;
179 u8 max_lun_supported;
180 u8 partitions[239]; /* Total allocation length should be 0xFF */
181};
182
183struct rdac_dh_data {
184 struct rdac_controller *ctlr;
185#define UNINITIALIZED_LUN (1 << 8)
186 unsigned lun;
eebe9b96
MB
187
188#define RDAC_MODE 0
189#define RDAC_MODE_AVT 1
190#define RDAC_MODE_IOSHIP 2
191 unsigned char mode;
192
fbd7ab3e
CS
193#define RDAC_STATE_ACTIVE 0
194#define RDAC_STATE_PASSIVE 1
195 unsigned char state;
ca9f0089
HR
196
197#define RDAC_LUN_UNOWNED 0
198#define RDAC_LUN_OWNED 1
ca9f0089 199 char lun_state;
eebe9b96
MB
200
201#define RDAC_PREFERRED 0
202#define RDAC_NON_PREFERRED 1
203 char preferred;
204
fbd7ab3e
CS
205 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
206 union {
207 struct c2_inquiry c2;
208 struct c4_inquiry c4;
209 struct c8_inquiry c8;
210 struct c9_inquiry c9;
211 } inq;
212};
213
eebe9b96
MB
214static const char *mode[] = {
215 "RDAC",
216 "AVT",
217 "IOSHIP",
218};
ca9f0089
HR
219static const char *lun_state[] =
220{
221 "unowned",
222 "owned",
ca9f0089
HR
223};
224
970f3f47
CS
225struct rdac_queue_data {
226 struct list_head entry;
227 struct rdac_dh_data *h;
228 activate_complete callback_fn;
229 void *callback_data;
230};
231
fbd7ab3e
CS
232static LIST_HEAD(ctlr_list);
233static DEFINE_SPINLOCK(list_lock);
970f3f47
CS
234static struct workqueue_struct *kmpath_rdacd;
235static void send_mode_select(struct work_struct *work);
fbd7ab3e 236
dd784edc
MB
237/*
238 * module parameter to enable rdac debug logging.
239 * 2 bits for each type of logging, only two types defined for now
240 * Can be enhanced if required at later point
241 */
242static int rdac_logging = 1;
243module_param(rdac_logging, int, S_IRUGO|S_IWUSR);
244MODULE_PARM_DESC(rdac_logging, "A bit mask of rdac logging levels, "
245 "Default is 1 - failover logging enabled, "
246 "set it to 0xF to enable all the logs");
247
248#define RDAC_LOG_FAILOVER 0
249#define RDAC_LOG_SENSE 2
250
251#define RDAC_LOG_BITS 2
252
253#define RDAC_LOG_LEVEL(SHIFT) \
254 ((rdac_logging >> (SHIFT)) & ((1 << (RDAC_LOG_BITS)) - 1))
255
256#define RDAC_LOG(SHIFT, sdev, f, arg...) \
257do { \
258 if (unlikely(RDAC_LOG_LEVEL(SHIFT))) \
259 sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \
260} while (0);
261
fbd7ab3e
CS
262static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
263{
264 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data;
265 BUG_ON(scsi_dh_data == NULL);
266 return ((struct rdac_dh_data *) scsi_dh_data->buf);
267}
268
269static struct request *get_rdac_req(struct scsi_device *sdev,
270 void *buffer, unsigned buflen, int rw)
271{
272 struct request *rq;
273 struct request_queue *q = sdev->request_queue;
fbd7ab3e 274
ca9f0089 275 rq = blk_get_request(q, rw, GFP_NOIO);
fbd7ab3e
CS
276
277 if (!rq) {
278 sdev_printk(KERN_INFO, sdev,
279 "get_rdac_req: blk_get_request failed.\n");
280 return NULL;
281 }
282
ca9f0089 283 if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) {
fbd7ab3e
CS
284 blk_put_request(rq);
285 sdev_printk(KERN_INFO, sdev,
286 "get_rdac_req: blk_rq_map_kern failed.\n");
287 return NULL;
288 }
289
fbd7ab3e 290 rq->cmd_type = REQ_TYPE_BLOCK_PC;
6000a368
MC
291 rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
292 REQ_FAILFAST_DRIVER;
fbd7ab3e
CS
293 rq->retries = RDAC_RETRIES;
294 rq->timeout = RDAC_TIMEOUT;
295
296 return rq;
297}
298
ca9f0089 299static struct request *rdac_failover_get(struct scsi_device *sdev,
04b6e153 300 struct rdac_dh_data *h, struct list_head *list)
fbd7ab3e
CS
301{
302 struct request *rq;
303 struct rdac_mode_common *common;
304 unsigned data_size;
04b6e153
MB
305 struct rdac_queue_data *qdata;
306 u8 *lun_table;
fbd7ab3e
CS
307
308 if (h->ctlr->use_ms10) {
309 struct rdac_pg_expanded *rdac_pg;
310
311 data_size = sizeof(struct rdac_pg_expanded);
312 rdac_pg = &h->ctlr->mode_select.expanded;
313 memset(rdac_pg, 0, data_size);
314 common = &rdac_pg->common;
315 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER + 0x40;
316 rdac_pg->subpage_code = 0x1;
317 rdac_pg->page_len[0] = 0x01;
318 rdac_pg->page_len[1] = 0x28;
04b6e153 319 lun_table = rdac_pg->lun_table;
fbd7ab3e
CS
320 } else {
321 struct rdac_pg_legacy *rdac_pg;
322
323 data_size = sizeof(struct rdac_pg_legacy);
324 rdac_pg = &h->ctlr->mode_select.legacy;
325 memset(rdac_pg, 0, data_size);
326 common = &rdac_pg->common;
327 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER;
328 rdac_pg->page_len = 0x68;
04b6e153 329 lun_table = rdac_pg->lun_table;
fbd7ab3e
CS
330 }
331 common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS;
332 common->quiescence_timeout = RDAC_QUIESCENCE_TIME;
333 common->rdac_options = RDAC_FORCED_QUIESENCE;
334
04b6e153
MB
335 list_for_each_entry(qdata, list, entry) {
336 lun_table[qdata->h->lun] = 0x81;
337 }
338
fbd7ab3e
CS
339 /* get request for block layer packet command */
340 rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE);
341 if (!rq)
342 return NULL;
343
344 /* Prepare the command. */
345 if (h->ctlr->use_ms10) {
346 rq->cmd[0] = MODE_SELECT_10;
347 rq->cmd[7] = data_size >> 8;
348 rq->cmd[8] = data_size & 0xff;
349 } else {
350 rq->cmd[0] = MODE_SELECT;
351 rq->cmd[4] = data_size;
352 }
353 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
354
ca9f0089
HR
355 rq->sense = h->sense;
356 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
357 rq->sense_len = 0;
358
fbd7ab3e
CS
359 return rq;
360}
361
362static void release_controller(struct kref *kref)
363{
364 struct rdac_controller *ctlr;
365 ctlr = container_of(kref, struct rdac_controller, kref);
366
fbd7ab3e 367 list_del(&ctlr->node);
fbd7ab3e
CS
368 kfree(ctlr);
369}
370
a53becc9 371static struct rdac_controller *get_controller(int index, char *array_name,
d6857595 372 u8 *array_id, struct scsi_device *sdev)
fbd7ab3e
CS
373{
374 struct rdac_controller *ctlr, *tmp;
375
fbd7ab3e 376 list_for_each_entry(tmp, &ctlr_list, node) {
a53becc9 377 if ((memcmp(tmp->array_id, array_id, UNIQUE_ID_LEN) == 0) &&
d6857595
CS
378 (tmp->index == index) &&
379 (tmp->host == sdev->host)) {
fbd7ab3e 380 kref_get(&tmp->kref);
fbd7ab3e
CS
381 return tmp;
382 }
383 }
384 ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC);
385 if (!ctlr)
3569e537 386 return NULL;
fbd7ab3e
CS
387
388 /* initialize fields of controller */
a53becc9
CS
389 memcpy(ctlr->array_id, array_id, UNIQUE_ID_LEN);
390 ctlr->index = index;
d6857595 391 ctlr->host = sdev->host;
1527666e
MB
392 memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN);
393
fbd7ab3e
CS
394 kref_init(&ctlr->kref);
395 ctlr->use_ms10 = -1;
970f3f47
CS
396 ctlr->ms_queued = 0;
397 ctlr->ms_sdev = NULL;
398 spin_lock_init(&ctlr->ms_lock);
399 INIT_WORK(&ctlr->ms_work, send_mode_select);
400 INIT_LIST_HEAD(&ctlr->ms_head);
fbd7ab3e 401 list_add(&ctlr->node, &ctlr_list);
3569e537 402
fbd7ab3e
CS
403 return ctlr;
404}
405
406static int submit_inquiry(struct scsi_device *sdev, int page_code,
ca9f0089 407 unsigned int len, struct rdac_dh_data *h)
fbd7ab3e
CS
408{
409 struct request *rq;
410 struct request_queue *q = sdev->request_queue;
fbd7ab3e
CS
411 int err = SCSI_DH_RES_TEMP_UNAVAIL;
412
413 rq = get_rdac_req(sdev, &h->inq, len, READ);
414 if (!rq)
415 goto done;
416
417 /* Prepare the command. */
418 rq->cmd[0] = INQUIRY;
419 rq->cmd[1] = 1;
420 rq->cmd[2] = page_code;
421 rq->cmd[4] = len;
422 rq->cmd_len = COMMAND_SIZE(INQUIRY);
ca9f0089
HR
423
424 rq->sense = h->sense;
425 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
426 rq->sense_len = 0;
427
fbd7ab3e
CS
428 err = blk_execute_rq(q, NULL, rq, 1);
429 if (err == -EIO)
430 err = SCSI_DH_IO;
ca9f0089
HR
431
432 blk_put_request(rq);
fbd7ab3e
CS
433done:
434 return err;
435}
436
1527666e 437static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h,
a53becc9 438 char *array_name, u8 *array_id)
fbd7ab3e 439{
1527666e 440 int err, i;
fbd7ab3e 441 struct c8_inquiry *inqp;
fbd7ab3e 442
ca9f0089 443 err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h);
fbd7ab3e
CS
444 if (err == SCSI_DH_OK) {
445 inqp = &h->inq.c8;
ca9f0089
HR
446 if (inqp->page_code != 0xc8)
447 return SCSI_DH_NOSYS;
448 if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' ||
449 inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd')
450 return SCSI_DH_NOSYS;
8479fca1 451 h->lun = inqp->lun[7]; /* Uses only the last byte */
1527666e
MB
452
453 for(i=0; i<ARRAY_LABEL_LEN-1; ++i)
454 *(array_name+i) = inqp->array_user_label[(2*i)+1];
455
456 *(array_name+ARRAY_LABEL_LEN-1) = '\0';
a53becc9
CS
457 memset(array_id, 0, UNIQUE_ID_LEN);
458 memcpy(array_id, inqp->array_unique_id, inqp->array_uniq_id_len);
fbd7ab3e
CS
459 }
460 return err;
461}
462
ca9f0089 463static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
fbd7ab3e
CS
464{
465 int err;
466 struct c9_inquiry *inqp;
fbd7ab3e 467
9eece961 468 h->state = RDAC_STATE_ACTIVE;
ca9f0089 469 err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h);
fbd7ab3e 470 if (err == SCSI_DH_OK) {
fbd7ab3e 471 inqp = &h->inq.c9;
1c3afc42
MB
472 /* detect the operating mode */
473 if ((inqp->avte_cvp >> 5) & 0x1)
474 h->mode = RDAC_MODE_IOSHIP; /* LUN in IOSHIP mode */
475 else if (inqp->avte_cvp >> 7)
476 h->mode = RDAC_MODE_AVT; /* LUN in AVT mode */
477 else
478 h->mode = RDAC_MODE; /* LUN in RDAC mode */
479
480 /* Update ownership */
481 if (inqp->avte_cvp & 0x1)
ca9f0089 482 h->lun_state = RDAC_LUN_OWNED;
1c3afc42
MB
483 else {
484 h->lun_state = RDAC_LUN_UNOWNED;
485 if (h->mode == RDAC_MODE)
486 h->state = RDAC_STATE_PASSIVE;
ca9f0089 487 }
ca9f0089 488
1c3afc42
MB
489 /* Update path prio*/
490 if (inqp->path_prio & 0x1)
491 h->preferred = RDAC_PREFERRED;
492 else
493 h->preferred = RDAC_NON_PREFERRED;
494 }
5a36756b 495
fbd7ab3e
CS
496 return err;
497}
498
ca9f0089 499static int initialize_controller(struct scsi_device *sdev,
a53becc9 500 struct rdac_dh_data *h, char *array_name, u8 *array_id)
fbd7ab3e 501{
a53becc9 502 int err, index;
fbd7ab3e 503 struct c4_inquiry *inqp;
fbd7ab3e 504
ca9f0089 505 err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h);
fbd7ab3e
CS
506 if (err == SCSI_DH_OK) {
507 inqp = &h->inq.c4;
a53becc9
CS
508 /* get the controller index */
509 if (inqp->slot_id[1] == 0x31)
510 index = 0;
511 else
512 index = 1;
3569e537
MB
513
514 spin_lock(&list_lock);
d6857595 515 h->ctlr = get_controller(index, array_name, array_id, sdev);
fbd7ab3e
CS
516 if (!h->ctlr)
517 err = SCSI_DH_RES_TEMP_UNAVAIL;
3569e537 518 spin_unlock(&list_lock);
fbd7ab3e
CS
519 }
520 return err;
521}
522
ca9f0089 523static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
fbd7ab3e
CS
524{
525 int err;
526 struct c2_inquiry *inqp;
fbd7ab3e 527
ca9f0089 528 err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h);
fbd7ab3e
CS
529 if (err == SCSI_DH_OK) {
530 inqp = &h->inq.c2;
531 /*
532 * If more than MODE6_MAX_LUN luns are supported, use
533 * mode select 10
534 */
535 if (inqp->max_lun_supported >= MODE6_MAX_LUN)
536 h->ctlr->use_ms10 = 1;
537 else
538 h->ctlr->use_ms10 = 0;
539 }
540 return err;
541}
542
ca9f0089 543static int mode_select_handle_sense(struct scsi_device *sdev,
970f3f47 544 unsigned char *sensebuf)
fbd7ab3e
CS
545{
546 struct scsi_sense_hdr sense_hdr;
7687fb92 547 int err = SCSI_DH_IO, ret;
dd784edc 548 struct rdac_dh_data *h = get_rdac_data(sdev);
fbd7ab3e 549
ca9f0089 550 ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
fbd7ab3e
CS
551 if (!ret)
552 goto done;
553
7687fb92
CV
554 switch (sense_hdr.sense_key) {
555 case NO_SENSE:
556 case ABORTED_COMMAND:
557 case UNIT_ATTENTION:
fbd7ab3e 558 err = SCSI_DH_RETRY;
7687fb92
CV
559 break;
560 case NOT_READY:
561 if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01)
562 /* LUN Not Ready and is in the Process of Becoming
563 * Ready
564 */
565 err = SCSI_DH_RETRY;
566 break;
567 case ILLEGAL_REQUEST:
568 if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36)
569 /*
570 * Command Lock contention
571 */
572 err = SCSI_DH_RETRY;
573 break;
574 default:
dd784edc 575 break;
fbd7ab3e
CS
576 }
577
dd784edc
MB
578 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
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);
582
fbd7ab3e
CS
583done:
584 return err;
585}
586
970f3f47 587static void send_mode_select(struct work_struct *work)
fbd7ab3e 588{
970f3f47
CS
589 struct rdac_controller *ctlr =
590 container_of(work, struct rdac_controller, ms_work);
fbd7ab3e 591 struct request *rq;
970f3f47
CS
592 struct scsi_device *sdev = ctlr->ms_sdev;
593 struct rdac_dh_data *h = get_rdac_data(sdev);
fbd7ab3e 594 struct request_queue *q = sdev->request_queue;
c85f8cb9 595 int err, retry_cnt = RDAC_RETRY_COUNT;
970f3f47
CS
596 struct rdac_queue_data *tmp, *qdata;
597 LIST_HEAD(list);
970f3f47
CS
598
599 spin_lock(&ctlr->ms_lock);
600 list_splice_init(&ctlr->ms_head, &list);
601 ctlr->ms_queued = 0;
602 ctlr->ms_sdev = NULL;
603 spin_unlock(&ctlr->ms_lock);
604
c85f8cb9
CS
605retry:
606 err = SCSI_DH_RES_TEMP_UNAVAIL;
04b6e153 607 rq = rdac_failover_get(sdev, h, &list);
fbd7ab3e
CS
608 if (!rq)
609 goto done;
610
dd784edc
MB
611 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
612 "%s MODE_SELECT command",
613 (char *) h->ctlr->array_name, h->ctlr->index,
c85f8cb9 614 (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying");
fbd7ab3e
CS
615
616 err = blk_execute_rq(q, NULL, rq, 1);
c85f8cb9
CS
617 blk_put_request(rq);
618 if (err != SCSI_DH_OK) {
ca9f0089 619 err = mode_select_handle_sense(sdev, h->sense);
c85f8cb9
CS
620 if (err == SCSI_DH_RETRY && retry_cnt--)
621 goto retry;
622 }
dd784edc 623 if (err == SCSI_DH_OK) {
fbd7ab3e 624 h->state = RDAC_STATE_ACTIVE;
dd784edc
MB
625 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
626 "MODE_SELECT completed",
627 (char *) h->ctlr->array_name, h->ctlr->index);
628 }
ca9f0089 629
fbd7ab3e 630done:
970f3f47
CS
631 list_for_each_entry_safe(qdata, tmp, &list, entry) {
632 list_del(&qdata->entry);
633 if (err == SCSI_DH_OK)
634 qdata->h->state = RDAC_STATE_ACTIVE;
635 if (qdata->callback_fn)
636 qdata->callback_fn(qdata->callback_data, err);
637 kfree(qdata);
638 }
639 return;
640}
641
642static int queue_mode_select(struct scsi_device *sdev,
643 activate_complete fn, void *data)
644{
645 struct rdac_queue_data *qdata;
646 struct rdac_controller *ctlr;
647
648 qdata = kzalloc(sizeof(*qdata), GFP_KERNEL);
649 if (!qdata)
650 return SCSI_DH_RETRY;
651
652 qdata->h = get_rdac_data(sdev);
653 qdata->callback_fn = fn;
654 qdata->callback_data = data;
655
656 ctlr = qdata->h->ctlr;
657 spin_lock(&ctlr->ms_lock);
658 list_add_tail(&qdata->entry, &ctlr->ms_head);
659 if (!ctlr->ms_queued) {
660 ctlr->ms_queued = 1;
661 ctlr->ms_sdev = sdev;
662 queue_work(kmpath_rdacd, &ctlr->ms_work);
663 }
664 spin_unlock(&ctlr->ms_lock);
665 return SCSI_DH_OK;
fbd7ab3e
CS
666}
667
3ae31f6a
CS
668static int rdac_activate(struct scsi_device *sdev,
669 activate_complete fn, void *data)
fbd7ab3e
CS
670{
671 struct rdac_dh_data *h = get_rdac_data(sdev);
672 int err = SCSI_DH_OK;
3425fbfe 673 int act = 0;
fbd7ab3e 674
ca9f0089
HR
675 err = check_ownership(sdev, h);
676 if (err != SCSI_DH_OK)
fbd7ab3e 677 goto done;
fbd7ab3e 678
3425fbfe
MB
679 switch (h->mode) {
680 case RDAC_MODE:
681 if (h->lun_state == RDAC_LUN_UNOWNED)
682 act = 1;
683 break;
684 case RDAC_MODE_IOSHIP:
685 if ((h->lun_state == RDAC_LUN_UNOWNED) &&
686 (h->preferred == RDAC_PREFERRED))
687 act = 1;
688 break;
689 default:
690 break;
691 }
692
693 if (act) {
970f3f47
CS
694 err = queue_mode_select(sdev, fn, data);
695 if (err == SCSI_DH_OK)
696 return 0;
697 }
fbd7ab3e 698done:
3ae31f6a
CS
699 if (fn)
700 fn(data, err);
701 return 0;
fbd7ab3e
CS
702}
703
704static int rdac_prep_fn(struct scsi_device *sdev, struct request *req)
705{
706 struct rdac_dh_data *h = get_rdac_data(sdev);
707 int ret = BLKPREP_OK;
708
709 if (h->state != RDAC_STATE_ACTIVE) {
710 ret = BLKPREP_KILL;
711 req->cmd_flags |= REQ_QUIET;
712 }
713 return ret;
714
715}
716
717static int rdac_check_sense(struct scsi_device *sdev,
718 struct scsi_sense_hdr *sense_hdr)
719{
720 struct rdac_dh_data *h = get_rdac_data(sdev);
dd784edc
MB
721
722 RDAC_LOG(RDAC_LOG_SENSE, sdev, "array %s, ctlr %d, "
723 "I/O returned with sense %02x/%02x/%02x",
724 (char *) h->ctlr->array_name, h->ctlr->index,
725 sense_hdr->sense_key, sense_hdr->asc, sense_hdr->ascq);
726
fbd7ab3e
CS
727 switch (sense_hdr->sense_key) {
728 case NOT_READY:
8f032263
CV
729 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01)
730 /* LUN Not Ready - Logical Unit Not Ready and is in
731 * the process of becoming ready
732 * Just retry.
733 */
734 return ADD_TO_MLQUEUE;
fbd7ab3e
CS
735 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81)
736 /* LUN Not Ready - Storage firmware incompatible
737 * Manual code synchonisation required.
738 *
739 * Nothing we can do here. Try to bypass the path.
740 */
741 return SUCCESS;
742 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1)
743 /* LUN Not Ready - Quiescense in progress
744 *
745 * Just retry and wait.
746 */
c7dbb627 747 return ADD_TO_MLQUEUE;
af50bb99
CV
748 if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02)
749 /* LUN Not Ready - Quiescense in progress
750 * or has been achieved
751 * Just retry.
752 */
753 return ADD_TO_MLQUEUE;
fbd7ab3e
CS
754 break;
755 case ILLEGAL_REQUEST:
756 if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) {
757 /* Invalid Request - Current Logical Unit Ownership.
758 * Controller is not the current owner of the LUN,
759 * Fail the path, so that the other path be used.
760 */
761 h->state = RDAC_STATE_PASSIVE;
762 return SUCCESS;
763 }
764 break;
765 case UNIT_ATTENTION:
766 if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00)
767 /*
768 * Power On, Reset, or Bus Device Reset, just retry.
ea41e415
CV
769 */
770 return ADD_TO_MLQUEUE;
771 if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02)
772 /*
773 * Quiescence in progress , just retry.
fbd7ab3e 774 */
c7dbb627 775 return ADD_TO_MLQUEUE;
fbd7ab3e
CS
776 break;
777 }
778 /* success just means we do not care what scsi-ml does */
779 return SCSI_RETURN_NOT_HANDLED;
780}
781
f08c0761 782static const struct scsi_dh_devlist rdac_dev_list[] = {
fbd7ab3e
CS
783 {"IBM", "1722"},
784 {"IBM", "1724"},
785 {"IBM", "1726"},
786 {"IBM", "1742"},
6f4fdda4
MB
787 {"IBM", "1745"},
788 {"IBM", "1746"},
fbd7ab3e
CS
789 {"IBM", "1814"},
790 {"IBM", "1815"},
791 {"IBM", "1818"},
792 {"IBM", "3526"},
793 {"SGI", "TP9400"},
794 {"SGI", "TP9500"},
66195fc9 795 {"SGI", "TP9700"},
fbd7ab3e
CS
796 {"SGI", "IS"},
797 {"STK", "OPENstorage D280"},
798 {"SUN", "CSM200_R"},
5bab0885
CB
799 {"SUN", "LCSM100_I"},
800 {"SUN", "LCSM100_S"},
801 {"SUN", "LCSM100_E"},
fbd7ab3e 802 {"SUN", "LCSM100_F"},
650849d7
YD
803 {"DELL", "MD3000"},
804 {"DELL", "MD3000i"},
cdf69bb9
YD
805 {"DELL", "MD32xx"},
806 {"DELL", "MD32xxi"},
2cf75f1c 807 {"DELL", "MD36xxi"},
bc898c97 808 {"DELL", "MD36xxf"},
273c4781
BM
809 {"LSI", "INF-01-00"},
810 {"ENGENIO", "INF-01-00"},
4dbfb544
CS
811 {"STK", "FLEXLINE 380"},
812 {"SUN", "CSM100_R_FC"},
15660676
CV
813 {"SUN", "STK6580_6780"},
814 {"SUN", "SUN_6180"},
66195fc9 815 {"SUN", "ArrayStorage"},
fbd7ab3e
CS
816 {NULL, NULL},
817};
818
bee89eae
MB
819static bool rdac_match(struct scsi_device *sdev)
820{
821 int i;
822
823 if (scsi_device_tpgs(sdev))
824 return false;
825
826 for (i = 0; rdac_dev_list[i].vendor; i++) {
827 if (!strncmp(sdev->vendor, rdac_dev_list[i].vendor,
828 strlen(rdac_dev_list[i].vendor)) &&
829 !strncmp(sdev->model, rdac_dev_list[i].model,
830 strlen(rdac_dev_list[i].model))) {
831 return true;
832 }
833 }
834 return false;
835}
836
765cbc6d
HR
837static int rdac_bus_attach(struct scsi_device *sdev);
838static void rdac_bus_detach(struct scsi_device *sdev);
fbd7ab3e
CS
839
840static struct scsi_device_handler rdac_dh = {
841 .name = RDAC_NAME,
842 .module = THIS_MODULE,
765cbc6d 843 .devlist = rdac_dev_list,
fbd7ab3e
CS
844 .prep_fn = rdac_prep_fn,
845 .check_sense = rdac_check_sense,
765cbc6d
HR
846 .attach = rdac_bus_attach,
847 .detach = rdac_bus_detach,
fbd7ab3e 848 .activate = rdac_activate,
bee89eae 849 .match = rdac_match,
fbd7ab3e
CS
850};
851
765cbc6d 852static int rdac_bus_attach(struct scsi_device *sdev)
fbd7ab3e 853{
fbd7ab3e
CS
854 struct scsi_dh_data *scsi_dh_data;
855 struct rdac_dh_data *h;
fbd7ab3e 856 unsigned long flags;
ca9f0089 857 int err;
1527666e 858 char array_name[ARRAY_LABEL_LEN];
a53becc9 859 char array_id[UNIQUE_ID_LEN];
fbd7ab3e 860
9dfeb315 861 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
765cbc6d
HR
862 + sizeof(*h) , GFP_KERNEL);
863 if (!scsi_dh_data) {
ca9f0089 864 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
765cbc6d 865 RDAC_NAME);
33af79d1 866 return 0;
765cbc6d 867 }
33af79d1 868
765cbc6d
HR
869 scsi_dh_data->scsi_dh = &rdac_dh;
870 h = (struct rdac_dh_data *) scsi_dh_data->buf;
871 h->lun = UNINITIALIZED_LUN;
872 h->state = RDAC_STATE_ACTIVE;
ca9f0089 873
a53becc9 874 err = get_lun_info(sdev, h, array_name, array_id);
ca9f0089
HR
875 if (err != SCSI_DH_OK)
876 goto failed;
877
a53becc9 878 err = initialize_controller(sdev, h, array_name, array_id);
ca9f0089
HR
879 if (err != SCSI_DH_OK)
880 goto failed;
881
87b79a53
MB
882 err = check_ownership(sdev, h);
883 if (err != SCSI_DH_OK)
884 goto clean_ctlr;
885
886 err = set_mode_select(sdev, h);
887 if (err != SCSI_DH_OK)
888 goto clean_ctlr;
889
ca9f0089 890 if (!try_module_get(THIS_MODULE))
87b79a53 891 goto clean_ctlr;
ca9f0089 892
765cbc6d
HR
893 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
894 sdev->scsi_dh_data = scsi_dh_data;
895 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
fbd7ab3e 896
ca9f0089 897 sdev_printk(KERN_NOTICE, sdev,
eebe9b96
MB
898 "%s: LUN %d (%s) (%s)\n",
899 RDAC_NAME, h->lun, mode[(int)h->mode],
900 lun_state[(int)h->lun_state]);
fbd7ab3e 901
fbd7ab3e 902 return 0;
ca9f0089 903
87b79a53 904clean_ctlr:
3569e537 905 spin_lock(&list_lock);
87b79a53 906 kref_put(&h->ctlr->kref, release_controller);
3569e537 907 spin_unlock(&list_lock);
87b79a53 908
ca9f0089
HR
909failed:
910 kfree(scsi_dh_data);
911 sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
912 RDAC_NAME);
913 return -EINVAL;
fbd7ab3e
CS
914}
915
765cbc6d
HR
916static void rdac_bus_detach( struct scsi_device *sdev )
917{
918 struct scsi_dh_data *scsi_dh_data;
919 struct rdac_dh_data *h;
920 unsigned long flags;
921
765cbc6d 922 scsi_dh_data = sdev->scsi_dh_data;
3569e537
MB
923 h = (struct rdac_dh_data *) scsi_dh_data->buf;
924 if (h->ctlr && h->ctlr->ms_queued)
925 flush_workqueue(kmpath_rdacd);
926
927 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
765cbc6d
HR
928 sdev->scsi_dh_data = NULL;
929 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
930
3569e537 931 spin_lock(&list_lock);
765cbc6d
HR
932 if (h->ctlr)
933 kref_put(&h->ctlr->kref, release_controller);
3569e537 934 spin_unlock(&list_lock);
765cbc6d
HR
935 kfree(scsi_dh_data);
936 module_put(THIS_MODULE);
ca9f0089 937 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
765cbc6d
HR
938}
939
940
941
fbd7ab3e
CS
942static int __init rdac_init(void)
943{
944 int r;
945
946 r = scsi_register_device_handler(&rdac_dh);
970f3f47 947 if (r != 0) {
fbd7ab3e 948 printk(KERN_ERR "Failed to register scsi device handler.");
970f3f47
CS
949 goto done;
950 }
951
952 /*
953 * Create workqueue to handle mode selects for rdac
954 */
955 kmpath_rdacd = create_singlethread_workqueue("kmpath_rdacd");
956 if (!kmpath_rdacd) {
957 scsi_unregister_device_handler(&rdac_dh);
958 printk(KERN_ERR "kmpath_rdacd creation failed.\n");
9fc397fc
RW
959
960 r = -EINVAL;
970f3f47
CS
961 }
962done:
fbd7ab3e
CS
963 return r;
964}
965
966static void __exit rdac_exit(void)
967{
970f3f47 968 destroy_workqueue(kmpath_rdacd);
fbd7ab3e
CS
969 scsi_unregister_device_handler(&rdac_dh);
970}
971
972module_init(rdac_init);
973module_exit(rdac_exit);
974
5f7a6433 975MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
fbd7ab3e 976MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
a0b990c6 977MODULE_VERSION("01.00.0000.0000");
fbd7ab3e 978MODULE_LICENSE("GPL");
This page took 0.368795 seconds and 5 git commands to generate.