📄 de600.c
字号:
} /* Start real output */ PRINTK(("de600_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 */#ifdef CHECK_LOST_DE600 /* This costs about 40 instructions per packet... */ de600_setup_address(NODE_ADDRESS, RW_ADDR); de600_read_byte(READ_DATA, dev); if (was_down || (de600_read_byte(READ_DATA, dev) != 0xde)) { if (adapter_init(dev)) { sti(); return 1; } }#endif de600_setup_address(transmit_from, RW_ADDR); for ( ; len > 0; --len, ++buffer) de600_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 a faked interrupt */ de600_setup_address(transmit_from, TX_ADDR); de600_put_command(TX_ENABLE); } else { dev->tbusy = !free_tx_pages; select_prn(); } sti(); /* interrupts back on */#ifdef FAKE_SMALL_MAX /* This will "patch" the socket TCP proto at an early moment */ if (skb->sk && (skb->sk->protocol == IPPROTO_TCP) && (skb->sk->prot->rspace != &de600_rspace)) skb->sk->prot->rspace = de600_rspace; /* Ugh! */#endif dev_kfree_skb (skb); return 0;}/* * The typical workload of the driver: * Handle the network interface interrupts. */static voidde600_interrupt(int irq, void *dev_id, struct pt_regs * regs){ struct device *dev = dev_id; byte 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) || (DE600_IRQ != irq)) { printk("%s: bogus interrupt %d\n", dev?dev->name:"DE-600", irq); return; } dev->interrupt = 1; select_nic(); irq_status = de600_read_status(dev); do { PRINTK(("de600_interrupt (%02X)\n", irq_status)); if (irq_status & RX_GOOD) de600_rx_intr(dev); else if (!(irq_status & RX_BUSY)) de600_put_command(RX_ENABLE); /* Any transmission in progress? */ if (free_tx_pages < TX_PAGES) retrig = de600_tx_intr(dev, irq_status); else retrig = 0; irq_status = de600_read_status(dev); } while ( (irq_status & RX_GOOD) || ((++boguscount < 100) && 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 intde600_tx_intr(struct device *dev, int irq_status){ /* * Returns 1 if tx still not done */ mark_bh(NET_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 net_device_stats *)(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; de600_setup_address(tx_fifo[tx_fifo_out], TX_ADDR); de600_put_command(TX_ENABLE); return 1; } /* else */ return 0;}/* * We have a good packet, get it out of the adapter. */static voidde600_rx_intr(struct device *dev){ struct sk_buff *skb; int i; int read_from; int size; register unsigned char *buffer; cli(); /* Get size of received packet */ size = de600_read_byte(RX_LEN, dev); /* low byte */ size += (de600_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(); de600_put_command(RX_ENABLE); sti(); if ((size < 32) || (size > 1535)) { printk("%s: Bogus packet size %d.\n", dev->name, size); if (size > 10000) adapter_init(dev); return; } skb = dev_alloc_skb(size+2); sti(); if (skb == NULL) { printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, size); return; } /* else */ skb->dev = dev; skb_reserve(skb,2); /* Align */ /* 'skb->data' points to the start of sk_buff data area. */ buffer = skb_put(skb,size); /* copy the packet into the buffer */ de600_setup_address(read_from, RW_ADDR); for (i = size; i > 0; --i, ++buffer) *buffer = de600_read_byte(READ_DATA, dev); ((struct net_device_stats *)(dev->priv))->rx_packets++; /* count all receives */ skb->protocol=eth_type_trans(skb,dev); netif_rx(skb); /* * If any worth-while packets have been received, netif_rx() * has done a mark_bh(INET_BH) for us and will work on them * when we get to the bottom-half routine. */}__initfunc(intde600_probe(struct device *dev)){ int i; static struct net_device_stats de600_netstats; /*dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);*/ printk("%s: D-Link DE-600 pocket adapter", dev->name); /* Alpha testers must have the version number to report bugs. */ if (de600_debug > 1) printk(version); /* probe for adapter */ rx_page = 0; select_nic(); (void)de600_read_status(dev); de600_put_command(RESET); de600_put_command(STOP_RESET); if (de600_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 */ de600_setup_address(NODE_ADDRESS, RW_ADDR); for (i = 0; i < ETH_ALEN; i++) { dev->dev_addr[i] = de600_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; }#if 0 /* Not yet */ if (check_region(DE600_IO, 3)) { printk(", port 0x%x busy\n", DE600_IO); return EBUSY; }#endif request_region(DE600_IO, 3, "de600"); printk(", Ethernet Address: %02X", dev->dev_addr[0]); for (i = 1; i < ETH_ALEN; i++) printk(":%02X",dev->dev_addr[i]); printk("\n"); /* Initialize the device structure. */ dev->priv = &de600_netstats; memset(dev->priv, 0, sizeof(struct net_device_stats)); dev->get_stats = get_stats; dev->open = de600_open; dev->stop = de600_close; dev->hard_start_xmit = &de600_start_xmit; ether_setup(dev); dev->flags&=~IFF_MULTICAST; select_prn(); return 0;}static intadapter_init(struct device *dev){ int i; long flags; save_flags(flags); cli(); select_nic(); rx_page = 0; /* used by RESET */ de600_put_command(RESET); de600_put_command(STOP_RESET);#ifdef CHECK_LOST_DE600 /* Check if it is still there... */ /* Get the some bytes of the adapter ethernet address from the ROM */ de600_setup_address(NODE_ADDRESS, RW_ADDR); de600_read_byte(READ_DATA, dev); if ((de600_read_byte(READ_DATA, dev) != 0xde) || (de600_read_byte(READ_DATA, dev) != 0x15)) { /* was: if (de600_read_status(dev) & 0xf0) { */ printk("Something has happened to the DE-600! Please check it"#ifdef SHUTDOWN_WHEN_LOST " and do a new ifconfig"#endif /* SHUTDOWN_WHEN_LOST */ "!\n");#ifdef SHUTDOWN_WHEN_LOST /* Goodbye, cruel world... */ dev->flags &= ~IFF_UP; de600_close(dev);#endif /* SHUTDOWN_WHEN_LOST */ was_down = 1; dev->tbusy = 1; /* Transmit busy... */ restore_flags(flags); return 1; /* failed */ }#endif /* CHECK_LOST_DE600 */ if (was_down) { printk("Thanks, I feel much better now!\n"); was_down = 0; } dev->tbusy = 0; /* Transmit busy... */ dev->interrupt = 0; tx_fifo_in = 0; tx_fifo_out = 0; free_tx_pages = TX_PAGES; /* set the ether address. */ de600_setup_address(NODE_ADDRESS, RW_ADDR); for (i = 0; i < ETH_ALEN; i++) de600_put_byte(dev->dev_addr[i]); /* where to start saving incoming packets */ rx_page = RX_BP | RX_BASE_PAGE; de600_setup_address(MEM_4K, RW_ADDR); /* Enable receiver */ de600_put_command(RX_ENABLE); select_prn(); restore_flags(flags); return 0; /* OK */}#ifdef FAKE_SMALL_MAX/* * The new router code (coming soon 8-) ) will fix this properly. */#define DE600_MIN_WINDOW 1024#define DE600_MAX_WINDOW 2048#define DE600_TCP_WINDOW_DIFF 1024/* * Copied from "net/inet/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 keep up with a net saturated * with packets homing in on it :-( ) * * 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! * * Note that the returned window info will never be smaller than * DE600_MIN_WINDOW, i.e. 1024 * This differs from the standard function, that can return an * arbitrarily small window! */#define min(a,b) ((a)<(b)?(a):(b))static unsigned longde600_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 = DE600_MAX_WINDOW - DE600_TCP_WINDOW_DIFF; */ if (atomic_read(&sk->rmem_alloc) >= sk->rcvbuf-2*DE600_MIN_WINDOW) return(0); amt = min((sk->rcvbuf-atomic_read(&sk->rmem_alloc))/2/*-DE600_MIN_WINDOW*/, DE600_MAX_WINDOW); if (amt < 0) return(0); return(amt); } return(0);}#endif#ifdef MODULEstatic char nullname[8];static struct device de600_dev = { nullname, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, de600_probe };intinit_module(void){ if (register_netdev(&de600_dev) != 0) return -EIO; return 0;}voidcleanup_module(void){ unregister_netdev(&de600_dev); release_region(DE600_IO, 3);}#endif /* MODULE *//* * Local variables: * kernel-compile-command: "gcc -D__KERNEL__ -Ilinux/include -I../../net/inet -Wall -Wstrict-prototypes -O2 -m486 -c de600.c" * module-compile-command: "gcc -D__KERNEL__ -DMODULE -Ilinux/include -I../../net/inet -Wall -Wstrict-prototypes -O2 -m486 -c de600.c" * compile-command: "gcc -D__KERNEL__ -DMODULE -Ilinux/include -I../../net/inet -Wall -Wstrict-prototypes -O2 -m486 -c de600.c" * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -