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
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)
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.
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.
23 #include <scsi/scsi.h>
24 #include <scsi/scsi_dbg.h>
25 #include <scsi/scsi_eh.h>
26 #include <scsi/scsi_dh.h>
28 #define HP_SW_NAME "hp_sw"
30 #define HP_SW_TIMEOUT (60 * HZ)
31 #define HP_SW_RETRIES 3
33 struct hp_sw_dh_data {
34 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
38 static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
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);
45 static int hp_sw_done(struct scsi_device *sdev)
47 struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
48 struct scsi_sense_hdr sshdr;
51 sdev_printk(KERN_INFO, sdev, "hp_sw_done\n");
53 rc = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, &sshdr);
56 switch (sshdr.sense_key) {
58 if ((sshdr.asc == 0x04) && (sshdr.ascq == 3)) {
66 rc = SCSI_DH_IMM_RETRY;
70 if (rc == SCSI_DH_OK || rc == SCSI_DH_IO)
72 else if (h->retries > HP_SW_RETRIES) {
79 static int hp_sw_activate(struct scsi_device *sdev)
81 struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
83 int ret = SCSI_DH_RES_TEMP_UNAVAIL;
85 req = blk_get_request(sdev->request_queue, WRITE, GFP_ATOMIC);
89 sdev_printk(KERN_INFO, sdev, "sending START_STOP.");
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);
102 ret = blk_execute_rq(req->q, NULL, req, 1);
103 if (!ret) /* SUCCESS */
104 ret = hp_sw_done(sdev);
111 static const struct {
114 } hp_sw_dh_data_list[] = {
121 static int hp_sw_bus_notify(struct notifier_block *, unsigned long, void *);
123 static struct scsi_device_handler hp_sw_dh = {
125 .module = THIS_MODULE,
126 .nb.notifier_call = hp_sw_bus_notify,
127 .activate = hp_sw_activate,
130 static int hp_sw_bus_notify(struct notifier_block *nb,
131 unsigned long action, void *data)
133 struct device *dev = data;
134 struct scsi_device *sdev;
135 struct scsi_dh_data *scsi_dh_data;
139 if (!scsi_is_sdev_device(dev))
142 sdev = to_scsi_device(dev);
144 if (action == BUS_NOTIFY_ADD_DEVICE) {
145 for (i = 0; hp_sw_dh_data_list[i].vendor; i++) {
146 if (!strncmp(sdev->vendor, hp_sw_dh_data_list[i].vendor,
147 strlen(hp_sw_dh_data_list[i].vendor)) &&
148 !strncmp(sdev->model, hp_sw_dh_data_list[i].model,
149 strlen(hp_sw_dh_data_list[i].model))) {
157 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *)
158 + sizeof(struct hp_sw_dh_data) , GFP_KERNEL);
160 sdev_printk(KERN_ERR, sdev, "Attach Failed %s.\n",
165 scsi_dh_data->scsi_dh = &hp_sw_dh;
166 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
167 sdev->scsi_dh_data = scsi_dh_data;
168 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
169 try_module_get(THIS_MODULE);
171 sdev_printk(KERN_NOTICE, sdev, "Attached %s.\n", HP_SW_NAME);
172 } else if (action == BUS_NOTIFY_DEL_DEVICE) {
173 if (sdev->scsi_dh_data == NULL ||
174 sdev->scsi_dh_data->scsi_dh != &hp_sw_dh)
177 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
178 scsi_dh_data = sdev->scsi_dh_data;
179 sdev->scsi_dh_data = NULL;
180 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
181 module_put(THIS_MODULE);
183 sdev_printk(KERN_NOTICE, sdev, "Dettached %s.\n", HP_SW_NAME);
192 static int __init hp_sw_init(void)
194 return scsi_register_device_handler(&hp_sw_dh);
197 static void __exit hp_sw_exit(void)
199 scsi_unregister_device_handler(&hp_sw_dh);
202 module_init(hp_sw_init);
203 module_exit(hp_sw_exit);
205 MODULE_DESCRIPTION("HP MSA 1000");
206 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu");
207 MODULE_LICENSE("GPL");