2 * LSI/Engenio/NetApp E-Series RDAC SCSI Device Handler
4 * Copyright (C) 2005 Mike Christie. All rights reserved.
5 * Copyright (C) Chandra Seetharaman, IBM Corp. 2007
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <scsi/scsi.h>
23 #include <scsi/scsi_eh.h>
24 #include <scsi/scsi_dh.h>
25 #include <linux/workqueue.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
29 #define RDAC_NAME "rdac"
30 #define RDAC_RETRY_COUNT 5
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.
39 #define RDAC_QUIESCENCE_TIME 20
43 #define RDAC_PAGE_CODE_REDUNDANT_CONTROLLER 0x2c
46 * Controller modes definitions
48 #define RDAC_MODE_TRANSFER_SPECIFIED_LUNS 0x02
53 #define RDAC_FORCED_QUIESENCE 0x02
55 #define RDAC_TIMEOUT (60 * HZ)
56 #define RDAC_RETRIES 3
58 struct rdac_mode_6_hdr
{
65 struct rdac_mode_10_hdr
{
73 struct rdac_mode_common
{
74 u8 controller_serial
[16];
75 u8 alt_controller_serial
[16];
78 u8 quiescence_timeout
;
82 struct rdac_pg_legacy
{
83 struct rdac_mode_6_hdr hdr
;
86 struct rdac_mode_common common
;
87 #define MODE6_MAX_LUN 32
88 u8 lun_table
[MODE6_MAX_LUN
];
94 struct rdac_pg_expanded
{
95 struct rdac_mode_10_hdr hdr
;
99 struct rdac_mode_common common
;
107 u8 page_code
; /* 0xC9 */
110 u8 page_id
[4]; /* "vace" */
116 #define SUBSYS_ID_LEN 16
117 #define SLOT_ID_LEN 2
118 #define ARRAY_LABEL_LEN 31
122 u8 page_code
; /* 0xC4 */
125 u8 page_id
[4]; /* "subs" */
126 u8 subsys_id
[SUBSYS_ID_LEN
];
128 u8 slot_id
[SLOT_ID_LEN
];
132 #define UNIQUE_ID_LEN 16
135 u8 page_code
; /* 0xC8 */
138 u8 page_id
[4]; /* "edid" */
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];
151 struct rdac_controller
{
152 u8 array_id
[UNIQUE_ID_LEN
];
155 struct list_head node
; /* list of all controllers */
157 struct rdac_pg_legacy legacy
;
158 struct rdac_pg_expanded expanded
;
161 u8 array_name
[ARRAY_LABEL_LEN
];
162 struct Scsi_Host
*host
;
165 struct work_struct ms_work
;
166 struct scsi_device
*ms_sdev
;
167 struct list_head ms_head
;
172 u8 page_code
; /* 0xC2 */
175 u8 page_id
[4]; /* "swr4" */
179 u8 max_lun_supported
;
180 u8 partitions
[239]; /* Total allocation length should be 0xFF */
183 struct rdac_dh_data
{
184 struct scsi_dh_data dh_data
;
185 struct rdac_controller
*ctlr
;
186 #define UNINITIALIZED_LUN (1 << 8)
190 #define RDAC_MODE_AVT 1
191 #define RDAC_MODE_IOSHIP 2
194 #define RDAC_STATE_ACTIVE 0
195 #define RDAC_STATE_PASSIVE 1
198 #define RDAC_LUN_UNOWNED 0
199 #define RDAC_LUN_OWNED 1
202 #define RDAC_PREFERRED 0
203 #define RDAC_NON_PREFERRED 1
206 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
208 struct c2_inquiry c2
;
209 struct c4_inquiry c4
;
210 struct c8_inquiry c8
;
211 struct c9_inquiry c9
;
215 static const char *mode
[] = {
220 static const char *lun_state
[] =
226 struct rdac_queue_data
{
227 struct list_head entry
;
228 struct rdac_dh_data
*h
;
229 activate_complete callback_fn
;
233 static LIST_HEAD(ctlr_list
);
234 static DEFINE_SPINLOCK(list_lock
);
235 static struct workqueue_struct
*kmpath_rdacd
;
236 static void send_mode_select(struct work_struct
*work
);
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
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");
249 #define RDAC_LOG_FAILOVER 0
250 #define RDAC_LOG_SENSE 2
252 #define RDAC_LOG_BITS 2
254 #define RDAC_LOG_LEVEL(SHIFT) \
255 ((rdac_logging >> (SHIFT)) & ((1 << (RDAC_LOG_BITS)) - 1))
257 #define RDAC_LOG(SHIFT, sdev, f, arg...) \
259 if (unlikely(RDAC_LOG_LEVEL(SHIFT))) \
260 sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \
263 static inline struct rdac_dh_data
*get_rdac_data(struct scsi_device
*sdev
)
265 return container_of(sdev
->scsi_dh_data
, struct rdac_dh_data
, dh_data
);
268 static struct request
*get_rdac_req(struct scsi_device
*sdev
,
269 void *buffer
, unsigned buflen
, int rw
)
272 struct request_queue
*q
= sdev
->request_queue
;
274 rq
= blk_get_request(q
, rw
, GFP_NOIO
);
277 sdev_printk(KERN_INFO
, sdev
,
278 "get_rdac_req: blk_get_request failed.\n");
281 blk_rq_set_block_pc(rq
);
283 if (buflen
&& blk_rq_map_kern(q
, rq
, buffer
, buflen
, GFP_NOIO
)) {
285 sdev_printk(KERN_INFO
, sdev
,
286 "get_rdac_req: blk_rq_map_kern failed.\n");
290 rq
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
292 rq
->retries
= RDAC_RETRIES
;
293 rq
->timeout
= RDAC_TIMEOUT
;
298 static struct request
*rdac_failover_get(struct scsi_device
*sdev
,
299 struct rdac_dh_data
*h
, struct list_head
*list
)
302 struct rdac_mode_common
*common
;
304 struct rdac_queue_data
*qdata
;
307 if (h
->ctlr
->use_ms10
) {
308 struct rdac_pg_expanded
*rdac_pg
;
310 data_size
= sizeof(struct rdac_pg_expanded
);
311 rdac_pg
= &h
->ctlr
->mode_select
.expanded
;
312 memset(rdac_pg
, 0, data_size
);
313 common
= &rdac_pg
->common
;
314 rdac_pg
->page_code
= RDAC_PAGE_CODE_REDUNDANT_CONTROLLER
+ 0x40;
315 rdac_pg
->subpage_code
= 0x1;
316 rdac_pg
->page_len
[0] = 0x01;
317 rdac_pg
->page_len
[1] = 0x28;
318 lun_table
= rdac_pg
->lun_table
;
320 struct rdac_pg_legacy
*rdac_pg
;
322 data_size
= sizeof(struct rdac_pg_legacy
);
323 rdac_pg
= &h
->ctlr
->mode_select
.legacy
;
324 memset(rdac_pg
, 0, data_size
);
325 common
= &rdac_pg
->common
;
326 rdac_pg
->page_code
= RDAC_PAGE_CODE_REDUNDANT_CONTROLLER
;
327 rdac_pg
->page_len
= 0x68;
328 lun_table
= rdac_pg
->lun_table
;
330 common
->rdac_mode
[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS
;
331 common
->quiescence_timeout
= RDAC_QUIESCENCE_TIME
;
332 common
->rdac_options
= RDAC_FORCED_QUIESENCE
;
334 list_for_each_entry(qdata
, list
, entry
) {
335 lun_table
[qdata
->h
->lun
] = 0x81;
338 /* get request for block layer packet command */
339 rq
= get_rdac_req(sdev
, &h
->ctlr
->mode_select
, data_size
, WRITE
);
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;
349 rq
->cmd
[0] = MODE_SELECT
;
350 rq
->cmd
[4] = data_size
;
352 rq
->cmd_len
= COMMAND_SIZE(rq
->cmd
[0]);
354 rq
->sense
= h
->sense
;
355 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
361 static void release_controller(struct kref
*kref
)
363 struct rdac_controller
*ctlr
;
364 ctlr
= container_of(kref
, struct rdac_controller
, kref
);
366 list_del(&ctlr
->node
);
370 static struct rdac_controller
*get_controller(int index
, char *array_name
,
371 u8
*array_id
, struct scsi_device
*sdev
)
373 struct rdac_controller
*ctlr
, *tmp
;
375 list_for_each_entry(tmp
, &ctlr_list
, node
) {
376 if ((memcmp(tmp
->array_id
, array_id
, UNIQUE_ID_LEN
) == 0) &&
377 (tmp
->index
== index
) &&
378 (tmp
->host
== sdev
->host
)) {
379 kref_get(&tmp
->kref
);
383 ctlr
= kmalloc(sizeof(*ctlr
), GFP_ATOMIC
);
387 /* initialize fields of controller */
388 memcpy(ctlr
->array_id
, array_id
, UNIQUE_ID_LEN
);
390 ctlr
->host
= sdev
->host
;
391 memcpy(ctlr
->array_name
, array_name
, ARRAY_LABEL_LEN
);
393 kref_init(&ctlr
->kref
);
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
);
400 list_add(&ctlr
->node
, &ctlr_list
);
405 static int submit_inquiry(struct scsi_device
*sdev
, int page_code
,
406 unsigned int len
, struct rdac_dh_data
*h
)
409 struct request_queue
*q
= sdev
->request_queue
;
410 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
412 rq
= get_rdac_req(sdev
, &h
->inq
, len
, READ
);
416 /* Prepare the command. */
417 rq
->cmd
[0] = INQUIRY
;
419 rq
->cmd
[2] = page_code
;
421 rq
->cmd_len
= COMMAND_SIZE(INQUIRY
);
423 rq
->sense
= h
->sense
;
424 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
427 err
= blk_execute_rq(q
, NULL
, rq
, 1);
436 static int get_lun_info(struct scsi_device
*sdev
, struct rdac_dh_data
*h
,
437 char *array_name
, u8
*array_id
)
440 struct c8_inquiry
*inqp
;
442 err
= submit_inquiry(sdev
, 0xC8, sizeof(struct c8_inquiry
), h
);
443 if (err
== SCSI_DH_OK
) {
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
;
450 h
->lun
= inqp
->lun
[7]; /* Uses only the last byte */
452 for(i
=0; i
<ARRAY_LABEL_LEN
-1; ++i
)
453 *(array_name
+i
) = inqp
->array_user_label
[(2*i
)+1];
455 *(array_name
+ARRAY_LABEL_LEN
-1) = '\0';
456 memset(array_id
, 0, UNIQUE_ID_LEN
);
457 memcpy(array_id
, inqp
->array_unique_id
, inqp
->array_uniq_id_len
);
462 static int check_ownership(struct scsi_device
*sdev
, struct rdac_dh_data
*h
)
465 struct c9_inquiry
*inqp
;
467 h
->state
= RDAC_STATE_ACTIVE
;
468 err
= submit_inquiry(sdev
, 0xC9, sizeof(struct c9_inquiry
), h
);
469 if (err
== SCSI_DH_OK
) {
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 */
477 h
->mode
= RDAC_MODE
; /* LUN in RDAC mode */
479 /* Update ownership */
480 if (inqp
->avte_cvp
& 0x1)
481 h
->lun_state
= RDAC_LUN_OWNED
;
483 h
->lun_state
= RDAC_LUN_UNOWNED
;
484 if (h
->mode
== RDAC_MODE
)
485 h
->state
= RDAC_STATE_PASSIVE
;
488 /* Update path prio*/
489 if (inqp
->path_prio
& 0x1)
490 h
->preferred
= RDAC_PREFERRED
;
492 h
->preferred
= RDAC_NON_PREFERRED
;
498 static int initialize_controller(struct scsi_device
*sdev
,
499 struct rdac_dh_data
*h
, char *array_name
, u8
*array_id
)
502 struct c4_inquiry
*inqp
;
504 err
= submit_inquiry(sdev
, 0xC4, sizeof(struct c4_inquiry
), h
);
505 if (err
== SCSI_DH_OK
) {
507 /* get the controller index */
508 if (inqp
->slot_id
[1] == 0x31)
513 spin_lock(&list_lock
);
514 h
->ctlr
= get_controller(index
, array_name
, array_id
, sdev
);
516 err
= SCSI_DH_RES_TEMP_UNAVAIL
;
517 spin_unlock(&list_lock
);
522 static int set_mode_select(struct scsi_device
*sdev
, struct rdac_dh_data
*h
)
525 struct c2_inquiry
*inqp
;
527 err
= submit_inquiry(sdev
, 0xC2, sizeof(struct c2_inquiry
), h
);
528 if (err
== SCSI_DH_OK
) {
531 * If more than MODE6_MAX_LUN luns are supported, use
534 if (inqp
->max_lun_supported
>= MODE6_MAX_LUN
)
535 h
->ctlr
->use_ms10
= 1;
537 h
->ctlr
->use_ms10
= 0;
542 static int mode_select_handle_sense(struct scsi_device
*sdev
,
543 unsigned char *sensebuf
)
545 struct scsi_sense_hdr sense_hdr
;
546 int err
= SCSI_DH_IO
, ret
;
547 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
549 ret
= scsi_normalize_sense(sensebuf
, SCSI_SENSE_BUFFERSIZE
, &sense_hdr
);
553 switch (sense_hdr
.sense_key
) {
555 case ABORTED_COMMAND
:
560 if (sense_hdr
.asc
== 0x04 && sense_hdr
.ascq
== 0x01)
561 /* LUN Not Ready and is in the Process of Becoming
566 case ILLEGAL_REQUEST
:
567 if (sense_hdr
.asc
== 0x91 && sense_hdr
.ascq
== 0x36)
569 * Command Lock contention
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
);
586 static void send_mode_select(struct work_struct
*work
)
588 struct rdac_controller
*ctlr
=
589 container_of(work
, struct rdac_controller
, ms_work
);
591 struct scsi_device
*sdev
= ctlr
->ms_sdev
;
592 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
593 struct request_queue
*q
= sdev
->request_queue
;
594 int err
, retry_cnt
= RDAC_RETRY_COUNT
;
595 struct rdac_queue_data
*tmp
, *qdata
;
598 spin_lock(&ctlr
->ms_lock
);
599 list_splice_init(&ctlr
->ms_head
, &list
);
601 ctlr
->ms_sdev
= NULL
;
602 spin_unlock(&ctlr
->ms_lock
);
605 err
= SCSI_DH_RES_TEMP_UNAVAIL
;
606 rq
= rdac_failover_get(sdev
, h
, &list
);
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
,
613 (retry_cnt
== RDAC_RETRY_COUNT
) ? "queueing" : "retrying");
615 err
= blk_execute_rq(q
, NULL
, rq
, 1);
617 if (err
!= SCSI_DH_OK
) {
618 err
= mode_select_handle_sense(sdev
, h
->sense
);
619 if (err
== SCSI_DH_RETRY
&& retry_cnt
--)
622 if (err
== SCSI_DH_OK
) {
623 h
->state
= RDAC_STATE_ACTIVE
;
624 RDAC_LOG(RDAC_LOG_FAILOVER
, sdev
, "array %s, ctlr %d, "
625 "MODE_SELECT completed",
626 (char *) h
->ctlr
->array_name
, h
->ctlr
->index
);
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
);
641 static int queue_mode_select(struct scsi_device
*sdev
,
642 activate_complete fn
, void *data
)
644 struct rdac_queue_data
*qdata
;
645 struct rdac_controller
*ctlr
;
647 qdata
= kzalloc(sizeof(*qdata
), GFP_KERNEL
);
649 return SCSI_DH_RETRY
;
651 qdata
->h
= get_rdac_data(sdev
);
652 qdata
->callback_fn
= fn
;
653 qdata
->callback_data
= data
;
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
) {
660 ctlr
->ms_sdev
= sdev
;
661 queue_work(kmpath_rdacd
, &ctlr
->ms_work
);
663 spin_unlock(&ctlr
->ms_lock
);
667 static int rdac_activate(struct scsi_device
*sdev
,
668 activate_complete fn
, void *data
)
670 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
671 int err
= SCSI_DH_OK
;
674 err
= check_ownership(sdev
, h
);
675 if (err
!= SCSI_DH_OK
)
680 if (h
->lun_state
== RDAC_LUN_UNOWNED
)
683 case RDAC_MODE_IOSHIP
:
684 if ((h
->lun_state
== RDAC_LUN_UNOWNED
) &&
685 (h
->preferred
== RDAC_PREFERRED
))
693 err
= queue_mode_select(sdev
, fn
, data
);
694 if (err
== SCSI_DH_OK
)
703 static int rdac_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
705 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
706 int ret
= BLKPREP_OK
;
708 if (h
->state
!= RDAC_STATE_ACTIVE
) {
710 req
->cmd_flags
|= REQ_QUIET
;
716 static int rdac_check_sense(struct scsi_device
*sdev
,
717 struct scsi_sense_hdr
*sense_hdr
)
719 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
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
);
726 switch (sense_hdr
->sense_key
) {
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
733 return ADD_TO_MLQUEUE
;
734 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x81)
735 /* LUN Not Ready - Storage firmware incompatible
736 * Manual code synchonisation required.
738 * Nothing we can do here. Try to bypass the path.
741 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0xA1)
742 /* LUN Not Ready - Quiescense in progress
744 * Just retry and wait.
746 return ADD_TO_MLQUEUE
;
747 if (sense_hdr
->asc
== 0xA1 && sense_hdr
->ascq
== 0x02)
748 /* LUN Not Ready - Quiescense in progress
749 * or has been achieved
752 return ADD_TO_MLQUEUE
;
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.
760 h
->state
= RDAC_STATE_PASSIVE
;
765 if (sense_hdr
->asc
== 0x29 && sense_hdr
->ascq
== 0x00)
767 * Power On, Reset, or Bus Device Reset, just retry.
769 return ADD_TO_MLQUEUE
;
770 if (sense_hdr
->asc
== 0x8b && sense_hdr
->ascq
== 0x02)
772 * Quiescence in progress , just retry.
774 return ADD_TO_MLQUEUE
;
777 /* success just means we do not care what scsi-ml does */
778 return SCSI_RETURN_NOT_HANDLED
;
781 static const struct {
784 } rdac_dev_list
[] = {
798 {"STK", "OPENstorage D280"},
799 {"STK", "FLEXLINE 380"},
802 {"SUN", "STK6580_6780"},
804 {"SUN", "ArrayStorage"},
806 {"NETAPP", "INF-01-00"},
807 {"LSI", "INF-01-00"},
808 {"ENGENIO", "INF-01-00"},
812 static bool rdac_match(struct scsi_device
*sdev
)
816 if (scsi_device_tpgs(sdev
))
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
))) {
830 static struct scsi_dh_data
*rdac_bus_attach(struct scsi_device
*sdev
)
832 struct rdac_dh_data
*h
;
834 char array_name
[ARRAY_LABEL_LEN
];
835 char array_id
[UNIQUE_ID_LEN
];
837 h
= kzalloc(sizeof(*h
) , GFP_KERNEL
);
839 return ERR_PTR(-ENOMEM
);
840 h
->lun
= UNINITIALIZED_LUN
;
841 h
->state
= RDAC_STATE_ACTIVE
;
843 err
= get_lun_info(sdev
, h
, array_name
, array_id
);
844 if (err
!= SCSI_DH_OK
)
847 err
= initialize_controller(sdev
, h
, array_name
, array_id
);
848 if (err
!= SCSI_DH_OK
)
851 err
= check_ownership(sdev
, h
);
852 if (err
!= SCSI_DH_OK
)
855 err
= set_mode_select(sdev
, h
);
856 if (err
!= SCSI_DH_OK
)
859 sdev_printk(KERN_NOTICE
, sdev
,
860 "%s: LUN %d (%s) (%s)\n",
861 RDAC_NAME
, h
->lun
, mode
[(int)h
->mode
],
862 lun_state
[(int)h
->lun_state
]);
867 spin_lock(&list_lock
);
868 kref_put(&h
->ctlr
->kref
, release_controller
);
869 spin_unlock(&list_lock
);
873 return ERR_PTR(-EINVAL
);
876 static void rdac_bus_detach( struct scsi_device
*sdev
)
878 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
880 if (h
->ctlr
&& h
->ctlr
->ms_queued
)
881 flush_workqueue(kmpath_rdacd
);
883 spin_lock(&list_lock
);
885 kref_put(&h
->ctlr
->kref
, release_controller
);
886 spin_unlock(&list_lock
);
890 static struct scsi_device_handler rdac_dh
= {
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
,
901 static int __init
rdac_init(void)
905 r
= scsi_register_device_handler(&rdac_dh
);
907 printk(KERN_ERR
"Failed to register scsi device handler.");
912 * Create workqueue to handle mode selects for rdac
914 kmpath_rdacd
= create_singlethread_workqueue("kmpath_rdacd");
916 scsi_unregister_device_handler(&rdac_dh
);
917 printk(KERN_ERR
"kmpath_rdacd creation failed.\n");
925 static void __exit
rdac_exit(void)
927 destroy_workqueue(kmpath_rdacd
);
928 scsi_unregister_device_handler(&rdac_dh
);
931 module_init(rdac_init
);
932 module_exit(rdac_exit
);
934 MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
935 MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
936 MODULE_VERSION("01.00.0000.0000");
937 MODULE_LICENSE("GPL");