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 <linux/module.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_dbg.h>
28 #include <scsi/scsi_eh.h>
29 #include <scsi/scsi_dh.h>
31 #define HP_SW_NAME "hp_sw"
33 #define HP_SW_TIMEOUT (60 * HZ)
34 #define HP_SW_RETRIES 3
36 #define HP_SW_PATH_UNINITIALIZED -1
37 #define HP_SW_PATH_ACTIVE 0
38 #define HP_SW_PATH_PASSIVE 1
40 struct hp_sw_dh_data
{
41 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
45 struct scsi_device
*sdev
;
46 activate_complete callback_fn
;
50 static int hp_sw_start_stop(struct hp_sw_dh_data
*);
53 * tur_done - Handle TEST UNIT READY return status
54 * @sdev: sdev the command has been sent to
55 * @errors: blk error code
57 * Returns SCSI_DH_DEV_OFFLINED if the sdev is on the passive path
59 static int tur_done(struct scsi_device
*sdev
, unsigned char *sense
)
61 struct scsi_sense_hdr sshdr
;
64 ret
= scsi_normalize_sense(sense
, SCSI_SENSE_BUFFERSIZE
, &sshdr
);
66 sdev_printk(KERN_WARNING
, sdev
,
67 "%s: sending tur failed, no sense available\n",
72 switch (sshdr
.sense_key
) {
74 ret
= SCSI_DH_IMM_RETRY
;
77 if ((sshdr
.asc
== 0x04) && (sshdr
.ascq
== 2)) {
79 * LUN not ready - Initialization command required
81 * This is the passive path
83 ret
= SCSI_DH_DEV_OFFLINED
;
88 sdev_printk(KERN_WARNING
, sdev
,
89 "%s: sending tur failed, sense %x/%x/%x\n",
90 HP_SW_NAME
, sshdr
.sense_key
, sshdr
.asc
,
100 * hp_sw_tur - Send TEST UNIT READY
101 * @sdev: sdev command should be sent to
103 * Use the TEST UNIT READY command to determine
106 static int hp_sw_tur(struct scsi_device
*sdev
, struct hp_sw_dh_data
*h
)
112 req
= blk_get_request(sdev
->request_queue
, WRITE
, GFP_NOIO
);
114 return SCSI_DH_RES_TEMP_UNAVAIL
;
116 blk_rq_set_block_pc(req
);
117 req
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
119 req
->cmd_len
= COMMAND_SIZE(TEST_UNIT_READY
);
120 req
->cmd
[0] = TEST_UNIT_READY
;
121 req
->timeout
= HP_SW_TIMEOUT
;
122 req
->sense
= h
->sense
;
123 memset(req
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
126 ret
= blk_execute_rq(req
->q
, NULL
, req
, 1);
128 if (req
->sense_len
> 0) {
129 ret
= tur_done(sdev
, h
->sense
);
131 sdev_printk(KERN_WARNING
, sdev
,
132 "%s: sending tur failed with %x\n",
133 HP_SW_NAME
, req
->errors
);
137 h
->path_state
= HP_SW_PATH_ACTIVE
;
140 if (ret
== SCSI_DH_IMM_RETRY
) {
141 blk_put_request(req
);
144 if (ret
== SCSI_DH_DEV_OFFLINED
) {
145 h
->path_state
= HP_SW_PATH_PASSIVE
;
149 blk_put_request(req
);
155 * start_done - Handle START STOP UNIT return status
156 * @sdev: sdev the command has been sent to
157 * @errors: blk error code
159 static int start_done(struct scsi_device
*sdev
, unsigned char *sense
)
161 struct scsi_sense_hdr sshdr
;
164 rc
= scsi_normalize_sense(sense
, SCSI_SENSE_BUFFERSIZE
, &sshdr
);
166 sdev_printk(KERN_WARNING
, sdev
,
167 "%s: sending start_stop_unit failed, "
168 "no sense available\n",
172 switch (sshdr
.sense_key
) {
174 if ((sshdr
.asc
== 0x04) && (sshdr
.ascq
== 3)) {
176 * LUN not ready - manual intervention required
178 * Switch-over in progress, retry.
185 sdev_printk(KERN_WARNING
, sdev
,
186 "%s: sending start_stop_unit failed, sense %x/%x/%x\n",
187 HP_SW_NAME
, sshdr
.sense_key
, sshdr
.asc
,
195 static void start_stop_endio(struct request
*req
, int error
)
197 struct hp_sw_dh_data
*h
= req
->end_io_data
;
198 unsigned err
= SCSI_DH_OK
;
200 if (error
|| host_byte(req
->errors
) != DID_OK
||
201 msg_byte(req
->errors
) != COMMAND_COMPLETE
) {
202 sdev_printk(KERN_WARNING
, h
->sdev
,
203 "%s: sending start_stop_unit failed with %x\n",
204 HP_SW_NAME
, req
->errors
);
209 if (req
->sense_len
> 0) {
210 err
= start_done(h
->sdev
, h
->sense
);
211 if (err
== SCSI_DH_RETRY
) {
213 if (--h
->retry_cnt
) {
214 blk_put_request(req
);
215 err
= hp_sw_start_stop(h
);
216 if (err
== SCSI_DH_OK
)
222 req
->end_io_data
= NULL
;
223 __blk_put_request(req
->q
, req
);
224 if (h
->callback_fn
) {
225 h
->callback_fn(h
->callback_data
, err
);
226 h
->callback_fn
= h
->callback_data
= NULL
;
233 * hp_sw_start_stop - Send START STOP UNIT command
234 * @sdev: sdev command should be sent to
236 * Sending START STOP UNIT activates the SP.
238 static int hp_sw_start_stop(struct hp_sw_dh_data
*h
)
242 req
= blk_get_request(h
->sdev
->request_queue
, WRITE
, GFP_ATOMIC
);
244 return SCSI_DH_RES_TEMP_UNAVAIL
;
246 blk_rq_set_block_pc(req
);
247 req
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
249 req
->cmd_len
= COMMAND_SIZE(START_STOP
);
250 req
->cmd
[0] = START_STOP
;
251 req
->cmd
[4] = 1; /* Start spin cycle */
252 req
->timeout
= HP_SW_TIMEOUT
;
253 req
->sense
= h
->sense
;
254 memset(req
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
256 req
->end_io_data
= h
;
258 blk_execute_rq_nowait(req
->q
, NULL
, req
, 1, start_stop_endio
);
262 static int hp_sw_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
264 struct hp_sw_dh_data
*h
= sdev
->handler_data
;
265 int ret
= BLKPREP_OK
;
267 if (h
->path_state
!= HP_SW_PATH_ACTIVE
) {
269 req
->cmd_flags
|= REQ_QUIET
;
276 * hp_sw_activate - Activate a path
277 * @sdev: sdev on the path to be activated
279 * The HP Active/Passive firmware is pretty simple;
280 * the passive path reports NOT READY with sense codes
281 * 0x04/0x02; a START STOP UNIT command will then
282 * activate the passive path (and deactivate the
283 * previously active one).
285 static int hp_sw_activate(struct scsi_device
*sdev
,
286 activate_complete fn
, void *data
)
288 int ret
= SCSI_DH_OK
;
289 struct hp_sw_dh_data
*h
= sdev
->handler_data
;
291 ret
= hp_sw_tur(sdev
, h
);
293 if (ret
== SCSI_DH_OK
&& h
->path_state
== HP_SW_PATH_PASSIVE
) {
294 h
->retry_cnt
= h
->retries
;
296 h
->callback_data
= data
;
297 ret
= hp_sw_start_stop(h
);
298 if (ret
== SCSI_DH_OK
)
300 h
->callback_fn
= h
->callback_data
= NULL
;
308 static int hp_sw_bus_attach(struct scsi_device
*sdev
)
310 struct hp_sw_dh_data
*h
;
313 h
= kzalloc(sizeof(*h
), GFP_KERNEL
);
316 h
->path_state
= HP_SW_PATH_UNINITIALIZED
;
317 h
->retries
= HP_SW_RETRIES
;
320 ret
= hp_sw_tur(sdev
, h
);
321 if (ret
!= SCSI_DH_OK
|| h
->path_state
== HP_SW_PATH_UNINITIALIZED
)
324 sdev_printk(KERN_INFO
, sdev
, "%s: attached to %s path\n",
325 HP_SW_NAME
, h
->path_state
== HP_SW_PATH_ACTIVE
?
328 sdev
->handler_data
= h
;
335 static void hp_sw_bus_detach( struct scsi_device
*sdev
)
337 kfree(sdev
->handler_data
);
338 sdev
->handler_data
= NULL
;
341 static struct scsi_device_handler hp_sw_dh
= {
343 .module
= THIS_MODULE
,
344 .attach
= hp_sw_bus_attach
,
345 .detach
= hp_sw_bus_detach
,
346 .activate
= hp_sw_activate
,
347 .prep_fn
= hp_sw_prep_fn
,
350 static int __init
hp_sw_init(void)
352 return scsi_register_device_handler(&hp_sw_dh
);
355 static void __exit
hp_sw_exit(void)
357 scsi_unregister_device_handler(&hp_sw_dh
);
360 module_init(hp_sw_init
);
361 module_exit(hp_sw_exit
);
363 MODULE_DESCRIPTION("HP Active/Passive driver");
364 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu");
365 MODULE_LICENSE("GPL");