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/completion.h>
8 #include <linux/kernel.h>
9 #include <linux/delay.h>
10 #include <linux/types.h>
11 #include <linux/string.h>
12 #include <linux/slab.h>
13 #include <linux/blkdev.h>
14 #include <linux/proc_fs.h>
15 #include <linux/stat.h>
16 #include <linux/init.h>
18 #include <linux/kmod.h>
24 #include <scsi/scsi_host.h>
25 #include "../fc4/fcp_impl.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
38 #define PLD(x) pluto_printk x;
39 #define PLND(x) printk ("PLUTO: "); printk x;
45 static struct ctrl_inquiry
{
46 struct Scsi_Host host
;
52 static int fcscount __initdata
= 0;
53 static atomic_t fcss __initdata
= ATOMIC_INIT(0);
54 static DECLARE_COMPLETION(fc_detect_complete
);
56 static int pluto_encode_addr(Scsi_Cmnd
*SCpnt
, u16
*addr
, fc_channel
*fc
, fcp_cmnd
*fcmd
);
58 static void __init
pluto_detect_done(Scsi_Cmnd
*SCpnt
)
63 static void __init
pluto_detect_scsi_done(Scsi_Cmnd
*SCpnt
)
65 PLND(("Detect done %08lx\n", (long)SCpnt
))
66 if (atomic_dec_and_test (&fcss
))
67 complete(&fc_detect_complete
);
70 int pluto_slave_configure(struct scsi_device
*device
)
74 if (device
->tagged_supported
)
75 depth_to_use
= /* 254 */ 8;
79 scsi_adjust_queue_depth(device
,
80 (device
->tagged_supported
?
87 /* Detect all SSAs attached to the machine.
88 To be fast, do it on all online FC channels at the same time. */
89 int __init
pluto_detect(struct scsi_host_template
*tpnt
)
91 int i
, retry
, nplutos
;
93 struct scsi_device dev
;
95 tpnt
->proc_name
= "pluto";
97 for_each_online_fc_channel(fc
) {
101 PLND(("%d channels online\n", fcscount
))
103 #if defined(MODULE) && defined(CONFIG_FC4_SOC_MODULE) && defined(CONFIG_KMOD)
104 request_module("soc");
106 for_each_online_fc_channel(fc
) {
114 fcs
= kcalloc(fcscount
, sizeof (struct ctrl_inquiry
), GFP_DMA
);
116 printk ("PLUTO: Not enough memory to probe\n");
120 memset (&dev
, 0, sizeof(dev
));
121 atomic_set (&fcss
, fcscount
);
124 for_each_online_fc_channel(fc
) {
126 struct Scsi_Host
*host
;
129 if (i
== fcscount
) break;
130 if (fc
->posmap
) continue;
132 PLD(("trying to find SSA\n"))
134 /* If this is already registered to some other SCSI host, then it cannot be pluto */
135 if (fc
->scsi_name
[0]) continue;
136 memcpy (fc
->scsi_name
, "SSA", 4);
140 fc
->can_queue
= PLUTO_CAN_QUEUE
;
142 fc
->encode_addr
= pluto_encode_addr
;
144 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 0);
146 SCpnt
= &(fcs
[i
].cmd
);
147 host
= &(fcs
[i
].host
);
148 pluto
= (struct pluto
*)host
->hostdata
;
152 SCpnt
->cmnd
[0] = INQUIRY
;
153 SCpnt
->cmnd
[4] = 255;
155 /* FC layer requires this, so that SCpnt->device->tagged_supported is initially 0 */
156 SCpnt
->device
= &dev
;
159 SCpnt
->cmd_len
= COMMAND_SIZE(INQUIRY
);
161 SCpnt
->request
->cmd_flags
&= ~REQ_STARTED
;
163 SCpnt
->request_bufflen
= 256;
164 SCpnt
->request_buffer
= fcs
[i
].inquiry
;
165 PLD(("set up %d %08lx\n", i
, (long)SCpnt
))
169 for (retry
= 0; retry
< 5; retry
++) {
170 for (i
= 0; i
< fcscount
; i
++) {
171 if (!fcs
[i
].fc
) break;
172 if (!(fcs
[i
].cmd
.request
->cmd_flags
& REQ_STARTED
)) {
173 fcs
[i
].cmd
.request
->cmd_flags
|= REQ_STARTED
;
174 disable_irq(fcs
[i
].fc
->irq
);
175 PLND(("queuecommand %d %d\n", retry
, i
))
176 fcp_scsi_queuecommand (&(fcs
[i
].cmd
),
177 pluto_detect_scsi_done
);
178 enable_irq(fcs
[i
].fc
->irq
);
182 wait_for_completion_timeout(&fc_detect_complete
, 10 * HZ
);
184 if (!atomic_read(&fcss
))
185 break; /* All fc channels have answered us */
188 PLND(("Finished search\n"))
189 for (i
= 0, nplutos
= 0; i
< fcscount
; i
++) {
192 if (!(fc
= fcs
[i
].fc
)) break;
194 SCpnt
= &(fcs
[i
].cmd
);
196 /* Let FC mid-level free allocated resources */
197 pluto_detect_scsi_done(SCpnt
);
199 if (!SCpnt
->result
) {
200 struct pluto_inquiry
*inq
;
202 struct Scsi_Host
*host
;
204 inq
= (struct pluto_inquiry
*)fcs
[i
].inquiry
;
206 if ((inq
->dtype
& 0x1f) == TYPE_PROCESSOR
&&
207 !strncmp (inq
->vendor_id
, "SUN", 3) &&
208 !strncmp (inq
->product_id
, "SSA", 3)) {
212 ages
= kcalloc((inq
->channels
+ 1) * inq
->targets
, sizeof(long), GFP_KERNEL
);
215 host
= scsi_register (tpnt
, sizeof (struct pluto
));
222 if (!try_module_get(fc
->module
)) {
224 scsi_unregister(host
);
230 pluto
= (struct pluto
*)host
->hostdata
;
232 host
->max_id
= inq
->targets
;
233 host
->max_channel
= inq
->channels
;
236 fc
->channels
= inq
->channels
+ 1;
237 fc
->targets
= inq
->targets
;
241 memcpy (pluto
->rev_str
, inq
->revision
, 4);
242 pluto
->rev_str
[4] = 0;
243 p
= strchr (pluto
->rev_str
, ' ');
245 memcpy (pluto
->fw_rev_str
, inq
->fw_revision
, 4);
246 pluto
->fw_rev_str
[4] = 0;
247 p
= strchr (pluto
->fw_rev_str
, ' ');
249 memcpy (pluto
->serial_str
, inq
->serial
, 12);
250 pluto
->serial_str
[12] = 0;
251 p
= strchr (pluto
->serial_str
, ' ');
254 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
))
256 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
258 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
262 printk ("PLUTO: Total of %d SparcSTORAGE Arrays found\n", nplutos
);
266 int pluto_release(struct Scsi_Host
*host
)
268 struct pluto
*pluto
= (struct pluto
*)host
->hostdata
;
269 fc_channel
*fc
= pluto
->fc
;
271 module_put(fc
->module
);
273 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
274 PLND((" releasing pluto.\n"));
276 PLND(("released pluto!\n"));
280 const char *pluto_info(struct Scsi_Host
*host
)
282 static char buf
[128], *p
;
283 struct pluto
*pluto
= (struct pluto
*) host
->hostdata
;
285 sprintf(buf
, "SUN SparcSTORAGE Array %s fw %s serial %s %dx%d on %s",
286 pluto
->rev_str
, pluto
->fw_rev_str
, pluto
->serial_str
,
287 host
->max_channel
, host
->max_id
, pluto
->fc
->name
);
290 sprintf(p
, " PROM node %x", pluto
->fc
->dev
->prom_node
);
295 /* SSA uses this FC4S addressing:
298 case 0: CONTROLLER - All of addr[1]..addr[3] has to be 0
299 case 1: SINGLE DISK - addr[1] channel, addr[2] id, addr[3] 0
300 case 2: DISK GROUP - ???
303 So that SCSI mid-layer can access to these, we reserve
304 channel 0 id 0 lun 0 for CONTROLLER
305 and channels 1 .. max_channel are normal single disks.
307 static int pluto_encode_addr(Scsi_Cmnd
*SCpnt
, u16
*addr
, fc_channel
*fc
, fcp_cmnd
*fcmd
)
309 PLND(("encode addr %d %d %d\n", SCpnt
->device
->channel
, SCpnt
->device
->id
, SCpnt
->cmnd
[1] & 0xe0))
310 /* We don't support LUNs - neither does SSA :) */
311 if (SCpnt
->cmnd
[1] & 0xe0)
313 if (!SCpnt
->device
->channel
) {
314 if (SCpnt
->device
->id
)
316 memset (addr
, 0, 4 * sizeof(u16
));
319 addr
[1] = SCpnt
->device
->channel
- 1;
320 addr
[2] = SCpnt
->device
->id
;
323 /* We're Point-to-Point, so target it to the default DID */
325 PLND(("trying %04x%04x%04x%04x\n", addr
[0], addr
[1], addr
[2], addr
[3]))
329 static struct scsi_host_template driver_template
= {
330 .name
= "Sparc Storage Array 100/200",
331 .detect
= pluto_detect
,
332 .release
= pluto_release
,
334 .queuecommand
= fcp_scsi_queuecommand
,
335 .slave_configure
= pluto_slave_configure
,
336 .can_queue
= PLUTO_CAN_QUEUE
,
340 .use_clustering
= ENABLE_CLUSTERING
,
341 .eh_abort_handler
= fcp_scsi_abort
,
342 .eh_device_reset_handler
= fcp_scsi_dev_reset
,
343 .eh_host_reset_handler
= fcp_scsi_host_reset
,
346 #include "scsi_module.c"
348 MODULE_LICENSE("GPL");