Import 2.3.13pre7
[davej-history.git] / drivers / fc4 / soc.c
blobcaa11c33e6f77c6bfa4caf8308f3542f14f89452
1 /* soc.c: Sparc SUNW,soc (Serial Optical Channel) Fibre Channel Sbus adapter support.
3 * Copyright (C) 1996,1997,1999 Jakub Jelinek (jj@ultra.linux.cz)
4 * Copyright (C) 1997,1998 Jirka Hanika (geo@ff.cuni.cz)
6 * Sources:
7 * Fibre Channel Physical & Signaling Interface (FC-PH), dpANS, 1994
8 * dpANS Fibre Channel Protocol for SCSI (X3.269-199X), Rev. 012, 1995
10 * Supported hardware:
11 * Tested on SOC sbus card bought with SS1000 in Linux running on SS5 and Ultra1.
12 * For SOC sbus cards, you have to make sure your FCode is 1.52 or later.
13 * If you have older FCode, you should try to upgrade or get SOC microcode from Sun
14 * (the microcode is present in Solaris soc driver as well). In that case you need
15 * to #define HAVE_SOC_UCODE and format the microcode into soc_asm.c. For the exact
16 * format mail me and I will tell you. I cannot offer you the actual microcode though,
17 * unless Sun confirms they don't mind.
20 static char *version =
21 "soc.c:v1.3 9/Feb/99 Jakub Jelinek (jj@ultra.linux.cz), Jirka Hanika (geo@ff.cuni.cz)\n";
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/types.h>
27 #include <linux/fcntl.h>
28 #include <linux/interrupt.h>
29 #include <linux/ptrace.h>
30 #include <linux/ioport.h>
31 #include <linux/in.h>
32 #include <linux/malloc.h>
33 #include <linux/string.h>
34 #include <linux/init.h>
35 #include <asm/bitops.h>
36 #include <asm/io.h>
37 #include <asm/dma.h>
38 #include <linux/errno.h>
39 #include <asm/byteorder.h>
41 #include <asm/openprom.h>
42 #include <asm/oplib.h>
43 #include <asm/auxio.h>
44 #include <asm/pgtable.h>
45 #include <asm/irq.h>
47 /* #define SOCDEBUG */
48 /* #define HAVE_SOC_UCODE */
50 #include "fcp_impl.h"
51 #include "soc.h"
52 #ifdef HAVE_SOC_UCODE
53 #include "soc_asm.h"
54 #endif
56 #define soc_printk printk ("soc%d: ", s->soc_no); printk
58 #ifdef SOCDEBUG
59 #define SOD(x) soc_printk x;
60 #else
61 #define SOD(x)
62 #endif
64 #define for_each_soc(s) for (s = socs; s; s = s->next)
65 struct soc *socs = NULL;
67 static inline void soc_disable(struct soc *s)
69 s->regs->imask = 0; s->regs->cmd = SOC_CMD_SOFT_RESET;
72 static inline void soc_enable(struct soc *s)
74 SOD(("enable %08x\n", s->cfg))
75 s->regs->sae = 0; s->regs->cfg = s->cfg;
76 s->regs->cmd = SOC_CMD_RSP_QALL;
77 SOC_SETIMASK(s, SOC_IMASK_RSP_QALL | SOC_IMASK_SAE);
78 SOD(("imask %08lx %08lx\n", s->imask, s->regs->imask));
81 static void soc_reset(fc_channel *fc)
83 soc_port *port = (soc_port *)fc;
84 struct soc *s = port->s;
86 /* FIXME */
87 soc_disable(s);
88 s->req[0].seqno = 1;
89 s->req[1].seqno = 1;
90 s->rsp[0].seqno = 1;
91 s->rsp[1].seqno = 1;
92 s->req[0].in = 0;
93 s->req[1].in = 0;
94 s->rsp[0].in = 0;
95 s->rsp[1].in = 0;
96 s->req[0].out = 0;
97 s->req[1].out = 0;
98 s->rsp[0].out = 0;
99 s->rsp[1].out = 0;
101 /* FIXME */
102 soc_enable(s);
105 static void inline soc_solicited (struct soc *s)
107 fc_hdr fchdr;
108 soc_rsp *hwrsp;
109 soc_cq *sw_cq;
110 int token;
111 int status;
112 fc_channel *fc;
114 sw_cq = &s->rsp[SOC_SOLICITED_RSP_Q];
116 if (sw_cq->pool == NULL)
117 sw_cq->pool =
118 (soc_req *)(s->xram + (xram_get_32low ((xram_p)&sw_cq->hw_cq->address) / sizeof(u16)));
119 sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
120 SOD (("soc_solicited, %d packets arrived\n", (sw_cq->in - sw_cq->out) & sw_cq->last))
121 for (;;) {
122 hwrsp = (soc_rsp *)sw_cq->pool + sw_cq->out;
123 token = xram_get_32low ((xram_p)&hwrsp->shdr.token);
124 status = xram_get_32low ((xram_p)&hwrsp->status);
125 fc = (fc_channel *)(&s->port[(token >> 11) & 1]);
127 if (status == SOC_OK)
128 fcp_receive_solicited(fc, token >> 12, token & ((1 << 11) - 1), FC_STATUS_OK, NULL);
129 else {
130 xram_copy_from(&fchdr, (xram_p)&hwrsp->fchdr, sizeof(fchdr));
131 /* We have intentionally defined FC_STATUS_* constants to match SOC_* constants, otherwise
132 we'd have to translate status */
133 fcp_receive_solicited(fc, token >> 12, token & ((1 << 11) - 1), status, &fchdr);
136 if (++sw_cq->out > sw_cq->last) {
137 sw_cq->seqno++;
138 sw_cq->out = 0;
141 if (sw_cq->out == sw_cq->in) {
142 sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
143 if (sw_cq->out == sw_cq->in) {
144 /* Tell the hardware about it */
145 s->regs->cmd = (sw_cq->out << 24) | (SOC_CMD_RSP_QALL & ~(SOC_CMD_RSP_Q0 << SOC_SOLICITED_RSP_Q));
146 /* Read it, so that we're sure it has been updated */
147 s->regs->cmd;
148 sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
149 if (sw_cq->out == sw_cq->in)
150 break;
156 static void inline soc_request (struct soc *s, u32 cmd)
158 SOC_SETIMASK(s, s->imask & ~(cmd & SOC_CMD_REQ_QALL));
159 SOD(("imask %08lx %08lx\n", s->imask, s->regs->imask));
161 SOD(("Queues available %08x OUT %X %X\n", cmd, xram_get_8((xram_p)&s->req[0].hw_cq->out), xram_get_8((xram_p)&s->req[0].hw_cq->out)))
162 if (s->port[s->curr_port].fc.state != FC_STATE_OFFLINE) {
163 fcp_queue_empty ((fc_channel *)&(s->port[s->curr_port]));
164 if (((s->req[1].in + 1) & s->req[1].last) != (s->req[1].out))
165 fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
166 } else
167 fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
168 if (s->port[1 - s->curr_port].fc.state != FC_STATE_OFFLINE)
169 s->curr_port ^= 1;
172 static void inline soc_unsolicited (struct soc *s)
174 soc_rsp *hwrsp, *hwrspc;
175 soc_cq *sw_cq;
176 int count;
177 int status;
178 int flags;
179 fc_channel *fc;
181 sw_cq = &s->rsp[SOC_UNSOLICITED_RSP_Q];
182 if (sw_cq->pool == NULL)
183 sw_cq->pool =
184 (soc_req *)(s->xram + (xram_get_32low ((xram_p)&sw_cq->hw_cq->address) / sizeof(u16)));
186 sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
187 SOD (("soc_unsolicited, %d packets arrived\n", (sw_cq->in - sw_cq->out) & sw_cq->last))
188 while (sw_cq->in != sw_cq->out) {
189 /* ...real work per entry here... */
190 hwrsp = (soc_rsp *)sw_cq->pool + sw_cq->out;
192 hwrspc = NULL;
193 flags = hwrsp->shdr.flags;
194 count = xram_get_8 ((xram_p)&hwrsp->count);
195 fc = (fc_channel *)&s->port[flags & SOC_PORT_B];
196 SOD(("FC %08lx fcp_state_change %08lx\n", (long)fc, (long)fc->fcp_state_change))
198 if (count != 1) {
199 /* Ugh, continuation entries */
200 u8 in;
202 if (count != 2) {
203 printk("%s: Too many continuations entries %d\n", fc->name, count);
204 goto update_out;
207 in = sw_cq->in;
208 if (in < sw_cq->out) in += sw_cq->last + 1;
209 if (in < sw_cq->out + 2) {
210 /* Ask the hardware about it if they haven't arrived yet */
211 s->regs->cmd = (sw_cq->out << 24) | (SOC_CMD_RSP_QALL & ~(SOC_CMD_RSP_Q0 << SOC_UNSOLICITED_RSP_Q));
212 /* Read it, so that we're sure it has been updated */
213 s->regs->cmd;
214 sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
215 in = sw_cq->in;
216 if (in < sw_cq->out) in += sw_cq->last + 1;
217 if (in < sw_cq->out + 2) /* Nothing came, let us wait */
218 return;
220 if (sw_cq->out == sw_cq->last)
221 hwrspc = (soc_rsp *)sw_cq->pool;
222 else
223 hwrspc = hwrsp + 1;
226 switch (flags & ~SOC_PORT_B) {
227 case SOC_STATUS:
228 status = xram_get_32low ((xram_p)&hwrsp->status);
229 switch (status) {
230 case SOC_ONLINE:
231 SOD(("State change to ONLINE\n"));
232 fcp_state_change(fc, FC_STATE_ONLINE);
233 break;
234 case SOC_OFFLINE:
235 SOD(("State change to OFFLINE\n"));
236 fcp_state_change(fc, FC_STATE_OFFLINE);
237 break;
238 default:
239 printk ("%s: Unknown STATUS no %d\n", fc->name, status);
240 break;
242 break;
243 case (SOC_UNSOLICITED|SOC_FC_HDR):
245 int r_ctl = xram_get_8 ((xram_p)&hwrsp->fchdr);
246 unsigned len;
247 char buf[64];
249 if ((r_ctl & 0xf0) == R_CTL_EXTENDED_SVC) {
250 len = xram_get_32 ((xram_p)&hwrsp->shdr.bytecnt);
251 if (len < 4 || !hwrspc)
252 printk ("%s: Invalid R_CTL %02x continuation entries\n", fc->name, r_ctl);
253 else {
254 if (len > 60) len = 60;
255 xram_copy_from (buf, (xram_p)hwrspc, (len + 3) & ~3);
256 if (*(u32 *)buf == LS_DISPLAY) {
257 int i;
259 for (i = 4; i < len; i++)
260 if (buf[i] == '\n') buf[i] = ' ';
261 buf[len] = 0;
262 printk ("%s message: %s\n", fc->name, buf + 4);
263 } else
264 printk ("%s: Unknown LS_CMD %02x\n", fc->name, buf[0]);
266 } else
267 printk ("%s: Unsolicited R_CTL %02x not handled\n", fc->name, r_ctl);
269 break;
270 default:
271 printk ("%s: Unexpected flags %08x\n", fc->name, flags);
272 break;
274 update_out:
275 if (++sw_cq->out > sw_cq->last) {
276 sw_cq->seqno++;
277 sw_cq->out = 0;
280 if (hwrspc) {
281 if (++sw_cq->out > sw_cq->last) {
282 sw_cq->seqno++;
283 sw_cq->out = 0;
287 if (sw_cq->out == sw_cq->in) {
288 sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
289 if (sw_cq->out == sw_cq->in) {
290 /* Tell the hardware about it */
291 s->regs->cmd = (sw_cq->out << 24) | (SOC_CMD_RSP_QALL & ~(SOC_CMD_RSP_Q0 << SOC_UNSOLICITED_RSP_Q));
292 /* Read it, so that we're sure it has been updated */
293 s->regs->cmd;
294 sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
300 static void soc_intr(int irq, void *dev_id, struct pt_regs *regs)
302 u32 cmd;
303 unsigned long flags;
304 register struct soc *s = (struct soc *)dev_id;
306 spin_lock_irqsave(&io_request_lock, flags);
307 cmd = s->regs->cmd;
308 for (; (cmd = SOC_INTR (s, cmd)); cmd = s->regs->cmd) {
309 if (cmd & SOC_CMD_RSP_Q1) soc_unsolicited (s);
310 if (cmd & SOC_CMD_RSP_Q0) soc_solicited (s);
311 if (cmd & SOC_CMD_REQ_QALL) soc_request (s, cmd);
313 spin_unlock_irqrestore(&io_request_lock, flags);
316 #define TOKEN(proto, port, token) (((proto)<<12)|(token)|(port))
318 static int soc_hw_enque (fc_channel *fc, fcp_cmnd *fcmd)
320 soc_port *port = (soc_port *)fc;
321 struct soc *s = port->s;
322 int qno;
323 soc_cq *sw_cq;
324 int cq_next_in;
325 soc_req *request;
326 fc_hdr *fch;
327 int i;
329 if (fcmd->proto == TYPE_SCSI_FCP)
330 qno = 1;
331 else
332 qno = 0;
333 SOD(("Putting a FCP packet type %d into hw queue %d\n", fcmd->proto, qno))
334 if (s->imask & (SOC_IMASK_REQ_Q0 << qno)) {
335 SOD(("EIO %08x\n", s->imask))
336 return -EIO;
338 sw_cq = s->req + qno;
339 cq_next_in = (sw_cq->in + 1) & sw_cq->last;
341 if (cq_next_in == sw_cq->out
342 && cq_next_in == (sw_cq->out = xram_get_8((xram_p)&sw_cq->hw_cq->out))) {
343 SOD(("%d IN %d OUT %d LAST %d\n", qno, sw_cq->in, sw_cq->out, sw_cq->last))
344 SOC_SETIMASK(s, s->imask | (SOC_IMASK_REQ_Q0 << qno));
345 SOD(("imask %08lx %08lx\n", s->imask, s->regs->imask));
346 /* If queue is full, just say NO */
347 return -EBUSY;
350 request = sw_cq->pool + sw_cq->in;
351 fch = &request->fchdr;
353 switch (fcmd->proto) {
354 case TYPE_SCSI_FCP:
355 request->shdr.token = TOKEN(TYPE_SCSI_FCP, port->mask, fcmd->token);
356 request->data[0].base = fc->dma_scsi_cmd + fcmd->token * sizeof(fcp_cmd);
357 request->data[0].count = sizeof(fcp_cmd);
358 request->data[1].base = fc->dma_scsi_rsp + fcmd->token * fc->rsp_size;
359 request->data[1].count = fc->rsp_size;
360 if (fcmd->data) {
361 request->shdr.segcnt = 3;
362 i = fc->scsi_cmd_pool[fcmd->token].fcp_data_len;
363 request->shdr.bytecnt = i;
364 request->data[2].base = fcmd->data;
365 request->data[2].count = i;
366 request->type = (fc->scsi_cmd_pool[fcmd->token].fcp_cntl & FCP_CNTL_WRITE) ?
367 SOC_CQTYPE_IO_WRITE : SOC_CQTYPE_IO_READ;
368 } else {
369 request->shdr.segcnt = 2;
370 request->shdr.bytecnt = 0;
371 request->data[2].base = 0;
372 request->data[2].count = 0;
373 request->type = SOC_CQTYPE_SIMPLE;
375 FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fc->did);
376 FILL_FCHDR_SID(fch, fc->sid);
377 FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
378 FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
379 FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
380 fch->param = 0;
381 request->shdr.flags = port->flags;
382 request->shdr.class = 2;
383 break;
385 case PROTO_OFFLINE:
386 memset (request, 0, sizeof(*request));
387 request->shdr.token = TOKEN(PROTO_OFFLINE, port->mask, fcmd->token);
388 request->type = SOC_CQTYPE_OFFLINE;
389 FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fc->did);
390 FILL_FCHDR_SID(fch, fc->sid);
391 FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
392 FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
393 FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
394 request->shdr.flags = port->flags;
395 break;
397 case PROTO_REPORT_AL_MAP:
398 /* SOC only supports Point-to-Point topology, no FC-AL, sorry... */
399 return -ENOSYS;
401 default:
402 request->shdr.token = TOKEN(fcmd->proto, port->mask, fcmd->token);
403 request->shdr.class = 2;
404 request->shdr.flags = port->flags;
405 memcpy (fch, &fcmd->fch, sizeof(fc_hdr));
406 request->data[0].count = fcmd->cmdlen;
407 request->data[1].count = fcmd->rsplen;
408 request->type = fcmd->class;
409 switch (fcmd->class) {
410 case FC_CLASS_OUTBOUND:
411 request->data[0].base = fcmd->cmd;
412 request->data[0].count = fcmd->cmdlen;
413 request->type = SOC_CQTYPE_OUTBOUND;
414 request->shdr.bytecnt = fcmd->cmdlen;
415 request->shdr.segcnt = 1;
416 break;
417 case FC_CLASS_INBOUND:
418 request->data[0].base = fcmd->rsp;
419 request->data[0].count = fcmd->rsplen;
420 request->type = SOC_CQTYPE_INBOUND;
421 request->shdr.bytecnt = 0;
422 request->shdr.segcnt = 1;
423 break;
424 case FC_CLASS_SIMPLE:
425 request->data[0].base = fcmd->cmd;
426 request->data[1].base = fcmd->rsp;
427 request->data[0].count = fcmd->cmdlen;
428 request->data[1].count = fcmd->rsplen;
429 request->type = SOC_CQTYPE_SIMPLE;
430 request->shdr.bytecnt = fcmd->cmdlen;
431 request->shdr.segcnt = 2;
432 break;
433 case FC_CLASS_IO_READ:
434 case FC_CLASS_IO_WRITE:
435 request->data[0].base = fcmd->cmd;
436 request->data[1].base = fcmd->rsp;
437 request->data[0].count = fcmd->cmdlen;
438 request->data[1].count = fcmd->rsplen;
439 request->type = (fcmd->class == FC_CLASS_IO_READ) ? SOC_CQTYPE_IO_READ : SOC_CQTYPE_IO_WRITE;
440 if (fcmd->data) {
441 request->data[2].base = fcmd->data;
442 request->data[2].count = fcmd->datalen;
443 request->shdr.bytecnt = fcmd->datalen;
444 request->shdr.segcnt = 3;
445 } else {
446 request->shdr.bytecnt = 0;
447 request->shdr.segcnt = 2;
449 break;
451 break;
454 request->count = 1;
455 request->flags = 0;
456 request->seqno = sw_cq->seqno;
458 /* And now tell the SOC about it */
460 if (++sw_cq->in > sw_cq->last) {
461 sw_cq->in = 0;
462 sw_cq->seqno++;
465 SOD(("Putting %08x into cmd\n", SOC_CMD_RSP_QALL | (sw_cq->in << 24) | (SOC_CMD_REQ_Q0 << qno)))
467 s->regs->cmd = SOC_CMD_RSP_QALL | (sw_cq->in << 24) | (SOC_CMD_REQ_Q0 << qno);
468 /* Read so that command is completed */
469 s->regs->cmd;
471 return 0;
474 static inline void soc_download_fw(struct soc *s)
476 #ifdef HAVE_SOC_UCODE
477 xram_copy_to (s->xram, soc_ucode, sizeof(soc_ucode));
478 xram_bzero (s->xram + (sizeof(soc_ucode)/sizeof(u16)), 32768 - sizeof(soc_ucode));
479 #endif
482 /* Check for what the best SBUS burst we can use happens
483 * to be on this machine.
485 static inline void soc_init_bursts(struct soc *s, struct linux_sbus_device *sdev)
487 int bsizes, bsizes_more;
489 bsizes = (prom_getintdefault(sdev->prom_node,"burst-sizes",0xff) & 0xff);
490 bsizes_more = (prom_getintdefault(sdev->my_bus->prom_node, "burst-sizes", 0xff) & 0xff);
491 bsizes &= bsizes_more;
492 if ((bsizes & 0x7f) == 0x7f)
493 s->cfg = SOC_CFG_BURST_64;
494 else if ((bsizes & 0x3f) == 0x3f)
495 s->cfg = SOC_CFG_BURST_32;
496 else if ((bsizes & 0x1f) == 0x1f)
497 s->cfg = SOC_CFG_BURST_16;
498 else
499 s->cfg = SOC_CFG_BURST_4;
502 static inline void soc_init(struct linux_sbus_device *sdev, int no)
504 unsigned char tmp[60];
505 int propl;
506 struct soc *s;
507 static unsigned version_printed = 0;
508 soc_hw_cq cq[8];
509 int size, i;
510 int irq;
512 s = kmalloc (sizeof (struct soc), GFP_KERNEL);
513 if (!s) return;
514 memset (s, 0, sizeof(struct soc));
515 s->soc_no = no;
517 SOD(("socs %08lx soc_intr %08lx soc_hw_enque %08x\n", (long)socs, (long)soc_intr, (long)soc_hw_enque))
518 if (version_printed++ == 0)
519 printk (version);
520 #ifdef MODULE
521 s->port[0].fc.module = &__this_module;
522 s->port[1].fc.module = &__this_module;
523 #else
524 s->port[0].fc.module = NULL;
525 s->port[1].fc.module = NULL;
526 #endif
528 s->next = socs;
529 socs = s;
530 s->port[0].fc.dev = sdev;
531 s->port[1].fc.dev = sdev;
532 s->port[0].s = s;
533 s->port[1].s = s;
535 s->port[0].fc.next = &s->port[1].fc;
537 /* World Wide Name of SOC */
538 propl = prom_getproperty (sdev->prom_node, "soc-wwn", tmp, sizeof(tmp));
539 if (propl != sizeof (fc_wwn)) {
540 s->wwn.naaid = NAAID_IEEE;
541 s->wwn.lo = 0x12345678;
542 } else
543 memcpy (&s->wwn, tmp, sizeof (fc_wwn));
545 propl = prom_getproperty (sdev->prom_node, "port-wwns", tmp, sizeof(tmp));
546 if (propl != 2 * sizeof (fc_wwn)) {
547 s->port[0].fc.wwn_nport.naaid = NAAID_IEEE_EXT;
548 s->port[0].fc.wwn_nport.hi = s->wwn.hi;
549 s->port[0].fc.wwn_nport.lo = s->wwn.lo;
550 s->port[1].fc.wwn_nport.naaid = NAAID_IEEE_EXT;
551 s->port[1].fc.wwn_nport.nportid = 1;
552 s->port[1].fc.wwn_nport.hi = s->wwn.hi;
553 s->port[1].fc.wwn_nport.lo = s->wwn.lo;
554 } else {
555 memcpy (&s->port[0].fc.wwn_nport, tmp, sizeof (fc_wwn));
556 memcpy (&s->port[1].fc.wwn_nport, tmp + sizeof (fc_wwn), sizeof (fc_wwn));
558 memcpy (&s->port[0].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
559 memcpy (&s->port[1].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
560 SOD(("Got wwns %08x%08x ports %08x%08x and %08x%08x\n",
561 *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
562 *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
563 *(u32 *)&s->port[1].fc.wwn_nport, s->port[1].fc.wwn_nport.lo))
565 s->port[0].fc.sid = 1;
566 s->port[1].fc.sid = 17;
567 s->port[0].fc.did = 2;
568 s->port[1].fc.did = 18;
570 s->port[0].fc.reset = soc_reset;
571 s->port[1].fc.reset = soc_reset;
573 /* Setup the reg property for this device. */
574 prom_apply_sbus_ranges(sdev->my_bus, sdev->reg_addrs, sdev->num_registers, sdev);
576 if (sdev->num_registers == 1) {
577 /* Probably SunFire onboard SOC */
578 s->xram = (xram_p)
579 sparc_alloc_io (sdev->reg_addrs [0].phys_addr, 0,
580 sdev->reg_addrs [0].reg_size, "soc_xram",
581 sdev->reg_addrs [0].which_io, 0);
582 s->regs = (struct soc_regs *)((char *)s->xram + 0x10000);
583 } else {
584 /* Probably SOC sbus card */
585 s->xram = (xram_p)
586 sparc_alloc_io (sdev->reg_addrs [1].phys_addr, 0,
587 sdev->reg_addrs [1].reg_size, "soc_xram",
588 sdev->reg_addrs [1].which_io, 0);
589 s->regs = (struct soc_regs *)
590 sparc_alloc_io (sdev->reg_addrs [2].phys_addr, 0,
591 sdev->reg_addrs [2].reg_size, "soc_regs",
592 sdev->reg_addrs [2].which_io, 0);
595 soc_init_bursts(s, sdev);
597 SOD(("Disabling SOC\n"))
599 soc_disable (s);
601 irq = sdev->irqs[0];
603 if (request_irq (irq, soc_intr, SA_SHIRQ, "SOC", (void *)s)) {
604 soc_printk ("Cannot order irq %d to go\n", irq);
605 socs = s->next;
606 return;
609 SOD(("SOC uses IRQ%s\n", __irq_itoa(irq)))
611 s->port[0].fc.irq = irq;
612 s->port[1].fc.irq = irq;
614 sprintf (s->port[0].fc.name, "soc%d port A", no);
615 sprintf (s->port[1].fc.name, "soc%d port B", no);
616 s->port[0].flags = SOC_FC_HDR | SOC_PORT_A;
617 s->port[1].flags = SOC_FC_HDR | SOC_PORT_B;
618 s->port[1].mask = (1 << 11);
620 s->port[0].fc.hw_enque = soc_hw_enque;
621 s->port[1].fc.hw_enque = soc_hw_enque;
623 soc_download_fw (s);
625 SOD(("Downloaded firmware\n"))
627 /* Now setup xram circular queues */
628 memset (cq, 0, sizeof(cq));
630 size = (SOC_CQ_REQ0_SIZE + SOC_CQ_REQ1_SIZE) * sizeof(soc_req);
631 s->req[0].pool = (soc_req *) sparc_dvma_malloc (size, "SOC request queues", &cq[0].address);
632 s->req[1].pool = s->req[0].pool + SOC_CQ_REQ0_SIZE;
634 s->req[0].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_REQ_OFFSET);
635 s->req[1].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_REQ_OFFSET + sizeof(soc_hw_cq) / sizeof(u16));
636 s->rsp[0].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_RSP_OFFSET);
637 s->rsp[1].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_RSP_OFFSET + sizeof(soc_hw_cq) / sizeof(u16));
639 cq[1].address = cq[0].address + (SOC_CQ_REQ0_SIZE * sizeof(soc_req));
640 cq[4].address = 1;
641 cq[5].address = 1;
642 cq[0].last = SOC_CQ_REQ0_SIZE - 1;
643 cq[1].last = SOC_CQ_REQ1_SIZE - 1;
644 cq[4].last = SOC_CQ_RSP0_SIZE - 1;
645 cq[5].last = SOC_CQ_RSP1_SIZE - 1;
646 for (i = 0; i < 8; i++)
647 cq[i].seqno = 1;
649 s->req[0].last = SOC_CQ_REQ0_SIZE - 1;
650 s->req[1].last = SOC_CQ_REQ1_SIZE - 1;
651 s->rsp[0].last = SOC_CQ_RSP0_SIZE - 1;
652 s->rsp[1].last = SOC_CQ_RSP1_SIZE - 1;
654 s->req[0].seqno = 1;
655 s->req[1].seqno = 1;
656 s->rsp[0].seqno = 1;
657 s->rsp[1].seqno = 1;
659 xram_copy_to (s->xram + SOC_CQ_REQ_OFFSET, cq, sizeof(cq));
661 /* Make our sw copy of SOC service parameters */
662 xram_copy_from (s->serv_params, s->xram + 0x140, sizeof (s->serv_params));
664 s->port[0].fc.common_svc = (common_svc_parm *)s->serv_params;
665 s->port[0].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
666 s->port[1].fc.common_svc = (common_svc_parm *)&s->serv_params;
667 s->port[1].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
669 soc_enable (s);
671 SOD(("Enabled SOC\n"))
674 #ifndef MODULE
675 int __init soc_probe(void)
676 #else
677 int init_module(void)
678 #endif
680 struct linux_sbus *bus;
681 struct linux_sbus_device *sdev = 0;
682 struct soc *s;
683 int cards = 0;
685 for_each_sbus(bus) {
686 for_each_sbusdev(sdev, bus) {
687 if(!strcmp(sdev->prom_name, "SUNW,soc")) {
688 soc_init(sdev, cards);
689 cards++;
693 if (!cards) return -EIO;
695 for_each_soc(s)
696 if (s->next)
697 s->port[1].fc.next = &s->next->port[0].fc;
698 fcp_init (&socs->port[0].fc);
699 return 0;
702 EXPORT_NO_SYMBOLS;
704 #ifdef MODULE
705 void cleanup_module(void)
707 struct soc *s;
708 int irq;
709 struct linux_sbus_device *sdev;
711 for_each_soc(s) {
712 irq = s->port[0].fc.irq;
713 disable_irq (irq);
714 free_irq (irq, s);
716 fcp_release(&(s->port[0].fc), 2);
718 sdev = s->port[0].fc.dev;
719 if (sdev->num_registers == 1)
720 sparc_free_io ((char *)s->xram, sdev->reg_addrs [0].reg_size);
721 else {
722 sparc_free_io ((char *)s->xram, sdev->reg_addrs [1].reg_size);
723 sparc_free_io ((char *)s->regs, sdev->reg_addrs [2].reg_size);
725 /* FIXME: sparc_dvma_free() ??? */
728 #endif