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

📄 sb1000.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* sb1000.c: A General Instruments SB1000 driver for linux. *//*	Written 1998 by Franco Venturi.	Copyright 1998 by Franco Venturi.	Copyright 1994,1995 by Donald Becker.	Copyright 1993 United States Government as represented by the	Director, National Security Agency.	This driver is for the General Instruments SB1000 (internal SURFboard)	The author may be reached as fventuri@mediaone.net	This program is free software; you can redistribute it	and/or  modify it under  the terms of  the GNU General	Public  License as  published  by  the  Free  Software	Foundation;  either  version 2 of the License, or  (at	your option) any later version.	Changes:	981115 Steven Hirsch <shirsch@adelphia.net>	Linus changed the timer interface.  Should work on all recent	development kernels.	980608 Steven Hirsch <shirsch@adelphia.net>	Small changes to make it work with 2.1.x kernels. Hopefully,	nothing major will change before official release of Linux 2.2.		Merged with 2.2 - Alan Cox*/static char version[] = "sb1000.c:v1.1.2 6/01/98 (fventuri@mediaone.net)\n";#include <linux/module.h>#include <linux/version.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/interrupt.h>#include <linux/ptrace.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/malloc.h>#include <linux/ioport.h>#include <linux/netdevice.h>#include <linux/if_arp.h>#include <linux/skbuff.h>#include <linux/delay.h>	/* for udelay() */#include <asm/processor.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/uaccess.h>#include <linux/etherdevice.h>#include <linux/isapnp.h>/* for SIOGCM/SIOSCM stuff */#include <linux/if_cablemodem.h>#ifdef SB1000_DEBUGint sb1000_debug = SB1000_DEBUG;#elseint sb1000_debug = 1;#endifstatic const int SB1000_IO_EXTENT = 8;/* SB1000 Maximum Receive Unit */static const int SB1000_MRU = 1500; /* octects */#define NPIDS 4struct sb1000_private {	struct sk_buff *rx_skb[NPIDS];	short rx_dlen[NPIDS];	unsigned int rx_bytes;	unsigned int rx_frames;	short rx_error_count;	short rx_error_dpc_count;	unsigned char rx_session_id[NPIDS];	unsigned char rx_frame_id[NPIDS];	unsigned char rx_pkt_type[NPIDS];	struct net_device_stats stats;};/* prototypes for Linux interface */extern int sb1000_probe(struct net_device *dev);static int sb1000_open(struct net_device *dev);static int sb1000_dev_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd);static int sb1000_start_xmit(struct sk_buff *skb, struct net_device *dev);static void sb1000_interrupt(int irq, void *dev_id, struct pt_regs *regs);static struct net_device_stats *sb1000_stats(struct net_device *dev);static int sb1000_close(struct net_device *dev);/* SB1000 hardware routines to be used during open/configuration phases */static inline void nicedelay(unsigned long usecs);static inline int card_wait_for_busy_clear(const int ioaddr[],	const char* name);static inline int card_wait_for_ready(const int ioaddr[], const char* name,	unsigned char in[]);static inline int card_send_command(const int ioaddr[], const char* name,	const unsigned char out[], unsigned char in[]);/* SB1000 hardware routines to be used during frame rx interrupt */static inline int sb1000_wait_for_ready(const int ioaddr[], const char* name);static inline int sb1000_wait_for_ready_clear(const int ioaddr[],	const char* name);static inline void sb1000_send_command(const int ioaddr[], const char* name,	const unsigned char out[]);static inline void sb1000_read_status(const int ioaddr[], unsigned char in[]);static inline void sb1000_issue_read_command(const int ioaddr[],	const char* name);/* SB1000 commands for open/configuration */static inline int sb1000_reset(const int ioaddr[], const char* name);static inline int sb1000_check_CRC(const int ioaddr[], const char* name);static inline int sb1000_start_get_set_command(const int ioaddr[],	const char* name);static inline int sb1000_end_get_set_command(const int ioaddr[],	const char* name);static inline int sb1000_activate(const int ioaddr[], const char* name);static inline int sb1000_get_firmware_version(const int ioaddr[],	const char* name, unsigned char version[], int do_end);static inline int sb1000_get_frequency(const int ioaddr[], const char* name,	int* frequency);static inline int sb1000_set_frequency(const int ioaddr[], const char* name,	int frequency);static inline int sb1000_get_PIDs(const int ioaddr[], const char* name,	short PID[]);static inline int sb1000_set_PIDs(const int ioaddr[], const char* name,	const short PID[]);/* SB1000 commands for frame rx interrupt */static inline int sb1000_rx(struct net_device *dev);static inline void sb1000_error_dpc(struct net_device *dev);/* probe for SB1000 using Plug-n-Play mechanism */intsb1000_probe(struct net_device *dev){	unsigned short ioaddr[2], irq;	struct pci_dev *idev=NULL;	unsigned int serial_number;		while(1)	{		/*		 *	Find the card		 */		 		idev=isapnp_find_dev(NULL, ISAPNP_VENDOR('G','I','C'),			ISAPNP_FUNCTION(0x1000), idev);					/*		 *	No card		 */		 		if(idev==NULL)			return -ENODEV;					/*		 *	Bring it online		 */		 		idev->prepare(idev);		idev->activate(idev);				/*		 *	Ports free ?		 */		 		if(!idev->resource[0].start || check_region(idev->resource[0].start, 16))			continue;		if(!idev->resource[1].start || check_region(idev->resource[1].start, 16))			continue;				serial_number = idev->bus->serial;				ioaddr[0]=idev->resource[0].start;		ioaddr[1]=idev->resource[1].start;				irq = idev->irq;		/* check I/O base and IRQ */		if (dev->base_addr != 0 && dev->base_addr != ioaddr[0])			continue;		if (dev->rmem_end != 0 && dev->rmem_end != ioaddr[1])			continue;		if (dev->irq != 0 && dev->irq != irq)			continue;					/*		 *	Ok set it up.		 */		 		 		dev->base_addr = ioaddr[0];		/* rmem_end holds the second I/O address - fv */		dev->rmem_end = ioaddr[1];		dev->irq = irq;		if (sb1000_debug > 0)			printk(KERN_NOTICE "%s: sb1000 at (%#3.3lx,%#3.3lx), "				"S/N %#8.8x, IRQ %d.\n", dev->name, dev->base_addr,				dev->rmem_end, serial_number, dev->irq);		dev = init_etherdev(dev, 0);		if (!dev)			return -ENOMEM;		SET_MODULE_OWNER(dev);		/* Make up a SB1000-specific-data structure. */		dev->priv = kmalloc(sizeof(struct sb1000_private), GFP_KERNEL);		if (dev->priv == NULL)			return -ENOMEM;		memset(dev->priv, 0, sizeof(struct sb1000_private));		if (sb1000_debug > 0)			printk(KERN_NOTICE "%s", version);		/* The SB1000-specific entries in the device structure. */		dev->open = sb1000_open;		dev->do_ioctl = sb1000_dev_ioctl;		dev->hard_start_xmit = sb1000_start_xmit;		dev->stop = sb1000_close;		dev->get_stats = sb1000_stats;		/* Fill in the generic fields of the device structure. */		dev->change_mtu		= NULL;		dev->hard_header	= NULL;		dev->rebuild_header 	= NULL;		dev->set_mac_address 	= NULL;		dev->header_cache_update= NULL;		dev->type		= ARPHRD_ETHER;		dev->hard_header_len 	= 0;		dev->mtu		= 1500;		dev->addr_len		= ETH_ALEN;		/* hardware address is 0:0:serial_number */		dev->dev_addr[0] = 0;		dev->dev_addr[1] = 0;		dev->dev_addr[2] = serial_number >> 24 & 0xff;		dev->dev_addr[3] = serial_number >> 16 & 0xff;		dev->dev_addr[4] = serial_number >>  8 & 0xff;		dev->dev_addr[5] = serial_number >>  0 & 0xff;		dev->tx_queue_len	= 0;			/* New-style flags. */		dev->flags		= IFF_POINTOPOINT|IFF_NOARP;		/* Lock resources */		request_region(ioaddr[0], 16, dev->name);		request_region(ioaddr[1], 16, dev->name);		return 0;	}}/* * SB1000 hardware routines to be used during open/configuration phases */const int TimeOutJiffies = (int)(8.75 * HZ);static inline void nicedelay(unsigned long usecs){	current->state = TASK_INTERRUPTIBLE;	schedule_timeout(HZ);	return;}/* Card Wait For Busy Clear (cannot be used during an interrupt) */static inline intcard_wait_for_busy_clear(const int ioaddr[], const char* name){	unsigned char a;	unsigned long timeout;	a = inb(ioaddr[0] + 7);	timeout = jiffies + TimeOutJiffies;	while (a & 0x80 || a & 0x40) {		/* a little sleep */		current->state = TASK_INTERRUPTIBLE;		schedule_timeout(0);		a = inb(ioaddr[0] + 7);		if (jiffies >= timeout) {			printk(KERN_WARNING "%s: card_wait_for_busy_clear timeout\n",				name);			return -ETIME;		}	}	return 0;}/* Card Wait For Ready (cannot be used during an interrupt) */static inline intcard_wait_for_ready(const int ioaddr[], const char* name, unsigned char in[]){	unsigned char a;	unsigned long timeout;	a = inb(ioaddr[1] + 6);	timeout = jiffies + TimeOutJiffies;	while (a & 0x80 || !(a & 0x40)) {		/* a little sleep */		current->state = TASK_INTERRUPTIBLE;		schedule_timeout(0);		a = inb(ioaddr[1] + 6);		if (jiffies >= timeout) {			printk(KERN_WARNING "%s: card_wait_for_ready timeout\n",				name);			return -ETIME;		}	}	in[1] = inb(ioaddr[0] + 1);	in[2] = inb(ioaddr[0] + 2);	in[3] = inb(ioaddr[0] + 3);	in[4] = inb(ioaddr[0] + 4);	in[0] = inb(ioaddr[0] + 5);	in[6] = inb(ioaddr[0] + 6);	in[5] = inb(ioaddr[1] + 6);	return 0;}/* Card Send Command (cannot be used during an interrupt) */static inline intcard_send_command(const int ioaddr[], const char* name,	const unsigned char out[], unsigned char in[]){	int status, x;	if ((status = card_wait_for_busy_clear(ioaddr, name)))		return status;	outb(0xa0, ioaddr[0] + 6);	outb(out[2], ioaddr[0] + 1);	outb(out[3], ioaddr[0] + 2);	outb(out[4], ioaddr[0] + 3);	outb(out[5], ioaddr[0] + 4);	outb(out[1], ioaddr[0] + 5);	outb(0xa0, ioaddr[0] + 6);	outb(out[0], ioaddr[0] + 7);	if (out[0] != 0x20 && out[0] != 0x30) {		if ((status = card_wait_for_ready(ioaddr, name, in)))			return status;		inb(ioaddr[0] + 7);		if (sb1000_debug > 3)			printk(KERN_DEBUG "%s: card_send_command "				"out: %02x%02x%02x%02x%02x%02x  "				"in: %02x%02x%02x%02x%02x%02x%02x\n", name,				out[0], out[1], out[2], out[3], out[4], out[5],				in[0], in[1], in[2], in[3], in[4], in[5], in[6]);	} else {		if (sb1000_debug > 3)			printk(KERN_DEBUG "%s: card_send_command "				"out: %02x%02x%02x%02x%02x%02x\n", name,				out[0], out[1], out[2], out[3], out[4], out[5]);	}	if (out[1] == 0x1b) {		x = (out[2] == 0x02);	} else {		if (out[0] >= 0x80 && in[0] != (out[1] | 0x80))			return -EIO;	}	return 0;}/* * SB1000 hardware routines to be used during frame rx interrupt */const int Sb1000TimeOutJiffies = 7 * HZ;/* Card Wait For Ready (to be used during frame rx) */static inline intsb1000_wait_for_ready(const int ioaddr[], const char* name){	unsigned long timeout;	timeout = jiffies + Sb1000TimeOutJiffies;	while (inb(ioaddr[1] + 6) & 0x80) {		if (jiffies >= timeout) {			printk(KERN_WARNING "%s: sb1000_wait_for_ready timeout\n",				name);			return -ETIME;		}	}	timeout = jiffies + Sb1000TimeOutJiffies;	while (!(inb(ioaddr[1] + 6) & 0x40)) {		if (jiffies >= timeout) {			printk(KERN_WARNING "%s: sb1000_wait_for_ready timeout\n",				name);			return -ETIME;		}	}	inb(ioaddr[0] + 7);	return 0;}/* Card Wait For Ready Clear (to be used during frame rx) */static inline intsb1000_wait_for_ready_clear(const int ioaddr[], const char* name){	unsigned long timeout;	timeout = jiffies + Sb1000TimeOutJiffies;	while (inb(ioaddr[1] + 6) & 0x80) {		if (jiffies >= timeout) {			printk(KERN_WARNING "%s: sb1000_wait_for_ready_clear timeout\n",				name);

⌨️ 快捷键说明

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