1b955f6caSJeff Kirsher /* 2b955f6caSJeff Kirsher * Amiga Linux/68k A2065 Ethernet Driver 3b955f6caSJeff Kirsher * 4b955f6caSJeff Kirsher * (C) Copyright 1995-2003 by Geert Uytterhoeven <geert@linux-m68k.org> 5b955f6caSJeff Kirsher * 6b955f6caSJeff Kirsher * Fixes and tips by: 7b955f6caSJeff Kirsher * - Janos Farkas (CHEXUM@sparta.banki.hu) 8b955f6caSJeff Kirsher * - Jes Degn Soerensen (jds@kom.auc.dk) 9b955f6caSJeff Kirsher * - Matt Domsch (Matt_Domsch@dell.com) 10b955f6caSJeff Kirsher * 11b955f6caSJeff Kirsher * ---------------------------------------------------------------------------- 12b955f6caSJeff Kirsher * 13b955f6caSJeff Kirsher * This program is based on 14b955f6caSJeff Kirsher * 15b955f6caSJeff Kirsher * ariadne.?: Amiga Linux/68k Ariadne Ethernet Driver 16b955f6caSJeff Kirsher * (C) Copyright 1995 by Geert Uytterhoeven, 17b955f6caSJeff Kirsher * Peter De Schrijver 18b955f6caSJeff Kirsher * 19b955f6caSJeff Kirsher * lance.c: An AMD LANCE ethernet driver for linux. 20b955f6caSJeff Kirsher * Written 1993-94 by Donald Becker. 21b955f6caSJeff Kirsher * 22b955f6caSJeff Kirsher * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller 23b955f6caSJeff Kirsher * Advanced Micro Devices 24b955f6caSJeff Kirsher * Publication #16907, Rev. B, Amendment/0, May 1994 25b955f6caSJeff Kirsher * 26b955f6caSJeff Kirsher * ---------------------------------------------------------------------------- 27b955f6caSJeff Kirsher * 28b955f6caSJeff Kirsher * This file is subject to the terms and conditions of the GNU General Public 29b955f6caSJeff Kirsher * License. See the file COPYING in the main directory of the Linux 30b955f6caSJeff Kirsher * distribution for more details. 31b955f6caSJeff Kirsher * 32b955f6caSJeff Kirsher * ---------------------------------------------------------------------------- 33b955f6caSJeff Kirsher * 34b955f6caSJeff Kirsher * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains: 35b955f6caSJeff Kirsher * 36b955f6caSJeff Kirsher * - an Am7990 Local Area Network Controller for Ethernet (LANCE) with 37b955f6caSJeff Kirsher * both 10BASE-2 (thin coax) and AUI (DB-15) connectors 38b955f6caSJeff Kirsher */ 39b955f6caSJeff Kirsher 40b955f6caSJeff Kirsher #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 41b955f6caSJeff Kirsher 42b955f6caSJeff Kirsher /*#define DEBUG*/ 43b955f6caSJeff Kirsher /*#define TEST_HITS*/ 44b955f6caSJeff Kirsher 45b955f6caSJeff Kirsher #include <linux/errno.h> 46b955f6caSJeff Kirsher #include <linux/netdevice.h> 47b955f6caSJeff Kirsher #include <linux/etherdevice.h> 48b955f6caSJeff Kirsher #include <linux/module.h> 49b955f6caSJeff Kirsher #include <linux/stddef.h> 50b955f6caSJeff Kirsher #include <linux/kernel.h> 51b955f6caSJeff Kirsher #include <linux/interrupt.h> 52b955f6caSJeff Kirsher #include <linux/ioport.h> 53b955f6caSJeff Kirsher #include <linux/skbuff.h> 54b955f6caSJeff Kirsher #include <linux/string.h> 55b955f6caSJeff Kirsher #include <linux/init.h> 56b955f6caSJeff Kirsher #include <linux/crc32.h> 57b955f6caSJeff Kirsher #include <linux/zorro.h> 58b955f6caSJeff Kirsher #include <linux/bitops.h> 59b955f6caSJeff Kirsher 60bd9ba8f4SGeert Uytterhoeven #include <asm/byteorder.h> 61b955f6caSJeff Kirsher #include <asm/irq.h> 62b955f6caSJeff Kirsher #include <asm/amigaints.h> 63b955f6caSJeff Kirsher #include <asm/amigahw.h> 64b955f6caSJeff Kirsher 65b955f6caSJeff Kirsher #include "a2065.h" 66b955f6caSJeff Kirsher 67b955f6caSJeff Kirsher /* Transmit/Receive Ring Definitions */ 68b955f6caSJeff Kirsher 69b955f6caSJeff Kirsher #define LANCE_LOG_TX_BUFFERS (2) 70b955f6caSJeff Kirsher #define LANCE_LOG_RX_BUFFERS (4) 71b955f6caSJeff Kirsher 72b955f6caSJeff Kirsher #define TX_RING_SIZE (1 << LANCE_LOG_TX_BUFFERS) 73b955f6caSJeff Kirsher #define RX_RING_SIZE (1 << LANCE_LOG_RX_BUFFERS) 74b955f6caSJeff Kirsher 75b955f6caSJeff Kirsher #define TX_RING_MOD_MASK (TX_RING_SIZE - 1) 76b955f6caSJeff Kirsher #define RX_RING_MOD_MASK (RX_RING_SIZE - 1) 77b955f6caSJeff Kirsher 78b955f6caSJeff Kirsher #define PKT_BUF_SIZE (1544) 79b955f6caSJeff Kirsher #define RX_BUFF_SIZE PKT_BUF_SIZE 80b955f6caSJeff Kirsher #define TX_BUFF_SIZE PKT_BUF_SIZE 81b955f6caSJeff Kirsher 82b955f6caSJeff Kirsher /* Layout of the Lance's RAM Buffer */ 83b955f6caSJeff Kirsher 84b955f6caSJeff Kirsher struct lance_init_block { 85b955f6caSJeff Kirsher unsigned short mode; /* Pre-set mode (reg. 15) */ 86b955f6caSJeff Kirsher unsigned char phys_addr[6]; /* Physical ethernet address */ 87b955f6caSJeff Kirsher unsigned filter[2]; /* Multicast filter. */ 88b955f6caSJeff Kirsher 89b955f6caSJeff Kirsher /* Receive and transmit ring base, along with extra bits. */ 90b955f6caSJeff Kirsher unsigned short rx_ptr; /* receive descriptor addr */ 91b955f6caSJeff Kirsher unsigned short rx_len; /* receive len and high addr */ 92b955f6caSJeff Kirsher unsigned short tx_ptr; /* transmit descriptor addr */ 93b955f6caSJeff Kirsher unsigned short tx_len; /* transmit len and high addr */ 94b955f6caSJeff Kirsher 95b955f6caSJeff Kirsher /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */ 96b955f6caSJeff Kirsher struct lance_rx_desc brx_ring[RX_RING_SIZE]; 97b955f6caSJeff Kirsher struct lance_tx_desc btx_ring[TX_RING_SIZE]; 98b955f6caSJeff Kirsher 99b955f6caSJeff Kirsher char rx_buf[RX_RING_SIZE][RX_BUFF_SIZE]; 100b955f6caSJeff Kirsher char tx_buf[TX_RING_SIZE][TX_BUFF_SIZE]; 101b955f6caSJeff Kirsher }; 102b955f6caSJeff Kirsher 103b955f6caSJeff Kirsher /* Private Device Data */ 104b955f6caSJeff Kirsher 105b955f6caSJeff Kirsher struct lance_private { 106b955f6caSJeff Kirsher char *name; 107b955f6caSJeff Kirsher volatile struct lance_regs *ll; 108b955f6caSJeff Kirsher volatile struct lance_init_block *init_block; /* Hosts view */ 109b955f6caSJeff Kirsher volatile struct lance_init_block *lance_init_block; /* Lance view */ 110b955f6caSJeff Kirsher 111b955f6caSJeff Kirsher int rx_new, tx_new; 112b955f6caSJeff Kirsher int rx_old, tx_old; 113b955f6caSJeff Kirsher 114b955f6caSJeff Kirsher int lance_log_rx_bufs, lance_log_tx_bufs; 115b955f6caSJeff Kirsher int rx_ring_mod_mask, tx_ring_mod_mask; 116b955f6caSJeff Kirsher 117b955f6caSJeff Kirsher int tpe; /* cable-selection is TPE */ 118b955f6caSJeff Kirsher int auto_select; /* cable-selection by carrier */ 119b955f6caSJeff Kirsher unsigned short busmaster_regval; 120b955f6caSJeff Kirsher 121b955f6caSJeff Kirsher #ifdef CONFIG_SUNLANCE 122b955f6caSJeff Kirsher struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */ 123b955f6caSJeff Kirsher int burst_sizes; /* ledma SBus burst sizes */ 124b955f6caSJeff Kirsher #endif 125b955f6caSJeff Kirsher struct timer_list multicast_timer; 126b955f6caSJeff Kirsher }; 127b955f6caSJeff Kirsher 128b955f6caSJeff Kirsher #define LANCE_ADDR(x) ((int)(x) & ~0xff000000) 129b955f6caSJeff Kirsher 130b955f6caSJeff Kirsher /* Load the CSR registers */ 131b955f6caSJeff Kirsher static void load_csrs(struct lance_private *lp) 132b955f6caSJeff Kirsher { 133b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 134b955f6caSJeff Kirsher volatile struct lance_init_block *aib = lp->lance_init_block; 135b955f6caSJeff Kirsher int leptr = LANCE_ADDR(aib); 136b955f6caSJeff Kirsher 137b955f6caSJeff Kirsher ll->rap = LE_CSR1; 138b955f6caSJeff Kirsher ll->rdp = (leptr & 0xFFFF); 139b955f6caSJeff Kirsher ll->rap = LE_CSR2; 140b955f6caSJeff Kirsher ll->rdp = leptr >> 16; 141b955f6caSJeff Kirsher ll->rap = LE_CSR3; 142b955f6caSJeff Kirsher ll->rdp = lp->busmaster_regval; 143b955f6caSJeff Kirsher 144b955f6caSJeff Kirsher /* Point back to csr0 */ 145b955f6caSJeff Kirsher ll->rap = LE_CSR0; 146b955f6caSJeff Kirsher } 147b955f6caSJeff Kirsher 148b955f6caSJeff Kirsher /* Setup the Lance Rx and Tx rings */ 149b955f6caSJeff Kirsher static void lance_init_ring(struct net_device *dev) 150b955f6caSJeff Kirsher { 151b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 152b955f6caSJeff Kirsher volatile struct lance_init_block *ib = lp->init_block; 153b955f6caSJeff Kirsher volatile struct lance_init_block *aib = lp->lance_init_block; 154b955f6caSJeff Kirsher /* for LANCE_ADDR computations */ 155b955f6caSJeff Kirsher int leptr; 156b955f6caSJeff Kirsher int i; 157b955f6caSJeff Kirsher 158b955f6caSJeff Kirsher /* Lock out other processes while setting up hardware */ 159b955f6caSJeff Kirsher netif_stop_queue(dev); 160b955f6caSJeff Kirsher lp->rx_new = lp->tx_new = 0; 161b955f6caSJeff Kirsher lp->rx_old = lp->tx_old = 0; 162b955f6caSJeff Kirsher 163b955f6caSJeff Kirsher ib->mode = 0; 164b955f6caSJeff Kirsher 165b955f6caSJeff Kirsher /* Copy the ethernet address to the lance init block 166b955f6caSJeff Kirsher * Note that on the sparc you need to swap the ethernet address. 167b955f6caSJeff Kirsher */ 168b955f6caSJeff Kirsher ib->phys_addr[0] = dev->dev_addr[1]; 169b955f6caSJeff Kirsher ib->phys_addr[1] = dev->dev_addr[0]; 170b955f6caSJeff Kirsher ib->phys_addr[2] = dev->dev_addr[3]; 171b955f6caSJeff Kirsher ib->phys_addr[3] = dev->dev_addr[2]; 172b955f6caSJeff Kirsher ib->phys_addr[4] = dev->dev_addr[5]; 173b955f6caSJeff Kirsher ib->phys_addr[5] = dev->dev_addr[4]; 174b955f6caSJeff Kirsher 175b955f6caSJeff Kirsher /* Setup the Tx ring entries */ 176b955f6caSJeff Kirsher netdev_dbg(dev, "TX rings:\n"); 177b955f6caSJeff Kirsher for (i = 0; i <= 1 << lp->lance_log_tx_bufs; i++) { 178b955f6caSJeff Kirsher leptr = LANCE_ADDR(&aib->tx_buf[i][0]); 179b955f6caSJeff Kirsher ib->btx_ring[i].tmd0 = leptr; 180b955f6caSJeff Kirsher ib->btx_ring[i].tmd1_hadr = leptr >> 16; 181b955f6caSJeff Kirsher ib->btx_ring[i].tmd1_bits = 0; 182b955f6caSJeff Kirsher ib->btx_ring[i].length = 0xf000; /* The ones required by tmd2 */ 183b955f6caSJeff Kirsher ib->btx_ring[i].misc = 0; 184b955f6caSJeff Kirsher if (i < 3) 185b955f6caSJeff Kirsher netdev_dbg(dev, "%d: 0x%08x\n", i, leptr); 186b955f6caSJeff Kirsher } 187b955f6caSJeff Kirsher 188b955f6caSJeff Kirsher /* Setup the Rx ring entries */ 189b955f6caSJeff Kirsher netdev_dbg(dev, "RX rings:\n"); 190b955f6caSJeff Kirsher for (i = 0; i < 1 << lp->lance_log_rx_bufs; i++) { 191b955f6caSJeff Kirsher leptr = LANCE_ADDR(&aib->rx_buf[i][0]); 192b955f6caSJeff Kirsher 193b955f6caSJeff Kirsher ib->brx_ring[i].rmd0 = leptr; 194b955f6caSJeff Kirsher ib->brx_ring[i].rmd1_hadr = leptr >> 16; 195b955f6caSJeff Kirsher ib->brx_ring[i].rmd1_bits = LE_R1_OWN; 196b955f6caSJeff Kirsher ib->brx_ring[i].length = -RX_BUFF_SIZE | 0xf000; 197b955f6caSJeff Kirsher ib->brx_ring[i].mblength = 0; 198b955f6caSJeff Kirsher if (i < 3) 199b955f6caSJeff Kirsher netdev_dbg(dev, "%d: 0x%08x\n", i, leptr); 200b955f6caSJeff Kirsher } 201b955f6caSJeff Kirsher 202b955f6caSJeff Kirsher /* Setup the initialization block */ 203b955f6caSJeff Kirsher 204b955f6caSJeff Kirsher /* Setup rx descriptor pointer */ 205b955f6caSJeff Kirsher leptr = LANCE_ADDR(&aib->brx_ring); 206b955f6caSJeff Kirsher ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16); 207b955f6caSJeff Kirsher ib->rx_ptr = leptr; 208b955f6caSJeff Kirsher netdev_dbg(dev, "RX ptr: %08x\n", leptr); 209b955f6caSJeff Kirsher 210b955f6caSJeff Kirsher /* Setup tx descriptor pointer */ 211b955f6caSJeff Kirsher leptr = LANCE_ADDR(&aib->btx_ring); 212b955f6caSJeff Kirsher ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16); 213b955f6caSJeff Kirsher ib->tx_ptr = leptr; 214b955f6caSJeff Kirsher netdev_dbg(dev, "TX ptr: %08x\n", leptr); 215b955f6caSJeff Kirsher 216b955f6caSJeff Kirsher /* Clear the multicast filter */ 217b955f6caSJeff Kirsher ib->filter[0] = 0; 218b955f6caSJeff Kirsher ib->filter[1] = 0; 219b955f6caSJeff Kirsher } 220b955f6caSJeff Kirsher 221b955f6caSJeff Kirsher static int init_restart_lance(struct lance_private *lp) 222b955f6caSJeff Kirsher { 223b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 224b955f6caSJeff Kirsher int i; 225b955f6caSJeff Kirsher 226b955f6caSJeff Kirsher ll->rap = LE_CSR0; 227b955f6caSJeff Kirsher ll->rdp = LE_C0_INIT; 228b955f6caSJeff Kirsher 229b955f6caSJeff Kirsher /* Wait for the lance to complete initialization */ 230b955f6caSJeff Kirsher for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++) 231b955f6caSJeff Kirsher barrier(); 232b955f6caSJeff Kirsher if ((i == 100) || (ll->rdp & LE_C0_ERR)) { 233b955f6caSJeff Kirsher pr_err("unopened after %d ticks, csr0=%04x\n", i, ll->rdp); 234b955f6caSJeff Kirsher return -EIO; 235b955f6caSJeff Kirsher } 236b955f6caSJeff Kirsher 237b955f6caSJeff Kirsher /* Clear IDON by writing a "1", enable interrupts and start lance */ 238b955f6caSJeff Kirsher ll->rdp = LE_C0_IDON; 239b955f6caSJeff Kirsher ll->rdp = LE_C0_INEA | LE_C0_STRT; 240b955f6caSJeff Kirsher 241b955f6caSJeff Kirsher return 0; 242b955f6caSJeff Kirsher } 243b955f6caSJeff Kirsher 244b955f6caSJeff Kirsher static int lance_rx(struct net_device *dev) 245b955f6caSJeff Kirsher { 246b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 247b955f6caSJeff Kirsher volatile struct lance_init_block *ib = lp->init_block; 248b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 249b955f6caSJeff Kirsher volatile struct lance_rx_desc *rd; 250b955f6caSJeff Kirsher unsigned char bits; 251b955f6caSJeff Kirsher 252b955f6caSJeff Kirsher #ifdef TEST_HITS 253b955f6caSJeff Kirsher int i; 254b955f6caSJeff Kirsher char buf[RX_RING_SIZE + 1]; 255b955f6caSJeff Kirsher 256b955f6caSJeff Kirsher for (i = 0; i < RX_RING_SIZE; i++) { 257b955f6caSJeff Kirsher char r1_own = ib->brx_ring[i].rmd1_bits & LE_R1_OWN; 258b955f6caSJeff Kirsher if (i == lp->rx_new) 259b955f6caSJeff Kirsher buf[i] = r1_own ? '_' : 'X'; 260b955f6caSJeff Kirsher else 261b955f6caSJeff Kirsher buf[i] = r1_own ? '.' : '1'; 262b955f6caSJeff Kirsher } 263b955f6caSJeff Kirsher buf[RX_RING_SIZE] = 0; 264b955f6caSJeff Kirsher 265b955f6caSJeff Kirsher pr_debug("RxRing TestHits: [%s]\n", buf); 266b955f6caSJeff Kirsher #endif 267b955f6caSJeff Kirsher 268b955f6caSJeff Kirsher ll->rdp = LE_C0_RINT | LE_C0_INEA; 269b955f6caSJeff Kirsher for (rd = &ib->brx_ring[lp->rx_new]; 270b955f6caSJeff Kirsher !((bits = rd->rmd1_bits) & LE_R1_OWN); 271b955f6caSJeff Kirsher rd = &ib->brx_ring[lp->rx_new]) { 272b955f6caSJeff Kirsher 273b955f6caSJeff Kirsher /* We got an incomplete frame? */ 274b955f6caSJeff Kirsher if ((bits & LE_R1_POK) != LE_R1_POK) { 275b955f6caSJeff Kirsher dev->stats.rx_over_errors++; 276b955f6caSJeff Kirsher dev->stats.rx_errors++; 277b955f6caSJeff Kirsher continue; 278b955f6caSJeff Kirsher } else if (bits & LE_R1_ERR) { 279b955f6caSJeff Kirsher /* Count only the end frame as a rx error, 280b955f6caSJeff Kirsher * not the beginning 281b955f6caSJeff Kirsher */ 282b955f6caSJeff Kirsher if (bits & LE_R1_BUF) 283b955f6caSJeff Kirsher dev->stats.rx_fifo_errors++; 284b955f6caSJeff Kirsher if (bits & LE_R1_CRC) 285b955f6caSJeff Kirsher dev->stats.rx_crc_errors++; 286b955f6caSJeff Kirsher if (bits & LE_R1_OFL) 287b955f6caSJeff Kirsher dev->stats.rx_over_errors++; 288b955f6caSJeff Kirsher if (bits & LE_R1_FRA) 289b955f6caSJeff Kirsher dev->stats.rx_frame_errors++; 290b955f6caSJeff Kirsher if (bits & LE_R1_EOP) 291b955f6caSJeff Kirsher dev->stats.rx_errors++; 292b955f6caSJeff Kirsher } else { 293b955f6caSJeff Kirsher int len = (rd->mblength & 0xfff) - 4; 2941d266430SPradeep A Dalvi struct sk_buff *skb = netdev_alloc_skb(dev, len + 2); 295b955f6caSJeff Kirsher 296b955f6caSJeff Kirsher if (!skb) { 297b955f6caSJeff Kirsher dev->stats.rx_dropped++; 298b955f6caSJeff Kirsher rd->mblength = 0; 299b955f6caSJeff Kirsher rd->rmd1_bits = LE_R1_OWN; 300b955f6caSJeff Kirsher lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask; 301b955f6caSJeff Kirsher return 0; 302b955f6caSJeff Kirsher } 303b955f6caSJeff Kirsher 304b955f6caSJeff Kirsher skb_reserve(skb, 2); /* 16 byte align */ 305b955f6caSJeff Kirsher skb_put(skb, len); /* make room */ 306b955f6caSJeff Kirsher skb_copy_to_linear_data(skb, 307b955f6caSJeff Kirsher (unsigned char *)&ib->rx_buf[lp->rx_new][0], 308b955f6caSJeff Kirsher len); 309b955f6caSJeff Kirsher skb->protocol = eth_type_trans(skb, dev); 310b955f6caSJeff Kirsher netif_rx(skb); 311b955f6caSJeff Kirsher dev->stats.rx_packets++; 312b955f6caSJeff Kirsher dev->stats.rx_bytes += len; 313b955f6caSJeff Kirsher } 314b955f6caSJeff Kirsher 315b955f6caSJeff Kirsher /* Return the packet to the pool */ 316b955f6caSJeff Kirsher rd->mblength = 0; 317b955f6caSJeff Kirsher rd->rmd1_bits = LE_R1_OWN; 318b955f6caSJeff Kirsher lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask; 319b955f6caSJeff Kirsher } 320b955f6caSJeff Kirsher return 0; 321b955f6caSJeff Kirsher } 322b955f6caSJeff Kirsher 323b955f6caSJeff Kirsher static int lance_tx(struct net_device *dev) 324b955f6caSJeff Kirsher { 325b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 326b955f6caSJeff Kirsher volatile struct lance_init_block *ib = lp->init_block; 327b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 328b955f6caSJeff Kirsher volatile struct lance_tx_desc *td; 329b955f6caSJeff Kirsher int i, j; 330b955f6caSJeff Kirsher int status; 331b955f6caSJeff Kirsher 332b955f6caSJeff Kirsher /* csr0 is 2f3 */ 333b955f6caSJeff Kirsher ll->rdp = LE_C0_TINT | LE_C0_INEA; 334b955f6caSJeff Kirsher /* csr0 is 73 */ 335b955f6caSJeff Kirsher 336b955f6caSJeff Kirsher j = lp->tx_old; 337b955f6caSJeff Kirsher for (i = j; i != lp->tx_new; i = j) { 338b955f6caSJeff Kirsher td = &ib->btx_ring[i]; 339b955f6caSJeff Kirsher 340b955f6caSJeff Kirsher /* If we hit a packet not owned by us, stop */ 341b955f6caSJeff Kirsher if (td->tmd1_bits & LE_T1_OWN) 342b955f6caSJeff Kirsher break; 343b955f6caSJeff Kirsher 344b955f6caSJeff Kirsher if (td->tmd1_bits & LE_T1_ERR) { 345b955f6caSJeff Kirsher status = td->misc; 346b955f6caSJeff Kirsher 347b955f6caSJeff Kirsher dev->stats.tx_errors++; 348b955f6caSJeff Kirsher if (status & LE_T3_RTY) 349b955f6caSJeff Kirsher dev->stats.tx_aborted_errors++; 350b955f6caSJeff Kirsher if (status & LE_T3_LCOL) 351b955f6caSJeff Kirsher dev->stats.tx_window_errors++; 352b955f6caSJeff Kirsher 353b955f6caSJeff Kirsher if (status & LE_T3_CLOS) { 354b955f6caSJeff Kirsher dev->stats.tx_carrier_errors++; 355b955f6caSJeff Kirsher if (lp->auto_select) { 356b955f6caSJeff Kirsher lp->tpe = 1 - lp->tpe; 357b955f6caSJeff Kirsher netdev_err(dev, "Carrier Lost, trying %s\n", 358b955f6caSJeff Kirsher lp->tpe ? "TPE" : "AUI"); 359b955f6caSJeff Kirsher /* Stop the lance */ 360b955f6caSJeff Kirsher ll->rap = LE_CSR0; 361b955f6caSJeff Kirsher ll->rdp = LE_C0_STOP; 362b955f6caSJeff Kirsher lance_init_ring(dev); 363b955f6caSJeff Kirsher load_csrs(lp); 364b955f6caSJeff Kirsher init_restart_lance(lp); 365b955f6caSJeff Kirsher return 0; 366b955f6caSJeff Kirsher } 367b955f6caSJeff Kirsher } 368b955f6caSJeff Kirsher 369b955f6caSJeff Kirsher /* buffer errors and underflows turn off 370b955f6caSJeff Kirsher * the transmitter, so restart the adapter 371b955f6caSJeff Kirsher */ 372b955f6caSJeff Kirsher if (status & (LE_T3_BUF | LE_T3_UFL)) { 373b955f6caSJeff Kirsher dev->stats.tx_fifo_errors++; 374b955f6caSJeff Kirsher 375b955f6caSJeff Kirsher netdev_err(dev, "Tx: ERR_BUF|ERR_UFL, restarting\n"); 376b955f6caSJeff Kirsher /* Stop the lance */ 377b955f6caSJeff Kirsher ll->rap = LE_CSR0; 378b955f6caSJeff Kirsher ll->rdp = LE_C0_STOP; 379b955f6caSJeff Kirsher lance_init_ring(dev); 380b955f6caSJeff Kirsher load_csrs(lp); 381b955f6caSJeff Kirsher init_restart_lance(lp); 382b955f6caSJeff Kirsher return 0; 383b955f6caSJeff Kirsher } 384b955f6caSJeff Kirsher } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) { 385b955f6caSJeff Kirsher /* So we don't count the packet more than once. */ 386b955f6caSJeff Kirsher td->tmd1_bits &= ~(LE_T1_POK); 387b955f6caSJeff Kirsher 388b955f6caSJeff Kirsher /* One collision before packet was sent. */ 389b955f6caSJeff Kirsher if (td->tmd1_bits & LE_T1_EONE) 390b955f6caSJeff Kirsher dev->stats.collisions++; 391b955f6caSJeff Kirsher 392b955f6caSJeff Kirsher /* More than one collision, be optimistic. */ 393b955f6caSJeff Kirsher if (td->tmd1_bits & LE_T1_EMORE) 394b955f6caSJeff Kirsher dev->stats.collisions += 2; 395b955f6caSJeff Kirsher 396b955f6caSJeff Kirsher dev->stats.tx_packets++; 397b955f6caSJeff Kirsher } 398b955f6caSJeff Kirsher 399b955f6caSJeff Kirsher j = (j + 1) & lp->tx_ring_mod_mask; 400b955f6caSJeff Kirsher } 401b955f6caSJeff Kirsher lp->tx_old = j; 402b955f6caSJeff Kirsher ll->rdp = LE_C0_TINT | LE_C0_INEA; 403b955f6caSJeff Kirsher return 0; 404b955f6caSJeff Kirsher } 405b955f6caSJeff Kirsher 406b955f6caSJeff Kirsher static int lance_tx_buffs_avail(struct lance_private *lp) 407b955f6caSJeff Kirsher { 408b955f6caSJeff Kirsher if (lp->tx_old <= lp->tx_new) 409b955f6caSJeff Kirsher return lp->tx_old + lp->tx_ring_mod_mask - lp->tx_new; 410b955f6caSJeff Kirsher return lp->tx_old - lp->tx_new - 1; 411b955f6caSJeff Kirsher } 412b955f6caSJeff Kirsher 413b955f6caSJeff Kirsher static irqreturn_t lance_interrupt(int irq, void *dev_id) 414b955f6caSJeff Kirsher { 415b955f6caSJeff Kirsher struct net_device *dev = dev_id; 416b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 417b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 418b955f6caSJeff Kirsher int csr0; 419b955f6caSJeff Kirsher 420b955f6caSJeff Kirsher ll->rap = LE_CSR0; /* LANCE Controller Status */ 421b955f6caSJeff Kirsher csr0 = ll->rdp; 422b955f6caSJeff Kirsher 423b955f6caSJeff Kirsher if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */ 424b955f6caSJeff Kirsher return IRQ_NONE; /* been generated by the Lance. */ 425b955f6caSJeff Kirsher 426b955f6caSJeff Kirsher /* Acknowledge all the interrupt sources ASAP */ 427b955f6caSJeff Kirsher ll->rdp = csr0 & ~(LE_C0_INEA | LE_C0_TDMD | LE_C0_STOP | LE_C0_STRT | 428b955f6caSJeff Kirsher LE_C0_INIT); 429b955f6caSJeff Kirsher 430b955f6caSJeff Kirsher if (csr0 & LE_C0_ERR) { 431b955f6caSJeff Kirsher /* Clear the error condition */ 432b955f6caSJeff Kirsher ll->rdp = LE_C0_BABL | LE_C0_ERR | LE_C0_MISS | LE_C0_INEA; 433b955f6caSJeff Kirsher } 434b955f6caSJeff Kirsher 435b955f6caSJeff Kirsher if (csr0 & LE_C0_RINT) 436b955f6caSJeff Kirsher lance_rx(dev); 437b955f6caSJeff Kirsher 438b955f6caSJeff Kirsher if (csr0 & LE_C0_TINT) 439b955f6caSJeff Kirsher lance_tx(dev); 440b955f6caSJeff Kirsher 441b955f6caSJeff Kirsher /* Log misc errors. */ 442b955f6caSJeff Kirsher if (csr0 & LE_C0_BABL) 443b955f6caSJeff Kirsher dev->stats.tx_errors++; /* Tx babble. */ 444b955f6caSJeff Kirsher if (csr0 & LE_C0_MISS) 445b955f6caSJeff Kirsher dev->stats.rx_errors++; /* Missed a Rx frame. */ 446b955f6caSJeff Kirsher if (csr0 & LE_C0_MERR) { 447b955f6caSJeff Kirsher netdev_err(dev, "Bus master arbitration failure, status %04x\n", 448b955f6caSJeff Kirsher csr0); 449b955f6caSJeff Kirsher /* Restart the chip. */ 450b955f6caSJeff Kirsher ll->rdp = LE_C0_STRT; 451b955f6caSJeff Kirsher } 452b955f6caSJeff Kirsher 453b955f6caSJeff Kirsher if (netif_queue_stopped(dev) && lance_tx_buffs_avail(lp) > 0) 454b955f6caSJeff Kirsher netif_wake_queue(dev); 455b955f6caSJeff Kirsher 456b955f6caSJeff Kirsher ll->rap = LE_CSR0; 457b955f6caSJeff Kirsher ll->rdp = (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS | LE_C0_MERR | 458b955f6caSJeff Kirsher LE_C0_IDON | LE_C0_INEA); 459b955f6caSJeff Kirsher return IRQ_HANDLED; 460b955f6caSJeff Kirsher } 461b955f6caSJeff Kirsher 462b955f6caSJeff Kirsher static int lance_open(struct net_device *dev) 463b955f6caSJeff Kirsher { 464b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 465b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 466b955f6caSJeff Kirsher int ret; 467b955f6caSJeff Kirsher 468b955f6caSJeff Kirsher /* Stop the Lance */ 469b955f6caSJeff Kirsher ll->rap = LE_CSR0; 470b955f6caSJeff Kirsher ll->rdp = LE_C0_STOP; 471b955f6caSJeff Kirsher 472b955f6caSJeff Kirsher /* Install the Interrupt handler */ 473b955f6caSJeff Kirsher ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED, 474b955f6caSJeff Kirsher dev->name, dev); 475b955f6caSJeff Kirsher if (ret) 476b955f6caSJeff Kirsher return ret; 477b955f6caSJeff Kirsher 478b955f6caSJeff Kirsher load_csrs(lp); 479b955f6caSJeff Kirsher lance_init_ring(dev); 480b955f6caSJeff Kirsher 481b955f6caSJeff Kirsher netif_start_queue(dev); 482b955f6caSJeff Kirsher 483b955f6caSJeff Kirsher return init_restart_lance(lp); 484b955f6caSJeff Kirsher } 485b955f6caSJeff Kirsher 486b955f6caSJeff Kirsher static int lance_close(struct net_device *dev) 487b955f6caSJeff Kirsher { 488b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 489b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 490b955f6caSJeff Kirsher 491b955f6caSJeff Kirsher netif_stop_queue(dev); 492b955f6caSJeff Kirsher del_timer_sync(&lp->multicast_timer); 493b955f6caSJeff Kirsher 494b955f6caSJeff Kirsher /* Stop the card */ 495b955f6caSJeff Kirsher ll->rap = LE_CSR0; 496b955f6caSJeff Kirsher ll->rdp = LE_C0_STOP; 497b955f6caSJeff Kirsher 498b955f6caSJeff Kirsher free_irq(IRQ_AMIGA_PORTS, dev); 499b955f6caSJeff Kirsher return 0; 500b955f6caSJeff Kirsher } 501b955f6caSJeff Kirsher 502b955f6caSJeff Kirsher static inline int lance_reset(struct net_device *dev) 503b955f6caSJeff Kirsher { 504b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 505b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 506b955f6caSJeff Kirsher int status; 507b955f6caSJeff Kirsher 508b955f6caSJeff Kirsher /* Stop the lance */ 509b955f6caSJeff Kirsher ll->rap = LE_CSR0; 510b955f6caSJeff Kirsher ll->rdp = LE_C0_STOP; 511b955f6caSJeff Kirsher 512b955f6caSJeff Kirsher load_csrs(lp); 513b955f6caSJeff Kirsher 514b955f6caSJeff Kirsher lance_init_ring(dev); 515*860e9538SFlorian Westphal netif_trans_update(dev); /* prevent tx timeout */ 516b955f6caSJeff Kirsher netif_start_queue(dev); 517b955f6caSJeff Kirsher 518b955f6caSJeff Kirsher status = init_restart_lance(lp); 519b955f6caSJeff Kirsher netdev_dbg(dev, "Lance restart=%d\n", status); 520b955f6caSJeff Kirsher 521b955f6caSJeff Kirsher return status; 522b955f6caSJeff Kirsher } 523b955f6caSJeff Kirsher 524b955f6caSJeff Kirsher static void lance_tx_timeout(struct net_device *dev) 525b955f6caSJeff Kirsher { 526b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 527b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 528b955f6caSJeff Kirsher 529b955f6caSJeff Kirsher netdev_err(dev, "transmit timed out, status %04x, reset\n", ll->rdp); 530b955f6caSJeff Kirsher lance_reset(dev); 531b955f6caSJeff Kirsher netif_wake_queue(dev); 532b955f6caSJeff Kirsher } 533b955f6caSJeff Kirsher 534b955f6caSJeff Kirsher static netdev_tx_t lance_start_xmit(struct sk_buff *skb, 535b955f6caSJeff Kirsher struct net_device *dev) 536b955f6caSJeff Kirsher { 537b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 538b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 539b955f6caSJeff Kirsher volatile struct lance_init_block *ib = lp->init_block; 540b955f6caSJeff Kirsher int entry, skblen; 541b955f6caSJeff Kirsher int status = NETDEV_TX_OK; 542b955f6caSJeff Kirsher unsigned long flags; 543b955f6caSJeff Kirsher 544b955f6caSJeff Kirsher if (skb_padto(skb, ETH_ZLEN)) 545b955f6caSJeff Kirsher return NETDEV_TX_OK; 546b955f6caSJeff Kirsher skblen = max_t(unsigned, skb->len, ETH_ZLEN); 547b955f6caSJeff Kirsher 548b955f6caSJeff Kirsher local_irq_save(flags); 549b955f6caSJeff Kirsher 550926f2730SFlorian Westphal if (!lance_tx_buffs_avail(lp)) 551926f2730SFlorian Westphal goto out_free; 552b955f6caSJeff Kirsher 553b955f6caSJeff Kirsher #ifdef DEBUG 554b955f6caSJeff Kirsher /* dump the packet */ 555b955f6caSJeff Kirsher print_hex_dump(KERN_DEBUG, "skb->data: ", DUMP_PREFIX_NONE, 556b955f6caSJeff Kirsher 16, 1, skb->data, 64, true); 557b955f6caSJeff Kirsher #endif 558b955f6caSJeff Kirsher entry = lp->tx_new & lp->tx_ring_mod_mask; 559b955f6caSJeff Kirsher ib->btx_ring[entry].length = (-skblen) | 0xf000; 560b955f6caSJeff Kirsher ib->btx_ring[entry].misc = 0; 561b955f6caSJeff Kirsher 562b955f6caSJeff Kirsher skb_copy_from_linear_data(skb, (void *)&ib->tx_buf[entry][0], skblen); 563b955f6caSJeff Kirsher 564b955f6caSJeff Kirsher /* Now, give the packet to the lance */ 565b955f6caSJeff Kirsher ib->btx_ring[entry].tmd1_bits = (LE_T1_POK | LE_T1_OWN); 566b955f6caSJeff Kirsher lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask; 567b955f6caSJeff Kirsher dev->stats.tx_bytes += skblen; 568b955f6caSJeff Kirsher 569b955f6caSJeff Kirsher if (lance_tx_buffs_avail(lp) <= 0) 570b955f6caSJeff Kirsher netif_stop_queue(dev); 571b955f6caSJeff Kirsher 572b955f6caSJeff Kirsher /* Kick the lance: transmit now */ 573b955f6caSJeff Kirsher ll->rdp = LE_C0_INEA | LE_C0_TDMD; 574926f2730SFlorian Westphal out_free: 575b955f6caSJeff Kirsher dev_kfree_skb(skb); 576b955f6caSJeff Kirsher 577b955f6caSJeff Kirsher local_irq_restore(flags); 578b955f6caSJeff Kirsher 579b955f6caSJeff Kirsher return status; 580b955f6caSJeff Kirsher } 581b955f6caSJeff Kirsher 582b955f6caSJeff Kirsher /* taken from the depca driver */ 583b955f6caSJeff Kirsher static void lance_load_multicast(struct net_device *dev) 584b955f6caSJeff Kirsher { 585b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 586b955f6caSJeff Kirsher volatile struct lance_init_block *ib = lp->init_block; 587b955f6caSJeff Kirsher volatile u16 *mcast_table = (u16 *)&ib->filter; 588b955f6caSJeff Kirsher struct netdev_hw_addr *ha; 589b955f6caSJeff Kirsher u32 crc; 590b955f6caSJeff Kirsher 591b955f6caSJeff Kirsher /* set all multicast bits */ 592b955f6caSJeff Kirsher if (dev->flags & IFF_ALLMULTI) { 593b955f6caSJeff Kirsher ib->filter[0] = 0xffffffff; 594b955f6caSJeff Kirsher ib->filter[1] = 0xffffffff; 595b955f6caSJeff Kirsher return; 596b955f6caSJeff Kirsher } 597b955f6caSJeff Kirsher /* clear the multicast filter */ 598b955f6caSJeff Kirsher ib->filter[0] = 0; 599b955f6caSJeff Kirsher ib->filter[1] = 0; 600b955f6caSJeff Kirsher 601b955f6caSJeff Kirsher /* Add addresses */ 602b955f6caSJeff Kirsher netdev_for_each_mc_addr(ha, dev) { 603b955f6caSJeff Kirsher crc = ether_crc_le(6, ha->addr); 604b955f6caSJeff Kirsher crc = crc >> 26; 605b955f6caSJeff Kirsher mcast_table[crc >> 4] |= 1 << (crc & 0xf); 606b955f6caSJeff Kirsher } 607b955f6caSJeff Kirsher } 608b955f6caSJeff Kirsher 609b955f6caSJeff Kirsher static void lance_set_multicast(struct net_device *dev) 610b955f6caSJeff Kirsher { 611b955f6caSJeff Kirsher struct lance_private *lp = netdev_priv(dev); 612b955f6caSJeff Kirsher volatile struct lance_init_block *ib = lp->init_block; 613b955f6caSJeff Kirsher volatile struct lance_regs *ll = lp->ll; 614b955f6caSJeff Kirsher 615b955f6caSJeff Kirsher if (!netif_running(dev)) 616b955f6caSJeff Kirsher return; 617b955f6caSJeff Kirsher 618b955f6caSJeff Kirsher if (lp->tx_old != lp->tx_new) { 619b955f6caSJeff Kirsher mod_timer(&lp->multicast_timer, jiffies + 4); 620b955f6caSJeff Kirsher netif_wake_queue(dev); 621b955f6caSJeff Kirsher return; 622b955f6caSJeff Kirsher } 623b955f6caSJeff Kirsher 624b955f6caSJeff Kirsher netif_stop_queue(dev); 625b955f6caSJeff Kirsher 626b955f6caSJeff Kirsher ll->rap = LE_CSR0; 627b955f6caSJeff Kirsher ll->rdp = LE_C0_STOP; 628b955f6caSJeff Kirsher lance_init_ring(dev); 629b955f6caSJeff Kirsher 630b955f6caSJeff Kirsher if (dev->flags & IFF_PROMISC) { 631b955f6caSJeff Kirsher ib->mode |= LE_MO_PROM; 632b955f6caSJeff Kirsher } else { 633b955f6caSJeff Kirsher ib->mode &= ~LE_MO_PROM; 634b955f6caSJeff Kirsher lance_load_multicast(dev); 635b955f6caSJeff Kirsher } 636b955f6caSJeff Kirsher load_csrs(lp); 637b955f6caSJeff Kirsher init_restart_lance(lp); 638b955f6caSJeff Kirsher netif_wake_queue(dev); 639b955f6caSJeff Kirsher } 640b955f6caSJeff Kirsher 6410cb0568dSBill Pemberton static int a2065_init_one(struct zorro_dev *z, 642b955f6caSJeff Kirsher const struct zorro_device_id *ent); 6430cb0568dSBill Pemberton static void a2065_remove_one(struct zorro_dev *z); 644b955f6caSJeff Kirsher 645b955f6caSJeff Kirsher 6460cb0568dSBill Pemberton static struct zorro_device_id a2065_zorro_tbl[] = { 647b955f6caSJeff Kirsher { ZORRO_PROD_CBM_A2065_1 }, 648b955f6caSJeff Kirsher { ZORRO_PROD_CBM_A2065_2 }, 649b955f6caSJeff Kirsher { ZORRO_PROD_AMERISTAR_A2065 }, 650b955f6caSJeff Kirsher { 0 } 651b955f6caSJeff Kirsher }; 652b955f6caSJeff Kirsher MODULE_DEVICE_TABLE(zorro, a2065_zorro_tbl); 653b955f6caSJeff Kirsher 654b955f6caSJeff Kirsher static struct zorro_driver a2065_driver = { 655b955f6caSJeff Kirsher .name = "a2065", 656b955f6caSJeff Kirsher .id_table = a2065_zorro_tbl, 657b955f6caSJeff Kirsher .probe = a2065_init_one, 6580cb0568dSBill Pemberton .remove = a2065_remove_one, 659b955f6caSJeff Kirsher }; 660b955f6caSJeff Kirsher 661b955f6caSJeff Kirsher static const struct net_device_ops lance_netdev_ops = { 662b955f6caSJeff Kirsher .ndo_open = lance_open, 663b955f6caSJeff Kirsher .ndo_stop = lance_close, 664b955f6caSJeff Kirsher .ndo_start_xmit = lance_start_xmit, 665b955f6caSJeff Kirsher .ndo_tx_timeout = lance_tx_timeout, 666afc4b13dSJiri Pirko .ndo_set_rx_mode = lance_set_multicast, 667b955f6caSJeff Kirsher .ndo_validate_addr = eth_validate_addr, 668b955f6caSJeff Kirsher .ndo_change_mtu = eth_change_mtu, 669b955f6caSJeff Kirsher .ndo_set_mac_address = eth_mac_addr, 670b955f6caSJeff Kirsher }; 671b955f6caSJeff Kirsher 6720cb0568dSBill Pemberton static int a2065_init_one(struct zorro_dev *z, 673b955f6caSJeff Kirsher const struct zorro_device_id *ent) 674b955f6caSJeff Kirsher { 675b955f6caSJeff Kirsher struct net_device *dev; 676b955f6caSJeff Kirsher struct lance_private *priv; 677b955f6caSJeff Kirsher unsigned long board = z->resource.start; 678b955f6caSJeff Kirsher unsigned long base_addr = board + A2065_LANCE; 679b955f6caSJeff Kirsher unsigned long mem_start = board + A2065_RAM; 680b955f6caSJeff Kirsher struct resource *r1, *r2; 681bd9ba8f4SGeert Uytterhoeven u32 serial; 682b955f6caSJeff Kirsher int err; 683b955f6caSJeff Kirsher 684b955f6caSJeff Kirsher r1 = request_mem_region(base_addr, sizeof(struct lance_regs), 685b955f6caSJeff Kirsher "Am7990"); 686b955f6caSJeff Kirsher if (!r1) 687b955f6caSJeff Kirsher return -EBUSY; 688b955f6caSJeff Kirsher r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM"); 689b955f6caSJeff Kirsher if (!r2) { 690b955f6caSJeff Kirsher release_mem_region(base_addr, sizeof(struct lance_regs)); 691b955f6caSJeff Kirsher return -EBUSY; 692b955f6caSJeff Kirsher } 693b955f6caSJeff Kirsher 694b955f6caSJeff Kirsher dev = alloc_etherdev(sizeof(struct lance_private)); 695b955f6caSJeff Kirsher if (dev == NULL) { 696b955f6caSJeff Kirsher release_mem_region(base_addr, sizeof(struct lance_regs)); 697b955f6caSJeff Kirsher release_mem_region(mem_start, A2065_RAM_SIZE); 698b955f6caSJeff Kirsher return -ENOMEM; 699b955f6caSJeff Kirsher } 700b955f6caSJeff Kirsher 701b955f6caSJeff Kirsher priv = netdev_priv(dev); 702b955f6caSJeff Kirsher 703b955f6caSJeff Kirsher r1->name = dev->name; 704b955f6caSJeff Kirsher r2->name = dev->name; 705b955f6caSJeff Kirsher 706bd9ba8f4SGeert Uytterhoeven serial = be32_to_cpu(z->rom.er_SerialNumber); 707b955f6caSJeff Kirsher dev->dev_addr[0] = 0x00; 708b955f6caSJeff Kirsher if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */ 709b955f6caSJeff Kirsher dev->dev_addr[1] = 0x80; 710b955f6caSJeff Kirsher dev->dev_addr[2] = 0x10; 711b955f6caSJeff Kirsher } else { /* Ameristar */ 712b955f6caSJeff Kirsher dev->dev_addr[1] = 0x00; 713b955f6caSJeff Kirsher dev->dev_addr[2] = 0x9f; 714b955f6caSJeff Kirsher } 715bd9ba8f4SGeert Uytterhoeven dev->dev_addr[3] = (serial >> 16) & 0xff; 716bd9ba8f4SGeert Uytterhoeven dev->dev_addr[4] = (serial >> 8) & 0xff; 717bd9ba8f4SGeert Uytterhoeven dev->dev_addr[5] = serial & 0xff; 7186112ea08SGeert Uytterhoeven dev->base_addr = (unsigned long)ZTWO_VADDR(base_addr); 7196112ea08SGeert Uytterhoeven dev->mem_start = (unsigned long)ZTWO_VADDR(mem_start); 720b955f6caSJeff Kirsher dev->mem_end = dev->mem_start + A2065_RAM_SIZE; 721b955f6caSJeff Kirsher 722b955f6caSJeff Kirsher priv->ll = (volatile struct lance_regs *)dev->base_addr; 723b955f6caSJeff Kirsher priv->init_block = (struct lance_init_block *)dev->mem_start; 724b955f6caSJeff Kirsher priv->lance_init_block = (struct lance_init_block *)A2065_RAM; 725b955f6caSJeff Kirsher priv->auto_select = 0; 726b955f6caSJeff Kirsher priv->busmaster_regval = LE_C3_BSWP; 727b955f6caSJeff Kirsher 728b955f6caSJeff Kirsher priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS; 729b955f6caSJeff Kirsher priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; 730b955f6caSJeff Kirsher priv->rx_ring_mod_mask = RX_RING_MOD_MASK; 731b955f6caSJeff Kirsher priv->tx_ring_mod_mask = TX_RING_MOD_MASK; 732b955f6caSJeff Kirsher 733b955f6caSJeff Kirsher dev->netdev_ops = &lance_netdev_ops; 734b955f6caSJeff Kirsher dev->watchdog_timeo = 5*HZ; 735b955f6caSJeff Kirsher dev->dma = 0; 736b955f6caSJeff Kirsher 737b955f6caSJeff Kirsher init_timer(&priv->multicast_timer); 738b955f6caSJeff Kirsher priv->multicast_timer.data = (unsigned long) dev; 739b955f6caSJeff Kirsher priv->multicast_timer.function = 740b955f6caSJeff Kirsher (void (*)(unsigned long))lance_set_multicast; 741b955f6caSJeff Kirsher 742b955f6caSJeff Kirsher err = register_netdev(dev); 743b955f6caSJeff Kirsher if (err) { 744b955f6caSJeff Kirsher release_mem_region(base_addr, sizeof(struct lance_regs)); 745b955f6caSJeff Kirsher release_mem_region(mem_start, A2065_RAM_SIZE); 746b955f6caSJeff Kirsher free_netdev(dev); 747b955f6caSJeff Kirsher return err; 748b955f6caSJeff Kirsher } 749b955f6caSJeff Kirsher zorro_set_drvdata(z, dev); 750b955f6caSJeff Kirsher 751b955f6caSJeff Kirsher netdev_info(dev, "A2065 at 0x%08lx, Ethernet Address %pM\n", 752b955f6caSJeff Kirsher board, dev->dev_addr); 753b955f6caSJeff Kirsher 754b955f6caSJeff Kirsher return 0; 755b955f6caSJeff Kirsher } 756b955f6caSJeff Kirsher 757b955f6caSJeff Kirsher 7580cb0568dSBill Pemberton static void a2065_remove_one(struct zorro_dev *z) 759b955f6caSJeff Kirsher { 760b955f6caSJeff Kirsher struct net_device *dev = zorro_get_drvdata(z); 761b955f6caSJeff Kirsher 762b955f6caSJeff Kirsher unregister_netdev(dev); 763b955f6caSJeff Kirsher release_mem_region(ZTWO_PADDR(dev->base_addr), 764b955f6caSJeff Kirsher sizeof(struct lance_regs)); 765b955f6caSJeff Kirsher release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE); 766b955f6caSJeff Kirsher free_netdev(dev); 767b955f6caSJeff Kirsher } 768b955f6caSJeff Kirsher 769b955f6caSJeff Kirsher static int __init a2065_init_module(void) 770b955f6caSJeff Kirsher { 771b955f6caSJeff Kirsher return zorro_register_driver(&a2065_driver); 772b955f6caSJeff Kirsher } 773b955f6caSJeff Kirsher 774b955f6caSJeff Kirsher static void __exit a2065_cleanup_module(void) 775b955f6caSJeff Kirsher { 776b955f6caSJeff Kirsher zorro_unregister_driver(&a2065_driver); 777b955f6caSJeff Kirsher } 778b955f6caSJeff Kirsher 779b955f6caSJeff Kirsher module_init(a2065_init_module); 780b955f6caSJeff Kirsher module_exit(a2065_cleanup_module); 781b955f6caSJeff Kirsher 782b955f6caSJeff Kirsher MODULE_LICENSE("GPL"); 783