Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/net/am79c961.c |
| 3 | * |
| 4 | * by Russell King <rmk@arm.linux.org.uk> 1995-2001. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * Derived from various things including skeleton.c |
| 11 | * |
| 12 | * This is a special driver for the am79c961A Lance chip used in the |
| 13 | * Intel (formally Digital Equipment Corp) EBSA110 platform. Please |
| 14 | * note that this can not be built as a module (it doesn't make sense). |
| 15 | */ |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/slab.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/crc32.h> |
| 28 | #include <linux/bitops.h> |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
Russell King | 9973022 | 2009-03-25 10:21:35 +0000 | [diff] [blame] | 30 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/hardware.h> |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 33 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #define TX_BUFFERS 15 |
| 36 | #define RX_BUFFERS 25 |
| 37 | |
| 38 | #include "am79c961a.h" |
| 39 | |
| 40 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 41 | am79c961_interrupt (int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | static unsigned int net_debug = NET_DEBUG; |
| 44 | |
| 45 | static const char version[] = |
| 46 | "am79c961 ethernet driver (C) 1995-2001 Russell King v0.04\n"; |
| 47 | |
| 48 | /* --------------------------------------------------------------------------- */ |
| 49 | |
| 50 | #ifdef __arm__ |
| 51 | static void write_rreg(u_long base, u_int reg, u_int val) |
| 52 | { |
Russell King - ARM Linux | d814dee | 2011-06-10 00:51:54 +0000 | [diff] [blame] | 53 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | "str%?h %1, [%2] @ NET_RAP\n\t" |
| 55 | "str%?h %0, [%2, #-4] @ NET_RDP" |
| 56 | : |
| 57 | : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464)); |
| 58 | } |
| 59 | |
| 60 | static inline unsigned short read_rreg(u_long base_addr, u_int reg) |
| 61 | { |
| 62 | unsigned short v; |
Russell King - ARM Linux | d814dee | 2011-06-10 00:51:54 +0000 | [diff] [blame] | 63 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | "str%?h %1, [%2] @ NET_RAP\n\t" |
| 65 | "ldr%?h %0, [%2, #-4] @ NET_RDP" |
| 66 | : "=r" (v) |
| 67 | : "r" (reg), "r" (ISAIO_BASE + 0x0464)); |
| 68 | return v; |
| 69 | } |
| 70 | |
| 71 | static inline void write_ireg(u_long base, u_int reg, u_int val) |
| 72 | { |
Russell King - ARM Linux | d814dee | 2011-06-10 00:51:54 +0000 | [diff] [blame] | 73 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | "str%?h %1, [%2] @ NET_RAP\n\t" |
| 75 | "str%?h %0, [%2, #8] @ NET_IDP" |
| 76 | : |
| 77 | : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464)); |
| 78 | } |
| 79 | |
| 80 | static inline unsigned short read_ireg(u_long base_addr, u_int reg) |
| 81 | { |
| 82 | u_short v; |
Russell King - ARM Linux | d814dee | 2011-06-10 00:51:54 +0000 | [diff] [blame] | 83 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | "str%?h %1, [%2] @ NAT_RAP\n\t" |
Russell King | 0e3a64e | 2005-10-02 18:02:25 +0100 | [diff] [blame] | 85 | "ldr%?h %0, [%2, #8] @ NET_IDP\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | : "=r" (v) |
| 87 | : "r" (reg), "r" (ISAIO_BASE + 0x0464)); |
| 88 | return v; |
| 89 | } |
| 90 | |
| 91 | #define am_writeword(dev,off,val) __raw_writew(val, ISAMEM_BASE + ((off) << 1)) |
| 92 | #define am_readword(dev,off) __raw_readw(ISAMEM_BASE + ((off) << 1)) |
| 93 | |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 94 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | am_writebuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length) |
| 96 | { |
| 97 | offset = ISAMEM_BASE + (offset << 1); |
| 98 | length = (length + 1) & ~1; |
| 99 | if ((int)buf & 2) { |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 100 | asm volatile("str%?h %2, [%0], #4" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8))); |
| 102 | buf += 2; |
| 103 | length -= 2; |
| 104 | } |
| 105 | while (length > 8) { |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 106 | register unsigned int tmp asm("r2"), tmp2 asm("r3"); |
| 107 | asm volatile( |
| 108 | "ldm%?ia %0!, {%1, %2}" |
| 109 | : "+r" (buf), "=&r" (tmp), "=&r" (tmp2)); |
| 110 | length -= 8; |
| 111 | asm volatile( |
| 112 | "str%?h %1, [%0], #4\n\t" |
| 113 | "mov%? %1, %1, lsr #16\n\t" |
| 114 | "str%?h %1, [%0], #4\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | "str%?h %2, [%0], #4\n\t" |
| 116 | "mov%? %2, %2, lsr #16\n\t" |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 117 | "str%?h %2, [%0], #4" |
| 118 | : "+r" (offset), "=&r" (tmp), "=&r" (tmp2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | while (length > 0) { |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 121 | asm volatile("str%?h %2, [%0], #4" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8))); |
| 123 | buf += 2; |
| 124 | length -= 2; |
| 125 | } |
| 126 | } |
| 127 | |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 128 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | am_readbuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length) |
| 130 | { |
| 131 | offset = ISAMEM_BASE + (offset << 1); |
| 132 | length = (length + 1) & ~1; |
| 133 | if ((int)buf & 2) { |
| 134 | unsigned int tmp; |
Russell King - ARM Linux | d814dee | 2011-06-10 00:51:54 +0000 | [diff] [blame] | 135 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | "ldr%?h %2, [%0], #4\n\t" |
| 137 | "str%?b %2, [%1], #1\n\t" |
| 138 | "mov%? %2, %2, lsr #8\n\t" |
| 139 | "str%?b %2, [%1], #1" |
| 140 | : "=&r" (offset), "=&r" (buf), "=r" (tmp): "0" (offset), "1" (buf)); |
| 141 | length -= 2; |
| 142 | } |
| 143 | while (length > 8) { |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 144 | register unsigned int tmp asm("r2"), tmp2 asm("r3"), tmp3; |
Russell King - ARM Linux | d814dee | 2011-06-10 00:51:54 +0000 | [diff] [blame] | 145 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | "ldr%?h %2, [%0], #4\n\t" |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 147 | "ldr%?h %4, [%0], #4\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | "ldr%?h %3, [%0], #4\n\t" |
Russell King - ARM Linux | f777737 | 2011-06-10 00:52:35 +0000 | [diff] [blame] | 149 | "orr%? %2, %2, %4, lsl #16\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | "ldr%?h %4, [%0], #4\n\t" |
| 151 | "orr%? %3, %3, %4, lsl #16\n\t" |
| 152 | "stm%?ia %1!, {%2, %3}" |
| 153 | : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2), "=r" (tmp3) |
| 154 | : "0" (offset), "1" (buf)); |
| 155 | length -= 8; |
| 156 | } |
| 157 | while (length > 0) { |
| 158 | unsigned int tmp; |
Russell King - ARM Linux | d814dee | 2011-06-10 00:51:54 +0000 | [diff] [blame] | 159 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | "ldr%?h %2, [%0], #4\n\t" |
| 161 | "str%?b %2, [%1], #1\n\t" |
| 162 | "mov%? %2, %2, lsr #8\n\t" |
| 163 | "str%?b %2, [%1], #1" |
| 164 | : "=&r" (offset), "=&r" (buf), "=r" (tmp) : "0" (offset), "1" (buf)); |
| 165 | length -= 2; |
| 166 | } |
| 167 | } |
| 168 | #else |
| 169 | #error Not compatible |
| 170 | #endif |
| 171 | |
| 172 | static int |
| 173 | am79c961_ramtest(struct net_device *dev, unsigned int val) |
| 174 | { |
| 175 | unsigned char *buffer = kmalloc (65536, GFP_KERNEL); |
| 176 | int i, error = 0, errorcount = 0; |
| 177 | |
| 178 | if (!buffer) |
| 179 | return 0; |
| 180 | memset (buffer, val, 65536); |
| 181 | am_writebuffer(dev, 0, buffer, 65536); |
| 182 | memset (buffer, val ^ 255, 65536); |
| 183 | am_readbuffer(dev, 0, buffer, 65536); |
| 184 | for (i = 0; i < 65536; i++) { |
| 185 | if (buffer[i] != val && !error) { |
| 186 | printk ("%s: buffer error (%02X %02X) %05X - ", dev->name, val, buffer[i], i); |
| 187 | error = 1; |
| 188 | errorcount ++; |
| 189 | } else if (error && buffer[i] == val) { |
| 190 | printk ("%05X\n", i); |
| 191 | error = 0; |
| 192 | } |
| 193 | } |
| 194 | if (error) |
| 195 | printk ("10000\n"); |
| 196 | kfree (buffer); |
| 197 | return errorcount; |
| 198 | } |
| 199 | |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 200 | static void am79c961_mc_hash(char *addr, u16 *hash) |
| 201 | { |
Tobias Klauser | bda7ed4 | 2011-06-29 02:14:46 +0000 | [diff] [blame] | 202 | int idx, bit; |
| 203 | u32 crc; |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 204 | |
Tobias Klauser | bda7ed4 | 2011-06-29 02:14:46 +0000 | [diff] [blame] | 205 | crc = ether_crc_le(ETH_ALEN, addr); |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 206 | |
Tobias Klauser | bda7ed4 | 2011-06-29 02:14:46 +0000 | [diff] [blame] | 207 | idx = crc >> 30; |
| 208 | bit = (crc >> 26) & 15; |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 209 | |
Tobias Klauser | bda7ed4 | 2011-06-29 02:14:46 +0000 | [diff] [blame] | 210 | hash[idx] |= 1 << bit; |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static unsigned int am79c961_get_rx_mode(struct net_device *dev, u16 *hash) |
| 214 | { |
| 215 | unsigned int mode = MODE_PORT_10BT; |
| 216 | |
| 217 | if (dev->flags & IFF_PROMISC) { |
| 218 | mode |= MODE_PROMISC; |
| 219 | memset(hash, 0xff, 4 * sizeof(*hash)); |
| 220 | } else if (dev->flags & IFF_ALLMULTI) { |
| 221 | memset(hash, 0xff, 4 * sizeof(*hash)); |
| 222 | } else { |
| 223 | struct netdev_hw_addr *ha; |
| 224 | |
| 225 | memset(hash, 0, 4 * sizeof(*hash)); |
| 226 | |
| 227 | netdev_for_each_mc_addr(ha, dev) |
| 228 | am79c961_mc_hash(ha->addr, hash); |
| 229 | } |
| 230 | |
| 231 | return mode; |
| 232 | } |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | static void |
| 235 | am79c961_init_for_open(struct net_device *dev) |
| 236 | { |
| 237 | struct dev_priv *priv = netdev_priv(dev); |
| 238 | unsigned long flags; |
| 239 | unsigned char *p; |
| 240 | u_int hdr_addr, first_free_addr; |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 241 | u16 multi_hash[4], mode = am79c961_get_rx_mode(dev, multi_hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | int i; |
| 243 | |
| 244 | /* |
| 245 | * Stop the chip. |
| 246 | */ |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 247 | spin_lock_irqsave(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | write_rreg (dev->base_addr, CSR0, CSR0_BABL|CSR0_CERR|CSR0_MISS|CSR0_MERR|CSR0_TINT|CSR0_RINT|CSR0_STOP); |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 249 | spin_unlock_irqrestore(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | write_ireg (dev->base_addr, 5, 0x00a0); /* Receive address LED */ |
| 252 | write_ireg (dev->base_addr, 6, 0x0081); /* Collision LED */ |
| 253 | write_ireg (dev->base_addr, 7, 0x0090); /* XMIT LED */ |
| 254 | write_ireg (dev->base_addr, 2, 0x0000); /* MODE register selects media */ |
| 255 | |
| 256 | for (i = LADRL; i <= LADRH; i++) |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 257 | write_rreg (dev->base_addr, i, multi_hash[i - LADRL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | for (i = PADRL, p = dev->dev_addr; i <= PADRH; i++, p += 2) |
| 260 | write_rreg (dev->base_addr, i, p[0] | (p[1] << 8)); |
| 261 | |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 262 | write_rreg (dev->base_addr, MODE, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | write_rreg (dev->base_addr, POLLINT, 0); |
| 264 | write_rreg (dev->base_addr, SIZERXR, -RX_BUFFERS); |
| 265 | write_rreg (dev->base_addr, SIZETXR, -TX_BUFFERS); |
| 266 | |
| 267 | first_free_addr = RX_BUFFERS * 8 + TX_BUFFERS * 8 + 16; |
| 268 | hdr_addr = 0; |
| 269 | |
| 270 | priv->rxhead = 0; |
| 271 | priv->rxtail = 0; |
| 272 | priv->rxhdr = hdr_addr; |
| 273 | |
| 274 | for (i = 0; i < RX_BUFFERS; i++) { |
| 275 | priv->rxbuffer[i] = first_free_addr; |
| 276 | am_writeword (dev, hdr_addr, first_free_addr); |
| 277 | am_writeword (dev, hdr_addr + 2, RMD_OWN); |
| 278 | am_writeword (dev, hdr_addr + 4, (-1600)); |
| 279 | am_writeword (dev, hdr_addr + 6, 0); |
| 280 | first_free_addr += 1600; |
| 281 | hdr_addr += 8; |
| 282 | } |
| 283 | priv->txhead = 0; |
| 284 | priv->txtail = 0; |
| 285 | priv->txhdr = hdr_addr; |
| 286 | for (i = 0; i < TX_BUFFERS; i++) { |
| 287 | priv->txbuffer[i] = first_free_addr; |
| 288 | am_writeword (dev, hdr_addr, first_free_addr); |
| 289 | am_writeword (dev, hdr_addr + 2, TMD_STP|TMD_ENP); |
| 290 | am_writeword (dev, hdr_addr + 4, 0xf000); |
| 291 | am_writeword (dev, hdr_addr + 6, 0); |
| 292 | first_free_addr += 1600; |
| 293 | hdr_addr += 8; |
| 294 | } |
| 295 | |
| 296 | write_rreg (dev->base_addr, BASERXL, priv->rxhdr); |
| 297 | write_rreg (dev->base_addr, BASERXH, 0); |
| 298 | write_rreg (dev->base_addr, BASETXL, priv->txhdr); |
| 299 | write_rreg (dev->base_addr, BASERXH, 0); |
| 300 | write_rreg (dev->base_addr, CSR0, CSR0_STOP); |
| 301 | write_rreg (dev->base_addr, CSR3, CSR3_IDONM|CSR3_BABLM|CSR3_DXSUFLO); |
| 302 | write_rreg (dev->base_addr, CSR4, CSR4_APAD_XMIT|CSR4_MFCOM|CSR4_RCVCCOM|CSR4_TXSTRTM|CSR4_JABM); |
| 303 | write_rreg (dev->base_addr, CSR0, CSR0_IENA|CSR0_STRT); |
| 304 | } |
| 305 | |
| 306 | static void am79c961_timer(unsigned long data) |
| 307 | { |
| 308 | struct net_device *dev = (struct net_device *)data; |
| 309 | struct dev_priv *priv = netdev_priv(dev); |
| 310 | unsigned int lnkstat, carrier; |
Russell King | 1df726e | 2011-09-05 08:58:29 +0100 | [diff] [blame] | 311 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Russell King | 1df726e | 2011-09-05 08:58:29 +0100 | [diff] [blame] | 313 | spin_lock_irqsave(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | lnkstat = read_ireg(dev->base_addr, ISALED0) & ISALED0_LNKST; |
Russell King | 1df726e | 2011-09-05 08:58:29 +0100 | [diff] [blame] | 315 | spin_unlock_irqrestore(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | carrier = netif_carrier_ok(dev); |
| 317 | |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 318 | if (lnkstat && !carrier) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | netif_carrier_on(dev); |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 320 | printk("%s: link up\n", dev->name); |
| 321 | } else if (!lnkstat && carrier) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | netif_carrier_off(dev); |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 323 | printk("%s: link down\n", dev->name); |
| 324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Russell King | 487fd4e | 2005-10-02 18:12:03 +0100 | [diff] [blame] | 326 | mod_timer(&priv->timer, jiffies + msecs_to_jiffies(500)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Open/initialize the board. |
| 331 | */ |
| 332 | static int |
| 333 | am79c961_open(struct net_device *dev) |
| 334 | { |
| 335 | struct dev_priv *priv = netdev_priv(dev); |
| 336 | int ret; |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | ret = request_irq(dev->irq, am79c961_interrupt, 0, dev->name, dev); |
| 339 | if (ret) |
| 340 | return ret; |
| 341 | |
| 342 | am79c961_init_for_open(dev); |
| 343 | |
| 344 | netif_carrier_off(dev); |
| 345 | |
| 346 | priv->timer.expires = jiffies; |
| 347 | add_timer(&priv->timer); |
| 348 | |
| 349 | netif_start_queue(dev); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * The inverse routine to am79c961_open(). |
| 356 | */ |
| 357 | static int |
| 358 | am79c961_close(struct net_device *dev) |
| 359 | { |
| 360 | struct dev_priv *priv = netdev_priv(dev); |
| 361 | unsigned long flags; |
| 362 | |
| 363 | del_timer_sync(&priv->timer); |
| 364 | |
| 365 | netif_stop_queue(dev); |
| 366 | netif_carrier_off(dev); |
| 367 | |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 368 | spin_lock_irqsave(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | write_rreg (dev->base_addr, CSR0, CSR0_STOP); |
| 370 | write_rreg (dev->base_addr, CSR3, CSR3_MASKALL); |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 371 | spin_unlock_irqrestore(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | free_irq (dev->irq, dev); |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* |
| 379 | * Set or clear promiscuous/multicast mode filter for this adapter. |
| 380 | */ |
| 381 | static void am79c961_setmulticastlist (struct net_device *dev) |
| 382 | { |
| 383 | struct dev_priv *priv = netdev_priv(dev); |
| 384 | unsigned long flags; |
Russell King - ARM Linux | bfc6501 | 2011-06-10 00:52:14 +0000 | [diff] [blame] | 385 | u16 multi_hash[4], mode = am79c961_get_rx_mode(dev, multi_hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | int i, stopped; |
| 387 | |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 388 | spin_lock_irqsave(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | stopped = read_rreg(dev->base_addr, CSR0) & CSR0_STOP; |
| 391 | |
| 392 | if (!stopped) { |
| 393 | /* |
| 394 | * Put the chip into suspend mode |
| 395 | */ |
| 396 | write_rreg(dev->base_addr, CTRL1, CTRL1_SPND); |
| 397 | |
| 398 | /* |
| 399 | * Spin waiting for chip to report suspend mode |
| 400 | */ |
| 401 | while ((read_rreg(dev->base_addr, CTRL1) & CTRL1_SPND) == 0) { |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 402 | spin_unlock_irqrestore(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | nop(); |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 404 | spin_lock_irqsave(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * Update the multicast hash table |
| 410 | */ |
Denis Cheng | ff8ac60 | 2007-09-02 18:30:18 +0800 | [diff] [blame] | 411 | for (i = 0; i < ARRAY_SIZE(multi_hash); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | write_rreg(dev->base_addr, i + LADRL, multi_hash[i]); |
| 413 | |
| 414 | /* |
| 415 | * Write the mode register |
| 416 | */ |
| 417 | write_rreg(dev->base_addr, MODE, mode); |
| 418 | |
| 419 | if (!stopped) { |
| 420 | /* |
| 421 | * Put the chip back into running mode |
| 422 | */ |
| 423 | write_rreg(dev->base_addr, CTRL1, 0); |
| 424 | } |
| 425 | |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 426 | spin_unlock_irqrestore(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static void am79c961_timeout(struct net_device *dev) |
| 430 | { |
| 431 | printk(KERN_WARNING "%s: transmit timed out, network cable problem?\n", |
| 432 | dev->name); |
| 433 | |
| 434 | /* |
| 435 | * ought to do some setup of the tx side here |
| 436 | */ |
| 437 | |
| 438 | netif_wake_queue(dev); |
| 439 | } |
| 440 | |
| 441 | /* |
| 442 | * Transmit a packet |
| 443 | */ |
| 444 | static int |
| 445 | am79c961_sendpacket(struct sk_buff *skb, struct net_device *dev) |
| 446 | { |
| 447 | struct dev_priv *priv = netdev_priv(dev); |
| 448 | unsigned int hdraddr, bufaddr; |
| 449 | unsigned int head; |
| 450 | unsigned long flags; |
| 451 | |
| 452 | head = priv->txhead; |
| 453 | hdraddr = priv->txhdr + (head << 3); |
| 454 | bufaddr = priv->txbuffer[head]; |
| 455 | head += 1; |
| 456 | if (head >= TX_BUFFERS) |
| 457 | head = 0; |
| 458 | |
| 459 | am_writebuffer (dev, bufaddr, skb->data, skb->len); |
| 460 | am_writeword (dev, hdraddr + 4, -skb->len); |
| 461 | am_writeword (dev, hdraddr + 2, TMD_OWN|TMD_STP|TMD_ENP); |
| 462 | priv->txhead = head; |
| 463 | |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 464 | spin_lock_irqsave(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | write_rreg (dev->base_addr, CSR0, CSR0_TDMD|CSR0_IENA); |
Uwe Kleine-König | fb22d72 | 2009-01-22 23:29:42 +0100 | [diff] [blame] | 466 | spin_unlock_irqrestore(&priv->chip_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | /* |
| 469 | * If the next packet is owned by the ethernet device, |
| 470 | * then the tx ring is full and we can't add another |
| 471 | * packet. |
| 472 | */ |
| 473 | if (am_readword(dev, priv->txhdr + (priv->txhead << 3) + 2) & TMD_OWN) |
| 474 | netif_stop_queue(dev); |
| 475 | |
| 476 | dev_kfree_skb(skb); |
| 477 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 478 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /* |
| 482 | * If we have a good packet(s), get it/them out of the buffers. |
| 483 | */ |
| 484 | static void |
| 485 | am79c961_rx(struct net_device *dev, struct dev_priv *priv) |
| 486 | { |
| 487 | do { |
| 488 | struct sk_buff *skb; |
| 489 | u_int hdraddr; |
| 490 | u_int pktaddr; |
| 491 | u_int status; |
| 492 | int len; |
| 493 | |
| 494 | hdraddr = priv->rxhdr + (priv->rxtail << 3); |
| 495 | pktaddr = priv->rxbuffer[priv->rxtail]; |
| 496 | |
| 497 | status = am_readword (dev, hdraddr + 2); |
| 498 | if (status & RMD_OWN) /* do we own it? */ |
| 499 | break; |
| 500 | |
| 501 | priv->rxtail ++; |
| 502 | if (priv->rxtail >= RX_BUFFERS) |
| 503 | priv->rxtail = 0; |
| 504 | |
| 505 | if ((status & (RMD_ERR|RMD_STP|RMD_ENP)) != (RMD_STP|RMD_ENP)) { |
| 506 | am_writeword (dev, hdraddr + 2, RMD_OWN); |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 507 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | if (status & RMD_ERR) { |
| 509 | if (status & RMD_FRAM) |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 510 | dev->stats.rx_frame_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (status & RMD_CRC) |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 512 | dev->stats.rx_crc_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } else if (status & RMD_STP) |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 514 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | continue; |
| 516 | } |
| 517 | |
| 518 | len = am_readword(dev, hdraddr + 6); |
| 519 | skb = dev_alloc_skb(len + 2); |
| 520 | |
| 521 | if (skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | skb_reserve(skb, 2); |
| 523 | |
| 524 | am_readbuffer(dev, pktaddr, skb_put(skb, len), len); |
| 525 | am_writeword(dev, hdraddr + 2, RMD_OWN); |
| 526 | skb->protocol = eth_type_trans(skb, dev); |
| 527 | netif_rx(skb); |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 528 | dev->stats.rx_bytes += len; |
| 529 | dev->stats.rx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } else { |
| 531 | am_writeword (dev, hdraddr + 2, RMD_OWN); |
| 532 | printk (KERN_WARNING "%s: memory squeeze, dropping packet.\n", dev->name); |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 533 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | break; |
| 535 | } |
| 536 | } while (1); |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * Update stats for the transmitted packet |
| 541 | */ |
| 542 | static void |
| 543 | am79c961_tx(struct net_device *dev, struct dev_priv *priv) |
| 544 | { |
| 545 | do { |
| 546 | short len; |
| 547 | u_int hdraddr; |
| 548 | u_int status; |
| 549 | |
| 550 | hdraddr = priv->txhdr + (priv->txtail << 3); |
| 551 | status = am_readword (dev, hdraddr + 2); |
| 552 | if (status & TMD_OWN) |
| 553 | break; |
| 554 | |
| 555 | priv->txtail ++; |
| 556 | if (priv->txtail >= TX_BUFFERS) |
| 557 | priv->txtail = 0; |
| 558 | |
| 559 | if (status & TMD_ERR) { |
| 560 | u_int status2; |
| 561 | |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 562 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | status2 = am_readword (dev, hdraddr + 6); |
| 565 | |
| 566 | /* |
| 567 | * Clear the error byte |
| 568 | */ |
| 569 | am_writeword (dev, hdraddr + 6, 0); |
| 570 | |
| 571 | if (status2 & TST_RTRY) |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 572 | dev->stats.collisions += 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (status2 & TST_LCOL) |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 574 | dev->stats.tx_window_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | if (status2 & TST_LCAR) |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 576 | dev->stats.tx_carrier_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | if (status2 & TST_UFLO) |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 578 | dev->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | continue; |
| 580 | } |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 581 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | len = am_readword (dev, hdraddr + 4); |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 583 | dev->stats.tx_bytes += -len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } while (priv->txtail != priv->txhead); |
| 585 | |
| 586 | netif_wake_queue(dev); |
| 587 | } |
| 588 | |
| 589 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 590 | am79c961_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
| 592 | struct net_device *dev = (struct net_device *)dev_id; |
| 593 | struct dev_priv *priv = netdev_priv(dev); |
| 594 | u_int status, n = 100; |
| 595 | int handled = 0; |
| 596 | |
| 597 | do { |
| 598 | status = read_rreg(dev->base_addr, CSR0); |
| 599 | write_rreg(dev->base_addr, CSR0, status & |
| 600 | (CSR0_IENA|CSR0_TINT|CSR0_RINT| |
| 601 | CSR0_MERR|CSR0_MISS|CSR0_CERR|CSR0_BABL)); |
| 602 | |
| 603 | if (status & CSR0_RINT) { |
| 604 | handled = 1; |
| 605 | am79c961_rx(dev, priv); |
| 606 | } |
| 607 | if (status & CSR0_TINT) { |
| 608 | handled = 1; |
| 609 | am79c961_tx(dev, priv); |
| 610 | } |
| 611 | if (status & CSR0_MISS) { |
| 612 | handled = 1; |
Tobias Klauser | 264fd77 | 2010-08-09 05:04:34 +0000 | [diff] [blame] | 613 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | if (status & CSR0_CERR) { |
| 616 | handled = 1; |
| 617 | mod_timer(&priv->timer, jiffies); |
| 618 | } |
| 619 | } while (--n && status & (CSR0_RINT | CSR0_TINT)); |
| 620 | |
| 621 | return IRQ_RETVAL(handled); |
| 622 | } |
| 623 | |
| 624 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 625 | static void am79c961_poll_controller(struct net_device *dev) |
| 626 | { |
| 627 | unsigned long flags; |
| 628 | local_irq_save(flags); |
Yoann Padioleau | 0da2f0f | 2007-07-06 02:39:56 -0700 | [diff] [blame] | 629 | am79c961_interrupt(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | local_irq_restore(flags); |
| 631 | } |
| 632 | #endif |
| 633 | |
| 634 | /* |
| 635 | * Initialise the chip. Note that we always expect |
| 636 | * to be entered with interrupts enabled. |
| 637 | */ |
| 638 | static int |
| 639 | am79c961_hw_init(struct net_device *dev) |
| 640 | { |
| 641 | struct dev_priv *priv = netdev_priv(dev); |
| 642 | |
| 643 | spin_lock_irq(&priv->chip_lock); |
| 644 | write_rreg (dev->base_addr, CSR0, CSR0_STOP); |
| 645 | write_rreg (dev->base_addr, CSR3, CSR3_MASKALL); |
| 646 | spin_unlock_irq(&priv->chip_lock); |
| 647 | |
| 648 | am79c961_ramtest(dev, 0x66); |
| 649 | am79c961_ramtest(dev, 0x99); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static void __init am79c961_banner(void) |
| 655 | { |
| 656 | static unsigned version_printed; |
| 657 | |
| 658 | if (net_debug && version_printed++ == 0) |
| 659 | printk(KERN_INFO "%s", version); |
| 660 | } |
Alexander Beregalov | fefbfb1 | 2009-04-09 17:25:25 +0000 | [diff] [blame] | 661 | static const struct net_device_ops am79c961_netdev_ops = { |
| 662 | .ndo_open = am79c961_open, |
| 663 | .ndo_stop = am79c961_close, |
| 664 | .ndo_start_xmit = am79c961_sendpacket, |
Alexander Beregalov | fefbfb1 | 2009-04-09 17:25:25 +0000 | [diff] [blame] | 665 | .ndo_set_multicast_list = am79c961_setmulticastlist, |
| 666 | .ndo_tx_timeout = am79c961_timeout, |
| 667 | .ndo_validate_addr = eth_validate_addr, |
| 668 | .ndo_change_mtu = eth_change_mtu, |
| 669 | .ndo_set_mac_address = eth_mac_addr, |
| 670 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 671 | .ndo_poll_controller = am79c961_poll_controller, |
| 672 | #endif |
| 673 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
Uwe Kleine-König | 447d8c2 | 2010-02-12 12:10:47 -0800 | [diff] [blame] | 675 | static int __devinit am79c961_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 677 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | struct net_device *dev; |
| 679 | struct dev_priv *priv; |
| 680 | int i, ret; |
| 681 | |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 682 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 683 | if (!res) |
| 684 | return -ENODEV; |
| 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | dev = alloc_etherdev(sizeof(struct dev_priv)); |
| 687 | ret = -ENOMEM; |
| 688 | if (!dev) |
| 689 | goto out; |
| 690 | |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 691 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | priv = netdev_priv(dev); |
| 694 | |
| 695 | /* |
| 696 | * Fixed address and IRQ lines here. |
| 697 | * The PNP initialisation should have been |
| 698 | * done by the ether bootp loader. |
| 699 | */ |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 700 | dev->base_addr = res->start; |
Roel Kluin | 6278367 | 2008-04-23 23:44:03 +0200 | [diff] [blame] | 701 | ret = platform_get_irq(pdev, 0); |
| 702 | |
| 703 | if (ret < 0) { |
| 704 | ret = -ENODEV; |
| 705 | goto nodev; |
| 706 | } |
| 707 | dev->irq = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
David Vrabel | 4894473 | 2006-01-19 17:56:29 +0000 | [diff] [blame] | 709 | ret = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | if (!request_region(dev->base_addr, 0x18, dev->name)) |
| 711 | goto nodev; |
| 712 | |
| 713 | /* |
| 714 | * Reset the device. |
| 715 | */ |
| 716 | inb(dev->base_addr + NET_RESET); |
| 717 | udelay(5); |
| 718 | |
| 719 | /* |
| 720 | * Check the manufacturer part of the |
| 721 | * ether address. |
| 722 | */ |
| 723 | if (inb(dev->base_addr) != 0x08 || |
| 724 | inb(dev->base_addr + 2) != 0x00 || |
| 725 | inb(dev->base_addr + 4) != 0x2b) |
| 726 | goto release; |
| 727 | |
Russell King | 487fd4e | 2005-10-02 18:12:03 +0100 | [diff] [blame] | 728 | for (i = 0; i < 6; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | dev->dev_addr[i] = inb(dev->base_addr + i * 2) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 731 | am79c961_banner(); |
| 732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | spin_lock_init(&priv->chip_lock); |
| 734 | init_timer(&priv->timer); |
| 735 | priv->timer.data = (unsigned long)dev; |
| 736 | priv->timer.function = am79c961_timer; |
| 737 | |
| 738 | if (am79c961_hw_init(dev)) |
| 739 | goto release; |
| 740 | |
Alexander Beregalov | fefbfb1 | 2009-04-09 17:25:25 +0000 | [diff] [blame] | 741 | dev->netdev_ops = &am79c961_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
| 743 | ret = register_netdev(dev); |
Russell King | 487fd4e | 2005-10-02 18:12:03 +0100 | [diff] [blame] | 744 | if (ret == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 745 | printk(KERN_INFO "%s: ether address %pM\n", |
| 746 | dev->name, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | return 0; |
Russell King | 487fd4e | 2005-10-02 18:12:03 +0100 | [diff] [blame] | 748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | release: |
| 751 | release_region(dev->base_addr, 0x18); |
| 752 | nodev: |
| 753 | free_netdev(dev); |
| 754 | out: |
| 755 | return ret; |
| 756 | } |
| 757 | |
Russell King | 50465d0 | 2006-01-09 13:59:36 +0000 | [diff] [blame] | 758 | static struct platform_driver am79c961_driver = { |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 759 | .probe = am79c961_probe, |
Russell King | 50465d0 | 2006-01-09 13:59:36 +0000 | [diff] [blame] | 760 | .driver = { |
| 761 | .name = "am79c961", |
| 762 | }, |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | static int __init am79c961_init(void) |
| 766 | { |
Russell King | 50465d0 | 2006-01-09 13:59:36 +0000 | [diff] [blame] | 767 | return platform_driver_register(&am79c961_driver); |
Russell King | 37bb30e | 2005-10-31 17:14:57 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | __initcall(am79c961_init); |