📄 soc.c
字号:
/* 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/malloc.h>#include <linux/string.h>#include <linux/init.h>#include <asm/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/auxio.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 void inline soc_solicited (struct soc *s){ fc_hdr fchdr; soc_rsp *hwrsp; soc_cq *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 *) (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 *)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 void inline 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 void inline soc_unsolicited (struct soc *s){ soc_rsp *hwrsp, *hwrspc; soc_cq *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 *) (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 *)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 *)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 void 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(&io_request_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(&io_request_lock, flags);}#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 *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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -