📄 yellowfin.c
字号:
#endif if (tx_errs == 0) break; /* It still hasn't been Txed */ if (tx_errs & 0xF8100000) { /* There was an major error, log it. */#ifndef final_version if (yellowfin_debug > 1) printk(KERN_DEBUG "%s: Transmit error, Tx status %4.4x.\n", dev->name, tx_errs);#endif yp->stats.tx_errors++; if (tx_errs & 0xF800) yp->stats.tx_aborted_errors++; if (tx_errs & 0x0800) yp->stats.tx_carrier_errors++; if (tx_errs & 0x2000) yp->stats.tx_window_errors++; if (tx_errs & 0x8000) yp->stats.tx_fifo_errors++;#ifdef ETHER_STATS if (tx_errs & 0x1000) yp->stats.collisions16++;#endif } else {#ifndef final_version if (yellowfin_debug > 4) printk(KERN_DEBUG "%s: Normal transmit, Tx status %4.4x.\n", dev->name, tx_errs);#endif#ifdef ETHER_STATS if (tx_errs & 0x0400) yp->stats.tx_deferred++;#endif yp->stats.collisions += tx_errs & 15; yp->stats.tx_packets++; } /* Free the original skb. */ DEV_FREE_SKB(yp->tx_skbuff[entry]); yp->tx_skbuff[entry] = 0; /* Mark status as empty. */ yp->tx_status[entry].tx_errs = 0; }#ifndef final_version if (yp->cur_tx - dirty_tx > TX_RING_SIZE) { printk(KERN_ERR "%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n", dev->name, dirty_tx, yp->cur_tx, yp->tx_full); dirty_tx += TX_RING_SIZE; }#endif if (yp->tx_full && dev->tbusy && yp->cur_tx - dirty_tx < TX_RING_SIZE - 2) { /* The ring is no longer full, clear tbusy. */ yp->tx_full = 0; clear_bit(0, (void*)&dev->tbusy); mark_bh(NET_BH); } yp->dirty_tx = dirty_tx; yp->tx_tail_desc = &yp->tx_status[dirty_tx % TX_RING_SIZE]; }#endif /* Log errors and other uncommon events. */ if (intr_status & 0x2ee) /* Abnormal error summary. */ yellowfin_error(dev, intr_status); if (--boguscnt < 0) { printk(KERN_WARNING "%s: Too much work at interrupt, status=0x%4.4x.\n", dev->name, intr_status); break; } } while (1); if (yellowfin_debug > 3) printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n", dev->name, inw(ioaddr + IntrStatus)); /* Code that should never be run! Perhaps remove after testing.. */ { static int stopit = 10; if (dev->start == 0 && --stopit < 0) { printk(KERN_ERR "%s: Emergency stop, looping startup interrupt.\n", dev->name); free_irq(irq, dev); } } dev->interrupt = 0; clear_bit(0, (void*)&yp->in_interrupt); return;}/* This routine is logically part of the interrupt handler, but separated for clarity and better register allocation. */static int yellowfin_rx(struct device *dev){ struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; int entry = yp->cur_rx % RX_RING_SIZE; int boguscnt = 20; if (yellowfin_debug > 4) { printk(KERN_DEBUG " In yellowfin_rx(), entry %d status %4.4x.\n", entry, yp->rx_ring[entry].status); printk(KERN_DEBUG " #%d desc. %4.4x %4.4x %8.8x %4.4x %4.4x.\n", entry, yp->rx_ring[entry].cmd, yp->rx_ring[entry].request_cnt, yp->rx_ring[entry].addr, yp->rx_ring[entry].result_cnt, yp->rx_ring[entry].status); } /* If EOP is set on the next entry, it's a new packet. Send it up. */ while (yp->rx_head_desc->status) { struct yellowfin_desc *desc = yp->rx_head_desc; u16 desc_status = desc->status; int data_size = desc->request_cnt - desc->result_cnt; u8 *buf_addr = bus_to_virt(desc->addr); s16 frame_status = *(s16*)&(buf_addr[data_size - 2]); /* ?Alpha safe on 885? */ if (yellowfin_debug > 4) printk(KERN_DEBUG " yellowfin_rx() status was %4.4x.\n", frame_status); if (--boguscnt < 0) break; if ( ! (desc_status & RX_EOP)) { printk(KERN_WARNING "%s: Oversized Ethernet frame spanned multiple buffers," " status %4.4x!\n", dev->name, desc_status); yp->stats.rx_length_errors++; } else if (yp->chip_id == 0 && (frame_status & 0x0038)) { /* There was a error. */ if (yellowfin_debug > 3) printk(KERN_DEBUG " yellowfin_rx() Rx error was %4.4x.\n", frame_status); yp->stats.rx_errors++; if (frame_status & 0x0060) yp->stats.rx_length_errors++; if (frame_status & 0x0008) yp->stats.rx_frame_errors++; if (frame_status & 0x0010) yp->stats.rx_crc_errors++; if (frame_status < 0) yp->stats.rx_dropped++; } else if (yp->chip_id != 0 && ((buf_addr[data_size-1] & 0x85) || buf_addr[data_size-2] & 0xC0)) { u8 status1 = buf_addr[data_size-2]; u8 status2 = buf_addr[data_size-1]; yp->stats.rx_errors++; if (status1 & 0xC0) yp->stats.rx_length_errors++; if (status2 & 0x03) yp->stats.rx_frame_errors++; if (status2 & 0x04) yp->stats.rx_crc_errors++; if (status2 & 0x80) yp->stats.rx_dropped++;#ifdef YF_PROTOTYPE /* Support for prototype hardware errata. */ } else if (memcmp(bus_to_virt(yp->rx_ring[entry].addr), dev->dev_addr, 6) != 0 && memcmp(bus_to_virt(yp->rx_ring[entry].addr), "\377\377\377\377\377\377", 6) != 0) { printk(KERN_WARNING "%s: Bad frame to %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n", dev->name, buf_addr[0], buf_addr[1], buf_addr[2], buf_addr[3], buf_addr[4], buf_addr[5]); bogus_rx++;#endif } else { struct sk_buff *skb; int pkt_len = data_size - (yp->chip_id ? 7 : 8 + buf_addr[data_size - 8]); /* To verify: Yellowfin Length should omit the CRC! */#ifndef final_version if (yellowfin_debug > 4) printk(KERN_DEBUG " yellowfin_rx() normal Rx pkt length %d" " of %d, bogus_cnt %d.\n", pkt_len, data_size, boguscnt);#endif /* Check if the packet is long enough to just pass up the skbuff without copying to a properly sized skbuff. */ if (pkt_len > rx_copybreak) { char *temp = skb_put(skb = yp->rx_skbuff[entry], pkt_len);#ifndef final_verison /* Remove after testing. */ if (bus_to_virt(yp->rx_ring[entry].addr) != temp) printk(KERN_WARNING "%s: Warning -- the skbuff addresses " "do not match in yellowfin_rx: %p vs. %p / %p.\n", dev->name, bus_to_virt(yp->rx_ring[entry].addr), skb->head, temp);#endif yp->rx_skbuff[entry] = NULL; } else { skb = dev_alloc_skb(pkt_len + 2); if (skb == NULL) break; skb->dev = dev; skb_reserve(skb, 2); /* 16 byte align the data fields */#if 1 eth_copy_and_sum(skb, bus_to_virt(yp->rx_ring[entry].addr), pkt_len, 0); skb_put(skb, pkt_len);#else memcpy(skb_put(skb, pkt_len), bus_to_virt(yp->rx_ring[entry].addr), pkt_len);#endif } skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); dev->last_rx = jiffies; yp->stats.rx_packets++; } entry = (++yp->cur_rx) % RX_RING_SIZE; yp->rx_head_desc = &yp->rx_ring[entry]; } /* Refill the Rx ring buffers. */ for (; yp->cur_rx - yp->dirty_rx > 0; yp->dirty_rx++) { struct sk_buff *skb; entry = yp->dirty_rx % RX_RING_SIZE; if (yp->rx_skbuff[entry] == NULL) { skb = dev_alloc_skb(yp->rx_buf_sz); if (skb == NULL) break; /* Better luck next round. */ skb->dev = dev; /* Mark as being used by this device. */ skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ yp->rx_ring[entry].addr = virt_to_bus(skb->tail); yp->rx_skbuff[entry] = skb; } yp->rx_ring[entry].cmd = CMD_STOP; yp->rx_ring[entry].status = 0; /* Clear complete bit. */ if (entry != 0) yp->rx_ring[entry - 1].cmd = CMD_RX_BUF | INTR_ALWAYS; else yp->rx_ring[RX_RING_SIZE - 1].cmd = CMD_RX_BUF | INTR_ALWAYS | BRANCH_ALWAYS; } return 0;}static void yellowfin_error(struct device *dev, int intr_status){ struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; printk(KERN_ERR "%s: Something Wicked happened! %4.4x.\n", dev->name, intr_status); /* Hmmmmm, it's not clear what to do here. */ if (intr_status & (IntrTxPCIErr | IntrTxPCIFault)) yp->stats.tx_errors++; if (intr_status & (IntrRxPCIErr | IntrRxPCIFault)) yp->stats.rx_errors++;}static int yellowfin_close(struct device *dev){ long ioaddr = dev->base_addr; struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; int i; dev->start = 0; dev->tbusy = 1; if (yellowfin_debug > 1) { printk(KERN_DEBUG "%s: Shutting down ethercard, status was Tx %4.4x Rx %4.4x Int %2.2x.\n", dev->name, inw(ioaddr + TxStatus), inw(ioaddr + RxStatus), inw(ioaddr + IntrStatus)); printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d, Rx %d / %d.\n", dev->name, yp->cur_tx, yp->dirty_tx, yp->cur_rx, yp->dirty_rx); } /* Disable interrupts by clearing the interrupt mask. */ outw(0x0000, ioaddr + IntrEnb); /* Stop the chip's Tx and Rx processes. */ outl(0x80000000, ioaddr + RxCtrl); outl(0x80000000, ioaddr + TxCtrl); del_timer(&yp->timer);#ifdef __i386__ if (yellowfin_debug > 2) { printk("\n"KERN_DEBUG" Tx ring at %8.8x:\n", (int)virt_to_bus(yp->tx_ring)); for (i = 0; i < TX_RING_SIZE*2; i++) printk(" %c #%d desc. %4.4x %4.4x %8.8x %8.8x %4.4x %4.4x.\n", inl(ioaddr + TxPtr) == (long)&yp->tx_ring[i] ? '>' : ' ', i, yp->tx_ring[i].cmd, yp->tx_ring[i].request_cnt, yp->tx_ring[i].addr, yp->tx_ring[i].branch_addr, yp->tx_ring[i].result_cnt, yp->tx_ring[i].status); printk(KERN_DEBUG " Tx status %p:\n", yp->tx_status); for (i = 0; i < TX_RING_SIZE; i++) printk(" #%d status %4.4x %4.4x %4.4x %4.4x.\n", i, yp->tx_status[i].tx_cnt, yp->tx_status[i].tx_errs, yp->tx_status[i].total_tx_cnt, yp->tx_status[i].paused); printk("\n"KERN_DEBUG " Rx ring %8.8x:\n", (int)virt_to_bus(yp->rx_ring)); for (i = 0; i < RX_RING_SIZE; i++) { printk(KERN_DEBUG " %c #%d desc. %4.4x %4.4x %8.8x %4.4x %4.4x\n", inl(ioaddr + RxPtr) == (long)&yp->rx_ring[i] ? '>' : ' ', i, yp->rx_ring[i].cmd, yp->rx_ring[i].request_cnt, yp->rx_ring[i].addr, yp->rx_ring[i].result_cnt, yp->rx_ring[i].status); if (yellowfin_debug > 6) { if (*(u8*)yp->rx_ring[i].addr != 0x69) { int j; for (j = 0; j < 0x50; j++) printk(" %4.4x", ((u16*)yp->rx_ring[i].addr)[j]); printk("\n"); } } } }#endif /* __i386__ debugging only */ free_irq(dev->irq, dev); /* Free all the skbuffs in the Rx queue. */ for (i = 0; i < RX_RING_SIZE; i++) { yp->rx_ring[i].cmd = CMD_STOP; yp->rx_ring[i].addr = 0xBADF00D0; /* An invalid address. */ if (yp->rx_skbuff[i]) {#if LINUX_VERSION_CODE < 0x20100 yp->rx_skbuff[i]->free = 1;#endif DEV_FREE_SKB(yp->rx_skbuff[i]); } yp->rx_skbuff[i] = 0; } for (i = 0; i < TX_RING_SIZE; i++) { if (yp->tx_skbuff[i]) DEV_FREE_SKB(yp->tx_skbuff[i]); yp->tx_skbuff[i] = 0; }#ifdef YF_PROTOTYPE /* Support for prototype hardware errata. */ if (yellowfin_debug > 0) { printk(KERN_DEBUG "%s: Received %d frames that we should not have.\n", dev->name, bogus_rx); }#endif MOD_DEC_USE_COUNT; return 0;}static struct enet_statistics *yellowfin_get_stats(struct device *dev){ struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; return &yp->stats;}/* Set or clear the multicast filter for this adaptor. *//* The little-endian AUTODIN32 ethernet CRC calculation. N.B. Do not use for bulk data, use a table-based routine instead. This is common code and should be moved to net/core/crc.c */static unsigned const ethernet_polynomial_le = 0xedb88320U;static inline unsigned ether_crc_le(int length, unsigned char *data){ unsigned int crc = 0xffffffff; /* Initial value. */ while(--length >= 0) { unsigned char current_octet = *data++; int bit; for (bit = 8; --bit >= 0; current_octet >>= 1) { if ((crc ^ current_octet) & 1) { crc >>= 1; crc ^= ethernet_polynomial_le; } else crc >>= 1; } } return crc;}static void set_rx_mode(struct device *dev){ struct yellowfin_private *yp = (struct yellowfin_private *)dev->priv; long ioaddr = dev->base_addr; u16 cfg_value = inw(ioaddr + Cnfg); /* Stop the Rx process to change any value. */ outw(cfg_value & ~0x1000, ioaddr + Cnfg); if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ /* Unconditionally log net taps. */ printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name); outw(0x000F, ioaddr + AddrMode); } else if ((dev->mc_count > 64) || (dev->flags & IFF_ALLMULTI)) { /* Too many to filter well, or accept all multicasts. */ outw(0x000B, ioaddr + AddrMode); } else if (dev->mc_count > 0) { /* Must use the multicast hash table. */ struct dev_mc_list *mclist; u16 hash_table[4]; int i; memset(hash_table, 0, sizeof(hash_table)); for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; i++, mclist = mclist->next) { /* Due to a bug in the early chip versions, multiple filter slots must be set for each address. */ if (yp->chip_id == 0) { set_bit((ether_crc_le(3, mclist->dmi_addr) >> 3) & 0x3f, hash_table); set_bit((ether_crc_le(4, mclist->dmi_addr) >> 3) & 0x3f, hash_table); set_bit((ether_crc_le(5, mclist->dmi_addr) >> 3) & 0x3f, hash_table); } set_bit((ether_crc_le(6, mclist->dmi_addr) >> 3) & 0x3f, hash_table); } /* Copy the hash table to the chip. */ for (i = 0; i < 4; i++) outw(hash_table[i], ioaddr + HashTbl + i*2); outw(0x0003, ioaddr + AddrMode); } else { /* Normal, unicast/broadcast-only mode. */ outw(0x0001, ioaddr + AddrMode); } /* Restart the Rx process. */ outw(cfg_value | 0x1000, ioaddr + Cnfg);}#ifdef HAVE_PRIVATE_IOCTLstatic int mii_ioctl(struct device *dev, struct ifreq *rq, int cmd){ long ioaddr = dev->base_addr; u16 *data = (u16 *)&rq->ifr_data; switch(cmd) { case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */ data[0] = ((struct yellowfin_private *)dev->priv)->phys[0] & 0x1f; /* Fall Through */ case SIOCDEVPRIVATE+1: /* Read the specified MII register. */ data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f); return 0; case SIOCDEVPRIVATE+2: /* Write the specified MII register */ if (!suser()) return -EPERM; mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]); return 0; default: return -EOPNOTSUPP; }}#endif /* HAVE_PRIVATE_IOCTL */#ifdef MODULE/* An additional parameter that may be passed in... */static int debug = -1;int init_module(void){ if (debug >= 0) yellowfin_debug = debug; return yellowfin_probe(0);}void cleanup_module(void){ struct device *next_dev; /* No need to check MOD_IN_USE, as sys_delete_module() checks. */ while (root_yellowfin_dev) { next_dev = ((struct yellowfin_private *)root_yellowfin_dev->priv)->next_module; unregister_netdev(root_yellowfin_dev); release_region(root_yellowfin_dev->base_addr, YELLOWFIN_TOTAL_SIZE); kfree(root_yellowfin_dev); root_yellowfin_dev = next_dev; }}#endif /* MODULE *//* * Local variables: * compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" * compile-command-alphaLX: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS` -fomit-frame-pointer -fno-strength-reduce -mno-fp-regs -Wa,-m21164a -DBWX_USABLE -DBWIO_ENABLED" * SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c yellowfin.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" * c-indent-level: 4 * c-basic-offset: 4 * tab-width: 4 * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -