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