1 From 870ed9cae083ff8a60a739ef7e74c5a1800533be Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Tue, 9 Sep 2014 22:45:34 +0200
4 Subject: [PATCH 28/36] NET: lantiq: various etop fixes
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 drivers/net/ethernet/lantiq_etop.c | 555 +++++++++++++++++++++++++-----------
9 1 file changed, 389 insertions(+), 166 deletions(-)
11 --- a/drivers/net/ethernet/lantiq_etop.c
12 +++ b/drivers/net/ethernet/lantiq_etop.c
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 - * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
18 + * Copyright (C) 2011-12 John Crispin <blogic@openwrt.org>
21 #include <linux/kernel.h>
24 #include <linux/platform_device.h>
25 #include <linux/ethtool.h>
26 +#include <linux/if_vlan.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/module.h>
32 +#include <linux/clk.h>
33 +#include <linux/of_net.h>
34 +#include <linux/of_irq.h>
35 +#include <linux/of_platform.h>
37 #include <asm/checksum.h>
41 #include <lantiq_platform.h>
43 -#define LTQ_ETOP_MDIO 0x11804
44 +#define LTQ_ETOP_MDIO_ACC 0x11804
45 #define MDIO_REQUEST 0x80000000
46 #define MDIO_READ 0x40000000
47 #define MDIO_ADDR_MASK 0x1f
49 #define MDIO_REG_OFFSET 0x10
50 #define MDIO_VAL_MASK 0xffff
52 -#define PPE32_CGEN 0x800
53 -#define LQ_PPE32_ENET_MAC_CFG 0x1840
54 +#define LTQ_ETOP_MDIO_CFG 0x11800
55 +#define MDIO_CFG_MASK 0x6
57 +#define LTQ_ETOP_CFG 0x11808
58 +#define LTQ_ETOP_IGPLEN 0x11820
59 +#define LTQ_ETOP_MAC_CFG 0x11840
61 #define LTQ_ETOP_ENETS0 0x11850
62 #define LTQ_ETOP_MAC_DA0 0x1186C
63 #define LTQ_ETOP_MAC_DA1 0x11870
64 -#define LTQ_ETOP_CFG 0x16020
65 -#define LTQ_ETOP_IGPLEN 0x16080
67 +#define MAC_CFG_MASK 0xfff
68 +#define MAC_CFG_CGEN (1 << 11)
69 +#define MAC_CFG_DUPLEX (1 << 2)
70 +#define MAC_CFG_SPEED (1 << 1)
71 +#define MAC_CFG_LINK (1 << 0)
73 #define MAX_DMA_CHAN 0x8
74 #define MAX_DMA_CRC_LEN 0x4
75 #define MAX_DMA_DATA_LEN 0x600
77 #define ETOP_FTCU BIT(28)
78 -#define ETOP_MII_MASK 0xf
79 -#define ETOP_MII_NORMAL 0xd
80 -#define ETOP_MII_REVERSE 0xe
81 #define ETOP_PLEN_UNDER 0x40
82 -#define ETOP_CGEN 0x800
83 +#define ETOP_CFG_MII0 0x01
85 -/* use 2 static channels for TX/RX */
86 -#define LTQ_ETOP_TX_CHANNEL 1
87 -#define LTQ_ETOP_RX_CHANNEL 6
88 -#define IS_TX(x) (x == LTQ_ETOP_TX_CHANNEL)
89 -#define IS_RX(x) (x == LTQ_ETOP_RX_CHANNEL)
90 +#define ETOP_CFG_MASK 0xfff
91 +#define ETOP_CFG_FEN0 (1 << 8)
92 +#define ETOP_CFG_SEN0 (1 << 6)
93 +#define ETOP_CFG_OFF1 (1 << 3)
94 +#define ETOP_CFG_REMII0 (1 << 1)
95 +#define ETOP_CFG_OFF0 (1 << 0)
97 +#define LTQ_GBIT_MDIO_CTL 0xCC
98 +#define LTQ_GBIT_MDIO_DATA 0xd0
99 +#define LTQ_GBIT_GCTL0 0x68
100 +#define LTQ_GBIT_PMAC_HD_CTL 0x8c
101 +#define LTQ_GBIT_P0_CTL 0x4
102 +#define LTQ_GBIT_PMAC_RX_IPG 0xa8
103 +#define LTQ_GBIT_RGMII_CTL 0x78
105 +#define PMAC_HD_CTL_AS (1 << 19)
106 +#define PMAC_HD_CTL_RXSH (1 << 22)
108 +/* Switch Enable (0=disable, 1=enable) */
109 +#define GCTL0_SE 0x80000000
110 +/* Disable MDIO auto polling (0=disable, 1=enable) */
111 +#define PX_CTL_DMDIO 0x00400000
113 +/* MDC clock divider, clock = 25MHz/((MDC_CLOCK + 1) * 2) */
114 +#define MDC_CLOCK_MASK 0xff000000
115 +#define MDC_CLOCK_OFFSET 24
117 +/* register information for the gbit's MDIO bus */
118 +#define MDIO_XR9_REQUEST 0x00008000
119 +#define MDIO_XR9_READ 0x00000800
120 +#define MDIO_XR9_WRITE 0x00000400
121 +#define MDIO_XR9_REG_MASK 0x1f
122 +#define MDIO_XR9_ADDR_MASK 0x1f
123 +#define MDIO_XR9_RD_MASK 0xffff
124 +#define MDIO_XR9_REG_OFFSET 0
125 +#define MDIO_XR9_ADDR_OFFSET 5
126 +#define MDIO_XR9_WR_OFFSET 16
128 +#define LTQ_DMA_ETOP ((of_machine_is_compatible("lantiq,ase")) ? \
129 + (INT_NUM_IM3_IRL0) : (INT_NUM_IM2_IRL0))
131 +/* the newer xway socks have a embedded 3/7 port gbit multiplexer */
132 #define ltq_etop_r32(x) ltq_r32(ltq_etop_membase + (x))
133 #define ltq_etop_w32(x, y) ltq_w32(x, ltq_etop_membase + (y))
134 #define ltq_etop_w32_mask(x, y, z) \
135 ltq_w32_mask(x, y, ltq_etop_membase + (z))
137 -#define DRV_VERSION "1.0"
138 +#define ltq_gbit_r32(x) ltq_r32(ltq_gbit_membase + (x))
139 +#define ltq_gbit_w32(x, y) ltq_w32(x, ltq_gbit_membase + (y))
140 +#define ltq_gbit_w32_mask(x, y, z) \
141 + ltq_w32_mask(x, y, ltq_gbit_membase + (z))
143 +#define DRV_VERSION "1.2"
145 static void __iomem *ltq_etop_membase;
146 +static void __iomem *ltq_gbit_membase;
148 struct ltq_etop_chan {
152 struct net_device *netdev;
153 struct napi_struct napi;
154 struct ltq_dma_channel dma;
155 @@ -98,22 +150,35 @@ struct ltq_etop_chan {
156 struct ltq_etop_priv {
157 struct net_device *netdev;
158 struct platform_device *pdev;
159 - struct ltq_eth_data *pldata;
160 struct resource *res;
162 struct mii_bus *mii_bus;
163 struct phy_device *phydev;
165 - struct ltq_etop_chan ch[MAX_DMA_CHAN];
166 - int tx_free[MAX_DMA_CHAN >> 1];
167 + struct ltq_etop_chan txch;
168 + struct ltq_etop_chan rxch;
173 + unsigned char mac[6];
178 + struct clk *clk_ppe;
179 + struct clk *clk_switch;
180 + struct clk *clk_ephy;
181 + struct clk *clk_ephycgu;
184 +static int ltq_etop_mdio_wr(struct mii_bus *bus, int phy_addr,
185 + int phy_reg, u16 phy_data);
188 ltq_etop_alloc_skb(struct ltq_etop_chan *ch)
190 - ch->skb[ch->dma.desc] = netdev_alloc_skb(ch->netdev, MAX_DMA_DATA_LEN);
191 + ch->skb[ch->dma.desc] = dev_alloc_skb(MAX_DMA_DATA_LEN);
192 if (!ch->skb[ch->dma.desc])
194 ch->dma.desc_base[ch->dma.desc].addr = dma_map_single(NULL,
195 @@ -148,8 +213,11 @@ ltq_etop_hw_receive(struct ltq_etop_chan
196 spin_unlock_irqrestore(&priv->lock, flags);
199 + skb->dev = ch->netdev;
200 skb->protocol = eth_type_trans(skb, ch->netdev);
201 netif_receive_skb(skb);
202 + ch->netdev->stats.rx_packets++;
203 + ch->netdev->stats.rx_bytes += len;
207 @@ -157,8 +225,10 @@ ltq_etop_poll_rx(struct napi_struct *nap
209 struct ltq_etop_chan *ch = container_of(napi,
210 struct ltq_etop_chan, napi);
211 + struct ltq_etop_priv *priv = netdev_priv(ch->netdev);
214 + unsigned long flags;
216 while ((rx < budget) && !complete) {
217 struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc];
218 @@ -172,7 +242,9 @@ ltq_etop_poll_rx(struct napi_struct *nap
220 if (complete || !rx) {
221 napi_complete(&ch->napi);
222 + spin_lock_irqsave(&priv->lock, flags);
223 ltq_dma_ack_irq(&ch->dma);
224 + spin_unlock_irqrestore(&priv->lock, flags);
228 @@ -184,12 +256,14 @@ ltq_etop_poll_tx(struct napi_struct *nap
229 container_of(napi, struct ltq_etop_chan, napi);
230 struct ltq_etop_priv *priv = netdev_priv(ch->netdev);
231 struct netdev_queue *txq =
232 - netdev_get_tx_queue(ch->netdev, ch->idx >> 1);
233 + netdev_get_tx_queue(ch->netdev, ch->dma.nr >> 1);
236 spin_lock_irqsave(&priv->lock, flags);
237 while ((ch->dma.desc_base[ch->tx_free].ctl &
238 (LTQ_DMA_OWN | LTQ_DMA_C)) == LTQ_DMA_C) {
239 + ch->netdev->stats.tx_packets++;
240 + ch->netdev->stats.tx_bytes += ch->skb[ch->tx_free]->len;
241 dev_kfree_skb_any(ch->skb[ch->tx_free]);
242 ch->skb[ch->tx_free] = NULL;
243 memset(&ch->dma.desc_base[ch->tx_free], 0,
244 @@ -202,7 +276,9 @@ ltq_etop_poll_tx(struct napi_struct *nap
245 if (netif_tx_queue_stopped(txq))
246 netif_tx_start_queue(txq);
247 napi_complete(&ch->napi);
248 + spin_lock_irqsave(&priv->lock, flags);
249 ltq_dma_ack_irq(&ch->dma);
250 + spin_unlock_irqrestore(&priv->lock, flags);
254 @@ -210,9 +286,10 @@ static irqreturn_t
255 ltq_etop_dma_irq(int irq, void *_priv)
257 struct ltq_etop_priv *priv = _priv;
258 - int ch = irq - LTQ_DMA_CH0_INT;
260 - napi_schedule(&priv->ch[ch].napi);
261 + if (irq == priv->txch.dma.irq)
262 + napi_schedule(&priv->txch.napi);
264 + napi_schedule(&priv->rxch.napi);
268 @@ -224,7 +301,7 @@ ltq_etop_free_channel(struct net_device
269 ltq_dma_free(&ch->dma);
271 free_irq(ch->dma.irq, priv);
272 - if (IS_RX(ch->idx)) {
273 + if (ch == &priv->txch) {
275 for (desc = 0; desc < LTQ_DESC_NUM; desc++)
276 dev_kfree_skb_any(ch->skb[ch->dma.desc]);
277 @@ -235,65 +312,133 @@ static void
278 ltq_etop_hw_exit(struct net_device *dev)
280 struct ltq_etop_priv *priv = netdev_priv(dev);
283 - ltq_pmu_disable(PMU_PPE);
284 - for (i = 0; i < MAX_DMA_CHAN; i++)
285 - if (IS_TX(i) || IS_RX(i))
286 - ltq_etop_free_channel(dev, &priv->ch[i]);
287 + clk_disable(priv->clk_ppe);
289 + if (of_machine_is_compatible("lantiq,ar9"))
290 + clk_disable(priv->clk_switch);
292 + if (of_machine_is_compatible("lantiq,ase")) {
293 + clk_disable(priv->clk_ephy);
294 + clk_disable(priv->clk_ephycgu);
297 + ltq_etop_free_channel(dev, &priv->txch);
298 + ltq_etop_free_channel(dev, &priv->rxch);
302 +ltq_etop_gbit_init(struct net_device *dev)
304 + struct ltq_etop_priv *priv = netdev_priv(dev);
306 + clk_enable(priv->clk_switch);
308 + /* enable gbit port0 on the SoC */
309 + ltq_gbit_w32_mask((1 << 17), (1 << 18), LTQ_GBIT_P0_CTL);
311 + ltq_gbit_w32_mask(0, GCTL0_SE, LTQ_GBIT_GCTL0);
312 + /* disable MDIO auto polling mode */
313 + ltq_gbit_w32_mask(0, PX_CTL_DMDIO, LTQ_GBIT_P0_CTL);
314 + /* set 1522 packet size */
315 + ltq_gbit_w32_mask(0x300, 0, LTQ_GBIT_GCTL0);
316 + /* disable pmac & dmac headers */
317 + ltq_gbit_w32_mask(PMAC_HD_CTL_AS | PMAC_HD_CTL_RXSH, 0,
318 + LTQ_GBIT_PMAC_HD_CTL);
319 + /* Due to traffic halt when burst length 8,
320 + replace default IPG value with 0x3B */
321 + ltq_gbit_w32(0x3B, LTQ_GBIT_PMAC_RX_IPG);
322 + /* set mdc clock to 2.5 MHz */
323 + ltq_gbit_w32_mask(MDC_CLOCK_MASK, 4 << MDC_CLOCK_OFFSET,
324 + LTQ_GBIT_RGMII_CTL);
328 ltq_etop_hw_init(struct net_device *dev)
330 struct ltq_etop_priv *priv = netdev_priv(dev);
332 + int mii_mode = priv->mii_mode;
334 - ltq_pmu_enable(PMU_PPE);
335 + clk_enable(priv->clk_ppe);
337 - switch (priv->pldata->mii_mode) {
338 + if (of_machine_is_compatible("lantiq,ar9")) {
339 + ltq_etop_gbit_init(dev);
340 + /* force the etops link to the gbit to MII */
341 + mii_mode = PHY_INTERFACE_MODE_MII;
343 + ltq_etop_w32_mask(MDIO_CFG_MASK, 0, LTQ_ETOP_MDIO_CFG);
344 + ltq_etop_w32_mask(MAC_CFG_MASK, MAC_CFG_CGEN | MAC_CFG_DUPLEX |
345 + MAC_CFG_SPEED | MAC_CFG_LINK, LTQ_ETOP_MAC_CFG);
347 + switch (mii_mode) {
348 case PHY_INTERFACE_MODE_RMII:
349 - ltq_etop_w32_mask(ETOP_MII_MASK,
350 - ETOP_MII_REVERSE, LTQ_ETOP_CFG);
351 + ltq_etop_w32_mask(ETOP_CFG_MASK, ETOP_CFG_REMII0 | ETOP_CFG_OFF1 |
352 + ETOP_CFG_SEN0 | ETOP_CFG_FEN0, LTQ_ETOP_CFG);
355 case PHY_INTERFACE_MODE_MII:
356 - ltq_etop_w32_mask(ETOP_MII_MASK,
357 - ETOP_MII_NORMAL, LTQ_ETOP_CFG);
358 + ltq_etop_w32_mask(ETOP_CFG_MASK, ETOP_CFG_OFF1 |
359 + ETOP_CFG_SEN0 | ETOP_CFG_FEN0, LTQ_ETOP_CFG);
363 + if (of_machine_is_compatible("lantiq,ase")) {
364 + clk_enable(priv->clk_ephy);
365 + /* disable external MII */
366 + ltq_etop_w32_mask(0, ETOP_CFG_MII0, LTQ_ETOP_CFG);
367 + /* enable clock for internal PHY */
368 + clk_enable(priv->clk_ephycgu);
369 + /* we need to write this magic to the internal phy to
371 + ltq_etop_mdio_wr(NULL, 0x8, 0x12, 0xC020);
372 + pr_info("Selected EPHY mode\n");
375 netdev_err(dev, "unknown mii mode %d\n",
376 - priv->pldata->mii_mode);
381 - /* enable crc generation */
382 - ltq_etop_w32(PPE32_CGEN, LQ_PPE32_ENET_MAC_CFG);
386 - ltq_dma_init_port(DMA_PORT_ETOP);
388 +ltq_etop_dma_init(struct net_device *dev)
390 + struct ltq_etop_priv *priv = netdev_priv(dev);
391 + int tx = priv->tx_irq - LTQ_DMA_ETOP;
392 + int rx = priv->rx_irq - LTQ_DMA_ETOP;
395 - for (i = 0; i < MAX_DMA_CHAN; i++) {
396 - int irq = LTQ_DMA_CH0_INT + i;
397 - struct ltq_etop_chan *ch = &priv->ch[i];
398 + ltq_dma_init_port(DMA_PORT_ETOP);
400 - ch->idx = ch->dma.nr = i;
401 + priv->txch.dma.nr = tx;
402 + ltq_dma_alloc_tx(&priv->txch.dma);
403 + err = request_irq(priv->tx_irq, ltq_etop_dma_irq, 0, "eth_tx", priv);
405 + netdev_err(dev, "failed to allocate tx irq\n");
408 + priv->txch.dma.irq = priv->tx_irq;
411 - ltq_dma_alloc_tx(&ch->dma);
412 - request_irq(irq, ltq_etop_dma_irq, 0, "etop_tx", priv);
413 - } else if (IS_RX(i)) {
414 - ltq_dma_alloc_rx(&ch->dma);
415 - for (ch->dma.desc = 0; ch->dma.desc < LTQ_DESC_NUM;
417 - if (ltq_etop_alloc_skb(ch))
420 - request_irq(irq, ltq_etop_dma_irq, 0, "etop_rx", priv);
421 + priv->rxch.dma.nr = rx;
422 + ltq_dma_alloc_rx(&priv->rxch.dma);
423 + for (priv->rxch.dma.desc = 0; priv->rxch.dma.desc < LTQ_DESC_NUM;
424 + priv->rxch.dma.desc++) {
425 + if (ltq_etop_alloc_skb(&priv->rxch)) {
426 + netdev_err(dev, "failed to allocate skbs\n");
433 + priv->rxch.dma.desc = 0;
434 + err = request_irq(priv->rx_irq, ltq_etop_dma_irq, 0, "eth_rx", priv);
436 + netdev_err(dev, "failed to allocate rx irq\n");
438 + priv->rxch.dma.irq = priv->rx_irq;
444 @@ -309,7 +454,10 @@ ltq_etop_get_settings(struct net_device
446 struct ltq_etop_priv *priv = netdev_priv(dev);
448 - return phy_ethtool_gset(priv->phydev, cmd);
450 + return phy_ethtool_gset(priv->phydev, cmd);
456 @@ -317,7 +465,10 @@ ltq_etop_set_settings(struct net_device
458 struct ltq_etop_priv *priv = netdev_priv(dev);
460 - return phy_ethtool_sset(priv->phydev, cmd);
462 + return phy_ethtool_sset(priv->phydev, cmd);
468 @@ -325,7 +476,10 @@ ltq_etop_nway_reset(struct net_device *d
470 struct ltq_etop_priv *priv = netdev_priv(dev);
472 - return phy_start_aneg(priv->phydev);
474 + return phy_start_aneg(priv->phydev);
479 static const struct ethtool_ops ltq_etop_ethtool_ops = {
480 @@ -336,6 +490,39 @@ static const struct ethtool_ops ltq_etop
484 +ltq_etop_mdio_wr_xr9(struct mii_bus *bus, int phy_addr,
485 + int phy_reg, u16 phy_data)
487 + u32 val = MDIO_XR9_REQUEST | MDIO_XR9_WRITE |
488 + (phy_data << MDIO_XR9_WR_OFFSET) |
489 + ((phy_addr & MDIO_XR9_ADDR_MASK) << MDIO_XR9_ADDR_OFFSET) |
490 + ((phy_reg & MDIO_XR9_REG_MASK) << MDIO_XR9_REG_OFFSET);
492 + while (ltq_gbit_r32(LTQ_GBIT_MDIO_CTL) & MDIO_XR9_REQUEST)
494 + ltq_gbit_w32(val, LTQ_GBIT_MDIO_CTL);
495 + while (ltq_gbit_r32(LTQ_GBIT_MDIO_CTL) & MDIO_XR9_REQUEST)
501 +ltq_etop_mdio_rd_xr9(struct mii_bus *bus, int phy_addr, int phy_reg)
503 + u32 val = MDIO_XR9_REQUEST | MDIO_XR9_READ |
504 + ((phy_addr & MDIO_XR9_ADDR_MASK) << MDIO_XR9_ADDR_OFFSET) |
505 + ((phy_reg & MDIO_XR9_REG_MASK) << MDIO_XR9_REG_OFFSET);
507 + while (ltq_gbit_r32(LTQ_GBIT_MDIO_CTL) & MDIO_XR9_REQUEST)
509 + ltq_gbit_w32(val, LTQ_GBIT_MDIO_CTL);
510 + while (ltq_gbit_r32(LTQ_GBIT_MDIO_CTL) & MDIO_XR9_REQUEST)
512 + val = ltq_gbit_r32(LTQ_GBIT_MDIO_DATA) & MDIO_XR9_RD_MASK;
517 ltq_etop_mdio_wr(struct mii_bus *bus, int phy_addr, int phy_reg, u16 phy_data)
519 u32 val = MDIO_REQUEST |
520 @@ -343,9 +530,9 @@ ltq_etop_mdio_wr(struct mii_bus *bus, in
521 ((phy_reg & MDIO_REG_MASK) << MDIO_REG_OFFSET) |
524 - while (ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_REQUEST)
525 + while (ltq_etop_r32(LTQ_ETOP_MDIO_ACC) & MDIO_REQUEST)
527 - ltq_etop_w32(val, LTQ_ETOP_MDIO);
528 + ltq_etop_w32(val, LTQ_ETOP_MDIO_ACC);
532 @@ -356,12 +543,12 @@ ltq_etop_mdio_rd(struct mii_bus *bus, in
533 ((phy_addr & MDIO_ADDR_MASK) << MDIO_ADDR_OFFSET) |
534 ((phy_reg & MDIO_REG_MASK) << MDIO_REG_OFFSET);
536 - while (ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_REQUEST)
537 + while (ltq_etop_r32(LTQ_ETOP_MDIO_ACC) & MDIO_REQUEST)
539 - ltq_etop_w32(val, LTQ_ETOP_MDIO);
540 - while (ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_REQUEST)
541 + ltq_etop_w32(val, LTQ_ETOP_MDIO_ACC);
542 + while (ltq_etop_r32(LTQ_ETOP_MDIO_ACC) & MDIO_REQUEST)
544 - val = ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_VAL_MASK;
545 + val = ltq_etop_r32(LTQ_ETOP_MDIO_ACC) & MDIO_VAL_MASK;
549 @@ -376,14 +563,18 @@ ltq_etop_mdio_probe(struct net_device *d
551 struct ltq_etop_priv *priv = netdev_priv(dev);
552 struct phy_device *phydev = NULL;
554 + u32 phy_supported = (SUPPORTED_10baseT_Half
555 + | SUPPORTED_10baseT_Full
556 + | SUPPORTED_100baseT_Half
557 + | SUPPORTED_100baseT_Full
558 + | SUPPORTED_Autoneg
562 - for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
563 - if (priv->mii_bus->phy_map[phy_addr]) {
564 - phydev = priv->mii_bus->phy_map[phy_addr];
568 + if (of_machine_is_compatible("lantiq,ase"))
569 + phydev = priv->mii_bus->phy_map[8];
571 + phydev = priv->mii_bus->phy_map[0];
574 netdev_err(dev, "no PHY found\n");
575 @@ -391,21 +582,18 @@ ltq_etop_mdio_probe(struct net_device *d
578 phydev = phy_connect(dev, dev_name(&phydev->dev),
579 - <q_etop_mdio_link, priv->pldata->mii_mode);
580 + <q_etop_mdio_link, priv->mii_mode);
582 if (IS_ERR(phydev)) {
583 netdev_err(dev, "Could not attach to PHY\n");
584 return PTR_ERR(phydev);
587 - phydev->supported &= (SUPPORTED_10baseT_Half
588 - | SUPPORTED_10baseT_Full
589 - | SUPPORTED_100baseT_Half
590 - | SUPPORTED_100baseT_Full
591 - | SUPPORTED_Autoneg
594 + if (of_machine_is_compatible("lantiq,ar9"))
595 + phy_supported |= SUPPORTED_1000baseT_Half
596 + | SUPPORTED_1000baseT_Full;
598 + phydev->supported &= phy_supported;
599 phydev->advertising = phydev->supported;
600 priv->phydev = phydev;
601 pr_info("%s: attached PHY [%s] (phy_addr=%s, irq=%d)\n",
602 @@ -430,8 +618,13 @@ ltq_etop_mdio_init(struct net_device *de
605 priv->mii_bus->priv = dev;
606 - priv->mii_bus->read = ltq_etop_mdio_rd;
607 - priv->mii_bus->write = ltq_etop_mdio_wr;
608 + if (of_machine_is_compatible("lantiq,ar9")) {
609 + priv->mii_bus->read = ltq_etop_mdio_rd_xr9;
610 + priv->mii_bus->write = ltq_etop_mdio_wr_xr9;
612 + priv->mii_bus->read = ltq_etop_mdio_rd;
613 + priv->mii_bus->write = ltq_etop_mdio_wr;
615 priv->mii_bus->name = "ltq_mii";
616 snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
617 priv->pdev->name, priv->pdev->id);
618 @@ -480,17 +673,19 @@ static int
619 ltq_etop_open(struct net_device *dev)
621 struct ltq_etop_priv *priv = netdev_priv(dev);
623 + unsigned long flags;
625 - for (i = 0; i < MAX_DMA_CHAN; i++) {
626 - struct ltq_etop_chan *ch = &priv->ch[i];
627 + napi_enable(&priv->txch.napi);
628 + napi_enable(&priv->rxch.napi);
630 + spin_lock_irqsave(&priv->lock, flags);
631 + ltq_dma_open(&priv->txch.dma);
632 + ltq_dma_open(&priv->rxch.dma);
633 + spin_unlock_irqrestore(&priv->lock, flags);
636 + phy_start(priv->phydev);
638 - if (!IS_TX(i) && (!IS_RX(i)))
640 - ltq_dma_open(&ch->dma);
641 - napi_enable(&ch->napi);
643 - phy_start(priv->phydev);
644 netif_tx_start_all_queues(dev);
647 @@ -499,18 +694,19 @@ static int
648 ltq_etop_stop(struct net_device *dev)
650 struct ltq_etop_priv *priv = netdev_priv(dev);
652 + unsigned long flags;
654 netif_tx_stop_all_queues(dev);
655 - phy_stop(priv->phydev);
656 - for (i = 0; i < MAX_DMA_CHAN; i++) {
657 - struct ltq_etop_chan *ch = &priv->ch[i];
659 + phy_stop(priv->phydev);
660 + napi_disable(&priv->txch.napi);
661 + napi_disable(&priv->rxch.napi);
663 + spin_lock_irqsave(&priv->lock, flags);
664 + ltq_dma_close(&priv->txch.dma);
665 + ltq_dma_close(&priv->rxch.dma);
666 + spin_unlock_irqrestore(&priv->lock, flags);
668 - if (!IS_RX(i) && !IS_TX(i))
670 - napi_disable(&ch->napi);
671 - ltq_dma_close(&ch->dma);
676 @@ -520,16 +716,16 @@ ltq_etop_tx(struct sk_buff *skb, struct
677 int queue = skb_get_queue_mapping(skb);
678 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue);
679 struct ltq_etop_priv *priv = netdev_priv(dev);
680 - struct ltq_etop_chan *ch = &priv->ch[(queue << 1) | 1];
681 - struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc];
683 + struct ltq_dma_desc *desc =
684 + &priv->txch.dma.desc_base[priv->txch.dma.desc];
689 len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
691 - if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) || ch->skb[ch->dma.desc]) {
692 - dev_kfree_skb_any(skb);
693 + if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) ||
694 + priv->txch.skb[priv->txch.dma.desc]) {
695 netdev_err(dev, "tx ring full\n");
696 netif_tx_stop_queue(txq);
697 return NETDEV_TX_BUSY;
698 @@ -537,7 +733,7 @@ ltq_etop_tx(struct sk_buff *skb, struct
700 /* dma needs to start on a 16 byte aligned address */
701 byte_offset = CPHYSADDR(skb->data) % 16;
702 - ch->skb[ch->dma.desc] = skb;
703 + priv->txch.skb[priv->txch.dma.desc] = skb;
705 dev->trans_start = jiffies;
707 @@ -547,11 +743,11 @@ ltq_etop_tx(struct sk_buff *skb, struct
709 desc->ctl = LTQ_DMA_OWN | LTQ_DMA_SOP | LTQ_DMA_EOP |
710 LTQ_DMA_TX_OFFSET(byte_offset) | (len & LTQ_DMA_SIZE_MASK);
712 - ch->dma.desc %= LTQ_DESC_NUM;
713 + priv->txch.dma.desc++;
714 + priv->txch.dma.desc %= LTQ_DESC_NUM;
715 spin_unlock_irqrestore(&priv->lock, flags);
717 - if (ch->dma.desc_base[ch->dma.desc].ctl & LTQ_DMA_OWN)
718 + if (priv->txch.dma.desc_base[priv->txch.dma.desc].ctl & LTQ_DMA_OWN)
719 netif_tx_stop_queue(txq);
722 @@ -566,8 +762,10 @@ ltq_etop_change_mtu(struct net_device *d
723 struct ltq_etop_priv *priv = netdev_priv(dev);
726 + int max = ETH_HLEN + VLAN_HLEN + new_mtu + ETH_FCS_LEN;
728 spin_lock_irqsave(&priv->lock, flags);
729 - ltq_etop_w32((ETOP_PLEN_UNDER << 16) | new_mtu,
730 + ltq_etop_w32((ETOP_PLEN_UNDER << 16) | max,
732 spin_unlock_irqrestore(&priv->lock, flags);
734 @@ -638,6 +836,9 @@ ltq_etop_init(struct net_device *dev)
737 ltq_etop_change_mtu(dev, 1500);
738 + err = ltq_etop_dma_init(dev);
742 memcpy(&mac, &priv->pldata->mac, sizeof(struct sockaddr));
743 if (!is_valid_ether_addr(mac.sa_data)) {
744 @@ -655,9 +856,10 @@ ltq_etop_init(struct net_device *dev)
745 dev->addr_assign_type = NET_ADDR_RANDOM;
747 ltq_etop_set_multicast_list(dev);
748 - err = ltq_etop_mdio_init(dev);
751 + if (!ltq_etop_mdio_init(dev))
752 + dev->ethtool_ops = <q_etop_ethtool_ops;
754 + pr_warn("etop: mdio probe failed\n");;
758 @@ -677,6 +879,9 @@ ltq_etop_tx_timeout(struct net_device *d
759 err = ltq_etop_hw_init(dev);
762 + err = ltq_etop_dma_init(dev);
765 dev->trans_start = jiffies;
766 netif_wake_queue(dev);
768 @@ -700,14 +905,19 @@ static const struct net_device_ops ltq_e
769 .ndo_tx_timeout = ltq_etop_tx_timeout,
773 -ltq_etop_probe(struct platform_device *pdev)
774 +static int ltq_etop_probe(struct platform_device *pdev)
776 struct net_device *dev;
777 struct ltq_etop_priv *priv;
778 - struct resource *res;
779 + struct resource *res, *gbit_res, irqres[2];
784 + err = of_irq_to_resource_table(pdev->dev.of_node, irqres, 2);
786 + dev_err(&pdev->dev, "failed to get etop irqs\n");
790 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
792 @@ -733,31 +943,62 @@ ltq_etop_probe(struct platform_device *p
796 - dev = alloc_etherdev_mq(sizeof(struct ltq_etop_priv), 4);
800 + if (of_machine_is_compatible("lantiq,ar9")) {
801 + gbit_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
803 + dev_err(&pdev->dev, "failed to get gbit resource\n");
807 + ltq_gbit_membase = devm_ioremap_nocache(&pdev->dev,
808 + gbit_res->start, resource_size(gbit_res));
809 + if (!ltq_gbit_membase) {
810 + dev_err(&pdev->dev, "failed to remap gigabit switch %d\n",
817 + dev = alloc_etherdev_mq(sizeof(struct ltq_etop_priv), 4);
818 strcpy(dev->name, "eth%d");
819 dev->netdev_ops = <q_eth_netdev_ops;
820 - dev->ethtool_ops = <q_etop_ethtool_ops;
821 priv = netdev_priv(dev);
824 - priv->pldata = dev_get_platdata(&pdev->dev);
826 - spin_lock_init(&priv->lock);
827 + priv->tx_irq = irqres[0].start;
828 + priv->rx_irq = irqres[1].start;
829 + priv->mii_mode = of_get_phy_mode(pdev->dev.of_node);
831 - for (i = 0; i < MAX_DMA_CHAN; i++) {
833 - netif_napi_add(dev, &priv->ch[i].napi,
834 - ltq_etop_poll_tx, 8);
836 - netif_napi_add(dev, &priv->ch[i].napi,
837 - ltq_etop_poll_rx, 32);
838 - priv->ch[i].netdev = dev;
839 + mac = of_get_mac_address(pdev->dev.of_node);
841 + memcpy(priv->mac, mac, ETH_ALEN);
843 + priv->clk_ppe = clk_get(&pdev->dev, NULL);
844 + if (IS_ERR(priv->clk_ppe))
845 + return PTR_ERR(priv->clk_ppe);
846 + if (of_machine_is_compatible("lantiq,ar9")) {
847 + priv->clk_switch = clk_get(&pdev->dev, "switch");
848 + if (IS_ERR(priv->clk_switch))
849 + return PTR_ERR(priv->clk_switch);
851 + if (of_machine_is_compatible("lantiq,ase")) {
852 + priv->clk_ephy = clk_get(&pdev->dev, "ephy");
853 + if (IS_ERR(priv->clk_ephy))
854 + return PTR_ERR(priv->clk_ephy);
855 + priv->clk_ephycgu = clk_get(&pdev->dev, "ephycgu");
856 + if (IS_ERR(priv->clk_ephycgu))
857 + return PTR_ERR(priv->clk_ephycgu);
860 + spin_lock_init(&priv->lock);
862 + netif_napi_add(dev, &priv->txch.napi, ltq_etop_poll_tx, 8);
863 + netif_napi_add(dev, &priv->rxch.napi, ltq_etop_poll_rx, 32);
864 + priv->txch.netdev = dev;
865 + priv->rxch.netdev = dev;
867 err = register_netdev(dev);
870 @@ -785,31 +1026,22 @@ ltq_etop_remove(struct platform_device *
874 +static const struct of_device_id ltq_etop_match[] = {
875 + { .compatible = "lantiq,etop-xway" },
878 +MODULE_DEVICE_TABLE(of, ltq_etop_match);
880 static struct platform_driver ltq_mii_driver = {
881 + .probe = ltq_etop_probe,
882 .remove = ltq_etop_remove,
885 + .of_match_table = ltq_etop_match,
892 - int ret = platform_driver_probe(<q_mii_driver, ltq_etop_probe);
895 - pr_err("ltq_etop: Error registering platform driver!");
902 - platform_driver_unregister(<q_mii_driver);
905 -module_init(init_ltq_etop);
906 -module_exit(exit_ltq_etop);
907 +module_platform_driver(ltq_mii_driver);
909 MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
910 MODULE_DESCRIPTION("Lantiq SoC ETOP");