[SCSI] qla2xxx: Add DMI (Diagnostics Monitoring Interface) support.
[linux-2.6/libata-dev.git] / drivers / scsi / pluto.c
blob83a671799934465240952a5b1b4d5f8b455dd1e3
1 /* pluto.c: SparcSTORAGE Array SCSI host adapter driver.
3 * Copyright (C) 1997,1998,1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
7 #include <linux/kernel.h>
8 #include <linux/delay.h>
9 #include <linux/types.h>
10 #include <linux/string.h>
11 #include <linux/slab.h>
12 #include <linux/blkdev.h>
13 #include <linux/proc_fs.h>
14 #include <linux/stat.h>
15 #include <linux/init.h>
16 #include <linux/config.h>
17 #ifdef CONFIG_KMOD
18 #include <linux/kmod.h>
19 #endif
21 #include <asm/irq.h>
23 #include "scsi.h"
24 #include <scsi/scsi_host.h>
25 #include "../fc4/fcp_impl.h"
26 #include "pluto.h"
28 #include <linux/module.h>
30 #define RQ_SCSI_BUSY 0xffff
31 #define RQ_SCSI_DONE 0xfffe
33 /* #define PLUTO_DEBUG */
35 #define pluto_printk printk ("PLUTO %s: ", fc->name); printk
37 #ifdef PLUTO_DEBUG
38 #define PLD(x) pluto_printk x;
39 #define PLND(x) printk ("PLUTO: "); printk x;
40 #else
41 #define PLD(x)
42 #define PLND(x)
43 #endif
45 static struct ctrl_inquiry {
46 struct Scsi_Host host;
47 struct pluto pluto;
48 Scsi_Cmnd cmd;
49 char inquiry[256];
50 fc_channel *fc;
51 } *fcs __initdata;
52 static int fcscount __initdata = 0;
53 static atomic_t fcss __initdata = ATOMIC_INIT(0);
54 DECLARE_MUTEX_LOCKED(fc_sem);
56 static int pluto_encode_addr(Scsi_Cmnd *SCpnt, u16 *addr, fc_channel *fc, fcp_cmnd *fcmd);
58 static void __init pluto_detect_timeout(unsigned long data)
60 PLND(("Timeout\n"))
61 up(&fc_sem);
64 static void __init pluto_detect_done(Scsi_Cmnd *SCpnt)
66 /* Do nothing */
69 static void __init pluto_detect_scsi_done(Scsi_Cmnd *SCpnt)
71 SCpnt->request->rq_status = RQ_SCSI_DONE;
72 PLND(("Detect done %08lx\n", (long)SCpnt))
73 if (atomic_dec_and_test (&fcss))
74 up(&fc_sem);
77 int pluto_slave_configure(struct scsi_device *device)
79 int depth_to_use;
81 if (device->tagged_supported)
82 depth_to_use = /* 254 */ 8;
83 else
84 depth_to_use = 2;
86 scsi_adjust_queue_depth(device,
87 (device->tagged_supported ?
88 MSG_SIMPLE_TAG : 0),
89 depth_to_use);
91 return 0;
94 /* Detect all SSAs attached to the machine.
95 To be fast, do it on all online FC channels at the same time. */
96 int __init pluto_detect(struct scsi_host_template *tpnt)
98 int i, retry, nplutos;
99 fc_channel *fc;
100 struct scsi_device dev;
101 DEFINE_TIMER(fc_timer, pluto_detect_timeout, 0, 0);
103 tpnt->proc_name = "pluto";
104 fcscount = 0;
105 for_each_online_fc_channel(fc) {
106 if (!fc->posmap)
107 fcscount++;
109 PLND(("%d channels online\n", fcscount))
110 if (!fcscount) {
111 #if defined(MODULE) && defined(CONFIG_FC4_SOC_MODULE) && defined(CONFIG_KMOD)
112 request_module("soc");
114 for_each_online_fc_channel(fc) {
115 if (!fc->posmap)
116 fcscount++;
118 if (!fcscount)
119 #endif
120 return 0;
122 fcs = (struct ctrl_inquiry *) kmalloc (sizeof (struct ctrl_inquiry) * fcscount, GFP_DMA);
123 if (!fcs) {
124 printk ("PLUTO: Not enough memory to probe\n");
125 return 0;
128 memset (fcs, 0, sizeof (struct ctrl_inquiry) * fcscount);
129 memset (&dev, 0, sizeof(dev));
130 atomic_set (&fcss, fcscount);
132 i = 0;
133 for_each_online_fc_channel(fc) {
134 Scsi_Cmnd *SCpnt;
135 struct Scsi_Host *host;
136 struct pluto *pluto;
138 if (i == fcscount) break;
139 if (fc->posmap) continue;
141 PLD(("trying to find SSA\n"))
143 /* If this is already registered to some other SCSI host, then it cannot be pluto */
144 if (fc->scsi_name[0]) continue;
145 memcpy (fc->scsi_name, "SSA", 4);
147 fcs[i].fc = fc;
149 fc->can_queue = PLUTO_CAN_QUEUE;
150 fc->rsp_size = 64;
151 fc->encode_addr = pluto_encode_addr;
153 fc->fcp_register(fc, TYPE_SCSI_FCP, 0);
155 SCpnt = &(fcs[i].cmd);
156 host = &(fcs[i].host);
157 pluto = (struct pluto *)host->hostdata;
159 pluto->fc = fc;
161 SCpnt->cmnd[0] = INQUIRY;
162 SCpnt->cmnd[4] = 255;
164 /* FC layer requires this, so that SCpnt->device->tagged_supported is initially 0 */
165 SCpnt->device = &dev;
166 dev.host = host;
168 SCpnt->cmd_len = COMMAND_SIZE(INQUIRY);
170 SCpnt->request->rq_status = RQ_SCSI_BUSY;
172 SCpnt->done = pluto_detect_done;
173 SCpnt->bufflen = 256;
174 SCpnt->buffer = fcs[i].inquiry;
175 SCpnt->request_bufflen = 256;
176 SCpnt->request_buffer = fcs[i].inquiry;
177 PLD(("set up %d %08lx\n", i, (long)SCpnt))
178 i++;
181 for (retry = 0; retry < 5; retry++) {
182 for (i = 0; i < fcscount; i++) {
183 if (!fcs[i].fc) break;
184 if (fcs[i].cmd.request->rq_status != RQ_SCSI_DONE) {
185 disable_irq(fcs[i].fc->irq);
186 PLND(("queuecommand %d %d\n", retry, i))
187 fcp_scsi_queuecommand (&(fcs[i].cmd),
188 pluto_detect_scsi_done);
189 enable_irq(fcs[i].fc->irq);
193 fc_timer.expires = jiffies + 10 * HZ;
194 add_timer(&fc_timer);
196 down(&fc_sem);
197 PLND(("Woken up\n"))
198 if (!atomic_read(&fcss))
199 break; /* All fc channels have answered us */
201 del_timer_sync(&fc_timer);
203 PLND(("Finished search\n"))
204 for (i = 0, nplutos = 0; i < fcscount; i++) {
205 Scsi_Cmnd *SCpnt;
207 if (!(fc = fcs[i].fc)) break;
209 SCpnt = &(fcs[i].cmd);
211 /* Let FC mid-level free allocated resources */
212 SCpnt->done (SCpnt);
214 if (!SCpnt->result) {
215 struct pluto_inquiry *inq;
216 struct pluto *pluto;
217 struct Scsi_Host *host;
219 inq = (struct pluto_inquiry *)fcs[i].inquiry;
221 if ((inq->dtype & 0x1f) == TYPE_PROCESSOR &&
222 !strncmp (inq->vendor_id, "SUN", 3) &&
223 !strncmp (inq->product_id, "SSA", 3)) {
224 char *p;
225 long *ages;
227 ages = kmalloc (((inq->channels + 1) * inq->targets) * sizeof(long), GFP_KERNEL);
228 if (!ages) continue;
230 host = scsi_register (tpnt, sizeof (struct pluto));
231 if(!host)
233 kfree(ages);
234 continue;
237 if (!try_module_get(fc->module)) {
238 kfree(ages);
239 scsi_unregister(host);
240 continue;
243 nplutos++;
245 pluto = (struct pluto *)host->hostdata;
247 host->max_id = inq->targets;
248 host->max_channel = inq->channels;
249 host->irq = fc->irq;
251 fc->channels = inq->channels + 1;
252 fc->targets = inq->targets;
253 fc->ages = ages;
254 memset (ages, 0, ((inq->channels + 1) * inq->targets) * sizeof(long));
256 pluto->fc = fc;
257 memcpy (pluto->rev_str, inq->revision, 4);
258 pluto->rev_str[4] = 0;
259 p = strchr (pluto->rev_str, ' ');
260 if (p) *p = 0;
261 memcpy (pluto->fw_rev_str, inq->fw_revision, 4);
262 pluto->fw_rev_str[4] = 0;
263 p = strchr (pluto->fw_rev_str, ' ');
264 if (p) *p = 0;
265 memcpy (pluto->serial_str, inq->serial, 12);
266 pluto->serial_str[12] = 0;
267 p = strchr (pluto->serial_str, ' ');
268 if (p) *p = 0;
270 PLD(("Found SSA rev %s fw rev %s serial %s %dx%d\n", pluto->rev_str, pluto->fw_rev_str, pluto->serial_str, host->max_channel, host->max_id))
271 } else
272 fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
273 } else
274 fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
276 kfree((char *)fcs);
277 if (nplutos)
278 printk ("PLUTO: Total of %d SparcSTORAGE Arrays found\n", nplutos);
279 return nplutos;
282 int pluto_release(struct Scsi_Host *host)
284 struct pluto *pluto = (struct pluto *)host->hostdata;
285 fc_channel *fc = pluto->fc;
287 module_put(fc->module);
289 fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
290 PLND((" releasing pluto.\n"));
291 kfree (fc->ages);
292 PLND(("released pluto!\n"));
293 return 0;
296 const char *pluto_info(struct Scsi_Host *host)
298 static char buf[128], *p;
299 struct pluto *pluto = (struct pluto *) host->hostdata;
301 sprintf(buf, "SUN SparcSTORAGE Array %s fw %s serial %s %dx%d on %s",
302 pluto->rev_str, pluto->fw_rev_str, pluto->serial_str,
303 host->max_channel, host->max_id, pluto->fc->name);
304 #ifdef __sparc__
305 p = strchr(buf, 0);
306 sprintf(p, " PROM node %x", pluto->fc->dev->prom_node);
307 #endif
308 return buf;
311 /* SSA uses this FC4S addressing:
312 switch (addr[0])
314 case 0: CONTROLLER - All of addr[1]..addr[3] has to be 0
315 case 1: SINGLE DISK - addr[1] channel, addr[2] id, addr[3] 0
316 case 2: DISK GROUP - ???
319 So that SCSI mid-layer can access to these, we reserve
320 channel 0 id 0 lun 0 for CONTROLLER
321 and channels 1 .. max_channel are normal single disks.
323 static int pluto_encode_addr(Scsi_Cmnd *SCpnt, u16 *addr, fc_channel *fc, fcp_cmnd *fcmd)
325 PLND(("encode addr %d %d %d\n", SCpnt->device->channel, SCpnt->device->id, SCpnt->cmnd[1] & 0xe0))
326 /* We don't support LUNs - neither does SSA :) */
327 if (SCpnt->cmnd[1] & 0xe0)
328 return -EINVAL;
329 if (!SCpnt->device->channel) {
330 if (SCpnt->device->id)
331 return -EINVAL;
332 memset (addr, 0, 4 * sizeof(u16));
333 } else {
334 addr[0] = 1;
335 addr[1] = SCpnt->device->channel - 1;
336 addr[2] = SCpnt->device->id;
337 addr[3] = 0;
339 /* We're Point-to-Point, so target it to the default DID */
340 fcmd->did = fc->did;
341 PLND(("trying %04x%04x%04x%04x\n", addr[0], addr[1], addr[2], addr[3]))
342 return 0;
345 static struct scsi_host_template driver_template = {
346 .name = "Sparc Storage Array 100/200",
347 .detect = pluto_detect,
348 .release = pluto_release,
349 .info = pluto_info,
350 .queuecommand = fcp_scsi_queuecommand,
351 .slave_configure = pluto_slave_configure,
352 .can_queue = PLUTO_CAN_QUEUE,
353 .this_id = -1,
354 .sg_tablesize = 1,
355 .cmd_per_lun = 1,
356 .use_clustering = ENABLE_CLUSTERING,
357 .eh_abort_handler = fcp_scsi_abort,
358 .eh_device_reset_handler = fcp_scsi_dev_reset,
359 .eh_host_reset_handler = fcp_scsi_host_reset,
362 #include "scsi_module.c"
364 MODULE_LICENSE("GPL");