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/malloc.h>
28 #include <linux/string.h>
29 #include <linux/init.h>
30 #include <asm/system.h>
31 #include <asm/bitops.h>
34 #include <linux/errno.h>
35 #include <asm/byteorder.h>
37 #include <asm/openprom.h>
38 #include <asm/oplib.h>
39 #include <asm/auxio.h>
40 #include <asm/system.h>
41 #include <asm/pgtable.h>
44 /* #define SOCALDEBUG */
45 /* #define HAVE_SOCAL_UCODE */
46 /* #define USE_64BIT_MODE */
50 #ifdef HAVE_SOCAL_UCODE
51 #include "socal_asm.h"
54 #define socal_printk printk ("socal%d: ", s->socal_no); printk
57 #define SOD(x) socal_printk x;
62 #define for_each_socal(s) for (s = socals; s; s = s->next)
63 struct socal
*socals
= NULL
;
65 /* I don't think our VIS mem* routines will behave well
67 static void socal_memcpy(void *d
, void *s
, int size
)
69 u32
*dp
= (u32
*)d
, *sp
= (u32
*)s
;
76 #ifdef HAVE_SOCAL_UCODE
77 static void socal_bzero(void *d
, int size
)
87 static inline void socal_disable(struct socal
*s
)
89 s
->regs
->imask
= 0; s
->regs
->cmd
= SOCAL_CMD_SOFT_RESET
;
92 static inline void socal_enable(struct socal
*s
)
94 SOD(("enable %08x\n", s
->cfg
))
95 s
->regs
->sae
= 0; s
->regs
->cfg
= s
->cfg
;
96 s
->regs
->cmd
= SOCAL_CMD_RSP_QALL
;
97 SOCAL_SETIMASK(s
, SOCAL_IMASK_RSP_QALL
| SOCAL_IMASK_SAE
);
98 SOD(("imask %08x %08x\n", s
->imask
, s
->regs
->imask
));
101 static void socal_reset(fc_channel
*fc
)
103 socal_port
*port
= (socal_port
*)fc
;
104 struct socal
*s
= port
->s
;
125 static void inline socal_solicited (struct socal
*s
, int qno
)
134 sw_cq
= &s
->rsp
[qno
];
136 if (sw_cq
->pool
== NULL
) {
137 SOD(("address %08x xram %p\n", sw_cq
->hw_cq
->address
, s
->xram
))
139 (socal_req
*)(s
->xram
+ (sw_cq
->hw_cq
->address
& 0xfffe));
141 /* Finally an improvement against old SOC :) */
142 sw_cq
->in
= s
->regs
->respr
[qno
];
143 SOD (("socal_solicited, %d packets arrived\n", (sw_cq
->in
- sw_cq
->out
) & sw_cq
->last
))
145 hwrsp
= (socal_rsp
*)sw_cq
->pool
+ sw_cq
->out
;
146 SOD(("hwrsp %p out %d\n", hwrsp
, sw_cq
->out
))
148 #if defined(SOCALDEBUG) && 0
150 u32
*u
= (u32
*)hwrsp
;
151 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n", u
[0],u
[1],u
[2],u
[3],u
[4],u
[5],u
[6],u
[7]))
153 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n", u
[0],u
[1],u
[2],u
[3],u
[4],u
[5],u
[6],u
[7]))
155 while (u
< ((u32
*)s
->regs
)) {
156 if (u
[0] == 0x00003000 || u
[0] == 0x00003801) {
157 SOD(("Found at %04lx\n", (unsigned long)u
- (unsigned long)s
->xram
))
158 SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n", u
[0],u
[1],u
[2],u
[3],u
[4],u
[5],u
[6],u
[7]))
160 SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n", u
[0],u
[1],u
[2],u
[3],u
[4],u
[5],u
[6],u
[7]))
168 token
= hwrsp
->shdr
.token
;
169 status
= hwrsp
->status
;
170 fc
= (fc_channel
*)(&s
->port
[(token
>> 11) & 1]);
172 SOD(("Solicited token %08x status %08x\n", token
, status
))
173 if (status
== SOCAL_OK
)
174 fcp_receive_solicited(fc
, token
>> 12, token
& ((1 << 11) - 1), FC_STATUS_OK
, NULL
);
176 socal_memcpy(&fchdr
, &hwrsp
->fchdr
, sizeof(fchdr
));
177 /* We have intentionally defined FC_STATUS_* constants to match SOCAL_* constants, otherwise
178 we'd have to translate status */
179 fcp_receive_solicited(fc
, token
>> 12, token
& ((1 << 11) - 1), status
, &fchdr
);
182 if (++sw_cq
->out
> sw_cq
->last
) {
187 if (sw_cq
->out
== sw_cq
->in
) {
188 sw_cq
->in
= s
->regs
->respr
[qno
];
189 if (sw_cq
->out
== sw_cq
->in
) {
190 /* Tell the hardware about it */
191 s
->regs
->cmd
= (sw_cq
->out
<< 24) | (SOCAL_CMD_RSP_QALL
& ~(SOCAL_CMD_RSP_Q0
<< qno
));
192 /* Read it, so that we're sure it has been updated */
194 sw_cq
->in
= s
->regs
->respr
[qno
];
195 if (sw_cq
->out
== sw_cq
->in
)
202 static void inline socal_request (struct socal
*s
, u32 cmd
)
204 SOCAL_SETIMASK(s
, s
->imask
& ~(cmd
& SOCAL_CMD_REQ_QALL
));
205 SOD(("imask %08x %08x\n", s
->imask
, s
->regs
->imask
));
207 SOD(("Queues available %08x OUT %X\n", cmd
, s
->regs
->reqpr
[0]))
208 if (s
->port
[s
->curr_port
].fc
.state
!= FC_STATE_OFFLINE
) {
209 fcp_queue_empty ((fc_channel
*)&(s
->port
[s
->curr_port
]));
210 if (((s
->req
[1].in
+ 1) & s
->req
[1].last
) != (s
->req
[1].out
))
211 fcp_queue_empty ((fc_channel
*)&(s
->port
[1 - s
->curr_port
]));
213 fcp_queue_empty ((fc_channel
*)&(s
->port
[1 - s
->curr_port
]));
214 if (s
->port
[1 - s
->curr_port
].fc
.state
!= FC_STATE_OFFLINE
)
218 static void inline socal_unsolicited (struct socal
*s
, int qno
)
220 socal_rsp
*hwrsp
, *hwrspc
;
227 sw_cq
= &s
->rsp
[qno
];
228 if (sw_cq
->pool
== NULL
) {
229 SOD(("address %08x xram %p\n", sw_cq
->hw_cq
->address
, s
->xram
))
231 (socal_req
*)(s
->xram
+ (sw_cq
->hw_cq
->address
& 0xfffe));
234 sw_cq
->in
= s
->regs
->respr
[qno
];
235 SOD (("socal_unsolicited, %d packets arrived, in %d\n", (sw_cq
->in
- sw_cq
->out
) & sw_cq
->last
, sw_cq
->in
))
236 while (sw_cq
->in
!= sw_cq
->out
) {
237 /* ...real work per entry here... */
238 hwrsp
= (socal_rsp
*)sw_cq
->pool
+ sw_cq
->out
;
239 SOD(("hwrsp %p out %d\n", hwrsp
, sw_cq
->out
))
241 #if defined(SOCALDEBUG) && 0
243 u32
*u
= (u32
*)hwrsp
;
244 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n", u
[0],u
[1],u
[2],u
[3],u
[4],u
[5],u
[6],u
[7]))
246 SOD(("%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n", u
[0],u
[1],u
[2],u
[3],u
[4],u
[5],u
[6],u
[7]))
251 flags
= hwrsp
->shdr
.flags
;
252 count
= hwrsp
->count
;
253 fc
= (fc_channel
*)&s
->port
[flags
& SOCAL_PORT_B
];
254 SOD(("FC %08lx\n", (long)fc
))
257 /* Ugh, continuation entries */
261 printk("%s: Too many continuations entries %d\n", fc
->name
, count
);
266 if (in
< sw_cq
->out
) in
+= sw_cq
->last
+ 1;
267 if (in
< sw_cq
->out
+ 2) {
268 /* Ask the hardware about it if they haven't arrived yet */
269 s
->regs
->cmd
= (sw_cq
->out
<< 24) | (SOCAL_CMD_RSP_QALL
& ~(SOCAL_CMD_RSP_Q0
<< qno
));
270 /* Read it, so that we're sure it has been updated */
272 sw_cq
->in
= s
->regs
->respr
[qno
];
274 if (in
< sw_cq
->out
) in
+= sw_cq
->last
+ 1;
275 if (in
< sw_cq
->out
+ 2) /* Nothing came, let us wait */
278 if (sw_cq
->out
== sw_cq
->last
)
279 hwrspc
= (socal_rsp
*)sw_cq
->pool
;
284 switch (flags
& ~SOCAL_PORT_B
) {
286 status
= hwrsp
->status
;
289 SOD(("State change to ONLINE\n"));
290 fcp_state_change(fc
, FC_STATE_ONLINE
);
292 case SOCAL_ONLINE_LOOP
:
293 SOD(("State change to ONLINE_LOOP\n"));
294 fcp_state_change(fc
, FC_STATE_ONLINE
);
297 SOD(("State change to OFFLINE\n"));
298 fcp_state_change(fc
, FC_STATE_OFFLINE
);
301 printk ("%s: Unknown STATUS no %d\n", fc
->name
, status
);
305 case (SOCAL_UNSOLICITED
|SOCAL_FC_HDR
):
307 int r_ctl
= *((u8
*)&hwrsp
->fchdr
);
311 if ((r_ctl
& 0xf0) == R_CTL_EXTENDED_SVC
) {
312 len
= hwrsp
->shdr
.bytecnt
;
313 if (len
< 4 || !hwrspc
)
314 printk ("%s: Invalid R_CTL %02x continuation entries\n", fc
->name
, r_ctl
);
316 if (len
> 60) len
= 60;
317 socal_memcpy (buf
, hwrspc
, (len
+ 3) & ~3);
318 if (*(u32
*)buf
== LS_DISPLAY
) {
321 for (i
= 4; i
< len
; i
++)
322 if (buf
[i
] == '\n') buf
[i
] = ' ';
324 printk ("%s message: %s\n", fc
->name
, buf
+ 4);
326 printk ("%s: Unknown LS_CMD %08x\n", fc
->name
, *(u32
*)buf
);
330 printk ("%s: Unsolicited R_CTL %02x not handled\n", fc
->name
, r_ctl
);
334 printk ("%s: Unexpected flags %08x\n", fc
->name
, flags
);
338 if (++sw_cq
->out
> sw_cq
->last
) {
344 if (++sw_cq
->out
> sw_cq
->last
) {
350 if (sw_cq
->out
== sw_cq
->in
) {
351 sw_cq
->in
= s
->regs
->respr
[qno
];
352 if (sw_cq
->out
== sw_cq
->in
) {
353 /* Tell the hardware about it */
354 s
->regs
->cmd
= (sw_cq
->out
<< 24) | (SOCAL_CMD_RSP_QALL
& ~(SOCAL_CMD_RSP_Q0
<< qno
));
355 /* Read it, so that we're sure it has been updated */
357 sw_cq
->in
= s
->regs
->respr
[qno
];
363 static void socal_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
367 register struct socal
*s
= (struct socal
*)dev_id
;
369 spin_lock_irqsave(&io_request_lock
, flags
);
371 for (; (cmd
= SOCAL_INTR (s
, cmd
)); cmd
= s
->regs
->cmd
) {
374 if (cnt
++ < 50) printk("soc_intr %08x\n", cmd
);
376 if (cmd
& SOCAL_CMD_RSP_Q2
) socal_unsolicited (s
, SOCAL_UNSOLICITED_RSP_Q
);
377 if (cmd
& SOCAL_CMD_RSP_Q1
) socal_unsolicited (s
, SOCAL_SOLICITED_BAD_RSP_Q
);
378 if (cmd
& SOCAL_CMD_RSP_Q0
) socal_solicited (s
, SOCAL_SOLICITED_RSP_Q
);
379 if (cmd
& SOCAL_CMD_REQ_QALL
) socal_request (s
, cmd
);
381 spin_unlock_irqrestore(&io_request_lock
, flags
);
384 #define TOKEN(proto, port, token) (((proto)<<12)|(token)|(port))
386 static int socal_hw_enque (fc_channel
*fc
, fcp_cmnd
*fcmd
)
388 socal_port
*port
= (socal_port
*)fc
;
389 struct socal
*s
= port
->s
;
397 if (fcmd
->proto
== TYPE_SCSI_FCP
)
401 SOD(("Putting a FCP packet type %d into hw queue %d\n", fcmd
->proto
, qno
))
402 if (s
->imask
& (SOCAL_IMASK_REQ_Q0
<< qno
)) {
403 SOD(("EIO %08x\n", s
->imask
))
406 sw_cq
= s
->req
+ qno
;
407 cq_next_in
= (sw_cq
->in
+ 1) & sw_cq
->last
;
409 if (cq_next_in
== sw_cq
->out
410 && cq_next_in
== (sw_cq
->out
= s
->regs
->reqpr
[qno
])) {
411 SOD(("%d IN %d OUT %d LAST %d\n", qno
, sw_cq
->in
, sw_cq
->out
, sw_cq
->last
))
412 SOCAL_SETIMASK(s
, s
->imask
| (SOCAL_IMASK_REQ_Q0
<< qno
));
413 SOD(("imask %08x %08x\n", s
->imask
, s
->regs
->imask
));
414 /* If queue is full, just say NO */
418 request
= sw_cq
->pool
+ sw_cq
->in
;
419 fch
= &request
->fchdr
;
421 switch (fcmd
->proto
) {
423 request
->shdr
.token
= TOKEN(TYPE_SCSI_FCP
, port
->mask
, fcmd
->token
);
424 request
->data
[0].base
= fc
->dma_scsi_cmd
+ fcmd
->token
* sizeof(fcp_cmd
);
425 request
->data
[0].count
= sizeof(fcp_cmd
);
426 request
->data
[1].base
= fc
->dma_scsi_rsp
+ fcmd
->token
* fc
->rsp_size
;
427 request
->data
[1].count
= fc
->rsp_size
;
429 request
->shdr
.segcnt
= 3;
430 i
= fc
->scsi_cmd_pool
[fcmd
->token
].fcp_data_len
;
431 request
->shdr
.bytecnt
= i
;
432 request
->data
[2].base
= fcmd
->data
;
433 request
->data
[2].count
= i
;
434 request
->type
= (fc
->scsi_cmd_pool
[fcmd
->token
].fcp_cntl
& FCP_CNTL_WRITE
) ?
435 SOCAL_CQTYPE_IO_WRITE
: SOCAL_CQTYPE_IO_READ
;
437 request
->shdr
.segcnt
= 2;
438 request
->shdr
.bytecnt
= 0;
439 request
->data
[2].base
= 0;
440 request
->data
[2].count
= 0;
441 request
->type
= SOCAL_CQTYPE_SIMPLE
;
443 FILL_FCHDR_RCTL_DID(fch
, R_CTL_COMMAND
, fcmd
->did
);
444 FILL_FCHDR_SID(fch
, fc
->sid
);
445 FILL_FCHDR_TYPE_FCTL(fch
, TYPE_SCSI_FCP
, F_CTL_FIRST_SEQ
| F_CTL_SEQ_INITIATIVE
);
446 FILL_FCHDR_SEQ_DF_SEQ(fch
, 0, 0, 0);
447 FILL_FCHDR_OXRX(fch
, 0xffff, 0xffff);
449 request
->shdr
.flags
= port
->flags
;
450 request
->shdr
.class = fc
->posmap
? 3 : 2;
454 memset (request
, 0, sizeof(*request
));
455 request
->shdr
.token
= TOKEN(PROTO_OFFLINE
, port
->mask
, fcmd
->token
);
456 request
->type
= SOCAL_CQTYPE_OFFLINE
;
457 FILL_FCHDR_RCTL_DID(fch
, R_CTL_COMMAND
, fcmd
->did
);
458 FILL_FCHDR_SID(fch
, fc
->sid
);
459 FILL_FCHDR_TYPE_FCTL(fch
, TYPE_SCSI_FCP
, F_CTL_FIRST_SEQ
| F_CTL_SEQ_INITIATIVE
);
460 FILL_FCHDR_SEQ_DF_SEQ(fch
, 0, 0, 0);
461 FILL_FCHDR_OXRX(fch
, 0xffff, 0xffff);
462 request
->shdr
.flags
= port
->flags
;
465 case PROTO_REPORT_AL_MAP
:
466 memset (request
, 0, sizeof(*request
));
467 request
->shdr
.token
= TOKEN(PROTO_REPORT_AL_MAP
, port
->mask
, fcmd
->token
);
468 request
->type
= SOCAL_CQTYPE_REPORT_MAP
;
469 request
->shdr
.flags
= port
->flags
;
470 request
->shdr
.segcnt
= 1;
471 request
->shdr
.bytecnt
= sizeof(fc_al_posmap
);
472 request
->data
[0].base
= fcmd
->cmd
;
473 request
->data
[0].count
= sizeof(fc_al_posmap
);
477 request
->shdr
.token
= TOKEN(fcmd
->proto
, port
->mask
, fcmd
->token
);
478 request
->shdr
.class = fc
->posmap
? 3 : 2;
479 request
->shdr
.flags
= port
->flags
;
480 memcpy (fch
, &fcmd
->fch
, sizeof(fc_hdr
));
481 request
->data
[0].count
= fcmd
->cmdlen
;
482 request
->data
[1].count
= fcmd
->rsplen
;
483 request
->type
= fcmd
->class;
484 switch (fcmd
->class) {
485 case FC_CLASS_OUTBOUND
:
486 request
->data
[0].base
= fcmd
->cmd
;
487 request
->data
[0].count
= fcmd
->cmdlen
;
488 request
->type
= SOCAL_CQTYPE_OUTBOUND
;
489 request
->shdr
.bytecnt
= fcmd
->cmdlen
;
490 request
->shdr
.segcnt
= 1;
492 case FC_CLASS_INBOUND
:
493 request
->data
[0].base
= fcmd
->rsp
;
494 request
->data
[0].count
= fcmd
->rsplen
;
495 request
->type
= SOCAL_CQTYPE_INBOUND
;
496 request
->shdr
.bytecnt
= 0;
497 request
->shdr
.segcnt
= 1;
499 case FC_CLASS_SIMPLE
:
500 request
->data
[0].base
= fcmd
->cmd
;
501 request
->data
[1].base
= fcmd
->rsp
;
502 request
->data
[0].count
= fcmd
->cmdlen
;
503 request
->data
[1].count
= fcmd
->rsplen
;
504 request
->type
= SOCAL_CQTYPE_SIMPLE
;
505 request
->shdr
.bytecnt
= fcmd
->cmdlen
;
506 request
->shdr
.segcnt
= 2;
508 case FC_CLASS_IO_READ
:
509 case FC_CLASS_IO_WRITE
:
510 request
->data
[0].base
= fcmd
->cmd
;
511 request
->data
[1].base
= fcmd
->rsp
;
512 request
->data
[0].count
= fcmd
->cmdlen
;
513 request
->data
[1].count
= fcmd
->rsplen
;
514 request
->type
= (fcmd
->class == FC_CLASS_IO_READ
) ? SOCAL_CQTYPE_IO_READ
: SOCAL_CQTYPE_IO_WRITE
;
516 request
->data
[2].base
= fcmd
->data
;
517 request
->data
[2].count
= fcmd
->datalen
;
518 request
->shdr
.bytecnt
= fcmd
->datalen
;
519 request
->shdr
.segcnt
= 3;
521 request
->shdr
.bytecnt
= 0;
522 request
->shdr
.segcnt
= 2;
531 request
->seqno
= sw_cq
->seqno
;
533 SOD(("queueing token %08x\n", request
->shdr
.token
))
535 /* And now tell the SOCAL about it */
537 if (++sw_cq
->in
> sw_cq
->last
) {
542 SOD(("Putting %08x into cmd\n", SOCAL_CMD_RSP_QALL
| (sw_cq
->in
<< 24) | (SOCAL_CMD_REQ_Q0
<< qno
)))
544 s
->regs
->cmd
= SOCAL_CMD_RSP_QALL
| (sw_cq
->in
<< 24) | (SOCAL_CMD_REQ_Q0
<< qno
);
545 /* Read so that command is completed */
551 static inline void socal_download_fw(struct socal
*s
)
553 #ifdef HAVE_SOCAL_UCODE
554 SOD(("Loading %ld bytes from %p to %p\n", sizeof(socal_ucode
), socal_ucode
, s
->xram
))
555 socal_memcpy (s
->xram
, socal_ucode
, sizeof(socal_ucode
));
556 SOD(("Clearing the rest of memory\n"))
557 socal_bzero (s
->xram
+ sizeof(socal_ucode
), 65536 - sizeof(socal_ucode
));
562 /* Check for what the best SBUS burst we can use happens
563 * to be on this machine.
565 static inline void socal_init_bursts(struct socal
*s
, struct linux_sbus_device
*sdev
)
567 int bsizes
, bsizes_more
;
570 bsizes
= (prom_getintdefault(sdev
->prom_node
,"burst-sizes",0xff) & 0xff);
571 bsizes_more
= (prom_getintdefault(sdev
->my_bus
->prom_node
, "burst-sizes", 0xff) & 0xff);
572 bsizes
&= bsizes_more
;
573 #ifdef USE_64BIT_MODE
575 mmu_set_sbus64(sdev
, bsizes
>> 16);
578 if ((bsizes
& 0x7f) == 0x7f)
579 cfg
= SOCAL_CFG_BURST_64
;
580 else if ((bsizes
& 0x3f) == 0x3f)
581 cfg
= SOCAL_CFG_BURST_32
;
582 else if ((bsizes
& 0x1f) == 0x1f)
583 cfg
= SOCAL_CFG_BURST_16
;
585 cfg
= SOCAL_CFG_BURST_4
;
586 #ifdef USE_64BIT_MODE
588 /* What is BURST_128? -jj */
589 if ((bsizes
& 0x780000) == 0x780000)
590 cfg
|= (SOCAL_CFG_BURST_64
<< 8) | SOCAL_CFG_SBUS_ENHANCED
;
591 else if ((bsizes
& 0x380000) == 0x380000)
592 cfg
|= (SOCAL_CFG_BURST_32
<< 8) | SOCAL_CFG_SBUS_ENHANCED
;
593 else if ((bsizes
& 0x180000) == 0x180000)
594 cfg
|= (SOCAL_CFG_BURST_16
<< 8) | SOCAL_CFG_SBUS_ENHANCED
;
596 cfg
|= (SOCAL_CFG_BURST_8
<< 8) | SOCAL_CFG_SBUS_ENHANCED
;
602 static inline void socal_init(struct linux_sbus_device
*sdev
, int no
)
604 unsigned char tmp
[60];
607 static unsigned version_printed
= 0;
612 s
= kmalloc (sizeof (struct socal
), GFP_KERNEL
);
614 memset (s
, 0, sizeof(struct socal
));
617 SOD(("socals %08lx socal_intr %08lx socal_hw_enque %08lx\n", (long)socals
, (long)socal_intr
, (long)socal_hw_enque
))
618 if (version_printed
++ == 0)
621 s
->port
[0].fc
.module
= &__this_module
;
622 s
->port
[1].fc
.module
= &__this_module
;
624 s
->port
[0].fc
.module
= NULL
;
625 s
->port
[1].fc
.module
= NULL
;
630 s
->port
[0].fc
.dev
= sdev
;
631 s
->port
[1].fc
.dev
= sdev
;
635 s
->port
[0].fc
.next
= &s
->port
[1].fc
;
637 /* World Wide Name of SOCAL */
638 propl
= prom_getproperty (sdev
->prom_node
, "wwn", tmp
, sizeof(tmp
));
639 if (propl
!= sizeof (fc_wwn
)) {
640 s
->wwn
.naaid
= NAAID_IEEE_REG
;
641 s
->wwn
.nportid
= 0x123;
643 s
->wwn
.lo
= 0x12345678;
645 memcpy (&s
->wwn
, tmp
, sizeof (fc_wwn
));
647 memcpy (&s
->port
[0].fc
.wwn_nport
, &s
->wwn
, sizeof (fc_wwn
));
648 s
->port
[0].fc
.wwn_nport
.lo
++;
649 memcpy (&s
->port
[1].fc
.wwn_nport
, &s
->wwn
, sizeof (fc_wwn
));
650 s
->port
[1].fc
.wwn_nport
.lo
+=2;
652 node
= prom_getchild (sdev
->prom_node
);
653 while (node
&& (node
= prom_searchsiblings (node
, "sf"))) {
656 port
= prom_getintdefault(node
, "port#", -1);
660 if (prom_getproplen(node
, "port-wwn") == sizeof (fc_wwn
))
661 prom_getproperty (node
, "port-wwn",
662 (char *)&s
->port
[port
].fc
.wwn_nport
,
668 node
= prom_getsibling(node
);
671 memcpy (&s
->port
[0].fc
.wwn_node
, &s
->wwn
, sizeof (fc_wwn
));
672 memcpy (&s
->port
[1].fc
.wwn_node
, &s
->wwn
, sizeof (fc_wwn
));
673 SOD(("Got wwns %08x%08x ports %08x%08x and %08x%08x\n",
674 *(u32
*)&s
->port
[0].fc
.wwn_node
, s
->port
[0].fc
.wwn_node
.lo
,
675 *(u32
*)&s
->port
[0].fc
.wwn_nport
, s
->port
[0].fc
.wwn_nport
.lo
,
676 *(u32
*)&s
->port
[1].fc
.wwn_nport
, s
->port
[1].fc
.wwn_nport
.lo
))
678 s
->port
[0].fc
.sid
= 1;
679 s
->port
[1].fc
.sid
= 17;
680 s
->port
[0].fc
.did
= 2;
681 s
->port
[1].fc
.did
= 18;
683 s
->port
[0].fc
.reset
= socal_reset
;
684 s
->port
[1].fc
.reset
= socal_reset
;
686 /* Setup the reg property for this device. */
687 prom_apply_sbus_ranges(sdev
->my_bus
, sdev
->reg_addrs
, sdev
->num_registers
, sdev
);
689 if (sdev
->num_registers
== 1) {
691 sparc_alloc_io (sdev
->reg_addrs
[0].phys_addr
, 0,
692 sdev
->reg_addrs
[0].reg_size
, "socal_xram",
693 sdev
->reg_addrs
[0].which_io
, 0);
694 if (sdev
->reg_addrs
[0].reg_size
> 0x20000)
695 s
->xram
= s
->eeprom
+ 0x10000;
698 s
->regs
= (struct socal_regs
*)(s
->xram
+ 0x10000);
700 /* E.g. starfire presents 3 registers for SOCAL */
702 sparc_alloc_io (sdev
->reg_addrs
[1].phys_addr
, 0,
703 sdev
->reg_addrs
[1].reg_size
, "socal_xram",
704 sdev
->reg_addrs
[1].which_io
, 0);
705 s
->regs
= (struct socal_regs
*)
706 sparc_alloc_io (sdev
->reg_addrs
[2].phys_addr
, 0,
707 sdev
->reg_addrs
[2].reg_size
, "socal_regs",
708 sdev
->reg_addrs
[2].which_io
, 0);
711 socal_init_bursts(s
, sdev
);
713 SOD(("Disabling SOCAL\n"))
719 if (request_irq (irq
, socal_intr
, SA_SHIRQ
, "SOCAL", (void *)s
)) {
720 socal_printk ("Cannot order irq %d to go\n", irq
);
725 SOD(("SOCAL uses IRQ %s\n", __irq_itoa(irq
)))
727 s
->port
[0].fc
.irq
= irq
;
728 s
->port
[1].fc
.irq
= irq
;
730 sprintf (s
->port
[0].fc
.name
, "socal%d port A", no
);
731 sprintf (s
->port
[1].fc
.name
, "socal%d port B", no
);
732 s
->port
[0].flags
= SOCAL_FC_HDR
| SOCAL_PORT_A
;
733 s
->port
[1].flags
= SOCAL_FC_HDR
| SOCAL_PORT_B
;
734 s
->port
[1].mask
= (1 << 11);
736 s
->port
[0].fc
.hw_enque
= socal_hw_enque
;
737 s
->port
[1].fc
.hw_enque
= socal_hw_enque
;
739 socal_download_fw (s
);
741 SOD(("Downloaded firmware\n"))
743 /* Now setup xram circular queues */
744 memset (cq
, 0, sizeof(cq
));
746 size
= (SOCAL_CQ_REQ0_SIZE
+ SOCAL_CQ_REQ1_SIZE
+ SOCAL_CQ_RSP0_SIZE
+ SOCAL_CQ_RSP1_SIZE
+ SOCAL_CQ_RSP2_SIZE
) * sizeof(socal_req
);
747 s
->req
[0].pool
= (socal_req
*) sparc_dvma_malloc (size
, "SOCAL request queues", &cq
[0].address
);
748 s
->req
[1].pool
= s
->req
[0].pool
+ SOCAL_CQ_REQ0_SIZE
;
749 s
->rsp
[0].pool
= s
->req
[1].pool
+ SOCAL_CQ_REQ1_SIZE
;
750 s
->rsp
[1].pool
= s
->rsp
[0].pool
+ SOCAL_CQ_RSP0_SIZE
;
751 s
->rsp
[2].pool
= s
->rsp
[1].pool
+ SOCAL_CQ_RSP1_SIZE
;
753 s
->req
[0].hw_cq
= (socal_hw_cq
*)(s
->xram
+ SOCAL_CQ_REQ_OFFSET
);
754 s
->req
[1].hw_cq
= (socal_hw_cq
*)(s
->xram
+ SOCAL_CQ_REQ_OFFSET
+ sizeof(socal_hw_cq
));
755 s
->rsp
[0].hw_cq
= (socal_hw_cq
*)(s
->xram
+ SOCAL_CQ_RSP_OFFSET
);
756 s
->rsp
[1].hw_cq
= (socal_hw_cq
*)(s
->xram
+ SOCAL_CQ_RSP_OFFSET
+ sizeof(socal_hw_cq
));
757 s
->rsp
[2].hw_cq
= (socal_hw_cq
*)(s
->xram
+ SOCAL_CQ_RSP_OFFSET
+ 2 * sizeof(socal_hw_cq
));
759 cq
[1].address
= cq
[0].address
+ (SOCAL_CQ_REQ0_SIZE
* sizeof(socal_req
));
760 cq
[4].address
= cq
[1].address
+ (SOCAL_CQ_REQ1_SIZE
* sizeof(socal_req
));
761 cq
[5].address
= cq
[4].address
+ (SOCAL_CQ_RSP0_SIZE
* sizeof(socal_req
));
762 cq
[6].address
= cq
[5].address
+ (SOCAL_CQ_RSP1_SIZE
* sizeof(socal_req
));
764 cq
[0].last
= SOCAL_CQ_REQ0_SIZE
- 1;
765 cq
[1].last
= SOCAL_CQ_REQ1_SIZE
- 1;
766 cq
[4].last
= SOCAL_CQ_RSP0_SIZE
- 1;
767 cq
[5].last
= SOCAL_CQ_RSP1_SIZE
- 1;
768 cq
[6].last
= SOCAL_CQ_RSP2_SIZE
- 1;
769 for (i
= 0; i
< 8; i
++)
772 s
->req
[0].last
= SOCAL_CQ_REQ0_SIZE
- 1;
773 s
->req
[1].last
= SOCAL_CQ_REQ1_SIZE
- 1;
774 s
->rsp
[0].last
= SOCAL_CQ_RSP0_SIZE
- 1;
775 s
->rsp
[1].last
= SOCAL_CQ_RSP1_SIZE
- 1;
776 s
->rsp
[2].last
= SOCAL_CQ_RSP2_SIZE
- 1;
784 socal_memcpy (s
->xram
+ SOCAL_CQ_REQ_OFFSET
, cq
, sizeof(cq
));
786 SOD(("Setting up params\n"))
788 /* Make our sw copy of SOCAL service parameters */
789 socal_memcpy (s
->serv_params
, s
->xram
+ 0x280, sizeof (s
->serv_params
));
791 s
->port
[0].fc
.common_svc
= (common_svc_parm
*)s
->serv_params
;
792 s
->port
[0].fc
.class_svcs
= (svc_parm
*)(s
->serv_params
+ 0x20);
793 s
->port
[1].fc
.common_svc
= (common_svc_parm
*)&s
->serv_params
;
794 s
->port
[1].fc
.class_svcs
= (svc_parm
*)(s
->serv_params
+ 0x20);
798 SOD(("Enabled SOCAL\n"))
802 __initfunc(int socal_probe(void))
804 int init_module(void)
807 struct linux_sbus
*bus
;
808 struct linux_sbus_device
*sdev
= 0;
813 for_each_sbusdev(sdev
, bus
) {
814 if(!strcmp(sdev
->prom_name
, "SUNW,socal")) {
815 socal_init(sdev
, cards
);
820 if (!cards
) return -EIO
;
824 s
->port
[1].fc
.next
= &s
->next
->port
[0].fc
;
826 fcp_init (&socals
->port
[0].fc
);
833 void cleanup_module(void)
837 struct linux_sbus_device
*sdev
;
840 irq
= s
->port
[0].fc
.irq
;
844 fcp_release(&(s
->port
[0].fc
), 2);
846 sdev
= s
->port
[0].fc
.dev
;
847 if (sdev
->num_registers
== 1)
848 sparc_free_io (s
->eeprom
, sdev
->reg_addrs
[0].reg_size
);
850 sparc_free_io (s
->xram
, sdev
->reg_addrs
[1].reg_size
);
851 sparc_free_io ((char *)s
->regs
, sdev
->reg_addrs
[2].reg_size
);
853 /* FIXME: sparc_dvma_free() ??? */