📄 lib82596.c
字号:
/* Transmitter timeout, serious problems. */ DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: transmit timed out, status resetting.\n", dev->name)); dev->stats.tx_errors++; /* Try to restart the adaptor */ if (lp->last_restart == dev->stats.tx_packets) { DEB(DEB_ERRORS, printk(KERN_DEBUG "Resetting board.\n")); /* Shutdown and restart */ i596_reset (dev, lp); } else { /* Issue a channel attention signal */ DEB(DEB_ERRORS, printk(KERN_DEBUG "Kicking board.\n")); lp->dma->scb.command = SWAP16(CUC_START | RX_START); DMA_WBACK_INV(dev, &(lp->dma->scb), sizeof(struct i596_scb)); ca (dev); lp->last_restart = dev->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 = netdev_priv(dev); struct tx_cmd *tx_cmd; struct i596_tbd *tbd; short length = skb->len; dev->trans_start = jiffies; DEB(DEB_STARTTX, printk(KERN_DEBUG "%s: i596_start_xmit(%x,%p) called\n", dev->name, skb->len, skb->data)); if (length < ETH_ZLEN) { if (skb_padto(skb, ETH_ZLEN)) return 0; length = ETH_ZLEN; } netif_stop_queue(dev); tx_cmd = lp->dma->tx_cmds + lp->next_tx_cmd; tbd = lp->dma->tbds + lp->next_tx_cmd; if (tx_cmd->cmd.command) { DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: xmit ring full, dropping packet.\n", dev->name)); dev->stats.tx_dropped++; dev_kfree_skb(skb); } else { if (++lp->next_tx_cmd == TX_RING_SIZE) lp->next_tx_cmd = 0; tx_cmd->tbd = SWAP32(virt_to_dma(lp, tbd)); tbd->next = I596_NULL; tx_cmd->cmd.command = SWAP16(CMD_FLEX | CmdTx); tx_cmd->skb = skb; tx_cmd->pad = 0; tx_cmd->size = 0; tbd->pad = 0; tbd->size = SWAP16(EOF | length); tx_cmd->dma_addr = dma_map_single(dev->dev.parent, skb->data, skb->len, DMA_TO_DEVICE); tbd->data = SWAP32(tx_cmd->dma_addr); DEB(DEB_TXADDR, print_eth(skb->data, "tx-queued")); DMA_WBACK_INV(dev, tx_cmd, sizeof(struct tx_cmd)); DMA_WBACK_INV(dev, tbd, sizeof(struct i596_tbd)); i596_add_cmd(dev, &tx_cmd->cmd); dev->stats.tx_packets++; dev->stats.tx_bytes += length; } netif_start_queue(dev); return 0;}static void print_eth(unsigned char *add, char *str){ DECLARE_MAC_BUF(mac); DECLARE_MAC_BUF(mac2); printk(KERN_DEBUG "i596 0x%p, %s --> %s %02X%02X, %s\n", add, print_mac(mac, add + 6), print_mac(mac2, add), add[12], add[13], str);}static int __devinit i82596_probe(struct net_device *dev){ int i; struct i596_private *lp = netdev_priv(dev); struct i596_dma *dma; /* This lot is ensure things have been cache line aligned. */ BUILD_BUG_ON(sizeof(struct i596_rfd) != 32); BUILD_BUG_ON(sizeof(struct i596_rbd) & 31); BUILD_BUG_ON(sizeof(struct tx_cmd) & 31); BUILD_BUG_ON(sizeof(struct i596_tbd) != 32);#ifndef __LP64__ BUILD_BUG_ON(sizeof(struct i596_dma) > 4096);#endif if (!dev->base_addr || !dev->irq) return -ENODEV; dma = (struct i596_dma *) DMA_ALLOC(dev->dev.parent, sizeof(struct i596_dma), &lp->dma_addr, GFP_KERNEL); if (!dma) { printk(KERN_ERR "%s: Couldn't get shared memory\n", __FILE__); return -ENOMEM; } /* The 82596-specific entries in the device structure. */ dev->open = i596_open; dev->stop = i596_close; dev->hard_start_xmit = i596_start_xmit; dev->set_multicast_list = set_multicast_list; dev->tx_timeout = i596_tx_timeout; dev->watchdog_timeo = TX_TIMEOUT;#ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = i596_poll_controller;#endif memset(dma, 0, sizeof(struct i596_dma)); lp->dma = dma; dma->scb.command = 0; dma->scb.cmd = I596_NULL; dma->scb.rfd = I596_NULL; spin_lock_init(&lp->lock); DMA_WBACK_INV(dev, dma, sizeof(struct i596_dma)); i = register_netdev(dev); if (i) { DMA_FREE(dev->dev.parent, sizeof(struct i596_dma), (void *)dma, lp->dma_addr); return i; }; DEB(DEB_PROBE, printk(KERN_INFO "%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])); DEB(DEB_PROBE, printk(" IRQ %d.\n", dev->irq)); DEB(DEB_INIT, printk(KERN_INFO "%s: dma at 0x%p (%d bytes), lp->scb at 0x%p\n", dev->name, dma, (int)sizeof(struct i596_dma), &dma->scb)); return 0;}#ifdef CONFIG_NET_POLL_CONTROLLERstatic void i596_poll_controller(struct net_device *dev){ disable_irq(dev->irq); i596_interrupt(dev->irq, dev); enable_irq(dev->irq);}#endifstatic irqreturn_t i596_interrupt(int irq, void *dev_id){ struct net_device *dev = dev_id; struct i596_private *lp; struct i596_dma *dma; unsigned short status, ack_cmd = 0; lp = netdev_priv(dev); dma = lp->dma; spin_lock (&lp->lock); wait_cmd(dev, dma, 100, "i596 interrupt, timeout"); status = SWAP16(dma->scb.status); DEB(DEB_INTS, printk(KERN_DEBUG "%s: i596 interrupt, IRQ %d, status %4.4x.\n", dev->name, dev->irq, status)); ack_cmd = status & 0xf000; if (!ack_cmd) { DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: interrupt with no events\n", dev->name)); spin_unlock (&lp->lock); return IRQ_NONE; } if ((status & 0x8000) || (status & 0x2000)) { struct i596_cmd *ptr; if ((status & 0x8000)) DEB(DEB_INTS, printk(KERN_DEBUG "%s: i596 interrupt completed command.\n", dev->name)); if ((status & 0x2000)) DEB(DEB_INTS, printk(KERN_DEBUG "%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700)); while (lp->cmd_head != NULL) { DMA_INV(dev, lp->cmd_head, sizeof(struct i596_cmd)); if (!(lp->cmd_head->status & SWAP16(STAT_C))) break; ptr = lp->cmd_head; DEB(DEB_STATUS, printk(KERN_DEBUG "cmd_head->status = %04x, ->command = %04x\n", SWAP16(lp->cmd_head->status), SWAP16(lp->cmd_head->command))); lp->cmd_head = ptr->v_next; lp->cmd_backlog--; switch (SWAP16(ptr->command) & 0x7) { case CmdTx: { struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr; struct sk_buff *skb = tx_cmd->skb; if (ptr->status & SWAP16(STAT_OK)) { DEB(DEB_TXADDR, print_eth(skb->data, "tx-done")); } else { dev->stats.tx_errors++; if (ptr->status & SWAP16(0x0020)) dev->stats.collisions++; if (!(ptr->status & SWAP16(0x0040))) dev->stats.tx_heartbeat_errors++; if (ptr->status & SWAP16(0x0400)) dev->stats.tx_carrier_errors++; if (ptr->status & SWAP16(0x0800)) dev->stats.collisions++; if (ptr->status & SWAP16(0x1000)) dev->stats.tx_aborted_errors++; } dma_unmap_single(dev->dev.parent, tx_cmd->dma_addr, skb->len, DMA_TO_DEVICE); dev_kfree_skb_irq(skb); tx_cmd->cmd.command = 0; /* Mark free */ break; } case CmdTDR: { unsigned short status = SWAP16(((struct tdr_cmd *)ptr)->status); if (status & 0x8000) { DEB(DEB_ANY, printk(KERN_DEBUG "%s: link ok.\n", dev->name)); } else { if (status & 0x4000) printk(KERN_ERR "%s: Transceiver problem.\n", dev->name); if (status & 0x2000) printk(KERN_ERR "%s: Termination problem.\n", dev->name); if (status & 0x1000) printk(KERN_ERR "%s: Short circuit.\n", dev->name); DEB(DEB_TDR, printk(KERN_DEBUG "%s: Time %d.\n", dev->name, status & 0x07ff)); } break; } case CmdConfigure: /* * Zap command so set_multicast_list() know * it is free */ ptr->command = 0; break; } ptr->v_next = NULL; ptr->b_next = I596_NULL; DMA_WBACK(dev, 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 != NULL) && (ptr != lp->cmd_tail)) { struct i596_cmd *prev = ptr; ptr->command &= SWAP16(0x1fff); ptr = ptr->v_next; DMA_WBACK_INV(dev, prev, sizeof(struct i596_cmd)); } if (lp->cmd_head != NULL) ack_cmd |= CUC_START; dma->scb.cmd = SWAP32(virt_to_dma(lp, &lp->cmd_head->status)); DMA_WBACK_INV(dev, &dma->scb, sizeof(struct i596_scb)); } if ((status & 0x1000) || (status & 0x4000)) { if ((status & 0x4000)) DEB(DEB_INTS, printk(KERN_DEBUG "%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(KERN_DEBUG "%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status)); ack_cmd |= RX_START; dev->stats.rx_errors++; dev->stats.rx_fifo_errors++; rebuild_rx_bufs(dev); } } } wait_cmd(dev, dma, 100, "i596 interrupt, timeout"); dma->scb.command = SWAP16(ack_cmd); DMA_WBACK(dev, &dma->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, dma, 100, "i596 interrupt, exit timeout"); DEB(DEB_INTS, printk(KERN_DEBUG "%s: exiting interrupt.\n", dev->name)); spin_unlock (&lp->lock); return IRQ_HANDLED;}static int i596_close(struct net_device *dev){ struct i596_private *lp = netdev_priv(dev); unsigned long flags; netif_stop_queue(dev); DEB(DEB_INIT, printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x.\n", dev->name, SWAP16(lp->dma->scb.status))); spin_lock_irqsave(&lp->lock, flags); wait_cmd(dev, lp->dma, 100, "close1 timed out"); lp->dma->scb.command = SWAP16(CUC_ABORT | RX_ABORT); DMA_WBACK(dev, &lp->dma->scb, sizeof(struct i596_scb)); ca(dev); wait_cmd(dev, lp->dma, 100, "close2 timed out"); spin_unlock_irqrestore(&lp->lock, flags); DEB(DEB_STRUCT, i596_display_data(dev)); i596_cleanup_cmd(dev, lp); free_irq(dev->irq, dev); remove_rx_bufs(dev); return 0;}/* * Set or clear the multicast filter for this adaptor. */static void set_multicast_list(struct net_device *dev){ struct i596_private *lp = netdev_priv(dev); struct i596_dma *dma = lp->dma; int config = 0, cnt; DECLARE_MAC_BUF(mac); DEB(DEB_MULTI, printk(KERN_DEBUG "%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) && !(dma->cf_cmd.i596_config[8] & 0x01)) { dma->cf_cmd.i596_config[8] |= 0x01; config = 1; } if (!(dev->flags & IFF_PROMISC) && (dma->cf_cmd.i596_config[8] & 0x01)) { dma->cf_cmd.i596_config[8] &= ~0x01; config = 1; } if ((dev->flags & IFF_ALLMULTI) && (dma->cf_cmd.i596_config[11] & 0x20)) { dma->cf_cmd.i596_config[11] &= ~0x20; config = 1; } if (!(dev->flags & IFF_ALLMULTI) && !(dma->cf_cmd.i596_config[11] & 0x20)) { dma->cf_cmd.i596_config[11] |= 0x20; config = 1; } if (config) { if (dma->cf_cmd.cmd.command) printk(KERN_INFO "%s: config change request already queued\n", dev->name); else { dma->cf_cmd.cmd.command = SWAP16(CmdConfigure); DMA_WBACK_INV(dev, &dma->cf_cmd, sizeof(struct cf_cmd)); i596_add_cmd(dev, &dma->cf_cmd.cmd); } } cnt = dev->mc_count; if (cnt > MAX_MC_CNT) { cnt = MAX_MC_CNT; printk(KERN_NOTICE "%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 = &dma->mc_cmd; cmd->cmd.command = SWAP16(CmdMulticastList); cmd->mc_cnt = SWAP16(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(KERN_DEBUG "%s: Adding address %s\n", dev->name, print_mac(mac, cp))); } DMA_WBACK_INV(dev, &dma->mc_cmd, sizeof(struct mc_cmd)); i596_add_cmd(dev, &cmd->cmd); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -