1 /* pluto.c: SparcSTORAGE Array SCSI host adapter driver.
3 * Copyright (C) 1997,1998,1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
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>
17 #include <linux/kmod.h>
23 #include <scsi/scsi_host.h>
24 #include "../fc4/fcp_impl.h"
27 #include <linux/module.h>
29 #define RQ_SCSI_BUSY 0xffff
30 #define RQ_SCSI_DONE 0xfffe
32 /* #define PLUTO_DEBUG */
34 #define pluto_printk printk ("PLUTO %s: ", fc->name); printk
37 #define PLD(x) pluto_printk x;
38 #define PLND(x) printk ("PLUTO: "); printk x;
44 static struct ctrl_inquiry {
45 struct Scsi_Host host;
51 static int fcscount __initdata = 0;
52 static atomic_t fcss __initdata = ATOMIC_INIT(0);
53 DECLARE_MUTEX_LOCKED(fc_sem);
55 static int pluto_encode_addr(Scsi_Cmnd *SCpnt, u16 *addr, fc_channel *fc, fcp_cmnd *fcmd);
57 static void __init pluto_detect_timeout(unsigned long data)
63 static void __init pluto_detect_done(Scsi_Cmnd *SCpnt)
68 static void __init pluto_detect_scsi_done(Scsi_Cmnd *SCpnt)
70 PLND(("Detect done %08lx\n", (long)SCpnt))
71 if (atomic_dec_and_test (&fcss))
75 int pluto_slave_configure(struct scsi_device *device)
79 if (device->tagged_supported)
80 depth_to_use = /* 254 */ 8;
84 scsi_adjust_queue_depth(device,
85 (device->tagged_supported ?
92 /* Detect all SSAs attached to the machine.
93 To be fast, do it on all online FC channels at the same time. */
94 int __init pluto_detect(struct scsi_host_template *tpnt)
96 int i, retry, nplutos;
98 struct scsi_device dev;
99 DEFINE_TIMER(fc_timer, pluto_detect_timeout, 0, 0);
101 tpnt->proc_name = "pluto";
103 for_each_online_fc_channel(fc) {
107 PLND(("%d channels online\n", fcscount))
109 #if defined(MODULE) && defined(CONFIG_FC4_SOC_MODULE) && defined(CONFIG_KMOD)
110 request_module("soc");
112 for_each_online_fc_channel(fc) {
120 fcs = (struct ctrl_inquiry *) kmalloc (sizeof (struct ctrl_inquiry) * fcscount, GFP_DMA);
122 printk ("PLUTO: Not enough memory to probe\n");
126 memset (fcs, 0, sizeof (struct ctrl_inquiry) * fcscount);
127 memset (&dev, 0, sizeof(dev));
128 atomic_set (&fcss, fcscount);
131 for_each_online_fc_channel(fc) {
133 struct Scsi_Host *host;
136 if (i == fcscount) break;
137 if (fc->posmap) continue;
139 PLD(("trying to find SSA\n"))
141 /* If this is already registered to some other SCSI host, then it cannot be pluto */
142 if (fc->scsi_name[0]) continue;
143 memcpy (fc->scsi_name, "SSA", 4);
147 fc->can_queue = PLUTO_CAN_QUEUE;
149 fc->encode_addr = pluto_encode_addr;
151 fc->fcp_register(fc, TYPE_SCSI_FCP, 0);
153 SCpnt = &(fcs[i].cmd);
154 host = &(fcs[i].host);
155 pluto = (struct pluto *)host->hostdata;
159 SCpnt->cmnd[0] = INQUIRY;
160 SCpnt->cmnd[4] = 255;
162 /* FC layer requires this, so that SCpnt->device->tagged_supported is initially 0 */
163 SCpnt->device = &dev;
166 SCpnt->cmd_len = COMMAND_SIZE(INQUIRY);
168 SCpnt->request->cmd_flags &= ~REQ_STARTED;
170 SCpnt->done = pluto_detect_done;
171 SCpnt->request_bufflen = 256;
172 SCpnt->request_buffer = fcs[i].inquiry;
173 PLD(("set up %d %08lx\n", i, (long)SCpnt))
177 for (retry = 0; retry < 5; retry++) {
178 for (i = 0; i < fcscount; i++) {
179 if (!fcs[i].fc) break;
180 if (!(fcs[i].cmd.request->cmd_flags & REQ_STARTED)) {
181 fcs[i].cmd.request->cmd_flags |= REQ_STARTED;
182 disable_irq(fcs[i].fc->irq);
183 PLND(("queuecommand %d %d\n", retry, i))
184 fcp_scsi_queuecommand (&(fcs[i].cmd),
185 pluto_detect_scsi_done);
186 enable_irq(fcs[i].fc->irq);
190 fc_timer.expires = jiffies + 10 * HZ;
191 add_timer(&fc_timer);
195 if (!atomic_read(&fcss))
196 break; /* All fc channels have answered us */
198 del_timer_sync(&fc_timer);
200 PLND(("Finished search\n"))
201 for (i = 0, nplutos = 0; i < fcscount; i++) {
204 if (!(fc = fcs[i].fc)) break;
206 SCpnt = &(fcs[i].cmd);
208 /* Let FC mid-level free allocated resources */
211 if (!SCpnt->result) {
212 struct pluto_inquiry *inq;
214 struct Scsi_Host *host;
216 inq = (struct pluto_inquiry *)fcs[i].inquiry;
218 if ((inq->dtype & 0x1f) == TYPE_PROCESSOR &&
219 !strncmp (inq->vendor_id, "SUN", 3) &&
220 !strncmp (inq->product_id, "SSA", 3)) {
224 ages = kmalloc (((inq->channels + 1) * inq->targets) * sizeof(long), GFP_KERNEL);
227 host = scsi_register (tpnt, sizeof (struct pluto));
234 if (!try_module_get(fc->module)) {
236 scsi_unregister(host);
242 pluto = (struct pluto *)host->hostdata;
244 host->max_id = inq->targets;
245 host->max_channel = inq->channels;
248 fc->channels = inq->channels + 1;
249 fc->targets = inq->targets;
251 memset (ages, 0, ((inq->channels + 1) * inq->targets) * sizeof(long));
254 memcpy (pluto->rev_str, inq->revision, 4);
255 pluto->rev_str[4] = 0;
256 p = strchr (pluto->rev_str, ' ');
258 memcpy (pluto->fw_rev_str, inq->fw_revision, 4);
259 pluto->fw_rev_str[4] = 0;
260 p = strchr (pluto->fw_rev_str, ' ');
262 memcpy (pluto->serial_str, inq->serial, 12);
263 pluto->serial_str[12] = 0;
264 p = strchr (pluto->serial_str, ' ');
267 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))
269 fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
271 fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
275 printk ("PLUTO: Total of %d SparcSTORAGE Arrays found\n", nplutos);
279 int pluto_release(struct Scsi_Host *host)
281 struct pluto *pluto = (struct pluto *)host->hostdata;
282 fc_channel *fc = pluto->fc;
284 module_put(fc->module);
286 fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
287 PLND((" releasing pluto.\n"));
289 PLND(("released pluto!\n"));
293 const char *pluto_info(struct Scsi_Host *host)
295 static char buf[128], *p;
296 struct pluto *pluto = (struct pluto *) host->hostdata;
298 sprintf(buf, "SUN SparcSTORAGE Array %s fw %s serial %s %dx%d on %s",
299 pluto->rev_str, pluto->fw_rev_str, pluto->serial_str,
300 host->max_channel, host->max_id, pluto->fc->name);
303 sprintf(p, " PROM node %x", pluto->fc->dev->prom_node);
308 /* SSA uses this FC4S addressing:
311 case 0: CONTROLLER - All of addr[1]..addr[3] has to be 0
312 case 1: SINGLE DISK - addr[1] channel, addr[2] id, addr[3] 0
313 case 2: DISK GROUP - ???
316 So that SCSI mid-layer can access to these, we reserve
317 channel 0 id 0 lun 0 for CONTROLLER
318 and channels 1 .. max_channel are normal single disks.
320 static int pluto_encode_addr(Scsi_Cmnd *SCpnt, u16 *addr, fc_channel *fc, fcp_cmnd *fcmd)
322 PLND(("encode addr %d %d %d\n", SCpnt->device->channel, SCpnt->device->id, SCpnt->cmnd[1] & 0xe0))
323 /* We don't support LUNs - neither does SSA :) */
324 if (SCpnt->cmnd[1] & 0xe0)
326 if (!SCpnt->device->channel) {
327 if (SCpnt->device->id)
329 memset (addr, 0, 4 * sizeof(u16));
332 addr[1] = SCpnt->device->channel - 1;
333 addr[2] = SCpnt->device->id;
336 /* We're Point-to-Point, so target it to the default DID */
338 PLND(("trying %04x%04x%04x%04x\n", addr[0], addr[1], addr[2], addr[3]))
342 static struct scsi_host_template driver_template = {
343 .name = "Sparc Storage Array 100/200",
344 .detect = pluto_detect,
345 .release = pluto_release,
347 .queuecommand = fcp_scsi_queuecommand,
348 .slave_configure = pluto_slave_configure,
349 .can_queue = PLUTO_CAN_QUEUE,
353 .use_clustering = ENABLE_CLUSTERING,
354 .eh_abort_handler = fcp_scsi_abort,
355 .eh_device_reset_handler = fcp_scsi_dev_reset,
356 .eh_host_reset_handler = fcp_scsi_host_reset,
359 #include "scsi_module.c"
361 MODULE_LICENSE("GPL");