File: /usr/src/linux/drivers/fc4/soc.c

1     /* soc.c: Sparc SUNW,soc (Serial Optical Channel) Fibre Channel Sbus adapter support.
2      *
3      * Copyright (C) 1996,1997,1999 Jakub Jelinek (jj@ultra.linux.cz)
4      * Copyright (C) 1997,1998 Jirka Hanika (geo@ff.cuni.cz)
5      *
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
9      *
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.
18      */
19     
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";
22     
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/slab.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>
40     
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>
46     
47     /* #define SOCDEBUG */
48     /* #define HAVE_SOC_UCODE */
49     
50     #include "fcp_impl.h"
51     #include "soc.h"
52     #ifdef HAVE_SOC_UCODE
53     #include "soc_asm.h"
54     #endif
55     
56     #define soc_printk printk ("soc%d: ", s->soc_no); printk 
57     
58     #ifdef SOCDEBUG
59     #define SOD(x)  soc_printk x;
60     #else
61     #define SOD(x)
62     #endif
63     
64     #define for_each_soc(s) for (s = socs; s; s = s->next)
65     struct soc *socs = NULL;
66     
67     static inline void soc_disable(struct soc *s)
68     {
69     	sbus_writel(0, s->regs + IMASK);
70     	sbus_writel(SOC_CMD_SOFT_RESET, s->regs + CMD);
71     }
72     
73     static inline void soc_enable(struct soc *s)
74     {
75     	SOD(("enable %08x\n", s->cfg))
76     	sbus_writel(0, s->regs + SAE);
77     	sbus_writel(s->cfg, s->regs + CFG);
78     	sbus_writel(SOC_CMD_RSP_QALL, s->regs + CMD);
79     	SOC_SETIMASK(s, SOC_IMASK_RSP_QALL | SOC_IMASK_SAE);
80     	SOD(("imask %08lx %08lx\n", s->imask, sbus_readl(s->regs + IMAK)));
81     }
82     
83     static void soc_reset(fc_channel *fc)
84     {
85     	soc_port *port = (soc_port *)fc;
86     	struct soc *s = port->s;
87     	
88     	/* FIXME */
89     	soc_disable(s);
90     	s->req[0].seqno = 1;
91     	s->req[1].seqno = 1;
92     	s->rsp[0].seqno = 1;
93     	s->rsp[1].seqno = 1;
94     	s->req[0].in = 0;
95     	s->req[1].in = 0;
96     	s->rsp[0].in = 0;
97     	s->rsp[1].in = 0;
98     	s->req[0].out = 0;
99     	s->req[1].out = 0;
100     	s->rsp[0].out = 0;
101     	s->rsp[1].out = 0;
102     
103     	/* FIXME */
104     	soc_enable(s);
105     }
106     
107     static void inline soc_solicited (struct soc *s)
108     {
109     	fc_hdr fchdr;
110     	soc_rsp *hwrsp;
111     	soc_cq *sw_cq;
112     	int token;
113     	int status;
114     	fc_channel *fc;
115     
116     	sw_cq = &s->rsp[SOC_SOLICITED_RSP_Q];
117     
118     	if (sw_cq->pool == NULL)
119     		sw_cq->pool = (soc_req *)
120     			(s->xram + xram_get_32low ((xram_p)&sw_cq->hw_cq->address));
121     	sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
122     	SOD (("soc_solicited, %d pkts arrived\n", (sw_cq->in-sw_cq->out) & sw_cq->last))
123     	for (;;) {
124     		hwrsp = (soc_rsp *)sw_cq->pool + sw_cq->out;
125     		token = xram_get_32low ((xram_p)&hwrsp->shdr.token);
126     		status = xram_get_32low ((xram_p)&hwrsp->status);
127     		fc = (fc_channel *)(&s->port[(token >> 11) & 1]);
128     		
129     		if (status == SOC_OK) {
130     			fcp_receive_solicited(fc, token >> 12,
131     					      token & ((1 << 11) - 1),
132     					      FC_STATUS_OK, NULL);
133     		} else {
134     			xram_copy_from(&fchdr, (xram_p)&hwrsp->fchdr, sizeof(fchdr));
135     			/* We have intentionally defined FC_STATUS_* constants
136     			 * to match SOC_* constants, otherwise we'd have to
137     			 * translate status.
138     			 */
139     			fcp_receive_solicited(fc, token >> 12,
140     					      token & ((1 << 11) - 1),
141     					      status, &fchdr);
142     		}
143     			
144     		if (++sw_cq->out > sw_cq->last) {
145     			sw_cq->seqno++;
146     			sw_cq->out = 0;
147     		}
148     		
149     		if (sw_cq->out == sw_cq->in) {
150     			sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
151     			if (sw_cq->out == sw_cq->in) {
152     				/* Tell the hardware about it */
153     				sbus_writel((sw_cq->out << 24) |
154     					    (SOC_CMD_RSP_QALL &
155     					     ~(SOC_CMD_RSP_Q0 << SOC_SOLICITED_RSP_Q)),
156     					    s->regs + CMD);
157     
158     				/* Read it, so that we're sure it has been updated */
159     				sbus_readl(s->regs + CMD);
160     				sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
161     				if (sw_cq->out == sw_cq->in)
162     					break;
163     			}
164     		}
165     	}
166     }
167     
168     static void inline soc_request (struct soc *s, u32 cmd)
169     {
170     	SOC_SETIMASK(s, s->imask & ~(cmd & SOC_CMD_REQ_QALL));
171     	SOD(("imask %08lx %08lx\n", s->imask, sbus_readl(s->regs + IMASK)));
172     
173     	SOD(("Queues available %08x OUT %X %X\n", cmd,
174     	     xram_get_8((xram_p)&s->req[0].hw_cq->out),
175     	     xram_get_8((xram_p)&s->req[0].hw_cq->out)))
176     	if (s->port[s->curr_port].fc.state != FC_STATE_OFFLINE) {
177     		fcp_queue_empty ((fc_channel *)&(s->port[s->curr_port]));
178     		if (((s->req[1].in + 1) & s->req[1].last) != (s->req[1].out))
179     			fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
180     	} else {
181     		fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
182     	}
183     	if (s->port[1 - s->curr_port].fc.state != FC_STATE_OFFLINE)
184     		s->curr_port ^= 1;
185     }
186     
187     static void inline soc_unsolicited (struct soc *s)
188     {
189     	soc_rsp *hwrsp, *hwrspc;
190     	soc_cq *sw_cq;
191     	int count;
192     	int status;
193     	int flags;
194     	fc_channel *fc;
195     
196     	sw_cq = &s->rsp[SOC_UNSOLICITED_RSP_Q];
197     	if (sw_cq->pool == NULL)
198     		sw_cq->pool = (soc_req *)
199     			(s->xram + (xram_get_32low ((xram_p)&sw_cq->hw_cq->address)));
200     
201     	sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
202     	SOD (("soc_unsolicited, %d packets arrived\n", (sw_cq->in - sw_cq->out) & sw_cq->last))
203     	while (sw_cq->in != sw_cq->out) {
204     		/* ...real work per entry here... */
205     		hwrsp = (soc_rsp *)sw_cq->pool + sw_cq->out;
206     
207     		hwrspc = NULL;
208     		flags = xram_get_16 ((xram_p)&hwrsp->shdr.flags);
209     		count = xram_get_8 ((xram_p)&hwrsp->count);
210     		fc = (fc_channel *)&s->port[flags & SOC_PORT_B];
211     		SOD(("FC %08lx fcp_state_change %08lx\n",
212     		     (long)fc, (long)fc->fcp_state_change))
213     		
214     		if (count != 1) {
215     			/* Ugh, continuation entries */
216     			u8 in;
217     
218     			if (count != 2) {
219     				printk("%s: Too many continuations entries %d\n",
220     				       fc->name, count);
221     				goto update_out;
222     			}
223     			
224     			in = sw_cq->in;
225     			if (in < sw_cq->out) in += sw_cq->last + 1;
226     			if (in < sw_cq->out + 2) {
227     				/* Ask the hardware if they haven't arrived yet. */
228     				sbus_writel((sw_cq->out << 24) |
229     					    (SOC_CMD_RSP_QALL &
230     					     ~(SOC_CMD_RSP_Q0 << SOC_UNSOLICITED_RSP_Q)),
231     					    s->regs + CMD);
232     
233     				/* Read it, so that we're sure it has been updated */
234     				sbus_readl(s->regs + CMD);
235     				sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
236     				in = sw_cq->in;
237     				if (in < sw_cq->out)
238     					in += sw_cq->last + 1;
239     				if (in < sw_cq->out + 2) /* Nothing came, let us wait */
240     					return;
241     			}
242     			if (sw_cq->out == sw_cq->last)
243     				hwrspc = (soc_rsp *)sw_cq->pool;
244     			else
245     				hwrspc = hwrsp + 1;
246     		}
247     		
248     		switch (flags & ~SOC_PORT_B) {
249     		case SOC_STATUS:
250     			status = xram_get_32low ((xram_p)&hwrsp->status);
251     			switch (status) {
252     			case SOC_ONLINE:
253     				SOD(("State change to ONLINE\n"));
254     				fcp_state_change(fc, FC_STATE_ONLINE);
255     				break;
256     			case SOC_OFFLINE:
257     				SOD(("State change to OFFLINE\n"));
258     				fcp_state_change(fc, FC_STATE_OFFLINE);
259     				break;
260     			default:
261     				printk ("%s: Unknown STATUS no %d\n",
262     					fc->name, status);
263     				break;
264     			}
265     			break;
266     		case (SOC_UNSOLICITED|SOC_FC_HDR):
267     			{
268     				int r_ctl = xram_get_8 ((xram_p)&hwrsp->fchdr);
269     				unsigned len;
270     				char buf[64];
271     				
272     				if ((r_ctl & 0xf0) == R_CTL_EXTENDED_SVC) {
273     					len = xram_get_32 ((xram_p)&hwrsp->shdr.bytecnt);
274     					if (len < 4 || !hwrspc) {
275     						printk ("%s: Invalid R_CTL %02x "
276     							"continuation entries\n",
277     							fc->name, r_ctl);
278     					} else {
279     						if (len > 60)
280     							len = 60;
281     						xram_copy_from (buf, (xram_p)hwrspc,
282     								(len + 3) & ~3);
283     						if (*(u32 *)buf == LS_DISPLAY) {
284     							int i;
285     							
286     							for (i = 4; i < len; i++)
287     								if (buf[i] == '\n')
288     									buf[i] = ' ';
289     							buf[len] = 0;
290     							printk ("%s message: %s\n",
291     								fc->name, buf + 4);
292     						} else {
293     							printk ("%s: Unknown LS_CMD "
294     								"%02x\n", fc->name,
295     								buf[0]);
296     						}
297     					}
298     				} else {
299     					printk ("%s: Unsolicited R_CTL %02x "
300     						"not handled\n", fc->name, r_ctl);
301     				}
302     			}
303     			break;
304     		default:
305     			printk ("%s: Unexpected flags %08x\n", fc->name, flags);
306     			break;
307     		};
308     update_out:
309     		if (++sw_cq->out > sw_cq->last) {
310     			sw_cq->seqno++;
311     			sw_cq->out = 0;
312     		}
313     		
314     		if (hwrspc) {
315     			if (++sw_cq->out > sw_cq->last) {
316     				sw_cq->seqno++;
317     				sw_cq->out = 0;
318     			}
319     		}
320     		
321     		if (sw_cq->out == sw_cq->in) {
322     			sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
323     			if (sw_cq->out == sw_cq->in) {
324     				/* Tell the hardware about it */
325     				sbus_writel((sw_cq->out << 24) |
326     					    (SOC_CMD_RSP_QALL &
327     					     ~(SOC_CMD_RSP_Q0 << SOC_UNSOLICITED_RSP_Q)),
328     					    s->regs + CMD);
329     
330     				/* Read it, so that we're sure it has been updated */
331     				sbus_readl(s->regs + CMD);
332     				sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
333     			}
334     		}
335     	}
336     }
337     
338     static void soc_intr(int irq, void *dev_id, struct pt_regs *regs)
339     {
340     	u32 cmd;
341     	unsigned long flags;
342     	register struct soc *s = (struct soc *)dev_id;
343     
344     	spin_lock_irqsave(&io_request_lock, flags);
345     	cmd = sbus_readl(s->regs + CMD);
346     	for (; (cmd = SOC_INTR (s, cmd)); cmd = sbus_readl(s->regs + CMD)) {
347     		if (cmd & SOC_CMD_RSP_Q1) soc_unsolicited (s);
348     		if (cmd & SOC_CMD_RSP_Q0) soc_solicited (s);
349     		if (cmd & SOC_CMD_REQ_QALL) soc_request (s, cmd);
350     	}
351     	spin_unlock_irqrestore(&io_request_lock, flags);
352     }
353     
354     #define TOKEN(proto, port, token) (((proto)<<12)|(token)|(port))
355     
356     static int soc_hw_enque (fc_channel *fc, fcp_cmnd *fcmd)
357     {
358     	soc_port *port = (soc_port *)fc;
359     	struct soc *s = port->s;
360     	int qno;
361     	soc_cq *sw_cq;
362     	int cq_next_in;
363     	soc_req *request;
364     	fc_hdr *fch;
365     	int i;
366     
367     	if (fcmd->proto == TYPE_SCSI_FCP)
368     		qno = 1;
369     	else
370     		qno = 0;
371     	SOD(("Putting a FCP packet type %d into hw queue %d\n", fcmd->proto, qno))
372     	if (s->imask & (SOC_IMASK_REQ_Q0 << qno)) {
373     		SOD(("EIO %08x\n", s->imask))
374     		return -EIO;
375     	}
376     	sw_cq = s->req + qno;
377     	cq_next_in = (sw_cq->in + 1) & sw_cq->last;
378     	
379     	if (cq_next_in == sw_cq->out &&
380     	    cq_next_in == (sw_cq->out = xram_get_8((xram_p)&sw_cq->hw_cq->out))) {
381     		SOD(("%d IN %d OUT %d LAST %d\n", qno, sw_cq->in, sw_cq->out, sw_cq->last))
382     		SOC_SETIMASK(s, s->imask | (SOC_IMASK_REQ_Q0 << qno));
383     		SOD(("imask %08lx %08lx\n", s->imask, sbus_readl(s->regs + IMASK)));
384     		/* If queue is full, just say NO */
385     		return -EBUSY;
386     	}
387     	
388     	request = sw_cq->pool + sw_cq->in;
389     	fch = &request->fchdr;
390     	
391     	switch (fcmd->proto) {
392     	case TYPE_SCSI_FCP:
393     		request->shdr.token = TOKEN(TYPE_SCSI_FCP, port->mask, fcmd->token); 
394     		request->data[0].base = fc->dma_scsi_cmd + fcmd->token * sizeof(fcp_cmd);
395     		request->data[0].count = sizeof(fcp_cmd);
396     		request->data[1].base = fc->dma_scsi_rsp + fcmd->token * fc->rsp_size;
397     		request->data[1].count = fc->rsp_size;
398     		if (fcmd->data) {
399     			request->shdr.segcnt = 3;
400     			i = fc->scsi_cmd_pool[fcmd->token].fcp_data_len;
401     			request->shdr.bytecnt = i;
402     			request->data[2].base = fcmd->data;
403     			request->data[2].count = i;
404     			request->type =
405     			    (fc->scsi_cmd_pool[fcmd->token].fcp_cntl & FCP_CNTL_WRITE) ?
406     				SOC_CQTYPE_IO_WRITE : SOC_CQTYPE_IO_READ;
407     		} else {
408     			request->shdr.segcnt = 2;
409     			request->shdr.bytecnt = 0;
410     			request->data[2].base = 0;
411     			request->data[2].count = 0;
412     			request->type = SOC_CQTYPE_SIMPLE;
413     		}
414     		FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fc->did);
415     		FILL_FCHDR_SID(fch, fc->sid);
416     		FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP,
417     				     F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
418     		FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
419     		FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
420     		fch->param = 0;
421     		request->shdr.flags = port->flags;
422     		request->shdr.class = 2;
423     		break;
424     		
425     	case PROTO_OFFLINE:
426     		memset (request, 0, sizeof(*request));
427     		request->shdr.token = TOKEN(PROTO_OFFLINE, port->mask, fcmd->token); 
428     		request->type = SOC_CQTYPE_OFFLINE;
429     		FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fc->did);
430     		FILL_FCHDR_SID(fch, fc->sid);
431     		FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP,
432     				     F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
433     		FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
434     		FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
435     		request->shdr.flags = port->flags;
436     		break;
437     		
438     	case PROTO_REPORT_AL_MAP:
439     		/* SOC only supports Point-to-Point topology, no FC-AL, sorry... */
440     		return -ENOSYS;
441     
442     	default: 
443     		request->shdr.token = TOKEN(fcmd->proto, port->mask, fcmd->token);
444     		request->shdr.class = 2;
445     		request->shdr.flags = port->flags;
446     		memcpy (fch, &fcmd->fch, sizeof(fc_hdr));
447     		request->data[0].count = fcmd->cmdlen;
448     		request->data[1].count = fcmd->rsplen;
449     		request->type = fcmd->class;
450     		switch (fcmd->class) {
451     		case FC_CLASS_OUTBOUND:
452     			request->data[0].base = fcmd->cmd;
453     			request->data[0].count = fcmd->cmdlen;
454     			request->type = SOC_CQTYPE_OUTBOUND;
455     			request->shdr.bytecnt = fcmd->cmdlen;
456     			request->shdr.segcnt = 1;
457     			break;
458     		case FC_CLASS_INBOUND:
459     			request->data[0].base = fcmd->rsp;
460     			request->data[0].count = fcmd->rsplen;
461     			request->type = SOC_CQTYPE_INBOUND;
462     			request->shdr.bytecnt = 0;
463     			request->shdr.segcnt = 1;
464     			break;
465     		case FC_CLASS_SIMPLE:
466     			request->data[0].base = fcmd->cmd;
467     			request->data[1].base = fcmd->rsp;
468     			request->data[0].count = fcmd->cmdlen;
469     			request->data[1].count = fcmd->rsplen;
470     			request->type = SOC_CQTYPE_SIMPLE;
471     			request->shdr.bytecnt = fcmd->cmdlen;
472     			request->shdr.segcnt = 2;
473     			break;
474     		case FC_CLASS_IO_READ:
475     		case FC_CLASS_IO_WRITE:
476     			request->data[0].base = fcmd->cmd;
477     			request->data[1].base = fcmd->rsp;
478     			request->data[0].count = fcmd->cmdlen;
479     			request->data[1].count = fcmd->rsplen;
480     			request->type =
481     			      (fcmd->class == FC_CLASS_IO_READ) ?
482     				SOC_CQTYPE_IO_READ : SOC_CQTYPE_IO_WRITE;
483     			if (fcmd->data) {
484     				request->data[2].base = fcmd->data;
485     				request->data[2].count = fcmd->datalen;
486     				request->shdr.bytecnt = fcmd->datalen;
487     				request->shdr.segcnt = 3;
488     			} else {
489     				request->shdr.bytecnt = 0;
490     				request->shdr.segcnt = 2;
491     			}
492     			break;
493     		};
494     		break;
495     	};
496     
497     	request->count = 1;
498     	request->flags = 0;
499     	request->seqno = sw_cq->seqno;
500     	
501     	/* And now tell the SOC about it */
502     
503     	if (++sw_cq->in > sw_cq->last) {
504     		sw_cq->in = 0;
505     		sw_cq->seqno++;
506     	}
507     	
508     	SOD(("Putting %08x into cmd\n",
509     	     SOC_CMD_RSP_QALL | (sw_cq->in << 24) | (SOC_CMD_REQ_Q0 << qno)))
510     	
511     	sbus_writel(SOC_CMD_RSP_QALL | (sw_cq->in << 24) | (SOC_CMD_REQ_Q0 << qno),
512     		    s->regs + CMD);
513     
514     	/* Read so that command is completed. */	
515     	sbus_readl(s->regs + CMD);
516     	
517     	return 0;
518     }
519     
520     static inline void soc_download_fw(struct soc *s)
521     {
522     #ifdef HAVE_SOC_UCODE
523     	xram_copy_to (s->xram, soc_ucode, sizeof(soc_ucode));
524     	xram_bzero (s->xram + sizeof(soc_ucode), 32768 - sizeof(soc_ucode));
525     #endif
526     }
527     
528     /* Check for what the best SBUS burst we can use happens
529      * to be on this machine.
530      */
531     static inline void soc_init_bursts(struct soc *s, struct sbus_dev *sdev)
532     {
533     	int bsizes, bsizes_more;
534     
535     	bsizes = (prom_getintdefault(sdev->prom_node,"burst-sizes",0xff) & 0xff);
536     	bsizes_more = (prom_getintdefault(sdev->bus->prom_node, "burst-sizes", 0xff) & 0xff);
537     	bsizes &= bsizes_more;
538     	if ((bsizes & 0x7f) == 0x7f)
539     		s->cfg = SOC_CFG_BURST_64;
540     	else if ((bsizes & 0x3f) == 0x3f) 
541     		s->cfg = SOC_CFG_BURST_32;
542     	else if ((bsizes & 0x1f) == 0x1f)
543     		s->cfg = SOC_CFG_BURST_16;
544     	else
545     		s->cfg = SOC_CFG_BURST_4;
546     }
547     
548     static inline void soc_init(struct sbus_dev *sdev, int no)
549     {
550     	unsigned char tmp[60];
551     	int propl;
552     	struct soc *s;
553     	static int version_printed = 0;
554     	soc_hw_cq cq[8];
555     	int size, i;
556     	int irq;
557     	
558     	s = kmalloc (sizeof (struct soc), GFP_KERNEL);
559     	if (s == NULL)
560     		return;
561     	memset (s, 0, sizeof(struct soc));
562     	s->soc_no = no;
563     
564     	SOD(("socs %08lx soc_intr %08lx soc_hw_enque %08x\n",
565     	     (long)socs, (long)soc_intr, (long)soc_hw_enque))	
566     	if (version_printed++ == 0)
567     		printk (version);
568     
569     	s->port[0].fc.module = THIS_MODULE;
570     	s->port[1].fc.module = THIS_MODULE;
571     
572     	s->next = socs;
573     	socs = s;
574     	s->port[0].fc.dev = sdev;
575     	s->port[1].fc.dev = sdev;
576     	s->port[0].s = s;
577     	s->port[1].s = s;
578     
579     	s->port[0].fc.next = &s->port[1].fc;
580     
581     	/* World Wide Name of SOC */
582     	propl = prom_getproperty (sdev->prom_node, "soc-wwn", tmp, sizeof(tmp));
583     	if (propl != sizeof (fc_wwn)) {
584     		s->wwn.naaid = NAAID_IEEE;
585     		s->wwn.lo = 0x12345678;
586     	} else
587     		memcpy (&s->wwn, tmp, sizeof (fc_wwn));
588     		
589     	propl = prom_getproperty (sdev->prom_node, "port-wwns", tmp, sizeof(tmp));
590     	if (propl != 2 * sizeof (fc_wwn)) {
591     		s->port[0].fc.wwn_nport.naaid = NAAID_IEEE_EXT;
592     		s->port[0].fc.wwn_nport.hi = s->wwn.hi;
593     		s->port[0].fc.wwn_nport.lo = s->wwn.lo;
594     		s->port[1].fc.wwn_nport.naaid = NAAID_IEEE_EXT;
595     		s->port[1].fc.wwn_nport.nportid = 1;
596     		s->port[1].fc.wwn_nport.hi = s->wwn.hi;
597     		s->port[1].fc.wwn_nport.lo = s->wwn.lo;
598     	} else {
599     		memcpy (&s->port[0].fc.wwn_nport, tmp, sizeof (fc_wwn));
600     		memcpy (&s->port[1].fc.wwn_nport, tmp + sizeof (fc_wwn), sizeof (fc_wwn));
601     	}
602     	memcpy (&s->port[0].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
603     	memcpy (&s->port[1].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
604     	SOD(("Got wwns %08x%08x ports %08x%08x and %08x%08x\n", 
605     	     *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
606     	     *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
607     	     *(u32 *)&s->port[1].fc.wwn_nport, s->port[1].fc.wwn_nport.lo))
608     		
609     	s->port[0].fc.sid = 1;
610     	s->port[1].fc.sid = 17;
611     	s->port[0].fc.did = 2;
612     	s->port[1].fc.did = 18;
613     	
614     	s->port[0].fc.reset = soc_reset;
615     	s->port[1].fc.reset = soc_reset;
616     	
617     	if (sdev->num_registers == 1) {
618     		/* Probably SunFire onboard SOC */
619     		s->xram = sbus_ioremap(&sdev->resource[0], 0,
620     				       0x10000UL, "soc xram");
621     		s->regs = sbus_ioremap(&sdev->resource[0], 0x10000UL,
622     				       0x10UL, "soc regs");
623     	} else {
624     		/* Probably SOC sbus card */
625     		s->xram = sbus_ioremap(&sdev->resource[1], 0,
626     				       sdev->reg_addrs[1].reg_size, "soc xram");
627     		s->regs = sbus_ioremap(&sdev->resource[2], 0,
628     				       sdev->reg_addrs[2].reg_size, "soc regs");
629     	}
630     	
631     	soc_init_bursts(s, sdev);
632     	
633     	SOD(("Disabling SOC\n"))
634     	
635     	soc_disable (s);
636     	
637     	irq = sdev->irqs[0];
638     
639     	if (request_irq (irq, soc_intr, SA_SHIRQ, "SOC", (void *)s)) {
640     		soc_printk ("Cannot order irq %d to go\n", irq);
641     		socs = s->next;
642     		return;
643     	}
644     
645     	SOD(("SOC uses IRQ%s\n", __irq_itoa(irq)))
646     	
647     	s->port[0].fc.irq = irq;
648     	s->port[1].fc.irq = irq;
649     	
650     	sprintf (s->port[0].fc.name, "soc%d port A", no);
651     	sprintf (s->port[1].fc.name, "soc%d port B", no);
652     	s->port[0].flags = SOC_FC_HDR | SOC_PORT_A;
653     	s->port[1].flags = SOC_FC_HDR | SOC_PORT_B;
654     	s->port[1].mask = (1 << 11);
655     	
656     	s->port[0].fc.hw_enque = soc_hw_enque;
657     	s->port[1].fc.hw_enque = soc_hw_enque;
658     	
659     	soc_download_fw (s);
660     	
661     	SOD(("Downloaded firmware\n"))
662     
663     	/* Now setup xram circular queues */
664     	memset (cq, 0, sizeof(cq));
665     	
666     	size = (SOC_CQ_REQ0_SIZE + SOC_CQ_REQ1_SIZE) * sizeof(soc_req);
667     	s->req_cpu = sbus_alloc_consistent(sdev, size, &s->req_dvma);
668     	s->req[0].pool = s->req_cpu;
669     	cq[0].address = s->req_dvma;
670     	s->req[1].pool = s->req[0].pool + SOC_CQ_REQ0_SIZE;
671     	
672     	s->req[0].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_REQ_OFFSET);
673     	s->req[1].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_REQ_OFFSET + sizeof(soc_hw_cq));
674     	s->rsp[0].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_RSP_OFFSET);
675     	s->rsp[1].hw_cq = (soc_hw_cq *)(s->xram + SOC_CQ_RSP_OFFSET + sizeof(soc_hw_cq));
676     	
677     	cq[1].address = cq[0].address + (SOC_CQ_REQ0_SIZE * sizeof(soc_req));
678     	cq[4].address = 1;
679     	cq[5].address = 1;
680     	cq[0].last = SOC_CQ_REQ0_SIZE - 1;
681     	cq[1].last = SOC_CQ_REQ1_SIZE - 1;
682     	cq[4].last = SOC_CQ_RSP0_SIZE - 1;
683     	cq[5].last = SOC_CQ_RSP1_SIZE - 1;
684     	for (i = 0; i < 8; i++)
685     		cq[i].seqno = 1;
686     	
687     	s->req[0].last = SOC_CQ_REQ0_SIZE - 1;
688     	s->req[1].last = SOC_CQ_REQ1_SIZE - 1;
689     	s->rsp[0].last = SOC_CQ_RSP0_SIZE - 1;
690     	s->rsp[1].last = SOC_CQ_RSP1_SIZE - 1;
691     	
692     	s->req[0].seqno = 1;
693     	s->req[1].seqno = 1;
694     	s->rsp[0].seqno = 1;
695     	s->rsp[1].seqno = 1;
696     
697     	xram_copy_to (s->xram + SOC_CQ_REQ_OFFSET, cq, sizeof(cq));
698     	
699     	/* Make our sw copy of SOC service parameters */
700     	xram_copy_from (s->serv_params, s->xram + 0x140, sizeof (s->serv_params));
701     	
702     	s->port[0].fc.common_svc = (common_svc_parm *)s->serv_params;
703     	s->port[0].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
704     	s->port[1].fc.common_svc = (common_svc_parm *)&s->serv_params;
705     	s->port[1].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
706     	
707     	soc_enable (s);
708     	
709     	SOD(("Enabled SOC\n"))
710     }
711     
712     static int __init soc_probe(void)
713     {
714     	struct sbus_bus *sbus;
715     	struct sbus_dev *sdev = 0;
716     	struct soc *s;
717     	int cards = 0;
718     
719     	for_each_sbus(sbus) {
720     		for_each_sbusdev(sdev, sbus) {
721     			if(!strcmp(sdev->prom_name, "SUNW,soc")) {
722     				soc_init(sdev, cards);
723     				cards++;
724     			}
725     		}
726     	}
727     	if (!cards) return -EIO;
728     
729     	for_each_soc(s)
730     		if (s->next)
731     			s->port[1].fc.next = &s->next->port[0].fc;
732     	fcp_init (&socs->port[0].fc);
733     	return 0;
734     }
735     
736     static void __exit soc_cleanup(void)
737     {
738     	struct soc *s;
739     	int irq;
740     	struct sbus_dev *sdev;
741     	
742     	for_each_soc(s) {
743     		irq = s->port[0].fc.irq;
744     		disable_irq (irq);
745     		free_irq (irq, s);
746     
747     		fcp_release(&(s->port[0].fc), 2);
748     
749     		sdev = s->port[0].fc.dev;
750     		if (sdev->num_registers == 1) {
751     			sbus_iounmap(s->xram, 0x10000UL);
752     			sbus_iounmap(s->regs, 0x10UL);
753     		} else {
754     			sbus_iounmap(s->xram, sdev->reg_addrs[1].reg_size);
755     			sbus_iounmap(s->regs, sdev->reg_addrs[2].reg_size);
756     		}
757     		sbus_free_consistent(sdev,
758     				     (SOC_CQ_REQ0_SIZE+SOC_CQ_REQ1_SIZE)*sizeof(soc_req),
759     				     s->req_cpu, s->req_dvma);
760     	}
761     }
762     
763     EXPORT_NO_SYMBOLS;
764     
765     module_init(soc_probe);
766     module_exit(soc_cleanup);
767