1 From ad11aedcc16574c0b3d3f5e40c67227d1846b94e Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 22 Apr 2013 23:20:03 +0200
4 Subject: [PATCH 16/33] NET: MIPS: add ralink SoC ethernet driver
6 Add support for Ralink FE and ESW.
8 Signed-off-by: John Crispin <blogic@openwrt.org>
10 .../include/asm/mach-ralink/rt305x_esw_platform.h | 27 +
11 arch/mips/ralink/rt305x.c | 1 +
12 drivers/net/ethernet/Kconfig | 1 +
13 drivers/net/ethernet/Makefile | 1 +
14 drivers/net/ethernet/ralink/Kconfig | 31 +
15 drivers/net/ethernet/ralink/Makefile | 18 +
16 drivers/net/ethernet/ralink/esw_rt3052.c | 1463 ++++++++++++++++++++
17 drivers/net/ethernet/ralink/esw_rt3052.h | 32 +
18 drivers/net/ethernet/ralink/gsw_mt7620a.c | 1027 ++++++++++++++
19 drivers/net/ethernet/ralink/gsw_mt7620a.h | 29 +
20 drivers/net/ethernet/ralink/mdio.c | 245 ++++
21 drivers/net/ethernet/ralink/mdio.h | 29 +
22 drivers/net/ethernet/ralink/mdio_rt2880.c | 232 ++++
23 drivers/net/ethernet/ralink/mdio_rt2880.h | 26 +
24 drivers/net/ethernet/ralink/ralink_soc_eth.c | 735 ++++++++++
25 drivers/net/ethernet/ralink/ralink_soc_eth.h | 374 +++++
26 drivers/net/ethernet/ralink/soc_mt7620.c | 111 ++
27 drivers/net/ethernet/ralink/soc_rt2880.c | 51 +
28 drivers/net/ethernet/ralink/soc_rt305x.c | 113 ++
29 drivers/net/ethernet/ralink/soc_rt3883.c | 60 +
30 20 files changed, 4606 insertions(+)
31 create mode 100644 arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h
32 create mode 100644 drivers/net/ethernet/ralink/Kconfig
33 create mode 100644 drivers/net/ethernet/ralink/Makefile
34 create mode 100644 drivers/net/ethernet/ralink/esw_rt3052.c
35 create mode 100644 drivers/net/ethernet/ralink/esw_rt3052.h
36 create mode 100644 drivers/net/ethernet/ralink/gsw_mt7620a.c
37 create mode 100644 drivers/net/ethernet/ralink/gsw_mt7620a.h
38 create mode 100644 drivers/net/ethernet/ralink/mdio.c
39 create mode 100644 drivers/net/ethernet/ralink/mdio.h
40 create mode 100644 drivers/net/ethernet/ralink/mdio_rt2880.c
41 create mode 100644 drivers/net/ethernet/ralink/mdio_rt2880.h
42 create mode 100644 drivers/net/ethernet/ralink/ralink_soc_eth.c
43 create mode 100644 drivers/net/ethernet/ralink/ralink_soc_eth.h
44 create mode 100644 drivers/net/ethernet/ralink/soc_mt7620.c
45 create mode 100644 drivers/net/ethernet/ralink/soc_rt2880.c
46 create mode 100644 drivers/net/ethernet/ralink/soc_rt305x.c
47 create mode 100644 drivers/net/ethernet/ralink/soc_rt3883.c
49 Index: linux-3.10.21/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h
50 ===================================================================
51 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
52 +++ linux-3.10.21/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h 2013-12-09 13:26:42.320125202 +0100
55 + * Ralink RT305x SoC platform device registration
57 + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
59 + * This program is free software; you can redistribute it and/or modify it
60 + * under the terms of the GNU General Public License version 2 as published
61 + * by the Free Software Foundation.
64 +#ifndef _RT305X_ESW_PLATFORM_H
65 +#define _RT305X_ESW_PLATFORM_H
68 + RT305X_ESW_VLAN_CONFIG_NONE = 0,
69 + RT305X_ESW_VLAN_CONFIG_LLLLW,
70 + RT305X_ESW_VLAN_CONFIG_WLLLL,
73 +struct rt305x_esw_platform_data
76 + u32 reg_initval_fct2;
77 + u32 reg_initval_fpa2;
80 +#endif /* _RT305X_ESW_PLATFORM_H */
81 Index: linux-3.10.21/arch/mips/ralink/rt305x.c
82 ===================================================================
83 --- linux-3.10.21.orig/arch/mips/ralink/rt305x.c 2013-11-29 20:12:03.000000000 +0100
84 +++ linux-3.10.21/arch/mips/ralink/rt305x.c 2013-12-09 14:04:34.200179338 +0100
88 ralink_clk_add("cpu", cpu_rate);
89 + ralink_clk_add("sys", sys_rate);
90 ralink_clk_add("10000b00.spi", sys_rate);
91 ralink_clk_add("10000100.timer", wdt_rate);
92 ralink_clk_add("10000120.watchdog", wdt_rate);
93 Index: linux-3.10.21/drivers/net/ethernet/Kconfig
94 ===================================================================
95 --- linux-3.10.21.orig/drivers/net/ethernet/Kconfig 2013-11-29 20:12:03.000000000 +0100
96 +++ linux-3.10.21/drivers/net/ethernet/Kconfig 2013-12-09 13:26:42.324125203 +0100
98 source "drivers/net/ethernet/packetengines/Kconfig"
99 source "drivers/net/ethernet/pasemi/Kconfig"
100 source "drivers/net/ethernet/qlogic/Kconfig"
101 +source "drivers/net/ethernet/ralink/Kconfig"
102 source "drivers/net/ethernet/realtek/Kconfig"
103 source "drivers/net/ethernet/renesas/Kconfig"
104 source "drivers/net/ethernet/rdc/Kconfig"
105 Index: linux-3.10.21/drivers/net/ethernet/Makefile
106 ===================================================================
107 --- linux-3.10.21.orig/drivers/net/ethernet/Makefile 2013-11-29 20:12:03.000000000 +0100
108 +++ linux-3.10.21/drivers/net/ethernet/Makefile 2013-12-09 13:26:42.324125203 +0100
110 obj-$(CONFIG_NET_PACKET_ENGINE) += packetengines/
111 obj-$(CONFIG_NET_VENDOR_PASEMI) += pasemi/
112 obj-$(CONFIG_NET_VENDOR_QLOGIC) += qlogic/
113 +obj-$(CONFIG_NET_RALINK) += ralink/
114 obj-$(CONFIG_NET_VENDOR_REALTEK) += realtek/
115 obj-$(CONFIG_SH_ETH) += renesas/
116 obj-$(CONFIG_NET_VENDOR_RDC) += rdc/
117 Index: linux-3.10.21/drivers/net/ethernet/ralink/Kconfig
118 ===================================================================
119 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
120 +++ linux-3.10.21/drivers/net/ethernet/ralink/Kconfig 2013-12-09 13:26:42.324125203 +0100
123 + tristate "Ralink RT288X/RT3X5X/RT3662/RT3883/MT7620 ethernet driver"
126 + This driver supports the ethernet mac inside the ralink wisocs
130 +config NET_RALINK_MDIO
131 + def_bool NET_RALINK
132 + depends on (SOC_RT288X || SOC_RT3883 || SOC_MT7620)
135 +config NET_RALINK_MDIO_RT2880
136 + def_bool NET_RALINK
137 + depends on (SOC_RT288X || SOC_RT3883)
138 + select NET_RALINK_MDIO
140 +config NET_RALINK_ESW_RT3052
141 + def_bool NET_RALINK
142 + depends on SOC_RT305X
146 +config NET_RALINK_GSW_MT7620
147 + def_bool NET_RALINK
148 + depends on SOC_MT7620
150 + select NET_RALINK_MDIO
154 Index: linux-3.10.21/drivers/net/ethernet/ralink/Makefile
155 ===================================================================
156 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
157 +++ linux-3.10.21/drivers/net/ethernet/ralink/Makefile 2013-12-09 13:26:42.324125203 +0100
160 +# Makefile for the Ralink SoCs built-in ethernet macs
163 +ralink-eth-y += ralink_soc_eth.o
165 +ralink-eth-$(CONFIG_NET_RALINK_MDIO) += mdio.o
166 +ralink-eth-$(CONFIG_NET_RALINK_MDIO_RT2880) += mdio_rt2880.o
168 +ralink-eth-$(CONFIG_NET_RALINK_ESW_RT3052) += esw_rt3052.o
169 +ralink-eth-$(CONFIG_NET_RALINK_GSW_MT7620) += gsw_mt7620a.o mt7530.o
171 +ralink-eth-$(CONFIG_SOC_RT288X) += soc_rt2880.o
172 +ralink-eth-$(CONFIG_SOC_RT305X) += soc_rt305x.o
173 +ralink-eth-$(CONFIG_SOC_RT3883) += soc_rt3883.o
174 +ralink-eth-$(CONFIG_SOC_MT7620) += soc_mt7620.o
176 +obj-$(CONFIG_NET_RALINK) += ralink-eth.o
177 Index: linux-3.10.21/drivers/net/ethernet/ralink/esw_rt3052.c
178 ===================================================================
179 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
180 +++ linux-3.10.21/drivers/net/ethernet/ralink/esw_rt3052.c 2013-12-09 13:26:42.328125203 +0100
183 + * This program is free software; you can redistribute it and/or modify
184 + * it under the terms of the GNU General Public License as published by
185 + * the Free Software Foundation; version 2 of the License
187 + * This program is distributed in the hope that it will be useful,
188 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
189 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
190 + * GNU General Public License for more details.
192 + * You should have received a copy of the GNU General Public License
193 + * along with this program; if not, write to the Free Software
194 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
196 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
199 +#include <linux/module.h>
200 +#include <linux/kernel.h>
201 +#include <linux/types.h>
202 +#include <linux/dma-mapping.h>
203 +#include <linux/init.h>
204 +#include <linux/skbuff.h>
205 +#include <linux/etherdevice.h>
206 +#include <linux/ethtool.h>
207 +#include <linux/platform_device.h>
208 +#include <linux/of_device.h>
209 +#include <linux/clk.h>
210 +#include <linux/of_net.h>
211 +#include <linux/of_mdio.h>
213 +#include <asm/mach-ralink/ralink_regs.h>
215 +#include "ralink_soc_eth.h"
217 +#include <linux/ioport.h>
218 +#include <linux/switch.h>
219 +#include <linux/mii.h>
221 +#include <ralink_regs.h>
222 +#include <asm/mach-ralink/rt305x.h>
223 +#include <asm/mach-ralink/rt305x_esw_platform.h>
226 + * HW limitations for this switch:
227 + * - No large frame support (PKT_MAX_LEN at most 1536)
228 + * - Can't have untagged vlan and tagged vlan on one port at the same time,
229 + * though this might be possible using the undocumented PPE.
232 +#define RT305X_ESW_REG_ISR 0x00
233 +#define RT305X_ESW_REG_IMR 0x04
234 +#define RT305X_ESW_REG_FCT0 0x08
235 +#define RT305X_ESW_REG_PFC1 0x14
236 +#define RT305X_ESW_REG_ATS 0x24
237 +#define RT305X_ESW_REG_ATS0 0x28
238 +#define RT305X_ESW_REG_ATS1 0x2c
239 +#define RT305X_ESW_REG_ATS2 0x30
240 +#define RT305X_ESW_REG_PVIDC(_n) (0x40 + 4 * (_n))
241 +#define RT305X_ESW_REG_VLANI(_n) (0x50 + 4 * (_n))
242 +#define RT305X_ESW_REG_VMSC(_n) (0x70 + 4 * (_n))
243 +#define RT305X_ESW_REG_POA 0x80
244 +#define RT305X_ESW_REG_FPA 0x84
245 +#define RT305X_ESW_REG_SOCPC 0x8c
246 +#define RT305X_ESW_REG_POC0 0x90
247 +#define RT305X_ESW_REG_POC1 0x94
248 +#define RT305X_ESW_REG_POC2 0x98
249 +#define RT305X_ESW_REG_SGC 0x9c
250 +#define RT305X_ESW_REG_STRT 0xa0
251 +#define RT305X_ESW_REG_PCR0 0xc0
252 +#define RT305X_ESW_REG_PCR1 0xc4
253 +#define RT305X_ESW_REG_FPA2 0xc8
254 +#define RT305X_ESW_REG_FCT2 0xcc
255 +#define RT305X_ESW_REG_SGC2 0xe4
256 +#define RT305X_ESW_REG_P0LED 0xa4
257 +#define RT305X_ESW_REG_P1LED 0xa8
258 +#define RT305X_ESW_REG_P2LED 0xac
259 +#define RT305X_ESW_REG_P3LED 0xb0
260 +#define RT305X_ESW_REG_P4LED 0xb4
261 +#define RT305X_ESW_REG_PXPC(_x) (0xe8 + (4 * _x))
262 +#define RT305X_ESW_REG_P1PC 0xec
263 +#define RT305X_ESW_REG_P2PC 0xf0
264 +#define RT305X_ESW_REG_P3PC 0xf4
265 +#define RT305X_ESW_REG_P4PC 0xf8
266 +#define RT305X_ESW_REG_P5PC 0xfc
268 +#define RT305X_ESW_LED_LINK 0
269 +#define RT305X_ESW_LED_100M 1
270 +#define RT305X_ESW_LED_DUPLEX 2
271 +#define RT305X_ESW_LED_ACTIVITY 3
272 +#define RT305X_ESW_LED_COLLISION 4
273 +#define RT305X_ESW_LED_LINKACT 5
274 +#define RT305X_ESW_LED_DUPLCOLL 6
275 +#define RT305X_ESW_LED_10MACT 7
276 +#define RT305X_ESW_LED_100MACT 8
277 +/* Additional led states not in datasheet: */
278 +#define RT305X_ESW_LED_BLINK 10
279 +#define RT305X_ESW_LED_ON 12
281 +#define RT305X_ESW_LINK_S 25
282 +#define RT305X_ESW_DUPLEX_S 9
283 +#define RT305X_ESW_SPD_S 0
285 +#define RT305X_ESW_PCR0_WT_NWAY_DATA_S 16
286 +#define RT305X_ESW_PCR0_WT_PHY_CMD BIT(13)
287 +#define RT305X_ESW_PCR0_CPU_PHY_REG_S 8
289 +#define RT305X_ESW_PCR1_WT_DONE BIT(0)
291 +#define RT305X_ESW_ATS_TIMEOUT (5 * HZ)
292 +#define RT305X_ESW_PHY_TIMEOUT (5 * HZ)
294 +#define RT305X_ESW_PVIDC_PVID_M 0xfff
295 +#define RT305X_ESW_PVIDC_PVID_S 12
297 +#define RT305X_ESW_VLANI_VID_M 0xfff
298 +#define RT305X_ESW_VLANI_VID_S 12
300 +#define RT305X_ESW_VMSC_MSC_M 0xff
301 +#define RT305X_ESW_VMSC_MSC_S 8
303 +#define RT305X_ESW_SOCPC_DISUN2CPU_S 0
304 +#define RT305X_ESW_SOCPC_DISMC2CPU_S 8
305 +#define RT305X_ESW_SOCPC_DISBC2CPU_S 16
306 +#define RT305X_ESW_SOCPC_CRC_PADDING BIT(25)
308 +#define RT305X_ESW_POC0_EN_BP_S 0
309 +#define RT305X_ESW_POC0_EN_FC_S 8
310 +#define RT305X_ESW_POC0_DIS_RMC2CPU_S 16
311 +#define RT305X_ESW_POC0_DIS_PORT_M 0x7f
312 +#define RT305X_ESW_POC0_DIS_PORT_S 23
314 +#define RT305X_ESW_POC2_UNTAG_EN_M 0xff
315 +#define RT305X_ESW_POC2_UNTAG_EN_S 0
316 +#define RT305X_ESW_POC2_ENAGING_S 8
317 +#define RT305X_ESW_POC2_DIS_UC_PAUSE_S 16
319 +#define RT305X_ESW_SGC2_DOUBLE_TAG_M 0x7f
320 +#define RT305X_ESW_SGC2_DOUBLE_TAG_S 0
321 +#define RT305X_ESW_SGC2_LAN_PMAP_M 0x3f
322 +#define RT305X_ESW_SGC2_LAN_PMAP_S 24
324 +#define RT305X_ESW_PFC1_EN_VLAN_M 0xff
325 +#define RT305X_ESW_PFC1_EN_VLAN_S 16
326 +#define RT305X_ESW_PFC1_EN_TOS_S 24
328 +#define RT305X_ESW_VLAN_NONE 0xfff
330 +#define RT305X_ESW_GSC_BC_STROM_MASK 0x3
331 +#define RT305X_ESW_GSC_BC_STROM_SHIFT 4
333 +#define RT305X_ESW_GSC_LED_FREQ_MASK 0x3
334 +#define RT305X_ESW_GSC_LED_FREQ_SHIFT 23
336 +#define RT305X_ESW_POA_LINK_MASK 0x1f
337 +#define RT305X_ESW_POA_LINK_SHIFT 25
339 +#define RT305X_ESW_PORT_ST_CHG BIT(26)
340 +#define RT305X_ESW_PORT0 0
341 +#define RT305X_ESW_PORT1 1
342 +#define RT305X_ESW_PORT2 2
343 +#define RT305X_ESW_PORT3 3
344 +#define RT305X_ESW_PORT4 4
345 +#define RT305X_ESW_PORT5 5
346 +#define RT305X_ESW_PORT6 6
348 +#define RT305X_ESW_PORTS_NONE 0
350 +#define RT305X_ESW_PMAP_LLLLLL 0x3f
351 +#define RT305X_ESW_PMAP_LLLLWL 0x2f
352 +#define RT305X_ESW_PMAP_WLLLLL 0x3e
354 +#define RT305X_ESW_PORTS_INTERNAL \
355 + (BIT(RT305X_ESW_PORT0) | BIT(RT305X_ESW_PORT1) | \
356 + BIT(RT305X_ESW_PORT2) | BIT(RT305X_ESW_PORT3) | \
357 + BIT(RT305X_ESW_PORT4))
359 +#define RT305X_ESW_PORTS_NOCPU \
360 + (RT305X_ESW_PORTS_INTERNAL | BIT(RT305X_ESW_PORT5))
362 +#define RT305X_ESW_PORTS_CPU BIT(RT305X_ESW_PORT6)
364 +#define RT305X_ESW_PORTS_ALL \
365 + (RT305X_ESW_PORTS_NOCPU | RT305X_ESW_PORTS_CPU)
367 +#define RT305X_ESW_NUM_VLANS 16
368 +#define RT305X_ESW_NUM_VIDS 4096
369 +#define RT305X_ESW_NUM_PORTS 7
370 +#define RT305X_ESW_NUM_LANWAN 6
371 +#define RT305X_ESW_NUM_LEDS 5
373 +#define RT5350_ESW_REG_PXTPC(_x) (0x150 + (4 * _x))
374 +#define RT5350_EWS_REG_LED_POLARITY 0x168
375 +#define RT5350_RESET_EPHY BIT(24)
376 +#define SYSC_REG_RESET_CTRL 0x34
379 + /* Global attributes. */
380 + RT305X_ESW_ATTR_ENABLE_VLAN,
381 + RT305X_ESW_ATTR_ALT_VLAN_DISABLE,
382 + RT305X_ESW_ATTR_BC_STATUS,
383 + RT305X_ESW_ATTR_LED_FREQ,
384 + /* Port attributes. */
385 + RT305X_ESW_ATTR_PORT_DISABLE,
386 + RT305X_ESW_ATTR_PORT_DOUBLETAG,
387 + RT305X_ESW_ATTR_PORT_UNTAG,
388 + RT305X_ESW_ATTR_PORT_LED,
389 + RT305X_ESW_ATTR_PORT_LAN,
390 + RT305X_ESW_ATTR_PORT_RECV_BAD,
391 + RT305X_ESW_ATTR_PORT_RECV_GOOD,
392 + RT5350_ESW_ATTR_PORT_TR_BAD,
393 + RT5350_ESW_ATTR_PORT_TR_GOOD,
410 + struct device *dev;
411 + void __iomem *base;
413 + const struct rt305x_esw_platform_data *pdata;
414 + /* Protects against concurrent register rmw operations. */
415 + spinlock_t reg_rw_lock;
417 + unsigned char port_map;
418 + unsigned int reg_initval_fct2;
419 + unsigned int reg_initval_fpa2;
420 + unsigned int reg_led_polarity;
423 + struct switch_dev swdev;
424 + bool global_vlan_enable;
425 + bool alt_vlan_disable;
426 + int bc_storm_protect;
428 + struct esw_vlan vlans[RT305X_ESW_NUM_VLANS];
429 + struct esw_port ports[RT305X_ESW_NUM_PORTS];
433 +static inline void esw_w32(struct rt305x_esw *esw, u32 val, unsigned reg)
435 + __raw_writel(val, esw->base + reg);
438 +static inline u32 esw_r32(struct rt305x_esw *esw, unsigned reg)
440 + return __raw_readl(esw->base + reg);
443 +static inline void esw_rmw_raw(struct rt305x_esw *esw, unsigned reg, unsigned long mask,
448 + t = __raw_readl(esw->base + reg) & ~mask;
449 + __raw_writel(t | val, esw->base + reg);
452 +static void esw_rmw(struct rt305x_esw *esw, unsigned reg, unsigned long mask,
455 + unsigned long flags;
457 + spin_lock_irqsave(&esw->reg_rw_lock, flags);
458 + esw_rmw_raw(esw, reg, mask, val);
459 + spin_unlock_irqrestore(&esw->reg_rw_lock, flags);
462 +static u32 rt305x_mii_write(struct rt305x_esw *esw, u32 phy_addr, u32 phy_register,
465 + unsigned long t_start = jiffies;
469 + if (!(esw_r32(esw, RT305X_ESW_REG_PCR1) &
470 + RT305X_ESW_PCR1_WT_DONE))
472 + if (time_after(jiffies, t_start + RT305X_ESW_PHY_TIMEOUT)) {
478 + write_data &= 0xffff;
480 + (write_data << RT305X_ESW_PCR0_WT_NWAY_DATA_S) |
481 + (phy_register << RT305X_ESW_PCR0_CPU_PHY_REG_S) |
482 + (phy_addr) | RT305X_ESW_PCR0_WT_PHY_CMD,
483 + RT305X_ESW_REG_PCR0);
487 + if (esw_r32(esw, RT305X_ESW_REG_PCR1) &
488 + RT305X_ESW_PCR1_WT_DONE)
491 + if (time_after(jiffies, t_start + RT305X_ESW_PHY_TIMEOUT)) {
498 + printk(KERN_ERR "ramips_eth: MDIO timeout\n");
502 +static unsigned esw_get_vlan_id(struct rt305x_esw *esw, unsigned vlan)
507 + s = RT305X_ESW_VLANI_VID_S * (vlan % 2);
508 + val = esw_r32(esw, RT305X_ESW_REG_VLANI(vlan / 2));
509 + val = (val >> s) & RT305X_ESW_VLANI_VID_M;
514 +static void esw_set_vlan_id(struct rt305x_esw *esw, unsigned vlan, unsigned vid)
518 + s = RT305X_ESW_VLANI_VID_S * (vlan % 2);
520 + RT305X_ESW_REG_VLANI(vlan / 2),
521 + RT305X_ESW_VLANI_VID_M << s,
522 + (vid & RT305X_ESW_VLANI_VID_M) << s);
525 +static unsigned esw_get_pvid(struct rt305x_esw *esw, unsigned port)
529 + s = RT305X_ESW_PVIDC_PVID_S * (port % 2);
530 + val = esw_r32(esw, RT305X_ESW_REG_PVIDC(port / 2));
531 + return (val >> s) & RT305X_ESW_PVIDC_PVID_M;
534 +static void esw_set_pvid(struct rt305x_esw *esw, unsigned port, unsigned pvid)
538 + s = RT305X_ESW_PVIDC_PVID_S * (port % 2);
540 + RT305X_ESW_REG_PVIDC(port / 2),
541 + RT305X_ESW_PVIDC_PVID_M << s,
542 + (pvid & RT305X_ESW_PVIDC_PVID_M) << s);
545 +static unsigned esw_get_vmsc(struct rt305x_esw *esw, unsigned vlan)
549 + s = RT305X_ESW_VMSC_MSC_S * (vlan % 4);
550 + val = esw_r32(esw, RT305X_ESW_REG_VMSC(vlan / 4));
551 + val = (val >> s) & RT305X_ESW_VMSC_MSC_M;
556 +static void esw_set_vmsc(struct rt305x_esw *esw, unsigned vlan, unsigned msc)
560 + s = RT305X_ESW_VMSC_MSC_S * (vlan % 4);
562 + RT305X_ESW_REG_VMSC(vlan / 4),
563 + RT305X_ESW_VMSC_MSC_M << s,
564 + (msc & RT305X_ESW_VMSC_MSC_M) << s);
567 +static unsigned esw_get_port_disable(struct rt305x_esw *esw)
570 + reg = esw_r32(esw, RT305X_ESW_REG_POC0);
571 + return (reg >> RT305X_ESW_POC0_DIS_PORT_S) &
572 + RT305X_ESW_POC0_DIS_PORT_M;
575 +static void esw_set_port_disable(struct rt305x_esw *esw, unsigned disable_mask)
578 + unsigned enable_mask;
582 + old_mask = esw_get_port_disable(esw);
583 + changed = old_mask ^ disable_mask;
584 + enable_mask = old_mask & disable_mask;
586 + /* enable before writing to MII */
587 + esw_rmw(esw, RT305X_ESW_REG_POC0,
588 + (RT305X_ESW_POC0_DIS_PORT_M <<
589 + RT305X_ESW_POC0_DIS_PORT_S),
590 + enable_mask << RT305X_ESW_POC0_DIS_PORT_S);
592 + for (i = 0; i < RT305X_ESW_NUM_LEDS; i++) {
593 + if (!(changed & (1 << i)))
595 + if (disable_mask & (1 << i)) {
597 + rt305x_mii_write(esw, i, MII_BMCR,
601 + rt305x_mii_write(esw, i, MII_BMCR,
609 + /* disable after writing to MII */
610 + esw_rmw(esw, RT305X_ESW_REG_POC0,
611 + (RT305X_ESW_POC0_DIS_PORT_M <<
612 + RT305X_ESW_POC0_DIS_PORT_S),
613 + disable_mask << RT305X_ESW_POC0_DIS_PORT_S);
616 +static void esw_set_gsc(struct rt305x_esw *esw)
618 + esw_rmw(esw, RT305X_ESW_REG_SGC,
619 + RT305X_ESW_GSC_BC_STROM_MASK << RT305X_ESW_GSC_BC_STROM_SHIFT,
620 + esw->bc_storm_protect << RT305X_ESW_GSC_BC_STROM_SHIFT);
621 + esw_rmw(esw, RT305X_ESW_REG_SGC,
622 + RT305X_ESW_GSC_LED_FREQ_MASK << RT305X_ESW_GSC_LED_FREQ_SHIFT,
623 + esw->led_frequency << RT305X_ESW_GSC_LED_FREQ_SHIFT);
626 +static int esw_apply_config(struct switch_dev *dev);
628 +static void esw_hw_init(struct rt305x_esw *esw)
631 + u8 port_disable = 0;
632 + u8 port_map = RT305X_ESW_PMAP_LLLLLL;
634 + /* vodoo from original driver */
635 + esw_w32(esw, 0xC8A07850, RT305X_ESW_REG_FCT0);
636 + esw_w32(esw, 0x00000000, RT305X_ESW_REG_SGC2);
637 + /* Port priority 1 for all ports, vlan enabled. */
638 + esw_w32(esw, 0x00005555 |
639 + (RT305X_ESW_PORTS_ALL << RT305X_ESW_PFC1_EN_VLAN_S),
640 + RT305X_ESW_REG_PFC1);
642 + /* Enable Back Pressure, and Flow Control */
644 + ((RT305X_ESW_PORTS_ALL << RT305X_ESW_POC0_EN_BP_S) |
645 + (RT305X_ESW_PORTS_ALL << RT305X_ESW_POC0_EN_FC_S)),
646 + RT305X_ESW_REG_POC0);
648 + /* Enable Aging, and VLAN TAG removal */
650 + ((RT305X_ESW_PORTS_ALL << RT305X_ESW_POC2_ENAGING_S) |
651 + (RT305X_ESW_PORTS_NOCPU << RT305X_ESW_POC2_UNTAG_EN_S)),
652 + RT305X_ESW_REG_POC2);
654 + if (esw->reg_initval_fct2)
655 + esw_w32(esw, esw->reg_initval_fct2, RT305X_ESW_REG_FCT2);
657 + esw_w32(esw, esw->pdata->reg_initval_fct2, RT305X_ESW_REG_FCT2);
660 + * 300s aging timer, max packet len 1536, broadcast storm prevention
661 + * disabled, disable collision abort, mac xor48 hash, 10 packet back
662 + * pressure jam, GMII disable was_transmit, back pressure disabled,
663 + * 30ms led flash, unmatched IGMP as broadcast, rmc tb fault to all
666 + esw_w32(esw, 0x0008a301, RT305X_ESW_REG_SGC);
668 + /* Setup SoC Port control register */
670 + (RT305X_ESW_SOCPC_CRC_PADDING |
671 + (RT305X_ESW_PORTS_CPU << RT305X_ESW_SOCPC_DISUN2CPU_S) |
672 + (RT305X_ESW_PORTS_CPU << RT305X_ESW_SOCPC_DISMC2CPU_S) |
673 + (RT305X_ESW_PORTS_CPU << RT305X_ESW_SOCPC_DISBC2CPU_S)),
674 + RT305X_ESW_REG_SOCPC);
676 + if (esw->reg_initval_fpa2)
677 + esw_w32(esw, esw->reg_initval_fpa2, RT305X_ESW_REG_FPA2);
679 + esw_w32(esw, esw->pdata->reg_initval_fpa2, RT305X_ESW_REG_FPA2);
680 + esw_w32(esw, 0x00000000, RT305X_ESW_REG_FPA);
682 + /* Force Link/Activity on ports */
683 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P0LED);
684 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P1LED);
685 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P2LED);
686 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P3LED);
687 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P4LED);
689 + /* Copy disabled port configuration from bootloader setup */
690 + port_disable = esw_get_port_disable(esw);
691 + for (i = 0; i < 6; i++)
692 + esw->ports[i].disable = (port_disable & (1 << i)) != 0;
694 + if (soc_is_rt3352()) {
696 + u32 val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
697 + rt_sysc_w32(val | RT5350_RESET_EPHY, SYSC_REG_RESET_CTRL);
698 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
700 + rt305x_mii_write(esw, 0, 31, 0x8000);
701 + for (i = 0; i < 5; i++) {
702 + if (esw->ports[i].disable) {
703 + rt305x_mii_write(esw, i, MII_BMCR, BMCR_PDOWN);
705 + rt305x_mii_write(esw, i, MII_BMCR,
710 + /* TX10 waveform coefficient LSB=0 disable PHY */
711 + rt305x_mii_write(esw, i, 26, 0x1601);
712 + /* TX100/TX10 AD/DA current bias */
713 + rt305x_mii_write(esw, i, 29, 0x7016);
714 + /* TX100 slew rate control */
715 + rt305x_mii_write(esw, i, 30, 0x0038);
718 + /* select global register */
719 + rt305x_mii_write(esw, 0, 31, 0x0);
720 + /* enlarge agcsel threshold 3 and threshold 2 */
721 + rt305x_mii_write(esw, 0, 1, 0x4a40);
722 + /* enlarge agcsel threshold 5 and threshold 4 */
723 + rt305x_mii_write(esw, 0, 2, 0x6254);
724 + /* enlarge agcsel threshold */
725 + rt305x_mii_write(esw, 0, 3, 0xa17f);
726 + rt305x_mii_write(esw, 0,12, 0x7eaa);
727 + /* longer TP_IDL tail length */
728 + rt305x_mii_write(esw, 0, 14, 0x65);
729 + /* increased squelch pulse count threshold. */
730 + rt305x_mii_write(esw, 0, 16, 0x0684);
731 + /* set TX10 signal amplitude threshold to minimum */
732 + rt305x_mii_write(esw, 0, 17, 0x0fe0);
733 + /* set squelch amplitude to higher threshold */
734 + rt305x_mii_write(esw, 0, 18, 0x40ba);
735 + /* tune TP_IDL tail and head waveform, enable power down slew rate control */
736 + rt305x_mii_write(esw, 0, 22, 0x253f);
737 + /* set PLL/Receive bias current are calibrated */
738 + rt305x_mii_write(esw, 0, 27, 0x2fda);
739 + /* change PLL/Receive bias current to internal(RT3350) */
740 + rt305x_mii_write(esw, 0, 28, 0xc410);
741 + /* change PLL bias current to internal(RT3052_MP3) */
742 + rt305x_mii_write(esw, 0, 29, 0x598b);
743 + /* select local register */
744 + rt305x_mii_write(esw, 0, 31, 0x8000);
745 + } else if (soc_is_rt5350()) {
747 + u32 val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
748 + rt_sysc_w32(val | RT5350_RESET_EPHY, SYSC_REG_RESET_CTRL);
749 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
751 + /* set the led polarity */
752 + esw_w32(esw, esw->reg_led_polarity & 0x1F, RT5350_EWS_REG_LED_POLARITY);
754 + /* local registers */
755 + rt305x_mii_write(esw, 0, 31, 0x8000);
756 + for (i = 0; i < 5; i++) {
757 + if (esw->ports[i].disable) {
758 + rt305x_mii_write(esw, i, MII_BMCR, BMCR_PDOWN);
760 + rt305x_mii_write(esw, i, MII_BMCR,
765 + /* TX10 waveform coefficient LSB=0 disable PHY */
766 + rt305x_mii_write(esw, i, 26, 0x1601);
767 + /* TX100/TX10 AD/DA current bias */
768 + rt305x_mii_write(esw, i, 29, 0x7015);
769 + /* TX100 slew rate control */
770 + rt305x_mii_write(esw, i, 30, 0x0038);
773 + /* global registers */
774 + rt305x_mii_write(esw, 0, 31, 0x0);
775 + /* enlarge agcsel threshold 3 and threshold 2 */
776 + rt305x_mii_write(esw, 0, 1, 0x4a40);
777 + /* enlarge agcsel threshold 5 and threshold 4 */
778 + rt305x_mii_write(esw, 0, 2, 0x6254);
779 + /* enlarge agcsel threshold 6 */
780 + rt305x_mii_write(esw, 0, 3, 0xa17f);
781 + rt305x_mii_write(esw, 0, 12, 0x7eaa);
782 + /* longer TP_IDL tail length */
783 + rt305x_mii_write(esw, 0, 14, 0x65);
784 + /* increased squelch pulse count threshold. */
785 + rt305x_mii_write(esw, 0, 16, 0x0684);
786 + /* set TX10 signal amplitude threshold to minimum */
787 + rt305x_mii_write(esw, 0, 17, 0x0fe0);
788 + /* set squelch amplitude to higher threshold */
789 + rt305x_mii_write(esw, 0, 18, 0x40ba);
790 + /* tune TP_IDL tail and head waveform, enable power down slew rate control */
791 + rt305x_mii_write(esw, 0, 22, 0x253f);
792 + /* set PLL/Receive bias current are calibrated */
793 + rt305x_mii_write(esw, 0, 27, 0x2fda);
794 + /* change PLL/Receive bias current to internal(RT3350) */
795 + rt305x_mii_write(esw, 0, 28, 0xc410);
796 + /* change PLL bias current to internal(RT3052_MP3) */
797 + rt305x_mii_write(esw, 0, 29, 0x598b);
798 + /* select local register */
799 + rt305x_mii_write(esw, 0, 31, 0x8000);
801 + rt305x_mii_write(esw, 0, 31, 0x8000);
802 + for (i = 0; i < 5; i++) {
803 + if (esw->ports[i].disable) {
804 + rt305x_mii_write(esw, i, MII_BMCR, BMCR_PDOWN);
806 + rt305x_mii_write(esw, i, MII_BMCR,
811 + /* TX10 waveform coefficient */
812 + rt305x_mii_write(esw, i, 26, 0x1601);
813 + /* TX100/TX10 AD/DA current bias */
814 + rt305x_mii_write(esw, i, 29, 0x7058);
815 + /* TX100 slew rate control */
816 + rt305x_mii_write(esw, i, 30, 0x0018);
820 + /* select global register */
821 + rt305x_mii_write(esw, 0, 31, 0x0);
822 + /* tune TP_IDL tail and head waveform */
823 + rt305x_mii_write(esw, 0, 22, 0x052f);
824 + /* set TX10 signal amplitude threshold to minimum */
825 + rt305x_mii_write(esw, 0, 17, 0x0fe0);
826 + /* set squelch amplitude to higher threshold */
827 + rt305x_mii_write(esw, 0, 18, 0x40ba);
828 + /* longer TP_IDL tail length */
829 + rt305x_mii_write(esw, 0, 14, 0x65);
830 + /* select local register */
831 + rt305x_mii_write(esw, 0, 31, 0x8000);
835 + port_map = esw->port_map;
837 + port_map = RT305X_ESW_PMAP_LLLLLL;
840 + * Unused HW feature, but still nice to be consistent here...
841 + * This is also exported to userspace ('lan' attribute) so it's
842 + * conveniently usable to decide which ports go into the wan vlan by
845 + esw_rmw(esw, RT305X_ESW_REG_SGC2,
846 + RT305X_ESW_SGC2_LAN_PMAP_M << RT305X_ESW_SGC2_LAN_PMAP_S,
847 + port_map << RT305X_ESW_SGC2_LAN_PMAP_S);
849 + /* make the switch leds blink */
850 + for (i = 0; i < RT305X_ESW_NUM_LEDS; i++)
851 + esw->ports[i].led = 0x05;
853 + /* Apply the empty config. */
854 + esw_apply_config(&esw->swdev);
856 + /* Only unmask the port change interrupt */
857 + esw_w32(esw, ~RT305X_ESW_PORT_ST_CHG, RT305X_ESW_REG_IMR);
860 +static irqreturn_t esw_interrupt(int irq, void *_esw)
862 + struct rt305x_esw *esw = (struct rt305x_esw *) _esw;
865 + status = esw_r32(esw, RT305X_ESW_REG_ISR);
866 + if (status & RT305X_ESW_PORT_ST_CHG) {
867 + u32 link = esw_r32(esw, RT305X_ESW_REG_POA);
868 + link >>= RT305X_ESW_POA_LINK_SHIFT;
869 + link &= RT305X_ESW_POA_LINK_MASK;
870 + dev_info(esw->dev, "link changed 0x%02X\n", link);
872 + esw_w32(esw, status, RT305X_ESW_REG_ISR);
874 + return IRQ_HANDLED;
877 +static int esw_apply_config(struct switch_dev *dev)
879 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
886 + for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
888 + if (esw->global_vlan_enable) {
889 + vid = esw->vlans[i].vid;
890 + vmsc = esw->vlans[i].ports;
892 + vid = RT305X_ESW_VLAN_NONE;
893 + vmsc = RT305X_ESW_PORTS_NONE;
895 + esw_set_vlan_id(esw, i, vid);
896 + esw_set_vmsc(esw, i, vmsc);
899 + for (i = 0; i < RT305X_ESW_NUM_PORTS; i++) {
901 + disable |= esw->ports[i].disable << i;
902 + if (esw->global_vlan_enable) {
903 + doubletag |= esw->ports[i].doubletag << i;
905 + untag |= esw->ports[i].untag << i;
906 + pvid = esw->ports[i].pvid;
908 + int x = esw->alt_vlan_disable ? 0 : 1;
909 + doubletag |= x << i;
914 + esw_set_pvid(esw, i, pvid);
915 + if (i < RT305X_ESW_NUM_LEDS)
916 + esw_w32(esw, esw->ports[i].led,
917 + RT305X_ESW_REG_P0LED + 4*i);
921 + esw_set_port_disable(esw, disable);
922 + esw_rmw(esw, RT305X_ESW_REG_SGC2,
923 + (RT305X_ESW_SGC2_DOUBLE_TAG_M <<
924 + RT305X_ESW_SGC2_DOUBLE_TAG_S),
925 + doubletag << RT305X_ESW_SGC2_DOUBLE_TAG_S);
926 + esw_rmw(esw, RT305X_ESW_REG_PFC1,
927 + RT305X_ESW_PFC1_EN_VLAN_M << RT305X_ESW_PFC1_EN_VLAN_S,
928 + en_vlan << RT305X_ESW_PFC1_EN_VLAN_S);
929 + esw_rmw(esw, RT305X_ESW_REG_POC2,
930 + RT305X_ESW_POC2_UNTAG_EN_M << RT305X_ESW_POC2_UNTAG_EN_S,
931 + untag << RT305X_ESW_POC2_UNTAG_EN_S);
933 + if (!esw->global_vlan_enable) {
935 + * Still need to put all ports into vlan 0 or they'll be
937 + * NOTE: vlan 0 is special, no vlan tag is prepended
939 + esw_set_vlan_id(esw, 0, 0);
940 + esw_set_vmsc(esw, 0, RT305X_ESW_PORTS_ALL);
946 +static int esw_reset_switch(struct switch_dev *dev)
948 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
950 + esw->global_vlan_enable = 0;
951 + memset(esw->ports, 0, sizeof(esw->ports));
952 + memset(esw->vlans, 0, sizeof(esw->vlans));
958 +static int esw_get_vlan_enable(struct switch_dev *dev,
959 + const struct switch_attr *attr,
960 + struct switch_val *val)
962 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
964 + val->value.i = esw->global_vlan_enable;
969 +static int esw_set_vlan_enable(struct switch_dev *dev,
970 + const struct switch_attr *attr,
971 + struct switch_val *val)
973 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
975 + esw->global_vlan_enable = val->value.i != 0;
980 +static int esw_get_alt_vlan_disable(struct switch_dev *dev,
981 + const struct switch_attr *attr,
982 + struct switch_val *val)
984 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
986 + val->value.i = esw->alt_vlan_disable;
991 +static int esw_set_alt_vlan_disable(struct switch_dev *dev,
992 + const struct switch_attr *attr,
993 + struct switch_val *val)
995 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
997 + esw->alt_vlan_disable = val->value.i != 0;
1003 +rt305x_esw_set_bc_status(struct switch_dev *dev,
1004 + const struct switch_attr *attr,
1005 + struct switch_val *val)
1007 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1009 + esw->bc_storm_protect = val->value.i & RT305X_ESW_GSC_BC_STROM_MASK;
1015 +rt305x_esw_get_bc_status(struct switch_dev *dev,
1016 + const struct switch_attr *attr,
1017 + struct switch_val *val)
1019 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1021 + val->value.i = esw->bc_storm_protect;
1027 +rt305x_esw_set_led_freq(struct switch_dev *dev,
1028 + const struct switch_attr *attr,
1029 + struct switch_val *val)
1031 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1033 + esw->led_frequency = val->value.i & RT305X_ESW_GSC_LED_FREQ_MASK;
1039 +rt305x_esw_get_led_freq(struct switch_dev *dev,
1040 + const struct switch_attr *attr,
1041 + struct switch_val *val)
1043 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1045 + val->value.i = esw->led_frequency;
1050 +static int esw_get_port_link(struct switch_dev *dev,
1052 + struct switch_port_link *link)
1054 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1057 + if (port < 0 || port >= RT305X_ESW_NUM_PORTS)
1060 + poa = esw_r32(esw, RT305X_ESW_REG_POA) >> port;
1062 + link->link = (poa >> RT305X_ESW_LINK_S) & 1;
1063 + link->duplex = (poa >> RT305X_ESW_DUPLEX_S) & 1;
1064 + if (port < RT305X_ESW_NUM_LEDS) {
1065 + speed = (poa >> RT305X_ESW_SPD_S) & 1;
1067 + if (port == RT305X_ESW_NUM_PORTS - 1)
1069 + speed = (poa >> RT305X_ESW_SPD_S) & 3;
1073 + link->speed = SWITCH_PORT_SPEED_10;
1076 + link->speed = SWITCH_PORT_SPEED_100;
1079 + case 3: /* forced gige speed can be 2 or 3 */
1080 + link->speed = SWITCH_PORT_SPEED_1000;
1083 + link->speed = SWITCH_PORT_SPEED_UNKNOWN;
1090 +static int esw_get_port_bool(struct switch_dev *dev,
1091 + const struct switch_attr *attr,
1092 + struct switch_val *val)
1094 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1095 + int idx = val->port_vlan;
1096 + u32 x, reg, shift;
1098 + if (idx < 0 || idx >= RT305X_ESW_NUM_PORTS)
1101 + switch (attr->id) {
1102 + case RT305X_ESW_ATTR_PORT_DISABLE:
1103 + reg = RT305X_ESW_REG_POC0;
1104 + shift = RT305X_ESW_POC0_DIS_PORT_S;
1106 + case RT305X_ESW_ATTR_PORT_DOUBLETAG:
1107 + reg = RT305X_ESW_REG_SGC2;
1108 + shift = RT305X_ESW_SGC2_DOUBLE_TAG_S;
1110 + case RT305X_ESW_ATTR_PORT_UNTAG:
1111 + reg = RT305X_ESW_REG_POC2;
1112 + shift = RT305X_ESW_POC2_UNTAG_EN_S;
1114 + case RT305X_ESW_ATTR_PORT_LAN:
1115 + reg = RT305X_ESW_REG_SGC2;
1116 + shift = RT305X_ESW_SGC2_LAN_PMAP_S;
1117 + if (idx >= RT305X_ESW_NUM_LANWAN)
1124 + x = esw_r32(esw, reg);
1125 + val->value.i = (x >> (idx + shift)) & 1;
1130 +static int esw_set_port_bool(struct switch_dev *dev,
1131 + const struct switch_attr *attr,
1132 + struct switch_val *val)
1134 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1135 + int idx = val->port_vlan;
1137 + if (idx < 0 || idx >= RT305X_ESW_NUM_PORTS ||
1138 + val->value.i < 0 || val->value.i > 1)
1141 + switch (attr->id) {
1142 + case RT305X_ESW_ATTR_PORT_DISABLE:
1143 + esw->ports[idx].disable = val->value.i;
1145 + case RT305X_ESW_ATTR_PORT_DOUBLETAG:
1146 + esw->ports[idx].doubletag = val->value.i;
1148 + case RT305X_ESW_ATTR_PORT_UNTAG:
1149 + esw->ports[idx].untag = val->value.i;
1158 +static int esw_get_port_recv_badgood(struct switch_dev *dev,
1159 + const struct switch_attr *attr,
1160 + struct switch_val *val)
1162 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1163 + int idx = val->port_vlan;
1164 + int shift = attr->id == RT305X_ESW_ATTR_PORT_RECV_GOOD ? 0 : 16;
1167 + if (idx < 0 || idx >= RT305X_ESW_NUM_LANWAN)
1169 + reg = esw_r32(esw, RT305X_ESW_REG_PXPC(idx));
1170 + val->value.i = (reg >> shift) & 0xffff;
1176 +esw_get_port_tr_badgood(struct switch_dev *dev,
1177 + const struct switch_attr *attr,
1178 + struct switch_val *val)
1180 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1182 + int idx = val->port_vlan;
1183 + int shift = attr->id == RT5350_ESW_ATTR_PORT_TR_GOOD ? 0 : 16;
1186 + if (!soc_is_rt5350())
1189 + if (idx < 0 || idx >= RT305X_ESW_NUM_LANWAN)
1192 + reg = esw_r32(esw, RT5350_ESW_REG_PXTPC(idx));
1193 + val->value.i = (reg >> shift) & 0xffff;
1198 +static int esw_get_port_led(struct switch_dev *dev,
1199 + const struct switch_attr *attr,
1200 + struct switch_val *val)
1202 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1203 + int idx = val->port_vlan;
1205 + if (idx < 0 || idx >= RT305X_ESW_NUM_PORTS ||
1206 + idx >= RT305X_ESW_NUM_LEDS)
1209 + val->value.i = esw_r32(esw, RT305X_ESW_REG_P0LED + 4*idx);
1214 +static int esw_set_port_led(struct switch_dev *dev,
1215 + const struct switch_attr *attr,
1216 + struct switch_val *val)
1218 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1219 + int idx = val->port_vlan;
1221 + if (idx < 0 || idx >= RT305X_ESW_NUM_LEDS)
1224 + esw->ports[idx].led = val->value.i;
1229 +static int esw_get_port_pvid(struct switch_dev *dev, int port, int *val)
1231 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1233 + if (port >= RT305X_ESW_NUM_PORTS)
1236 + *val = esw_get_pvid(esw, port);
1241 +static int esw_set_port_pvid(struct switch_dev *dev, int port, int val)
1243 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1245 + if (port >= RT305X_ESW_NUM_PORTS)
1248 + esw->ports[port].pvid = val;
1253 +static int esw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val)
1255 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1257 + int vlan_idx = -1;
1262 + if (val->port_vlan < 0 || val->port_vlan >= RT305X_ESW_NUM_VIDS)
1266 + for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
1267 + if (esw_get_vlan_id(esw, i) == val->port_vlan &&
1268 + esw_get_vmsc(esw, i) != RT305X_ESW_PORTS_NONE) {
1274 + if (vlan_idx == -1)
1277 + vmsc = esw_get_vmsc(esw, vlan_idx);
1278 + poc2 = esw_r32(esw, RT305X_ESW_REG_POC2);
1280 + for (i = 0; i < RT305X_ESW_NUM_PORTS; i++) {
1281 + struct switch_port *p;
1282 + int port_mask = 1 << i;
1284 + if (!(vmsc & port_mask))
1287 + p = &val->value.ports[val->len++];
1289 + if (poc2 & (port_mask << RT305X_ESW_POC2_UNTAG_EN_S))
1292 + p->flags = 1 << SWITCH_PORT_FLAG_TAGGED;
1298 +static int esw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val)
1300 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1302 + int vlan_idx = -1;
1305 + if (val->port_vlan < 0 || val->port_vlan >= RT305X_ESW_NUM_VIDS ||
1306 + val->len > RT305X_ESW_NUM_PORTS)
1309 + /* one of the already defined vlans? */
1310 + for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
1311 + if (esw->vlans[i].vid == val->port_vlan &&
1312 + esw->vlans[i].ports != RT305X_ESW_PORTS_NONE) {
1318 + /* select a free slot */
1319 + for (i = 0; vlan_idx == -1 && i < RT305X_ESW_NUM_VLANS; i++) {
1320 + if (esw->vlans[i].ports == RT305X_ESW_PORTS_NONE)
1324 + /* bail if all slots are in use */
1325 + if (vlan_idx == -1)
1328 + ports = RT305X_ESW_PORTS_NONE;
1329 + for (i = 0; i < val->len; i++) {
1330 + struct switch_port *p = &val->value.ports[i];
1331 + int port_mask = 1 << p->id;
1332 + bool untagged = !(p->flags & (1 << SWITCH_PORT_FLAG_TAGGED));
1334 + if (p->id >= RT305X_ESW_NUM_PORTS)
1337 + ports |= port_mask;
1338 + esw->ports[p->id].untag = untagged;
1340 + esw->vlans[vlan_idx].ports = ports;
1341 + if (ports == RT305X_ESW_PORTS_NONE)
1342 + esw->vlans[vlan_idx].vid = RT305X_ESW_VLAN_NONE;
1344 + esw->vlans[vlan_idx].vid = val->port_vlan;
1349 +static const struct switch_attr esw_global[] = {
1351 + .type = SWITCH_TYPE_INT,
1352 + .name = "enable_vlan",
1353 + .description = "VLAN mode (1:enabled)",
1355 + .id = RT305X_ESW_ATTR_ENABLE_VLAN,
1356 + .get = esw_get_vlan_enable,
1357 + .set = esw_set_vlan_enable,
1360 + .type = SWITCH_TYPE_INT,
1361 + .name = "alternate_vlan_disable",
1362 + .description = "Use en_vlan instead of doubletag to disable"
1365 + .id = RT305X_ESW_ATTR_ALT_VLAN_DISABLE,
1366 + .get = esw_get_alt_vlan_disable,
1367 + .set = esw_set_alt_vlan_disable,
1370 + .type = SWITCH_TYPE_INT,
1371 + .name = "bc_storm_protect",
1372 + .description = "Global broadcast storm protection (0:Disable, 1:64 blocks, 2:96 blocks, 3:128 blocks)",
1374 + .id = RT305X_ESW_ATTR_BC_STATUS,
1375 + .get = rt305x_esw_get_bc_status,
1376 + .set = rt305x_esw_set_bc_status,
1379 + .type = SWITCH_TYPE_INT,
1380 + .name = "led_frequency",
1381 + .description = "LED Flash frequency (0:30mS, 1:60mS, 2:240mS, 3:480mS)",
1383 + .id = RT305X_ESW_ATTR_LED_FREQ,
1384 + .get = rt305x_esw_get_led_freq,
1385 + .set = rt305x_esw_set_led_freq,
1389 +static const struct switch_attr esw_port[] = {
1391 + .type = SWITCH_TYPE_INT,
1392 + .name = "disable",
1393 + .description = "Port state (1:disabled)",
1395 + .id = RT305X_ESW_ATTR_PORT_DISABLE,
1396 + .get = esw_get_port_bool,
1397 + .set = esw_set_port_bool,
1400 + .type = SWITCH_TYPE_INT,
1401 + .name = "doubletag",
1402 + .description = "Double tagging for incoming vlan packets "
1405 + .id = RT305X_ESW_ATTR_PORT_DOUBLETAG,
1406 + .get = esw_get_port_bool,
1407 + .set = esw_set_port_bool,
1410 + .type = SWITCH_TYPE_INT,
1412 + .description = "Untag (1:strip outgoing vlan tag)",
1414 + .id = RT305X_ESW_ATTR_PORT_UNTAG,
1415 + .get = esw_get_port_bool,
1416 + .set = esw_set_port_bool,
1419 + .type = SWITCH_TYPE_INT,
1421 + .description = "LED mode (0:link, 1:100m, 2:duplex, 3:activity,"
1422 + " 4:collision, 5:linkact, 6:duplcoll, 7:10mact,"
1423 + " 8:100mact, 10:blink, 11:off, 12:on)",
1425 + .id = RT305X_ESW_ATTR_PORT_LED,
1426 + .get = esw_get_port_led,
1427 + .set = esw_set_port_led,
1430 + .type = SWITCH_TYPE_INT,
1432 + .description = "HW port group (0:wan, 1:lan)",
1434 + .id = RT305X_ESW_ATTR_PORT_LAN,
1435 + .get = esw_get_port_bool,
1438 + .type = SWITCH_TYPE_INT,
1439 + .name = "recv_bad",
1440 + .description = "Receive bad packet counter",
1441 + .id = RT305X_ESW_ATTR_PORT_RECV_BAD,
1442 + .get = esw_get_port_recv_badgood,
1445 + .type = SWITCH_TYPE_INT,
1446 + .name = "recv_good",
1447 + .description = "Receive good packet counter",
1448 + .id = RT305X_ESW_ATTR_PORT_RECV_GOOD,
1449 + .get = esw_get_port_recv_badgood,
1452 + .type = SWITCH_TYPE_INT,
1455 + .description = "Transmit bad packet counter. rt5350 only",
1456 + .id = RT5350_ESW_ATTR_PORT_TR_BAD,
1457 + .get = esw_get_port_tr_badgood,
1460 + .type = SWITCH_TYPE_INT,
1461 + .name = "tr_good",
1463 + .description = "Transmit good packet counter. rt5350 only",
1464 + .id = RT5350_ESW_ATTR_PORT_TR_GOOD,
1465 + .get = esw_get_port_tr_badgood,
1469 +static const struct switch_attr esw_vlan[] = {
1472 +static const struct switch_dev_ops esw_ops = {
1474 + .attr = esw_global,
1475 + .n_attr = ARRAY_SIZE(esw_global),
1479 + .n_attr = ARRAY_SIZE(esw_port),
1483 + .n_attr = ARRAY_SIZE(esw_vlan),
1485 + .get_vlan_ports = esw_get_vlan_ports,
1486 + .set_vlan_ports = esw_set_vlan_ports,
1487 + .get_port_pvid = esw_get_port_pvid,
1488 + .set_port_pvid = esw_set_port_pvid,
1489 + .get_port_link = esw_get_port_link,
1490 + .apply_config = esw_apply_config,
1491 + .reset_switch = esw_reset_switch,
1494 +static struct rt305x_esw_platform_data rt3050_esw_data = {
1495 + /* All ports are LAN ports. */
1496 + .vlan_config = RT305X_ESW_VLAN_CONFIG_NONE,
1497 + .reg_initval_fct2 = 0x00d6500c,
1499 + * ext phy base addr 31, enable port 5 polling, rx/tx clock skew 1,
1500 + * turbo mii off, rgmi 3.3v off
1502 + * port6: enabled, gige, full-duplex, rx/tx-flow-control
1504 + .reg_initval_fpa2 = 0x3f502b28,
1507 +static const struct of_device_id ralink_esw_match[] = {
1508 + { .compatible = "ralink,rt3050-esw", .data = &rt3050_esw_data },
1511 +MODULE_DEVICE_TABLE(of, ralink_esw_match);
1513 +static int esw_probe(struct platform_device *pdev)
1515 + struct device_node *np = pdev->dev.of_node;
1516 + const struct rt305x_esw_platform_data *pdata;
1517 + const __be32 *port_map, *reg_init;
1518 + struct rt305x_esw *esw;
1519 + struct switch_dev *swdev;
1520 + struct resource *res, *irq;
1523 + pdata = pdev->dev.platform_data;
1525 + const struct of_device_id *match;
1526 + match = of_match_device(ralink_esw_match, &pdev->dev);
1528 + pdata = (struct rt305x_esw_platform_data *) match->data;
1533 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1535 + dev_err(&pdev->dev, "no memory resource found\n");
1539 + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1541 + dev_err(&pdev->dev, "no irq resource found\n");
1545 + esw = kzalloc(sizeof(struct rt305x_esw), GFP_KERNEL);
1547 + dev_err(&pdev->dev, "no memory for private data\n");
1551 + esw->dev = &pdev->dev;
1552 + esw->irq = irq->start;
1553 + esw->base = ioremap(res->start, resource_size(res));
1555 + dev_err(&pdev->dev, "ioremap failed\n");
1560 + port_map = of_get_property(np, "ralink,portmap", NULL);
1562 + esw->port_map = be32_to_cpu(*port_map);
1564 + reg_init = of_get_property(np, "ralink,fct2", NULL);
1566 + esw->reg_initval_fct2 = be32_to_cpu(*reg_init);
1568 + reg_init = of_get_property(np, "ralink,fpa2", NULL);
1570 + esw->reg_initval_fpa2 = be32_to_cpu(*reg_init);
1572 + reg_init = of_get_property(np, "ralink,led_polarity", NULL);
1574 + esw->reg_led_polarity = be32_to_cpu(*reg_init);
1576 + swdev = &esw->swdev;
1577 + swdev->of_node = pdev->dev.of_node;
1578 + swdev->name = "rt305x-esw";
1579 + swdev->alias = "rt305x";
1580 + swdev->cpu_port = RT305X_ESW_PORT6;
1581 + swdev->ports = RT305X_ESW_NUM_PORTS;
1582 + swdev->vlans = RT305X_ESW_NUM_VIDS;
1583 + swdev->ops = &esw_ops;
1585 + err = register_switch(swdev, NULL);
1587 + dev_err(&pdev->dev, "register_switch failed\n");
1591 + platform_set_drvdata(pdev, esw);
1593 + esw->pdata = pdata;
1594 + spin_lock_init(&esw->reg_rw_lock);
1598 + esw_w32(esw, RT305X_ESW_PORT_ST_CHG, RT305X_ESW_REG_ISR);
1599 + esw_w32(esw, ~RT305X_ESW_PORT_ST_CHG, RT305X_ESW_REG_IMR);
1600 + request_irq(esw->irq, esw_interrupt, 0, "esw", esw);
1605 + iounmap(esw->base);
1611 +static int esw_remove(struct platform_device *pdev)
1613 + struct rt305x_esw *esw;
1615 + esw = platform_get_drvdata(pdev);
1617 + unregister_switch(&esw->swdev);
1618 + platform_set_drvdata(pdev, NULL);
1619 + iounmap(esw->base);
1626 +static struct platform_driver esw_driver = {
1627 + .probe = esw_probe,
1628 + .remove = esw_remove,
1630 + .name = "rt305x-esw",
1631 + .owner = THIS_MODULE,
1632 + .of_match_table = ralink_esw_match,
1636 +int __init rtesw_init(void)
1638 + return platform_driver_register(&esw_driver);
1641 +void rtesw_exit(void)
1643 + platform_driver_unregister(&esw_driver);
1645 Index: linux-3.10.21/drivers/net/ethernet/ralink/esw_rt3052.h
1646 ===================================================================
1647 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1648 +++ linux-3.10.21/drivers/net/ethernet/ralink/esw_rt3052.h 2013-12-09 13:26:42.328125203 +0100
1651 + * This program is free software; you can redistribute it and/or modify
1652 + * it under the terms of the GNU General Public License as published by
1653 + * the Free Software Foundation; version 2 of the License
1655 + * This program is distributed in the hope that it will be useful,
1656 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1657 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1658 + * GNU General Public License for more details.
1660 + * You should have received a copy of the GNU General Public License
1661 + * along with this program; if not, write to the Free Software
1662 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
1664 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
1667 +#ifndef _RALINK_ESW_RT3052_H__
1668 +#define _RALINK_ESW_RT3052_H__
1670 +#ifdef CONFIG_NET_RALINK_ESW_RT3052
1672 +int __init rtesw_init(void);
1673 +void rtesw_exit(void);
1677 +static inline int __init rtesw_init(void) { return 0; }
1678 +static inline void rtesw_exit(void) { }
1682 Index: linux-3.10.21/drivers/net/ethernet/ralink/gsw_mt7620a.c
1683 ===================================================================
1684 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1685 +++ linux-3.10.21/drivers/net/ethernet/ralink/gsw_mt7620a.c 2013-12-09 13:26:42.328125203 +0100
1688 + * This program is free software; you can redistribute it and/or modify
1689 + * it under the terms of the GNU General Public License as published by
1690 + * the Free Software Foundation; version 2 of the License
1692 + * This program is distributed in the hope that it will be useful,
1693 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1694 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1695 + * GNU General Public License for more details.
1697 + * You should have received a copy of the GNU General Public License
1698 + * along with this program; if not, write to the Free Software
1699 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
1701 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
1704 +#include <linux/module.h>
1705 +#include <linux/kernel.h>
1706 +#include <linux/types.h>
1707 +#include <linux/dma-mapping.h>
1708 +#include <linux/init.h>
1709 +#include <linux/skbuff.h>
1710 +#include <linux/etherdevice.h>
1711 +#include <linux/ethtool.h>
1712 +#include <linux/platform_device.h>
1713 +#include <linux/of_device.h>
1714 +#include <linux/clk.h>
1715 +#include <linux/of_net.h>
1716 +#include <linux/of_mdio.h>
1717 +#include <linux/of_irq.h>
1718 +#include <linux/of_address.h>
1719 +#include <linux/switch.h>
1721 +#include <asm/mach-ralink/ralink_regs.h>
1723 +#include "ralink_soc_eth.h"
1725 +#include <linux/ioport.h>
1726 +#include <linux/switch.h>
1727 +#include <linux/mii.h>
1729 +#include <ralink_regs.h>
1730 +#include <asm/mach-ralink/mt7620.h>
1732 +#include "ralink_soc_eth.h"
1733 +#include "gsw_mt7620a.h"
1734 +#include "mt7530.h"
1737 +#define GSW_REG_PHY_TIMEOUT (5 * HZ)
1739 +#define MT7620A_GSW_REG_PIAC 0x7004
1741 +#define GSW_NUM_VLANS 16
1742 +#define GSW_NUM_VIDS 4096
1743 +#define GSW_NUM_PORTS 7
1744 +#define GSW_PORT6 6
1746 +#define GSW_MDIO_ACCESS BIT(31)
1747 +#define GSW_MDIO_READ BIT(19)
1748 +#define GSW_MDIO_WRITE BIT(18)
1749 +#define GSW_MDIO_START BIT(16)
1750 +#define GSW_MDIO_ADDR_SHIFT 20
1751 +#define GSW_MDIO_REG_SHIFT 25
1753 +#define GSW_REG_PORT_PMCR(x) (0x3000 + (x * 0x100))
1754 +#define GSW_REG_PORT_STATUS(x) (0x3008 + (x * 0x100))
1755 +#define GSW_REG_SMACCR0 0x3fE4
1756 +#define GSW_REG_SMACCR1 0x3fE8
1757 +#define GSW_REG_CKGCR 0x3ff0
1759 +#define GSW_REG_IMR 0x7008
1760 +#define GSW_REG_ISR 0x700c
1762 +#define SYSC_REG_CFG1 0x14
1764 +#define PORT_IRQ_ST_CHG 0x7f
1766 +#define SYSCFG1 0x14
1768 +#define ESW_PHY_POLLING 0x7000
1770 +#define PMCR_IPG BIT(18)
1771 +#define PMCR_MAC_MODE BIT(16)
1772 +#define PMCR_FORCE BIT(15)
1773 +#define PMCR_TX_EN BIT(14)
1774 +#define PMCR_RX_EN BIT(13)
1775 +#define PMCR_BACKOFF BIT(9)
1776 +#define PMCR_BACKPRES BIT(8)
1777 +#define PMCR_RX_FC BIT(5)
1778 +#define PMCR_TX_FC BIT(4)
1779 +#define PMCR_SPEED(_x) (_x << 2)
1780 +#define PMCR_DUPLEX BIT(1)
1781 +#define PMCR_LINK BIT(0)
1783 +#define PHY_AN_EN BIT(31)
1784 +#define PHY_PRE_EN BIT(30)
1785 +#define PMY_MDC_CONF(_x) ((_x & 0x3f) << 24)
1788 + /* Global attributes. */
1789 + GSW_ATTR_ENABLE_VLAN,
1790 + /* Port attributes. */
1791 + GSW_ATTR_PORT_UNTAG,
1799 +struct mt7620_gsw {
1800 + struct device *dev;
1801 + void __iomem *base;
1804 + long unsigned int autopoll;
1807 +static inline void gsw_w32(struct mt7620_gsw *gsw, u32 val, unsigned reg)
1809 + iowrite32(val, gsw->base + reg);
1812 +static inline u32 gsw_r32(struct mt7620_gsw *gsw, unsigned reg)
1814 + return ioread32(gsw->base + reg);
1817 +static int mt7620_mii_busy_wait(struct mt7620_gsw *gsw)
1819 + unsigned long t_start = jiffies;
1822 + if (!(gsw_r32(gsw, MT7620A_GSW_REG_PIAC) & GSW_MDIO_ACCESS))
1824 + if (time_after(jiffies, t_start + GSW_REG_PHY_TIMEOUT)) {
1829 + printk(KERN_ERR "mdio: MDIO timeout\n");
1833 +static u32 _mt7620_mii_write(struct mt7620_gsw *gsw, u32 phy_addr, u32 phy_register,
1836 + if (mt7620_mii_busy_wait(gsw))
1839 + write_data &= 0xffff;
1841 + gsw_w32(gsw, GSW_MDIO_ACCESS | GSW_MDIO_START | GSW_MDIO_WRITE |
1842 + (phy_register << GSW_MDIO_REG_SHIFT) |
1843 + (phy_addr << GSW_MDIO_ADDR_SHIFT) | write_data,
1844 + MT7620A_GSW_REG_PIAC);
1846 + if (mt7620_mii_busy_wait(gsw))
1852 +static u32 _mt7620_mii_read(struct mt7620_gsw *gsw, int phy_addr, int phy_reg)
1856 + if (mt7620_mii_busy_wait(gsw))
1859 + gsw_w32(gsw, GSW_MDIO_ACCESS | GSW_MDIO_START | GSW_MDIO_READ |
1860 + (phy_reg << GSW_MDIO_REG_SHIFT) |
1861 + (phy_addr << GSW_MDIO_ADDR_SHIFT),
1862 + MT7620A_GSW_REG_PIAC);
1864 + if (mt7620_mii_busy_wait(gsw))
1867 + d = gsw_r32(gsw, MT7620A_GSW_REG_PIAC) & 0xffff;
1872 +int mt7620_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val)
1874 + struct fe_priv *priv = bus->priv;
1875 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1877 + return _mt7620_mii_write(gsw, phy_addr, phy_reg, val);
1880 +int mt7620_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg)
1882 + struct fe_priv *priv = bus->priv;
1883 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1885 + return _mt7620_mii_read(gsw, phy_addr, phy_reg);
1888 +static unsigned char *fe_speed_str(int speed)
1905 +int mt7620a_has_carrier(struct fe_priv *priv)
1907 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1910 + for (i = 0; i < GSW_PORT6; i++)
1911 + if (gsw_r32(gsw, GSW_REG_PORT_STATUS(i)) & 0x1)
1916 +static void mt7620a_handle_carrier(struct fe_priv *priv)
1921 + if (mt7620a_has_carrier(priv))
1922 + netif_carrier_on(priv->netdev);
1924 + netif_carrier_off(priv->netdev);
1927 +void mt7620_mdio_link_adjust(struct fe_priv *priv, int port)
1929 + if (priv->link[port])
1930 + netdev_info(priv->netdev, "port %d link up (%sMbps/%s duplex)\n",
1931 + port, fe_speed_str(priv->phy->speed[port]),
1932 + (DUPLEX_FULL == priv->phy->duplex[port]) ? "Full" : "Half");
1934 + netdev_info(priv->netdev, "port %d link down\n", port);
1935 + mt7620a_handle_carrier(priv);
1938 +static irqreturn_t gsw_interrupt(int irq, void *_priv)
1940 + struct fe_priv *priv = (struct fe_priv *) _priv;
1941 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1943 + int i, max = (gsw->port4 == PORT4_EPHY) ? (4) : (3);
1945 + status = gsw_r32(gsw, GSW_REG_ISR);
1946 + if (status & PORT_IRQ_ST_CHG)
1947 + for (i = 0; i <= max; i++) {
1948 + u32 status = gsw_r32(gsw, GSW_REG_PORT_STATUS(i));
1949 + int link = status & 0x1;
1951 + if (link != priv->link[i]) {
1953 + netdev_info(priv->netdev, "port %d link up (%sMbps/%s duplex)\n",
1954 + i, fe_speed_str((status >> 2) & 3),
1955 + (status & 0x2) ? "Full" : "Half");
1957 + netdev_info(priv->netdev, "port %d link down\n", i);
1960 + priv->link[i] = link;
1962 + mt7620a_handle_carrier(priv);
1964 + gsw_w32(gsw, status, GSW_REG_ISR);
1966 + return IRQ_HANDLED;
1969 +static int mt7620_is_bga(void)
1971 + u32 bga = rt_sysc_r32(0x0c);
1973 + return (bga >> 16) & 1;
1976 +static void gsw_auto_poll(struct mt7620_gsw *gsw)
1979 + int lsb = -1, msb = 0;
1981 + for_each_set_bit(phy, &gsw->autopoll, 32) {
1987 + gsw_w32(gsw, PHY_AN_EN | PHY_PRE_EN | PMY_MDC_CONF(5) | (msb << 8) | lsb, ESW_PHY_POLLING);
1990 +void mt7620_port_init(struct fe_priv *priv, struct device_node *np)
1992 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1993 + const __be32 *_id = of_get_property(np, "reg", NULL);
1994 + int phy_mode, size, id;
1996 + u32 val, mask = 0;
1997 + int min = (gsw->port4 == PORT4_EPHY) ? (5) : (4);
1999 + if (!_id || (be32_to_cpu(*_id) < min) || (be32_to_cpu(*_id) > 5)) {
2001 + pr_err("%s: invalid port id %d\n", np->name, be32_to_cpu(*_id));
2003 + pr_err("%s: invalid port id\n", np->name);
2007 + id = be32_to_cpu(*_id);
2012 + priv->phy->phy_fixed[id] = of_get_property(np, "ralink,fixed-link", &size);
2013 + if (priv->phy->phy_fixed[id] && (size != (4 * sizeof(*priv->phy->phy_fixed[id])))) {
2014 + pr_err("%s: invalid fixed link property\n", np->name);
2015 + priv->phy->phy_fixed[id] = NULL;
2019 + phy_mode = of_get_phy_mode(np);
2020 + switch (phy_mode) {
2021 + case PHY_INTERFACE_MODE_RGMII:
2024 + case PHY_INTERFACE_MODE_MII:
2027 + case PHY_INTERFACE_MODE_RMII:
2031 + dev_err(priv->device, "port %d - invalid phy mode\n", id);
2035 + priv->phy->phy_node[id] = of_parse_phandle(np, "phy-handle", 0);
2036 + if (!priv->phy->phy_node[id] && !priv->phy->phy_fixed[id])
2039 + val = rt_sysc_r32(SYSCFG1);
2040 + val &= ~(3 << shift);
2041 + val |= mask << shift;
2042 + rt_sysc_w32(val, SYSCFG1);
2044 + if (priv->phy->phy_fixed[id]) {
2045 + const __be32 *link = priv->phy->phy_fixed[id];
2049 + priv->phy->speed[id] = be32_to_cpup(link++);
2050 + tx_fc = be32_to_cpup(link++);
2051 + rx_fc = be32_to_cpup(link++);
2052 + priv->phy->duplex[id] = be32_to_cpup(link++);
2053 + priv->link[id] = 1;
2055 + switch (priv->phy->speed[id]) {
2066 + dev_err(priv->device, "invalid link speed: %d\n", priv->phy->speed[id]);
2067 + priv->phy->phy_fixed[id] = 0;
2070 + val = PMCR_SPEED(val);
2071 + val |= PMCR_LINK | PMCR_BACKPRES | PMCR_BACKOFF | PMCR_RX_EN |
2072 + PMCR_TX_EN | PMCR_FORCE | PMCR_MAC_MODE | PMCR_IPG;
2074 + val |= PMCR_TX_FC;
2076 + val |= PMCR_RX_FC;
2077 + if (priv->phy->duplex[id])
2078 + val |= PMCR_DUPLEX;
2079 + gsw_w32(gsw, val, GSW_REG_PORT_PMCR(id));
2080 + dev_info(priv->device, "using fixed link parameters\n");
2084 + if (priv->phy->phy_node[id] && priv->mii_bus->phy_map[id]) {
2085 + u32 val = PMCR_BACKPRES | PMCR_BACKOFF | PMCR_RX_EN |
2086 + PMCR_TX_EN | PMCR_MAC_MODE | PMCR_IPG;
2088 + gsw_w32(gsw, val, GSW_REG_PORT_PMCR(id));
2089 + fe_connect_phy_node(priv, priv->phy->phy_node[id]);
2090 + gsw->autopoll |= BIT(id);
2091 + gsw_auto_poll(gsw);
2096 +static void gsw_hw_init(struct mt7620_gsw *gsw)
2098 + u32 is_BGA = mt7620_is_bga();
2100 + rt_sysc_w32(rt_sysc_r32(SYSC_REG_CFG1) | BIT(8), SYSC_REG_CFG1);
2101 + gsw_w32(gsw, gsw_r32(gsw, GSW_REG_CKGCR) & ~(0x3 << 4), GSW_REG_CKGCR);
2103 + /*correct PHY setting L3.0 BGA*/
2104 + _mt7620_mii_write(gsw, 1, 31, 0x4000); //global, page 4
2106 + _mt7620_mii_write(gsw, 1, 17, 0x7444);
2108 + _mt7620_mii_write(gsw, 1, 19, 0x0114);
2110 + _mt7620_mii_write(gsw, 1, 19, 0x0117);
2112 + _mt7620_mii_write(gsw, 1, 22, 0x10cf);
2113 + _mt7620_mii_write(gsw, 1, 25, 0x6212);
2114 + _mt7620_mii_write(gsw, 1, 26, 0x0777);
2115 + _mt7620_mii_write(gsw, 1, 29, 0x4000);
2116 + _mt7620_mii_write(gsw, 1, 28, 0xc077);
2117 + _mt7620_mii_write(gsw, 1, 24, 0x0000);
2119 + _mt7620_mii_write(gsw, 1, 31, 0x3000); //global, page 3
2120 + _mt7620_mii_write(gsw, 1, 17, 0x4838);
2122 + _mt7620_mii_write(gsw, 1, 31, 0x2000); //global, page 2
2124 + _mt7620_mii_write(gsw, 1, 21, 0x0515);
2125 + _mt7620_mii_write(gsw, 1, 22, 0x0053);
2126 + _mt7620_mii_write(gsw, 1, 23, 0x00bf);
2127 + _mt7620_mii_write(gsw, 1, 24, 0x0aaf);
2128 + _mt7620_mii_write(gsw, 1, 25, 0x0fad);
2129 + _mt7620_mii_write(gsw, 1, 26, 0x0fc1);
2131 + _mt7620_mii_write(gsw, 1, 21, 0x0517);
2132 + _mt7620_mii_write(gsw, 1, 22, 0x0fd2);
2133 + _mt7620_mii_write(gsw, 1, 23, 0x00bf);
2134 + _mt7620_mii_write(gsw, 1, 24, 0x0aab);
2135 + _mt7620_mii_write(gsw, 1, 25, 0x00ae);
2136 + _mt7620_mii_write(gsw, 1, 26, 0x0fff);
2138 + _mt7620_mii_write(gsw, 1, 31, 0x1000); //global, page 1
2139 + _mt7620_mii_write(gsw, 1, 17, 0xe7f8);
2141 + _mt7620_mii_write(gsw, 1, 31, 0x8000); //local, page 0
2142 + _mt7620_mii_write(gsw, 0, 30, 0xa000);
2143 + _mt7620_mii_write(gsw, 1, 30, 0xa000);
2144 + _mt7620_mii_write(gsw, 2, 30, 0xa000);
2145 + _mt7620_mii_write(gsw, 3, 30, 0xa000);
2147 + _mt7620_mii_write(gsw, 0, 4, 0x05e1);
2148 + _mt7620_mii_write(gsw, 1, 4, 0x05e1);
2149 + _mt7620_mii_write(gsw, 2, 4, 0x05e1);
2150 + _mt7620_mii_write(gsw, 3, 4, 0x05e1);
2151 + _mt7620_mii_write(gsw, 1, 31, 0xa000); //local, page 2
2152 + _mt7620_mii_write(gsw, 0, 16, 0x1111);
2153 + _mt7620_mii_write(gsw, 1, 16, 0x1010);
2154 + _mt7620_mii_write(gsw, 2, 16, 0x1515);
2155 + _mt7620_mii_write(gsw, 3, 16, 0x0f0f);
2157 + /* CPU Port6 Force Link 1G, FC ON */
2158 + gsw_w32(gsw, 0x5e33b, GSW_REG_PORT_PMCR(6));
2159 + /* Set Port6 CPU Port */
2160 + gsw_w32(gsw, 0x7f7f7fe0, 0x0010);
2162 + /* setup port 4 */
2163 + if (gsw->port4 == PORT4_EPHY) {
2164 + u32 val = rt_sysc_r32(SYSCFG1);
2166 + rt_sysc_w32(val, SYSCFG1);
2167 + _mt7620_mii_write(gsw, 4, 30, 0xa000);
2168 + _mt7620_mii_write(gsw, 4, 4, 0x05e1);
2169 + _mt7620_mii_write(gsw, 4, 16, 0x1313);
2170 + pr_info("gsw: setting port4 to ephy mode\n");
2174 +void mt7620_set_mac(struct fe_priv *priv, unsigned char *mac)
2176 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
2177 + unsigned long flags;
2179 + spin_lock_irqsave(&priv->page_lock, flags);
2180 + gsw_w32(gsw, (mac[0] << 8) | mac[1], GSW_REG_SMACCR1);
2181 + gsw_w32(gsw, (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
2183 + spin_unlock_irqrestore(&priv->page_lock, flags);
2186 +static struct of_device_id gsw_match[] = {
2187 + { .compatible = "ralink,mt7620a-gsw" },
2191 +int mt7620_gsw_config(struct fe_priv *priv)
2193 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
2195 + /* is the mt7530 internal or external */
2196 + if ((_mt7620_mii_read(gsw, 0x1f, 2) == 1) && (_mt7620_mii_read(gsw, 0x1f, 3) == 0xbeef))
2197 + mt7530_probe(priv->device, NULL, priv->mii_bus);
2199 + mt7530_probe(priv->device, gsw->base, NULL);
2204 +int mt7620_gsw_probe(struct fe_priv *priv)
2206 + struct mt7620_gsw *gsw;
2207 + struct device_node *np;
2208 + const char *port4 = NULL;
2210 + np = of_find_matching_node(NULL, gsw_match);
2212 + dev_err(priv->device, "no gsw node found\n");
2215 + np = of_node_get(np);
2217 + gsw = devm_kzalloc(priv->device, sizeof(struct mt7620_gsw), GFP_KERNEL);
2219 + dev_err(priv->device, "no gsw memory for private data\n");
2223 + gsw->irq = irq_of_parse_and_map(np, 0);
2225 + dev_err(priv->device, "no gsw irq resource found\n");
2229 + gsw->base = of_iomap(np, 0);
2231 + dev_err(priv->device, "gsw ioremap failed\n");
2235 + gsw->dev = priv->device;
2236 + priv->soc->swpriv = gsw;
2238 + of_property_read_string(np, "ralink,port4", &port4);
2239 + if (port4 && !strcmp(port4, "ephy"))
2240 + gsw->port4 = PORT4_EPHY;
2241 + else if (port4 && !strcmp(port4, "gmac"))
2242 + gsw->port4 = PORT4_EXT;
2248 + gsw_w32(gsw, ~PORT_IRQ_ST_CHG, GSW_REG_IMR);
2249 + request_irq(gsw->irq, gsw_interrupt, 0, "gsw", priv);
2253 Index: linux-3.10.21/drivers/net/ethernet/ralink/gsw_mt7620a.h
2254 ===================================================================
2255 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2256 +++ linux-3.10.21/drivers/net/ethernet/ralink/gsw_mt7620a.h 2013-12-09 13:26:42.328125203 +0100
2259 + * This program is free software; you can redistribute it and/or modify
2260 + * it under the terms of the GNU General Public License as published by
2261 + * the Free Software Foundation; version 2 of the License
2263 + * This program is distributed in the hope that it will be useful,
2264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2266 + * GNU General Public License for more details.
2268 + * You should have received a copy of the GNU General Public License
2269 + * along with this program; if not, write to the Free Software
2270 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2272 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2275 +#ifndef _RALINK_GSW_MT7620_H__
2276 +#define _RALINK_GSW_MT7620_H__
2278 +extern int mt7620_gsw_config(struct fe_priv *priv);
2279 +extern int mt7620_gsw_probe(struct fe_priv *priv);
2280 +extern void mt7620_set_mac(struct fe_priv *priv, unsigned char *mac);
2281 +extern int mt7620_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val);
2282 +extern int mt7620_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg);
2283 +extern void mt7620_mdio_link_adjust(struct fe_priv *priv, int port);
2284 +extern void mt7620_port_init(struct fe_priv *priv, struct device_node *np);
2285 +extern int mt7620a_has_carrier(struct fe_priv *priv);
2288 Index: linux-3.10.21/drivers/net/ethernet/ralink/mdio.c
2289 ===================================================================
2290 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2291 +++ linux-3.10.21/drivers/net/ethernet/ralink/mdio.c 2013-12-09 13:26:42.328125203 +0100
2294 + * This program is free software; you can redistribute it and/or modify
2295 + * it under the terms of the GNU General Public License as published by
2296 + * the Free Software Foundation; version 2 of the License
2298 + * This program is distributed in the hope that it will be useful,
2299 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2300 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2301 + * GNU General Public License for more details.
2303 + * You should have received a copy of the GNU General Public License
2304 + * along with this program; if not, write to the Free Software
2305 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2307 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2310 +#include <linux/module.h>
2311 +#include <linux/kernel.h>
2312 +#include <linux/types.h>
2313 +#include <linux/dma-mapping.h>
2314 +#include <linux/init.h>
2315 +#include <linux/skbuff.h>
2316 +#include <linux/etherdevice.h>
2317 +#include <linux/ethtool.h>
2318 +#include <linux/platform_device.h>
2319 +#include <linux/phy.h>
2320 +#include <linux/of_device.h>
2321 +#include <linux/clk.h>
2322 +#include <linux/of_net.h>
2323 +#include <linux/of_mdio.h>
2325 +#include "ralink_soc_eth.h"
2328 +static int fe_mdio_reset(struct mii_bus *bus)
2334 +static void fe_phy_link_adjust(struct net_device *dev)
2336 + struct fe_priv *priv = netdev_priv(dev);
2337 + unsigned long flags;
2340 + spin_lock_irqsave(&priv->phy->lock, flags);
2341 + for (i = 0; i < 8; i++) {
2342 + if (priv->phy->phy_node[i]) {
2343 + struct phy_device *phydev = priv->phy->phy[i];
2344 + int status_change = 0;
2347 + if (priv->phy->duplex[i] != phydev->duplex ||
2348 + priv->phy->speed[i] != phydev->speed)
2349 + status_change = 1;
2351 + if (phydev->link != priv->link[i])
2352 + status_change = 1;
2354 + switch (phydev->speed) {
2358 + priv->link[i] = phydev->link;
2359 + priv->phy->duplex[i] = phydev->duplex;
2360 + priv->phy->speed[i] = phydev->speed;
2362 + if (status_change && priv->soc->mdio_adjust_link)
2363 + priv->soc->mdio_adjust_link(priv, i);
2370 +int fe_connect_phy_node(struct fe_priv *priv, struct device_node *phy_node)
2372 + const __be32 *_port = NULL;
2373 + struct phy_device *phydev;
2374 + int phy_mode, port;
2376 + _port = of_get_property(phy_node, "reg", NULL);
2378 + if (!_port || (be32_to_cpu(*_port) >= 0x20)) {
2379 + pr_err("%s: invalid port id\n", phy_node->name);
2382 + port = be32_to_cpu(*_port);
2383 + phy_mode = of_get_phy_mode(phy_node);
2384 + if (phy_mode < 0) {
2385 + dev_err(priv->device, "incorrect phy-mode %d\n", phy_mode);
2386 + priv->phy->phy_node[port] = NULL;
2390 + phydev = of_phy_connect(priv->netdev, phy_node, fe_phy_link_adjust,
2392 + if (IS_ERR(phydev)) {
2393 + dev_err(priv->device, "could not connect to PHY\n");
2394 + priv->phy->phy_node[port] = NULL;
2395 + return PTR_ERR(phydev);
2398 + phydev->supported &= PHY_GBIT_FEATURES;
2399 + phydev->advertising = phydev->supported;
2400 + phydev->no_auto_carrier_off = 1;
2402 + dev_info(priv->device,
2403 + "connected port %d to PHY at %s [uid=%08x, driver=%s]\n",
2404 + port, dev_name(&phydev->dev), phydev->phy_id,
2405 + phydev->drv->name);
2407 + priv->phy->phy[port] = phydev;
2408 + priv->link[port] = 0;
2413 +static int fe_phy_connect(struct fe_priv *priv)
2418 +static void fe_phy_disconnect(struct fe_priv *priv)
2420 + unsigned long flags;
2423 + for (i = 0; i < 8; i++)
2424 + if (priv->phy->phy_fixed[i]) {
2425 + spin_lock_irqsave(&priv->phy->lock, flags);
2426 + priv->link[i] = 0;
2427 + if (priv->soc->mdio_adjust_link)
2428 + priv->soc->mdio_adjust_link(priv, i);
2429 + spin_unlock_irqrestore(&priv->phy->lock, flags);
2430 + } else if (priv->phy->phy[i]) {
2431 + phy_disconnect(priv->phy->phy[i]);
2435 +static void fe_phy_start(struct fe_priv *priv)
2437 + unsigned long flags;
2440 + for (i = 0; i < 8; i++) {
2441 + if (priv->phy->phy_fixed[i]) {
2442 + spin_lock_irqsave(&priv->phy->lock, flags);
2443 + priv->link[i] = 1;
2444 + if (priv->soc->mdio_adjust_link)
2445 + priv->soc->mdio_adjust_link(priv, i);
2446 + spin_unlock_irqrestore(&priv->phy->lock, flags);
2447 + } else if (priv->phy->phy[i]) {
2448 + phy_start(priv->phy->phy[i]);
2453 +static void fe_phy_stop(struct fe_priv *priv)
2455 + unsigned long flags;
2458 + for (i = 0; i < 8; i++)
2459 + if (priv->phy->phy_fixed[i]) {
2460 + spin_lock_irqsave(&priv->phy->lock, flags);
2461 + priv->link[i] = 0;
2462 + if (priv->soc->mdio_adjust_link)
2463 + priv->soc->mdio_adjust_link(priv, i);
2464 + spin_unlock_irqrestore(&priv->phy->lock, flags);
2465 + } else if (priv->phy->phy[i]) {
2466 + phy_stop(priv->phy->phy[i]);
2470 +static struct fe_phy phy_ralink = {
2471 + .connect = fe_phy_connect,
2472 + .disconnect = fe_phy_disconnect,
2473 + .start = fe_phy_start,
2474 + .stop = fe_phy_stop,
2477 +int fe_mdio_init(struct fe_priv *priv)
2479 + struct device_node *mii_np;
2482 + if (!priv->soc->mdio_read || !priv->soc->mdio_write)
2485 + spin_lock_init(&phy_ralink.lock);
2486 + priv->phy = &phy_ralink;
2488 + mii_np = of_get_child_by_name(priv->device->of_node, "mdio-bus");
2490 + dev_err(priv->device, "no %s child node found", "mdio-bus");
2494 + if (!of_device_is_available(mii_np)) {
2496 + goto err_put_node;
2499 + priv->mii_bus = mdiobus_alloc();
2500 + if (priv->mii_bus == NULL) {
2502 + goto err_put_node;
2505 + priv->mii_bus->name = "mdio";
2506 + priv->mii_bus->read = priv->soc->mdio_read;
2507 + priv->mii_bus->write = priv->soc->mdio_write;
2508 + priv->mii_bus->reset = fe_mdio_reset;
2509 + priv->mii_bus->irq = priv->mii_irq;
2510 + priv->mii_bus->priv = priv;
2511 + priv->mii_bus->parent = priv->device;
2513 + snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s", mii_np->name);
2514 + err = of_mdiobus_register(priv->mii_bus, mii_np);
2516 + goto err_free_bus;
2521 + kfree(priv->mii_bus);
2523 + of_node_put(mii_np);
2524 + priv->mii_bus = NULL;
2528 +void fe_mdio_cleanup(struct fe_priv *priv)
2530 + if (!priv->mii_bus)
2533 + mdiobus_unregister(priv->mii_bus);
2534 + of_node_put(priv->mii_bus->dev.of_node);
2535 + kfree(priv->mii_bus);
2537 Index: linux-3.10.21/drivers/net/ethernet/ralink/mdio.h
2538 ===================================================================
2539 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2540 +++ linux-3.10.21/drivers/net/ethernet/ralink/mdio.h 2013-12-09 13:26:42.328125203 +0100
2543 + * This program is free software; you can redistribute it and/or modify
2544 + * it under the terms of the GNU General Public License as published by
2545 + * the Free Software Foundation; version 2 of the License
2547 + * This program is distributed in the hope that it will be useful,
2548 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2549 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2550 + * GNU General Public License for more details.
2552 + * You should have received a copy of the GNU General Public License
2553 + * along with this program; if not, write to the Free Software
2554 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2556 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2559 +#ifndef _RALINK_MDIO_H__
2560 +#define _RALINK_MDIO_H__
2562 +#ifdef CONFIG_NET_RALINK_MDIO
2563 +extern int fe_mdio_init(struct fe_priv *priv);
2564 +extern void fe_mdio_cleanup(struct fe_priv *priv);
2565 +extern int fe_connect_phy_node(struct fe_priv *priv, struct device_node *phy_node);
2567 +static inline int fe_mdio_init(struct fe_priv *priv) { return 0; }
2568 +static inline void fe_mdio_cleanup(struct fe_priv *priv) {}
2571 Index: linux-3.10.21/drivers/net/ethernet/ralink/mdio_rt2880.c
2572 ===================================================================
2573 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2574 +++ linux-3.10.21/drivers/net/ethernet/ralink/mdio_rt2880.c 2013-12-09 13:26:42.328125203 +0100
2577 + * This program is free software; you can redistribute it and/or modify
2578 + * it under the terms of the GNU General Public License as published by
2579 + * the Free Software Foundation; version 2 of the License
2581 + * This program is distributed in the hope that it will be useful,
2582 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2583 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2584 + * GNU General Public License for more details.
2586 + * You should have received a copy of the GNU General Public License
2587 + * along with this program; if not, write to the Free Software
2588 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2590 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2593 +#include <linux/module.h>
2594 +#include <linux/kernel.h>
2595 +#include <linux/types.h>
2596 +#include <linux/dma-mapping.h>
2597 +#include <linux/init.h>
2598 +#include <linux/skbuff.h>
2599 +#include <linux/etherdevice.h>
2600 +#include <linux/ethtool.h>
2601 +#include <linux/platform_device.h>
2602 +#include <linux/phy.h>
2603 +#include <linux/of_device.h>
2604 +#include <linux/clk.h>
2605 +#include <linux/of_net.h>
2606 +#include <linux/of_mdio.h>
2608 +#include "ralink_soc_eth.h"
2609 +#include "mdio_rt2880.h"
2612 +#define FE_MDIO_RETRY 1000
2614 +static unsigned char *rt2880_speed_str(struct fe_priv *priv)
2616 + switch (priv->phy->speed[0]) {
2628 +void rt2880_mdio_link_adjust(struct fe_priv *priv, int port)
2632 + if (!priv->link[0]) {
2633 + netif_carrier_off(priv->netdev);
2634 + netdev_info(priv->netdev, "link down\n");
2638 + mdio_cfg = FE_MDIO_CFG_TX_CLK_SKEW_200 |
2639 + FE_MDIO_CFG_RX_CLK_SKEW_200 |
2640 + FE_MDIO_CFG_GP1_FRC_EN;
2642 + if (priv->phy->duplex[0] == DUPLEX_FULL)
2643 + mdio_cfg |= FE_MDIO_CFG_GP1_DUPLEX;
2645 + if (priv->phy->tx_fc[0])
2646 + mdio_cfg |= FE_MDIO_CFG_GP1_FC_TX;
2648 + if (priv->phy->rx_fc[0])
2649 + mdio_cfg |= FE_MDIO_CFG_GP1_FC_RX;
2651 + switch (priv->phy->speed[0]) {
2653 + mdio_cfg |= FE_MDIO_CFG_GP1_SPEED_10;
2656 + mdio_cfg |= FE_MDIO_CFG_GP1_SPEED_100;
2659 + mdio_cfg |= FE_MDIO_CFG_GP1_SPEED_1000;
2665 + fe_w32(mdio_cfg, FE_MDIO_CFG);
2667 + netif_carrier_on(priv->netdev);
2668 + netdev_info(priv->netdev, "link up (%sMbps/%s duplex)\n",
2669 + rt2880_speed_str(priv),
2670 + (DUPLEX_FULL == priv->phy->duplex[0]) ? "Full" : "Half");
2673 +static int rt2880_mdio_wait_ready(struct fe_priv *priv)
2677 + retries = FE_MDIO_RETRY;
2681 + t = fe_r32(FE_MDIO_ACCESS);
2682 + if ((t & (0x1 << 31)) == 0)
2685 + if (retries-- == 0)
2691 + dev_err(priv->device, "MDIO operation timed out\n");
2692 + return -ETIMEDOUT;
2695 +int rt2880_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg)
2697 + struct fe_priv *priv = bus->priv;
2701 + err = rt2880_mdio_wait_ready(priv);
2705 + t = (phy_addr << 24) | (phy_reg << 16);
2706 + fe_w32(t, FE_MDIO_ACCESS);
2708 + fe_w32(t, FE_MDIO_ACCESS);
2710 + err = rt2880_mdio_wait_ready(priv);
2714 + pr_info("%s: addr=%04x, reg=%04x, value=%04x\n", __func__,
2715 + phy_addr, phy_reg, fe_r32(FE_MDIO_ACCESS) & 0xffff);
2717 + return fe_r32(FE_MDIO_ACCESS) & 0xffff;
2720 +int rt2880_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val)
2722 + struct fe_priv *priv = bus->priv;
2726 + pr_info("%s: addr=%04x, reg=%04x, value=%04x\n", __func__,
2727 + phy_addr, phy_reg, fe_r32(FE_MDIO_ACCESS) & 0xffff);
2729 + err = rt2880_mdio_wait_ready(priv);
2733 + t = (1 << 30) | (phy_addr << 24) | (phy_reg << 16) | val;
2734 + fe_w32(t, FE_MDIO_ACCESS);
2736 + fe_w32(t, FE_MDIO_ACCESS);
2738 + return rt2880_mdio_wait_ready(priv);
2741 +void rt2880_port_init(struct fe_priv *priv, struct device_node *np)
2743 + const __be32 *id = of_get_property(np, "reg", NULL);
2744 + const __be32 *link;
2748 + if (!id || (be32_to_cpu(*id) != 0)) {
2749 + pr_err("%s: invalid port id\n", np->name);
2753 + priv->phy->phy_fixed[0] = of_get_property(np, "ralink,fixed-link", &size);
2754 + if (priv->phy->phy_fixed[0] && (size != (4 * sizeof(*priv->phy->phy_fixed[0])))) {
2755 + pr_err("%s: invalid fixed link property\n", np->name);
2756 + priv->phy->phy_fixed[0] = NULL;
2760 + phy_mode = of_get_phy_mode(np);
2761 + switch (phy_mode) {
2762 + case PHY_INTERFACE_MODE_RGMII:
2764 + case PHY_INTERFACE_MODE_MII:
2766 + case PHY_INTERFACE_MODE_RMII:
2769 + if (!priv->phy->phy_fixed[0])
2770 + dev_err(priv->device, "port %d - invalid phy mode\n", priv->phy->speed[0]);
2774 + priv->phy->phy_node[0] = of_parse_phandle(np, "phy-handle", 0);
2775 + if (!priv->phy->phy_node[0] && !priv->phy->phy_fixed[0])
2778 + if (priv->phy->phy_fixed[0]) {
2779 + link = priv->phy->phy_fixed[0];
2780 + priv->phy->speed[0] = be32_to_cpup(link++);
2781 + priv->phy->duplex[0] = be32_to_cpup(link++);
2782 + priv->phy->tx_fc[0] = be32_to_cpup(link++);
2783 + priv->phy->rx_fc[0] = be32_to_cpup(link++);
2785 + priv->link[0] = 1;
2786 + switch (priv->phy->speed[0]) {
2794 + dev_err(priv->device, "invalid link speed: %d\n", priv->phy->speed[0]);
2795 + priv->phy->phy_fixed[0] = 0;
2798 + dev_info(priv->device, "using fixed link parameters\n");
2799 + rt2880_mdio_link_adjust(priv, 0);
2802 + if (priv->phy->phy_node[0] && priv->mii_bus->phy_map[0]) {
2803 + fe_connect_phy_node(priv, priv->phy->phy_node[0]);
2808 Index: linux-3.10.21/drivers/net/ethernet/ralink/mdio_rt2880.h
2809 ===================================================================
2810 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2811 +++ linux-3.10.21/drivers/net/ethernet/ralink/mdio_rt2880.h 2013-12-09 13:26:42.328125203 +0100
2814 + * This program is free software; you can redistribute it and/or modify
2815 + * it under the terms of the GNU General Public License as published by
2816 + * the Free Software Foundation; version 2 of the License
2818 + * This program is distributed in the hope that it will be useful,
2819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2821 + * GNU General Public License for more details.
2823 + * You should have received a copy of the GNU General Public License
2824 + * along with this program; if not, write to the Free Software
2825 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2827 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2830 +#ifndef _RALINK_MDIO_RT2880_H__
2831 +#define _RALINK_MDIO_RT2880_H__
2833 +void rt2880_mdio_link_adjust(struct fe_priv *priv, int port);
2834 +int rt2880_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg);
2835 +int rt2880_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val);
2836 +void rt2880_port_init(struct fe_priv *priv, struct device_node *np);
2839 Index: linux-3.10.21/drivers/net/ethernet/ralink/ralink_soc_eth.c
2840 ===================================================================
2841 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2842 +++ linux-3.10.21/drivers/net/ethernet/ralink/ralink_soc_eth.c 2013-12-09 14:01:00.060174130 +0100
2845 + * This program is free software; you can redistribute it and/or modify
2846 + * it under the terms of the GNU General Public License as published by
2847 + * the Free Software Foundation; version 2 of the License
2849 + * This program is distributed in the hope that it will be useful,
2850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2852 + * GNU General Public License for more details.
2854 + * You should have received a copy of the GNU General Public License
2855 + * along with this program; if not, write to the Free Software
2856 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2858 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2861 +#include <linux/module.h>
2862 +#include <linux/kernel.h>
2863 +#include <linux/types.h>
2864 +#include <linux/dma-mapping.h>
2865 +#include <linux/init.h>
2866 +#include <linux/skbuff.h>
2867 +#include <linux/etherdevice.h>
2868 +#include <linux/ethtool.h>
2869 +#include <linux/platform_device.h>
2870 +#include <linux/of_device.h>
2871 +#include <linux/clk.h>
2872 +#include <linux/of_net.h>
2873 +#include <linux/of_mdio.h>
2874 +#include <linux/if_vlan.h>
2875 +#include <linux/reset.h>
2877 +#include <asm/mach-ralink/ralink_regs.h>
2879 +#include "ralink_soc_eth.h"
2880 +#include "esw_rt3052.h"
2883 +#define TX_TIMEOUT (2 * HZ)
2884 +#define MAX_RX_LENGTH 1536
2885 +#define DMA_DUMMY_DESC 0xffffffff
2887 +static const u32 fe_reg_table_default[FE_REG_COUNT] = {
2888 + [FE_REG_PDMA_GLO_CFG] = FE_PDMA_GLO_CFG,
2889 + [FE_REG_PDMA_RST_CFG] = FE_PDMA_RST_CFG,
2890 + [FE_REG_DLY_INT_CFG] = FE_DLY_INT_CFG,
2891 + [FE_REG_TX_BASE_PTR0] = FE_TX_BASE_PTR0,
2892 + [FE_REG_TX_MAX_CNT0] = FE_TX_MAX_CNT0,
2893 + [FE_REG_TX_CTX_IDX0] = FE_TX_CTX_IDX0,
2894 + [FE_REG_RX_BASE_PTR0] = FE_RX_BASE_PTR0,
2895 + [FE_REG_RX_MAX_CNT0] = FE_RX_MAX_CNT0,
2896 + [FE_REG_RX_CALC_IDX0] = FE_RX_CALC_IDX0,
2897 + [FE_REG_FE_INT_ENABLE] = FE_FE_INT_ENABLE,
2898 + [FE_REG_FE_INT_STATUS] = FE_FE_INT_STATUS,
2901 +static const u32 *fe_reg_table = fe_reg_table_default;
2903 +static void __iomem *fe_base = 0;
2905 +void fe_w32(u32 val, unsigned reg)
2907 + __raw_writel(val, fe_base + reg);
2910 +u32 fe_r32(unsigned reg)
2912 + return __raw_readl(fe_base + reg);
2915 +static inline void fe_reg_w32(u32 val, enum fe_reg reg)
2917 + fe_w32(val, fe_reg_table[reg]);
2920 +static inline u32 fe_reg_r32(enum fe_reg reg)
2922 + return fe_r32(fe_reg_table[reg]);
2925 +static inline void fe_int_disable(u32 mask)
2927 + fe_reg_w32(fe_reg_r32(FE_REG_FE_INT_ENABLE) & ~mask,
2928 + FE_REG_FE_INT_ENABLE);
2930 + fe_reg_r32(FE_REG_FE_INT_ENABLE);
2933 +static inline void fe_int_enable(u32 mask)
2935 + fe_reg_w32(fe_reg_r32(FE_REG_FE_INT_ENABLE) | mask,
2936 + FE_REG_FE_INT_ENABLE);
2938 + fe_reg_r32(FE_REG_FE_INT_ENABLE);
2941 +static inline void fe_hw_set_macaddr(struct fe_priv *priv, unsigned char *mac)
2943 + unsigned long flags;
2945 + spin_lock_irqsave(&priv->page_lock, flags);
2946 + fe_w32((mac[0] << 8) | mac[1], FE_GDMA1_MAC_ADRH);
2947 + fe_w32((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
2948 + FE_GDMA1_MAC_ADRL);
2949 + spin_unlock_irqrestore(&priv->page_lock, flags);
2952 +static int fe_set_mac_address(struct net_device *dev, void *p)
2954 + int ret = eth_mac_addr(dev, p);
2957 + struct fe_priv *priv = netdev_priv(dev);
2959 + if (priv->soc->set_mac)
2960 + priv->soc->set_mac(priv, dev->dev_addr);
2962 + fe_hw_set_macaddr(priv, p);
2968 +static struct sk_buff* fe_alloc_skb(struct fe_priv *priv)
2970 + struct sk_buff *skb;
2972 + skb = netdev_alloc_skb(priv->netdev, MAX_RX_LENGTH + NET_IP_ALIGN);
2976 + skb_reserve(skb, NET_IP_ALIGN);
2981 +static int fe_alloc_rx(struct fe_priv *priv)
2983 + int size = NUM_DMA_DESC * sizeof(struct fe_rx_dma);
2986 + priv->rx_dma = dma_alloc_coherent(&priv->netdev->dev, size,
2987 + &priv->rx_phys, GFP_ATOMIC);
2988 + if (!priv->rx_dma)
2991 + memset(priv->rx_dma, 0, size);
2993 + for (i = 0; i < NUM_DMA_DESC; i++) {
2994 + priv->rx_skb[i] = fe_alloc_skb(priv);
2995 + if (!priv->rx_skb[i])
2999 + for (i = 0; i < NUM_DMA_DESC; i++) {
3000 + dma_addr_t dma_addr = dma_map_single(&priv->netdev->dev,
3001 + priv->rx_skb[i]->data,
3004 + priv->rx_dma[i].rxd1 = (unsigned int) dma_addr;
3006 + if (priv->soc->rx_dma)
3007 + priv->soc->rx_dma(priv, i, MAX_RX_LENGTH);
3009 + priv->rx_dma[i].rxd2 = RX_DMA_LSO;
3013 + fe_reg_w32(priv->rx_phys, FE_REG_RX_BASE_PTR0);
3014 + fe_reg_w32(NUM_DMA_DESC, FE_REG_RX_MAX_CNT0);
3015 + fe_reg_w32((NUM_DMA_DESC - 1), FE_REG_RX_CALC_IDX0);
3016 + fe_reg_w32(FE_PST_DRX_IDX0, FE_REG_PDMA_RST_CFG);
3021 +static int fe_alloc_tx(struct fe_priv *priv)
3023 + int size = NUM_DMA_DESC * sizeof(struct fe_tx_dma);
3026 + priv->tx_free_idx = 0;
3028 + priv->tx_dma = dma_alloc_coherent(&priv->netdev->dev, size,
3029 + &priv->tx_phys, GFP_ATOMIC);
3030 + if (!priv->tx_dma)
3033 + memset(priv->tx_dma, 0, size);
3035 + for (i = 0; i < NUM_DMA_DESC; i++) {
3036 + if (priv->soc->tx_dma) {
3037 + priv->soc->tx_dma(priv, i, NULL);
3041 + priv->tx_dma[i].txd2 = TX_DMA_LSO | TX_DMA_DONE;
3042 + priv->tx_dma[i].txd4 = TX_DMA_QN(3) | TX_DMA_PN(1);
3045 + fe_reg_w32(priv->tx_phys, FE_REG_TX_BASE_PTR0);
3046 + fe_reg_w32(NUM_DMA_DESC, FE_REG_TX_MAX_CNT0);
3047 + fe_reg_w32(0, FE_REG_TX_CTX_IDX0);
3048 + fe_reg_w32(FE_PST_DTX_IDX0, FE_REG_PDMA_RST_CFG);
3053 +static void fe_free_dma(struct fe_priv *priv)
3057 + for (i = 0; i < NUM_DMA_DESC; i++) {
3058 + if (priv->rx_skb[i]) {
3059 + dma_unmap_single(&priv->netdev->dev, priv->rx_dma[i].rxd1,
3060 + MAX_RX_LENGTH, DMA_FROM_DEVICE);
3061 + dev_kfree_skb_any(priv->rx_skb[i]);
3062 + priv->rx_skb[i] = NULL;
3065 + if (priv->tx_skb[i]) {
3066 + dev_kfree_skb_any(priv->tx_skb[i]);
3067 + priv->tx_skb[i] = NULL;
3071 + if (priv->rx_dma) {
3072 + int size = NUM_DMA_DESC * sizeof(struct fe_rx_dma);
3073 + dma_free_coherent(&priv->netdev->dev, size, priv->rx_dma,
3077 + if (priv->tx_dma) {
3078 + int size = NUM_DMA_DESC * sizeof(struct fe_tx_dma);
3079 + dma_free_coherent(&priv->netdev->dev, size, priv->tx_dma,
3083 + netdev_reset_queue(priv->netdev);
3086 +static void fe_start_tso(struct sk_buff *skb, struct net_device *dev, unsigned int nr_frags, int idx)
3088 + struct fe_priv *priv = netdev_priv(dev);
3089 + struct skb_frag_struct *frag;
3092 + for (i = 0; i < nr_frags; i++) {
3093 + dma_addr_t mapped_addr;
3095 + frag = &skb_shinfo(skb)->frags[i];
3096 + mapped_addr = skb_frag_dma_map(&dev->dev, frag, 0, skb_frag_size(frag), DMA_TO_DEVICE);
3098 + idx = (idx + 1) % NUM_DMA_DESC;
3099 + priv->tx_dma[idx].txd1 = mapped_addr;
3100 + if (i == nr_frags - 1)
3101 + priv->tx_dma[idx].txd2 = TX_DMA_LSO | TX_DMA_PLEN0(frag->size);
3103 + priv->tx_dma[idx].txd2 = TX_DMA_PLEN0(frag->size);
3105 + priv->tx_dma[idx].txd3 = mapped_addr;
3106 + if (i == nr_frags - 1)
3107 + priv->tx_dma[idx].txd2 |= TX_DMA_LS1 | TX_DMA_PLEN1(frag->size);
3109 + priv->tx_dma[idx].txd2 |= TX_DMA_PLEN1(frag->size);
3114 +static int fe_start_xmit(struct sk_buff *skb, struct net_device *dev)
3116 + unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3117 + struct fe_priv *priv = netdev_priv(dev);
3118 + dma_addr_t mapped_addr;
3119 + u32 tx_next, tx, tx_num = 1;
3122 + if (priv->soc->min_pkt_len) {
3123 + if (skb->len < priv->soc->min_pkt_len) {
3124 + if (skb_padto(skb, priv->soc->min_pkt_len)) {
3126 + "fe_eth: skb_padto failed\n");
3130 + skb_put(skb, priv->soc->min_pkt_len - skb->len);
3134 + dev->trans_start = jiffies;
3135 + mapped_addr = dma_map_single(&priv->netdev->dev, skb->data,
3136 + skb->len, DMA_TO_DEVICE);
3138 + spin_lock(&priv->page_lock);
3140 + tx = fe_reg_r32(FE_REG_TX_CTX_IDX0);
3141 + if (priv->soc->tso && nr_frags)
3142 + tx_num += nr_frags >> 1;
3143 + tx_next = (tx + tx_num) % NUM_DMA_DESC;
3144 + if ((priv->tx_skb[tx]) || (priv->tx_skb[tx_next]) ||
3145 + !(priv->tx_dma[tx].txd2 & TX_DMA_DONE) ||
3146 + !(priv->tx_dma[tx_next].txd2 & TX_DMA_DONE))
3148 + spin_unlock(&priv->page_lock);
3149 + dev->stats.tx_dropped++;
3152 + return NETDEV_TX_OK;
3155 + if (priv->soc->tso) {
3158 + priv->tx_skb[(tx + t - 1) % NUM_DMA_DESC] = skb;
3160 + priv->tx_skb[(tx + t - 1) % NUM_DMA_DESC] = (struct sk_buff *) DMA_DUMMY_DESC;
3162 + priv->tx_skb[tx] = skb;
3164 + priv->tx_dma[tx].txd1 = (unsigned int) mapped_addr;
3167 + priv->tx_dma[tx].txd4 &= ~0x80;
3168 + if (priv->soc->tx_dma)
3169 + priv->soc->tx_dma(priv, tx, skb);
3171 + priv->tx_dma[tx].txd2 = TX_DMA_LSO | TX_DMA_PLEN0(skb->len);
3173 + if (skb->ip_summed == CHECKSUM_PARTIAL)
3174 + priv->tx_dma[tx].txd4 |= TX_DMA_CHKSUM;
3176 + priv->tx_dma[tx].txd4 &= ~TX_DMA_CHKSUM;
3178 + if (priv->soc->tso)
3179 + fe_start_tso(skb, dev, nr_frags, tx);
3181 + if (skb_shinfo(skb)->gso_segs > 1) {
3182 + struct iphdr *iph = NULL;
3183 + struct tcphdr *th = NULL;
3184 + struct ipv6hdr *ip6h = NULL;
3186 + ip6h = (struct ipv6hdr *) skb_network_header(skb);
3187 + iph = (struct iphdr *) skb_network_header(skb);
3188 + if ((iph->version == 4) && (iph->protocol == IPPROTO_TCP)) {
3189 + th = (struct tcphdr *)skb_transport_header(skb);
3190 + priv->tx_dma[tx].txd4 |= BIT(28);
3191 + th->check = htons(skb_shinfo(skb)->gso_size);
3192 + dma_cache_sync(NULL, th, sizeof(struct tcphdr), DMA_TO_DEVICE);
3193 + } else if ((ip6h->version == 6) && (ip6h->nexthdr == NEXTHDR_TCP)) {
3194 + th = (struct tcphdr *)skb_transport_header(skb);
3195 + priv->tx_dma[tx].txd4 |= BIT(28);
3196 + th->check = htons(skb_shinfo(skb)->gso_size);
3197 + dma_cache_sync(NULL, th, sizeof(struct tcphdr), DMA_TO_DEVICE);
3201 + for (i = 0; i < tx_num; i++)
3202 + dma_cache_sync(NULL, &priv->tx_dma[tx + i], sizeof(struct fe_tx_dma), DMA_TO_DEVICE);
3204 + dev->stats.tx_packets++;
3205 + dev->stats.tx_bytes += skb->len;
3208 + fe_reg_w32(tx_next, FE_REG_TX_CTX_IDX0);
3209 + netdev_sent_queue(dev, skb->len);
3211 + spin_unlock(&priv->page_lock);
3213 + return NETDEV_TX_OK;
3216 +static int fe_poll_rx(struct napi_struct *napi, int budget)
3218 + struct fe_priv *priv = container_of(napi, struct fe_priv, rx_napi);
3219 + int idx = fe_reg_r32(FE_REG_RX_CALC_IDX0);
3223 + while ((rx < budget) && !complete) {
3224 + idx = (idx + 1) % NUM_DMA_DESC;
3226 + if (priv->rx_dma[idx].rxd2 & RX_DMA_DONE) {
3227 + struct sk_buff *new_skb = fe_alloc_skb(priv);
3230 + int pktlen = RX_DMA_PLEN0(priv->rx_dma[idx].rxd2);
3231 + dma_addr_t dma_addr;
3233 + dma_unmap_single(&priv->netdev->dev, priv->rx_dma[idx].rxd1,
3234 + MAX_RX_LENGTH, DMA_FROM_DEVICE);
3236 + skb_put(priv->rx_skb[idx], pktlen);
3237 + priv->rx_skb[idx]->dev = priv->netdev;
3238 + priv->rx_skb[idx]->protocol = eth_type_trans(priv->rx_skb[idx], priv->netdev);
3239 + if (priv->rx_dma[idx].rxd4 & priv->soc->checksum_bit)
3240 + priv->rx_skb[idx]->ip_summed = CHECKSUM_UNNECESSARY;
3242 + priv->rx_skb[idx]->ip_summed = CHECKSUM_NONE;
3243 + priv->netdev->stats.rx_packets++;
3244 + priv->netdev->stats.rx_bytes += pktlen;
3246 +#ifdef CONFIG_INET_LRO
3247 + if (priv->soc->get_skb_header && priv->rx_skb[idx]->ip_summed == CHECKSUM_UNNECESSARY)
3248 + lro_receive_skb(&priv->lro_mgr, priv->rx_skb[idx], NULL);
3251 + netif_receive_skb(priv->rx_skb[idx]);
3253 + priv->rx_skb[idx] = new_skb;
3255 + dma_addr = dma_map_single(&priv->netdev->dev,
3259 + priv->rx_dma[idx].rxd1 = (unsigned int) dma_addr;
3262 + priv->netdev->stats.rx_dropped++;
3265 + if (priv->soc->rx_dma)
3266 + priv->soc->rx_dma(priv, idx, MAX_RX_LENGTH);
3268 + priv->rx_dma[idx].rxd2 = RX_DMA_LSO;
3269 + fe_reg_w32(idx, FE_REG_RX_CALC_IDX0);
3277 +#ifdef CONFIG_INET_LRO
3278 + if (priv->soc->get_skb_header)
3279 + lro_flush_all(&priv->lro_mgr);
3282 + napi_complete(&priv->rx_napi);
3283 + fe_int_enable(priv->soc->rx_dly_int);
3289 +static void fe_tx_housekeeping(unsigned long ptr)
3291 + struct net_device *dev = (struct net_device*)ptr;
3292 + struct fe_priv *priv = netdev_priv(dev);
3293 + unsigned int bytes_compl = 0;
3294 + unsigned int pkts_compl = 0;
3296 + spin_lock(&priv->page_lock);
3298 + struct fe_tx_dma *txd;
3300 + txd = &priv->tx_dma[priv->tx_free_idx];
3302 + if (!(txd->txd2 & TX_DMA_DONE) || !(priv->tx_skb[priv->tx_free_idx]))
3305 + if (priv->tx_skb[priv->tx_free_idx] != (struct sk_buff *) DMA_DUMMY_DESC) {
3306 + bytes_compl += priv->tx_skb[priv->tx_free_idx]->len;
3307 + dev_kfree_skb_irq(priv->tx_skb[priv->tx_free_idx]);
3310 + priv->tx_skb[priv->tx_free_idx] = NULL;
3311 + priv->tx_free_idx++;
3312 + if (priv->tx_free_idx >= NUM_DMA_DESC)
3313 + priv->tx_free_idx = 0;
3316 + netdev_completed_queue(priv->netdev, pkts_compl, bytes_compl);
3317 + spin_unlock(&priv->page_lock);
3319 + fe_int_enable(priv->soc->tx_dly_int);
3322 +static void fe_tx_timeout(struct net_device *dev)
3324 + struct fe_priv *priv = netdev_priv(dev);
3326 + tasklet_schedule(&priv->tx_tasklet);
3327 + priv->netdev->stats.tx_errors++;
3328 + netdev_err(dev, "transmit timed out, waking up the queue\n");
3329 + netif_wake_queue(dev);
3332 +static irqreturn_t fe_handle_irq(int irq, void *dev)
3334 + struct fe_priv *priv = netdev_priv(dev);
3335 + unsigned int status;
3336 + unsigned int mask;
3338 + status = fe_reg_r32(FE_REG_FE_INT_STATUS);
3339 + mask = fe_reg_r32(FE_REG_FE_INT_ENABLE);
3341 + if (!(status & mask))
3344 + if (status & priv->soc->rx_dly_int) {
3345 + fe_int_disable(priv->soc->rx_dly_int);
3346 + napi_schedule(&priv->rx_napi);
3349 + if (status & priv->soc->tx_dly_int) {
3350 + fe_int_disable(priv->soc->tx_dly_int);
3351 + tasklet_schedule(&priv->tx_tasklet);
3354 + fe_reg_w32(status, FE_REG_FE_INT_STATUS);
3356 + return IRQ_HANDLED;
3359 +static int fe_hw_init(struct net_device *dev)
3361 + struct fe_priv *priv = netdev_priv(dev);
3364 + err = devm_request_irq(priv->device, dev->irq, fe_handle_irq, 0,
3365 + dev_name(priv->device), dev);
3369 + err = fe_alloc_rx(priv);
3371 + err = fe_alloc_tx(priv);
3375 + if (priv->soc->set_mac)
3376 + priv->soc->set_mac(priv, dev->dev_addr);
3378 + fe_hw_set_macaddr(priv, dev->dev_addr);
3380 + fe_reg_w32(FE_DELAY_INIT, FE_REG_DLY_INT_CFG);
3382 + fe_int_disable(priv->soc->tx_dly_int | priv->soc->rx_dly_int);
3384 + tasklet_init(&priv->tx_tasklet, fe_tx_housekeeping, (unsigned long)dev);
3386 + if (priv->soc->fwd_config) {
3387 + priv->soc->fwd_config(priv);
3389 + unsigned long sysclk = priv->sysclk;
3392 + netdev_err(dev, "unable to get clock\n");
3396 + sysclk /= FE_US_CYC_CNT_DIVISOR;
3397 + sysclk <<= FE_US_CYC_CNT_SHIFT;
3399 + fe_w32((fe_r32(FE_FE_GLO_CFG) &
3400 + ~(FE_US_CYC_CNT_MASK << FE_US_CYC_CNT_SHIFT)) | sysclk,
3403 + fe_w32(fe_r32(FE_GDMA1_FWD_CFG) & ~0xffff, FE_GDMA1_FWD_CFG);
3404 + fe_w32(fe_r32(FE_GDMA1_FWD_CFG) | (FE_GDM1_ICS_EN | FE_GDM1_TCS_EN | FE_GDM1_UCS_EN),
3405 + FE_GDMA1_FWD_CFG);
3406 + fe_w32(fe_r32(FE_CDMA_CSG_CFG) | (FE_ICS_GEN_EN | FE_TCS_GEN_EN | FE_UCS_GEN_EN),
3408 + fe_w32(FE_PSE_FQFC_CFG_INIT, FE_PSE_FQ_CFG);
3411 + fe_w32(1, FE_FE_RST_GL);
3412 + fe_w32(0, FE_FE_RST_GL);
3417 +static int fe_open(struct net_device *dev)
3419 + struct fe_priv *priv = netdev_priv(dev);
3420 + unsigned long flags;
3423 + spin_lock_irqsave(&priv->page_lock, flags);
3424 + napi_enable(&priv->rx_napi);
3426 + val = FE_TX_WB_DDONE | FE_RX_DMA_EN | FE_TX_DMA_EN;
3427 + val |= priv->soc->pdma_glo_cfg;
3428 + fe_reg_w32(val, FE_REG_PDMA_GLO_CFG);
3430 + spin_unlock_irqrestore(&priv->page_lock, flags);
3433 + priv->phy->start(priv);
3435 + if (priv->soc->has_carrier && priv->soc->has_carrier(priv))
3436 + netif_carrier_on(dev);
3438 + netif_start_queue(dev);
3439 + fe_int_enable(priv->soc->tx_dly_int | priv->soc->rx_dly_int);
3444 +static int fe_stop(struct net_device *dev)
3446 + struct fe_priv *priv = netdev_priv(dev);
3447 + unsigned long flags;
3449 + fe_int_disable(priv->soc->tx_dly_int | priv->soc->rx_dly_int);
3451 + netif_stop_queue(dev);
3454 + priv->phy->stop(priv);
3456 + spin_lock_irqsave(&priv->page_lock, flags);
3457 + napi_disable(&priv->rx_napi);
3459 + fe_reg_w32(fe_reg_r32(FE_REG_PDMA_GLO_CFG) &
3460 + ~(FE_TX_WB_DDONE | FE_RX_DMA_EN | FE_TX_DMA_EN),
3461 + FE_REG_PDMA_GLO_CFG);
3462 + spin_unlock_irqrestore(&priv->page_lock, flags);
3467 +static int __init fe_init(struct net_device *dev)
3469 + struct fe_priv *priv = netdev_priv(dev);
3470 + struct device_node *port;
3473 + BUG_ON(!priv->soc->reset_fe);
3474 + priv->soc->reset_fe();
3476 + if (priv->soc->switch_init)
3477 + priv->soc->switch_init(priv);
3479 + net_srandom(jiffies);
3480 + memcpy(dev->dev_addr, priv->soc->mac, ETH_ALEN);
3481 + of_get_mac_address_mtd(priv->device->of_node, dev->dev_addr);
3483 + err = fe_mdio_init(priv);
3488 + err = priv->phy->connect(priv);
3490 + goto err_mdio_cleanup;
3493 + if (priv->soc->port_init)
3494 + for_each_child_of_node(priv->device->of_node, port)
3495 + if (of_device_is_compatible(port, "ralink,eth-port") && of_device_is_available(port))
3496 + priv->soc->port_init(priv, port);
3498 + err = fe_hw_init(dev);
3500 + goto err_phy_disconnect;
3502 + if (priv->soc->switch_config)
3503 + priv->soc->switch_config(priv);
3507 +err_phy_disconnect:
3509 + priv->phy->disconnect(priv);
3511 + fe_mdio_cleanup(priv);
3516 +static void fe_uninit(struct net_device *dev)
3518 + struct fe_priv *priv = netdev_priv(dev);
3520 + tasklet_kill(&priv->tx_tasklet);
3523 + priv->phy->disconnect(priv);
3524 + fe_mdio_cleanup(priv);
3526 + fe_reg_w32(0, FE_REG_FE_INT_ENABLE);
3527 + free_irq(dev->irq, dev);
3529 + fe_free_dma(priv);
3532 +static const struct net_device_ops fe_netdev_ops = {
3533 + .ndo_init = fe_init,
3534 + .ndo_uninit = fe_uninit,
3535 + .ndo_open = fe_open,
3536 + .ndo_stop = fe_stop,
3537 + .ndo_start_xmit = fe_start_xmit,
3538 + .ndo_tx_timeout = fe_tx_timeout,
3539 + .ndo_set_mac_address = fe_set_mac_address,
3540 + .ndo_change_mtu = eth_change_mtu,
3541 + .ndo_validate_addr = eth_validate_addr,
3544 +static int fe_probe(struct platform_device *pdev)
3546 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3547 + const struct of_device_id *match;
3548 + struct fe_soc_data *soc = NULL;
3549 + struct net_device *netdev;
3550 + struct fe_priv *priv;
3551 + struct clk *sysclk;
3554 + device_reset(&pdev->dev);
3556 + match = of_match_device(of_fe_match, &pdev->dev);
3557 + soc = (struct fe_soc_data *) match->data;
3559 + if (soc->init_data)
3560 + soc->init_data(soc);
3561 + if (soc->reg_table)
3562 + fe_reg_table = soc->reg_table;
3564 + fe_base = devm_request_and_ioremap(&pdev->dev, res);
3568 + netdev = alloc_etherdev(sizeof(struct fe_priv));
3570 + dev_err(&pdev->dev, "alloc_etherdev failed\n");
3574 + strcpy(netdev->name, "eth%d");
3575 + netdev->netdev_ops = &fe_netdev_ops;
3576 + netdev->base_addr = (unsigned long) fe_base;
3577 + netdev->watchdog_timeo = TX_TIMEOUT;
3578 + netdev->features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
3580 + if (fe_reg_table[FE_REG_FE_DMA_VID_BASE])
3581 + netdev->features |= NETIF_F_HW_VLAN_CTAG_TX;
3584 + dev_info(&pdev->dev, "Enabling TSO\n");
3585 + netdev->features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_IPV6_CSUM;
3588 + netdev->hw_features = netdev->vlan_features = netdev->features;
3590 + netdev->irq = platform_get_irq(pdev, 0);
3591 + if (netdev->irq < 0) {
3592 + dev_err(&pdev->dev, "no IRQ resource found\n");
3597 + priv = netdev_priv(netdev);
3598 + memset(priv, 0, sizeof(struct fe_priv));
3599 + spin_lock_init(&priv->page_lock);
3601 + sysclk = devm_clk_get(&pdev->dev, NULL);
3602 + if (!IS_ERR(sysclk))
3603 + priv->sysclk = clk_get_rate(sysclk);
3605 + priv->netdev = netdev;
3606 + priv->device = &pdev->dev;
3609 + err = register_netdev(netdev);
3611 + dev_err(&pdev->dev, "error bringing up device\n");
3615 + netif_napi_add(netdev, &priv->rx_napi, fe_poll_rx, 32);
3617 +#ifdef CONFIG_INET_LRO
3618 + if (priv->soc->get_skb_header) {
3619 + priv->lro_mgr.dev = netdev;
3620 + memset(&priv->lro_mgr.stats, 0, sizeof(priv->lro_mgr.stats));
3621 + priv->lro_mgr.features = LRO_F_NAPI;
3622 + priv->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
3623 + priv->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
3624 + priv->lro_mgr.max_desc = ARRAY_SIZE(priv->lro_arr);
3625 + priv->lro_mgr.max_aggr = 64;
3626 + priv->lro_mgr.frag_align_pad = 0;
3627 + priv->lro_mgr.lro_arr = priv->lro_arr;
3628 + priv->lro_mgr.get_skb_header = priv->soc->get_skb_header;
3632 + platform_set_drvdata(pdev, netdev);
3634 + netdev_info(netdev, "done loading\n");
3639 +static int fe_remove(struct platform_device *pdev)
3641 + struct net_device *dev = platform_get_drvdata(pdev);
3642 + struct fe_priv *priv = netdev_priv(dev);
3644 + netif_stop_queue(dev);
3645 + netif_napi_del(&priv->rx_napi);
3647 + unregister_netdev(dev);
3653 +static struct platform_driver fe_driver = {
3654 + .probe = fe_probe,
3655 + .remove = fe_remove,
3657 + .name = "ralink_soc_eth",
3658 + .owner = THIS_MODULE,
3659 + .of_match_table = of_fe_match,
3663 +static int __init init_rtfe(void)
3667 + ret = rtesw_init();
3671 + ret = platform_driver_register(&fe_driver);
3678 +static void __exit exit_rtfe(void)
3680 + platform_driver_unregister(&fe_driver);
3684 +module_init(init_rtfe);
3685 +module_exit(exit_rtfe);
3687 +MODULE_LICENSE("GPL");
3688 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
3689 +MODULE_DESCRIPTION("Ethernet driver for Ralink SoC");
3690 Index: linux-3.10.21/drivers/net/ethernet/ralink/ralink_soc_eth.h
3691 ===================================================================
3692 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3693 +++ linux-3.10.21/drivers/net/ethernet/ralink/ralink_soc_eth.h 2013-12-09 13:26:42.332125203 +0100
3696 + * This program is free software; you can redistribute it and/or modify
3697 + * it under the terms of the GNU General Public License as published by
3698 + * the Free Software Foundation; version 2 of the License
3700 + * This program is distributed in the hope that it will be useful,
3701 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3702 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3703 + * GNU General Public License for more details.
3705 + * You should have received a copy of the GNU General Public License
3706 + * along with this program; if not, write to the Free Software
3707 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
3709 + * based on Ralink SDK3.3
3710 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
3716 +#include <linux/mii.h>
3717 +#include <linux/interrupt.h>
3718 +#include <linux/netdevice.h>
3719 +#include <linux/dma-mapping.h>
3720 +#include <linux/phy.h>
3721 +#include <linux/inet_lro.h>
3725 + FE_REG_PDMA_GLO_CFG = 0,
3726 + FE_REG_PDMA_RST_CFG,
3727 + FE_REG_DLY_INT_CFG,
3728 + FE_REG_TX_BASE_PTR0,
3729 + FE_REG_TX_MAX_CNT0,
3730 + FE_REG_TX_CTX_IDX0,
3731 + FE_REG_RX_BASE_PTR0,
3732 + FE_REG_RX_MAX_CNT0,
3733 + FE_REG_RX_CALC_IDX0,
3734 + FE_REG_FE_INT_ENABLE,
3735 + FE_REG_FE_INT_STATUS,
3736 + FE_REG_FE_DMA_VID_BASE,
3740 +#define NUM_DMA_DESC 0x100
3742 +#define FE_DELAY_EN_INT 0x80
3743 +#define FE_DELAY_MAX_INT 0x04
3744 +#define FE_DELAY_MAX_TOUT 0x04
3745 +#define FE_DELAY_CHAN (((FE_DELAY_EN_INT | FE_DELAY_MAX_INT) << 8) | FE_DELAY_MAX_TOUT)
3746 +#define FE_DELAY_INIT ((FE_DELAY_CHAN << 16) | FE_DELAY_CHAN)
3747 +#define FE_PSE_FQFC_CFG_INIT 0x80504000
3749 +/* interrupt bits */
3750 +#define FE_CNT_PPE_AF BIT(31)
3751 +#define FE_CNT_GDM_AF BIT(29)
3752 +#define FE_PSE_P2_FC BIT(26)
3753 +#define FE_PSE_BUF_DROP BIT(24)
3754 +#define FE_GDM_OTHER_DROP BIT(23)
3755 +#define FE_PSE_P1_FC BIT(22)
3756 +#define FE_PSE_P0_FC BIT(21)
3757 +#define FE_PSE_FQ_EMPTY BIT(20)
3758 +#define FE_GE1_STA_CHG BIT(18)
3759 +#define FE_TX_COHERENT BIT(17)
3760 +#define FE_RX_COHERENT BIT(16)
3761 +#define FE_TX_DONE_INT3 BIT(11)
3762 +#define FE_TX_DONE_INT2 BIT(10)
3763 +#define FE_TX_DONE_INT1 BIT(9)
3764 +#define FE_TX_DONE_INT0 BIT(8)
3765 +#define FE_RX_DONE_INT0 BIT(2)
3766 +#define FE_TX_DLY_INT BIT(1)
3767 +#define FE_RX_DLY_INT BIT(0)
3769 +#define RT5350_RX_DLY_INT BIT(30)
3770 +#define RT5350_TX_DLY_INT BIT(28)
3773 +#define FE_FE_OFFSET 0x0000
3774 +#define FE_GDMA_OFFSET 0x0020
3775 +#define FE_PSE_OFFSET 0x0040
3776 +#define FE_GDMA2_OFFSET 0x0060
3777 +#define FE_CDMA_OFFSET 0x0080
3778 +#define FE_DMA_VID0 0x00a8
3779 +#define FE_PDMA_OFFSET 0x0100
3780 +#define FE_PPE_OFFSET 0x0200
3781 +#define FE_CMTABLE_OFFSET 0x0400
3782 +#define FE_POLICYTABLE_OFFSET 0x1000
3784 +#define RT5350_PDMA_OFFSET 0x0800
3785 +#define RT5350_SDM_OFFSET 0x0c00
3787 +#define FE_MDIO_ACCESS (FE_FE_OFFSET + 0x00)
3788 +#define FE_MDIO_CFG (FE_FE_OFFSET + 0x04)
3789 +#define FE_FE_GLO_CFG (FE_FE_OFFSET + 0x08)
3790 +#define FE_FE_RST_GL (FE_FE_OFFSET + 0x0C)
3791 +#define FE_FE_INT_STATUS (FE_FE_OFFSET + 0x10)
3792 +#define FE_FE_INT_ENABLE (FE_FE_OFFSET + 0x14)
3793 +#define FE_MDIO_CFG2 (FE_FE_OFFSET + 0x18)
3794 +#define FE_FOC_TS_T (FE_FE_OFFSET + 0x1C)
3796 +#define FE_GDMA1_FWD_CFG (FE_GDMA_OFFSET + 0x00)
3797 +#define FE_GDMA1_SCH_CFG (FE_GDMA_OFFSET + 0x04)
3798 +#define FE_GDMA1_SHPR_CFG (FE_GDMA_OFFSET + 0x08)
3799 +#define FE_GDMA1_MAC_ADRL (FE_GDMA_OFFSET + 0x0C)
3800 +#define FE_GDMA1_MAC_ADRH (FE_GDMA_OFFSET + 0x10)
3802 +#define FE_GDMA2_FWD_CFG (FE_GDMA2_OFFSET + 0x00)
3803 +#define FE_GDMA2_SCH_CFG (FE_GDMA2_OFFSET + 0x04)
3804 +#define FE_GDMA2_SHPR_CFG (FE_GDMA2_OFFSET + 0x08)
3805 +#define FE_GDMA2_MAC_ADRL (FE_GDMA2_OFFSET + 0x0C)
3806 +#define FE_GDMA2_MAC_ADRH (FE_GDMA2_OFFSET + 0x10)
3808 +#define FE_PSE_FQ_CFG (FE_PSE_OFFSET + 0x00)
3809 +#define FE_CDMA_FC_CFG (FE_PSE_OFFSET + 0x04)
3810 +#define FE_GDMA1_FC_CFG (FE_PSE_OFFSET + 0x08)
3811 +#define FE_GDMA2_FC_CFG (FE_PSE_OFFSET + 0x0C)
3813 +#define FE_CDMA_CSG_CFG (FE_CDMA_OFFSET + 0x00)
3814 +#define FE_CDMA_SCH_CFG (FE_CDMA_OFFSET + 0x04)
3816 +#define MT7620A_GDMA_OFFSET 0x0600
3817 +#define MT7620A_GDMA1_FWD_CFG (MT7620A_GDMA_OFFSET + 0x00)
3818 +#define MT7620A_FE_GDMA1_SCH_CFG (MT7620A_GDMA_OFFSET + 0x04)
3819 +#define MT7620A_FE_GDMA1_SHPR_CFG (MT7620A_GDMA_OFFSET + 0x08)
3820 +#define MT7620A_FE_GDMA1_MAC_ADRL (MT7620A_GDMA_OFFSET + 0x0C)
3821 +#define MT7620A_FE_GDMA1_MAC_ADRH (MT7620A_GDMA_OFFSET + 0x10)
3823 +#define RT5350_TX_BASE_PTR0 (RT5350_PDMA_OFFSET + 0x00)
3824 +#define RT5350_TX_MAX_CNT0 (RT5350_PDMA_OFFSET + 0x04)
3825 +#define RT5350_TX_CTX_IDX0 (RT5350_PDMA_OFFSET + 0x08)
3826 +#define RT5350_TX_DTX_IDX0 (RT5350_PDMA_OFFSET + 0x0C)
3827 +#define RT5350_TX_BASE_PTR1 (RT5350_PDMA_OFFSET + 0x10)
3828 +#define RT5350_TX_MAX_CNT1 (RT5350_PDMA_OFFSET + 0x14)
3829 +#define RT5350_TX_CTX_IDX1 (RT5350_PDMA_OFFSET + 0x18)
3830 +#define RT5350_TX_DTX_IDX1 (RT5350_PDMA_OFFSET + 0x1C)
3831 +#define RT5350_TX_BASE_PTR2 (RT5350_PDMA_OFFSET + 0x20)
3832 +#define RT5350_TX_MAX_CNT2 (RT5350_PDMA_OFFSET + 0x24)
3833 +#define RT5350_TX_CTX_IDX2 (RT5350_PDMA_OFFSET + 0x28)
3834 +#define RT5350_TX_DTX_IDX2 (RT5350_PDMA_OFFSET + 0x2C)
3835 +#define RT5350_TX_BASE_PTR3 (RT5350_PDMA_OFFSET + 0x30)
3836 +#define RT5350_TX_MAX_CNT3 (RT5350_PDMA_OFFSET + 0x34)
3837 +#define RT5350_TX_CTX_IDX3 (RT5350_PDMA_OFFSET + 0x38)
3838 +#define RT5350_TX_DTX_IDX3 (RT5350_PDMA_OFFSET + 0x3C)
3839 +#define RT5350_RX_BASE_PTR0 (RT5350_PDMA_OFFSET + 0x100)
3840 +#define RT5350_RX_MAX_CNT0 (RT5350_PDMA_OFFSET + 0x104)
3841 +#define RT5350_RX_CALC_IDX0 (RT5350_PDMA_OFFSET + 0x108)
3842 +#define RT5350_RX_DRX_IDX0 (RT5350_PDMA_OFFSET + 0x10C)
3843 +#define RT5350_RX_BASE_PTR1 (RT5350_PDMA_OFFSET + 0x110)
3844 +#define RT5350_RX_MAX_CNT1 (RT5350_PDMA_OFFSET + 0x114)
3845 +#define RT5350_RX_CALC_IDX1 (RT5350_PDMA_OFFSET + 0x118)
3846 +#define RT5350_RX_DRX_IDX1 (RT5350_PDMA_OFFSET + 0x11C)
3847 +#define RT5350_PDMA_GLO_CFG (RT5350_PDMA_OFFSET + 0x204)
3848 +#define RT5350_PDMA_RST_CFG (RT5350_PDMA_OFFSET + 0x208)
3849 +#define RT5350_DLY_INT_CFG (RT5350_PDMA_OFFSET + 0x20c)
3850 +#define RT5350_FE_INT_STATUS (RT5350_PDMA_OFFSET + 0x220)
3851 +#define RT5350_FE_INT_ENABLE (RT5350_PDMA_OFFSET + 0x228)
3852 +#define RT5350_PDMA_SCH_CFG (RT5350_PDMA_OFFSET + 0x280)
3854 +#define FE_PDMA_GLO_CFG (FE_PDMA_OFFSET + 0x00)
3855 +#define FE_PDMA_RST_CFG (FE_PDMA_OFFSET + 0x04)
3856 +#define FE_PDMA_SCH_CFG (FE_PDMA_OFFSET + 0x08)
3857 +#define FE_DLY_INT_CFG (FE_PDMA_OFFSET + 0x0C)
3858 +#define FE_TX_BASE_PTR0 (FE_PDMA_OFFSET + 0x10)
3859 +#define FE_TX_MAX_CNT0 (FE_PDMA_OFFSET + 0x14)
3860 +#define FE_TX_CTX_IDX0 (FE_PDMA_OFFSET + 0x18)
3861 +#define FE_TX_DTX_IDX0 (FE_PDMA_OFFSET + 0x1C)
3862 +#define FE_TX_BASE_PTR1 (FE_PDMA_OFFSET + 0x20)
3863 +#define FE_TX_MAX_CNT1 (FE_PDMA_OFFSET + 0x24)
3864 +#define FE_TX_CTX_IDX1 (FE_PDMA_OFFSET + 0x28)
3865 +#define FE_TX_DTX_IDX1 (FE_PDMA_OFFSET + 0x2C)
3866 +#define FE_RX_BASE_PTR0 (FE_PDMA_OFFSET + 0x30)
3867 +#define FE_RX_MAX_CNT0 (FE_PDMA_OFFSET + 0x34)
3868 +#define FE_RX_CALC_IDX0 (FE_PDMA_OFFSET + 0x38)
3869 +#define FE_RX_DRX_IDX0 (FE_PDMA_OFFSET + 0x3C)
3870 +#define FE_TX_BASE_PTR2 (FE_PDMA_OFFSET + 0x40)
3871 +#define FE_TX_MAX_CNT2 (FE_PDMA_OFFSET + 0x44)
3872 +#define FE_TX_CTX_IDX2 (FE_PDMA_OFFSET + 0x48)
3873 +#define FE_TX_DTX_IDX2 (FE_PDMA_OFFSET + 0x4C)
3874 +#define FE_TX_BASE_PTR3 (FE_PDMA_OFFSET + 0x50)
3875 +#define FE_TX_MAX_CNT3 (FE_PDMA_OFFSET + 0x54)
3876 +#define FE_TX_CTX_IDX3 (FE_PDMA_OFFSET + 0x58)
3877 +#define FE_TX_DTX_IDX3 (FE_PDMA_OFFSET + 0x5C)
3878 +#define FE_RX_BASE_PTR1 (FE_PDMA_OFFSET + 0x60)
3879 +#define FE_RX_MAX_CNT1 (FE_PDMA_OFFSET + 0x64)
3880 +#define FE_RX_CALC_IDX1 (FE_PDMA_OFFSET + 0x68)
3881 +#define FE_RX_DRX_IDX1 (FE_PDMA_OFFSET + 0x6C)
3883 +#define RT5350_SDM_CFG (RT5350_SDM_OFFSET + 0x00) //Switch DMA configuration
3884 +#define RT5350_SDM_RRING (RT5350_SDM_OFFSET + 0x04) //Switch DMA Rx Ring
3885 +#define RT5350_SDM_TRING (RT5350_SDM_OFFSET + 0x08) //Switch DMA Tx Ring
3886 +#define RT5350_SDM_MAC_ADRL (RT5350_SDM_OFFSET + 0x0C) //Switch MAC address LSB
3887 +#define RT5350_SDM_MAC_ADRH (RT5350_SDM_OFFSET + 0x10) //Switch MAC Address MSB
3888 +#define RT5350_SDM_TPCNT (RT5350_SDM_OFFSET + 0x100) //Switch DMA Tx packet count
3889 +#define RT5350_SDM_TBCNT (RT5350_SDM_OFFSET + 0x104) //Switch DMA Tx byte count
3890 +#define RT5350_SDM_RPCNT (RT5350_SDM_OFFSET + 0x108) //Switch DMA rx packet count
3891 +#define RT5350_SDM_RBCNT (RT5350_SDM_OFFSET + 0x10C) //Switch DMA rx byte count
3892 +#define RT5350_SDM_CS_ERR (RT5350_SDM_OFFSET + 0x110) //Switch DMA rx checksum error count
3894 +#define RT5350_SDM_ICS_EN BIT(16)
3895 +#define RT5350_SDM_TCS_EN BIT(17)
3896 +#define RT5350_SDM_UCS_EN BIT(18)
3899 +/* MDIO_CFG register bits */
3900 +#define FE_MDIO_CFG_AUTO_POLL_EN BIT(29)
3901 +#define FE_MDIO_CFG_GP1_BP_EN BIT(16)
3902 +#define FE_MDIO_CFG_GP1_FRC_EN BIT(15)
3903 +#define FE_MDIO_CFG_GP1_SPEED_10 (0 << 13)
3904 +#define FE_MDIO_CFG_GP1_SPEED_100 (1 << 13)
3905 +#define FE_MDIO_CFG_GP1_SPEED_1000 (2 << 13)
3906 +#define FE_MDIO_CFG_GP1_DUPLEX BIT(12)
3907 +#define FE_MDIO_CFG_GP1_FC_TX BIT(11)
3908 +#define FE_MDIO_CFG_GP1_FC_RX BIT(10)
3909 +#define FE_MDIO_CFG_GP1_LNK_DWN BIT(9)
3910 +#define FE_MDIO_CFG_GP1_AN_FAIL BIT(8)
3911 +#define FE_MDIO_CFG_MDC_CLK_DIV_1 (0 << 6)
3912 +#define FE_MDIO_CFG_MDC_CLK_DIV_2 (1 << 6)
3913 +#define FE_MDIO_CFG_MDC_CLK_DIV_4 (2 << 6)
3914 +#define FE_MDIO_CFG_MDC_CLK_DIV_8 (3 << 6)
3915 +#define FE_MDIO_CFG_TURBO_MII_FREQ BIT(5)
3916 +#define FE_MDIO_CFG_TURBO_MII_MODE BIT(4)
3917 +#define FE_MDIO_CFG_RX_CLK_SKEW_0 (0 << 2)
3918 +#define FE_MDIO_CFG_RX_CLK_SKEW_200 (1 << 2)
3919 +#define FE_MDIO_CFG_RX_CLK_SKEW_400 (2 << 2)
3920 +#define FE_MDIO_CFG_RX_CLK_SKEW_INV (3 << 2)
3921 +#define FE_MDIO_CFG_TX_CLK_SKEW_0 0
3922 +#define FE_MDIO_CFG_TX_CLK_SKEW_200 1
3923 +#define FE_MDIO_CFG_TX_CLK_SKEW_400 2
3924 +#define FE_MDIO_CFG_TX_CLK_SKEW_INV 3
3926 +/* uni-cast port */
3927 +#define FE_GDM1_ICS_EN BIT(22)
3928 +#define FE_GDM1_TCS_EN BIT(21)
3929 +#define FE_GDM1_UCS_EN BIT(20)
3930 +#define FE_GDM1_JMB_EN BIT(19)
3931 +#define FE_GDM1_STRPCRC BIT(16)
3932 +#define FE_GDM1_UFRC_P_CPU (0 << 12)
3933 +#define FE_GDM1_UFRC_P_GDMA1 (1 << 12)
3934 +#define FE_GDM1_UFRC_P_PPE (6 << 12)
3937 +#define FE_ICS_GEN_EN BIT(2)
3938 +#define FE_UCS_GEN_EN BIT(1)
3939 +#define FE_TCS_GEN_EN BIT(0)
3942 +#define FE_PST_DRX_IDX0 BIT(16)
3943 +#define FE_PST_DTX_IDX3 BIT(3)
3944 +#define FE_PST_DTX_IDX2 BIT(2)
3945 +#define FE_PST_DTX_IDX1 BIT(1)
3946 +#define FE_PST_DTX_IDX0 BIT(0)
3948 +#define FE_TX_WB_DDONE BIT(6)
3949 +#define FE_RX_DMA_BUSY BIT(3)
3950 +#define FE_TX_DMA_BUSY BIT(1)
3951 +#define FE_RX_DMA_EN BIT(2)
3952 +#define FE_TX_DMA_EN BIT(0)
3954 +#define FE_PDMA_SIZE_4DWORDS (0 << 4)
3955 +#define FE_PDMA_SIZE_8DWORDS (1 << 4)
3956 +#define FE_PDMA_SIZE_16DWORDS (2 << 4)
3958 +#define FE_US_CYC_CNT_MASK 0xff
3959 +#define FE_US_CYC_CNT_SHIFT 0x8
3960 +#define FE_US_CYC_CNT_DIVISOR 1000000
3962 +#define RX_DMA_PLEN0(_x) (((_x) >> 16) & 0x3fff)
3963 +#define RX_DMA_LSO BIT(30)
3964 +#define RX_DMA_DONE BIT(31)
3965 +#define RX_DMA_L4VALID BIT(30)
3968 + unsigned int rxd1;
3969 + unsigned int rxd2;
3970 + unsigned int rxd3;
3971 + unsigned int rxd4;
3972 +} __packed __aligned(4);
3974 +#define TX_DMA_PLEN0_MASK ((0x3fff) << 16)
3975 +#define TX_DMA_PLEN0(_x) (((_x) & 0x3fff) << 16)
3976 +#define TX_DMA_PLEN1(_x) ((_x) & 0x3fff)
3977 +#define TX_DMA_LS1 BIT(14)
3978 +#define TX_DMA_LSO BIT(30)
3979 +#define TX_DMA_DONE BIT(31)
3980 +#define TX_DMA_QN(_x) ((_x) << 16)
3981 +#define TX_DMA_PN(_x) ((_x) << 24)
3982 +#define TX_DMA_QN_MASK TX_DMA_QN(0x7)
3983 +#define TX_DMA_PN_MASK TX_DMA_PN(0x7)
3984 +#define TX_DMA_CHKSUM (0x7 << 29)
3987 + unsigned int txd1;
3988 + unsigned int txd2;
3989 + unsigned int txd3;
3990 + unsigned int txd4;
3991 +} __packed __aligned(4);
3996 + struct phy_device *phy[8];
3997 + struct device_node *phy_node[8];
3998 + const __be32 *phy_fixed[8];
4005 + int (*connect)(struct fe_priv *priv);
4006 + void (*disconnect)(struct fe_priv *priv);
4007 + void (*start)(struct fe_priv *priv);
4008 + void (*stop)(struct fe_priv *priv);
4013 + unsigned char mac[6];
4014 + const u32 *reg_table;
4016 + void (*init_data)(struct fe_soc_data *data);
4017 + void (*reset_fe)(void);
4018 + void (*set_mac)(struct fe_priv *priv, unsigned char *mac);
4019 + void (*fwd_config)(struct fe_priv *priv);
4020 + void (*tx_dma)(struct fe_priv *priv, int idx, struct sk_buff *skb);
4021 + void (*rx_dma)(struct fe_priv *priv, int idx, int len);
4022 + int (*switch_init)(struct fe_priv *priv);
4023 + int (*switch_config)(struct fe_priv *priv);
4024 + void (*port_init)(struct fe_priv *priv, struct device_node *port);
4025 + int (*has_carrier)(struct fe_priv *priv);
4026 + int (*mdio_init)(struct fe_priv *priv);
4027 + void (*mdio_cleanup)(struct fe_priv *priv);
4028 + int (*mdio_write)(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val);
4029 + int (*mdio_read)(struct mii_bus *bus, int phy_addr, int phy_reg);
4030 + void (*mdio_adjust_link)(struct fe_priv *priv, int port);
4031 + int (*get_skb_header)(struct sk_buff *skb, void **iphdr, void **tcph, u64 *hdr_flags, void *priv);
4045 + spinlock_t page_lock;
4047 + struct fe_soc_data *soc;
4048 + struct net_device *netdev;
4049 + struct device *device;
4050 + unsigned long sysclk;
4052 + struct fe_rx_dma *rx_dma;
4053 + struct napi_struct rx_napi;
4054 + struct sk_buff *rx_skb[NUM_DMA_DESC];
4055 + dma_addr_t rx_phys;
4057 + struct fe_tx_dma *tx_dma;
4058 + struct tasklet_struct tx_tasklet;
4059 + struct sk_buff *tx_skb[NUM_DMA_DESC];
4060 + dma_addr_t tx_phys;
4061 + unsigned int tx_free_idx;
4063 + struct fe_phy *phy;
4064 + struct mii_bus *mii_bus;
4065 + int mii_irq[PHY_MAX_ADDR];
4069 + struct net_lro_mgr lro_mgr;
4070 + struct net_lro_desc lro_arr[8];
4073 +extern const struct of_device_id of_fe_match[];
4075 +void fe_w32(u32 val, unsigned reg);
4076 +u32 fe_r32(unsigned reg);
4078 +#endif /* FE_ETH_H */
4079 Index: linux-3.10.21/drivers/net/ethernet/ralink/soc_mt7620.c
4080 ===================================================================
4081 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4082 +++ linux-3.10.21/drivers/net/ethernet/ralink/soc_mt7620.c 2013-12-09 13:26:42.332125203 +0100
4085 + * This program is free software; you can redistribute it and/or modify
4086 + * it under the terms of the GNU General Public License as published by
4087 + * the Free Software Foundation; version 2 of the License
4089 + * This program is distributed in the hope that it will be useful,
4090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4092 + * GNU General Public License for more details.
4094 + * You should have received a copy of the GNU General Public License
4095 + * along with this program; if not, write to the Free Software
4096 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4098 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4101 +#include <linux/module.h>
4102 +#include <linux/platform_device.h>
4103 +#include <linux/if_vlan.h>
4105 +#include <asm/mach-ralink/ralink_regs.h>
4107 +#include <mt7620.h>
4108 +#include "ralink_soc_eth.h"
4109 +#include "gsw_mt7620a.h"
4111 +#define MT7620A_CDMA_CSG_CFG 0x400
4112 +#define MT7620_DMA_VID (MT7620A_CDMA_CSG_CFG | 0x30)
4113 +#define MT7620A_DMA_2B_OFFSET BIT(31)
4114 +#define MT7620A_RESET_FE BIT(21)
4115 +#define MT7620A_RESET_ESW BIT(23)
4116 +#define MT7620_L4_VALID BIT(23)
4118 +#define SYSC_REG_RESET_CTRL 0x34
4119 +#define MAX_RX_LENGTH 1536
4121 +#define CDMA_ICS_EN BIT(2)
4122 +#define CDMA_UCS_EN BIT(1)
4123 +#define CDMA_TCS_EN BIT(0)
4125 +#define GDMA_ICS_EN BIT(22)
4126 +#define GDMA_TCS_EN BIT(21)
4127 +#define GDMA_UCS_EN BIT(20)
4129 +static const u32 rt5350_reg_table[FE_REG_COUNT] = {
4130 + [FE_REG_PDMA_GLO_CFG] = RT5350_PDMA_GLO_CFG,
4131 + [FE_REG_PDMA_RST_CFG] = RT5350_PDMA_RST_CFG,
4132 + [FE_REG_DLY_INT_CFG] = RT5350_DLY_INT_CFG,
4133 + [FE_REG_TX_BASE_PTR0] = RT5350_TX_BASE_PTR0,
4134 + [FE_REG_TX_MAX_CNT0] = RT5350_TX_MAX_CNT0,
4135 + [FE_REG_TX_CTX_IDX0] = RT5350_TX_CTX_IDX0,
4136 + [FE_REG_RX_BASE_PTR0] = RT5350_RX_BASE_PTR0,
4137 + [FE_REG_RX_MAX_CNT0] = RT5350_RX_MAX_CNT0,
4138 + [FE_REG_RX_CALC_IDX0] = RT5350_RX_CALC_IDX0,
4139 + [FE_REG_FE_INT_ENABLE] = RT5350_FE_INT_ENABLE,
4140 + [FE_REG_FE_INT_STATUS] = RT5350_FE_INT_STATUS,
4141 + [FE_REG_FE_DMA_VID_BASE] = MT7620_DMA_VID,
4144 +static void mt7620_fe_reset(void)
4146 + rt_sysc_w32(MT7620A_RESET_FE | MT7620A_RESET_ESW, SYSC_REG_RESET_CTRL);
4147 + rt_sysc_w32(0, SYSC_REG_RESET_CTRL);
4150 +static void mt7620_fwd_config(struct fe_priv *priv)
4154 + /* frame engine will push VLAN tag regarding to VIDX feild in Tx desc. */
4155 + for (i = 0; i < 16; i += 2)
4156 + fe_w32(((i + 1) << 16) + i, MT7620_DMA_VID + (i * 2));
4158 + fe_w32(fe_r32(MT7620A_GDMA1_FWD_CFG) & ~7, MT7620A_GDMA1_FWD_CFG);
4159 + fe_w32(fe_r32(MT7620A_GDMA1_FWD_CFG) | (GDMA_ICS_EN | GDMA_TCS_EN | GDMA_UCS_EN), MT7620A_GDMA1_FWD_CFG);
4160 + fe_w32(fe_r32(MT7620A_CDMA_CSG_CFG) | (CDMA_ICS_EN | CDMA_UCS_EN | CDMA_TCS_EN), MT7620A_CDMA_CSG_CFG);
4163 +static void mt7620_tx_dma(struct fe_priv *priv, int idx, struct sk_buff *skb)
4165 + unsigned int nr_frags = 0;
4166 + unsigned int len = 0;
4169 + nr_frags = skb_shinfo(skb)->nr_frags;
4170 + len = skb->len - skb->data_len;
4174 + priv->tx_dma[idx].txd2 = TX_DMA_LSO | TX_DMA_DONE;
4175 + else if (!nr_frags)
4176 + priv->tx_dma[idx].txd2 = TX_DMA_LSO | TX_DMA_PLEN0(len);
4178 + priv->tx_dma[idx].txd2 = TX_DMA_PLEN0(len);
4180 + if(skb && vlan_tx_tag_present(skb))
4181 + priv->tx_dma[idx].txd4 = 0x80 | (vlan_tx_tag_get(skb) >> 13) << 4 | (vlan_tx_tag_get(skb) & 0xF);
4183 + priv->tx_dma[idx].txd4 = 0;
4186 +static void mt7620_rx_dma(struct fe_priv *priv, int idx, int len)
4188 + priv->rx_dma[idx].rxd2 = RX_DMA_PLEN0(len);
4191 +#ifdef CONFIG_INET_LRO
4193 +mt7620_get_skb_header(struct sk_buff *skb, void **iphdr, void **tcph,
4194 + u64 *hdr_flags, void *_priv)
4196 + struct iphdr *iph = NULL;
4200 + * Make sure that this packet is Ethernet II, is not VLAN
4201 + * tagged, is IPv4, has a valid IP header, and is TCP.
4203 + if (skb->protocol == 0x0081)
4204 + vhdr_len = VLAN_HLEN;
4206 + iph = (struct iphdr *)(skb->data + vhdr_len);
4207 + if(iph->protocol != IPPROTO_TCP)
4211 + *tcph = skb->data + (iph->ihl << 2) + vhdr_len;
4212 + *hdr_flags = LRO_IPV4 | LRO_TCP;
4218 +static void mt7620_init_data(struct fe_soc_data *data)
4220 + if (mt7620_get_eco() >= 5)
4224 +static struct fe_soc_data mt7620_data = {
4225 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
4226 + .init_data = mt7620_init_data,
4227 + .reset_fe = mt7620_fe_reset,
4228 + .set_mac = mt7620_set_mac,
4229 + .fwd_config = mt7620_fwd_config,
4230 + .tx_dma = mt7620_tx_dma,
4231 + .rx_dma = mt7620_rx_dma,
4232 + .switch_init = mt7620_gsw_probe,
4233 + .switch_config = mt7620_gsw_config,
4234 + .port_init = mt7620_port_init,
4236 + .reg_table = rt5350_reg_table,
4237 + .pdma_glo_cfg = FE_PDMA_SIZE_16DWORDS | MT7620A_DMA_2B_OFFSET,
4238 + .rx_dly_int = RT5350_RX_DLY_INT,
4239 + .tx_dly_int = RT5350_TX_DLY_INT,
4240 + .checksum_bit = MT7620_L4_VALID,
4241 + .has_carrier = mt7620a_has_carrier,
4242 + .mdio_read = mt7620_mdio_read,
4243 + .mdio_write = mt7620_mdio_write,
4244 + .mdio_adjust_link = mt7620_mdio_link_adjust,
4245 +#ifdef CONFIG_INET_LRO
4246 + .get_skb_header = mt7620_get_skb_header,
4250 +const struct of_device_id of_fe_match[] = {
4251 + { .compatible = "ralink,mt7620a-eth", .data = &mt7620_data },
4255 +MODULE_DEVICE_TABLE(of, of_fe_match);
4256 Index: linux-3.10.21/drivers/net/ethernet/ralink/soc_rt2880.c
4257 ===================================================================
4258 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4259 +++ linux-3.10.21/drivers/net/ethernet/ralink/soc_rt2880.c 2013-12-09 13:26:42.332125203 +0100
4262 + * This program is free software; you can redistribute it and/or modify
4263 + * it under the terms of the GNU General Public License as published by
4264 + * the Free Software Foundation; version 2 of the License
4266 + * This program is distributed in the hope that it will be useful,
4267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4269 + * GNU General Public License for more details.
4271 + * You should have received a copy of the GNU General Public License
4272 + * along with this program; if not, write to the Free Software
4273 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4275 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4278 +#include <linux/module.h>
4280 +#include <asm/mach-ralink/ralink_regs.h>
4282 +#include "ralink_soc_eth.h"
4283 +#include "mdio_rt2880.h"
4285 +#define SYSC_REG_RESET_CTRL 0x034
4286 +#define RT2880_RESET_FE BIT(18)
4288 +void rt2880_fe_reset(void)
4290 + rt_sysc_w32(RT2880_RESET_FE, SYSC_REG_RESET_CTRL);
4293 +struct fe_soc_data rt2880_data = {
4294 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
4295 + .reset_fe = rt2880_fe_reset,
4296 + .min_pkt_len = 64,
4297 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
4298 + .checksum_bit = RX_DMA_L4VALID,
4299 + .rx_dly_int = FE_RX_DLY_INT,
4300 + .tx_dly_int = FE_TX_DLY_INT,
4301 + .mdio_read = rt2880_mdio_read,
4302 + .mdio_write = rt2880_mdio_write,
4303 + .mdio_adjust_link = rt2880_mdio_link_adjust,
4306 +const struct of_device_id of_fe_match[] = {
4307 + { .compatible = "ralink,rt2880-eth", .data = &rt2880_data },
4311 +MODULE_DEVICE_TABLE(of, of_fe_match);
4312 Index: linux-3.10.21/drivers/net/ethernet/ralink/soc_rt305x.c
4313 ===================================================================
4314 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4315 +++ linux-3.10.21/drivers/net/ethernet/ralink/soc_rt305x.c 2013-12-09 13:26:42.332125203 +0100
4318 + * This program is free software; you can redistribute it and/or modify
4319 + * it under the terms of the GNU General Public License as published by
4320 + * the Free Software Foundation; version 2 of the License
4322 + * This program is distributed in the hope that it will be useful,
4323 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4324 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4325 + * GNU General Public License for more details.
4327 + * You should have received a copy of the GNU General Public License
4328 + * along with this program; if not, write to the Free Software
4329 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4331 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4334 +#include <linux/module.h>
4336 +#include <asm/mach-ralink/ralink_regs.h>
4338 +#include "ralink_soc_eth.h"
4340 +#define RT305X_RESET_FE BIT(21)
4341 +#define RT305X_RESET_ESW BIT(23)
4342 +#define SYSC_REG_RESET_CTRL 0x034
4344 +static const u32 rt5350_reg_table[FE_REG_COUNT] = {
4345 + [FE_REG_PDMA_GLO_CFG] = RT5350_PDMA_GLO_CFG,
4346 + [FE_REG_PDMA_RST_CFG] = RT5350_PDMA_RST_CFG,
4347 + [FE_REG_DLY_INT_CFG] = RT5350_DLY_INT_CFG,
4348 + [FE_REG_TX_BASE_PTR0] = RT5350_TX_BASE_PTR0,
4349 + [FE_REG_TX_MAX_CNT0] = RT5350_TX_MAX_CNT0,
4350 + [FE_REG_TX_CTX_IDX0] = RT5350_TX_CTX_IDX0,
4351 + [FE_REG_RX_BASE_PTR0] = RT5350_RX_BASE_PTR0,
4352 + [FE_REG_RX_MAX_CNT0] = RT5350_RX_MAX_CNT0,
4353 + [FE_REG_RX_CALC_IDX0] = RT5350_RX_CALC_IDX0,
4354 + [FE_REG_FE_INT_ENABLE] = RT5350_FE_INT_ENABLE,
4355 + [FE_REG_FE_INT_STATUS] = RT5350_FE_INT_STATUS,
4356 + [FE_REG_FE_DMA_VID_BASE] = 0,
4359 +static void rt305x_fe_reset(void)
4361 + rt_sysc_w32(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
4362 + rt_sysc_w32(0, SYSC_REG_RESET_CTRL);
4365 +static void rt5350_set_mac(struct fe_priv *priv, unsigned char *mac)
4367 + unsigned long flags;
4369 + spin_lock_irqsave(&priv->page_lock, flags);
4370 + fe_w32((mac[0] << 8) | mac[1], RT5350_SDM_MAC_ADRH);
4371 + fe_w32((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
4372 + RT5350_SDM_MAC_ADRL);
4373 + spin_unlock_irqrestore(&priv->page_lock, flags);
4376 +static void rt5350_fwd_config(struct fe_priv *priv)
4378 + unsigned long sysclk = priv->sysclk;
4381 + sysclk /= FE_US_CYC_CNT_DIVISOR;
4382 + sysclk <<= FE_US_CYC_CNT_SHIFT;
4384 + fe_w32((fe_r32(FE_FE_GLO_CFG) &
4385 + ~(FE_US_CYC_CNT_MASK << FE_US_CYC_CNT_SHIFT)) | sysclk,
4389 + fe_w32(fe_r32(RT5350_SDM_CFG) & ~0xffff, RT5350_SDM_CFG);
4390 + fe_w32(fe_r32(RT5350_SDM_CFG) | RT5350_SDM_ICS_EN | RT5350_SDM_TCS_EN | RT5350_SDM_UCS_EN,
4394 +static void rt5350_fe_reset(void)
4396 + rt_sysc_w32(RT305X_RESET_FE | RT305X_RESET_ESW, SYSC_REG_RESET_CTRL);
4397 + rt_sysc_w32(0, SYSC_REG_RESET_CTRL);
4400 +static struct fe_soc_data rt3050_data = {
4401 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
4402 + .reset_fe = rt305x_fe_reset,
4403 + .min_pkt_len = 64,
4404 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
4405 + .checksum_bit = RX_DMA_L4VALID,
4406 + .rx_dly_int = FE_RX_DLY_INT,
4407 + .tx_dly_int = FE_TX_DLY_INT,
4410 +static struct fe_soc_data rt5350_data = {
4411 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
4412 + .reg_table = rt5350_reg_table,
4413 + .reset_fe = rt5350_fe_reset,
4414 + .set_mac = rt5350_set_mac,
4415 + .fwd_config = rt5350_fwd_config,
4416 + .min_pkt_len = 64,
4417 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
4418 + .checksum_bit = RX_DMA_L4VALID,
4419 + .rx_dly_int = RT5350_RX_DLY_INT,
4420 + .tx_dly_int = RT5350_TX_DLY_INT,
4423 +const struct of_device_id of_fe_match[] = {
4424 + { .compatible = "ralink,rt3050-eth", .data = &rt3050_data },
4425 + { .compatible = "ralink,rt5350-eth", .data = &rt5350_data },
4429 +MODULE_DEVICE_TABLE(of, of_fe_match);
4430 Index: linux-3.10.21/drivers/net/ethernet/ralink/soc_rt3883.c
4431 ===================================================================
4432 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4433 +++ linux-3.10.21/drivers/net/ethernet/ralink/soc_rt3883.c 2013-12-09 13:26:42.332125203 +0100
4436 + * This program is free software; you can redistribute it and/or modify
4437 + * it under the terms of the GNU General Public License as published by
4438 + * the Free Software Foundation; version 2 of the License
4440 + * This program is distributed in the hope that it will be useful,
4441 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4442 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4443 + * GNU General Public License for more details.
4445 + * You should have received a copy of the GNU General Public License
4446 + * along with this program; if not, write to the Free Software
4447 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4449 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4452 +#include <linux/module.h>
4454 +#include <asm/mach-ralink/ralink_regs.h>
4456 +#include "ralink_soc_eth.h"
4457 +#include "mdio_rt2880.h"
4459 +#define RT3883_SYSC_REG_RSTCTRL 0x34
4460 +#define RT3883_RSTCTRL_FE BIT(21)
4462 +static void rt3883_fe_reset(void)
4466 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
4467 + t |= RT3883_RSTCTRL_FE;
4468 + rt_sysc_w32(t , RT3883_SYSC_REG_RSTCTRL);
4470 + t &= ~RT3883_RSTCTRL_FE;
4471 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
4474 +static struct fe_soc_data rt3883_data = {
4475 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
4476 + .reset_fe = rt3883_fe_reset,
4477 + .min_pkt_len = 64,
4478 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
4479 + .rx_dly_int = FE_RX_DLY_INT,
4480 + .tx_dly_int = FE_TX_DLY_INT,
4481 + .checksum_bit = RX_DMA_L4VALID,
4482 + .mdio_read = rt2880_mdio_read,
4483 + .mdio_write = rt2880_mdio_write,
4484 + .mdio_adjust_link = rt2880_mdio_link_adjust,
4485 + .port_init = rt2880_port_init,
4488 +const struct of_device_id of_fe_match[] = {
4489 + { .compatible = "ralink,rt3883-eth", .data = &rt3883_data },
4493 +MODULE_DEVICE_TABLE(of, of_fe_match);
4495 Index: linux-3.10.21/drivers/net/ethernet/ralink/mt7530.c
4496 ===================================================================
4497 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4498 +++ linux-3.10.21/drivers/net/ethernet/ralink/mt7530.c 2013-12-09 13:26:42.336125203 +0100
4501 + * This program is free software; you can redistribute it and/or
4502 + * modify it under the terms of the GNU General Public License
4503 + * as published by the Free Software Foundation; either version 2
4504 + * of the License, or (at your option) any later version.
4506 + * This program is distributed in the hope that it will be useful,
4507 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4508 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4509 + * GNU General Public License for more details.
4511 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
4514 +#include <linux/if.h>
4515 +#include <linux/module.h>
4516 +#include <linux/init.h>
4517 +#include <linux/list.h>
4518 +#include <linux/if_ether.h>
4519 +#include <linux/skbuff.h>
4520 +#include <linux/netdevice.h>
4521 +#include <linux/netlink.h>
4522 +#include <linux/bitops.h>
4523 +#include <net/genetlink.h>
4524 +#include <linux/switch.h>
4525 +#include <linux/delay.h>
4526 +#include <linux/phy.h>
4527 +#include <linux/netdevice.h>
4528 +#include <linux/etherdevice.h>
4529 +#include <linux/lockdep.h>
4530 +#include <linux/workqueue.h>
4531 +#include <linux/of_device.h>
4533 +#include "mt7530.h"
4535 +#define MT7530_CPU_PORT 6
4536 +#define MT7530_NUM_PORTS 7
4537 +#define MT7530_NUM_VLANS 16
4538 +#define MT7530_NUM_VIDS 16
4540 +#define REG_ESW_VLAN_VTCR 0x90
4541 +#define REG_ESW_VLAN_VAWD1 0x94
4542 +#define REG_ESW_VLAN_VAWD2 0x98
4545 + /* Global attributes. */
4546 + MT7530_ATTR_ENABLE_VLAN,
4549 +struct mt7530_port {
4553 +struct mt7530_vlan {
4557 +struct mt7530_priv {
4558 + void __iomem *base;
4559 + struct mii_bus *bus;
4560 + struct switch_dev swdev;
4562 + bool global_vlan_enable;
4563 + struct mt7530_vlan vlans[MT7530_NUM_VLANS];
4564 + struct mt7530_port ports[MT7530_NUM_PORTS];
4567 +struct mt7530_mapping {
4571 +} mt7530_defaults[] = {
4574 + .pvids = { 1, 1, 1, 1, 2, 1 },
4575 + .vlans = { 0, 0x6f, 0x50 },
4578 + .pvids = { 2, 1, 1, 1, 1, 1 },
4579 + .vlans = { 0, 0x7e, 0x41 },
4583 +struct mt7530_mapping*
4584 +mt7530_find_mapping(struct device_node *np)
4589 + if (of_property_read_string(np, "ralink,port-map", &map))
4592 + for (i = 0; i < ARRAY_SIZE(mt7530_defaults); i++)
4593 + if (!strcmp(map, mt7530_defaults[i].name))
4594 + return &mt7530_defaults[i];
4600 +mt7530_apply_mapping(struct mt7530_priv *mt7530, struct mt7530_mapping *map)
4604 + mt7530->global_vlan_enable = 1;
4606 + for (i = 0; i < 6; i++)
4607 + mt7530->ports[i].pvid = map->pvids[i];
4608 + for (i = 0; i < 8; i++)
4609 + mt7530->vlans[i].ports = map->vlans[i];
4613 +mt7530_reset_switch(struct switch_dev *dev)
4615 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4617 + memset(priv->ports, 0, sizeof(priv->ports));
4618 + memset(priv->vlans, 0, sizeof(priv->vlans));
4624 +mt7530_get_vlan_enable(struct switch_dev *dev,
4625 + const struct switch_attr *attr,
4626 + struct switch_val *val)
4628 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4630 + val->value.i = priv->global_vlan_enable;
4636 +mt7530_set_vlan_enable(struct switch_dev *dev,
4637 + const struct switch_attr *attr,
4638 + struct switch_val *val)
4640 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4642 + priv->global_vlan_enable = val->value.i != 0;
4648 +mt7530_r32(struct mt7530_priv *priv, u32 reg)
4653 + mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
4654 + low = mdiobus_read(priv->bus, 0x1f, (reg >> 2) & 0xf);
4655 + high = mdiobus_read(priv->bus, 0x1f, 0x10);
4657 + return (high << 16) | (low & 0xffff);
4660 + return ioread32(priv->base + reg);
4664 +mt7530_w32(struct mt7530_priv *priv, u32 reg, u32 val)
4667 + mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
4668 + mdiobus_write(priv->bus, 0x1f, (reg >> 2) & 0xf, val & 0xffff);
4669 + mdiobus_write(priv->bus, 0x1f, 0x10, val >> 16);
4673 + iowrite32(val, priv->base + reg);
4677 +mt7530_vtcr(struct mt7530_priv *priv, u32 cmd, u32 val)
4681 + mt7530_w32(priv, REG_ESW_VLAN_VTCR, BIT(31) | (cmd << 12) | val);
4683 + for (i = 0; i < 20; i++) {
4684 + u32 val = mt7530_r32(priv, REG_ESW_VLAN_VTCR);
4686 + if ((val & BIT(31)) == 0)
4692 + printk("mt7530: vtcr timeout\n");
4696 +mt7530_get_port_pvid(struct switch_dev *dev, int port, int *val)
4698 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4700 + if (port >= MT7530_NUM_PORTS)
4703 + *val = mt7530_r32(priv, 0x2014 + (0x100 * port));
4710 +mt7530_set_port_pvid(struct switch_dev *dev, int port, int pvid)
4712 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4714 + if (port >= MT7530_NUM_PORTS)
4717 + priv->ports[port].pvid = pvid;
4723 +mt7530_get_vlan_ports(struct switch_dev *dev, struct switch_val *val)
4725 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4731 + if (val->port_vlan < 0 || val->port_vlan >= MT7530_NUM_VIDS)
4734 + mt7530_vtcr(priv, 0, val->port_vlan);
4735 + member = mt7530_r32(priv, REG_ESW_VLAN_VAWD1);
4739 + for (i = 0; i < MT7530_NUM_PORTS; i++) {
4740 + struct switch_port *p;
4741 + if (!(member & BIT(i)))
4744 + p = &val->value.ports[val->len++];
4753 +mt7530_set_vlan_ports(struct switch_dev *dev, struct switch_val *val)
4755 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4759 + if (val->port_vlan < 0 || val->port_vlan >= MT7530_NUM_VIDS ||
4760 + val->len > MT7530_NUM_PORTS)
4763 + for (i = 0; i < val->len; i++) {
4764 + struct switch_port *p = &val->value.ports[i];
4766 + if (p->id >= MT7530_NUM_PORTS)
4769 + ports |= BIT(p->id);
4771 + priv->vlans[val->port_vlan].ports = ports;
4777 +mt7530_apply_config(struct switch_dev *dev)
4779 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4782 + if (!priv->global_vlan_enable) {
4783 + mt7530_w32(priv, 0x2004, 0xff000);
4784 + mt7530_w32(priv, 0x2104, 0xff000);
4785 + mt7530_w32(priv, 0x2204, 0xff000);
4786 + mt7530_w32(priv, 0x2304, 0xff000);
4787 + mt7530_w32(priv, 0x2404, 0xff000);
4788 + mt7530_w32(priv, 0x2504, 0xff000);
4789 + mt7530_w32(priv, 0x2604, 0xff000);
4790 + mt7530_w32(priv, 0x2010, 0x810000c);
4791 + mt7530_w32(priv, 0x2110, 0x810000c);
4792 + mt7530_w32(priv, 0x2210, 0x810000c);
4793 + mt7530_w32(priv, 0x2310, 0x810000c);
4794 + mt7530_w32(priv, 0x2410, 0x810000c);
4795 + mt7530_w32(priv, 0x2510, 0x810000c);
4796 + mt7530_w32(priv, 0x2610, 0x810000c);
4800 + // LAN/WAN ports as security mode
4801 + mt7530_w32(priv, 0x2004, 0xff0003);
4802 + mt7530_w32(priv, 0x2104, 0xff0003);
4803 + mt7530_w32(priv, 0x2204, 0xff0003);
4804 + mt7530_w32(priv, 0x2304, 0xff0003);
4805 + mt7530_w32(priv, 0x2404, 0xff0003);
4806 + mt7530_w32(priv, 0x2504, 0xff0003);
4807 + // LAN/WAN ports as transparent port
4808 + mt7530_w32(priv, 0x2010, 0x810000c0);
4809 + mt7530_w32(priv, 0x2110, 0x810000c0);
4810 + mt7530_w32(priv, 0x2210, 0x810000c0);
4811 + mt7530_w32(priv, 0x2310, 0x810000c0);
4812 + mt7530_w32(priv, 0x2410, 0x810000c0);
4813 + mt7530_w32(priv, 0x2510, 0x810000c0);
4815 + // set CPU/P7 port as user port
4816 + mt7530_w32(priv, 0x2610, 0x81000000);
4817 + mt7530_w32(priv, 0x2710, 0x81000000);
4819 + mt7530_w32(priv, 0x2604, 0x20ff0003);
4820 + mt7530_w32(priv, 0x2704, 0x20ff0003);
4821 + mt7530_w32(priv, 0x2610, 0x81000000);
4823 + for (i = 0; i < MT7530_NUM_VLANS; i++) {
4824 + u8 ports = priv->vlans[i].ports;
4825 + u32 val = mt7530_r32(priv, 0x100 + 4 * (i / 2));
4834 + mt7530_w32(priv, 0x100 + 4 * (i / 2), val);
4837 + mt7530_w32(priv, REG_ESW_VLAN_VAWD1, BIT(30) | (ports << 16) | BIT(0));
4839 + mt7530_w32(priv, REG_ESW_VLAN_VAWD1, 0);
4841 + mt7530_vtcr(priv, 1, i);
4844 + for (i = 0; i < MT7530_NUM_PORTS; i++)
4845 + mt7530_w32(priv, 0x2014 + (0x100 * i), 0x10000 | priv->ports[i].pvid);
4851 +mt7530_get_port_link(struct switch_dev *dev, int port,
4852 + struct switch_port_link *link)
4854 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
4857 + if (port < 0 || port >= MT7530_NUM_PORTS)
4860 + pmsr = mt7530_r32(priv, 0x3008 + (0x100 * port));
4862 + link->link = pmsr & 1;
4863 + link->duplex = (pmsr >> 1) & 1;
4864 + speed = (pmsr >> 2) & 3;
4868 + link->speed = SWITCH_PORT_SPEED_10;
4871 + link->speed = SWITCH_PORT_SPEED_100;
4874 + case 3: /* forced gige speed can be 2 or 3 */
4875 + link->speed = SWITCH_PORT_SPEED_1000;
4878 + link->speed = SWITCH_PORT_SPEED_UNKNOWN;
4885 +static const struct switch_attr mt7530_global[] = {
4887 + .type = SWITCH_TYPE_INT,
4888 + .name = "enable_vlan",
4889 + .description = "VLAN mode (1:enabled)",
4891 + .id = MT7530_ATTR_ENABLE_VLAN,
4892 + .get = mt7530_get_vlan_enable,
4893 + .set = mt7530_set_vlan_enable,
4897 +static const struct switch_attr mt7530_port[] = {
4900 +static const struct switch_attr mt7530_vlan[] = {
4903 +static const struct switch_dev_ops mt7530_ops = {
4905 + .attr = mt7530_global,
4906 + .n_attr = ARRAY_SIZE(mt7530_global),
4909 + .attr = mt7530_port,
4910 + .n_attr = ARRAY_SIZE(mt7530_port),
4913 + .attr = mt7530_vlan,
4914 + .n_attr = ARRAY_SIZE(mt7530_vlan),
4916 + .get_vlan_ports = mt7530_get_vlan_ports,
4917 + .set_vlan_ports = mt7530_set_vlan_ports,
4918 + .get_port_pvid = mt7530_get_port_pvid,
4919 + .set_port_pvid = mt7530_set_port_pvid,
4920 + .get_port_link = mt7530_get_port_link,
4921 + .apply_config = mt7530_apply_config,
4922 + .reset_switch = mt7530_reset_switch,
4926 +mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus)
4928 + struct switch_dev *swdev;
4929 + struct mt7530_priv *mt7530;
4930 + struct mt7530_mapping *map;
4933 + if (bus && bus->phy_map[0x1f]->phy_id != 0x1beef)
4936 + mt7530 = devm_kzalloc(dev, sizeof(struct mt7530_priv), GFP_KERNEL);
4940 + mt7530->base = base;
4941 + mt7530->bus = bus;
4942 + mt7530->global_vlan_enable = 1;
4944 + swdev = &mt7530->swdev;
4945 + swdev->name = "mt7530";
4946 + swdev->alias = "mt7530";
4947 + swdev->cpu_port = MT7530_CPU_PORT;
4948 + swdev->ports = MT7530_NUM_PORTS;
4949 + swdev->vlans = MT7530_NUM_VLANS;
4950 + swdev->ops = &mt7530_ops;
4952 + ret = register_switch(swdev, NULL);
4954 + dev_err(dev, "failed to register mt7530\n");
4958 + dev_info(dev, "loaded mt7530 driver\n");
4960 + map = mt7530_find_mapping(dev->of_node);
4962 + mt7530_apply_mapping(mt7530, map);
4963 + mt7530_apply_config(swdev);
4967 Index: linux-3.10.21/drivers/net/ethernet/ralink/mt7530.h
4968 ===================================================================
4969 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4970 +++ linux-3.10.21/drivers/net/ethernet/ralink/mt7530.h 2013-12-09 13:26:42.336125203 +0100
4973 + * This program is free software; you can redistribute it and/or
4974 + * modify it under the terms of the GNU General Public License
4975 + * as published by the Free Software Foundation; either version 2
4976 + * of the License, or (at your option) any later version.
4978 + * This program is distributed in the hope that it will be useful,
4979 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4980 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4981 + * GNU General Public License for more details.
4983 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
4986 +#ifndef _MT7530_H__
4987 +#define _MT7530_H__
4989 +int mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus);