aboutsummaryrefslogtreecommitdiff
path: root/drivers/fc4
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/fc4
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/fc4')
-rw-r--r--drivers/fc4/Kconfig81
-rw-r--r--drivers/fc4/Makefile9
-rw-r--r--drivers/fc4/fc-al.h27
-rw-r--r--drivers/fc4/fc.c1158
-rw-r--r--drivers/fc4/fc.h230
-rw-r--r--drivers/fc4/fc_syms.c33
-rw-r--r--drivers/fc4/fcp.h94
-rw-r--r--drivers/fc4/fcp_impl.h164
-rw-r--r--drivers/fc4/soc.c766
-rw-r--r--drivers/fc4/soc.h301
-rw-r--r--drivers/fc4/socal.c906
-rw-r--r--drivers/fc4/socal.h314
12 files changed, 4083 insertions, 0 deletions
diff --git a/drivers/fc4/Kconfig b/drivers/fc4/Kconfig
new file mode 100644
index 00000000000..f00c02a13ed
--- /dev/null
+++ b/drivers/fc4/Kconfig
@@ -0,0 +1,81 @@
+#
+# FC4 device configuration
+#
+
+menu "Fibre Channel support"
+
+config FC4
+ tristate "Fibre Channel and FC4 SCSI support"
+ ---help---
+ Fibre Channel is a high speed serial protocol mainly used to
+ connect large storage devices to the computer; it is compatible with
+ and intended to replace SCSI.
+
+ This is an experimental support for storage arrays connected to your
+ computer using optical fibre cables and the "X3.269-199X Fibre
+ Channel Protocol for SCSI" specification. If you want to use this,
+ you need to say Y here and to "SCSI support" as well as to the
+ drivers for the storage array itself and for the interface adapter
+ such as SOC or SOC+. This subsystem could even serve for IP
+ networking, with some code extensions.
+
+ If unsure, say N.
+
+comment "FC4 drivers"
+ depends on FC4
+
+config FC4_SOC
+ tristate "Sun SOC/Sbus"
+ depends on FC4!=n && (SPARC32 || SPARC64)
+ help
+ Serial Optical Channel is an interface card with one or two Fibre
+ Optic ports, each of which can be connected to a disk array. Note
+ that if you have older firmware in the card, you'll need the
+ microcode from the Solaris driver to make it work.
+
+ To compile this support as a module, choose M here: the module will
+ be called soc.
+
+config FC4_SOCAL
+ tristate "Sun SOC+ (aka SOCAL)"
+ depends on FC4!=n && (SPARC32 || SPARC64)
+ ---help---
+ Serial Optical Channel Plus is an interface card with up to two
+ Fibre Optic ports. This card supports FC Arbitrated Loop (usually
+ A5000 or internal FC disks in E[3-6]000 machines through the
+ Interface Board). You'll probably need the microcode from the
+ Solaris driver to make it work.
+
+ To compile this support as a module, choose M here: the module will
+ be called socal.
+
+comment "FC4 targets"
+ depends on FC4
+
+config SCSI_PLUTO
+ tristate "SparcSTORAGE Array 100 and 200 series"
+ depends on FC4!=n && SCSI
+ help
+ If you never bought a disk array made by Sun, go with N.
+
+ To compile this support as a module, choose M here: the module will
+ be called pluto.
+
+config SCSI_FCAL
+ tristate "Sun Enterprise Network Array (A5000 and EX500)" if SPARC32 || SPARC64
+ depends on FC4!=n && SCSI
+ help
+ This driver drives FC-AL disks connected through a Fibre Channel
+ card using the drivers/fc4 layer (currently only SOCAL). The most
+ common is either A5000 array or internal disks in E[3-6]000
+ machines.
+
+ To compile this support as a module, choose M here: the module will
+ be called fcal.
+
+config SCSI_FCAL
+ prompt "Generic FC-AL disk driver"
+ depends on FC4!=n && SCSI && !SPARC32 && !SPARC64
+
+endmenu
+
diff --git a/drivers/fc4/Makefile b/drivers/fc4/Makefile
new file mode 100644
index 00000000000..0db3fbb553e
--- /dev/null
+++ b/drivers/fc4/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile for the Linux Fibre Channel device drivers.
+#
+
+fc4-objs := fc.o fc_syms.o
+
+obj-$(CONFIG_FC4) += fc4.o
+obj-$(CONFIG_FC4_SOC) += soc.o
+obj-$(CONFIG_FC4_SOCAL) += socal.o
diff --git a/drivers/fc4/fc-al.h b/drivers/fc4/fc-al.h
new file mode 100644
index 00000000000..62d3ca436d7
--- /dev/null
+++ b/drivers/fc4/fc-al.h
@@ -0,0 +1,27 @@
+/* fc-al.h: Definitions for Fibre Channel Arbitrated Loop topology.
+ *
+ * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+ *
+ * Sources:
+ * Fibre Channel Arbitrated Loop (FC-AL), ANSI, Rev. 4.5, 1995
+ */
+
+#ifndef __FC_AL_H
+#define __FC_AL_H
+
+/* Loop initialization payloads */
+#define FC_AL_LISM 0x11010000 /* Select Master, 12B payload */
+#define FC_AL_LIFA 0x11020000 /* Fabric Assign AL_PA bitmap, 20B payload */
+#define FC_AL_LIPA 0x11030000 /* Previously Acquired AL_PA bitmap, 20B payload */
+#define FC_AL_LIHA 0x11040000 /* Hard Assigned AL_PA bitmap, 20B payload */
+#define FC_AL_LISA 0x11050000 /* Soft Assigned AL_PA bitmap, 20B payload */
+#define FC_AL_LIRP 0x11060000 /* Report AL_PA position map, 132B payload */
+#define FC_AL_LILP 0x11070000 /* Loop AL_PA position map, 132B payload */
+
+typedef struct {
+ u32 magic;
+ u8 len;
+ u8 alpa[127];
+} fc_al_posmap;
+
+#endif /* !(__FC_H) */
diff --git a/drivers/fc4/fc.c b/drivers/fc4/fc.c
new file mode 100644
index 00000000000..1fbb219aa9b
--- /dev/null
+++ b/drivers/fc4/fc.c
@@ -0,0 +1,1158 @@
+/* fc.c: Generic Fibre Channel and FC4 SCSI driver.
+ *
+ * Copyright (C) 1997,1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
+ * Copyright (C) 1997,1998 Jirka Hanika (geo@ff.cuni.cz)
+ *
+ * There are two kinds of Fibre Channel adapters used in Linux. Either
+ * the adapter is "smart" and does all FC bookkeeping by itself and
+ * just presents a standard SCSI interface to the operating system
+ * (that's e.g. the case with Qlogic FC cards), or leaves most of the FC
+ * bookkeeping to the OS (e.g. soc, socal). Drivers for the former adapters
+ * will look like normal SCSI drivers (with the exception of max_id will be
+ * usually 127), the latter on the other side allows SCSI, IP over FC and other
+ * protocols. This driver tree is for the latter adapters.
+ *
+ * This file should support both Point-to-Point and Arbitrated Loop topologies.
+ *
+ * Sources:
+ * Fibre Channel Physical & Signaling Interface (FC-PH), dpANS, 1994
+ * dpANS Fibre Channel Protocol for SCSI (X3.269-199X), Rev. 012, 1995
+ * Fibre Channel Arbitrated Loop (FC-AL), Rev. 4.5, 1995
+ * Fibre Channel Private Loop SCSI Direct Attach (FC-PLDA), Rev. 2.1, 1997
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/jiffies.h>
+#include <linux/types.h>
+#include <linux/fcntl.h>
+#include <linux/interrupt.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/in.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/init.h>
+
+#include <asm/pgtable.h>
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include "fcp_impl.h"
+#include <scsi/scsi_host.h>
+
+/* #define FCDEBUG */
+
+#define fc_printk printk ("%s: ", fc->name); printk
+
+#ifdef FCDEBUG
+#define FCD(x) fc_printk x;
+#define FCND(x) printk ("FC: "); printk x;
+#else
+#define FCD(x)
+#define FCND(x)
+#endif
+
+#ifdef __sparc__
+#define dma_alloc_consistent(d,s,p) sbus_alloc_consistent(d,s,p)
+#define dma_free_consistent(d,s,v,h) sbus_free_consistent(d,s,v,h)
+#define dma_map_single(d,v,s,dir) sbus_map_single(d,v,s,dir)
+#define dma_unmap_single(d,h,s,dir) sbus_unmap_single(d,h,s,dir)
+#define dma_map_sg(d,s,n,dir) sbus_map_sg(d,s,n,dir)
+#define dma_unmap_sg(d,s,n,dir) sbus_unmap_sg(d,s,n,dir)
+#else
+#define dma_alloc_consistent(d,s,p) pci_alloc_consistent(d,s,p)
+#define dma_free_consistent(d,s,v,h) pci_free_consistent(d,s,v,h)
+#define dma_map_single(d,v,s,dir) pci_map_single(d,v,s,dir)
+#define dma_unmap_single(d,h,s,dir) pci_unmap_single(d,h,s,dir)
+#define dma_map_sg(d,s,n,dir) pci_map_sg(d,s,n,dir)
+#define dma_unmap_sg(d,s,n,dir) pci_unmap_sg(d,s,n,dir)
+#endif
+
+#define FCP_CMND(SCpnt) ((fcp_cmnd *)&(SCpnt->SCp))
+#define FC_SCMND(SCpnt) ((fc_channel *)(SCpnt->device->host->hostdata[0]))
+#define SC_FCMND(fcmnd) ((Scsi_Cmnd *)((long)fcmnd - (long)&(((Scsi_Cmnd *)0)->SCp)))
+
+static int fcp_scsi_queue_it(fc_channel *, Scsi_Cmnd *, fcp_cmnd *, int);
+void fcp_queue_empty(fc_channel *);
+
+static void fcp_scsi_insert_queue (fc_channel *fc, fcp_cmnd *fcmd)
+{
+ if (!fc->scsi_que) {
+ fc->scsi_que = fcmd;
+ fcmd->next = fcmd;
+ fcmd->prev = fcmd;
+ } else {
+ fc->scsi_que->prev->next = fcmd;
+ fcmd->prev = fc->scsi_que->prev;
+ fc->scsi_que->prev = fcmd;
+ fcmd->next = fc->scsi_que;
+ }
+}
+
+static void fcp_scsi_remove_queue (fc_channel *fc, fcp_cmnd *fcmd)
+{
+ if (fcmd == fcmd->next) {
+ fc->scsi_que = NULL;
+ return;
+ }
+ if (fcmd == fc->scsi_que)
+ fc->scsi_que = fcmd->next;
+ fcmd->prev->next = fcmd->next;
+ fcmd->next->prev = fcmd->prev;
+}
+
+fc_channel *fc_channels = NULL;
+
+#define LSMAGIC 620829043
+typedef struct {
+ /* Must be first */
+ struct semaphore sem;
+ int magic;
+ int count;
+ logi *logi;
+ fcp_cmnd *fcmds;
+ atomic_t todo;
+ struct timer_list timer;
+ unsigned char grace[0];
+} ls;
+
+#define LSOMAGIC 654907799
+typedef struct {
+ /* Must be first */
+ struct semaphore sem;
+ int magic;
+ int count;
+ fcp_cmnd *fcmds;
+ atomic_t todo;
+ struct timer_list timer;
+} lso;
+
+#define LSEMAGIC 84482456
+typedef struct {
+ /* Must be first */
+ struct semaphore sem;
+ int magic;
+ int status;
+ struct timer_list timer;
+} lse;
+
+static void fcp_login_timeout(unsigned long data)
+{
+ ls *l = (ls *)data;
+ FCND(("Login timeout\n"))
+ up(&l->sem);
+}
+
+static void fcp_login_done(fc_channel *fc, int i, int status)
+{
+ fcp_cmnd *fcmd;
+ logi *plogi;
+ fc_hdr *fch;
+ ls *l = (ls *)fc->ls;
+
+ FCD(("Login done %d %d\n", i, status))
+ if (i < l->count) {
+ if (fc->state == FC_STATE_FPORT_OK) {
+ FCD(("Additional FPORT_OK received with status %d\n", status))
+ return;
+ }
+ switch (status) {
+ case FC_STATUS_OK: /* Oh, we found a fabric */
+ case FC_STATUS_P_RJT: /* Oh, we haven't found any */
+ fc->state = FC_STATE_FPORT_OK;
+ fcmd = l->fcmds + i;
+ plogi = l->logi + 3 * i;
+ dma_unmap_single (fc->dev, fcmd->cmd, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ plogi->code = LS_PLOGI;
+ memcpy (&plogi->nport_wwn, &fc->wwn_nport, sizeof(fc_wwn));
+ memcpy (&plogi->node_wwn, &fc->wwn_node, sizeof(fc_wwn));
+ memcpy (&plogi->common, fc->common_svc, sizeof(common_svc_parm));
+ memcpy (&plogi->class1, fc->class_svcs, 3*sizeof(svc_parm));
+ fch = &fcmd->fch;
+ fcmd->token += l->count;
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_ELS_REQ, fc->did);
+ FILL_FCHDR_SID(fch, fc->sid);
+#ifdef FCDEBUG
+ {
+ int i;
+ unsigned *x = (unsigned *)plogi;
+ printk ("logi: ");
+ for (i = 0; i < 21; i++)
+ printk ("%08x ", x[i]);
+ printk ("\n");
+ }
+#endif
+ fcmd->cmd = dma_map_single (fc->dev, plogi, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ fcmd->rsp = fcmd->cmd + 2 * sizeof(logi);
+ if (fc->hw_enque (fc, fcmd))
+ printk ("FC: Cannot enque PLOGI packet on %s\n", fc->name);
+ break;
+ case FC_STATUS_ERR_OFFLINE:
+ fc->state = FC_STATE_MAYBEOFFLINE;
+ FCD (("FC is offline %d\n", l->grace[i]))
+ break;
+ default:
+ printk ("FLOGI failed for %s with status %d\n", fc->name, status);
+ /* Do some sort of error recovery here */
+ break;
+ }
+ } else {
+ i -= l->count;
+ if (fc->state != FC_STATE_FPORT_OK) {
+ FCD(("Unexpected N-PORT rsp received"))
+ return;
+ }
+ switch (status) {
+ case FC_STATUS_OK:
+ plogi = l->logi + 3 * i;
+ dma_unmap_single (fc->dev, l->fcmds[i].cmd, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ if (!fc->wwn_dest.lo && !fc->wwn_dest.hi) {
+ memcpy (&fc->wwn_dest, &plogi[1].node_wwn, sizeof(fc_wwn));
+ FCD(("Dest WWN %08x%08x\n", *(u32 *)&fc->wwn_dest, fc->wwn_dest.lo))
+ } else if (fc->wwn_dest.lo != plogi[1].node_wwn.lo ||
+ fc->wwn_dest.hi != plogi[1].node_wwn.hi) {
+ printk ("%s: mismatch in wwns. Got %08x%08x, expected %08x%08x\n",
+ fc->name,
+ *(u32 *)&plogi[1].node_wwn, plogi[1].node_wwn.lo,
+ *(u32 *)&fc->wwn_dest, fc->wwn_dest.lo);
+ }
+ fc->state = FC_STATE_ONLINE;
+ printk ("%s: ONLINE\n", fc->name);
+ if (atomic_dec_and_test (&l->todo))
+ up(&l->sem);
+ break;
+ case FC_STATUS_ERR_OFFLINE:
+ fc->state = FC_STATE_OFFLINE;
+ dma_unmap_single (fc->dev, l->fcmds[i].cmd, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ printk ("%s: FC is offline\n", fc->name);
+ if (atomic_dec_and_test (&l->todo))
+ up(&l->sem);
+ break;
+ default:
+ printk ("PLOGI failed for %s with status %d\n", fc->name, status);
+ /* Do some sort of error recovery here */
+ break;
+ }
+ }
+}
+
+static void fcp_report_map_done(fc_channel *fc, int i, int status)
+{
+ fcp_cmnd *fcmd;
+ fc_hdr *fch;
+ unsigned char j;
+ ls *l = (ls *)fc->ls;
+ fc_al_posmap *p;
+
+ FCD(("Report map done %d %d\n", i, status))
+ switch (status) {
+ case FC_STATUS_OK: /* Ok, let's have a fun on a loop */
+ dma_unmap_single (fc->dev, l->fcmds[i].cmd, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ p = (fc_al_posmap *)(l->logi + 3 * i);
+#ifdef FCDEBUG
+ {
+ u32 *u = (u32 *)p;
+ FCD(("%08x\n", u[0]))
+ u ++;
+ FCD(("%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]))
+ }
+#endif
+ if ((p->magic & 0xffff0000) != FC_AL_LILP || !p->len) {
+ printk ("FC: Bad magic from REPORT_AL_MAP on %s - %08x\n", fc->name, p->magic);
+ fc->state = FC_STATE_OFFLINE;
+ } else {
+ fc->posmap = (fcp_posmap *)kmalloc(sizeof(fcp_posmap)+p->len, GFP_KERNEL);
+ if (!fc->posmap) {
+ printk("FC: Not enough memory, offlining channel\n");
+ fc->state = FC_STATE_OFFLINE;
+ } else {
+ int k;
+ memset(fc->posmap, 0, sizeof(fcp_posmap)+p->len);
+ /* FIXME: This is where SOCAL transfers our AL-PA.
+ Keep it here till we found out what other cards do... */
+ fc->sid = (p->magic & 0xff);
+ for (i = 0; i < p->len; i++)
+ if (p->alpa[i] == fc->sid)
+ break;
+ k = p->len;
+ if (i == p->len)
+ i = 0;
+ else {
+ p->len--;
+ i++;
+ }
+ fc->posmap->len = p->len;
+ for (j = 0; j < p->len; j++) {
+ if (i == k) i = 0;
+ fc->posmap->list[j] = p->alpa[i++];
+ }
+ fc->state = FC_STATE_ONLINE;
+ }
+ }
+ printk ("%s: ONLINE\n", fc->name);
+ if (atomic_dec_and_test (&l->todo))
+ up(&l->sem);
+ break;
+ case FC_STATUS_POINTTOPOINT: /* We're Point-to-Point, no AL... */
+ FCD(("SID %d DID %d\n", fc->sid, fc->did))
+ fcmd = l->fcmds + i;
+ dma_unmap_single(fc->dev, fcmd->cmd, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ fch = &fcmd->fch;
+ memset(l->logi + 3 * i, 0, 3 * sizeof(logi));
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_ELS_REQ, FS_FABRIC_F_PORT);
+ FILL_FCHDR_SID(fch, 0);
+ FILL_FCHDR_TYPE_FCTL(fch, TYPE_EXTENDED_LS, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
+ FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
+ FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
+ fch->param = 0;
+ l->logi [3 * i].code = LS_FLOGI;
+ fcmd->cmd = dma_map_single (fc->dev, l->logi + 3 * i, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ fcmd->rsp = fcmd->cmd + sizeof(logi);
+ fcmd->cmdlen = sizeof(logi);
+ fcmd->rsplen = sizeof(logi);
+ fcmd->data = (dma_addr_t)NULL;
+ fcmd->class = FC_CLASS_SIMPLE;
+ fcmd->proto = TYPE_EXTENDED_LS;
+ if (fc->hw_enque (fc, fcmd))
+ printk ("FC: Cannot enque FLOGI packet on %s\n", fc->name);
+ break;
+ case FC_STATUS_ERR_OFFLINE:
+ fc->state = FC_STATE_MAYBEOFFLINE;
+ FCD (("FC is offline %d\n", l->grace[i]))
+ break;
+ default:
+ printk ("FLOGI failed for %s with status %d\n", fc->name, status);
+ /* Do some sort of error recovery here */
+ break;
+ }
+}
+
+void fcp_register(fc_channel *fc, u8 type, int unregister)
+{
+ int size, i;
+ int slots = (fc->can_queue * 3) >> 1;
+
+ FCND(("Going to %sregister\n", unregister ? "un" : ""))
+
+ if (type == TYPE_SCSI_FCP) {
+ if (!unregister) {
+ fc->scsi_cmd_pool = (fcp_cmd *)
+ dma_alloc_consistent (fc->dev,
+ slots * (sizeof (fcp_cmd) + fc->rsp_size),
+ &fc->dma_scsi_cmd);
+ fc->scsi_rsp_pool = (char *)(fc->scsi_cmd_pool + slots);
+ fc->dma_scsi_rsp = fc->dma_scsi_cmd + slots * sizeof (fcp_cmd);
+ fc->scsi_bitmap_end = (slots + 63) & ~63;
+ size = fc->scsi_bitmap_end / 8;
+ fc->scsi_bitmap = kmalloc (size, GFP_KERNEL);
+ memset (fc->scsi_bitmap, 0, size);
+ set_bit (0, fc->scsi_bitmap);
+ for (i = fc->can_queue; i < fc->scsi_bitmap_end; i++)
+ set_bit (i, fc->scsi_bitmap);
+ fc->scsi_free = fc->can_queue;
+ fc->cmd_slots = (fcp_cmnd **)kmalloc(slots * sizeof(fcp_cmnd*), GFP_KERNEL);
+ memset(fc->cmd_slots, 0, slots * sizeof(fcp_cmnd*));
+ fc->abort_count = 0;
+ } else {
+ fc->scsi_name[0] = 0;
+ kfree (fc->scsi_bitmap);
+ kfree (fc->cmd_slots);
+ FCND(("Unregistering\n"));
+ if (fc->rst_pkt) {
+ if (fc->rst_pkt->eh_state == SCSI_STATE_UNUSED)
+ kfree(fc->rst_pkt);
+ else {
+ /* Can't happen. Some memory would be lost. */
+ printk("FC: Reset in progress. Now?!");
+ }
+ }
+ FCND(("Unregistered\n"));
+ }
+ } else
+ printk ("FC: %segistering unknown type %02x\n", unregister ? "Unr" : "R", type);
+}
+
+static void fcp_scsi_done(Scsi_Cmnd *SCpnt);
+
+static inline void fcp_scsi_receive(fc_channel *fc, int token, int status, fc_hdr *fch)
+{
+ fcp_cmnd *fcmd;
+ fcp_rsp *rsp;
+ int host_status;
+ Scsi_Cmnd *SCpnt;
+ int sense_len;
+ int rsp_status;
+
+ fcmd = fc->cmd_slots[token];
+ if (!fcmd) return;
+ rsp = (fcp_rsp *) (fc->scsi_rsp_pool + fc->rsp_size * token);
+ SCpnt = SC_FCMND(fcmd);
+
+ if (SCpnt->done != fcp_scsi_done)
+ return;
+
+ rsp_status = rsp->fcp_status;
+ FCD(("rsp_status %08x status %08x\n", rsp_status, status))
+ switch (status) {
+ case FC_STATUS_OK:
+ host_status=DID_OK;
+
+ if (rsp_status & FCP_STATUS_RESID) {
+#ifdef FCDEBUG
+ FCD(("Resid %d\n", rsp->fcp_resid))
+ {
+ fcp_cmd *cmd = fc->scsi_cmd_pool + token;
+ int i;
+
+ printk ("Command ");
+ for (i = 0; i < sizeof(fcp_cmd); i+=4)
+ printk ("%08x ", *(u32 *)(((char *)cmd)+i));
+ printk ("\nResponse ");
+ for (i = 0; i < fc->rsp_size; i+=4)
+ printk ("%08x ", *(u32 *)(((char *)rsp)+i));
+ printk ("\n");
+ }
+#endif
+ }
+
+ if (rsp_status & FCP_STATUS_SENSE_LEN) {
+ sense_len = rsp->fcp_sense_len;
+ if (sense_len > sizeof(SCpnt->sense_buffer)) sense_len = sizeof(SCpnt->sense_buffer);
+ memcpy(SCpnt->sense_buffer, ((char *)(rsp+1)), sense_len);
+ }
+
+ if (fcmd->data) {
+ if (SCpnt->use_sg)
+ dma_unmap_sg(fc->dev, (struct scatterlist *)SCpnt->buffer,
+ SCpnt->use_sg,
+ SCpnt->sc_data_direction);
+ else
+ dma_unmap_single(fc->dev, fcmd->data, SCpnt->request_bufflen,
+ SCpnt->sc_data_direction);
+ }
+ break;
+ default:
+ host_status=DID_ERROR; /* FIXME */
+ FCD(("Wrong FC status %d for token %d\n", status, token))
+ break;
+ }
+
+ if (status_byte(rsp_status) == QUEUE_FULL) {
+ printk ("%s: (%d,%d) Received rsp_status 0x%x\n", fc->name, SCpnt->device->channel, SCpnt->device->id, rsp_status);
+ }
+
+ SCpnt->result = (host_status << 16) | (rsp_status & 0xff);
+#ifdef FCDEBUG
+ if (host_status || SCpnt->result || rsp_status) printk("FC: host_status %d, packet status %d\n",
+ host_status, SCpnt->result);
+#endif
+ SCpnt->done = fcmd->done;
+ fcmd->done=NULL;
+ clear_bit(token, fc->scsi_bitmap);
+ fc->scsi_free++;
+ FCD(("Calling scsi_done with %08x\n", SCpnt->result))
+ SCpnt->scsi_done(SCpnt);
+}
+
+void fcp_receive_solicited(fc_channel *fc, int proto, int token, int status, fc_hdr *fch)
+{
+ int magic;
+ FCD(("receive_solicited %d %d %d\n", proto, token, status))
+ switch (proto) {
+ case TYPE_SCSI_FCP:
+ fcp_scsi_receive(fc, token, status, fch); break;
+ case TYPE_EXTENDED_LS:
+ case PROTO_REPORT_AL_MAP:
+ magic = 0;
+ if (fc->ls)
+ magic = ((ls *)(fc->ls))->magic;
+ if (magic == LSMAGIC) {
+ ls *l = (ls *)fc->ls;
+ int i = (token >= l->count) ? token - l->count : token;
+
+ /* Let's be sure */
+ if ((unsigned)i < l->count && l->fcmds[i].fc == fc) {
+ if (proto == TYPE_EXTENDED_LS)
+ fcp_login_done(fc, token, status);
+ else
+ fcp_report_map_done(fc, token, status);
+ break;
+ }
+ }
+ FCD(("fc %p fc->ls %p fc->cmd_slots %p\n", fc, fc->ls, fc->cmd_slots))
+ if (proto == TYPE_EXTENDED_LS && !fc->ls && fc->cmd_slots) {
+ fcp_cmnd *fcmd;
+
+ fcmd = fc->cmd_slots[token];
+ if (fcmd && fcmd->ls && ((ls *)(fcmd->ls))->magic == LSEMAGIC) {
+ lse *l = (lse *)fcmd->ls;
+
+ l->status = status;
+ up (&l->sem);
+ }
+ }
+ break;
+ case PROTO_OFFLINE:
+ if (fc->ls && ((lso *)(fc->ls))->magic == LSOMAGIC) {
+ lso *l = (lso *)fc->ls;
+
+ if ((unsigned)token < l->count && l->fcmds[token].fc == fc) {
+ /* Wow, OFFLINE response arrived :) */
+ FCD(("OFFLINE Response arrived\n"))
+ fc->state = FC_STATE_OFFLINE;
+ if (atomic_dec_and_test (&l->todo))
+ up(&l->sem);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+void fcp_state_change(fc_channel *fc, int state)
+{
+ FCD(("state_change %d %d\n", state, fc->state))
+ if (state == FC_STATE_ONLINE && fc->state == FC_STATE_MAYBEOFFLINE)
+ fc->state = FC_STATE_UNINITED;
+ else if (state == FC_STATE_ONLINE)
+ printk (KERN_WARNING "%s: state change to ONLINE\n", fc->name);
+ else
+ printk (KERN_ERR "%s: state change to OFFLINE\n", fc->name);
+}
+
+int fcp_initialize(fc_channel *fcchain, int count)
+{
+ fc_channel *fc;
+ fcp_cmnd *fcmd;
+ int i, retry, ret;
+ ls *l;
+
+ FCND(("fcp_inititialize %08lx\n", (long)fcp_init))
+ FCND(("fc_channels %08lx\n", (long)fc_channels))
+ FCND((" SID %d DID %d\n", fcchain->sid, fcchain->did))
+ l = kmalloc(sizeof (ls) + count, GFP_KERNEL);
+ if (!l) {
+ printk ("FC: Cannot allocate memory for initialization\n");
+ return -ENOMEM;
+ }
+ memset (l, 0, sizeof(ls) + count);
+ l->magic = LSMAGIC;
+ l->count = count;
+ FCND(("FCP Init for %d channels\n", count))
+ init_MUTEX_LOCKED(&l->sem);
+ init_timer(&l->timer);
+ l->timer.function = fcp_login_timeout;
+ l->timer.data = (unsigned long)l;
+ atomic_set (&l->todo, count);
+ l->logi = kmalloc (count * 3 * sizeof(logi), GFP_KERNEL);
+ l->fcmds = kmalloc (count * sizeof(fcp_cmnd), GFP_KERNEL);
+ if (!l->logi || !l->fcmds) {
+ if (l->logi) kfree (l->logi);
+ if (l->fcmds) kfree (l->fcmds);
+ kfree (l);
+ printk ("FC: Cannot allocate DMA memory for initialization\n");
+ return -ENOMEM;
+ }
+ memset (l->logi, 0, count * 3 * sizeof(logi));
+ memset (l->fcmds, 0, count * sizeof(fcp_cmnd));
+ for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) {
+ fc->state = FC_STATE_UNINITED;
+ fc->rst_pkt = NULL; /* kmalloc when first used */
+ }
+ /* First try if we are in a AL topology */
+ FCND(("Initializing REPORT_MAP packets\n"))
+ for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) {
+ fcmd = l->fcmds + i;
+ fc->login = fcmd;
+ fc->ls = (void *)l;
+ /* Assumes sizeof(fc_al_posmap) < 3 * sizeof(logi), which is true */
+ fcmd->cmd = dma_map_single (fc->dev, l->logi + 3 * i, 3 * sizeof(logi),
+ DMA_BIDIRECTIONAL);
+ fcmd->proto = PROTO_REPORT_AL_MAP;
+ fcmd->token = i;
+ fcmd->fc = fc;
+ }
+ for (retry = 0; retry < 8; retry++) {
+ int nqueued = 0;
+ FCND(("Sending REPORT_MAP/FLOGI/PLOGI packets\n"))
+ for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) {
+ if (fc->state == FC_STATE_ONLINE || fc->state == FC_STATE_OFFLINE)
+ continue;
+ disable_irq(fc->irq);
+ if (fc->state == FC_STATE_MAYBEOFFLINE) {
+ if (!l->grace[i]) {
+ l->grace[i]++;
+ FCD(("Grace\n"))
+ } else {
+ fc->state = FC_STATE_OFFLINE;
+ enable_irq(fc->irq);
+ dma_unmap_single (fc->dev, l->fcmds[i].cmd, 3 * sizeof(logi), DMA_BIDIRECTIONAL);
+ if (atomic_dec_and_test (&l->todo))
+ goto all_done;
+ }
+ }
+ ret = fc->hw_enque (fc, fc->login);
+ enable_irq(fc->irq);
+ if (!ret) {
+ nqueued++;
+ continue;
+ }
+ if (ret == -ENOSYS && fc->login->proto == PROTO_REPORT_AL_MAP) {
+ /* Oh yes, this card handles Point-to-Point only, so let's try that. */
+ fc_hdr *fch;
+
+ FCD(("SID %d DID %d\n", fc->sid, fc->did))
+ fcmd = l->fcmds + i;
+ dma_unmap_single(fc->dev, fcmd->cmd, 3 * sizeof(logi), DMA_BIDIRECTIONAL);
+ fch = &fcmd->fch;
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_ELS_REQ, FS_FABRIC_F_PORT);
+ FILL_FCHDR_SID(fch, 0);
+ FILL_FCHDR_TYPE_FCTL(fch, TYPE_EXTENDED_LS, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
+ FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
+ FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
+ fch->param = 0;
+ l->logi [3 * i].code = LS_FLOGI;
+ fcmd->cmd = dma_map_single (fc->dev, l->logi + 3 * i, 3 * sizeof(logi), DMA_BIDIRECTIONAL);
+ fcmd->rsp = fcmd->cmd + sizeof(logi);
+ fcmd->cmdlen = sizeof(logi);
+ fcmd->rsplen = sizeof(logi);
+ fcmd->data = (dma_addr_t)NULL;
+ fcmd->class = FC_CLASS_SIMPLE;
+ fcmd->proto = TYPE_EXTENDED_LS;
+ } else
+ printk ("FC: Cannot enque FLOGI/REPORT_MAP packet on %s\n", fc->name);
+ }
+
+ if (nqueued) {
+ l->timer.expires = jiffies + 5 * HZ;
+ add_timer(&l->timer);
+
+ down(&l->sem);
+ if (!atomic_read(&l->todo)) {
+ FCND(("All channels answered in time\n"))
+ break; /* All fc channels have answered us */
+ }
+ }
+ }
+all_done:
+ for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) {
+ fc->ls = NULL;
+ switch (fc->state) {
+ case FC_STATE_ONLINE: break;
+ case FC_STATE_OFFLINE: break;
+ default: dma_unmap_single (fc->dev, l->fcmds[i].cmd, 3 * sizeof(logi), DMA_BIDIRECTIONAL);
+ break;
+ }
+ }
+ del_timer(&l->timer);
+ kfree (l->logi);
+ kfree (l->fcmds);
+ kfree (l);
+ return 0;
+}
+
+int fcp_forceoffline(fc_channel *fcchain, int count)
+{
+ fc_channel *fc;
+ fcp_cmnd *fcmd;
+ int i, ret;
+ lso l;
+
+ memset (&l, 0, sizeof(lso));
+ l.count = count;
+ l.magic = LSOMAGIC;
+ FCND(("FCP Force Offline for %d channels\n", count))
+ init_MUTEX_LOCKED(&l.sem);
+ init_timer(&l.timer);
+ l.timer.function = fcp_login_timeout;
+ l.timer.data = (unsigned long)&l;
+ atomic_set (&l.todo, count);
+ l.fcmds = kmalloc (count * sizeof(fcp_cmnd), GFP_KERNEL);
+ if (!l.fcmds) {
+ kfree (l.fcmds);
+ printk ("FC: Cannot allocate memory for forcing offline\n");
+ return -ENOMEM;
+ }
+ memset (l.fcmds, 0, count * sizeof(fcp_cmnd));
+ FCND(("Initializing OFFLINE packets\n"))
+ for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) {
+ fc->state = FC_STATE_UNINITED;
+ fcmd = l.fcmds + i;
+ fc->login = fcmd;
+ fc->ls = (void *)&l;
+ fcmd->did = fc->did;
+ fcmd->class = FC_CLASS_OFFLINE;
+ fcmd->proto = PROTO_OFFLINE;
+ fcmd->token = i;
+ fcmd->fc = fc;
+ disable_irq(fc->irq);
+ ret = fc->hw_enque (fc, fc->login);
+ enable_irq(fc->irq);
+ if (ret) printk ("FC: Cannot enque OFFLINE packet on %s\n", fc->name);
+ }
+
+ l.timer.expires = jiffies + 5 * HZ;
+ add_timer(&l.timer);
+ down(&l.sem);
+ del_timer(&l.timer);
+
+ for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++)
+ fc->ls = NULL;
+ kfree (l.fcmds);
+ return 0;
+}
+
+int fcp_init(fc_channel *fcchain)
+{
+ fc_channel *fc;
+ int count=0;
+ int ret;
+
+ for (fc = fcchain; fc; fc = fc->next) {
+ fc->fcp_register = fcp_register;
+ count++;
+ }
+
+ ret = fcp_initialize (fcchain, count);
+ if (ret)
+ return ret;
+
+ if (!fc_channels)
+ fc_channels = fcchain;
+ else {
+ for (fc = fc_channels; fc->next; fc = fc->next);
+ fc->next = fcchain;
+ }
+ return ret;
+}
+
+void fcp_release(fc_channel *fcchain, int count) /* count must > 0 */
+{
+ fc_channel *fc;
+ fc_channel *fcx;
+
+ for (fc = fcchain; --count && fc->next; fc = fc->next);
+ if (count) {
+ printk("FC: nothing to release\n");
+ return;
+ }
+
+ if (fc_channels == fcchain)
+ fc_channels = fc->next;
+ else {
+ for (fcx = fc_channels; fcx->next != fcchain; fcx = fcx->next);
+ fcx->next = fc->next;
+ }
+ fc->next = NULL;
+
+ /*
+ * We've just grabbed fcchain out of the fc_channel list
+ * and zero-terminated it, while destroying the count.
+ *
+ * Freeing the fc's is the low level driver's responsibility.
+ */
+}
+
+
+static void fcp_scsi_done (Scsi_Cmnd *SCpnt)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
+ if (FCP_CMND(SCpnt)->done)
+ FCP_CMND(SCpnt)->done(SCpnt);
+ spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
+}
+
+static int fcp_scsi_queue_it(fc_channel *fc, Scsi_Cmnd *SCpnt, fcp_cmnd *fcmd, int prepare)
+{
+ long i;
+ fcp_cmd *cmd;
+ u32 fcp_cntl;
+ if (prepare) {
+ i = find_first_zero_bit (fc->scsi_bitmap, fc->scsi_bitmap_end);
+ set_bit (i, fc->scsi_bitmap);
+ fcmd->token = i;
+ cmd = fc->scsi_cmd_pool + i;
+
+ if (fc->encode_addr (SCpnt, cmd->fcp_addr, fc, fcmd)) {
+ /* Invalid channel/id/lun and couldn't map it into fcp_addr */
+ clear_bit (i, fc->scsi_bitmap);
+ SCpnt->result = (DID_BAD_TARGET << 16);
+ SCpnt->scsi_done(SCpnt);
+ return 0;
+ }
+ fc->scsi_free--;
+ fc->cmd_slots[fcmd->token] = fcmd;
+
+ if (SCpnt->device->tagged_supported) {
+ if (jiffies - fc->ages[SCpnt->device->channel * fc->targets + SCpnt->device->id] > (5 * 60 * HZ)) {
+ fc->ages[SCpnt->device->channel * fc->targets + SCpnt->device->id] = jiffies;
+ fcp_cntl = FCP_CNTL_QTYPE_ORDERED;
+ } else
+ fcp_cntl = FCP_CNTL_QTYPE_SIMPLE;
+ } else
+ fcp_cntl = FCP_CNTL_QTYPE_UNTAGGED;
+ if (!SCpnt->request_bufflen && !SCpnt->use_sg) {
+ cmd->fcp_cntl = fcp_cntl;
+ fcmd->data = (dma_addr_t)NULL;
+ } else {
+ switch (SCpnt->cmnd[0]) {
+ case WRITE_6:
+ case WRITE_10:
+ case WRITE_12:
+ cmd->fcp_cntl = (FCP_CNTL_WRITE | fcp_cntl); break;
+ default:
+ cmd->fcp_cntl = (FCP_CNTL_READ | fcp_cntl); break;
+ }
+ if (!SCpnt->use_sg) {
+ cmd->fcp_data_len = SCpnt->request_bufflen;
+ fcmd->data = dma_map_single (fc->dev, (char *)SCpnt->request_buffer,
+ SCpnt->request_bufflen,
+ SCpnt->sc_data_direction);
+ } else {
+ struct scatterlist *sg = (struct scatterlist *)SCpnt->buffer;
+ int nents;
+
+ FCD(("XXX: Use_sg %d %d\n", SCpnt->use_sg, sg->length))
+ nents = dma_map_sg (fc->dev, sg, SCpnt->use_sg,
+ SCpnt->sc_data_direction);
+ if (nents > 1) printk ("%s: SG for nents %d (use_sg %d) not handled yet\n", fc->name, nents, SCpnt->use_sg);
+ fcmd->data = sg_dma_address(sg);
+ cmd->fcp_data_len = sg_dma_len(sg);
+ }
+ }
+ memcpy (cmd->fcp_cdb, SCpnt->cmnd, SCpnt->cmd_len);
+ memset (cmd->fcp_cdb+SCpnt->cmd_len, 0, sizeof(cmd->fcp_cdb)-SCpnt->cmd_len);
+ FCD(("XXX: %04x.%04x.%04x.%04x - %08x%08x%08x\n", cmd->fcp_addr[0], cmd->fcp_addr[1], cmd->fcp_addr[2], cmd->fcp_addr[3], *(u32 *)SCpnt->cmnd, *(u32 *)(SCpnt->cmnd+4), *(u32 *)(SCpnt->cmnd+8)))
+ }
+ FCD(("Trying to enque %p\n", fcmd))
+ if (!fc->scsi_que) {
+ if (!fc->hw_enque (fc, fcmd)) {
+ FCD(("hw_enque succeeded for %p\n", fcmd))
+ return 0;
+ }
+ }
+ FCD(("Putting into que1 %p\n", fcmd))
+ fcp_scsi_insert_queue (fc, fcmd);
+ return 0;
+}
+
+int fcp_scsi_queuecommand(Scsi_Cmnd *SCpnt, void (* done)(Scsi_Cmnd *))
+{
+ fcp_cmnd *fcmd = FCP_CMND(SCpnt);
+ fc_channel *fc = FC_SCMND(SCpnt);
+
+ FCD(("Entering SCSI queuecommand %p\n", fcmd))
+ if (SCpnt->done != fcp_scsi_done) {
+ fcmd->done = SCpnt->done;
+ SCpnt->done = fcp_scsi_done;
+ SCpnt->scsi_done = done;
+ fcmd->proto = TYPE_SCSI_FCP;
+ if (!fc->scsi_free) {
+ FCD(("FC: !scsi_free, putting cmd on ML queue\n"))
+#if (FCP_SCSI_USE_NEW_EH_CODE == 0)
+ printk("fcp_scsi_queue_command: queue full, losing cmd, bad\n");
+#endif
+ return 1;
+ }
+ return fcp_scsi_queue_it(fc, SCpnt, fcmd, 1);
+ }
+ return fcp_scsi_queue_it(fc, SCpnt, fcmd, 0);
+}
+
+void fcp_queue_empty(fc_channel *fc)
+{
+ fcp_cmnd *fcmd;
+
+ FCD(("Queue empty\n"))
+ while ((fcmd = fc->scsi_que)) {
+ /* The hw told us we can try again queue some packet */
+ if (fc->hw_enque (fc, fcmd))
+ break;
+ fcp_scsi_remove_queue (fc, fcmd);
+ }
+}
+
+int fcp_scsi_abort(Scsi_Cmnd *SCpnt)
+{
+ /* Internal bookkeeping only. Lose 1 cmd_slots slot. */
+ fcp_cmnd *fcmd = FCP_CMND(SCpnt);
+ fc_channel *fc = FC_SCMND(SCpnt);
+
+ /*
+ * We react to abort requests by simply forgetting
+ * about the command and pretending everything's sweet.
+ * This may or may not be silly. We can't, however,
+ * immediately reuse the command's cmd_slots slot,
+ * as its result may arrive later and we cannot
+ * check whether it is the aborted one, can't we?
+ *
+ * Therefore, after the first few aborts are done,
+ * we tell the scsi error handler to do something clever.
+ * It will eventually call host reset, refreshing
+ * cmd_slots for us.
+ *
+ * There is a theoretical chance that we sometimes allow
+ * more than can_queue packets to the jungle this way,
+ * but the worst outcome possible is a series of
+ * more aborts and eventually the dev_reset catharsis.
+ */
+
+ if (++fc->abort_count < (fc->can_queue >> 1)) {
+ unsigned long flags;
+
+ SCpnt->result = DID_ABORT;
+ spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
+ fcmd->done(SCpnt);
+ spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
+ printk("FC: soft abort\n");
+ return SUCCESS;
+ } else {
+ printk("FC: hard abort refused\n");
+ return FAILED;
+ }
+}
+
+void fcp_scsi_reset_done(Scsi_Cmnd *SCpnt)
+{
+ fc_channel *fc = FC_SCMND(SCpnt);
+
+ fc->rst_pkt->eh_state = SCSI_STATE_FINISHED;
+ up(fc->rst_pkt->device->host->eh_action);
+}
+
+#define FCP_RESET_TIMEOUT (2*HZ)
+
+int fcp_scsi_dev_reset(Scsi_Cmnd *SCpnt)
+{
+ fcp_cmd *cmd;
+ fcp_cmnd *fcmd;
+ fc_channel *fc = FC_SCMND(SCpnt);
+ DECLARE_MUTEX_LOCKED(sem);
+
+ if (!fc->rst_pkt) {
+ fc->rst_pkt = (Scsi_Cmnd *) kmalloc(sizeof(SCpnt), GFP_KERNEL);
+ if (!fc->rst_pkt) return FAILED;
+
+ fcmd = FCP_CMND(fc->rst_pkt);
+
+
+ fcmd->token = 0;
+ cmd = fc->scsi_cmd_pool + 0;
+ FCD(("Preparing rst packet\n"))
+ fc->encode_addr (SCpnt, cmd->fcp_addr, fc, fcmd);
+ fc->rst_pkt->device = SCpnt->device;
+ fc->rst_pkt->cmd_len = 0;
+
+ fc->cmd_slots[0] = fcmd;
+
+ cmd->fcp_cntl = FCP_CNTL_QTYPE_ORDERED | FCP_CNTL_RESET;
+ fcmd->data = (dma_addr_t)NULL;
+ fcmd->proto = TYPE_SCSI_FCP;
+
+ memcpy (cmd->fcp_cdb, SCpnt->cmnd, SCpnt->cmd_len);
+ memset (cmd->fcp_cdb+SCpnt->cmd_len, 0, sizeof(cmd->fcp_cdb)-SCpnt->cmd_len);
+ FCD(("XXX: %04x.%04x.%04x.%04x - %08x%08x%08x\n", cmd->fcp_addr[0], cmd->fcp_addr[1], cmd->fcp_addr[2], cmd->fcp_addr[3], *(u32 *)SCpnt->cmnd, *(u32 *)(SCpnt->cmnd+4), *(u32 *)(SCpnt->cmnd+8)))
+ } else {
+ fcmd = FCP_CMND(fc->rst_pkt);
+ if (fc->rst_pkt->eh_state == SCSI_STATE_QUEUED)
+ return FAILED; /* or SUCCESS. Only these */
+ }
+ fc->rst_pkt->done = NULL;
+
+
+ fc->rst_pkt->eh_state = SCSI_STATE_QUEUED;
+ init_timer(&fc->rst_pkt->eh_timeout);
+ fc->rst_pkt->eh_timeout.data = (unsigned long) fc->rst_pkt;
+ fc->rst_pkt->eh_timeout.expires = jiffies + FCP_RESET_TIMEOUT;
+ fc->rst_pkt->eh_timeout.function = (void (*)(unsigned long))fcp_scsi_reset_done;
+
+ add_timer(&fc->rst_pkt->eh_timeout);
+
+ /*
+ * Set up the semaphore so we wait for the command to complete.
+ */
+
+ fc->rst_pkt->device->host->eh_action = &sem;
+ fc->rst_pkt->request->rq_status = RQ_SCSI_BUSY;
+
+ fc->rst_pkt->done = fcp_scsi_reset_done;
+ fcp_scsi_queue_it(fc, fc->rst_pkt, fcmd, 0);
+
+ down(&sem);
+
+ fc->rst_pkt->device->host->eh_action = NULL;
+ del_timer(&fc->rst_pkt->eh_timeout);
+
+ /*
+ * See if timeout. If so, tell the host to forget about it.
+ * In other words, we don't want a callback any more.
+ */
+ if (fc->rst_pkt->eh_state == SCSI_STATE_TIMEOUT ) {
+ fc->rst_pkt->eh_state = SCSI_STATE_UNUSED;
+ return FAILED;
+ }
+ fc->rst_pkt->eh_state = SCSI_STATE_UNUSED;
+ return SUCCESS;
+}
+
+int fcp_scsi_bus_reset(Scsi_Cmnd *SCpnt)
+{
+ printk ("FC: bus reset!\n");
+ return FAILED;
+}
+
+int fcp_scsi_host_reset(Scsi_Cmnd *SCpnt)
+{
+ fc_channel *fc = FC_SCMND(SCpnt);
+ fcp_cmnd *fcmd = FCP_CMND(SCpnt);
+ int i;
+
+ printk ("FC: host reset\n");
+
+ for (i=0; i < fc->can_queue; i++) {
+ if (fc->cmd_slots[i] && SCpnt->result != DID_ABORT) {
+ SCpnt->result = DID_RESET;
+ fcmd->done(SCpnt);
+ fc->cmd_slots[i] = NULL;
+ }
+ }
+ fc->reset(fc);
+ fc->abort_count = 0;
+ if (fcp_initialize(fc, 1)) return SUCCESS;
+ else return FAILED;
+}
+
+static int fcp_els_queue_it(fc_channel *fc, fcp_cmnd *fcmd)
+{
+ long i;
+
+ i = find_first_zero_bit (fc->scsi_bitmap, fc->scsi_bitmap_end);
+ set_bit (i, fc->scsi_bitmap);
+ fcmd->token = i;
+ fc->scsi_free--;
+ fc->cmd_slots[fcmd->token] = fcmd;
+ return fcp_scsi_queue_it(fc, NULL, fcmd, 0);
+}
+
+static int fc_do_els(fc_channel *fc, unsigned int alpa, void *data, int len)
+{
+ fcp_cmnd _fcmd, *fcmd;
+ fc_hdr *fch;
+ lse l;
+ int i;
+
+ fcmd = &_fcmd;
+ memset(fcmd, 0, sizeof(fcmd));
+ FCD(("PLOGI SID %d DID %d\n", fc->sid, alpa))
+ fch = &fcmd->fch;
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_ELS_REQ, alpa);
+ FILL_FCHDR_SID(fch, fc->sid);
+ FILL_FCHDR_TYPE_FCTL(fch, TYPE_EXTENDED_LS, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
+ FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
+ FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
+ fch->param = 0;
+ fcmd->cmd = dma_map_single (fc->dev, data, 2 * len, DMA_BIDIRECTIONAL);
+ fcmd->rsp = fcmd->cmd + len;
+ fcmd->cmdlen = len;
+ fcmd->rsplen = len;
+ fcmd->data = (dma_addr_t)NULL;
+ fcmd->fc = fc;
+ fcmd->class = FC_CLASS_SIMPLE;
+ fcmd->proto = TYPE_EXTENDED_LS;
+
+ memset (&l, 0, sizeof(lse));
+ l.magic = LSEMAGIC;
+ init_MUTEX_LOCKED(&l.sem);
+ l.timer.function = fcp_login_timeout;
+ l.timer.data = (unsigned long)&l;
+ l.status = FC_STATUS_TIMED_OUT;
+ fcmd->ls = (void *)&l;
+
+ disable_irq(fc->irq);
+ fcp_els_queue_it(fc, fcmd);
+ enable_irq(fc->irq);
+
+ for (i = 0;;) {
+ l.timer.expires = jiffies + 5 * HZ;
+ add_timer(&l.timer);
+ down(&l.sem);
+ del_timer(&l.timer);
+ if (l.status != FC_STATUS_TIMED_OUT) break;
+ if (++i == 3) break;
+ disable_irq(fc->irq);
+ fcp_scsi_queue_it(fc, NULL, fcmd, 0);
+ enable_irq(fc->irq);
+ }
+
+ clear_bit(fcmd->token, fc->scsi_bitmap);
+ fc->scsi_free++;
+ dma_unmap_single (fc->dev, fcmd->cmd, 2 * len, DMA_BIDIRECTIONAL);
+ return l.status;
+}
+
+int fc_do_plogi(fc_channel *fc, unsigned char alpa, fc_wwn *node, fc_wwn *nport)
+{
+ logi *l;
+ int status;
+
+ l = (logi *)kmalloc(2 * sizeof(logi), GFP_KERNEL);
+ if (!l) return -ENOMEM;
+ memset(l, 0, 2 * sizeof(logi));
+ l->code = LS_PLOGI;
+ memcpy (&l->nport_wwn, &fc->wwn_nport, sizeof(fc_wwn));
+ memcpy (&l->node_wwn, &fc->wwn_node, sizeof(fc_wwn));
+ memcpy (&l->common, fc->common_svc, sizeof(common_svc_parm));
+ memcpy (&l->class1, fc->class_svcs, 3*sizeof(svc_parm));
+ status = fc_do_els(fc, alpa, l, sizeof(logi));
+ if (status == FC_STATUS_OK) {
+ if (l[1].code == LS_ACC) {
+#ifdef FCDEBUG
+ u32 *u = (u32 *)&l[1].nport_wwn;
+ FCD(("AL-PA %02x: Port WWN %08x%08x Node WWN %08x%08x\n", alpa,
+ u[0], u[1], u[2], u[3]))
+#endif
+ memcpy(nport, &l[1].nport_wwn, sizeof(fc_wwn));
+ memcpy(node, &l[1].node_wwn, sizeof(fc_wwn));
+ } else
+ status = FC_STATUS_BAD_RSP;
+ }
+ kfree(l);
+ return status;
+}
+
+typedef struct {
+ unsigned int code;
+ unsigned params[4];
+} prli;
+
+int fc_do_prli(fc_channel *fc, unsigned char alpa)
+{
+ prli *p;
+ int status;
+
+ p = (prli *)kmalloc(2 * sizeof(prli), GFP_KERNEL);
+ if (!p) return -ENOMEM;
+ memset(p, 0, 2 * sizeof(prli));
+ p->code = LS_PRLI;
+ p->params[0] = 0x08002000;
+ p->params[3] = 0x00000022;
+ status = fc_do_els(fc, alpa, p, sizeof(prli));
+ if (status == FC_STATUS_OK && p[1].code != LS_PRLI_ACC && p[1].code != LS_ACC)
+ status = FC_STATUS_BAD_RSP;
+ kfree(p);
+ return status;
+}
+
+MODULE_LICENSE("GPL");
+
diff --git a/drivers/fc4/fc.h b/drivers/fc4/fc.h
new file mode 100644
index 00000000000..13f89d4c8cb
--- /dev/null
+++ b/drivers/fc4/fc.h
@@ -0,0 +1,230 @@
+/* fc.h: Definitions for Fibre Channel Physical and Signaling Interface.
+ *
+ * Copyright (C) 1996-1997,1999 Jakub Jelinek (jj@ultra.linux.cz)
+ *
+ * Sources:
+ * Fibre Channel Physical & Signaling Interface (FC-PH), dpANS, 1994
+ * dpANS Fibre Channel Protocol for SCSI (X3.269-199X), Rev. 012, 1995
+ */
+
+#ifndef __FC_H
+#define __FC_H
+
+/* World Wide Name */
+#define NAAID_IEEE 1
+#define NAAID_IEEE_EXT 2
+#define NAAID_LOCAL 3
+#define NAAID_IP 4
+#define NAAID_IEEE_REG 5
+#define NAAID_IEEE_REG_EXT 6
+#define NAAID_CCITT 12
+#define NAAID_CCITT_GRP 14
+
+/* This is NAAID_IEEE_EXT scheme */
+typedef struct {
+ u32 naaid:4;
+ u32 nportid:12;
+ u32 hi:16;
+ u32 lo;
+} fc_wwn;
+
+/* Frame header for FC-PH frames */
+
+/* r_ctl field */
+#define R_CTL_DEVICE_DATA 0x00 /* FC4 Device_Data frame */
+#define R_CTL_EXTENDED_SVC 0x20 /* Extended Link_Data frame */
+#define R_CTL_FC4_SVC 0x30 /* FC4 Link_Data frame */
+#define R_CTL_VIDEO 0x40 /* Video_Data frame */
+#define R_CTL_BASIC_SVC 0x80 /* Basic Link_Data frame */
+#define R_CTL_LINK_CTL 0xc0 /* Link_Control frame */
+/* FC4 Device_Data frames */
+#define R_CTL_UNCATEGORIZED 0x00
+#define R_CTL_SOLICITED_DATA 0x01
+#define R_CTL_UNSOL_CONTROL 0x02
+#define R_CTL_SOLICITED_CONTROL 0x03
+#define R_CTL_UNSOL_DATA 0x04
+#define R_CTL_XFER_RDY 0x05
+#define R_CTL_COMMAND 0x06
+#define R_CTL_STATUS 0x07
+/* Basic Link_Data frames */
+#define R_CTL_LS_NOP 0x80
+#define R_CTL_LS_ABTS 0x81
+#define R_CTL_LS_RMC 0x82
+#define R_CTL_LS_BA_ACC 0x84
+#define R_CTL_LS_BA_RJT 0x85
+/* Extended Link_Data frames */
+#define R_CTL_ELS_REQ 0x22
+#define R_CTL_ELS_RSP 0x23
+/* Link_Control frames */
+#define R_CTL_ACK_1 0xc0
+#define R_CTL_ACK_N 0xc1
+#define R_CTL_P_RJT 0xc2
+#define R_CTL_F_RJT 0xc3
+#define R_CTL_P_BSY 0xc4
+#define R_CTL_F_BSY_DF 0xc5
+#define R_CTL_F_BSY_LC 0xc6
+#define R_CTL_LCR 0xc7
+
+/* type field */
+#define TYPE_BASIC_LS 0x00
+#define TYPE_EXTENDED_LS 0x01
+#define TYPE_IS8802 0x04
+#define TYPE_IS8802_SNAP 0x05
+#define TYPE_SCSI_FCP 0x08
+#define TYPE_SCSI_GPP 0x09
+#define TYPE_HIPP_FP 0x0a
+#define TYPE_IPI3_MASTER 0x11
+#define TYPE_IPI3_SLAVE 0x12
+#define TYPE_IPI3_PEER 0x13
+
+/* f_ctl field */
+#define F_CTL_FILL_BYTES 0x000003
+#define F_CTL_XCHG_REASSEMBLE 0x000004
+#define F_CTL_RO_PRESENT 0x000008
+#define F_CTL_ABORT_SEQ 0x000030
+#define F_CTL_CONTINUE_SEQ 0x0000c0
+#define F_CTL_INVALIDATE_XID 0x004000
+#define F_CTL_XID_REASSIGNED 0x008000
+#define F_CTL_SEQ_INITIATIVE 0x010000
+#define F_CTL_CHAINED_SEQ 0x020000
+#define F_CTL_END_CONNECT 0x040000
+#define F_CTL_END_SEQ 0x080000
+#define F_CTL_LAST_SEQ 0x100000
+#define F_CTL_FIRST_SEQ 0x200000
+#define F_CTL_SEQ_CONTEXT 0x400000
+#define F_CTL_XCHG_CONTEXT 0x800000
+
+typedef struct {
+ u32 r_ctl:8, did:24;
+ u32 xxx1:8, sid:24;
+ u32 type:8, f_ctl:24;
+ u32 seq_id:8, df_ctl:8, seq_cnt:16;
+ u16 ox_id, rx_id;
+ u32 param;
+} fc_hdr;
+/* The following are ugly macros to make setup of this structure faster */
+#define FILL_FCHDR_RCTL_DID(fch, r_ctl, did) *(u32 *)(fch) = ((r_ctl) << 24) | (did);
+#define FILL_FCHDR_SID(fch, sid) *((u32 *)(fch)+1) = (sid);
+#define FILL_FCHDR_TYPE_FCTL(fch, type, f_ctl) *((u32 *)(fch)+2) = ((type) << 24) | (f_ctl);
+#define FILL_FCHDR_SEQ_DF_SEQ(fch, seq_id, df_ctl, seq_cnt) *((u32 *)(fch)+3) = ((seq_id) << 24) | ((df_ctl) << 16) | (seq_cnt);
+#define FILL_FCHDR_OXRX(fch, ox_id, rx_id) *((u32 *)(fch)+4) = ((ox_id) << 16) | (rx_id);
+
+/* Well known addresses */
+#define FS_GENERAL_MULTICAST 0xfffff7
+#define FS_WELL_KNOWN_MULTICAST 0xfffff8
+#define FS_HUNT_GROUP 0xfffff9
+#define FS_MANAGEMENT_SERVER 0xfffffa
+#define FS_TIME_SERVER 0xfffffb
+#define FS_NAME_SERVER 0xfffffc
+#define FS_FABRIC_CONTROLLER 0xfffffd
+#define FS_FABRIC_F_PORT 0xfffffe
+#define FS_BROADCAST 0xffffff
+
+/* Reject frames */
+/* The param field should be cast to this structure */
+typedef struct {
+ u8 action;
+ u8 reason;
+ u8 xxx;
+ u8 vendor_unique;
+} rjt_param;
+
+/* Reject action codes */
+#define RJT_RETRY 0x01
+#define RJT_NONRETRY 0x02
+
+/* Reject reason codes */
+#define RJT_INVALID_DID 0x01
+#define RJT_INVALID_SID 0x02
+#define RJT_NPORT_NOT_AVAIL_TEMP 0x03
+#define RJT_NPORT_NOT_AVAIL_PERM 0x04
+#define RJT_CLASS_NOT_SUPPORTED 0x05
+#define RJT_DELIMITER_ERROR 0x06
+#define RJT_TYPE_NOT_SUPPORTED 0x07
+#define RJT_INVALID_LINK_CONTROL 0x08
+#define RJT_INVALID_R_CTL 0x09
+#define RJT_INVALID_F_CTL 0x0a
+#define RJT_INVALID_OX_ID 0x0b
+#define RJT_INVALID_RX_ID 0x0c
+#define RJT_INVALID_SEQ_ID 0x0d
+#define RJT_INVALID_DF_CTL 0x0e
+#define RJT_INVALID_SEQ_CNT 0x0f
+#define RJT_INVALID_PARAMETER 0x10
+#define RJT_EXCHANGE_ERROR 0x11
+#define RJT_PROTOCOL_ERROR 0x12
+#define RJT_INCORRECT_LENGTH 0x13
+#define RJT_UNEXPECTED_ACK 0x14
+#define RJT_UNEXPECTED_LINK_RESP 0x15
+#define RJT_LOGIN_REQUIRED 0x16
+#define RJT_EXCESSIVE_SEQUENCES 0x17
+#define RJT_CANT_ESTABLISH_EXCHANGE 0x18
+#define RJT_SECURITY_NOT_SUPPORTED 0x19
+#define RJT_FABRIC_NA 0x1a
+#define RJT_VENDOR_UNIQUE 0xff
+
+
+#define SP_F_PORT_LOGIN 0x10
+
+/* Extended SVC commands */
+#define LS_RJT 0x01000000
+#define LS_ACC 0x02000000
+#define LS_PRLI_ACC 0x02100014
+#define LS_PLOGI 0x03000000
+#define LS_FLOGI 0x04000000
+#define LS_LOGO 0x05000000
+#define LS_ABTX 0x06000000
+#define LS_RCS 0x07000000
+#define LS_RES 0x08000000
+#define LS_RSS 0x09000000
+#define LS_RSI 0x0a000000
+#define LS_ESTS 0x0b000000
+#define LS_ESTC 0x0c000000
+#define LS_ADVC 0x0d000000
+#define LS_RTV 0x0e000000
+#define LS_RLS 0x0f000000
+#define LS_ECHO 0x10000000
+#define LS_TEST 0x11000000
+#define LS_RRQ 0x12000000
+#define LS_IDENT 0x20000000
+#define LS_PRLI 0x20100014
+#define LS_DISPLAY 0x21000000
+#define LS_PRLO 0x21100014
+#define LS_PDISC 0x50000000
+#define LS_ADISC 0x52000000
+
+typedef struct {
+ u8 fcph_hi, fcph_lo;
+ u16 buf2buf_credit;
+ u8 common_features;
+ u8 xxx1;
+ u16 buf2buf_size;
+ u8 xxx2;
+ u8 total_concurrent;
+ u16 off_by_info;
+ u32 e_d_tov;
+} common_svc_parm;
+
+typedef struct {
+ u16 serv_opts;
+ u16 initiator_ctl;
+ u16 rcpt_ctl;
+ u16 recv_size;
+ u8 xxx1;
+ u8 concurrent_seqs;
+ u16 end2end_credit;
+ u16 open_seqs_per_xchg;
+ u16 xxx2;
+} svc_parm;
+
+/* Login */
+typedef struct {
+ u32 code;
+ common_svc_parm common;
+ fc_wwn nport_wwn;
+ fc_wwn node_wwn;
+ svc_parm class1;
+ svc_parm class2;
+ svc_parm class3;
+} logi;
+
+#endif /* !(__FC_H) */
diff --git a/drivers/fc4/fc_syms.c b/drivers/fc4/fc_syms.c
new file mode 100644
index 00000000000..8bac2c45302
--- /dev/null
+++ b/drivers/fc4/fc_syms.c
@@ -0,0 +1,33 @@
+/*
+ * We should not even be trying to compile this if we are not doing
+ * a module.
+ */
+#include <linux/config.h>
+#include <linux/module.h>
+
+#ifdef CONFIG_MODULES
+
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+
+#include "fcp_impl.h"
+
+EXPORT_SYMBOL(fcp_init);
+EXPORT_SYMBOL(fcp_release);
+EXPORT_SYMBOL(fcp_queue_empty);
+EXPORT_SYMBOL(fcp_receive_solicited);
+EXPORT_SYMBOL(fc_channels);
+EXPORT_SYMBOL(fcp_state_change);
+EXPORT_SYMBOL(fc_do_plogi);
+EXPORT_SYMBOL(fc_do_prli);
+
+/* SCSI stuff */
+EXPORT_SYMBOL(fcp_scsi_queuecommand);
+EXPORT_SYMBOL(fcp_scsi_abort);
+EXPORT_SYMBOL(fcp_scsi_dev_reset);
+EXPORT_SYMBOL(fcp_scsi_bus_reset);
+EXPORT_SYMBOL(fcp_scsi_host_reset);
+
+#endif /* CONFIG_MODULES */
diff --git a/drivers/fc4/fcp.h b/drivers/fc4/fcp.h
new file mode 100644
index 00000000000..6aa34a7a4c1
--- /dev/null
+++ b/drivers/fc4/fcp.h
@@ -0,0 +1,94 @@
+/* fcp.h: Definitions for Fibre Channel Protocol.
+ *
+ * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+ *
+ */
+
+#ifndef __FCP_H
+#define __FCP_H
+
+/* FCP addressing is hierarchical with up to 4 layers, MS first.
+ Exact meaning of the addresses is up to the vendor */
+
+/* fcp_cntl field */
+#define FCP_CNTL_WRITE 0x00000001 /* Initiator write */
+#define FCP_CNTL_READ 0x00000002 /* Initiator read */
+#define FCP_CNTL_ABORT_TSK 0x00000200 /* Abort task set */
+#define FCP_CNTL_CLR_TASK 0x00000400 /* Clear task set */
+#define FCP_CNTL_RESET 0x00002000 /* Reset */
+#define FCP_CNTL_CLR_ACA 0x00004000 /* Clear ACA */
+#define FCP_CNTL_KILL_TASK 0x00008000 /* Terminate task */
+#define FCP_CNTL_QTYPE_MASK 0x00070000 /* Tagged queueing type */
+#define FCP_CNTL_QTYPE_SIMPLE 0x00000000
+#define FCP_CNTL_QTYPE_HEAD_OF_Q 0x00010000
+#define FCP_CNTL_QTYPE_ORDERED 0x00020000
+#define FCP_CNTL_QTYPE_ACA_Q_TAG 0x00040000
+#define FCP_CNTL_QTYPE_UNTAGGED 0x00050000
+
+typedef struct {
+ u16 fcp_addr[4];
+ u32 fcp_cntl;
+ u8 fcp_cdb[16];
+ u32 fcp_data_len;
+} fcp_cmd;
+
+/* fcp_status field */
+#define FCP_STATUS_MASK 0x000000ff /* scsi status of command */
+#define FCP_STATUS_RSP_LEN 0x00000100 /* response_len != 0 */
+#define FCP_STATUS_SENSE_LEN 0x00000200 /* sense_len != 0 */
+#define FCP_STATUS_RESID 0x00000400 /* resid != 0 */
+
+typedef struct {
+ u32 xxx[2];
+ u32 fcp_status;
+ u32 fcp_resid;
+ u32 fcp_sense_len;
+ u32 fcp_response_len;
+ /* u8 fcp_sense[fcp_sense_len]; */
+ /* u8 fcp_response[fcp_response_len]; */
+} fcp_rsp;
+
+/* fcp errors */
+
+/* rsp_info_type field */
+#define FCP_RSP_SCSI_BUS_ERR 0x01
+#define FCP_RSP_SCSI_PORT_ERR 0x02
+#define FCP_RSP_CARD_ERR 0x03
+
+/* isp_status field */
+#define FCP_RSP_CMD_COMPLETE 0x0000
+#define FCP_RSP_CMD_INCOMPLETE 0x0001
+#define FCP_RSP_CMD_DMA_ERR 0x0002
+#define FCP_RSP_CMD_TRAN_ERR 0x0003
+#define FCP_RSP_CMD_RESET 0x0004
+#define FCP_RSP_CMD_ABORTED 0x0005
+#define FCP_RSP_CMD_TIMEOUT 0x0006
+#define FCP_RSP_CMD_OVERRUN 0x0007
+
+/* isp_state_flags field */
+#define FCP_RSP_ST_GOT_BUS 0x0100
+#define FCP_RSP_ST_GOT_TARGET 0x0200
+#define FCP_RSP_ST_SENT_CMD 0x0400
+#define FCP_RSP_ST_XFRD_DATA 0x0800
+#define FCP_RSP_ST_GOT_STATUS 0x1000
+#define FCP_RSP_ST_GOT_SENSE 0x2000
+
+/* isp_stat_flags field */
+#define FCP_RSP_STAT_DISC 0x0001
+#define FCP_RSP_STAT_SYNC 0x0002
+#define FCP_RSP_STAT_PERR 0x0004
+#define FCP_RSP_STAT_BUS_RESET 0x0008
+#define FCP_RSP_STAT_DEV_RESET 0x0010
+#define FCP_RSP_STAT_ABORTED 0x0020
+#define FCP_RSP_STAT_TIMEOUT 0x0040
+#define FCP_RSP_STAT_NEGOTIATE 0x0080
+
+typedef struct {
+ u8 rsp_info_type;
+ u8 xxx;
+ u16 isp_status;
+ u16 isp_state_flags;
+ u16 isp_stat_flags;
+} fcp_scsi_err;
+
+#endif /* !(__FCP_H) */
diff --git a/drivers/fc4/fcp_impl.h b/drivers/fc4/fcp_impl.h
new file mode 100644
index 00000000000..e44d652a83d
--- /dev/null
+++ b/drivers/fc4/fcp_impl.h
@@ -0,0 +1,164 @@
+/* fcp_impl.h: Generic SCSI on top of FC4 - our interface defines.
+ *
+ * Copyright (C) 1997-1999 Jakub Jelinek (jj@ultra.linux.cz)
+ * Copyright (C) 1998 Jirka Hanika (geo@ff.cuni.cz)
+ */
+
+#ifndef _FCP_SCSI_H
+#define _FCP_SCSI_H
+
+#include <linux/types.h>
+#include "../scsi/scsi.h"
+
+#include "fc.h"
+#include "fcp.h"
+#include "fc-al.h"
+
+#include <asm/io.h>
+#ifdef __sparc__
+#include <asm/sbus.h>
+#endif
+
+/* 0 or 1 */
+#define FCP_SCSI_USE_NEW_EH_CODE 0
+
+#define FC_CLASS_OUTBOUND 0x01
+#define FC_CLASS_INBOUND 0x02
+#define FC_CLASS_SIMPLE 0x03
+#define FC_CLASS_IO_WRITE 0x04
+#define FC_CLASS_IO_READ 0x05
+#define FC_CLASS_UNSOLICITED 0x06
+#define FC_CLASS_OFFLINE 0x08
+
+#define PROTO_OFFLINE 0x02
+#define PROTO_REPORT_AL_MAP 0x03
+#define PROTO_FORCE_LIP 0x06
+
+struct _fc_channel;
+
+typedef struct fcp_cmnd {
+ struct fcp_cmnd *next;
+ struct fcp_cmnd *prev;
+ void (*done)(Scsi_Cmnd *);
+ unsigned short proto;
+ unsigned short token;
+ unsigned int did;
+ /* FCP SCSI stuff */
+ dma_addr_t data;
+ /* From now on this cannot be touched for proto == TYPE_SCSI_FCP */
+ fc_hdr fch;
+ dma_addr_t cmd;
+ dma_addr_t rsp;
+ int cmdlen;
+ int rsplen;
+ int class;
+ int datalen;
+ /* This is just used as a verification during login */
+ struct _fc_channel *fc;
+ void *ls;
+} fcp_cmnd;
+
+typedef struct {
+ unsigned int len;
+ unsigned char list[0];
+} fcp_posmap;
+
+typedef struct _fc_channel {
+ struct _fc_channel *next;
+ int irq;
+ int state;
+ int sid;
+ int did;
+ char name[16];
+ void (*fcp_register)(struct _fc_channel *, u8, int);
+ void (*reset)(struct _fc_channel *);
+ int (*hw_enque)(struct _fc_channel *, fcp_cmnd *);
+ fc_wwn wwn_node;
+ fc_wwn wwn_nport;
+ fc_wwn wwn_dest;
+ common_svc_parm *common_svc;
+ svc_parm *class_svcs;
+#ifdef __sparc__
+ struct sbus_dev *dev;
+#else
+ struct pci_dev *dev;
+#endif
+ struct module *module;
+ /* FCP SCSI stuff */
+ short can_queue;
+ short abort_count;
+ int rsp_size;
+ fcp_cmd *scsi_cmd_pool;
+ char *scsi_rsp_pool;
+ dma_addr_t dma_scsi_cmd, dma_scsi_rsp;
+ long *scsi_bitmap;
+ long scsi_bitmap_end;
+ int scsi_free;
+ int (*encode_addr)(Scsi_Cmnd *, u16 *, struct _fc_channel *, fcp_cmnd *);
+ fcp_cmnd *scsi_que;
+ char scsi_name[4];
+ fcp_cmnd **cmd_slots;
+ int channels;
+ int targets;
+ long *ages;
+ Scsi_Cmnd *rst_pkt;
+ fcp_posmap *posmap;
+ /* LOGIN stuff */
+ fcp_cmnd *login;
+ void *ls;
+} fc_channel;
+
+extern fc_channel *fc_channels;
+
+#define FC_STATE_UNINITED 0
+#define FC_STATE_ONLINE 1
+#define FC_STATE_OFFLINE 2
+#define FC_STATE_RESETING 3
+#define FC_STATE_FPORT_OK 4
+#define FC_STATE_MAYBEOFFLINE 5
+
+#define FC_STATUS_OK 0
+#define FC_STATUS_P_RJT 2
+#define FC_STATUS_F_RJT 3
+#define FC_STATUS_P_BSY 4
+#define FC_STATUS_F_BSY 5
+#define FC_STATUS_ERR_OFFLINE 0x11
+#define FC_STATUS_TIMEOUT 0x12
+#define FC_STATUS_ERR_OVERRUN 0x13
+#define FC_STATUS_POINTTOPOINT 0x15
+#define FC_STATUS_AL 0x16
+#define FC_STATUS_UNKNOWN_CQ_TYPE 0x20
+#define FC_STATUS_BAD_SEG_CNT 0x21
+#define FC_STATUS_MAX_XCHG_EXCEEDED 0x22
+#define FC_STATUS_BAD_XID 0x23
+#define FC_STATUS_XCHG_BUSY 0x24
+#define FC_STATUS_BAD_POOL_ID 0x25
+#define FC_STATUS_INSUFFICIENT_CQES 0x26
+#define FC_STATUS_ALLOC_FAIL 0x27
+#define FC_STATUS_BAD_SID 0x28
+#define FC_STATUS_NO_SEQ_INIT 0x29
+#define FC_STATUS_TIMED_OUT -1
+#define FC_STATUS_BAD_RSP -2
+
+void fcp_queue_empty(fc_channel *);
+int fcp_init(fc_channel *);
+void fcp_release(fc_channel *fc_chain, int count);
+void fcp_receive_solicited(fc_channel *, int, int, int, fc_hdr *);
+void fcp_state_change(fc_channel *, int);
+int fc_do_plogi(fc_channel *, unsigned char, fc_wwn *, fc_wwn *);
+int fc_do_prli(fc_channel *, unsigned char);
+
+#define for_each_fc_channel(fc) \
+ for (fc = fc_channels; fc; fc = fc->next)
+
+#define for_each_online_fc_channel(fc) \
+ for_each_fc_channel(fc) \
+ if (fc->state == FC_STATE_ONLINE)
+
+int fcp_scsi_queuecommand(Scsi_Cmnd *, void (* done)(Scsi_Cmnd *));
+int fcp_scsi_abort(Scsi_Cmnd *);
+int fcp_scsi_dev_reset(Scsi_Cmnd *);
+int fcp_scsi_bus_reset(Scsi_Cmnd *);
+int fcp_scsi_host_reset(Scsi_Cmnd *);
+
+#endif /* !(_FCP_SCSI_H) */
diff --git a/drivers/fc4/soc.c b/drivers/fc4/soc.c
new file mode 100644
index 00000000000..247b4630277
--- /dev/null
+++ b/drivers/fc4/soc.c
@@ -0,0 +1,766 @@
+/* soc.c: Sparc SUNW,soc (Serial Optical Channel) Fibre Channel Sbus adapter support.
+ *
+ * Copyright (C) 1996,1997,1999 Jakub Jelinek (jj@ultra.linux.cz)
+ * Copyright (C) 1997,1998 Jirka Hanika (geo@ff.cuni.cz)
+ *
+ * Sources:
+ * Fibre Channel Physical & Signaling Interface (FC-PH), dpANS, 1994
+ * dpANS Fibre Channel Protocol for SCSI (X3.269-199X), Rev. 012, 1995
+ *
+ * Supported hardware:
+ * Tested on SOC sbus card bought with SS1000 in Linux running on SS5 and Ultra1.
+ * For SOC sbus cards, you have to make sure your FCode is 1.52 or later.
+ * If you have older FCode, you should try to upgrade or get SOC microcode from Sun
+ * (the microcode is present in Solaris soc driver as well). In that case you need
+ * to #define HAVE_SOC_UCODE and format the microcode into soc_asm.c. For the exact
+ * format mail me and I will tell you. I cannot offer you the actual microcode though,
+ * unless Sun confirms they don't mind.
+ */
+
+static char *version =
+ "soc.c:v1.3 9/Feb/99 Jakub Jelinek (jj@ultra.linux.cz), Jirka Hanika (geo@ff.cuni.cz)\n";
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/fcntl.h>
+#include <linux/interrupt.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/in.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/init.h>
+#include <linux/bitops.h>
+#include <asm/io.h>
+#include <asm/dma.h>
+#include <linux/errno.h>
+#include <asm/byteorder.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+#include <asm/pgtable.h>
+#include <asm/irq.h>
+
+/* #define SOCDEBUG */
+/* #define HAVE_SOC_UCODE */
+
+#include "fcp_impl.h"
+#include "soc.h"
+#ifdef HAVE_SOC_UCODE
+#include "soc_asm.h"
+#endif
+
+#define soc_printk printk ("soc%d: ", s->soc_no); printk
+
+#ifdef SOCDEBUG
+#define SOD(x) soc_printk x;
+#else
+#define SOD(x)
+#endif
+
+#define for_each_soc(s) for (s = socs; s; s = s->next)
+struct soc *socs = NULL;
+
+static inline void soc_disable(struct soc *s)
+{
+ sbus_writel(0, s->regs + IMASK);
+ sbus_writel(SOC_CMD_SOFT_RESET, s->regs + CMD);
+}
+
+static inline void soc_enable(struct soc *s)
+{
+ SOD(("enable %08x\n", s->cfg))
+ sbus_writel(0, s->regs + SAE);
+ sbus_writel(s->cfg, s->regs + CFG);
+ sbus_writel(SOC_CMD_RSP_QALL, s->regs + CMD);
+ SOC_SETIMASK(s, SOC_IMASK_RSP_QALL | SOC_IMASK_SAE);
+ SOD(("imask %08lx %08lx\n", s->imask, sbus_readl(s->regs + IMAK)));
+}
+
+static void soc_reset(fc_channel *fc)
+{
+ soc_port *port = (soc_port *)fc;
+ struct soc *s = port->s;
+
+ /* FIXME */
+ soc_disable(s);
+ s->req[0].seqno = 1;
+ s->req[1].seqno = 1;
+ s->rsp[0].seqno = 1;
+ s->rsp[1].seqno = 1;
+ s->req[0].in = 0;
+ s->req[1].in = 0;
+ s->rsp[0].in = 0;
+ s->rsp[1].in = 0;
+ s->req[0].out = 0;
+ s->req[1].out = 0;
+ s->rsp[0].out = 0;
+ s->rsp[1].out = 0;
+
+ /* FIXME */
+ soc_enable(s);
+}
+
+static inline void soc_solicited (struct soc *s)
+{
+ fc_hdr fchdr;
+ soc_rsp __iomem *hwrsp;
+ soc_cq_rsp *sw_cq;
+ int token;
+ int status;
+ fc_channel *fc;
+
+ sw_cq = &s->rsp[SOC_SOLICITED_RSP_Q];
+
+ if (sw_cq->pool == NULL)
+ sw_cq->pool = (soc_req __iomem *)
+ (s->xram + xram_get_32low ((xram_p)&sw_cq->hw_cq->address));
+ sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
+ SOD (("soc_solicited, %d pkts arrived\n", (sw_cq->in-sw_cq->out) & sw_cq->last))
+ for (;;) {
+ hwrsp = (soc_rsp __iomem *)sw_cq->pool + sw_cq->out;
+ token = xram_get_32low ((xram_p)&hwrsp->shdr.token);
+ status = xram_get_32low ((xram_p)&hwrsp->status);
+ fc = (fc_channel *)(&s->port[(token >> 11) & 1]);
+
+ if (status == SOC_OK) {
+ fcp_receive_solicited(fc, token >> 12,
+ token & ((1 << 11) - 1),
+ FC_STATUS_OK, NULL);
+ } else {
+ xram_copy_from(&fchdr, (xram_p)&hwrsp->fchdr, sizeof(fchdr));
+ /* We have intentionally defined FC_STATUS_* constants
+ * to match SOC_* constants, otherwise we'd have to
+ * translate status.
+ */
+ fcp_receive_solicited(fc, token >> 12,
+ token & ((1 << 11) - 1),
+ status, &fchdr);
+ }
+
+ if (++sw_cq->out > sw_cq->last) {
+ sw_cq->seqno++;
+ sw_cq->out = 0;
+ }
+
+ if (sw_cq->out == sw_cq->in) {
+ sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
+ if (sw_cq->out == sw_cq->in) {
+ /* Tell the hardware about it */
+ sbus_writel((sw_cq->out << 24) |
+ (SOC_CMD_RSP_QALL &
+ ~(SOC_CMD_RSP_Q0 << SOC_SOLICITED_RSP_Q)),
+ s->regs + CMD);
+
+ /* Read it, so that we're sure it has been updated */
+ sbus_readl(s->regs + CMD);
+ sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
+ if (sw_cq->out == sw_cq->in)
+ break;
+ }
+ }
+ }
+}
+
+static inline void soc_request (struct soc *s, u32 cmd)
+{
+ SOC_SETIMASK(s, s->imask & ~(cmd & SOC_CMD_REQ_QALL));
+ SOD(("imask %08lx %08lx\n", s->imask, sbus_readl(s->regs + IMASK)));
+
+ SOD(("Queues available %08x OUT %X %X\n", cmd,
+ xram_get_8((xram_p)&s->req[0].hw_cq->out),
+ xram_get_8((xram_p)&s->req[0].hw_cq->out)))
+ if (s->port[s->curr_port].fc.state != FC_STATE_OFFLINE) {
+ fcp_queue_empty ((fc_channel *)&(s->port[s->curr_port]));
+ if (((s->req[1].in + 1) & s->req[1].last) != (s->req[1].out))
+ fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
+ } else {
+ fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
+ }
+ if (s->port[1 - s->curr_port].fc.state != FC_STATE_OFFLINE)
+ s->curr_port ^= 1;
+}
+
+static inline void soc_unsolicited (struct soc *s)
+{
+ soc_rsp __iomem *hwrsp, *hwrspc;
+ soc_cq_rsp *sw_cq;
+ int count;
+ int status;
+ int flags;
+ fc_channel *fc;
+
+ sw_cq = &s->rsp[SOC_UNSOLICITED_RSP_Q];
+ if (sw_cq->pool == NULL)
+ sw_cq->pool = (soc_req __iomem *)
+ (s->xram + (xram_get_32low ((xram_p)&sw_cq->hw_cq->address)));
+
+ sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
+ SOD (("soc_unsolicited, %d packets arrived\n", (sw_cq->in - sw_cq->out) & sw_cq->last))
+ while (sw_cq->in != sw_cq->out) {
+ /* ...real work per entry here... */
+ hwrsp = (soc_rsp __iomem *)sw_cq->pool + sw_cq->out;
+
+ hwrspc = NULL;
+ flags = xram_get_16 ((xram_p)&hwrsp->shdr.flags);
+ count = xram_get_8 ((xram_p)&hwrsp->count);
+ fc = (fc_channel *)&s->port[flags & SOC_PORT_B];
+ SOD(("FC %08lx fcp_state_change %08lx\n",
+ (long)fc, (long)fc->fcp_state_change))
+
+ if (count != 1) {
+ /* Ugh, continuation entries */
+ u8 in;
+
+ if (count != 2) {
+ printk("%s: Too many continuations entries %d\n",
+ fc->name, count);
+ goto update_out;
+ }
+
+ in = sw_cq->in;
+ if (in < sw_cq->out) in += sw_cq->last + 1;
+ if (in < sw_cq->out + 2) {
+ /* Ask the hardware if they haven't arrived yet. */
+ sbus_writel((sw_cq->out << 24) |
+ (SOC_CMD_RSP_QALL &
+ ~(SOC_CMD_RSP_Q0 << SOC_UNSOLICITED_RSP_Q)),
+ s->regs + CMD);
+
+ /* Read it, so that we're sure it has been updated */
+ sbus_readl(s->regs + CMD);
+ sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
+ in = sw_cq->in;
+ if (in < sw_cq->out)
+ in += sw_cq->last + 1;
+ if (in < sw_cq->out + 2) /* Nothing came, let us wait */
+ return;
+ }
+ if (sw_cq->out == sw_cq->last)
+ hwrspc = (soc_rsp __iomem *)sw_cq->pool;
+ else
+ hwrspc = hwrsp + 1;
+ }
+
+ switch (flags & ~SOC_PORT_B) {
+ case SOC_STATUS:
+ status = xram_get_32low ((xram_p)&hwrsp->status);
+ switch (status) {
+ case SOC_ONLINE:
+ SOD(("State change to ONLINE\n"));
+ fcp_state_change(fc, FC_STATE_ONLINE);
+ break;
+ case SOC_OFFLINE:
+ SOD(("State change to OFFLINE\n"));
+ fcp_state_change(fc, FC_STATE_OFFLINE);
+ break;
+ default:
+ printk ("%s: Unknown STATUS no %d\n",
+ fc->name, status);
+ break;
+ }
+ break;
+ case (SOC_UNSOLICITED|SOC_FC_HDR):
+ {
+ int r_ctl = xram_get_8 ((xram_p)&hwrsp->fchdr);
+ unsigned len;
+ char buf[64];
+
+ if ((r_ctl & 0xf0) == R_CTL_EXTENDED_SVC) {
+ len = xram_get_32 ((xram_p)&hwrsp->shdr.bytecnt);
+ if (len < 4 || !hwrspc) {
+ printk ("%s: Invalid R_CTL %02x "
+ "continuation entries\n",
+ fc->name, r_ctl);
+ } else {
+ if (len > 60)
+ len = 60;
+ xram_copy_from (buf, (xram_p)hwrspc,
+ (len + 3) & ~3);
+ if (*(u32 *)buf == LS_DISPLAY) {
+ int i;
+
+ for (i = 4; i < len; i++)
+ if (buf[i] == '\n')
+ buf[i] = ' ';
+ buf[len] = 0;
+ printk ("%s message: %s\n",
+ fc->name, buf + 4);
+ } else {
+ printk ("%s: Unknown LS_CMD "
+ "%02x\n", fc->name,
+ buf[0]);
+ }
+ }
+ } else {
+ printk ("%s: Unsolicited R_CTL %02x "
+ "not handled\n", fc->name, r_ctl);
+ }
+ }
+ break;
+ default:
+ printk ("%s: Unexpected flags %08x\n", fc->name, flags);
+ break;
+ };
+update_out:
+ if (++sw_cq->out > sw_cq->last) {
+ sw_cq->seqno++;
+ sw_cq->out = 0;
+ }
+
+ if (hwrspc) {
+ if (++sw_cq->out > sw_cq->last) {
+ sw_cq->seqno++;
+ sw_cq->out = 0;
+ }
+ }
+
+ if (sw_cq->out == sw_cq->in) {
+ sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
+ if (sw_cq->out == sw_cq->in) {
+ /* Tell the hardware about it */
+ sbus_writel((sw_cq->out << 24) |
+ (SOC_CMD_RSP_QALL &
+ ~(SOC_CMD_RSP_Q0 << SOC_UNSOLICITED_RSP_Q)),
+ s->regs + CMD);
+
+ /* Read it, so that we're sure it has been updated */
+ sbus_readl(s->regs + CMD);
+ sw_cq->in = xram_get_8 ((xram_p)&sw_cq->hw_cq->in);
+ }
+ }
+ }
+}
+
+static irqreturn_t soc_intr(int irq, void *dev_id, struct pt_regs *regs)
+{
+ u32 cmd;
+ unsigned long flags;
+ register struct soc *s = (struct soc *)dev_id;
+
+ spin_lock_irqsave(&s->lock, flags);
+ cmd = sbus_readl(s->regs + CMD);
+ for (; (cmd = SOC_INTR (s, cmd)); cmd = sbus_readl(s->regs + CMD)) {
+ if (cmd & SOC_CMD_RSP_Q1) soc_unsolicited (s);
+ if (cmd & SOC_CMD_RSP_Q0) soc_solicited (s);
+ if (cmd & SOC_CMD_REQ_QALL) soc_request (s, cmd);
+ }
+ spin_unlock_irqrestore(&s->lock, flags);
+
+ return IRQ_HANDLED;
+}
+
+#define TOKEN(proto, port, token) (((proto)<<12)|(token)|(port))
+
+static int soc_hw_enque (fc_channel *fc, fcp_cmnd *fcmd)
+{
+ soc_port *port = (soc_port *)fc;
+ struct soc *s = port->s;
+ int qno;
+ soc_cq_req *sw_cq;
+ int cq_next_in;
+ soc_req *request;
+ fc_hdr *fch;
+ int i;
+
+ if (fcmd->proto == TYPE_SCSI_FCP)
+ qno = 1;
+ else
+ qno = 0;
+ SOD(("Putting a FCP packet type %d into hw queue %d\n", fcmd->proto, qno))
+ if (s->imask & (SOC_IMASK_REQ_Q0 << qno)) {
+ SOD(("EIO %08x\n", s->imask))
+ return -EIO;
+ }
+ sw_cq = s->req + qno;
+ cq_next_in = (sw_cq->in + 1) & sw_cq->last;
+
+ if (cq_next_in == sw_cq->out &&
+ cq_next_in == (sw_cq->out = xram_get_8((xram_p)&sw_cq->hw_cq->out))) {
+ SOD(("%d IN %d OUT %d LAST %d\n", qno, sw_cq->in, sw_cq->out, sw_cq->last))
+ SOC_SETIMASK(s, s->imask | (SOC_IMASK_REQ_Q0 << qno));
+ SOD(("imask %08lx %08lx\n", s->imask, sbus_readl(s->regs + IMASK)));
+ /* If queue is full, just say NO */
+ return -EBUSY;
+ }
+
+ request = sw_cq->pool + sw_cq->in;
+ fch = &request->fchdr;
+
+ switch (fcmd->proto) {
+ case TYPE_SCSI_FCP:
+ request->shdr.token = TOKEN(TYPE_SCSI_FCP, port->mask, fcmd->token);
+ request->data[0].base = fc->dma_scsi_cmd + fcmd->token * sizeof(fcp_cmd);
+ request->data[0].count = sizeof(fcp_cmd);
+ request->data[1].base = fc->dma_scsi_rsp + fcmd->token * fc->rsp_size;
+ request->data[1].count = fc->rsp_size;
+ if (fcmd->data) {
+ request->shdr.segcnt = 3;
+ i = fc->scsi_cmd_pool[fcmd->token].fcp_data_len;
+ request->shdr.bytecnt = i;
+ request->data[2].base = fcmd->data;
+ request->data[2].count = i;
+ request->type =
+ (fc->scsi_cmd_pool[fcmd->token].fcp_cntl & FCP_CNTL_WRITE) ?
+ SOC_CQTYPE_IO_WRITE : SOC_CQTYPE_IO_READ;
+ } else {
+ request->shdr.segcnt = 2;
+ request->shdr.bytecnt = 0;
+ request->data[2].base = 0;
+ request->data[2].count = 0;
+ request->type = SOC_CQTYPE_SIMPLE;
+ }
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fc->did);
+ FILL_FCHDR_SID(fch, fc->sid);
+ FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP,
+ F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
+ FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
+ FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
+ fch->param = 0;
+ request->shdr.flags = port->flags;
+ request->shdr.class = 2;
+ break;
+
+ case PROTO_OFFLINE:
+ memset (request, 0, sizeof(*request));
+ request->shdr.token = TOKEN(PROTO_OFFLINE, port->mask, fcmd->token);
+ request->type = SOC_CQTYPE_OFFLINE;
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fc->did);
+ FILL_FCHDR_SID(fch, fc->sid);
+ FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP,
+ F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
+ FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
+ FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
+ request->shdr.flags = port->flags;
+ break;
+
+ case PROTO_REPORT_AL_MAP:
+ /* SOC only supports Point-to-Point topology, no FC-AL, sorry... */
+ return -ENOSYS;
+
+ default:
+ request->shdr.token = TOKEN(fcmd->proto, port->mask, fcmd->token);
+ request->shdr.class = 2;
+ request->shdr.flags = port->flags;
+ memcpy (fch, &fcmd->fch, sizeof(fc_hdr));
+ request->data[0].count = fcmd->cmdlen;
+ request->data[1].count = fcmd->rsplen;
+ request->type = fcmd->class;
+ switch (fcmd->class) {
+ case FC_CLASS_OUTBOUND:
+ request->data[0].base = fcmd->cmd;
+ request->data[0].count = fcmd->cmdlen;
+ request->type = SOC_CQTYPE_OUTBOUND;
+ request->shdr.bytecnt = fcmd->cmdlen;
+ request->shdr.segcnt = 1;
+ break;
+ case FC_CLASS_INBOUND:
+ request->data[0].base = fcmd->rsp;
+ request->data[0].count = fcmd->rsplen;
+ request->type = SOC_CQTYPE_INBOUND;
+ request->shdr.bytecnt = 0;
+ request->shdr.segcnt = 1;
+ break;
+ case FC_CLASS_SIMPLE:
+ request->data[0].base = fcmd->cmd;
+ request->data[1].base = fcmd->rsp;
+ request->data[0].count = fcmd->cmdlen;
+ request->data[1].count = fcmd->rsplen;
+ request->type = SOC_CQTYPE_SIMPLE;
+ request->shdr.bytecnt = fcmd->cmdlen;
+ request->shdr.segcnt = 2;
+ break;
+ case FC_CLASS_IO_READ:
+ case FC_CLASS_IO_WRITE:
+ request->data[0].base = fcmd->cmd;
+ request->data[1].base = fcmd->rsp;
+ request->data[0].count = fcmd->cmdlen;
+ request->data[1].count = fcmd->rsplen;
+ request->type =
+ (fcmd->class == FC_CLASS_IO_READ) ?
+ SOC_CQTYPE_IO_READ : SOC_CQTYPE_IO_WRITE;
+ if (fcmd->data) {
+ request->data[2].base = fcmd->data;
+ request->data[2].count = fcmd->datalen;
+ request->shdr.bytecnt = fcmd->datalen;
+ request->shdr.segcnt = 3;
+ } else {
+ request->shdr.bytecnt = 0;
+ request->shdr.segcnt = 2;
+ }
+ break;
+ };
+ break;
+ };
+
+ request->count = 1;
+ request->flags = 0;
+ request->seqno = sw_cq->seqno;
+
+ /* And now tell the SOC about it */
+
+ if (++sw_cq->in > sw_cq->last) {
+ sw_cq->in = 0;
+ sw_cq->seqno++;
+ }
+
+ SOD(("Putting %08x into cmd\n",
+ SOC_CMD_RSP_QALL | (sw_cq->in << 24) | (SOC_CMD_REQ_Q0 << qno)))
+
+ sbus_writel(SOC_CMD_RSP_QALL | (sw_cq->in << 24) | (SOC_CMD_REQ_Q0 << qno),
+ s->regs + CMD);
+
+ /* Read so that command is completed. */
+ sbus_readl(s->regs + CMD);
+
+ return 0;
+}
+
+static inline void soc_download_fw(struct soc *s)
+{
+#ifdef HAVE_SOC_UCODE
+ xram_copy_to (s->xram, soc_ucode, sizeof(soc_ucode));
+ xram_bzero (s->xram + sizeof(soc_ucode), 32768 - sizeof(soc_ucode));
+#endif
+}
+
+/* Check for what the best SBUS burst we can use happens
+ * to be on this machine.
+ */
+static inline void soc_init_bursts(struct soc *s, struct sbus_dev *sdev)
+{
+ int bsizes, bsizes_more;
+
+ bsizes = (prom_getintdefault(sdev->prom_node,"burst-sizes",0xff) & 0xff);
+ bsizes_more = (prom_getintdefault(sdev->bus->prom_node, "burst-sizes", 0xff) & 0xff);
+ bsizes &= bsizes_more;
+ if ((bsizes & 0x7f) == 0x7f)
+ s->cfg = SOC_CFG_BURST_64;
+ else if ((bsizes & 0x3f) == 0x3f)
+ s->cfg = SOC_CFG_BURST_32;
+ else if ((bsizes & 0x1f) == 0x1f)
+ s->cfg = SOC_CFG_BURST_16;
+ else
+ s->cfg = SOC_CFG_BURST_4;
+}
+
+static inline void soc_init(struct sbus_dev *sdev, int no)
+{
+ unsigned char tmp[60];
+ int propl;
+ struct soc *s;
+ static int version_printed = 0;
+ soc_hw_cq cq[8];
+ int size, i;
+ int irq;
+
+ s = kmalloc (sizeof (struct soc), GFP_KERNEL);
+ if (s == NULL)
+ return;
+ memset (s, 0, sizeof(struct soc));
+ spin_lock_init(&s->lock);
+ s->soc_no = no;
+
+ SOD(("socs %08lx soc_intr %08lx soc_hw_enque %08x\n",
+ (long)socs, (long)soc_intr, (long)soc_hw_enque))
+ if (version_printed++ == 0)
+ printk (version);
+
+ s->port[0].fc.module = THIS_MODULE;
+ s->port[1].fc.module = THIS_MODULE;
+
+ s->next = socs;
+ socs = s;
+ s->port[0].fc.dev = sdev;
+ s->port[1].fc.dev = sdev;
+ s->port[0].s = s;
+ s->port[1].s = s;
+
+ s->port[0].fc.next = &s->port[1].fc;
+
+ /* World Wide Name of SOC */
+ propl = prom_getproperty (sdev->prom_node, "soc-wwn", tmp, sizeof(tmp));
+ if (propl != sizeof (fc_wwn)) {
+ s->wwn.naaid = NAAID_IEEE;
+ s->wwn.lo = 0x12345678;
+ } else
+ memcpy (&s->wwn, tmp, sizeof (fc_wwn));
+
+ propl = prom_getproperty (sdev->prom_node, "port-wwns", tmp, sizeof(tmp));
+ if (propl != 2 * sizeof (fc_wwn)) {
+ s->port[0].fc.wwn_nport.naaid = NAAID_IEEE_EXT;
+ s->port[0].fc.wwn_nport.hi = s->wwn.hi;
+ s->port[0].fc.wwn_nport.lo = s->wwn.lo;
+ s->port[1].fc.wwn_nport.naaid = NAAID_IEEE_EXT;
+ s->port[1].fc.wwn_nport.nportid = 1;
+ s->port[1].fc.wwn_nport.hi = s->wwn.hi;
+ s->port[1].fc.wwn_nport.lo = s->wwn.lo;
+ } else {
+ memcpy (&s->port[0].fc.wwn_nport, tmp, sizeof (fc_wwn));
+ memcpy (&s->port[1].fc.wwn_nport, tmp + sizeof (fc_wwn), sizeof (fc_wwn));
+ }
+ memcpy (&s->port[0].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
+ memcpy (&s->port[1].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
+ SOD(("Got wwns %08x%08x ports %08x%08x and %08x%08x\n",
+ *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
+ *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
+ *(u32 *)&s->port[1].fc.wwn_nport, s->port[1].fc.wwn_nport.lo))
+
+ s->port[0].fc.sid = 1;
+ s->port[1].fc.sid = 17;
+ s->port[0].fc.did = 2;
+ s->port[1].fc.did = 18;
+
+ s->port[0].fc.reset = soc_reset;
+ s->port[1].fc.reset = soc_reset;
+
+ if (sdev->num_registers == 1) {
+ /* Probably SunFire onboard SOC */
+ s->xram = sbus_ioremap(&sdev->resource[0], 0,
+ 0x10000UL, "soc xram");
+ s->regs = sbus_ioremap(&sdev->resource[0], 0x10000UL,
+ 0x10UL, "soc regs");
+ } else {
+ /* Probably SOC sbus card */
+ s->xram = sbus_ioremap(&sdev->resource[1], 0,
+ sdev->reg_addrs[1].reg_size, "soc xram");
+ s->regs = sbus_ioremap(&sdev->resource[2], 0,
+ sdev->reg_addrs[2].reg_size, "soc regs");
+ }
+
+ soc_init_bursts(s, sdev);
+
+ SOD(("Disabling SOC\n"))
+
+ soc_disable (s);
+
+ irq = sdev->irqs[0];
+
+ if (request_irq (irq, soc_intr, SA_SHIRQ, "SOC", (void *)s)) {
+ soc_printk ("Cannot order irq %d to go\n", irq);
+ socs = s->next;
+ return;
+ }
+
+ SOD(("SOC uses IRQ%s\n", __irq_itoa(irq)))
+
+ s->port[0].fc.irq = irq;
+ s->port[1].fc.irq = irq;
+
+ sprintf (s->port[0].fc.name, "soc%d port A", no);
+ sprintf (s->port[1].fc.name, "soc%d port B", no);
+ s->port[0].flags = SOC_FC_HDR | SOC_PORT_A;
+ s->port[1].flags = SOC_FC_HDR | SOC_PORT_B;
+ s->port[1].mask = (1 << 11);
+
+ s->port[0].fc.hw_enque = soc_hw_enque;
+ s->port[1].fc.hw_enque = soc_hw_enque;
+
+ soc_download_fw (s);
+
+ SOD(("Downloaded firmware\n"))
+
+ /* Now setup xram circular queues */
+ memset (cq, 0, sizeof(cq));
+
+ size = (SOC_CQ_REQ0_SIZE + SOC_CQ_REQ1_SIZE) * sizeof(soc_req);
+ s->req_cpu = sbus_alloc_consistent(sdev, size, &s->req_dvma);
+ s->req[0].pool = s->req_cpu;
+ cq[0].address = s->req_dvma;
+ s->req[1].pool = s->req[0].pool + SOC_CQ_REQ0_SIZE;
+
+ s->req[0].hw_cq = (soc_hw_cq __iomem *)(s->xram + SOC_CQ_REQ_OFFSET);
+ s->req[1].hw_cq = (soc_hw_cq __iomem *)(s->xram + SOC_CQ_REQ_OFFSET + sizeof(soc_hw_cq));
+ s->rsp[0].hw_cq = (soc_hw_cq __iomem *)(s->xram + SOC_CQ_RSP_OFFSET);
+ s->rsp[1].hw_cq = (soc_hw_cq __iomem *)(s->xram + SOC_CQ_RSP_OFFSET + sizeof(soc_hw_cq));
+
+ cq[1].address = cq[0].address + (SOC_CQ_REQ0_SIZE * sizeof(soc_req));
+ cq[4].address = 1;
+ cq[5].address = 1;
+ cq[0].last = SOC_CQ_REQ0_SIZE - 1;
+ cq[1].last = SOC_CQ_REQ1_SIZE - 1;
+ cq[4].last = SOC_CQ_RSP0_SIZE - 1;
+ cq[5].last = SOC_CQ_RSP1_SIZE - 1;
+ for (i = 0; i < 8; i++)
+ cq[i].seqno = 1;
+
+ s->req[0].last = SOC_CQ_REQ0_SIZE - 1;
+ s->req[1].last = SOC_CQ_REQ1_SIZE - 1;
+ s->rsp[0].last = SOC_CQ_RSP0_SIZE - 1;
+ s->rsp[1].last = SOC_CQ_RSP1_SIZE - 1;
+
+ s->req[0].seqno = 1;
+ s->req[1].seqno = 1;
+ s->rsp[0].seqno = 1;
+ s->rsp[1].seqno = 1;
+
+ xram_copy_to (s->xram + SOC_CQ_REQ_OFFSET, cq, sizeof(cq));
+
+ /* Make our sw copy of SOC service parameters */
+ xram_copy_from (s->serv_params, s->xram + 0x140, sizeof (s->serv_params));
+
+ s->port[0].fc.common_svc = (common_svc_parm *)s->serv_params;
+ s->port[0].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
+ s->port[1].fc.common_svc = (common_svc_parm *)&s->serv_params;
+ s->port[1].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
+
+ soc_enable (s);
+
+ SOD(("Enabled SOC\n"))
+}
+
+static int __init soc_probe(void)
+{
+ struct sbus_bus *sbus;
+ struct sbus_dev *sdev = NULL;
+ struct soc *s;
+ int cards = 0;
+
+ for_each_sbus(sbus) {
+ for_each_sbusdev(sdev, sbus) {
+ if(!strcmp(sdev->prom_name, "SUNW,soc")) {
+ soc_init(sdev, cards);
+ cards++;
+ }
+ }
+ }
+ if (!cards) return -EIO;
+
+ for_each_soc(s)
+ if (s->next)
+ s->port[1].fc.next = &s->next->port[0].fc;
+ fcp_init (&socs->port[0].fc);
+ return 0;
+}
+
+static void __exit soc_cleanup(void)
+{
+ struct soc *s;
+ int irq;
+ struct sbus_dev *sdev;
+
+ for_each_soc(s) {
+ irq = s->port[0].fc.irq;
+ free_irq (irq, s);
+
+ fcp_release(&(s->port[0].fc), 2);
+
+ sdev = s->port[0].fc.dev;
+ if (sdev->num_registers == 1) {
+ sbus_iounmap(s->xram, 0x10000UL);
+ sbus_iounmap(s->regs, 0x10UL);
+ } else {
+ sbus_iounmap(s->xram, sdev->reg_addrs[1].reg_size);
+ sbus_iounmap(s->regs, sdev->reg_addrs[2].reg_size);
+ }
+ sbus_free_consistent(sdev,
+ (SOC_CQ_REQ0_SIZE+SOC_CQ_REQ1_SIZE)*sizeof(soc_req),
+ s->req_cpu, s->req_dvma);
+ }
+}
+
+module_init(soc_probe);
+module_exit(soc_cleanup);
+MODULE_LICENSE("GPL");
diff --git a/drivers/fc4/soc.h b/drivers/fc4/soc.h
new file mode 100644
index 00000000000..d38cf5b28ee
--- /dev/null
+++ b/drivers/fc4/soc.h
@@ -0,0 +1,301 @@
+/* soc.h: Definitions for Sparc SUNW,soc Fibre Channel Sbus driver.
+ *
+ * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+ */
+
+#ifndef __SOC_H
+#define __SOC_H
+
+#include "fc.h"
+#include "fcp.h"
+#include "fcp_impl.h"
+
+/* Hardware register offsets and constants first {{{ */
+#define CFG 0x00UL /* Config Register */
+#define SAE 0x04UL /* Slave Access Error Register */
+#define CMD 0x08UL /* Command and Status Register */
+#define IMASK 0x0cUL /* Interrupt Mask Register */
+
+/* Config Register */
+#define SOC_CFG_EXT_RAM_BANK_MASK 0x07000000
+#define SOC_CFG_EEPROM_BANK_MASK 0x00030000
+#define SOC_CFG_BURST64_MASK 0x00000700
+#define SOC_CFG_SBUS_PARITY_TEST 0x00000020
+#define SOC_CFG_SBUS_PARITY_CHECK 0x00000010
+#define SOC_CFG_SBUS_ENHANCED 0x00000008
+#define SOC_CFG_BURST_MASK 0x00000007
+/* Bursts */
+#define SOC_CFG_BURST_4 0x00000000
+#define SOC_CFG_BURST_16 0x00000004
+#define SOC_CFG_BURST_32 0x00000005
+#define SOC_CFG_BURST_64 0x00000006
+
+/* Slave Access Error Register */
+#define SOC_SAE_ALIGNMENT 0x00000004
+#define SOC_SAE_UNSUPPORTED 0x00000002
+#define SOC_SAE_PARITY 0x00000001
+
+/* Command & Status Register */
+#define SOC_CMD_RSP_QALL 0x000f0000
+#define SOC_CMD_RSP_Q0 0x00010000
+#define SOC_CMD_RSP_Q1 0x00020000
+#define SOC_CMD_RSP_Q2 0x00040000
+#define SOC_CMD_RSP_Q3 0x00080000
+#define SOC_CMD_REQ_QALL 0x00000f00
+#define SOC_CMD_REQ_Q0 0x00000100
+#define SOC_CMD_REQ_Q1 0x00000200
+#define SOC_CMD_REQ_Q2 0x00000400
+#define SOC_CMD_REQ_Q3 0x00000800
+#define SOC_CMD_SAE 0x00000080
+#define SOC_CMD_INTR_PENDING 0x00000008
+#define SOC_CMD_NON_QUEUED 0x00000004
+#define SOC_CMD_IDLE 0x00000002
+#define SOC_CMD_SOFT_RESET 0x00000001
+
+/* Interrupt Mask Register */
+#define SOC_IMASK_RSP_QALL 0x000f0000
+#define SOC_IMASK_RSP_Q0 0x00010000
+#define SOC_IMASK_RSP_Q1 0x00020000
+#define SOC_IMASK_RSP_Q2 0x00040000
+#define SOC_IMASK_RSP_Q3 0x00080000
+#define SOC_IMASK_REQ_QALL 0x00000f00
+#define SOC_IMASK_REQ_Q0 0x00000100
+#define SOC_IMASK_REQ_Q1 0x00000200
+#define SOC_IMASK_REQ_Q2 0x00000400
+#define SOC_IMASK_REQ_Q3 0x00000800
+#define SOC_IMASK_SAE 0x00000080
+#define SOC_IMASK_NON_QUEUED 0x00000004
+
+#define SOC_INTR(s, cmd) \
+ (((cmd & SOC_CMD_RSP_QALL) | ((~cmd) & SOC_CMD_REQ_QALL)) \
+ & s->imask)
+
+#define SOC_SETIMASK(s, i) \
+do { (s)->imask = (i); \
+ sbus_writel((i), (s)->regs + IMASK); \
+} while(0)
+
+/* XRAM
+ *
+ * This is a 64KB register area. It accepts only halfword access.
+ * That's why here are the following inline functions...
+ */
+
+typedef void __iomem *xram_p;
+
+/* Get 32bit number from XRAM */
+static inline u32 xram_get_32(xram_p x)
+{
+ return ((sbus_readw(x + 0x00UL) << 16) |
+ (sbus_readw(x + 0x02UL)));
+}
+
+/* Like the above, but when we don't care about the high 16 bits */
+static inline u32 xram_get_32low(xram_p x)
+{
+ return (u32) sbus_readw(x + 0x02UL);
+}
+
+static inline u16 xram_get_16(xram_p x)
+{
+ return sbus_readw(x);
+}
+
+static inline u8 xram_get_8(xram_p x)
+{
+ if ((unsigned long)x & 0x1UL) {
+ x = x - 1;
+ return (u8) sbus_readw(x);
+ } else {
+ return (u8) (sbus_readw(x) >> 8);
+ }
+}
+
+static inline void xram_copy_from(void *p, xram_p x, int len)
+{
+ for (len >>= 2; len > 0; len--, x += sizeof(u32)) {
+ u32 val, *p32 = p;
+
+ val = ((sbus_readw(x + 0x00UL) << 16) |
+ (sbus_readw(x + 0x02UL)));
+ *p32++ = val;
+ p = p32;
+ }
+}
+
+static inline void xram_copy_to(xram_p x, void *p, int len)
+{
+ for (len >>= 2; len > 0; len--, x += sizeof(u32)) {
+ u32 tmp, *p32 = p;
+
+ tmp = *p32++;
+ p = p32;
+ sbus_writew(tmp >> 16, x + 0x00UL);
+ sbus_writew(tmp, x + 0x02UL);
+ }
+}
+
+static inline void xram_bzero(xram_p x, int len)
+{
+ for (len >>= 1; len > 0; len--, x += sizeof(u16))
+ sbus_writew(0, x);
+}
+
+/* Circular Queue */
+
+#define SOC_CQ_REQ_OFFSET (0x100 * sizeof(u16))
+#define SOC_CQ_RSP_OFFSET (0x110 * sizeof(u16))
+
+typedef struct {
+ u32 address;
+ u8 in;
+ u8 out;
+ u8 last;
+ u8 seqno;
+} soc_hw_cq;
+
+#define SOC_PORT_A 0x0000 /* From/To Port A */
+#define SOC_PORT_B 0x0001 /* From/To Port A */
+#define SOC_FC_HDR 0x0002 /* Contains FC Header */
+#define SOC_NORSP 0x0004 /* Don't generate response nor interrupt */
+#define SOC_NOINT 0x0008 /* Generate response but not interrupt */
+#define SOC_XFERRDY 0x0010 /* Generate XFERRDY */
+#define SOC_IGNOREPARAM 0x0020 /* Ignore PARAM field in the FC header */
+#define SOC_COMPLETE 0x0040 /* Command completed */
+#define SOC_UNSOLICITED 0x0080 /* For request this is the packet to establish unsolicited pools, */
+ /* for rsp this is unsolicited packet */
+#define SOC_STATUS 0x0100 /* State change (on/off line) */
+
+typedef struct {
+ u32 token;
+ u16 flags;
+ u8 class;
+ u8 segcnt;
+ u32 bytecnt;
+} soc_hdr;
+
+typedef struct {
+ u32 base;
+ u32 count;
+} soc_data;
+
+#define SOC_CQTYPE_OUTBOUND 0x01
+#define SOC_CQTYPE_INBOUND 0x02
+#define SOC_CQTYPE_SIMPLE 0x03
+#define SOC_CQTYPE_IO_WRITE 0x04
+#define SOC_CQTYPE_IO_READ 0x05
+#define SOC_CQTYPE_UNSOLICITED 0x06
+#define SOC_CQTYPE_DIAG 0x07
+#define SOC_CQTYPE_OFFLINE 0x08
+#define SOC_CQTYPE_RESPONSE 0x10
+#define SOC_CQTYPE_INLINE 0x20
+
+#define SOC_CQFLAGS_CONT 0x01
+#define SOC_CQFLAGS_FULL 0x02
+#define SOC_CQFLAGS_BADHDR 0x04
+#define SOC_CQFLAGS_BADPKT 0x08
+
+typedef struct {
+ soc_hdr shdr;
+ soc_data data[3];
+ fc_hdr fchdr;
+ u8 count;
+ u8 type;
+ u8 flags;
+ u8 seqno;
+} soc_req;
+
+#define SOC_OK 0
+#define SOC_P_RJT 2
+#define SOC_F_RJT 3
+#define SOC_P_BSY 4
+#define SOC_F_BSY 5
+#define SOC_ONLINE 0x10
+#define SOC_OFFLINE 0x11
+#define SOC_TIMEOUT 0x12
+#define SOC_OVERRUN 0x13
+#define SOC_UNKOWN_CQ_TYPE 0x20
+#define SOC_BAD_SEG_CNT 0x21
+#define SOC_MAX_XCHG_EXCEEDED 0x22
+#define SOC_BAD_XID 0x23
+#define SOC_XCHG_BUSY 0x24
+#define SOC_BAD_POOL_ID 0x25
+#define SOC_INSUFFICIENT_CQES 0x26
+#define SOC_ALLOC_FAIL 0x27
+#define SOC_BAD_SID 0x28
+#define SOC_NO_SEG_INIT 0x29
+
+typedef struct {
+ soc_hdr shdr;
+ u32 status;
+ soc_data data;
+ u8 xxx1[12];
+ fc_hdr fchdr;
+ u8 count;
+ u8 type;
+ u8 flags;
+ u8 seqno;
+} soc_rsp;
+
+/* }}} */
+
+/* Now our software structures and constants we use to drive the beast {{{ */
+
+#define SOC_CQ_REQ0_SIZE 4
+#define SOC_CQ_REQ1_SIZE 64
+#define SOC_CQ_RSP0_SIZE 8
+#define SOC_CQ_RSP1_SIZE 4
+
+#define SOC_SOLICITED_RSP_Q 0
+#define SOC_UNSOLICITED_RSP_Q 1
+
+struct soc;
+
+typedef struct {
+ /* This must come first */
+ fc_channel fc;
+ struct soc *s;
+ u16 flags;
+ u16 mask;
+} soc_port;
+
+typedef struct {
+ soc_hw_cq __iomem *hw_cq; /* Related XRAM cq */
+ soc_req __iomem *pool;
+ u8 in;
+ u8 out;
+ u8 last;
+ u8 seqno;
+} soc_cq_rsp;
+
+typedef struct {
+ soc_hw_cq __iomem *hw_cq; /* Related XRAM cq */
+ soc_req *pool;
+ u8 in;
+ u8 out;
+ u8 last;
+ u8 seqno;
+} soc_cq_req;
+
+struct soc {
+ spinlock_t lock;
+ soc_port port[2]; /* Every SOC has one or two FC ports */
+ soc_cq_req req[2]; /* Request CQs */
+ soc_cq_rsp rsp[2]; /* Response CQs */
+ int soc_no;
+ void __iomem *regs;
+ xram_p xram;
+ fc_wwn wwn;
+ u32 imask; /* Our copy of regs->imask */
+ u32 cfg; /* Our copy of regs->cfg */
+ char serv_params[80];
+ struct soc *next;
+ int curr_port; /* Which port will have priority to fcp_queue_empty */
+
+ soc_req *req_cpu;
+ u32 req_dvma;
+};
+
+/* }}} */
+
+#endif /* !(__SOC_H) */
diff --git a/drivers/fc4/socal.c b/drivers/fc4/socal.c
new file mode 100644
index 00000000000..b2377dbd84a
--- /dev/null
+++ b/drivers/fc4/socal.c
@@ -0,0 +1,906 @@
+/* socal.c: Sparc SUNW,socal (SOC+) Fibre Channel Sbus adapter support.
+ *
+ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
+ *
+ * Sources:
+ * Fibre Channel Physical & Signaling Interface (FC-PH), dpANS, 1994
+ * dpANS Fibre Channel Protocol for SCSI (X3.269-199X), Rev. 012, 1995
+ * SOC+ Programming Guide 0.1
+ * Fibre Channel Arbitrated Loop (FC-AL), dpANS rev. 4.5, 1995
+ *
+ * Supported hardware:
+ * On-board SOC+ adapters of Ultra Enterprise servers and sun4d.
+ */
+
+static char *version =
+ "socal.c: SOC+ driver v1.1 9/Feb/99 Jakub Jelinek (jj@ultra.linux.cz)\n";
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/fcntl.h>
+#include <linux/interrupt.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/in.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/init.h>
+#include <linux/bitops.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/dma.h>
+#include <linux/errno.h>
+#include <asm/byteorder.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+#include <asm/pgtable.h>
+#include <asm/irq.h>
+
+/* #define SOCALDEBUG */
+/* #define HAVE_SOCAL_UCODE */
+/* #define USE_64BIT_MODE */
+
+#include "fcp_impl.h"
+#include "socal.h"
+#ifdef HAVE_SOCAL_UCODE
+#include "socal_asm.h"
+#endif
+
+#define socal_printk printk ("socal%d: ", s->socal_no); printk
+
+#ifdef SOCALDEBUG
+#define SOD(x) socal_printk x;
+#else
+#define SOD(x)
+#endif
+
+#define for_each_socal(s) for (s = socals; s; s = s->next)
+struct socal *socals = NULL;
+
+static void socal_copy_from_xram(void *d, void __iomem *xram, long size)
+{
+ u32 *dp = (u32 *) d;
+ while (size) {
+ *dp++ = sbus_readl(xram);
+ xram += sizeof(u32);
+ size -= sizeof(u32);
+ }
+}
+
+static void socal_copy_to_xram(void __iomem *xram, void *s, long size)
+{
+ u32 *sp = (u32 *) s;
+ while (size) {
+ u32 val = *sp++;
+ sbus_writel(val, xram);
+ xram += sizeof(u32);
+ size -= sizeof(u32);
+ }
+}
+
+#ifdef HAVE_SOCAL_UCODE
+static void socal_bzero(unsigned long xram, int size)
+{
+ while (size) {
+ sbus_writel(0, xram);
+ xram += sizeof(u32);
+ size -= sizeof(u32);
+ }
+}
+#endif
+
+static inline void socal_disable(struct socal *s)
+{
+ sbus_writel(0, s->regs + IMASK);
+ sbus_writel(SOCAL_CMD_SOFT_RESET, s->regs + CMD);
+}
+
+static inline void socal_enable(struct socal *s)
+{
+ SOD(("enable %08x\n", s->cfg))
+ sbus_writel(0, s->regs + SAE);
+ sbus_writel(s->cfg, s->regs + CFG);
+ sbus_writel(SOCAL_CMD_RSP_QALL, s->regs + CMD);
+ SOCAL_SETIMASK(s, SOCAL_IMASK_RSP_QALL | SOCAL_IMASK_SAE);
+ SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
+}
+
+static void socal_reset(fc_channel *fc)
+{
+ socal_port *port = (socal_port *)fc;
+ struct socal *s = port->s;
+
+ /* FIXME */
+ socal_disable(s);
+ s->req[0].seqno = 1;
+ s->req[1].seqno = 1;
+ s->rsp[0].seqno = 1;
+ s->rsp[1].seqno = 1;
+ s->req[0].in = 0;
+ s->req[1].in = 0;
+ s->rsp[0].in = 0;
+ s->rsp[1].in = 0;
+ s->req[0].out = 0;
+ s->req[1].out = 0;
+ s->rsp[0].out = 0;
+ s->rsp[1].out = 0;
+
+ /* FIXME */
+ socal_enable(s);
+}
+
+static inline void socal_solicited(struct socal *s, unsigned long qno)
+{
+ socal_rsp *hwrsp;
+ socal_cq *sw_cq;
+ int token;
+ int status;
+ fc_channel *fc;
+
+ sw_cq = &s->rsp[qno];
+
+ /* Finally an improvement against old SOC :) */
+ sw_cq->in = sbus_readb(s->regs + RESP + qno);
+ SOD (("socal_solicited, %d packets arrived\n",
+ (sw_cq->in - sw_cq->out) & sw_cq->last))
+ for (;;) {
+ hwrsp = (socal_rsp *)sw_cq->pool + sw_cq->out;
+ SOD(("hwrsp %p out %d\n", hwrsp, sw_cq->out))
+
+#if defined(SOCALDEBUG) && 0
+ {
+ u32 *u = (u32 *)hwrsp;
+ 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]))
+ u += 8;
+ 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]))
+ u = (u32 *)s->xram;
+ while (u < ((u32 *)s->regs)) {
+ if (sbus_readl(&u[0]) == 0x00003000 ||
+ sbus_readl(&u[0]) == 0x00003801) {
+ SOD(("Found at %04lx\n",
+ (unsigned long)u - (unsigned long)s->xram))
+ SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
+ sbus_readl(&u[0]), sbus_readl(&u[1]),
+ sbus_readl(&u[2]), sbus_readl(&u[3]),
+ sbus_readl(&u[4]), sbus_readl(&u[5]),
+ sbus_readl(&u[6]), sbus_readl(&u[7])))
+ u += 8;
+ SOD((" %08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x\n",
+ sbus_readl(&u[0]), sbus_readl(&u[1]),
+ sbus_readl(&u[2]), sbus_readl(&u[3]),
+ sbus_readl(&u[4]), sbus_readl(&u[5]),
+ sbus_readl(&u[6]), sbus_readl(&u[7])))
+ u -= 8;
+ }
+ u++;
+ }
+ }
+#endif
+
+ token = hwrsp->shdr.token;
+ status = hwrsp->status;
+ fc = (fc_channel *)(&s->port[(token >> 11) & 1]);
+
+ SOD(("Solicited token %08x status %08x\n", token, status))
+ if (status == SOCAL_OK) {
+ fcp_receive_solicited(fc, token >> 12,
+ token & ((1 << 11) - 1),
+ FC_STATUS_OK, NULL);
+ } else {
+ /* We have intentionally defined FC_STATUS_* constants
+ * to match SOCAL_* constants, otherwise we'd have to
+ * translate status.
+ */
+ fcp_receive_solicited(fc, token >> 12,
+ token & ((1 << 11) - 1), status, &hwrsp->fchdr);
+ }
+
+ if (++sw_cq->out > sw_cq->last) {
+ sw_cq->seqno++;
+ sw_cq->out = 0;
+ }
+
+ if (sw_cq->out == sw_cq->in) {
+ sw_cq->in = sbus_readb(s->regs + RESP + qno);
+ if (sw_cq->out == sw_cq->in) {
+ /* Tell the hardware about it */
+ sbus_writel((sw_cq->out << 24) |
+ (SOCAL_CMD_RSP_QALL &
+ ~(SOCAL_CMD_RSP_Q0 << qno)),
+ s->regs + CMD);
+
+ /* Read it, so that we're sure it has been updated */
+ sbus_readl(s->regs + CMD);
+ sw_cq->in = sbus_readb(s->regs + RESP + qno);
+ if (sw_cq->out == sw_cq->in)
+ break;
+ }
+ }
+ }
+}
+
+static inline void socal_request (struct socal *s, u32 cmd)
+{
+ SOCAL_SETIMASK(s, s->imask & ~(cmd & SOCAL_CMD_REQ_QALL));
+ SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
+
+ SOD(("Queues available %08x OUT %X\n", cmd, s->regs->reqpr[0]))
+ if (s->port[s->curr_port].fc.state != FC_STATE_OFFLINE) {
+ fcp_queue_empty ((fc_channel *)&(s->port[s->curr_port]));
+ if (((s->req[1].in + 1) & s->req[1].last) != (s->req[1].out))
+ fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
+ } else {
+ fcp_queue_empty ((fc_channel *)&(s->port[1 - s->curr_port]));
+ }
+ if (s->port[1 - s->curr_port].fc.state != FC_STATE_OFFLINE)
+ s->curr_port ^= 1;
+}
+
+static inline void socal_unsolicited (struct socal *s, unsigned long qno)
+{
+ socal_rsp *hwrsp, *hwrspc;
+ socal_cq *sw_cq;
+ int count;
+ int status;
+ int flags;
+ fc_channel *fc;
+
+ sw_cq = &s->rsp[qno];
+
+ sw_cq->in = sbus_readb(s->regs + RESP + qno);
+ SOD (("socal_unsolicited, %d packets arrived, in %d\n",
+ (sw_cq->in - sw_cq->out) & sw_cq->last, sw_cq->in))
+ while (sw_cq->in != sw_cq->out) {
+ /* ...real work per entry here... */
+ hwrsp = (socal_rsp *)sw_cq->pool + sw_cq->out;
+ SOD(("hwrsp %p out %d\n", hwrsp, sw_cq->out))
+
+#if defined(SOCALDEBUG) && 0
+ {
+ u32 *u = (u32 *)hwrsp;
+ 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]))
+ u += 8;
+ 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]))
+ }
+#endif
+
+ hwrspc = NULL;
+ flags = hwrsp->shdr.flags;
+ count = hwrsp->count;
+ fc = (fc_channel *)&s->port[flags & SOCAL_PORT_B];
+ SOD(("FC %08lx\n", (long)fc))
+
+ if (count != 1) {
+ /* Ugh, continuation entries */
+ u8 in;
+
+ if (count != 2) {
+ printk("%s: Too many continuations entries %d\n",
+ fc->name, count);
+ goto update_out;
+ }
+
+ in = sw_cq->in;
+ if (in < sw_cq->out)
+ in += sw_cq->last + 1;
+ if (in < sw_cq->out + 2) {
+ /* Ask the hardware if they haven't arrived yet. */
+ sbus_writel((sw_cq->out << 24) |
+ (SOCAL_CMD_RSP_QALL &
+ ~(SOCAL_CMD_RSP_Q0 << qno)),
+ s->regs + CMD);
+
+ /* Read it, so that we're sure it has been updated */
+ sbus_readl(s->regs + CMD);
+ sw_cq->in = sbus_readb(s->regs + RESP + qno);
+ in = sw_cq->in;
+ if (in < sw_cq->out)
+ in += sw_cq->last + 1;
+ if (in < sw_cq->out + 2) /* Nothing came, let us wait */
+ return;
+ }
+ if (sw_cq->out == sw_cq->last)
+ hwrspc = (socal_rsp *)sw_cq->pool;
+ else
+ hwrspc = hwrsp + 1;
+ }
+
+ switch (flags & ~SOCAL_PORT_B) {
+ case SOCAL_STATUS:
+ status = hwrsp->status;
+ switch (status) {
+ case SOCAL_ONLINE:
+ SOD(("State change to ONLINE\n"));
+ fcp_state_change(fc, FC_STATE_ONLINE);
+ break;
+ case SOCAL_ONLINE_LOOP:
+ SOD(("State change to ONLINE_LOOP\n"));
+ fcp_state_change(fc, FC_STATE_ONLINE);
+ break;
+ case SOCAL_OFFLINE:
+ SOD(("State change to OFFLINE\n"));
+ fcp_state_change(fc, FC_STATE_OFFLINE);
+ break;
+ default:
+ printk ("%s: Unknown STATUS no %d\n",
+ fc->name, status);
+ break;
+ };
+
+ break;
+ case (SOCAL_UNSOLICITED|SOCAL_FC_HDR):
+ {
+ int r_ctl = *((u8 *)&hwrsp->fchdr);
+ unsigned len;
+
+ if ((r_ctl & 0xf0) == R_CTL_EXTENDED_SVC) {
+ len = hwrsp->shdr.bytecnt;
+ if (len < 4 || !hwrspc) {
+ printk ("%s: Invalid R_CTL %02x "
+ "continuation entries\n",
+ fc->name, r_ctl);
+ } else {
+ if (len > 60)
+ len = 60;
+ if (*(u32 *)hwrspc == LS_DISPLAY) {
+ int i;
+
+ for (i = 4; i < len; i++)
+ if (((u8 *)hwrspc)[i] == '\n')
+ ((u8 *)hwrspc)[i] = ' ';
+ ((u8 *)hwrspc)[len] = 0;
+ printk ("%s message: %s\n",
+ fc->name, ((u8 *)hwrspc) + 4);
+ } else {
+ printk ("%s: Unknown LS_CMD "
+ "%08x\n", fc->name,
+ *(u32 *)hwrspc);
+ }
+ }
+ } else {
+ printk ("%s: Unsolicited R_CTL %02x "
+ "not handled\n", fc->name, r_ctl);
+ }
+ }
+ break;
+ default:
+ printk ("%s: Unexpected flags %08x\n", fc->name, flags);
+ break;
+ };
+update_out:
+ if (++sw_cq->out > sw_cq->last) {
+ sw_cq->seqno++;
+ sw_cq->out = 0;
+ }
+
+ if (hwrspc) {
+ if (++sw_cq->out > sw_cq->last) {
+ sw_cq->seqno++;
+ sw_cq->out = 0;
+ }
+ }
+
+ if (sw_cq->out == sw_cq->in) {
+ sw_cq->in = sbus_readb(s->regs + RESP + qno);
+ if (sw_cq->out == sw_cq->in) {
+ /* Tell the hardware about it */
+ sbus_writel((sw_cq->out << 24) |
+ (SOCAL_CMD_RSP_QALL &
+ ~(SOCAL_CMD_RSP_Q0 << qno)),
+ s->regs + CMD);
+
+ /* Read it, so that we're sure it has been updated */
+ sbus_readl(s->regs + CMD);
+ sw_cq->in = sbus_readb(s->regs + RESP + qno);
+ }
+ }
+ }
+}
+
+static irqreturn_t socal_intr(int irq, void *dev_id, struct pt_regs *regs)
+{
+ u32 cmd;
+ unsigned long flags;
+ register struct socal *s = (struct socal *)dev_id;
+
+ spin_lock_irqsave(&s->lock, flags);
+ cmd = sbus_readl(s->regs + CMD);
+ for (; (cmd = SOCAL_INTR (s, cmd)); cmd = sbus_readl(s->regs + CMD)) {
+#ifdef SOCALDEBUG
+ static int cnt = 0;
+ if (cnt++ < 50)
+ printk("soc_intr %08x\n", cmd);
+#endif
+ if (cmd & SOCAL_CMD_RSP_Q2)
+ socal_unsolicited (s, SOCAL_UNSOLICITED_RSP_Q);
+ if (cmd & SOCAL_CMD_RSP_Q1)
+ socal_unsolicited (s, SOCAL_SOLICITED_BAD_RSP_Q);
+ if (cmd & SOCAL_CMD_RSP_Q0)
+ socal_solicited (s, SOCAL_SOLICITED_RSP_Q);
+ if (cmd & SOCAL_CMD_REQ_QALL)
+ socal_request (s, cmd);
+ }
+ spin_unlock_irqrestore(&s->lock, flags);
+
+ return IRQ_HANDLED;
+}
+
+#define TOKEN(proto, port, token) (((proto)<<12)|(token)|(port))
+
+static int socal_hw_enque (fc_channel *fc, fcp_cmnd *fcmd)
+{
+ socal_port *port = (socal_port *)fc;
+ struct socal *s = port->s;
+ unsigned long qno;
+ socal_cq *sw_cq;
+ int cq_next_in;
+ socal_req *request;
+ fc_hdr *fch;
+ int i;
+
+ if (fcmd->proto == TYPE_SCSI_FCP)
+ qno = 1;
+ else
+ qno = 0;
+ SOD(("Putting a FCP packet type %d into hw queue %d\n", fcmd->proto, qno))
+ if (s->imask & (SOCAL_IMASK_REQ_Q0 << qno)) {
+ SOD(("EIO %08x\n", s->imask))
+ return -EIO;
+ }
+ sw_cq = s->req + qno;
+ cq_next_in = (sw_cq->in + 1) & sw_cq->last;
+
+ if (cq_next_in == sw_cq->out &&
+ cq_next_in == (sw_cq->out = sbus_readb(s->regs + REQP + qno))) {
+ SOD(("%d IN %d OUT %d LAST %d\n",
+ qno, sw_cq->in,
+ sw_cq->out, sw_cq->last))
+ SOCAL_SETIMASK(s, s->imask | (SOCAL_IMASK_REQ_Q0 << qno));
+ SOD(("imask %08x %08x\n", s->imask, sbus_readl(s->regs + IMASK)));
+
+ /* If queue is full, just say NO. */
+ return -EBUSY;
+ }
+
+ request = sw_cq->pool + sw_cq->in;
+ fch = &request->fchdr;
+
+ switch (fcmd->proto) {
+ case TYPE_SCSI_FCP:
+ request->shdr.token = TOKEN(TYPE_SCSI_FCP, port->mask, fcmd->token);
+ request->data[0].base = fc->dma_scsi_cmd + fcmd->token * sizeof(fcp_cmd);
+ request->data[0].count = sizeof(fcp_cmd);
+ request->data[1].base = fc->dma_scsi_rsp + fcmd->token * fc->rsp_size;
+ request->data[1].count = fc->rsp_size;
+ if (fcmd->data) {
+ request->shdr.segcnt = 3;
+ i = fc->scsi_cmd_pool[fcmd->token].fcp_data_len;
+ request->shdr.bytecnt = i;
+ request->data[2].base = fcmd->data;
+ request->data[2].count = i;
+ request->type = (fc->scsi_cmd_pool[fcmd->token].fcp_cntl & FCP_CNTL_WRITE) ?
+ SOCAL_CQTYPE_IO_WRITE : SOCAL_CQTYPE_IO_READ;
+ } else {
+ request->shdr.segcnt = 2;
+ request->shdr.bytecnt = 0;
+ request->data[2].base = 0;
+ request->data[2].count = 0;
+ request->type = SOCAL_CQTYPE_SIMPLE;
+ }
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fcmd->did);
+ FILL_FCHDR_SID(fch, fc->sid);
+ FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
+ FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
+ FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
+ fch->param = 0;
+ request->shdr.flags = port->flags;
+ request->shdr.class = fc->posmap ? 3 : 2;
+ break;
+
+ case PROTO_OFFLINE:
+ memset (request, 0, sizeof(*request));
+ request->shdr.token = TOKEN(PROTO_OFFLINE, port->mask, fcmd->token);
+ request->type = SOCAL_CQTYPE_OFFLINE;
+ FILL_FCHDR_RCTL_DID(fch, R_CTL_COMMAND, fcmd->did);
+ FILL_FCHDR_SID(fch, fc->sid);
+ FILL_FCHDR_TYPE_FCTL(fch, TYPE_SCSI_FCP, F_CTL_FIRST_SEQ | F_CTL_SEQ_INITIATIVE);
+ FILL_FCHDR_SEQ_DF_SEQ(fch, 0, 0, 0);
+ FILL_FCHDR_OXRX(fch, 0xffff, 0xffff);
+ request->shdr.flags = port->flags;
+ break;
+
+ case PROTO_REPORT_AL_MAP:
+ memset (request, 0, sizeof(*request));
+ request->shdr.token = TOKEN(PROTO_REPORT_AL_MAP, port->mask, fcmd->token);
+ request->type = SOCAL_CQTYPE_REPORT_MAP;
+ request->shdr.flags = port->flags;
+ request->shdr.segcnt = 1;
+ request->shdr.bytecnt = sizeof(fc_al_posmap);
+ request->data[0].base = fcmd->cmd;
+ request->data[0].count = sizeof(fc_al_posmap);
+ break;
+
+ default:
+ request->shdr.token = TOKEN(fcmd->proto, port->mask, fcmd->token);
+ request->shdr.class = fc->posmap ? 3 : 2;
+ request->shdr.flags = port->flags;
+ memcpy (fch, &fcmd->fch, sizeof(fc_hdr));
+ request->data[0].count = fcmd->cmdlen;
+ request->data[1].count = fcmd->rsplen;
+ request->type = fcmd->class;
+ switch (fcmd->class) {
+ case FC_CLASS_OUTBOUND:
+ request->data[0].base = fcmd->cmd;
+ request->data[0].count = fcmd->cmdlen;
+ request->type = SOCAL_CQTYPE_OUTBOUND;
+ request->shdr.bytecnt = fcmd->cmdlen;
+ request->shdr.segcnt = 1;
+ break;
+ case FC_CLASS_INBOUND:
+ request->data[0].base = fcmd->rsp;
+ request->data[0].count = fcmd->rsplen;
+ request->type = SOCAL_CQTYPE_INBOUND;
+ request->shdr.bytecnt = 0;
+ request->shdr.segcnt = 1;
+ break;
+ case FC_CLASS_SIMPLE:
+ request->data[0].base = fcmd->cmd;
+ request->data[1].base = fcmd->rsp;
+ request->data[0].count = fcmd->cmdlen;
+ request->data[1].count = fcmd->rsplen;
+ request->type = SOCAL_CQTYPE_SIMPLE;
+ request->shdr.bytecnt = fcmd->cmdlen;
+ request->shdr.segcnt = 2;
+ break;
+ case FC_CLASS_IO_READ:
+ case FC_CLASS_IO_WRITE:
+ request->data[0].base = fcmd->cmd;
+ request->data[1].base = fcmd->rsp;
+ request->data[0].count = fcmd->cmdlen;
+ request->data[1].count = fcmd->rsplen;
+ request->type = (fcmd->class == FC_CLASS_IO_READ) ? SOCAL_CQTYPE_IO_READ : SOCAL_CQTYPE_IO_WRITE;
+ if (fcmd->data) {
+ request->data[2].base = fcmd->data;
+ request->data[2].count = fcmd->datalen;
+ request->shdr.bytecnt = fcmd->datalen;
+ request->shdr.segcnt = 3;
+ } else {
+ request->shdr.bytecnt = 0;
+ request->shdr.segcnt = 2;
+ }
+ break;
+ }
+ break;
+ }
+
+ request->count = 1;
+ request->flags = 0;
+ request->seqno = sw_cq->seqno;
+
+ SOD(("queueing token %08x\n", request->shdr.token))
+
+ /* And now tell the SOCAL about it */
+
+ if (++sw_cq->in > sw_cq->last) {
+ sw_cq->in = 0;
+ sw_cq->seqno++;
+ }
+
+ SOD(("Putting %08x into cmd\n", SOCAL_CMD_RSP_QALL | (sw_cq->in << 24) | (SOCAL_CMD_REQ_Q0 << qno)))
+
+ sbus_writel(SOCAL_CMD_RSP_QALL | (sw_cq->in << 24) | (SOCAL_CMD_REQ_Q0 << qno),
+ s->regs + CMD);
+
+ /* Read so that command is completed */
+ sbus_readl(s->regs + CMD);
+
+ return 0;
+}
+
+static inline void socal_download_fw(struct socal *s)
+{
+#ifdef HAVE_SOCAL_UCODE
+ SOD(("Loading %ld bytes from %p to %p\n", sizeof(socal_ucode), socal_ucode, s->xram))
+ socal_copy_to_xram(s->xram, socal_ucode, sizeof(socal_ucode));
+ SOD(("Clearing the rest of memory\n"))
+ socal_bzero (s->xram + sizeof(socal_ucode), 65536 - sizeof(socal_ucode));
+ SOD(("Done\n"))
+#endif
+}
+
+/* Check for what the best SBUS burst we can use happens
+ * to be on this machine.
+ */
+static inline void socal_init_bursts(struct socal *s, struct sbus_dev *sdev)
+{
+ int bsizes, bsizes_more;
+ u32 cfg;
+
+ bsizes = (prom_getintdefault(sdev->prom_node,"burst-sizes",0xff) & 0xff);
+ bsizes_more = (prom_getintdefault(sdev->bus->prom_node, "burst-sizes", 0xff) & 0xff);
+ bsizes &= bsizes_more;
+#ifdef USE_64BIT_MODE
+#ifdef __sparc_v9__
+ mmu_set_sbus64(sdev, bsizes >> 16);
+#endif
+#endif
+ if ((bsizes & 0x7f) == 0x7f)
+ cfg = SOCAL_CFG_BURST_64;
+ else if ((bsizes & 0x3f) == 0x3f)
+ cfg = SOCAL_CFG_BURST_32;
+ else if ((bsizes & 0x1f) == 0x1f)
+ cfg = SOCAL_CFG_BURST_16;
+ else
+ cfg = SOCAL_CFG_BURST_4;
+#ifdef USE_64BIT_MODE
+#ifdef __sparc_v9__
+ /* What is BURST_128? -jj */
+ if ((bsizes & 0x780000) == 0x780000)
+ cfg |= (SOCAL_CFG_BURST_64 << 8) | SOCAL_CFG_SBUS_ENHANCED;
+ else if ((bsizes & 0x380000) == 0x380000)
+ cfg |= (SOCAL_CFG_BURST_32 << 8) | SOCAL_CFG_SBUS_ENHANCED;
+ else if ((bsizes & 0x180000) == 0x180000)
+ cfg |= (SOCAL_CFG_BURST_16 << 8) | SOCAL_CFG_SBUS_ENHANCED;
+ else
+ cfg |= (SOCAL_CFG_BURST_8 << 8) | SOCAL_CFG_SBUS_ENHANCED;
+#endif
+#endif
+ s->cfg = cfg;
+}
+
+static inline void socal_init(struct sbus_dev *sdev, int no)
+{
+ unsigned char tmp[60];
+ int propl;
+ struct socal *s;
+ static unsigned version_printed = 0;
+ socal_hw_cq cq[8];
+ int size, i;
+ int irq, node;
+
+ s = kmalloc (sizeof (struct socal), GFP_KERNEL);
+ if (!s) return;
+ memset (s, 0, sizeof(struct socal));
+ spin_lock_init(&s->lock);
+ s->socal_no = no;
+
+ SOD(("socals %08lx socal_intr %08lx socal_hw_enque %08lx\n",
+ (long)socals, (long)socal_intr, (long)socal_hw_enque))
+ if (version_printed++ == 0)
+ printk (version);
+
+ s->port[0].fc.module = THIS_MODULE;
+ s->port[1].fc.module = THIS_MODULE;
+
+ s->next = socals;
+ socals = s;
+ s->port[0].fc.dev = sdev;
+ s->port[1].fc.dev = sdev;
+ s->port[0].s = s;
+ s->port[1].s = s;
+
+ s->port[0].fc.next = &s->port[1].fc;
+
+ /* World Wide Name of SOCAL */
+ propl = prom_getproperty (sdev->prom_node, "wwn", tmp, sizeof(tmp));
+ if (propl != sizeof (fc_wwn)) {
+ s->wwn.naaid = NAAID_IEEE_REG;
+ s->wwn.nportid = 0x123;
+ s->wwn.hi = 0x1234;
+ s->wwn.lo = 0x12345678;
+ } else
+ memcpy (&s->wwn, tmp, sizeof (fc_wwn));
+
+ memcpy (&s->port[0].fc.wwn_nport, &s->wwn, sizeof (fc_wwn));
+ s->port[0].fc.wwn_nport.lo++;
+ memcpy (&s->port[1].fc.wwn_nport, &s->wwn, sizeof (fc_wwn));
+ s->port[1].fc.wwn_nport.lo+=2;
+
+ node = prom_getchild (sdev->prom_node);
+ while (node && (node = prom_searchsiblings (node, "sf"))) {
+ int port;
+
+ port = prom_getintdefault(node, "port#", -1);
+ switch (port) {
+ case 0:
+ case 1:
+ if (prom_getproplen(node, "port-wwn") == sizeof (fc_wwn))
+ prom_getproperty (node, "port-wwn",
+ (char *)&s->port[port].fc.wwn_nport,
+ sizeof (fc_wwn));
+ break;
+ default:
+ break;
+ };
+
+ node = prom_getsibling(node);
+ }
+
+ memcpy (&s->port[0].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
+ memcpy (&s->port[1].fc.wwn_node, &s->wwn, sizeof (fc_wwn));
+ SOD(("Got wwns %08x%08x ports %08x%08x and %08x%08x\n",
+ *(u32 *)&s->port[0].fc.wwn_node, s->port[0].fc.wwn_node.lo,
+ *(u32 *)&s->port[0].fc.wwn_nport, s->port[0].fc.wwn_nport.lo,
+ *(u32 *)&s->port[1].fc.wwn_nport, s->port[1].fc.wwn_nport.lo))
+
+ s->port[0].fc.sid = 1;
+ s->port[1].fc.sid = 17;
+ s->port[0].fc.did = 2;
+ s->port[1].fc.did = 18;
+
+ s->port[0].fc.reset = socal_reset;
+ s->port[1].fc.reset = socal_reset;
+
+ if (sdev->num_registers == 1) {
+ s->eeprom = sbus_ioremap(&sdev->resource[0], 0,
+ sdev->reg_addrs[0].reg_size, "socal xram");
+ if (sdev->reg_addrs[0].reg_size > 0x20000)
+ s->xram = s->eeprom + 0x10000UL;
+ else
+ s->xram = s->eeprom;
+ s->regs = (s->xram + 0x10000UL);
+ } else {
+ /* E.g. starfire presents 3 registers for SOCAL */
+ s->xram = sbus_ioremap(&sdev->resource[1], 0,
+ sdev->reg_addrs[1].reg_size, "socal xram");
+ s->regs = sbus_ioremap(&sdev->resource[2], 0,
+ sdev->reg_addrs[2].reg_size, "socal regs");
+ }
+
+ socal_init_bursts(s, sdev);
+
+ SOD(("Disabling SOCAL\n"))
+
+ socal_disable (s);
+
+ irq = sdev->irqs[0];
+
+ if (request_irq (irq, socal_intr, SA_SHIRQ, "SOCAL", (void *)s)) {
+ socal_printk ("Cannot order irq %d to go\n", irq);
+ socals = s->next;
+ return;
+ }
+
+ SOD(("SOCAL uses IRQ %s\n", __irq_itoa(irq)))
+
+ s->port[0].fc.irq = irq;
+ s->port[1].fc.irq = irq;
+
+ sprintf (s->port[0].fc.name, "socal%d port A", no);
+ sprintf (s->port[1].fc.name, "socal%d port B", no);
+ s->port[0].flags = SOCAL_FC_HDR | SOCAL_PORT_A;
+ s->port[1].flags = SOCAL_FC_HDR | SOCAL_PORT_B;
+ s->port[1].mask = (1 << 11);
+
+ s->port[0].fc.hw_enque = socal_hw_enque;
+ s->port[1].fc.hw_enque = socal_hw_enque;
+
+ socal_download_fw (s);
+
+ SOD(("Downloaded firmware\n"))
+
+ /* Now setup xram circular queues */
+ memset (cq, 0, sizeof(cq));
+
+ size = (SOCAL_CQ_REQ0_SIZE + SOCAL_CQ_REQ1_SIZE +
+ SOCAL_CQ_RSP0_SIZE + SOCAL_CQ_RSP1_SIZE +
+ SOCAL_CQ_RSP2_SIZE) * sizeof(socal_req);
+ s->req_cpu = sbus_alloc_consistent(sdev, size, &s->req_dvma);
+ s->req[0].pool = s->req_cpu;
+ cq[0].address = s->req_dvma;
+ s->req[1].pool = s->req[0].pool + SOCAL_CQ_REQ0_SIZE;
+ s->rsp[0].pool = s->req[1].pool + SOCAL_CQ_REQ1_SIZE;
+ s->rsp[1].pool = s->rsp[0].pool + SOCAL_CQ_RSP0_SIZE;
+ s->rsp[2].pool = s->rsp[1].pool + SOCAL_CQ_RSP1_SIZE;
+
+ s->req[0].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_REQ_OFFSET);
+ s->req[1].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_REQ_OFFSET + sizeof(socal_hw_cq));
+ s->rsp[0].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET);
+ s->rsp[1].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET + sizeof(socal_hw_cq));
+ s->rsp[2].hw_cq = (socal_hw_cq __iomem *)(s->xram + SOCAL_CQ_RSP_OFFSET + 2 * sizeof(socal_hw_cq));
+
+ cq[1].address = cq[0].address + (SOCAL_CQ_REQ0_SIZE * sizeof(socal_req));
+ cq[4].address = cq[1].address + (SOCAL_CQ_REQ1_SIZE * sizeof(socal_req));
+ cq[5].address = cq[4].address + (SOCAL_CQ_RSP0_SIZE * sizeof(socal_req));
+ cq[6].address = cq[5].address + (SOCAL_CQ_RSP1_SIZE * sizeof(socal_req));
+
+ cq[0].last = SOCAL_CQ_REQ0_SIZE - 1;
+ cq[1].last = SOCAL_CQ_REQ1_SIZE - 1;
+ cq[4].last = SOCAL_CQ_RSP0_SIZE - 1;
+ cq[5].last = SOCAL_CQ_RSP1_SIZE - 1;
+ cq[6].last = SOCAL_CQ_RSP2_SIZE - 1;
+ for (i = 0; i < 8; i++)
+ cq[i].seqno = 1;
+
+ s->req[0].last = SOCAL_CQ_REQ0_SIZE - 1;
+ s->req[1].last = SOCAL_CQ_REQ1_SIZE - 1;
+ s->rsp[0].last = SOCAL_CQ_RSP0_SIZE - 1;
+ s->rsp[1].last = SOCAL_CQ_RSP1_SIZE - 1;
+ s->rsp[2].last = SOCAL_CQ_RSP2_SIZE - 1;
+
+ s->req[0].seqno = 1;
+ s->req[1].seqno = 1;
+ s->rsp[0].seqno = 1;
+ s->rsp[1].seqno = 1;
+ s->rsp[2].seqno = 1;
+
+ socal_copy_to_xram(s->xram + SOCAL_CQ_REQ_OFFSET, cq, sizeof(cq));
+
+ SOD(("Setting up params\n"))
+
+ /* Make our sw copy of SOCAL service parameters */
+ socal_copy_from_xram(s->serv_params, s->xram + 0x280, sizeof (s->serv_params));
+
+ s->port[0].fc.common_svc = (common_svc_parm *)s->serv_params;
+ s->port[0].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
+ s->port[1].fc.common_svc = (common_svc_parm *)&s->serv_params;
+ s->port[1].fc.class_svcs = (svc_parm *)(s->serv_params + 0x20);
+
+ socal_enable (s);
+
+ SOD(("Enabled SOCAL\n"))
+}
+
+static int __init socal_probe(void)
+{
+ struct sbus_bus *sbus;
+ struct sbus_dev *sdev = NULL;
+ struct socal *s;
+ int cards = 0;
+
+ for_each_sbus(sbus) {
+ for_each_sbusdev(sdev, sbus) {
+ if(!strcmp(sdev->prom_name, "SUNW,socal")) {
+ socal_init(sdev, cards);
+ cards++;
+ }
+ }
+ }
+ if (!cards)
+ return -EIO;
+
+ for_each_socal(s)
+ if (s->next)
+ s->port[1].fc.next = &s->next->port[0].fc;
+
+ fcp_init (&socals->port[0].fc);
+ return 0;
+}
+
+static void __exit socal_cleanup(void)
+{
+ struct socal *s;
+ int irq;
+ struct sbus_dev *sdev;
+
+ for_each_socal(s) {
+ irq = s->port[0].fc.irq;
+ free_irq (irq, s);
+
+ fcp_release(&(s->port[0].fc), 2);
+
+ sdev = s->port[0].fc.dev;
+ if (sdev->num_registers == 1) {
+ sbus_iounmap(s->eeprom, sdev->reg_addrs[0].reg_size);
+ } else {
+ sbus_iounmap(s->xram, sdev->reg_addrs[1].reg_size);
+ sbus_iounmap(s->regs, sdev->reg_addrs[2].reg_size);
+ }
+ sbus_free_consistent(sdev,
+ (SOCAL_CQ_REQ0_SIZE + SOCAL_CQ_REQ1_SIZE +
+ SOCAL_CQ_RSP0_SIZE + SOCAL_CQ_RSP1_SIZE +
+ SOCAL_CQ_RSP2_SIZE) * sizeof(socal_req),
+ s->req_cpu, s->req_dvma);
+ }
+}
+
+module_init(socal_probe);
+module_exit(socal_cleanup);
+MODULE_LICENSE("GPL");
diff --git a/drivers/fc4/socal.h b/drivers/fc4/socal.h
new file mode 100644
index 00000000000..774edf68e4d
--- /dev/null
+++ b/drivers/fc4/socal.h
@@ -0,0 +1,314 @@
+/* socal.h: Definitions for Sparc SUNW,socal (SOC+) Fibre Channel Sbus driver.
+ *
+ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
+ */
+
+#ifndef __SOCAL_H
+#define __SOCAL_H
+
+#include "fc.h"
+#include "fcp.h"
+#include "fcp_impl.h"
+
+/* Hardware register offsets and constants first {{{ */
+#define CFG 0x00UL
+#define SAE 0x04UL
+#define CMD 0x08UL
+#define IMASK 0x0cUL
+#define REQP 0x10UL
+#define RESP 0x14UL
+
+/* Config Register */
+#define SOCAL_CFG_EXT_RAM_BANK_MASK 0x07000000
+#define SOCAL_CFG_EEPROM_BANK_MASK 0x00030000
+#define SOCAL_CFG_BURST64_MASK 0x00000700
+#define SOCAL_CFG_SBUS_PARITY_TEST 0x00000020
+#define SOCAL_CFG_SBUS_PARITY_CHECK 0x00000010
+#define SOCAL_CFG_SBUS_ENHANCED 0x00000008
+#define SOCAL_CFG_BURST_MASK 0x00000007
+/* Bursts */
+#define SOCAL_CFG_BURST_4 0x00000000
+#define SOCAL_CFG_BURST_8 0x00000003
+#define SOCAL_CFG_BURST_16 0x00000004
+#define SOCAL_CFG_BURST_32 0x00000005
+#define SOCAL_CFG_BURST_64 0x00000006
+#define SOCAL_CFG_BURST_128 0x00000007
+
+/* Slave Access Error Register */
+#define SOCAL_SAE_ALIGNMENT 0x00000004
+#define SOCAL_SAE_UNSUPPORTED 0x00000002
+#define SOCAL_SAE_PARITY 0x00000001
+
+/* Command & Status Register */
+#define SOCAL_CMD_RSP_QALL 0x000f0000
+#define SOCAL_CMD_RSP_Q0 0x00010000
+#define SOCAL_CMD_RSP_Q1 0x00020000
+#define SOCAL_CMD_RSP_Q2 0x00040000
+#define SOCAL_CMD_RSP_Q3 0x00080000
+#define SOCAL_CMD_REQ_QALL 0x00000f00
+#define SOCAL_CMD_REQ_Q0 0x00000100
+#define SOCAL_CMD_REQ_Q1 0x00000200
+#define SOCAL_CMD_REQ_Q2 0x00000400
+#define SOCAL_CMD_REQ_Q3 0x00000800
+#define SOCAL_CMD_SAE 0x00000080
+#define SOCAL_CMD_INTR_PENDING 0x00000008
+#define SOCAL_CMD_NON_QUEUED 0x00000004
+#define SOCAL_CMD_IDLE 0x00000002
+#define SOCAL_CMD_SOFT_RESET 0x00000001
+
+/* Interrupt Mask Register */
+#define SOCAL_IMASK_RSP_QALL 0x000f0000
+#define SOCAL_IMASK_RSP_Q0 0x00010000
+#define SOCAL_IMASK_RSP_Q1 0x00020000
+#define SOCAL_IMASK_RSP_Q2 0x00040000
+#define SOCAL_IMASK_RSP_Q3 0x00080000
+#define SOCAL_IMASK_REQ_QALL 0x00000f00
+#define SOCAL_IMASK_REQ_Q0 0x00000100
+#define SOCAL_IMASK_REQ_Q1 0x00000200
+#define SOCAL_IMASK_REQ_Q2 0x00000400
+#define SOCAL_IMASK_REQ_Q3 0x00000800
+#define SOCAL_IMASK_SAE 0x00000080
+#define SOCAL_IMASK_NON_QUEUED 0x00000004
+
+#define SOCAL_INTR(s, cmd) \
+ (((cmd & SOCAL_CMD_RSP_QALL) | ((~cmd) & SOCAL_CMD_REQ_QALL)) \
+ & s->imask)
+
+#define SOCAL_SETIMASK(s, i) \
+do { (s)->imask = (i); \
+ sbus_writel((i), (s)->regs + IMASK); \
+} while (0)
+
+#define SOCAL_MAX_EXCHANGES 1024
+
+/* XRAM
+ *
+ * This is a 64KB register area.
+ * From the documentation, it seems like it is finally able to cope
+ * at least with 1,2,4 byte accesses for read and 2,4 byte accesses for write.
+ */
+
+/* Circular Queue */
+
+#define SOCAL_CQ_REQ_OFFSET 0x200
+#define SOCAL_CQ_RSP_OFFSET 0x220
+
+typedef struct {
+ u32 address;
+ u8 in;
+ u8 out;
+ u8 last;
+ u8 seqno;
+} socal_hw_cq;
+
+#define SOCAL_PORT_A 0x0000 /* From/To Port A */
+#define SOCAL_PORT_B 0x0001 /* From/To Port A */
+#define SOCAL_FC_HDR 0x0002 /* Contains FC Header */
+#define SOCAL_NORSP 0x0004 /* Don't generate response nor interrupt */
+#define SOCAL_NOINT 0x0008 /* Generate response but not interrupt */
+#define SOCAL_XFERRDY 0x0010 /* Generate XFERRDY */
+#define SOCAL_IGNOREPARAM 0x0020 /* Ignore PARAM field in the FC header */
+#define SOCAL_COMPLETE 0x0040 /* Command completed */
+#define SOCAL_UNSOLICITED 0x0080 /* For request this is the packet to establish unsolicited pools, */
+ /* for rsp this is unsolicited packet */
+#define SOCAL_STATUS 0x0100 /* State change (on/off line) */
+#define SOCAL_RSP_HDR 0x0200 /* Return frame header in any case */
+
+typedef struct {
+ u32 token;
+ u16 flags;
+ u8 class;
+ u8 segcnt;
+ u32 bytecnt;
+} socal_hdr;
+
+typedef struct {
+ u32 base;
+ u32 count;
+} socal_data;
+
+#define SOCAL_CQTYPE_NOP 0x00
+#define SOCAL_CQTYPE_OUTBOUND 0x01
+#define SOCAL_CQTYPE_INBOUND 0x02
+#define SOCAL_CQTYPE_SIMPLE 0x03
+#define SOCAL_CQTYPE_IO_WRITE 0x04
+#define SOCAL_CQTYPE_IO_READ 0x05
+#define SOCAL_CQTYPE_UNSOLICITED 0x06
+#define SOCAL_CQTYPE_BYPASS_DEV 0x06
+#define SOCAL_CQTYPE_DIAG 0x07
+#define SOCAL_CQTYPE_OFFLINE 0x08
+#define SOCAL_CQTYPE_ADD_POOL 0x09
+#define SOCAL_CQTYPE_DELETE_POOL 0x0a
+#define SOCAL_CQTYPE_ADD_BUFFER 0x0b
+#define SOCAL_CQTYPE_ADD_POOL_BUFFER 0x0c
+#define SOCAL_CQTYPE_REQUEST_ABORT 0x0d
+#define SOCAL_CQTYPE_REQUEST_LIP 0x0e
+#define SOCAL_CQTYPE_REPORT_MAP 0x0f
+#define SOCAL_CQTYPE_RESPONSE 0x10
+#define SOCAL_CQTYPE_INLINE 0x20
+
+#define SOCAL_CQFLAGS_CONT 0x01
+#define SOCAL_CQFLAGS_FULL 0x02
+#define SOCAL_CQFLAGS_BADHDR 0x04
+#define SOCAL_CQFLAGS_BADPKT 0x08
+
+typedef struct {
+ socal_hdr shdr;
+ socal_data data[3];
+ fc_hdr fchdr;
+ u8 count;
+ u8 type;
+ u8 flags;
+ u8 seqno;
+} socal_req;
+
+#define SOCAL_OK 0
+#define SOCAL_P_RJT 2
+#define SOCAL_F_RJT 3
+#define SOCAL_P_BSY 4
+#define SOCAL_F_BSY 5
+#define SOCAL_ONLINE 0x10
+#define SOCAL_OFFLINE 0x11
+#define SOCAL_TIMEOUT 0x12
+#define SOCAL_OVERRUN 0x13
+#define SOCAL_ONLINE_LOOP 0x14
+#define SOCAL_OLD_PORT 0x15
+#define SOCAL_AL_PORT 0x16
+#define SOCAL_UNKOWN_CQ_TYPE 0x20
+#define SOCAL_BAD_SEG_CNT 0x21
+#define SOCAL_MAX_XCHG_EXCEEDED 0x22
+#define SOCAL_BAD_XID 0x23
+#define SOCAL_XCHG_BUSY 0x24
+#define SOCAL_BAD_POOL_ID 0x25
+#define SOCAL_INSUFFICIENT_CQES 0x26
+#define SOCAL_ALLOC_FAIL 0x27
+#define SOCAL_BAD_SID 0x28
+#define SOCAL_NO_SEG_INIT 0x29
+#define SOCAL_BAD_DID 0x2a
+#define SOCAL_ABORTED 0x30
+#define SOCAL_ABORT_FAILED 0x31
+
+typedef struct {
+ socal_hdr shdr;
+ u32 status;
+ socal_data data;
+ u8 xxx1[10];
+ u16 ncmds;
+ fc_hdr fchdr;
+ u8 count;
+ u8 type;
+ u8 flags;
+ u8 seqno;
+} socal_rsp;
+
+typedef struct {
+ socal_hdr shdr;
+ u8 xxx1[48];
+ u8 count;
+ u8 type;
+ u8 flags;
+ u8 seqno;
+} socal_cmdonly;
+
+#define SOCAL_DIAG_NOP 0x00
+#define SOCAL_DIAG_INT_LOOP 0x01
+#define SOCAL_DIAG_EXT_LOOP 0x02
+#define SOCAL_DIAG_REM_LOOP 0x03
+#define SOCAL_DIAG_XRAM_TEST 0x04
+#define SOCAL_DIAG_SOC_TEST 0x05
+#define SOCAL_DIAG_HCB_TEST 0x06
+#define SOCAL_DIAG_SOCLB_TEST 0x07
+#define SOCAL_DIAG_SRDSLB_TEST 0x08
+#define SOCAL_DIAG_EXTOE_TEST 0x09
+
+typedef struct {
+ socal_hdr shdr;
+ u32 cmd;
+ u8 xxx1[44];
+ u8 count;
+ u8 type;
+ u8 flags;
+ u8 seqno;
+} socal_diag_req;
+
+#define SOCAL_POOL_MASK_RCTL 0x800000
+#define SOCAL_POOL_MASK_DID 0x700000
+#define SOCAL_POOL_MASK_SID 0x070000
+#define SOCAL_POOL_MASK_TYPE 0x008000
+#define SOCAL_POOL_MASK_F_CTL 0x007000
+#define SOCAL_POOL_MASK_SEQ_ID 0x000800
+#define SOCAL_POOL_MASK_D_CTL 0x000400
+#define SOCAL_POOL_MASK_SEQ_CNT 0x000300
+#define SOCAL_POOL_MASK_OX_ID 0x0000f0
+#define SOCAL_POOL_MASK_PARAM 0x00000f
+
+typedef struct {
+ socal_hdr shdr;
+ u32 pool_id;
+ u32 header_mask;
+ u32 buf_size;
+ u32 entries;
+ u8 xxx1[8];
+ fc_hdr fchdr;
+ u8 count;
+ u8 type;
+ u8 flags;
+ u8 seqno;
+} socal_pool_req;
+
+/* }}} */
+
+/* Now our software structures and constants we use to drive the beast {{{ */
+
+#define SOCAL_CQ_REQ0_SIZE 4
+#define SOCAL_CQ_REQ1_SIZE 256
+#define SOCAL_CQ_RSP0_SIZE 8
+#define SOCAL_CQ_RSP1_SIZE 4
+#define SOCAL_CQ_RSP2_SIZE 4
+
+#define SOCAL_SOLICITED_RSP_Q 0
+#define SOCAL_SOLICITED_BAD_RSP_Q 1
+#define SOCAL_UNSOLICITED_RSP_Q 2
+
+struct socal;
+
+typedef struct {
+ /* This must come first */
+ fc_channel fc;
+ struct socal *s;
+ u16 flags;
+ u16 mask;
+} socal_port;
+
+typedef struct {
+ socal_hw_cq __iomem *hw_cq; /* Related XRAM cq */
+ socal_req *pool;
+ u8 in;
+ u8 out;
+ u8 last;
+ u8 seqno;
+} socal_cq;
+
+struct socal {
+ spinlock_t lock;
+ socal_port port[2]; /* Every SOCAL has one or two FC ports */
+ socal_cq req[4]; /* Request CQs */
+ socal_cq rsp[4]; /* Response CQs */
+ int socal_no;
+ void __iomem *regs;
+ void __iomem *xram;
+ void __iomem *eeprom;
+ fc_wwn wwn;
+ u32 imask; /* Our copy of regs->imask */
+ u32 cfg; /* Our copy of regs->cfg */
+ char serv_params[80];
+ struct socal *next;
+ int curr_port; /* Which port will have priority to fcp_queue_empty */
+
+ socal_req * req_cpu;
+ u32 req_dvma;
+};
+
+/* }}} */
+
+#endif /* !(__SOCAL_H) */