aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bfin_mac.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/bfin_mac.c')
-rw-r--r--drivers/net/bfin_mac.c262
1 files changed, 153 insertions, 109 deletions
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index 012613fde3f4..6c019e148546 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -1,13 +1,18 @@
1/* 1/*
2 * Blackfin On-Chip MAC Driver 2 * Blackfin On-Chip MAC Driver
3 * 3 *
4 * Copyright 2004-2007 Analog Devices Inc. 4 * Copyright 2004-2010 Analog Devices Inc.
5 * 5 *
6 * Enter bugs at http://blackfin.uclinux.org/ 6 * Enter bugs at http://blackfin.uclinux.org/
7 * 7 *
8 * Licensed under the GPL-2 or later. 8 * Licensed under the GPL-2 or later.
9 */ 9 */
10 10
11#define DRV_VERSION "1.1"
12#define DRV_DESC "Blackfin on-chip Ethernet MAC driver"
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
11#include <linux/init.h> 16#include <linux/init.h>
12#include <linux/module.h> 17#include <linux/module.h>
13#include <linux/kernel.h> 18#include <linux/kernel.h>
@@ -23,7 +28,6 @@
23#include <linux/device.h> 28#include <linux/device.h>
24#include <linux/spinlock.h> 29#include <linux/spinlock.h>
25#include <linux/mii.h> 30#include <linux/mii.h>
26#include <linux/phy.h>
27#include <linux/netdevice.h> 31#include <linux/netdevice.h>
28#include <linux/etherdevice.h> 32#include <linux/etherdevice.h>
29#include <linux/ethtool.h> 33#include <linux/ethtool.h>
@@ -38,27 +42,23 @@
38#include <asm/blackfin.h> 42#include <asm/blackfin.h>
39#include <asm/cacheflush.h> 43#include <asm/cacheflush.h>
40#include <asm/portmux.h> 44#include <asm/portmux.h>
45#include <mach/pll.h>
41 46
42#include "bfin_mac.h" 47#include "bfin_mac.h"
43 48
44#define DRV_NAME "bfin_mac" 49MODULE_AUTHOR("Bryan Wu, Luke Yang");
45#define DRV_VERSION "1.1"
46#define DRV_AUTHOR "Bryan Wu, Luke Yang"
47#define DRV_DESC "Blackfin on-chip Ethernet MAC driver"
48
49MODULE_AUTHOR(DRV_AUTHOR);
50MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
51MODULE_DESCRIPTION(DRV_DESC); 51MODULE_DESCRIPTION(DRV_DESC);
52MODULE_ALIAS("platform:bfin_mac"); 52MODULE_ALIAS("platform:bfin_mac");
53 53
54#if defined(CONFIG_BFIN_MAC_USE_L1) 54#if defined(CONFIG_BFIN_MAC_USE_L1)
55# define bfin_mac_alloc(dma_handle, size) l1_data_sram_zalloc(size) 55# define bfin_mac_alloc(dma_handle, size, num) l1_data_sram_zalloc(size*num)
56# define bfin_mac_free(dma_handle, ptr) l1_data_sram_free(ptr) 56# define bfin_mac_free(dma_handle, ptr, num) l1_data_sram_free(ptr)
57#else 57#else
58# define bfin_mac_alloc(dma_handle, size) \ 58# define bfin_mac_alloc(dma_handle, size, num) \
59 dma_alloc_coherent(NULL, size, dma_handle, GFP_KERNEL) 59 dma_alloc_coherent(NULL, size*num, dma_handle, GFP_KERNEL)
60# define bfin_mac_free(dma_handle, ptr) \ 60# define bfin_mac_free(dma_handle, ptr, num) \
61 dma_free_coherent(NULL, sizeof(*ptr), ptr, dma_handle) 61 dma_free_coherent(NULL, sizeof(*ptr)*num, ptr, dma_handle)
62#endif 62#endif
63 63
64#define PKT_BUF_SZ 1580 64#define PKT_BUF_SZ 1580
@@ -75,12 +75,6 @@ static struct net_dma_desc_tx *current_tx_ptr;
75static struct net_dma_desc_tx *tx_desc; 75static struct net_dma_desc_tx *tx_desc;
76static struct net_dma_desc_rx *rx_desc; 76static struct net_dma_desc_rx *rx_desc;
77 77
78#if defined(CONFIG_BFIN_MAC_RMII)
79static u16 pin_req[] = P_RMII0;
80#else
81static u16 pin_req[] = P_MII0;
82#endif
83
84static void desc_list_free(void) 78static void desc_list_free(void)
85{ 79{
86 struct net_dma_desc_rx *r; 80 struct net_dma_desc_rx *r;
@@ -101,7 +95,7 @@ static void desc_list_free(void)
101 t = t->next; 95 t = t->next;
102 } 96 }
103 } 97 }
104 bfin_mac_free(dma_handle, tx_desc); 98 bfin_mac_free(dma_handle, tx_desc, CONFIG_BFIN_TX_DESC_NUM);
105 } 99 }
106 100
107 if (rx_desc) { 101 if (rx_desc) {
@@ -115,7 +109,7 @@ static void desc_list_free(void)
115 r = r->next; 109 r = r->next;
116 } 110 }
117 } 111 }
118 bfin_mac_free(dma_handle, rx_desc); 112 bfin_mac_free(dma_handle, rx_desc, CONFIG_BFIN_RX_DESC_NUM);
119 } 113 }
120} 114}
121 115
@@ -132,13 +126,13 @@ static int desc_list_init(void)
132#endif 126#endif
133 127
134 tx_desc = bfin_mac_alloc(&dma_handle, 128 tx_desc = bfin_mac_alloc(&dma_handle,
135 sizeof(struct net_dma_desc_tx) * 129 sizeof(struct net_dma_desc_tx),
136 CONFIG_BFIN_TX_DESC_NUM); 130 CONFIG_BFIN_TX_DESC_NUM);
137 if (tx_desc == NULL) 131 if (tx_desc == NULL)
138 goto init_error; 132 goto init_error;
139 133
140 rx_desc = bfin_mac_alloc(&dma_handle, 134 rx_desc = bfin_mac_alloc(&dma_handle,
141 sizeof(struct net_dma_desc_rx) * 135 sizeof(struct net_dma_desc_rx),
142 CONFIG_BFIN_RX_DESC_NUM); 136 CONFIG_BFIN_RX_DESC_NUM);
143 if (rx_desc == NULL) 137 if (rx_desc == NULL)
144 goto init_error; 138 goto init_error;
@@ -195,8 +189,7 @@ static int desc_list_init(void)
195 /* allocate a new skb for next time receive */ 189 /* allocate a new skb for next time receive */
196 new_skb = dev_alloc_skb(PKT_BUF_SZ + NET_IP_ALIGN); 190 new_skb = dev_alloc_skb(PKT_BUF_SZ + NET_IP_ALIGN);
197 if (!new_skb) { 191 if (!new_skb) {
198 printk(KERN_NOTICE DRV_NAME 192 pr_notice("init: low on mem - packet dropped\n");
199 ": init: low on mem - packet dropped\n");
200 goto init_error; 193 goto init_error;
201 } 194 }
202 skb_reserve(new_skb, NET_IP_ALIGN); 195 skb_reserve(new_skb, NET_IP_ALIGN);
@@ -246,7 +239,7 @@ static int desc_list_init(void)
246 239
247init_error: 240init_error:
248 desc_list_free(); 241 desc_list_free();
249 printk(KERN_ERR DRV_NAME ": kmalloc failed\n"); 242 pr_err("kmalloc failed\n");
250 return -ENOMEM; 243 return -ENOMEM;
251} 244}
252 245
@@ -265,8 +258,7 @@ static int bfin_mdio_poll(void)
265 while ((bfin_read_EMAC_STAADD()) & STABUSY) { 258 while ((bfin_read_EMAC_STAADD()) & STABUSY) {
266 udelay(1); 259 udelay(1);
267 if (timeout_cnt-- < 0) { 260 if (timeout_cnt-- < 0) {
268 printk(KERN_ERR DRV_NAME 261 pr_err("wait MDC/MDIO transaction to complete timeout\n");
269 ": wait MDC/MDIO transaction to complete timeout\n");
270 return -ETIMEDOUT; 262 return -ETIMEDOUT;
271 } 263 }
272 } 264 }
@@ -346,23 +338,23 @@ static void bfin_mac_adjust_link(struct net_device *dev)
346 } 338 }
347 339
348 if (phydev->speed != lp->old_speed) { 340 if (phydev->speed != lp->old_speed) {
349#if defined(CONFIG_BFIN_MAC_RMII) 341 if (phydev->interface == PHY_INTERFACE_MODE_RMII) {
350 u32 opmode = bfin_read_EMAC_OPMODE(); 342 u32 opmode = bfin_read_EMAC_OPMODE();
351 switch (phydev->speed) { 343 switch (phydev->speed) {
352 case 10: 344 case 10:
353 opmode |= RMII_10; 345 opmode |= RMII_10;
354 break; 346 break;
355 case 100: 347 case 100:
356 opmode &= ~(RMII_10); 348 opmode &= ~RMII_10;
357 break; 349 break;
358 default: 350 default:
359 printk(KERN_WARNING 351 netdev_warn(dev,
360 "%s: Ack! Speed (%d) is not 10/100!\n", 352 "Ack! Speed (%d) is not 10/100!\n",
361 DRV_NAME, phydev->speed); 353 phydev->speed);
362 break; 354 break;
355 }
356 bfin_write_EMAC_OPMODE(opmode);
363 } 357 }
364 bfin_write_EMAC_OPMODE(opmode);
365#endif
366 358
367 new_state = 1; 359 new_state = 1;
368 lp->old_speed = phydev->speed; 360 lp->old_speed = phydev->speed;
@@ -391,7 +383,7 @@ static void bfin_mac_adjust_link(struct net_device *dev)
391/* MDC = 2.5 MHz */ 383/* MDC = 2.5 MHz */
392#define MDC_CLK 2500000 384#define MDC_CLK 2500000
393 385
394static int mii_probe(struct net_device *dev) 386static int mii_probe(struct net_device *dev, int phy_mode)
395{ 387{
396 struct bfin_mac_local *lp = netdev_priv(dev); 388 struct bfin_mac_local *lp = netdev_priv(dev);
397 struct phy_device *phydev = NULL; 389 struct phy_device *phydev = NULL;
@@ -410,8 +402,8 @@ static int mii_probe(struct net_device *dev)
410 sysctl = (sysctl & ~MDCDIV) | SET_MDCDIV(mdc_div); 402 sysctl = (sysctl & ~MDCDIV) | SET_MDCDIV(mdc_div);
411 bfin_write_EMAC_SYSCTL(sysctl); 403 bfin_write_EMAC_SYSCTL(sysctl);
412 404
413 /* search for connect PHY device */ 405 /* search for connected PHY device */
414 for (i = 0; i < PHY_MAX_ADDR; i++) { 406 for (i = 0; i < PHY_MAX_ADDR; ++i) {
415 struct phy_device *const tmp_phydev = lp->mii_bus->phy_map[i]; 407 struct phy_device *const tmp_phydev = lp->mii_bus->phy_map[i];
416 408
417 if (!tmp_phydev) 409 if (!tmp_phydev)
@@ -423,21 +415,21 @@ static int mii_probe(struct net_device *dev)
423 415
424 /* now we are supposed to have a proper phydev, to attach to... */ 416 /* now we are supposed to have a proper phydev, to attach to... */
425 if (!phydev) { 417 if (!phydev) {
426 printk(KERN_INFO "%s: Don't found any phy device at all\n", 418 netdev_err(dev, "no phy device found\n");
427 dev->name);
428 return -ENODEV; 419 return -ENODEV;
429 } 420 }
430 421
431#if defined(CONFIG_BFIN_MAC_RMII) 422 if (phy_mode != PHY_INTERFACE_MODE_RMII &&
432 phydev = phy_connect(dev, dev_name(&phydev->dev), &bfin_mac_adjust_link, 423 phy_mode != PHY_INTERFACE_MODE_MII) {
433 0, PHY_INTERFACE_MODE_RMII); 424 netdev_err(dev, "invalid phy interface mode\n");
434#else 425 return -EINVAL;
426 }
427
435 phydev = phy_connect(dev, dev_name(&phydev->dev), &bfin_mac_adjust_link, 428 phydev = phy_connect(dev, dev_name(&phydev->dev), &bfin_mac_adjust_link,
436 0, PHY_INTERFACE_MODE_MII); 429 0, phy_mode);
437#endif
438 430
439 if (IS_ERR(phydev)) { 431 if (IS_ERR(phydev)) {
440 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); 432 netdev_err(dev, "could not attach PHY\n");
441 return PTR_ERR(phydev); 433 return PTR_ERR(phydev);
442 } 434 }
443 435
@@ -458,11 +450,10 @@ static int mii_probe(struct net_device *dev)
458 lp->old_duplex = -1; 450 lp->old_duplex = -1;
459 lp->phydev = phydev; 451 lp->phydev = phydev;
460 452
461 printk(KERN_INFO "%s: attached PHY driver [%s] " 453 pr_info("attached PHY driver [%s] "
462 "(mii_bus:phy_addr=%s, irq=%d, mdc_clk=%dHz(mdc_div=%d)" 454 "(mii_bus:phy_addr=%s, irq=%d, mdc_clk=%dHz(mdc_div=%d)@sclk=%dMHz)\n",
463 "@sclk=%dMHz)\n", 455 phydev->drv->name, dev_name(&phydev->dev), phydev->irq,
464 DRV_NAME, phydev->drv->name, dev_name(&phydev->dev), phydev->irq, 456 MDC_CLK, mdc_div, sclk/1000000);
465 MDC_CLK, mdc_div, sclk/1000000);
466 457
467 return 0; 458 return 0;
468} 459}
@@ -507,7 +498,7 @@ bfin_mac_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
507static void bfin_mac_ethtool_getdrvinfo(struct net_device *dev, 498static void bfin_mac_ethtool_getdrvinfo(struct net_device *dev,
508 struct ethtool_drvinfo *info) 499 struct ethtool_drvinfo *info)
509{ 500{
510 strcpy(info->driver, DRV_NAME); 501 strcpy(info->driver, KBUILD_MODNAME);
511 strcpy(info->version, DRV_VERSION); 502 strcpy(info->version, DRV_VERSION);
512 strcpy(info->fw_version, "N/A"); 503 strcpy(info->fw_version, "N/A");
513 strcpy(info->bus_info, dev_name(&dev->dev)); 504 strcpy(info->bus_info, dev_name(&dev->dev));
@@ -567,8 +558,10 @@ static const struct ethtool_ops bfin_mac_ethtool_ops = {
567}; 558};
568 559
569/**************************************************************************/ 560/**************************************************************************/
570void setup_system_regs(struct net_device *dev) 561static void setup_system_regs(struct net_device *dev)
571{ 562{
563 struct bfin_mac_local *lp = netdev_priv(dev);
564 int i;
572 unsigned short sysctl; 565 unsigned short sysctl;
573 566
574 /* 567 /*
@@ -576,6 +569,15 @@ void setup_system_regs(struct net_device *dev)
576 * Configure checksum support and rcve frame word alignment 569 * Configure checksum support and rcve frame word alignment
577 */ 570 */
578 sysctl = bfin_read_EMAC_SYSCTL(); 571 sysctl = bfin_read_EMAC_SYSCTL();
572 /*
573 * check if interrupt is requested for any PHY,
574 * enable PHY interrupt only if needed
575 */
576 for (i = 0; i < PHY_MAX_ADDR; ++i)
577 if (lp->mii_bus->irq[i] != PHY_POLL)
578 break;
579 if (i < PHY_MAX_ADDR)
580 sysctl |= PHYIE;
579 sysctl |= RXDWA; 581 sysctl |= RXDWA;
580#if defined(BFIN_MAC_CSUM_OFFLOAD) 582#if defined(BFIN_MAC_CSUM_OFFLOAD)
581 sysctl |= RXCKS; 583 sysctl |= RXCKS;
@@ -586,6 +588,10 @@ void setup_system_regs(struct net_device *dev)
586 588
587 bfin_write_EMAC_MMC_CTL(RSTC | CROLL); 589 bfin_write_EMAC_MMC_CTL(RSTC | CROLL);
588 590
591 /* Set vlan regs to let 1522 bytes long packets pass through */
592 bfin_write_EMAC_VLAN1(lp->vlan1_mask);
593 bfin_write_EMAC_VLAN2(lp->vlan2_mask);
594
589 /* Initialize the TX DMA channel registers */ 595 /* Initialize the TX DMA channel registers */
590 bfin_write_DMA2_X_COUNT(0); 596 bfin_write_DMA2_X_COUNT(0);
591 bfin_write_DMA2_X_MODIFY(4); 597 bfin_write_DMA2_X_MODIFY(4);
@@ -803,15 +809,14 @@ static void bfin_dump_hwtamp(char *s, ktime_t *hw, ktime_t *ts, struct timecompa
803static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) 809static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
804{ 810{
805 struct bfin_mac_local *lp = netdev_priv(netdev); 811 struct bfin_mac_local *lp = netdev_priv(netdev);
806 union skb_shared_tx *shtx = skb_tx(skb);
807 812
808 if (shtx->hardware) { 813 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) {
809 int timeout_cnt = MAX_TIMEOUT_CNT; 814 int timeout_cnt = MAX_TIMEOUT_CNT;
810 815
811 /* When doing time stamping, keep the connection to the socket 816 /* When doing time stamping, keep the connection to the socket
812 * a while longer 817 * a while longer
813 */ 818 */
814 shtx->in_progress = 1; 819 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
815 820
816 /* 821 /*
817 * The timestamping is done at the EMAC module's MII/RMII interface 822 * The timestamping is done at the EMAC module's MII/RMII interface
@@ -822,8 +827,7 @@ static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
822 while ((!(bfin_read_EMAC_PTP_ISTAT() & TXTL)) && (--timeout_cnt)) 827 while ((!(bfin_read_EMAC_PTP_ISTAT() & TXTL)) && (--timeout_cnt))
823 udelay(1); 828 udelay(1);
824 if (timeout_cnt == 0) 829 if (timeout_cnt == 0)
825 printk(KERN_ERR DRV_NAME 830 netdev_err(netdev, "timestamp the TX packet failed\n");
826 ": fails to timestamp the TX packet\n");
827 else { 831 else {
828 struct skb_shared_hwtstamps shhwtstamps; 832 struct skb_shared_hwtstamps shhwtstamps;
829 u64 ns; 833 u64 ns;
@@ -991,7 +995,6 @@ static int bfin_mac_hard_start_xmit(struct sk_buff *skb,
991 struct bfin_mac_local *lp = netdev_priv(dev); 995 struct bfin_mac_local *lp = netdev_priv(dev);
992 u16 *data; 996 u16 *data;
993 u32 data_align = (unsigned long)(skb->data) & 0x3; 997 u32 data_align = (unsigned long)(skb->data) & 0x3;
994 union skb_shared_tx *shtx = skb_tx(skb);
995 998
996 current_tx_ptr->skb = skb; 999 current_tx_ptr->skb = skb;
997 1000
@@ -1005,7 +1008,7 @@ static int bfin_mac_hard_start_xmit(struct sk_buff *skb,
1005 * of this field are the length of the packet payload in bytes and the higher 1008 * of this field are the length of the packet payload in bytes and the higher
1006 * 4 bits are the timestamping enable field. 1009 * 4 bits are the timestamping enable field.
1007 */ 1010 */
1008 if (shtx->hardware) 1011 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
1009 *data |= 0x1000; 1012 *data |= 0x1000;
1010 1013
1011 current_tx_ptr->desc_a.start_addr = (u32)data; 1014 current_tx_ptr->desc_a.start_addr = (u32)data;
@@ -1015,7 +1018,7 @@ static int bfin_mac_hard_start_xmit(struct sk_buff *skb,
1015 } else { 1018 } else {
1016 *((u16 *)(current_tx_ptr->packet)) = (u16)(skb->len); 1019 *((u16 *)(current_tx_ptr->packet)) = (u16)(skb->len);
1017 /* enable timestamping for the sent packet */ 1020 /* enable timestamping for the sent packet */
1018 if (shtx->hardware) 1021 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
1019 *((u16 *)(current_tx_ptr->packet)) |= 0x1000; 1022 *((u16 *)(current_tx_ptr->packet)) |= 0x1000;
1020 memcpy((u8 *)(current_tx_ptr->packet + 2), skb->data, 1023 memcpy((u8 *)(current_tx_ptr->packet + 2), skb->data,
1021 skb->len); 1024 skb->len);
@@ -1079,8 +1082,7 @@ static void bfin_mac_rx(struct net_device *dev)
1079 * we which case we simply drop the packet 1082 * we which case we simply drop the packet
1080 */ 1083 */
1081 if (current_rx_ptr->status.status_word & RX_ERROR_MASK) { 1084 if (current_rx_ptr->status.status_word & RX_ERROR_MASK) {
1082 printk(KERN_NOTICE DRV_NAME 1085 netdev_notice(dev, "rx: receive error - packet dropped\n");
1083 ": rx: receive error - packet dropped\n");
1084 dev->stats.rx_dropped++; 1086 dev->stats.rx_dropped++;
1085 goto out; 1087 goto out;
1086 } 1088 }
@@ -1090,8 +1092,7 @@ static void bfin_mac_rx(struct net_device *dev)
1090 1092
1091 new_skb = dev_alloc_skb(PKT_BUF_SZ + NET_IP_ALIGN); 1093 new_skb = dev_alloc_skb(PKT_BUF_SZ + NET_IP_ALIGN);
1092 if (!new_skb) { 1094 if (!new_skb) {
1093 printk(KERN_NOTICE DRV_NAME 1095 netdev_notice(dev, "rx: low on mem - packet dropped\n");
1094 ": rx: low on mem - packet dropped\n");
1095 dev->stats.rx_dropped++; 1096 dev->stats.rx_dropped++;
1096 goto out; 1097 goto out;
1097 } 1098 }
@@ -1204,12 +1205,12 @@ static void bfin_mac_disable(void)
1204/* 1205/*
1205 * Enable Interrupts, Receive, and Transmit 1206 * Enable Interrupts, Receive, and Transmit
1206 */ 1207 */
1207static int bfin_mac_enable(void) 1208static int bfin_mac_enable(struct phy_device *phydev)
1208{ 1209{
1209 int ret; 1210 int ret;
1210 u32 opmode; 1211 u32 opmode;
1211 1212
1212 pr_debug("%s: %s\n", DRV_NAME, __func__); 1213 pr_debug("%s\n", __func__);
1213 1214
1214 /* Set RX DMA */ 1215 /* Set RX DMA */
1215 bfin_write_DMA1_NEXT_DESC_PTR(&(rx_list_head->desc_a)); 1216 bfin_write_DMA1_NEXT_DESC_PTR(&(rx_list_head->desc_a));
@@ -1234,12 +1235,22 @@ static int bfin_mac_enable(void)
1234 opmode |= DRO | DC | PSF; 1235 opmode |= DRO | DC | PSF;
1235 opmode |= RE; 1236 opmode |= RE;
1236 1237
1237#if defined(CONFIG_BFIN_MAC_RMII) 1238 if (phydev->interface == PHY_INTERFACE_MODE_RMII) {
1238 opmode |= RMII; /* For Now only 100MBit are supported */ 1239 opmode |= RMII; /* For Now only 100MBit are supported */
1239#if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) && CONFIG_BF_REV_0_2 1240#if defined(CONFIG_BF537) || defined(CONFIG_BF536)
1240 opmode |= TE; 1241 if (__SILICON_REVISION__ < 3) {
1241#endif 1242 /*
1243 * This isn't publicly documented (fun times!), but in
1244 * silicon <=0.2, the RX and TX pins are clocked together.
1245 * So in order to recv, we must enable the transmit side
1246 * as well. This will cause a spurious TX interrupt too,
1247 * but we can easily consume that.
1248 */
1249 opmode |= TE;
1250 }
1242#endif 1251#endif
1252 }
1253
1243 /* Turn on the EMAC rx */ 1254 /* Turn on the EMAC rx */
1244 bfin_write_EMAC_OPMODE(opmode); 1255 bfin_write_EMAC_OPMODE(opmode);
1245 1256
@@ -1271,7 +1282,7 @@ static void bfin_mac_timeout(struct net_device *dev)
1271 if (netif_queue_stopped(lp->ndev)) 1282 if (netif_queue_stopped(lp->ndev))
1272 netif_wake_queue(lp->ndev); 1283 netif_wake_queue(lp->ndev);
1273 1284
1274 bfin_mac_enable(); 1285 bfin_mac_enable(lp->phydev);
1275 1286
1276 /* We can accept TX packets again */ 1287 /* We can accept TX packets again */
1277 dev->trans_start = jiffies; /* prevent tx timeout */ 1288 dev->trans_start = jiffies; /* prevent tx timeout */
@@ -1282,19 +1293,12 @@ static void bfin_mac_multicast_hash(struct net_device *dev)
1282{ 1293{
1283 u32 emac_hashhi, emac_hashlo; 1294 u32 emac_hashhi, emac_hashlo;
1284 struct netdev_hw_addr *ha; 1295 struct netdev_hw_addr *ha;
1285 char *addrs;
1286 u32 crc; 1296 u32 crc;
1287 1297
1288 emac_hashhi = emac_hashlo = 0; 1298 emac_hashhi = emac_hashlo = 0;
1289 1299
1290 netdev_for_each_mc_addr(ha, dev) { 1300 netdev_for_each_mc_addr(ha, dev) {
1291 addrs = ha->addr; 1301 crc = ether_crc(ETH_ALEN, ha->addr);
1292
1293 /* skip non-multicast addresses */
1294 if (!(*addrs & 1))
1295 continue;
1296
1297 crc = ether_crc(ETH_ALEN, addrs);
1298 crc >>= 26; 1302 crc >>= 26;
1299 1303
1300 if (crc & 0x20) 1304 if (crc & 0x20)
@@ -1318,7 +1322,7 @@ static void bfin_mac_set_multicast_list(struct net_device *dev)
1318 u32 sysctl; 1322 u32 sysctl;
1319 1323
1320 if (dev->flags & IFF_PROMISC) { 1324 if (dev->flags & IFF_PROMISC) {
1321 printk(KERN_INFO "%s: set to promisc mode\n", dev->name); 1325 netdev_info(dev, "set promisc mode\n");
1322 sysctl = bfin_read_EMAC_OPMODE(); 1326 sysctl = bfin_read_EMAC_OPMODE();
1323 sysctl |= PR; 1327 sysctl |= PR;
1324 bfin_write_EMAC_OPMODE(sysctl); 1328 bfin_write_EMAC_OPMODE(sysctl);
@@ -1343,11 +1347,19 @@ static void bfin_mac_set_multicast_list(struct net_device *dev)
1343 1347
1344static int bfin_mac_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) 1348static int bfin_mac_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1345{ 1349{
1350 struct bfin_mac_local *lp = netdev_priv(netdev);
1351
1352 if (!netif_running(netdev))
1353 return -EINVAL;
1354
1346 switch (cmd) { 1355 switch (cmd) {
1347 case SIOCSHWTSTAMP: 1356 case SIOCSHWTSTAMP:
1348 return bfin_mac_hwtstamp_ioctl(netdev, ifr, cmd); 1357 return bfin_mac_hwtstamp_ioctl(netdev, ifr, cmd);
1349 default: 1358 default:
1350 return -EOPNOTSUPP; 1359 if (lp->phydev)
1360 return phy_mii_ioctl(lp->phydev, ifr, cmd);
1361 else
1362 return -EOPNOTSUPP;
1351 } 1363 }
1352} 1364}
1353 1365
@@ -1380,7 +1392,7 @@ static int bfin_mac_open(struct net_device *dev)
1380 * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx 1392 * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
1381 */ 1393 */
1382 if (!is_valid_ether_addr(dev->dev_addr)) { 1394 if (!is_valid_ether_addr(dev->dev_addr)) {
1383 printk(KERN_WARNING DRV_NAME ": no valid ethernet hw addr\n"); 1395 netdev_warn(dev, "no valid ethernet hw addr\n");
1384 return -EINVAL; 1396 return -EINVAL;
1385 } 1397 }
1386 1398
@@ -1395,7 +1407,7 @@ static int bfin_mac_open(struct net_device *dev)
1395 setup_mac_addr(dev->dev_addr); 1407 setup_mac_addr(dev->dev_addr);
1396 1408
1397 bfin_mac_disable(); 1409 bfin_mac_disable();
1398 ret = bfin_mac_enable(); 1410 ret = bfin_mac_enable(lp->phydev);
1399 if (ret) 1411 if (ret)
1400 return ret; 1412 return ret;
1401 pr_debug("hardware init finished\n"); 1413 pr_debug("hardware init finished\n");
@@ -1451,6 +1463,7 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev)
1451 struct net_device *ndev; 1463 struct net_device *ndev;
1452 struct bfin_mac_local *lp; 1464 struct bfin_mac_local *lp;
1453 struct platform_device *pd; 1465 struct platform_device *pd;
1466 struct bfin_mii_bus_platform_data *mii_bus_data;
1454 int rc; 1467 int rc;
1455 1468
1456 ndev = alloc_etherdev(sizeof(struct bfin_mac_local)); 1469 ndev = alloc_etherdev(sizeof(struct bfin_mac_local));
@@ -1502,16 +1515,20 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev)
1502 if (!lp->mii_bus) { 1515 if (!lp->mii_bus) {
1503 dev_err(&pdev->dev, "Cannot get mii_bus!\n"); 1516 dev_err(&pdev->dev, "Cannot get mii_bus!\n");
1504 rc = -ENODEV; 1517 rc = -ENODEV;
1505 goto out_err_mii_bus_probe; 1518 goto out_err_probe_mac;
1506 } 1519 }
1507 lp->mii_bus->priv = ndev; 1520 lp->mii_bus->priv = ndev;
1521 mii_bus_data = pd->dev.platform_data;
1508 1522
1509 rc = mii_probe(ndev); 1523 rc = mii_probe(ndev, mii_bus_data->phy_mode);
1510 if (rc) { 1524 if (rc) {
1511 dev_err(&pdev->dev, "MII Probe failed!\n"); 1525 dev_err(&pdev->dev, "MII Probe failed!\n");
1512 goto out_err_mii_probe; 1526 goto out_err_mii_probe;
1513 } 1527 }
1514 1528
1529 lp->vlan1_mask = ETH_P_8021Q | mii_bus_data->vlan1_mask;
1530 lp->vlan2_mask = ETH_P_8021Q | mii_bus_data->vlan2_mask;
1531
1515 /* Fill in the fields of the device structure with ethernet values. */ 1532 /* Fill in the fields of the device structure with ethernet values. */
1516 ether_setup(ndev); 1533 ether_setup(ndev);
1517 1534
@@ -1543,7 +1560,7 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev)
1543 bfin_mac_hwtstamp_init(ndev); 1560 bfin_mac_hwtstamp_init(ndev);
1544 1561
1545 /* now, print out the card info, in a short format.. */ 1562 /* now, print out the card info, in a short format.. */
1546 dev_info(&pdev->dev, "%s, Version %s\n", DRV_DESC, DRV_VERSION); 1563 netdev_info(ndev, "%s, Version %s\n", DRV_DESC, DRV_VERSION);
1547 1564
1548 return 0; 1565 return 0;
1549 1566
@@ -1553,8 +1570,6 @@ out_err_request_irq:
1553out_err_mii_probe: 1570out_err_mii_probe:
1554 mdiobus_unregister(lp->mii_bus); 1571 mdiobus_unregister(lp->mii_bus);
1555 mdiobus_free(lp->mii_bus); 1572 mdiobus_free(lp->mii_bus);
1556out_err_mii_bus_probe:
1557 peripheral_free_list(pin_req);
1558out_err_probe_mac: 1573out_err_probe_mac:
1559 platform_set_drvdata(pdev, NULL); 1574 platform_set_drvdata(pdev, NULL);
1560 free_netdev(ndev); 1575 free_netdev(ndev);
@@ -1577,8 +1592,6 @@ static int __devexit bfin_mac_remove(struct platform_device *pdev)
1577 1592
1578 free_netdev(ndev); 1593 free_netdev(ndev);
1579 1594
1580 peripheral_free_list(pin_req);
1581
1582 return 0; 1595 return 0;
1583} 1596}
1584 1597
@@ -1624,13 +1637,22 @@ static int bfin_mac_resume(struct platform_device *pdev)
1624static int __devinit bfin_mii_bus_probe(struct platform_device *pdev) 1637static int __devinit bfin_mii_bus_probe(struct platform_device *pdev)
1625{ 1638{
1626 struct mii_bus *miibus; 1639 struct mii_bus *miibus;
1640 struct bfin_mii_bus_platform_data *mii_bus_pd;
1641 const unsigned short *pin_req;
1627 int rc, i; 1642 int rc, i;
1628 1643
1644 mii_bus_pd = dev_get_platdata(&pdev->dev);
1645 if (!mii_bus_pd) {
1646 dev_err(&pdev->dev, "No peripherals in platform data!\n");
1647 return -EINVAL;
1648 }
1649
1629 /* 1650 /*
1630 * We are setting up a network card, 1651 * We are setting up a network card,
1631 * so set the GPIO pins to Ethernet mode 1652 * so set the GPIO pins to Ethernet mode
1632 */ 1653 */
1633 rc = peripheral_request_list(pin_req, DRV_NAME); 1654 pin_req = mii_bus_pd->mac_peripherals;
1655 rc = peripheral_request_list(pin_req, KBUILD_MODNAME);
1634 if (rc) { 1656 if (rc) {
1635 dev_err(&pdev->dev, "Requesting peripherals failed!\n"); 1657 dev_err(&pdev->dev, "Requesting peripherals failed!\n");
1636 return rc; 1658 return rc;
@@ -1646,13 +1668,30 @@ static int __devinit bfin_mii_bus_probe(struct platform_device *pdev)
1646 1668
1647 miibus->parent = &pdev->dev; 1669 miibus->parent = &pdev->dev;
1648 miibus->name = "bfin_mii_bus"; 1670 miibus->name = "bfin_mii_bus";
1671 miibus->phy_mask = mii_bus_pd->phy_mask;
1672
1649 snprintf(miibus->id, MII_BUS_ID_SIZE, "0"); 1673 snprintf(miibus->id, MII_BUS_ID_SIZE, "0");
1650 miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 1674 miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
1651 if (miibus->irq == NULL) 1675 if (!miibus->irq)
1652 goto out_err_alloc; 1676 goto out_err_irq_alloc;
1653 for (i = 0; i < PHY_MAX_ADDR; ++i) 1677
1678 for (i = rc; i < PHY_MAX_ADDR; ++i)
1654 miibus->irq[i] = PHY_POLL; 1679 miibus->irq[i] = PHY_POLL;
1655 1680
1681 rc = clamp(mii_bus_pd->phydev_number, 0, PHY_MAX_ADDR);
1682 if (rc != mii_bus_pd->phydev_number)
1683 dev_err(&pdev->dev, "Invalid number (%i) of phydevs\n",
1684 mii_bus_pd->phydev_number);
1685 for (i = 0; i < rc; ++i) {
1686 unsigned short phyaddr = mii_bus_pd->phydev_data[i].addr;
1687 if (phyaddr < PHY_MAX_ADDR)
1688 miibus->irq[phyaddr] = mii_bus_pd->phydev_data[i].irq;
1689 else
1690 dev_err(&pdev->dev,
1691 "Invalid PHY address %i for phydev %i\n",
1692 phyaddr, i);
1693 }
1694
1656 rc = mdiobus_register(miibus); 1695 rc = mdiobus_register(miibus);
1657 if (rc) { 1696 if (rc) {
1658 dev_err(&pdev->dev, "Cannot register MDIO bus!\n"); 1697 dev_err(&pdev->dev, "Cannot register MDIO bus!\n");
@@ -1664,6 +1703,7 @@ static int __devinit bfin_mii_bus_probe(struct platform_device *pdev)
1664 1703
1665out_err_mdiobus_register: 1704out_err_mdiobus_register:
1666 kfree(miibus->irq); 1705 kfree(miibus->irq);
1706out_err_irq_alloc:
1667 mdiobus_free(miibus); 1707 mdiobus_free(miibus);
1668out_err_alloc: 1708out_err_alloc:
1669 peripheral_free_list(pin_req); 1709 peripheral_free_list(pin_req);
@@ -1674,11 +1714,15 @@ out_err_alloc:
1674static int __devexit bfin_mii_bus_remove(struct platform_device *pdev) 1714static int __devexit bfin_mii_bus_remove(struct platform_device *pdev)
1675{ 1715{
1676 struct mii_bus *miibus = platform_get_drvdata(pdev); 1716 struct mii_bus *miibus = platform_get_drvdata(pdev);
1717 struct bfin_mii_bus_platform_data *mii_bus_pd =
1718 dev_get_platdata(&pdev->dev);
1719
1677 platform_set_drvdata(pdev, NULL); 1720 platform_set_drvdata(pdev, NULL);
1678 mdiobus_unregister(miibus); 1721 mdiobus_unregister(miibus);
1679 kfree(miibus->irq); 1722 kfree(miibus->irq);
1680 mdiobus_free(miibus); 1723 mdiobus_free(miibus);
1681 peripheral_free_list(pin_req); 1724 peripheral_free_list(mii_bus_pd->mac_peripherals);
1725
1682 return 0; 1726 return 0;
1683} 1727}
1684 1728
@@ -1697,7 +1741,7 @@ static struct platform_driver bfin_mac_driver = {
1697 .resume = bfin_mac_resume, 1741 .resume = bfin_mac_resume,
1698 .suspend = bfin_mac_suspend, 1742 .suspend = bfin_mac_suspend,
1699 .driver = { 1743 .driver = {
1700 .name = DRV_NAME, 1744 .name = KBUILD_MODNAME,
1701 .owner = THIS_MODULE, 1745 .owner = THIS_MODULE,
1702 }, 1746 },
1703}; 1747};