2 * Basic HP/COMPAQ MSA 1000 support. This is only needed if your HW cannot be
5 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
6 * Copyright (C) 2006 Mike Christie
7 * Copyright (C) 2008 Hannes Reinecke <hare@suse.de>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, write to
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/slab.h>
25 #include <scsi/scsi.h>
26 #include <scsi/scsi_dbg.h>
27 #include <scsi/scsi_eh.h>
28 #include <scsi/scsi_dh.h>
30 #define HP_SW_NAME "hp_sw"
32 #define HP_SW_TIMEOUT (60 * HZ)
33 #define HP_SW_RETRIES 3
35 #define HP_SW_PATH_UNINITIALIZED -1
36 #define HP_SW_PATH_ACTIVE 0
37 #define HP_SW_PATH_PASSIVE 1
39 struct hp_sw_dh_data
{
40 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
44 struct scsi_device
*sdev
;
45 activate_complete callback_fn
;
49 static int hp_sw_start_stop(struct hp_sw_dh_data
*);
51 static inline struct hp_sw_dh_data
*get_hp_sw_data(struct scsi_device
*sdev
)
53 struct scsi_dh_data
*scsi_dh_data
= sdev
->scsi_dh_data
;
54 BUG_ON(scsi_dh_data
== NULL
);
55 return ((struct hp_sw_dh_data
*) scsi_dh_data
->buf
);
59 * tur_done - Handle TEST UNIT READY return status
60 * @sdev: sdev the command has been sent to
61 * @errors: blk error code
63 * Returns SCSI_DH_DEV_OFFLINED if the sdev is on the passive path
65 static int tur_done(struct scsi_device
*sdev
, unsigned char *sense
)
67 struct scsi_sense_hdr sshdr
;
70 ret
= scsi_normalize_sense(sense
, SCSI_SENSE_BUFFERSIZE
, &sshdr
);
72 sdev_printk(KERN_WARNING
, sdev
,
73 "%s: sending tur failed, no sense available\n",
78 switch (sshdr
.sense_key
) {
80 ret
= SCSI_DH_IMM_RETRY
;
83 if ((sshdr
.asc
== 0x04) && (sshdr
.ascq
== 2)) {
85 * LUN not ready - Initialization command required
87 * This is the passive path
89 ret
= SCSI_DH_DEV_OFFLINED
;
94 sdev_printk(KERN_WARNING
, sdev
,
95 "%s: sending tur failed, sense %x/%x/%x\n",
96 HP_SW_NAME
, sshdr
.sense_key
, sshdr
.asc
,
106 * hp_sw_tur - Send TEST UNIT READY
107 * @sdev: sdev command should be sent to
109 * Use the TEST UNIT READY command to determine
112 static int hp_sw_tur(struct scsi_device
*sdev
, struct hp_sw_dh_data
*h
)
118 req
= blk_get_request(sdev
->request_queue
, WRITE
, GFP_NOIO
);
120 return SCSI_DH_RES_TEMP_UNAVAIL
;
122 req
->cmd_type
= REQ_TYPE_BLOCK_PC
;
123 req
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
125 req
->cmd_len
= COMMAND_SIZE(TEST_UNIT_READY
);
126 req
->cmd
[0] = TEST_UNIT_READY
;
127 req
->timeout
= HP_SW_TIMEOUT
;
128 req
->sense
= h
->sense
;
129 memset(req
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
132 ret
= blk_execute_rq(req
->q
, NULL
, req
, 1);
134 if (req
->sense_len
> 0) {
135 ret
= tur_done(sdev
, h
->sense
);
137 sdev_printk(KERN_WARNING
, sdev
,
138 "%s: sending tur failed with %x\n",
139 HP_SW_NAME
, req
->errors
);
143 h
->path_state
= HP_SW_PATH_ACTIVE
;
146 if (ret
== SCSI_DH_IMM_RETRY
) {
147 blk_put_request(req
);
150 if (ret
== SCSI_DH_DEV_OFFLINED
) {
151 h
->path_state
= HP_SW_PATH_PASSIVE
;
155 blk_put_request(req
);
161 * start_done - Handle START STOP UNIT return status
162 * @sdev: sdev the command has been sent to
163 * @errors: blk error code
165 static int start_done(struct scsi_device
*sdev
, unsigned char *sense
)
167 struct scsi_sense_hdr sshdr
;
170 rc
= scsi_normalize_sense(sense
, SCSI_SENSE_BUFFERSIZE
, &sshdr
);
172 sdev_printk(KERN_WARNING
, sdev
,
173 "%s: sending start_stop_unit failed, "
174 "no sense available\n",
178 switch (sshdr
.sense_key
) {
180 if ((sshdr
.asc
== 0x04) && (sshdr
.ascq
== 3)) {
182 * LUN not ready - manual intervention required
184 * Switch-over in progress, retry.
191 sdev_printk(KERN_WARNING
, sdev
,
192 "%s: sending start_stop_unit failed, sense %x/%x/%x\n",
193 HP_SW_NAME
, sshdr
.sense_key
, sshdr
.asc
,
201 static void start_stop_endio(struct request
*req
, int error
)
203 struct hp_sw_dh_data
*h
= req
->end_io_data
;
204 unsigned err
= SCSI_DH_OK
;
206 if (error
|| host_byte(req
->errors
) != DID_OK
||
207 msg_byte(req
->errors
) != COMMAND_COMPLETE
) {
208 sdev_printk(KERN_WARNING
, h
->sdev
,
209 "%s: sending start_stop_unit failed with %x\n",
210 HP_SW_NAME
, req
->errors
);
215 if (req
->sense_len
> 0) {
216 err
= start_done(h
->sdev
, h
->sense
);
217 if (err
== SCSI_DH_RETRY
) {
219 if (--h
->retry_cnt
) {
220 blk_put_request(req
);
221 err
= hp_sw_start_stop(h
);
222 if (err
== SCSI_DH_OK
)
228 req
->end_io_data
= NULL
;
229 __blk_put_request(req
->q
, req
);
230 if (h
->callback_fn
) {
231 h
->callback_fn(h
->callback_data
, err
);
232 h
->callback_fn
= h
->callback_data
= NULL
;
239 * hp_sw_start_stop - Send START STOP UNIT command
240 * @sdev: sdev command should be sent to
242 * Sending START STOP UNIT activates the SP.
244 static int hp_sw_start_stop(struct hp_sw_dh_data
*h
)
248 req
= blk_get_request(h
->sdev
->request_queue
, WRITE
, GFP_ATOMIC
);
250 return SCSI_DH_RES_TEMP_UNAVAIL
;
252 req
->cmd_type
= REQ_TYPE_BLOCK_PC
;
253 req
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
255 req
->cmd_len
= COMMAND_SIZE(START_STOP
);
256 req
->cmd
[0] = START_STOP
;
257 req
->cmd
[4] = 1; /* Start spin cycle */
258 req
->timeout
= HP_SW_TIMEOUT
;
259 req
->sense
= h
->sense
;
260 memset(req
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
262 req
->end_io_data
= h
;
264 blk_execute_rq_nowait(req
->q
, NULL
, req
, 1, start_stop_endio
);
268 static int hp_sw_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
270 struct hp_sw_dh_data
*h
= get_hp_sw_data(sdev
);
271 int ret
= BLKPREP_OK
;
273 if (h
->path_state
!= HP_SW_PATH_ACTIVE
) {
275 req
->cmd_flags
|= REQ_QUIET
;
282 * hp_sw_activate - Activate a path
283 * @sdev: sdev on the path to be activated
285 * The HP Active/Passive firmware is pretty simple;
286 * the passive path reports NOT READY with sense codes
287 * 0x04/0x02; a START STOP UNIT command will then
288 * activate the passive path (and deactivate the
289 * previously active one).
291 static int hp_sw_activate(struct scsi_device
*sdev
,
292 activate_complete fn
, void *data
)
294 int ret
= SCSI_DH_OK
;
295 struct hp_sw_dh_data
*h
= get_hp_sw_data(sdev
);
297 ret
= hp_sw_tur(sdev
, h
);
299 if (ret
== SCSI_DH_OK
&& h
->path_state
== HP_SW_PATH_PASSIVE
) {
300 h
->retry_cnt
= h
->retries
;
302 h
->callback_data
= data
;
303 ret
= hp_sw_start_stop(h
);
304 if (ret
== SCSI_DH_OK
)
306 h
->callback_fn
= h
->callback_data
= NULL
;
314 static const struct scsi_dh_devlist hp_sw_dh_data_list
[] = {
315 {"COMPAQ", "MSA1000 VOLUME"},
316 {"COMPAQ", "HSV110"},
322 static int hp_sw_bus_attach(struct scsi_device
*sdev
);
323 static void hp_sw_bus_detach(struct scsi_device
*sdev
);
325 static struct scsi_device_handler hp_sw_dh
= {
327 .module
= THIS_MODULE
,
328 .devlist
= hp_sw_dh_data_list
,
329 .attach
= hp_sw_bus_attach
,
330 .detach
= hp_sw_bus_detach
,
331 .activate
= hp_sw_activate
,
332 .prep_fn
= hp_sw_prep_fn
,
335 static int hp_sw_bus_attach(struct scsi_device
*sdev
)
337 struct scsi_dh_data
*scsi_dh_data
;
338 struct hp_sw_dh_data
*h
;
342 scsi_dh_data
= kzalloc(sizeof(*scsi_dh_data
)
343 + sizeof(*h
) , GFP_KERNEL
);
345 sdev_printk(KERN_ERR
, sdev
, "%s: Attach Failed\n",
350 scsi_dh_data
->scsi_dh
= &hp_sw_dh
;
351 h
= (struct hp_sw_dh_data
*) scsi_dh_data
->buf
;
352 h
->path_state
= HP_SW_PATH_UNINITIALIZED
;
353 h
->retries
= HP_SW_RETRIES
;
356 ret
= hp_sw_tur(sdev
, h
);
357 if (ret
!= SCSI_DH_OK
|| h
->path_state
== HP_SW_PATH_UNINITIALIZED
)
360 if (!try_module_get(THIS_MODULE
))
363 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
364 sdev
->scsi_dh_data
= scsi_dh_data
;
365 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
367 sdev_printk(KERN_INFO
, sdev
, "%s: attached to %s path\n",
368 HP_SW_NAME
, h
->path_state
== HP_SW_PATH_ACTIVE
?
375 sdev_printk(KERN_ERR
, sdev
, "%s: not attached\n",
380 static void hp_sw_bus_detach( struct scsi_device
*sdev
)
382 struct scsi_dh_data
*scsi_dh_data
;
385 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
386 scsi_dh_data
= sdev
->scsi_dh_data
;
387 sdev
->scsi_dh_data
= NULL
;
388 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
389 module_put(THIS_MODULE
);
391 sdev_printk(KERN_NOTICE
, sdev
, "%s: Detached\n", HP_SW_NAME
);
396 static int __init
hp_sw_init(void)
398 return scsi_register_device_handler(&hp_sw_dh
);
401 static void __exit
hp_sw_exit(void)
403 scsi_unregister_device_handler(&hp_sw_dh
);
406 module_init(hp_sw_init
);
407 module_exit(hp_sw_exit
);
409 MODULE_DESCRIPTION("HP Active/Passive driver");
410 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu");
411 MODULE_LICENSE("GPL");