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>
16 #include <linux/config.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 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
)
64 static void __init
pluto_detect_done(Scsi_Cmnd
*SCpnt
)
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
))
77 int pluto_slave_configure(struct scsi_device
*device
)
81 if (device
->tagged_supported
)
82 depth_to_use
= /* 254 */ 8;
86 scsi_adjust_queue_depth(device
,
87 (device
->tagged_supported
?
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
;
100 struct scsi_device dev
;
101 DEFINE_TIMER(fc_timer
, pluto_detect_timeout
, 0, 0);
103 tpnt
->proc_name
= "pluto";
105 for_each_online_fc_channel(fc
) {
109 PLND(("%d channels online\n", fcscount
))
111 #if defined(MODULE) && defined(CONFIG_FC4_SOC_MODULE) && defined(CONFIG_KMOD)
112 request_module("soc");
114 for_each_online_fc_channel(fc
) {
122 fcs
= (struct ctrl_inquiry
*) kmalloc (sizeof (struct ctrl_inquiry
) * fcscount
, GFP_DMA
);
124 printk ("PLUTO: Not enough memory to probe\n");
128 memset (fcs
, 0, sizeof (struct ctrl_inquiry
) * fcscount
);
129 memset (&dev
, 0, sizeof(dev
));
130 atomic_set (&fcss
, fcscount
);
133 for_each_online_fc_channel(fc
) {
135 struct Scsi_Host
*host
;
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);
149 fc
->can_queue
= PLUTO_CAN_QUEUE
;
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
;
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
;
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
))
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
);
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
++) {
207 if (!(fc
= fcs
[i
].fc
)) break;
209 SCpnt
= &(fcs
[i
].cmd
);
211 /* Let FC mid-level free allocated resources */
214 if (!SCpnt
->result
) {
215 struct pluto_inquiry
*inq
;
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)) {
227 ages
= kmalloc (((inq
->channels
+ 1) * inq
->targets
) * sizeof(long), GFP_KERNEL
);
230 host
= scsi_register (tpnt
, sizeof (struct pluto
));
237 if (!try_module_get(fc
->module
)) {
239 scsi_unregister(host
);
245 pluto
= (struct pluto
*)host
->hostdata
;
247 host
->max_id
= inq
->targets
;
248 host
->max_channel
= inq
->channels
;
251 fc
->channels
= inq
->channels
+ 1;
252 fc
->targets
= inq
->targets
;
254 memset (ages
, 0, ((inq
->channels
+ 1) * inq
->targets
) * sizeof(long));
257 memcpy (pluto
->rev_str
, inq
->revision
, 4);
258 pluto
->rev_str
[4] = 0;
259 p
= strchr (pluto
->rev_str
, ' ');
261 memcpy (pluto
->fw_rev_str
, inq
->fw_revision
, 4);
262 pluto
->fw_rev_str
[4] = 0;
263 p
= strchr (pluto
->fw_rev_str
, ' ');
265 memcpy (pluto
->serial_str
, inq
->serial
, 12);
266 pluto
->serial_str
[12] = 0;
267 p
= strchr (pluto
->serial_str
, ' ');
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
))
272 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
274 fc
->fcp_register(fc
, TYPE_SCSI_FCP
, 1);
278 printk ("PLUTO: Total of %d SparcSTORAGE Arrays found\n", 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"));
292 PLND(("released pluto!\n"));
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
);
306 sprintf(p
, " PROM node %x", pluto
->fc
->dev
->prom_node
);
311 /* SSA uses this FC4S addressing:
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)
329 if (!SCpnt
->device
->channel
) {
330 if (SCpnt
->device
->id
)
332 memset (addr
, 0, 4 * sizeof(u16
));
335 addr
[1] = SCpnt
->device
->channel
- 1;
336 addr
[2] = SCpnt
->device
->id
;
339 /* We're Point-to-Point, so target it to the default DID */
341 PLND(("trying %04x%04x%04x%04x\n", addr
[0], addr
[1], addr
[2], addr
[3]))
345 static struct scsi_host_template driver_template
= {
346 .name
= "Sparc Storage Array 100/200",
347 .detect
= pluto_detect
,
348 .release
= pluto_release
,
350 .queuecommand
= fcp_scsi_queuecommand
,
351 .slave_configure
= pluto_slave_configure
,
352 .can_queue
= PLUTO_CAN_QUEUE
,
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");