53 #include <linux/errno.h>
54 #include <linux/if_ether.h>
56 #include <linux/kernel.h>
57 #include <linux/module.h>
58 #include <linux/netdevice.h>
61 #include <linux/stddef.h>
62 #include <linux/string.h>
64 #include <linux/types.h>
66 #include <asm/addrspace.h>
76 "declance.c: v0.011 by Linux MIPS DECstation task force\n";
82 #define __unused __attribute__ ((unused))
97 #define LE_MO_PROM 0x8000
99 #define LE_C0_ERR 0x8000
100 #define LE_C0_BABL 0x4000
101 #define LE_C0_CERR 0x2000
102 #define LE_C0_MISS 0x1000
103 #define LE_C0_MERR 0x0800
104 #define LE_C0_RINT 0x0400
105 #define LE_C0_TINT 0x0200
106 #define LE_C0_IDON 0x0100
107 #define LE_C0_INTR 0x0080
108 #define LE_C0_INEA 0x0040
109 #define LE_C0_RXON 0x0020
110 #define LE_C0_TXON 0x0010
111 #define LE_C0_TDMD 0x0008
112 #define LE_C0_STOP 0x0004
113 #define LE_C0_STRT 0x0002
114 #define LE_C0_INIT 0x0001
116 #define LE_C3_BSWP 0x4
117 #define LE_C3_ACON 0x2
118 #define LE_C3_BCON 0x1
121 #define LE_R1_OWN 0x8000
122 #define LE_R1_ERR 0x4000
123 #define LE_R1_FRA 0x2000
124 #define LE_R1_OFL 0x1000
125 #define LE_R1_CRC 0x0800
126 #define LE_R1_BUF 0x0400
127 #define LE_R1_SOP 0x0200
128 #define LE_R1_EOP 0x0100
129 #define LE_R1_POK 0x0300
132 #define LE_T1_OWN 0x8000
133 #define LE_T1_ERR 0x4000
134 #define LE_T1_EMORE 0x1000
135 #define LE_T1_EONE 0x0800
136 #define LE_T1_EDEF 0x0400
137 #define LE_T1_SOP 0x0200
138 #define LE_T1_EOP 0x0100
139 #define LE_T1_POK 0x0300
141 #define LE_T3_BUF 0x8000
142 #define LE_T3_UFL 0x4000
143 #define LE_T3_LCOL 0x1000
144 #define LE_T3_CLOS 0x0800
145 #define LE_T3_RTY 0x0400
146 #define LE_T3_TDR 0x03ff
150 #ifndef LANCE_LOG_TX_BUFFERS
151 #define LANCE_LOG_TX_BUFFERS 4
152 #define LANCE_LOG_RX_BUFFERS 4
155 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
156 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
158 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
159 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
161 #define PKT_BUF_SZ 1536
162 #define RX_BUFF_SIZE PKT_BUF_SZ
163 #define TX_BUFF_SIZE PKT_BUF_SZ
225 #define BUF_OFFSET_CPU sizeof(struct lance_init_block)
226 #define BUF_OFFSET_LNC sizeof(struct lance_init_block)
228 #define shift_off(off, type) \
229 (type == ASIC_LANCE || type == PMAX_LANCE ? off << 1 : off)
231 #define lib_off(rt, type) \
232 shift_off(offsetof(struct lance_init_block, rt), type)
234 #define lib_ptr(ib, rt, type) \
235 ((volatile u16 *)((u8 *)(ib) + lib_off(rt, type)))
237 #define rds_off(rt, type) \
238 shift_off(offsetof(struct lance_rx_desc, rt), type)
240 #define rds_ptr(rd, rt, type) \
241 ((volatile u16 *)((u8 *)(rd) + rds_off(rt, type)))
243 #define tds_off(rt, type) \
244 shift_off(offsetof(struct lance_tx_desc, rt), type)
246 #define tds_ptr(td, rt, type) \
247 ((volatile u16 *)((u8 *)(td) + tds_off(rt, type)))
273 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
274 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
275 lp->tx_old - lp->tx_new-1)
284 volatile unsigned short rdp;
286 volatile unsigned short rap;
291 static struct tc_driver dec_lance_tc_driver;
326 static void cp_to_buf(
const int type,
void *to,
const void *
from,
int len)
329 const unsigned short *
fp;
332 const unsigned char *rfp;
375 rtp = (
unsigned char *) tp;
376 rfp = (
unsigned char *) fp;
385 static void cp_from_buf(
const int type,
void *to,
const void *from,
int len)
388 const unsigned short *
fp;
391 const unsigned char *rfp;
436 rtp = (
unsigned char *) tp;
437 rfp = (
unsigned char *) fp;
456 netif_stop_queue(dev);
477 printk(
"RX ptr: %8.8x(%8.8x)\n",
486 printk(
"TX ptr: %8.8x(%8.8x)\n",
496 *
lib_ptr(ib, btx_ring[
i].tmd1, lp->
type) = (leptr >> 16) &
502 printk(
"%d: 0x%8.8x(0x%8.8x)\n",
512 *
lib_ptr(ib, brx_ring[
i].rmd1, lp->
type) = ((leptr >> 16) &
519 printk(
"%d: 0x%8.8x(0x%8.8x)\n",
538 printk(
"LANCE unopened after %d ticks, csr0=%4.4x.\n",
543 printk(
"LANCE unopened after %d ticks, csr0=%4.4x.\n",
589 dev->
stats.rx_over_errors++;
590 dev->
stats.rx_errors++;
596 dev->
stats.rx_fifo_errors++;
598 dev->
stats.rx_crc_errors++;
600 dev->
stats.rx_over_errors++;
602 dev->
stats.rx_frame_errors++;
604 dev->
stats.rx_errors++;
607 skb = netdev_alloc_skb(dev, len + 2);
610 printk(
"%s: Memory squeeze, deferring packet.\n",
612 dev->
stats.rx_dropped++;
620 dev->
stats.rx_bytes += len;
625 cp_from_buf(lp->
type,
skb->data,
630 dev->
stats.rx_packets++;
654 spin_lock(&lp->
lock);
656 for (i =
j; i != lp->
tx_new; i =
j) {
665 dev->
stats.tx_errors++;
667 dev->
stats.tx_aborted_errors++;
669 dev->
stats.tx_window_errors++;
672 dev->
stats.tx_carrier_errors++;
677 lance_init_ring(dev);
679 init_restart_lance(lp);
686 dev->
stats.tx_fifo_errors++;
688 printk(
"%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
693 lance_init_ring(dev);
695 init_restart_lance(lp);
707 dev->
stats.collisions++;
711 dev->
stats.collisions += 2;
713 dev->
stats.tx_packets++;
719 if (netif_queue_stopped(dev) &&
721 netif_wake_queue(dev);
723 spin_unlock(&lp->
lock);
759 dev->
stats.tx_errors++;
762 dev->
stats.rx_errors++;
765 printk(
"%s: Memory error, status %04x\n", dev->
name, csr0);
769 lance_init_ring(dev);
771 init_restart_lance(lp);
772 netif_wake_queue(dev);
803 lance_init_ring(dev);
806 netif_start_queue(dev);
817 "lance error", dev)) {
819 printk(
"%s: Can't get DMA IRQ %d\n", dev->
name,
832 spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
835 status = init_restart_lance(lp);
844 netif_stop_queue(dev);
862 spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
870 static inline int lance_reset(
struct net_device *dev)
880 lance_init_ring(dev);
883 status = init_restart_lance(lp);
895 netif_wake_queue(dev);
914 dev->
stats.tx_bytes += len;
931 netif_stop_queue(dev);
936 spin_unlock_irqrestore(&lp->
lock, flags);
943 static void lance_load_multicast(
struct net_device *dev)
978 if (!netif_running(dev))
983 netif_wake_queue(dev);
987 netif_stop_queue(dev);
992 lance_init_ring(dev);
998 lance_load_multicast(dev);
1001 init_restart_lance(lp);
1002 netif_wake_queue(dev);
1005 static void lance_set_multicast_retry(
unsigned long _opaque)
1023 static int __devinit dec_lance_probe(
struct device *bdev,
const int type)
1025 static unsigned version_printed;
1026 static const char fmt[] =
"declance%d";
1033 unsigned long esar_base;
1034 unsigned char *esar;
1040 snprintf(name,
sizeof(name),
"%s", dev_name(bdev));
1043 dev = root_lance_dev;
1046 lp = netdev_priv(dev);
1049 snprintf(name,
sizeof(name), fmt, i);
1062 lp = netdev_priv(dev);
1114 start =
to_tc_dev(bdev)->resource.start;
1115 len =
to_tc_dev(bdev)->resource.end - start + 1;
1118 "%s: Unable to reserve MMIO resource\n",
1190 esar = (
unsigned char *) esar_base;
1194 if (esar[0x60] != 0xff && esar[0x64] != 0x00 &&
1195 esar[0x68] != 0x55 && esar[0x6c] != 0xaa) {
1197 "%s: Ethernet station address prom not found!\n",
1200 goto err_out_resource;
1203 for (i = 0; i < 8; i++) {
1204 if (esar[i * 4] != esar[0x3c - i * 4] &&
1205 esar[i * 4] != esar[0x40 + i * 4] &&
1206 esar[0x3c - i * 4] != esar[0x40 + i * 4]) {
1208 "ethernet station address prom!\n", name);
1210 goto err_out_resource;
1220 printk(
"%s: IOASIC onboard LANCE", name);
1223 printk(
"%s: PMAD-AA", name);
1226 printk(
"%s: PMAX onboard LANCE", name);
1229 for (i = 0; i < 6; i++)
1259 "%s: Unable to register netdev, aborting.\n", name);
1260 goto err_out_resource;
1264 lp->
next = root_lance_dev;
1265 root_lance_dev =
dev;
1268 printk(
"%s: registered as %s.\n", name, dev->
name);
1282 static void __exit dec_lance_remove(
struct device *bdev)
1288 start =
to_tc_dev(bdev)->resource.start;
1289 len =
to_tc_dev(bdev)->resource.end - start + 1;
1295 static int __init dec_lance_platform_probe(
void)
1309 return (count > 0) ? 0 : -
ENODEV;
1312 static void __exit dec_lance_platform_remove(
void)
1314 while (root_lance_dev) {
1319 root_lance_dev = lp->
next;
1326 static int __exit dec_lance_tc_remove(
struct device *dev);
1328 static const struct tc_device_id dec_lance_tc_table[] = {
1329 {
"DEC ",
"PMAD-AA " },
1334 static struct tc_driver dec_lance_tc_driver = {
1335 .id_table = dec_lance_tc_table,
1339 .probe = dec_lance_tc_probe,
1340 .remove =
__exit_p(dec_lance_tc_remove),
1346 int status = dec_lance_probe(dev,
PMAD_LANCE);
1352 static int __exit dec_lance_tc_remove(
struct device *dev)
1355 dec_lance_remove(dev);
1360 static int __init dec_lance_init(
void)
1366 dec_lance_platform_probe();
1370 static void __exit dec_lance_exit(
void)
1372 dec_lance_platform_remove();