diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/net/fec.c | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'drivers/net/fec.c')
-rw-r--r-- | drivers/net/fec.c | 775 |
1 files changed, 444 insertions, 331 deletions
diff --git a/drivers/net/fec.c b/drivers/net/fec.c index cce32d43175f..885d8baff7d5 100644 --- a/drivers/net/fec.c +++ b/drivers/net/fec.c | |||
@@ -17,6 +17,8 @@ | |||
17 | * | 17 | * |
18 | * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be) | 18 | * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be) |
19 | * Copyright (c) 2004-2006 Macq Electronique SA. | 19 | * Copyright (c) 2004-2006 Macq Electronique SA. |
20 | * | ||
21 | * Copyright (C) 2010 Freescale Semiconductor, Inc. | ||
20 | */ | 22 | */ |
21 | 23 | ||
22 | #include <linux/module.h> | 24 | #include <linux/module.h> |
@@ -45,29 +47,42 @@ | |||
45 | 47 | ||
46 | #include <asm/cacheflush.h> | 48 | #include <asm/cacheflush.h> |
47 | 49 | ||
48 | #ifndef CONFIG_ARCH_MXC | 50 | #ifndef CONFIG_ARM |
49 | #include <asm/coldfire.h> | 51 | #include <asm/coldfire.h> |
50 | #include <asm/mcfsim.h> | 52 | #include <asm/mcfsim.h> |
51 | #endif | 53 | #endif |
52 | 54 | ||
53 | #include "fec.h" | 55 | #include "fec.h" |
54 | 56 | ||
55 | #ifdef CONFIG_ARCH_MXC | 57 | #if defined(CONFIG_ARM) |
56 | #include <mach/hardware.h> | ||
57 | #define FEC_ALIGNMENT 0xf | 58 | #define FEC_ALIGNMENT 0xf |
58 | #else | 59 | #else |
59 | #define FEC_ALIGNMENT 0x3 | 60 | #define FEC_ALIGNMENT 0x3 |
60 | #endif | 61 | #endif |
61 | 62 | ||
62 | /* | 63 | #define DRIVER_NAME "fec" |
63 | * Define the fixed address of the FEC hardware. | 64 | |
64 | */ | 65 | /* Controller is ENET-MAC */ |
65 | #if defined(CONFIG_M5272) | 66 | #define FEC_QUIRK_ENET_MAC (1 << 0) |
67 | /* Controller needs driver to swap frame */ | ||
68 | #define FEC_QUIRK_SWAP_FRAME (1 << 1) | ||
66 | 69 | ||
67 | static unsigned char fec_mac_default[] = { | 70 | static struct platform_device_id fec_devtype[] = { |
68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 71 | { |
72 | .name = DRIVER_NAME, | ||
73 | .driver_data = 0, | ||
74 | }, { | ||
75 | .name = "imx28-fec", | ||
76 | .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME, | ||
77 | }, | ||
78 | { } | ||
69 | }; | 79 | }; |
70 | 80 | ||
81 | static unsigned char macaddr[ETH_ALEN]; | ||
82 | module_param_array(macaddr, byte, NULL, 0); | ||
83 | MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address"); | ||
84 | |||
85 | #if defined(CONFIG_M5272) | ||
71 | /* | 86 | /* |
72 | * Some hardware gets it MAC address out of local flash memory. | 87 | * Some hardware gets it MAC address out of local flash memory. |
73 | * if this is non-zero then assume it is the address to get MAC from. | 88 | * if this is non-zero then assume it is the address to get MAC from. |
@@ -133,7 +148,7 @@ static unsigned char fec_mac_default[] = { | |||
133 | * account when setting it. | 148 | * account when setting it. |
134 | */ | 149 | */ |
135 | #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \ | 150 | #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \ |
136 | defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARCH_MXC) | 151 | defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM) |
137 | #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16) | 152 | #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16) |
138 | #else | 153 | #else |
139 | #define OPT_FRAME_SIZE 0 | 154 | #define OPT_FRAME_SIZE 0 |
@@ -168,7 +183,7 @@ struct fec_enet_private { | |||
168 | struct bufdesc *rx_bd_base; | 183 | struct bufdesc *rx_bd_base; |
169 | struct bufdesc *tx_bd_base; | 184 | struct bufdesc *tx_bd_base; |
170 | /* The next free ring entry */ | 185 | /* The next free ring entry */ |
171 | struct bufdesc *cur_rx, *cur_tx; | 186 | struct bufdesc *cur_rx, *cur_tx; |
172 | /* The ring entries to be free()ed */ | 187 | /* The ring entries to be free()ed */ |
173 | struct bufdesc *dirty_tx; | 188 | struct bufdesc *dirty_tx; |
174 | 189 | ||
@@ -176,29 +191,21 @@ struct fec_enet_private { | |||
176 | /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */ | 191 | /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */ |
177 | spinlock_t hw_lock; | 192 | spinlock_t hw_lock; |
178 | 193 | ||
179 | struct platform_device *pdev; | 194 | struct platform_device *pdev; |
180 | 195 | ||
181 | int opened; | 196 | int opened; |
182 | 197 | ||
183 | /* Phylib and MDIO interface */ | 198 | /* Phylib and MDIO interface */ |
184 | struct mii_bus *mii_bus; | 199 | struct mii_bus *mii_bus; |
185 | struct phy_device *phy_dev; | 200 | struct phy_device *phy_dev; |
186 | int mii_timeout; | 201 | int mii_timeout; |
187 | uint phy_speed; | 202 | uint phy_speed; |
188 | phy_interface_t phy_interface; | 203 | phy_interface_t phy_interface; |
189 | int index; | ||
190 | int link; | 204 | int link; |
191 | int full_duplex; | 205 | int full_duplex; |
192 | struct completion mdio_done; | 206 | struct completion mdio_done; |
193 | }; | 207 | }; |
194 | 208 | ||
195 | static irqreturn_t fec_enet_interrupt(int irq, void * dev_id); | ||
196 | static void fec_enet_tx(struct net_device *dev); | ||
197 | static void fec_enet_rx(struct net_device *dev); | ||
198 | static int fec_enet_close(struct net_device *dev); | ||
199 | static void fec_restart(struct net_device *dev, int duplex); | ||
200 | static void fec_stop(struct net_device *dev); | ||
201 | |||
202 | /* FEC MII MMFR bits definition */ | 209 | /* FEC MII MMFR bits definition */ |
203 | #define FEC_MMFR_ST (1 << 30) | 210 | #define FEC_MMFR_ST (1 << 30) |
204 | #define FEC_MMFR_OP_READ (2 << 28) | 211 | #define FEC_MMFR_OP_READ (2 << 28) |
@@ -213,10 +220,23 @@ static void fec_stop(struct net_device *dev); | |||
213 | /* Transmitter timeout */ | 220 | /* Transmitter timeout */ |
214 | #define TX_TIMEOUT (2 * HZ) | 221 | #define TX_TIMEOUT (2 * HZ) |
215 | 222 | ||
223 | static void *swap_buffer(void *bufaddr, int len) | ||
224 | { | ||
225 | int i; | ||
226 | unsigned int *buf = bufaddr; | ||
227 | |||
228 | for (i = 0; i < (len + 3) / 4; i++, buf++) | ||
229 | *buf = cpu_to_be32(*buf); | ||
230 | |||
231 | return bufaddr; | ||
232 | } | ||
233 | |||
216 | static netdev_tx_t | 234 | static netdev_tx_t |
217 | fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) | 235 | fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
218 | { | 236 | { |
219 | struct fec_enet_private *fep = netdev_priv(dev); | 237 | struct fec_enet_private *fep = netdev_priv(ndev); |
238 | const struct platform_device_id *id_entry = | ||
239 | platform_get_device_id(fep->pdev); | ||
220 | struct bufdesc *bdp; | 240 | struct bufdesc *bdp; |
221 | void *bufaddr; | 241 | void *bufaddr; |
222 | unsigned short status; | 242 | unsigned short status; |
@@ -235,9 +255,9 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
235 | 255 | ||
236 | if (status & BD_ENET_TX_READY) { | 256 | if (status & BD_ENET_TX_READY) { |
237 | /* Ooops. All transmit buffers are full. Bail out. | 257 | /* Ooops. All transmit buffers are full. Bail out. |
238 | * This should not happen, since dev->tbusy should be set. | 258 | * This should not happen, since ndev->tbusy should be set. |
239 | */ | 259 | */ |
240 | printk("%s: tx queue full!.\n", dev->name); | 260 | printk("%s: tx queue full!.\n", ndev->name); |
241 | spin_unlock_irqrestore(&fep->hw_lock, flags); | 261 | spin_unlock_irqrestore(&fep->hw_lock, flags); |
242 | return NETDEV_TX_BUSY; | 262 | return NETDEV_TX_BUSY; |
243 | } | 263 | } |
@@ -257,20 +277,28 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
257 | if (((unsigned long) bufaddr) & FEC_ALIGNMENT) { | 277 | if (((unsigned long) bufaddr) & FEC_ALIGNMENT) { |
258 | unsigned int index; | 278 | unsigned int index; |
259 | index = bdp - fep->tx_bd_base; | 279 | index = bdp - fep->tx_bd_base; |
260 | memcpy(fep->tx_bounce[index], (void *)skb->data, skb->len); | 280 | memcpy(fep->tx_bounce[index], skb->data, skb->len); |
261 | bufaddr = fep->tx_bounce[index]; | 281 | bufaddr = fep->tx_bounce[index]; |
262 | } | 282 | } |
263 | 283 | ||
284 | /* | ||
285 | * Some design made an incorrect assumption on endian mode of | ||
286 | * the system that it's running on. As the result, driver has to | ||
287 | * swap every frame going to and coming from the controller. | ||
288 | */ | ||
289 | if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) | ||
290 | swap_buffer(bufaddr, skb->len); | ||
291 | |||
264 | /* Save skb pointer */ | 292 | /* Save skb pointer */ |
265 | fep->tx_skbuff[fep->skb_cur] = skb; | 293 | fep->tx_skbuff[fep->skb_cur] = skb; |
266 | 294 | ||
267 | dev->stats.tx_bytes += skb->len; | 295 | ndev->stats.tx_bytes += skb->len; |
268 | fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK; | 296 | fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK; |
269 | 297 | ||
270 | /* Push the data cache so the CPM does not get stale memory | 298 | /* Push the data cache so the CPM does not get stale memory |
271 | * data. | 299 | * data. |
272 | */ | 300 | */ |
273 | bdp->cbd_bufaddr = dma_map_single(&dev->dev, bufaddr, | 301 | bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr, |
274 | FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); | 302 | FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); |
275 | 303 | ||
276 | /* Send it on its way. Tell FEC it's ready, interrupt when done, | 304 | /* Send it on its way. Tell FEC it's ready, interrupt when done, |
@@ -291,7 +319,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
291 | 319 | ||
292 | if (bdp == fep->dirty_tx) { | 320 | if (bdp == fep->dirty_tx) { |
293 | fep->tx_full = 1; | 321 | fep->tx_full = 1; |
294 | netif_stop_queue(dev); | 322 | netif_stop_queue(ndev); |
295 | } | 323 | } |
296 | 324 | ||
297 | fep->cur_tx = bdp; | 325 | fep->cur_tx = bdp; |
@@ -301,62 +329,170 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
301 | return NETDEV_TX_OK; | 329 | return NETDEV_TX_OK; |
302 | } | 330 | } |
303 | 331 | ||
332 | /* This function is called to start or restart the FEC during a link | ||
333 | * change. This only happens when switching between half and full | ||
334 | * duplex. | ||
335 | */ | ||
304 | static void | 336 | static void |
305 | fec_timeout(struct net_device *dev) | 337 | fec_restart(struct net_device *ndev, int duplex) |
306 | { | 338 | { |
307 | struct fec_enet_private *fep = netdev_priv(dev); | 339 | struct fec_enet_private *fep = netdev_priv(ndev); |
340 | const struct platform_device_id *id_entry = | ||
341 | platform_get_device_id(fep->pdev); | ||
342 | int i; | ||
343 | u32 temp_mac[2]; | ||
344 | u32 rcntl = OPT_FRAME_SIZE | 0x04; | ||
308 | 345 | ||
309 | dev->stats.tx_errors++; | 346 | /* Whack a reset. We should wait for this. */ |
347 | writel(1, fep->hwp + FEC_ECNTRL); | ||
348 | udelay(10); | ||
310 | 349 | ||
311 | fec_restart(dev, fep->full_duplex); | 350 | /* |
312 | netif_wake_queue(dev); | 351 | * enet-mac reset will reset mac address registers too, |
313 | } | 352 | * so need to reconfigure it. |
353 | */ | ||
354 | if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) { | ||
355 | memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN); | ||
356 | writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW); | ||
357 | writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH); | ||
358 | } | ||
314 | 359 | ||
315 | static irqreturn_t | 360 | /* Clear any outstanding interrupt. */ |
316 | fec_enet_interrupt(int irq, void * dev_id) | 361 | writel(0xffc00000, fep->hwp + FEC_IEVENT); |
317 | { | ||
318 | struct net_device *dev = dev_id; | ||
319 | struct fec_enet_private *fep = netdev_priv(dev); | ||
320 | uint int_events; | ||
321 | irqreturn_t ret = IRQ_NONE; | ||
322 | 362 | ||
323 | do { | 363 | /* Reset all multicast. */ |
324 | int_events = readl(fep->hwp + FEC_IEVENT); | 364 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
325 | writel(int_events, fep->hwp + FEC_IEVENT); | 365 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
366 | #ifndef CONFIG_M5272 | ||
367 | writel(0, fep->hwp + FEC_HASH_TABLE_HIGH); | ||
368 | writel(0, fep->hwp + FEC_HASH_TABLE_LOW); | ||
369 | #endif | ||
326 | 370 | ||
327 | if (int_events & FEC_ENET_RXF) { | 371 | /* Set maximum receive buffer size. */ |
328 | ret = IRQ_HANDLED; | 372 | writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE); |
329 | fec_enet_rx(dev); | ||
330 | } | ||
331 | 373 | ||
332 | /* Transmit OK, or non-fatal error. Update the buffer | 374 | /* Set receive and transmit descriptor base. */ |
333 | * descriptors. FEC handles all errors, we just discover | 375 | writel(fep->bd_dma, fep->hwp + FEC_R_DES_START); |
334 | * them as part of the transmit process. | 376 | writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE, |
335 | */ | 377 | fep->hwp + FEC_X_DES_START); |
336 | if (int_events & FEC_ENET_TXF) { | 378 | |
337 | ret = IRQ_HANDLED; | 379 | fep->dirty_tx = fep->cur_tx = fep->tx_bd_base; |
338 | fec_enet_tx(dev); | 380 | fep->cur_rx = fep->rx_bd_base; |
381 | |||
382 | /* Reset SKB transmit buffers. */ | ||
383 | fep->skb_cur = fep->skb_dirty = 0; | ||
384 | for (i = 0; i <= TX_RING_MOD_MASK; i++) { | ||
385 | if (fep->tx_skbuff[i]) { | ||
386 | dev_kfree_skb_any(fep->tx_skbuff[i]); | ||
387 | fep->tx_skbuff[i] = NULL; | ||
339 | } | 388 | } |
389 | } | ||
340 | 390 | ||
341 | if (int_events & FEC_ENET_MII) { | 391 | /* Enable MII mode */ |
342 | ret = IRQ_HANDLED; | 392 | if (duplex) { |
343 | complete(&fep->mdio_done); | 393 | /* FD enable */ |
394 | writel(0x04, fep->hwp + FEC_X_CNTRL); | ||
395 | } else { | ||
396 | /* No Rcv on Xmit */ | ||
397 | rcntl |= 0x02; | ||
398 | writel(0x0, fep->hwp + FEC_X_CNTRL); | ||
399 | } | ||
400 | |||
401 | fep->full_duplex = duplex; | ||
402 | |||
403 | /* Set MII speed */ | ||
404 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); | ||
405 | |||
406 | /* | ||
407 | * The phy interface and speed need to get configured | ||
408 | * differently on enet-mac. | ||
409 | */ | ||
410 | if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) { | ||
411 | /* Enable flow control and length check */ | ||
412 | rcntl |= 0x40000000 | 0x00000020; | ||
413 | |||
414 | /* MII or RMII */ | ||
415 | if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) | ||
416 | rcntl |= (1 << 8); | ||
417 | else | ||
418 | rcntl &= ~(1 << 8); | ||
419 | |||
420 | /* 10M or 100M */ | ||
421 | if (fep->phy_dev && fep->phy_dev->speed == SPEED_100) | ||
422 | rcntl &= ~(1 << 9); | ||
423 | else | ||
424 | rcntl |= (1 << 9); | ||
425 | |||
426 | } else { | ||
427 | #ifdef FEC_MIIGSK_ENR | ||
428 | if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) { | ||
429 | /* disable the gasket and wait */ | ||
430 | writel(0, fep->hwp + FEC_MIIGSK_ENR); | ||
431 | while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4) | ||
432 | udelay(1); | ||
433 | |||
434 | /* | ||
435 | * configure the gasket: | ||
436 | * RMII, 50 MHz, no loopback, no echo | ||
437 | */ | ||
438 | writel(1, fep->hwp + FEC_MIIGSK_CFGR); | ||
439 | |||
440 | /* re-enable the gasket */ | ||
441 | writel(2, fep->hwp + FEC_MIIGSK_ENR); | ||
344 | } | 442 | } |
345 | } while (int_events); | 443 | #endif |
444 | } | ||
445 | writel(rcntl, fep->hwp + FEC_R_CNTRL); | ||
346 | 446 | ||
347 | return ret; | 447 | /* And last, enable the transmit and receive processing */ |
448 | writel(2, fep->hwp + FEC_ECNTRL); | ||
449 | writel(0, fep->hwp + FEC_R_DES_ACTIVE); | ||
450 | |||
451 | /* Enable interrupts we wish to service */ | ||
452 | writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); | ||
348 | } | 453 | } |
349 | 454 | ||
455 | static void | ||
456 | fec_stop(struct net_device *ndev) | ||
457 | { | ||
458 | struct fec_enet_private *fep = netdev_priv(ndev); | ||
459 | |||
460 | /* We cannot expect a graceful transmit stop without link !!! */ | ||
461 | if (fep->link) { | ||
462 | writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */ | ||
463 | udelay(10); | ||
464 | if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA)) | ||
465 | printk("fec_stop : Graceful transmit stop did not complete !\n"); | ||
466 | } | ||
467 | |||
468 | /* Whack a reset. We should wait for this. */ | ||
469 | writel(1, fep->hwp + FEC_ECNTRL); | ||
470 | udelay(10); | ||
471 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); | ||
472 | writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); | ||
473 | } | ||
474 | |||
475 | |||
476 | static void | ||
477 | fec_timeout(struct net_device *ndev) | ||
478 | { | ||
479 | struct fec_enet_private *fep = netdev_priv(ndev); | ||
480 | |||
481 | ndev->stats.tx_errors++; | ||
482 | |||
483 | fec_restart(ndev, fep->full_duplex); | ||
484 | netif_wake_queue(ndev); | ||
485 | } | ||
350 | 486 | ||
351 | static void | 487 | static void |
352 | fec_enet_tx(struct net_device *dev) | 488 | fec_enet_tx(struct net_device *ndev) |
353 | { | 489 | { |
354 | struct fec_enet_private *fep; | 490 | struct fec_enet_private *fep; |
355 | struct bufdesc *bdp; | 491 | struct bufdesc *bdp; |
356 | unsigned short status; | 492 | unsigned short status; |
357 | struct sk_buff *skb; | 493 | struct sk_buff *skb; |
358 | 494 | ||
359 | fep = netdev_priv(dev); | 495 | fep = netdev_priv(ndev); |
360 | spin_lock(&fep->hw_lock); | 496 | spin_lock(&fep->hw_lock); |
361 | bdp = fep->dirty_tx; | 497 | bdp = fep->dirty_tx; |
362 | 498 | ||
@@ -364,7 +500,8 @@ fec_enet_tx(struct net_device *dev) | |||
364 | if (bdp == fep->cur_tx && fep->tx_full == 0) | 500 | if (bdp == fep->cur_tx && fep->tx_full == 0) |
365 | break; | 501 | break; |
366 | 502 | ||
367 | dma_unmap_single(&dev->dev, bdp->cbd_bufaddr, FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); | 503 | dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, |
504 | FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); | ||
368 | bdp->cbd_bufaddr = 0; | 505 | bdp->cbd_bufaddr = 0; |
369 | 506 | ||
370 | skb = fep->tx_skbuff[fep->skb_dirty]; | 507 | skb = fep->tx_skbuff[fep->skb_dirty]; |
@@ -372,19 +509,19 @@ fec_enet_tx(struct net_device *dev) | |||
372 | if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC | | 509 | if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC | |
373 | BD_ENET_TX_RL | BD_ENET_TX_UN | | 510 | BD_ENET_TX_RL | BD_ENET_TX_UN | |
374 | BD_ENET_TX_CSL)) { | 511 | BD_ENET_TX_CSL)) { |
375 | dev->stats.tx_errors++; | 512 | ndev->stats.tx_errors++; |
376 | if (status & BD_ENET_TX_HB) /* No heartbeat */ | 513 | if (status & BD_ENET_TX_HB) /* No heartbeat */ |
377 | dev->stats.tx_heartbeat_errors++; | 514 | ndev->stats.tx_heartbeat_errors++; |
378 | if (status & BD_ENET_TX_LC) /* Late collision */ | 515 | if (status & BD_ENET_TX_LC) /* Late collision */ |
379 | dev->stats.tx_window_errors++; | 516 | ndev->stats.tx_window_errors++; |
380 | if (status & BD_ENET_TX_RL) /* Retrans limit */ | 517 | if (status & BD_ENET_TX_RL) /* Retrans limit */ |
381 | dev->stats.tx_aborted_errors++; | 518 | ndev->stats.tx_aborted_errors++; |
382 | if (status & BD_ENET_TX_UN) /* Underrun */ | 519 | if (status & BD_ENET_TX_UN) /* Underrun */ |
383 | dev->stats.tx_fifo_errors++; | 520 | ndev->stats.tx_fifo_errors++; |
384 | if (status & BD_ENET_TX_CSL) /* Carrier lost */ | 521 | if (status & BD_ENET_TX_CSL) /* Carrier lost */ |
385 | dev->stats.tx_carrier_errors++; | 522 | ndev->stats.tx_carrier_errors++; |
386 | } else { | 523 | } else { |
387 | dev->stats.tx_packets++; | 524 | ndev->stats.tx_packets++; |
388 | } | 525 | } |
389 | 526 | ||
390 | if (status & BD_ENET_TX_READY) | 527 | if (status & BD_ENET_TX_READY) |
@@ -394,7 +531,7 @@ fec_enet_tx(struct net_device *dev) | |||
394 | * but we eventually sent the packet OK. | 531 | * but we eventually sent the packet OK. |
395 | */ | 532 | */ |
396 | if (status & BD_ENET_TX_DEF) | 533 | if (status & BD_ENET_TX_DEF) |
397 | dev->stats.collisions++; | 534 | ndev->stats.collisions++; |
398 | 535 | ||
399 | /* Free the sk buffer associated with this last transmit */ | 536 | /* Free the sk buffer associated with this last transmit */ |
400 | dev_kfree_skb_any(skb); | 537 | dev_kfree_skb_any(skb); |
@@ -411,8 +548,8 @@ fec_enet_tx(struct net_device *dev) | |||
411 | */ | 548 | */ |
412 | if (fep->tx_full) { | 549 | if (fep->tx_full) { |
413 | fep->tx_full = 0; | 550 | fep->tx_full = 0; |
414 | if (netif_queue_stopped(dev)) | 551 | if (netif_queue_stopped(ndev)) |
415 | netif_wake_queue(dev); | 552 | netif_wake_queue(ndev); |
416 | } | 553 | } |
417 | } | 554 | } |
418 | fep->dirty_tx = bdp; | 555 | fep->dirty_tx = bdp; |
@@ -426,9 +563,11 @@ fec_enet_tx(struct net_device *dev) | |||
426 | * effectively tossing the packet. | 563 | * effectively tossing the packet. |
427 | */ | 564 | */ |
428 | static void | 565 | static void |
429 | fec_enet_rx(struct net_device *dev) | 566 | fec_enet_rx(struct net_device *ndev) |
430 | { | 567 | { |
431 | struct fec_enet_private *fep = netdev_priv(dev); | 568 | struct fec_enet_private *fep = netdev_priv(ndev); |
569 | const struct platform_device_id *id_entry = | ||
570 | platform_get_device_id(fep->pdev); | ||
432 | struct bufdesc *bdp; | 571 | struct bufdesc *bdp; |
433 | unsigned short status; | 572 | unsigned short status; |
434 | struct sk_buff *skb; | 573 | struct sk_buff *skb; |
@@ -460,17 +599,17 @@ fec_enet_rx(struct net_device *dev) | |||
460 | /* Check for errors. */ | 599 | /* Check for errors. */ |
461 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | | 600 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | |
462 | BD_ENET_RX_CR | BD_ENET_RX_OV)) { | 601 | BD_ENET_RX_CR | BD_ENET_RX_OV)) { |
463 | dev->stats.rx_errors++; | 602 | ndev->stats.rx_errors++; |
464 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { | 603 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { |
465 | /* Frame too long or too short. */ | 604 | /* Frame too long or too short. */ |
466 | dev->stats.rx_length_errors++; | 605 | ndev->stats.rx_length_errors++; |
467 | } | 606 | } |
468 | if (status & BD_ENET_RX_NO) /* Frame alignment */ | 607 | if (status & BD_ENET_RX_NO) /* Frame alignment */ |
469 | dev->stats.rx_frame_errors++; | 608 | ndev->stats.rx_frame_errors++; |
470 | if (status & BD_ENET_RX_CR) /* CRC Error */ | 609 | if (status & BD_ENET_RX_CR) /* CRC Error */ |
471 | dev->stats.rx_crc_errors++; | 610 | ndev->stats.rx_crc_errors++; |
472 | if (status & BD_ENET_RX_OV) /* FIFO overrun */ | 611 | if (status & BD_ENET_RX_OV) /* FIFO overrun */ |
473 | dev->stats.rx_fifo_errors++; | 612 | ndev->stats.rx_fifo_errors++; |
474 | } | 613 | } |
475 | 614 | ||
476 | /* Report late collisions as a frame error. | 615 | /* Report late collisions as a frame error. |
@@ -478,19 +617,22 @@ fec_enet_rx(struct net_device *dev) | |||
478 | * have in the buffer. So, just drop this frame on the floor. | 617 | * have in the buffer. So, just drop this frame on the floor. |
479 | */ | 618 | */ |
480 | if (status & BD_ENET_RX_CL) { | 619 | if (status & BD_ENET_RX_CL) { |
481 | dev->stats.rx_errors++; | 620 | ndev->stats.rx_errors++; |
482 | dev->stats.rx_frame_errors++; | 621 | ndev->stats.rx_frame_errors++; |
483 | goto rx_processing_done; | 622 | goto rx_processing_done; |
484 | } | 623 | } |
485 | 624 | ||
486 | /* Process the incoming frame. */ | 625 | /* Process the incoming frame. */ |
487 | dev->stats.rx_packets++; | 626 | ndev->stats.rx_packets++; |
488 | pkt_len = bdp->cbd_datlen; | 627 | pkt_len = bdp->cbd_datlen; |
489 | dev->stats.rx_bytes += pkt_len; | 628 | ndev->stats.rx_bytes += pkt_len; |
490 | data = (__u8*)__va(bdp->cbd_bufaddr); | 629 | data = (__u8*)__va(bdp->cbd_bufaddr); |
491 | 630 | ||
492 | dma_unmap_single(NULL, bdp->cbd_bufaddr, bdp->cbd_datlen, | 631 | dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, |
493 | DMA_FROM_DEVICE); | 632 | FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE); |
633 | |||
634 | if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) | ||
635 | swap_buffer(data, pkt_len); | ||
494 | 636 | ||
495 | /* This does 16 byte alignment, exactly what we need. | 637 | /* This does 16 byte alignment, exactly what we need. |
496 | * The packet length includes FCS, but we don't want to | 638 | * The packet length includes FCS, but we don't want to |
@@ -501,18 +643,18 @@ fec_enet_rx(struct net_device *dev) | |||
501 | 643 | ||
502 | if (unlikely(!skb)) { | 644 | if (unlikely(!skb)) { |
503 | printk("%s: Memory squeeze, dropping packet.\n", | 645 | printk("%s: Memory squeeze, dropping packet.\n", |
504 | dev->name); | 646 | ndev->name); |
505 | dev->stats.rx_dropped++; | 647 | ndev->stats.rx_dropped++; |
506 | } else { | 648 | } else { |
507 | skb_reserve(skb, NET_IP_ALIGN); | 649 | skb_reserve(skb, NET_IP_ALIGN); |
508 | skb_put(skb, pkt_len - 4); /* Make room */ | 650 | skb_put(skb, pkt_len - 4); /* Make room */ |
509 | skb_copy_to_linear_data(skb, data, pkt_len - 4); | 651 | skb_copy_to_linear_data(skb, data, pkt_len - 4); |
510 | skb->protocol = eth_type_trans(skb, dev); | 652 | skb->protocol = eth_type_trans(skb, ndev); |
511 | netif_rx(skb); | 653 | netif_rx(skb); |
512 | } | 654 | } |
513 | 655 | ||
514 | bdp->cbd_bufaddr = dma_map_single(NULL, data, bdp->cbd_datlen, | 656 | bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data, |
515 | DMA_FROM_DEVICE); | 657 | FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE); |
516 | rx_processing_done: | 658 | rx_processing_done: |
517 | /* Clear the status flags for this buffer */ | 659 | /* Clear the status flags for this buffer */ |
518 | status &= ~BD_ENET_RX_STATS; | 660 | status &= ~BD_ENET_RX_STATS; |
@@ -537,47 +679,97 @@ rx_processing_done: | |||
537 | spin_unlock(&fep->hw_lock); | 679 | spin_unlock(&fep->hw_lock); |
538 | } | 680 | } |
539 | 681 | ||
682 | static irqreturn_t | ||
683 | fec_enet_interrupt(int irq, void *dev_id) | ||
684 | { | ||
685 | struct net_device *ndev = dev_id; | ||
686 | struct fec_enet_private *fep = netdev_priv(ndev); | ||
687 | uint int_events; | ||
688 | irqreturn_t ret = IRQ_NONE; | ||
689 | |||
690 | do { | ||
691 | int_events = readl(fep->hwp + FEC_IEVENT); | ||
692 | writel(int_events, fep->hwp + FEC_IEVENT); | ||
693 | |||
694 | if (int_events & FEC_ENET_RXF) { | ||
695 | ret = IRQ_HANDLED; | ||
696 | fec_enet_rx(ndev); | ||
697 | } | ||
698 | |||
699 | /* Transmit OK, or non-fatal error. Update the buffer | ||
700 | * descriptors. FEC handles all errors, we just discover | ||
701 | * them as part of the transmit process. | ||
702 | */ | ||
703 | if (int_events & FEC_ENET_TXF) { | ||
704 | ret = IRQ_HANDLED; | ||
705 | fec_enet_tx(ndev); | ||
706 | } | ||
707 | |||
708 | if (int_events & FEC_ENET_MII) { | ||
709 | ret = IRQ_HANDLED; | ||
710 | complete(&fep->mdio_done); | ||
711 | } | ||
712 | } while (int_events); | ||
713 | |||
714 | return ret; | ||
715 | } | ||
716 | |||
717 | |||
718 | |||
540 | /* ------------------------------------------------------------------------- */ | 719 | /* ------------------------------------------------------------------------- */ |
541 | #ifdef CONFIG_M5272 | 720 | static void __inline__ fec_get_mac(struct net_device *ndev) |
542 | static void __inline__ fec_get_mac(struct net_device *dev) | ||
543 | { | 721 | { |
544 | struct fec_enet_private *fep = netdev_priv(dev); | 722 | struct fec_enet_private *fep = netdev_priv(ndev); |
723 | struct fec_platform_data *pdata = fep->pdev->dev.platform_data; | ||
545 | unsigned char *iap, tmpaddr[ETH_ALEN]; | 724 | unsigned char *iap, tmpaddr[ETH_ALEN]; |
546 | 725 | ||
547 | if (FEC_FLASHMAC) { | 726 | /* |
548 | /* | 727 | * try to get mac address in following order: |
549 | * Get MAC address from FLASH. | 728 | * |
550 | * If it is all 1's or 0's, use the default. | 729 | * 1) module parameter via kernel command line in form |
551 | */ | 730 | * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0 |
552 | iap = (unsigned char *)FEC_FLASHMAC; | 731 | */ |
553 | if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) && | 732 | iap = macaddr; |
554 | (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0)) | 733 | |
555 | iap = fec_mac_default; | 734 | /* |
556 | if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) && | 735 | * 2) from flash or fuse (via platform data) |
557 | (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff)) | 736 | */ |
558 | iap = fec_mac_default; | 737 | if (!is_valid_ether_addr(iap)) { |
559 | } else { | 738 | #ifdef CONFIG_M5272 |
560 | *((unsigned long *) &tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW); | 739 | if (FEC_FLASHMAC) |
561 | *((unsigned short *) &tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH) >> 16); | 740 | iap = (unsigned char *)FEC_FLASHMAC; |
741 | #else | ||
742 | if (pdata) | ||
743 | memcpy(iap, pdata->mac, ETH_ALEN); | ||
744 | #endif | ||
745 | } | ||
746 | |||
747 | /* | ||
748 | * 3) FEC mac registers set by bootloader | ||
749 | */ | ||
750 | if (!is_valid_ether_addr(iap)) { | ||
751 | *((unsigned long *) &tmpaddr[0]) = | ||
752 | be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW)); | ||
753 | *((unsigned short *) &tmpaddr[4]) = | ||
754 | be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16); | ||
562 | iap = &tmpaddr[0]; | 755 | iap = &tmpaddr[0]; |
563 | } | 756 | } |
564 | 757 | ||
565 | memcpy(dev->dev_addr, iap, ETH_ALEN); | 758 | memcpy(ndev->dev_addr, iap, ETH_ALEN); |
566 | 759 | ||
567 | /* Adjust MAC if using default MAC address */ | 760 | /* Adjust MAC if using macaddr */ |
568 | if (iap == fec_mac_default) | 761 | if (iap == macaddr) |
569 | dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index; | 762 | ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->pdev->id; |
570 | } | 763 | } |
571 | #endif | ||
572 | 764 | ||
573 | /* ------------------------------------------------------------------------- */ | 765 | /* ------------------------------------------------------------------------- */ |
574 | 766 | ||
575 | /* | 767 | /* |
576 | * Phy section | 768 | * Phy section |
577 | */ | 769 | */ |
578 | static void fec_enet_adjust_link(struct net_device *dev) | 770 | static void fec_enet_adjust_link(struct net_device *ndev) |
579 | { | 771 | { |
580 | struct fec_enet_private *fep = netdev_priv(dev); | 772 | struct fec_enet_private *fep = netdev_priv(ndev); |
581 | struct phy_device *phy_dev = fep->phy_dev; | 773 | struct phy_device *phy_dev = fep->phy_dev; |
582 | unsigned long flags; | 774 | unsigned long flags; |
583 | 775 | ||
@@ -594,7 +786,7 @@ static void fec_enet_adjust_link(struct net_device *dev) | |||
594 | /* Duplex link change */ | 786 | /* Duplex link change */ |
595 | if (phy_dev->link) { | 787 | if (phy_dev->link) { |
596 | if (fep->full_duplex != phy_dev->duplex) { | 788 | if (fep->full_duplex != phy_dev->duplex) { |
597 | fec_restart(dev, phy_dev->duplex); | 789 | fec_restart(ndev, phy_dev->duplex); |
598 | status_change = 1; | 790 | status_change = 1; |
599 | } | 791 | } |
600 | } | 792 | } |
@@ -603,9 +795,9 @@ static void fec_enet_adjust_link(struct net_device *dev) | |||
603 | if (phy_dev->link != fep->link) { | 795 | if (phy_dev->link != fep->link) { |
604 | fep->link = phy_dev->link; | 796 | fep->link = phy_dev->link; |
605 | if (phy_dev->link) | 797 | if (phy_dev->link) |
606 | fec_restart(dev, phy_dev->duplex); | 798 | fec_restart(ndev, phy_dev->duplex); |
607 | else | 799 | else |
608 | fec_stop(dev); | 800 | fec_stop(ndev); |
609 | status_change = 1; | 801 | status_change = 1; |
610 | } | 802 | } |
611 | 803 | ||
@@ -651,8 +843,8 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum, | |||
651 | fep->mii_timeout = 0; | 843 | fep->mii_timeout = 0; |
652 | init_completion(&fep->mdio_done); | 844 | init_completion(&fep->mdio_done); |
653 | 845 | ||
654 | /* start a read op */ | 846 | /* start a write op */ |
655 | writel(FEC_MMFR_ST | FEC_MMFR_OP_READ | | 847 | writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE | |
656 | FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) | | 848 | FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) | |
657 | FEC_MMFR_TA | FEC_MMFR_DATA(value), | 849 | FEC_MMFR_TA | FEC_MMFR_DATA(value), |
658 | fep->hwp + FEC_MII_DATA); | 850 | fep->hwp + FEC_MII_DATA); |
@@ -674,13 +866,14 @@ static int fec_enet_mdio_reset(struct mii_bus *bus) | |||
674 | return 0; | 866 | return 0; |
675 | } | 867 | } |
676 | 868 | ||
677 | static int fec_enet_mii_probe(struct net_device *dev) | 869 | static int fec_enet_mii_probe(struct net_device *ndev) |
678 | { | 870 | { |
679 | struct fec_enet_private *fep = netdev_priv(dev); | 871 | struct fec_enet_private *fep = netdev_priv(ndev); |
680 | struct phy_device *phy_dev = NULL; | 872 | struct phy_device *phy_dev = NULL; |
681 | char mdio_bus_id[MII_BUS_ID_SIZE]; | 873 | char mdio_bus_id[MII_BUS_ID_SIZE]; |
682 | char phy_name[MII_BUS_ID_SIZE + 3]; | 874 | char phy_name[MII_BUS_ID_SIZE + 3]; |
683 | int phy_id; | 875 | int phy_id; |
876 | int dev_id = fep->pdev->id; | ||
684 | 877 | ||
685 | fep->phy_dev = NULL; | 878 | fep->phy_dev = NULL; |
686 | 879 | ||
@@ -692,22 +885,24 @@ static int fec_enet_mii_probe(struct net_device *dev) | |||
692 | continue; | 885 | continue; |
693 | if (fep->mii_bus->phy_map[phy_id]->phy_id == 0) | 886 | if (fep->mii_bus->phy_map[phy_id]->phy_id == 0) |
694 | continue; | 887 | continue; |
888 | if (dev_id--) | ||
889 | continue; | ||
695 | strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE); | 890 | strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE); |
696 | break; | 891 | break; |
697 | } | 892 | } |
698 | 893 | ||
699 | if (phy_id >= PHY_MAX_ADDR) { | 894 | if (phy_id >= PHY_MAX_ADDR) { |
700 | printk(KERN_INFO "%s: no PHY, assuming direct connection " | 895 | printk(KERN_INFO "%s: no PHY, assuming direct connection " |
701 | "to switch\n", dev->name); | 896 | "to switch\n", ndev->name); |
702 | strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE); | 897 | strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE); |
703 | phy_id = 0; | 898 | phy_id = 0; |
704 | } | 899 | } |
705 | 900 | ||
706 | snprintf(phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id); | 901 | snprintf(phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id); |
707 | phy_dev = phy_connect(dev, phy_name, &fec_enet_adjust_link, 0, | 902 | phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, 0, |
708 | PHY_INTERFACE_MODE_MII); | 903 | PHY_INTERFACE_MODE_MII); |
709 | if (IS_ERR(phy_dev)) { | 904 | if (IS_ERR(phy_dev)) { |
710 | printk(KERN_ERR "%s: could not attach to PHY\n", dev->name); | 905 | printk(KERN_ERR "%s: could not attach to PHY\n", ndev->name); |
711 | return PTR_ERR(phy_dev); | 906 | return PTR_ERR(phy_dev); |
712 | } | 907 | } |
713 | 908 | ||
@@ -720,7 +915,7 @@ static int fec_enet_mii_probe(struct net_device *dev) | |||
720 | fep->full_duplex = 0; | 915 | fep->full_duplex = 0; |
721 | 916 | ||
722 | printk(KERN_INFO "%s: Freescale FEC PHY driver [%s] " | 917 | printk(KERN_INFO "%s: Freescale FEC PHY driver [%s] " |
723 | "(mii_bus:phy_addr=%s, irq=%d)\n", dev->name, | 918 | "(mii_bus:phy_addr=%s, irq=%d)\n", ndev->name, |
724 | fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev), | 919 | fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev), |
725 | fep->phy_dev->irq); | 920 | fep->phy_dev->irq); |
726 | 921 | ||
@@ -729,10 +924,35 @@ static int fec_enet_mii_probe(struct net_device *dev) | |||
729 | 924 | ||
730 | static int fec_enet_mii_init(struct platform_device *pdev) | 925 | static int fec_enet_mii_init(struct platform_device *pdev) |
731 | { | 926 | { |
732 | struct net_device *dev = platform_get_drvdata(pdev); | 927 | static struct mii_bus *fec0_mii_bus; |
733 | struct fec_enet_private *fep = netdev_priv(dev); | 928 | struct net_device *ndev = platform_get_drvdata(pdev); |
929 | struct fec_enet_private *fep = netdev_priv(ndev); | ||
930 | const struct platform_device_id *id_entry = | ||
931 | platform_get_device_id(fep->pdev); | ||
734 | int err = -ENXIO, i; | 932 | int err = -ENXIO, i; |
735 | 933 | ||
934 | /* | ||
935 | * The dual fec interfaces are not equivalent with enet-mac. | ||
936 | * Here are the differences: | ||
937 | * | ||
938 | * - fec0 supports MII & RMII modes while fec1 only supports RMII | ||
939 | * - fec0 acts as the 1588 time master while fec1 is slave | ||
940 | * - external phys can only be configured by fec0 | ||
941 | * | ||
942 | * That is to say fec1 can not work independently. It only works | ||
943 | * when fec0 is working. The reason behind this design is that the | ||
944 | * second interface is added primarily for Switch mode. | ||
945 | * | ||
946 | * Because of the last point above, both phys are attached on fec0 | ||
947 | * mdio interface in board design, and need to be configured by | ||
948 | * fec0 mii_bus. | ||
949 | */ | ||
950 | if ((id_entry->driver_data & FEC_QUIRK_ENET_MAC) && pdev->id) { | ||
951 | /* fec1 uses fec0 mii_bus */ | ||
952 | fep->mii_bus = fec0_mii_bus; | ||
953 | return 0; | ||
954 | } | ||
955 | |||
736 | fep->mii_timeout = 0; | 956 | fep->mii_timeout = 0; |
737 | 957 | ||
738 | /* | 958 | /* |
@@ -764,11 +984,13 @@ static int fec_enet_mii_init(struct platform_device *pdev) | |||
764 | for (i = 0; i < PHY_MAX_ADDR; i++) | 984 | for (i = 0; i < PHY_MAX_ADDR; i++) |
765 | fep->mii_bus->irq[i] = PHY_POLL; | 985 | fep->mii_bus->irq[i] = PHY_POLL; |
766 | 986 | ||
767 | platform_set_drvdata(dev, fep->mii_bus); | ||
768 | |||
769 | if (mdiobus_register(fep->mii_bus)) | 987 | if (mdiobus_register(fep->mii_bus)) |
770 | goto err_out_free_mdio_irq; | 988 | goto err_out_free_mdio_irq; |
771 | 989 | ||
990 | /* save fec0 mii_bus */ | ||
991 | if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) | ||
992 | fec0_mii_bus = fep->mii_bus; | ||
993 | |||
772 | return 0; | 994 | return 0; |
773 | 995 | ||
774 | err_out_free_mdio_irq: | 996 | err_out_free_mdio_irq: |
@@ -788,10 +1010,10 @@ static void fec_enet_mii_remove(struct fec_enet_private *fep) | |||
788 | mdiobus_free(fep->mii_bus); | 1010 | mdiobus_free(fep->mii_bus); |
789 | } | 1011 | } |
790 | 1012 | ||
791 | static int fec_enet_get_settings(struct net_device *dev, | 1013 | static int fec_enet_get_settings(struct net_device *ndev, |
792 | struct ethtool_cmd *cmd) | 1014 | struct ethtool_cmd *cmd) |
793 | { | 1015 | { |
794 | struct fec_enet_private *fep = netdev_priv(dev); | 1016 | struct fec_enet_private *fep = netdev_priv(ndev); |
795 | struct phy_device *phydev = fep->phy_dev; | 1017 | struct phy_device *phydev = fep->phy_dev; |
796 | 1018 | ||
797 | if (!phydev) | 1019 | if (!phydev) |
@@ -800,10 +1022,10 @@ static int fec_enet_get_settings(struct net_device *dev, | |||
800 | return phy_ethtool_gset(phydev, cmd); | 1022 | return phy_ethtool_gset(phydev, cmd); |
801 | } | 1023 | } |
802 | 1024 | ||
803 | static int fec_enet_set_settings(struct net_device *dev, | 1025 | static int fec_enet_set_settings(struct net_device *ndev, |
804 | struct ethtool_cmd *cmd) | 1026 | struct ethtool_cmd *cmd) |
805 | { | 1027 | { |
806 | struct fec_enet_private *fep = netdev_priv(dev); | 1028 | struct fec_enet_private *fep = netdev_priv(ndev); |
807 | struct phy_device *phydev = fep->phy_dev; | 1029 | struct phy_device *phydev = fep->phy_dev; |
808 | 1030 | ||
809 | if (!phydev) | 1031 | if (!phydev) |
@@ -812,14 +1034,14 @@ static int fec_enet_set_settings(struct net_device *dev, | |||
812 | return phy_ethtool_sset(phydev, cmd); | 1034 | return phy_ethtool_sset(phydev, cmd); |
813 | } | 1035 | } |
814 | 1036 | ||
815 | static void fec_enet_get_drvinfo(struct net_device *dev, | 1037 | static void fec_enet_get_drvinfo(struct net_device *ndev, |
816 | struct ethtool_drvinfo *info) | 1038 | struct ethtool_drvinfo *info) |
817 | { | 1039 | { |
818 | struct fec_enet_private *fep = netdev_priv(dev); | 1040 | struct fec_enet_private *fep = netdev_priv(ndev); |
819 | 1041 | ||
820 | strcpy(info->driver, fep->pdev->dev.driver->name); | 1042 | strcpy(info->driver, fep->pdev->dev.driver->name); |
821 | strcpy(info->version, "Revision: 1.0"); | 1043 | strcpy(info->version, "Revision: 1.0"); |
822 | strcpy(info->bus_info, dev_name(&dev->dev)); | 1044 | strcpy(info->bus_info, dev_name(&ndev->dev)); |
823 | } | 1045 | } |
824 | 1046 | ||
825 | static struct ethtool_ops fec_enet_ethtool_ops = { | 1047 | static struct ethtool_ops fec_enet_ethtool_ops = { |
@@ -829,12 +1051,12 @@ static struct ethtool_ops fec_enet_ethtool_ops = { | |||
829 | .get_link = ethtool_op_get_link, | 1051 | .get_link = ethtool_op_get_link, |
830 | }; | 1052 | }; |
831 | 1053 | ||
832 | static int fec_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | 1054 | static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) |
833 | { | 1055 | { |
834 | struct fec_enet_private *fep = netdev_priv(dev); | 1056 | struct fec_enet_private *fep = netdev_priv(ndev); |
835 | struct phy_device *phydev = fep->phy_dev; | 1057 | struct phy_device *phydev = fep->phy_dev; |
836 | 1058 | ||
837 | if (!netif_running(dev)) | 1059 | if (!netif_running(ndev)) |
838 | return -EINVAL; | 1060 | return -EINVAL; |
839 | 1061 | ||
840 | if (!phydev) | 1062 | if (!phydev) |
@@ -843,9 +1065,9 @@ static int fec_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |||
843 | return phy_mii_ioctl(phydev, rq, cmd); | 1065 | return phy_mii_ioctl(phydev, rq, cmd); |
844 | } | 1066 | } |
845 | 1067 | ||
846 | static void fec_enet_free_buffers(struct net_device *dev) | 1068 | static void fec_enet_free_buffers(struct net_device *ndev) |
847 | { | 1069 | { |
848 | struct fec_enet_private *fep = netdev_priv(dev); | 1070 | struct fec_enet_private *fep = netdev_priv(ndev); |
849 | int i; | 1071 | int i; |
850 | struct sk_buff *skb; | 1072 | struct sk_buff *skb; |
851 | struct bufdesc *bdp; | 1073 | struct bufdesc *bdp; |
@@ -855,7 +1077,7 @@ static void fec_enet_free_buffers(struct net_device *dev) | |||
855 | skb = fep->rx_skbuff[i]; | 1077 | skb = fep->rx_skbuff[i]; |
856 | 1078 | ||
857 | if (bdp->cbd_bufaddr) | 1079 | if (bdp->cbd_bufaddr) |
858 | dma_unmap_single(&dev->dev, bdp->cbd_bufaddr, | 1080 | dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, |
859 | FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); | 1081 | FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); |
860 | if (skb) | 1082 | if (skb) |
861 | dev_kfree_skb(skb); | 1083 | dev_kfree_skb(skb); |
@@ -867,9 +1089,9 @@ static void fec_enet_free_buffers(struct net_device *dev) | |||
867 | kfree(fep->tx_bounce[i]); | 1089 | kfree(fep->tx_bounce[i]); |
868 | } | 1090 | } |
869 | 1091 | ||
870 | static int fec_enet_alloc_buffers(struct net_device *dev) | 1092 | static int fec_enet_alloc_buffers(struct net_device *ndev) |
871 | { | 1093 | { |
872 | struct fec_enet_private *fep = netdev_priv(dev); | 1094 | struct fec_enet_private *fep = netdev_priv(ndev); |
873 | int i; | 1095 | int i; |
874 | struct sk_buff *skb; | 1096 | struct sk_buff *skb; |
875 | struct bufdesc *bdp; | 1097 | struct bufdesc *bdp; |
@@ -878,12 +1100,12 @@ static int fec_enet_alloc_buffers(struct net_device *dev) | |||
878 | for (i = 0; i < RX_RING_SIZE; i++) { | 1100 | for (i = 0; i < RX_RING_SIZE; i++) { |
879 | skb = dev_alloc_skb(FEC_ENET_RX_FRSIZE); | 1101 | skb = dev_alloc_skb(FEC_ENET_RX_FRSIZE); |
880 | if (!skb) { | 1102 | if (!skb) { |
881 | fec_enet_free_buffers(dev); | 1103 | fec_enet_free_buffers(ndev); |
882 | return -ENOMEM; | 1104 | return -ENOMEM; |
883 | } | 1105 | } |
884 | fep->rx_skbuff[i] = skb; | 1106 | fep->rx_skbuff[i] = skb; |
885 | 1107 | ||
886 | bdp->cbd_bufaddr = dma_map_single(&dev->dev, skb->data, | 1108 | bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data, |
887 | FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); | 1109 | FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); |
888 | bdp->cbd_sc = BD_ENET_RX_EMPTY; | 1110 | bdp->cbd_sc = BD_ENET_RX_EMPTY; |
889 | bdp++; | 1111 | bdp++; |
@@ -910,45 +1132,47 @@ static int fec_enet_alloc_buffers(struct net_device *dev) | |||
910 | } | 1132 | } |
911 | 1133 | ||
912 | static int | 1134 | static int |
913 | fec_enet_open(struct net_device *dev) | 1135 | fec_enet_open(struct net_device *ndev) |
914 | { | 1136 | { |
915 | struct fec_enet_private *fep = netdev_priv(dev); | 1137 | struct fec_enet_private *fep = netdev_priv(ndev); |
916 | int ret; | 1138 | int ret; |
917 | 1139 | ||
918 | /* I should reset the ring buffers here, but I don't yet know | 1140 | /* I should reset the ring buffers here, but I don't yet know |
919 | * a simple way to do that. | 1141 | * a simple way to do that. |
920 | */ | 1142 | */ |
921 | 1143 | ||
922 | ret = fec_enet_alloc_buffers(dev); | 1144 | ret = fec_enet_alloc_buffers(ndev); |
923 | if (ret) | 1145 | if (ret) |
924 | return ret; | 1146 | return ret; |
925 | 1147 | ||
926 | /* Probe and connect to PHY when open the interface */ | 1148 | /* Probe and connect to PHY when open the interface */ |
927 | ret = fec_enet_mii_probe(dev); | 1149 | ret = fec_enet_mii_probe(ndev); |
928 | if (ret) { | 1150 | if (ret) { |
929 | fec_enet_free_buffers(dev); | 1151 | fec_enet_free_buffers(ndev); |
930 | return ret; | 1152 | return ret; |
931 | } | 1153 | } |
932 | phy_start(fep->phy_dev); | 1154 | phy_start(fep->phy_dev); |
933 | netif_start_queue(dev); | 1155 | netif_start_queue(ndev); |
934 | fep->opened = 1; | 1156 | fep->opened = 1; |
935 | return 0; | 1157 | return 0; |
936 | } | 1158 | } |
937 | 1159 | ||
938 | static int | 1160 | static int |
939 | fec_enet_close(struct net_device *dev) | 1161 | fec_enet_close(struct net_device *ndev) |
940 | { | 1162 | { |
941 | struct fec_enet_private *fep = netdev_priv(dev); | 1163 | struct fec_enet_private *fep = netdev_priv(ndev); |
942 | 1164 | ||
943 | /* Don't know what to do yet. */ | 1165 | /* Don't know what to do yet. */ |
944 | fep->opened = 0; | 1166 | fep->opened = 0; |
945 | netif_stop_queue(dev); | 1167 | netif_stop_queue(ndev); |
946 | fec_stop(dev); | 1168 | fec_stop(ndev); |
947 | 1169 | ||
948 | if (fep->phy_dev) | 1170 | if (fep->phy_dev) { |
1171 | phy_stop(fep->phy_dev); | ||
949 | phy_disconnect(fep->phy_dev); | 1172 | phy_disconnect(fep->phy_dev); |
1173 | } | ||
950 | 1174 | ||
951 | fec_enet_free_buffers(dev); | 1175 | fec_enet_free_buffers(ndev); |
952 | 1176 | ||
953 | return 0; | 1177 | return 0; |
954 | } | 1178 | } |
@@ -966,14 +1190,14 @@ fec_enet_close(struct net_device *dev) | |||
966 | #define HASH_BITS 6 /* #bits in hash */ | 1190 | #define HASH_BITS 6 /* #bits in hash */ |
967 | #define CRC32_POLY 0xEDB88320 | 1191 | #define CRC32_POLY 0xEDB88320 |
968 | 1192 | ||
969 | static void set_multicast_list(struct net_device *dev) | 1193 | static void set_multicast_list(struct net_device *ndev) |
970 | { | 1194 | { |
971 | struct fec_enet_private *fep = netdev_priv(dev); | 1195 | struct fec_enet_private *fep = netdev_priv(ndev); |
972 | struct netdev_hw_addr *ha; | 1196 | struct netdev_hw_addr *ha; |
973 | unsigned int i, bit, data, crc, tmp; | 1197 | unsigned int i, bit, data, crc, tmp; |
974 | unsigned char hash; | 1198 | unsigned char hash; |
975 | 1199 | ||
976 | if (dev->flags & IFF_PROMISC) { | 1200 | if (ndev->flags & IFF_PROMISC) { |
977 | tmp = readl(fep->hwp + FEC_R_CNTRL); | 1201 | tmp = readl(fep->hwp + FEC_R_CNTRL); |
978 | tmp |= 0x8; | 1202 | tmp |= 0x8; |
979 | writel(tmp, fep->hwp + FEC_R_CNTRL); | 1203 | writel(tmp, fep->hwp + FEC_R_CNTRL); |
@@ -984,7 +1208,7 @@ static void set_multicast_list(struct net_device *dev) | |||
984 | tmp &= ~0x8; | 1208 | tmp &= ~0x8; |
985 | writel(tmp, fep->hwp + FEC_R_CNTRL); | 1209 | writel(tmp, fep->hwp + FEC_R_CNTRL); |
986 | 1210 | ||
987 | if (dev->flags & IFF_ALLMULTI) { | 1211 | if (ndev->flags & IFF_ALLMULTI) { |
988 | /* Catch all multicast addresses, so set the | 1212 | /* Catch all multicast addresses, so set the |
989 | * filter to all 1's | 1213 | * filter to all 1's |
990 | */ | 1214 | */ |
@@ -999,7 +1223,7 @@ static void set_multicast_list(struct net_device *dev) | |||
999 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); | 1223 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
1000 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); | 1224 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
1001 | 1225 | ||
1002 | netdev_for_each_mc_addr(ha, dev) { | 1226 | netdev_for_each_mc_addr(ha, ndev) { |
1003 | /* Only support group multicast for now */ | 1227 | /* Only support group multicast for now */ |
1004 | if (!(ha->addr[0] & 1)) | 1228 | if (!(ha->addr[0] & 1)) |
1005 | continue; | 1229 | continue; |
@@ -1007,7 +1231,7 @@ static void set_multicast_list(struct net_device *dev) | |||
1007 | /* calculate crc32 value of mac address */ | 1231 | /* calculate crc32 value of mac address */ |
1008 | crc = 0xffffffff; | 1232 | crc = 0xffffffff; |
1009 | 1233 | ||
1010 | for (i = 0; i < dev->addr_len; i++) { | 1234 | for (i = 0; i < ndev->addr_len; i++) { |
1011 | data = ha->addr[i]; | 1235 | data = ha->addr[i]; |
1012 | for (bit = 0; bit < 8; bit++, data >>= 1) { | 1236 | for (bit = 0; bit < 8; bit++, data >>= 1) { |
1013 | crc = (crc >> 1) ^ | 1237 | crc = (crc >> 1) ^ |
@@ -1034,20 +1258,20 @@ static void set_multicast_list(struct net_device *dev) | |||
1034 | 1258 | ||
1035 | /* Set a MAC change in hardware. */ | 1259 | /* Set a MAC change in hardware. */ |
1036 | static int | 1260 | static int |
1037 | fec_set_mac_address(struct net_device *dev, void *p) | 1261 | fec_set_mac_address(struct net_device *ndev, void *p) |
1038 | { | 1262 | { |
1039 | struct fec_enet_private *fep = netdev_priv(dev); | 1263 | struct fec_enet_private *fep = netdev_priv(ndev); |
1040 | struct sockaddr *addr = p; | 1264 | struct sockaddr *addr = p; |
1041 | 1265 | ||
1042 | if (!is_valid_ether_addr(addr->sa_data)) | 1266 | if (!is_valid_ether_addr(addr->sa_data)) |
1043 | return -EADDRNOTAVAIL; | 1267 | return -EADDRNOTAVAIL; |
1044 | 1268 | ||
1045 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); | 1269 | memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len); |
1046 | 1270 | ||
1047 | writel(dev->dev_addr[3] | (dev->dev_addr[2] << 8) | | 1271 | writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) | |
1048 | (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24), | 1272 | (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24), |
1049 | fep->hwp + FEC_ADDR_LOW); | 1273 | fep->hwp + FEC_ADDR_LOW); |
1050 | writel((dev->dev_addr[5] << 16) | (dev->dev_addr[4] << 24), | 1274 | writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24), |
1051 | fep->hwp + FEC_ADDR_HIGH); | 1275 | fep->hwp + FEC_ADDR_HIGH); |
1052 | return 0; | 1276 | return 0; |
1053 | } | 1277 | } |
@@ -1061,17 +1285,16 @@ static const struct net_device_ops fec_netdev_ops = { | |||
1061 | .ndo_validate_addr = eth_validate_addr, | 1285 | .ndo_validate_addr = eth_validate_addr, |
1062 | .ndo_tx_timeout = fec_timeout, | 1286 | .ndo_tx_timeout = fec_timeout, |
1063 | .ndo_set_mac_address = fec_set_mac_address, | 1287 | .ndo_set_mac_address = fec_set_mac_address, |
1064 | .ndo_do_ioctl = fec_enet_ioctl, | 1288 | .ndo_do_ioctl = fec_enet_ioctl, |
1065 | }; | 1289 | }; |
1066 | 1290 | ||
1067 | /* | 1291 | /* |
1068 | * XXX: We need to clean up on failure exits here. | 1292 | * XXX: We need to clean up on failure exits here. |
1069 | * | 1293 | * |
1070 | * index is only used in legacy code | ||
1071 | */ | 1294 | */ |
1072 | static int fec_enet_init(struct net_device *dev, int index) | 1295 | static int fec_enet_init(struct net_device *ndev) |
1073 | { | 1296 | { |
1074 | struct fec_enet_private *fep = netdev_priv(dev); | 1297 | struct fec_enet_private *fep = netdev_priv(ndev); |
1075 | struct bufdesc *cbd_base; | 1298 | struct bufdesc *cbd_base; |
1076 | struct bufdesc *bdp; | 1299 | struct bufdesc *bdp; |
1077 | int i; | 1300 | int i; |
@@ -1086,35 +1309,19 @@ static int fec_enet_init(struct net_device *dev, int index) | |||
1086 | 1309 | ||
1087 | spin_lock_init(&fep->hw_lock); | 1310 | spin_lock_init(&fep->hw_lock); |
1088 | 1311 | ||
1089 | fep->index = index; | 1312 | fep->netdev = ndev; |
1090 | fep->hwp = (void __iomem *)dev->base_addr; | ||
1091 | fep->netdev = dev; | ||
1092 | 1313 | ||
1093 | /* Set the Ethernet address */ | 1314 | /* Get the Ethernet address */ |
1094 | #ifdef CONFIG_M5272 | 1315 | fec_get_mac(ndev); |
1095 | fec_get_mac(dev); | ||
1096 | #else | ||
1097 | { | ||
1098 | unsigned long l; | ||
1099 | l = readl(fep->hwp + FEC_ADDR_LOW); | ||
1100 | dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24); | ||
1101 | dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16); | ||
1102 | dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8); | ||
1103 | dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0); | ||
1104 | l = readl(fep->hwp + FEC_ADDR_HIGH); | ||
1105 | dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24); | ||
1106 | dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16); | ||
1107 | } | ||
1108 | #endif | ||
1109 | 1316 | ||
1110 | /* Set receive and transmit descriptor base. */ | 1317 | /* Set receive and transmit descriptor base. */ |
1111 | fep->rx_bd_base = cbd_base; | 1318 | fep->rx_bd_base = cbd_base; |
1112 | fep->tx_bd_base = cbd_base + RX_RING_SIZE; | 1319 | fep->tx_bd_base = cbd_base + RX_RING_SIZE; |
1113 | 1320 | ||
1114 | /* The FEC Ethernet specific entries in the device structure */ | 1321 | /* The FEC Ethernet specific entries in the device structure */ |
1115 | dev->watchdog_timeo = TX_TIMEOUT; | 1322 | ndev->watchdog_timeo = TX_TIMEOUT; |
1116 | dev->netdev_ops = &fec_netdev_ops; | 1323 | ndev->netdev_ops = &fec_netdev_ops; |
1117 | dev->ethtool_ops = &fec_enet_ethtool_ops; | 1324 | ndev->ethtool_ops = &fec_enet_ethtool_ops; |
1118 | 1325 | ||
1119 | /* Initialize the receive buffer descriptors. */ | 1326 | /* Initialize the receive buffer descriptors. */ |
1120 | bdp = fep->rx_bd_base; | 1327 | bdp = fep->rx_bd_base; |
@@ -1143,114 +1350,11 @@ static int fec_enet_init(struct net_device *dev, int index) | |||
1143 | bdp--; | 1350 | bdp--; |
1144 | bdp->cbd_sc |= BD_SC_WRAP; | 1351 | bdp->cbd_sc |= BD_SC_WRAP; |
1145 | 1352 | ||
1146 | fec_restart(dev, 0); | 1353 | fec_restart(ndev, 0); |
1147 | 1354 | ||
1148 | return 0; | 1355 | return 0; |
1149 | } | 1356 | } |
1150 | 1357 | ||
1151 | /* This function is called to start or restart the FEC during a link | ||
1152 | * change. This only happens when switching between half and full | ||
1153 | * duplex. | ||
1154 | */ | ||
1155 | static void | ||
1156 | fec_restart(struct net_device *dev, int duplex) | ||
1157 | { | ||
1158 | struct fec_enet_private *fep = netdev_priv(dev); | ||
1159 | int i; | ||
1160 | |||
1161 | /* Whack a reset. We should wait for this. */ | ||
1162 | writel(1, fep->hwp + FEC_ECNTRL); | ||
1163 | udelay(10); | ||
1164 | |||
1165 | /* Clear any outstanding interrupt. */ | ||
1166 | writel(0xffc00000, fep->hwp + FEC_IEVENT); | ||
1167 | |||
1168 | /* Reset all multicast. */ | ||
1169 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); | ||
1170 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); | ||
1171 | #ifndef CONFIG_M5272 | ||
1172 | writel(0, fep->hwp + FEC_HASH_TABLE_HIGH); | ||
1173 | writel(0, fep->hwp + FEC_HASH_TABLE_LOW); | ||
1174 | #endif | ||
1175 | |||
1176 | /* Set maximum receive buffer size. */ | ||
1177 | writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE); | ||
1178 | |||
1179 | /* Set receive and transmit descriptor base. */ | ||
1180 | writel(fep->bd_dma, fep->hwp + FEC_R_DES_START); | ||
1181 | writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE, | ||
1182 | fep->hwp + FEC_X_DES_START); | ||
1183 | |||
1184 | fep->dirty_tx = fep->cur_tx = fep->tx_bd_base; | ||
1185 | fep->cur_rx = fep->rx_bd_base; | ||
1186 | |||
1187 | /* Reset SKB transmit buffers. */ | ||
1188 | fep->skb_cur = fep->skb_dirty = 0; | ||
1189 | for (i = 0; i <= TX_RING_MOD_MASK; i++) { | ||
1190 | if (fep->tx_skbuff[i]) { | ||
1191 | dev_kfree_skb_any(fep->tx_skbuff[i]); | ||
1192 | fep->tx_skbuff[i] = NULL; | ||
1193 | } | ||
1194 | } | ||
1195 | |||
1196 | /* Enable MII mode */ | ||
1197 | if (duplex) { | ||
1198 | /* MII enable / FD enable */ | ||
1199 | writel(OPT_FRAME_SIZE | 0x04, fep->hwp + FEC_R_CNTRL); | ||
1200 | writel(0x04, fep->hwp + FEC_X_CNTRL); | ||
1201 | } else { | ||
1202 | /* MII enable / No Rcv on Xmit */ | ||
1203 | writel(OPT_FRAME_SIZE | 0x06, fep->hwp + FEC_R_CNTRL); | ||
1204 | writel(0x0, fep->hwp + FEC_X_CNTRL); | ||
1205 | } | ||
1206 | fep->full_duplex = duplex; | ||
1207 | |||
1208 | /* Set MII speed */ | ||
1209 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); | ||
1210 | |||
1211 | #ifdef FEC_MIIGSK_ENR | ||
1212 | if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) { | ||
1213 | /* disable the gasket and wait */ | ||
1214 | writel(0, fep->hwp + FEC_MIIGSK_ENR); | ||
1215 | while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4) | ||
1216 | udelay(1); | ||
1217 | |||
1218 | /* configure the gasket: RMII, 50 MHz, no loopback, no echo */ | ||
1219 | writel(1, fep->hwp + FEC_MIIGSK_CFGR); | ||
1220 | |||
1221 | /* re-enable the gasket */ | ||
1222 | writel(2, fep->hwp + FEC_MIIGSK_ENR); | ||
1223 | } | ||
1224 | #endif | ||
1225 | |||
1226 | /* And last, enable the transmit and receive processing */ | ||
1227 | writel(2, fep->hwp + FEC_ECNTRL); | ||
1228 | writel(0, fep->hwp + FEC_R_DES_ACTIVE); | ||
1229 | |||
1230 | /* Enable interrupts we wish to service */ | ||
1231 | writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); | ||
1232 | } | ||
1233 | |||
1234 | static void | ||
1235 | fec_stop(struct net_device *dev) | ||
1236 | { | ||
1237 | struct fec_enet_private *fep = netdev_priv(dev); | ||
1238 | |||
1239 | /* We cannot expect a graceful transmit stop without link !!! */ | ||
1240 | if (fep->link) { | ||
1241 | writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */ | ||
1242 | udelay(10); | ||
1243 | if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA)) | ||
1244 | printk("fec_stop : Graceful transmit stop did not complete !\n"); | ||
1245 | } | ||
1246 | |||
1247 | /* Whack a reset. We should wait for this. */ | ||
1248 | writel(1, fep->hwp + FEC_ECNTRL); | ||
1249 | udelay(10); | ||
1250 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); | ||
1251 | writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK); | ||
1252 | } | ||
1253 | |||
1254 | static int __devinit | 1358 | static int __devinit |
1255 | fec_probe(struct platform_device *pdev) | 1359 | fec_probe(struct platform_device *pdev) |
1256 | { | 1360 | { |
@@ -1270,19 +1374,20 @@ fec_probe(struct platform_device *pdev) | |||
1270 | 1374 | ||
1271 | /* Init network device */ | 1375 | /* Init network device */ |
1272 | ndev = alloc_etherdev(sizeof(struct fec_enet_private)); | 1376 | ndev = alloc_etherdev(sizeof(struct fec_enet_private)); |
1273 | if (!ndev) | 1377 | if (!ndev) { |
1274 | return -ENOMEM; | 1378 | ret = -ENOMEM; |
1379 | goto failed_alloc_etherdev; | ||
1380 | } | ||
1275 | 1381 | ||
1276 | SET_NETDEV_DEV(ndev, &pdev->dev); | 1382 | SET_NETDEV_DEV(ndev, &pdev->dev); |
1277 | 1383 | ||
1278 | /* setup board info structure */ | 1384 | /* setup board info structure */ |
1279 | fep = netdev_priv(ndev); | 1385 | fep = netdev_priv(ndev); |
1280 | memset(fep, 0, sizeof(*fep)); | ||
1281 | 1386 | ||
1282 | ndev->base_addr = (unsigned long)ioremap(r->start, resource_size(r)); | 1387 | fep->hwp = ioremap(r->start, resource_size(r)); |
1283 | fep->pdev = pdev; | 1388 | fep->pdev = pdev; |
1284 | 1389 | ||
1285 | if (!ndev->base_addr) { | 1390 | if (!fep->hwp) { |
1286 | ret = -ENOMEM; | 1391 | ret = -ENOMEM; |
1287 | goto failed_ioremap; | 1392 | goto failed_ioremap; |
1288 | } | 1393 | } |
@@ -1300,10 +1405,9 @@ fec_probe(struct platform_device *pdev) | |||
1300 | break; | 1405 | break; |
1301 | ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev); | 1406 | ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev); |
1302 | if (ret) { | 1407 | if (ret) { |
1303 | while (i >= 0) { | 1408 | while (--i >= 0) { |
1304 | irq = platform_get_irq(pdev, i); | 1409 | irq = platform_get_irq(pdev, i); |
1305 | free_irq(irq, ndev); | 1410 | free_irq(irq, ndev); |
1306 | i--; | ||
1307 | } | 1411 | } |
1308 | goto failed_irq; | 1412 | goto failed_irq; |
1309 | } | 1413 | } |
@@ -1316,7 +1420,7 @@ fec_probe(struct platform_device *pdev) | |||
1316 | } | 1420 | } |
1317 | clk_enable(fep->clk); | 1421 | clk_enable(fep->clk); |
1318 | 1422 | ||
1319 | ret = fec_enet_init(ndev, 0); | 1423 | ret = fec_enet_init(ndev); |
1320 | if (ret) | 1424 | if (ret) |
1321 | goto failed_init; | 1425 | goto failed_init; |
1322 | 1426 | ||
@@ -1346,9 +1450,11 @@ failed_clk: | |||
1346 | free_irq(irq, ndev); | 1450 | free_irq(irq, ndev); |
1347 | } | 1451 | } |
1348 | failed_irq: | 1452 | failed_irq: |
1349 | iounmap((void __iomem *)ndev->base_addr); | 1453 | iounmap(fep->hwp); |
1350 | failed_ioremap: | 1454 | failed_ioremap: |
1351 | free_netdev(ndev); | 1455 | free_netdev(ndev); |
1456 | failed_alloc_etherdev: | ||
1457 | release_mem_region(r->start, resource_size(r)); | ||
1352 | 1458 | ||
1353 | return ret; | 1459 | return ret; |
1354 | } | 1460 | } |
@@ -1358,16 +1464,22 @@ fec_drv_remove(struct platform_device *pdev) | |||
1358 | { | 1464 | { |
1359 | struct net_device *ndev = platform_get_drvdata(pdev); | 1465 | struct net_device *ndev = platform_get_drvdata(pdev); |
1360 | struct fec_enet_private *fep = netdev_priv(ndev); | 1466 | struct fec_enet_private *fep = netdev_priv(ndev); |
1361 | 1467 | struct resource *r; | |
1362 | platform_set_drvdata(pdev, NULL); | ||
1363 | 1468 | ||
1364 | fec_stop(ndev); | 1469 | fec_stop(ndev); |
1365 | fec_enet_mii_remove(fep); | 1470 | fec_enet_mii_remove(fep); |
1366 | clk_disable(fep->clk); | 1471 | clk_disable(fep->clk); |
1367 | clk_put(fep->clk); | 1472 | clk_put(fep->clk); |
1368 | iounmap((void __iomem *)ndev->base_addr); | 1473 | iounmap(fep->hwp); |
1369 | unregister_netdev(ndev); | 1474 | unregister_netdev(ndev); |
1370 | free_netdev(ndev); | 1475 | free_netdev(ndev); |
1476 | |||
1477 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1478 | BUG_ON(!r); | ||
1479 | release_mem_region(r->start, resource_size(r)); | ||
1480 | |||
1481 | platform_set_drvdata(pdev, NULL); | ||
1482 | |||
1371 | return 0; | 1483 | return 0; |
1372 | } | 1484 | } |
1373 | 1485 | ||
@@ -1376,14 +1488,14 @@ static int | |||
1376 | fec_suspend(struct device *dev) | 1488 | fec_suspend(struct device *dev) |
1377 | { | 1489 | { |
1378 | struct net_device *ndev = dev_get_drvdata(dev); | 1490 | struct net_device *ndev = dev_get_drvdata(dev); |
1379 | struct fec_enet_private *fep; | 1491 | struct fec_enet_private *fep = netdev_priv(ndev); |
1380 | 1492 | ||
1381 | if (ndev) { | 1493 | if (netif_running(ndev)) { |
1382 | fep = netdev_priv(ndev); | 1494 | fec_stop(ndev); |
1383 | if (netif_running(ndev)) | 1495 | netif_device_detach(ndev); |
1384 | fec_enet_close(ndev); | ||
1385 | clk_disable(fep->clk); | ||
1386 | } | 1496 | } |
1497 | clk_disable(fep->clk); | ||
1498 | |||
1387 | return 0; | 1499 | return 0; |
1388 | } | 1500 | } |
1389 | 1501 | ||
@@ -1391,14 +1503,14 @@ static int | |||
1391 | fec_resume(struct device *dev) | 1503 | fec_resume(struct device *dev) |
1392 | { | 1504 | { |
1393 | struct net_device *ndev = dev_get_drvdata(dev); | 1505 | struct net_device *ndev = dev_get_drvdata(dev); |
1394 | struct fec_enet_private *fep; | 1506 | struct fec_enet_private *fep = netdev_priv(ndev); |
1395 | 1507 | ||
1396 | if (ndev) { | 1508 | clk_enable(fep->clk); |
1397 | fep = netdev_priv(ndev); | 1509 | if (netif_running(ndev)) { |
1398 | clk_enable(fep->clk); | 1510 | fec_restart(ndev, fep->full_duplex); |
1399 | if (netif_running(ndev)) | 1511 | netif_device_attach(ndev); |
1400 | fec_enet_open(ndev); | ||
1401 | } | 1512 | } |
1513 | |||
1402 | return 0; | 1514 | return 0; |
1403 | } | 1515 | } |
1404 | 1516 | ||
@@ -1414,12 +1526,13 @@ static const struct dev_pm_ops fec_pm_ops = { | |||
1414 | 1526 | ||
1415 | static struct platform_driver fec_driver = { | 1527 | static struct platform_driver fec_driver = { |
1416 | .driver = { | 1528 | .driver = { |
1417 | .name = "fec", | 1529 | .name = DRIVER_NAME, |
1418 | .owner = THIS_MODULE, | 1530 | .owner = THIS_MODULE, |
1419 | #ifdef CONFIG_PM | 1531 | #ifdef CONFIG_PM |
1420 | .pm = &fec_pm_ops, | 1532 | .pm = &fec_pm_ops, |
1421 | #endif | 1533 | #endif |
1422 | }, | 1534 | }, |
1535 | .id_table = fec_devtype, | ||
1423 | .probe = fec_probe, | 1536 | .probe = fec_probe, |
1424 | .remove = __devexit_p(fec_drv_remove), | 1537 | .remove = __devexit_p(fec_drv_remove), |
1425 | }; | 1538 | }; |