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 rdac_controller
*ctlr
;
185 #define UNINITIALIZED_LUN (1 << 8)
189 #define RDAC_MODE_AVT 1
190 #define RDAC_MODE_IOSHIP 2
193 #define RDAC_STATE_ACTIVE 0
194 #define RDAC_STATE_PASSIVE 1
197 #define RDAC_LUN_UNOWNED 0
198 #define RDAC_LUN_OWNED 1
201 #define RDAC_PREFERRED 0
202 #define RDAC_NON_PREFERRED 1
205 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
207 struct c2_inquiry c2
;
208 struct c4_inquiry c4
;
209 struct c8_inquiry c8
;
210 struct c9_inquiry c9
;
214 static const char *mode
[] = {
219 static const char *lun_state
[] =
225 struct rdac_queue_data
{
226 struct list_head entry
;
227 struct rdac_dh_data
*h
;
228 activate_complete callback_fn
;
232 static LIST_HEAD(ctlr_list
);
233 static DEFINE_SPINLOCK(list_lock
);
234 static struct workqueue_struct
*kmpath_rdacd
;
235 static void send_mode_select(struct work_struct
*work
);
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
242 static int rdac_logging
= 1;
243 module_param(rdac_logging
, int, S_IRUGO
|S_IWUSR
);
244 MODULE_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");
248 #define RDAC_LOG_FAILOVER 0
249 #define RDAC_LOG_SENSE 2
251 #define RDAC_LOG_BITS 2
253 #define RDAC_LOG_LEVEL(SHIFT) \
254 ((rdac_logging >> (SHIFT)) & ((1 << (RDAC_LOG_BITS)) - 1))
256 #define RDAC_LOG(SHIFT, sdev, f, arg...) \
258 if (unlikely(RDAC_LOG_LEVEL(SHIFT))) \
259 sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \
262 static inline struct rdac_dh_data
*get_rdac_data(struct scsi_device
*sdev
)
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
);
269 static struct request
*get_rdac_req(struct scsi_device
*sdev
,
270 void *buffer
, unsigned buflen
, int rw
)
273 struct request_queue
*q
= sdev
->request_queue
;
275 rq
= blk_get_request(q
, rw
, GFP_NOIO
);
278 sdev_printk(KERN_INFO
, sdev
,
279 "get_rdac_req: blk_get_request failed.\n");
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_type
= REQ_TYPE_BLOCK_PC
;
291 rq
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
293 rq
->retries
= RDAC_RETRIES
;
294 rq
->timeout
= RDAC_TIMEOUT
;
299 static struct request
*rdac_failover_get(struct scsi_device
*sdev
,
300 struct rdac_dh_data
*h
, struct list_head
*list
)
303 struct rdac_mode_common
*common
;
305 struct rdac_queue_data
*qdata
;
308 if (h
->ctlr
->use_ms10
) {
309 struct rdac_pg_expanded
*rdac_pg
;
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;
319 lun_table
= rdac_pg
->lun_table
;
321 struct rdac_pg_legacy
*rdac_pg
;
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;
329 lun_table
= rdac_pg
->lun_table
;
331 common
->rdac_mode
[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS
;
332 common
->quiescence_timeout
= RDAC_QUIESCENCE_TIME
;
333 common
->rdac_options
= RDAC_FORCED_QUIESENCE
;
335 list_for_each_entry(qdata
, list
, entry
) {
336 lun_table
[qdata
->h
->lun
] = 0x81;
339 /* get request for block layer packet command */
340 rq
= get_rdac_req(sdev
, &h
->ctlr
->mode_select
, data_size
, WRITE
);
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;
350 rq
->cmd
[0] = MODE_SELECT
;
351 rq
->cmd
[4] = data_size
;
353 rq
->cmd_len
= COMMAND_SIZE(rq
->cmd
[0]);
355 rq
->sense
= h
->sense
;
356 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
362 static void release_controller(struct kref
*kref
)
364 struct rdac_controller
*ctlr
;
365 ctlr
= container_of(kref
, struct rdac_controller
, kref
);
367 list_del(&ctlr
->node
);
371 static struct rdac_controller
*get_controller(int index
, char *array_name
,
372 u8
*array_id
, struct scsi_device
*sdev
)
374 struct rdac_controller
*ctlr
, *tmp
;
376 list_for_each_entry(tmp
, &ctlr_list
, node
) {
377 if ((memcmp(tmp
->array_id
, array_id
, UNIQUE_ID_LEN
) == 0) &&
378 (tmp
->index
== index
) &&
379 (tmp
->host
== sdev
->host
)) {
380 kref_get(&tmp
->kref
);
384 ctlr
= kmalloc(sizeof(*ctlr
), GFP_ATOMIC
);
388 /* initialize fields of controller */
389 memcpy(ctlr
->array_id
, array_id
, UNIQUE_ID_LEN
);
391 ctlr
->host
= sdev
->host
;
392 memcpy(ctlr
->array_name
, array_name
, ARRAY_LABEL_LEN
);
394 kref_init(&ctlr
->kref
);
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
);
401 list_add(&ctlr
->node
, &ctlr_list
);
406 static int submit_inquiry(struct scsi_device
*sdev
, int page_code
,
407 unsigned int len
, struct rdac_dh_data
*h
)
410 struct request_queue
*q
= sdev
->request_queue
;
411 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
413 rq
= get_rdac_req(sdev
, &h
->inq
, len
, READ
);
417 /* Prepare the command. */
418 rq
->cmd
[0] = INQUIRY
;
420 rq
->cmd
[2] = page_code
;
422 rq
->cmd_len
= COMMAND_SIZE(INQUIRY
);
424 rq
->sense
= h
->sense
;
425 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
428 err
= blk_execute_rq(q
, NULL
, rq
, 1);
437 static int get_lun_info(struct scsi_device
*sdev
, struct rdac_dh_data
*h
,
438 char *array_name
, u8
*array_id
)
441 struct c8_inquiry
*inqp
;
443 err
= submit_inquiry(sdev
, 0xC8, sizeof(struct c8_inquiry
), h
);
444 if (err
== SCSI_DH_OK
) {
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
;
451 h
->lun
= inqp
->lun
[7]; /* Uses only the last byte */
453 for(i
=0; i
<ARRAY_LABEL_LEN
-1; ++i
)
454 *(array_name
+i
) = inqp
->array_user_label
[(2*i
)+1];
456 *(array_name
+ARRAY_LABEL_LEN
-1) = '\0';
457 memset(array_id
, 0, UNIQUE_ID_LEN
);
458 memcpy(array_id
, inqp
->array_unique_id
, inqp
->array_uniq_id_len
);
463 static int check_ownership(struct scsi_device
*sdev
, struct rdac_dh_data
*h
)
466 struct c9_inquiry
*inqp
;
468 h
->state
= RDAC_STATE_ACTIVE
;
469 err
= submit_inquiry(sdev
, 0xC9, sizeof(struct c9_inquiry
), h
);
470 if (err
== SCSI_DH_OK
) {
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 */
478 h
->mode
= RDAC_MODE
; /* LUN in RDAC mode */
480 /* Update ownership */
481 if (inqp
->avte_cvp
& 0x1)
482 h
->lun_state
= RDAC_LUN_OWNED
;
484 h
->lun_state
= RDAC_LUN_UNOWNED
;
485 if (h
->mode
== RDAC_MODE
)
486 h
->state
= RDAC_STATE_PASSIVE
;
489 /* Update path prio*/
490 if (inqp
->path_prio
& 0x1)
491 h
->preferred
= RDAC_PREFERRED
;
493 h
->preferred
= RDAC_NON_PREFERRED
;
499 static int initialize_controller(struct scsi_device
*sdev
,
500 struct rdac_dh_data
*h
, char *array_name
, u8
*array_id
)
503 struct c4_inquiry
*inqp
;
505 err
= submit_inquiry(sdev
, 0xC4, sizeof(struct c4_inquiry
), h
);
506 if (err
== SCSI_DH_OK
) {
508 /* get the controller index */
509 if (inqp
->slot_id
[1] == 0x31)
514 spin_lock(&list_lock
);
515 h
->ctlr
= get_controller(index
, array_name
, array_id
, sdev
);
517 err
= SCSI_DH_RES_TEMP_UNAVAIL
;
518 spin_unlock(&list_lock
);
523 static int set_mode_select(struct scsi_device
*sdev
, struct rdac_dh_data
*h
)
526 struct c2_inquiry
*inqp
;
528 err
= submit_inquiry(sdev
, 0xC2, sizeof(struct c2_inquiry
), h
);
529 if (err
== SCSI_DH_OK
) {
532 * If more than MODE6_MAX_LUN luns are supported, use
535 if (inqp
->max_lun_supported
>= MODE6_MAX_LUN
)
536 h
->ctlr
->use_ms10
= 1;
538 h
->ctlr
->use_ms10
= 0;
543 static int mode_select_handle_sense(struct scsi_device
*sdev
,
544 unsigned char *sensebuf
)
546 struct scsi_sense_hdr sense_hdr
;
547 int err
= SCSI_DH_IO
, ret
;
548 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
550 ret
= scsi_normalize_sense(sensebuf
, SCSI_SENSE_BUFFERSIZE
, &sense_hdr
);
554 switch (sense_hdr
.sense_key
) {
556 case ABORTED_COMMAND
:
561 if (sense_hdr
.asc
== 0x04 && sense_hdr
.ascq
== 0x01)
562 /* LUN Not Ready and is in the Process of Becoming
567 case ILLEGAL_REQUEST
:
568 if (sense_hdr
.asc
== 0x91 && sense_hdr
.ascq
== 0x36)
570 * Command Lock contention
572 err
= SCSI_DH_IMM_RETRY
;
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
);
587 static void send_mode_select(struct work_struct
*work
)
589 struct rdac_controller
*ctlr
=
590 container_of(work
, struct rdac_controller
, ms_work
);
592 struct scsi_device
*sdev
= ctlr
->ms_sdev
;
593 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
594 struct request_queue
*q
= sdev
->request_queue
;
595 int err
, retry_cnt
= RDAC_RETRY_COUNT
;
596 struct rdac_queue_data
*tmp
, *qdata
;
599 spin_lock(&ctlr
->ms_lock
);
600 list_splice_init(&ctlr
->ms_head
, &list
);
602 ctlr
->ms_sdev
= NULL
;
603 spin_unlock(&ctlr
->ms_lock
);
606 err
= SCSI_DH_RES_TEMP_UNAVAIL
;
607 rq
= rdac_failover_get(sdev
, h
, &list
);
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
,
614 (retry_cnt
== RDAC_RETRY_COUNT
) ? "queueing" : "retrying");
616 err
= blk_execute_rq(q
, NULL
, rq
, 1);
618 if (err
!= SCSI_DH_OK
) {
619 err
= mode_select_handle_sense(sdev
, h
->sense
);
620 if (err
== SCSI_DH_RETRY
&& retry_cnt
--)
622 if (err
== SCSI_DH_IMM_RETRY
)
625 if (err
== SCSI_DH_OK
) {
626 h
->state
= RDAC_STATE_ACTIVE
;
627 RDAC_LOG(RDAC_LOG_FAILOVER
, sdev
, "array %s, ctlr %d, "
628 "MODE_SELECT completed",
629 (char *) h
->ctlr
->array_name
, h
->ctlr
->index
);
633 list_for_each_entry_safe(qdata
, tmp
, &list
, entry
) {
634 list_del(&qdata
->entry
);
635 if (err
== SCSI_DH_OK
)
636 qdata
->h
->state
= RDAC_STATE_ACTIVE
;
637 if (qdata
->callback_fn
)
638 qdata
->callback_fn(qdata
->callback_data
, err
);
644 static int queue_mode_select(struct scsi_device
*sdev
,
645 activate_complete fn
, void *data
)
647 struct rdac_queue_data
*qdata
;
648 struct rdac_controller
*ctlr
;
650 qdata
= kzalloc(sizeof(*qdata
), GFP_KERNEL
);
652 return SCSI_DH_RETRY
;
654 qdata
->h
= get_rdac_data(sdev
);
655 qdata
->callback_fn
= fn
;
656 qdata
->callback_data
= data
;
658 ctlr
= qdata
->h
->ctlr
;
659 spin_lock(&ctlr
->ms_lock
);
660 list_add_tail(&qdata
->entry
, &ctlr
->ms_head
);
661 if (!ctlr
->ms_queued
) {
663 ctlr
->ms_sdev
= sdev
;
664 queue_work(kmpath_rdacd
, &ctlr
->ms_work
);
666 spin_unlock(&ctlr
->ms_lock
);
670 static int rdac_activate(struct scsi_device
*sdev
,
671 activate_complete fn
, void *data
)
673 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
674 int err
= SCSI_DH_OK
;
677 err
= check_ownership(sdev
, h
);
678 if (err
!= SCSI_DH_OK
)
683 if (h
->lun_state
== RDAC_LUN_UNOWNED
)
686 case RDAC_MODE_IOSHIP
:
687 if ((h
->lun_state
== RDAC_LUN_UNOWNED
) &&
688 (h
->preferred
== RDAC_PREFERRED
))
696 err
= queue_mode_select(sdev
, fn
, data
);
697 if (err
== SCSI_DH_OK
)
706 static int rdac_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
708 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
709 int ret
= BLKPREP_OK
;
711 if (h
->state
!= RDAC_STATE_ACTIVE
) {
713 req
->cmd_flags
|= REQ_QUIET
;
719 static int rdac_check_sense(struct scsi_device
*sdev
,
720 struct scsi_sense_hdr
*sense_hdr
)
722 struct rdac_dh_data
*h
= get_rdac_data(sdev
);
724 RDAC_LOG(RDAC_LOG_SENSE
, sdev
, "array %s, ctlr %d, "
725 "I/O returned with sense %02x/%02x/%02x",
726 (char *) h
->ctlr
->array_name
, h
->ctlr
->index
,
727 sense_hdr
->sense_key
, sense_hdr
->asc
, sense_hdr
->ascq
);
729 switch (sense_hdr
->sense_key
) {
731 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x01)
732 /* LUN Not Ready - Logical Unit Not Ready and is in
733 * the process of becoming ready
736 return ADD_TO_MLQUEUE
;
737 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x81)
738 /* LUN Not Ready - Storage firmware incompatible
739 * Manual code synchonisation required.
741 * Nothing we can do here. Try to bypass the path.
744 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0xA1)
745 /* LUN Not Ready - Quiescense in progress
747 * Just retry and wait.
749 return ADD_TO_MLQUEUE
;
750 if (sense_hdr
->asc
== 0xA1 && sense_hdr
->ascq
== 0x02)
751 /* LUN Not Ready - Quiescense in progress
752 * or has been achieved
755 return ADD_TO_MLQUEUE
;
757 case ILLEGAL_REQUEST
:
758 if (sense_hdr
->asc
== 0x94 && sense_hdr
->ascq
== 0x01) {
759 /* Invalid Request - Current Logical Unit Ownership.
760 * Controller is not the current owner of the LUN,
761 * Fail the path, so that the other path be used.
763 h
->state
= RDAC_STATE_PASSIVE
;
768 if (sense_hdr
->asc
== 0x29 && sense_hdr
->ascq
== 0x00)
770 * Power On, Reset, or Bus Device Reset, just retry.
772 return ADD_TO_MLQUEUE
;
773 if (sense_hdr
->asc
== 0x8b && sense_hdr
->ascq
== 0x02)
775 * Quiescence in progress , just retry.
777 return ADD_TO_MLQUEUE
;
780 /* success just means we do not care what scsi-ml does */
781 return SCSI_RETURN_NOT_HANDLED
;
784 static const struct scsi_dh_devlist rdac_dev_list
[] = {
797 {"STK", "OPENstorage D280"},
798 {"STK", "FLEXLINE 380"},
801 {"SUN", "STK6580_6780"},
803 {"SUN", "ArrayStorage"},
805 {"NETAPP", "INF-01-00"},
806 {"LSI", "INF-01-00"},
807 {"ENGENIO", "INF-01-00"},
811 static bool rdac_match(struct scsi_device
*sdev
)
815 if (scsi_device_tpgs(sdev
))
818 for (i
= 0; rdac_dev_list
[i
].vendor
; i
++) {
819 if (!strncmp(sdev
->vendor
, rdac_dev_list
[i
].vendor
,
820 strlen(rdac_dev_list
[i
].vendor
)) &&
821 !strncmp(sdev
->model
, rdac_dev_list
[i
].model
,
822 strlen(rdac_dev_list
[i
].model
))) {
829 static int rdac_bus_attach(struct scsi_device
*sdev
);
830 static void rdac_bus_detach(struct scsi_device
*sdev
);
832 static struct scsi_device_handler rdac_dh
= {
834 .module
= THIS_MODULE
,
835 .devlist
= rdac_dev_list
,
836 .prep_fn
= rdac_prep_fn
,
837 .check_sense
= rdac_check_sense
,
838 .attach
= rdac_bus_attach
,
839 .detach
= rdac_bus_detach
,
840 .activate
= rdac_activate
,
844 static int rdac_bus_attach(struct scsi_device
*sdev
)
846 struct scsi_dh_data
*scsi_dh_data
;
847 struct rdac_dh_data
*h
;
850 char array_name
[ARRAY_LABEL_LEN
];
851 char array_id
[UNIQUE_ID_LEN
];
853 scsi_dh_data
= kzalloc(sizeof(*scsi_dh_data
)
854 + sizeof(*h
) , GFP_KERNEL
);
856 sdev_printk(KERN_ERR
, sdev
, "%s: Attach failed\n",
861 scsi_dh_data
->scsi_dh
= &rdac_dh
;
862 h
= (struct rdac_dh_data
*) scsi_dh_data
->buf
;
863 h
->lun
= UNINITIALIZED_LUN
;
864 h
->state
= RDAC_STATE_ACTIVE
;
866 err
= get_lun_info(sdev
, h
, array_name
, array_id
);
867 if (err
!= SCSI_DH_OK
)
870 err
= initialize_controller(sdev
, h
, array_name
, array_id
);
871 if (err
!= SCSI_DH_OK
)
874 err
= check_ownership(sdev
, h
);
875 if (err
!= SCSI_DH_OK
)
878 err
= set_mode_select(sdev
, h
);
879 if (err
!= SCSI_DH_OK
)
882 if (!try_module_get(THIS_MODULE
))
885 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
886 sdev
->scsi_dh_data
= scsi_dh_data
;
887 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
889 sdev_printk(KERN_NOTICE
, sdev
,
890 "%s: LUN %d (%s) (%s)\n",
891 RDAC_NAME
, h
->lun
, mode
[(int)h
->mode
],
892 lun_state
[(int)h
->lun_state
]);
897 spin_lock(&list_lock
);
898 kref_put(&h
->ctlr
->kref
, release_controller
);
899 spin_unlock(&list_lock
);
903 sdev_printk(KERN_ERR
, sdev
, "%s: not attached\n",
908 static void rdac_bus_detach( struct scsi_device
*sdev
)
910 struct scsi_dh_data
*scsi_dh_data
;
911 struct rdac_dh_data
*h
;
914 scsi_dh_data
= sdev
->scsi_dh_data
;
915 h
= (struct rdac_dh_data
*) scsi_dh_data
->buf
;
916 if (h
->ctlr
&& h
->ctlr
->ms_queued
)
917 flush_workqueue(kmpath_rdacd
);
919 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
920 sdev
->scsi_dh_data
= NULL
;
921 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
923 spin_lock(&list_lock
);
925 kref_put(&h
->ctlr
->kref
, release_controller
);
926 spin_unlock(&list_lock
);
928 module_put(THIS_MODULE
);
929 sdev_printk(KERN_NOTICE
, sdev
, "%s: Detached\n", RDAC_NAME
);
934 static int __init
rdac_init(void)
938 r
= scsi_register_device_handler(&rdac_dh
);
940 printk(KERN_ERR
"Failed to register scsi device handler.");
945 * Create workqueue to handle mode selects for rdac
947 kmpath_rdacd
= create_singlethread_workqueue("kmpath_rdacd");
949 scsi_unregister_device_handler(&rdac_dh
);
950 printk(KERN_ERR
"kmpath_rdacd creation failed.\n");
958 static void __exit
rdac_exit(void)
960 destroy_workqueue(kmpath_rdacd
);
961 scsi_unregister_device_handler(&rdac_dh
);
964 module_init(rdac_init
);
965 module_exit(rdac_exit
);
967 MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
968 MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
969 MODULE_VERSION("01.00.0000.0000");
970 MODULE_LICENSE("GPL");