| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *  linux/drivers/acorn/net/etherh.c | 
|  | 3 | * | 
|  | 4 | *  Copyright (C) 2000-2002 Russell King | 
|  | 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 | * NS8390 I-cubed EtherH and ANT EtherM specific driver | 
|  | 11 | * Thanks to I-Cubed for information on their cards. | 
|  | 12 | * EtherM conversion (C) 1999 Chris Kemp and Tim Watterton | 
|  | 13 | * EtherM integration (C) 2000 Aleph One Ltd (Tak-Shing Chan) | 
|  | 14 | * EtherM integration re-engineered by Russell King. | 
|  | 15 | * | 
|  | 16 | * Changelog: | 
|  | 17 | *  08-12-1996	RMK	1.00	Created | 
|  | 18 | *		RMK	1.03	Added support for EtherLan500 cards | 
|  | 19 | *  23-11-1997	RMK	1.04	Added media autodetection | 
|  | 20 | *  16-04-1998	RMK	1.05	Improved media autodetection | 
|  | 21 | *  10-02-2000	RMK	1.06	Updated for 2.3.43 | 
|  | 22 | *  13-05-2000	RMK	1.07	Updated for 2.3.99-pre8 | 
|  | 23 | *  12-10-1999  CK/TEW		EtherM driver first release | 
|  | 24 | *  21-12-2000	TTC		EtherH/EtherM integration | 
|  | 25 | *  25-12-2000	RMK	1.08	Clean integration of EtherM into this driver. | 
|  | 26 | *  03-01-2002	RMK	1.09	Always enable IRQs if we're in the nic slot. | 
|  | 27 | */ | 
|  | 28 |  | 
|  | 29 | #include <linux/module.h> | 
|  | 30 | #include <linux/kernel.h> | 
|  | 31 | #include <linux/sched.h> | 
|  | 32 | #include <linux/types.h> | 
|  | 33 | #include <linux/fcntl.h> | 
|  | 34 | #include <linux/interrupt.h> | 
|  | 35 | #include <linux/ptrace.h> | 
|  | 36 | #include <linux/ioport.h> | 
|  | 37 | #include <linux/in.h> | 
|  | 38 | #include <linux/slab.h> | 
|  | 39 | #include <linux/string.h> | 
|  | 40 | #include <linux/errno.h> | 
|  | 41 | #include <linux/netdevice.h> | 
|  | 42 | #include <linux/etherdevice.h> | 
|  | 43 | #include <linux/ethtool.h> | 
|  | 44 | #include <linux/skbuff.h> | 
|  | 45 | #include <linux/delay.h> | 
|  | 46 | #include <linux/device.h> | 
|  | 47 | #include <linux/init.h> | 
|  | 48 | #include <linux/bitops.h> | 
|  | 49 |  | 
|  | 50 | #include <asm/system.h> | 
|  | 51 | #include <asm/ecard.h> | 
|  | 52 | #include <asm/io.h> | 
|  | 53 | #include <asm/irq.h> | 
|  | 54 |  | 
|  | 55 | #include "../8390.h" | 
|  | 56 |  | 
|  | 57 | #define NET_DEBUG  0 | 
|  | 58 | #define DEBUG_INIT 2 | 
|  | 59 |  | 
|  | 60 | #define DRV_NAME	"etherh" | 
|  | 61 | #define DRV_VERSION	"1.11" | 
|  | 62 |  | 
|  | 63 | static unsigned int net_debug = NET_DEBUG; | 
|  | 64 |  | 
|  | 65 | struct etherh_priv { | 
|  | 66 | void __iomem	*ioc_fast; | 
|  | 67 | void __iomem	*memc; | 
|  | 68 | void __iomem	*dma_base; | 
|  | 69 | unsigned int	id; | 
|  | 70 | void __iomem	*ctrl_port; | 
|  | 71 | unsigned char	ctrl; | 
|  | 72 | u32		supported; | 
|  | 73 | }; | 
|  | 74 |  | 
|  | 75 | struct etherh_data { | 
|  | 76 | unsigned long	ns8390_offset; | 
|  | 77 | unsigned long	dataport_offset; | 
|  | 78 | unsigned long	ctrlport_offset; | 
|  | 79 | int		ctrl_ioc; | 
|  | 80 | const char	name[16]; | 
|  | 81 | u32		supported; | 
|  | 82 | unsigned char	tx_start_page; | 
|  | 83 | unsigned char	stop_page; | 
|  | 84 | }; | 
|  | 85 |  | 
|  | 86 | MODULE_AUTHOR("Russell King"); | 
|  | 87 | MODULE_DESCRIPTION("EtherH/EtherM driver"); | 
|  | 88 | MODULE_LICENSE("GPL"); | 
|  | 89 |  | 
|  | 90 | static char version[] __initdata = | 
|  | 91 | "EtherH/EtherM Driver (c) 2002-2004 Russell King " DRV_VERSION "\n"; | 
|  | 92 |  | 
|  | 93 | #define ETHERH500_DATAPORT	0x800	/* MEMC */ | 
|  | 94 | #define ETHERH500_NS8390	0x000	/* MEMC */ | 
|  | 95 | #define ETHERH500_CTRLPORT	0x800	/* IOC  */ | 
|  | 96 |  | 
|  | 97 | #define ETHERH600_DATAPORT	0x040	/* MEMC */ | 
|  | 98 | #define ETHERH600_NS8390	0x800	/* MEMC */ | 
|  | 99 | #define ETHERH600_CTRLPORT	0x200	/* MEMC */ | 
|  | 100 |  | 
|  | 101 | #define ETHERH_CP_IE		1 | 
|  | 102 | #define ETHERH_CP_IF		2 | 
|  | 103 | #define ETHERH_CP_HEARTBEAT	2 | 
|  | 104 |  | 
|  | 105 | #define ETHERH_TX_START_PAGE	1 | 
|  | 106 | #define ETHERH_STOP_PAGE	127 | 
|  | 107 |  | 
|  | 108 | /* | 
|  | 109 | * These came from CK/TEW | 
|  | 110 | */ | 
|  | 111 | #define ETHERM_DATAPORT		0x200	/* MEMC */ | 
|  | 112 | #define ETHERM_NS8390		0x800	/* MEMC */ | 
|  | 113 | #define ETHERM_CTRLPORT		0x23c	/* MEMC */ | 
|  | 114 |  | 
|  | 115 | #define ETHERM_TX_START_PAGE	64 | 
|  | 116 | #define ETHERM_STOP_PAGE	127 | 
|  | 117 |  | 
|  | 118 | /* ------------------------------------------------------------------------ */ | 
|  | 119 |  | 
|  | 120 | #define etherh_priv(dev) \ | 
|  | 121 | ((struct etherh_priv *)(((char *)netdev_priv(dev)) + sizeof(struct ei_device))) | 
|  | 122 |  | 
|  | 123 | static inline void etherh_set_ctrl(struct etherh_priv *eh, unsigned char mask) | 
|  | 124 | { | 
|  | 125 | unsigned char ctrl = eh->ctrl | mask; | 
|  | 126 | eh->ctrl = ctrl; | 
|  | 127 | writeb(ctrl, eh->ctrl_port); | 
|  | 128 | } | 
|  | 129 |  | 
|  | 130 | static inline void etherh_clr_ctrl(struct etherh_priv *eh, unsigned char mask) | 
|  | 131 | { | 
|  | 132 | unsigned char ctrl = eh->ctrl & ~mask; | 
|  | 133 | eh->ctrl = ctrl; | 
|  | 134 | writeb(ctrl, eh->ctrl_port); | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | static inline unsigned int etherh_get_stat(struct etherh_priv *eh) | 
|  | 138 | { | 
|  | 139 | return readb(eh->ctrl_port); | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 |  | 
|  | 143 |  | 
|  | 144 |  | 
|  | 145 | static void etherh_irq_enable(ecard_t *ec, int irqnr) | 
|  | 146 | { | 
|  | 147 | struct etherh_priv *eh = ec->irq_data; | 
|  | 148 |  | 
|  | 149 | etherh_set_ctrl(eh, ETHERH_CP_IE); | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | static void etherh_irq_disable(ecard_t *ec, int irqnr) | 
|  | 153 | { | 
|  | 154 | struct etherh_priv *eh = ec->irq_data; | 
|  | 155 |  | 
|  | 156 | etherh_clr_ctrl(eh, ETHERH_CP_IE); | 
|  | 157 | } | 
|  | 158 |  | 
|  | 159 | static expansioncard_ops_t etherh_ops = { | 
|  | 160 | .irqenable	= etherh_irq_enable, | 
|  | 161 | .irqdisable	= etherh_irq_disable, | 
|  | 162 | }; | 
|  | 163 |  | 
|  | 164 |  | 
|  | 165 |  | 
|  | 166 |  | 
|  | 167 | static void | 
|  | 168 | etherh_setif(struct net_device *dev) | 
|  | 169 | { | 
|  | 170 | struct ei_device *ei_local = netdev_priv(dev); | 
|  | 171 | unsigned long flags; | 
|  | 172 | void __iomem *addr; | 
|  | 173 |  | 
|  | 174 | local_irq_save(flags); | 
|  | 175 |  | 
|  | 176 | /* set the interface type */ | 
|  | 177 | switch (etherh_priv(dev)->id) { | 
|  | 178 | case PROD_I3_ETHERLAN600: | 
|  | 179 | case PROD_I3_ETHERLAN600A: | 
| Nicolas Pitre | c7e7887 | 2005-06-29 18:10:54 +0100 | [diff] [blame] | 180 | addr = (void *)dev->base_addr + EN0_RCNTHI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
|  | 182 | switch (dev->if_port) { | 
|  | 183 | case IF_PORT_10BASE2: | 
|  | 184 | writeb((readb(addr) & 0xf8) | 1, addr); | 
|  | 185 | break; | 
|  | 186 | case IF_PORT_10BASET: | 
|  | 187 | writeb((readb(addr) & 0xf8), addr); | 
|  | 188 | break; | 
|  | 189 | } | 
|  | 190 | break; | 
|  | 191 |  | 
|  | 192 | case PROD_I3_ETHERLAN500: | 
|  | 193 | switch (dev->if_port) { | 
|  | 194 | case IF_PORT_10BASE2: | 
|  | 195 | etherh_clr_ctrl(etherh_priv(dev), ETHERH_CP_IF); | 
|  | 196 | break; | 
|  | 197 |  | 
|  | 198 | case IF_PORT_10BASET: | 
|  | 199 | etherh_set_ctrl(etherh_priv(dev), ETHERH_CP_IF); | 
|  | 200 | break; | 
|  | 201 | } | 
|  | 202 | break; | 
|  | 203 |  | 
|  | 204 | default: | 
|  | 205 | break; | 
|  | 206 | } | 
|  | 207 |  | 
|  | 208 | local_irq_restore(flags); | 
|  | 209 | } | 
|  | 210 |  | 
|  | 211 | static int | 
|  | 212 | etherh_getifstat(struct net_device *dev) | 
|  | 213 | { | 
|  | 214 | struct ei_device *ei_local = netdev_priv(dev); | 
|  | 215 | void __iomem *addr; | 
|  | 216 | int stat = 0; | 
|  | 217 |  | 
|  | 218 | switch (etherh_priv(dev)->id) { | 
|  | 219 | case PROD_I3_ETHERLAN600: | 
|  | 220 | case PROD_I3_ETHERLAN600A: | 
| Nicolas Pitre | c7e7887 | 2005-06-29 18:10:54 +0100 | [diff] [blame] | 221 | addr = (void *)dev->base_addr + EN0_RCNTHI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | switch (dev->if_port) { | 
|  | 223 | case IF_PORT_10BASE2: | 
|  | 224 | stat = 1; | 
|  | 225 | break; | 
|  | 226 | case IF_PORT_10BASET: | 
|  | 227 | stat = readb(addr) & 4; | 
|  | 228 | break; | 
|  | 229 | } | 
|  | 230 | break; | 
|  | 231 |  | 
|  | 232 | case PROD_I3_ETHERLAN500: | 
|  | 233 | switch (dev->if_port) { | 
|  | 234 | case IF_PORT_10BASE2: | 
|  | 235 | stat = 1; | 
|  | 236 | break; | 
|  | 237 | case IF_PORT_10BASET: | 
|  | 238 | stat = etherh_get_stat(etherh_priv(dev)) & ETHERH_CP_HEARTBEAT; | 
|  | 239 | break; | 
|  | 240 | } | 
|  | 241 | break; | 
|  | 242 |  | 
|  | 243 | default: | 
|  | 244 | stat = 0; | 
|  | 245 | break; | 
|  | 246 | } | 
|  | 247 |  | 
|  | 248 | return stat != 0; | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | /* | 
|  | 252 | * Configure the interface.  Note that we ignore the other | 
|  | 253 | * parts of ifmap, since its mostly meaningless for this driver. | 
|  | 254 | */ | 
|  | 255 | static int etherh_set_config(struct net_device *dev, struct ifmap *map) | 
|  | 256 | { | 
|  | 257 | switch (map->port) { | 
|  | 258 | case IF_PORT_10BASE2: | 
|  | 259 | case IF_PORT_10BASET: | 
|  | 260 | /* | 
|  | 261 | * If the user explicitly sets the interface | 
|  | 262 | * media type, turn off automedia detection. | 
|  | 263 | */ | 
|  | 264 | dev->flags &= ~IFF_AUTOMEDIA; | 
|  | 265 | dev->if_port = map->port; | 
|  | 266 | break; | 
|  | 267 |  | 
|  | 268 | default: | 
|  | 269 | return -EINVAL; | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | etherh_setif(dev); | 
|  | 273 |  | 
|  | 274 | return 0; | 
|  | 275 | } | 
|  | 276 |  | 
|  | 277 | /* | 
|  | 278 | * Reset the 8390 (hard reset).  Note that we can't actually do this. | 
|  | 279 | */ | 
|  | 280 | static void | 
|  | 281 | etherh_reset(struct net_device *dev) | 
|  | 282 | { | 
|  | 283 | struct ei_device *ei_local = netdev_priv(dev); | 
| Nicolas Pitre | c7e7887 | 2005-06-29 18:10:54 +0100 | [diff] [blame] | 284 | void __iomem *addr = (void *)dev->base_addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 |  | 
|  | 286 | writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr); | 
|  | 287 |  | 
|  | 288 | /* | 
|  | 289 | * See if we need to change the interface type. | 
|  | 290 | * Note that we use 'interface_num' as a flag | 
|  | 291 | * to indicate that we need to change the media. | 
|  | 292 | */ | 
|  | 293 | if (dev->flags & IFF_AUTOMEDIA && ei_local->interface_num) { | 
|  | 294 | ei_local->interface_num = 0; | 
|  | 295 |  | 
|  | 296 | if (dev->if_port == IF_PORT_10BASET) | 
|  | 297 | dev->if_port = IF_PORT_10BASE2; | 
|  | 298 | else | 
|  | 299 | dev->if_port = IF_PORT_10BASET; | 
|  | 300 |  | 
|  | 301 | etherh_setif(dev); | 
|  | 302 | } | 
|  | 303 | } | 
|  | 304 |  | 
|  | 305 | /* | 
|  | 306 | * Write a block of data out to the 8390 | 
|  | 307 | */ | 
|  | 308 | static void | 
|  | 309 | etherh_block_output (struct net_device *dev, int count, const unsigned char *buf, int start_page) | 
|  | 310 | { | 
|  | 311 | struct ei_device *ei_local = netdev_priv(dev); | 
|  | 312 | unsigned long dma_start; | 
|  | 313 | void __iomem *dma_base, *addr; | 
|  | 314 |  | 
|  | 315 | if (ei_local->dmaing) { | 
|  | 316 | printk(KERN_ERR "%s: DMAing conflict in etherh_block_input: " | 
|  | 317 | " DMAstat %d irqlock %d\n", dev->name, | 
|  | 318 | ei_local->dmaing, ei_local->irqlock); | 
|  | 319 | return; | 
|  | 320 | } | 
|  | 321 |  | 
|  | 322 | /* | 
|  | 323 | * Make sure we have a round number of bytes if we're in word mode. | 
|  | 324 | */ | 
|  | 325 | if (count & 1 && ei_local->word16) | 
|  | 326 | count++; | 
|  | 327 |  | 
|  | 328 | ei_local->dmaing = 1; | 
|  | 329 |  | 
| Nicolas Pitre | c7e7887 | 2005-06-29 18:10:54 +0100 | [diff] [blame] | 330 | addr = (void *)dev->base_addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | dma_base = etherh_priv(dev)->dma_base; | 
|  | 332 |  | 
|  | 333 | count = (count + 1) & ~1; | 
|  | 334 | writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD); | 
|  | 335 |  | 
|  | 336 | writeb (0x42, addr + EN0_RCNTLO); | 
|  | 337 | writeb (0x00, addr + EN0_RCNTHI); | 
|  | 338 | writeb (0x42, addr + EN0_RSARLO); | 
|  | 339 | writeb (0x00, addr + EN0_RSARHI); | 
|  | 340 | writeb (E8390_RREAD | E8390_START, addr + E8390_CMD); | 
|  | 341 |  | 
|  | 342 | udelay (1); | 
|  | 343 |  | 
|  | 344 | writeb (ENISR_RDC, addr + EN0_ISR); | 
|  | 345 | writeb (count, addr + EN0_RCNTLO); | 
|  | 346 | writeb (count >> 8, addr + EN0_RCNTHI); | 
|  | 347 | writeb (0, addr + EN0_RSARLO); | 
|  | 348 | writeb (start_page, addr + EN0_RSARHI); | 
|  | 349 | writeb (E8390_RWRITE | E8390_START, addr + E8390_CMD); | 
|  | 350 |  | 
|  | 351 | if (ei_local->word16) | 
|  | 352 | writesw (dma_base, buf, count >> 1); | 
|  | 353 | else | 
|  | 354 | writesb (dma_base, buf, count); | 
|  | 355 |  | 
|  | 356 | dma_start = jiffies; | 
|  | 357 |  | 
|  | 358 | while ((readb (addr + EN0_ISR) & ENISR_RDC) == 0) | 
|  | 359 | if (jiffies - dma_start > 2*HZ/100) { /* 20ms */ | 
|  | 360 | printk(KERN_ERR "%s: timeout waiting for TX RDC\n", | 
|  | 361 | dev->name); | 
|  | 362 | etherh_reset (dev); | 
|  | 363 | NS8390_init (dev, 1); | 
|  | 364 | break; | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | writeb (ENISR_RDC, addr + EN0_ISR); | 
|  | 368 | ei_local->dmaing = 0; | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | /* | 
|  | 372 | * Read a block of data from the 8390 | 
|  | 373 | */ | 
|  | 374 | static void | 
|  | 375 | etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) | 
|  | 376 | { | 
|  | 377 | struct ei_device *ei_local = netdev_priv(dev); | 
|  | 378 | unsigned char *buf; | 
|  | 379 | void __iomem *dma_base, *addr; | 
|  | 380 |  | 
|  | 381 | if (ei_local->dmaing) { | 
|  | 382 | printk(KERN_ERR "%s: DMAing conflict in etherh_block_input: " | 
|  | 383 | " DMAstat %d irqlock %d\n", dev->name, | 
|  | 384 | ei_local->dmaing, ei_local->irqlock); | 
|  | 385 | return; | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | ei_local->dmaing = 1; | 
|  | 389 |  | 
| Nicolas Pitre | c7e7887 | 2005-06-29 18:10:54 +0100 | [diff] [blame] | 390 | addr = (void *)dev->base_addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | dma_base = etherh_priv(dev)->dma_base; | 
|  | 392 |  | 
|  | 393 | buf = skb->data; | 
|  | 394 | writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD); | 
|  | 395 | writeb (count, addr + EN0_RCNTLO); | 
|  | 396 | writeb (count >> 8, addr + EN0_RCNTHI); | 
|  | 397 | writeb (ring_offset, addr + EN0_RSARLO); | 
|  | 398 | writeb (ring_offset >> 8, addr + EN0_RSARHI); | 
|  | 399 | writeb (E8390_RREAD | E8390_START, addr + E8390_CMD); | 
|  | 400 |  | 
|  | 401 | if (ei_local->word16) { | 
|  | 402 | readsw (dma_base, buf, count >> 1); | 
|  | 403 | if (count & 1) | 
|  | 404 | buf[count - 1] = readb (dma_base); | 
|  | 405 | } else | 
|  | 406 | readsb (dma_base, buf, count); | 
|  | 407 |  | 
|  | 408 | writeb (ENISR_RDC, addr + EN0_ISR); | 
|  | 409 | ei_local->dmaing = 0; | 
|  | 410 | } | 
|  | 411 |  | 
|  | 412 | /* | 
|  | 413 | * Read a header from the 8390 | 
|  | 414 | */ | 
|  | 415 | static void | 
|  | 416 | etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) | 
|  | 417 | { | 
|  | 418 | struct ei_device *ei_local = netdev_priv(dev); | 
|  | 419 | void __iomem *dma_base, *addr; | 
|  | 420 |  | 
|  | 421 | if (ei_local->dmaing) { | 
|  | 422 | printk(KERN_ERR "%s: DMAing conflict in etherh_get_header: " | 
|  | 423 | " DMAstat %d irqlock %d\n", dev->name, | 
|  | 424 | ei_local->dmaing, ei_local->irqlock); | 
|  | 425 | return; | 
|  | 426 | } | 
|  | 427 |  | 
|  | 428 | ei_local->dmaing = 1; | 
|  | 429 |  | 
| Nicolas Pitre | c7e7887 | 2005-06-29 18:10:54 +0100 | [diff] [blame] | 430 | addr = (void *)dev->base_addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | dma_base = etherh_priv(dev)->dma_base; | 
|  | 432 |  | 
|  | 433 | writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD); | 
|  | 434 | writeb (sizeof (*hdr), addr + EN0_RCNTLO); | 
|  | 435 | writeb (0, addr + EN0_RCNTHI); | 
|  | 436 | writeb (0, addr + EN0_RSARLO); | 
|  | 437 | writeb (ring_page, addr + EN0_RSARHI); | 
|  | 438 | writeb (E8390_RREAD | E8390_START, addr + E8390_CMD); | 
|  | 439 |  | 
|  | 440 | if (ei_local->word16) | 
|  | 441 | readsw (dma_base, hdr, sizeof (*hdr) >> 1); | 
|  | 442 | else | 
|  | 443 | readsb (dma_base, hdr, sizeof (*hdr)); | 
|  | 444 |  | 
|  | 445 | writeb (ENISR_RDC, addr + EN0_ISR); | 
|  | 446 | ei_local->dmaing = 0; | 
|  | 447 | } | 
|  | 448 |  | 
|  | 449 | /* | 
|  | 450 | * Open/initialize the board.  This is called (in the current kernel) | 
|  | 451 | * sometime after booting when the 'ifconfig' program is run. | 
|  | 452 | * | 
|  | 453 | * This routine should set everything up anew at each open, even | 
|  | 454 | * registers that "should" only need to be set once at boot, so that | 
|  | 455 | * there is non-reboot way to recover if something goes wrong. | 
|  | 456 | */ | 
|  | 457 | static int | 
|  | 458 | etherh_open(struct net_device *dev) | 
|  | 459 | { | 
|  | 460 | struct ei_device *ei_local = netdev_priv(dev); | 
|  | 461 |  | 
|  | 462 | if (!is_valid_ether_addr(dev->dev_addr)) { | 
|  | 463 | printk(KERN_WARNING "%s: invalid ethernet MAC address\n", | 
|  | 464 | dev->name); | 
|  | 465 | return -EINVAL; | 
|  | 466 | } | 
|  | 467 |  | 
|  | 468 | if (request_irq(dev->irq, ei_interrupt, 0, dev->name, dev)) | 
|  | 469 | return -EAGAIN; | 
|  | 470 |  | 
|  | 471 | /* | 
|  | 472 | * Make sure that we aren't going to change the | 
|  | 473 | * media type on the next reset - we are about to | 
|  | 474 | * do automedia manually now. | 
|  | 475 | */ | 
|  | 476 | ei_local->interface_num = 0; | 
|  | 477 |  | 
|  | 478 | /* | 
|  | 479 | * If we are doing automedia detection, do it now. | 
|  | 480 | * This is more reliable than the 8390's detection. | 
|  | 481 | */ | 
|  | 482 | if (dev->flags & IFF_AUTOMEDIA) { | 
|  | 483 | dev->if_port = IF_PORT_10BASET; | 
|  | 484 | etherh_setif(dev); | 
|  | 485 | mdelay(1); | 
|  | 486 | if (!etherh_getifstat(dev)) { | 
|  | 487 | dev->if_port = IF_PORT_10BASE2; | 
|  | 488 | etherh_setif(dev); | 
|  | 489 | } | 
|  | 490 | } else | 
|  | 491 | etherh_setif(dev); | 
|  | 492 |  | 
|  | 493 | etherh_reset(dev); | 
|  | 494 | ei_open(dev); | 
|  | 495 |  | 
|  | 496 | return 0; | 
|  | 497 | } | 
|  | 498 |  | 
|  | 499 | /* | 
|  | 500 | * The inverse routine to etherh_open(). | 
|  | 501 | */ | 
|  | 502 | static int | 
|  | 503 | etherh_close(struct net_device *dev) | 
|  | 504 | { | 
|  | 505 | ei_close (dev); | 
|  | 506 | free_irq (dev->irq, dev); | 
|  | 507 | return 0; | 
|  | 508 | } | 
|  | 509 |  | 
|  | 510 | /* | 
|  | 511 | * Initialisation | 
|  | 512 | */ | 
|  | 513 |  | 
|  | 514 | static void __init etherh_banner(void) | 
|  | 515 | { | 
|  | 516 | static int version_printed; | 
|  | 517 |  | 
|  | 518 | if (net_debug && version_printed++ == 0) | 
|  | 519 | printk(KERN_INFO "%s", version); | 
|  | 520 | } | 
|  | 521 |  | 
|  | 522 | /* | 
|  | 523 | * Read the ethernet address string from the on board rom. | 
|  | 524 | * This is an ascii string... | 
|  | 525 | */ | 
|  | 526 | static int __init etherh_addr(char *addr, struct expansion_card *ec) | 
|  | 527 | { | 
|  | 528 | struct in_chunk_dir cd; | 
|  | 529 | char *s; | 
|  | 530 |  | 
|  | 531 | if (!ecard_readchunk(&cd, ec, 0xf5, 0)) { | 
|  | 532 | printk(KERN_ERR "%s: unable to read podule description string\n", | 
|  | 533 | ec->dev.bus_id); | 
|  | 534 | goto no_addr; | 
|  | 535 | } | 
|  | 536 |  | 
|  | 537 | s = strchr(cd.d.string, '('); | 
|  | 538 | if (s) { | 
|  | 539 | int i; | 
|  | 540 |  | 
|  | 541 | for (i = 0; i < 6; i++) { | 
|  | 542 | addr[i] = simple_strtoul(s + 1, &s, 0x10); | 
|  | 543 | if (*s != (i == 5? ')' : ':')) | 
|  | 544 | break; | 
|  | 545 | } | 
|  | 546 |  | 
|  | 547 | if (i == 6) | 
|  | 548 | return 0; | 
|  | 549 | } | 
|  | 550 |  | 
|  | 551 | printk(KERN_ERR "%s: unable to parse MAC address: %s\n", | 
|  | 552 | ec->dev.bus_id, cd.d.string); | 
|  | 553 |  | 
|  | 554 | no_addr: | 
|  | 555 | return -ENODEV; | 
|  | 556 | } | 
|  | 557 |  | 
|  | 558 | /* | 
|  | 559 | * Create an ethernet address from the system serial number. | 
|  | 560 | */ | 
|  | 561 | static int __init etherm_addr(char *addr) | 
|  | 562 | { | 
|  | 563 | unsigned int serial; | 
|  | 564 |  | 
|  | 565 | if (system_serial_low == 0 && system_serial_high == 0) | 
|  | 566 | return -ENODEV; | 
|  | 567 |  | 
|  | 568 | serial = system_serial_low | system_serial_high; | 
|  | 569 |  | 
|  | 570 | addr[0] = 0; | 
|  | 571 | addr[1] = 0; | 
|  | 572 | addr[2] = 0xa4; | 
|  | 573 | addr[3] = 0x10 + (serial >> 24); | 
|  | 574 | addr[4] = serial >> 16; | 
|  | 575 | addr[5] = serial >> 8; | 
|  | 576 | return 0; | 
|  | 577 | } | 
|  | 578 |  | 
|  | 579 | static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | 
|  | 580 | { | 
|  | 581 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); | 
|  | 582 | strlcpy(info->version, DRV_VERSION, sizeof(info->version)); | 
|  | 583 | strlcpy(info->bus_info, dev->class_dev.dev->bus_id, | 
|  | 584 | sizeof(info->bus_info)); | 
|  | 585 | } | 
|  | 586 |  | 
|  | 587 | static int etherh_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | 
|  | 588 | { | 
|  | 589 | cmd->supported	= etherh_priv(dev)->supported; | 
|  | 590 | cmd->speed	= SPEED_10; | 
|  | 591 | cmd->duplex	= DUPLEX_HALF; | 
|  | 592 | cmd->port	= dev->if_port == IF_PORT_10BASET ? PORT_TP : PORT_BNC; | 
|  | 593 | cmd->autoneg	= dev->flags & IFF_AUTOMEDIA ? AUTONEG_ENABLE : AUTONEG_DISABLE; | 
|  | 594 | return 0; | 
|  | 595 | } | 
|  | 596 |  | 
|  | 597 | static int etherh_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | 
|  | 598 | { | 
|  | 599 | switch (cmd->autoneg) { | 
|  | 600 | case AUTONEG_ENABLE: | 
|  | 601 | dev->flags |= IFF_AUTOMEDIA; | 
|  | 602 | break; | 
|  | 603 |  | 
|  | 604 | case AUTONEG_DISABLE: | 
|  | 605 | switch (cmd->port) { | 
|  | 606 | case PORT_TP: | 
|  | 607 | dev->if_port = IF_PORT_10BASET; | 
|  | 608 | break; | 
|  | 609 |  | 
|  | 610 | case PORT_BNC: | 
|  | 611 | dev->if_port = IF_PORT_10BASE2; | 
|  | 612 | break; | 
|  | 613 |  | 
|  | 614 | default: | 
|  | 615 | return -EINVAL; | 
|  | 616 | } | 
|  | 617 | dev->flags &= ~IFF_AUTOMEDIA; | 
|  | 618 | break; | 
|  | 619 |  | 
|  | 620 | default: | 
|  | 621 | return -EINVAL; | 
|  | 622 | } | 
|  | 623 |  | 
|  | 624 | etherh_setif(dev); | 
|  | 625 |  | 
|  | 626 | return 0; | 
|  | 627 | } | 
|  | 628 |  | 
|  | 629 | static struct ethtool_ops etherh_ethtool_ops = { | 
|  | 630 | .get_settings	= etherh_get_settings, | 
|  | 631 | .set_settings	= etherh_set_settings, | 
|  | 632 | .get_drvinfo	= etherh_get_drvinfo, | 
|  | 633 | }; | 
|  | 634 |  | 
|  | 635 | static u32 etherh_regoffsets[16]; | 
|  | 636 | static u32 etherm_regoffsets[16]; | 
|  | 637 |  | 
|  | 638 | static int __init | 
|  | 639 | etherh_probe(struct expansion_card *ec, const struct ecard_id *id) | 
|  | 640 | { | 
|  | 641 | const struct etherh_data *data = id->data; | 
|  | 642 | struct ei_device *ei_local; | 
|  | 643 | struct net_device *dev; | 
|  | 644 | struct etherh_priv *eh; | 
|  | 645 | int i, ret; | 
|  | 646 |  | 
|  | 647 | etherh_banner(); | 
|  | 648 |  | 
|  | 649 | ret = ecard_request_resources(ec); | 
|  | 650 | if (ret) | 
|  | 651 | goto out; | 
|  | 652 |  | 
|  | 653 | dev = __alloc_ei_netdev(sizeof(struct etherh_priv)); | 
|  | 654 | if (!dev) { | 
|  | 655 | ret = -ENOMEM; | 
|  | 656 | goto release; | 
|  | 657 | } | 
|  | 658 |  | 
|  | 659 | SET_MODULE_OWNER(dev); | 
|  | 660 | SET_NETDEV_DEV(dev, &ec->dev); | 
|  | 661 |  | 
|  | 662 | dev->open		= etherh_open; | 
|  | 663 | dev->stop		= etherh_close; | 
|  | 664 | dev->set_config		= etherh_set_config; | 
|  | 665 | dev->irq		= ec->irq; | 
|  | 666 | dev->ethtool_ops	= ðerh_ethtool_ops; | 
|  | 667 |  | 
|  | 668 | if (data->supported & SUPPORTED_Autoneg) | 
|  | 669 | dev->flags |= IFF_AUTOMEDIA; | 
|  | 670 | if (data->supported & SUPPORTED_TP) { | 
|  | 671 | dev->flags |= IFF_PORTSEL; | 
|  | 672 | dev->if_port = IF_PORT_10BASET; | 
|  | 673 | } else if (data->supported & SUPPORTED_BNC) { | 
|  | 674 | dev->flags |= IFF_PORTSEL; | 
|  | 675 | dev->if_port = IF_PORT_10BASE2; | 
|  | 676 | } else | 
|  | 677 | dev->if_port = IF_PORT_UNKNOWN; | 
|  | 678 |  | 
|  | 679 | eh = etherh_priv(dev); | 
|  | 680 | eh->supported		= data->supported; | 
|  | 681 | eh->ctrl		= 0; | 
|  | 682 | eh->id			= ec->cid.product; | 
|  | 683 | eh->memc		= ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), PAGE_SIZE); | 
|  | 684 | if (!eh->memc) { | 
|  | 685 | ret = -ENOMEM; | 
|  | 686 | goto free; | 
|  | 687 | } | 
|  | 688 |  | 
|  | 689 | eh->ctrl_port = eh->memc; | 
|  | 690 | if (data->ctrl_ioc) { | 
|  | 691 | eh->ioc_fast = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), PAGE_SIZE); | 
|  | 692 | if (!eh->ioc_fast) { | 
|  | 693 | ret = -ENOMEM; | 
|  | 694 | goto free; | 
|  | 695 | } | 
|  | 696 | eh->ctrl_port = eh->ioc_fast; | 
|  | 697 | } | 
|  | 698 |  | 
| Nicolas Pitre | c7e7887 | 2005-06-29 18:10:54 +0100 | [diff] [blame] | 699 | dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | eh->dma_base = eh->memc + data->dataport_offset; | 
|  | 701 | eh->ctrl_port += data->ctrlport_offset; | 
|  | 702 |  | 
|  | 703 | /* | 
|  | 704 | * IRQ and control port handling - only for non-NIC slot cards. | 
|  | 705 | */ | 
|  | 706 | if (ec->slot_no != 8) { | 
|  | 707 | ec->ops		= ðerh_ops; | 
|  | 708 | ec->irq_data	= eh; | 
|  | 709 | } else { | 
|  | 710 | /* | 
|  | 711 | * If we're in the NIC slot, make sure the IRQ is enabled | 
|  | 712 | */ | 
|  | 713 | etherh_set_ctrl(eh, ETHERH_CP_IE); | 
|  | 714 | } | 
|  | 715 |  | 
|  | 716 | ei_local = netdev_priv(dev); | 
|  | 717 | spin_lock_init(&ei_local->page_lock); | 
|  | 718 |  | 
|  | 719 | if (ec->cid.product == PROD_ANT_ETHERM) { | 
|  | 720 | etherm_addr(dev->dev_addr); | 
|  | 721 | ei_local->reg_offset = etherm_regoffsets; | 
|  | 722 | } else { | 
|  | 723 | etherh_addr(dev->dev_addr, ec); | 
|  | 724 | ei_local->reg_offset = etherh_regoffsets; | 
|  | 725 | } | 
|  | 726 |  | 
|  | 727 | ei_local->name          = dev->name; | 
|  | 728 | ei_local->word16        = 1; | 
|  | 729 | ei_local->tx_start_page = data->tx_start_page; | 
|  | 730 | ei_local->rx_start_page = ei_local->tx_start_page + TX_PAGES; | 
|  | 731 | ei_local->stop_page     = data->stop_page; | 
|  | 732 | ei_local->reset_8390    = etherh_reset; | 
|  | 733 | ei_local->block_input   = etherh_block_input; | 
|  | 734 | ei_local->block_output  = etherh_block_output; | 
|  | 735 | ei_local->get_8390_hdr  = etherh_get_header; | 
|  | 736 | ei_local->interface_num = 0; | 
|  | 737 |  | 
|  | 738 | etherh_reset(dev); | 
|  | 739 | NS8390_init(dev, 0); | 
|  | 740 |  | 
|  | 741 | ret = register_netdev(dev); | 
|  | 742 | if (ret) | 
|  | 743 | goto free; | 
|  | 744 |  | 
|  | 745 | printk(KERN_INFO "%s: %s in slot %d, ", | 
|  | 746 | dev->name, data->name, ec->slot_no); | 
|  | 747 |  | 
|  | 748 | for (i = 0; i < 6; i++) | 
|  | 749 | printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':'); | 
|  | 750 |  | 
|  | 751 | ecard_set_drvdata(ec, dev); | 
|  | 752 |  | 
|  | 753 | return 0; | 
|  | 754 |  | 
|  | 755 | free: | 
|  | 756 | if (eh->ioc_fast) | 
|  | 757 | iounmap(eh->ioc_fast); | 
|  | 758 | if (eh->memc) | 
|  | 759 | iounmap(eh->memc); | 
|  | 760 | free_netdev(dev); | 
|  | 761 | release: | 
|  | 762 | ecard_release_resources(ec); | 
|  | 763 | out: | 
|  | 764 | return ret; | 
|  | 765 | } | 
|  | 766 |  | 
|  | 767 | static void __devexit etherh_remove(struct expansion_card *ec) | 
|  | 768 | { | 
|  | 769 | struct net_device *dev = ecard_get_drvdata(ec); | 
|  | 770 | struct etherh_priv *eh = etherh_priv(dev); | 
|  | 771 |  | 
|  | 772 | ecard_set_drvdata(ec, NULL); | 
|  | 773 |  | 
|  | 774 | unregister_netdev(dev); | 
|  | 775 | ec->ops = NULL; | 
|  | 776 |  | 
|  | 777 | if (eh->ioc_fast) | 
|  | 778 | iounmap(eh->ioc_fast); | 
|  | 779 | iounmap(eh->memc); | 
|  | 780 |  | 
|  | 781 | free_netdev(dev); | 
|  | 782 |  | 
|  | 783 | ecard_release_resources(ec); | 
|  | 784 | } | 
|  | 785 |  | 
|  | 786 | static struct etherh_data etherm_data = { | 
|  | 787 | .ns8390_offset		= ETHERM_NS8390, | 
|  | 788 | .dataport_offset	= ETHERM_NS8390 + ETHERM_DATAPORT, | 
|  | 789 | .ctrlport_offset	= ETHERM_NS8390 + ETHERM_CTRLPORT, | 
|  | 790 | .name			= "ANT EtherM", | 
|  | 791 | .supported		= SUPPORTED_10baseT_Half, | 
|  | 792 | .tx_start_page		= ETHERM_TX_START_PAGE, | 
|  | 793 | .stop_page		= ETHERM_STOP_PAGE, | 
|  | 794 | }; | 
|  | 795 |  | 
|  | 796 | static struct etherh_data etherlan500_data = { | 
|  | 797 | .ns8390_offset		= ETHERH500_NS8390, | 
|  | 798 | .dataport_offset	= ETHERH500_NS8390 + ETHERH500_DATAPORT, | 
|  | 799 | .ctrlport_offset	= ETHERH500_CTRLPORT, | 
|  | 800 | .ctrl_ioc		= 1, | 
|  | 801 | .name			= "i3 EtherH 500", | 
|  | 802 | .supported		= SUPPORTED_10baseT_Half, | 
|  | 803 | .tx_start_page		= ETHERH_TX_START_PAGE, | 
|  | 804 | .stop_page		= ETHERH_STOP_PAGE, | 
|  | 805 | }; | 
|  | 806 |  | 
|  | 807 | static struct etherh_data etherlan600_data = { | 
|  | 808 | .ns8390_offset		= ETHERH600_NS8390, | 
|  | 809 | .dataport_offset	= ETHERH600_NS8390 + ETHERH600_DATAPORT, | 
|  | 810 | .ctrlport_offset	= ETHERH600_NS8390 + ETHERH600_CTRLPORT, | 
|  | 811 | .name			= "i3 EtherH 600", | 
|  | 812 | .supported		= SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg, | 
|  | 813 | .tx_start_page		= ETHERH_TX_START_PAGE, | 
|  | 814 | .stop_page		= ETHERH_STOP_PAGE, | 
|  | 815 | }; | 
|  | 816 |  | 
|  | 817 | static struct etherh_data etherlan600a_data = { | 
|  | 818 | .ns8390_offset		= ETHERH600_NS8390, | 
|  | 819 | .dataport_offset	= ETHERH600_NS8390 + ETHERH600_DATAPORT, | 
|  | 820 | .ctrlport_offset	= ETHERH600_NS8390 + ETHERH600_CTRLPORT, | 
|  | 821 | .name			= "i3 EtherH 600A", | 
|  | 822 | .supported		= SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg, | 
|  | 823 | .tx_start_page		= ETHERH_TX_START_PAGE, | 
|  | 824 | .stop_page		= ETHERH_STOP_PAGE, | 
|  | 825 | }; | 
|  | 826 |  | 
|  | 827 | static const struct ecard_id etherh_ids[] = { | 
|  | 828 | { MANU_ANT, PROD_ANT_ETHERM,      ðerm_data       }, | 
|  | 829 | { MANU_I3,  PROD_I3_ETHERLAN500,  ðerlan500_data  }, | 
|  | 830 | { MANU_I3,  PROD_I3_ETHERLAN600,  ðerlan600_data  }, | 
|  | 831 | { MANU_I3,  PROD_I3_ETHERLAN600A, ðerlan600a_data }, | 
|  | 832 | { 0xffff,   0xffff } | 
|  | 833 | }; | 
|  | 834 |  | 
|  | 835 | static struct ecard_driver etherh_driver = { | 
|  | 836 | .probe		= etherh_probe, | 
|  | 837 | .remove		= __devexit_p(etherh_remove), | 
|  | 838 | .id_table	= etherh_ids, | 
|  | 839 | .drv = { | 
|  | 840 | .name	= DRV_NAME, | 
|  | 841 | }, | 
|  | 842 | }; | 
|  | 843 |  | 
|  | 844 | static int __init etherh_init(void) | 
|  | 845 | { | 
|  | 846 | int i; | 
|  | 847 |  | 
|  | 848 | for (i = 0; i < 16; i++) { | 
|  | 849 | etherh_regoffsets[i] = i << 2; | 
|  | 850 | etherm_regoffsets[i] = i << 5; | 
|  | 851 | } | 
|  | 852 |  | 
|  | 853 | return ecard_register_driver(ðerh_driver); | 
|  | 854 | } | 
|  | 855 |  | 
|  | 856 | static void __exit etherh_exit(void) | 
|  | 857 | { | 
|  | 858 | ecard_remove_driver(ðerh_driver); | 
|  | 859 | } | 
|  | 860 |  | 
|  | 861 | module_init(etherh_init); | 
|  | 862 | module_exit(etherh_exit); |