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

📄 he.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* $Id: he.c,v 1.18 2003/05/06 22:57:15 chas Exp $ *//*  he.c  ForeRunnerHE ATM Adapter driver for ATM on Linux  Copyright (C) 1999-2001  Naval Research Laboratory  This library is free software; you can redistribute it and/or  modify it under the terms of the GNU Lesser General Public  License as published by the Free Software Foundation; either  version 2.1 of the License, or (at your option) any later version.  This library is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public  License along with this library; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//*  he.c  ForeRunnerHE ATM Adapter driver for ATM on Linux  Copyright (C) 1999-2001  Naval Research Laboratory  Permission to use, copy, modify and distribute this software and its  documentation is hereby granted, provided that both the copyright  notice and this permission notice appear in all copies of the software,  derivative works or modified versions, and any portions thereof, and  that both notices appear in supporting documentation.  NRL ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND  DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER  RESULTING FROM THE USE OF THIS SOFTWARE.  This driver was written using the "Programmer's Reference Manual for  ForeRunnerHE(tm)", MANU0361-01 - Rev. A, 08/21/98.  AUTHORS:	chas williams <chas@cmf.nrl.navy.mil>	eric kinzie <ekinzie@cmf.nrl.navy.mil>  NOTES:	4096 supported 'connections'	group 0 is used for all traffic	interrupt queue 0 is used for all interrupts	aal0 support (based on work from ulrich.u.muller@nokia.com) */#include <linux/module.h>#include <linux/kernel.h>#include <linux/skbuff.h>#include <linux/pci.h>#include <linux/errno.h>#include <linux/types.h>#include <linux/string.h>#include <linux/delay.h>#include <linux/init.h>#include <linux/mm.h>#include <linux/sched.h>#include <linux/timer.h>#include <linux/interrupt.h>#include <linux/dma-mapping.h>#include <asm/io.h>#include <asm/byteorder.h>#include <asm/uaccess.h>#include <linux/atmdev.h>#include <linux/atm.h>#include <linux/sonet.h>#define USE_TASKLET#undef USE_SCATTERGATHER#undef USE_CHECKSUM_HW			/* still confused about this */#define USE_RBPS#undef USE_RBPS_POOL			/* if memory is tight try this */#undef USE_RBPL_POOL			/* if memory is tight try this */#define USE_TPD_POOL/* #undef CONFIG_ATM_HE_USE_SUNI *//* #undef HE_DEBUG */#include "he.h"#include "suni.h"#include <linux/atm_he.h>#define hprintk(fmt,args...)	printk(KERN_ERR DEV_LABEL "%d: " fmt, he_dev->number , ##args)#ifdef HE_DEBUG#define HPRINTK(fmt,args...)	printk(KERN_DEBUG DEV_LABEL "%d: " fmt, he_dev->number , ##args)#else /* !HE_DEBUG */#define HPRINTK(fmt,args...)	do { } while (0)#endif /* HE_DEBUG *//* version definition */static char *version = "$Id: he.c,v 1.18 2003/05/06 22:57:15 chas Exp $";/* declarations */static int he_open(struct atm_vcc *vcc);static void he_close(struct atm_vcc *vcc);static int he_send(struct atm_vcc *vcc, struct sk_buff *skb);static int he_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg);static irqreturn_t he_irq_handler(int irq, void *dev_id);static void he_tasklet(unsigned long data);static int he_proc_read(struct atm_dev *dev,loff_t *pos,char *page);static int he_start(struct atm_dev *dev);static void he_stop(struct he_dev *dev);static void he_phy_put(struct atm_dev *, unsigned char, unsigned long);static unsigned char he_phy_get(struct atm_dev *, unsigned long);static u8 read_prom_byte(struct he_dev *he_dev, int addr);/* globals */static struct he_dev *he_devs;static int disable64;static short nvpibits = -1;static short nvcibits = -1;static short rx_skb_reserve = 16;static int irq_coalesce = 1;static int sdh = 0;/* Read from EEPROM = 0000 0011b */static unsigned int readtab[] = {	CS_HIGH | CLK_HIGH,	CS_LOW | CLK_LOW,	CLK_HIGH,               /* 0 */	CLK_LOW,	CLK_HIGH,               /* 0 */	CLK_LOW,	CLK_HIGH,               /* 0 */	CLK_LOW,	CLK_HIGH,               /* 0 */	CLK_LOW,	CLK_HIGH,               /* 0 */	CLK_LOW,	CLK_HIGH,               /* 0 */	CLK_LOW | SI_HIGH,	CLK_HIGH | SI_HIGH,     /* 1 */	CLK_LOW | SI_HIGH,	CLK_HIGH | SI_HIGH      /* 1 */};      /* Clock to read from/write to the EEPROM */static unsigned int clocktab[] = {	CLK_LOW,	CLK_HIGH,	CLK_LOW,	CLK_HIGH,	CLK_LOW,	CLK_HIGH,	CLK_LOW,	CLK_HIGH,	CLK_LOW,	CLK_HIGH,	CLK_LOW,	CLK_HIGH,	CLK_LOW,	CLK_HIGH,	CLK_LOW,	CLK_HIGH,	CLK_LOW};     static struct atmdev_ops he_ops ={	.open =		he_open,	.close =	he_close,		.ioctl =	he_ioctl,		.send =		he_send,	.phy_put =	he_phy_put,	.phy_get =	he_phy_get,	.proc_read =	he_proc_read,	.owner =	THIS_MODULE};#define he_writel(dev, val, reg)	do { writel(val, (dev)->membase + (reg)); wmb(); } while (0)#define he_readl(dev, reg)		readl((dev)->membase + (reg))/* section 2.12 connection memory access */static __inline__ voidhe_writel_internal(struct he_dev *he_dev, unsigned val, unsigned addr,								unsigned flags){	he_writel(he_dev, val, CON_DAT);	(void) he_readl(he_dev, CON_DAT);		/* flush posted writes */	he_writel(he_dev, flags | CON_CTL_WRITE | CON_CTL_ADDR(addr), CON_CTL);	while (he_readl(he_dev, CON_CTL) & CON_CTL_BUSY);}#define he_writel_rcm(dev, val, reg) 				\			he_writel_internal(dev, val, reg, CON_CTL_RCM)#define he_writel_tcm(dev, val, reg) 				\			he_writel_internal(dev, val, reg, CON_CTL_TCM)#define he_writel_mbox(dev, val, reg) 				\			he_writel_internal(dev, val, reg, CON_CTL_MBOX)static unsignedhe_readl_internal(struct he_dev *he_dev, unsigned addr, unsigned flags){	he_writel(he_dev, flags | CON_CTL_READ | CON_CTL_ADDR(addr), CON_CTL);	while (he_readl(he_dev, CON_CTL) & CON_CTL_BUSY);	return he_readl(he_dev, CON_DAT);}#define he_readl_rcm(dev, reg) \			he_readl_internal(dev, reg, CON_CTL_RCM)#define he_readl_tcm(dev, reg) \			he_readl_internal(dev, reg, CON_CTL_TCM)#define he_readl_mbox(dev, reg) \			he_readl_internal(dev, reg, CON_CTL_MBOX)/* figure 2.2 connection id */#define he_mkcid(dev, vpi, vci)		(((vpi << (dev)->vcibits) | vci) & 0x1fff)/* 2.5.1 per connection transmit state registers */#define he_writel_tsr0(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 0)#define he_readl_tsr0(dev, cid) \		he_readl_tcm(dev, CONFIG_TSRA | (cid << 3) | 0)#define he_writel_tsr1(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 1)#define he_writel_tsr2(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 2)#define he_writel_tsr3(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 3)#define he_writel_tsr4(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 4)	/* from page 2-20	 *	 * NOTE While the transmit connection is active, bits 23 through 0	 *      of this register must not be written by the host.  Byte	 *      enables should be used during normal operation when writing	 *      the most significant byte.	 */#define he_writel_tsr4_upper(dev, val, cid) \		he_writel_internal(dev, val, CONFIG_TSRA | (cid << 3) | 4, \							CON_CTL_TCM \							| CON_BYTE_DISABLE_2 \							| CON_BYTE_DISABLE_1 \							| CON_BYTE_DISABLE_0)#define he_readl_tsr4(dev, cid) \		he_readl_tcm(dev, CONFIG_TSRA | (cid << 3) | 4)#define he_writel_tsr5(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 5)#define he_writel_tsr6(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 6)#define he_writel_tsr7(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 7)#define he_writel_tsr8(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 0)#define he_writel_tsr9(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 1)#define he_writel_tsr10(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 2)#define he_writel_tsr11(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 3)#define he_writel_tsr12(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRC | (cid << 1) | 0)#define he_writel_tsr13(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRC | (cid << 1) | 1)#define he_writel_tsr14(dev, val, cid) \		he_writel_tcm(dev, val, CONFIG_TSRD | cid)#define he_writel_tsr14_upper(dev, val, cid) \		he_writel_internal(dev, val, CONFIG_TSRD | cid, \							CON_CTL_TCM \							| CON_BYTE_DISABLE_2 \							| CON_BYTE_DISABLE_1 \							| CON_BYTE_DISABLE_0)/* 2.7.1 per connection receive state registers */#define he_writel_rsr0(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 0)#define he_readl_rsr0(dev, cid) \		he_readl_rcm(dev, 0x00000 | (cid << 3) | 0)#define he_writel_rsr1(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 1)#define he_writel_rsr2(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 2)#define he_writel_rsr3(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 3)#define he_writel_rsr4(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 4)#define he_writel_rsr5(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 5)#define he_writel_rsr6(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 6)#define he_writel_rsr7(dev, val, cid) \		he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 7)static __inline__ struct atm_vcc*__find_vcc(struct he_dev *he_dev, unsigned cid){	struct hlist_head *head;	struct atm_vcc *vcc;	struct hlist_node *node;	struct sock *s;	short vpi;	int vci;	vpi = cid >> he_dev->vcibits;	vci = cid & ((1 << he_dev->vcibits) - 1);	head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];	sk_for_each(s, node, head) {		vcc = atm_sk(s);		if (vcc->dev == he_dev->atm_dev &&		    vcc->vci == vci && vcc->vpi == vpi &&		    vcc->qos.rxtp.traffic_class != ATM_NONE) {				return vcc;		}	}	return NULL;}static int __devinithe_init_one(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent){	struct atm_dev *atm_dev = NULL;	struct he_dev *he_dev = NULL;	int err = 0;	printk(KERN_INFO "he: %s\n", version);	if (pci_enable_device(pci_dev))		return -EIO;	if (pci_set_dma_mask(pci_dev, DMA_32BIT_MASK) != 0) {		printk(KERN_WARNING "he: no suitable dma available\n");		err = -EIO;		goto init_one_failure;	}	atm_dev = atm_dev_register(DEV_LABEL, &he_ops, -1, NULL);	if (!atm_dev) {		err = -ENODEV;		goto init_one_failure;	}	pci_set_drvdata(pci_dev, atm_dev);	he_dev = kzalloc(sizeof(struct he_dev),							GFP_KERNEL);	if (!he_dev) {		err = -ENOMEM;		goto init_one_failure;	}	he_dev->pci_dev = pci_dev;	he_dev->atm_dev = atm_dev;	he_dev->atm_dev->dev_data = he_dev;	atm_dev->dev_data = he_dev;	he_dev->number = atm_dev->number;#ifdef USE_TASKLET	tasklet_init(&he_dev->tasklet, he_tasklet, (unsigned long) he_dev);#endif	spin_lock_init(&he_dev->global_lock);	if (he_start(atm_dev)) {		he_stop(he_dev);		err = -ENODEV;		goto init_one_failure;	}	he_dev->next = NULL;	if (he_devs)		he_dev->next = he_devs;	he_devs = he_dev;	return 0;init_one_failure:	if (atm_dev)		atm_dev_deregister(atm_dev);	kfree(he_dev);	pci_disable_device(pci_dev);	return err;}static void __devexithe_remove_one (struct pci_dev *pci_dev){	struct atm_dev *atm_dev;	struct he_dev *he_dev;	atm_dev = pci_get_drvdata(pci_dev);	he_dev = HE_DEV(atm_dev);	/* need to remove from he_devs */	he_stop(he_dev);	atm_dev_deregister(atm_dev);	kfree(he_dev);	pci_set_drvdata(pci_dev, NULL);	pci_disable_device(pci_dev);}static unsignedrate_to_atmf(unsigned rate)		/* cps to atm forum format */{#define NONZERO (1 << 14)	unsigned exp = 0;	if (rate == 0)		return 0;	rate <<= 9;	while (rate > 0x3ff) {		++exp;		rate >>= 1;	}	return (NONZERO | (exp << 9) | (rate & 0x1ff));}static void __devinithe_init_rx_lbfp0(struct he_dev *he_dev){	unsigned i, lbm_offset, lbufd_index, lbuf_addr, lbuf_count;	unsigned lbufs_per_row = he_dev->cells_per_row / he_dev->cells_per_lbuf;	unsigned lbuf_bufsize = he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD;	unsigned row_offset = he_dev->r0_startrow * he_dev->bytes_per_row;		lbufd_index = 0;	lbm_offset = he_readl(he_dev, RCMLBM_BA);	he_writel(he_dev, lbufd_index, RLBF0_H);	for (i = 0, lbuf_count = 0; i < he_dev->r0_numbuffs; ++i) {		lbufd_index += 2;		lbuf_addr = (row_offset + (lbuf_count * lbuf_bufsize)) / 32;		he_writel_rcm(he_dev, lbuf_addr, lbm_offset);

⌨️ 快捷键说明

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