atarilance.c
来自「linux 内核源代码」· C语言 代码 · 共 1,183 行 · 第 1/3 页
C
1,183 行
if (len < ETH_ZLEN) len = ETH_ZLEN; /* PAM-Card has a bug: Can only send packets with even number of bytes! */ else if (lp->cardtype == PAM_CARD && (len & 1)) ++len; if (len > skb->len) { if (skb_padto(skb, len)) return 0; } netif_stop_queue (dev); /* Fill in a Tx ring entry */ if (lance_debug >= 3) { printk( "%s: TX pkt type 0x%04x from " "%s to %s" " data at 0x%08x len %d\n", dev->name, ((u_short *)skb->data)[6], print_mac(mac, &skb->data[6]), print_mac(mac2, skb->data), (int)skb->data, (int)skb->len ); } /* We're not prepared for the int until the last flags are set/reset. And * the int may happen already after setting the OWN_CHIP... */ spin_lock_irqsave (&lp->devlock, flags); /* Mask to ring buffer boundary. */ entry = lp->cur_tx & TX_RING_MOD_MASK; head = &(MEM->tx_head[entry]); /* Caution: the write order is important here, set the "ownership" bits * last. */ head->length = -len; head->misc = 0; lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len ); head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP; dev->stats.tx_bytes += skb->len; dev_kfree_skb( skb ); lp->cur_tx++; while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) { lp->cur_tx -= TX_RING_SIZE; lp->dirty_tx -= TX_RING_SIZE; } /* Trigger an immediate send poll. */ DREG = CSR0_INEA | CSR0_TDMD; dev->trans_start = jiffies; if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) == TMD1_OWN_HOST) netif_start_queue (dev); else lp->tx_full = 1; spin_unlock_irqrestore (&lp->devlock, flags); return 0;}/* The LANCE interrupt handler. */static irqreturn_t lance_interrupt( int irq, void *dev_id ){ struct net_device *dev = dev_id; struct lance_private *lp; struct lance_ioreg *IO; int csr0, boguscnt = 10; int handled = 0; if (dev == NULL) { DPRINTK( 1, ( "lance_interrupt(): interrupt for unknown device.\n" )); return IRQ_NONE; } lp = (struct lance_private *)dev->priv; IO = lp->iobase; spin_lock (&lp->devlock); AREG = CSR0; while( ((csr0 = DREG) & (CSR0_ERR | CSR0_TINT | CSR0_RINT)) && --boguscnt >= 0) { handled = 1; /* Acknowledge all of the current interrupt sources ASAP. */ DREG = csr0 & ~(CSR0_INIT | CSR0_STRT | CSR0_STOP | CSR0_TDMD | CSR0_INEA); DPRINTK( 2, ( "%s: interrupt csr0=%04x new csr=%04x.\n", dev->name, csr0, DREG )); if (csr0 & CSR0_RINT) /* Rx interrupt */ lance_rx( dev ); if (csr0 & CSR0_TINT) { /* Tx-done interrupt */ int dirty_tx = lp->dirty_tx; while( dirty_tx < lp->cur_tx) { int entry = dirty_tx & TX_RING_MOD_MASK; int status = MEM->tx_head[entry].flag; if (status & TMD1_OWN_CHIP) break; /* It still hasn't been Txed */ MEM->tx_head[entry].flag = 0; if (status & TMD1_ERR) { /* There was an major error, log it. */ int err_status = MEM->tx_head[entry].misc; dev->stats.tx_errors++; if (err_status & TMD3_RTRY) dev->stats.tx_aborted_errors++; if (err_status & TMD3_LCAR) dev->stats.tx_carrier_errors++; if (err_status & TMD3_LCOL) dev->stats.tx_window_errors++; if (err_status & TMD3_UFLO) { /* Ackk! On FIFO errors the Tx unit is turned off! */ dev->stats.tx_fifo_errors++; /* Remove this verbosity later! */ DPRINTK( 1, ( "%s: Tx FIFO error! Status %04x\n", dev->name, csr0 )); /* Restart the chip. */ DREG = CSR0_STRT; } } else { if (status & (TMD1_MORE | TMD1_ONE | TMD1_DEF)) dev->stats.collisions++; dev->stats.tx_packets++; } /* XXX MSch: free skb?? */ dirty_tx++; }#ifndef final_version if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) { DPRINTK( 0, ( "out-of-sync dirty pointer," " %d vs. %d, full=%ld.\n", dirty_tx, lp->cur_tx, lp->tx_full )); dirty_tx += TX_RING_SIZE; }#endif if (lp->tx_full && (netif_queue_stopped(dev)) && dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) { /* The ring is no longer full, clear tbusy. */ lp->tx_full = 0; netif_wake_queue (dev); } lp->dirty_tx = dirty_tx; } /* Log misc errors. */ if (csr0 & CSR0_BABL) dev->stats.tx_errors++; /* Tx babble. */ if (csr0 & CSR0_MISS) dev->stats.rx_errors++; /* Missed a Rx frame. */ if (csr0 & CSR0_MERR) { DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), " "status %04x.\n", dev->name, csr0 )); /* Restart the chip. */ DREG = CSR0_STRT; } } /* Clear any other interrupt, and set interrupt enable. */ DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR | CSR0_IDON | CSR0_INEA; DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n", dev->name, DREG )); spin_unlock (&lp->devlock); return IRQ_RETVAL(handled);}static int lance_rx( struct net_device *dev ){ struct lance_private *lp = (struct lance_private *)dev->priv; int entry = lp->cur_rx & RX_RING_MOD_MASK; int i; DPRINTK( 2, ( "%s: rx int, flag=%04x\n", dev->name, MEM->rx_head[entry].flag )); /* If we own the next entry, it's a new packet. Send it up. */ while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) { struct lance_rx_head *head = &(MEM->rx_head[entry]); int status = head->flag; if (status != (RMD1_ENP|RMD1_STP)) { /* There was an error. */ /* There is a tricky error noted by John Murphy, <murf@perftech.com> to Russ Nelson: Even with full-sized buffers it's possible for a jabber packet to use two buffers, with only the last correctly noting the error. */ if (status & RMD1_ENP) /* Only count a general error at the */ dev->stats.rx_errors++; /* end of a packet.*/ if (status & RMD1_FRAM) dev->stats.rx_frame_errors++; if (status & RMD1_OFLO) dev->stats.rx_over_errors++; if (status & RMD1_CRC) dev->stats.rx_crc_errors++; if (status & RMD1_BUFF) dev->stats.rx_fifo_errors++; head->flag &= (RMD1_ENP|RMD1_STP); } else { /* Malloc up new buffer, compatible with net-3. */ short pkt_len = head->msg_length & 0xfff; struct sk_buff *skb; if (pkt_len < 60) { printk( "%s: Runt packet!\n", dev->name ); dev->stats.rx_errors++; } else { skb = dev_alloc_skb( pkt_len+2 ); if (skb == NULL) { DPRINTK( 1, ( "%s: Memory squeeze, deferring packet.\n", dev->name )); for( i = 0; i < RX_RING_SIZE; i++ ) if (MEM->rx_head[(entry+i) & RX_RING_MOD_MASK].flag & RMD1_OWN_CHIP) break; if (i > RX_RING_SIZE - 2) { dev->stats.rx_dropped++; head->flag |= RMD1_OWN_CHIP; lp->cur_rx++; } break; } if (lance_debug >= 3) { u_char *data = PKTBUF_ADDR(head); DECLARE_MAC_BUF(mac); DECLARE_MAC_BUF(mac2); printk(KERN_DEBUG "%s: RX pkt type 0x%04x from %s to %s " "data %02x %02x %02x %02x %02x %02x %02x %02x " "len %d\n", dev->name, ((u_short *)data)[6], print_mac(mac, &data[6]), print_mac(mac2, data), data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], pkt_len); } skb_reserve( skb, 2 ); /* 16 byte align */ skb_put( skb, pkt_len ); /* Make room */ lp->memcpy_f( skb->data, PKTBUF_ADDR(head), pkt_len ); skb->protocol = eth_type_trans( skb, dev ); netif_rx( skb ); dev->last_rx = jiffies; dev->stats.rx_packets++; dev->stats.rx_bytes += pkt_len; } } head->flag |= RMD1_OWN_CHIP; entry = (++lp->cur_rx) & RX_RING_MOD_MASK; } lp->cur_rx &= RX_RING_MOD_MASK; /* From lance.c (Donald Becker): */ /* We should check that at least two ring entries are free. If not, we should free one and mark stats->rx_dropped++. */ return 0;}static int lance_close( struct net_device *dev ){ struct lance_private *lp = (struct lance_private *)dev->priv; struct lance_ioreg *IO = lp->iobase; netif_stop_queue (dev); AREG = CSR0; DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n", dev->name, DREG )); /* We stop the LANCE here -- it occasionally polls memory if we don't. */ DREG = CSR0_STOP; return 0;}/* Set or clear the multicast filter for this adaptor. num_addrs == -1 Promiscuous mode, receive all packets num_addrs == 0 Normal mode, clear multicast list num_addrs > 0 Multicast mode, receive normal and MC packets, and do best-effort filtering. */static void set_multicast_list( struct net_device *dev ){ struct lance_private *lp = (struct lance_private *)dev->priv; struct lance_ioreg *IO = lp->iobase; if (netif_running(dev)) /* Only possible if board is already started */ return; /* We take the simple way out and always enable promiscuous mode. */ DREG = CSR0_STOP; /* Temporarily stop the lance. */ if (dev->flags & IFF_PROMISC) { /* Log any net taps. */ DPRINTK( 2, ( "%s: Promiscuous mode enabled.\n", dev->name )); REGA( CSR15 ) = 0x8000; /* Set promiscuous mode */ } else { short multicast_table[4]; int num_addrs = dev->mc_count; int i; /* We don't use the multicast table, but rely on upper-layer * filtering. */ memset( multicast_table, (num_addrs == 0) ? 0 : -1, sizeof(multicast_table) ); for( i = 0; i < 4; i++ ) REGA( CSR8+i ) = multicast_table[i]; REGA( CSR15 ) = 0; /* Unset promiscuous mode */ } /* * Always set BSWP after a STOP as STOP puts it back into * little endian mode. */ REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0); /* Resume normal operation and reset AREG to CSR0 */ REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT;}/* This is needed for old RieblCards and possible for new RieblCards */static int lance_set_mac_address( struct net_device *dev, void *addr ){ struct lance_private *lp = (struct lance_private *)dev->priv; struct sockaddr *saddr = addr; int i; if (lp->cardtype != OLD_RIEBL && lp->cardtype != NEW_RIEBL) return( -EOPNOTSUPP ); if (netif_running(dev)) { /* Only possible while card isn't started */ DPRINTK( 1, ( "%s: hwaddr can be set only while card isn't open.\n", dev->name )); return( -EIO ); } memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len ); for( i = 0; i < 6; i++ ) MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */ lp->memcpy_f( RIEBL_HWADDR_ADDR, dev->dev_addr, 6 ); /* set also the magic for future sessions */ *RIEBL_MAGIC_ADDR = RIEBL_MAGIC; return( 0 );}#ifdef MODULEstatic struct net_device *atarilance_dev;int __init init_module(void){ atarilance_dev = atarilance_probe(-1); if (IS_ERR(atarilance_dev)) return PTR_ERR(atarilance_dev); return 0;}void __exit cleanup_module(void){ unregister_netdev(atarilance_dev); free_irq(atarilance_dev->irq, atarilance_dev); free_netdev(atarilance_dev);}#endif /* MODULE *//* * Local variables: * c-indent-level: 4 * tab-width: 4 * End: */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?