📄 lasi_82596.c
字号:
/* Shutdown and restart */ i596_reset (dev, lp, ioaddr); } else { /* Issue a channel attention signal */ DEB(DEB_ERRORS,printk ("Kicking board.\n")); lp->scb.command = CUC_START | RX_START; CHECK_WBACK_INV(&(lp->scb), sizeof(struct i596_scb)); CA (dev); lp->last_restart = lp->stats.tx_packets; } dev->trans_start = jiffies; netif_wake_queue (dev);}static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; struct tx_cmd *tx_cmd; struct i596_tbd *tbd; short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; dev->trans_start = jiffies; DEB(DEB_STARTTX,printk("%s: i596_start_xmit(%x,%x) called\n", dev->name, skb->len, (unsigned int)skb->data)); netif_stop_queue(dev); tx_cmd = lp->tx_cmds + lp->next_tx_cmd; tbd = lp->tbds + lp->next_tx_cmd; if (tx_cmd->cmd.command) { DEB(DEB_ERRORS,printk ("%s: xmit ring full, dropping packet.\n", dev->name)); lp->stats.tx_dropped++; dev_kfree_skb(skb); } else { if (++lp->next_tx_cmd == TX_RING_SIZE) lp->next_tx_cmd = 0; tx_cmd->tbd = WSWAPtbd(virt_to_dma(lp,tbd)); tbd->next = I596_NULL; tx_cmd->cmd.command = CMD_FLEX | CmdTx; tx_cmd->skb = skb; tx_cmd->pad = 0; tx_cmd->size = 0; tbd->pad = 0; tbd->size = EOF | length; tx_cmd->dma_addr = pci_map_single(NULL, skb->data, skb->len, PCI_DMA_TODEVICE); tbd->data = WSWAPchar(tx_cmd->dma_addr); DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued")); CHECK_WBACK_INV(tx_cmd, sizeof(struct tx_cmd)); CHECK_WBACK_INV(tbd, sizeof(struct i596_tbd)); i596_add_cmd(dev, &tx_cmd->cmd); lp->stats.tx_packets++; lp->stats.tx_bytes += length; } netif_start_queue(dev); return 0;}static void print_eth(unsigned char *add, char *str){ int i; printk("i596 0x%p, ", add); for (i = 0; i < 6; i++) printk(" %02X", add[i + 6]); printk(" -->"); for (i = 0; i < 6; i++) printk(" %02X", add[i]); printk(" %02X%02X, %s\n", add[12], add[13], str);}#define LAN_PROM_ADDR 0xF0810000static int __init i82596_probe(struct net_device *dev, int options){ int i; struct i596_private *lp; char eth_addr[6]; dma_addr_t dma_addr; /* This lot is ensure things have been cache line aligned. */ if (sizeof(struct i596_rfd) != 32) { printk("82596: sizeof(struct i596_rfd) = %d\n", sizeof(struct i596_rfd)); return -ENODEV; } if (sizeof(struct i596_rbd) != 32) { printk("82596: sizeof(struct i596_rbd) = %d\n", sizeof(struct i596_rbd)); return -ENODEV; } if (sizeof(struct tx_cmd) != 32) { printk("82596: sizeof(struct tx_cmd) = %d\n", sizeof(struct tx_cmd)); return -ENODEV; } if (sizeof(struct i596_tbd) != 32) { printk("82596: sizeof(struct i596_tbd) = %d\n", sizeof(struct i596_tbd)); return -ENODEV; } if (sizeof(struct i596_private) > 4096) { printk("82596: sizeof(struct i596_private) = %d\n", sizeof(struct i596_private)); return -ENODEV; } /* FIXME: Currently this works only, if set-up from lasi.c. This should be changed to use probing too ! */ if (!dev->base_addr || !dev->irq) return -ENODEV; if (!pdc_lan_station_id( (char*)ð_addr, (void*)dev->base_addr)) { for(i=0;i<6;i++) eth_addr[i] = gsc_readb(LAN_PROM_ADDR+i); printk("82596.c: MAC of HP700 LAN blindely read from the prom!\n"); } dev->mem_start = (int)pci_alloc_consistent( NULL, sizeof(struct i596_private), &dma_addr); if (!dev->mem_start) { printk("%s: Couldn't get consistent shared memory\n", dev->name); dma_consistent = 0; dev->mem_start = (int)__get_free_pages(GFP_ATOMIC, 0); if (!dev->mem_start) { printk("%s: Couldn't get shared memory\n", dev->name);#ifdef ENABLE_APRICOT release_region(dev->base_addr, I596_TOTAL_SIZE);#endif return -ENOMEM; } dma_addr = virt_to_bus(dev->mem_start); } ether_setup(dev); DEB(DEB_PROBE,printk("%s: 82596 at %#3lx,", dev->name, dev->base_addr)); for (i = 0; i < 6; i++) DEB(DEB_PROBE,printk(" %2.2X", dev->dev_addr[i] = eth_addr[i])); DEB(DEB_PROBE,printk(" IRQ %d.\n", dev->irq)); DEB(DEB_PROBE,printk(version)); /* The 82596-specific entries in the device structure. */ dev->open = i596_open; dev->stop = i596_close; dev->hard_start_xmit = i596_start_xmit; dev->get_stats = i596_get_stats; dev->set_multicast_list = set_multicast_list; dev->tx_timeout = i596_tx_timeout; dev->watchdog_timeo = TX_TIMEOUT; dev->priv = (void *)(dev->mem_start); lp = (struct i596_private *) dev->priv; DEB(DEB_INIT,printk ("%s: lp at 0x%08lx (%d bytes), lp->scb at 0x%08lx\n", dev->name, (unsigned long)lp, sizeof(struct i596_private), (unsigned long)&lp->scb)); memset((void *) lp, 0, sizeof(struct i596_private));#if 0 kernel_set_cachemode((void *)(dev->mem_start), 4096, IOMAP_NOCACHE_SER);#endif lp->options = options; lp->scb.command = 0; lp->scb.cmd = I596_NULL; lp->scb.rfd = I596_NULL; lp->lock = SPIN_LOCK_UNLOCKED; lp->dma_addr = dma_addr; CHECK_WBACK_INV(dev->mem_start, sizeof(struct i596_private)); return 0;}int __init lasi_i82596_probe(struct net_device *dev){ return i82596_probe(dev, 0);}int __init asp_i82596_probe(struct net_device *dev){ return i82596_probe(dev, OPT_SWAP_PORT);}static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs){ struct net_device *dev = dev_id; struct i596_private *lp; unsigned short status, ack_cmd = 0; if (dev == NULL) { printk("i596_interrupt(): irq %d for unknown device.\n", irq); return; } lp = (struct i596_private *) dev->priv; spin_lock (&lp->lock); wait_cmd(dev,lp,100,"i596 interrupt, timeout"); status = lp->scb.status; DEB(DEB_INTS,printk("%s: i596 interrupt, IRQ %d, status %4.4x.\n", dev->name, irq, status)); ack_cmd = status & 0xf000; if (!ack_cmd) { DEB(DEB_ERRORS, printk("%s: interrupt with no events\n", dev->name)); spin_unlock (&lp->lock); return; } if ((status & 0x8000) || (status & 0x2000)) { struct i596_cmd *ptr; if ((status & 0x8000)) DEB(DEB_INTS,printk("%s: i596 interrupt completed command.\n", dev->name)); if ((status & 0x2000)) DEB(DEB_INTS,printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700)); while (lp->cmd_head != I596_NULL) { CHECK_INV(lp->cmd_head, sizeof(struct i596_cmd)); if (!(lp->cmd_head->status & STAT_C)) break; ptr = lp->cmd_head; DEB(DEB_STATUS,printk("cmd_head->status = %04x, ->command = %04x\n", lp->cmd_head->status, lp->cmd_head->command)); lp->cmd_head = ptr->v_next; lp->cmd_backlog--; switch ((ptr->command) & 0x7) { case CmdTx: { struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr; struct sk_buff *skb = tx_cmd->skb; if ((ptr->status) & STAT_OK) { DEB(DEB_TXADDR,print_eth(skb->data, "tx-done")); } else { lp->stats.tx_errors++; if ((ptr->status) & 0x0020) lp->stats.collisions++; if (!((ptr->status) & 0x0040)) lp->stats.tx_heartbeat_errors++; if ((ptr->status) & 0x0400) lp->stats.tx_carrier_errors++; if ((ptr->status) & 0x0800) lp->stats.collisions++; if ((ptr->status) & 0x1000) lp->stats.tx_aborted_errors++; } pci_unmap_single(NULL, tx_cmd->dma_addr, skb->len, PCI_DMA_TODEVICE); dev_kfree_skb_irq(skb); tx_cmd->cmd.command = 0; /* Mark free */ break; } case CmdTDR: { unsigned short status = ((struct tdr_cmd *)ptr)->status; if (status & 0x8000) { DEB(DEB_ANY,printk("%s: link ok.\n", dev->name)); } else { if (status & 0x4000) printk("%s: Transceiver problem.\n", dev->name); if (status & 0x2000) printk("%s: Termination problem.\n", dev->name); if (status & 0x1000) printk("%s: Short circuit.\n", dev->name); DEB(DEB_TDR,printk("%s: Time %d.\n", dev->name, status & 0x07ff)); } break; } case CmdConfigure: /* Zap command so set_multicast_list() knows it is free */ ptr->command = 0; break; } ptr->v_next = ptr->b_next = I596_NULL; CHECK_WBACK(ptr, sizeof(struct i596_cmd)); lp->last_cmd = jiffies; } /* This mess is arranging that only the last of any outstanding * commands has the interrupt bit set. Should probably really * only add to the cmd queue when the CU is stopped. */ ptr = lp->cmd_head; while ((ptr != I596_NULL) && (ptr != lp->cmd_tail)) { struct i596_cmd *prev = ptr; ptr->command &= 0x1fff; ptr = ptr->v_next; CHECK_WBACK_INV(prev, sizeof(struct i596_cmd)); } if ((lp->cmd_head != I596_NULL)) ack_cmd |= CUC_START; lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&lp->cmd_head->status)); CHECK_WBACK_INV(&lp->scb, sizeof(struct i596_scb)); } if ((status & 0x1000) || (status & 0x4000)) { if ((status & 0x4000)) DEB(DEB_INTS,printk("%s: i596 interrupt received a frame.\n", dev->name)); i596_rx(dev); /* Only RX_START if stopped - RGH 07-07-96 */ if (status & 0x1000) { if (netif_running(dev)) { DEB(DEB_ERRORS,printk("%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status)); ack_cmd |= RX_START; lp->stats.rx_errors++; lp->stats.rx_fifo_errors++; rebuild_rx_bufs(dev); } } } wait_cmd(dev,lp,100,"i596 interrupt, timeout"); lp->scb.command = ack_cmd; CHECK_WBACK(&lp->scb, sizeof(struct i596_scb)); /* DANGER: I suspect that some kind of interrupt acknowledgement aside from acking the 82596 might be needed here... but it's running acceptably without */ CA(dev); wait_cmd(dev,lp,100,"i596 interrupt, exit timeout"); DEB(DEB_INTS,printk("%s: exiting interrupt.\n", dev->name)); spin_unlock (&lp->lock); return;}static int i596_close(struct net_device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; unsigned long flags; netif_stop_queue(dev); DEB(DEB_INIT,printk("%s: Shutting down ethercard, status was %4.4x.\n", dev->name, lp->scb.status)); save_flags(flags); cli(); wait_cmd(dev,lp,100,"close1 timed out"); lp->scb.command = CUC_ABORT | RX_ABORT; CHECK_WBACK(&lp->scb, sizeof(struct i596_scb)); CA(dev); wait_cmd(dev,lp,100,"close2 timed out"); restore_flags(flags); DEB(DEB_STRUCT,i596_display_data(dev)); i596_cleanup_cmd(dev,lp); disable_irq(dev->irq); free_irq(dev->irq, dev); remove_rx_bufs(dev); release_region(dev->base_addr, 12); MOD_DEC_USE_COUNT; return 0;}static struct net_device_stats * i596_get_stats(struct net_device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; return &lp->stats;}/* * Set or clear the multicast filter for this adaptor. */static void set_multicast_list(struct net_device *dev){ struct i596_private *lp = (struct i596_private *) dev->priv; int config = 0, cnt; DEB(DEB_MULTI,printk("%s: set multicast list, %d entries, promisc %s, allmulti %s\n", dev->name, dev->mc_count, dev->flags & IFF_PROMISC ? "ON" : "OFF", dev->flags & IFF_ALLMULTI ? "ON" : "OFF")); if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) { lp->cf_cmd.i596_config[8] |= 0x01; config = 1; } if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) { lp->cf_cmd.i596_config[8] &= ~0x01; config = 1; } if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) { lp->cf_cmd.i596_config[11] &= ~0x20; config = 1; } if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) { lp->cf_cmd.i596_config[11] |= 0x20; config = 1; } if (config) { if (lp->cf_cmd.cmd.command) printk("%s: config change request already queued\n", dev->name); else { lp->cf_cmd.cmd.command = CmdConfigure; CHECK_WBACK_INV(&lp->cf_cmd, sizeof(struct cf_cmd)); i596_add_cmd(dev, &lp->cf_cmd.cmd); } } cnt = dev->mc_count; if (cnt > MAX_MC_CNT) { cnt = MAX_MC_CNT; printk("%s: Only %d multicast addresses supported", dev->name, cnt); } if (dev->mc_count > 0) { struct dev_mc_list *dmi; unsigned char *cp; struct mc_cmd *cmd; cmd = &lp->mc_cmd; cmd->cmd.command = CmdMulticastList; cmd->mc_cnt = dev->mc_count * 6; cp = cmd->mc_addrs; for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) { memcpy(cp, dmi->dmi_addr, 6); if (i596_debug > 1) DEB(DEB_MULTI,printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5])); } CHECK_WBACK_INV(&lp->mc_cmd, sizeof(struct mc_cmd)); i596_add_cmd(dev, &cmd->cmd); }}#ifdef HAVE_DEVLISTstatic unsigned int i596_portlist[] __initdata ={0x300, 0};struct netdev_entry i596_drv ={"lasi_i82596", lasi_i82596_probe, I596_TOTAL_SIZE, i596_portlist};#endif#ifdef MODULEstatic char devicename[9] ={0,};static struct net_device dev_82596 ={ devicename, /* device name inserted by drivers/net/net_init.c */ 0, 0, 0, 0, 0, 0, /* base, irq */ 0, 0, 0, NULL, lasi_i82596_probe};MODULE_PARM(debug, "i");static int debug = -1;int init_module(void){ if (debug >= 0) i596_debug = debug; if (register_netdev(&dev_82596) != 0) return -EIO; return 0;}void cleanup_module(void){ unregister_netdev(&dev_82596); lp = (struct i596_private *) dev_82596.priv; if (dma_consistent) pci_free_consistent( NULL, sizeof( struct i596_private), dev_82596.mem_start, lp->dma_addr); else free_page ((u32)(dev_82596.mem_start)); dev_82596.priv = NULL;}#endif /* MODULE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -