aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Dooks <ben-linux@fluff.org>2008-06-24 17:16:02 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-06-24 22:57:51 -0400
commitf8d79e79a1700fdcf26a1dfcaefad905b1279600 (patch)
treec864c88840548336575f3ed56277e7419b80479f
parent59eae1fa3ba19be35f09b37e73d90ac5028996fe (diff)
DM9000: Cleanup source code - remove forward declerations
Cleanup the source code by moving the code around to avoid having to declare the functions before they are used. Signed-off-by: Ben Dooks <ben-linux@fluff.org> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
-rw-r--r--drivers/net/dm9000.c1016
1 files changed, 498 insertions, 518 deletions
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 79538ab4ee60..679c291107f5 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -152,23 +152,6 @@ static inline board_info_t *to_dm9000_board(struct net_device *dev)
152 return dev->priv; 152 return dev->priv;
153} 153}
154 154
155/* function declaration ------------------------------------- */
156static int dm9000_open(struct net_device *);
157static int dm9000_start_xmit(struct sk_buff *, struct net_device *);
158static int dm9000_stop(struct net_device *);
159
160static void dm9000_init_dm9000(struct net_device *);
161
162static irqreturn_t dm9000_interrupt(int, void *);
163
164static int dm9000_phy_read(struct net_device *dev, int phy, int reg);
165static void dm9000_phy_write(struct net_device *dev, int phy, int reg, int v);
166
167static void dm9000_read_eeprom(board_info_t *, int addr, u8 *to);
168static void dm9000_write_eeprom(board_info_t *, int addr, u8 *dp);
169static void dm9000_rx(struct net_device *);
170static void dm9000_hash_table(struct net_device *);
171
172/* DM9000 network board routine ---------------------------- */ 155/* DM9000 network board routine ---------------------------- */
173 156
174static void 157static void
@@ -315,49 +298,129 @@ static void dm9000_schedule_poll(board_info_t *db)
315 schedule_delayed_work(&db->phy_poll, HZ * 2); 298 schedule_delayed_work(&db->phy_poll, HZ * 2);
316} 299}
317 300
318/* Our watchdog timed out. Called by the networking layer */ 301static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
319static void dm9000_timeout(struct net_device *dev) 302{
303 board_info_t *dm = to_dm9000_board(dev);
304
305 if (!netif_running(dev))
306 return -EINVAL;
307
308 return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL);
309}
310
311static unsigned int
312dm9000_read_locked(board_info_t *db, int reg)
320{ 313{
321 board_info_t *db = (board_info_t *) dev->priv;
322 u8 reg_save;
323 unsigned long flags; 314 unsigned long flags;
315 unsigned int ret;
324 316
325 /* Save previous register address */ 317 spin_lock_irqsave(&db->lock, flags);
326 reg_save = readb(db->io_addr); 318 ret = ior(db, reg);
327 spin_lock_irqsave(&db->lock,flags); 319 spin_unlock_irqrestore(&db->lock, flags);
328 320
329 netif_stop_queue(dev); 321 return ret;
330 dm9000_reset(db); 322}
331 dm9000_init_dm9000(dev);
332 /* We can accept TX packets again */
333 dev->trans_start = jiffies;
334 netif_wake_queue(dev);
335 323
336 /* Restore previous register address */ 324static int dm9000_wait_eeprom(board_info_t *db)
337 writeb(reg_save, db->io_addr); 325{
338 spin_unlock_irqrestore(&db->lock,flags); 326 unsigned int status;
327 int timeout = 8; /* wait max 8msec */
328
329 /* The DM9000 data sheets say we should be able to
330 * poll the ERRE bit in EPCR to wait for the EEPROM
331 * operation. From testing several chips, this bit
332 * does not seem to work.
333 *
334 * We attempt to use the bit, but fall back to the
335 * timeout (which is why we do not return an error
336 * on expiry) to say that the EEPROM operation has
337 * completed.
338 */
339
340 while (1) {
341 status = dm9000_read_locked(db, DM9000_EPCR);
342
343 if ((status & EPCR_ERRE) == 0)
344 break;
345
346 if (timeout-- < 0) {
347 dev_dbg(db->dev, "timeout waiting EEPROM\n");
348 break;
349 }
350 }
351
352 return 0;
339} 353}
340 354
341#ifdef CONFIG_NET_POLL_CONTROLLER
342/* 355/*
343 *Used by netconsole 356 * Read a word data from EEPROM
344 */ 357 */
345static void dm9000_poll_controller(struct net_device *dev) 358static void
359dm9000_read_eeprom(board_info_t *db, int offset, u8 *to)
346{ 360{
347 disable_irq(dev->irq); 361 unsigned long flags;
348 dm9000_interrupt(dev->irq,dev); 362
349 enable_irq(dev->irq); 363 if (db->flags & DM9000_PLATF_NO_EEPROM) {
364 to[0] = 0xff;
365 to[1] = 0xff;
366 return;
367 }
368
369 mutex_lock(&db->addr_lock);
370
371 spin_lock_irqsave(&db->lock, flags);
372
373 iow(db, DM9000_EPAR, offset);
374 iow(db, DM9000_EPCR, EPCR_ERPRR);
375
376 spin_unlock_irqrestore(&db->lock, flags);
377
378 dm9000_wait_eeprom(db);
379
380 /* delay for at-least 150uS */
381 msleep(1);
382
383 spin_lock_irqsave(&db->lock, flags);
384
385 iow(db, DM9000_EPCR, 0x0);
386
387 to[0] = ior(db, DM9000_EPDRL);
388 to[1] = ior(db, DM9000_EPDRH);
389
390 spin_unlock_irqrestore(&db->lock, flags);
391
392 mutex_unlock(&db->addr_lock);
350} 393}
351#endif
352 394
353static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd) 395/*
396 * Write a word data to SROM
397 */
398static void
399dm9000_write_eeprom(board_info_t *db, int offset, u8 *data)
354{ 400{
355 board_info_t *dm = to_dm9000_board(dev); 401 unsigned long flags;
356 402
357 if (!netif_running(dev)) 403 if (db->flags & DM9000_PLATF_NO_EEPROM)
358 return -EINVAL; 404 return;
359 405
360 return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL); 406 mutex_lock(&db->addr_lock);
407
408 spin_lock_irqsave(&db->lock, flags);
409 iow(db, DM9000_EPAR, offset);
410 iow(db, DM9000_EPDRH, data[1]);
411 iow(db, DM9000_EPDRL, data[0]);
412 iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
413 spin_unlock_irqrestore(&db->lock, flags);
414
415 dm9000_wait_eeprom(db);
416
417 mdelay(1); /* wait at least 150uS to clear */
418
419 spin_lock_irqsave(&db->lock, flags);
420 iow(db, DM9000_EPCR, 0);
421 spin_unlock_irqrestore(&db->lock, flags);
422
423 mutex_unlock(&db->addr_lock);
361} 424}
362 425
363/* ethtool ops */ 426/* ethtool ops */
@@ -527,271 +590,55 @@ static unsigned char dm9000_type_to_char(enum dm9000_type type)
527 return '?'; 590 return '?';
528} 591}
529 592
530#define res_size(_r) (((_r)->end - (_r)->start) + 1)
531
532/* 593/*
533 * Search DM9000 board, allocate space and register it 594 * Set DM9000 multicast address
534 */ 595 */
535static int __devinit 596static void
536dm9000_probe(struct platform_device *pdev) 597dm9000_hash_table(struct net_device *dev)
537{ 598{
538 struct dm9000_plat_data *pdata = pdev->dev.platform_data; 599 board_info_t *db = (board_info_t *) dev->priv;
539 struct board_info *db; /* Point a board information structure */ 600 struct dev_mc_list *mcptr = dev->mc_list;
540 struct net_device *ndev; 601 int mc_cnt = dev->mc_count;
541 const unsigned char *mac_src; 602 int i, oft;
542 int ret = 0; 603 u32 hash_val;
543 int iosize; 604 u16 hash_table[4];
544 int i; 605 u8 rcr = RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN;
545 u32 id_val; 606 unsigned long flags;
546
547 /* Init network device */
548 ndev = alloc_etherdev(sizeof (struct board_info));
549 if (!ndev) {
550 dev_err(&pdev->dev, "could not allocate device.\n");
551 return -ENOMEM;
552 }
553
554 SET_NETDEV_DEV(ndev, &pdev->dev);
555
556 dev_dbg(&pdev->dev, "dm9000_probe()\n");
557
558 /* setup board info structure */
559 db = (struct board_info *) ndev->priv;
560 memset(db, 0, sizeof (*db));
561
562 db->dev = &pdev->dev;
563 db->ndev = ndev;
564
565 spin_lock_init(&db->lock);
566 mutex_init(&db->addr_lock);
567
568 INIT_DELAYED_WORK(&db->phy_poll, dm9000_poll_work);
569
570 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
571 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
572 db->irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
573
574 if (db->addr_res == NULL || db->data_res == NULL ||
575 db->irq_res == NULL) {
576 dev_err(db->dev, "insufficient resources\n");
577 ret = -ENOENT;
578 goto out;
579 }
580
581 iosize = res_size(db->addr_res);
582 db->addr_req = request_mem_region(db->addr_res->start, iosize,
583 pdev->name);
584
585 if (db->addr_req == NULL) {
586 dev_err(db->dev, "cannot claim address reg area\n");
587 ret = -EIO;
588 goto out;
589 }
590
591 db->io_addr = ioremap(db->addr_res->start, iosize);
592
593 if (db->io_addr == NULL) {
594 dev_err(db->dev, "failed to ioremap address reg\n");
595 ret = -EINVAL;
596 goto out;
597 }
598
599 iosize = res_size(db->data_res);
600 db->data_req = request_mem_region(db->data_res->start, iosize,
601 pdev->name);
602
603 if (db->data_req == NULL) {
604 dev_err(db->dev, "cannot claim data reg area\n");
605 ret = -EIO;
606 goto out;
607 }
608
609 db->io_data = ioremap(db->data_res->start, iosize);
610
611 if (db->io_data == NULL) {
612 dev_err(db->dev, "failed to ioremap data reg\n");
613 ret = -EINVAL;
614 goto out;
615 }
616
617 /* fill in parameters for net-dev structure */
618 ndev->base_addr = (unsigned long)db->io_addr;
619 ndev->irq = db->irq_res->start;
620
621 /* ensure at least we have a default set of IO routines */
622 dm9000_set_io(db, iosize);
623
624 /* check to see if anything is being over-ridden */
625 if (pdata != NULL) {
626 /* check to see if the driver wants to over-ride the
627 * default IO width */
628
629 if (pdata->flags & DM9000_PLATF_8BITONLY)
630 dm9000_set_io(db, 1);
631
632 if (pdata->flags & DM9000_PLATF_16BITONLY)
633 dm9000_set_io(db, 2);
634
635 if (pdata->flags & DM9000_PLATF_32BITONLY)
636 dm9000_set_io(db, 4);
637
638 /* check to see if there are any IO routine
639 * over-rides */
640
641 if (pdata->inblk != NULL)
642 db->inblk = pdata->inblk;
643
644 if (pdata->outblk != NULL)
645 db->outblk = pdata->outblk;
646
647 if (pdata->dumpblk != NULL)
648 db->dumpblk = pdata->dumpblk;
649
650 db->flags = pdata->flags;
651 }
652
653 dm9000_reset(db);
654
655 /* try multiple times, DM9000 sometimes gets the read wrong */
656 for (i = 0; i < 8; i++) {
657 id_val = ior(db, DM9000_VIDL);
658 id_val |= (u32)ior(db, DM9000_VIDH) << 8;
659 id_val |= (u32)ior(db, DM9000_PIDL) << 16;
660 id_val |= (u32)ior(db, DM9000_PIDH) << 24;
661
662 if (id_val == DM9000_ID)
663 break;
664 dev_err(db->dev, "read wrong id 0x%08x\n", id_val);
665 }
666
667 if (id_val != DM9000_ID) {
668 dev_err(db->dev, "wrong id: 0x%08x\n", id_val);
669 ret = -ENODEV;
670 goto out;
671 }
672
673 /* Identify what type of DM9000 we are working on */
674
675 id_val = ior(db, DM9000_CHIPR);
676 dev_dbg(db->dev, "dm9000 revision 0x%02x\n", id_val);
677
678 switch (id_val) {
679 case CHIPR_DM9000A:
680 db->type = TYPE_DM9000A;
681 break;
682 case CHIPR_DM9000B:
683 db->type = TYPE_DM9000B;
684 break;
685 default:
686 dev_dbg(db->dev, "ID %02x => defaulting to DM9000E\n", id_val);
687 db->type = TYPE_DM9000E;
688 }
689
690 /* from this point we assume that we have found a DM9000 */
691
692 /* driver system function */
693 ether_setup(ndev);
694
695 ndev->open = &dm9000_open;
696 ndev->hard_start_xmit = &dm9000_start_xmit;
697 ndev->tx_timeout = &dm9000_timeout;
698 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
699 ndev->stop = &dm9000_stop;
700 ndev->set_multicast_list = &dm9000_hash_table;
701 ndev->ethtool_ops = &dm9000_ethtool_ops;
702 ndev->do_ioctl = &dm9000_ioctl;
703
704#ifdef CONFIG_NET_POLL_CONTROLLER
705 ndev->poll_controller = &dm9000_poll_controller;
706#endif
707 607
708 db->msg_enable = NETIF_MSG_LINK; 608 dm9000_dbg(db, 1, "entering %s\n", __func__);
709 db->mii.phy_id_mask = 0x1f;
710 db->mii.reg_num_mask = 0x1f;
711 db->mii.force_media = 0;
712 db->mii.full_duplex = 0;
713 db->mii.dev = ndev;
714 db->mii.mdio_read = dm9000_phy_read;
715 db->mii.mdio_write = dm9000_phy_write;
716 609
717 mac_src = "eeprom"; 610 spin_lock_irqsave(&db->lock, flags);
718 611
719 /* try reading the node address from the attached EEPROM */ 612 for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
720 for (i = 0; i < 6; i += 2) 613 iow(db, oft, dev->dev_addr[i]);
721 dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
722 614
723 if (!is_valid_ether_addr(ndev->dev_addr)) { 615 /* Clear Hash Table */
724 /* try reading from mac */ 616 for (i = 0; i < 4; i++)
617 hash_table[i] = 0x0;
725 618
726 mac_src = "chip"; 619 /* broadcast address */
727 for (i = 0; i < 6; i++) 620 hash_table[3] = 0x8000;
728 ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
729 }
730 621
731 if (!is_valid_ether_addr(ndev->dev_addr)) 622 if (dev->flags & IFF_PROMISC)
732 dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please " 623 rcr |= RCR_PRMSC;
733 "set using ifconfig\n", ndev->name);
734 624
735 platform_set_drvdata(pdev, ndev); 625 if (dev->flags & IFF_ALLMULTI)
736 ret = register_netdev(ndev); 626 rcr |= RCR_ALL;
737 627
738 if (ret == 0) { 628 /* the multicast address in Hash Table : 64 bits */
739 DECLARE_MAC_BUF(mac); 629 for (i = 0; i < mc_cnt; i++, mcptr = mcptr->next) {
740 printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %s (%s)\n", 630 hash_val = ether_crc_le(6, mcptr->dmi_addr) & 0x3f;
741 ndev->name, dm9000_type_to_char(db->type), 631 hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
742 db->io_addr, db->io_data, ndev->irq,
743 print_mac(mac, ndev->dev_addr), mac_src);
744 } 632 }
745 return 0;
746
747out:
748 dev_err(db->dev, "not found (%d).\n", ret);
749 633
750 dm9000_release_board(pdev, db); 634 /* Write the hash table to MAC MD table */
751 free_netdev(ndev); 635 for (i = 0, oft = DM9000_MAR; i < 4; i++) {
752 636 iow(db, oft++, hash_table[i]);
753 return ret; 637 iow(db, oft++, hash_table[i] >> 8);
754}
755
756/*
757 * Open the interface.
758 * The interface is opened whenever "ifconfig" actives it.
759 */
760static int
761dm9000_open(struct net_device *dev)
762{
763 board_info_t *db = dev->priv;
764 unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK;
765
766 if (netif_msg_ifup(db))
767 dev_dbg(db->dev, "enabling %s\n", dev->name);
768
769 /* If there is no IRQ type specified, default to something that
770 * may work, and tell the user that this is a problem */
771
772 if (irqflags == IRQF_TRIGGER_NONE) {
773 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
774 irqflags = DEFAULT_TRIGGER;
775 } 638 }
776 639
777 irqflags |= IRQF_SHARED; 640 iow(db, DM9000_RCR, rcr);
778 641 spin_unlock_irqrestore(&db->lock, flags);
779 if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev))
780 return -EAGAIN;
781
782 /* Initialize DM9000 board */
783 dm9000_reset(db);
784 dm9000_init_dm9000(dev);
785
786 /* Init driver variable */
787 db->dbug_cnt = 0;
788
789 mii_check_media(&db->mii, netif_msg_link(db), 1);
790 netif_start_queue(dev);
791
792 dm9000_schedule_poll(db);
793
794 return 0;
795} 642}
796 643
797/* 644/*
@@ -843,6 +690,29 @@ dm9000_init_dm9000(struct net_device *dev)
843 dev->trans_start = 0; 690 dev->trans_start = 0;
844} 691}
845 692
693/* Our watchdog timed out. Called by the networking layer */
694static void dm9000_timeout(struct net_device *dev)
695{
696 board_info_t *db = (board_info_t *) dev->priv;
697 u8 reg_save;
698 unsigned long flags;
699
700 /* Save previous register address */
701 reg_save = readb(db->io_addr);
702 spin_lock_irqsave(&db->lock, flags);
703
704 netif_stop_queue(dev);
705 dm9000_reset(db);
706 dm9000_init_dm9000(dev);
707 /* We can accept TX packets again */
708 dev->trans_start = jiffies;
709 netif_wake_queue(dev);
710
711 /* Restore previous register address */
712 writeb(reg_save, db->io_addr);
713 spin_unlock_irqrestore(&db->lock, flags);
714}
715
846/* 716/*
847 * Hardware start transmission. 717 * Hardware start transmission.
848 * Send a packet to media from the upper layer. 718 * Send a packet to media from the upper layer.
@@ -891,50 +761,12 @@ dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev)
891 return 0; 761 return 0;
892} 762}
893 763
894static void
895dm9000_shutdown(struct net_device *dev)
896{
897 board_info_t *db = dev->priv;
898
899 /* RESET device */
900 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */
901 iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */
902 iow(db, DM9000_IMR, IMR_PAR); /* Disable all interrupt */
903 iow(db, DM9000_RCR, 0x00); /* Disable RX */
904}
905
906/*
907 * Stop the interface.
908 * The interface is stopped when it is brought.
909 */
910static int
911dm9000_stop(struct net_device *ndev)
912{
913 board_info_t *db = ndev->priv;
914
915 if (netif_msg_ifdown(db))
916 dev_dbg(db->dev, "shutting down %s\n", ndev->name);
917
918 cancel_delayed_work_sync(&db->phy_poll);
919
920 netif_stop_queue(ndev);
921 netif_carrier_off(ndev);
922
923 /* free interrupt */
924 free_irq(ndev->irq, ndev);
925
926 dm9000_shutdown(ndev);
927
928 return 0;
929}
930
931/* 764/*
932 * DM9000 interrupt handler 765 * DM9000 interrupt handler
933 * receive the packet to upper layer, free the transmitted packet 766 * receive the packet to upper layer, free the transmitted packet
934 */ 767 */
935 768
936static void 769static void dm9000_tx_done(struct net_device *dev, board_info_t *db)
937dm9000_tx_done(struct net_device *dev, board_info_t * db)
938{ 770{
939 int tx_status = ior(db, DM9000_NSR); /* Got TX status */ 771 int tx_status = ior(db, DM9000_NSR); /* Got TX status */
940 772
@@ -957,59 +789,6 @@ dm9000_tx_done(struct net_device *dev, board_info_t * db)
957 } 789 }
958} 790}
959 791
960static irqreturn_t
961dm9000_interrupt(int irq, void *dev_id)
962{
963 struct net_device *dev = dev_id;
964 board_info_t *db = dev->priv;
965 int int_status;
966 u8 reg_save;
967
968 dm9000_dbg(db, 3, "entering %s\n", __func__);
969
970 /* A real interrupt coming */
971
972 spin_lock(&db->lock);
973
974 /* Save previous register address */
975 reg_save = readb(db->io_addr);
976
977 /* Disable all interrupts */
978 iow(db, DM9000_IMR, IMR_PAR);
979
980 /* Got DM9000 interrupt status */
981 int_status = ior(db, DM9000_ISR); /* Got ISR */
982 iow(db, DM9000_ISR, int_status); /* Clear ISR status */
983
984 if (netif_msg_intr(db))
985 dev_dbg(db->dev, "interrupt status %02x\n", int_status);
986
987 /* Received the coming packet */
988 if (int_status & ISR_PRS)
989 dm9000_rx(dev);
990
991 /* Trnasmit Interrupt check */
992 if (int_status & ISR_PTS)
993 dm9000_tx_done(dev, db);
994
995 if (db->type != TYPE_DM9000E) {
996 if (int_status & ISR_LNKCHNG) {
997 /* fire a link-change request */
998 schedule_delayed_work(&db->phy_poll, 1);
999 }
1000 }
1001
1002 /* Re-enable interrupt mask */
1003 iow(db, DM9000_IMR, db->imr_all);
1004
1005 /* Restore previous register address */
1006 writeb(reg_save, db->io_addr);
1007
1008 spin_unlock(&db->lock);
1009
1010 return IRQ_HANDLED;
1011}
1012
1013struct dm9000_rxhdr { 792struct dm9000_rxhdr {
1014 u8 RxPktReady; 793 u8 RxPktReady;
1015 u8 RxStatus; 794 u8 RxStatus;
@@ -1113,173 +892,111 @@ dm9000_rx(struct net_device *dev)
1113 } while (rxbyte == DM9000_PKT_RDY); 892 } while (rxbyte == DM9000_PKT_RDY);
1114} 893}
1115 894
1116static unsigned int 895static irqreturn_t dm9000_interrupt(int irq, void *dev_id)
1117dm9000_read_locked(board_info_t *db, int reg)
1118{ 896{
1119 unsigned long flags; 897 struct net_device *dev = dev_id;
1120 unsigned int ret; 898 board_info_t *db = dev->priv;
899 int int_status;
900 u8 reg_save;
1121 901
1122 spin_lock_irqsave(&db->lock, flags); 902 dm9000_dbg(db, 3, "entering %s\n", __func__);
1123 ret = ior(db, reg);
1124 spin_unlock_irqrestore(&db->lock, flags);
1125 903
1126 return ret; 904 /* A real interrupt coming */
1127}
1128 905
1129static int dm9000_wait_eeprom(board_info_t *db) 906 spin_lock(&db->lock);
1130{
1131 unsigned int status;
1132 int timeout = 8; /* wait max 8msec */
1133 907
1134 /* The DM9000 data sheets say we should be able to 908 /* Save previous register address */
1135 * poll the ERRE bit in EPCR to wait for the EEPROM 909 reg_save = readb(db->io_addr);
1136 * operation. From testing several chips, this bit
1137 * does not seem to work.
1138 *
1139 * We attempt to use the bit, but fall back to the
1140 * timeout (which is why we do not return an error
1141 * on expiry) to say that the EEPROM operation has
1142 * completed.
1143 */
1144 910
1145 while (1) { 911 /* Disable all interrupts */
1146 status = dm9000_read_locked(db, DM9000_EPCR); 912 iow(db, DM9000_IMR, IMR_PAR);
1147 913
1148 if ((status & EPCR_ERRE) == 0) 914 /* Got DM9000 interrupt status */
1149 break; 915 int_status = ior(db, DM9000_ISR); /* Got ISR */
916 iow(db, DM9000_ISR, int_status); /* Clear ISR status */
1150 917
1151 if (timeout-- < 0) { 918 if (netif_msg_intr(db))
1152 dev_dbg(db->dev, "timeout waiting EEPROM\n"); 919 dev_dbg(db->dev, "interrupt status %02x\n", int_status);
1153 break;
1154 }
1155 }
1156 920
1157 return 0; 921 /* Received the coming packet */
1158} 922 if (int_status & ISR_PRS)
923 dm9000_rx(dev);
1159 924
1160/* 925 /* Trnasmit Interrupt check */
1161 * Read a word data from EEPROM 926 if (int_status & ISR_PTS)
1162 */ 927 dm9000_tx_done(dev, db);
1163static void
1164dm9000_read_eeprom(board_info_t *db, int offset, u8 *to)
1165{
1166 unsigned long flags;
1167 928
1168 if (db->flags & DM9000_PLATF_NO_EEPROM) { 929 if (db->type != TYPE_DM9000E) {
1169 to[0] = 0xff; 930 if (int_status & ISR_LNKCHNG) {
1170 to[1] = 0xff; 931 /* fire a link-change request */
1171 return; 932 schedule_delayed_work(&db->phy_poll, 1);
933 }
1172 } 934 }
1173 935
1174 mutex_lock(&db->addr_lock); 936 /* Re-enable interrupt mask */
1175 937 iow(db, DM9000_IMR, db->imr_all);
1176 spin_lock_irqsave(&db->lock, flags);
1177
1178 iow(db, DM9000_EPAR, offset);
1179 iow(db, DM9000_EPCR, EPCR_ERPRR);
1180
1181 spin_unlock_irqrestore(&db->lock, flags);
1182
1183 dm9000_wait_eeprom(db);
1184
1185 /* delay for at-least 150uS */
1186 msleep(1);
1187
1188 spin_lock_irqsave(&db->lock, flags);
1189
1190 iow(db, DM9000_EPCR, 0x0);
1191 938
1192 to[0] = ior(db, DM9000_EPDRL); 939 /* Restore previous register address */
1193 to[1] = ior(db, DM9000_EPDRH); 940 writeb(reg_save, db->io_addr);
1194 941
1195 spin_unlock_irqrestore(&db->lock, flags); 942 spin_unlock(&db->lock);
1196 943
1197 mutex_unlock(&db->addr_lock); 944 return IRQ_HANDLED;
1198} 945}
1199 946
947#ifdef CONFIG_NET_POLL_CONTROLLER
1200/* 948/*
1201 * Write a word data to SROM 949 *Used by netconsole
1202 */ 950 */
1203static void 951static void dm9000_poll_controller(struct net_device *dev)
1204dm9000_write_eeprom(board_info_t *db, int offset, u8 *data)
1205{ 952{
1206 unsigned long flags; 953 disable_irq(dev->irq);
1207 954 dm9000_interrupt(dev->irq, dev);
1208 if (db->flags & DM9000_PLATF_NO_EEPROM) 955 enable_irq(dev->irq);
1209 return;
1210
1211 mutex_lock(&db->addr_lock);
1212
1213 spin_lock_irqsave(&db->lock, flags);
1214 iow(db, DM9000_EPAR, offset);
1215 iow(db, DM9000_EPDRH, data[1]);
1216 iow(db, DM9000_EPDRL, data[0]);
1217 iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
1218 spin_unlock_irqrestore(&db->lock, flags);
1219
1220 dm9000_wait_eeprom(db);
1221
1222 mdelay(1); /* wait at least 150uS to clear */
1223
1224 spin_lock_irqsave(&db->lock, flags);
1225 iow(db, DM9000_EPCR, 0);
1226 spin_unlock_irqrestore(&db->lock, flags);
1227
1228 mutex_unlock(&db->addr_lock);
1229} 956}
957#endif
1230 958
1231/* 959/*
1232 * Set DM9000 multicast address 960 * Open the interface.
961 * The interface is opened whenever "ifconfig" actives it.
1233 */ 962 */
1234static void 963static int
1235dm9000_hash_table(struct net_device *dev) 964dm9000_open(struct net_device *dev)
1236{ 965{
1237 board_info_t *db = (board_info_t *) dev->priv; 966 board_info_t *db = dev->priv;
1238 struct dev_mc_list *mcptr = dev->mc_list; 967 unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK;
1239 int mc_cnt = dev->mc_count;
1240 int i, oft;
1241 u32 hash_val;
1242 u16 hash_table[4];
1243 u8 rcr = RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN;
1244 unsigned long flags;
1245
1246 dm9000_dbg(db, 1, "entering %s\n", __func__);
1247
1248 spin_lock_irqsave(&db->lock, flags);
1249 968
1250 for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) 969 if (netif_msg_ifup(db))
1251 iow(db, oft, dev->dev_addr[i]); 970 dev_dbg(db->dev, "enabling %s\n", dev->name);
1252 971
1253 /* Clear Hash Table */ 972 /* If there is no IRQ type specified, default to something that
1254 for (i = 0; i < 4; i++) 973 * may work, and tell the user that this is a problem */
1255 hash_table[i] = 0x0;
1256 974
1257 /* broadcast address */ 975 if (irqflags == IRQF_TRIGGER_NONE) {
1258 hash_table[3] = 0x8000; 976 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
977 irqflags = DEFAULT_TRIGGER;
978 }
979
980 irqflags |= IRQF_SHARED;
1259 981
1260 if (dev->flags & IFF_PROMISC) 982 if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev))
1261 rcr |= RCR_PRMSC; 983 return -EAGAIN;
1262 984
1263 if (dev->flags & IFF_ALLMULTI) 985 /* Initialize DM9000 board */
1264 rcr |= RCR_ALL; 986 dm9000_reset(db);
987 dm9000_init_dm9000(dev);
1265 988
1266 /* the multicast address in Hash Table : 64 bits */ 989 /* Init driver variable */
1267 for (i = 0; i < mc_cnt; i++, mcptr = mcptr->next) { 990 db->dbug_cnt = 0;
1268 hash_val = ether_crc_le(6, mcptr->dmi_addr) & 0x3f;
1269 hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
1270 }
1271 991
1272 /* Write the hash table to MAC MD table */ 992 mii_check_media(&db->mii, netif_msg_link(db), 1);
1273 for (i = 0, oft = DM9000_MAR; i < 4; i++) { 993 netif_start_queue(dev);
1274 iow(db, oft++, hash_table[i]); 994
1275 iow(db, oft++, hash_table[i] >> 8); 995 dm9000_schedule_poll(db);
1276 }
1277 996
1278 iow(db, DM9000_RCR, rcr); 997 return 0;
1279 spin_unlock_irqrestore(&db->lock, flags);
1280} 998}
1281 999
1282
1283/* 1000/*
1284 * Sleep, either by using msleep() or if we are suspending, then 1001 * Sleep, either by using msleep() or if we are suspending, then
1285 * use mdelay() to sleep. 1002 * use mdelay() to sleep.
@@ -1383,6 +1100,269 @@ dm9000_phy_write(struct net_device *dev,
1383 mutex_unlock(&db->addr_lock); 1100 mutex_unlock(&db->addr_lock);
1384} 1101}
1385 1102
1103static void
1104dm9000_shutdown(struct net_device *dev)
1105{
1106 board_info_t *db = dev->priv;
1107
1108 /* RESET device */
1109 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */
1110 iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */
1111 iow(db, DM9000_IMR, IMR_PAR); /* Disable all interrupt */
1112 iow(db, DM9000_RCR, 0x00); /* Disable RX */
1113}
1114
1115/*
1116 * Stop the interface.
1117 * The interface is stopped when it is brought.
1118 */
1119static int
1120dm9000_stop(struct net_device *ndev)
1121{
1122 board_info_t *db = ndev->priv;
1123
1124 if (netif_msg_ifdown(db))
1125 dev_dbg(db->dev, "shutting down %s\n", ndev->name);
1126
1127 cancel_delayed_work_sync(&db->phy_poll);
1128
1129 netif_stop_queue(ndev);
1130 netif_carrier_off(ndev);
1131
1132 /* free interrupt */
1133 free_irq(ndev->irq, ndev);
1134
1135 dm9000_shutdown(ndev);
1136
1137 return 0;
1138}
1139
1140#define res_size(_r) (((_r)->end - (_r)->start) + 1)
1141
1142/*
1143 * Search DM9000 board, allocate space and register it
1144 */
1145static int __devinit
1146dm9000_probe(struct platform_device *pdev)
1147{
1148 struct dm9000_plat_data *pdata = pdev->dev.platform_data;
1149 struct board_info *db; /* Point a board information structure */
1150 struct net_device *ndev;
1151 const unsigned char *mac_src;
1152 int ret = 0;
1153 int iosize;
1154 int i;
1155 u32 id_val;
1156
1157 /* Init network device */
1158 ndev = alloc_etherdev(sizeof(struct board_info));
1159 if (!ndev) {
1160 dev_err(&pdev->dev, "could not allocate device.\n");
1161 return -ENOMEM;
1162 }
1163
1164 SET_NETDEV_DEV(ndev, &pdev->dev);
1165
1166 dev_dbg(&pdev->dev, "dm9000_probe()\n");
1167
1168 /* setup board info structure */
1169 db = ndev->priv;
1170 memset(db, 0, sizeof(*db));
1171
1172 db->dev = &pdev->dev;
1173 db->ndev = ndev;
1174
1175 spin_lock_init(&db->lock);
1176 mutex_init(&db->addr_lock);
1177
1178 INIT_DELAYED_WORK(&db->phy_poll, dm9000_poll_work);
1179
1180 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1181 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1182 db->irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1183
1184 if (db->addr_res == NULL || db->data_res == NULL ||
1185 db->irq_res == NULL) {
1186 dev_err(db->dev, "insufficient resources\n");
1187 ret = -ENOENT;
1188 goto out;
1189 }
1190
1191 iosize = res_size(db->addr_res);
1192 db->addr_req = request_mem_region(db->addr_res->start, iosize,
1193 pdev->name);
1194
1195 if (db->addr_req == NULL) {
1196 dev_err(db->dev, "cannot claim address reg area\n");
1197 ret = -EIO;
1198 goto out;
1199 }
1200
1201 db->io_addr = ioremap(db->addr_res->start, iosize);
1202
1203 if (db->io_addr == NULL) {
1204 dev_err(db->dev, "failed to ioremap address reg\n");
1205 ret = -EINVAL;
1206 goto out;
1207 }
1208
1209 iosize = res_size(db->data_res);
1210 db->data_req = request_mem_region(db->data_res->start, iosize,
1211 pdev->name);
1212
1213 if (db->data_req == NULL) {
1214 dev_err(db->dev, "cannot claim data reg area\n");
1215 ret = -EIO;
1216 goto out;
1217 }
1218
1219 db->io_data = ioremap(db->data_res->start, iosize);
1220
1221 if (db->io_data == NULL) {
1222 dev_err(db->dev, "failed to ioremap data reg\n");
1223 ret = -EINVAL;
1224 goto out;
1225 }
1226
1227 /* fill in parameters for net-dev structure */
1228 ndev->base_addr = (unsigned long)db->io_addr;
1229 ndev->irq = db->irq_res->start;
1230
1231 /* ensure at least we have a default set of IO routines */
1232 dm9000_set_io(db, iosize);
1233
1234 /* check to see if anything is being over-ridden */
1235 if (pdata != NULL) {
1236 /* check to see if the driver wants to over-ride the
1237 * default IO width */
1238
1239 if (pdata->flags & DM9000_PLATF_8BITONLY)
1240 dm9000_set_io(db, 1);
1241
1242 if (pdata->flags & DM9000_PLATF_16BITONLY)
1243 dm9000_set_io(db, 2);
1244
1245 if (pdata->flags & DM9000_PLATF_32BITONLY)
1246 dm9000_set_io(db, 4);
1247
1248 /* check to see if there are any IO routine
1249 * over-rides */
1250
1251 if (pdata->inblk != NULL)
1252 db->inblk = pdata->inblk;
1253
1254 if (pdata->outblk != NULL)
1255 db->outblk = pdata->outblk;
1256
1257 if (pdata->dumpblk != NULL)
1258 db->dumpblk = pdata->dumpblk;
1259
1260 db->flags = pdata->flags;
1261 }
1262
1263 dm9000_reset(db);
1264
1265 /* try multiple times, DM9000 sometimes gets the read wrong */
1266 for (i = 0; i < 8; i++) {
1267 id_val = ior(db, DM9000_VIDL);
1268 id_val |= (u32)ior(db, DM9000_VIDH) << 8;
1269 id_val |= (u32)ior(db, DM9000_PIDL) << 16;
1270 id_val |= (u32)ior(db, DM9000_PIDH) << 24;
1271
1272 if (id_val == DM9000_ID)
1273 break;
1274 dev_err(db->dev, "read wrong id 0x%08x\n", id_val);
1275 }
1276
1277 if (id_val != DM9000_ID) {
1278 dev_err(db->dev, "wrong id: 0x%08x\n", id_val);
1279 ret = -ENODEV;
1280 goto out;
1281 }
1282
1283 /* Identify what type of DM9000 we are working on */
1284
1285 id_val = ior(db, DM9000_CHIPR);
1286 dev_dbg(db->dev, "dm9000 revision 0x%02x\n", id_val);
1287
1288 switch (id_val) {
1289 case CHIPR_DM9000A:
1290 db->type = TYPE_DM9000A;
1291 break;
1292 case CHIPR_DM9000B:
1293 db->type = TYPE_DM9000B;
1294 break;
1295 default:
1296 dev_dbg(db->dev, "ID %02x => defaulting to DM9000E\n", id_val);
1297 db->type = TYPE_DM9000E;
1298 }
1299
1300 /* from this point we assume that we have found a DM9000 */
1301
1302 /* driver system function */
1303 ether_setup(ndev);
1304
1305 ndev->open = &dm9000_open;
1306 ndev->hard_start_xmit = &dm9000_start_xmit;
1307 ndev->tx_timeout = &dm9000_timeout;
1308 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
1309 ndev->stop = &dm9000_stop;
1310 ndev->set_multicast_list = &dm9000_hash_table;
1311 ndev->ethtool_ops = &dm9000_ethtool_ops;
1312 ndev->do_ioctl = &dm9000_ioctl;
1313
1314#ifdef CONFIG_NET_POLL_CONTROLLER
1315 ndev->poll_controller = &dm9000_poll_controller;
1316#endif
1317
1318 db->msg_enable = NETIF_MSG_LINK;
1319 db->mii.phy_id_mask = 0x1f;
1320 db->mii.reg_num_mask = 0x1f;
1321 db->mii.force_media = 0;
1322 db->mii.full_duplex = 0;
1323 db->mii.dev = ndev;
1324 db->mii.mdio_read = dm9000_phy_read;
1325 db->mii.mdio_write = dm9000_phy_write;
1326
1327 mac_src = "eeprom";
1328
1329 /* try reading the node address from the attached EEPROM */
1330 for (i = 0; i < 6; i += 2)
1331 dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
1332
1333 if (!is_valid_ether_addr(ndev->dev_addr)) {
1334 /* try reading from mac */
1335
1336 mac_src = "chip";
1337 for (i = 0; i < 6; i++)
1338 ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
1339 }
1340
1341 if (!is_valid_ether_addr(ndev->dev_addr))
1342 dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "
1343 "set using ifconfig\n", ndev->name);
1344
1345 platform_set_drvdata(pdev, ndev);
1346 ret = register_netdev(ndev);
1347
1348 if (ret == 0) {
1349 DECLARE_MAC_BUF(mac);
1350 printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %s (%s)\n",
1351 ndev->name, dm9000_type_to_char(db->type),
1352 db->io_addr, db->io_data, ndev->irq,
1353 print_mac(mac, ndev->dev_addr), mac_src);
1354 }
1355 return 0;
1356
1357out:
1358 dev_err(db->dev, "not found (%d).\n", ret);
1359
1360 dm9000_release_board(pdev, db);
1361 free_netdev(ndev);
1362
1363 return ret;
1364}
1365
1386static int 1366static int
1387dm9000_drv_suspend(struct platform_device *dev, pm_message_t state) 1367dm9000_drv_suspend(struct platform_device *dev, pm_message_t state)
1388{ 1368{