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
= kmalloc(sizeof (struct ctrl_inquiry
) * fcscount
, GFP_DMA
);
116 printk ("PLUTO: Not enough memory to probe\n");
120 memset (fcs
, 0, sizeof (struct ctrl_inquiry
) * fcscount
);
121 memset (&dev
, 0, sizeof(dev
));
122 atomic_set (&fcss
, fcscount
);
125 for_each_online_fc_channel(fc
) {
127 struct Scsi_Host
*host
;
130 if (i
== fcscount
) break;
131 if (fc
->posmap
) continue;
133 PLD(("trying to find SSA\n"))
135 /* If this is already registered to some other SCSI host, then it cannot be pluto */
136 if (fc
->scsi_name
[0]) continue;
137 memcpy (fc
->scsi_name
, "SSA", 4);
141 fc
->can_queue
= PLUTO_CAN_QUEUE
;
143 fc
->encode_addr
= pluto_encode_addr
;
145 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 0);
147 SCpnt
= &(fcs
[i
].cmd
);
148 host
= &(fcs
[i
].host
);
149 pluto
= (struct pluto
*)host
->hostdata
;
153 SCpnt
->cmnd
[0] = INQUIRY
;
154 SCpnt
->cmnd
[4] = 255;
156 /* FC layer requires this, so that SCpnt->device->tagged_supported is initially 0 */
157 SCpnt
->device
= &dev
;
160 SCpnt
->cmd_len
= COMMAND_SIZE(INQUIRY
);
162 SCpnt
->request
->cmd_flags
&= ~REQ_STARTED
;
164 SCpnt
->done
= pluto_detect_done
;
165 SCpnt
->request_bufflen
= 256;
166 SCpnt
->request_buffer
= fcs
[i
].inquiry
;
167 PLD(("set up %d %08lx\n", i
, (long)SCpnt
))
171 for (retry
= 0; retry
< 5; retry
++) {
172 for (i
= 0; i
< fcscount
; i
++) {
173 if (!fcs
[i
].fc
) break;
174 if (!(fcs
[i
].cmd
.request
->cmd_flags
& REQ_STARTED
)) {
175 fcs
[i
].cmd
.request
->cmd_flags
|= REQ_STARTED
;
176 disable_irq(fcs
[i
].fc
->irq
);
177 PLND(("queuecommand %d %d\n", retry
, i
))
178 fcp_scsi_queuecommand (&(fcs
[i
].cmd
),
179 pluto_detect_scsi_done
);
180 enable_irq(fcs
[i
].fc
->irq
);
184 wait_for_completion_timeout(&fc_detect_complete
, 10 * HZ
);
186 if (!atomic_read(&fcss
))
187 break; /* All fc channels have answered us */
190 PLND(("Finished search\n"))
191 for (i
= 0, nplutos
= 0; i
< fcscount
; i
++) {
194 if (!(fc
= fcs
[i
].fc
)) break;
196 SCpnt
= &(fcs
[i
].cmd
);
198 /* Let FC mid-level free allocated resources */
201 if (!SCpnt
->result
) {
202 struct pluto_inquiry
*inq
;
204 struct Scsi_Host
*host
;
206 inq
= (struct pluto_inquiry
*)fcs
[i
].inquiry
;
208 if ((inq
->dtype
& 0x1f) == TYPE_PROCESSOR
&&
209 !strncmp (inq
->vendor_id
, "SUN", 3) &&
210 !strncmp (inq
->product_id
, "SSA", 3)) {
214 ages
= kmalloc (((inq
->channels
+ 1) * inq
->targets
) * sizeof(long), GFP_KERNEL
);
217 host
= scsi_register (tpnt
, sizeof (struct pluto
));
224 if (!try_module_get(fc
->module
)) {
226 scsi_unregister(host
);
232 pluto
= (struct pluto
*)host
->hostdata
;
234 host
->max_id
= inq
->targets
;
235 host
->max_channel
= inq
->channels
;
238 fc
->channels
= inq
->channels
+ 1;
239 fc
->targets
= inq
->targets
;
241 memset (ages
, 0, ((inq
->channels
+ 1) * inq
->targets
) * sizeof(long));
244 memcpy (pluto
->rev_str
, inq
->revision
, 4);
245 pluto
->rev_str
[4] = 0;
246 p
= strchr (pluto
->rev_str
, ' ');
248 memcpy (pluto
->fw_rev_str
, inq
->fw_revision
, 4);
249 pluto
->fw_rev_str
[4] = 0;
250 p
= strchr (pluto
->fw_rev_str
, ' ');
252 memcpy (pluto
->serial_str
, inq
->serial
, 12);
253 pluto
->serial_str
[12] = 0;
254 p
= strchr (pluto
->serial_str
, ' ');
257 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
))
259 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
261 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
265 printk ("PLUTO: Total of %d SparcSTORAGE Arrays found\n", nplutos
);
269 int pluto_release(struct Scsi_Host
*host
)
271 struct pluto
*pluto
= (struct pluto
*)host
->hostdata
;
272 fc_channel
*fc
= pluto
->fc
;
274 module_put(fc
->module
);
276 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
277 PLND((" releasing pluto.\n"));
279 PLND(("released pluto!\n"));
283 const char *pluto_info(struct Scsi_Host
*host
)
285 static char buf
[128], *p
;
286 struct pluto
*pluto
= (struct pluto
*) host
->hostdata
;
288 sprintf(buf
, "SUN SparcSTORAGE Array %s fw %s serial %s %dx%d on %s",
289 pluto
->rev_str
, pluto
->fw_rev_str
, pluto
->serial_str
,
290 host
->max_channel
, host
->max_id
, pluto
->fc
->name
);
293 sprintf(p
, " PROM node %x", pluto
->fc
->dev
->prom_node
);
298 /* SSA uses this FC4S addressing:
301 case 0: CONTROLLER - All of addr[1]..addr[3] has to be 0
302 case 1: SINGLE DISK - addr[1] channel, addr[2] id, addr[3] 0
303 case 2: DISK GROUP - ???
306 So that SCSI mid-layer can access to these, we reserve
307 channel 0 id 0 lun 0 for CONTROLLER
308 and channels 1 .. max_channel are normal single disks.
310 static int pluto_encode_addr(Scsi_Cmnd
*SCpnt
, u16
*addr
, fc_channel
*fc
, fcp_cmnd
*fcmd
)
312 PLND(("encode addr %d %d %d\n", SCpnt
->device
->channel
, SCpnt
->device
->id
, SCpnt
->cmnd
[1] & 0xe0))
313 /* We don't support LUNs - neither does SSA :) */
314 if (SCpnt
->cmnd
[1] & 0xe0)
316 if (!SCpnt
->device
->channel
) {
317 if (SCpnt
->device
->id
)
319 memset (addr
, 0, 4 * sizeof(u16
));
322 addr
[1] = SCpnt
->device
->channel
- 1;
323 addr
[2] = SCpnt
->device
->id
;
326 /* We're Point-to-Point, so target it to the default DID */
328 PLND(("trying %04x%04x%04x%04x\n", addr
[0], addr
[1], addr
[2], addr
[3]))
332 static struct scsi_host_template driver_template
= {
333 .name
= "Sparc Storage Array 100/200",
334 .detect
= pluto_detect
,
335 .release
= pluto_release
,
337 .queuecommand
= fcp_scsi_queuecommand
,
338 .slave_configure
= pluto_slave_configure
,
339 .can_queue
= PLUTO_CAN_QUEUE
,
343 .use_clustering
= ENABLE_CLUSTERING
,
344 .eh_abort_handler
= fcp_scsi_abort
,
345 .eh_device_reset_handler
= fcp_scsi_dev_reset
,
346 .eh_host_reset_handler
= fcp_scsi_host_reset
,
349 #include "scsi_module.c"
351 MODULE_LICENSE("GPL");