aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-02-15 15:08:24 -0500
committerDavid S. Miller <davem@davemloft.net>2011-02-15 15:08:24 -0500
commit29e1846a6ba84e0c6e257dd5b1231ed53b98fe9b (patch)
treeedbfe4cc95193e62337a385ad42b3a4c3ab6829f
parentf39925dbde7788cfb96419c0f092b086aa325c0f (diff)
parentcd1f402c18cf31b38bb304bc0c320669762ac50b (diff)
Merge branch 'fec' of git://git.pengutronix.de/git/ukl/linux-2.6
-rw-r--r--drivers/net/Kconfig3
-rw-r--r--drivers/net/fec.c650
2 files changed, 328 insertions, 325 deletions
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 03823327db25..65027a72ca93 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -1944,7 +1944,8 @@ config 68360_ENET
1944config FEC 1944config FEC
1945 bool "FEC ethernet controller (of ColdFire and some i.MX CPUs)" 1945 bool "FEC ethernet controller (of ColdFire and some i.MX CPUs)"
1946 depends on M523x || M527x || M5272 || M528x || M520x || M532x || \ 1946 depends on M523x || M527x || M5272 || M528x || M520x || M532x || \
1947 MACH_MX27 || ARCH_MX35 || ARCH_MX25 || ARCH_MX5 || SOC_IMX28 1947 IMX_HAVE_PLATFORM_FEC || MXS_HAVE_PLATFORM_FEC
1948 default IMX_HAVE_PLATFORM_FEC || MXS_HAVE_PLATFORM_FEC if ARM
1948 select PHYLIB 1949 select PHYLIB
1949 help 1950 help
1950 Say Y here if you want to use the built-in 10/100 Fast ethernet 1951 Say Y here if you want to use the built-in 10/100 Fast ethernet
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 2a71373719ae..74798bee672e 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -54,7 +54,7 @@
54 54
55#include "fec.h" 55#include "fec.h"
56 56
57#if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28) 57#if defined(CONFIG_ARM)
58#define FEC_ALIGNMENT 0xf 58#define FEC_ALIGNMENT 0xf
59#else 59#else
60#define FEC_ALIGNMENT 0x3 60#define FEC_ALIGNMENT 0x3
@@ -147,8 +147,7 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
147 * account when setting it. 147 * account when setting it.
148 */ 148 */
149#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \ 149#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
150 defined(CONFIG_M520x) || defined(CONFIG_M532x) || \ 150 defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM)
151 defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
152#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16) 151#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
153#else 152#else
154#define OPT_FRAME_SIZE 0 153#define OPT_FRAME_SIZE 0
@@ -183,7 +182,7 @@ struct fec_enet_private {
183 struct bufdesc *rx_bd_base; 182 struct bufdesc *rx_bd_base;
184 struct bufdesc *tx_bd_base; 183 struct bufdesc *tx_bd_base;
185 /* The next free ring entry */ 184 /* The next free ring entry */
186 struct bufdesc *cur_rx, *cur_tx; 185 struct bufdesc *cur_rx, *cur_tx;
187 /* The ring entries to be free()ed */ 186 /* The ring entries to be free()ed */
188 struct bufdesc *dirty_tx; 187 struct bufdesc *dirty_tx;
189 188
@@ -191,28 +190,21 @@ struct fec_enet_private {
191 /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */ 190 /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
192 spinlock_t hw_lock; 191 spinlock_t hw_lock;
193 192
194 struct platform_device *pdev; 193 struct platform_device *pdev;
195 194
196 int opened; 195 int opened;
197 196
198 /* Phylib and MDIO interface */ 197 /* Phylib and MDIO interface */
199 struct mii_bus *mii_bus; 198 struct mii_bus *mii_bus;
200 struct phy_device *phy_dev; 199 struct phy_device *phy_dev;
201 int mii_timeout; 200 int mii_timeout;
202 uint phy_speed; 201 uint phy_speed;
203 phy_interface_t phy_interface; 202 phy_interface_t phy_interface;
204 int link; 203 int link;
205 int full_duplex; 204 int full_duplex;
206 struct completion mdio_done; 205 struct completion mdio_done;
207}; 206};
208 207
209static irqreturn_t fec_enet_interrupt(int irq, void * dev_id);
210static void fec_enet_tx(struct net_device *dev);
211static void fec_enet_rx(struct net_device *dev);
212static int fec_enet_close(struct net_device *dev);
213static void fec_restart(struct net_device *dev, int duplex);
214static void fec_stop(struct net_device *dev);
215
216/* FEC MII MMFR bits definition */ 208/* FEC MII MMFR bits definition */
217#define FEC_MMFR_ST (1 << 30) 209#define FEC_MMFR_ST (1 << 30)
218#define FEC_MMFR_OP_READ (2 << 28) 210#define FEC_MMFR_OP_READ (2 << 28)
@@ -239,9 +231,9 @@ static void *swap_buffer(void *bufaddr, int len)
239} 231}
240 232
241static netdev_tx_t 233static netdev_tx_t
242fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) 234fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
243{ 235{
244 struct fec_enet_private *fep = netdev_priv(dev); 236 struct fec_enet_private *fep = netdev_priv(ndev);
245 const struct platform_device_id *id_entry = 237 const struct platform_device_id *id_entry =
246 platform_get_device_id(fep->pdev); 238 platform_get_device_id(fep->pdev);
247 struct bufdesc *bdp; 239 struct bufdesc *bdp;
@@ -262,9 +254,9 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
262 254
263 if (status & BD_ENET_TX_READY) { 255 if (status & BD_ENET_TX_READY) {
264 /* Ooops. All transmit buffers are full. Bail out. 256 /* Ooops. All transmit buffers are full. Bail out.
265 * This should not happen, since dev->tbusy should be set. 257 * This should not happen, since ndev->tbusy should be set.
266 */ 258 */
267 printk("%s: tx queue full!.\n", dev->name); 259 printk("%s: tx queue full!.\n", ndev->name);
268 spin_unlock_irqrestore(&fep->hw_lock, flags); 260 spin_unlock_irqrestore(&fep->hw_lock, flags);
269 return NETDEV_TX_BUSY; 261 return NETDEV_TX_BUSY;
270 } 262 }
@@ -284,7 +276,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
284 if (((unsigned long) bufaddr) & FEC_ALIGNMENT) { 276 if (((unsigned long) bufaddr) & FEC_ALIGNMENT) {
285 unsigned int index; 277 unsigned int index;
286 index = bdp - fep->tx_bd_base; 278 index = bdp - fep->tx_bd_base;
287 memcpy(fep->tx_bounce[index], (void *)skb->data, skb->len); 279 memcpy(fep->tx_bounce[index], skb->data, skb->len);
288 bufaddr = fep->tx_bounce[index]; 280 bufaddr = fep->tx_bounce[index];
289 } 281 }
290 282
@@ -299,13 +291,13 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
299 /* Save skb pointer */ 291 /* Save skb pointer */
300 fep->tx_skbuff[fep->skb_cur] = skb; 292 fep->tx_skbuff[fep->skb_cur] = skb;
301 293
302 dev->stats.tx_bytes += skb->len; 294 ndev->stats.tx_bytes += skb->len;
303 fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK; 295 fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
304 296
305 /* Push the data cache so the CPM does not get stale memory 297 /* Push the data cache so the CPM does not get stale memory
306 * data. 298 * data.
307 */ 299 */
308 bdp->cbd_bufaddr = dma_map_single(&dev->dev, bufaddr, 300 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
309 FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); 301 FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
310 302
311 /* Send it on its way. Tell FEC it's ready, interrupt when done, 303 /* Send it on its way. Tell FEC it's ready, interrupt when done,
@@ -326,7 +318,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
326 318
327 if (bdp == fep->dirty_tx) { 319 if (bdp == fep->dirty_tx) {
328 fep->tx_full = 1; 320 fep->tx_full = 1;
329 netif_stop_queue(dev); 321 netif_stop_queue(ndev);
330 } 322 }
331 323
332 fep->cur_tx = bdp; 324 fep->cur_tx = bdp;
@@ -336,62 +328,170 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
336 return NETDEV_TX_OK; 328 return NETDEV_TX_OK;
337} 329}
338 330
331/* This function is called to start or restart the FEC during a link
332 * change. This only happens when switching between half and full
333 * duplex.
334 */
339static void 335static void
340fec_timeout(struct net_device *dev) 336fec_restart(struct net_device *ndev, int duplex)
341{ 337{
342 struct fec_enet_private *fep = netdev_priv(dev); 338 struct fec_enet_private *fep = netdev_priv(ndev);
339 const struct platform_device_id *id_entry =
340 platform_get_device_id(fep->pdev);
341 int i;
342 u32 temp_mac[2];
343 u32 rcntl = OPT_FRAME_SIZE | 0x04;
343 344
344 dev->stats.tx_errors++; 345 /* Whack a reset. We should wait for this. */
346 writel(1, fep->hwp + FEC_ECNTRL);
347 udelay(10);
345 348
346 fec_restart(dev, fep->full_duplex); 349 /*
347 netif_wake_queue(dev); 350 * enet-mac reset will reset mac address registers too,
348} 351 * so need to reconfigure it.
352 */
353 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
354 memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN);
355 writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
356 writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
357 }
349 358
350static irqreturn_t 359 /* Clear any outstanding interrupt. */
351fec_enet_interrupt(int irq, void * dev_id) 360 writel(0xffc00000, fep->hwp + FEC_IEVENT);
352{
353 struct net_device *dev = dev_id;
354 struct fec_enet_private *fep = netdev_priv(dev);
355 uint int_events;
356 irqreturn_t ret = IRQ_NONE;
357 361
358 do { 362 /* Reset all multicast. */
359 int_events = readl(fep->hwp + FEC_IEVENT); 363 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
360 writel(int_events, fep->hwp + FEC_IEVENT); 364 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
365#ifndef CONFIG_M5272
366 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
367 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
368#endif
361 369
362 if (int_events & FEC_ENET_RXF) { 370 /* Set maximum receive buffer size. */
363 ret = IRQ_HANDLED; 371 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
364 fec_enet_rx(dev);
365 }
366 372
367 /* Transmit OK, or non-fatal error. Update the buffer 373 /* Set receive and transmit descriptor base. */
368 * descriptors. FEC handles all errors, we just discover 374 writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
369 * them as part of the transmit process. 375 writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE,
370 */ 376 fep->hwp + FEC_X_DES_START);
371 if (int_events & FEC_ENET_TXF) { 377
372 ret = IRQ_HANDLED; 378 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
373 fec_enet_tx(dev); 379 fep->cur_rx = fep->rx_bd_base;
380
381 /* Reset SKB transmit buffers. */
382 fep->skb_cur = fep->skb_dirty = 0;
383 for (i = 0; i <= TX_RING_MOD_MASK; i++) {
384 if (fep->tx_skbuff[i]) {
385 dev_kfree_skb_any(fep->tx_skbuff[i]);
386 fep->tx_skbuff[i] = NULL;
374 } 387 }
388 }
375 389
376 if (int_events & FEC_ENET_MII) { 390 /* Enable MII mode */
377 ret = IRQ_HANDLED; 391 if (duplex) {
378 complete(&fep->mdio_done); 392 /* FD enable */
393 writel(0x04, fep->hwp + FEC_X_CNTRL);
394 } else {
395 /* No Rcv on Xmit */
396 rcntl |= 0x02;
397 writel(0x0, fep->hwp + FEC_X_CNTRL);
398 }
399
400 fep->full_duplex = duplex;
401
402 /* Set MII speed */
403 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
404
405 /*
406 * The phy interface and speed need to get configured
407 * differently on enet-mac.
408 */
409 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
410 /* Enable flow control and length check */
411 rcntl |= 0x40000000 | 0x00000020;
412
413 /* MII or RMII */
414 if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
415 rcntl |= (1 << 8);
416 else
417 rcntl &= ~(1 << 8);
418
419 /* 10M or 100M */
420 if (fep->phy_dev && fep->phy_dev->speed == SPEED_100)
421 rcntl &= ~(1 << 9);
422 else
423 rcntl |= (1 << 9);
424
425 } else {
426#ifdef FEC_MIIGSK_ENR
427 if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) {
428 /* disable the gasket and wait */
429 writel(0, fep->hwp + FEC_MIIGSK_ENR);
430 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
431 udelay(1);
432
433 /*
434 * configure the gasket:
435 * RMII, 50 MHz, no loopback, no echo
436 */
437 writel(1, fep->hwp + FEC_MIIGSK_CFGR);
438
439 /* re-enable the gasket */
440 writel(2, fep->hwp + FEC_MIIGSK_ENR);
379 } 441 }
380 } while (int_events); 442#endif
443 }
444 writel(rcntl, fep->hwp + FEC_R_CNTRL);
381 445
382 return ret; 446 /* And last, enable the transmit and receive processing */
447 writel(2, fep->hwp + FEC_ECNTRL);
448 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
449
450 /* Enable interrupts we wish to service */
451 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
452}
453
454static void
455fec_stop(struct net_device *ndev)
456{
457 struct fec_enet_private *fep = netdev_priv(ndev);
458
459 /* We cannot expect a graceful transmit stop without link !!! */
460 if (fep->link) {
461 writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
462 udelay(10);
463 if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
464 printk("fec_stop : Graceful transmit stop did not complete !\n");
465 }
466
467 /* Whack a reset. We should wait for this. */
468 writel(1, fep->hwp + FEC_ECNTRL);
469 udelay(10);
470 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
471 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
383} 472}
384 473
385 474
386static void 475static void
387fec_enet_tx(struct net_device *dev) 476fec_timeout(struct net_device *ndev)
477{
478 struct fec_enet_private *fep = netdev_priv(ndev);
479
480 ndev->stats.tx_errors++;
481
482 fec_restart(ndev, fep->full_duplex);
483 netif_wake_queue(ndev);
484}
485
486static void
487fec_enet_tx(struct net_device *ndev)
388{ 488{
389 struct fec_enet_private *fep; 489 struct fec_enet_private *fep;
390 struct bufdesc *bdp; 490 struct bufdesc *bdp;
391 unsigned short status; 491 unsigned short status;
392 struct sk_buff *skb; 492 struct sk_buff *skb;
393 493
394 fep = netdev_priv(dev); 494 fep = netdev_priv(ndev);
395 spin_lock(&fep->hw_lock); 495 spin_lock(&fep->hw_lock);
396 bdp = fep->dirty_tx; 496 bdp = fep->dirty_tx;
397 497
@@ -399,7 +499,8 @@ fec_enet_tx(struct net_device *dev)
399 if (bdp == fep->cur_tx && fep->tx_full == 0) 499 if (bdp == fep->cur_tx && fep->tx_full == 0)
400 break; 500 break;
401 501
402 dma_unmap_single(&dev->dev, bdp->cbd_bufaddr, FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); 502 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
503 FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
403 bdp->cbd_bufaddr = 0; 504 bdp->cbd_bufaddr = 0;
404 505
405 skb = fep->tx_skbuff[fep->skb_dirty]; 506 skb = fep->tx_skbuff[fep->skb_dirty];
@@ -407,19 +508,19 @@ fec_enet_tx(struct net_device *dev)
407 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC | 508 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
408 BD_ENET_TX_RL | BD_ENET_TX_UN | 509 BD_ENET_TX_RL | BD_ENET_TX_UN |
409 BD_ENET_TX_CSL)) { 510 BD_ENET_TX_CSL)) {
410 dev->stats.tx_errors++; 511 ndev->stats.tx_errors++;
411 if (status & BD_ENET_TX_HB) /* No heartbeat */ 512 if (status & BD_ENET_TX_HB) /* No heartbeat */
412 dev->stats.tx_heartbeat_errors++; 513 ndev->stats.tx_heartbeat_errors++;
413 if (status & BD_ENET_TX_LC) /* Late collision */ 514 if (status & BD_ENET_TX_LC) /* Late collision */
414 dev->stats.tx_window_errors++; 515 ndev->stats.tx_window_errors++;
415 if (status & BD_ENET_TX_RL) /* Retrans limit */ 516 if (status & BD_ENET_TX_RL) /* Retrans limit */
416 dev->stats.tx_aborted_errors++; 517 ndev->stats.tx_aborted_errors++;
417 if (status & BD_ENET_TX_UN) /* Underrun */ 518 if (status & BD_ENET_TX_UN) /* Underrun */
418 dev->stats.tx_fifo_errors++; 519 ndev->stats.tx_fifo_errors++;
419 if (status & BD_ENET_TX_CSL) /* Carrier lost */ 520 if (status & BD_ENET_TX_CSL) /* Carrier lost */
420 dev->stats.tx_carrier_errors++; 521 ndev->stats.tx_carrier_errors++;
421 } else { 522 } else {
422 dev->stats.tx_packets++; 523 ndev->stats.tx_packets++;
423 } 524 }
424 525
425 if (status & BD_ENET_TX_READY) 526 if (status & BD_ENET_TX_READY)
@@ -429,7 +530,7 @@ fec_enet_tx(struct net_device *dev)
429 * but we eventually sent the packet OK. 530 * but we eventually sent the packet OK.
430 */ 531 */
431 if (status & BD_ENET_TX_DEF) 532 if (status & BD_ENET_TX_DEF)
432 dev->stats.collisions++; 533 ndev->stats.collisions++;
433 534
434 /* Free the sk buffer associated with this last transmit */ 535 /* Free the sk buffer associated with this last transmit */
435 dev_kfree_skb_any(skb); 536 dev_kfree_skb_any(skb);
@@ -446,8 +547,8 @@ fec_enet_tx(struct net_device *dev)
446 */ 547 */
447 if (fep->tx_full) { 548 if (fep->tx_full) {
448 fep->tx_full = 0; 549 fep->tx_full = 0;
449 if (netif_queue_stopped(dev)) 550 if (netif_queue_stopped(ndev))
450 netif_wake_queue(dev); 551 netif_wake_queue(ndev);
451 } 552 }
452 } 553 }
453 fep->dirty_tx = bdp; 554 fep->dirty_tx = bdp;
@@ -461,9 +562,9 @@ fec_enet_tx(struct net_device *dev)
461 * effectively tossing the packet. 562 * effectively tossing the packet.
462 */ 563 */
463static void 564static void
464fec_enet_rx(struct net_device *dev) 565fec_enet_rx(struct net_device *ndev)
465{ 566{
466 struct fec_enet_private *fep = netdev_priv(dev); 567 struct fec_enet_private *fep = netdev_priv(ndev);
467 const struct platform_device_id *id_entry = 568 const struct platform_device_id *id_entry =
468 platform_get_device_id(fep->pdev); 569 platform_get_device_id(fep->pdev);
469 struct bufdesc *bdp; 570 struct bufdesc *bdp;
@@ -497,17 +598,17 @@ fec_enet_rx(struct net_device *dev)
497 /* Check for errors. */ 598 /* Check for errors. */
498 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | 599 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
499 BD_ENET_RX_CR | BD_ENET_RX_OV)) { 600 BD_ENET_RX_CR | BD_ENET_RX_OV)) {
500 dev->stats.rx_errors++; 601 ndev->stats.rx_errors++;
501 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { 602 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
502 /* Frame too long or too short. */ 603 /* Frame too long or too short. */
503 dev->stats.rx_length_errors++; 604 ndev->stats.rx_length_errors++;
504 } 605 }
505 if (status & BD_ENET_RX_NO) /* Frame alignment */ 606 if (status & BD_ENET_RX_NO) /* Frame alignment */
506 dev->stats.rx_frame_errors++; 607 ndev->stats.rx_frame_errors++;
507 if (status & BD_ENET_RX_CR) /* CRC Error */ 608 if (status & BD_ENET_RX_CR) /* CRC Error */
508 dev->stats.rx_crc_errors++; 609 ndev->stats.rx_crc_errors++;
509 if (status & BD_ENET_RX_OV) /* FIFO overrun */ 610 if (status & BD_ENET_RX_OV) /* FIFO overrun */
510 dev->stats.rx_fifo_errors++; 611 ndev->stats.rx_fifo_errors++;
511 } 612 }
512 613
513 /* Report late collisions as a frame error. 614 /* Report late collisions as a frame error.
@@ -515,19 +616,19 @@ fec_enet_rx(struct net_device *dev)
515 * have in the buffer. So, just drop this frame on the floor. 616 * have in the buffer. So, just drop this frame on the floor.
516 */ 617 */
517 if (status & BD_ENET_RX_CL) { 618 if (status & BD_ENET_RX_CL) {
518 dev->stats.rx_errors++; 619 ndev->stats.rx_errors++;
519 dev->stats.rx_frame_errors++; 620 ndev->stats.rx_frame_errors++;
520 goto rx_processing_done; 621 goto rx_processing_done;
521 } 622 }
522 623
523 /* Process the incoming frame. */ 624 /* Process the incoming frame. */
524 dev->stats.rx_packets++; 625 ndev->stats.rx_packets++;
525 pkt_len = bdp->cbd_datlen; 626 pkt_len = bdp->cbd_datlen;
526 dev->stats.rx_bytes += pkt_len; 627 ndev->stats.rx_bytes += pkt_len;
527 data = (__u8*)__va(bdp->cbd_bufaddr); 628 data = (__u8*)__va(bdp->cbd_bufaddr);
528 629
529 dma_unmap_single(NULL, bdp->cbd_bufaddr, bdp->cbd_datlen, 630 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
530 DMA_FROM_DEVICE); 631 FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
531 632
532 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) 633 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
533 swap_buffer(data, pkt_len); 634 swap_buffer(data, pkt_len);
@@ -541,18 +642,18 @@ fec_enet_rx(struct net_device *dev)
541 642
542 if (unlikely(!skb)) { 643 if (unlikely(!skb)) {
543 printk("%s: Memory squeeze, dropping packet.\n", 644 printk("%s: Memory squeeze, dropping packet.\n",
544 dev->name); 645 ndev->name);
545 dev->stats.rx_dropped++; 646 ndev->stats.rx_dropped++;
546 } else { 647 } else {
547 skb_reserve(skb, NET_IP_ALIGN); 648 skb_reserve(skb, NET_IP_ALIGN);
548 skb_put(skb, pkt_len - 4); /* Make room */ 649 skb_put(skb, pkt_len - 4); /* Make room */
549 skb_copy_to_linear_data(skb, data, pkt_len - 4); 650 skb_copy_to_linear_data(skb, data, pkt_len - 4);
550 skb->protocol = eth_type_trans(skb, dev); 651 skb->protocol = eth_type_trans(skb, ndev);
551 netif_rx(skb); 652 netif_rx(skb);
552 } 653 }
553 654
554 bdp->cbd_bufaddr = dma_map_single(NULL, data, bdp->cbd_datlen, 655 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
555 DMA_FROM_DEVICE); 656 FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
556rx_processing_done: 657rx_processing_done:
557 /* Clear the status flags for this buffer */ 658 /* Clear the status flags for this buffer */
558 status &= ~BD_ENET_RX_STATS; 659 status &= ~BD_ENET_RX_STATS;
@@ -577,10 +678,47 @@ rx_processing_done:
577 spin_unlock(&fep->hw_lock); 678 spin_unlock(&fep->hw_lock);
578} 679}
579 680
681static irqreturn_t
682fec_enet_interrupt(int irq, void *dev_id)
683{
684 struct net_device *ndev = dev_id;
685 struct fec_enet_private *fep = netdev_priv(ndev);
686 uint int_events;
687 irqreturn_t ret = IRQ_NONE;
688
689 do {
690 int_events = readl(fep->hwp + FEC_IEVENT);
691 writel(int_events, fep->hwp + FEC_IEVENT);
692
693 if (int_events & FEC_ENET_RXF) {
694 ret = IRQ_HANDLED;
695 fec_enet_rx(ndev);
696 }
697
698 /* Transmit OK, or non-fatal error. Update the buffer
699 * descriptors. FEC handles all errors, we just discover
700 * them as part of the transmit process.
701 */
702 if (int_events & FEC_ENET_TXF) {
703 ret = IRQ_HANDLED;
704 fec_enet_tx(ndev);
705 }
706
707 if (int_events & FEC_ENET_MII) {
708 ret = IRQ_HANDLED;
709 complete(&fep->mdio_done);
710 }
711 } while (int_events);
712
713 return ret;
714}
715
716
717
580/* ------------------------------------------------------------------------- */ 718/* ------------------------------------------------------------------------- */
581static void __inline__ fec_get_mac(struct net_device *dev) 719static void __inline__ fec_get_mac(struct net_device *ndev)
582{ 720{
583 struct fec_enet_private *fep = netdev_priv(dev); 721 struct fec_enet_private *fep = netdev_priv(ndev);
584 struct fec_platform_data *pdata = fep->pdev->dev.platform_data; 722 struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
585 unsigned char *iap, tmpaddr[ETH_ALEN]; 723 unsigned char *iap, tmpaddr[ETH_ALEN];
586 724
@@ -616,11 +754,11 @@ static void __inline__ fec_get_mac(struct net_device *dev)
616 iap = &tmpaddr[0]; 754 iap = &tmpaddr[0];
617 } 755 }
618 756
619 memcpy(dev->dev_addr, iap, ETH_ALEN); 757 memcpy(ndev->dev_addr, iap, ETH_ALEN);
620 758
621 /* Adjust MAC if using macaddr */ 759 /* Adjust MAC if using macaddr */
622 if (iap == macaddr) 760 if (iap == macaddr)
623 dev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->pdev->id; 761 ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->pdev->id;
624} 762}
625 763
626/* ------------------------------------------------------------------------- */ 764/* ------------------------------------------------------------------------- */
@@ -628,9 +766,9 @@ static void __inline__ fec_get_mac(struct net_device *dev)
628/* 766/*
629 * Phy section 767 * Phy section
630 */ 768 */
631static void fec_enet_adjust_link(struct net_device *dev) 769static void fec_enet_adjust_link(struct net_device *ndev)
632{ 770{
633 struct fec_enet_private *fep = netdev_priv(dev); 771 struct fec_enet_private *fep = netdev_priv(ndev);
634 struct phy_device *phy_dev = fep->phy_dev; 772 struct phy_device *phy_dev = fep->phy_dev;
635 unsigned long flags; 773 unsigned long flags;
636 774
@@ -647,7 +785,7 @@ static void fec_enet_adjust_link(struct net_device *dev)
647 /* Duplex link change */ 785 /* Duplex link change */
648 if (phy_dev->link) { 786 if (phy_dev->link) {
649 if (fep->full_duplex != phy_dev->duplex) { 787 if (fep->full_duplex != phy_dev->duplex) {
650 fec_restart(dev, phy_dev->duplex); 788 fec_restart(ndev, phy_dev->duplex);
651 status_change = 1; 789 status_change = 1;
652 } 790 }
653 } 791 }
@@ -656,9 +794,9 @@ static void fec_enet_adjust_link(struct net_device *dev)
656 if (phy_dev->link != fep->link) { 794 if (phy_dev->link != fep->link) {
657 fep->link = phy_dev->link; 795 fep->link = phy_dev->link;
658 if (phy_dev->link) 796 if (phy_dev->link)
659 fec_restart(dev, phy_dev->duplex); 797 fec_restart(ndev, phy_dev->duplex);
660 else 798 else
661 fec_stop(dev); 799 fec_stop(ndev);
662 status_change = 1; 800 status_change = 1;
663 } 801 }
664 802
@@ -727,9 +865,9 @@ static int fec_enet_mdio_reset(struct mii_bus *bus)
727 return 0; 865 return 0;
728} 866}
729 867
730static int fec_enet_mii_probe(struct net_device *dev) 868static int fec_enet_mii_probe(struct net_device *ndev)
731{ 869{
732 struct fec_enet_private *fep = netdev_priv(dev); 870 struct fec_enet_private *fep = netdev_priv(ndev);
733 struct phy_device *phy_dev = NULL; 871 struct phy_device *phy_dev = NULL;
734 char mdio_bus_id[MII_BUS_ID_SIZE]; 872 char mdio_bus_id[MII_BUS_ID_SIZE];
735 char phy_name[MII_BUS_ID_SIZE + 3]; 873 char phy_name[MII_BUS_ID_SIZE + 3];
@@ -754,16 +892,16 @@ static int fec_enet_mii_probe(struct net_device *dev)
754 892
755 if (phy_id >= PHY_MAX_ADDR) { 893 if (phy_id >= PHY_MAX_ADDR) {
756 printk(KERN_INFO "%s: no PHY, assuming direct connection " 894 printk(KERN_INFO "%s: no PHY, assuming direct connection "
757 "to switch\n", dev->name); 895 "to switch\n", ndev->name);
758 strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE); 896 strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE);
759 phy_id = 0; 897 phy_id = 0;
760 } 898 }
761 899
762 snprintf(phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id); 900 snprintf(phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
763 phy_dev = phy_connect(dev, phy_name, &fec_enet_adjust_link, 0, 901 phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, 0,
764 PHY_INTERFACE_MODE_MII); 902 PHY_INTERFACE_MODE_MII);
765 if (IS_ERR(phy_dev)) { 903 if (IS_ERR(phy_dev)) {
766 printk(KERN_ERR "%s: could not attach to PHY\n", dev->name); 904 printk(KERN_ERR "%s: could not attach to PHY\n", ndev->name);
767 return PTR_ERR(phy_dev); 905 return PTR_ERR(phy_dev);
768 } 906 }
769 907
@@ -776,7 +914,7 @@ static int fec_enet_mii_probe(struct net_device *dev)
776 fep->full_duplex = 0; 914 fep->full_duplex = 0;
777 915
778 printk(KERN_INFO "%s: Freescale FEC PHY driver [%s] " 916 printk(KERN_INFO "%s: Freescale FEC PHY driver [%s] "
779 "(mii_bus:phy_addr=%s, irq=%d)\n", dev->name, 917 "(mii_bus:phy_addr=%s, irq=%d)\n", ndev->name,
780 fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev), 918 fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev),
781 fep->phy_dev->irq); 919 fep->phy_dev->irq);
782 920
@@ -786,8 +924,8 @@ static int fec_enet_mii_probe(struct net_device *dev)
786static int fec_enet_mii_init(struct platform_device *pdev) 924static int fec_enet_mii_init(struct platform_device *pdev)
787{ 925{
788 static struct mii_bus *fec0_mii_bus; 926 static struct mii_bus *fec0_mii_bus;
789 struct net_device *dev = platform_get_drvdata(pdev); 927 struct net_device *ndev = platform_get_drvdata(pdev);
790 struct fec_enet_private *fep = netdev_priv(dev); 928 struct fec_enet_private *fep = netdev_priv(ndev);
791 const struct platform_device_id *id_entry = 929 const struct platform_device_id *id_entry =
792 platform_get_device_id(fep->pdev); 930 platform_get_device_id(fep->pdev);
793 int err = -ENXIO, i; 931 int err = -ENXIO, i;
@@ -845,7 +983,7 @@ static int fec_enet_mii_init(struct platform_device *pdev)
845 for (i = 0; i < PHY_MAX_ADDR; i++) 983 for (i = 0; i < PHY_MAX_ADDR; i++)
846 fep->mii_bus->irq[i] = PHY_POLL; 984 fep->mii_bus->irq[i] = PHY_POLL;
847 985
848 platform_set_drvdata(dev, fep->mii_bus); 986 platform_set_drvdata(ndev, fep->mii_bus);
849 987
850 if (mdiobus_register(fep->mii_bus)) 988 if (mdiobus_register(fep->mii_bus))
851 goto err_out_free_mdio_irq; 989 goto err_out_free_mdio_irq;
@@ -873,10 +1011,10 @@ static void fec_enet_mii_remove(struct fec_enet_private *fep)
873 mdiobus_free(fep->mii_bus); 1011 mdiobus_free(fep->mii_bus);
874} 1012}
875 1013
876static int fec_enet_get_settings(struct net_device *dev, 1014static int fec_enet_get_settings(struct net_device *ndev,
877 struct ethtool_cmd *cmd) 1015 struct ethtool_cmd *cmd)
878{ 1016{
879 struct fec_enet_private *fep = netdev_priv(dev); 1017 struct fec_enet_private *fep = netdev_priv(ndev);
880 struct phy_device *phydev = fep->phy_dev; 1018 struct phy_device *phydev = fep->phy_dev;
881 1019
882 if (!phydev) 1020 if (!phydev)
@@ -885,10 +1023,10 @@ static int fec_enet_get_settings(struct net_device *dev,
885 return phy_ethtool_gset(phydev, cmd); 1023 return phy_ethtool_gset(phydev, cmd);
886} 1024}
887 1025
888static int fec_enet_set_settings(struct net_device *dev, 1026static int fec_enet_set_settings(struct net_device *ndev,
889 struct ethtool_cmd *cmd) 1027 struct ethtool_cmd *cmd)
890{ 1028{
891 struct fec_enet_private *fep = netdev_priv(dev); 1029 struct fec_enet_private *fep = netdev_priv(ndev);
892 struct phy_device *phydev = fep->phy_dev; 1030 struct phy_device *phydev = fep->phy_dev;
893 1031
894 if (!phydev) 1032 if (!phydev)
@@ -897,14 +1035,14 @@ static int fec_enet_set_settings(struct net_device *dev,
897 return phy_ethtool_sset(phydev, cmd); 1035 return phy_ethtool_sset(phydev, cmd);
898} 1036}
899 1037
900static void fec_enet_get_drvinfo(struct net_device *dev, 1038static void fec_enet_get_drvinfo(struct net_device *ndev,
901 struct ethtool_drvinfo *info) 1039 struct ethtool_drvinfo *info)
902{ 1040{
903 struct fec_enet_private *fep = netdev_priv(dev); 1041 struct fec_enet_private *fep = netdev_priv(ndev);
904 1042
905 strcpy(info->driver, fep->pdev->dev.driver->name); 1043 strcpy(info->driver, fep->pdev->dev.driver->name);
906 strcpy(info->version, "Revision: 1.0"); 1044 strcpy(info->version, "Revision: 1.0");
907 strcpy(info->bus_info, dev_name(&dev->dev)); 1045 strcpy(info->bus_info, dev_name(&ndev->dev));
908} 1046}
909 1047
910static struct ethtool_ops fec_enet_ethtool_ops = { 1048static struct ethtool_ops fec_enet_ethtool_ops = {
@@ -914,12 +1052,12 @@ static struct ethtool_ops fec_enet_ethtool_ops = {
914 .get_link = ethtool_op_get_link, 1052 .get_link = ethtool_op_get_link,
915}; 1053};
916 1054
917static int fec_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1055static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
918{ 1056{
919 struct fec_enet_private *fep = netdev_priv(dev); 1057 struct fec_enet_private *fep = netdev_priv(ndev);
920 struct phy_device *phydev = fep->phy_dev; 1058 struct phy_device *phydev = fep->phy_dev;
921 1059
922 if (!netif_running(dev)) 1060 if (!netif_running(ndev))
923 return -EINVAL; 1061 return -EINVAL;
924 1062
925 if (!phydev) 1063 if (!phydev)
@@ -928,9 +1066,9 @@ static int fec_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
928 return phy_mii_ioctl(phydev, rq, cmd); 1066 return phy_mii_ioctl(phydev, rq, cmd);
929} 1067}
930 1068
931static void fec_enet_free_buffers(struct net_device *dev) 1069static void fec_enet_free_buffers(struct net_device *ndev)
932{ 1070{
933 struct fec_enet_private *fep = netdev_priv(dev); 1071 struct fec_enet_private *fep = netdev_priv(ndev);
934 int i; 1072 int i;
935 struct sk_buff *skb; 1073 struct sk_buff *skb;
936 struct bufdesc *bdp; 1074 struct bufdesc *bdp;
@@ -940,7 +1078,7 @@ static void fec_enet_free_buffers(struct net_device *dev)
940 skb = fep->rx_skbuff[i]; 1078 skb = fep->rx_skbuff[i];
941 1079
942 if (bdp->cbd_bufaddr) 1080 if (bdp->cbd_bufaddr)
943 dma_unmap_single(&dev->dev, bdp->cbd_bufaddr, 1081 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
944 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); 1082 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
945 if (skb) 1083 if (skb)
946 dev_kfree_skb(skb); 1084 dev_kfree_skb(skb);
@@ -952,9 +1090,9 @@ static void fec_enet_free_buffers(struct net_device *dev)
952 kfree(fep->tx_bounce[i]); 1090 kfree(fep->tx_bounce[i]);
953} 1091}
954 1092
955static int fec_enet_alloc_buffers(struct net_device *dev) 1093static int fec_enet_alloc_buffers(struct net_device *ndev)
956{ 1094{
957 struct fec_enet_private *fep = netdev_priv(dev); 1095 struct fec_enet_private *fep = netdev_priv(ndev);
958 int i; 1096 int i;
959 struct sk_buff *skb; 1097 struct sk_buff *skb;
960 struct bufdesc *bdp; 1098 struct bufdesc *bdp;
@@ -963,12 +1101,12 @@ static int fec_enet_alloc_buffers(struct net_device *dev)
963 for (i = 0; i < RX_RING_SIZE; i++) { 1101 for (i = 0; i < RX_RING_SIZE; i++) {
964 skb = dev_alloc_skb(FEC_ENET_RX_FRSIZE); 1102 skb = dev_alloc_skb(FEC_ENET_RX_FRSIZE);
965 if (!skb) { 1103 if (!skb) {
966 fec_enet_free_buffers(dev); 1104 fec_enet_free_buffers(ndev);
967 return -ENOMEM; 1105 return -ENOMEM;
968 } 1106 }
969 fep->rx_skbuff[i] = skb; 1107 fep->rx_skbuff[i] = skb;
970 1108
971 bdp->cbd_bufaddr = dma_map_single(&dev->dev, skb->data, 1109 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data,
972 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); 1110 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
973 bdp->cbd_sc = BD_ENET_RX_EMPTY; 1111 bdp->cbd_sc = BD_ENET_RX_EMPTY;
974 bdp++; 1112 bdp++;
@@ -995,45 +1133,47 @@ static int fec_enet_alloc_buffers(struct net_device *dev)
995} 1133}
996 1134
997static int 1135static int
998fec_enet_open(struct net_device *dev) 1136fec_enet_open(struct net_device *ndev)
999{ 1137{
1000 struct fec_enet_private *fep = netdev_priv(dev); 1138 struct fec_enet_private *fep = netdev_priv(ndev);
1001 int ret; 1139 int ret;
1002 1140
1003 /* I should reset the ring buffers here, but I don't yet know 1141 /* I should reset the ring buffers here, but I don't yet know
1004 * a simple way to do that. 1142 * a simple way to do that.
1005 */ 1143 */
1006 1144
1007 ret = fec_enet_alloc_buffers(dev); 1145 ret = fec_enet_alloc_buffers(ndev);
1008 if (ret) 1146 if (ret)
1009 return ret; 1147 return ret;
1010 1148
1011 /* Probe and connect to PHY when open the interface */ 1149 /* Probe and connect to PHY when open the interface */
1012 ret = fec_enet_mii_probe(dev); 1150 ret = fec_enet_mii_probe(ndev);
1013 if (ret) { 1151 if (ret) {
1014 fec_enet_free_buffers(dev); 1152 fec_enet_free_buffers(ndev);
1015 return ret; 1153 return ret;
1016 } 1154 }
1017 phy_start(fep->phy_dev); 1155 phy_start(fep->phy_dev);
1018 netif_start_queue(dev); 1156 netif_start_queue(ndev);
1019 fep->opened = 1; 1157 fep->opened = 1;
1020 return 0; 1158 return 0;
1021} 1159}
1022 1160
1023static int 1161static int
1024fec_enet_close(struct net_device *dev) 1162fec_enet_close(struct net_device *ndev)
1025{ 1163{
1026 struct fec_enet_private *fep = netdev_priv(dev); 1164 struct fec_enet_private *fep = netdev_priv(ndev);
1027 1165
1028 /* Don't know what to do yet. */ 1166 /* Don't know what to do yet. */
1029 fep->opened = 0; 1167 fep->opened = 0;
1030 netif_stop_queue(dev); 1168 netif_stop_queue(ndev);
1031 fec_stop(dev); 1169 fec_stop(ndev);
1032 1170
1033 if (fep->phy_dev) 1171 if (fep->phy_dev) {
1172 phy_stop(fep->phy_dev);
1034 phy_disconnect(fep->phy_dev); 1173 phy_disconnect(fep->phy_dev);
1174 }
1035 1175
1036 fec_enet_free_buffers(dev); 1176 fec_enet_free_buffers(ndev);
1037 1177
1038 return 0; 1178 return 0;
1039} 1179}
@@ -1051,14 +1191,14 @@ fec_enet_close(struct net_device *dev)
1051#define HASH_BITS 6 /* #bits in hash */ 1191#define HASH_BITS 6 /* #bits in hash */
1052#define CRC32_POLY 0xEDB88320 1192#define CRC32_POLY 0xEDB88320
1053 1193
1054static void set_multicast_list(struct net_device *dev) 1194static void set_multicast_list(struct net_device *ndev)
1055{ 1195{
1056 struct fec_enet_private *fep = netdev_priv(dev); 1196 struct fec_enet_private *fep = netdev_priv(ndev);
1057 struct netdev_hw_addr *ha; 1197 struct netdev_hw_addr *ha;
1058 unsigned int i, bit, data, crc, tmp; 1198 unsigned int i, bit, data, crc, tmp;
1059 unsigned char hash; 1199 unsigned char hash;
1060 1200
1061 if (dev->flags & IFF_PROMISC) { 1201 if (ndev->flags & IFF_PROMISC) {
1062 tmp = readl(fep->hwp + FEC_R_CNTRL); 1202 tmp = readl(fep->hwp + FEC_R_CNTRL);
1063 tmp |= 0x8; 1203 tmp |= 0x8;
1064 writel(tmp, fep->hwp + FEC_R_CNTRL); 1204 writel(tmp, fep->hwp + FEC_R_CNTRL);
@@ -1069,7 +1209,7 @@ static void set_multicast_list(struct net_device *dev)
1069 tmp &= ~0x8; 1209 tmp &= ~0x8;
1070 writel(tmp, fep->hwp + FEC_R_CNTRL); 1210 writel(tmp, fep->hwp + FEC_R_CNTRL);
1071 1211
1072 if (dev->flags & IFF_ALLMULTI) { 1212 if (ndev->flags & IFF_ALLMULTI) {
1073 /* Catch all multicast addresses, so set the 1213 /* Catch all multicast addresses, so set the
1074 * filter to all 1's 1214 * filter to all 1's
1075 */ 1215 */
@@ -1084,7 +1224,7 @@ static void set_multicast_list(struct net_device *dev)
1084 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); 1224 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1085 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); 1225 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1086 1226
1087 netdev_for_each_mc_addr(ha, dev) { 1227 netdev_for_each_mc_addr(ha, ndev) {
1088 /* Only support group multicast for now */ 1228 /* Only support group multicast for now */
1089 if (!(ha->addr[0] & 1)) 1229 if (!(ha->addr[0] & 1))
1090 continue; 1230 continue;
@@ -1092,7 +1232,7 @@ static void set_multicast_list(struct net_device *dev)
1092 /* calculate crc32 value of mac address */ 1232 /* calculate crc32 value of mac address */
1093 crc = 0xffffffff; 1233 crc = 0xffffffff;
1094 1234
1095 for (i = 0; i < dev->addr_len; i++) { 1235 for (i = 0; i < ndev->addr_len; i++) {
1096 data = ha->addr[i]; 1236 data = ha->addr[i];
1097 for (bit = 0; bit < 8; bit++, data >>= 1) { 1237 for (bit = 0; bit < 8; bit++, data >>= 1) {
1098 crc = (crc >> 1) ^ 1238 crc = (crc >> 1) ^
@@ -1119,20 +1259,20 @@ static void set_multicast_list(struct net_device *dev)
1119 1259
1120/* Set a MAC change in hardware. */ 1260/* Set a MAC change in hardware. */
1121static int 1261static int
1122fec_set_mac_address(struct net_device *dev, void *p) 1262fec_set_mac_address(struct net_device *ndev, void *p)
1123{ 1263{
1124 struct fec_enet_private *fep = netdev_priv(dev); 1264 struct fec_enet_private *fep = netdev_priv(ndev);
1125 struct sockaddr *addr = p; 1265 struct sockaddr *addr = p;
1126 1266
1127 if (!is_valid_ether_addr(addr->sa_data)) 1267 if (!is_valid_ether_addr(addr->sa_data))
1128 return -EADDRNOTAVAIL; 1268 return -EADDRNOTAVAIL;
1129 1269
1130 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); 1270 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
1131 1271
1132 writel(dev->dev_addr[3] | (dev->dev_addr[2] << 8) | 1272 writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) |
1133 (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24), 1273 (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24),
1134 fep->hwp + FEC_ADDR_LOW); 1274 fep->hwp + FEC_ADDR_LOW);
1135 writel((dev->dev_addr[5] << 16) | (dev->dev_addr[4] << 24), 1275 writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24),
1136 fep->hwp + FEC_ADDR_HIGH); 1276 fep->hwp + FEC_ADDR_HIGH);
1137 return 0; 1277 return 0;
1138} 1278}
@@ -1146,16 +1286,16 @@ static const struct net_device_ops fec_netdev_ops = {
1146 .ndo_validate_addr = eth_validate_addr, 1286 .ndo_validate_addr = eth_validate_addr,
1147 .ndo_tx_timeout = fec_timeout, 1287 .ndo_tx_timeout = fec_timeout,
1148 .ndo_set_mac_address = fec_set_mac_address, 1288 .ndo_set_mac_address = fec_set_mac_address,
1149 .ndo_do_ioctl = fec_enet_ioctl, 1289 .ndo_do_ioctl = fec_enet_ioctl,
1150}; 1290};
1151 1291
1152 /* 1292 /*
1153 * XXX: We need to clean up on failure exits here. 1293 * XXX: We need to clean up on failure exits here.
1154 * 1294 *
1155 */ 1295 */
1156static int fec_enet_init(struct net_device *dev) 1296static int fec_enet_init(struct net_device *ndev)
1157{ 1297{
1158 struct fec_enet_private *fep = netdev_priv(dev); 1298 struct fec_enet_private *fep = netdev_priv(ndev);
1159 struct bufdesc *cbd_base; 1299 struct bufdesc *cbd_base;
1160 struct bufdesc *bdp; 1300 struct bufdesc *bdp;
1161 int i; 1301 int i;
@@ -1170,20 +1310,19 @@ static int fec_enet_init(struct net_device *dev)
1170 1310
1171 spin_lock_init(&fep->hw_lock); 1311 spin_lock_init(&fep->hw_lock);
1172 1312
1173 fep->hwp = (void __iomem *)dev->base_addr; 1313 fep->netdev = ndev;
1174 fep->netdev = dev;
1175 1314
1176 /* Get the Ethernet address */ 1315 /* Get the Ethernet address */
1177 fec_get_mac(dev); 1316 fec_get_mac(ndev);
1178 1317
1179 /* Set receive and transmit descriptor base. */ 1318 /* Set receive and transmit descriptor base. */
1180 fep->rx_bd_base = cbd_base; 1319 fep->rx_bd_base = cbd_base;
1181 fep->tx_bd_base = cbd_base + RX_RING_SIZE; 1320 fep->tx_bd_base = cbd_base + RX_RING_SIZE;
1182 1321
1183 /* The FEC Ethernet specific entries in the device structure */ 1322 /* The FEC Ethernet specific entries in the device structure */
1184 dev->watchdog_timeo = TX_TIMEOUT; 1323 ndev->watchdog_timeo = TX_TIMEOUT;
1185 dev->netdev_ops = &fec_netdev_ops; 1324 ndev->netdev_ops = &fec_netdev_ops;
1186 dev->ethtool_ops = &fec_enet_ethtool_ops; 1325 ndev->ethtool_ops = &fec_enet_ethtool_ops;
1187 1326
1188 /* Initialize the receive buffer descriptors. */ 1327 /* Initialize the receive buffer descriptors. */
1189 bdp = fep->rx_bd_base; 1328 bdp = fep->rx_bd_base;
@@ -1212,152 +1351,11 @@ static int fec_enet_init(struct net_device *dev)
1212 bdp--; 1351 bdp--;
1213 bdp->cbd_sc |= BD_SC_WRAP; 1352 bdp->cbd_sc |= BD_SC_WRAP;
1214 1353
1215 fec_restart(dev, 0); 1354 fec_restart(ndev, 0);
1216 1355
1217 return 0; 1356 return 0;
1218} 1357}
1219 1358
1220/* This function is called to start or restart the FEC during a link
1221 * change. This only happens when switching between half and full
1222 * duplex.
1223 */
1224static void
1225fec_restart(struct net_device *dev, int duplex)
1226{
1227 struct fec_enet_private *fep = netdev_priv(dev);
1228 const struct platform_device_id *id_entry =
1229 platform_get_device_id(fep->pdev);
1230 int i;
1231 u32 val, temp_mac[2];
1232
1233 /* Whack a reset. We should wait for this. */
1234 writel(1, fep->hwp + FEC_ECNTRL);
1235 udelay(10);
1236
1237 /*
1238 * enet-mac reset will reset mac address registers too,
1239 * so need to reconfigure it.
1240 */
1241 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
1242 memcpy(&temp_mac, dev->dev_addr, ETH_ALEN);
1243 writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
1244 writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
1245 }
1246
1247 /* Clear any outstanding interrupt. */
1248 writel(0xffc00000, fep->hwp + FEC_IEVENT);
1249
1250 /* Reset all multicast. */
1251 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1252 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1253#ifndef CONFIG_M5272
1254 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
1255 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
1256#endif
1257
1258 /* Set maximum receive buffer size. */
1259 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
1260
1261 /* Set receive and transmit descriptor base. */
1262 writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
1263 writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE,
1264 fep->hwp + FEC_X_DES_START);
1265
1266 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
1267 fep->cur_rx = fep->rx_bd_base;
1268
1269 /* Reset SKB transmit buffers. */
1270 fep->skb_cur = fep->skb_dirty = 0;
1271 for (i = 0; i <= TX_RING_MOD_MASK; i++) {
1272 if (fep->tx_skbuff[i]) {
1273 dev_kfree_skb_any(fep->tx_skbuff[i]);
1274 fep->tx_skbuff[i] = NULL;
1275 }
1276 }
1277
1278 /* Enable MII mode */
1279 if (duplex) {
1280 /* MII enable / FD enable */
1281 writel(OPT_FRAME_SIZE | 0x04, fep->hwp + FEC_R_CNTRL);
1282 writel(0x04, fep->hwp + FEC_X_CNTRL);
1283 } else {
1284 /* MII enable / No Rcv on Xmit */
1285 writel(OPT_FRAME_SIZE | 0x06, fep->hwp + FEC_R_CNTRL);
1286 writel(0x0, fep->hwp + FEC_X_CNTRL);
1287 }
1288 fep->full_duplex = duplex;
1289
1290 /* Set MII speed */
1291 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
1292
1293 /*
1294 * The phy interface and speed need to get configured
1295 * differently on enet-mac.
1296 */
1297 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
1298 val = readl(fep->hwp + FEC_R_CNTRL);
1299
1300 /* MII or RMII */
1301 if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
1302 val |= (1 << 8);
1303 else
1304 val &= ~(1 << 8);
1305
1306 /* 10M or 100M */
1307 if (fep->phy_dev && fep->phy_dev->speed == SPEED_100)
1308 val &= ~(1 << 9);
1309 else
1310 val |= (1 << 9);
1311
1312 writel(val, fep->hwp + FEC_R_CNTRL);
1313 } else {
1314#ifdef FEC_MIIGSK_ENR
1315 if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) {
1316 /* disable the gasket and wait */
1317 writel(0, fep->hwp + FEC_MIIGSK_ENR);
1318 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
1319 udelay(1);
1320
1321 /*
1322 * configure the gasket:
1323 * RMII, 50 MHz, no loopback, no echo
1324 */
1325 writel(1, fep->hwp + FEC_MIIGSK_CFGR);
1326
1327 /* re-enable the gasket */
1328 writel(2, fep->hwp + FEC_MIIGSK_ENR);
1329 }
1330#endif
1331 }
1332
1333 /* And last, enable the transmit and receive processing */
1334 writel(2, fep->hwp + FEC_ECNTRL);
1335 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
1336
1337 /* Enable interrupts we wish to service */
1338 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
1339}
1340
1341static void
1342fec_stop(struct net_device *dev)
1343{
1344 struct fec_enet_private *fep = netdev_priv(dev);
1345
1346 /* We cannot expect a graceful transmit stop without link !!! */
1347 if (fep->link) {
1348 writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
1349 udelay(10);
1350 if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
1351 printk("fec_stop : Graceful transmit stop did not complete !\n");
1352 }
1353
1354 /* Whack a reset. We should wait for this. */
1355 writel(1, fep->hwp + FEC_ECNTRL);
1356 udelay(10);
1357 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
1358 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
1359}
1360
1361static int __devinit 1359static int __devinit
1362fec_probe(struct platform_device *pdev) 1360fec_probe(struct platform_device *pdev)
1363{ 1361{
@@ -1377,19 +1375,20 @@ fec_probe(struct platform_device *pdev)
1377 1375
1378 /* Init network device */ 1376 /* Init network device */
1379 ndev = alloc_etherdev(sizeof(struct fec_enet_private)); 1377 ndev = alloc_etherdev(sizeof(struct fec_enet_private));
1380 if (!ndev) 1378 if (!ndev) {
1381 return -ENOMEM; 1379 ret = -ENOMEM;
1380 goto failed_alloc_etherdev;
1381 }
1382 1382
1383 SET_NETDEV_DEV(ndev, &pdev->dev); 1383 SET_NETDEV_DEV(ndev, &pdev->dev);
1384 1384
1385 /* setup board info structure */ 1385 /* setup board info structure */
1386 fep = netdev_priv(ndev); 1386 fep = netdev_priv(ndev);
1387 memset(fep, 0, sizeof(*fep));
1388 1387
1389 ndev->base_addr = (unsigned long)ioremap(r->start, resource_size(r)); 1388 fep->hwp = ioremap(r->start, resource_size(r));
1390 fep->pdev = pdev; 1389 fep->pdev = pdev;
1391 1390
1392 if (!ndev->base_addr) { 1391 if (!fep->hwp) {
1393 ret = -ENOMEM; 1392 ret = -ENOMEM;
1394 goto failed_ioremap; 1393 goto failed_ioremap;
1395 } 1394 }
@@ -1407,10 +1406,9 @@ fec_probe(struct platform_device *pdev)
1407 break; 1406 break;
1408 ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev); 1407 ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
1409 if (ret) { 1408 if (ret) {
1410 while (i >= 0) { 1409 while (--i >= 0) {
1411 irq = platform_get_irq(pdev, i); 1410 irq = platform_get_irq(pdev, i);
1412 free_irq(irq, ndev); 1411 free_irq(irq, ndev);
1413 i--;
1414 } 1412 }
1415 goto failed_irq; 1413 goto failed_irq;
1416 } 1414 }
@@ -1453,9 +1451,11 @@ failed_clk:
1453 free_irq(irq, ndev); 1451 free_irq(irq, ndev);
1454 } 1452 }
1455failed_irq: 1453failed_irq:
1456 iounmap((void __iomem *)ndev->base_addr); 1454 iounmap(fep->hwp);
1457failed_ioremap: 1455failed_ioremap:
1458 free_netdev(ndev); 1456 free_netdev(ndev);
1457failed_alloc_etherdev:
1458 release_mem_region(r->start, resource_size(r));
1459 1459
1460 return ret; 1460 return ret;
1461} 1461}
@@ -1465,16 +1465,22 @@ fec_drv_remove(struct platform_device *pdev)
1465{ 1465{
1466 struct net_device *ndev = platform_get_drvdata(pdev); 1466 struct net_device *ndev = platform_get_drvdata(pdev);
1467 struct fec_enet_private *fep = netdev_priv(ndev); 1467 struct fec_enet_private *fep = netdev_priv(ndev);
1468 1468 struct resource *r;
1469 platform_set_drvdata(pdev, NULL);
1470 1469
1471 fec_stop(ndev); 1470 fec_stop(ndev);
1472 fec_enet_mii_remove(fep); 1471 fec_enet_mii_remove(fep);
1473 clk_disable(fep->clk); 1472 clk_disable(fep->clk);
1474 clk_put(fep->clk); 1473 clk_put(fep->clk);
1475 iounmap((void __iomem *)ndev->base_addr); 1474 iounmap(fep->hwp);
1476 unregister_netdev(ndev); 1475 unregister_netdev(ndev);
1477 free_netdev(ndev); 1476 free_netdev(ndev);
1477
1478 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1479 BUG_ON(!r);
1480 release_mem_region(r->start, resource_size(r));
1481
1482 platform_set_drvdata(pdev, NULL);
1483
1478 return 0; 1484 return 0;
1479} 1485}
1480 1486
@@ -1483,16 +1489,14 @@ static int
1483fec_suspend(struct device *dev) 1489fec_suspend(struct device *dev)
1484{ 1490{
1485 struct net_device *ndev = dev_get_drvdata(dev); 1491 struct net_device *ndev = dev_get_drvdata(dev);
1486 struct fec_enet_private *fep; 1492 struct fec_enet_private *fep = netdev_priv(ndev);
1487 1493
1488 if (ndev) { 1494 if (netif_running(ndev)) {
1489 fep = netdev_priv(ndev); 1495 fec_stop(ndev);
1490 if (netif_running(ndev)) { 1496 netif_device_detach(ndev);
1491 fec_stop(ndev);
1492 netif_device_detach(ndev);
1493 }
1494 clk_disable(fep->clk);
1495 } 1497 }
1498 clk_disable(fep->clk);
1499
1496 return 0; 1500 return 0;
1497} 1501}
1498 1502
@@ -1500,16 +1504,14 @@ static int
1500fec_resume(struct device *dev) 1504fec_resume(struct device *dev)
1501{ 1505{
1502 struct net_device *ndev = dev_get_drvdata(dev); 1506 struct net_device *ndev = dev_get_drvdata(dev);
1503 struct fec_enet_private *fep; 1507 struct fec_enet_private *fep = netdev_priv(ndev);
1504 1508
1505 if (ndev) { 1509 clk_enable(fep->clk);
1506 fep = netdev_priv(ndev); 1510 if (netif_running(ndev)) {
1507 clk_enable(fep->clk); 1511 fec_restart(ndev, fep->full_duplex);
1508 if (netif_running(ndev)) { 1512 netif_device_attach(ndev);
1509 fec_restart(ndev, fep->full_duplex);
1510 netif_device_attach(ndev);
1511 }
1512 } 1513 }
1514
1513 return 0; 1515 return 0;
1514} 1516}
1515 1517