📄 d_link.c
字号:
{
int transmit_from;
int len;
int tickssofar;
unsigned char *buffer = skb->data;
/*
* If some higher layer thinks we've missed a
* tx-done interrupt we are passed NULL.
* Caution: dev_tint() handles the cli()/sti() itself.
*/
if (skb == NULL) {
dev_tint(dev);
return 0;
}
/* For ethernet, fill in the header (hardware addresses) with an arp. */
if (!skb->arp)
if(dev->rebuild_header(skb->data, dev)) {
skb->dev = dev;
arp_queue (skb);
return 0;
}
skb->arp = 1;
if (free_tx_pages <= 0) { /* Do timeouts, to avoid hangs. */
tickssofar = jiffies - dev->trans_start;
if (tickssofar < 5)
return 1;
/* else */
printk("%s: transmit timed out (%d), %s?\n",
dev->name,
tickssofar,
"network cable problem"
);
/* Restart the adapter. */
adapter_init(dev);
}
/* Start real output */
PRINTK(("d_link_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages));
if ((len = skb->len) < RUNT)
len = RUNT;
cli();
select_nic();
tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len;
tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES; /* Next free tx page */
d_link_setup_address(transmit_from, RW_ADDR);
for ( ; len > 0; --len, ++buffer)
d_link_put_byte(*buffer);
if (free_tx_pages-- == TX_PAGES) { /* No transmission going on */
dev->trans_start = jiffies;
dev->tbusy = 0; /* allow more packets into adapter */
/* Send page and generate an interrupt */
d_link_setup_address(transmit_from, TX_ADDR);
d_link_put_command(TX_ENABLE);
}
else {
dev->tbusy = !free_tx_pages;
select_prn();
}
sti(); /* interrupts back on */
if (skb->free)
kfree_skb (skb, FREE_WRITE);
return 0;
}
/*
* The typical workload of the driver:
* Handle the network interface interrupts.
*/
static void
d_link_interrupt(int reg_ptr)
{
int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
struct device *dev = irq2dev_map[irq];
unsigned char irq_status;
int retrig = 0;
int boguscount = 0;
/* This might just as well be deleted now, no crummy drivers present :-) */
if ((dev == NULL) || (dev->start == 0) || (D_LINK_IRQ != irq)) {
printk("%s: bogus interrupt %d\n", dev?dev->name:"DE-600", irq);
return;
}
dev->interrupt = 1;
select_nic();
irq_status = d_link_read_status(dev);
do {
PRINTK(("d_link_interrupt (%2.2X)\n", irq_status));
if (irq_status & RX_GOOD)
d_link_rx_intr(dev);
else if (!(irq_status & RX_BUSY))
d_link_put_command(RX_ENABLE);
/* Any transmission in progress? */
if (free_tx_pages < TX_PAGES)
retrig = d_link_tx_intr(dev, irq_status);
else
retrig = 0;
irq_status = d_link_read_status(dev);
} while ( (irq_status & RX_GOOD) || ((++boguscount < 10) && retrig) );
/*
* Yeah, it _looks_ like busy waiting, smells like busy waiting
* and I know it's not PC, but please, it will only occur once
* in a while and then only for a loop or so (< 1ms for sure!)
*/
/* Enable adapter interrupts */
dev->interrupt = 0;
select_prn();
if (retrig)
trigger_interrupt(dev);
sti();
return;
}
static int
d_link_tx_intr(struct device *dev, int irq_status)
{
/*
* Returns 1 if tx still not done
*/
mark_bh(INET_BH);
/* Check if current transmission is done yet */
if (irq_status & TX_BUSY)
return 1; /* tx not done, try again */
/* else */
/* If last transmission OK then bump fifo index */
if (!(irq_status & TX_FAILED16)) {
tx_fifo_out = (tx_fifo_out + 1) % TX_PAGES;
++free_tx_pages;
((struct netstats *)(dev->priv))->tx_packets++;
dev->tbusy = 0;
}
/* More to send, or resend last packet? */
if ((free_tx_pages < TX_PAGES) || (irq_status & TX_FAILED16)) {
dev->trans_start = jiffies;
d_link_setup_address(tx_fifo[tx_fifo_out], TX_ADDR);
d_link_put_command(TX_ENABLE);
return 1;
}
/* else */
return 0;
}
/*
* We have a good packet, get it out of the adapter.
*/
static void
d_link_rx_intr(struct device *dev)
{
struct sk_buff *skb;
int i;
int read_from;
int size;
int sksize;
register unsigned char *buffer;
cli();
/* Get size of received packet */
size = d_link_read_byte(RX_LEN, dev); /* low byte */
size += (d_link_read_byte(RX_LEN, dev) << 8); /* high byte */
size -= 4; /* Ignore trailing 4 CRC-bytes */
/* Tell adapter where to store next incoming packet, enable receiver */
read_from = rx_page_adr();
next_rx_page();
d_link_put_command(RX_ENABLE);
sti();
if ((size < 32) || (size > 1535))
printk("%s: Bogus packet size %d.\n", dev->name, size);
sksize = sizeof(struct sk_buff) + size;
skb = alloc_skb(sksize, GFP_ATOMIC);
sti();
if (skb == NULL) {
printk("%s: Couldn't allocate a sk_buff of size %d.\n",
dev->name, sksize);
return;
}
/* else */
skb->lock = 0;
skb->mem_len = sksize;
skb->mem_addr = skb;
/* 'skb->data' points to the start of sk_buff data area. */
buffer = skb->data;
/* copy the packet into the buffer */
d_link_setup_address(read_from, RW_ADDR);
for (i = size; i > 0; --i, ++buffer)
*buffer = d_link_read_byte(READ_DATA, dev);
((struct netstats *)(dev->priv))->rx_packets++; /* count all receives */
if (dev_rint((unsigned char *)skb, size, IN_SKBUFF, dev))
printk("%s: receive buffers full.\n", dev->name);
/*
* If any worth-while packets have been received, dev_rint()
* has done a mark_bh(INET_BH) for us and will work on them
* when we get to the bottom-half routine.
*/
}
int
d_link_init(struct device *dev)
{
int i;
printk("%s: D-Link DE-600 pocket adapter", dev->name);
/* Alpha testers must have the version number to report bugs. */
if (d_link_debug > 1)
printk(version);
/* probe for adapter */
rx_page = 0;
select_nic();
(void)d_link_read_status(dev);
d_link_put_command(RESET);
d_link_put_command(STOP_RESET);
if (d_link_read_status(dev) & 0xf0) {
printk(": not at I/O %#3x.\n", DATA_PORT);
return ENODEV;
}
/*
* Maybe we found one,
* have to check if it is a D-Link DE-600 adapter...
*/
/* Get the adapter ethernet address from the ROM */
d_link_setup_address(NODE_ADDRESS, RW_ADDR);
for (i = 0; i < ETH_ALEN; i++) {
dev->dev_addr[i] = d_link_read_byte(READ_DATA, dev);
dev->broadcast[i] = 0xff;
}
/* Check magic code */
if ((dev->dev_addr[1] == 0xde) && (dev->dev_addr[2] == 0x15)) {
/* OK, install real address */
dev->dev_addr[0] = 0x00;
dev->dev_addr[1] = 0x80;
dev->dev_addr[2] = 0xc8;
dev->dev_addr[3] &= 0x0f;
dev->dev_addr[3] |= 0x70;
} else {
printk(" not identified in the printer port\n");
return ENODEV;
}
printk(", Ethernet Address: %2.2X", dev->dev_addr[0]);
for (i = 1; i < ETH_ALEN; i++)
printk(":%2.2X",dev->dev_addr[i]);
printk("\n");
/* Initialize the device structure. */
dev->priv = kmalloc(sizeof(struct netstats), GFP_KERNEL);
memset(dev->priv, 0, sizeof(struct netstats));
for (i = 0; i < DEV_NUMBUFFS; i++)
dev->buffs[i] = NULL;
dev->get_stats = get_stats;
dev->hard_header = eth_header;
dev->add_arp = eth_add_arp;
dev->queue_xmit = dev_queue_xmit;
dev->rebuild_header = eth_rebuild_header;
dev->type_trans = eth_type_trans;
dev->open = d_link_open;
dev->stop = d_link_close;
dev->hard_start_xmit = &d_link_start_xmit;
/* These are ethernet specific. */
dev->type = ARPHRD_ETHER;
dev->hard_header_len = ETH_HLEN;
dev->mtu = 1500; /* eth_mtu */
dev->addr_len = ETH_ALEN;
/* New-style flags. */
dev->flags = IFF_BROADCAST;
dev->family = AF_INET;
dev->pa_addr = 0;
dev->pa_brdaddr = 0;
dev->pa_mask = 0;
dev->pa_alen = sizeof(unsigned long);
select_prn();
return 0;
}
static void
adapter_init(struct device *dev)
{
int i;
cli();
dev->tbusy = 0; /* Transmit busy... */
dev->interrupt = 0;
dev->start = 1;
select_nic();
rx_page = 0; /* used by RESET */
d_link_put_command(RESET);
d_link_put_command(STOP_RESET);
tx_fifo_in = 0;
tx_fifo_out = 0;
free_tx_pages = TX_PAGES;
/* set the ether address. */
d_link_setup_address(NODE_ADDRESS, RW_ADDR);
for (i = 0; i < ETH_ALEN; i++)
d_link_put_byte(dev->dev_addr[i]);
/* where to start saving incoming packets */
rx_page = RX_BP | RX_BASE_PAGE;
d_link_setup_address(MEM_4K, RW_ADDR);
/* Enable receiver */
d_link_put_command(RX_ENABLE);
select_prn();
sti();
}
#define D_LINK_MIN_WINDOW 1024
#define D_LINK_MAX_WINDOW 2048
#define D_LINK_TCP_WINDOW_DIFF 1024
/*
* Copied from sock.c
*
* Sets a lower max receive window in order to achieve <= 2
* packets arriving at the adapter in fast succession.
* (No way that a DE-600 can cope with an ethernet saturated with its packets :-)
*
* Since there are only 2 receive buffers in the DE-600
* and it takes some time to copy from the adapter,
* this is absolutely necessary for any TCP performance whatsoever!
*
*/
#define min(a,b) ((a)<(b)?(a):(b))
static unsigned long
d_link_rspace(struct sock *sk)
{
int amt;
if (sk != NULL) {
/*
* Hack! You might want to play with commenting away the following line,
* if you know what you do!
*/
sk->max_unacked = D_LINK_MAX_WINDOW - D_LINK_TCP_WINDOW_DIFF;
if (sk->rmem_alloc >= SK_RMEM_MAX-2*D_LINK_MIN_WINDOW) return(0);
amt = min((SK_RMEM_MAX-sk->rmem_alloc)/2-D_LINK_MIN_WINDOW, D_LINK_MAX_WINDOW);
if (amt < 0) return(0);
return(amt);
}
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -