1 /* socal.c: Sparc SUNW,socal (SOC+) Fibre Channel Sbus adapter support.
3 * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
6 * Fibre Channel Physical & Signaling Interface (FC-PH), dpANS, 1994
7 * dpANS Fibre Channel Protocol for SCSI (X3.269-199X), Rev. 012, 1995
8 * SOC+ Programming Guide 0.1
9 * Fibre Channel Arbitrated Loop (FC-AL), dpANS rev. 4.5, 1995
12 * On-board SOC+ adapters of Ultra Enterprise servers and sun4d.
15 static char *version =
16 "socal.c: SOC+ driver v1.1 9/Feb/99 Jakub Jelinek (jj@ultra.linux.cz)\n";
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/types.h>
22 #include <linux/fcntl.h>
23 #include <linux/interrupt.h>
24 #include <linux/ptrace.h>
25 #include <linux/ioport.h>
27 #include <linux/slab.h>
28 #include <linux/string.h>
29 #include <linux/init.h>
30 #include <linux/bitops.h>
31 #include <asm/system.h>
34 #include <linux/errno.h>
35 #include <asm/byteorder.h>
37 #include <asm/openprom.h>
38 #include <asm/oplib.h>
39 #include <asm/pgtable.h>
42 /* #define SOCALDEBUG */
43 /* #define HAVE_SOCAL_UCODE */
44 /* #define USE_64BIT_MODE */
48 #ifdef HAVE_SOCAL_UCODE
49 #include "socal_asm.h"
52 #define socal_printk printk ("socal%d: ", s->socal_no); printk
55 #define SOD(x) socal_printk x;
60 #define for_each_socal(s) for (s = socals; s; s = s->next)
61 struct socal *socals = NULL;
63 static void socal_copy_from_xram(void *d, void __iomem *xram, long size)
67 *dp++ = sbus_readl(xram);
73 static void socal_copy_to_xram(void __iomem *xram, void *s, long size)
78 sbus_writel(val, xram);
84 #ifdef HAVE_SOCAL_UCODE
85 static void socal_bzero(unsigned long xram, int size)
95 static inline void socal_disable(struct socal *s)
97 sbus_writel(0, s->regs + IMASK);
98 sbus_writel(SOCAL_CMD_SOFT_RESET, s->regs + CMD);
101 static inline void socal_enable(struct socal *s)
103 SOD(("enable %08x\n", s->cfg))
104 sbus_writel(0, s->regs + SAE);
105 sbus_writel(s->cfg, s->regs + CFG);
106 sbus_writel(SOCAL_CMD_RSP_QALL, s->regs + CMD);
107 SOCAL_SETIMASK(s, SOCAL_IMASK_RSP_QALL | SOCAL_IMASK_SAE);
108 SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
111 static void socal_reset(fc_channel *fc)
113 socal_port *port = (socal_port *)fc;
114 struct socal *s = port->s;
135 static inline void socal_solicited(struct socal *s, unsigned long qno)
143 sw_cq = &s->rsp[qno];
145 /* Finally an improvement against old SOC :) */
146 sw_cq->in = sbus_readb(s->regs + RESP + qno);
147 SOD (("socal_solicited, %d packets arrived\n",
148 (sw_cq->in - sw_cq->out) & sw_cq->last))
150 hwrsp = (socal_rsp *)sw_cq->pool + sw_cq->out;
151 SOD(("hwrsp %p out %d\n", hwrsp, sw_cq->out))
153 #if defined(SOCALDEBUG) && 0
155 u32 *u = (u32 *)hwrsp;
156 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
157 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
159 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
160 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
162 while (u < ((u32 *)s->regs)) {
163 if (sbus_readl(&u[0]) == 0x00003000 ||
164 sbus_readl(&u[0]) == 0x00003801) {
165 SOD(("Found at %04lx\n",
166 (unsigned long)u - (unsigned long)s->xram))
167 SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
168 sbus_readl(&u[0]), sbus_readl(&u[1]),
169 sbus_readl(&u[2]), sbus_readl(&u[3]),
170 sbus_readl(&u[4]), sbus_readl(&u[5]),
171 sbus_readl(&u[6]), sbus_readl(&u[7])))
173 SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
174 sbus_readl(&u[0]), sbus_readl(&u[1]),
175 sbus_readl(&u[2]), sbus_readl(&u[3]),
176 sbus_readl(&u[4]), sbus_readl(&u[5]),
177 sbus_readl(&u[6]), sbus_readl(&u[7])))
185 token = hwrsp->shdr.token;
186 status = hwrsp->status;
187 fc = (fc_channel *)(&s->port[(token >> 11) & 1]);
189 SOD(("Solicited token %08x status %08x\n", token, status))
190 if (status == SOCAL_OK) {
191 fcp_receive_solicited(fc, token >> 12,
192 token & ((1 << 11) - 1),
195 /* We have intentionally defined FC_STATUS_* constants
196 * to match SOCAL_* constants, otherwise we'd have to
199 fcp_receive_solicited(fc, token >> 12,
200 token & ((1 << 11) - 1), status, &hwrsp->fchdr);
203 if (++sw_cq->out > sw_cq->last) {
208 if (sw_cq->out == sw_cq->in) {
209 sw_cq->in = sbus_readb(s->regs + RESP + qno);
210 if (sw_cq->out == sw_cq->in) {
211 /* Tell the hardware about it */
212 sbus_writel((sw_cq->out << 24) |
213 (SOCAL_CMD_RSP_QALL &
214 ~(SOCAL_CMD_RSP_Q0 << qno)),
217 /* Read it, so that we're sure it has been updated */
218 sbus_readl(s->regs + CMD);
219 sw_cq->in = sbus_readb(s->regs + RESP + qno);
220 if (sw_cq->out == sw_cq->in)
227 static inline void socal_request (struct socal *s, u32 cmd)
229 SOCAL_SETIMASK(s, s->imask & ~(cmd & SOCAL_CMD_REQ_QALL));
230 SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
232 SOD(("Queues available %08x OUT %X\n", cmd, s->regs->reqpr[0]))
233 if (s->port[s->curr_port].fc.state != FC_STATE_OFFLINE) {
234 fcp_queue_empty ((fc_channel *)&(s->port[s->curr_port]));
235 if (((s->req[1].in + 1) & s->req[1].last) != (s->req[1].out))
236 fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
238 fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
240 if (s->port[1 - s->curr_port].fc.state != FC_STATE_OFFLINE)
244 static inline void socal_unsolicited (struct socal *s, unsigned long qno)
246 socal_rsp *hwrsp, *hwrspc;
253 sw_cq = &s->rsp[qno];
255 sw_cq->in = sbus_readb(s->regs + RESP + qno);
256 SOD (("socal_unsolicited, %d packets arrived, in %d\n",
257 (sw_cq->in - sw_cq->out) & sw_cq->last, sw_cq->in))
258 while (sw_cq->in != sw_cq->out) {
259 /* ...real work per entry here... */
260 hwrsp = (socal_rsp *)sw_cq->pool + sw_cq->out;
261 SOD(("hwrsp %p out %d\n", hwrsp, sw_cq->out))
263 #if defined(SOCALDEBUG) && 0
265 u32 *u = (u32 *)hwrsp;
266 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
267 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
269 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
270 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
275 flags = hwrsp->shdr.flags;
276 count = hwrsp->count;
277 fc = (fc_channel *)&s->port[flags & SOCAL_PORT_B];
278 SOD(("FC %08lx\n", (long)fc))
281 /* Ugh, continuation entries */
285 printk("%s: Too many continuations entries %d\n",
292 in += sw_cq->last + 1;
293 if (in < sw_cq->out + 2) {
294 /* Ask the hardware if they haven't arrived yet. */
295 sbus_writel((sw_cq->out << 24) |
296 (SOCAL_CMD_RSP_QALL &
297 ~(SOCAL_CMD_RSP_Q0 << qno)),
300 /* Read it, so that we're sure it has been updated */
301 sbus_readl(s->regs + CMD);
302 sw_cq->in = sbus_readb(s->regs + RESP + qno);
305 in += sw_cq->last + 1;
306 if (in < sw_cq->out + 2) /* Nothing came, let us wait */
309 if (sw_cq->out == sw_cq->last)
310 hwrspc = (socal_rsp *)sw_cq->pool;
315 switch (flags & ~SOCAL_PORT_B) {
317 status = hwrsp->status;
320 SOD(("State change to ONLINE\n"));
321 fcp_state_change(fc, FC_STATE_ONLINE);
323 case SOCAL_ONLINE_LOOP:
324 SOD(("State change to ONLINE_LOOP\n"));
325 fcp_state_change(fc, FC_STATE_ONLINE);
328 SOD(("State change to OFFLINE\n"));
329 fcp_state_change(fc, FC_STATE_OFFLINE);
332 printk ("%s: Unknown STATUS no %d\n",
338 case (SOCAL_UNSOLICITED|SOCAL_FC_HDR):
340 int r_ctl = *((u8 *)&hwrsp->fchdr);
343 if ((r_ctl & 0xf0) == R_CTL_EXTENDED_SVC) {
344 len = hwrsp->shdr.bytecnt;
345 if (len < 4 || !hwrspc) {
346 printk ("%s: Invalid R_CTL %02x "
347 "continuation entries\n",
352 if (*(u32 *)hwrspc == LS_DISPLAY) {
355 for (i = 4; i < len; i++)
356 if (((u8 *)hwrspc)[i] == '\n')
357 ((u8 *)hwrspc)[i] = ' ';
358 ((u8 *)hwrspc)[len] = 0;
359 printk ("%s message: %s\n",
360 fc->name, ((u8 *)hwrspc) + 4);
362 printk ("%s: Unknown LS_CMD "
368 printk ("%s: Unsolicited R_CTL %02x "
369 "not handled\n", fc->name, r_ctl);
374 printk ("%s: Unexpected flags %08x\n", fc->name, flags);
378 if (++sw_cq->out > sw_cq->last) {
384 if (++sw_cq->out > sw_cq->last) {
390 if (sw_cq->out == sw_cq->in) {
391 sw_cq->in = sbus_readb(s->regs + RESP + qno);
392 if (sw_cq->out == sw_cq->in) {
393 /* Tell the hardware about it */
394 sbus_writel((sw_cq->out << 24) |
395 (SOCAL_CMD_RSP_QALL &
396 ~(SOCAL_CMD_RSP_Q0 << qno)),
399 /* Read it, so that we're sure it has been updated */
400 sbus_readl(s->regs + CMD);
401 sw_cq->in = sbus_readb(s->regs + RESP + qno);
407 static irqreturn_t socal_intr(int irq, void *dev_id)
411 register struct socal *s = (struct socal *)dev_id;
413 spin_lock_irqsave(&s->lock, flags);
414 cmd = sbus_readl(s->regs + CMD);
415 for (; (cmd = SOCAL_INTR (s, cmd)); cmd = sbus_readl(s->regs + CMD)) {
419 printk("soc_intr %08x\n", cmd);
421 if (cmd & SOCAL_CMD_RSP_Q2)
422 socal_unsolicited (s, SOCAL_UNSOLICITED_RSP_Q);
423 if (cmd & SOCAL_CMD_RSP_Q1)
424 socal_unsolicited (s, SOCAL_SOLICITED_BAD_RSP_Q);
425 if (cmd & SOCAL_CMD_RSP_Q0)
426 socal_solicited (s, SOCAL_SOLICITED_RSP_Q);
427 if (cmd & SOCAL_CMD_REQ_QALL)
428 socal_request (s, cmd);
430 spin_unlock_irqrestore(&s->lock, flags);
435 #define TOKEN(proto, port, token) (((proto)<<12)|(token)|(port))
437 static int socal_hw_enque (fc_channel *fc, fcp_cmnd *fcmd)
439 socal_port *port = (socal_port *)fc;
440 struct socal *s = port->s;
448 if (fcmd->proto == TYPE_SCSI_FCP)
452 SOD(("Putting a FCP packet type %d into hw queue %d\n", fcmd->proto, qno))
453 if (s->imask & (SOCAL_IMASK_REQ_Q0 << qno)) {
454 SOD(("EIO %08x\n", s->imask))
457 sw_cq = s->req + qno;
458 cq_next_in = (sw_cq->in + 1) & sw_cq->last;
460 if (cq_next_in == sw_cq->out &&
461 cq_next_in == (sw_cq->out = sbus_readb(s->regs + REQP + qno))) {
462 SOD(("%d IN %d OUT %d LAST %d\n",
464 sw_cq->out, sw_cq->last))
465 SOCAL_SETIMASK(s, s->imask | (SOCAL_IMASK_REQ_Q0 << qno));
466 SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
468 /* If queue is full, just say NO. */
472 request = sw_cq->pool + sw_cq->in;
473 fch = &request->fchdr;
475 switch (fcmd->proto) {
477 request->shdr.token = TOKEN(TYPE_SCSI_FCP, port->mask, fcmd->token);
478 request->data[0].base = fc->dma_scsi_cmd + fcmd->token * sizeof(fcp_cmd);
479 request->data[0].count = sizeof(fcp_cmd);
480 request->data[1].base = fc->dma_scsi_rsp + fcmd->token * fc->rsp_size;
481 request->data[1].count = fc->rsp_size;
483 request->shdr.segcnt = 3;
484 i = fc->scsi_cmd_pool[fcmd->token].fcp_data_len;
485 request->shdr.bytecnt = i;
486 request->data[2].base = fcmd->data;
487 request->data[2].count = i;
488 request->type = (fc->scsi_cmd_pool[fcmd->token].fcp_cntl & FCP_CNTL_WRITE) ?
489 SOCAL_CQTYPE_IO_WRITE : SOCAL_CQTYPE_IO_READ;
491 request->shdr.segcnt = 2;
492 request->shdr.bytecnt = 0;
493 request->data[2].base = 0;
494 request->data[2].count = 0;
495 request->type = SOCAL_CQTYPE_SIMPLE;
497 FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fcmd->did);
498 FILL_FCHDR_SID(fch, fc->sid);
499 FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
500 FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
501 FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
503 request->shdr.flags = port->flags;
504 request->shdr.class = fc->posmap ? 3 : 2;
508 memset (request, 0, sizeof(*request));
509 request->shdr.token = TOKEN(PROTO_OFFLINE, port->mask, fcmd->token);
510 request->type = SOCAL_CQTYPE_OFFLINE;
511 FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fcmd->did);
512 FILL_FCHDR_SID(fch, fc->sid);
513 FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
514 FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
515 FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
516 request->shdr.flags = port->flags;
519 case PROTO_REPORT_AL_MAP:
520 memset (request, 0, sizeof(*request));
521 request->shdr.token = TOKEN(PROTO_REPORT_AL_MAP, port->mask, fcmd->token);
522 request->type = SOCAL_CQTYPE_REPORT_MAP;
523 request->shdr.flags = port->flags;
524 request->shdr.segcnt = 1;
525 request->shdr.bytecnt = sizeof(fc_al_posmap);
526 request->data[0].base = fcmd->cmd;
527 request->data[0].count = sizeof(fc_al_posmap);
531 request->shdr.token = TOKEN(fcmd->proto, port->mask, fcmd->token);
532 request->shdr.class = fc->posmap ? 3 : 2;
533 request->shdr.flags = port->flags;
534 memcpy (fch, &fcmd->fch, sizeof(fc_hdr));
535 request->data[0].count = fcmd->cmdlen;
536 request->data[1].count = fcmd->rsplen;
537 request->type = fcmd->class;
538 switch (fcmd->class) {
539 case FC_CLASS_OUTBOUND:
540 request->data[0].base = fcmd->cmd;
541 request->data[0].count = fcmd->cmdlen;
542 request->type = SOCAL_CQTYPE_OUTBOUND;
543 request->shdr.bytecnt = fcmd->cmdlen;
544 request->shdr.segcnt = 1;
546 case FC_CLASS_INBOUND:
547 request->data[0].base = fcmd->rsp;
548 request->data[0].count = fcmd->rsplen;
549 request->type = SOCAL_CQTYPE_INBOUND;
550 request->shdr.bytecnt = 0;
551 request->shdr.segcnt = 1;
553 case FC_CLASS_SIMPLE:
554 request->data[0].base = fcmd->cmd;
555 request->data[1].base = fcmd->rsp;
556 request->data[0].count = fcmd->cmdlen;
557 request->data[1].count = fcmd->rsplen;
558 request->type = SOCAL_CQTYPE_SIMPLE;
559 request->shdr.bytecnt = fcmd->cmdlen;
560 request->shdr.segcnt = 2;
562 case FC_CLASS_IO_READ:
563 case FC_CLASS_IO_WRITE:
564 request->data[0].base = fcmd->cmd;
565 request->data[1].base = fcmd->rsp;
566 request->data[0].count = fcmd->cmdlen;
567 request->data[1].count = fcmd->rsplen;
568 request->type = (fcmd->class == FC_CLASS_IO_READ) ? SOCAL_CQTYPE_IO_READ : SOCAL_CQTYPE_IO_WRITE;
570 request->data[2].base = fcmd->data;
571 request->data[2].count = fcmd->datalen;
572 request->shdr.bytecnt = fcmd->datalen;
573 request->shdr.segcnt = 3;
575 request->shdr.bytecnt = 0;
576 request->shdr.segcnt = 2;
585 request->seqno = sw_cq->seqno;
587 SOD(("queueing token %08x\n", request->shdr.token))
589 /* And now tell the SOCAL about it */
591 if (++sw_cq->in > sw_cq->last) {
596 SOD(("Putting %08x into cmd\n", SOCAL_CMD_RSP_QALL | (sw_cq->in << 24) | (SOCAL_CMD_REQ_Q0 << qno)))
598 sbus_writel(SOCAL_CMD_RSP_QALL | (sw_cq->in << 24) | (SOCAL_CMD_REQ_Q0 << qno),
601 /* Read so that command is completed */
602 sbus_readl(s->regs + CMD);
607 static inline void socal_download_fw(struct socal *s)
609 #ifdef HAVE_SOCAL_UCODE
610 SOD(("Loading %ld bytes from %p to %p\n", sizeof(socal_ucode), socal_ucode, s->xram))
611 socal_copy_to_xram(s->xram, socal_ucode, sizeof(socal_ucode));
612 SOD(("Clearing the rest of memory\n"))
613 socal_bzero (s->xram + sizeof(socal_ucode), 65536 - sizeof(socal_ucode));
618 /* Check for what the best SBUS burst we can use happens
619 * to be on this machine.
621 static inline void socal_init_bursts(struct socal *s, struct sbus_dev *sdev)
623 int bsizes, bsizes_more;
626 bsizes = (prom_getintdefault(sdev->prom_node,"burst-sizes",0xff) & 0xff);
627 bsizes_more = (prom_getintdefault(sdev->bus->prom_node, "burst-sizes", 0xff) & 0xff);
628 bsizes &= bsizes_more;
629 #ifdef USE_64BIT_MODE
631 mmu_set_sbus64(sdev, bsizes >> 16);
634 if ((bsizes & 0x7f) == 0x7f)
635 cfg = SOCAL_CFG_BURST_64;
636 else if ((bsizes & 0x3f) == 0x3f)
637 cfg = SOCAL_CFG_BURST_32;
638 else if ((bsizes & 0x1f) == 0x1f)
639 cfg = SOCAL_CFG_BURST_16;
641 cfg = SOCAL_CFG_BURST_4;
642 #ifdef USE_64BIT_MODE
644 /* What is BURST_128? -jj */
645 if ((bsizes & 0x780000) == 0x780000)
646 cfg |= (SOCAL_CFG_BURST_64 << 8) | SOCAL_CFG_SBUS_ENHANCED;
647 else if ((bsizes & 0x380000) == 0x380000)
648 cfg |= (SOCAL_CFG_BURST_32 << 8) | SOCAL_CFG_SBUS_ENHANCED;
649 else if ((bsizes & 0x180000) == 0x180000)
650 cfg |= (SOCAL_CFG_BURST_16 << 8) | SOCAL_CFG_SBUS_ENHANCED;
652 cfg |= (SOCAL_CFG_BURST_8 << 8) | SOCAL_CFG_SBUS_ENHANCED;
658 static inline void socal_init(struct sbus_dev *sdev, int no)
660 unsigned char tmp[60];
663 static unsigned version_printed = 0;
668 s = kzalloc (sizeof (struct socal), GFP_KERNEL);
670 spin_lock_init(&s->lock);
673 SOD(("socals %08lx socal_intr %08lx socal_hw_enque %08lx\n",
674 (long)socals, (long)socal_intr, (long)socal_hw_enque))
675 if (version_printed++ == 0)
678 s->port[0].fc.module = THIS_MODULE;
679 s->port[1].fc.module = THIS_MODULE;
683 s->port[0].fc.dev = sdev;
684 s->port[1].fc.dev = sdev;
688 s->port[0].fc.next = &s->port[1].fc;
690 /* World Wide Name of SOCAL */
691 propl = prom_getproperty (sdev->prom_node, "wwn", tmp, sizeof(tmp));
692 if (propl != sizeof (fc_wwn)) {
693 s->wwn.naaid = NAAID_IEEE_REG;
694 s->wwn.nportid = 0x123;
696 s->wwn.lo = 0x12345678;
698 memcpy (&s->wwn, tmp, sizeof (fc_wwn));
700 memcpy (&s->port[0].fc.wwn_nport, &s->wwn, sizeof (fc_wwn));
701 s->port[0].fc.wwn_nport.lo++;
702 memcpy (&s->port[1].fc.wwn_nport, &s->wwn, sizeof (fc_wwn));
703 s->port[1].fc.wwn_nport.lo+=2;
705 node = prom_getchild (sdev->prom_node);
706 while (node && (node = prom_searchsiblings (node, "sf"))) {
709 port = prom_getintdefault(node, "port#", -1);
713 if (prom_getproplen(node, "port-wwn") == sizeof (fc_wwn))
714 prom_getproperty (node, "port-wwn",
715 (char *)&s->port[port].fc.wwn_nport,
722 node = prom_getsibling(node);
725 memcpy (&s->port[0].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
726 memcpy (&s->port[1].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
727 SOD(("Got wwns %08x%08x ports %08x%08x and %08x%08x\n",
728 *(u32 *)&s->port[0].fc.wwn_node, s->port[0].fc.wwn_node.lo,
729 *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
730 *(u32 *)&s->port[1].fc.wwn_nport, s->port[1].fc.wwn_nport.lo))
732 s->port[0].fc.sid = 1;
733 s->port[1].fc.sid = 17;
734 s->port[0].fc.did = 2;
735 s->port[1].fc.did = 18;
737 s->port[0].fc.reset = socal_reset;
738 s->port[1].fc.reset = socal_reset;
740 if (sdev->num_registers == 1) {
741 s->eeprom = sbus_ioremap(&sdev->resource[0], 0,
742 sdev->reg_addrs[0].reg_size, "socal xram");
743 if (sdev->reg_addrs[0].reg_size > 0x20000)
744 s->xram = s->eeprom + 0x10000UL;
747 s->regs = (s->xram + 0x10000UL);
749 /* E.g. starfire presents 3 registers for SOCAL */
750 s->xram = sbus_ioremap(&sdev->resource[1], 0,
751 sdev->reg_addrs[1].reg_size, "socal xram");
752 s->regs = sbus_ioremap(&sdev->resource[2], 0,
753 sdev->reg_addrs[2].reg_size, "socal regs");
756 socal_init_bursts(s, sdev);
758 SOD(("Disabling SOCAL\n"))
764 if (request_irq (irq, socal_intr, IRQF_SHARED, "SOCAL", (void *)s)) {
765 socal_printk ("Cannot order irq %d to go\n", irq);
770 SOD(("SOCAL uses IRQ %d\n", irq))
772 s->port[0].fc.irq = irq;
773 s->port[1].fc.irq = irq;
775 sprintf (s->port[0].fc.name, "socal%d port A", no);
776 sprintf (s->port[1].fc.name, "socal%d port B", no);
777 s->port[0].flags = SOCAL_FC_HDR | SOCAL_PORT_A;
778 s->port[1].flags = SOCAL_FC_HDR | SOCAL_PORT_B;
779 s->port[1].mask = (1 << 11);
781 s->port[0].fc.hw_enque = socal_hw_enque;
782 s->port[1].fc.hw_enque = socal_hw_enque;
784 socal_download_fw (s);
786 SOD(("Downloaded firmware\n"))
788 /* Now setup xram circular queues */
789 memset (cq, 0, sizeof(cq));
791 size = (SOCAL_CQ_REQ0_SIZE + SOCAL_CQ_REQ1_SIZE +
792 SOCAL_CQ_RSP0_SIZE + SOCAL_CQ_RSP1_SIZE +
793 SOCAL_CQ_RSP2_SIZE) * sizeof(socal_req);
794 s->req_cpu = sbus_alloc_consistent(sdev, size, &s->req_dvma);
795 s->req[0].pool = s->req_cpu;
796 cq[0].address = s->req_dvma;
797 s->req[1].pool = s->req[0].pool + SOCAL_CQ_REQ0_SIZE;
798 s->rsp[0].pool = s->req[1].pool + SOCAL_CQ_REQ1_SIZE;
799 s->rsp[1].pool = s->rsp[0].pool + SOCAL_CQ_RSP0_SIZE;
800 s->rsp[2].pool = s->rsp[1].pool + SOCAL_CQ_RSP1_SIZE;
802 s->req[0].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_REQ_OFFSET);
803 s->req[1].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_REQ_OFFSET + sizeof(socal_hw_cq));
804 s->rsp[0].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET);
805 s->rsp[1].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET + sizeof(socal_hw_cq));
806 s->rsp[2].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET + 2 * sizeof(socal_hw_cq));
808 cq[1].address = cq[0].address + (SOCAL_CQ_REQ0_SIZE * sizeof(socal_req));
809 cq[4].address = cq[1].address + (SOCAL_CQ_REQ1_SIZE * sizeof(socal_req));
810 cq[5].address = cq[4].address + (SOCAL_CQ_RSP0_SIZE * sizeof(socal_req));
811 cq[6].address = cq[5].address + (SOCAL_CQ_RSP1_SIZE * sizeof(socal_req));
813 cq[0].last = SOCAL_CQ_REQ0_SIZE - 1;
814 cq[1].last = SOCAL_CQ_REQ1_SIZE - 1;
815 cq[4].last = SOCAL_CQ_RSP0_SIZE - 1;
816 cq[5].last = SOCAL_CQ_RSP1_SIZE - 1;
817 cq[6].last = SOCAL_CQ_RSP2_SIZE - 1;
818 for (i = 0; i < 8; i++)
821 s->req[0].last = SOCAL_CQ_REQ0_SIZE - 1;
822 s->req[1].last = SOCAL_CQ_REQ1_SIZE - 1;
823 s->rsp[0].last = SOCAL_CQ_RSP0_SIZE - 1;
824 s->rsp[1].last = SOCAL_CQ_RSP1_SIZE - 1;
825 s->rsp[2].last = SOCAL_CQ_RSP2_SIZE - 1;
833 socal_copy_to_xram(s->xram + SOCAL_CQ_REQ_OFFSET, cq, sizeof(cq));
835 SOD(("Setting up params\n"))
837 /* Make our sw copy of SOCAL service parameters */
838 socal_copy_from_xram(s->serv_params, s->xram + 0x280, sizeof (s->serv_params));
840 s->port[0].fc.common_svc = (common_svc_parm *)s->serv_params;
841 s->port[0].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
842 s->port[1].fc.common_svc = (common_svc_parm *)&s->serv_params;
843 s->port[1].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
847 SOD(("Enabled SOCAL\n"))
850 static int __init socal_probe(void)
852 struct sbus_bus *sbus;
853 struct sbus_dev *sdev = NULL;
857 for_each_sbus(sbus) {
858 for_each_sbusdev(sdev, sbus) {
859 if(!strcmp(sdev->prom_name, "SUNW,socal")) {
860 socal_init(sdev, cards);
870 s->port[1].fc.next = &s->next->port[0].fc;
872 fcp_init (&socals->port[0].fc);
876 static void __exit socal_cleanup(void)
880 struct sbus_dev *sdev;
883 irq = s->port[0].fc.irq;
886 fcp_release(&(s->port[0].fc), 2);
888 sdev = s->port[0].fc.dev;
889 if (sdev->num_registers == 1) {
890 sbus_iounmap(s->eeprom, sdev->reg_addrs[0].reg_size);
892 sbus_iounmap(s->xram, sdev->reg_addrs[1].reg_size);
893 sbus_iounmap(s->regs, sdev->reg_addrs[2].reg_size);
895 sbus_free_consistent(sdev,
896 (SOCAL_CQ_REQ0_SIZE + SOCAL_CQ_REQ1_SIZE +
897 SOCAL_CQ_RSP0_SIZE + SOCAL_CQ_RSP1_SIZE +
898 SOCAL_CQ_RSP2_SIZE) * sizeof(socal_req),
899 s->req_cpu, s->req_dvma);
903 module_init(socal_probe);
904 module_exit(socal_cleanup);
905 MODULE_LICENSE("GPL");