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/types.h>
21 #include <linux/fcntl.h>
22 #include <linux/interrupt.h>
23 #include <linux/ptrace.h>
24 #include <linux/ioport.h>
26 #include <linux/slab.h>
27 #include <linux/string.h>
28 #include <linux/init.h>
29 #include <linux/bitops.h>
30 #include <asm/system.h>
33 #include <linux/errno.h>
34 #include <asm/byteorder.h>
36 #include <asm/openprom.h>
37 #include <asm/oplib.h>
38 #include <asm/pgtable.h>
41 /* #define SOCALDEBUG */
42 /* #define HAVE_SOCAL_UCODE */
43 /* #define USE_64BIT_MODE */
47 #ifdef HAVE_SOCAL_UCODE
48 #include "socal_asm.h"
51 #define socal_printk printk ("socal%d: ", s->socal_no); printk
54 #define SOD(x) socal_printk x;
59 #define for_each_socal(s) for (s = socals; s; s = s->next)
60 struct socal *socals = NULL;
62 static void socal_copy_from_xram(void *d, void __iomem *xram, long size)
66 *dp++ = sbus_readl(xram);
72 static void socal_copy_to_xram(void __iomem *xram, void *s, long size)
77 sbus_writel(val, xram);
83 #ifdef HAVE_SOCAL_UCODE
84 static void socal_bzero(unsigned long xram, int size)
94 static inline void socal_disable(struct socal *s)
96 sbus_writel(0, s->regs + IMASK);
97 sbus_writel(SOCAL_CMD_SOFT_RESET, s->regs + CMD);
100 static inline void socal_enable(struct socal *s)
102 SOD(("enable %08x\n", s->cfg))
103 sbus_writel(0, s->regs + SAE);
104 sbus_writel(s->cfg, s->regs + CFG);
105 sbus_writel(SOCAL_CMD_RSP_QALL, s->regs + CMD);
106 SOCAL_SETIMASK(s, SOCAL_IMASK_RSP_QALL | SOCAL_IMASK_SAE);
107 SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
110 static void socal_reset(fc_channel *fc)
112 socal_port *port = (socal_port *)fc;
113 struct socal *s = port->s;
134 static inline void socal_solicited(struct socal *s, unsigned long qno)
142 sw_cq = &s->rsp[qno];
144 /* Finally an improvement against old SOC :) */
145 sw_cq->in = sbus_readb(s->regs + RESP + qno);
146 SOD (("socal_solicited, %d packets arrived\n",
147 (sw_cq->in - sw_cq->out) & sw_cq->last))
149 hwrsp = (socal_rsp *)sw_cq->pool + sw_cq->out;
150 SOD(("hwrsp %p out %d\n", hwrsp, sw_cq->out))
152 #if defined(SOCALDEBUG) && 0
154 u32 *u = (u32 *)hwrsp;
155 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
156 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
158 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
159 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
161 while (u < ((u32 *)s->regs)) {
162 if (sbus_readl(&u[0]) == 0x00003000 ||
163 sbus_readl(&u[0]) == 0x00003801) {
164 SOD(("Found at %04lx\n",
165 (unsigned long)u - (unsigned long)s->xram))
166 SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
167 sbus_readl(&u[0]), sbus_readl(&u[1]),
168 sbus_readl(&u[2]), sbus_readl(&u[3]),
169 sbus_readl(&u[4]), sbus_readl(&u[5]),
170 sbus_readl(&u[6]), sbus_readl(&u[7])))
172 SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
173 sbus_readl(&u[0]), sbus_readl(&u[1]),
174 sbus_readl(&u[2]), sbus_readl(&u[3]),
175 sbus_readl(&u[4]), sbus_readl(&u[5]),
176 sbus_readl(&u[6]), sbus_readl(&u[7])))
184 token = hwrsp->shdr.token;
185 status = hwrsp->status;
186 fc = (fc_channel *)(&s->port[(token >> 11) & 1]);
188 SOD(("Solicited token %08x status %08x\n", token, status))
189 if (status == SOCAL_OK) {
190 fcp_receive_solicited(fc, token >> 12,
191 token & ((1 << 11) - 1),
194 /* We have intentionally defined FC_STATUS_* constants
195 * to match SOCAL_* constants, otherwise we'd have to
198 fcp_receive_solicited(fc, token >> 12,
199 token & ((1 << 11) - 1), status, &hwrsp->fchdr);
202 if (++sw_cq->out > sw_cq->last) {
207 if (sw_cq->out == sw_cq->in) {
208 sw_cq->in = sbus_readb(s->regs + RESP + qno);
209 if (sw_cq->out == sw_cq->in) {
210 /* Tell the hardware about it */
211 sbus_writel((sw_cq->out << 24) |
212 (SOCAL_CMD_RSP_QALL &
213 ~(SOCAL_CMD_RSP_Q0 << qno)),
216 /* Read it, so that we're sure it has been updated */
217 sbus_readl(s->regs + CMD);
218 sw_cq->in = sbus_readb(s->regs + RESP + qno);
219 if (sw_cq->out == sw_cq->in)
226 static inline void socal_request (struct socal *s, u32 cmd)
228 SOCAL_SETIMASK(s, s->imask & ~(cmd & SOCAL_CMD_REQ_QALL));
229 SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
231 SOD(("Queues available %08x OUT %X\n", cmd, s->regs->reqpr[0]))
232 if (s->port[s->curr_port].fc.state != FC_STATE_OFFLINE) {
233 fcp_queue_empty ((fc_channel *)&(s->port[s->curr_port]));
234 if (((s->req[1].in + 1) & s->req[1].last) != (s->req[1].out))
235 fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
237 fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
239 if (s->port[1 - s->curr_port].fc.state != FC_STATE_OFFLINE)
243 static inline void socal_unsolicited (struct socal *s, unsigned long qno)
245 socal_rsp *hwrsp, *hwrspc;
252 sw_cq = &s->rsp[qno];
254 sw_cq->in = sbus_readb(s->regs + RESP + qno);
255 SOD (("socal_unsolicited, %d packets arrived, in %d\n",
256 (sw_cq->in - sw_cq->out) & sw_cq->last, sw_cq->in))
257 while (sw_cq->in != sw_cq->out) {
258 /* ...real work per entry here... */
259 hwrsp = (socal_rsp *)sw_cq->pool + sw_cq->out;
260 SOD(("hwrsp %p out %d\n", hwrsp, sw_cq->out))
262 #if defined(SOCALDEBUG) && 0
264 u32 *u = (u32 *)hwrsp;
265 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
266 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
268 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
269 u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]))
274 flags = hwrsp->shdr.flags;
275 count = hwrsp->count;
276 fc = (fc_channel *)&s->port[flags & SOCAL_PORT_B];
277 SOD(("FC %08lx\n", (long)fc))
280 /* Ugh, continuation entries */
284 printk("%s: Too many continuations entries %d\n",
291 in += sw_cq->last + 1;
292 if (in < sw_cq->out + 2) {
293 /* Ask the hardware if they haven't arrived yet. */
294 sbus_writel((sw_cq->out << 24) |
295 (SOCAL_CMD_RSP_QALL &
296 ~(SOCAL_CMD_RSP_Q0 << qno)),
299 /* Read it, so that we're sure it has been updated */
300 sbus_readl(s->regs + CMD);
301 sw_cq->in = sbus_readb(s->regs + RESP + qno);
304 in += sw_cq->last + 1;
305 if (in < sw_cq->out + 2) /* Nothing came, let us wait */
308 if (sw_cq->out == sw_cq->last)
309 hwrspc = (socal_rsp *)sw_cq->pool;
314 switch (flags & ~SOCAL_PORT_B) {
316 status = hwrsp->status;
319 SOD(("State change to ONLINE\n"));
320 fcp_state_change(fc, FC_STATE_ONLINE);
322 case SOCAL_ONLINE_LOOP:
323 SOD(("State change to ONLINE_LOOP\n"));
324 fcp_state_change(fc, FC_STATE_ONLINE);
327 SOD(("State change to OFFLINE\n"));
328 fcp_state_change(fc, FC_STATE_OFFLINE);
331 printk ("%s: Unknown STATUS no %d\n",
337 case (SOCAL_UNSOLICITED|SOCAL_FC_HDR):
339 int r_ctl = *((u8 *)&hwrsp->fchdr);
342 if ((r_ctl & 0xf0) == R_CTL_EXTENDED_SVC) {
343 len = hwrsp->shdr.bytecnt;
344 if (len < 4 || !hwrspc) {
345 printk ("%s: Invalid R_CTL %02x "
346 "continuation entries\n",
351 if (*(u32 *)hwrspc == LS_DISPLAY) {
354 for (i = 4; i < len; i++)
355 if (((u8 *)hwrspc)[i] == '\n')
356 ((u8 *)hwrspc)[i] = ' ';
357 ((u8 *)hwrspc)[len] = 0;
358 printk ("%s message: %s\n",
359 fc->name, ((u8 *)hwrspc) + 4);
361 printk ("%s: Unknown LS_CMD "
367 printk ("%s: Unsolicited R_CTL %02x "
368 "not handled\n", fc->name, r_ctl);
373 printk ("%s: Unexpected flags %08x\n", fc->name, flags);
377 if (++sw_cq->out > sw_cq->last) {
383 if (++sw_cq->out > sw_cq->last) {
389 if (sw_cq->out == sw_cq->in) {
390 sw_cq->in = sbus_readb(s->regs + RESP + qno);
391 if (sw_cq->out == sw_cq->in) {
392 /* Tell the hardware about it */
393 sbus_writel((sw_cq->out << 24) |
394 (SOCAL_CMD_RSP_QALL &
395 ~(SOCAL_CMD_RSP_Q0 << qno)),
398 /* Read it, so that we're sure it has been updated */
399 sbus_readl(s->regs + CMD);
400 sw_cq->in = sbus_readb(s->regs + RESP + qno);
406 static irqreturn_t socal_intr(int irq, void *dev_id)
410 register struct socal *s = (struct socal *)dev_id;
412 spin_lock_irqsave(&s->lock, flags);
413 cmd = sbus_readl(s->regs + CMD);
414 for (; (cmd = SOCAL_INTR (s, cmd)); cmd = sbus_readl(s->regs + CMD)) {
418 printk("soc_intr %08x\n", cmd);
420 if (cmd & SOCAL_CMD_RSP_Q2)
421 socal_unsolicited (s, SOCAL_UNSOLICITED_RSP_Q);
422 if (cmd & SOCAL_CMD_RSP_Q1)
423 socal_unsolicited (s, SOCAL_SOLICITED_BAD_RSP_Q);
424 if (cmd & SOCAL_CMD_RSP_Q0)
425 socal_solicited (s, SOCAL_SOLICITED_RSP_Q);
426 if (cmd & SOCAL_CMD_REQ_QALL)
427 socal_request (s, cmd);
429 spin_unlock_irqrestore(&s->lock, flags);
434 #define TOKEN(proto, port, token) (((proto)<<12)|(token)|(port))
436 static int socal_hw_enque (fc_channel *fc, fcp_cmnd *fcmd)
438 socal_port *port = (socal_port *)fc;
439 struct socal *s = port->s;
447 if (fcmd->proto == TYPE_SCSI_FCP)
451 SOD(("Putting a FCP packet type %d into hw queue %d\n", fcmd->proto, qno))
452 if (s->imask & (SOCAL_IMASK_REQ_Q0 << qno)) {
453 SOD(("EIO %08x\n", s->imask))
456 sw_cq = s->req + qno;
457 cq_next_in = (sw_cq->in + 1) & sw_cq->last;
459 if (cq_next_in == sw_cq->out &&
460 cq_next_in == (sw_cq->out = sbus_readb(s->regs + REQP + qno))) {
461 SOD(("%d IN %d OUT %d LAST %d\n",
463 sw_cq->out, sw_cq->last))
464 SOCAL_SETIMASK(s, s->imask | (SOCAL_IMASK_REQ_Q0 << qno));
465 SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
467 /* If queue is full, just say NO. */
471 request = sw_cq->pool + sw_cq->in;
472 fch = &request->fchdr;
474 switch (fcmd->proto) {
476 request->shdr.token = TOKEN(TYPE_SCSI_FCP, port->mask, fcmd->token);
477 request->data[0].base = fc->dma_scsi_cmd + fcmd->token * sizeof(fcp_cmd);
478 request->data[0].count = sizeof(fcp_cmd);
479 request->data[1].base = fc->dma_scsi_rsp + fcmd->token * fc->rsp_size;
480 request->data[1].count = fc->rsp_size;
482 request->shdr.segcnt = 3;
483 i = fc->scsi_cmd_pool[fcmd->token].fcp_data_len;
484 request->shdr.bytecnt = i;
485 request->data[2].base = fcmd->data;
486 request->data[2].count = i;
487 request->type = (fc->scsi_cmd_pool[fcmd->token].fcp_cntl & FCP_CNTL_WRITE) ?
488 SOCAL_CQTYPE_IO_WRITE : SOCAL_CQTYPE_IO_READ;
490 request->shdr.segcnt = 2;
491 request->shdr.bytecnt = 0;
492 request->data[2].base = 0;
493 request->data[2].count = 0;
494 request->type = SOCAL_CQTYPE_SIMPLE;
496 FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fcmd->did);
497 FILL_FCHDR_SID(fch, fc->sid);
498 FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
499 FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
500 FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
502 request->shdr.flags = port->flags;
503 request->shdr.class = fc->posmap ? 3 : 2;
507 memset (request, 0, sizeof(*request));
508 request->shdr.token = TOKEN(PROTO_OFFLINE, port->mask, fcmd->token);
509 request->type = SOCAL_CQTYPE_OFFLINE;
510 FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fcmd->did);
511 FILL_FCHDR_SID(fch, fc->sid);
512 FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
513 FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
514 FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
515 request->shdr.flags = port->flags;
518 case PROTO_REPORT_AL_MAP:
519 memset (request, 0, sizeof(*request));
520 request->shdr.token = TOKEN(PROTO_REPORT_AL_MAP, port->mask, fcmd->token);
521 request->type = SOCAL_CQTYPE_REPORT_MAP;
522 request->shdr.flags = port->flags;
523 request->shdr.segcnt = 1;
524 request->shdr.bytecnt = sizeof(fc_al_posmap);
525 request->data[0].base = fcmd->cmd;
526 request->data[0].count = sizeof(fc_al_posmap);
530 request->shdr.token = TOKEN(fcmd->proto, port->mask, fcmd->token);
531 request->shdr.class = fc->posmap ? 3 : 2;
532 request->shdr.flags = port->flags;
533 memcpy (fch, &fcmd->fch, sizeof(fc_hdr));
534 request->data[0].count = fcmd->cmdlen;
535 request->data[1].count = fcmd->rsplen;
536 request->type = fcmd->class;
537 switch (fcmd->class) {
538 case FC_CLASS_OUTBOUND:
539 request->data[0].base = fcmd->cmd;
540 request->data[0].count = fcmd->cmdlen;
541 request->type = SOCAL_CQTYPE_OUTBOUND;
542 request->shdr.bytecnt = fcmd->cmdlen;
543 request->shdr.segcnt = 1;
545 case FC_CLASS_INBOUND:
546 request->data[0].base = fcmd->rsp;
547 request->data[0].count = fcmd->rsplen;
548 request->type = SOCAL_CQTYPE_INBOUND;
549 request->shdr.bytecnt = 0;
550 request->shdr.segcnt = 1;
552 case FC_CLASS_SIMPLE:
553 request->data[0].base = fcmd->cmd;
554 request->data[1].base = fcmd->rsp;
555 request->data[0].count = fcmd->cmdlen;
556 request->data[1].count = fcmd->rsplen;
557 request->type = SOCAL_CQTYPE_SIMPLE;
558 request->shdr.bytecnt = fcmd->cmdlen;
559 request->shdr.segcnt = 2;
561 case FC_CLASS_IO_READ:
562 case FC_CLASS_IO_WRITE:
563 request->data[0].base = fcmd->cmd;
564 request->data[1].base = fcmd->rsp;
565 request->data[0].count = fcmd->cmdlen;
566 request->data[1].count = fcmd->rsplen;
567 request->type = (fcmd->class == FC_CLASS_IO_READ) ? SOCAL_CQTYPE_IO_READ : SOCAL_CQTYPE_IO_WRITE;
569 request->data[2].base = fcmd->data;
570 request->data[2].count = fcmd->datalen;
571 request->shdr.bytecnt = fcmd->datalen;
572 request->shdr.segcnt = 3;
574 request->shdr.bytecnt = 0;
575 request->shdr.segcnt = 2;
584 request->seqno = sw_cq->seqno;
586 SOD(("queueing token %08x\n", request->shdr.token))
588 /* And now tell the SOCAL about it */
590 if (++sw_cq->in > sw_cq->last) {
595 SOD(("Putting %08x into cmd\n", SOCAL_CMD_RSP_QALL | (sw_cq->in << 24) | (SOCAL_CMD_REQ_Q0 << qno)))
597 sbus_writel(SOCAL_CMD_RSP_QALL | (sw_cq->in << 24) | (SOCAL_CMD_REQ_Q0 << qno),
600 /* Read so that command is completed */
601 sbus_readl(s->regs + CMD);
606 static inline void socal_download_fw(struct socal *s)
608 #ifdef HAVE_SOCAL_UCODE
609 SOD(("Loading %ld bytes from %p to %p\n", sizeof(socal_ucode), socal_ucode, s->xram))
610 socal_copy_to_xram(s->xram, socal_ucode, sizeof(socal_ucode));
611 SOD(("Clearing the rest of memory\n"))
612 socal_bzero (s->xram + sizeof(socal_ucode), 65536 - sizeof(socal_ucode));
617 /* Check for what the best SBUS burst we can use happens
618 * to be on this machine.
620 static inline void socal_init_bursts(struct socal *s, struct sbus_dev *sdev)
622 int bsizes, bsizes_more;
625 bsizes = (prom_getintdefault(sdev->prom_node,"burst-sizes",0xff) & 0xff);
626 bsizes_more = (prom_getintdefault(sdev->bus->prom_node, "burst-sizes", 0xff) & 0xff);
627 bsizes &= bsizes_more;
628 #ifdef USE_64BIT_MODE
630 mmu_set_sbus64(sdev, bsizes >> 16);
633 if ((bsizes & 0x7f) == 0x7f)
634 cfg = SOCAL_CFG_BURST_64;
635 else if ((bsizes & 0x3f) == 0x3f)
636 cfg = SOCAL_CFG_BURST_32;
637 else if ((bsizes & 0x1f) == 0x1f)
638 cfg = SOCAL_CFG_BURST_16;
640 cfg = SOCAL_CFG_BURST_4;
641 #ifdef USE_64BIT_MODE
643 /* What is BURST_128? -jj */
644 if ((bsizes & 0x780000) == 0x780000)
645 cfg |= (SOCAL_CFG_BURST_64 << 8) | SOCAL_CFG_SBUS_ENHANCED;
646 else if ((bsizes & 0x380000) == 0x380000)
647 cfg |= (SOCAL_CFG_BURST_32 << 8) | SOCAL_CFG_SBUS_ENHANCED;
648 else if ((bsizes & 0x180000) == 0x180000)
649 cfg |= (SOCAL_CFG_BURST_16 << 8) | SOCAL_CFG_SBUS_ENHANCED;
651 cfg |= (SOCAL_CFG_BURST_8 << 8) | SOCAL_CFG_SBUS_ENHANCED;
657 static inline void socal_init(struct sbus_dev *sdev, int no)
659 unsigned char tmp[60];
662 static unsigned version_printed = 0;
667 s = kzalloc (sizeof (struct socal), GFP_KERNEL);
669 spin_lock_init(&s->lock);
672 SOD(("socals %08lx socal_intr %08lx socal_hw_enque %08lx\n",
673 (long)socals, (long)socal_intr, (long)socal_hw_enque))
674 if (version_printed++ == 0)
677 s->port[0].fc.module = THIS_MODULE;
678 s->port[1].fc.module = THIS_MODULE;
682 s->port[0].fc.dev = sdev;
683 s->port[1].fc.dev = sdev;
687 s->port[0].fc.next = &s->port[1].fc;
689 /* World Wide Name of SOCAL */
690 propl = prom_getproperty (sdev->prom_node, "wwn", tmp, sizeof(tmp));
691 if (propl != sizeof (fc_wwn)) {
692 s->wwn.naaid = NAAID_IEEE_REG;
693 s->wwn.nportid = 0x123;
695 s->wwn.lo = 0x12345678;
697 memcpy (&s->wwn, tmp, sizeof (fc_wwn));
699 memcpy (&s->port[0].fc.wwn_nport, &s->wwn, sizeof (fc_wwn));
700 s->port[0].fc.wwn_nport.lo++;
701 memcpy (&s->port[1].fc.wwn_nport, &s->wwn, sizeof (fc_wwn));
702 s->port[1].fc.wwn_nport.lo+=2;
704 node = prom_getchild (sdev->prom_node);
705 while (node && (node = prom_searchsiblings (node, "sf"))) {
708 port = prom_getintdefault(node, "port#", -1);
712 if (prom_getproplen(node, "port-wwn") == sizeof (fc_wwn))
713 prom_getproperty (node, "port-wwn",
714 (char *)&s->port[port].fc.wwn_nport,
721 node = prom_getsibling(node);
724 memcpy (&s->port[0].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
725 memcpy (&s->port[1].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
726 SOD(("Got wwns %08x%08x ports %08x%08x and %08x%08x\n",
727 *(u32 *)&s->port[0].fc.wwn_node, s->port[0].fc.wwn_node.lo,
728 *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
729 *(u32 *)&s->port[1].fc.wwn_nport, s->port[1].fc.wwn_nport.lo))
731 s->port[0].fc.sid = 1;
732 s->port[1].fc.sid = 17;
733 s->port[0].fc.did = 2;
734 s->port[1].fc.did = 18;
736 s->port[0].fc.reset = socal_reset;
737 s->port[1].fc.reset = socal_reset;
739 if (sdev->num_registers == 1) {
740 s->eeprom = sbus_ioremap(&sdev->resource[0], 0,
741 sdev->reg_addrs[0].reg_size, "socal xram");
742 if (sdev->reg_addrs[0].reg_size > 0x20000)
743 s->xram = s->eeprom + 0x10000UL;
746 s->regs = (s->xram + 0x10000UL);
748 /* E.g. starfire presents 3 registers for SOCAL */
749 s->xram = sbus_ioremap(&sdev->resource[1], 0,
750 sdev->reg_addrs[1].reg_size, "socal xram");
751 s->regs = sbus_ioremap(&sdev->resource[2], 0,
752 sdev->reg_addrs[2].reg_size, "socal regs");
755 socal_init_bursts(s, sdev);
757 SOD(("Disabling SOCAL\n"))
763 if (request_irq (irq, socal_intr, IRQF_SHARED, "SOCAL", (void *)s)) {
764 socal_printk ("Cannot order irq %d to go\n", irq);
769 SOD(("SOCAL uses IRQ %d\n", irq))
771 s->port[0].fc.irq = irq;
772 s->port[1].fc.irq = irq;
774 sprintf (s->port[0].fc.name, "socal%d port A", no);
775 sprintf (s->port[1].fc.name, "socal%d port B", no);
776 s->port[0].flags = SOCAL_FC_HDR | SOCAL_PORT_A;
777 s->port[1].flags = SOCAL_FC_HDR | SOCAL_PORT_B;
778 s->port[1].mask = (1 << 11);
780 s->port[0].fc.hw_enque = socal_hw_enque;
781 s->port[1].fc.hw_enque = socal_hw_enque;
783 socal_download_fw (s);
785 SOD(("Downloaded firmware\n"))
787 /* Now setup xram circular queues */
788 memset (cq, 0, sizeof(cq));
790 size = (SOCAL_CQ_REQ0_SIZE + SOCAL_CQ_REQ1_SIZE +
791 SOCAL_CQ_RSP0_SIZE + SOCAL_CQ_RSP1_SIZE +
792 SOCAL_CQ_RSP2_SIZE) * sizeof(socal_req);
793 s->req_cpu = sbus_alloc_consistent(sdev, size, &s->req_dvma);
794 s->req[0].pool = s->req_cpu;
795 cq[0].address = s->req_dvma;
796 s->req[1].pool = s->req[0].pool + SOCAL_CQ_REQ0_SIZE;
797 s->rsp[0].pool = s->req[1].pool + SOCAL_CQ_REQ1_SIZE;
798 s->rsp[1].pool = s->rsp[0].pool + SOCAL_CQ_RSP0_SIZE;
799 s->rsp[2].pool = s->rsp[1].pool + SOCAL_CQ_RSP1_SIZE;
801 s->req[0].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_REQ_OFFSET);
802 s->req[1].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_REQ_OFFSET + sizeof(socal_hw_cq));
803 s->rsp[0].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET);
804 s->rsp[1].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET + sizeof(socal_hw_cq));
805 s->rsp[2].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET + 2 * sizeof(socal_hw_cq));
807 cq[1].address = cq[0].address + (SOCAL_CQ_REQ0_SIZE * sizeof(socal_req));
808 cq[4].address = cq[1].address + (SOCAL_CQ_REQ1_SIZE * sizeof(socal_req));
809 cq[5].address = cq[4].address + (SOCAL_CQ_RSP0_SIZE * sizeof(socal_req));
810 cq[6].address = cq[5].address + (SOCAL_CQ_RSP1_SIZE * sizeof(socal_req));
812 cq[0].last = SOCAL_CQ_REQ0_SIZE - 1;
813 cq[1].last = SOCAL_CQ_REQ1_SIZE - 1;
814 cq[4].last = SOCAL_CQ_RSP0_SIZE - 1;
815 cq[5].last = SOCAL_CQ_RSP1_SIZE - 1;
816 cq[6].last = SOCAL_CQ_RSP2_SIZE - 1;
817 for (i = 0; i < 8; i++)
820 s->req[0].last = SOCAL_CQ_REQ0_SIZE - 1;
821 s->req[1].last = SOCAL_CQ_REQ1_SIZE - 1;
822 s->rsp[0].last = SOCAL_CQ_RSP0_SIZE - 1;
823 s->rsp[1].last = SOCAL_CQ_RSP1_SIZE - 1;
824 s->rsp[2].last = SOCAL_CQ_RSP2_SIZE - 1;
832 socal_copy_to_xram(s->xram + SOCAL_CQ_REQ_OFFSET, cq, sizeof(cq));
834 SOD(("Setting up params\n"))
836 /* Make our sw copy of SOCAL service parameters */
837 socal_copy_from_xram(s->serv_params, s->xram + 0x280, sizeof (s->serv_params));
839 s->port[0].fc.common_svc = (common_svc_parm *)s->serv_params;
840 s->port[0].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
841 s->port[1].fc.common_svc = (common_svc_parm *)&s->serv_params;
842 s->port[1].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
846 SOD(("Enabled SOCAL\n"))
849 static int __init socal_probe(void)
851 struct sbus_bus *sbus;
852 struct sbus_dev *sdev = NULL;
856 for_each_sbus(sbus) {
857 for_each_sbusdev(sdev, sbus) {
858 if(!strcmp(sdev->prom_name, "SUNW,socal")) {
859 socal_init(sdev, cards);
869 s->port[1].fc.next = &s->next->port[0].fc;
871 fcp_init (&socals->port[0].fc);
875 static void __exit socal_cleanup(void)
879 struct sbus_dev *sdev;
882 irq = s->port[0].fc.irq;
885 fcp_release(&(s->port[0].fc), 2);
887 sdev = s->port[0].fc.dev;
888 if (sdev->num_registers == 1) {
889 sbus_iounmap(s->eeprom, sdev->reg_addrs[0].reg_size);
891 sbus_iounmap(s->xram, sdev->reg_addrs[1].reg_size);
892 sbus_iounmap(s->regs, sdev->reg_addrs[2].reg_size);
894 sbus_free_consistent(sdev,
895 (SOCAL_CQ_REQ0_SIZE + SOCAL_CQ_REQ1_SIZE +
896 SOCAL_CQ_RSP0_SIZE + SOCAL_CQ_RSP1_SIZE +
897 SOCAL_CQ_RSP2_SIZE) * sizeof(socal_req),
898 s->req_cpu, s->req_dvma);
902 module_init(socal_probe);
903 module_exit(socal_cleanup);
904 MODULE_LICENSE("GPL");