aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/cirrus
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2012-05-18 08:56:31 -0400
committerDavid S. Miller <davem@davemloft.net>2012-05-18 23:48:07 -0400
commit6fba180ee8b1c86b03d33013b4c2fc54fc5fc248 (patch)
treea80bed23a1e5cde7b0c5b72699e19cd98ef0b2ea /drivers/net/ethernet/cirrus
parent808e9a77358995612c250ad5319f4bfe12c8416d (diff)
cirrus: cs89x0: Remove function prototypes and reorder declarations
Move blocks of code around to avoid function prototypes. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/cirrus')
-rw-r--r--drivers/net/ethernet/cirrus/cs89x0.c1467
1 files changed, 721 insertions, 746 deletions
diff --git a/drivers/net/ethernet/cirrus/cs89x0.c b/drivers/net/ethernet/cirrus/cs89x0.c
index 859f8bec292b..845b2020f291 100644
--- a/drivers/net/ethernet/cirrus/cs89x0.c
+++ b/drivers/net/ethernet/cirrus/cs89x0.c
@@ -174,28 +174,6 @@ struct net_local {
174#endif 174#endif
175}; 175};
176 176
177/* Index to functions, as function prototypes. */
178static int net_open(struct net_device *dev);
179static netdev_tx_t net_send_packet(struct sk_buff *skb, struct net_device *dev);
180static irqreturn_t net_interrupt(int irq, void *dev_id);
181static void set_multicast_list(struct net_device *dev);
182static void net_timeout(struct net_device *dev);
183static void net_rx(struct net_device *dev);
184static int net_close(struct net_device *dev);
185static struct net_device_stats *net_get_stats(struct net_device *dev);
186static void reset_chip(struct net_device *dev);
187static int get_eeprom_data(struct net_device *dev, int off, int len, int *buffer);
188static int get_eeprom_cksum(int off, int len, int *buffer);
189static int set_mac_address(struct net_device *dev, void *addr);
190static void count_rx_errors(int status, struct net_device *dev);
191#ifdef CONFIG_NET_POLL_CONTROLLER
192static void net_poll_controller(struct net_device *dev);
193#endif
194#if ALLOW_DMA
195static void get_dma_channel(struct net_device *dev);
196static void release_dma_buff(struct net_local *lp);
197#endif
198
199/* Example routines you must write ;->. */ 177/* Example routines you must write ;->. */
200#define tx_done(dev) 1 178#define tx_done(dev) 1
201 179
@@ -321,7 +299,7 @@ get_eeprom_data(struct net_device *dev, int off, int len, int *buffer)
321{ 299{
322 int i; 300 int i;
323 301
324 cs89_dbg(3, info, "EEPROM data from %x for %x:\n", off, len); 302 cs89_dbg(3, info, "EEPROM data from %x for %x:", off, len);
325 for (i = 0; i < len; i++) { 303 for (i = 0; i < len; i++) {
326 if (wait_eeprom_ready(dev) < 0) 304 if (wait_eeprom_ready(dev) < 0)
327 return -1; 305 return -1;
@@ -330,7 +308,7 @@ get_eeprom_data(struct net_device *dev, int off, int len, int *buffer)
330 if (wait_eeprom_ready(dev) < 0) 308 if (wait_eeprom_ready(dev) < 0)
331 return -1; 309 return -1;
332 buffer[i] = readreg(dev, PP_EEData); 310 buffer[i] = readreg(dev, PP_EEData);
333 cs89_dbg(3, cont, "%04x ", buffer[i]); 311 cs89_dbg(3, cont, " %04x", buffer[i]);
334 } 312 }
335 cs89_dbg(3, cont, "\n"); 313 cs89_dbg(3, cont, "\n");
336 return 0; 314 return 0;
@@ -350,420 +328,44 @@ get_eeprom_cksum(int off, int len, int *buffer)
350 return -1; 328 return -1;
351} 329}
352 330
353#ifdef CONFIG_NET_POLL_CONTROLLER 331static void
354/* 332write_irq(struct net_device *dev, int chip_type, int irq)
355 * Polling receive - used by netconsole and other diagnostic tools
356 * to allow network i/o with interrupts disabled.
357 */
358static void net_poll_controller(struct net_device *dev)
359{
360 disable_irq(dev->irq);
361 net_interrupt(dev->irq, dev);
362 enable_irq(dev->irq);
363}
364#endif
365
366static const struct net_device_ops net_ops = {
367 .ndo_open = net_open,
368 .ndo_stop = net_close,
369 .ndo_tx_timeout = net_timeout,
370 .ndo_start_xmit = net_send_packet,
371 .ndo_get_stats = net_get_stats,
372 .ndo_set_rx_mode = set_multicast_list,
373 .ndo_set_mac_address = set_mac_address,
374#ifdef CONFIG_NET_POLL_CONTROLLER
375 .ndo_poll_controller = net_poll_controller,
376#endif
377 .ndo_change_mtu = eth_change_mtu,
378 .ndo_validate_addr = eth_validate_addr,
379};
380
381/* This is the real probe routine.
382 * Linux has a history of friendly device probes on the ISA bus.
383 * A good device probes avoids doing writes, and
384 * verifies that the correct device exists and functions.
385 * Return 0 on success.
386 */
387static int __init
388cs89x0_probe1(struct net_device *dev, void __iomem *ioaddr, int modular)
389{ 333{
390 struct net_local *lp = netdev_priv(dev);
391 int i; 334 int i;
392 int tmp;
393 unsigned rev_type = 0;
394 int eeprom_buff[CHKSUM_LEN];
395 int retval;
396 335
397 /* Initialize the device structure. */ 336 if (chip_type == CS8900) {
398 if (!modular) {
399 memset(lp, 0, sizeof(*lp));
400 spin_lock_init(&lp->lock);
401#ifndef MODULE
402#if ALLOW_DMA
403 if (g_cs89x0_dma) {
404 lp->use_dma = 1;
405 lp->dma = g_cs89x0_dma;
406 lp->dmasize = 16; /* Could make this an option... */
407 }
408#endif
409 lp->force = g_cs89x0_media__force;
410#endif
411 }
412
413 pr_debug("PP_addr at %p[%x]: 0x%x\n",
414 ioaddr, ADD_PORT, ioread16(ioaddr + ADD_PORT));
415 iowrite16(PP_ChipID, ioaddr + ADD_PORT);
416
417 tmp = ioread16(ioaddr + DATA_PORT);
418 if (tmp != CHIP_EISA_ID_SIG) {
419 pr_debug("%s: incorrect signature at %p[%x]: 0x%x!="
420 CHIP_EISA_ID_SIG_STR "\n",
421 dev->name, ioaddr, DATA_PORT, tmp);
422 retval = -ENODEV;
423 goto out1;
424 }
425
426 lp->virt_addr = ioaddr;
427
428 /* get the chip type */
429 rev_type = readreg(dev, PRODUCT_ID_ADD);
430 lp->chip_type = rev_type & ~REVISON_BITS;
431 lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
432
433 /* Check the chip type and revision in order to set the correct send command
434 CS8920 revision C and CS8900 revision F can use the faster send. */
435 lp->send_cmd = TX_AFTER_381;
436 if (lp->chip_type == CS8900 && lp->chip_revision >= 'F')
437 lp->send_cmd = TX_NOW;
438 if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
439 lp->send_cmd = TX_NOW;
440
441 pr_info_once("%s\n", version);
442
443 pr_info("%s: cs89%c0%s rev %c found at %p ",
444 dev->name,
445 lp->chip_type == CS8900 ? '0' : '2',
446 lp->chip_type == CS8920M ? "M" : "",
447 lp->chip_revision,
448 lp->virt_addr);
449
450 reset_chip(dev);
451
452 /* Here we read the current configuration of the chip.
453 * If there is no Extended EEPROM then the idea is to not disturb
454 * the chip configuration, it should have been correctly setup by
455 * automatic EEPROM read on reset. So, if the chip says it read
456 * the EEPROM the driver will always do *something* instead of
457 * complain that adapter_cnf is 0.
458 */
459
460 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) ==
461 (EEPROM_OK | EEPROM_PRESENT)) {
462 /* Load the MAC. */
463 for (i = 0; i < ETH_ALEN / 2; i++) {
464 unsigned int Addr;
465 Addr = readreg(dev, PP_IA + i * 2);
466 dev->dev_addr[i * 2] = Addr & 0xFF;
467 dev->dev_addr[i * 2 + 1] = Addr >> 8;
468 }
469
470 /* Load the Adapter Configuration.
471 * Note: Barring any more specific information from some
472 * other source (ie EEPROM+Schematics), we would not know
473 * how to operate a 10Base2 interface on the AUI port.
474 * However, since we do read the status of HCB1 and use
475 * settings that always result in calls to control_dc_dc(dev,0)
476 * a BNC interface should work if the enable pin
477 * (dc/dc converter) is on HCB1.
478 * It will be called AUI however.
479 */
480
481 lp->adapter_cnf = 0;
482 i = readreg(dev, PP_LineCTL);
483 /* Preserve the setting of the HCB1 pin. */
484 if ((i & (HCB1 | HCB1_ENBL)) == (HCB1 | HCB1_ENBL))
485 lp->adapter_cnf |= A_CNF_DC_DC_POLARITY;
486 /* Save the sqelch bit */
487 if ((i & LOW_RX_SQUELCH) == LOW_RX_SQUELCH)
488 lp->adapter_cnf |= A_CNF_EXTND_10B_2 | A_CNF_LOW_RX_SQUELCH;
489 /* Check if the card is in 10Base-t only mode */
490 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == 0)
491 lp->adapter_cnf |= A_CNF_10B_T | A_CNF_MEDIA_10B_T;
492 /* Check if the card is in AUI only mode */
493 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUI_ONLY)
494 lp->adapter_cnf |= A_CNF_AUI | A_CNF_MEDIA_AUI;
495 /* Check if the card is in Auto mode. */
496 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUTO_AUI_10BASET)
497 lp->adapter_cnf |= A_CNF_AUI | A_CNF_10B_T |
498 A_CNF_MEDIA_AUI | A_CNF_MEDIA_10B_T | A_CNF_MEDIA_AUTO;
499
500 cs89_dbg(1, info, "%s: PP_LineCTL=0x%x, adapter_cnf=0x%x\n",
501 dev->name, i, lp->adapter_cnf);
502
503 /* IRQ. Other chips already probe, see below. */
504 if (lp->chip_type == CS8900)
505 lp->isa_config = readreg(dev, PP_CS8900_ISAINT) & INT_NO_MASK;
506
507 pr_cont("[Cirrus EEPROM] ");
508 }
509
510 pr_cont("\n");
511
512 /* First check to see if an EEPROM is attached. */
513
514 if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
515 pr_warn("No EEPROM, relying on command line....\n");
516 else if (get_eeprom_data(dev, START_EEPROM_DATA, CHKSUM_LEN, eeprom_buff) < 0) {
517 pr_warn("EEPROM read failed, relying on command line\n");
518 } else if (get_eeprom_cksum(START_EEPROM_DATA, CHKSUM_LEN, eeprom_buff) < 0) {
519 /* Check if the chip was able to read its own configuration starting
520 at 0 in the EEPROM*/
521 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) !=
522 (EEPROM_OK | EEPROM_PRESENT))
523 pr_warn("Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command line\n");
524
525 } else {
526 /* This reads an extended EEPROM that is not documented
527 * in the CS8900 datasheet.
528 */
529
530 /* get transmission control word but keep the autonegotiation bits */
531 if (!lp->auto_neg_cnf)
532 lp->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET / 2];
533 /* Store adapter configuration */
534 if (!lp->adapter_cnf)
535 lp->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET / 2];
536 /* Store ISA configuration */
537 lp->isa_config = eeprom_buff[ISA_CNF_OFFSET / 2];
538 dev->mem_start = eeprom_buff[PACKET_PAGE_OFFSET / 2] << 8;
539
540 /* eeprom_buff has 32-bit ints, so we can't just memcpy it */
541 /* store the initial memory base address */
542 for (i = 0; i < ETH_ALEN / 2; i++) {
543 dev->dev_addr[i * 2] = eeprom_buff[i];
544 dev->dev_addr[i * 2 + 1] = eeprom_buff[i] >> 8;
545 }
546 cs89_dbg(1, debug, "%s: new adapter_cnf: 0x%x\n",
547 dev->name, lp->adapter_cnf);
548 }
549
550 /* allow them to force multiple transceivers. If they force multiple, autosense */
551 {
552 int count = 0;
553 if (lp->force & FORCE_RJ45) {
554 lp->adapter_cnf |= A_CNF_10B_T;
555 count++;
556 }
557 if (lp->force & FORCE_AUI) {
558 lp->adapter_cnf |= A_CNF_AUI;
559 count++;
560 }
561 if (lp->force & FORCE_BNC) {
562 lp->adapter_cnf |= A_CNF_10B_2;
563 count++;
564 }
565 if (count > 1)
566 lp->adapter_cnf |= A_CNF_MEDIA_AUTO;
567 else if (lp->force & FORCE_RJ45)
568 lp->adapter_cnf |= A_CNF_MEDIA_10B_T;
569 else if (lp->force & FORCE_AUI)
570 lp->adapter_cnf |= A_CNF_MEDIA_AUI;
571 else if (lp->force & FORCE_BNC)
572 lp->adapter_cnf |= A_CNF_MEDIA_10B_2;
573 }
574
575 cs89_dbg(1, debug, "%s: after force 0x%x, adapter_cnf=0x%x\n",
576 dev->name, lp->force, lp->adapter_cnf);
577
578 /* FIXME: We don't let you set dc-dc polarity or low RX squelch from the command line: add it here */
579
580 /* FIXME: We don't let you set the IMM bit from the command line: add it to lp->auto_neg_cnf here */
581
582 /* FIXME: we don't set the Ethernet address on the command line. Use
583 * ifconfig IFACE hw ether AABBCCDDEEFF
584 */
585
586 pr_info("media %s%s%s",
587 (lp->adapter_cnf & A_CNF_10B_T) ? "RJ-45," : "",
588 (lp->adapter_cnf & A_CNF_AUI) ? "AUI," : "",
589 (lp->adapter_cnf & A_CNF_10B_2) ? "BNC," : "");
590
591 lp->irq_map = 0xffff;
592
593 /* If this is a CS8900 then no pnp soft */
594 if (lp->chip_type != CS8900 &&
595 /* Check if the ISA IRQ has been set */
596 (i = readreg(dev, PP_CS8920_ISAINT) & 0xff,
597 (i != 0 && i < CS8920_NO_INTS))) {
598 if (!dev->irq)
599 dev->irq = i;
600 } else {
601 i = lp->isa_config & INT_NO_MASK;
602#ifndef CONFIG_CS89x0_PLATFORM 337#ifndef CONFIG_CS89x0_PLATFORM
603 if (lp->chip_type == CS8900) { 338 /* Search the mapping table for the corresponding IRQ pin. */
604#ifdef CS89x0_NONISA_IRQ 339 for (i = 0; i != ARRAY_SIZE(cs8900_irq_map); i++)
605 i = cs8900_irq_map[0]; 340 if (cs8900_irq_map[i] == irq)
341 break;
342 /* Not found */
343 if (i == ARRAY_SIZE(cs8900_irq_map))
344 i = 3;
606#else 345#else
607 /* Translate the IRQ using the IRQ mapping table. */ 346 /* INTRQ0 pin is used for interrupt generation. */
608 if (i >= ARRAY_SIZE(cs8900_irq_map)) 347 i = 0;
609 pr_err("invalid ISA interrupt number %d\n", i);
610 else
611 i = cs8900_irq_map[i];
612
613 lp->irq_map = CS8900_IRQ_MAP; /* fixed IRQ map for CS8900 */
614 } else {
615 int irq_map_buff[IRQ_MAP_LEN/2];
616
617 if (get_eeprom_data(dev, IRQ_MAP_EEPROM_DATA,
618 IRQ_MAP_LEN / 2,
619 irq_map_buff) >= 0) {
620 if ((irq_map_buff[0] & 0xff) == PNP_IRQ_FRMT)
621 lp->irq_map = ((irq_map_buff[0] >> 8) |
622 (irq_map_buff[1] << 8));
623 }
624#endif
625 }
626#endif
627 if (!dev->irq)
628 dev->irq = i;
629 }
630
631 pr_cont(" IRQ %d", dev->irq);
632
633#if ALLOW_DMA
634 if (lp->use_dma) {
635 get_dma_channel(dev);
636 pr_cont(", DMA %d", dev->dma);
637 } else
638#endif 348#endif
639 pr_cont(", programmed I/O"); 349 writereg(dev, PP_CS8900_ISAINT, i);
640 350 } else {
641 /* print the ethernet address. */ 351 writereg(dev, PP_CS8920_ISAINT, irq);
642 pr_cont(", MAC %pM\n", dev->dev_addr);
643
644 dev->netdev_ops = &net_ops;
645 dev->watchdog_timeo = HZ;
646
647 cs89_dbg(0, info, "cs89x0_probe1() successful\n");
648
649 retval = register_netdev(dev);
650 if (retval)
651 goto out2;
652 return 0;
653out2:
654 iowrite16(PP_ChipID, lp->virt_addr + ADD_PORT);
655out1:
656 return retval;
657}
658
659#ifndef CONFIG_CS89x0_PLATFORM
660/*
661 * This function converts the I/O port addres used by the cs89x0_probe() and
662 * init_module() functions to the I/O memory address used by the
663 * cs89x0_probe1() function.
664 */
665static int __init
666cs89x0_ioport_probe(struct net_device *dev, unsigned long ioport, int modular)
667{
668 struct net_local *lp = netdev_priv(dev);
669 int ret;
670 void __iomem *io_mem;
671
672 if (!lp)
673 return -ENOMEM;
674
675 dev->base_addr = ioport;
676
677 if (!request_region(ioport, NETCARD_IO_EXTENT, DRV_NAME)) {
678 ret = -EBUSY;
679 goto out;
680 }
681
682 io_mem = ioport_map(ioport & ~3, NETCARD_IO_EXTENT);
683 if (!io_mem) {
684 ret = -ENOMEM;
685 goto release;
686 }
687
688 /* if they give us an odd I/O address, then do ONE write to
689 * the address port, to get it back to address zero, where we
690 * expect to find the EISA signature word. An IO with a base of 0x3
691 * will skip the test for the ADD_PORT.
692 */
693 if (ioport & 1) {
694 cs89_dbg(1, info, "%s: odd ioaddr 0x%lx\n", dev->name, ioport);
695 if ((ioport & 2) != 2) {
696 if ((ioread16(io_mem + ADD_PORT) & ADD_MASK) !=
697 ADD_SIG) {
698 pr_err("%s: bad signature 0x%x\n",
699 dev->name, ioread16(io_mem + ADD_PORT));
700 ret = -ENODEV;
701 goto unmap;
702 }
703 }
704 } 352 }
705
706 ret = cs89x0_probe1(dev, io_mem, modular);
707 if (!ret)
708 goto out;
709unmap:
710 ioport_unmap(io_mem);
711release:
712 release_region(ioport, NETCARD_IO_EXTENT);
713out:
714 return ret;
715} 353}
716 354
717#ifndef MODULE 355static void
718/* Check for a network adaptor of this type, and return '0' iff one exists. 356count_rx_errors(int status, struct net_device *dev)
719 * If dev->base_addr == 0, probe all likely locations.
720 * If dev->base_addr == 1, always return failure.
721 * If dev->base_addr == 2, allocate space for the device and return success
722 * (detachable devices only).
723 * Return 0 on success.
724 */
725
726struct net_device * __init cs89x0_probe(int unit)
727{ 357{
728 struct net_device *dev = alloc_etherdev(sizeof(struct net_local)); 358 dev->stats.rx_errors++;
729 unsigned *port; 359 if (status & RX_RUNT)
730 int err = 0; 360 dev->stats.rx_length_errors++;
731 int irq; 361 if (status & RX_EXTRA_DATA)
732 int io; 362 dev->stats.rx_length_errors++;
733 363 if ((status & RX_CRC_ERROR) && !(status & (RX_EXTRA_DATA | RX_RUNT)))
734 if (!dev) 364 /* per str 172 */
735 return ERR_PTR(-ENODEV); 365 dev->stats.rx_crc_errors++;
736 366 if (status & RX_DRIBBLE)
737 sprintf(dev->name, "eth%d", unit); 367 dev->stats.rx_frame_errors++;
738 netdev_boot_setup_check(dev);
739 io = dev->base_addr;
740 irq = dev->irq;
741
742 cs89_dbg(0, info, "cs89x0_probe(0x%x)\n", io);
743
744 if (io > 0x1ff) { /* Check a single specified location. */
745 err = cs89x0_ioport_probe(dev, io, 0);
746 } else if (io != 0) { /* Don't probe at all. */
747 err = -ENXIO;
748 } else {
749 for (port = netcard_portlist; *port; port++) {
750 if (cs89x0_ioport_probe(dev, *port, 0) == 0)
751 break;
752 dev->irq = irq;
753 }
754 if (!*port)
755 err = -ENODEV;
756 }
757 if (err)
758 goto out;
759 return dev;
760out:
761 free_netdev(dev);
762 pr_warn("no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n");
763 return ERR_PTR(err);
764} 368}
765#endif
766#endif
767 369
768/********************************* 370/*********************************
769 * This page contains DMA routines 371 * This page contains DMA routines
@@ -915,44 +517,16 @@ skip_this_frame:
915 dev->stats.rx_bytes += length; 517 dev->stats.rx_bytes += length;
916} 518}
917 519
918#endif /* ALLOW_DMA */ 520static void release_dma_buff(struct net_local *lp)
919
920static void __init reset_chip(struct net_device *dev)
921{ 521{
922#if !defined(CONFIG_MACH_MX31ADS) 522 if (lp->dma_buff) {
923#if !defined(CS89x0_NONISA_IRQ) 523 free_pages((unsigned long)(lp->dma_buff),
924 struct net_local *lp = netdev_priv(dev); 524 get_order(lp->dmasize * 1024));
925#endif /* CS89x0_NONISA_IRQ */ 525 lp->dma_buff = NULL;
926 int reset_start_time;
927
928 writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
929
930 /* wait 30 ms */
931 msleep(30);
932
933#if !defined(CS89x0_NONISA_IRQ)
934 if (lp->chip_type != CS8900) {
935 /* Hardware problem requires PNP registers to be reconfigured after a reset */
936 iowrite16(PP_CS8920_ISAINT, lp->virt_addr + ADD_PORT);
937 iowrite8(dev->irq, lp->virt_addr + DATA_PORT);
938 iowrite8(0, lp->virt_addr + DATA_PORT + 1);
939
940 iowrite16(PP_CS8920_ISAMemB, lp->virt_addr + ADD_PORT);
941 iowrite8((dev->mem_start >> 16) & 0xff,
942 lp->virt_addr + DATA_PORT);
943 iowrite8((dev->mem_start >> 8) & 0xff,
944 lp->virt_addr + DATA_PORT + 1);
945 } 526 }
946#endif /* CS89x0_NONISA_IRQ */
947
948 /* Wait until the chip is reset */
949 reset_start_time = jiffies;
950 while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 &&
951 jiffies - reset_start_time < 2)
952 ;
953#endif /* !CONFIG_MACH_MX31ADS */
954} 527}
955 528
529#endif /* ALLOW_DMA */
956 530
957static void 531static void
958control_dc_dc(struct net_device *dev, int on_not_off) 532control_dc_dc(struct net_device *dev, int on_not_off)
@@ -977,6 +551,49 @@ control_dc_dc(struct net_device *dev, int on_not_off)
977 ; 551 ;
978} 552}
979 553
554/* send a test packet - return true if carrier bits are ok */
555static int
556send_test_pkt(struct net_device *dev)
557{
558 struct net_local *lp = netdev_priv(dev);
559 char test_packet[] = {
560 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
561 0, 46, /* A 46 in network order */
562 0, 0, /* DSAP=0 & SSAP=0 fields */
563 0xf3, 0 /* Control (Test Req + P bit set) */
564 };
565 long timenow = jiffies;
566
567 writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON);
568
569 memcpy(test_packet, dev->dev_addr, ETH_ALEN);
570 memcpy(test_packet + ETH_ALEN, dev->dev_addr, ETH_ALEN);
571
572 iowrite16(TX_AFTER_ALL, lp->virt_addr + TX_CMD_PORT);
573 iowrite16(ETH_ZLEN, lp->virt_addr + TX_LEN_PORT);
574
575 /* Test to see if the chip has allocated memory for the packet */
576 while (jiffies - timenow < 5)
577 if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW)
578 break;
579 if (jiffies - timenow >= 5)
580 return 0; /* this shouldn't happen */
581
582 /* Write the contents of the packet */
583 writewords(lp, TX_FRAME_PORT, test_packet, (ETH_ZLEN + 1) >> 1);
584
585 cs89_dbg(1, debug, "Sending test packet ");
586 /* wait a couple of jiffies for packet to be received */
587 for (timenow = jiffies; jiffies - timenow < 3;)
588 ;
589 if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
590 cs89_dbg(1, cont, "succeeded\n");
591 return 1;
592 }
593 cs89_dbg(1, cont, "failed\n");
594 return 0;
595}
596
980#define DETECTED_NONE 0 597#define DETECTED_NONE 0
981#define DETECTED_RJ45H 1 598#define DETECTED_RJ45H 1
982#define DETECTED_RJ45F 2 599#define DETECTED_RJ45F 2
@@ -1063,50 +680,22 @@ detect_tp(struct net_device *dev)
1063 return DETECTED_RJ45H; 680 return DETECTED_RJ45H;
1064} 681}
1065 682
1066/* send a test packet - return true if carrier bits are ok */
1067static int 683static int
1068send_test_pkt(struct net_device *dev) 684detect_bnc(struct net_device *dev)
1069{ 685{
1070 struct net_local *lp = netdev_priv(dev); 686 struct net_local *lp = netdev_priv(dev);
1071 char test_packet[] = {
1072 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1073 0, 46, /* A 46 in network order */
1074 0, 0, /* DSAP=0 & SSAP=0 fields */
1075 0xf3, 0 /* Control (Test Req + P bit set) */
1076 };
1077 long timenow = jiffies;
1078
1079 writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON);
1080
1081 memcpy(test_packet, dev->dev_addr, ETH_ALEN);
1082 memcpy(test_packet + ETH_ALEN, dev->dev_addr, ETH_ALEN);
1083
1084 iowrite16(TX_AFTER_ALL, lp->virt_addr + TX_CMD_PORT);
1085 iowrite16(ETH_ZLEN, lp->virt_addr + TX_LEN_PORT);
1086 687
1087 /* Test to see if the chip has allocated memory for the packet */ 688 cs89_dbg(1, debug, "%s: Attempting BNC\n", dev->name);
1088 while (jiffies - timenow < 5) 689 control_dc_dc(dev, 1);
1089 if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW)
1090 break;
1091 if (jiffies - timenow >= 5)
1092 return 0; /* this shouldn't happen */
1093 690
1094 /* Write the contents of the packet */ 691 writereg(dev, PP_LineCTL, (lp->linectl & ~AUTO_AUI_10BASET) | AUI_ONLY);
1095 writewords(lp, TX_FRAME_PORT, test_packet, (ETH_ZLEN + 1) >> 1);
1096 692
1097 cs89_dbg(1, debug, "Sending test packet "); 693 if (send_test_pkt(dev))
1098 /* wait a couple of jiffies for packet to be received */ 694 return DETECTED_BNC;
1099 for (timenow = jiffies; jiffies - timenow < 3;) 695 else
1100 ; 696 return DETECTED_NONE;
1101 if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
1102 cs89_dbg(1, cont, "succeeded\n");
1103 return 1;
1104 }
1105 cs89_dbg(1, cont, "failed\n");
1106 return 0;
1107} 697}
1108 698
1109
1110static int 699static int
1111detect_aui(struct net_device *dev) 700detect_aui(struct net_device *dev)
1112{ 701{
@@ -1123,45 +712,154 @@ detect_aui(struct net_device *dev)
1123 return DETECTED_NONE; 712 return DETECTED_NONE;
1124} 713}
1125 714
1126static int 715/* We have a good packet(s), get it/them out of the buffers. */
1127detect_bnc(struct net_device *dev) 716static void
717net_rx(struct net_device *dev)
1128{ 718{
1129 struct net_local *lp = netdev_priv(dev); 719 struct net_local *lp = netdev_priv(dev);
720 struct sk_buff *skb;
721 int status, length;
1130 722
1131 cs89_dbg(1, debug, "%s: Attempting BNC\n", dev->name); 723 status = ioread16(lp->virt_addr + RX_FRAME_PORT);
1132 control_dc_dc(dev, 1); 724 length = ioread16(lp->virt_addr + RX_FRAME_PORT);
1133 725
1134 writereg(dev, PP_LineCTL, (lp->linectl & ~AUTO_AUI_10BASET) | AUI_ONLY); 726 if ((status & RX_OK) == 0) {
727 count_rx_errors(status, dev);
728 return;
729 }
1135 730
1136 if (send_test_pkt(dev)) 731 /* Malloc up new buffer. */
1137 return DETECTED_BNC; 732 skb = netdev_alloc_skb(dev, length + 2);
1138 else 733 if (skb == NULL) {
1139 return DETECTED_NONE; 734#if 0 /* Again, this seems a cruel thing to do */
735 pr_warn("%s: Memory squeeze, dropping packet\n", dev->name);
736#endif
737 dev->stats.rx_dropped++;
738 return;
739 }
740 skb_reserve(skb, 2); /* longword align L3 header */
741
742 readwords(lp, RX_FRAME_PORT, skb_put(skb, length), length >> 1);
743 if (length & 1)
744 skb->data[length-1] = ioread16(lp->virt_addr + RX_FRAME_PORT);
745
746 cs89_dbg(3, debug, "%s: received %d byte packet of type %x\n",
747 dev->name, length,
748 (skb->data[ETH_ALEN + ETH_ALEN] << 8) |
749 skb->data[ETH_ALEN + ETH_ALEN + 1]);
750
751 skb->protocol = eth_type_trans(skb, dev);
752 netif_rx(skb);
753 dev->stats.rx_packets++;
754 dev->stats.rx_bytes += length;
1140} 755}
1141 756
757/* The typical workload of the driver:
758 * Handle the network interface interrupts.
759 */
1142 760
1143static void 761static irqreturn_t net_interrupt(int irq, void *dev_id)
1144write_irq(struct net_device *dev, int chip_type, int irq)
1145{ 762{
1146 int i; 763 struct net_device *dev = dev_id;
764 struct net_local *lp;
765 int status;
766 int handled = 0;
1147 767
1148 if (chip_type == CS8900) { 768 lp = netdev_priv(dev);
1149#ifndef CONFIG_CS89x0_PLATFORM 769
1150 /* Search the mapping table for the corresponding IRQ pin. */ 770 /* we MUST read all the events out of the ISQ, otherwise we'll never
1151 for (i = 0; i != ARRAY_SIZE(cs8900_irq_map); i++) 771 * get interrupted again. As a consequence, we can't have any limit
1152 if (cs8900_irq_map[i] == irq) 772 * on the number of times we loop in the interrupt handler. The
1153 break; 773 * hardware guarantees that eventually we'll run out of events. Of
1154 /* Not found */ 774 * course, if you're on a slow machine, and packets are arriving
1155 if (i == ARRAY_SIZE(cs8900_irq_map)) 775 * faster than you can read them off, you're screwed. Hasta la
1156 i = 3; 776 * vista, baby!
1157#else 777 */
1158 /* INTRQ0 pin is used for interrupt generation. */ 778 while ((status = ioread16(lp->virt_addr + ISQ_PORT))) {
1159 i = 0; 779 cs89_dbg(4, debug, "%s: event=%04x\n", dev->name, status);
780 handled = 1;
781 switch (status & ISQ_EVENT_MASK) {
782 case ISQ_RECEIVER_EVENT:
783 /* Got a packet(s). */
784 net_rx(dev);
785 break;
786 case ISQ_TRANSMITTER_EVENT:
787 dev->stats.tx_packets++;
788 netif_wake_queue(dev); /* Inform upper layers. */
789 if ((status & (TX_OK |
790 TX_LOST_CRS |
791 TX_SQE_ERROR |
792 TX_LATE_COL |
793 TX_16_COL)) != TX_OK) {
794 if ((status & TX_OK) == 0)
795 dev->stats.tx_errors++;
796 if (status & TX_LOST_CRS)
797 dev->stats.tx_carrier_errors++;
798 if (status & TX_SQE_ERROR)
799 dev->stats.tx_heartbeat_errors++;
800 if (status & TX_LATE_COL)
801 dev->stats.tx_window_errors++;
802 if (status & TX_16_COL)
803 dev->stats.tx_aborted_errors++;
804 }
805 break;
806 case ISQ_BUFFER_EVENT:
807 if (status & READY_FOR_TX) {
808 /* we tried to transmit a packet earlier,
809 * but inexplicably ran out of buffers.
810 * That shouldn't happen since we only ever
811 * load one packet. Shrug. Do the right
812 * thing anyway.
813 */
814 netif_wake_queue(dev); /* Inform upper layers. */
815 }
816 if (status & TX_UNDERRUN) {
817 cs89_dbg(0, err, "%s: transmit underrun\n",
818 dev->name);
819 lp->send_underrun++;
820 if (lp->send_underrun == 3)
821 lp->send_cmd = TX_AFTER_381;
822 else if (lp->send_underrun == 6)
823 lp->send_cmd = TX_AFTER_ALL;
824 /* transmit cycle is done, although
825 * frame wasn't transmitted - this
826 * avoids having to wait for the upper
827 * layers to timeout on us, in the
828 * event of a tx underrun
829 */
830 netif_wake_queue(dev); /* Inform upper layers. */
831 }
832#if ALLOW_DMA
833 if (lp->use_dma && (status & RX_DMA)) {
834 int count = readreg(dev, PP_DmaFrameCnt);
835 while (count) {
836 cs89_dbg(5, debug,
837 "%s: receiving %d DMA frames\n",
838 dev->name, count);
839 if (count > 1)
840 cs89_dbg(2, debug,
841 "%s: receiving %d DMA frames\n",
842 dev->name, count);
843 dma_rx(dev);
844 if (--count == 0)
845 count = readreg(dev, PP_DmaFrameCnt);
846 if (count > 0)
847 cs89_dbg(2, debug,
848 "%s: continuing with %d DMA frames\n",
849 dev->name, count);
850 }
851 }
1160#endif 852#endif
1161 writereg(dev, PP_CS8900_ISAINT, i); 853 break;
1162 } else { 854 case ISQ_RX_MISS_EVENT:
1163 writereg(dev, PP_CS8920_ISAINT, irq); 855 dev->stats.rx_missed_errors += (status >> 6);
856 break;
857 case ISQ_TX_COL_EVENT:
858 dev->stats.collisions += (status >> 6);
859 break;
860 }
1164 } 861 }
862 return IRQ_RETVAL(handled);
1165} 863}
1166 864
1167/* Open/initialize the board. This is called (in the current kernel) 865/* Open/initialize the board. This is called (in the current kernel)
@@ -1433,6 +1131,52 @@ bad_out:
1433 return ret; 1131 return ret;
1434} 1132}
1435 1133
1134/* The inverse routine to net_open(). */
1135static int
1136net_close(struct net_device *dev)
1137{
1138#if ALLOW_DMA
1139 struct net_local *lp = netdev_priv(dev);
1140#endif
1141
1142 netif_stop_queue(dev);
1143
1144 writereg(dev, PP_RxCFG, 0);
1145 writereg(dev, PP_TxCFG, 0);
1146 writereg(dev, PP_BufCFG, 0);
1147 writereg(dev, PP_BusCTL, 0);
1148
1149 free_irq(dev->irq, dev);
1150
1151#if ALLOW_DMA
1152 if (lp->use_dma && lp->dma) {
1153 free_dma(dev->dma);
1154 release_dma_buff(lp);
1155 }
1156#endif
1157
1158 /* Update the statistics here. */
1159 return 0;
1160}
1161
1162/* Get the current statistics.
1163 * This may be called with the card open or closed.
1164 */
1165static struct net_device_stats *
1166net_get_stats(struct net_device *dev)
1167{
1168 struct net_local *lp = netdev_priv(dev);
1169 unsigned long flags;
1170
1171 spin_lock_irqsave(&lp->lock, flags);
1172 /* Update the statistics from the device registers. */
1173 dev->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);
1174 dev->stats.collisions += (readreg(dev, PP_TxCol) >> 6);
1175 spin_unlock_irqrestore(&lp->lock, flags);
1176
1177 return &dev->stats;
1178}
1179
1436static void net_timeout(struct net_device *dev) 1180static void net_timeout(struct net_device *dev)
1437{ 1181{
1438 /* If we get here, some higher level has decided we are broken. 1182 /* If we get here, some higher level has decided we are broken.
@@ -1495,228 +1239,6 @@ static netdev_tx_t net_send_packet(struct sk_buff *skb, struct net_device *dev)
1495 return NETDEV_TX_OK; 1239 return NETDEV_TX_OK;
1496} 1240}
1497 1241
1498/* The typical workload of the driver:
1499 * Handle the network interface interrupts.
1500 */
1501
1502static irqreturn_t net_interrupt(int irq, void *dev_id)
1503{
1504 struct net_device *dev = dev_id;
1505 struct net_local *lp;
1506 int status;
1507 int handled = 0;
1508
1509 lp = netdev_priv(dev);
1510
1511 /* we MUST read all the events out of the ISQ, otherwise we'll never
1512 * get interrupted again. As a consequence, we can't have any limit
1513 * on the number of times we loop in the interrupt handler. The
1514 * hardware guarantees that eventually we'll run out of events. Of
1515 * course, if you're on a slow machine, and packets are arriving
1516 * faster than you can read them off, you're screwed. Hasta la
1517 * vista, baby!
1518 */
1519 while ((status = ioread16(lp->virt_addr + ISQ_PORT))) {
1520 cs89_dbg(4, debug, "%s: event=%04x\n", dev->name, status);
1521 handled = 1;
1522 switch (status & ISQ_EVENT_MASK) {
1523 case ISQ_RECEIVER_EVENT:
1524 /* Got a packet(s). */
1525 net_rx(dev);
1526 break;
1527 case ISQ_TRANSMITTER_EVENT:
1528 dev->stats.tx_packets++;
1529 netif_wake_queue(dev); /* Inform upper layers. */
1530 if ((status & (TX_OK |
1531 TX_LOST_CRS |
1532 TX_SQE_ERROR |
1533 TX_LATE_COL |
1534 TX_16_COL)) != TX_OK) {
1535 if ((status & TX_OK) == 0)
1536 dev->stats.tx_errors++;
1537 if (status & TX_LOST_CRS)
1538 dev->stats.tx_carrier_errors++;
1539 if (status & TX_SQE_ERROR)
1540 dev->stats.tx_heartbeat_errors++;
1541 if (status & TX_LATE_COL)
1542 dev->stats.tx_window_errors++;
1543 if (status & TX_16_COL)
1544 dev->stats.tx_aborted_errors++;
1545 }
1546 break;
1547 case ISQ_BUFFER_EVENT:
1548 if (status & READY_FOR_TX) {
1549 /* we tried to transmit a packet earlier,
1550 * but inexplicably ran out of buffers.
1551 * That shouldn't happen since we only ever
1552 * load one packet. Shrug. Do the right
1553 * thing anyway.
1554 */
1555 netif_wake_queue(dev); /* Inform upper layers. */
1556 }
1557 if (status & TX_UNDERRUN) {
1558 cs89_dbg(0, err, "%s: transmit underrun\n",
1559 dev->name);
1560 lp->send_underrun++;
1561 if (lp->send_underrun == 3)
1562 lp->send_cmd = TX_AFTER_381;
1563 else if (lp->send_underrun == 6)
1564 lp->send_cmd = TX_AFTER_ALL;
1565 /* transmit cycle is done, although
1566 * frame wasn't transmitted - this
1567 * avoids having to wait for the upper
1568 * layers to timeout on us, in the
1569 * event of a tx underrun
1570 */
1571 netif_wake_queue(dev); /* Inform upper layers. */
1572 }
1573#if ALLOW_DMA
1574 if (lp->use_dma && (status & RX_DMA)) {
1575 int count = readreg(dev, PP_DmaFrameCnt);
1576 while (count) {
1577 cs89_dbg(5, debug,
1578 "%s: receiving %d DMA frames\n",
1579 dev->name, count);
1580 if (count > 1)
1581 cs89_dbg(2, debug,
1582 "%s: receiving %d DMA frames\n",
1583 dev->name, count);
1584 dma_rx(dev);
1585 if (--count == 0)
1586 count = readreg(dev, PP_DmaFrameCnt);
1587 if (count > 0)
1588 cs89_dbg(2, debug,
1589 "%s: continuing with %d DMA frames\n",
1590 dev->name, count);
1591 }
1592 }
1593#endif
1594 break;
1595 case ISQ_RX_MISS_EVENT:
1596 dev->stats.rx_missed_errors += (status >> 6);
1597 break;
1598 case ISQ_TX_COL_EVENT:
1599 dev->stats.collisions += (status >> 6);
1600 break;
1601 }
1602 }
1603 return IRQ_RETVAL(handled);
1604}
1605
1606static void
1607count_rx_errors(int status, struct net_device *dev)
1608{
1609 dev->stats.rx_errors++;
1610 if (status & RX_RUNT)
1611 dev->stats.rx_length_errors++;
1612 if (status & RX_EXTRA_DATA)
1613 dev->stats.rx_length_errors++;
1614 if ((status & RX_CRC_ERROR) && !(status & (RX_EXTRA_DATA | RX_RUNT)))
1615 /* per str 172 */
1616 dev->stats.rx_crc_errors++;
1617 if (status & RX_DRIBBLE)
1618 dev->stats.rx_frame_errors++;
1619}
1620
1621/* We have a good packet(s), get it/them out of the buffers. */
1622static void
1623net_rx(struct net_device *dev)
1624{
1625 struct net_local *lp = netdev_priv(dev);
1626 struct sk_buff *skb;
1627 int status, length;
1628
1629 status = ioread16(lp->virt_addr + RX_FRAME_PORT);
1630 length = ioread16(lp->virt_addr + RX_FRAME_PORT);
1631
1632 if ((status & RX_OK) == 0) {
1633 count_rx_errors(status, dev);
1634 return;
1635 }
1636
1637 /* Malloc up new buffer. */
1638 skb = netdev_alloc_skb(dev, length + 2);
1639 if (skb == NULL) {
1640#if 0 /* Again, this seems a cruel thing to do */
1641 pr_warn("%s: Memory squeeze, dropping packet\n", dev->name);
1642#endif
1643 dev->stats.rx_dropped++;
1644 return;
1645 }
1646 skb_reserve(skb, 2); /* longword align L3 header */
1647
1648 readwords(lp, RX_FRAME_PORT, skb_put(skb, length), length >> 1);
1649 if (length & 1)
1650 skb->data[length-1] = ioread16(lp->virt_addr + RX_FRAME_PORT);
1651
1652 cs89_dbg(3, debug, "%s: received %d byte packet of type %x\n",
1653 dev->name, length,
1654 (skb->data[ETH_ALEN + ETH_ALEN] << 8) |
1655 skb->data[ETH_ALEN + ETH_ALEN + 1]);
1656
1657 skb->protocol = eth_type_trans(skb, dev);
1658 netif_rx(skb);
1659 dev->stats.rx_packets++;
1660 dev->stats.rx_bytes += length;
1661}
1662
1663#if ALLOW_DMA
1664static void release_dma_buff(struct net_local *lp)
1665{
1666 if (lp->dma_buff) {
1667 free_pages((unsigned long)(lp->dma_buff),
1668 get_order(lp->dmasize * 1024));
1669 lp->dma_buff = NULL;
1670 }
1671}
1672#endif
1673
1674/* The inverse routine to net_open(). */
1675static int
1676net_close(struct net_device *dev)
1677{
1678#if ALLOW_DMA
1679 struct net_local *lp = netdev_priv(dev);
1680#endif
1681
1682 netif_stop_queue(dev);
1683
1684 writereg(dev, PP_RxCFG, 0);
1685 writereg(dev, PP_TxCFG, 0);
1686 writereg(dev, PP_BufCFG, 0);
1687 writereg(dev, PP_BusCTL, 0);
1688
1689 free_irq(dev->irq, dev);
1690
1691#if ALLOW_DMA
1692 if (lp->use_dma && lp->dma) {
1693 free_dma(dev->dma);
1694 release_dma_buff(lp);
1695 }
1696#endif
1697
1698 /* Update the statistics here. */
1699 return 0;
1700}
1701
1702/* Get the current statistics.
1703 * This may be called with the card open or closed.
1704 */
1705static struct net_device_stats *
1706net_get_stats(struct net_device *dev)
1707{
1708 struct net_local *lp = netdev_priv(dev);
1709 unsigned long flags;
1710
1711 spin_lock_irqsave(&lp->lock, flags);
1712 /* Update the statistics from the device registers. */
1713 dev->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);
1714 dev->stats.collisions += (readreg(dev, PP_TxCol) >> 6);
1715 spin_unlock_irqrestore(&lp->lock, flags);
1716
1717 return &dev->stats;
1718}
1719
1720static void set_multicast_list(struct net_device *dev) 1242static void set_multicast_list(struct net_device *dev)
1721{ 1243{
1722 struct net_local *lp = netdev_priv(dev); 1244 struct net_local *lp = netdev_priv(dev);
@@ -1768,6 +1290,459 @@ static int set_mac_address(struct net_device *dev, void *p)
1768 return 0; 1290 return 0;
1769} 1291}
1770 1292
1293#ifdef CONFIG_NET_POLL_CONTROLLER
1294/*
1295 * Polling receive - used by netconsole and other diagnostic tools
1296 * to allow network i/o with interrupts disabled.
1297 */
1298static void net_poll_controller(struct net_device *dev)
1299{
1300 disable_irq(dev->irq);
1301 net_interrupt(dev->irq, dev);
1302 enable_irq(dev->irq);
1303}
1304#endif
1305
1306static const struct net_device_ops net_ops = {
1307 .ndo_open = net_open,
1308 .ndo_stop = net_close,
1309 .ndo_tx_timeout = net_timeout,
1310 .ndo_start_xmit = net_send_packet,
1311 .ndo_get_stats = net_get_stats,
1312 .ndo_set_rx_mode = set_multicast_list,
1313 .ndo_set_mac_address = set_mac_address,
1314#ifdef CONFIG_NET_POLL_CONTROLLER
1315 .ndo_poll_controller = net_poll_controller,
1316#endif
1317 .ndo_change_mtu = eth_change_mtu,
1318 .ndo_validate_addr = eth_validate_addr,
1319};
1320
1321static void __init reset_chip(struct net_device *dev)
1322{
1323#if !defined(CONFIG_MACH_MX31ADS)
1324#if !defined(CS89x0_NONISA_IRQ)
1325 struct net_local *lp = netdev_priv(dev);
1326#endif /* CS89x0_NONISA_IRQ */
1327 int reset_start_time;
1328
1329 writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
1330
1331 /* wait 30 ms */
1332 msleep(30);
1333
1334#if !defined(CS89x0_NONISA_IRQ)
1335 if (lp->chip_type != CS8900) {
1336 /* Hardware problem requires PNP registers to be reconfigured after a reset */
1337 iowrite16(PP_CS8920_ISAINT, lp->virt_addr + ADD_PORT);
1338 iowrite8(dev->irq, lp->virt_addr + DATA_PORT);
1339 iowrite8(0, lp->virt_addr + DATA_PORT + 1);
1340
1341 iowrite16(PP_CS8920_ISAMemB, lp->virt_addr + ADD_PORT);
1342 iowrite8((dev->mem_start >> 16) & 0xff,
1343 lp->virt_addr + DATA_PORT);
1344 iowrite8((dev->mem_start >> 8) & 0xff,
1345 lp->virt_addr + DATA_PORT + 1);
1346 }
1347#endif /* CS89x0_NONISA_IRQ */
1348
1349 /* Wait until the chip is reset */
1350 reset_start_time = jiffies;
1351 while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 &&
1352 jiffies - reset_start_time < 2)
1353 ;
1354#endif /* !CONFIG_MACH_MX31ADS */
1355}
1356
1357/* This is the real probe routine.
1358 * Linux has a history of friendly device probes on the ISA bus.
1359 * A good device probes avoids doing writes, and
1360 * verifies that the correct device exists and functions.
1361 * Return 0 on success.
1362 */
1363static int __init
1364cs89x0_probe1(struct net_device *dev, void __iomem *ioaddr, int modular)
1365{
1366 struct net_local *lp = netdev_priv(dev);
1367 int i;
1368 int tmp;
1369 unsigned rev_type = 0;
1370 int eeprom_buff[CHKSUM_LEN];
1371 int retval;
1372
1373 /* Initialize the device structure. */
1374 if (!modular) {
1375 memset(lp, 0, sizeof(*lp));
1376 spin_lock_init(&lp->lock);
1377#ifndef MODULE
1378#if ALLOW_DMA
1379 if (g_cs89x0_dma) {
1380 lp->use_dma = 1;
1381 lp->dma = g_cs89x0_dma;
1382 lp->dmasize = 16; /* Could make this an option... */
1383 }
1384#endif
1385 lp->force = g_cs89x0_media__force;
1386#endif
1387 }
1388
1389 pr_debug("PP_addr at %p[%x]: 0x%x\n",
1390 ioaddr, ADD_PORT, ioread16(ioaddr + ADD_PORT));
1391 iowrite16(PP_ChipID, ioaddr + ADD_PORT);
1392
1393 tmp = ioread16(ioaddr + DATA_PORT);
1394 if (tmp != CHIP_EISA_ID_SIG) {
1395 pr_debug("%s: incorrect signature at %p[%x]: 0x%x!="
1396 CHIP_EISA_ID_SIG_STR "\n",
1397 dev->name, ioaddr, DATA_PORT, tmp);
1398 retval = -ENODEV;
1399 goto out1;
1400 }
1401
1402 lp->virt_addr = ioaddr;
1403
1404 /* get the chip type */
1405 rev_type = readreg(dev, PRODUCT_ID_ADD);
1406 lp->chip_type = rev_type & ~REVISON_BITS;
1407 lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
1408
1409 /* Check the chip type and revision in order to set the correct
1410 * send command. CS8920 revision C and CS8900 revision F can use
1411 * the faster send.
1412 */
1413 lp->send_cmd = TX_AFTER_381;
1414 if (lp->chip_type == CS8900 && lp->chip_revision >= 'F')
1415 lp->send_cmd = TX_NOW;
1416 if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
1417 lp->send_cmd = TX_NOW;
1418
1419 pr_info_once("%s\n", version);
1420
1421 pr_info("%s: cs89%c0%s rev %c found at %p ",
1422 dev->name,
1423 lp->chip_type == CS8900 ? '0' : '2',
1424 lp->chip_type == CS8920M ? "M" : "",
1425 lp->chip_revision,
1426 lp->virt_addr);
1427
1428 reset_chip(dev);
1429
1430 /* Here we read the current configuration of the chip.
1431 * If there is no Extended EEPROM then the idea is to not disturb
1432 * the chip configuration, it should have been correctly setup by
1433 * automatic EEPROM read on reset. So, if the chip says it read
1434 * the EEPROM the driver will always do *something* instead of
1435 * complain that adapter_cnf is 0.
1436 */
1437
1438 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) ==
1439 (EEPROM_OK | EEPROM_PRESENT)) {
1440 /* Load the MAC. */
1441 for (i = 0; i < ETH_ALEN / 2; i++) {
1442 unsigned int Addr;
1443 Addr = readreg(dev, PP_IA + i * 2);
1444 dev->dev_addr[i * 2] = Addr & 0xFF;
1445 dev->dev_addr[i * 2 + 1] = Addr >> 8;
1446 }
1447
1448 /* Load the Adapter Configuration.
1449 * Note: Barring any more specific information from some
1450 * other source (ie EEPROM+Schematics), we would not know
1451 * how to operate a 10Base2 interface on the AUI port.
1452 * However, since we do read the status of HCB1 and use
1453 * settings that always result in calls to control_dc_dc(dev,0)
1454 * a BNC interface should work if the enable pin
1455 * (dc/dc converter) is on HCB1.
1456 * It will be called AUI however.
1457 */
1458
1459 lp->adapter_cnf = 0;
1460 i = readreg(dev, PP_LineCTL);
1461 /* Preserve the setting of the HCB1 pin. */
1462 if ((i & (HCB1 | HCB1_ENBL)) == (HCB1 | HCB1_ENBL))
1463 lp->adapter_cnf |= A_CNF_DC_DC_POLARITY;
1464 /* Save the sqelch bit */
1465 if ((i & LOW_RX_SQUELCH) == LOW_RX_SQUELCH)
1466 lp->adapter_cnf |= A_CNF_EXTND_10B_2 | A_CNF_LOW_RX_SQUELCH;
1467 /* Check if the card is in 10Base-t only mode */
1468 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == 0)
1469 lp->adapter_cnf |= A_CNF_10B_T | A_CNF_MEDIA_10B_T;
1470 /* Check if the card is in AUI only mode */
1471 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUI_ONLY)
1472 lp->adapter_cnf |= A_CNF_AUI | A_CNF_MEDIA_AUI;
1473 /* Check if the card is in Auto mode. */
1474 if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUTO_AUI_10BASET)
1475 lp->adapter_cnf |= A_CNF_AUI | A_CNF_10B_T |
1476 A_CNF_MEDIA_AUI | A_CNF_MEDIA_10B_T | A_CNF_MEDIA_AUTO;
1477
1478 cs89_dbg(1, info, "%s: PP_LineCTL=0x%x, adapter_cnf=0x%x\n",
1479 dev->name, i, lp->adapter_cnf);
1480
1481 /* IRQ. Other chips already probe, see below. */
1482 if (lp->chip_type == CS8900)
1483 lp->isa_config = readreg(dev, PP_CS8900_ISAINT) & INT_NO_MASK;
1484
1485 pr_cont("[Cirrus EEPROM] ");
1486 }
1487
1488 pr_cont("\n");
1489
1490 /* First check to see if an EEPROM is attached. */
1491
1492 if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
1493 pr_warn("No EEPROM, relying on command line....\n");
1494 else if (get_eeprom_data(dev, START_EEPROM_DATA, CHKSUM_LEN, eeprom_buff) < 0) {
1495 pr_warn("EEPROM read failed, relying on command line\n");
1496 } else if (get_eeprom_cksum(START_EEPROM_DATA, CHKSUM_LEN, eeprom_buff) < 0) {
1497 /* Check if the chip was able to read its own configuration starting
1498 at 0 in the EEPROM*/
1499 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) !=
1500 (EEPROM_OK | EEPROM_PRESENT))
1501 pr_warn("Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command line\n");
1502
1503 } else {
1504 /* This reads an extended EEPROM that is not documented
1505 * in the CS8900 datasheet.
1506 */
1507
1508 /* get transmission control word but keep the autonegotiation bits */
1509 if (!lp->auto_neg_cnf)
1510 lp->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET / 2];
1511 /* Store adapter configuration */
1512 if (!lp->adapter_cnf)
1513 lp->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET / 2];
1514 /* Store ISA configuration */
1515 lp->isa_config = eeprom_buff[ISA_CNF_OFFSET / 2];
1516 dev->mem_start = eeprom_buff[PACKET_PAGE_OFFSET / 2] << 8;
1517
1518 /* eeprom_buff has 32-bit ints, so we can't just memcpy it */
1519 /* store the initial memory base address */
1520 for (i = 0; i < ETH_ALEN / 2; i++) {
1521 dev->dev_addr[i * 2] = eeprom_buff[i];
1522 dev->dev_addr[i * 2 + 1] = eeprom_buff[i] >> 8;
1523 }
1524 cs89_dbg(1, debug, "%s: new adapter_cnf: 0x%x\n",
1525 dev->name, lp->adapter_cnf);
1526 }
1527
1528 /* allow them to force multiple transceivers. If they force multiple, autosense */
1529 {
1530 int count = 0;
1531 if (lp->force & FORCE_RJ45) {
1532 lp->adapter_cnf |= A_CNF_10B_T;
1533 count++;
1534 }
1535 if (lp->force & FORCE_AUI) {
1536 lp->adapter_cnf |= A_CNF_AUI;
1537 count++;
1538 }
1539 if (lp->force & FORCE_BNC) {
1540 lp->adapter_cnf |= A_CNF_10B_2;
1541 count++;
1542 }
1543 if (count > 1)
1544 lp->adapter_cnf |= A_CNF_MEDIA_AUTO;
1545 else if (lp->force & FORCE_RJ45)
1546 lp->adapter_cnf |= A_CNF_MEDIA_10B_T;
1547 else if (lp->force & FORCE_AUI)
1548 lp->adapter_cnf |= A_CNF_MEDIA_AUI;
1549 else if (lp->force & FORCE_BNC)
1550 lp->adapter_cnf |= A_CNF_MEDIA_10B_2;
1551 }
1552
1553 cs89_dbg(1, debug, "%s: after force 0x%x, adapter_cnf=0x%x\n",
1554 dev->name, lp->force, lp->adapter_cnf);
1555
1556 /* FIXME: We don't let you set dc-dc polarity or low RX squelch from the command line: add it here */
1557
1558 /* FIXME: We don't let you set the IMM bit from the command line: add it to lp->auto_neg_cnf here */
1559
1560 /* FIXME: we don't set the Ethernet address on the command line. Use
1561 * ifconfig IFACE hw ether AABBCCDDEEFF
1562 */
1563
1564 pr_info("media %s%s%s",
1565 (lp->adapter_cnf & A_CNF_10B_T) ? "RJ-45," : "",
1566 (lp->adapter_cnf & A_CNF_AUI) ? "AUI," : "",
1567 (lp->adapter_cnf & A_CNF_10B_2) ? "BNC," : "");
1568
1569 lp->irq_map = 0xffff;
1570
1571 /* If this is a CS8900 then no pnp soft */
1572 if (lp->chip_type != CS8900 &&
1573 /* Check if the ISA IRQ has been set */
1574 (i = readreg(dev, PP_CS8920_ISAINT) & 0xff,
1575 (i != 0 && i < CS8920_NO_INTS))) {
1576 if (!dev->irq)
1577 dev->irq = i;
1578 } else {
1579 i = lp->isa_config & INT_NO_MASK;
1580#ifndef CONFIG_CS89x0_PLATFORM
1581 if (lp->chip_type == CS8900) {
1582#ifdef CS89x0_NONISA_IRQ
1583 i = cs8900_irq_map[0];
1584#else
1585 /* Translate the IRQ using the IRQ mapping table. */
1586 if (i >= ARRAY_SIZE(cs8900_irq_map))
1587 pr_err("invalid ISA interrupt number %d\n", i);
1588 else
1589 i = cs8900_irq_map[i];
1590
1591 lp->irq_map = CS8900_IRQ_MAP; /* fixed IRQ map for CS8900 */
1592 } else {
1593 int irq_map_buff[IRQ_MAP_LEN/2];
1594
1595 if (get_eeprom_data(dev, IRQ_MAP_EEPROM_DATA,
1596 IRQ_MAP_LEN / 2,
1597 irq_map_buff) >= 0) {
1598 if ((irq_map_buff[0] & 0xff) == PNP_IRQ_FRMT)
1599 lp->irq_map = ((irq_map_buff[0] >> 8) |
1600 (irq_map_buff[1] << 8));
1601 }
1602#endif
1603 }
1604#endif
1605 if (!dev->irq)
1606 dev->irq = i;
1607 }
1608
1609 pr_cont(" IRQ %d", dev->irq);
1610
1611#if ALLOW_DMA
1612 if (lp->use_dma) {
1613 get_dma_channel(dev);
1614 pr_cont(", DMA %d", dev->dma);
1615 } else
1616#endif
1617 pr_cont(", programmed I/O");
1618
1619 /* print the ethernet address. */
1620 pr_cont(", MAC %pM\n", dev->dev_addr);
1621
1622 dev->netdev_ops = &net_ops;
1623 dev->watchdog_timeo = HZ;
1624
1625 cs89_dbg(0, info, "cs89x0_probe1() successful\n");
1626
1627 retval = register_netdev(dev);
1628 if (retval)
1629 goto out2;
1630 return 0;
1631out2:
1632 iowrite16(PP_ChipID, lp->virt_addr + ADD_PORT);
1633out1:
1634 return retval;
1635}
1636
1637#ifndef CONFIG_CS89x0_PLATFORM
1638/*
1639 * This function converts the I/O port addres used by the cs89x0_probe() and
1640 * init_module() functions to the I/O memory address used by the
1641 * cs89x0_probe1() function.
1642 */
1643static int __init
1644cs89x0_ioport_probe(struct net_device *dev, unsigned long ioport, int modular)
1645{
1646 struct net_local *lp = netdev_priv(dev);
1647 int ret;
1648 void __iomem *io_mem;
1649
1650 if (!lp)
1651 return -ENOMEM;
1652
1653 dev->base_addr = ioport;
1654
1655 if (!request_region(ioport, NETCARD_IO_EXTENT, DRV_NAME)) {
1656 ret = -EBUSY;
1657 goto out;
1658 }
1659
1660 io_mem = ioport_map(ioport & ~3, NETCARD_IO_EXTENT);
1661 if (!io_mem) {
1662 ret = -ENOMEM;
1663 goto release;
1664 }
1665
1666 /* if they give us an odd I/O address, then do ONE write to
1667 * the address port, to get it back to address zero, where we
1668 * expect to find the EISA signature word. An IO with a base of 0x3
1669 * will skip the test for the ADD_PORT.
1670 */
1671 if (ioport & 1) {
1672 cs89_dbg(1, info, "%s: odd ioaddr 0x%lx\n", dev->name, ioport);
1673 if ((ioport & 2) != 2) {
1674 if ((ioread16(io_mem + ADD_PORT) & ADD_MASK) !=
1675 ADD_SIG) {
1676 pr_err("%s: bad signature 0x%x\n",
1677 dev->name, ioread16(io_mem + ADD_PORT));
1678 ret = -ENODEV;
1679 goto unmap;
1680 }
1681 }
1682 }
1683
1684 ret = cs89x0_probe1(dev, io_mem, modular);
1685 if (!ret)
1686 goto out;
1687unmap:
1688 ioport_unmap(io_mem);
1689release:
1690 release_region(ioport, NETCARD_IO_EXTENT);
1691out:
1692 return ret;
1693}
1694
1695#ifndef MODULE
1696/* Check for a network adaptor of this type, and return '0' iff one exists.
1697 * If dev->base_addr == 0, probe all likely locations.
1698 * If dev->base_addr == 1, always return failure.
1699 * If dev->base_addr == 2, allocate space for the device and return success
1700 * (detachable devices only).
1701 * Return 0 on success.
1702 */
1703
1704struct net_device * __init cs89x0_probe(int unit)
1705{
1706 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
1707 unsigned *port;
1708 int err = 0;
1709 int irq;
1710 int io;
1711
1712 if (!dev)
1713 return ERR_PTR(-ENODEV);
1714
1715 sprintf(dev->name, "eth%d", unit);
1716 netdev_boot_setup_check(dev);
1717 io = dev->base_addr;
1718 irq = dev->irq;
1719
1720 cs89_dbg(0, info, "cs89x0_probe(0x%x)\n", io);
1721
1722 if (io > 0x1ff) { /* Check a single specified location. */
1723 err = cs89x0_ioport_probe(dev, io, 0);
1724 } else if (io != 0) { /* Don't probe at all. */
1725 err = -ENXIO;
1726 } else {
1727 for (port = netcard_portlist; *port; port++) {
1728 if (cs89x0_ioport_probe(dev, *port, 0) == 0)
1729 break;
1730 dev->irq = irq;
1731 }
1732 if (!*port)
1733 err = -ENODEV;
1734 }
1735 if (err)
1736 goto out;
1737 return dev;
1738out:
1739 free_netdev(dev);
1740 pr_warn("no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n");
1741 return ERR_PTR(err);
1742}
1743#endif
1744#endif
1745
1771#if defined(MODULE) && !defined(CONFIG_CS89x0_PLATFORM) 1746#if defined(MODULE) && !defined(CONFIG_CS89x0_PLATFORM)
1772 1747
1773static struct net_device *dev_cs89x0; 1748static struct net_device *dev_cs89x0;