1 From 7591c5702cfe842f415e42f387532fe71ea3640f Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Fri, 9 Mar 2012 19:03:40 +0100
4 Subject: [PATCH 43/70] NET: adds driver for lantiq vr9 ethernet
7 .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h | 2 +-
8 arch/mips/lantiq/xway/devices.c | 20 +
9 arch/mips/lantiq/xway/devices.h | 1 +
10 drivers/net/ethernet/Kconfig | 6 +
11 drivers/net/ethernet/Makefile | 1 +
12 drivers/net/ethernet/lantiq_vrx200.c | 1358 ++++++++++++++++++++
13 6 files changed, 1387 insertions(+), 1 deletions(-)
14 create mode 100644 drivers/net/ethernet/lantiq_vrx200.c
16 --- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
17 +++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
20 /* GBIT - gigabit switch */
21 #define LTQ_GBIT_BASE_ADDR 0x1E108000
22 -#define LTQ_GBIT_SIZE 0x200
23 +#define LTQ_GBIT_SIZE 0x4000
26 #define LTQ_DMA_BASE_ADDR 0x1E104100
27 --- a/arch/mips/lantiq/xway/devices.c
28 +++ b/arch/mips/lantiq/xway/devices.c
29 @@ -83,6 +83,7 @@ static struct platform_device ltq_etop =
31 .resource = ltq_etop_resources,
37 @@ -96,3 +97,22 @@ ltq_register_etop(struct ltq_eth_data *e
38 platform_device_register(<q_etop);
43 +static struct resource ltq_vrx200_resources[] = {
44 + MEM_RES("gbit", LTQ_GBIT_BASE_ADDR, LTQ_GBIT_SIZE),
47 +static struct platform_device ltq_vrx200 = {
48 + .name = "ltq_vrx200",
49 + .resource = ltq_vrx200_resources,
55 +ltq_register_vrx200(struct ltq_eth_data *eth)
57 + ltq_vrx200.dev.platform_data = eth;
58 + platform_device_register(<q_vrx200);
60 --- a/arch/mips/lantiq/xway/devices.h
61 +++ b/arch/mips/lantiq/xway/devices.h
62 @@ -17,5 +17,6 @@ extern void ltq_register_gpio_stp(void);
63 extern void ltq_register_ase_asc(void);
64 extern void ltq_register_etop(struct ltq_eth_data *eth);
65 extern void xway_register_nand(struct mtd_partition *parts, int count);
66 +extern void ltq_register_vrx200(struct ltq_eth_data *eth);
69 --- a/drivers/net/ethernet/Kconfig
70 +++ b/drivers/net/ethernet/Kconfig
71 @@ -84,6 +84,12 @@ config LANTIQ_ETOP
73 Support for the MII0 inside the Lantiq SoC
76 + tristate "Lantiq SoC vrx200 driver"
77 + depends on SOC_TYPE_XWAY
79 + Support for the MII0 inside the Lantiq SoC
81 source "drivers/net/ethernet/marvell/Kconfig"
82 source "drivers/net/ethernet/mellanox/Kconfig"
83 source "drivers/net/ethernet/micrel/Kconfig"
84 --- a/drivers/net/ethernet/Makefile
85 +++ b/drivers/net/ethernet/Makefile
86 @@ -35,6 +35,7 @@ obj-$(CONFIG_IP1000) += icplus/
87 obj-$(CONFIG_JME) += jme.o
88 obj-$(CONFIG_KORINA) += korina.o
89 obj-$(CONFIG_LANTIQ_ETOP) += lantiq_etop.o
90 +obj-$(CONFIG_LANTIQ_VRX200) += lantiq_vrx200.o
91 obj-$(CONFIG_NET_VENDOR_MARVELL) += marvell/
92 obj-$(CONFIG_NET_VENDOR_MELLANOX) += mellanox/
93 obj-$(CONFIG_NET_VENDOR_MICREL) += micrel/
95 +++ b/drivers/net/ethernet/lantiq_vrx200.c
98 + * This program is free software; you can redistribute it and/or modify it
99 + * under the terms of the GNU General Public License version 2 as published
100 + * by the Free Software Foundation.
102 + * This program is distributed in the hope that it will be useful,
103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 + * GNU General Public License for more details.
107 + * You should have received a copy of the GNU General Public License
108 + * along with this program; if not, write to the Free Software
109 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
111 + * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
114 +#include <linux/kernel.h>
115 +#include <linux/slab.h>
116 +#include <linux/errno.h>
117 +#include <linux/types.h>
118 +#include <linux/interrupt.h>
119 +#include <linux/uaccess.h>
120 +#include <linux/in.h>
121 +#include <linux/netdevice.h>
122 +#include <linux/etherdevice.h>
123 +#include <linux/phy.h>
124 +#include <linux/ip.h>
125 +#include <linux/tcp.h>
126 +#include <linux/skbuff.h>
127 +#include <linux/mm.h>
128 +#include <linux/platform_device.h>
129 +#include <linux/ethtool.h>
130 +#include <linux/init.h>
131 +#include <linux/delay.h>
132 +#include <linux/io.h>
133 +#include <linux/dma-mapping.h>
134 +#include <linux/module.h>
135 +#include <linux/clk.h>
137 +#include <asm/checksum.h>
139 +#include <lantiq_soc.h>
140 +#include <xway_dma.h>
141 +#include <lantiq_platform.h>
143 +#define LTQ_SWITCH_BASE 0x1E108000
144 +#define LTQ_SWITCH_CORE_BASE LTQ_SWITCH_BASE
145 +#define LTQ_SWITCH_TOP_PDI_BASE LTQ_SWITCH_CORE_BASE
146 +#define LTQ_SWITCH_BM_PDI_BASE (LTQ_SWITCH_CORE_BASE + 4 * 0x40)
147 +#define LTQ_SWITCH_MAC_PDI_0_BASE (LTQ_SWITCH_CORE_BASE + 4 * 0x900)
148 +#define LTQ_SWITCH_MAC_PDI_X_BASE(x) (LTQ_SWITCH_MAC_PDI_0_BASE + x * 0x30)
149 +#define LTQ_SWITCH_TOPLEVEL_BASE (LTQ_SWITCH_BASE + 4 * 0xC40)
150 +#define LTQ_SWITCH_MDIO_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE)
151 +#define LTQ_SWITCH_MII_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE + 4 * 0x36)
152 +#define LTQ_SWITCH_PMAC_PDI_BASE (LTQ_SWITCH_TOPLEVEL_BASE + 4 * 0x82)
154 +#define LTQ_ETHSW_MAC_CTRL0_PADEN (1 << 8)
155 +#define LTQ_ETHSW_MAC_CTRL0_FCS (1 << 7)
156 +#define LTQ_ETHSW_MAC_CTRL1_SHORTPRE (1 << 8)
157 +#define LTQ_ETHSW_MAC_CTRL2_MLEN (1 << 3)
158 +#define LTQ_ETHSW_MAC_CTRL2_LCHKL (1 << 2)
159 +#define LTQ_ETHSW_MAC_CTRL2_LCHKS_DIS 0
160 +#define LTQ_ETHSW_MAC_CTRL2_LCHKS_UNTAG 1
161 +#define LTQ_ETHSW_MAC_CTRL2_LCHKS_TAG 2
162 +#define LTQ_ETHSW_MAC_CTRL6_RBUF_DLY_WP_SHIFT 9
163 +#define LTQ_ETHSW_MAC_CTRL6_RXBUF_BYPASS (1 << 6)
164 +#define LTQ_ETHSW_GLOB_CTRL_SE (1 << 15)
165 +#define LTQ_ETHSW_MDC_CFG1_MCEN (1 << 8)
166 +#define LTQ_ETHSW_PMAC_HD_CTL_FC (1 << 10)
167 +#define LTQ_ETHSW_PMAC_HD_CTL_RC (1 << 4)
168 +#define LTQ_ETHSW_PMAC_HD_CTL_AC (1 << 2)
169 +#define ADVERTIZE_MPD (1 << 10)
171 +#define MDIO_DEVAD_NONE (-1)
173 +#define LTQ_ETH_RX_BUFFER_CNT PKTBUFSRX
175 +#define LTQ_MDIO_DRV_NAME "ltq-mdio"
176 +#define LTQ_ETH_DRV_NAME "ltq-eth"
178 +#define LTQ_ETHSW_MAX_GMAC 1
179 +#define LTQ_ETHSW_PMAC 1
181 +#define ltq_setbits(a, set) \
182 + ltq_w32(ltq_r32(a) | (set), a)
184 +enum ltq_reset_modules {
194 +dbg_ltq_writel(void *a, unsigned int b)
199 +int ltq_reset_once(enum ltq_reset_modules module, ulong usec);
201 +struct ltq_ethsw_mac_pdi_x_regs {
202 + u32 pstat; /* Port status */
203 + u32 pisr; /* Interrupt status */
204 + u32 pier; /* Interrupt enable */
205 + u32 ctrl_0; /* Control 0 */
206 + u32 ctrl_1; /* Control 1 */
207 + u32 ctrl_2; /* Control 2 */
208 + u32 ctrl_3; /* Control 3 */
209 + u32 ctrl_4; /* Control 4 */
210 + u32 ctrl_5; /* Control 5 */
211 + u32 ctrl_6; /* Control 6 */
212 + u32 bufst; /* TX/RX buffer control */
213 + u32 testen; /* Test enable */
216 +struct ltq_ethsw_mac_pdi_regs {
217 + struct ltq_ethsw_mac_pdi_x_regs mac[12];
220 +struct ltq_ethsw_mdio_pdi_regs {
221 + u32 glob_ctrl; /* Global control 0 */
223 + u32 mdio_ctrl; /* MDIO control */
224 + u32 mdio_read; /* MDIO read data */
225 + u32 mdio_write; /* MDIO write data */
226 + u32 mdc_cfg_0; /* MDC clock configuration 0 */
227 + u32 mdc_cfg_1; /* MDC clock configuration 1 */
229 + u32 phy_addr_5; /* PHY address port 5 */
230 + u32 phy_addr_4; /* PHY address port 4 */
231 + u32 phy_addr_3; /* PHY address port 3 */
232 + u32 phy_addr_2; /* PHY address port 2 */
233 + u32 phy_addr_1; /* PHY address port 1 */
234 + u32 phy_addr_0; /* PHY address port 0 */
235 + u32 mdio_stat_0; /* MDIO PHY polling status port 0 */
236 + u32 mdio_stat_1; /* MDIO PHY polling status port 1 */
237 + u32 mdio_stat_2; /* MDIO PHY polling status port 2 */
238 + u32 mdio_stat_3; /* MDIO PHY polling status port 3 */
239 + u32 mdio_stat_4; /* MDIO PHY polling status port 4 */
240 + u32 mdio_stat_5; /* MDIO PHY polling status port 5 */
243 +struct ltq_ethsw_mii_pdi_regs {
244 + u32 mii_cfg0; /* xMII port 0 configuration */
245 + u32 pcdu0; /* Port 0 clock delay configuration */
246 + u32 mii_cfg1; /* xMII port 1 configuration */
247 + u32 pcdu1; /* Port 1 clock delay configuration */
248 + u32 mii_cfg2; /* xMII port 2 configuration */
250 + u32 mii_cfg3; /* xMII port 3 configuration */
252 + u32 mii_cfg4; /* xMII port 4 configuration */
254 + u32 mii_cfg5; /* xMII port 5 configuration */
255 + u32 pcdu5; /* Port 5 clock delay configuration */
258 +struct ltq_ethsw_pmac_pdi_regs {
259 + u32 hd_ctl; /* PMAC header control */
260 + u32 tl; /* PMAC type/length */
261 + u32 sa1; /* PMAC source address 1 */
262 + u32 sa2; /* PMAC source address 2 */
263 + u32 sa3; /* PMAC source address 3 */
264 + u32 da1; /* PMAC destination address 1 */
265 + u32 da2; /* PMAC destination address 2 */
266 + u32 da3; /* PMAC destination address 3 */
267 + u32 vlan; /* PMAC VLAN */
268 + u32 rx_ipg; /* PMAC interpacket gap in RX direction */
269 + u32 st_etype; /* PMAC special tag ethertype */
270 + u32 ewan; /* PMAC ethernet WAN group */
273 +struct ltq_mdio_phy_addr_reg {
277 + unsigned lnkst:2; /* Link status control */
278 + unsigned speed:2; /* Speed control */
279 + unsigned fdup:2; /* Full duplex control */
280 + unsigned fcontx:2; /* Flow control mode TX */
281 + unsigned fconrx:2; /* Flow control mode RX */
282 + unsigned addr:5; /* PHY address */
288 +enum ltq_mdio_phy_addr_lnkst {
289 + LTQ_MDIO_PHY_ADDR_LNKST_AUTO = 0,
290 + LTQ_MDIO_PHY_ADDR_LNKST_UP = 1,
291 + LTQ_MDIO_PHY_ADDR_LNKST_DOWN = 2,
294 +enum ltq_mdio_phy_addr_speed {
295 + LTQ_MDIO_PHY_ADDR_SPEED_M10 = 0,
296 + LTQ_MDIO_PHY_ADDR_SPEED_M100 = 1,
297 + LTQ_MDIO_PHY_ADDR_SPEED_G1 = 2,
298 + LTQ_MDIO_PHY_ADDR_SPEED_AUTO = 3,
301 +enum ltq_mdio_phy_addr_fdup {
302 + LTQ_MDIO_PHY_ADDR_FDUP_AUTO = 0,
303 + LTQ_MDIO_PHY_ADDR_FDUP_ENABLE = 1,
304 + LTQ_MDIO_PHY_ADDR_FDUP_DISABLE = 3,
307 +enum ltq_mdio_phy_addr_fcon {
308 + LTQ_MDIO_PHY_ADDR_FCON_AUTO = 0,
309 + LTQ_MDIO_PHY_ADDR_FCON_ENABLE = 1,
310 + LTQ_MDIO_PHY_ADDR_FCON_DISABLE = 3,
313 +struct ltq_mii_mii_cfg_reg {
316 + unsigned res:1; /* Hardware reset */
317 + unsigned en:1; /* xMII interface enable */
318 + unsigned isol:1; /* xMII interface isolate */
319 + unsigned ldclkdis:1; /* Link down clock disable */
321 + unsigned crs:2; /* CRS sensitivity config */
322 + unsigned rgmii_ibs:1; /* RGMII In Band status */
323 + unsigned rmii:1; /* RMII ref clock direction */
324 + unsigned miirate:3; /* xMII interface clock rate */
325 + unsigned miimode:4; /* xMII interface mode */
331 +enum ltq_mii_mii_cfg_miirate {
332 + LTQ_MII_MII_CFG_MIIRATE_M2P5 = 0,
333 + LTQ_MII_MII_CFG_MIIRATE_M25 = 1,
334 + LTQ_MII_MII_CFG_MIIRATE_M125 = 2,
335 + LTQ_MII_MII_CFG_MIIRATE_M50 = 3,
336 + LTQ_MII_MII_CFG_MIIRATE_AUTO = 4,
339 +enum ltq_mii_mii_cfg_miimode {
340 + LTQ_MII_MII_CFG_MIIMODE_MIIP = 0,
341 + LTQ_MII_MII_CFG_MIIMODE_MIIM = 1,
342 + LTQ_MII_MII_CFG_MIIMODE_RMIIP = 2,
343 + LTQ_MII_MII_CFG_MIIMODE_RMIIM = 3,
344 + LTQ_MII_MII_CFG_MIIMODE_RGMII = 4,
347 +struct ltq_eth_priv {
348 + struct ltq_dma_device *dma_dev;
349 + struct mii_dev *bus;
350 + struct eth_device *dev;
351 + struct phy_device *phymap[LTQ_ETHSW_MAX_GMAC];
355 +enum ltq_mdio_mbusy {
356 + LTQ_MDIO_MBUSY_IDLE = 0,
357 + LTQ_MDIO_MBUSY_BUSY = 1,
361 + LTQ_MDIO_OP_WRITE = 1,
362 + LTQ_MDIO_OP_READ = 2,
365 +struct ltq_mdio_access {
378 +enum LTQ_ETH_PORT_FLAGS {
379 + LTQ_ETH_PORT_NONE = 0,
380 + LTQ_ETH_PORT_PHY = 1,
381 + LTQ_ETH_PORT_SWITCH = (1 << 1),
382 + LTQ_ETH_PORT_MAC = (1 << 2),
385 +struct ltq_eth_port_config {
389 + phy_interface_t phy_if;
392 +struct ltq_eth_board_config {
393 + const struct ltq_eth_port_config *ports;
397 +static const struct ltq_eth_port_config eth_port_config[] = {
398 + /* GMAC0: external Lantiq PEF7071 10/100/1000 PHY for LAN port 0 */
399 + { 0, 0x0, LTQ_ETH_PORT_PHY, PHY_INTERFACE_MODE_RGMII },
400 + /* GMAC1: external Lantiq PEF7071 10/100/1000 PHY for LAN port 1 */
401 + { 1, 0x1, LTQ_ETH_PORT_PHY, PHY_INTERFACE_MODE_RGMII },
404 +static const struct ltq_eth_board_config board_config = {
405 + .ports = eth_port_config,
406 + .num_ports = ARRAY_SIZE(eth_port_config),
409 +static struct ltq_ethsw_mac_pdi_regs *ltq_ethsw_mac_pdi_regs =
410 + (struct ltq_ethsw_mac_pdi_regs *) CKSEG1ADDR(LTQ_SWITCH_MAC_PDI_0_BASE);
412 +static struct ltq_ethsw_mdio_pdi_regs *ltq_ethsw_mdio_pdi_regs =
413 + (struct ltq_ethsw_mdio_pdi_regs *) CKSEG1ADDR(LTQ_SWITCH_MDIO_PDI_BASE);
415 +static struct ltq_ethsw_mii_pdi_regs *ltq_ethsw_mii_pdi_regs =
416 + (struct ltq_ethsw_mii_pdi_regs *) CKSEG1ADDR(LTQ_SWITCH_MII_PDI_BASE);
418 +static struct ltq_ethsw_pmac_pdi_regs *ltq_ethsw_pmac_pdi_regs =
419 + (struct ltq_ethsw_pmac_pdi_regs *) CKSEG1ADDR(LTQ_SWITCH_PMAC_PDI_BASE);
422 +#define MAX_DMA_CHAN 0x8
423 +#define MAX_DMA_CRC_LEN 0x4
424 +#define MAX_DMA_DATA_LEN 0x600
426 +/* use 2 static channels for TX/RX
427 + depending on the SoC we need to use different DMA channels for ethernet */
428 +#define LTQ_ETOP_TX_CHANNEL 1
429 +#define LTQ_ETOP_RX_CHANNEL 0
431 +#define IS_TX(x) (x == LTQ_ETOP_TX_CHANNEL)
432 +#define IS_RX(x) (x == LTQ_ETOP_RX_CHANNEL)
434 +#define DRV_VERSION "1.0"
436 +static void __iomem *ltq_vrx200_membase;
438 +struct ltq_vrx200_chan {
441 + struct net_device *netdev;
442 + struct napi_struct napi;
443 + struct ltq_dma_channel dma;
444 + struct sk_buff *skb[LTQ_DESC_NUM];
447 +struct ltq_vrx200_priv {
448 + struct net_device *netdev;
449 + struct ltq_eth_data *pldata;
450 + struct resource *res;
452 + struct mii_bus *mii_bus;
453 + struct phy_device *phydev;
455 + struct ltq_vrx200_chan ch[MAX_DMA_CHAN];
456 + int tx_free[MAX_DMA_CHAN >> 1];
460 + struct clk *clk_ppe;
463 +static int ltq_vrx200_mdio_wr(struct mii_bus *bus, int phy_addr,
464 + int phy_reg, u16 phy_data);
467 +ltq_vrx200_alloc_skb(struct ltq_vrx200_chan *ch)
469 + ch->skb[ch->dma.desc] = dev_alloc_skb(MAX_DMA_DATA_LEN);
470 + if (!ch->skb[ch->dma.desc])
472 + ch->dma.desc_base[ch->dma.desc].addr = dma_map_single(NULL,
473 + ch->skb[ch->dma.desc]->data, MAX_DMA_DATA_LEN,
475 + ch->dma.desc_base[ch->dma.desc].addr =
476 + CPHYSADDR(ch->skb[ch->dma.desc]->data);
477 + ch->dma.desc_base[ch->dma.desc].ctl =
478 + LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) |
480 + skb_reserve(ch->skb[ch->dma.desc], NET_IP_ALIGN);
485 +ltq_vrx200_hw_receive(struct ltq_vrx200_chan *ch)
487 + struct ltq_vrx200_priv *priv = netdev_priv(ch->netdev);
488 + struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc];
489 + struct sk_buff *skb = ch->skb[ch->dma.desc];
490 + int len = (desc->ctl & LTQ_DMA_SIZE_MASK) - MAX_DMA_CRC_LEN;
491 + unsigned long flags;
493 + spin_lock_irqsave(&priv->lock, flags);
494 + if (ltq_vrx200_alloc_skb(ch)) {
495 + netdev_err(ch->netdev,
496 + "failed to allocate new rx buffer, stopping DMA\n");
497 + ltq_dma_close(&ch->dma);
500 + ch->dma.desc %= LTQ_DESC_NUM;
501 + spin_unlock_irqrestore(&priv->lock, flags);
504 + skb->dev = ch->netdev;
505 + skb->protocol = eth_type_trans(skb, ch->netdev);
506 + netif_receive_skb(skb);
510 +ltq_vrx200_poll_rx(struct napi_struct *napi, int budget)
512 + struct ltq_vrx200_chan *ch = container_of(napi,
513 + struct ltq_vrx200_chan, napi);
514 + struct ltq_vrx200_priv *priv = netdev_priv(ch->netdev);
517 + unsigned long flags;
519 + while ((rx < budget) && !complete) {
520 + struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc];
522 + if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) == LTQ_DMA_C) {
523 + ltq_vrx200_hw_receive(ch);
529 + if (complete || !rx) {
530 + napi_complete(&ch->napi);
531 + spin_lock_irqsave(&priv->lock, flags);
532 + ltq_dma_ack_irq(&ch->dma);
533 + spin_unlock_irqrestore(&priv->lock, flags);
539 +ltq_vrx200_poll_tx(struct napi_struct *napi, int budget)
541 + struct ltq_vrx200_chan *ch =
542 + container_of(napi, struct ltq_vrx200_chan, napi);
543 + struct ltq_vrx200_priv *priv = netdev_priv(ch->netdev);
544 + struct netdev_queue *txq =
545 + netdev_get_tx_queue(ch->netdev, ch->idx >> 1);
546 + unsigned long flags;
548 + spin_lock_irqsave(&priv->lock, flags);
549 + while ((ch->dma.desc_base[ch->tx_free].ctl &
550 + (LTQ_DMA_OWN | LTQ_DMA_C)) == LTQ_DMA_C) {
551 + dev_kfree_skb_any(ch->skb[ch->tx_free]);
552 + ch->skb[ch->tx_free] = NULL;
553 + memset(&ch->dma.desc_base[ch->tx_free], 0,
554 + sizeof(struct ltq_dma_desc));
556 + ch->tx_free %= LTQ_DESC_NUM;
558 + spin_unlock_irqrestore(&priv->lock, flags);
560 + if (netif_tx_queue_stopped(txq))
561 + netif_tx_start_queue(txq);
562 + napi_complete(&ch->napi);
563 + spin_lock_irqsave(&priv->lock, flags);
564 + ltq_dma_ack_irq(&ch->dma);
565 + spin_unlock_irqrestore(&priv->lock, flags);
570 +ltq_vrx200_dma_irq(int irq, void *_priv)
572 + struct ltq_vrx200_priv *priv = _priv;
573 + int ch = irq - LTQ_DMA_ETOP;
575 + napi_schedule(&priv->ch[ch].napi);
576 + return IRQ_HANDLED;
580 +ltq_vrx200_free_channel(struct net_device *dev, struct ltq_vrx200_chan *ch)
582 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
584 + ltq_dma_free(&ch->dma);
586 + free_irq(ch->dma.irq, priv);
587 + if (IS_RX(ch->idx)) {
589 + for (desc = 0; desc < LTQ_DESC_NUM; desc++)
590 + dev_kfree_skb_any(ch->skb[ch->dma.desc]);
595 +ltq_vrx200_hw_exit(struct net_device *dev)
597 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
600 + clk_disable(priv->clk_ppe);
602 + for (i = 0; i < MAX_DMA_CHAN; i++)
603 + if (IS_TX(i) || IS_RX(i))
604 + ltq_vrx200_free_channel(dev, &priv->ch[i]);
607 +static void *ltq_eth_phy_addr_reg(int num)
611 + return <q_ethsw_mdio_pdi_regs->phy_addr_0;
613 + return <q_ethsw_mdio_pdi_regs->phy_addr_1;
615 + return <q_ethsw_mdio_pdi_regs->phy_addr_2;
617 + return <q_ethsw_mdio_pdi_regs->phy_addr_3;
619 + return <q_ethsw_mdio_pdi_regs->phy_addr_4;
621 + return <q_ethsw_mdio_pdi_regs->phy_addr_5;
627 +static void *ltq_eth_mii_cfg_reg(int num)
631 + return <q_ethsw_mii_pdi_regs->mii_cfg0;
633 + return <q_ethsw_mii_pdi_regs->mii_cfg1;
635 + return <q_ethsw_mii_pdi_regs->mii_cfg2;
637 + return <q_ethsw_mii_pdi_regs->mii_cfg3;
639 + return <q_ethsw_mii_pdi_regs->mii_cfg4;
641 + return <q_ethsw_mii_pdi_regs->mii_cfg5;
647 +static void ltq_eth_gmac_update(struct phy_device *phydev, int num)
649 + struct ltq_mdio_phy_addr_reg phy_addr_reg;
650 + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
651 + void *phy_addr = ltq_eth_phy_addr_reg(num);
652 + void *mii_cfg = ltq_eth_mii_cfg_reg(num);
654 + phy_addr_reg.val = ltq_r32(phy_addr);
655 + mii_cfg_reg.val = ltq_r32(mii_cfg);
657 + phy_addr_reg.bits.addr = phydev->addr;
660 + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_UP;
662 + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_DOWN;
664 + switch (phydev->speed) {
666 + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_G1;
667 + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M125;
670 + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M100;
671 + switch (mii_cfg_reg.bits.miimode) {
672 + case LTQ_MII_MII_CFG_MIIMODE_RMIIM:
673 + case LTQ_MII_MII_CFG_MIIMODE_RMIIP:
674 + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M50;
677 + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M25;
682 + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M10;
683 + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M2P5;
687 + if (phydev->duplex == DUPLEX_FULL)
688 + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_ENABLE;
690 + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_DISABLE;
692 + dbg_ltq_writel(phy_addr, phy_addr_reg.val);
693 + dbg_ltq_writel(mii_cfg, mii_cfg_reg.val);
698 +static void ltq_eth_port_config(struct ltq_vrx200_priv *priv,
699 + const struct ltq_eth_port_config *port)
701 + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
702 + void *mii_cfg = ltq_eth_mii_cfg_reg(port->num);
703 + int setup_gpio = 0;
705 + mii_cfg_reg.val = ltq_r32(mii_cfg);
708 + switch (port->num) {
709 + case 0: /* xMII0 */
710 + case 1: /* xMII1 */
711 + switch (port->phy_if) {
712 + case PHY_INTERFACE_MODE_MII:
713 + if (port->flags & LTQ_ETH_PORT_PHY)
714 + /* MII MAC mode, connected to external PHY */
715 + mii_cfg_reg.bits.miimode =
716 + LTQ_MII_MII_CFG_MIIMODE_MIIM;
718 + /* MII PHY mode, connected to external MAC */
719 + mii_cfg_reg.bits.miimode =
720 + LTQ_MII_MII_CFG_MIIMODE_MIIP;
723 + case PHY_INTERFACE_MODE_RMII:
724 + if (port->flags & LTQ_ETH_PORT_PHY)
725 + /* RMII MAC mode, connected to external PHY */
726 + mii_cfg_reg.bits.miimode =
727 + LTQ_MII_MII_CFG_MIIMODE_RMIIM;
729 + /* RMII PHY mode, connected to external MAC */
730 + mii_cfg_reg.bits.miimode =
731 + LTQ_MII_MII_CFG_MIIMODE_RMIIP;
734 + case PHY_INTERFACE_MODE_RGMII:
735 + /* RGMII MAC mode, connected to external PHY */
736 + mii_cfg_reg.bits.miimode =
737 + LTQ_MII_MII_CFG_MIIMODE_RGMII;
744 + case 2: /* internal GPHY0 */
745 + case 3: /* internal GPHY0 */
746 + case 4: /* internal GPHY1 */
747 + switch (port->phy_if) {
748 + case PHY_INTERFACE_MODE_MII:
749 + case PHY_INTERFACE_MODE_GMII:
750 + /* MII MAC mode, connected to internal GPHY */
751 + mii_cfg_reg.bits.miimode =
752 + LTQ_MII_MII_CFG_MIIMODE_MIIM;
759 + case 5: /* internal GPHY1 or xMII2 */
760 + switch (port->phy_if) {
761 + case PHY_INTERFACE_MODE_MII:
762 + /* MII MAC mode, connected to internal GPHY */
763 + mii_cfg_reg.bits.miimode =
764 + LTQ_MII_MII_CFG_MIIMODE_MIIM;
767 + case PHY_INTERFACE_MODE_RGMII:
768 + /* RGMII MAC mode, connected to external PHY */
769 + mii_cfg_reg.bits.miimode =
770 + LTQ_MII_MII_CFG_MIIMODE_RGMII;
781 + /* Enable MII interface */
782 + mii_cfg_reg.bits.en = port->flags ? 1 : 0;
783 + dbg_ltq_writel(mii_cfg, mii_cfg_reg.val);
787 +static void ltq_eth_gmac_init(int num)
789 + struct ltq_mdio_phy_addr_reg phy_addr_reg;
790 + struct ltq_mii_mii_cfg_reg mii_cfg_reg;
791 + void *phy_addr = ltq_eth_phy_addr_reg(num);
792 + void *mii_cfg = ltq_eth_mii_cfg_reg(num);
793 + struct ltq_ethsw_mac_pdi_x_regs *mac_pdi_regs;
795 + mac_pdi_regs = <q_ethsw_mac_pdi_regs->mac[num];
797 + /* Reset PHY status to link down */
798 + phy_addr_reg.val = ltq_r32(phy_addr);
799 + phy_addr_reg.bits.addr = num;
800 + phy_addr_reg.bits.lnkst = LTQ_MDIO_PHY_ADDR_LNKST_DOWN;
801 + phy_addr_reg.bits.speed = LTQ_MDIO_PHY_ADDR_SPEED_M10;
802 + phy_addr_reg.bits.fdup = LTQ_MDIO_PHY_ADDR_FDUP_DISABLE;
803 + dbg_ltq_writel(phy_addr, phy_addr_reg.val);
805 + /* Reset and disable MII interface */
806 + mii_cfg_reg.val = ltq_r32(mii_cfg);
807 + mii_cfg_reg.bits.en = 0;
808 + mii_cfg_reg.bits.res = 1;
809 + mii_cfg_reg.bits.miirate = LTQ_MII_MII_CFG_MIIRATE_M2P5;
810 + dbg_ltq_writel(mii_cfg, mii_cfg_reg.val);
813 + * Enable padding of short frames, enable frame checksum generation
814 + * in transmit direction
816 + dbg_ltq_writel(&mac_pdi_regs->ctrl_0, LTQ_ETHSW_MAC_CTRL0_PADEN |
817 + LTQ_ETHSW_MAC_CTRL0_FCS);
819 + /* Set inter packet gap size to 12 bytes */
820 + dbg_ltq_writel(&mac_pdi_regs->ctrl_1, 12);
823 + * Configure frame length checks:
824 + * - allow jumbo frames
825 + * - enable long length check
826 + * - enable short length without VLAN tags
828 + dbg_ltq_writel(&mac_pdi_regs->ctrl_2, LTQ_ETHSW_MAC_CTRL2_MLEN |
829 + LTQ_ETHSW_MAC_CTRL2_LCHKL |
830 + LTQ_ETHSW_MAC_CTRL2_LCHKS_UNTAG);
834 +static void ltq_eth_pmac_init(void)
836 + struct ltq_ethsw_mac_pdi_x_regs *mac_pdi_regs;
838 + mac_pdi_regs = <q_ethsw_mac_pdi_regs->mac[LTQ_ETHSW_PMAC];
841 + * Enable padding of short frames, enable frame checksum generation
842 + * in transmit direction
844 + dbg_ltq_writel(&mac_pdi_regs->ctrl_0, LTQ_ETHSW_MAC_CTRL0_PADEN |
845 + LTQ_ETHSW_MAC_CTRL0_FCS);
848 + * Configure frame length checks:
849 + * - allow jumbo frames
850 + * - enable long length check
851 + * - enable short length without VLAN tags
853 + dbg_ltq_writel(&mac_pdi_regs->ctrl_2, LTQ_ETHSW_MAC_CTRL2_MLEN |
854 + LTQ_ETHSW_MAC_CTRL2_LCHKL |
855 + LTQ_ETHSW_MAC_CTRL2_LCHKS_UNTAG);
858 + * Apply workaround for buffer congestion:
859 + * - shorten preambel to 1 byte
860 + * - set minimum inter packet gap size to 7 bytes
861 + * - enable receive buffer bypass mode
863 + dbg_ltq_writel(&mac_pdi_regs->ctrl_1, LTQ_ETHSW_MAC_CTRL1_SHORTPRE | 7);
864 + dbg_ltq_writel(&mac_pdi_regs->ctrl_6,
865 + (6 << LTQ_ETHSW_MAC_CTRL6_RBUF_DLY_WP_SHIFT) |
866 + LTQ_ETHSW_MAC_CTRL6_RXBUF_BYPASS);
868 + /* Set request assertion threshold to 8, IPG counter to 11 */
869 + dbg_ltq_writel(<q_ethsw_pmac_pdi_regs->rx_ipg, 0x8B);
872 + * Configure frame header control:
873 + * - enable reaction on pause frames (flow control)
874 + * - remove CRC for packets from PMAC to DMA
875 + * - add CRC for packets from DMA to PMAC
877 + dbg_ltq_writel(<q_ethsw_pmac_pdi_regs->hd_ctl, LTQ_ETHSW_PMAC_HD_CTL_FC |
878 + /*LTQ_ETHSW_PMAC_HD_CTL_RC | */LTQ_ETHSW_PMAC_HD_CTL_AC);
882 +ltq_vrx200_hw_init(struct net_device *dev)
884 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
888 + netdev_info(dev, "setting up dma\n");
889 + ltq_dma_init_port(DMA_PORT_ETOP);
891 + netdev_info(dev, "setting up pmu\n");
892 + clk_enable(priv->clk_ppe);
894 + /* Reset ethernet and switch subsystems */
895 + netdev_info(dev, "reset core\n");
896 + ltq_reset_once(BIT(8), 10);
898 + /* Enable switch macro */
899 + ltq_setbits(<q_ethsw_mdio_pdi_regs->glob_ctrl,
900 + LTQ_ETHSW_GLOB_CTRL_SE);
902 + /* Disable MDIO auto-polling for all ports */
903 + dbg_ltq_writel(<q_ethsw_mdio_pdi_regs->mdc_cfg_0, 0);
906 + * Enable and set MDIO management clock to 2.5 MHz. This is the
907 + * maximum clock for FE PHYs.
908 + * Formula for clock is:
911 + * x = ----------- - 1
914 + dbg_ltq_writel(<q_ethsw_mdio_pdi_regs->mdc_cfg_1,
915 + LTQ_ETHSW_MDC_CFG1_MCEN | 9);
917 + /* Init MAC connected to CPU */
918 + ltq_eth_pmac_init();
920 + /* Init MACs connected to external MII interfaces */
921 + for (i = 0; i < LTQ_ETHSW_MAX_GMAC; i++)
922 + ltq_eth_gmac_init(i);
924 + for (i = 0; i < MAX_DMA_CHAN && !err; i++) {
925 + int irq = LTQ_DMA_ETOP + i;
926 + struct ltq_vrx200_chan *ch = &priv->ch[i];
928 + ch->idx = ch->dma.nr = i;
931 + ltq_dma_alloc_tx(&ch->dma);
932 + err = request_irq(irq, ltq_vrx200_dma_irq, IRQF_DISABLED,
933 + "vrx200_tx", priv);
934 + } else if (IS_RX(i)) {
935 + ltq_dma_alloc_rx(&ch->dma);
936 + for (ch->dma.desc = 0; ch->dma.desc < LTQ_DESC_NUM;
938 + if (ltq_vrx200_alloc_skb(ch))
941 + err = request_irq(irq, ltq_vrx200_dma_irq, IRQF_DISABLED,
942 + "vrx200_rx", priv);
947 + for (i = 0; i < board_config.num_ports; i++)
948 + ltq_eth_port_config(priv, &board_config.ports[i]);
953 +ltq_vrx200_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
955 + strcpy(info->driver, "Lantiq ETOP");
956 + strcpy(info->bus_info, "internal");
957 + strcpy(info->version, DRV_VERSION);
961 +ltq_vrx200_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
963 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
965 + return phy_ethtool_gset(priv->phydev, cmd);
969 +ltq_vrx200_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
971 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
973 + return phy_ethtool_sset(priv->phydev, cmd);
977 +ltq_vrx200_nway_reset(struct net_device *dev)
979 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
981 + return phy_start_aneg(priv->phydev);
984 +static const struct ethtool_ops ltq_vrx200_ethtool_ops = {
985 + .get_drvinfo = ltq_vrx200_get_drvinfo,
986 + .get_settings = ltq_vrx200_get_settings,
987 + .set_settings = ltq_vrx200_set_settings,
988 + .nway_reset = ltq_vrx200_nway_reset,
991 +static inline int ltq_mdio_poll(struct mii_bus *bus)
993 + struct ltq_mdio_access acc;
994 + unsigned cnt = 10000;
996 + while (likely(cnt--)) {
997 + acc.val = ltq_r32(<q_ethsw_mdio_pdi_regs->mdio_ctrl);
998 + if (!acc.bits.mbusy)
1006 +ltq_vrx200_mdio_wr(struct mii_bus *bus, int addr, int regnum, u16 val)
1008 + struct ltq_mdio_access acc;
1012 + acc.bits.mbusy = LTQ_MDIO_MBUSY_BUSY;
1013 + acc.bits.op = LTQ_MDIO_OP_WRITE;
1014 + acc.bits.phyad = addr;
1015 + acc.bits.regad = regnum;
1017 + ret = ltq_mdio_poll(bus);
1021 + dbg_ltq_writel(<q_ethsw_mdio_pdi_regs->mdio_write, val);
1022 + dbg_ltq_writel(<q_ethsw_mdio_pdi_regs->mdio_ctrl, acc.val);
1028 +ltq_vrx200_mdio_rd(struct mii_bus *bus, int addr, int regnum)
1030 + struct ltq_mdio_access acc;
1034 + acc.bits.mbusy = LTQ_MDIO_MBUSY_BUSY;
1035 + acc.bits.op = LTQ_MDIO_OP_READ;
1036 + acc.bits.phyad = addr;
1037 + acc.bits.regad = regnum;
1039 + ret = ltq_mdio_poll(bus);
1043 + dbg_ltq_writel(<q_ethsw_mdio_pdi_regs->mdio_ctrl, acc.val);
1045 + ret = ltq_mdio_poll(bus);
1049 + ret = ltq_r32(<q_ethsw_mdio_pdi_regs->mdio_read);
1057 +ltq_vrx200_mdio_link(struct net_device *dev)
1059 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1060 + ltq_eth_gmac_update(priv->phydev, 0);
1064 +ltq_vrx200_mdio_probe(struct net_device *dev)
1066 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1067 + struct phy_device *phydev = NULL;
1070 + phydev = priv->mii_bus->phy_map[0];
1073 + netdev_err(dev, "no PHY found\n");
1077 + phydev = phy_connect(dev, dev_name(&phydev->dev), <q_vrx200_mdio_link,
1080 + if (IS_ERR(phydev)) {
1081 + netdev_err(dev, "Could not attach to PHY\n");
1082 + return PTR_ERR(phydev);
1085 + phydev->supported &= (SUPPORTED_10baseT_Half
1086 + | SUPPORTED_10baseT_Full
1087 + | SUPPORTED_100baseT_Half
1088 + | SUPPORTED_100baseT_Full
1089 + | SUPPORTED_1000baseT_Half
1090 + | SUPPORTED_1000baseT_Full
1091 + | SUPPORTED_Autoneg
1094 + phydev->advertising = phydev->supported;
1095 + priv->phydev = phydev;
1097 + pr_info("%s: attached PHY [%s] (phy_addr=%s, irq=%d)\n",
1098 + dev->name, phydev->drv->name,
1099 + dev_name(&phydev->dev), phydev->irq);
1101 + val = ltq_vrx200_mdio_rd(priv->mii_bus, MDIO_DEVAD_NONE, MII_CTRL1000);
1102 + val |= ADVERTIZE_MPD;
1103 + ltq_vrx200_mdio_wr(priv->mii_bus, MDIO_DEVAD_NONE, MII_CTRL1000, val);
1104 + ltq_vrx200_mdio_wr(priv->mii_bus, 0, 0, 0x1040);
1106 + phy_start_aneg(phydev);
1112 +ltq_vrx200_mdio_init(struct net_device *dev)
1114 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1118 + priv->mii_bus = mdiobus_alloc();
1119 + if (!priv->mii_bus) {
1120 + netdev_err(dev, "failed to allocate mii bus\n");
1125 + priv->mii_bus->priv = dev;
1126 + priv->mii_bus->read = ltq_vrx200_mdio_rd;
1127 + priv->mii_bus->write = ltq_vrx200_mdio_wr;
1128 + priv->mii_bus->name = "ltq_mii";
1129 + snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%x", 0);
1130 + priv->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
1131 + if (!priv->mii_bus->irq) {
1133 + goto err_out_free_mdiobus;
1136 + for (i = 0; i < PHY_MAX_ADDR; ++i)
1137 + priv->mii_bus->irq[i] = PHY_POLL;
1139 + if (mdiobus_register(priv->mii_bus)) {
1141 + goto err_out_free_mdio_irq;
1144 + if (ltq_vrx200_mdio_probe(dev)) {
1146 + goto err_out_unregister_bus;
1150 +err_out_unregister_bus:
1151 + mdiobus_unregister(priv->mii_bus);
1152 +err_out_free_mdio_irq:
1153 + kfree(priv->mii_bus->irq);
1154 +err_out_free_mdiobus:
1155 + mdiobus_free(priv->mii_bus);
1161 +ltq_vrx200_mdio_cleanup(struct net_device *dev)
1163 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1165 + phy_disconnect(priv->phydev);
1166 + mdiobus_unregister(priv->mii_bus);
1167 + kfree(priv->mii_bus->irq);
1168 + mdiobus_free(priv->mii_bus);
1171 +void phy_dump(struct net_device *dev)
1173 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1175 + for (i = 0; i < 0x1F; i++) {
1176 + unsigned int val = ltq_vrx200_mdio_rd(priv->mii_bus, 0, i);
1177 + printk("%d %4X\n", i, val);
1182 +ltq_vrx200_open(struct net_device *dev)
1184 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1186 + unsigned long flags;
1188 + for (i = 0; i < MAX_DMA_CHAN; i++) {
1189 + struct ltq_vrx200_chan *ch = &priv->ch[i];
1191 + if (!IS_TX(i) && (!IS_RX(i)))
1193 + napi_enable(&ch->napi);
1194 + spin_lock_irqsave(&priv->lock, flags);
1195 + ltq_dma_open(&ch->dma);
1196 + spin_unlock_irqrestore(&priv->lock, flags);
1198 + if (priv->phydev) {
1199 + phy_start(priv->phydev);
1202 + netif_tx_start_all_queues(dev);
1207 +ltq_vrx200_stop(struct net_device *dev)
1209 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1211 + unsigned long flags;
1213 + netif_tx_stop_all_queues(dev);
1215 + phy_stop(priv->phydev);
1216 + for (i = 0; i < MAX_DMA_CHAN; i++) {
1217 + struct ltq_vrx200_chan *ch = &priv->ch[i];
1219 + if (!IS_RX(i) && !IS_TX(i))
1221 + napi_disable(&ch->napi);
1222 + spin_lock_irqsave(&priv->lock, flags);
1223 + ltq_dma_close(&ch->dma);
1224 + spin_unlock_irqrestore(&priv->lock, flags);
1230 +ltq_vrx200_tx(struct sk_buff *skb, struct net_device *dev)
1232 + int queue = skb_get_queue_mapping(skb);
1233 + struct netdev_queue *txq = netdev_get_tx_queue(dev, queue);
1234 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1235 + struct ltq_vrx200_chan *ch = &priv->ch[(queue << 1) | 1];
1236 + struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc];
1237 + unsigned long flags;
1241 + len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
1243 + if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) || ch->skb[ch->dma.desc]) {
1244 + netdev_err(dev, "tx ring full\n");
1245 + netif_tx_stop_queue(txq);
1246 + return NETDEV_TX_BUSY;
1249 + /* dma needs to start on a 16 byte aligned address */
1250 + byte_offset = CPHYSADDR(skb->data) % 16;
1251 + ch->skb[ch->dma.desc] = skb;
1253 + dev->trans_start = jiffies;
1255 + spin_lock_irqsave(&priv->lock, flags);
1256 + desc->addr = ((unsigned int) dma_map_single(NULL, skb->data, len,
1257 + DMA_TO_DEVICE)) - byte_offset;
1259 + desc->ctl = LTQ_DMA_OWN | LTQ_DMA_SOP | LTQ_DMA_EOP |
1260 + LTQ_DMA_TX_OFFSET(byte_offset) | (len & LTQ_DMA_SIZE_MASK);
1262 + ch->dma.desc %= LTQ_DESC_NUM;
1263 + spin_unlock_irqrestore(&priv->lock, flags);
1265 + if (ch->dma.desc_base[ch->dma.desc].ctl & LTQ_DMA_OWN)
1266 + netif_tx_stop_queue(txq);
1268 + return NETDEV_TX_OK;
1272 +ltq_vrx200_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1274 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1276 + /* TODO: mii-toll reports "No MII transceiver present!." ?!*/
1277 + return phy_mii_ioctl(priv->phydev, rq, cmd);
1281 +ltq_vrx200_select_queue(struct net_device *dev, struct sk_buff *skb)
1283 + /* we are currently only using the first queue */
1288 +ltq_vrx200_init(struct net_device *dev)
1290 + struct ltq_vrx200_priv *priv = netdev_priv(dev);
1291 + struct sockaddr mac;
1295 + dev->watchdog_timeo = 10 * HZ;
1297 + err = ltq_vrx200_hw_init(dev);
1301 + memcpy(&mac, &priv->pldata->mac, sizeof(struct sockaddr));
1302 + if (!is_valid_ether_addr(mac.sa_data)) {
1303 + pr_warn("vrx200: invalid MAC, using random\n");
1304 + random_ether_addr(mac.sa_data);
1306 + eth_mac_addr(dev, &mac);
1308 + if (!ltq_vrx200_mdio_init(dev))
1309 + dev->ethtool_ops = <q_vrx200_ethtool_ops;
1311 + pr_warn("vrx200: mdio probe failed\n");;
1315 + ltq_vrx200_hw_exit(dev);
1320 +ltq_vrx200_tx_timeout(struct net_device *dev)
1324 + ltq_vrx200_hw_exit(dev);
1325 + err = ltq_vrx200_hw_init(dev);
1328 + dev->trans_start = jiffies;
1329 + netif_wake_queue(dev);
1333 + ltq_vrx200_hw_exit(dev);
1334 + netdev_err(dev, "failed to restart vrx200 after TX timeout\n");
1337 +static const struct net_device_ops ltq_eth_netdev_ops = {
1338 + .ndo_open = ltq_vrx200_open,
1339 + .ndo_stop = ltq_vrx200_stop,
1340 + .ndo_start_xmit = ltq_vrx200_tx,
1341 + .ndo_change_mtu = eth_change_mtu,
1342 + .ndo_do_ioctl = ltq_vrx200_ioctl,
1343 + .ndo_set_mac_address = eth_mac_addr,
1344 + .ndo_validate_addr = eth_validate_addr,
1345 + .ndo_select_queue = ltq_vrx200_select_queue,
1346 + .ndo_init = ltq_vrx200_init,
1347 + .ndo_tx_timeout = ltq_vrx200_tx_timeout,
1350 +static int __devinit
1351 +ltq_vrx200_probe(struct platform_device *pdev)
1353 + struct net_device *dev;
1354 + struct ltq_vrx200_priv *priv;
1355 + struct resource *res;
1359 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1361 + dev_err(&pdev->dev, "failed to get vrx200 resource\n");
1366 + res = devm_request_mem_region(&pdev->dev, res->start,
1367 + resource_size(res), dev_name(&pdev->dev));
1369 + dev_err(&pdev->dev, "failed to request vrx200 resource\n");
1374 + ltq_vrx200_membase = devm_ioremap_nocache(&pdev->dev,
1375 + res->start, resource_size(res));
1376 + if (!ltq_vrx200_membase) {
1377 + dev_err(&pdev->dev, "failed to remap vrx200 engine %d\n",
1383 + if (ltq_gpio_request(&pdev->dev, 42, 2, 1, "MDIO") ||
1384 + ltq_gpio_request(&pdev->dev, 43, 2, 1, "MDC")) {
1385 + dev_err(&pdev->dev, "failed to request MDIO gpios\n");
1390 + dev = alloc_etherdev_mq(sizeof(struct ltq_vrx200_priv), 4);
1391 + strcpy(dev->name, "eth%d");
1392 + dev->netdev_ops = <q_eth_netdev_ops;
1393 + priv = netdev_priv(dev);
1395 + priv->pldata = dev_get_platdata(&pdev->dev);
1396 + priv->netdev = dev;
1398 + priv->clk_ppe = clk_get(&pdev->dev, NULL);
1399 + if (IS_ERR(priv->clk_ppe))
1400 + return PTR_ERR(priv->clk_ppe);
1402 + spin_lock_init(&priv->lock);
1404 + for (i = 0; i < MAX_DMA_CHAN; i++) {
1406 + netif_napi_add(dev, &priv->ch[i].napi,
1407 + ltq_vrx200_poll_tx, 8);
1408 + else if (IS_RX(i))
1409 + netif_napi_add(dev, &priv->ch[i].napi,
1410 + ltq_vrx200_poll_rx, 32);
1411 + priv->ch[i].netdev = dev;
1414 + err = register_netdev(dev);
1418 + platform_set_drvdata(pdev, dev);
1427 +static int __devexit
1428 +ltq_vrx200_remove(struct platform_device *pdev)
1430 + struct net_device *dev = platform_get_drvdata(pdev);
1433 + netif_tx_stop_all_queues(dev);
1434 + ltq_vrx200_hw_exit(dev);
1435 + ltq_vrx200_mdio_cleanup(dev);
1436 + unregister_netdev(dev);
1441 +static struct platform_driver ltq_mii_driver = {
1442 + .probe = ltq_vrx200_probe,
1443 + .remove = __devexit_p(ltq_vrx200_remove),
1445 + .name = "ltq_vrx200",
1446 + .owner = THIS_MODULE,
1450 +module_platform_driver(ltq_mii_driver);
1452 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
1453 +MODULE_DESCRIPTION("Lantiq SoC ETOP");
1454 +MODULE_LICENSE("GPL");