37 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40 #include <linux/module.h>
41 #include <linux/stddef.h>
42 #include <linux/kernel.h>
43 #include <linux/string.h>
44 #include <linux/errno.h>
46 #include <linux/netdevice.h>
52 #include <linux/bitops.h>
69 #define swapw(x) (((x >> 8) & 0x00ff) | ((x << 8) & 0xff00))
71 #define lowb(x) (x & 0xff)
73 #define swhighw(x) ((((x) >> 8) & 0xff00) | (((x) >> 24) & 0x00ff))
75 #define swloww(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
79 #define TX_RING_SIZE 5
80 #define RX_RING_SIZE 16
82 #define PKT_BUF_SIZE 1520
108 *(dest++) = *(src++);
112 *dest = (*(
u_char *)src) << 8;
121 netif_stop_queue(dev);
133 offsetof(
struct lancedata, tx_buff[
i])) |
139 netdev_dbg(dev,
"TX Entry %2d at %p, Buf at %p\n",
149 offsetof(
struct lancedata, rx_buff[
i])) |
155 netdev_dbg(dev,
"RX Entry %2d at %p, Buf at %p\n",
179 dev->
stats.rx_errors++;
181 dev->
stats.rx_frame_errors++;
183 dev->
stats.rx_over_errors++;
185 dev->
stats.rx_crc_errors++;
187 dev->
stats.rx_fifo_errors++;
194 skb = netdev_alloc_skb(dev, pkt_len + 2);
196 netdev_warn(dev,
"Memory squeeze, deferring packet\n");
198 if (
lowb(priv->
rx_ring[(entry + i) % RX_RING_SIZE]->RMD1) & RF_OWN)
201 if (i > RX_RING_SIZE - 2) {
202 dev->
stats.rx_dropped++;
212 skb_copy_to_linear_data(skb,
213 (
const void *)priv->
rx_buff[entry],
216 netdev_dbg(dev,
"RX pkt type 0x%04x from %pM to %pM data %p len %u\n",
222 dev->
stats.rx_packets++;
227 entry = (++priv->
cur_rx) % RX_RING_SIZE;
252 priv = netdev_priv(dev);
255 while ((csr0 = lance->
RDP) & (
ERR |
RINT |
TINT) && --boguscnt >= 0) {
261 netdev_dbg(dev,
"interrupt csr0=%#02x new csr=%#02x [",
308 while (dirty_tx < priv->cur_tx) {
320 dev->
stats.tx_errors++;
322 dev->
stats.tx_aborted_errors++;
324 dev->
stats.tx_carrier_errors++;
326 dev->
stats.tx_window_errors++;
329 dev->
stats.tx_fifo_errors++;
331 netdev_err(dev,
"Tx FIFO error! Status %04x\n",
338 dev->
stats.collisions++;
339 dev->
stats.tx_packets++;
344 #ifndef final_version
345 if (priv->
cur_tx - dirty_tx >= TX_RING_SIZE) {
346 netdev_err(dev,
"out-of-sync dirty pointer, %d vs. %d, full=%d\n",
353 if (priv->
tx_full && netif_queue_stopped(dev) &&
354 dirty_tx > priv->
cur_tx - TX_RING_SIZE + 2) {
357 netif_wake_queue(dev);
366 dev->
stats.tx_errors++;
370 dev->
stats.rx_errors++;
374 netdev_err(dev,
"Bus master arbitration failure, status %04x\n",
383 lance->
RDP = INEA | BABL | CERR | MISS | MERR |
IDON;
386 netdev_dbg(dev,
"exiting interrupt, csr%d=%#04x\n",
392 static int ariadne_open(
struct net_device *dev)
411 if ((
version & 0x00000fff) != 0x00000003) {
412 pr_warn(
"Couldn't find AMD Ethernet Chip\n");
415 if ((
version & 0x0ffff000) != 0x00003000) {
416 pr_warn(
"Couldn't find Am79C960 (Wrong part number = %ld)\n",
421 netdev_dbg(dev,
"Am79C960 (PCnet-ISA) Revision %ld\n",
424 ariadne_init_ring(dev);
484 netif_start_queue(dev);
497 static int ariadne_close(
struct net_device *dev)
501 netif_stop_queue(dev);
508 netdev_dbg(dev,
"Shutting down ethercard, status was %02x\n",
511 dev->
stats.rx_missed_errors);
522 static inline void ariadne_reset(
struct net_device *dev)
528 ariadne_init_ring(dev);
530 netif_start_queue(dev);
533 static void ariadne_tx_timeout(
struct net_device *dev)
537 netdev_err(dev,
"transmit timed out, status %04x, resetting\n",
540 netif_wake_queue(dev);
569 netdev_dbg(dev,
"TX pkt type 0x%04x from %pM to %pM data %p len %u\n",
588 skb->
len > 64 ? 64 : skb->
len,
true);
597 if ((priv->
cur_tx >= TX_RING_SIZE) &&
600 netdev_dbg(dev,
"*** Subtracting TX_RING_SIZE from cur_tx (%d) and dirty_tx (%d)\n",
606 dev->
stats.tx_bytes += len;
612 if (
lowb(priv->
tx_ring[(entry + 1) % TX_RING_SIZE]->TMD1) != 0) {
613 netif_stop_queue(dev);
628 saved_addr = lance->
RAP;
631 lance->
RAP = saved_addr;
643 static void set_multicast_list(
struct net_device *dev)
647 if (!netif_running(dev))
650 netif_stop_queue(dev);
655 ariadne_init_ring(dev);
661 short multicast_table[4];
667 memset(multicast_table, (num_addrs == 0) ? 0 : -1,
668 sizeof(multicast_table));
669 for (i = 0; i < 4; i++) {
672 lance->
RDP =
swapw(multicast_table[i]);
679 lance->
RDP = INEA | STRT |
IDON;
681 netif_wake_queue(dev);
685 static void __devexit ariadne_remove_one(
struct zorro_dev *z)
687 struct net_device *dev = zorro_get_drvdata(z);
702 .ndo_open = ariadne_open,
703 .ndo_stop = ariadne_close,
704 .ndo_start_xmit = ariadne_start_xmit,
705 .ndo_tx_timeout = ariadne_tx_timeout,
706 .ndo_get_stats = ariadne_get_stats,
707 .ndo_set_rx_mode = set_multicast_list,
713 static int __devinit ariadne_init_one(
struct zorro_dev *z,
716 unsigned long board = z->resource.start;
740 priv = netdev_priv(dev);
748 dev->
dev_addr[3] = (z->rom.er_SerialNumber >> 16) & 0xff;
749 dev->
dev_addr[4] = (z->rom.er_SerialNumber >> 8) & 0xff;
750 dev->
dev_addr[5] = z->rom.er_SerialNumber & 0xff;
765 zorro_set_drvdata(z, dev);
767 netdev_info(dev,
"Ariadne at 0x%08lx, Ethernet Address %pM\n",
773 static struct zorro_driver ariadne_driver = {
775 .id_table = ariadne_zorro_tbl,
776 .probe = ariadne_init_one,
780 static int __init ariadne_init_module(
void)
785 static void __exit ariadne_cleanup_module(
void)