blob: 53a31c753cb1e682ead92268901bc966845a1996 [file] [log] [blame]
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -07001/*
Chauhan, Vijay5f7a6432011-09-02 13:26:32 +05302 * LSI/Engenio/NetApp E-Series RDAC SCSI Device Handler
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -07003 *
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>
Chandra Seetharaman970f3f42009-10-21 09:22:51 -070025#include <linux/workqueue.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Paul Gortmakeracf33682011-05-27 09:47:43 -040027#include <linux/module.h>
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -070028
29#define RDAC_NAME "rdac"
Chandra Seetharamanc85f8cb92008-11-05 20:06:37 -080030#define RDAC_RETRY_COUNT 5
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -070031
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 */
Phil Carmody497888c2011-07-14 15:07:13 +030039#define RDAC_QUIESCENCE_TIME 20
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -070040/*
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
Moger, Babu15276662009-09-03 21:42:21 -0600118#define ARRAY_LABEL_LEN 31
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700119
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
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700132#define UNIQUE_ID_LEN 16
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;
145 u8 array_unique_id[UNIQUE_ID_LEN];
146 u8 array_user_label_len;
147 u8 array_user_label[60];
148 u8 lun[8];
149};
150
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700151struct rdac_controller {
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700152 u8 array_id[UNIQUE_ID_LEN];
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700153 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;
Moger, Babu15276662009-09-03 21:42:21 -0600160 u8 index;
161 u8 array_name[ARRAY_LABEL_LEN];
Chandra Seetharamand6857592011-07-27 11:22:56 -0700162 struct Scsi_Host *host;
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700163 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;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700168};
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700169
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700170struct 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;
Moger, Babueebe9b92011-04-08 11:37:40 -0600187
188#define RDAC_MODE 0
189#define RDAC_MODE_AVT 1
190#define RDAC_MODE_IOSHIP 2
191 unsigned char mode;
192
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700193#define RDAC_STATE_ACTIVE 0
194#define RDAC_STATE_PASSIVE 1
195 unsigned char state;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700196
197#define RDAC_LUN_UNOWNED 0
198#define RDAC_LUN_OWNED 1
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700199 char lun_state;
Moger, Babueebe9b92011-04-08 11:37:40 -0600200
201#define RDAC_PREFERRED 0
202#define RDAC_NON_PREFERRED 1
203 char preferred;
204
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700205 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
Moger, Babueebe9b92011-04-08 11:37:40 -0600214static const char *mode[] = {
215 "RDAC",
216 "AVT",
217 "IOSHIP",
218};
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700219static const char *lun_state[] =
220{
221 "unowned",
222 "owned",
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700223};
224
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700225struct 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
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700232static LIST_HEAD(ctlr_list);
233static DEFINE_SPINLOCK(list_lock);
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700234static struct workqueue_struct *kmpath_rdacd;
235static void send_mode_select(struct work_struct *work);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700236
Moger, Babudd784ed2009-09-03 21:42:28 -0600237/*
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
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700262static 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;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700274
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700275 rq = blk_get_request(q, rw, GFP_NOIO);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700276
277 if (!rq) {
278 sdev_printk(KERN_INFO, sdev,
279 "get_rdac_req: blk_get_request failed.\n");
280 return NULL;
281 }
282
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700283 if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) {
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700284 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
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700290 rq->cmd_type = REQ_TYPE_BLOCK_PC;
Mike Christie6000a362008-08-19 18:45:30 -0500291 rq->cmd_flags |= REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
292 REQ_FAILFAST_DRIVER;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700293 rq->retries = RDAC_RETRIES;
294 rq->timeout = RDAC_TIMEOUT;
295
296 return rq;
297}
298
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700299static struct request *rdac_failover_get(struct scsi_device *sdev,
Moger, Babu04b6e152011-02-11 15:14:08 -0700300 struct rdac_dh_data *h, struct list_head *list)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700301{
302 struct request *rq;
303 struct rdac_mode_common *common;
304 unsigned data_size;
Moger, Babu04b6e152011-02-11 15:14:08 -0700305 struct rdac_queue_data *qdata;
306 u8 *lun_table;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700307
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;
Moger, Babu04b6e152011-02-11 15:14:08 -0700319 lun_table = rdac_pg->lun_table;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700320 } 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;
Moger, Babu04b6e152011-02-11 15:14:08 -0700329 lun_table = rdac_pg->lun_table;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700330 }
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
Moger, Babu04b6e152011-02-11 15:14:08 -0700335 list_for_each_entry(qdata, list, entry) {
336 lun_table[qdata->h->lun] = 0x81;
337 }
338
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700339 /* 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
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700355 rq->sense = h->sense;
356 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
357 rq->sense_len = 0;
358
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700359 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
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700367 flush_workqueue(kmpath_rdacd);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700368 spin_lock(&list_lock);
369 list_del(&ctlr->node);
370 spin_unlock(&list_lock);
371 kfree(ctlr);
372}
373
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700374static struct rdac_controller *get_controller(int index, char *array_name,
Chandra Seetharamand6857592011-07-27 11:22:56 -0700375 u8 *array_id, struct scsi_device *sdev)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700376{
377 struct rdac_controller *ctlr, *tmp;
378
379 spin_lock(&list_lock);
380
381 list_for_each_entry(tmp, &ctlr_list, node) {
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700382 if ((memcmp(tmp->array_id, array_id, UNIQUE_ID_LEN) == 0) &&
Chandra Seetharamand6857592011-07-27 11:22:56 -0700383 (tmp->index == index) &&
384 (tmp->host == sdev->host)) {
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700385 kref_get(&tmp->kref);
386 spin_unlock(&list_lock);
387 return tmp;
388 }
389 }
390 ctlr = kmalloc(sizeof(*ctlr), GFP_ATOMIC);
391 if (!ctlr)
392 goto done;
393
394 /* initialize fields of controller */
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700395 memcpy(ctlr->array_id, array_id, UNIQUE_ID_LEN);
396 ctlr->index = index;
Chandra Seetharamand6857592011-07-27 11:22:56 -0700397 ctlr->host = sdev->host;
Moger, Babu15276662009-09-03 21:42:21 -0600398 memcpy(ctlr->array_name, array_name, ARRAY_LABEL_LEN);
399
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700400 kref_init(&ctlr->kref);
401 ctlr->use_ms10 = -1;
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700402 ctlr->ms_queued = 0;
403 ctlr->ms_sdev = NULL;
404 spin_lock_init(&ctlr->ms_lock);
405 INIT_WORK(&ctlr->ms_work, send_mode_select);
406 INIT_LIST_HEAD(&ctlr->ms_head);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700407 list_add(&ctlr->node, &ctlr_list);
408done:
409 spin_unlock(&list_lock);
410 return ctlr;
411}
412
413static int submit_inquiry(struct scsi_device *sdev, int page_code,
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700414 unsigned int len, struct rdac_dh_data *h)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700415{
416 struct request *rq;
417 struct request_queue *q = sdev->request_queue;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700418 int err = SCSI_DH_RES_TEMP_UNAVAIL;
419
420 rq = get_rdac_req(sdev, &h->inq, len, READ);
421 if (!rq)
422 goto done;
423
424 /* Prepare the command. */
425 rq->cmd[0] = INQUIRY;
426 rq->cmd[1] = 1;
427 rq->cmd[2] = page_code;
428 rq->cmd[4] = len;
429 rq->cmd_len = COMMAND_SIZE(INQUIRY);
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700430
431 rq->sense = h->sense;
432 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
433 rq->sense_len = 0;
434
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700435 err = blk_execute_rq(q, NULL, rq, 1);
436 if (err == -EIO)
437 err = SCSI_DH_IO;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700438
439 blk_put_request(rq);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700440done:
441 return err;
442}
443
Moger, Babu15276662009-09-03 21:42:21 -0600444static int get_lun_info(struct scsi_device *sdev, struct rdac_dh_data *h,
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700445 char *array_name, u8 *array_id)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700446{
Moger, Babu15276662009-09-03 21:42:21 -0600447 int err, i;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700448 struct c8_inquiry *inqp;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700449
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700450 err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700451 if (err == SCSI_DH_OK) {
452 inqp = &h->inq.c8;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700453 if (inqp->page_code != 0xc8)
454 return SCSI_DH_NOSYS;
455 if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' ||
456 inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd')
457 return SCSI_DH_NOSYS;
Chandra Seetharaman8479fca2008-08-12 17:26:58 -0700458 h->lun = inqp->lun[7]; /* Uses only the last byte */
Moger, Babu15276662009-09-03 21:42:21 -0600459
460 for(i=0; i<ARRAY_LABEL_LEN-1; ++i)
461 *(array_name+i) = inqp->array_user_label[(2*i)+1];
462
463 *(array_name+ARRAY_LABEL_LEN-1) = '\0';
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700464 memset(array_id, 0, UNIQUE_ID_LEN);
465 memcpy(array_id, inqp->array_unique_id, inqp->array_uniq_id_len);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700466 }
467 return err;
468}
469
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700470static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700471{
472 int err;
473 struct c9_inquiry *inqp;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700474
Chandra Seetharaman9eece962008-11-05 20:05:21 -0800475 h->state = RDAC_STATE_ACTIVE;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700476 err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700477 if (err == SCSI_DH_OK) {
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700478 inqp = &h->inq.c9;
Moger, Babu1c3afc42011-04-08 11:38:33 -0600479 /* detect the operating mode */
480 if ((inqp->avte_cvp >> 5) & 0x1)
481 h->mode = RDAC_MODE_IOSHIP; /* LUN in IOSHIP mode */
482 else if (inqp->avte_cvp >> 7)
483 h->mode = RDAC_MODE_AVT; /* LUN in AVT mode */
484 else
485 h->mode = RDAC_MODE; /* LUN in RDAC mode */
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700486
Moger, Babu1c3afc42011-04-08 11:38:33 -0600487 /* Update ownership */
488 if (inqp->avte_cvp & 0x1)
489 h->lun_state = RDAC_LUN_OWNED;
490 else {
491 h->lun_state = RDAC_LUN_UNOWNED;
492 if (h->mode == RDAC_MODE)
493 h->state = RDAC_STATE_PASSIVE;
494 }
495
496 /* Update path prio*/
497 if (inqp->path_prio & 0x1)
498 h->preferred = RDAC_PREFERRED;
499 else
500 h->preferred = RDAC_NON_PREFERRED;
501 }
Chandra Seetharaman5a367562008-08-21 23:12:40 -0700502
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700503 return err;
504}
505
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700506static int initialize_controller(struct scsi_device *sdev,
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700507 struct rdac_dh_data *h, char *array_name, u8 *array_id)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700508{
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700509 int err, index;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700510 struct c4_inquiry *inqp;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700511
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700512 err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700513 if (err == SCSI_DH_OK) {
514 inqp = &h->inq.c4;
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700515 /* get the controller index */
516 if (inqp->slot_id[1] == 0x31)
517 index = 0;
518 else
519 index = 1;
Chandra Seetharamand6857592011-07-27 11:22:56 -0700520 h->ctlr = get_controller(index, array_name, array_id, sdev);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700521 if (!h->ctlr)
522 err = SCSI_DH_RES_TEMP_UNAVAIL;
523 }
524 return err;
525}
526
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700527static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700528{
529 int err;
530 struct c2_inquiry *inqp;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700531
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700532 err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700533 if (err == SCSI_DH_OK) {
534 inqp = &h->inq.c2;
535 /*
536 * If more than MODE6_MAX_LUN luns are supported, use
537 * mode select 10
538 */
539 if (inqp->max_lun_supported >= MODE6_MAX_LUN)
540 h->ctlr->use_ms10 = 1;
541 else
542 h->ctlr->use_ms10 = 0;
543 }
544 return err;
545}
546
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700547static int mode_select_handle_sense(struct scsi_device *sdev,
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700548 unsigned char *sensebuf)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700549{
550 struct scsi_sense_hdr sense_hdr;
Chauhan, Vijay7687fb92009-03-04 12:17:54 +0530551 int err = SCSI_DH_IO, ret;
Moger, Babudd784ed2009-09-03 21:42:28 -0600552 struct rdac_dh_data *h = get_rdac_data(sdev);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700553
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700554 ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700555 if (!ret)
556 goto done;
557
Chauhan, Vijay7687fb92009-03-04 12:17:54 +0530558 switch (sense_hdr.sense_key) {
559 case NO_SENSE:
560 case ABORTED_COMMAND:
561 case UNIT_ATTENTION:
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700562 err = SCSI_DH_RETRY;
Chauhan, Vijay7687fb92009-03-04 12:17:54 +0530563 break;
564 case NOT_READY:
565 if (sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x01)
566 /* LUN Not Ready and is in the Process of Becoming
567 * Ready
568 */
569 err = SCSI_DH_RETRY;
570 break;
571 case ILLEGAL_REQUEST:
572 if (sense_hdr.asc == 0x91 && sense_hdr.ascq == 0x36)
573 /*
574 * Command Lock contention
575 */
576 err = SCSI_DH_RETRY;
577 break;
578 default:
Moger, Babudd784ed2009-09-03 21:42:28 -0600579 break;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700580 }
581
Moger, Babudd784ed2009-09-03 21:42:28 -0600582 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
583 "MODE_SELECT returned with sense %02x/%02x/%02x",
584 (char *) h->ctlr->array_name, h->ctlr->index,
585 sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq);
586
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700587done:
588 return err;
589}
590
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700591static void send_mode_select(struct work_struct *work)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700592{
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700593 struct rdac_controller *ctlr =
594 container_of(work, struct rdac_controller, ms_work);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700595 struct request *rq;
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700596 struct scsi_device *sdev = ctlr->ms_sdev;
597 struct rdac_dh_data *h = get_rdac_data(sdev);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700598 struct request_queue *q = sdev->request_queue;
Chandra Seetharamanc85f8cb92008-11-05 20:06:37 -0800599 int err, retry_cnt = RDAC_RETRY_COUNT;
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700600 struct rdac_queue_data *tmp, *qdata;
601 LIST_HEAD(list);
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700602
603 spin_lock(&ctlr->ms_lock);
604 list_splice_init(&ctlr->ms_head, &list);
605 ctlr->ms_queued = 0;
606 ctlr->ms_sdev = NULL;
607 spin_unlock(&ctlr->ms_lock);
608
Chandra Seetharamanc85f8cb92008-11-05 20:06:37 -0800609retry:
610 err = SCSI_DH_RES_TEMP_UNAVAIL;
Moger, Babu04b6e152011-02-11 15:14:08 -0700611 rq = rdac_failover_get(sdev, h, &list);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700612 if (!rq)
613 goto done;
614
Moger, Babudd784ed2009-09-03 21:42:28 -0600615 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
616 "%s MODE_SELECT command",
617 (char *) h->ctlr->array_name, h->ctlr->index,
Chandra Seetharamanc85f8cb92008-11-05 20:06:37 -0800618 (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying");
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700619
620 err = blk_execute_rq(q, NULL, rq, 1);
Chandra Seetharamanc85f8cb92008-11-05 20:06:37 -0800621 blk_put_request(rq);
622 if (err != SCSI_DH_OK) {
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700623 err = mode_select_handle_sense(sdev, h->sense);
Chandra Seetharamanc85f8cb92008-11-05 20:06:37 -0800624 if (err == SCSI_DH_RETRY && retry_cnt--)
625 goto retry;
626 }
Moger, Babudd784ed2009-09-03 21:42:28 -0600627 if (err == SCSI_DH_OK) {
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700628 h->state = RDAC_STATE_ACTIVE;
Moger, Babudd784ed2009-09-03 21:42:28 -0600629 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
630 "MODE_SELECT completed",
631 (char *) h->ctlr->array_name, h->ctlr->index);
632 }
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700633
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700634done:
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700635 list_for_each_entry_safe(qdata, tmp, &list, entry) {
636 list_del(&qdata->entry);
637 if (err == SCSI_DH_OK)
638 qdata->h->state = RDAC_STATE_ACTIVE;
639 if (qdata->callback_fn)
640 qdata->callback_fn(qdata->callback_data, err);
641 kfree(qdata);
642 }
643 return;
644}
645
646static int queue_mode_select(struct scsi_device *sdev,
647 activate_complete fn, void *data)
648{
649 struct rdac_queue_data *qdata;
650 struct rdac_controller *ctlr;
651
652 qdata = kzalloc(sizeof(*qdata), GFP_KERNEL);
653 if (!qdata)
654 return SCSI_DH_RETRY;
655
656 qdata->h = get_rdac_data(sdev);
657 qdata->callback_fn = fn;
658 qdata->callback_data = data;
659
660 ctlr = qdata->h->ctlr;
661 spin_lock(&ctlr->ms_lock);
662 list_add_tail(&qdata->entry, &ctlr->ms_head);
663 if (!ctlr->ms_queued) {
664 ctlr->ms_queued = 1;
665 ctlr->ms_sdev = sdev;
666 queue_work(kmpath_rdacd, &ctlr->ms_work);
667 }
668 spin_unlock(&ctlr->ms_lock);
669 return SCSI_DH_OK;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700670}
671
Chandra Seetharaman3ae31f62009-10-21 09:22:46 -0700672static int rdac_activate(struct scsi_device *sdev,
673 activate_complete fn, void *data)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700674{
675 struct rdac_dh_data *h = get_rdac_data(sdev);
676 int err = SCSI_DH_OK;
Moger, Babu3425fbf2011-04-08 11:39:30 -0600677 int act = 0;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700678
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700679 err = check_ownership(sdev, h);
680 if (err != SCSI_DH_OK)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700681 goto done;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700682
Moger, Babu3425fbf2011-04-08 11:39:30 -0600683 switch (h->mode) {
684 case RDAC_MODE:
685 if (h->lun_state == RDAC_LUN_UNOWNED)
686 act = 1;
687 break;
688 case RDAC_MODE_IOSHIP:
689 if ((h->lun_state == RDAC_LUN_UNOWNED) &&
690 (h->preferred == RDAC_PREFERRED))
691 act = 1;
692 break;
693 default:
694 break;
695 }
696
697 if (act) {
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700698 err = queue_mode_select(sdev, fn, data);
699 if (err == SCSI_DH_OK)
700 return 0;
701 }
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700702done:
Chandra Seetharaman3ae31f62009-10-21 09:22:46 -0700703 if (fn)
704 fn(data, err);
705 return 0;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700706}
707
708static int rdac_prep_fn(struct scsi_device *sdev, struct request *req)
709{
710 struct rdac_dh_data *h = get_rdac_data(sdev);
711 int ret = BLKPREP_OK;
712
713 if (h->state != RDAC_STATE_ACTIVE) {
714 ret = BLKPREP_KILL;
715 req->cmd_flags |= REQ_QUIET;
716 }
717 return ret;
718
719}
720
721static int rdac_check_sense(struct scsi_device *sdev,
722 struct scsi_sense_hdr *sense_hdr)
723{
724 struct rdac_dh_data *h = get_rdac_data(sdev);
Moger, Babudd784ed2009-09-03 21:42:28 -0600725
726 RDAC_LOG(RDAC_LOG_SENSE, sdev, "array %s, ctlr %d, "
727 "I/O returned with sense %02x/%02x/%02x",
728 (char *) h->ctlr->array_name, h->ctlr->index,
729 sense_hdr->sense_key, sense_hdr->asc, sense_hdr->ascq);
730
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700731 switch (sense_hdr->sense_key) {
732 case NOT_READY:
Chauhan, Vijay8f032262009-04-20 18:14:23 +0530733 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01)
734 /* LUN Not Ready - Logical Unit Not Ready and is in
735 * the process of becoming ready
736 * Just retry.
737 */
738 return ADD_TO_MLQUEUE;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700739 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x81)
740 /* LUN Not Ready - Storage firmware incompatible
741 * Manual code synchonisation required.
742 *
743 * Nothing we can do here. Try to bypass the path.
744 */
745 return SUCCESS;
746 if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0xA1)
747 /* LUN Not Ready - Quiescense in progress
748 *
749 * Just retry and wait.
750 */
Mike Andersonc7dbb622008-08-12 12:11:57 -0700751 return ADD_TO_MLQUEUE;
Chauhan, Vijayaf50bb92009-03-17 18:51:40 +0530752 if (sense_hdr->asc == 0xA1 && sense_hdr->ascq == 0x02)
753 /* LUN Not Ready - Quiescense in progress
754 * or has been achieved
755 * Just retry.
756 */
757 return ADD_TO_MLQUEUE;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700758 break;
759 case ILLEGAL_REQUEST:
760 if (sense_hdr->asc == 0x94 && sense_hdr->ascq == 0x01) {
761 /* Invalid Request - Current Logical Unit Ownership.
762 * Controller is not the current owner of the LUN,
763 * Fail the path, so that the other path be used.
764 */
765 h->state = RDAC_STATE_PASSIVE;
766 return SUCCESS;
767 }
768 break;
769 case UNIT_ATTENTION:
770 if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00)
771 /*
772 * Power On, Reset, or Bus Device Reset, just retry.
773 */
Mike Andersonc7dbb622008-08-12 12:11:57 -0700774 return ADD_TO_MLQUEUE;
Chauhan, Vijayea41e412009-01-26 21:29:37 +0530775 if (sense_hdr->asc == 0x8b && sense_hdr->ascq == 0x02)
776 /*
777 * Quiescence in progress , just retry.
778 */
779 return ADD_TO_MLQUEUE;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700780 break;
781 }
782 /* success just means we do not care what scsi-ml does */
783 return SCSI_RETURN_NOT_HANDLED;
784}
785
Adrian Bunkf08c0762008-08-11 11:59:21 -0700786static const struct scsi_dh_devlist rdac_dev_list[] = {
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700787 {"IBM", "1722"},
788 {"IBM", "1724"},
789 {"IBM", "1726"},
790 {"IBM", "1742"},
Moger, Babu6f4fdda2009-11-04 12:36:16 -0700791 {"IBM", "1745"},
792 {"IBM", "1746"},
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700793 {"IBM", "1814"},
794 {"IBM", "1815"},
795 {"IBM", "1818"},
796 {"IBM", "3526"},
797 {"SGI", "TP9400"},
798 {"SGI", "TP9500"},
Moger, Babu66195fc2011-09-02 11:21:17 -0400799 {"SGI", "TP9700"},
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700800 {"SGI", "IS"},
801 {"STK", "OPENstorage D280"},
802 {"SUN", "CSM200_R"},
Charlie Brady5bab0882009-08-26 14:16:57 -0400803 {"SUN", "LCSM100_I"},
804 {"SUN", "LCSM100_S"},
805 {"SUN", "LCSM100_E"},
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700806 {"SUN", "LCSM100_F"},
Yanqing_Liu@Dell.com650849d2008-10-02 12:18:33 -0500807 {"DELL", "MD3000"},
808 {"DELL", "MD3000i"},
Yanqing_Liu@Dell.comcdf69bb2009-08-17 14:31:42 -0500809 {"DELL", "MD32xx"},
810 {"DELL", "MD32xxi"},
Yanqing_Liu@Dell.com2cf75f12010-05-19 12:31:36 -0500811 {"DELL", "MD36xxi"},
Yanqing_Liu@Dell.combc898c92011-03-11 09:47:11 -0600812 {"DELL", "MD36xxf"},
Babu Moger273c4782008-11-10 16:17:48 -0700813 {"LSI", "INF-01-00"},
814 {"ENGENIO", "INF-01-00"},
Chandra Seetharaman4dbfb542009-08-12 12:43:20 -0700815 {"STK", "FLEXLINE 380"},
816 {"SUN", "CSM100_R_FC"},
Chauhan, Vijay15660672010-10-18 14:07:24 +0530817 {"SUN", "STK6580_6780"},
818 {"SUN", "SUN_6180"},
Moger, Babu66195fc2011-09-02 11:21:17 -0400819 {"SUN", "ArrayStorage"},
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700820 {NULL, NULL},
821};
822
Moger, Babubee89ea2011-12-01 15:01:40 -0500823static bool rdac_match(struct scsi_device *sdev)
824{
825 int i;
826
827 if (scsi_device_tpgs(sdev))
828 return false;
829
830 for (i = 0; rdac_dev_list[i].vendor; i++) {
831 if (!strncmp(sdev->vendor, rdac_dev_list[i].vendor,
832 strlen(rdac_dev_list[i].vendor)) &&
833 !strncmp(sdev->model, rdac_dev_list[i].model,
834 strlen(rdac_dev_list[i].model))) {
835 return true;
836 }
837 }
838 return false;
839}
840
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700841static int rdac_bus_attach(struct scsi_device *sdev);
842static void rdac_bus_detach(struct scsi_device *sdev);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700843
844static struct scsi_device_handler rdac_dh = {
845 .name = RDAC_NAME,
846 .module = THIS_MODULE,
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700847 .devlist = rdac_dev_list,
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700848 .prep_fn = rdac_prep_fn,
849 .check_sense = rdac_check_sense,
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700850 .attach = rdac_bus_attach,
851 .detach = rdac_bus_detach,
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700852 .activate = rdac_activate,
Moger, Babubee89ea2011-12-01 15:01:40 -0500853 .match = rdac_match,
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700854};
855
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700856static int rdac_bus_attach(struct scsi_device *sdev)
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700857{
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700858 struct scsi_dh_data *scsi_dh_data;
859 struct rdac_dh_data *h;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700860 unsigned long flags;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700861 int err;
Moger, Babu15276662009-09-03 21:42:21 -0600862 char array_name[ARRAY_LABEL_LEN];
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700863 char array_id[UNIQUE_ID_LEN];
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700864
Hillf Danton9dfeb312011-02-11 15:17:33 -0700865 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700866 + sizeof(*h) , GFP_KERNEL);
867 if (!scsi_dh_data) {
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700868 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700869 RDAC_NAME);
Chandra Seetharaman33af79d2008-07-16 17:35:08 -0700870 return 0;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700871 }
872
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700873 scsi_dh_data->scsi_dh = &rdac_dh;
874 h = (struct rdac_dh_data *) scsi_dh_data->buf;
875 h->lun = UNINITIALIZED_LUN;
876 h->state = RDAC_STATE_ACTIVE;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700877
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700878 err = get_lun_info(sdev, h, array_name, array_id);
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700879 if (err != SCSI_DH_OK)
880 goto failed;
881
Chandra Seetharamana53becc2011-07-20 14:18:56 -0700882 err = initialize_controller(sdev, h, array_name, array_id);
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700883 if (err != SCSI_DH_OK)
884 goto failed;
885
Moger, Babu87b79a52009-09-03 21:42:15 -0600886 err = check_ownership(sdev, h);
887 if (err != SCSI_DH_OK)
888 goto clean_ctlr;
889
890 err = set_mode_select(sdev, h);
891 if (err != SCSI_DH_OK)
892 goto clean_ctlr;
893
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700894 if (!try_module_get(THIS_MODULE))
Moger, Babu87b79a52009-09-03 21:42:15 -0600895 goto clean_ctlr;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700896
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700897 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
898 sdev->scsi_dh_data = scsi_dh_data;
899 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700900
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700901 sdev_printk(KERN_NOTICE, sdev,
Moger, Babueebe9b92011-04-08 11:37:40 -0600902 "%s: LUN %d (%s) (%s)\n",
903 RDAC_NAME, h->lun, mode[(int)h->mode],
904 lun_state[(int)h->lun_state]);
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700905
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700906 return 0;
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700907
Moger, Babu87b79a52009-09-03 21:42:15 -0600908clean_ctlr:
909 kref_put(&h->ctlr->kref, release_controller);
910
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700911failed:
912 kfree(scsi_dh_data);
913 sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
914 RDAC_NAME);
915 return -EINVAL;
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700916}
917
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700918static void rdac_bus_detach( struct scsi_device *sdev )
919{
920 struct scsi_dh_data *scsi_dh_data;
921 struct rdac_dh_data *h;
922 unsigned long flags;
923
924 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
925 scsi_dh_data = sdev->scsi_dh_data;
926 sdev->scsi_dh_data = NULL;
927 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
928
929 h = (struct rdac_dh_data *) scsi_dh_data->buf;
930 if (h->ctlr)
931 kref_put(&h->ctlr->kref, release_controller);
932 kfree(scsi_dh_data);
933 module_put(THIS_MODULE);
Hannes Reineckeca9f0082008-07-17 16:53:15 -0700934 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700935}
936
937
938
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700939static int __init rdac_init(void)
940{
941 int r;
942
943 r = scsi_register_device_handler(&rdac_dh);
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700944 if (r != 0) {
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700945 printk(KERN_ERR "Failed to register scsi device handler.");
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700946 goto done;
947 }
948
949 /*
950 * Create workqueue to handle mode selects for rdac
951 */
952 kmpath_rdacd = create_singlethread_workqueue("kmpath_rdacd");
953 if (!kmpath_rdacd) {
954 scsi_unregister_device_handler(&rdac_dh);
955 printk(KERN_ERR "kmpath_rdacd creation failed.\n");
Richard Weinberger9fc397f2011-11-18 01:44:27 +0100956
957 r = -EINVAL;
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700958 }
959done:
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700960 return r;
961}
962
963static void __exit rdac_exit(void)
964{
Chandra Seetharaman970f3f42009-10-21 09:22:51 -0700965 destroy_workqueue(kmpath_rdacd);
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700966 scsi_unregister_device_handler(&rdac_dh);
967}
968
969module_init(rdac_init);
970module_exit(rdac_exit);
971
Chauhan, Vijay5f7a6432011-09-02 13:26:32 +0530972MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700973MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
Moger, Babua0b990c2011-02-11 16:12:44 -0700974MODULE_VERSION("01.00.0000.0000");
Chandra Seetharamanfbd7ab32008-05-01 14:49:52 -0700975MODULE_LICENSE("GPL");