亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? lance.c

?? 內核是系統的心臟
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* lance.c: An AMD LANCE ethernet driver for linux. */
/*
    Written 1993 by Donald Becker.

    Copyright 1993 United States Government as represented by the
    Director, National Security Agency.  This software may be used and
    distributed according to the terms of the GNU Public License,
    incorporated herein by reference.

    This driver is for the Allied Telesis AT1500 and HP J2405A, and should work
    with most other LANCE-based bus-master (NE2100 clone) ethercards.

    The author may be reached as becker@super.org or
    C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
*/

static char *version = "lance.c:v0.14g 12/21/93 becker@super.org\n";

#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/ptrace.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/malloc.h>
#include <linux/interrupt.h>
#include <asm/bitops.h>
#include <asm/io.h>
#include <asm/dma.h>

#include "dev.h"
#include "eth.h"
#include "skbuff.h"
#include "arp.h"

#ifndef HAVE_PORTRESERVE
#define check_region(addr, size)	0
#define snarf_region(addr, size)	do ; while(0)
#endif

#ifndef HAVE_ALLOC_SKB
#define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
#define kfree_skbmem(buff, size) kfree_s(buff,size)
#endif

struct device *init_etherdev(struct device *dev, int sizeof_private,
			     unsigned long *mem_startp);

#ifdef LANCE_DEBUG
int lance_debug = LANCE_DEBUG;
#else
int lance_debug = 1;
#endif

#ifndef LANCE_DMA
#define LANCE_DMA	5
#endif

/*
  		Theory of Operation

I. Board Compatibility

This device driver is designed for the AMD 79C960, the "PCnet-ISA
single-chip ethernet controller for ISA".  This chip is used in a wide
variety of boards from vendors such as Allied Telesis, HP, Kingston,
and Boca.  This driver is also intended to work with older AMD 7990
designs, such as the NE1500 and NE2100.  For convenience, I use the name
LANCE to refer to either AMD chip.

II. Board-specific settings

The driver is designed to work the boards that use the faster
bus-master mode, rather than in shared memory mode.  (Only older designs
have on-board buffer memory needed to support the slower shared memory mode.)

Most boards have jumpered settings for the I/O base, IRQ line, and DMA channel.
This driver probes the likely base addresses, {0x300, 0x320, 0x340, 0x360}.
After the board is found it generates an DMA-timeout interrupt and uses
autoIRQ to find the IRQ line.  The DMA channel defaults to LANCE_DMA, or it
can be set with the low bits of the otherwise-unused dev->mem_start value.

The HP-J2405A board is an exception: with this board it's easy to read the
EEPROM-set values for the base, IRQ, and DMA.  Of course you must already
_know_ the base address, but that entry is for changing the EEPROM.

III. Driver operation

IIIa. Ring buffers
The LANCE uses ring buffers of Tx and Rx descriptors.  Each entry describes
the base and length of the data buffer, along with status bits.  The length
of these buffers is set by LANCE_LOG_{RX,TX}_BUFFERS, which is log_2() of
the buffer length (rather than being directly the buffer length) for
implementation ease.  The current values are 2 (Tx) and 4 (Rx), which leads to
ring sizes of 4 (Tx) and 16 (Rx).  Increasing the number of ring entries
needlessly uses extra space and reduces the chance that an upper layer will
be able to reorder queued Tx packets based on priority.  Decreasing the number
of entries makes it more difficult to achieve back-to-back packet transmission
and increases the chance that Rx ring will overflow.  (Consider the worst case
of receiving back-to-back minimum-sized packets.)

The LANCE has the capability to "chain" both Rx and Tx buffers, but this driver
statically allocates full-sized (slightly oversized -- PKT_BUF_SZ) buffers to
avoid the administrative overhead. For the Rx side this avoids dynamically
allocating full-sized buffers "just in case", at the expense of a
memory-to-memory data copy for each packet received.  For most systems this
is an good tradeoff: the Rx buffer will always be in low memory, the copy
is inexpensive, and it primes the cache for later packet processing.  For Tx
the buffers are only used when needed as low-memory bounce buffers.

IIIB. 16M memory limitations.
For the ISA bus master mode all structures used directly by the LANCE,
the initialization block, Rx and Tx rings, and data buffers, must be
accessable from the ISA bus, i.e. in the lower 16M of real memory.
This is a problem for current Linux kernels on >16M machines. The network
devices are initialized after memory initialization, and the kernel doles out
memory from the top of memory downward.  The current solution is to have a
special network initialization routine that's called before memory
initialization; this will eventually be generalized for all network devices.
As mentioned before, low-memory "bounce-buffers" are used when needed.

IIIC. Synchronization
The driver runs as two independent, single-threaded flows of control.  One
is the send-packet routine, which enforces single-threaded use by the
dev->tbusy flag.  The other thread is the interrupt handler, which is single
threaded by the hardware and other software.

The send packet thread has partial control over the Tx ring and 'dev->tbusy'
flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
queue slot is empty, it clears the tbusy flag when finished otherwise it sets
the 'lp->tx_full' flag.

The interrupt handler has exclusive control over the Rx ring and records stats
from the Tx ring.  (The Tx-done interrupt can't be selectively turned off, so
we can't avoid the interrupt overhead by having the Tx routine reap the Tx
stats.)  After reaping the stats, it marks the queue entry as empty by setting
the 'base' to zero.  Iff the 'lp->tx_full' flag is set, it clears both the
tx_full and tbusy flags.

*/

/* Set the number of Tx and Rx buffers, using Log_2(# buffers).
   Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
   That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4). */
#ifndef LANCE_LOG_TX_BUFFERS
#define LANCE_LOG_TX_BUFFERS 4
#define LANCE_LOG_RX_BUFFERS 4
#endif

#define TX_RING_SIZE		(1 << (LANCE_LOG_TX_BUFFERS))
#define TX_RING_MOD_MASK	(TX_RING_SIZE - 1)
#define TX_RING_LEN_BITS	((LANCE_LOG_TX_BUFFERS) << 29)

#define RX_RING_SIZE		(1 << (LANCE_LOG_RX_BUFFERS))
#define RX_RING_MOD_MASK	(RX_RING_SIZE - 1)
#define RX_RING_LEN_BITS	((LANCE_LOG_RX_BUFFERS) << 29)

#define PKT_BUF_SZ	1544

/* Offsets from base I/O address. */
#define LANCE_DATA 0x10
#define LANCE_ADDR 0x12
#define LANCE_RESET 0x14
#define LANCE_BUS_IF 0x16
#define LANCE_TOTAL_SIZE 0x18

/* The LANCE Rx and Tx ring descriptors. */
struct lance_rx_head {
    int	base;
    short buf_length;		/* This length is 2's complement (negative)! */
    short msg_length;		/* This length is "normal". */
};

struct lance_tx_head {
    int	  base;
    short length;		/* Length is 2's complement (negative)! */
    short misc;
};

/* The LANCE initialization block, described in databook. */
struct lance_init_block {
    unsigned short mode;	/* Pre-set mode (reg. 15) */
    unsigned char phys_addr[6];	/* Physical ethernet address */
    unsigned filter[2];		/* Multicast filter (unused). */
    /* Receive and transmit ring base, along with extra bits. */
    unsigned rx_ring;		/* Tx and Rx ring base pointers */
    unsigned tx_ring;
};

struct lance_private {
    char devname[8];
    /* These must aligned on 8-byte boundaries. */
    struct lance_rx_head rx_ring[RX_RING_SIZE];
    struct lance_tx_head tx_ring[TX_RING_SIZE];
    struct lance_init_block	init_block;
    long rx_buffs;		/* Address of Rx and Tx buffers. */
    /* Tx low-memory "bounce buffer" address. */
    char (*tx_bounce_buffs)[PKT_BUF_SZ];
    int	cur_rx, cur_tx;		/* The next free ring entry */
    int dirty_rx, dirty_tx;	/* The ring entries to be free()ed. */
    int dma;
    struct enet_statistics stats;
    char old_lance;
    int pad0, pad1;		/* Used for alignment */
};

unsigned long lance_probe1(short ioaddr, unsigned long mem_start);
static int lance_open(struct device *dev);
static void lance_init_ring(struct device *dev);
static int lance_start_xmit(struct sk_buff *skb, struct device *dev);
static int lance_rx(struct device *dev);
static void lance_interrupt(int reg_ptr);
static int lance_close(struct device *dev);
static struct enet_statistics *lance_get_stats(struct device *dev);
#ifdef HAVE_MULTICAST
static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
#endif



unsigned long lance_init(unsigned long mem_start, unsigned long mem_end)
{
    int *port, ports[] = {0x300, 0x320, 0x340, 0x360, 0};

    for (port = &ports[0]; *port; port++) {
	int ioaddr = *port;

	if (   check_region(ioaddr, LANCE_TOTAL_SIZE) == 0
	    && inb(ioaddr + 14) == 0x57
	    && inb(ioaddr + 15) == 0x57) {
	    mem_start = lance_probe1(ioaddr, mem_start);
	}
    }

    return mem_start;
}

unsigned long lance_probe1(short ioaddr, unsigned long mem_start)
{
    struct device *dev;
    struct lance_private *lp;
    int hpJ2405A = 0;
    int i, reset_val;

    hpJ2405A = (inb(ioaddr) == 0x08 && inb(ioaddr+1) == 0x00
		&& inb(ioaddr+2) == 0x09);

    /* Reset the LANCE.  */
    reset_val = inw(ioaddr+LANCE_RESET); /* Reset the LANCE */

    /* The Un-Reset needed is only needed for the real NE2100, and will
       confuse the HP board. */
    if (!hpJ2405A)
	outw(reset_val, ioaddr+LANCE_RESET);

    outw(0x0000, ioaddr+LANCE_ADDR); /* Switch to window 0 */
    if (inw(ioaddr+LANCE_DATA) != 0x0004)
	return mem_start;

    dev = init_etherdev(0, sizeof(struct lance_private)
			+ PKT_BUF_SZ*(RX_RING_SIZE + TX_RING_SIZE),
			&mem_start);

    printk("%s: LANCE at %#3x,", dev->name, ioaddr);

    /* There is a 16 byte station address PROM at the base address.
       The first six bytes are the station address. */
    for (i = 0; i < 6; i++)
	printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));

    dev->base_addr = ioaddr;
    snarf_region(ioaddr, LANCE_TOTAL_SIZE);

    /* Make certain the data structures used by the LANCE are aligned. */
    dev->priv = (void *)(((int)dev->priv + 7) & ~7);
    lp = (struct lance_private *)dev->priv;
    lp->rx_buffs = (long)dev->priv + sizeof(struct lance_private);
    lp->tx_bounce_buffs = (char (*)[PKT_BUF_SZ])
			   (lp->rx_buffs + PKT_BUF_SZ*RX_RING_SIZE);

#ifndef final_version
    /* This should never happen. */
    if ((int)(lp->rx_ring) & 0x07) {
	printk(" **ERROR** LANCE Rx and Tx rings not on even boundary.\n");
	return mem_start;
    }
#endif

    outw(88, ioaddr+LANCE_ADDR);
    lp->old_lance = (inw(ioaddr+LANCE_DATA) != 0x3003);

#if defined(notdef)
    printk(lp->old_lance ? " original LANCE (%04x)" : " PCnet-ISA LANCE (%04x)",
	   inw(ioaddr+LANCE_DATA));
#endif

    lp->init_block.mode = 0x0003;	/* Disable Rx and Tx. */
    for (i = 0; i < 6; i++)
	lp->init_block.phys_addr[i] = dev->dev_addr[i];
    lp->init_block.filter[0] = 0x00000000;
    lp->init_block.filter[1] = 0x00000000;
    lp->init_block.rx_ring = (int)lp->rx_ring | RX_RING_LEN_BITS;
    lp->init_block.tx_ring = (int)lp->tx_ring | TX_RING_LEN_BITS;

    outw(0x0001, ioaddr+LANCE_ADDR);
    outw((short) (int) &lp->init_block, ioaddr+LANCE_DATA);
    outw(0x0002, ioaddr+LANCE_ADDR);
    outw(((int)&lp->init_block) >> 16, ioaddr+LANCE_DATA);
    outw(0x0000, ioaddr+LANCE_ADDR);

    if (hpJ2405A) {
	char dma_tbl[4] = {3, 5, 6, 7};
	char irq_tbl[8] = {3, 4, 5, 9, 10, 11, 12, 15};
	short reset_val = inw(ioaddr+LANCE_RESET);
	dev->dma = dma_tbl[(reset_val >> 2) & 3];
	dev->irq = irq_tbl[(reset_val >> 4) & 7];
	printk(" HP J2405A IRQ %d DMA %d.\n", dev->irq, dev->dma);
    } else {
	/* The DMA channel may be passed in on this parameter. */
	if (dev->mem_start & 0x07)
	    dev->dma = dev->mem_start & 0x07;
	else if (dev->dma == 0)
	    dev->dma = LANCE_DMA;

	/* To auto-IRQ we enable the initialization-done and DMA err,
	   interrupts. For now we will always get a DMA error. */
	if (dev->irq < 2) {

	    autoirq_setup(0);

	    /* Trigger an initialization just for the interrupt. */
	    outw(0x0041, ioaddr+LANCE_DATA);

	    dev->irq = autoirq_report(1);
	    if (dev->irq)
		printk(", probed IRQ %d, fixed at DMA %d.\n",
		       dev->irq, dev->dma);
	    else {
		printk(", failed to detect IRQ line.\n");
		return mem_start;
	    }
	} else
	    printk(" assigned IRQ %d DMA %d.\n", dev->irq, dev->dma);
    }

    if (! lp->old_lance) {
	/* Turn on auto-select of media (10baseT or BNC) so that the user
	   can watch the LEDs even if the board isn't opened. */
	outw(0x0002, ioaddr+LANCE_ADDR);
	outw(0x0002, ioaddr+LANCE_BUS_IF);
    }

    if (lance_debug > 0)
	printk(version);

    /* The LANCE-specific entries in the device structure. */
    dev->open = &lance_open;
    dev->hard_start_xmit = &lance_start_xmit;
    dev->stop = &lance_close;
    dev->get_stats = &lance_get_stats;
#ifdef HAVE_MULTICAST
    dev->set_multicast_list = &set_multicast_list;
#endif

    return mem_start;
}


static int
lance_open(struct device *dev)
{
    struct lance_private *lp = (struct lance_private *)dev->priv;
    int ioaddr = dev->base_addr;
    int i;

    if (request_irq(dev->irq, &lance_interrupt)) {
	return -EAGAIN;
    }

    if (request_dma(dev->dma)) {
	free_irq(dev->irq);
	return -EAGAIN;
    }
    irq2dev_map[dev->irq] = dev;

    /* Reset the LANCE */
    inw(ioaddr+LANCE_RESET);

    /* The DMA controller is used as a no-operation slave, "cascade mode". */
    enable_dma(dev->dma);
    set_dma_mode(dev->dma, DMA_MODE_CASCADE);

    /* Un-Reset the LANCE, needed only for the NE2100. */
    if (lp->old_lance)
	outw(0, ioaddr+LANCE_RESET);

    if (! lp->old_lance) {
	/* This is 79C960-specific: Turn on auto-select of media (AUI, BNC). */
	outw(0x0002, ioaddr+LANCE_ADDR);
	outw(0x0002, ioaddr+LANCE_BUS_IF);
    }

    if (lance_debug > 1)
	printk("%s: lance_open() irq %d dma %d tx/rx rings %#x/%#x init %#x.\n",
	       dev->name, dev->irq, dev->dma, (int) lp->tx_ring, (int) lp->rx_ring,
	       (int) &lp->init_block);

    lance_init_ring(dev);
    /* Re-initialize the LANCE, and start it when done. */
    outw(0x0001, ioaddr+LANCE_ADDR);
    outw((short) (int) &lp->init_block, ioaddr+LANCE_DATA);
    outw(0x0002, ioaddr+LANCE_ADDR);
    outw(((int)&lp->init_block) >> 16, ioaddr+LANCE_DATA);

    outw(0x0004, ioaddr+LANCE_ADDR);
    outw(0x0d15, ioaddr+LANCE_DATA);

    outw(0x0000, ioaddr+LANCE_ADDR);
    outw(0x0001, ioaddr+LANCE_DATA);

    dev->tbusy = 0;
    dev->interrupt = 0;
    dev->start = 1;
    i = 0;
    while (i++ < 100)
	if (inw(ioaddr+LANCE_DATA) & 0x0100)
	    break;
    outw(0x0142, ioaddr+LANCE_DATA);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品视频在线视频| 精品视频123区在线观看| 91在线视频在线| 欧美视频一区二区三区| 欧美一区二区三区四区久久| 国产欧美1区2区3区| 亚洲免费色视频| 日本伊人午夜精品| av色综合久久天堂av综合| 精品国产成人系列| 亚洲欧美日韩人成在线播放| 天堂va蜜桃一区二区三区漫画版| 国产裸体歌舞团一区二区| 一本色道久久综合精品竹菊| 欧美人牲a欧美精品| 亚洲同性gay激情无套| 国产精品一线二线三线| 69堂国产成人免费视频| 亚洲精品大片www| 岛国精品在线观看| 日韩精品一区二区三区在线观看| 亚洲黄色av一区| 91女厕偷拍女厕偷拍高清| 国产人成亚洲第一网站在线播放| 人人狠狠综合久久亚洲| 欧美三级韩国三级日本一级| 亚洲精品国产视频| 色婷婷久久久亚洲一区二区三区| 最新日韩av在线| 大陆成人av片| 国产精品萝li| 在线精品视频免费播放| 亚洲一区二区中文在线| 日本国产一区二区| 亚洲欧美一区二区三区极速播放| 国产精品1区二区.| 国产精品入口麻豆原神| 99久久精品免费观看| 亚洲色图欧洲色图婷婷| 在线免费观看不卡av| 国产乱子伦一区二区三区国色天香| 欧美在线看片a免费观看| 午夜国产精品一区| 欧美成人video| 91啪九色porn原创视频在线观看| 亚洲成人av电影在线| 精品国产乱码久久久久久闺蜜| 国产成人免费在线| 一区二区三区四区高清精品免费观看| 91高清视频免费看| 麻豆国产一区二区| 亚洲日本va午夜在线影院| 91麻豆精品国产91久久久资源速度 | 欧洲精品一区二区| 日本不卡一区二区三区| 久久精品人人爽人人爽| 91黄色免费版| 国产一区二区0| 日韩高清在线观看| 国产精品久久久一区麻豆最新章节| 欧美日韩一级视频| 成人妖精视频yjsp地址| 蜜臀精品一区二区三区在线观看| 亚洲欧美色综合| 国产目拍亚洲精品99久久精品| 高清不卡在线观看| 亚洲视频一区二区在线观看| 欧美在线三级电影| 亚洲日本在线a| 亚洲成人在线网站| 久久99精品国产91久久来源| 成人激情电影免费在线观看| 色视频一区二区| 久久久久国产成人精品亚洲午夜| 在线国产电影不卡| eeuss鲁片一区二区三区| 国内精品久久久久影院薰衣草 | 粉嫩aⅴ一区二区三区四区五区| 偷拍与自拍一区| 亚洲第一电影网| 日产国产欧美视频一区精品| 日韩精品午夜视频| 亚洲成a人v欧美综合天堂| 亚洲最新视频在线播放| 亚洲另类春色校园小说| 一区二区三区免费| 午夜一区二区三区视频| 日韩成人一区二区三区在线观看| 亚洲女女做受ⅹxx高潮| 亚洲综合色视频| 精品亚洲免费视频| 国精品**一区二区三区在线蜜桃| aaa亚洲精品| 欧美xxxxx裸体时装秀| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 亚洲影院理伦片| 99riav一区二区三区| 日韩一区二区三区电影在线观看 | 日本欧美一区二区| 国产成a人亚洲精| 欧美日韩五月天| 国产欧美日韩综合| 捆绑变态av一区二区三区| 欧美综合天天夜夜久久| 国产午夜精品一区二区三区视频| 天天操天天色综合| 91国内精品野花午夜精品| 中文字幕一区二区三区视频| 国产资源在线一区| 日韩一级片在线播放| 亚洲自拍偷拍av| 欧美日韩中文字幕一区二区| 亚洲国产色一区| 国产成人午夜视频| 国产成人综合在线| 日韩欧美国产一区二区三区| 国产精品77777| 亚洲mv在线观看| 国产日产欧产精品推荐色| 欧美精品丝袜中出| 成人伦理片在线| 亚洲制服丝袜av| 欧美一区二区三区视频在线观看 | 亚洲一区二区欧美激情| 欧美日韩国产一区| 精品一区二区三区在线视频| 欧美精品一区二区在线观看| 国产69精品一区二区亚洲孕妇| 国产精品进线69影院| 欧美日韩精品欧美日韩精品| 卡一卡二国产精品| 亚洲天堂网中文字| 日韩一区二区免费在线电影 | 视频一区中文字幕| 欧美国产乱子伦| 91精品欧美福利在线观看| 国产精品一二三| 日韩高清电影一区| 亚洲图片欧美激情| 精品福利一二区| 欧美日韩mp4| 不卡一卡二卡三乱码免费网站| 亚洲乱码国产乱码精品精可以看| 精品久久久网站| 欧美精品 国产精品| 91免费观看视频在线| 国产精品一区二区在线播放| 免费欧美日韩国产三级电影| 亚洲激情中文1区| 国产精品久久久久久久蜜臀| 日韩欧美国产一区二区三区 | 亚洲黄色录像片| 亚洲桃色在线一区| 国产精品麻豆久久久| 久久精品一区八戒影视| 欧美精品一区二区三区在线| 欧美日韩国产免费一区二区| 欧美日韩免费一区二区三区视频| 91福利精品视频| 欧美视频精品在线观看| 欧美日韩一本到| 日韩视频国产视频| 欧美高清性hdvideosex| 91精品国产色综合久久ai换脸| 欧美人与禽zozo性伦| 欧美一区二区视频网站| 欧美电影免费观看高清完整版在线| 在线不卡中文字幕| 久久先锋影音av| 一区二区三区.www| 国产麻豆精品在线| 欧美亚洲一区二区在线观看| 久久蜜桃av一区精品变态类天堂| 综合在线观看色| 韩国精品免费视频| 欧美日韩精品一区视频| 国产精品毛片久久久久久久| 美国精品在线观看| 欧美网站一区二区| 国产精品免费免费| 亚洲一二三区不卡| 青青草一区二区三区| 国产传媒欧美日韩成人| av电影在线不卡| 91精品久久久久久久久99蜜臂| 久久综合狠狠综合| 一区二区三区国产精品| 成人中文字幕合集| 成人美女在线观看| 日韩一区国产二区欧美三区| 亚洲欧美一区二区三区久本道91| 日韩高清在线电影| 成人免费看的视频| 3atv一区二区三区| 一区二区三区日韩| 国产电影精品久久禁18| 精品少妇一区二区三区| 一区二区三区中文免费| 国产精品综合二区| 欧美一区二区三级|