⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socal.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 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 <asm/system.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 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, unsigned long 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(unsigned long 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_UCODEstatic void socal_bzero(unsigned long xram, int size){	while (size) {		sbus_writel(0, xram);		xram += sizeof(u32);		size -= sizeof(u32);	}}#endifstatic 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 void inline 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 void inline 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 void inline 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 void 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(&io_request_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(&io_request_lock, flags);}#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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -