Commit | Line | Data |
---|---|---|
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 | ||
58 | struct rdac_mode_6_hdr { | |
59 | u8 data_len; | |
60 | u8 medium_type; | |
61 | u8 device_params; | |
62 | u8 block_desc_len; | |
63 | }; | |
64 | ||
65 | struct 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 | ||
73 | struct 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 | ||
82 | struct 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 | ||
94 | struct 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 | ||
105 | struct 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 | |
120 | struct 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 |
133 | struct 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 |
151 | struct 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 |
170 | struct 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 | ||
183 | struct rdac_dh_data { | |
cd37743f | 184 | struct scsi_dh_data dh_data; |
fbd7ab3e CS |
185 | struct rdac_controller *ctlr; |
186 | #define UNINITIALIZED_LUN (1 << 8) | |
187 | unsigned lun; | |
eebe9b96 MB |
188 | |
189 | #define RDAC_MODE 0 | |
190 | #define RDAC_MODE_AVT 1 | |
191 | #define RDAC_MODE_IOSHIP 2 | |
192 | unsigned char mode; | |
193 | ||
fbd7ab3e CS |
194 | #define RDAC_STATE_ACTIVE 0 |
195 | #define RDAC_STATE_PASSIVE 1 | |
196 | unsigned char state; | |
ca9f0089 HR |
197 | |
198 | #define RDAC_LUN_UNOWNED 0 | |
199 | #define RDAC_LUN_OWNED 1 | |
ca9f0089 | 200 | char lun_state; |
eebe9b96 MB |
201 | |
202 | #define RDAC_PREFERRED 0 | |
203 | #define RDAC_NON_PREFERRED 1 | |
204 | char preferred; | |
205 | ||
fbd7ab3e CS |
206 | unsigned char sense[SCSI_SENSE_BUFFERSIZE]; |
207 | union { | |
208 | struct c2_inquiry c2; | |
209 | struct c4_inquiry c4; | |
210 | struct c8_inquiry c8; | |
211 | struct c9_inquiry c9; | |
212 | } inq; | |
213 | }; | |
214 | ||
eebe9b96 MB |
215 | static const char *mode[] = { |
216 | "RDAC", | |
217 | "AVT", | |
218 | "IOSHIP", | |
219 | }; | |
ca9f0089 HR |
220 | static const char *lun_state[] = |
221 | { | |
222 | "unowned", | |
223 | "owned", | |
ca9f0089 HR |
224 | }; |
225 | ||
970f3f47 CS |
226 | struct rdac_queue_data { |
227 | struct list_head entry; | |
228 | struct rdac_dh_data *h; | |
229 | activate_complete callback_fn; | |
230 | void *callback_data; | |
231 | }; | |
232 | ||
fbd7ab3e CS |
233 | static LIST_HEAD(ctlr_list); |
234 | static DEFINE_SPINLOCK(list_lock); | |
970f3f47 CS |
235 | static struct workqueue_struct *kmpath_rdacd; |
236 | static void send_mode_select(struct work_struct *work); | |
fbd7ab3e | 237 | |
dd784edc MB |
238 | /* |
239 | * module parameter to enable rdac debug logging. | |
240 | * 2 bits for each type of logging, only two types defined for now | |
241 | * Can be enhanced if required at later point | |
242 | */ | |
243 | static int rdac_logging = 1; | |
244 | module_param(rdac_logging, int, S_IRUGO|S_IWUSR); | |
245 | MODULE_PARM_DESC(rdac_logging, "A bit mask of rdac logging levels, " | |
246 | "Default is 1 - failover logging enabled, " | |
247 | "set it to 0xF to enable all the logs"); | |
248 | ||
249 | #define RDAC_LOG_FAILOVER 0 | |
250 | #define RDAC_LOG_SENSE 2 | |
251 | ||
252 | #define RDAC_LOG_BITS 2 | |
253 | ||
254 | #define RDAC_LOG_LEVEL(SHIFT) \ | |
255 | ((rdac_logging >> (SHIFT)) & ((1 << (RDAC_LOG_BITS)) - 1)) | |
256 | ||
257 | #define RDAC_LOG(SHIFT, sdev, f, arg...) \ | |
258 | do { \ | |
259 | if (unlikely(RDAC_LOG_LEVEL(SHIFT))) \ | |
260 | sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \ | |
261 | } while (0); | |
262 | ||
fbd7ab3e CS |
263 | static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev) |
264 | { | |
cd37743f | 265 | return container_of(sdev->scsi_dh_data, struct rdac_dh_data, dh_data); |
fbd7ab3e CS |
266 | } |
267 | ||
268 | static struct request *get_rdac_req(struct scsi_device *sdev, | |
269 | void *buffer, unsigned buflen, int rw) | |
270 | { | |
271 | struct request *rq; | |
272 | struct request_queue *q = sdev->request_queue; | |
fbd7ab3e | 273 | |
ca9f0089 | 274 | rq = blk_get_request(q, rw, GFP_NOIO); |
fbd7ab3e | 275 | |
a492f075 | 276 | if (IS_ERR(rq)) { |
fbd7ab3e CS |
277 | sdev_printk(KERN_INFO, sdev, |
278 | "get_rdac_req: blk_get_request failed.\n"); | |
279 | return NULL; | |
280 | } | |
f27b087b | 281 | blk_rq_set_block_pc(rq); |
fbd7ab3e | 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 | ||
6000a368 MC |
290 | rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | |
291 | REQ_FAILFAST_DRIVER; | |
fbd7ab3e CS |
292 | rq->retries = RDAC_RETRIES; |
293 | rq->timeout = RDAC_TIMEOUT; | |
294 | ||
295 | return rq; | |
296 | } | |
297 | ||
ca9f0089 | 298 | static struct request *rdac_failover_get(struct scsi_device *sdev, |
04b6e153 | 299 | struct rdac_dh_data *h, struct list_head *list) |
fbd7ab3e CS |
300 | { |
301 | struct request *rq; | |
302 | struct rdac_mode_common *common; | |
303 | unsigned data_size; | |
04b6e153 MB |
304 | struct rdac_queue_data *qdata; |
305 | u8 *lun_table; | |
fbd7ab3e CS |
306 | |
307 | if (h->ctlr->use_ms10) { | |
308 | struct rdac_pg_expanded *rdac_pg; | |
309 | ||
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; | |
04b6e153 | 318 | lun_table = rdac_pg->lun_table; |
fbd7ab3e CS |
319 | } else { |
320 | struct rdac_pg_legacy *rdac_pg; | |
321 | ||
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; | |
04b6e153 | 328 | lun_table = rdac_pg->lun_table; |
fbd7ab3e CS |
329 | } |
330 | common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS; | |
331 | common->quiescence_timeout = RDAC_QUIESCENCE_TIME; | |
332 | common->rdac_options = RDAC_FORCED_QUIESENCE; | |
333 | ||
04b6e153 MB |
334 | list_for_each_entry(qdata, list, entry) { |
335 | lun_table[qdata->h->lun] = 0x81; | |
336 | } | |
337 | ||
fbd7ab3e CS |
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; | |
342 | ||
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; | |
351 | } | |
352 | rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); | |
353 | ||
ca9f0089 HR |
354 | rq->sense = h->sense; |
355 | memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); | |
356 | rq->sense_len = 0; | |
357 | ||
fbd7ab3e CS |
358 | return rq; |
359 | } | |
360 | ||
361 | static void release_controller(struct kref *kref) | |
362 | { | |
363 | struct rdac_controller *ctlr; | |
364 | ctlr = container_of(kref, struct rdac_controller, kref); | |
365 | ||
fbd7ab3e | 366 | list_del(&ctlr->node); |
fbd7ab3e CS |
367 | kfree(ctlr); |
368 | } | |
369 | ||
a53becc9 | 370 | static struct rdac_controller *get_controller(int index, char *array_name, |
d6857595 | 371 | u8 *array_id, struct scsi_device *sdev) |
fbd7ab3e CS |
372 | { |
373 | struct rdac_controller *ctlr, *tmp; | |
374 | ||
fbd7ab3e | 375 | list_for_each_entry(tmp, &ctlr_list, node) { |
a53becc9 | 376 | if ((memcmp(tmp->array_id, array_id, UNIQUE_ID_LEN) == 0) && |
d6857595 CS |
377 | (tmp->index == index) && |
378 | (tmp->host == sdev->host)) { | |
fbd7ab3e | 379 | kref_get(&tmp->kref); |
fbd7ab3e CS |
380 | return tmp; |
381 | } | |
382 | } | |
383 | ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC); | |
384 | if (!ctlr) | |
3569e537 | 385 | return NULL; |
fbd7ab3e CS |
386 | |
387 | /* initialize fields of controller */ | |
a53becc9 CS |
388 | memcpy(ctlr->array_id, array_id, UNIQUE_ID_LEN); |
389 | ctlr->index = index; | |
d6857595 | 390 | ctlr->host = sdev->host; |
1527666e MB |
391 | memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN); |
392 | ||
fbd7ab3e CS |
393 | kref_init(&ctlr->kref); |
394 | ctlr->use_ms10 = -1; | |
970f3f47 CS |
395 | ctlr->ms_queued = 0; |
396 | ctlr->ms_sdev = NULL; | |
397 | spin_lock_init(&ctlr->ms_lock); | |
398 | INIT_WORK(&ctlr->ms_work, send_mode_select); | |
399 | INIT_LIST_HEAD(&ctlr->ms_head); | |
fbd7ab3e | 400 | list_add(&ctlr->node, &ctlr_list); |
3569e537 | 401 | |
fbd7ab3e CS |
402 | return ctlr; |
403 | } | |
404 | ||
405 | static int submit_inquiry(struct scsi_device *sdev, int page_code, | |
ca9f0089 | 406 | unsigned int len, struct rdac_dh_data *h) |
fbd7ab3e CS |
407 | { |
408 | struct request *rq; | |
409 | struct request_queue *q = sdev->request_queue; | |
fbd7ab3e CS |
410 | int err = SCSI_DH_RES_TEMP_UNAVAIL; |
411 | ||
412 | rq = get_rdac_req(sdev, &h->inq, len, READ); | |
413 | if (!rq) | |
414 | goto done; | |
415 | ||
416 | /* Prepare the command. */ | |
417 | rq->cmd[0] = INQUIRY; | |
418 | rq->cmd[1] = 1; | |
419 | rq->cmd[2] = page_code; | |
420 | rq->cmd[4] = len; | |
421 | rq->cmd_len = COMMAND_SIZE(INQUIRY); | |
ca9f0089 HR |
422 | |
423 | rq->sense = h->sense; | |
424 | memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); | |
425 | rq->sense_len = 0; | |
426 | ||
fbd7ab3e CS |
427 | err = blk_execute_rq(q, NULL, rq, 1); |
428 | if (err == -EIO) | |
429 | err = SCSI_DH_IO; | |
ca9f0089 HR |
430 | |
431 | blk_put_request(rq); | |
fbd7ab3e CS |
432 | done: |
433 | return err; | |
434 | } | |
435 | ||
1527666e | 436 | static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h, |
a53becc9 | 437 | char *array_name, u8 *array_id) |
fbd7ab3e | 438 | { |
1527666e | 439 | int err, i; |
fbd7ab3e | 440 | struct c8_inquiry *inqp; |
fbd7ab3e | 441 | |
ca9f0089 | 442 | err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h); |
fbd7ab3e CS |
443 | if (err == SCSI_DH_OK) { |
444 | inqp = &h->inq.c8; | |
ca9f0089 HR |
445 | if (inqp->page_code != 0xc8) |
446 | return SCSI_DH_NOSYS; | |
447 | if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' || | |
448 | inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd') | |
449 | return SCSI_DH_NOSYS; | |
8479fca1 | 450 | h->lun = inqp->lun[7]; /* Uses only the last byte */ |
1527666e MB |
451 | |
452 | for(i=0; i<ARRAY_LABEL_LEN-1; ++i) | |
453 | *(array_name+i) = inqp->array_user_label[(2*i)+1]; | |
454 | ||
455 | *(array_name+ARRAY_LABEL_LEN-1) = '\0'; | |
a53becc9 CS |
456 | memset(array_id, 0, UNIQUE_ID_LEN); |
457 | memcpy(array_id, inqp->array_unique_id, inqp->array_uniq_id_len); | |
fbd7ab3e CS |
458 | } |
459 | return err; | |
460 | } | |
461 | ||
ca9f0089 | 462 | static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h) |
fbd7ab3e CS |
463 | { |
464 | int err; | |
465 | struct c9_inquiry *inqp; | |
fbd7ab3e | 466 | |
9eece961 | 467 | h->state = RDAC_STATE_ACTIVE; |
ca9f0089 | 468 | err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h); |
fbd7ab3e | 469 | if (err == SCSI_DH_OK) { |
fbd7ab3e | 470 | inqp = &h->inq.c9; |
1c3afc42 MB |
471 | /* detect the operating mode */ |
472 | if ((inqp->avte_cvp >> 5) & 0x1) | |
473 | h->mode = RDAC_MODE_IOSHIP; /* LUN in IOSHIP mode */ | |
474 | else if (inqp->avte_cvp >> 7) | |
475 | h->mode = RDAC_MODE_AVT; /* LUN in AVT mode */ | |
476 | else | |
477 | h->mode = RDAC_MODE; /* LUN in RDAC mode */ | |
478 | ||
479 | /* Update ownership */ | |
480 | if (inqp->avte_cvp & 0x1) | |
ca9f0089 | 481 | h->lun_state = RDAC_LUN_OWNED; |
1c3afc42 MB |
482 | else { |
483 | h->lun_state = RDAC_LUN_UNOWNED; | |
484 | if (h->mode == RDAC_MODE) | |
485 | h->state = RDAC_STATE_PASSIVE; | |
ca9f0089 | 486 | } |
ca9f0089 | 487 | |
1c3afc42 MB |
488 | /* Update path prio*/ |
489 | if (inqp->path_prio & 0x1) | |
490 | h->preferred = RDAC_PREFERRED; | |
491 | else | |
492 | h->preferred = RDAC_NON_PREFERRED; | |
493 | } | |
5a36756b | 494 | |
fbd7ab3e CS |
495 | return err; |
496 | } | |
497 | ||
ca9f0089 | 498 | static int initialize_controller(struct scsi_device *sdev, |
a53becc9 | 499 | struct rdac_dh_data *h, char *array_name, u8 *array_id) |
fbd7ab3e | 500 | { |
a53becc9 | 501 | int err, index; |
fbd7ab3e | 502 | struct c4_inquiry *inqp; |
fbd7ab3e | 503 | |
ca9f0089 | 504 | err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h); |
fbd7ab3e CS |
505 | if (err == SCSI_DH_OK) { |
506 | inqp = &h->inq.c4; | |
a53becc9 CS |
507 | /* get the controller index */ |
508 | if (inqp->slot_id[1] == 0x31) | |
509 | index = 0; | |
510 | else | |
511 | index = 1; | |
3569e537 MB |
512 | |
513 | spin_lock(&list_lock); | |
d6857595 | 514 | h->ctlr = get_controller(index, array_name, array_id, sdev); |
fbd7ab3e CS |
515 | if (!h->ctlr) |
516 | err = SCSI_DH_RES_TEMP_UNAVAIL; | |
3569e537 | 517 | spin_unlock(&list_lock); |
fbd7ab3e CS |
518 | } |
519 | return err; | |
520 | } | |
521 | ||
ca9f0089 | 522 | static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h) |
fbd7ab3e CS |
523 | { |
524 | int err; | |
525 | struct c2_inquiry *inqp; | |
fbd7ab3e | 526 | |
ca9f0089 | 527 | err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h); |
fbd7ab3e CS |
528 | if (err == SCSI_DH_OK) { |
529 | inqp = &h->inq.c2; | |
530 | /* | |
531 | * If more than MODE6_MAX_LUN luns are supported, use | |
532 | * mode select 10 | |
533 | */ | |
534 | if (inqp->max_lun_supported >= MODE6_MAX_LUN) | |
535 | h->ctlr->use_ms10 = 1; | |
536 | else | |
537 | h->ctlr->use_ms10 = 0; | |
538 | } | |
539 | return err; | |
540 | } | |
541 | ||
ca9f0089 | 542 | static int mode_select_handle_sense(struct scsi_device *sdev, |
970f3f47 | 543 | unsigned char *sensebuf) |
fbd7ab3e CS |
544 | { |
545 | struct scsi_sense_hdr sense_hdr; | |
7687fb92 | 546 | int err = SCSI_DH_IO, ret; |
dd784edc | 547 | struct rdac_dh_data *h = get_rdac_data(sdev); |
fbd7ab3e | 548 | |
ca9f0089 | 549 | ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr); |
fbd7ab3e CS |
550 | if (!ret) |
551 | goto done; | |
552 | ||
7687fb92 CV |
553 | switch (sense_hdr.sense_key) { |
554 | case NO_SENSE: | |
555 | case ABORTED_COMMAND: | |
556 | case UNIT_ATTENTION: | |
fbd7ab3e | 557 | err = SCSI_DH_RETRY; |
7687fb92 CV |
558 | break; |
559 | case NOT_READY: | |
560 | if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01) | |
561 | /* LUN Not Ready and is in the Process of Becoming | |
562 | * Ready | |
563 | */ | |
564 | err = SCSI_DH_RETRY; | |
565 | break; | |
566 | case ILLEGAL_REQUEST: | |
567 | if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36) | |
568 | /* | |
569 | * Command Lock contention | |
570 | */ | |
571 | err = SCSI_DH_RETRY; | |
572 | break; | |
573 | default: | |
dd784edc | 574 | break; |
fbd7ab3e CS |
575 | } |
576 | ||
dd784edc MB |
577 | RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, " |
578 | "MODE_SELECT returned with sense %02x/%02x/%02x", | |
579 | (char *) h->ctlr->array_name, h->ctlr->index, | |
580 | sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq); | |
581 | ||
fbd7ab3e CS |
582 | done: |
583 | return err; | |
584 | } | |
585 | ||
970f3f47 | 586 | static void send_mode_select(struct work_struct *work) |
fbd7ab3e | 587 | { |
970f3f47 CS |
588 | struct rdac_controller *ctlr = |
589 | container_of(work, struct rdac_controller, ms_work); | |
fbd7ab3e | 590 | struct request *rq; |
970f3f47 CS |
591 | struct scsi_device *sdev = ctlr->ms_sdev; |
592 | struct rdac_dh_data *h = get_rdac_data(sdev); | |
fbd7ab3e | 593 | struct request_queue *q = sdev->request_queue; |
c85f8cb9 | 594 | int err, retry_cnt = RDAC_RETRY_COUNT; |
970f3f47 CS |
595 | struct rdac_queue_data *tmp, *qdata; |
596 | LIST_HEAD(list); | |
970f3f47 CS |
597 | |
598 | spin_lock(&ctlr->ms_lock); | |
599 | list_splice_init(&ctlr->ms_head, &list); | |
600 | ctlr->ms_queued = 0; | |
601 | ctlr->ms_sdev = NULL; | |
602 | spin_unlock(&ctlr->ms_lock); | |
603 | ||
c85f8cb9 CS |
604 | retry: |
605 | err = SCSI_DH_RES_TEMP_UNAVAIL; | |
04b6e153 | 606 | rq = rdac_failover_get(sdev, h, &list); |
fbd7ab3e CS |
607 | if (!rq) |
608 | goto done; | |
609 | ||
dd784edc MB |
610 | RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, " |
611 | "%s MODE_SELECT command", | |
612 | (char *) h->ctlr->array_name, h->ctlr->index, | |
c85f8cb9 | 613 | (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying"); |
fbd7ab3e CS |
614 | |
615 | err = blk_execute_rq(q, NULL, rq, 1); | |
c85f8cb9 CS |
616 | blk_put_request(rq); |
617 | if (err != SCSI_DH_OK) { | |
ca9f0089 | 618 | err = mode_select_handle_sense(sdev, h->sense); |
c85f8cb9 CS |
619 | if (err == SCSI_DH_RETRY && retry_cnt--) |
620 | goto retry; | |
621 | } | |
dd784edc | 622 | if (err == SCSI_DH_OK) { |
fbd7ab3e | 623 | h->state = RDAC_STATE_ACTIVE; |
dd784edc MB |
624 | RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, " |
625 | "MODE_SELECT completed", | |
626 | (char *) h->ctlr->array_name, h->ctlr->index); | |
627 | } | |
ca9f0089 | 628 | |
fbd7ab3e | 629 | done: |
970f3f47 CS |
630 | list_for_each_entry_safe(qdata, tmp, &list, entry) { |
631 | list_del(&qdata->entry); | |
632 | if (err == SCSI_DH_OK) | |
633 | qdata->h->state = RDAC_STATE_ACTIVE; | |
634 | if (qdata->callback_fn) | |
635 | qdata->callback_fn(qdata->callback_data, err); | |
636 | kfree(qdata); | |
637 | } | |
638 | return; | |
639 | } | |
640 | ||
641 | static int queue_mode_select(struct scsi_device *sdev, | |
642 | activate_complete fn, void *data) | |
643 | { | |
644 | struct rdac_queue_data *qdata; | |
645 | struct rdac_controller *ctlr; | |
646 | ||
647 | qdata = kzalloc(sizeof(*qdata), GFP_KERNEL); | |
648 | if (!qdata) | |
649 | return SCSI_DH_RETRY; | |
650 | ||
651 | qdata->h = get_rdac_data(sdev); | |
652 | qdata->callback_fn = fn; | |
653 | qdata->callback_data = data; | |
654 | ||
655 | ctlr = qdata->h->ctlr; | |
656 | spin_lock(&ctlr->ms_lock); | |
657 | list_add_tail(&qdata->entry, &ctlr->ms_head); | |
658 | if (!ctlr->ms_queued) { | |
659 | ctlr->ms_queued = 1; | |
660 | ctlr->ms_sdev = sdev; | |
661 | queue_work(kmpath_rdacd, &ctlr->ms_work); | |
662 | } | |
663 | spin_unlock(&ctlr->ms_lock); | |
664 | return SCSI_DH_OK; | |
fbd7ab3e CS |
665 | } |
666 | ||
3ae31f6a CS |
667 | static int rdac_activate(struct scsi_device *sdev, |
668 | activate_complete fn, void *data) | |
fbd7ab3e CS |
669 | { |
670 | struct rdac_dh_data *h = get_rdac_data(sdev); | |
671 | int err = SCSI_DH_OK; | |
3425fbfe | 672 | int act = 0; |
fbd7ab3e | 673 | |
ca9f0089 HR |
674 | err = check_ownership(sdev, h); |
675 | if (err != SCSI_DH_OK) | |
fbd7ab3e | 676 | goto done; |
fbd7ab3e | 677 | |
3425fbfe MB |
678 | switch (h->mode) { |
679 | case RDAC_MODE: | |
680 | if (h->lun_state == RDAC_LUN_UNOWNED) | |
681 | act = 1; | |
682 | break; | |
683 | case RDAC_MODE_IOSHIP: | |
684 | if ((h->lun_state == RDAC_LUN_UNOWNED) && | |
685 | (h->preferred == RDAC_PREFERRED)) | |
686 | act = 1; | |
687 | break; | |
688 | default: | |
689 | break; | |
690 | } | |
691 | ||
692 | if (act) { | |
970f3f47 CS |
693 | err = queue_mode_select(sdev, fn, data); |
694 | if (err == SCSI_DH_OK) | |
695 | return 0; | |
696 | } | |
fbd7ab3e | 697 | done: |
3ae31f6a CS |
698 | if (fn) |
699 | fn(data, err); | |
700 | return 0; | |
fbd7ab3e CS |
701 | } |
702 | ||
703 | static int rdac_prep_fn(struct scsi_device *sdev, struct request *req) | |
704 | { | |
705 | struct rdac_dh_data *h = get_rdac_data(sdev); | |
706 | int ret = BLKPREP_OK; | |
707 | ||
708 | if (h->state != RDAC_STATE_ACTIVE) { | |
709 | ret = BLKPREP_KILL; | |
710 | req->cmd_flags |= REQ_QUIET; | |
711 | } | |
712 | return ret; | |
713 | ||
714 | } | |
715 | ||
716 | static int rdac_check_sense(struct scsi_device *sdev, | |
717 | struct scsi_sense_hdr *sense_hdr) | |
718 | { | |
719 | struct rdac_dh_data *h = get_rdac_data(sdev); | |
dd784edc MB |
720 | |
721 | RDAC_LOG(RDAC_LOG_SENSE, sdev, "array %s, ctlr %d, " | |
722 | "I/O returned with sense %02x/%02x/%02x", | |
723 | (char *) h->ctlr->array_name, h->ctlr->index, | |
724 | sense_hdr->sense_key, sense_hdr->asc, sense_hdr->ascq); | |
725 | ||
fbd7ab3e CS |
726 | switch (sense_hdr->sense_key) { |
727 | case NOT_READY: | |
8f032263 CV |
728 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01) |
729 | /* LUN Not Ready - Logical Unit Not Ready and is in | |
730 | * the process of becoming ready | |
731 | * Just retry. | |
732 | */ | |
733 | return ADD_TO_MLQUEUE; | |
fbd7ab3e CS |
734 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81) |
735 | /* LUN Not Ready - Storage firmware incompatible | |
736 | * Manual code synchonisation required. | |
737 | * | |
738 | * Nothing we can do here. Try to bypass the path. | |
739 | */ | |
740 | return SUCCESS; | |
741 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1) | |
742 | /* LUN Not Ready - Quiescense in progress | |
743 | * | |
744 | * Just retry and wait. | |
745 | */ | |
c7dbb627 | 746 | return ADD_TO_MLQUEUE; |
af50bb99 CV |
747 | if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02) |
748 | /* LUN Not Ready - Quiescense in progress | |
749 | * or has been achieved | |
750 | * Just retry. | |
751 | */ | |
752 | return ADD_TO_MLQUEUE; | |
fbd7ab3e CS |
753 | break; |
754 | case ILLEGAL_REQUEST: | |
755 | if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) { | |
756 | /* Invalid Request - Current Logical Unit Ownership. | |
757 | * Controller is not the current owner of the LUN, | |
758 | * Fail the path, so that the other path be used. | |
759 | */ | |
760 | h->state = RDAC_STATE_PASSIVE; | |
761 | return SUCCESS; | |
762 | } | |
763 | break; | |
764 | case UNIT_ATTENTION: | |
765 | if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00) | |
766 | /* | |
767 | * Power On, Reset, or Bus Device Reset, just retry. | |
ea41e415 CV |
768 | */ |
769 | return ADD_TO_MLQUEUE; | |
770 | if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02) | |
771 | /* | |
772 | * Quiescence in progress , just retry. | |
fbd7ab3e | 773 | */ |
c7dbb627 | 774 | return ADD_TO_MLQUEUE; |
fbd7ab3e CS |
775 | break; |
776 | } | |
777 | /* success just means we do not care what scsi-ml does */ | |
778 | return SCSI_RETURN_NOT_HANDLED; | |
779 | } | |
780 | ||
a64d01dc CH |
781 | static const struct { |
782 | char *vendor; | |
783 | char *model; | |
784 | } rdac_dev_list[] = { | |
fbd7ab3e CS |
785 | {"IBM", "1722"}, |
786 | {"IBM", "1724"}, | |
787 | {"IBM", "1726"}, | |
788 | {"IBM", "1742"}, | |
6f4fdda4 MB |
789 | {"IBM", "1745"}, |
790 | {"IBM", "1746"}, | |
4df01b06 | 791 | {"IBM", "1813"}, |
fbd7ab3e CS |
792 | {"IBM", "1814"}, |
793 | {"IBM", "1815"}, | |
794 | {"IBM", "1818"}, | |
795 | {"IBM", "3526"}, | |
35204772 | 796 | {"SGI", "TP9"}, |
fbd7ab3e CS |
797 | {"SGI", "IS"}, |
798 | {"STK", "OPENstorage D280"}, | |
e7ba29d6 | 799 | {"STK", "FLEXLINE 380"}, |
35204772 MB |
800 | {"SUN", "CSM"}, |
801 | {"SUN", "LCSM100"}, | |
e7ba29d6 MB |
802 | {"SUN", "STK6580_6780"}, |
803 | {"SUN", "SUN_6180"}, | |
804 | {"SUN", "ArrayStorage"}, | |
35204772 | 805 | {"DELL", "MD3"}, |
e7ba29d6 | 806 | {"NETAPP", "INF-01-00"}, |
273c4781 BM |
807 | {"LSI", "INF-01-00"}, |
808 | {"ENGENIO", "INF-01-00"}, | |
fbd7ab3e CS |
809 | {NULL, NULL}, |
810 | }; | |
811 | ||
bee89eae MB |
812 | static bool rdac_match(struct scsi_device *sdev) |
813 | { | |
814 | int i; | |
815 | ||
816 | if (scsi_device_tpgs(sdev)) | |
817 | return false; | |
818 | ||
819 | for (i = 0; rdac_dev_list[i].vendor; i++) { | |
820 | if (!strncmp(sdev->vendor, rdac_dev_list[i].vendor, | |
821 | strlen(rdac_dev_list[i].vendor)) && | |
822 | !strncmp(sdev->model, rdac_dev_list[i].model, | |
823 | strlen(rdac_dev_list[i].model))) { | |
824 | return true; | |
825 | } | |
826 | } | |
827 | return false; | |
828 | } | |
829 | ||
1d520328 | 830 | static struct scsi_dh_data *rdac_bus_attach(struct scsi_device *sdev) |
fbd7ab3e | 831 | { |
fbd7ab3e | 832 | struct rdac_dh_data *h; |
ca9f0089 | 833 | int err; |
1527666e | 834 | char array_name[ARRAY_LABEL_LEN]; |
a53becc9 | 835 | char array_id[UNIQUE_ID_LEN]; |
fbd7ab3e | 836 | |
cd37743f | 837 | h = kzalloc(sizeof(*h) , GFP_KERNEL); |
1d520328 CH |
838 | if (!h) |
839 | return ERR_PTR(-ENOMEM); | |
765cbc6d HR |
840 | h->lun = UNINITIALIZED_LUN; |
841 | h->state = RDAC_STATE_ACTIVE; | |
ca9f0089 | 842 | |
a53becc9 | 843 | err = get_lun_info(sdev, h, array_name, array_id); |
ca9f0089 HR |
844 | if (err != SCSI_DH_OK) |
845 | goto failed; | |
846 | ||
a53becc9 | 847 | err = initialize_controller(sdev, h, array_name, array_id); |
ca9f0089 HR |
848 | if (err != SCSI_DH_OK) |
849 | goto failed; | |
850 | ||
87b79a53 MB |
851 | err = check_ownership(sdev, h); |
852 | if (err != SCSI_DH_OK) | |
853 | goto clean_ctlr; | |
854 | ||
855 | err = set_mode_select(sdev, h); | |
856 | if (err != SCSI_DH_OK) | |
857 | goto clean_ctlr; | |
858 | ||
ca9f0089 | 859 | sdev_printk(KERN_NOTICE, sdev, |
eebe9b96 MB |
860 | "%s: LUN %d (%s) (%s)\n", |
861 | RDAC_NAME, h->lun, mode[(int)h->mode], | |
862 | lun_state[(int)h->lun_state]); | |
fbd7ab3e | 863 | |
1d520328 | 864 | return &h->dh_data; |
ca9f0089 | 865 | |
87b79a53 | 866 | clean_ctlr: |
3569e537 | 867 | spin_lock(&list_lock); |
87b79a53 | 868 | kref_put(&h->ctlr->kref, release_controller); |
3569e537 | 869 | spin_unlock(&list_lock); |
87b79a53 | 870 | |
ca9f0089 | 871 | failed: |
cd37743f | 872 | kfree(h); |
1d520328 | 873 | return ERR_PTR(-EINVAL); |
fbd7ab3e CS |
874 | } |
875 | ||
765cbc6d HR |
876 | static void rdac_bus_detach( struct scsi_device *sdev ) |
877 | { | |
cd37743f | 878 | struct rdac_dh_data *h = get_rdac_data(sdev); |
765cbc6d | 879 | |
3569e537 MB |
880 | if (h->ctlr && h->ctlr->ms_queued) |
881 | flush_workqueue(kmpath_rdacd); | |
882 | ||
3569e537 | 883 | spin_lock(&list_lock); |
765cbc6d HR |
884 | if (h->ctlr) |
885 | kref_put(&h->ctlr->kref, release_controller); | |
3569e537 | 886 | spin_unlock(&list_lock); |
cd37743f | 887 | kfree(h); |
765cbc6d HR |
888 | } |
889 | ||
1d520328 CH |
890 | static struct scsi_device_handler rdac_dh = { |
891 | .name = RDAC_NAME, | |
892 | .module = THIS_MODULE, | |
893 | .prep_fn = rdac_prep_fn, | |
894 | .check_sense = rdac_check_sense, | |
895 | .attach = rdac_bus_attach, | |
896 | .detach = rdac_bus_detach, | |
897 | .activate = rdac_activate, | |
898 | .match = rdac_match, | |
899 | }; | |
765cbc6d | 900 | |
fbd7ab3e CS |
901 | static int __init rdac_init(void) |
902 | { | |
903 | int r; | |
904 | ||
905 | r = scsi_register_device_handler(&rdac_dh); | |
970f3f47 | 906 | if (r != 0) { |
fbd7ab3e | 907 | printk(KERN_ERR "Failed to register scsi device handler."); |
970f3f47 CS |
908 | goto done; |
909 | } | |
910 | ||
911 | /* | |
912 | * Create workqueue to handle mode selects for rdac | |
913 | */ | |
914 | kmpath_rdacd = create_singlethread_workqueue("kmpath_rdacd"); | |
915 | if (!kmpath_rdacd) { | |
916 | scsi_unregister_device_handler(&rdac_dh); | |
917 | printk(KERN_ERR "kmpath_rdacd creation failed.\n"); | |
9fc397fc RW |
918 | |
919 | r = -EINVAL; | |
970f3f47 CS |
920 | } |
921 | done: | |
fbd7ab3e CS |
922 | return r; |
923 | } | |
924 | ||
925 | static void __exit rdac_exit(void) | |
926 | { | |
970f3f47 | 927 | destroy_workqueue(kmpath_rdacd); |
fbd7ab3e CS |
928 | scsi_unregister_device_handler(&rdac_dh); |
929 | } | |
930 | ||
931 | module_init(rdac_init); | |
932 | module_exit(rdac_exit); | |
933 | ||
5f7a6433 | 934 | MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver"); |
fbd7ab3e | 935 | MODULE_AUTHOR("Mike Christie, Chandra Seetharaman"); |
a0b990c6 | 936 | MODULE_VERSION("01.00.0000.0000"); |
fbd7ab3e | 937 | MODULE_LICENSE("GPL"); |