Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* mac8390.c: New driver for 8390-based Nubus (or Nubus-alike) |
| 2 | Ethernet cards on Linux */ |
| 3 | /* Based on the former daynaport.c driver, by Alan Cox. Some code |
| 4 | taken from or inspired by skeleton.c by Donald Becker, acenic.c by |
| 5 | Jes Sorensen, and ne2k-pci.c by Donald Becker and Paul Gortmaker. |
| 6 | |
| 7 | This software may be used and distributed according to the terms of |
| 8 | the GNU Public License, incorporated herein by reference. */ |
| 9 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10 | /* 2000-02-28: support added for Dayna and Kinetics cards by |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | A.G.deWijn@phys.uu.nl */ |
| 12 | /* 2000-04-04: support added for Dayna2 by bart@etpmod.phys.tue.nl */ |
| 13 | /* 2001-04-18: support for DaynaPort E/LC-M by rayk@knightsmanor.org */ |
| 14 | /* 2001-05-15: support for Cabletron ported from old daynaport driver |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 15 | * and fixed access to Sonic Sys card which masquerades as a Farallon |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * by rayk@knightsmanor.org */ |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 17 | /* 2002-12-30: Try to support more cards, some clues from NetBSD driver */ |
| 18 | /* 2003-12-26: Make sure Asante cards always work. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/fcntl.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/ptrace.h> |
| 26 | #include <linux/ioport.h> |
| 27 | #include <linux/nubus.h> |
| 28 | #include <linux/in.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/errno.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/skbuff.h> |
| 36 | #include <linux/bitops.h> |
| 37 | |
| 38 | #include <asm/system.h> |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/dma.h> |
| 41 | #include <asm/hwtest.h> |
| 42 | #include <asm/macints.h> |
| 43 | |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 44 | static char version[] = |
| 45 | "mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n"; |
| 46 | |
| 47 | #define EI_SHIFT(x) (ei_local->reg_offset[x]) |
| 48 | #define ei_inb(port) in_8(port) |
| 49 | #define ei_outb(val,port) out_8(port,val) |
| 50 | #define ei_inb_p(port) in_8(port) |
| 51 | #define ei_outb_p(val,port) out_8(port,val) |
| 52 | |
| 53 | #include "lib8390.c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #define WD_START_PG 0x00 /* First page of TX buffer */ |
| 56 | #define CABLETRON_RX_START_PG 0x00 /* First page of RX buffer */ |
| 57 | #define CABLETRON_RX_STOP_PG 0x30 /* Last page +1 of RX ring */ |
| 58 | #define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG /* First page of TX buffer */ |
| 59 | |
| 60 | /* Unfortunately it seems we have to hardcode these for the moment */ |
| 61 | /* Shouldn't the card know about this? Does anyone know where to read it off the card? Do we trust the data provided by the card? */ |
| 62 | |
| 63 | #define DAYNA_8390_BASE 0x80000 |
| 64 | #define DAYNA_8390_MEM 0x00000 |
| 65 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 66 | #define CABLETRON_8390_BASE 0x90000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define CABLETRON_8390_MEM 0x00000 |
| 68 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 69 | #define INTERLAN_8390_BASE 0xE0000 |
| 70 | #define INTERLAN_8390_MEM 0xD0000 |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | enum mac8390_type { |
| 73 | MAC8390_NONE = -1, |
| 74 | MAC8390_APPLE, |
| 75 | MAC8390_ASANTE, |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 76 | MAC8390_FARALLON, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | MAC8390_CABLETRON, |
| 78 | MAC8390_DAYNA, |
| 79 | MAC8390_INTERLAN, |
| 80 | MAC8390_KINETICS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static const char * cardname[] = { |
| 84 | "apple", |
| 85 | "asante", |
| 86 | "farallon", |
| 87 | "cabletron", |
| 88 | "dayna", |
| 89 | "interlan", |
| 90 | "kinetics", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | static int word16[] = { |
| 94 | 1, /* apple */ |
| 95 | 1, /* asante */ |
| 96 | 1, /* farallon */ |
| 97 | 1, /* cabletron */ |
| 98 | 0, /* dayna */ |
| 99 | 1, /* interlan */ |
| 100 | 0, /* kinetics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /* on which cards do we use NuBus resources? */ |
| 104 | static int useresources[] = { |
| 105 | 1, /* apple */ |
| 106 | 1, /* asante */ |
| 107 | 1, /* farallon */ |
| 108 | 0, /* cabletron */ |
| 109 | 0, /* dayna */ |
| 110 | 0, /* interlan */ |
| 111 | 0, /* kinetics */ |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | enum mac8390_access { |
| 115 | ACCESS_UNKNOWN = 0, |
| 116 | ACCESS_32, |
| 117 | ACCESS_16, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | extern int mac8390_memtest(struct net_device * dev); |
| 121 | static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev, |
| 122 | enum mac8390_type type); |
| 123 | |
| 124 | static int mac8390_open(struct net_device * dev); |
| 125 | static int mac8390_close(struct net_device * dev); |
| 126 | static void mac8390_no_reset(struct net_device *dev); |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 127 | static void interlan_reset(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 129 | /* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | static void sane_get_8390_hdr(struct net_device *dev, |
| 131 | struct e8390_pkt_hdr *hdr, int ring_page); |
| 132 | static void sane_block_input(struct net_device * dev, int count, |
| 133 | struct sk_buff * skb, int ring_offset); |
| 134 | static void sane_block_output(struct net_device * dev, int count, |
| 135 | const unsigned char * buf, const int start_page); |
| 136 | |
| 137 | /* dayna_memcpy to and from card */ |
| 138 | static void dayna_memcpy_fromcard(struct net_device *dev, void *to, |
| 139 | int from, int count); |
| 140 | static void dayna_memcpy_tocard(struct net_device *dev, int to, |
| 141 | const void *from, int count); |
| 142 | |
| 143 | /* Dayna - Dayna/Kinetics use this */ |
| 144 | static void dayna_get_8390_hdr(struct net_device *dev, |
| 145 | struct e8390_pkt_hdr *hdr, int ring_page); |
| 146 | static void dayna_block_input(struct net_device *dev, int count, |
| 147 | struct sk_buff *skb, int ring_offset); |
| 148 | static void dayna_block_output(struct net_device *dev, int count, |
| 149 | const unsigned char *buf, int start_page); |
| 150 | |
| 151 | #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c)) |
| 152 | #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c)) |
| 153 | |
| 154 | /* Slow Sane (16-bit chunk memory read/write) Cabletron uses this */ |
| 155 | static void slow_sane_get_8390_hdr(struct net_device *dev, |
| 156 | struct e8390_pkt_hdr *hdr, int ring_page); |
| 157 | static void slow_sane_block_input(struct net_device *dev, int count, |
| 158 | struct sk_buff *skb, int ring_offset); |
| 159 | static void slow_sane_block_output(struct net_device *dev, int count, |
| 160 | const unsigned char *buf, int start_page); |
| 161 | static void word_memcpy_tocard(void *tp, const void *fp, int count); |
| 162 | static void word_memcpy_fromcard(void *tp, const void *fp, int count); |
| 163 | |
Adrian Bunk | 909fa88 | 2008-06-10 01:23:39 +0300 | [diff] [blame] | 164 | static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 166 | switch (dev->dr_sw) { |
| 167 | case NUBUS_DRSW_3COM: |
| 168 | switch (dev->dr_hw) { |
| 169 | case NUBUS_DRHW_APPLE_SONIC_NB: |
| 170 | case NUBUS_DRHW_APPLE_SONIC_LC: |
| 171 | case NUBUS_DRHW_SONNET: |
| 172 | return MAC8390_NONE; |
| 173 | break; |
| 174 | default: |
| 175 | return MAC8390_APPLE; |
| 176 | break; |
| 177 | } |
| 178 | break; |
| 179 | |
| 180 | case NUBUS_DRSW_APPLE: |
| 181 | switch (dev->dr_hw) { |
| 182 | case NUBUS_DRHW_ASANTE_LC: |
| 183 | return MAC8390_NONE; |
| 184 | break; |
| 185 | case NUBUS_DRHW_CABLETRON: |
| 186 | return MAC8390_CABLETRON; |
| 187 | break; |
| 188 | default: |
| 189 | return MAC8390_APPLE; |
| 190 | break; |
| 191 | } |
| 192 | break; |
| 193 | |
| 194 | case NUBUS_DRSW_ASANTE: |
| 195 | return MAC8390_ASANTE; |
| 196 | break; |
| 197 | |
| 198 | case NUBUS_DRSW_TECHWORKS: |
| 199 | case NUBUS_DRSW_DAYNA2: |
| 200 | case NUBUS_DRSW_DAYNA_LC: |
| 201 | if (dev->dr_hw == NUBUS_DRHW_CABLETRON) |
| 202 | return MAC8390_CABLETRON; |
| 203 | else |
| 204 | return MAC8390_APPLE; |
| 205 | break; |
| 206 | |
| 207 | case NUBUS_DRSW_FARALLON: |
| 208 | return MAC8390_FARALLON; |
| 209 | break; |
| 210 | |
| 211 | case NUBUS_DRSW_KINETICS: |
| 212 | switch (dev->dr_hw) { |
| 213 | case NUBUS_DRHW_INTERLAN: |
| 214 | return MAC8390_INTERLAN; |
| 215 | break; |
| 216 | default: |
| 217 | return MAC8390_KINETICS; |
| 218 | break; |
| 219 | } |
| 220 | break; |
| 221 | |
| 222 | case NUBUS_DRSW_DAYNA: |
| 223 | // These correspond to Dayna Sonic cards |
| 224 | // which use the macsonic driver |
| 225 | if (dev->dr_hw == NUBUS_DRHW_SMC9194 || |
| 226 | dev->dr_hw == NUBUS_DRHW_INTERLAN ) |
| 227 | return MAC8390_NONE; |
| 228 | else |
| 229 | return MAC8390_DAYNA; |
| 230 | break; |
| 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return MAC8390_NONE; |
| 233 | } |
| 234 | |
Adrian Bunk | 909fa88 | 2008-06-10 01:23:39 +0300 | [diff] [blame] | 235 | static enum mac8390_access __init mac8390_testio(volatile unsigned long membase) |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 236 | { |
| 237 | unsigned long outdata = 0xA5A0B5B0; |
| 238 | unsigned long indata = 0x00000000; |
| 239 | /* Try writing 32 bits */ |
| 240 | memcpy((char *)membase, (char *)&outdata, 4); |
| 241 | /* Now compare them */ |
| 242 | if (memcmp((char *)&outdata, (char *)membase, 4) == 0) |
| 243 | return ACCESS_32; |
| 244 | /* Write 16 bit output */ |
| 245 | word_memcpy_tocard((char *)membase, (char *)&outdata, 4); |
| 246 | /* Now read it back */ |
| 247 | word_memcpy_fromcard((char *)&indata, (char *)membase, 4); |
| 248 | if (outdata == indata) |
| 249 | return ACCESS_16; |
| 250 | return ACCESS_UNKNOWN; |
| 251 | } |
| 252 | |
Adrian Bunk | 909fa88 | 2008-06-10 01:23:39 +0300 | [diff] [blame] | 253 | static int __init mac8390_memsize(unsigned long membase) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | unsigned long flags; |
| 256 | int i, j; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | local_irq_save(flags); |
| 259 | /* Check up to 32K in 4K increments */ |
| 260 | for (i = 0; i < 8; i++) { |
| 261 | volatile unsigned short *m = (unsigned short *) (membase + (i * 0x1000)); |
| 262 | |
| 263 | /* Unwriteable - we have a fully decoded card and the |
| 264 | RAM end located */ |
| 265 | if (hwreg_present(m) == 0) |
| 266 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /* write a distinctive byte */ |
| 269 | *m = 0xA5A0 | i; |
| 270 | /* check that we read back what we wrote */ |
| 271 | if (*m != (0xA5A0 | i)) |
| 272 | break; |
| 273 | |
| 274 | /* check for partial decode and wrap */ |
| 275 | for (j = 0; j < i; j++) { |
| 276 | volatile unsigned short *p = (unsigned short *) (membase + (j * 0x1000)); |
| 277 | if (*p != (0xA5A0 | j)) |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | local_irq_restore(flags); |
| 282 | /* in any case, we stopped once we tried one block too many, |
| 283 | or once we reached 32K */ |
| 284 | return i * 0x1000; |
| 285 | } |
| 286 | |
| 287 | struct net_device * __init mac8390_probe(int unit) |
| 288 | { |
| 289 | struct net_device *dev; |
| 290 | volatile unsigned short *i; |
| 291 | int version_disp = 0; |
| 292 | struct nubus_dev * ndev = NULL; |
| 293 | int err = -ENODEV; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | struct nubus_dir dir; |
| 296 | struct nubus_dirent ent; |
| 297 | int offset; |
| 298 | static unsigned int slots; |
| 299 | |
| 300 | enum mac8390_type cardtype; |
| 301 | |
| 302 | /* probably should check for Nubus instead */ |
| 303 | |
| 304 | if (!MACH_IS_MAC) |
| 305 | return ERR_PTR(-ENODEV); |
| 306 | |
Finn Thain | 217cbfa | 2009-05-25 22:43:49 -0700 | [diff] [blame] | 307 | dev = ____alloc_ei_netdev(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | if (!dev) |
| 309 | return ERR_PTR(-ENOMEM); |
| 310 | |
| 311 | if (unit >= 0) |
| 312 | sprintf(dev->name, "eth%d", unit); |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, ndev))) { |
| 315 | /* Have we seen it already? */ |
| 316 | if (slots & (1<<ndev->board->slot)) |
| 317 | continue; |
| 318 | slots |= 1<<ndev->board->slot; |
| 319 | |
| 320 | if ((cardtype = mac8390_ident(ndev)) == MAC8390_NONE) |
| 321 | continue; |
| 322 | |
| 323 | if (version_disp == 0) { |
| 324 | version_disp = 1; |
| 325 | printk(version); |
| 326 | } |
| 327 | |
| 328 | dev->irq = SLOT2IRQ(ndev->board->slot); |
| 329 | /* This is getting to be a habit */ |
| 330 | dev->base_addr = ndev->board->slot_addr | ((ndev->board->slot&0xf) << 20); |
| 331 | |
| 332 | /* Get some Nubus info - we will trust the card's idea |
| 333 | of where its memory and registers are. */ |
| 334 | |
| 335 | if (nubus_get_func_dir(ndev, &dir) == -1) { |
| 336 | printk(KERN_ERR "%s: Unable to get Nubus functional" |
| 337 | " directory for slot %X!\n", |
| 338 | dev->name, ndev->board->slot); |
| 339 | continue; |
| 340 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /* Get the MAC address */ |
| 343 | if ((nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent)) == -1) { |
| 344 | printk(KERN_INFO "%s: Couldn't get MAC address!\n", |
| 345 | dev->name); |
| 346 | continue; |
| 347 | } else { |
| 348 | nubus_get_rsrc_mem(dev->dev_addr, &ent, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | if (useresources[cardtype] == 1) { |
| 352 | nubus_rewinddir(&dir); |
| 353 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, &ent) == -1) { |
| 354 | printk(KERN_ERR "%s: Memory offset resource" |
| 355 | " for slot %X not found!\n", |
| 356 | dev->name, ndev->board->slot); |
| 357 | continue; |
| 358 | } |
| 359 | nubus_get_rsrc_mem(&offset, &ent, 4); |
| 360 | dev->mem_start = dev->base_addr + offset; |
| 361 | /* yes, this is how the Apple driver does it */ |
| 362 | dev->base_addr = dev->mem_start + 0x10000; |
| 363 | nubus_rewinddir(&dir); |
| 364 | if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH, &ent) == -1) { |
| 365 | printk(KERN_INFO "%s: Memory length resource" |
| 366 | " for slot %X not found" |
| 367 | ", probing\n", |
| 368 | dev->name, ndev->board->slot); |
| 369 | offset = mac8390_memsize(dev->mem_start); |
| 370 | } else { |
| 371 | nubus_get_rsrc_mem(&offset, &ent, 4); |
| 372 | } |
| 373 | dev->mem_end = dev->mem_start + offset; |
| 374 | } else { |
| 375 | switch (cardtype) { |
| 376 | case MAC8390_KINETICS: |
| 377 | case MAC8390_DAYNA: /* it's the same */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 378 | dev->base_addr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | (int)(ndev->board->slot_addr + |
| 380 | DAYNA_8390_BASE); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 381 | dev->mem_start = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | (int)(ndev->board->slot_addr + |
| 383 | DAYNA_8390_MEM); |
| 384 | dev->mem_end = |
| 385 | dev->mem_start + |
| 386 | mac8390_memsize(dev->mem_start); |
| 387 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 388 | case MAC8390_INTERLAN: |
| 389 | dev->base_addr = |
| 390 | (int)(ndev->board->slot_addr + |
| 391 | INTERLAN_8390_BASE); |
| 392 | dev->mem_start = |
| 393 | (int)(ndev->board->slot_addr + |
| 394 | INTERLAN_8390_MEM); |
| 395 | dev->mem_end = |
| 396 | dev->mem_start + |
| 397 | mac8390_memsize(dev->mem_start); |
| 398 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | case MAC8390_CABLETRON: |
| 400 | dev->base_addr = |
| 401 | (int)(ndev->board->slot_addr + |
| 402 | CABLETRON_8390_BASE); |
| 403 | dev->mem_start = |
| 404 | (int)(ndev->board->slot_addr + |
| 405 | CABLETRON_8390_MEM); |
| 406 | /* The base address is unreadable if 0x00 |
| 407 | * has been written to the command register |
| 408 | * Reset the chip by writing E8390_NODMA + |
| 409 | * E8390_PAGE0 + E8390_STOP just to be |
| 410 | * sure |
| 411 | */ |
| 412 | i = (void *)dev->base_addr; |
| 413 | *i = 0x21; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 414 | dev->mem_end = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | dev->mem_start + |
| 416 | mac8390_memsize(dev->mem_start); |
| 417 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | default: |
| 420 | printk(KERN_ERR "Card type %s is" |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 421 | " unsupported, sorry\n", |
| 422 | ndev->board->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | continue; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /* Do the nasty 8390 stuff */ |
| 428 | if (!mac8390_initdev(dev, ndev, cardtype)) |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | if (!ndev) |
| 433 | goto out; |
| 434 | err = register_netdev(dev); |
| 435 | if (err) |
| 436 | goto out; |
| 437 | return dev; |
| 438 | |
| 439 | out: |
| 440 | free_netdev(dev); |
| 441 | return ERR_PTR(err); |
| 442 | } |
| 443 | |
| 444 | #ifdef MODULE |
| 445 | MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others"); |
| 446 | MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver"); |
| 447 | MODULE_LICENSE("GPL"); |
| 448 | |
| 449 | /* overkill, of course */ |
| 450 | static struct net_device *dev_mac8390[15]; |
| 451 | int init_module(void) |
| 452 | { |
| 453 | int i; |
| 454 | for (i = 0; i < 15; i++) { |
| 455 | struct net_device *dev = mac8390_probe(-1); |
| 456 | if (IS_ERR(dev)) |
| 457 | break; |
| 458 | dev_mac890[i] = dev; |
| 459 | } |
| 460 | if (!i) { |
| 461 | printk(KERN_NOTICE "mac8390.c: No useable cards found, driver NOT installed.\n"); |
| 462 | return -ENODEV; |
| 463 | } |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | void cleanup_module(void) |
| 468 | { |
| 469 | int i; |
| 470 | for (i = 0; i < 15; i++) { |
| 471 | struct net_device *dev = dev_mac890[i]; |
| 472 | if (dev) { |
| 473 | unregister_netdev(dev); |
| 474 | free_netdev(dev); |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | #endif /* MODULE */ |
| 480 | |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 481 | static const struct net_device_ops mac8390_netdev_ops = { |
| 482 | .ndo_open = mac8390_open, |
| 483 | .ndo_stop = mac8390_close, |
Finn Thain | 217cbfa | 2009-05-25 22:43:49 -0700 | [diff] [blame] | 484 | .ndo_start_xmit = __ei_start_xmit, |
| 485 | .ndo_tx_timeout = __ei_tx_timeout, |
| 486 | .ndo_get_stats = __ei_get_stats, |
| 487 | .ndo_set_multicast_list = __ei_set_multicast_list, |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 488 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | fe96aaa | 2009-01-09 11:13:14 +0000 | [diff] [blame] | 489 | .ndo_set_mac_address = eth_mac_addr, |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 490 | .ndo_change_mtu = eth_change_mtu, |
| 491 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Finn Thain | 4e0168f | 2009-05-28 02:05:53 +0000 | [diff] [blame] | 492 | .ndo_poll_controller = __ei_poll, |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 493 | #endif |
| 494 | }; |
| 495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev, |
| 497 | enum mac8390_type type) |
| 498 | { |
| 499 | static u32 fwrd4_offsets[16]={ |
| 500 | 0, 4, 8, 12, |
| 501 | 16, 20, 24, 28, |
| 502 | 32, 36, 40, 44, |
| 503 | 48, 52, 56, 60 |
| 504 | }; |
| 505 | static u32 back4_offsets[16]={ |
| 506 | 60, 56, 52, 48, |
| 507 | 44, 40, 36, 32, |
| 508 | 28, 24, 20, 16, |
| 509 | 12, 8, 4, 0 |
| 510 | }; |
| 511 | static u32 fwrd2_offsets[16]={ |
| 512 | 0, 2, 4, 6, |
| 513 | 8, 10, 12, 14, |
| 514 | 16, 18, 20, 22, |
| 515 | 24, 26, 28, 30 |
| 516 | }; |
| 517 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 518 | int access_bitmode = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | /* Now fill in our stuff */ |
Stephen Hemminger | ca17584 | 2008-12-02 15:00:28 -0800 | [diff] [blame] | 521 | dev->netdev_ops = &mac8390_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | /* GAR, ei_status is actually a macro even though it looks global */ |
| 524 | ei_status.name = cardname[type]; |
| 525 | ei_status.word16 = word16[type]; |
| 526 | |
| 527 | /* Cabletron's TX/RX buffers are backwards */ |
| 528 | if (type == MAC8390_CABLETRON) { |
| 529 | ei_status.tx_start_page = CABLETRON_TX_START_PG; |
| 530 | ei_status.rx_start_page = CABLETRON_RX_START_PG; |
| 531 | ei_status.stop_page = CABLETRON_RX_STOP_PG; |
| 532 | ei_status.rmem_start = dev->mem_start; |
| 533 | ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256; |
| 534 | } else { |
| 535 | ei_status.tx_start_page = WD_START_PG; |
| 536 | ei_status.rx_start_page = WD_START_PG + TX_PAGES; |
| 537 | ei_status.stop_page = (dev->mem_end - dev->mem_start)/256; |
| 538 | ei_status.rmem_start = dev->mem_start + TX_PAGES*256; |
| 539 | ei_status.rmem_end = dev->mem_end; |
| 540 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* Fill in model-specific information and functions */ |
| 543 | switch(type) { |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 544 | case MAC8390_FARALLON: |
| 545 | case MAC8390_APPLE: |
| 546 | switch(mac8390_testio(dev->mem_start)) { |
| 547 | case ACCESS_UNKNOWN: |
| 548 | printk("Don't know how to access card memory!\n"); |
| 549 | return -ENODEV; |
| 550 | break; |
| 551 | |
| 552 | case ACCESS_16: |
| 553 | /* 16 bit card, register map is reversed */ |
| 554 | ei_status.reset_8390 = &mac8390_no_reset; |
| 555 | ei_status.block_input = &slow_sane_block_input; |
| 556 | ei_status.block_output = &slow_sane_block_output; |
| 557 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
| 558 | ei_status.reg_offset = back4_offsets; |
| 559 | break; |
| 560 | |
| 561 | case ACCESS_32: |
| 562 | /* 32 bit card, register map is reversed */ |
| 563 | ei_status.reset_8390 = &mac8390_no_reset; |
| 564 | ei_status.block_input = &sane_block_input; |
| 565 | ei_status.block_output = &sane_block_output; |
| 566 | ei_status.get_8390_hdr = &sane_get_8390_hdr; |
| 567 | ei_status.reg_offset = back4_offsets; |
| 568 | access_bitmode = 1; |
| 569 | break; |
| 570 | } |
| 571 | break; |
| 572 | |
| 573 | case MAC8390_ASANTE: |
| 574 | /* Some Asante cards pass the 32 bit test |
| 575 | * but overwrite system memory when run at 32 bit. |
| 576 | * so we run them all at 16 bit. |
| 577 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | ei_status.reset_8390 = &mac8390_no_reset; |
| 579 | ei_status.block_input = &slow_sane_block_input; |
| 580 | ei_status.block_output = &slow_sane_block_output; |
| 581 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
| 582 | ei_status.reg_offset = back4_offsets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | case MAC8390_CABLETRON: |
| 586 | /* 16 bit card, register map is short forward */ |
| 587 | ei_status.reset_8390 = &mac8390_no_reset; |
| 588 | ei_status.block_input = &slow_sane_block_input; |
| 589 | ei_status.block_output = &slow_sane_block_output; |
| 590 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
| 591 | ei_status.reg_offset = fwrd2_offsets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | case MAC8390_DAYNA: |
| 595 | case MAC8390_KINETICS: |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 596 | /* 16 bit memory, register map is forward */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /* dayna and similar */ |
| 598 | ei_status.reset_8390 = &mac8390_no_reset; |
| 599 | ei_status.block_input = &dayna_block_input; |
| 600 | ei_status.block_output = &dayna_block_output; |
| 601 | ei_status.get_8390_hdr = &dayna_get_8390_hdr; |
| 602 | ei_status.reg_offset = fwrd4_offsets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | break; |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 604 | |
| 605 | case MAC8390_INTERLAN: |
| 606 | /* 16 bit memory, register map is forward */ |
| 607 | ei_status.reset_8390 = &interlan_reset; |
| 608 | ei_status.block_input = &slow_sane_block_input; |
| 609 | ei_status.block_output = &slow_sane_block_output; |
| 610 | ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; |
| 611 | ei_status.reg_offset = fwrd4_offsets; |
| 612 | break; |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | default: |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 615 | printk(KERN_ERR "Card type %s is unsupported, sorry\n", ndev->board->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | return -ENODEV; |
| 617 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 618 | |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 619 | __NS8390_init(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | /* Good, done, now spit out some messages */ |
| 622 | printk(KERN_INFO "%s: %s in slot %X (type %s)\n", |
Finn Thain | cd39c7a | 2009-05-25 16:52:47 +0000 | [diff] [blame] | 623 | dev->name, ndev->board->name, ndev->board->slot, cardname[type]); |
| 624 | printk(KERN_INFO |
| 625 | "MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n", |
| 626 | dev->dev_addr, dev->irq, |
| 627 | (unsigned int)(dev->mem_end - dev->mem_start) >> 10, |
| 628 | dev->mem_start, access_bitmode ? 32 : 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | static int mac8390_open(struct net_device *dev) |
| 633 | { |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 634 | __ei_open(dev); |
| 635 | if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq); |
| 637 | return -EAGAIN; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static int mac8390_close(struct net_device *dev) |
| 643 | { |
| 644 | free_irq(dev->irq, dev); |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 645 | __ei_close(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | static void mac8390_no_reset(struct net_device *dev) |
| 650 | { |
| 651 | ei_status.txing = 0; |
| 652 | if (ei_debug > 1) |
| 653 | printk("reset not supported\n"); |
| 654 | return; |
| 655 | } |
| 656 | |
Finn Thain | 2964db0 | 2007-05-01 22:32:54 +0200 | [diff] [blame] | 657 | static void interlan_reset(struct net_device *dev) |
| 658 | { |
| 659 | unsigned char *target=nubus_slot_addr(IRQ2SLOT(dev->irq)); |
| 660 | if (ei_debug > 1) |
| 661 | printk("Need to reset the NS8390 t=%lu...", jiffies); |
| 662 | ei_status.txing = 0; |
| 663 | target[0xC0000] = 0; |
| 664 | if (ei_debug > 1) |
| 665 | printk("reset complete\n"); |
| 666 | return; |
| 667 | } |
| 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | /* dayna_memcpy_fromio/dayna_memcpy_toio */ |
| 670 | /* directly from daynaport.c by Alan Cox */ |
| 671 | static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count) |
| 672 | { |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 673 | volatile unsigned char *ptr; |
| 674 | unsigned char *target=to; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | from<<=1; /* word, skip overhead */ |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 676 | ptr=(unsigned char *)(dev->mem_start+from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | /* Leading byte? */ |
| 678 | if (from&2) { |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 679 | *target++ = ptr[-1]; |
| 680 | ptr += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | count--; |
| 682 | } |
| 683 | while(count>=2) |
| 684 | { |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 685 | *(unsigned short *)target = *(unsigned short volatile *)ptr; |
| 686 | ptr += 4; /* skip cruft */ |
| 687 | target += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | count-=2; |
| 689 | } |
| 690 | /* Trailing byte? */ |
| 691 | if(count) |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 692 | *target = *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count) |
| 696 | { |
| 697 | volatile unsigned short *ptr; |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 698 | const unsigned char *src=from; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | to<<=1; /* word, skip overhead */ |
| 700 | ptr=(unsigned short *)(dev->mem_start+to); |
| 701 | /* Leading byte? */ |
| 702 | if (to&2) { /* avoid a byte write (stomps on other data) */ |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 703 | ptr[-1] = (ptr[-1]&0xFF00)|*src++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | ptr++; |
| 705 | count--; |
| 706 | } |
| 707 | while(count>=2) |
| 708 | { |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 709 | *ptr++=*(unsigned short *)src; /* Copy and */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | ptr++; /* skip cruft */ |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 711 | src += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | count-=2; |
| 713 | } |
| 714 | /* Trailing byte? */ |
| 715 | if(count) |
| 716 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | /* card doesn't like byte writes */ |
Al Viro | 09cc07a | 2006-01-12 01:06:21 -0800 | [diff] [blame] | 718 | *ptr=(*ptr&0x00FF)|(*src << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
| 722 | /* sane block input/output */ |
| 723 | static void sane_get_8390_hdr(struct net_device *dev, |
| 724 | struct e8390_pkt_hdr *hdr, int ring_page) |
| 725 | { |
| 726 | unsigned long hdr_start = (ring_page - WD_START_PG)<<8; |
| 727 | memcpy_fromio((void *)hdr, (char *)dev->mem_start + hdr_start, 4); |
| 728 | /* Fix endianness */ |
| 729 | hdr->count = swab16(hdr->count); |
| 730 | } |
| 731 | |
| 732 | static void sane_block_input(struct net_device *dev, int count, |
| 733 | struct sk_buff *skb, int ring_offset) |
| 734 | { |
| 735 | unsigned long xfer_base = ring_offset - (WD_START_PG<<8); |
| 736 | unsigned long xfer_start = xfer_base + dev->mem_start; |
| 737 | |
| 738 | if (xfer_start + count > ei_status.rmem_end) { |
| 739 | /* We must wrap the input move. */ |
| 740 | int semi_count = ei_status.rmem_end - xfer_start; |
| 741 | memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, semi_count); |
| 742 | count -= semi_count; |
| 743 | memcpy_toio(skb->data + semi_count, (char *)ei_status.rmem_start, count); |
| 744 | } else { |
| 745 | memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, count); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | static void sane_block_output(struct net_device *dev, int count, |
| 750 | const unsigned char *buf, int start_page) |
| 751 | { |
| 752 | long shmem = (start_page - WD_START_PG)<<8; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | memcpy_toio((char *)dev->mem_start + shmem, buf, count); |
| 755 | } |
| 756 | |
| 757 | /* dayna block input/output */ |
| 758 | static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) |
| 759 | { |
| 760 | unsigned long hdr_start = (ring_page - WD_START_PG)<<8; |
| 761 | |
| 762 | dayna_memcpy_fromcard(dev, (void *)hdr, hdr_start, 4); |
| 763 | /* Fix endianness */ |
| 764 | hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8); |
| 765 | } |
| 766 | |
| 767 | static void dayna_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) |
| 768 | { |
| 769 | unsigned long xfer_base = ring_offset - (WD_START_PG<<8); |
| 770 | unsigned long xfer_start = xfer_base+dev->mem_start; |
| 771 | |
| 772 | /* Note the offset math is done in card memory space which is word |
| 773 | per long onto our space. */ |
| 774 | |
| 775 | if (xfer_start + count > ei_status.rmem_end) |
| 776 | { |
| 777 | /* We must wrap the input move. */ |
| 778 | int semi_count = ei_status.rmem_end - xfer_start; |
| 779 | dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count); |
| 780 | count -= semi_count; |
| 781 | dayna_memcpy_fromcard(dev, skb->data + semi_count, |
| 782 | ei_status.rmem_start - dev->mem_start, |
| 783 | count); |
| 784 | } |
| 785 | else |
| 786 | { |
| 787 | dayna_memcpy_fromcard(dev, skb->data, xfer_base, count); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | static void dayna_block_output(struct net_device *dev, int count, const unsigned char *buf, |
| 792 | int start_page) |
| 793 | { |
| 794 | long shmem = (start_page - WD_START_PG)<<8; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | dayna_memcpy_tocard(dev, shmem, buf, count); |
| 797 | } |
| 798 | |
| 799 | /* Cabletron block I/O */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 800 | static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | int ring_page) |
| 802 | { |
| 803 | unsigned long hdr_start = (ring_page - WD_START_PG)<<8; |
| 804 | word_memcpy_fromcard((void *)hdr, (char *)dev->mem_start+hdr_start, 4); |
| 805 | /* Register endianism - fix here rather than 8390.c */ |
| 806 | hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8); |
| 807 | } |
| 808 | |
| 809 | static void slow_sane_block_input(struct net_device *dev, int count, struct sk_buff *skb, |
| 810 | int ring_offset) |
| 811 | { |
| 812 | unsigned long xfer_base = ring_offset - (WD_START_PG<<8); |
| 813 | unsigned long xfer_start = xfer_base+dev->mem_start; |
| 814 | |
| 815 | if (xfer_start + count > ei_status.rmem_end) |
| 816 | { |
| 817 | /* We must wrap the input move. */ |
| 818 | int semi_count = ei_status.rmem_end - xfer_start; |
| 819 | word_memcpy_fromcard(skb->data, (char *)dev->mem_start + |
| 820 | xfer_base, semi_count); |
| 821 | count -= semi_count; |
| 822 | word_memcpy_fromcard(skb->data + semi_count, |
| 823 | (char *)ei_status.rmem_start, count); |
| 824 | } |
| 825 | else |
| 826 | { |
| 827 | word_memcpy_fromcard(skb->data, (char *)dev->mem_start + |
| 828 | xfer_base, count); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | static void slow_sane_block_output(struct net_device *dev, int count, const unsigned char *buf, |
| 833 | int start_page) |
| 834 | { |
| 835 | long shmem = (start_page - WD_START_PG)<<8; |
| 836 | |
| 837 | word_memcpy_tocard((char *)dev->mem_start + shmem, buf, count); |
| 838 | } |
| 839 | |
| 840 | static void word_memcpy_tocard(void *tp, const void *fp, int count) |
| 841 | { |
| 842 | volatile unsigned short *to = tp; |
| 843 | const unsigned short *from = fp; |
| 844 | |
| 845 | count++; |
| 846 | count/=2; |
| 847 | |
| 848 | while(count--) |
| 849 | *to++=*from++; |
| 850 | } |
| 851 | |
| 852 | static void word_memcpy_fromcard(void *tp, const void *fp, int count) |
| 853 | { |
| 854 | unsigned short *to = tp; |
| 855 | const volatile unsigned short *from = fp; |
| 856 | |
| 857 | count++; |
| 858 | count/=2; |
| 859 | |
| 860 | while(count--) |
| 861 | *to++=*from++; |
| 862 | } |
| 863 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 864 | |