72 static char lancestr[] =
"LANCE";
74 #include <linux/module.h>
75 #include <linux/kernel.h>
76 #include <linux/types.h>
77 #include <linux/fcntl.h>
81 #include <linux/string.h>
85 #include <linux/errno.h>
86 #include <linux/socket.h>
88 #include <linux/netdevice.h>
91 #include <linux/ethtool.h>
92 #include <linux/bitops.h>
100 #include <asm/pgtable.h>
101 #include <asm/byteorder.h>
102 #include <asm/idprom.h>
103 #include <asm/prom.h>
107 #define DRV_NAME "sunlance"
108 #define DRV_VERSION "2.02"
109 #define DRV_RELDATE "8/24/03"
121 #ifndef LANCE_LOG_TX_BUFFERS
122 #define LANCE_LOG_TX_BUFFERS 4
123 #define LANCE_LOG_RX_BUFFERS 4
131 #define LE_MO_PROM 0x8000
133 #define LE_C0_ERR 0x8000
134 #define LE_C0_BABL 0x4000
135 #define LE_C0_CERR 0x2000
136 #define LE_C0_MISS 0x1000
137 #define LE_C0_MERR 0x0800
138 #define LE_C0_RINT 0x0400
139 #define LE_C0_TINT 0x0200
140 #define LE_C0_IDON 0x0100
141 #define LE_C0_INTR 0x0080
142 #define LE_C0_INEA 0x0040
143 #define LE_C0_RXON 0x0020
144 #define LE_C0_TXON 0x0010
145 #define LE_C0_TDMD 0x0008
146 #define LE_C0_STOP 0x0004
147 #define LE_C0_STRT 0x0002
148 #define LE_C0_INIT 0x0001
150 #define LE_C3_BSWP 0x4
151 #define LE_C3_ACON 0x2
152 #define LE_C3_BCON 0x1
155 #define LE_R1_OWN 0x80
156 #define LE_R1_ERR 0x40
157 #define LE_R1_FRA 0x20
158 #define LE_R1_OFL 0x10
159 #define LE_R1_CRC 0x08
160 #define LE_R1_BUF 0x04
161 #define LE_R1_SOP 0x02
162 #define LE_R1_EOP 0x01
163 #define LE_R1_POK 0x03
165 #define LE_T1_OWN 0x80
166 #define LE_T1_ERR 0x40
167 #define LE_T1_EMORE 0x10
168 #define LE_T1_EONE 0x08
169 #define LE_T1_EDEF 0x04
170 #define LE_T1_SOP 0x02
171 #define LE_T1_EOP 0x01
172 #define LE_T1_POK 0x03
174 #define LE_T3_BUF 0x8000
175 #define LE_T3_UFL 0x4000
176 #define LE_T3_LCOL 0x1000
177 #define LE_T3_CLOS 0x0800
178 #define LE_T3_RTY 0x0400
179 #define LE_T3_TDR 0x03ff
181 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
182 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
183 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
184 #define TX_NEXT(__x) (((__x)+1) & TX_RING_MOD_MASK)
186 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
187 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
188 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
189 #define RX_NEXT(__x) (((__x)+1) & RX_RING_MOD_MASK)
191 #define PKT_BUF_SZ 1544
192 #define RX_BUFF_SIZE PKT_BUF_SZ
193 #define TX_BUFF_SIZE PKT_BUF_SZ
235 #define libdesc_offset(rt, elem) \
236 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem])))))
238 #define libbuff_offset(rt, elem) \
239 ((__u32)(((unsigned long)(&(((struct lance_init_block *)0)->rt[elem][0])))))
272 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
273 lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
274 lp->tx_old - lp->tx_new-1)
279 #define LANCE_REG_SIZE 0x04UL
281 #define STOP_LANCE(__lp) \
282 do { void __iomem *__base = (__lp)->lregs; \
283 sbus_writew(LE_CSR0, __base + RAP); \
284 sbus_writew(LE_C0_STOP, __base + RDP); \
297 #define LANCE_ADDR(x) ((long)(x) & ~0xff000000)
330 netif_stop_queue(dev);
348 ib->
btx_ring [
i].tmd1_hadr = leptr >> 16;
359 ib->
brx_ring [
i].rmd1_hadr = leptr >> 16;
369 ib->
rx_len = (LANCE_LOG_RX_BUFFERS << 13) | (leptr >> 16);
374 ib->
tx_len = (LANCE_LOG_TX_BUFFERS << 13) | (leptr >> 16);
378 static void lance_init_ring_pio(
struct net_device *dev)
386 netif_stop_queue(dev);
473 init_restart_ledma(lp);
479 for (i = 0; i < 100; i++) {
508 static void lance_rx_dvma(
struct net_device *dev)
523 dev->
stats.rx_over_errors++;
524 dev->
stats.rx_errors++;
536 skb = netdev_alloc_skb(dev, len + 2);
541 dev->
stats.rx_dropped++;
552 skb_copy_to_linear_data(skb,
553 (
unsigned char *)&(ib->
rx_buf [entry][0]),
557 dev->
stats.rx_packets++;
569 static void lance_tx_dvma(
struct net_device *dev)
575 spin_lock(&lp->
lock);
578 for (i = j; i != lp->
tx_new; i =
j) {
589 dev->
stats.tx_errors++;
594 dev->
stats.tx_carrier_errors++;
598 dev->
name, lp->
tpe?
"TPE":
"AUI");
602 init_restart_lance(lp);
611 dev->
stats.tx_fifo_errors++;
618 init_restart_lance(lp);
621 }
else if ((bits &
LE_T1_POK) == LE_T1_POK) {
629 dev->
stats.collisions++;
633 dev->
stats.collisions += 2;
635 dev->
stats.tx_packets++;
642 if (netif_queue_stopped(dev) &&
644 netif_wake_queue(dev);
646 spin_unlock(&lp->
lock);
649 static void lance_piocopy_to_skb(
struct sk_buff *skb,
void __iomem *piobuf,
int len)
679 static void lance_rx_pio(
struct net_device *dev)
694 if ((bits & LE_R1_POK) != LE_R1_POK) {
695 dev->
stats.rx_over_errors++;
696 dev->
stats.rx_errors++;
697 }
else if (bits & LE_R1_ERR) {
701 if (bits & LE_R1_BUF) dev->
stats.rx_fifo_errors++;
702 if (bits & LE_R1_CRC) dev->
stats.rx_crc_errors++;
703 if (bits & LE_R1_OFL) dev->
stats.rx_over_errors++;
704 if (bits & LE_R1_FRA) dev->
stats.rx_frame_errors++;
708 skb = netdev_alloc_skb(dev, len + 2);
713 dev->
stats.rx_dropped++;
722 skb_reserve (skb, 2);
724 lance_piocopy_to_skb(skb, &(ib->
rx_buf[entry][0]), len);
727 dev->
stats.rx_packets++;
739 static void lance_tx_pio(
struct net_device *dev)
745 spin_lock(&lp->
lock);
748 for (i = j; i != lp->
tx_new; i =
j) {
753 if (bits & LE_T1_OWN)
756 if (bits & LE_T1_ERR) {
759 dev->
stats.tx_errors++;
760 if (status & LE_T3_RTY) dev->
stats.tx_aborted_errors++;
761 if (status & LE_T3_LCOL) dev->
stats.tx_window_errors++;
763 if (status & LE_T3_CLOS) {
764 dev->
stats.tx_carrier_errors++;
768 dev->
name, lp->
tpe?
"TPE":
"AUI");
772 init_restart_lance(lp);
781 dev->
stats.tx_fifo_errors++;
788 init_restart_lance(lp);
791 }
else if ((bits & LE_T1_POK) == LE_T1_POK) {
799 dev->
stats.collisions++;
803 dev->
stats.collisions += 2;
805 dev->
stats.tx_packets++;
812 if (netif_queue_stopped(dev) &&
814 netif_wake_queue(dev);
816 spin_unlock(&lp->
lock);
832 if ((csr0 & LE_C0_ERR) != 0) {
846 dev->
stats.tx_errors++;
849 dev->
stats.rx_errors++;
856 dev->
name, csr0, addr & 0xffffff);
873 init_restart_lance(lp);
874 netif_wake_queue(dev);
895 for (i = 0; i < 6; i++) {
907 for (i = 0; i < 6; i++) {
926 lancestr, (
void *) dev)) {
959 netif_start_queue(dev);
961 status = init_restart_lance(lp);
963 build_fake_packet(lp);
974 netif_stop_queue(dev);
983 static int lance_reset(
struct net_device *dev)
1006 status = init_restart_lance(lp);
1010 static void lance_piocopy_from_skb(
void __iomem *
dest,
unsigned char *
src,
int len)
1017 switch ((
unsigned long)src & 0x3) {
1048 u32 val = p16[0]<<16 | p16[1];
1058 u16 val = src[0] << 8 | src[1];
1068 static void lance_piozero(
void __iomem *dest,
int len)
1072 if ((
unsigned long)piobuf & 1) {
1083 if ((
unsigned long)piobuf & 2) {
1111 netif_wake_queue(dev);
1117 int entry, skblen, len;
1123 spin_lock_irq(&lp->
lock);
1125 dev->
stats.tx_bytes += len;
1132 lance_piocopy_from_skb(&ib->
tx_buf[entry][0], skb->
data, skblen);
1134 lance_piozero(&ib->
tx_buf[entry][skblen], len - skblen);
1140 skb_copy_from_linear_data(skb, &ib->
tx_buf [entry][0], skblen);
1142 memset((
char *) &ib->
tx_buf [entry][skblen], 0, len - skblen);
1149 netif_stop_queue(dev);
1160 spin_unlock_irq(&lp->
lock);
1168 static void lance_load_multicast(
struct net_device *dev)
1202 tmp |= 1 << (crc & 0xf);
1207 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
1219 if (!netif_running(dev))
1224 netif_wake_queue(dev);
1228 netif_stop_queue(dev);
1236 mode = ib_mem->
mode;
1249 lance_load_multicast(dev);
1252 init_restart_lance(lp);
1253 netif_wake_queue(dev);
1256 static void lance_set_multicast_retry(
unsigned long _opaque)
1263 static void lance_free_hwresources(
struct lance_private *lp)
1271 resource_size(&ledma->
resource[0]));
1291 static const struct ethtool_ops sparc_lance_ethtool_ops = {
1292 .get_drvinfo = sparc_lance_get_drvinfo,
1312 static unsigned version_printed;
1321 lp = netdev_priv(dev);
1332 for (i = 0; i < 6; i++)
1346 resource_size(&ledma->
resource[0]),
1350 "ledma registers.\n");
1359 if (lebuffer->
resource[0].start & 7) {
1360 printk(
KERN_ERR "SunLance: ERROR: Rx and Tx rings not on even boundary.\n");
1373 lp->
rx = lance_rx_pio;
1374 lp->
tx = lance_tx_pio;
1381 printk(
KERN_ERR "SunLance: Cannot allocate consistent DMA memory.\n");
1386 lp->
rx = lance_rx_dvma;
1387 lp->
tx = lance_tx_dvma;
1394 lp->
name = lancestr;
1400 unsigned int sbmask;
1409 sbus_dp = ledma_dp->
parent;
1416 if (!prop || prop[0] ==
'\0') {
1420 "auto-carrier-detection.\n");
1430 if (
strcmp(prop,
"true")) {
1432 "'tpe-link-test?'\n");
1440 }
else if (!
strcmp(prop,
"aui")) {
1486 lance_free_hwresources(lp);
1498 err = sparc_lance_probe_one(op, parent,
NULL);
1499 }
else if (!
strcmp(parent_dp->
name,
"lebuffer")) {
1500 err = sparc_lance_probe_one(op,
NULL, parent);
1502 err = sparc_lance_probe_one(op,
NULL,
NULL);
1514 lance_free_hwresources(lp);
1523 static const struct of_device_id sunlance_sbus_match[] = {
1536 .of_match_table = sunlance_sbus_match,
1538 .probe = sunlance_sbus_probe,