2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; version 2 of the License
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 * Copyright (C) 2009 John Crispin <blogic@openwrt.org>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/types.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/init.h>
23 #include <linux/skbuff.h>
24 #include <linux/etherdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/platform_device.h>
27 #include <linux/phy.h>
29 #include <ramips_eth_platform.h>
30 #include "ramips_eth.h"
32 #define TX_TIMEOUT (20 * HZ / 100)
33 #define MAX_RX_LENGTH 1600
35 #ifdef CONFIG_RALINK_RT305X
36 #include "ramips_esw.c"
38 static inline int rt305x_esw_init(void) { return 0; }
39 static inline void rt305x_esw_exit(void) { }
42 #define phys_to_bus(a) (a & 0x1FFFFFFF)
44 #ifdef CONFIG_RAMIPS_ETH_DEBUG
45 #define RADEBUG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
47 #define RADEBUG(fmt, args...) do {} while (0)
50 static struct net_device
* ramips_dev
;
51 static void __iomem
*ramips_fe_base
= 0;
54 ramips_fe_wr(u32 val
, unsigned reg
)
56 __raw_writel(val
, ramips_fe_base
+ reg
);
60 ramips_fe_rr(unsigned reg
)
62 return __raw_readl(ramips_fe_base
+ reg
);
66 ramips_fe_int_disable(u32 mask
)
68 ramips_fe_wr(ramips_fe_rr(RAMIPS_FE_INT_ENABLE
) & ~mask
,
69 RAMIPS_FE_INT_ENABLE
);
71 ramips_fe_rr(RAMIPS_FE_INT_ENABLE
);
75 ramips_fe_int_enable(u32 mask
)
77 ramips_fe_wr(ramips_fe_rr(RAMIPS_FE_INT_ENABLE
) | mask
,
78 RAMIPS_FE_INT_ENABLE
);
80 ramips_fe_rr(RAMIPS_FE_INT_ENABLE
);
84 ramips_hw_set_macaddr(unsigned char *mac
)
86 ramips_fe_wr((mac
[0] << 8) | mac
[1], RAMIPS_GDMA1_MAC_ADRH
);
87 ramips_fe_wr((mac
[2] << 24) | (mac
[3] << 16) | (mac
[4] << 8) | mac
[5],
88 RAMIPS_GDMA1_MAC_ADRL
);
91 #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT3883)
93 #define RAMIPS_MDIO_RETRY 1000
95 static unsigned char *ramips_speed_str(struct raeth_priv
*re
)
109 static void ramips_link_adjust(struct raeth_priv
*re
)
111 struct ramips_eth_platform_data
*pdata
;
114 pdata
= re
->parent
->platform_data
;
116 netif_carrier_off(re
->netdev
);
117 netdev_info(re
->netdev
, "link down\n");
121 mdio_cfg
= RAMIPS_MDIO_CFG_TX_CLK_SKEW_200
|
122 RAMIPS_MDIO_CFG_TX_CLK_SKEW_200
|
123 RAMIPS_MDIO_CFG_GP1_FRC_EN
;
125 if (re
->duplex
== DUPLEX_FULL
)
126 mdio_cfg
|= RAMIPS_MDIO_CFG_GP1_DUPLEX
;
129 mdio_cfg
|= RAMIPS_MDIO_CFG_GP1_FC_TX
;
132 mdio_cfg
|= RAMIPS_MDIO_CFG_GP1_FC_RX
;
136 mdio_cfg
|= RAMIPS_MDIO_CFG_GP1_SPEED_10
;
139 mdio_cfg
|= RAMIPS_MDIO_CFG_GP1_SPEED_100
;
142 mdio_cfg
|= RAMIPS_MDIO_CFG_GP1_SPEED_1000
;
148 ramips_fe_wr(mdio_cfg
, RAMIPS_MDIO_CFG
);
150 netif_carrier_on(re
->netdev
);
151 netdev_info(re
->netdev
, "link up (%sMbps/%s duplex)\n",
152 ramips_speed_str(re
),
153 (DUPLEX_FULL
== re
->duplex
) ? "Full" : "Half");
157 ramips_mdio_wait_ready(struct raeth_priv
*re
)
161 retries
= RAMIPS_MDIO_RETRY
;
165 t
= ramips_fe_rr(RAMIPS_MDIO_ACCESS
);
166 if ((t
& (0x1 << 31)) == 0)
175 dev_err(re
->parent
, "MDIO operation timed out\n");
180 ramips_mdio_read(struct mii_bus
*bus
, int phy_addr
, int phy_reg
)
182 struct raeth_priv
*re
= bus
->priv
;
186 err
= ramips_mdio_wait_ready(re
);
190 t
= (phy_addr
<< 24) | (phy_reg
<< 16);
191 ramips_fe_wr(t
, RAMIPS_MDIO_ACCESS
);
193 ramips_fe_wr(t
, RAMIPS_MDIO_ACCESS
);
195 err
= ramips_mdio_wait_ready(re
);
199 RADEBUG("%s: addr=%04x, reg=%04x, value=%04x\n", __func__
,
200 phy_addr
, phy_reg
, ramips_fe_rr(RAMIPS_MDIO_ACCESS
) & 0xffff);
202 return ramips_fe_rr(RAMIPS_MDIO_ACCESS
) & 0xffff;
206 ramips_mdio_write(struct mii_bus
*bus
, int phy_addr
, int phy_reg
, u16 val
)
208 struct raeth_priv
*re
= bus
->priv
;
212 RADEBUG("%s: addr=%04x, reg=%04x, value=%04x\n", __func__
,
213 phy_addr
, phy_reg
, ramips_fe_rr(RAMIPS_MDIO_ACCESS
) & 0xffff);
215 err
= ramips_mdio_wait_ready(re
);
219 t
= (1 << 30) | (phy_addr
<< 24) | (phy_reg
<< 16) | val
;
220 ramips_fe_wr(t
, RAMIPS_MDIO_ACCESS
);
222 ramips_fe_wr(t
, RAMIPS_MDIO_ACCESS
);
224 return ramips_mdio_wait_ready(re
);
228 ramips_mdio_reset(struct mii_bus
*bus
)
235 ramips_mdio_init(struct raeth_priv
*re
)
240 re
->mii_bus
= mdiobus_alloc();
241 if (re
->mii_bus
== NULL
)
244 re
->mii_bus
->name
= "ramips_mdio";
245 re
->mii_bus
->read
= ramips_mdio_read
;
246 re
->mii_bus
->write
= ramips_mdio_write
;
247 re
->mii_bus
->reset
= ramips_mdio_reset
;
248 re
->mii_bus
->irq
= re
->mii_irq
;
249 re
->mii_bus
->priv
= re
;
250 re
->mii_bus
->parent
= re
->parent
;
252 snprintf(re
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%s", "ramips_mdio");
253 re
->mii_bus
->phy_mask
= 0;
255 for (i
= 0; i
< PHY_MAX_ADDR
; i
++)
256 re
->mii_irq
[i
] = PHY_POLL
;
258 err
= mdiobus_register(re
->mii_bus
);
270 ramips_mdio_cleanup(struct raeth_priv
*re
)
272 mdiobus_unregister(re
->mii_bus
);
277 ramips_phy_link_adjust(struct net_device
*dev
)
279 struct raeth_priv
*re
= netdev_priv(dev
);
280 struct phy_device
*phydev
= re
->phy_dev
;
282 int status_change
= 0;
284 spin_lock_irqsave(&re
->phy_lock
, flags
);
287 if (re
->duplex
!= phydev
->duplex
||
288 re
->speed
!= phydev
->speed
)
291 if (phydev
->link
!= re
->link
)
294 re
->link
= phydev
->link
;
295 re
->duplex
= phydev
->duplex
;
296 re
->speed
= phydev
->speed
;
299 ramips_link_adjust(re
);
301 spin_unlock_irqrestore(&re
->phy_lock
, flags
);
305 ramips_phy_connect_multi(struct raeth_priv
*re
)
307 struct net_device
*netdev
= re
->netdev
;
308 struct ramips_eth_platform_data
*pdata
;
309 struct phy_device
*phydev
= NULL
;
313 pdata
= re
->parent
->platform_data
;
314 for (phy_addr
= 0; phy_addr
< PHY_MAX_ADDR
; phy_addr
++) {
315 if (!(pdata
->phy_mask
& (1 << phy_addr
)))
318 if (re
->mii_bus
->phy_map
[phy_addr
] == NULL
)
321 RADEBUG("%s: PHY found at %s, uid=%08x\n",
323 dev_name(&re
->mii_bus
->phy_map
[phy_addr
]->dev
),
324 re
->mii_bus
->phy_map
[phy_addr
]->phy_id
);
327 phydev
= re
->mii_bus
->phy_map
[phy_addr
];
331 netdev_err(netdev
, "no PHY found with phy_mask=%08x\n",
336 re
->phy_dev
= phy_connect(netdev
, dev_name(&phydev
->dev
),
337 ramips_phy_link_adjust
, 0,
340 if (IS_ERR(re
->phy_dev
)) {
341 netdev_err(netdev
, "could not connect to PHY at %s\n",
342 dev_name(&phydev
->dev
));
343 return PTR_ERR(re
->phy_dev
);
346 phydev
->supported
&= PHY_GBIT_FEATURES
;
347 phydev
->advertising
= phydev
->supported
;
349 RADEBUG("%s: connected to PHY at %s [uid=%08x, driver=%s]\n",
350 netdev
->name
, dev_name(&phydev
->dev
),
351 phydev
->phy_id
, phydev
->drv
->name
);
363 ramips_phy_connect_fixed(struct raeth_priv
*re
)
365 struct ramips_eth_platform_data
*pdata
;
367 pdata
= re
->parent
->platform_data
;
368 switch (pdata
->speed
) {
374 netdev_err(re
->netdev
, "invalid speed specified\n");
378 RADEBUG("%s: using fixed link parameters\n", re
->netdev
->name
);
380 re
->speed
= pdata
->speed
;
381 re
->duplex
= pdata
->duplex
;
382 re
->tx_fc
= pdata
->tx_fc
;
383 re
->rx_fc
= pdata
->tx_fc
;
389 ramips_phy_connect(struct raeth_priv
*re
)
391 struct ramips_eth_platform_data
*pdata
;
393 pdata
= re
->parent
->platform_data
;
395 return ramips_phy_connect_multi(re
);
397 return ramips_phy_connect_fixed(re
);
401 ramips_phy_disconnect(struct raeth_priv
*re
)
404 phy_disconnect(re
->phy_dev
);
408 ramips_phy_start(struct raeth_priv
*re
)
413 phy_start(re
->phy_dev
);
415 spin_lock_irqsave(&re
->phy_lock
, flags
);
417 ramips_link_adjust(re
);
418 spin_unlock_irqrestore(&re
->phy_lock
, flags
);
423 ramips_phy_stop(struct raeth_priv
*re
)
428 phy_stop(re
->phy_dev
);
430 spin_lock_irqsave(&re
->phy_lock
, flags
);
432 ramips_link_adjust(re
);
433 spin_unlock_irqrestore(&re
->phy_lock
, flags
);
437 ramips_mdio_init(struct raeth_priv
*re
)
443 ramips_mdio_cleanup(struct raeth_priv
*re
)
448 ramips_phy_connect(struct raeth_priv
*re
)
454 ramips_phy_disconnect(struct raeth_priv
*re
)
459 ramips_phy_start(struct raeth_priv
*re
)
464 ramips_phy_stop(struct raeth_priv
*re
)
467 #endif /* CONFIG_RALINK_RT288X || CONFIG_RALINK_RT3883 */
470 ramips_cleanup_dma(struct raeth_priv
*re
)
474 for (i
= 0; i
< NUM_RX_DESC
; i
++)
476 dma_unmap_single(&re
->netdev
->dev
, re
->rx_dma
[i
],
477 MAX_RX_LENGTH
, DMA_FROM_DEVICE
);
478 dev_kfree_skb_any(re
->rx_skb
[i
]);
482 dma_free_coherent(&re
->netdev
->dev
,
483 NUM_RX_DESC
* sizeof(struct ramips_rx_dma
),
484 re
->rx
, re
->rx_desc_dma
);
487 dma_free_coherent(&re
->netdev
->dev
,
488 NUM_TX_DESC
* sizeof(struct ramips_tx_dma
),
489 re
->tx
, re
->tx_desc_dma
);
493 ramips_alloc_dma(struct raeth_priv
*re
)
498 re
->skb_free_idx
= 0;
501 re
->tx
= dma_alloc_coherent(&re
->netdev
->dev
,
502 NUM_TX_DESC
* sizeof(struct ramips_tx_dma
),
503 &re
->tx_desc_dma
, GFP_ATOMIC
);
507 memset(re
->tx
, 0, NUM_TX_DESC
* sizeof(struct ramips_tx_dma
));
508 for (i
= 0; i
< NUM_TX_DESC
; i
++) {
509 re
->tx
[i
].txd2
= TX_DMA_LSO
| TX_DMA_DONE
;
510 re
->tx
[i
].txd4
= TX_DMA_QN(3) | TX_DMA_PN(1);
514 re
->rx
= dma_alloc_coherent(&re
->netdev
->dev
,
515 NUM_RX_DESC
* sizeof(struct ramips_rx_dma
),
516 &re
->rx_desc_dma
, GFP_ATOMIC
);
520 memset(re
->rx
, 0, sizeof(struct ramips_rx_dma
) * NUM_RX_DESC
);
521 for (i
= 0; i
< NUM_RX_DESC
; i
++) {
523 struct sk_buff
*new_skb
= dev_alloc_skb(MAX_RX_LENGTH
+
529 skb_reserve(new_skb
, NET_IP_ALIGN
);
531 dma_addr
= dma_map_single(&re
->netdev
->dev
, new_skb
->data
,
532 MAX_RX_LENGTH
, DMA_FROM_DEVICE
);
533 re
->rx_dma
[i
] = dma_addr
;
534 re
->rx
[i
].rxd1
= (unsigned int) re
->rx_dma
[i
];
535 re
->rx
[i
].rxd2
|= RX_DMA_LSO
;
536 re
->rx_skb
[i
] = new_skb
;
542 ramips_cleanup_dma(re
);
547 ramips_setup_dma(struct raeth_priv
*re
)
549 ramips_fe_wr(re
->tx_desc_dma
, RAMIPS_TX_BASE_PTR0
);
550 ramips_fe_wr(NUM_TX_DESC
, RAMIPS_TX_MAX_CNT0
);
551 ramips_fe_wr(0, RAMIPS_TX_CTX_IDX0
);
552 ramips_fe_wr(RAMIPS_PST_DTX_IDX0
, RAMIPS_PDMA_RST_CFG
);
554 ramips_fe_wr(re
->rx_desc_dma
, RAMIPS_RX_BASE_PTR0
);
555 ramips_fe_wr(NUM_RX_DESC
, RAMIPS_RX_MAX_CNT0
);
556 ramips_fe_wr((NUM_RX_DESC
- 1), RAMIPS_RX_CALC_IDX0
);
557 ramips_fe_wr(RAMIPS_PST_DRX_IDX0
, RAMIPS_PDMA_RST_CFG
);
561 ramips_eth_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
563 struct raeth_priv
*re
= netdev_priv(dev
);
565 unsigned int tx_next
;
566 dma_addr_t mapped_addr
;
568 if (re
->plat
->min_pkt_len
) {
569 if (skb
->len
< re
->plat
->min_pkt_len
) {
570 if (skb_padto(skb
, re
->plat
->min_pkt_len
)) {
572 "ramips_eth: skb_padto failed\n");
576 skb_put(skb
, re
->plat
->min_pkt_len
- skb
->len
);
580 dev
->trans_start
= jiffies
;
581 mapped_addr
= dma_map_single(&re
->netdev
->dev
, skb
->data
, skb
->len
,
584 spin_lock(&re
->page_lock
);
585 tx
= ramips_fe_rr(RAMIPS_TX_CTX_IDX0
);
586 tx_next
= (tx
+ 1) % NUM_TX_DESC
;
588 if ((re
->tx_skb
[tx
]) || (re
->tx_skb
[tx_next
]) ||
589 !(re
->tx
[tx
].txd2
& TX_DMA_DONE
) ||
590 !(re
->tx
[tx_next
].txd2
& TX_DMA_DONE
))
593 re
->tx
[tx
].txd1
= (unsigned int) mapped_addr
;
594 re
->tx
[tx
].txd2
&= ~(TX_DMA_PLEN0_MASK
| TX_DMA_DONE
);
595 re
->tx
[tx
].txd2
|= TX_DMA_PLEN0(skb
->len
);
596 dev
->stats
.tx_packets
++;
597 dev
->stats
.tx_bytes
+= skb
->len
;
598 re
->tx_skb
[tx
] = skb
;
600 ramips_fe_wr(tx_next
, RAMIPS_TX_CTX_IDX0
);
601 spin_unlock(&re
->page_lock
);
605 spin_unlock(&re
->page_lock
);
606 dev
->stats
.tx_dropped
++;
612 ramips_eth_rx_hw(unsigned long ptr
)
614 struct net_device
*dev
= (struct net_device
*) ptr
;
615 struct raeth_priv
*re
= netdev_priv(dev
);
620 struct sk_buff
*rx_skb
, *new_skb
;
623 rx
= (ramips_fe_rr(RAMIPS_RX_CALC_IDX0
) + 1) % NUM_RX_DESC
;
624 if (!(re
->rx
[rx
].rxd2
& RX_DMA_DONE
))
628 rx_skb
= re
->rx_skb
[rx
];
629 pktlen
= RX_DMA_PLEN0(re
->rx
[rx
].rxd2
);
631 new_skb
= netdev_alloc_skb(dev
, MAX_RX_LENGTH
+ NET_IP_ALIGN
);
632 /* Reuse the buffer on allocation failures */
636 dma_unmap_single(&re
->netdev
->dev
, re
->rx_dma
[rx
],
637 MAX_RX_LENGTH
, DMA_FROM_DEVICE
);
639 skb_put(rx_skb
, pktlen
);
641 rx_skb
->protocol
= eth_type_trans(rx_skb
, dev
);
642 rx_skb
->ip_summed
= CHECKSUM_NONE
;
643 dev
->stats
.rx_packets
++;
644 dev
->stats
.rx_bytes
+= pktlen
;
647 re
->rx_skb
[rx
] = new_skb
;
648 skb_reserve(new_skb
, NET_IP_ALIGN
);
650 dma_addr
= dma_map_single(&re
->netdev
->dev
,
654 re
->rx_dma
[rx
] = dma_addr
;
655 re
->rx
[rx
].rxd1
= (unsigned int) dma_addr
;
657 dev
->stats
.rx_dropped
++;
660 re
->rx
[rx
].rxd2
&= ~RX_DMA_DONE
;
662 ramips_fe_wr(rx
, RAMIPS_RX_CALC_IDX0
);
666 tasklet_schedule(&re
->rx_tasklet
);
668 ramips_fe_int_enable(RAMIPS_RX_DLY_INT
);
672 ramips_eth_tx_housekeeping(unsigned long ptr
)
674 struct net_device
*dev
= (struct net_device
*)ptr
;
675 struct raeth_priv
*re
= netdev_priv(dev
);
677 spin_lock(&re
->page_lock
);
678 while ((re
->tx
[re
->skb_free_idx
].txd2
& TX_DMA_DONE
) &&
679 (re
->tx_skb
[re
->skb_free_idx
])) {
680 dev_kfree_skb_irq(re
->tx_skb
[re
->skb_free_idx
]);
681 re
->tx_skb
[re
->skb_free_idx
] = 0;
683 if (re
->skb_free_idx
>= NUM_TX_DESC
)
684 re
->skb_free_idx
= 0;
686 spin_unlock(&re
->page_lock
);
688 ramips_fe_int_enable(RAMIPS_TX_DLY_INT
);
692 ramips_eth_timeout(struct net_device
*dev
)
694 struct raeth_priv
*re
= netdev_priv(dev
);
696 tasklet_schedule(&re
->tx_housekeeping_tasklet
);
700 ramips_eth_irq(int irq
, void *dev
)
702 struct raeth_priv
*re
= netdev_priv(dev
);
703 unsigned long fe_int
= ramips_fe_rr(RAMIPS_FE_INT_STATUS
);
705 ramips_fe_wr(0xFFFFFFFF, RAMIPS_FE_INT_STATUS
);
707 if (fe_int
& RAMIPS_RX_DLY_INT
) {
708 ramips_fe_int_disable(RAMIPS_RX_DLY_INT
);
709 tasklet_schedule(&re
->rx_tasklet
);
712 if (fe_int
& RAMIPS_TX_DLY_INT
) {
713 ramips_fe_int_disable(RAMIPS_TX_DLY_INT
);
714 tasklet_schedule(&re
->tx_housekeeping_tasklet
);
721 ramips_eth_open(struct net_device
*dev
)
723 struct raeth_priv
*re
= netdev_priv(dev
);
726 err
= request_irq(dev
->irq
, ramips_eth_irq
, IRQF_DISABLED
,
731 err
= ramips_alloc_dma(re
);
735 ramips_hw_set_macaddr(dev
->dev_addr
);
737 ramips_setup_dma(re
);
738 ramips_fe_wr((ramips_fe_rr(RAMIPS_PDMA_GLO_CFG
) & 0xff) |
739 (RAMIPS_TX_WB_DDONE
| RAMIPS_RX_DMA_EN
|
740 RAMIPS_TX_DMA_EN
| RAMIPS_PDMA_SIZE_4DWORDS
),
741 RAMIPS_PDMA_GLO_CFG
);
742 ramips_fe_wr((ramips_fe_rr(RAMIPS_FE_GLO_CFG
) &
743 ~(RAMIPS_US_CYC_CNT_MASK
<< RAMIPS_US_CYC_CNT_SHIFT
)) |
744 ((re
->plat
->sys_freq
/ RAMIPS_US_CYC_CNT_DIVISOR
) << RAMIPS_US_CYC_CNT_SHIFT
),
747 tasklet_init(&re
->tx_housekeeping_tasklet
, ramips_eth_tx_housekeeping
,
749 tasklet_init(&re
->rx_tasklet
, ramips_eth_rx_hw
, (unsigned long)dev
);
751 ramips_phy_start(re
);
753 ramips_fe_wr(RAMIPS_DELAY_INIT
, RAMIPS_DLY_INT_CFG
);
754 ramips_fe_wr(RAMIPS_TX_DLY_INT
| RAMIPS_RX_DLY_INT
, RAMIPS_FE_INT_ENABLE
);
755 ramips_fe_wr(ramips_fe_rr(RAMIPS_GDMA1_FWD_CFG
) &
756 ~(RAMIPS_GDM1_ICS_EN
| RAMIPS_GDM1_TCS_EN
| RAMIPS_GDM1_UCS_EN
| 0xffff),
757 RAMIPS_GDMA1_FWD_CFG
);
758 ramips_fe_wr(ramips_fe_rr(RAMIPS_CDMA_CSG_CFG
) &
759 ~(RAMIPS_ICS_GEN_EN
| RAMIPS_TCS_GEN_EN
| RAMIPS_UCS_GEN_EN
),
760 RAMIPS_CDMA_CSG_CFG
);
761 ramips_fe_wr(RAMIPS_PSE_FQFC_CFG_INIT
, RAMIPS_PSE_FQ_CFG
);
762 ramips_fe_wr(1, RAMIPS_FE_RST_GL
);
763 ramips_fe_wr(0, RAMIPS_FE_RST_GL
);
765 netif_start_queue(dev
);
769 free_irq(dev
->irq
, dev
);
774 ramips_eth_stop(struct net_device
*dev
)
776 struct raeth_priv
*re
= netdev_priv(dev
);
778 ramips_fe_wr(ramips_fe_rr(RAMIPS_PDMA_GLO_CFG
) &
779 ~(RAMIPS_TX_WB_DDONE
| RAMIPS_RX_DMA_EN
| RAMIPS_TX_DMA_EN
),
780 RAMIPS_PDMA_GLO_CFG
);
782 /* disable all interrupts in the hw */
783 ramips_fe_wr(0, RAMIPS_FE_INT_ENABLE
);
786 free_irq(dev
->irq
, dev
);
787 netif_stop_queue(dev
);
788 tasklet_kill(&re
->tx_housekeeping_tasklet
);
789 tasklet_kill(&re
->rx_tasklet
);
790 ramips_cleanup_dma(re
);
791 RADEBUG("ramips_eth: stopped\n");
796 ramips_eth_probe(struct net_device
*dev
)
798 struct raeth_priv
*re
= netdev_priv(dev
);
801 BUG_ON(!re
->plat
->reset_fe
);
802 re
->plat
->reset_fe();
803 net_srandom(jiffies
);
804 memcpy(dev
->dev_addr
, re
->plat
->mac
, ETH_ALEN
);
808 dev
->watchdog_timeo
= TX_TIMEOUT
;
809 spin_lock_init(&re
->page_lock
);
810 spin_lock_init(&re
->phy_lock
);
812 err
= ramips_mdio_init(re
);
816 err
= ramips_phy_connect(re
);
818 goto err_mdio_cleanup
;
823 ramips_mdio_cleanup(re
);
828 ramips_eth_uninit(struct net_device
*dev
)
830 struct raeth_priv
*re
= netdev_priv(dev
);
832 ramips_phy_disconnect(re
);
833 ramips_mdio_cleanup(re
);
836 static const struct net_device_ops ramips_eth_netdev_ops
= {
837 .ndo_init
= ramips_eth_probe
,
838 .ndo_uninit
= ramips_eth_uninit
,
839 .ndo_open
= ramips_eth_open
,
840 .ndo_stop
= ramips_eth_stop
,
841 .ndo_start_xmit
= ramips_eth_hard_start_xmit
,
842 .ndo_tx_timeout
= ramips_eth_timeout
,
843 .ndo_change_mtu
= eth_change_mtu
,
844 .ndo_set_mac_address
= eth_mac_addr
,
845 .ndo_validate_addr
= eth_validate_addr
,
849 ramips_eth_plat_probe(struct platform_device
*plat
)
851 struct raeth_priv
*re
;
852 struct ramips_eth_platform_data
*data
= plat
->dev
.platform_data
;
853 struct resource
*res
;
857 dev_err(&plat
->dev
, "no platform data specified\n");
861 res
= platform_get_resource(plat
, IORESOURCE_MEM
, 0);
863 dev_err(&plat
->dev
, "no memory resource found\n");
867 ramips_fe_base
= ioremap_nocache(res
->start
, res
->end
- res
->start
+ 1);
871 ramips_dev
= alloc_etherdev(sizeof(struct raeth_priv
));
873 dev_err(&plat
->dev
, "alloc_etherdev failed\n");
878 strcpy(ramips_dev
->name
, "eth%d");
879 ramips_dev
->irq
= platform_get_irq(plat
, 0);
880 if (ramips_dev
->irq
< 0) {
881 dev_err(&plat
->dev
, "no IRQ resource found\n");
885 ramips_dev
->addr_len
= ETH_ALEN
;
886 ramips_dev
->base_addr
= (unsigned long)ramips_fe_base
;
887 ramips_dev
->netdev_ops
= &ramips_eth_netdev_ops
;
889 re
= netdev_priv(ramips_dev
);
891 re
->netdev
= ramips_dev
;
892 re
->parent
= &plat
->dev
;
893 re
->speed
= data
->speed
;
894 re
->duplex
= data
->duplex
;
895 re
->rx_fc
= data
->rx_fc
;
896 re
->tx_fc
= data
->tx_fc
;
899 err
= register_netdev(ramips_dev
);
901 dev_err(&plat
->dev
, "error bringing up device\n");
905 RADEBUG("ramips_eth: loaded\n");
911 iounmap(ramips_fe_base
);
916 ramips_eth_plat_remove(struct platform_device
*plat
)
918 unregister_netdev(ramips_dev
);
919 free_netdev(ramips_dev
);
920 RADEBUG("ramips_eth: unloaded\n");
924 static struct platform_driver ramips_eth_driver
= {
925 .probe
= ramips_eth_plat_probe
,
926 .remove
= ramips_eth_plat_remove
,
928 .name
= "ramips_eth",
929 .owner
= THIS_MODULE
,
934 ramips_eth_init(void)
938 ret
= rt305x_esw_init();
942 ret
= platform_driver_register(&ramips_eth_driver
);
945 "ramips_eth: Error registering platfom driver!\n");
957 ramips_eth_cleanup(void)
959 platform_driver_unregister(&ramips_eth_driver
);
963 module_init(ramips_eth_init
);
964 module_exit(ramips_eth_cleanup
);
966 MODULE_LICENSE("GPL");
967 MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
968 MODULE_DESCRIPTION("ethernet driver for ramips boards");