blob: 78259bc5dfc9e1153f703a61a2f6c3b1312fa39e [file] [log] [blame]
Mike Christief6dd3372008-05-01 14:49:59 -07001/*
2 * Basic HP/COMPAQ MSA 1000 support. This is only needed if your HW cannot be
3 * upgraded.
4 *
5 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
6 * Copyright (C) 2006 Mike Christie
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <scsi/scsi.h>
24#include <scsi/scsi_dbg.h>
25#include <scsi/scsi_eh.h>
26#include <scsi/scsi_dh.h>
27
28#define HP_SW_NAME "hp_sw"
29
30#define HP_SW_TIMEOUT (60 * HZ)
31#define HP_SW_RETRIES 3
32
33struct hp_sw_dh_data {
34 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
35 int retries;
36};
37
38static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
39{
40 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data;
41 BUG_ON(scsi_dh_data == NULL);
42 return ((struct hp_sw_dh_data *) scsi_dh_data->buf);
43}
44
45static int hp_sw_done(struct scsi_device *sdev)
46{
47 struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
48 struct scsi_sense_hdr sshdr;
49 int rc;
50
51 sdev_printk(KERN_INFO, sdev, "hp_sw_done\n");
52
53 rc = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, &sshdr);
54 if (!rc)
55 goto done;
56 switch (sshdr.sense_key) {
57 case NOT_READY:
58 if ((sshdr.asc == 0x04) && (sshdr.ascq == 3)) {
59 rc = SCSI_DH_RETRY;
60 h->retries++;
61 break;
62 }
63 /* fall through */
64 default:
65 h->retries++;
66 rc = SCSI_DH_IMM_RETRY;
67 }
68
69done:
70 if (rc == SCSI_DH_OK || rc == SCSI_DH_IO)
71 h->retries = 0;
72 else if (h->retries > HP_SW_RETRIES) {
73 h->retries = 0;
74 rc = SCSI_DH_IO;
75 }
76 return rc;
77}
78
79static int hp_sw_activate(struct scsi_device *sdev)
80{
81 struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
82 struct request *req;
83 int ret = SCSI_DH_RES_TEMP_UNAVAIL;
84
85 req = blk_get_request(sdev->request_queue, WRITE, GFP_ATOMIC);
86 if (!req)
87 goto done;
88
89 sdev_printk(KERN_INFO, sdev, "sending START_STOP.");
90
91 req->cmd_type = REQ_TYPE_BLOCK_PC;
92 req->cmd_flags |= REQ_FAILFAST;
93 req->cmd_len = COMMAND_SIZE(START_STOP);
94 memset(req->cmd, 0, MAX_COMMAND_SIZE);
95 req->cmd[0] = START_STOP;
96 req->cmd[4] = 1; /* Start spin cycle */
97 req->timeout = HP_SW_TIMEOUT;
98 req->sense = h->sense;
99 memset(req->sense, 0, SCSI_SENSE_BUFFERSIZE);
100 req->sense_len = 0;
101
102 ret = blk_execute_rq(req->q, NULL, req, 1);
103 if (!ret) /* SUCCESS */
104 ret = hp_sw_done(sdev);
105 else
106 ret = SCSI_DH_IO;
107done:
108 return ret;
109}
110
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700111const struct scsi_dh_devlist hp_sw_dh_data_list[] = {
Mike Christief6dd3372008-05-01 14:49:59 -0700112 {"COMPAQ", "MSA"},
113 {"HP", "HSV"},
114 {"DEC", "HSG80"},
115 {NULL, NULL},
116};
117
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700118static int hp_sw_bus_attach(struct scsi_device *sdev);
119static void hp_sw_bus_detach(struct scsi_device *sdev);
Mike Christief6dd3372008-05-01 14:49:59 -0700120
121static struct scsi_device_handler hp_sw_dh = {
122 .name = HP_SW_NAME,
123 .module = THIS_MODULE,
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700124 .devlist = hp_sw_dh_data_list,
125 .attach = hp_sw_bus_attach,
126 .detach = hp_sw_bus_detach,
Mike Christief6dd3372008-05-01 14:49:59 -0700127 .activate = hp_sw_activate,
128};
129
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700130static int hp_sw_bus_attach(struct scsi_device *sdev)
Mike Christief6dd3372008-05-01 14:49:59 -0700131{
Mike Christief6dd3372008-05-01 14:49:59 -0700132 struct scsi_dh_data *scsi_dh_data;
Mike Christief6dd3372008-05-01 14:49:59 -0700133 unsigned long flags;
134
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700135 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *)
136 + sizeof(struct hp_sw_dh_data) , GFP_KERNEL);
137 if (!scsi_dh_data) {
138 sdev_printk(KERN_ERR, sdev, "Attach Failed %s.\n",
139 HP_SW_NAME);
Chandra Seetharaman33af79d2008-07-16 17:35:08 -0700140 return 0;
Mike Christief6dd3372008-05-01 14:49:59 -0700141 }
142
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700143 scsi_dh_data->scsi_dh = &hp_sw_dh;
144 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
145 sdev->scsi_dh_data = scsi_dh_data;
146 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
147 try_module_get(THIS_MODULE);
148
149 sdev_printk(KERN_NOTICE, sdev, "Attached %s.\n", HP_SW_NAME);
150
Mike Christief6dd3372008-05-01 14:49:59 -0700151 return 0;
152}
153
Hannes Reinecke765cbc62008-07-17 16:52:51 -0700154static void hp_sw_bus_detach( struct scsi_device *sdev )
155{
156 struct scsi_dh_data *scsi_dh_data;
157 unsigned long flags;
158
159 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
160 scsi_dh_data = sdev->scsi_dh_data;
161 sdev->scsi_dh_data = NULL;
162 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
163 module_put(THIS_MODULE);
164
165 sdev_printk(KERN_NOTICE, sdev, "Detached %s\n", HP_SW_NAME);
166
167 kfree(scsi_dh_data);
168}
169
Mike Christief6dd3372008-05-01 14:49:59 -0700170static int __init hp_sw_init(void)
171{
172 return scsi_register_device_handler(&hp_sw_dh);
173}
174
175static void __exit hp_sw_exit(void)
176{
177 scsi_unregister_device_handler(&hp_sw_dh);
178}
179
180module_init(hp_sw_init);
181module_exit(hp_sw_exit);
182
183MODULE_DESCRIPTION("HP MSA 1000");
184MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu");
185MODULE_LICENSE("GPL");