diff options
Diffstat (limited to 'drivers/net/arm/at91_ether.c')
-rw-r--r-- | drivers/net/arm/at91_ether.c | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c index b54b857e357e..fada15d959de 100644 --- a/drivers/net/arm/at91_ether.c +++ b/drivers/net/arm/at91_ether.c | |||
@@ -41,9 +41,6 @@ | |||
41 | #define DRV_NAME "at91_ether" | 41 | #define DRV_NAME "at91_ether" |
42 | #define DRV_VERSION "1.0" | 42 | #define DRV_VERSION "1.0" |
43 | 43 | ||
44 | static struct net_device *at91_dev; | ||
45 | |||
46 | static struct timer_list check_timer; | ||
47 | #define LINK_POLL_INTERVAL (HZ) | 44 | #define LINK_POLL_INTERVAL (HZ) |
48 | 45 | ||
49 | /* ..................................................................... */ | 46 | /* ..................................................................... */ |
@@ -146,7 +143,7 @@ static void read_phy(unsigned char phy_addr, unsigned char address, unsigned int | |||
146 | */ | 143 | */ |
147 | static void update_linkspeed(struct net_device *dev, int silent) | 144 | static void update_linkspeed(struct net_device *dev, int silent) |
148 | { | 145 | { |
149 | struct at91_private *lp = (struct at91_private *) dev->priv; | 146 | struct at91_private *lp = netdev_priv(dev); |
150 | unsigned int bmsr, bmcr, lpa, mac_cfg; | 147 | unsigned int bmsr, bmcr, lpa, mac_cfg; |
151 | unsigned int speed, duplex; | 148 | unsigned int speed, duplex; |
152 | 149 | ||
@@ -199,7 +196,7 @@ static void update_linkspeed(struct net_device *dev, int silent) | |||
199 | static irqreturn_t at91ether_phy_interrupt(int irq, void *dev_id) | 196 | static irqreturn_t at91ether_phy_interrupt(int irq, void *dev_id) |
200 | { | 197 | { |
201 | struct net_device *dev = (struct net_device *) dev_id; | 198 | struct net_device *dev = (struct net_device *) dev_id; |
202 | struct at91_private *lp = (struct at91_private *) dev->priv; | 199 | struct at91_private *lp = netdev_priv(dev); |
203 | unsigned int phy; | 200 | unsigned int phy; |
204 | 201 | ||
205 | /* | 202 | /* |
@@ -242,7 +239,7 @@ done: | |||
242 | */ | 239 | */ |
243 | static void enable_phyirq(struct net_device *dev) | 240 | static void enable_phyirq(struct net_device *dev) |
244 | { | 241 | { |
245 | struct at91_private *lp = (struct at91_private *) dev->priv; | 242 | struct at91_private *lp = netdev_priv(dev); |
246 | unsigned int dsintr, irq_number; | 243 | unsigned int dsintr, irq_number; |
247 | int status; | 244 | int status; |
248 | 245 | ||
@@ -252,8 +249,7 @@ static void enable_phyirq(struct net_device *dev) | |||
252 | * PHY doesn't have an IRQ pin (RTL8201, DP83847, AC101L), | 249 | * PHY doesn't have an IRQ pin (RTL8201, DP83847, AC101L), |
253 | * or board does not have it connected. | 250 | * or board does not have it connected. |
254 | */ | 251 | */ |
255 | check_timer.expires = jiffies + LINK_POLL_INTERVAL; | 252 | mod_timer(&lp->check_timer, jiffies + LINK_POLL_INTERVAL); |
256 | add_timer(&check_timer); | ||
257 | return; | 253 | return; |
258 | } | 254 | } |
259 | 255 | ||
@@ -294,13 +290,13 @@ static void enable_phyirq(struct net_device *dev) | |||
294 | */ | 290 | */ |
295 | static void disable_phyirq(struct net_device *dev) | 291 | static void disable_phyirq(struct net_device *dev) |
296 | { | 292 | { |
297 | struct at91_private *lp = (struct at91_private *) dev->priv; | 293 | struct at91_private *lp = netdev_priv(dev); |
298 | unsigned int dsintr; | 294 | unsigned int dsintr; |
299 | unsigned int irq_number; | 295 | unsigned int irq_number; |
300 | 296 | ||
301 | irq_number = lp->board_data.phy_irq_pin; | 297 | irq_number = lp->board_data.phy_irq_pin; |
302 | if (!irq_number) { | 298 | if (!irq_number) { |
303 | del_timer_sync(&check_timer); | 299 | del_timer_sync(&lp->check_timer); |
304 | return; | 300 | return; |
305 | } | 301 | } |
306 | 302 | ||
@@ -340,7 +336,7 @@ static void disable_phyirq(struct net_device *dev) | |||
340 | #if 0 | 336 | #if 0 |
341 | static void reset_phy(struct net_device *dev) | 337 | static void reset_phy(struct net_device *dev) |
342 | { | 338 | { |
343 | struct at91_private *lp = (struct at91_private *) dev->priv; | 339 | struct at91_private *lp = netdev_priv(dev); |
344 | unsigned int bmcr; | 340 | unsigned int bmcr; |
345 | 341 | ||
346 | spin_lock_irq(&lp->lock); | 342 | spin_lock_irq(&lp->lock); |
@@ -362,13 +358,13 @@ static void reset_phy(struct net_device *dev) | |||
362 | static void at91ether_check_link(unsigned long dev_id) | 358 | static void at91ether_check_link(unsigned long dev_id) |
363 | { | 359 | { |
364 | struct net_device *dev = (struct net_device *) dev_id; | 360 | struct net_device *dev = (struct net_device *) dev_id; |
361 | struct at91_private *lp = netdev_priv(dev); | ||
365 | 362 | ||
366 | enable_mdi(); | 363 | enable_mdi(); |
367 | update_linkspeed(dev, 1); | 364 | update_linkspeed(dev, 1); |
368 | disable_mdi(); | 365 | disable_mdi(); |
369 | 366 | ||
370 | check_timer.expires = jiffies + LINK_POLL_INTERVAL; | 367 | mod_timer(&lp->check_timer, jiffies + LINK_POLL_INTERVAL); |
371 | add_timer(&check_timer); | ||
372 | } | 368 | } |
373 | 369 | ||
374 | /* ......................... ADDRESS MANAGEMENT ........................ */ | 370 | /* ......................... ADDRESS MANAGEMENT ........................ */ |
@@ -590,7 +586,7 @@ static void mdio_write(struct net_device *dev, int phy_id, int location, int val | |||
590 | 586 | ||
591 | static int at91ether_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | 587 | static int at91ether_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
592 | { | 588 | { |
593 | struct at91_private *lp = (struct at91_private *) dev->priv; | 589 | struct at91_private *lp = netdev_priv(dev); |
594 | int ret; | 590 | int ret; |
595 | 591 | ||
596 | spin_lock_irq(&lp->lock); | 592 | spin_lock_irq(&lp->lock); |
@@ -611,7 +607,7 @@ static int at91ether_get_settings(struct net_device *dev, struct ethtool_cmd *cm | |||
611 | 607 | ||
612 | static int at91ether_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | 608 | static int at91ether_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
613 | { | 609 | { |
614 | struct at91_private *lp = (struct at91_private *) dev->priv; | 610 | struct at91_private *lp = netdev_priv(dev); |
615 | int ret; | 611 | int ret; |
616 | 612 | ||
617 | spin_lock_irq(&lp->lock); | 613 | spin_lock_irq(&lp->lock); |
@@ -627,7 +623,7 @@ static int at91ether_set_settings(struct net_device *dev, struct ethtool_cmd *cm | |||
627 | 623 | ||
628 | static int at91ether_nwayreset(struct net_device *dev) | 624 | static int at91ether_nwayreset(struct net_device *dev) |
629 | { | 625 | { |
630 | struct at91_private *lp = (struct at91_private *) dev->priv; | 626 | struct at91_private *lp = netdev_priv(dev); |
631 | int ret; | 627 | int ret; |
632 | 628 | ||
633 | spin_lock_irq(&lp->lock); | 629 | spin_lock_irq(&lp->lock); |
@@ -658,7 +654,7 @@ static const struct ethtool_ops at91ether_ethtool_ops = { | |||
658 | 654 | ||
659 | static int at91ether_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | 655 | static int at91ether_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
660 | { | 656 | { |
661 | struct at91_private *lp = (struct at91_private *) dev->priv; | 657 | struct at91_private *lp = netdev_priv(dev); |
662 | int res; | 658 | int res; |
663 | 659 | ||
664 | if (!netif_running(dev)) | 660 | if (!netif_running(dev)) |
@@ -680,7 +676,7 @@ static int at91ether_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |||
680 | */ | 676 | */ |
681 | static void at91ether_start(struct net_device *dev) | 677 | static void at91ether_start(struct net_device *dev) |
682 | { | 678 | { |
683 | struct at91_private *lp = (struct at91_private *) dev->priv; | 679 | struct at91_private *lp = netdev_priv(dev); |
684 | struct recv_desc_bufs *dlist, *dlist_phys; | 680 | struct recv_desc_bufs *dlist, *dlist_phys; |
685 | int i; | 681 | int i; |
686 | unsigned long ctl; | 682 | unsigned long ctl; |
@@ -712,7 +708,7 @@ static void at91ether_start(struct net_device *dev) | |||
712 | */ | 708 | */ |
713 | static int at91ether_open(struct net_device *dev) | 709 | static int at91ether_open(struct net_device *dev) |
714 | { | 710 | { |
715 | struct at91_private *lp = (struct at91_private *) dev->priv; | 711 | struct at91_private *lp = netdev_priv(dev); |
716 | unsigned long ctl; | 712 | unsigned long ctl; |
717 | 713 | ||
718 | if (!is_valid_ether_addr(dev->dev_addr)) | 714 | if (!is_valid_ether_addr(dev->dev_addr)) |
@@ -752,7 +748,7 @@ static int at91ether_open(struct net_device *dev) | |||
752 | */ | 748 | */ |
753 | static int at91ether_close(struct net_device *dev) | 749 | static int at91ether_close(struct net_device *dev) |
754 | { | 750 | { |
755 | struct at91_private *lp = (struct at91_private *) dev->priv; | 751 | struct at91_private *lp = netdev_priv(dev); |
756 | unsigned long ctl; | 752 | unsigned long ctl; |
757 | 753 | ||
758 | /* Disable Receiver and Transmitter */ | 754 | /* Disable Receiver and Transmitter */ |
@@ -779,7 +775,7 @@ static int at91ether_close(struct net_device *dev) | |||
779 | */ | 775 | */ |
780 | static int at91ether_tx(struct sk_buff *skb, struct net_device *dev) | 776 | static int at91ether_tx(struct sk_buff *skb, struct net_device *dev) |
781 | { | 777 | { |
782 | struct at91_private *lp = (struct at91_private *) dev->priv; | 778 | struct at91_private *lp = netdev_priv(dev); |
783 | 779 | ||
784 | if (at91_emac_read(AT91_EMAC_TSR) & AT91_EMAC_TSR_BNQ) { | 780 | if (at91_emac_read(AT91_EMAC_TSR) & AT91_EMAC_TSR_BNQ) { |
785 | netif_stop_queue(dev); | 781 | netif_stop_queue(dev); |
@@ -811,7 +807,7 @@ static int at91ether_tx(struct sk_buff *skb, struct net_device *dev) | |||
811 | */ | 807 | */ |
812 | static struct net_device_stats *at91ether_stats(struct net_device *dev) | 808 | static struct net_device_stats *at91ether_stats(struct net_device *dev) |
813 | { | 809 | { |
814 | struct at91_private *lp = (struct at91_private *) dev->priv; | 810 | struct at91_private *lp = netdev_priv(dev); |
815 | int ale, lenerr, seqe, lcol, ecol; | 811 | int ale, lenerr, seqe, lcol, ecol; |
816 | 812 | ||
817 | if (netif_running(dev)) { | 813 | if (netif_running(dev)) { |
@@ -847,7 +843,7 @@ static struct net_device_stats *at91ether_stats(struct net_device *dev) | |||
847 | */ | 843 | */ |
848 | static void at91ether_rx(struct net_device *dev) | 844 | static void at91ether_rx(struct net_device *dev) |
849 | { | 845 | { |
850 | struct at91_private *lp = (struct at91_private *) dev->priv; | 846 | struct at91_private *lp = netdev_priv(dev); |
851 | struct recv_desc_bufs *dlist; | 847 | struct recv_desc_bufs *dlist; |
852 | unsigned char *p_recv; | 848 | unsigned char *p_recv; |
853 | struct sk_buff *skb; | 849 | struct sk_buff *skb; |
@@ -857,14 +853,13 @@ static void at91ether_rx(struct net_device *dev) | |||
857 | while (dlist->descriptors[lp->rxBuffIndex].addr & EMAC_DESC_DONE) { | 853 | while (dlist->descriptors[lp->rxBuffIndex].addr & EMAC_DESC_DONE) { |
858 | p_recv = dlist->recv_buf[lp->rxBuffIndex]; | 854 | p_recv = dlist->recv_buf[lp->rxBuffIndex]; |
859 | pktlen = dlist->descriptors[lp->rxBuffIndex].size & 0x7ff; /* Length of frame including FCS */ | 855 | pktlen = dlist->descriptors[lp->rxBuffIndex].size & 0x7ff; /* Length of frame including FCS */ |
860 | skb = alloc_skb(pktlen + 2, GFP_ATOMIC); | 856 | skb = dev_alloc_skb(pktlen + 2); |
861 | if (skb != NULL) { | 857 | if (skb != NULL) { |
862 | skb_reserve(skb, 2); | 858 | skb_reserve(skb, 2); |
863 | memcpy(skb_put(skb, pktlen), p_recv, pktlen); | 859 | memcpy(skb_put(skb, pktlen), p_recv, pktlen); |
864 | 860 | ||
865 | skb->dev = dev; | 861 | skb->dev = dev; |
866 | skb->protocol = eth_type_trans(skb, dev); | 862 | skb->protocol = eth_type_trans(skb, dev); |
867 | skb->len = pktlen; | ||
868 | dev->last_rx = jiffies; | 863 | dev->last_rx = jiffies; |
869 | lp->stats.rx_bytes += pktlen; | 864 | lp->stats.rx_bytes += pktlen; |
870 | netif_rx(skb); | 865 | netif_rx(skb); |
@@ -891,7 +886,7 @@ static void at91ether_rx(struct net_device *dev) | |||
891 | static irqreturn_t at91ether_interrupt(int irq, void *dev_id) | 886 | static irqreturn_t at91ether_interrupt(int irq, void *dev_id) |
892 | { | 887 | { |
893 | struct net_device *dev = (struct net_device *) dev_id; | 888 | struct net_device *dev = (struct net_device *) dev_id; |
894 | struct at91_private *lp = (struct at91_private *) dev->priv; | 889 | struct at91_private *lp = netdev_priv(dev); |
895 | unsigned long intstatus, ctl; | 890 | unsigned long intstatus, ctl; |
896 | 891 | ||
897 | /* MAC Interrupt Status register indicates what interrupts are pending. | 892 | /* MAC Interrupt Status register indicates what interrupts are pending. |
@@ -927,6 +922,17 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id) | |||
927 | return IRQ_HANDLED; | 922 | return IRQ_HANDLED; |
928 | } | 923 | } |
929 | 924 | ||
925 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
926 | static void at91ether_poll_controller(struct net_device *dev) | ||
927 | { | ||
928 | unsigned long flags; | ||
929 | |||
930 | local_irq_save(flags); | ||
931 | at91ether_interrupt(dev->irq, dev); | ||
932 | local_irq_restore(flags); | ||
933 | } | ||
934 | #endif | ||
935 | |||
930 | /* | 936 | /* |
931 | * Initialize the ethernet interface | 937 | * Initialize the ethernet interface |
932 | */ | 938 | */ |
@@ -939,9 +945,6 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add | |||
939 | unsigned int val; | 945 | unsigned int val; |
940 | int res; | 946 | int res; |
941 | 947 | ||
942 | if (at91_dev) /* already initialized */ | ||
943 | return 0; | ||
944 | |||
945 | dev = alloc_etherdev(sizeof(struct at91_private)); | 948 | dev = alloc_etherdev(sizeof(struct at91_private)); |
946 | if (!dev) | 949 | if (!dev) |
947 | return -ENOMEM; | 950 | return -ENOMEM; |
@@ -957,7 +960,7 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add | |||
957 | } | 960 | } |
958 | 961 | ||
959 | /* Allocate memory for DMA Receive descriptors */ | 962 | /* Allocate memory for DMA Receive descriptors */ |
960 | lp = (struct at91_private *)dev->priv; | 963 | lp = netdev_priv(dev); |
961 | lp->dlist = (struct recv_desc_bufs *) dma_alloc_coherent(NULL, sizeof(struct recv_desc_bufs), (dma_addr_t *) &lp->dlist_phys, GFP_KERNEL); | 964 | lp->dlist = (struct recv_desc_bufs *) dma_alloc_coherent(NULL, sizeof(struct recv_desc_bufs), (dma_addr_t *) &lp->dlist_phys, GFP_KERNEL); |
962 | if (lp->dlist == NULL) { | 965 | if (lp->dlist == NULL) { |
963 | free_irq(dev->irq, dev); | 966 | free_irq(dev->irq, dev); |
@@ -979,6 +982,9 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add | |||
979 | dev->set_mac_address = set_mac_address; | 982 | dev->set_mac_address = set_mac_address; |
980 | dev->ethtool_ops = &at91ether_ethtool_ops; | 983 | dev->ethtool_ops = &at91ether_ethtool_ops; |
981 | dev->do_ioctl = at91ether_ioctl; | 984 | dev->do_ioctl = at91ether_ioctl; |
985 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
986 | dev->poll_controller = at91ether_poll_controller; | ||
987 | #endif | ||
982 | 988 | ||
983 | SET_NETDEV_DEV(dev, &pdev->dev); | 989 | SET_NETDEV_DEV(dev, &pdev->dev); |
984 | 990 | ||
@@ -1024,7 +1030,6 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add | |||
1024 | dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys); | 1030 | dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys); |
1025 | return res; | 1031 | return res; |
1026 | } | 1032 | } |
1027 | at91_dev = dev; | ||
1028 | 1033 | ||
1029 | /* Determine current link speed */ | 1034 | /* Determine current link speed */ |
1030 | spin_lock_irq(&lp->lock); | 1035 | spin_lock_irq(&lp->lock); |
@@ -1036,9 +1041,9 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add | |||
1036 | 1041 | ||
1037 | /* If board has no PHY IRQ, use a timer to poll the PHY */ | 1042 | /* If board has no PHY IRQ, use a timer to poll the PHY */ |
1038 | if (!lp->board_data.phy_irq_pin) { | 1043 | if (!lp->board_data.phy_irq_pin) { |
1039 | init_timer(&check_timer); | 1044 | init_timer(&lp->check_timer); |
1040 | check_timer.data = (unsigned long)dev; | 1045 | lp->check_timer.data = (unsigned long)dev; |
1041 | check_timer.function = at91ether_check_link; | 1046 | lp->check_timer.function = at91ether_check_link; |
1042 | } | 1047 | } |
1043 | 1048 | ||
1044 | /* Display ethernet banner */ | 1049 | /* Display ethernet banner */ |
@@ -1115,15 +1120,16 @@ static int __init at91ether_probe(struct platform_device *pdev) | |||
1115 | 1120 | ||
1116 | static int __devexit at91ether_remove(struct platform_device *pdev) | 1121 | static int __devexit at91ether_remove(struct platform_device *pdev) |
1117 | { | 1122 | { |
1118 | struct at91_private *lp = (struct at91_private *) at91_dev->priv; | 1123 | struct net_device *dev = platform_get_drvdata(pdev); |
1124 | struct at91_private *lp = netdev_priv(dev); | ||
1119 | 1125 | ||
1120 | unregister_netdev(at91_dev); | 1126 | unregister_netdev(dev); |
1121 | free_irq(at91_dev->irq, at91_dev); | 1127 | free_irq(dev->irq, dev); |
1122 | dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys); | 1128 | dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys); |
1123 | clk_put(lp->ether_clk); | 1129 | clk_put(lp->ether_clk); |
1124 | 1130 | ||
1125 | free_netdev(at91_dev); | 1131 | platform_set_drvdata(pdev, NULL); |
1126 | at91_dev = NULL; | 1132 | free_netdev(dev); |
1127 | return 0; | 1133 | return 0; |
1128 | } | 1134 | } |
1129 | 1135 | ||
@@ -1131,8 +1137,8 @@ static int __devexit at91ether_remove(struct platform_device *pdev) | |||
1131 | 1137 | ||
1132 | static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg) | 1138 | static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg) |
1133 | { | 1139 | { |
1134 | struct at91_private *lp = (struct at91_private *) at91_dev->priv; | ||
1135 | struct net_device *net_dev = platform_get_drvdata(pdev); | 1140 | struct net_device *net_dev = platform_get_drvdata(pdev); |
1141 | struct at91_private *lp = netdev_priv(net_dev); | ||
1136 | int phy_irq = lp->board_data.phy_irq_pin; | 1142 | int phy_irq = lp->board_data.phy_irq_pin; |
1137 | 1143 | ||
1138 | if (netif_running(net_dev)) { | 1144 | if (netif_running(net_dev)) { |
@@ -1149,8 +1155,8 @@ static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
1149 | 1155 | ||
1150 | static int at91ether_resume(struct platform_device *pdev) | 1156 | static int at91ether_resume(struct platform_device *pdev) |
1151 | { | 1157 | { |
1152 | struct at91_private *lp = (struct at91_private *) at91_dev->priv; | ||
1153 | struct net_device *net_dev = platform_get_drvdata(pdev); | 1158 | struct net_device *net_dev = platform_get_drvdata(pdev); |
1159 | struct at91_private *lp = netdev_priv(net_dev); | ||
1154 | int phy_irq = lp->board_data.phy_irq_pin; | 1160 | int phy_irq = lp->board_data.phy_irq_pin; |
1155 | 1161 | ||
1156 | if (netif_running(net_dev)) { | 1162 | if (netif_running(net_dev)) { |