1 From c55d6cf3e2c593bf7d228c6532ec9bd8da82e09d 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 35/57] 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 | 32 +
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 | 566 ++++++++
19 drivers/net/ethernet/ralink/gsw_mt7620a.h | 30 +
20 drivers/net/ethernet/ralink/mdio.c | 244 ++++
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/mt7530.c | 579 ++++++++
25 drivers/net/ethernet/ralink/mt7530.h | 20 +
26 drivers/net/ethernet/ralink/ralink_soc_eth.c | 844 +++++++++++
27 drivers/net/ethernet/ralink/ralink_soc_eth.h | 384 +++++
28 drivers/net/ethernet/ralink/soc_mt7620.c | 172 +++
29 drivers/net/ethernet/ralink/soc_rt2880.c | 52 +
30 drivers/net/ethernet/ralink/soc_rt305x.c | 113 ++
31 drivers/net/ethernet/ralink/soc_rt3883.c | 60 +
32 22 files changed, 4926 insertions(+)
33 create mode 100644 arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h
34 create mode 100644 drivers/net/ethernet/ralink/Kconfig
35 create mode 100644 drivers/net/ethernet/ralink/Makefile
36 create mode 100644 drivers/net/ethernet/ralink/esw_rt3052.c
37 create mode 100644 drivers/net/ethernet/ralink/esw_rt3052.h
38 create mode 100644 drivers/net/ethernet/ralink/gsw_mt7620a.c
39 create mode 100644 drivers/net/ethernet/ralink/gsw_mt7620a.h
40 create mode 100644 drivers/net/ethernet/ralink/mdio.c
41 create mode 100644 drivers/net/ethernet/ralink/mdio.h
42 create mode 100644 drivers/net/ethernet/ralink/mdio_rt2880.c
43 create mode 100644 drivers/net/ethernet/ralink/mdio_rt2880.h
44 create mode 100644 drivers/net/ethernet/ralink/mt7530.c
45 create mode 100644 drivers/net/ethernet/ralink/mt7530.h
46 create mode 100644 drivers/net/ethernet/ralink/ralink_soc_eth.c
47 create mode 100644 drivers/net/ethernet/ralink/ralink_soc_eth.h
48 create mode 100644 drivers/net/ethernet/ralink/soc_mt7620.c
49 create mode 100644 drivers/net/ethernet/ralink/soc_rt2880.c
50 create mode 100644 drivers/net/ethernet/ralink/soc_rt305x.c
51 create mode 100644 drivers/net/ethernet/ralink/soc_rt3883.c
53 Index: linux-3.14.18/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h
54 ===================================================================
55 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
56 +++ linux-3.14.18/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h 2014-10-28 10:43:11.882131200 +0100
59 + * Ralink RT305x SoC platform device registration
61 + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
63 + * This program is free software; you can redistribute it and/or modify it
64 + * under the terms of the GNU General Public License version 2 as published
65 + * by the Free Software Foundation.
68 +#ifndef _RT305X_ESW_PLATFORM_H
69 +#define _RT305X_ESW_PLATFORM_H
72 + RT305X_ESW_VLAN_CONFIG_NONE = 0,
73 + RT305X_ESW_VLAN_CONFIG_LLLLW,
74 + RT305X_ESW_VLAN_CONFIG_WLLLL,
77 +struct rt305x_esw_platform_data
80 + u32 reg_initval_fct2;
81 + u32 reg_initval_fpa2;
84 +#endif /* _RT305X_ESW_PLATFORM_H */
85 Index: linux-3.14.18/arch/mips/ralink/rt305x.c
86 ===================================================================
87 --- linux-3.14.18.orig/arch/mips/ralink/rt305x.c 2014-10-28 10:43:11.766130990 +0100
88 +++ linux-3.14.18/arch/mips/ralink/rt305x.c 2014-10-28 10:43:11.882131200 +0100
92 ralink_clk_add("cpu", cpu_rate);
93 + ralink_clk_add("sys", sys_rate);
94 ralink_clk_add("10000b00.spi", sys_rate);
95 ralink_clk_add("10000100.timer", wdt_rate);
96 ralink_clk_add("10000120.watchdog", wdt_rate);
97 Index: linux-3.14.18/drivers/net/ethernet/Kconfig
98 ===================================================================
99 --- linux-3.14.18.orig/drivers/net/ethernet/Kconfig 2014-09-06 01:34:59.000000000 +0200
100 +++ linux-3.14.18/drivers/net/ethernet/Kconfig 2014-10-29 14:59:06.927617708 +0100
102 source "drivers/net/ethernet/packetengines/Kconfig"
103 source "drivers/net/ethernet/pasemi/Kconfig"
104 source "drivers/net/ethernet/qlogic/Kconfig"
105 +source "drivers/net/ethernet/ralink/Kconfig"
106 source "drivers/net/ethernet/realtek/Kconfig"
107 source "drivers/net/ethernet/renesas/Kconfig"
108 source "drivers/net/ethernet/rdc/Kconfig"
109 Index: linux-3.14.18/drivers/net/ethernet/Makefile
110 ===================================================================
111 --- linux-3.14.18.orig/drivers/net/ethernet/Makefile 2014-09-06 01:34:59.000000000 +0200
112 +++ linux-3.14.18/drivers/net/ethernet/Makefile 2014-10-29 14:59:06.927617708 +0100
114 obj-$(CONFIG_NET_PACKET_ENGINE) += packetengines/
115 obj-$(CONFIG_NET_VENDOR_PASEMI) += pasemi/
116 obj-$(CONFIG_NET_VENDOR_QLOGIC) += qlogic/
117 +obj-$(CONFIG_NET_RALINK) += ralink/
118 obj-$(CONFIG_NET_VENDOR_REALTEK) += realtek/
119 obj-$(CONFIG_SH_ETH) += renesas/
120 obj-$(CONFIG_NET_VENDOR_RDC) += rdc/
121 Index: linux-3.14.18/drivers/net/ethernet/ralink/Kconfig
122 ===================================================================
123 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
124 +++ linux-3.14.18/drivers/net/ethernet/ralink/Kconfig 2014-10-28 10:43:11.886131208 +0100
127 + tristate "Ralink RT288X/RT3X5X/RT3662/RT3883/MT7620 ethernet driver"
130 + This driver supports the ethernet mac inside the ralink wisocs
134 +config NET_RALINK_MDIO
135 + def_bool NET_RALINK
136 + depends on (SOC_RT288X || SOC_RT3883 || SOC_MT7620)
139 +config NET_RALINK_MDIO_RT2880
140 + def_bool NET_RALINK
141 + depends on (SOC_RT288X || SOC_RT3883)
142 + select NET_RALINK_MDIO
144 +config NET_RALINK_ESW_RT3052
145 + def_bool NET_RALINK
146 + depends on SOC_RT305X
150 +config NET_RALINK_GSW_MT7620
151 + def_bool NET_RALINK
152 + depends on SOC_MT7620
154 + select NET_RALINK_MDIO
158 Index: linux-3.14.18/drivers/net/ethernet/ralink/Makefile
159 ===================================================================
160 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
161 +++ linux-3.14.18/drivers/net/ethernet/ralink/Makefile 2014-10-28 10:43:11.886131208 +0100
164 +# Makefile for the Ralink SoCs built-in ethernet macs
167 +ralink-eth-y += ralink_soc_eth.o
169 +ralink-eth-$(CONFIG_NET_RALINK_MDIO) += mdio.o
170 +ralink-eth-$(CONFIG_NET_RALINK_MDIO_RT2880) += mdio_rt2880.o
172 +ralink-eth-$(CONFIG_NET_RALINK_ESW_RT3052) += esw_rt3052.o
173 +ralink-eth-$(CONFIG_NET_RALINK_GSW_MT7620) += gsw_mt7620a.o mt7530.o
175 +ralink-eth-$(CONFIG_SOC_RT288X) += soc_rt2880.o
176 +ralink-eth-$(CONFIG_SOC_RT305X) += soc_rt305x.o
177 +ralink-eth-$(CONFIG_SOC_RT3883) += soc_rt3883.o
178 +ralink-eth-$(CONFIG_SOC_MT7620) += soc_mt7620.o
180 +obj-$(CONFIG_NET_RALINK) += ralink-eth.o
181 Index: linux-3.14.18/drivers/net/ethernet/ralink/esw_rt3052.c
182 ===================================================================
183 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
184 +++ linux-3.14.18/drivers/net/ethernet/ralink/esw_rt3052.c 2014-10-28 10:43:11.886131208 +0100
187 + * This program is free software; you can redistribute it and/or modify
188 + * it under the terms of the GNU General Public License as published by
189 + * the Free Software Foundation; version 2 of the License
191 + * This program is distributed in the hope that it will be useful,
192 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
193 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
194 + * GNU General Public License for more details.
196 + * You should have received a copy of the GNU General Public License
197 + * along with this program; if not, write to the Free Software
198 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
200 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
203 +#include <linux/module.h>
204 +#include <linux/kernel.h>
205 +#include <linux/types.h>
206 +#include <linux/dma-mapping.h>
207 +#include <linux/init.h>
208 +#include <linux/skbuff.h>
209 +#include <linux/etherdevice.h>
210 +#include <linux/ethtool.h>
211 +#include <linux/platform_device.h>
212 +#include <linux/of_device.h>
213 +#include <linux/clk.h>
214 +#include <linux/of_net.h>
215 +#include <linux/of_mdio.h>
217 +#include <asm/mach-ralink/ralink_regs.h>
219 +#include "ralink_soc_eth.h"
221 +#include <linux/ioport.h>
222 +#include <linux/switch.h>
223 +#include <linux/mii.h>
225 +#include <ralink_regs.h>
226 +#include <asm/mach-ralink/rt305x.h>
227 +#include <asm/mach-ralink/rt305x_esw_platform.h>
230 + * HW limitations for this switch:
231 + * - No large frame support (PKT_MAX_LEN at most 1536)
232 + * - Can't have untagged vlan and tagged vlan on one port at the same time,
233 + * though this might be possible using the undocumented PPE.
236 +#define RT305X_ESW_REG_ISR 0x00
237 +#define RT305X_ESW_REG_IMR 0x04
238 +#define RT305X_ESW_REG_FCT0 0x08
239 +#define RT305X_ESW_REG_PFC1 0x14
240 +#define RT305X_ESW_REG_ATS 0x24
241 +#define RT305X_ESW_REG_ATS0 0x28
242 +#define RT305X_ESW_REG_ATS1 0x2c
243 +#define RT305X_ESW_REG_ATS2 0x30
244 +#define RT305X_ESW_REG_PVIDC(_n) (0x40 + 4 * (_n))
245 +#define RT305X_ESW_REG_VLANI(_n) (0x50 + 4 * (_n))
246 +#define RT305X_ESW_REG_VMSC(_n) (0x70 + 4 * (_n))
247 +#define RT305X_ESW_REG_POA 0x80
248 +#define RT305X_ESW_REG_FPA 0x84
249 +#define RT305X_ESW_REG_SOCPC 0x8c
250 +#define RT305X_ESW_REG_POC0 0x90
251 +#define RT305X_ESW_REG_POC1 0x94
252 +#define RT305X_ESW_REG_POC2 0x98
253 +#define RT305X_ESW_REG_SGC 0x9c
254 +#define RT305X_ESW_REG_STRT 0xa0
255 +#define RT305X_ESW_REG_PCR0 0xc0
256 +#define RT305X_ESW_REG_PCR1 0xc4
257 +#define RT305X_ESW_REG_FPA2 0xc8
258 +#define RT305X_ESW_REG_FCT2 0xcc
259 +#define RT305X_ESW_REG_SGC2 0xe4
260 +#define RT305X_ESW_REG_P0LED 0xa4
261 +#define RT305X_ESW_REG_P1LED 0xa8
262 +#define RT305X_ESW_REG_P2LED 0xac
263 +#define RT305X_ESW_REG_P3LED 0xb0
264 +#define RT305X_ESW_REG_P4LED 0xb4
265 +#define RT305X_ESW_REG_PXPC(_x) (0xe8 + (4 * _x))
266 +#define RT305X_ESW_REG_P1PC 0xec
267 +#define RT305X_ESW_REG_P2PC 0xf0
268 +#define RT305X_ESW_REG_P3PC 0xf4
269 +#define RT305X_ESW_REG_P4PC 0xf8
270 +#define RT305X_ESW_REG_P5PC 0xfc
272 +#define RT305X_ESW_LED_LINK 0
273 +#define RT305X_ESW_LED_100M 1
274 +#define RT305X_ESW_LED_DUPLEX 2
275 +#define RT305X_ESW_LED_ACTIVITY 3
276 +#define RT305X_ESW_LED_COLLISION 4
277 +#define RT305X_ESW_LED_LINKACT 5
278 +#define RT305X_ESW_LED_DUPLCOLL 6
279 +#define RT305X_ESW_LED_10MACT 7
280 +#define RT305X_ESW_LED_100MACT 8
281 +/* Additional led states not in datasheet: */
282 +#define RT305X_ESW_LED_BLINK 10
283 +#define RT305X_ESW_LED_ON 12
285 +#define RT305X_ESW_LINK_S 25
286 +#define RT305X_ESW_DUPLEX_S 9
287 +#define RT305X_ESW_SPD_S 0
289 +#define RT305X_ESW_PCR0_WT_NWAY_DATA_S 16
290 +#define RT305X_ESW_PCR0_WT_PHY_CMD BIT(13)
291 +#define RT305X_ESW_PCR0_CPU_PHY_REG_S 8
293 +#define RT305X_ESW_PCR1_WT_DONE BIT(0)
295 +#define RT305X_ESW_ATS_TIMEOUT (5 * HZ)
296 +#define RT305X_ESW_PHY_TIMEOUT (5 * HZ)
298 +#define RT305X_ESW_PVIDC_PVID_M 0xfff
299 +#define RT305X_ESW_PVIDC_PVID_S 12
301 +#define RT305X_ESW_VLANI_VID_M 0xfff
302 +#define RT305X_ESW_VLANI_VID_S 12
304 +#define RT305X_ESW_VMSC_MSC_M 0xff
305 +#define RT305X_ESW_VMSC_MSC_S 8
307 +#define RT305X_ESW_SOCPC_DISUN2CPU_S 0
308 +#define RT305X_ESW_SOCPC_DISMC2CPU_S 8
309 +#define RT305X_ESW_SOCPC_DISBC2CPU_S 16
310 +#define RT305X_ESW_SOCPC_CRC_PADDING BIT(25)
312 +#define RT305X_ESW_POC0_EN_BP_S 0
313 +#define RT305X_ESW_POC0_EN_FC_S 8
314 +#define RT305X_ESW_POC0_DIS_RMC2CPU_S 16
315 +#define RT305X_ESW_POC0_DIS_PORT_M 0x7f
316 +#define RT305X_ESW_POC0_DIS_PORT_S 23
318 +#define RT305X_ESW_POC2_UNTAG_EN_M 0xff
319 +#define RT305X_ESW_POC2_UNTAG_EN_S 0
320 +#define RT305X_ESW_POC2_ENAGING_S 8
321 +#define RT305X_ESW_POC2_DIS_UC_PAUSE_S 16
323 +#define RT305X_ESW_SGC2_DOUBLE_TAG_M 0x7f
324 +#define RT305X_ESW_SGC2_DOUBLE_TAG_S 0
325 +#define RT305X_ESW_SGC2_LAN_PMAP_M 0x3f
326 +#define RT305X_ESW_SGC2_LAN_PMAP_S 24
328 +#define RT305X_ESW_PFC1_EN_VLAN_M 0xff
329 +#define RT305X_ESW_PFC1_EN_VLAN_S 16
330 +#define RT305X_ESW_PFC1_EN_TOS_S 24
332 +#define RT305X_ESW_VLAN_NONE 0xfff
334 +#define RT305X_ESW_GSC_BC_STROM_MASK 0x3
335 +#define RT305X_ESW_GSC_BC_STROM_SHIFT 4
337 +#define RT305X_ESW_GSC_LED_FREQ_MASK 0x3
338 +#define RT305X_ESW_GSC_LED_FREQ_SHIFT 23
340 +#define RT305X_ESW_POA_LINK_MASK 0x1f
341 +#define RT305X_ESW_POA_LINK_SHIFT 25
343 +#define RT305X_ESW_PORT_ST_CHG BIT(26)
344 +#define RT305X_ESW_PORT0 0
345 +#define RT305X_ESW_PORT1 1
346 +#define RT305X_ESW_PORT2 2
347 +#define RT305X_ESW_PORT3 3
348 +#define RT305X_ESW_PORT4 4
349 +#define RT305X_ESW_PORT5 5
350 +#define RT305X_ESW_PORT6 6
352 +#define RT305X_ESW_PORTS_NONE 0
354 +#define RT305X_ESW_PMAP_LLLLLL 0x3f
355 +#define RT305X_ESW_PMAP_LLLLWL 0x2f
356 +#define RT305X_ESW_PMAP_WLLLLL 0x3e
358 +#define RT305X_ESW_PORTS_INTERNAL \
359 + (BIT(RT305X_ESW_PORT0) | BIT(RT305X_ESW_PORT1) | \
360 + BIT(RT305X_ESW_PORT2) | BIT(RT305X_ESW_PORT3) | \
361 + BIT(RT305X_ESW_PORT4))
363 +#define RT305X_ESW_PORTS_NOCPU \
364 + (RT305X_ESW_PORTS_INTERNAL | BIT(RT305X_ESW_PORT5))
366 +#define RT305X_ESW_PORTS_CPU BIT(RT305X_ESW_PORT6)
368 +#define RT305X_ESW_PORTS_ALL \
369 + (RT305X_ESW_PORTS_NOCPU | RT305X_ESW_PORTS_CPU)
371 +#define RT305X_ESW_NUM_VLANS 16
372 +#define RT305X_ESW_NUM_VIDS 4096
373 +#define RT305X_ESW_NUM_PORTS 7
374 +#define RT305X_ESW_NUM_LANWAN 6
375 +#define RT305X_ESW_NUM_LEDS 5
377 +#define RT5350_ESW_REG_PXTPC(_x) (0x150 + (4 * _x))
378 +#define RT5350_EWS_REG_LED_POLARITY 0x168
379 +#define RT5350_RESET_EPHY BIT(24)
380 +#define SYSC_REG_RESET_CTRL 0x34
383 + /* Global attributes. */
384 + RT305X_ESW_ATTR_ENABLE_VLAN,
385 + RT305X_ESW_ATTR_ALT_VLAN_DISABLE,
386 + RT305X_ESW_ATTR_BC_STATUS,
387 + RT305X_ESW_ATTR_LED_FREQ,
388 + /* Port attributes. */
389 + RT305X_ESW_ATTR_PORT_DISABLE,
390 + RT305X_ESW_ATTR_PORT_DOUBLETAG,
391 + RT305X_ESW_ATTR_PORT_UNTAG,
392 + RT305X_ESW_ATTR_PORT_LED,
393 + RT305X_ESW_ATTR_PORT_LAN,
394 + RT305X_ESW_ATTR_PORT_RECV_BAD,
395 + RT305X_ESW_ATTR_PORT_RECV_GOOD,
396 + RT5350_ESW_ATTR_PORT_TR_BAD,
397 + RT5350_ESW_ATTR_PORT_TR_GOOD,
414 + struct device *dev;
415 + void __iomem *base;
417 + const struct rt305x_esw_platform_data *pdata;
418 + /* Protects against concurrent register rmw operations. */
419 + spinlock_t reg_rw_lock;
421 + unsigned char port_map;
422 + unsigned int reg_initval_fct2;
423 + unsigned int reg_initval_fpa2;
424 + unsigned int reg_led_polarity;
427 + struct switch_dev swdev;
428 + bool global_vlan_enable;
429 + bool alt_vlan_disable;
430 + int bc_storm_protect;
432 + struct esw_vlan vlans[RT305X_ESW_NUM_VLANS];
433 + struct esw_port ports[RT305X_ESW_NUM_PORTS];
437 +static inline void esw_w32(struct rt305x_esw *esw, u32 val, unsigned reg)
439 + __raw_writel(val, esw->base + reg);
442 +static inline u32 esw_r32(struct rt305x_esw *esw, unsigned reg)
444 + return __raw_readl(esw->base + reg);
447 +static inline void esw_rmw_raw(struct rt305x_esw *esw, unsigned reg, unsigned long mask,
452 + t = __raw_readl(esw->base + reg) & ~mask;
453 + __raw_writel(t | val, esw->base + reg);
456 +static void esw_rmw(struct rt305x_esw *esw, unsigned reg, unsigned long mask,
459 + unsigned long flags;
461 + spin_lock_irqsave(&esw->reg_rw_lock, flags);
462 + esw_rmw_raw(esw, reg, mask, val);
463 + spin_unlock_irqrestore(&esw->reg_rw_lock, flags);
466 +static u32 rt305x_mii_write(struct rt305x_esw *esw, u32 phy_addr, u32 phy_register,
469 + unsigned long t_start = jiffies;
473 + if (!(esw_r32(esw, RT305X_ESW_REG_PCR1) &
474 + RT305X_ESW_PCR1_WT_DONE))
476 + if (time_after(jiffies, t_start + RT305X_ESW_PHY_TIMEOUT)) {
482 + write_data &= 0xffff;
484 + (write_data << RT305X_ESW_PCR0_WT_NWAY_DATA_S) |
485 + (phy_register << RT305X_ESW_PCR0_CPU_PHY_REG_S) |
486 + (phy_addr) | RT305X_ESW_PCR0_WT_PHY_CMD,
487 + RT305X_ESW_REG_PCR0);
491 + if (esw_r32(esw, RT305X_ESW_REG_PCR1) &
492 + RT305X_ESW_PCR1_WT_DONE)
495 + if (time_after(jiffies, t_start + RT305X_ESW_PHY_TIMEOUT)) {
502 + printk(KERN_ERR "ramips_eth: MDIO timeout\n");
506 +static unsigned esw_get_vlan_id(struct rt305x_esw *esw, unsigned vlan)
511 + s = RT305X_ESW_VLANI_VID_S * (vlan % 2);
512 + val = esw_r32(esw, RT305X_ESW_REG_VLANI(vlan / 2));
513 + val = (val >> s) & RT305X_ESW_VLANI_VID_M;
518 +static void esw_set_vlan_id(struct rt305x_esw *esw, unsigned vlan, unsigned vid)
522 + s = RT305X_ESW_VLANI_VID_S * (vlan % 2);
524 + RT305X_ESW_REG_VLANI(vlan / 2),
525 + RT305X_ESW_VLANI_VID_M << s,
526 + (vid & RT305X_ESW_VLANI_VID_M) << s);
529 +static unsigned esw_get_pvid(struct rt305x_esw *esw, unsigned port)
533 + s = RT305X_ESW_PVIDC_PVID_S * (port % 2);
534 + val = esw_r32(esw, RT305X_ESW_REG_PVIDC(port / 2));
535 + return (val >> s) & RT305X_ESW_PVIDC_PVID_M;
538 +static void esw_set_pvid(struct rt305x_esw *esw, unsigned port, unsigned pvid)
542 + s = RT305X_ESW_PVIDC_PVID_S * (port % 2);
544 + RT305X_ESW_REG_PVIDC(port / 2),
545 + RT305X_ESW_PVIDC_PVID_M << s,
546 + (pvid & RT305X_ESW_PVIDC_PVID_M) << s);
549 +static unsigned esw_get_vmsc(struct rt305x_esw *esw, unsigned vlan)
553 + s = RT305X_ESW_VMSC_MSC_S * (vlan % 4);
554 + val = esw_r32(esw, RT305X_ESW_REG_VMSC(vlan / 4));
555 + val = (val >> s) & RT305X_ESW_VMSC_MSC_M;
560 +static void esw_set_vmsc(struct rt305x_esw *esw, unsigned vlan, unsigned msc)
564 + s = RT305X_ESW_VMSC_MSC_S * (vlan % 4);
566 + RT305X_ESW_REG_VMSC(vlan / 4),
567 + RT305X_ESW_VMSC_MSC_M << s,
568 + (msc & RT305X_ESW_VMSC_MSC_M) << s);
571 +static unsigned esw_get_port_disable(struct rt305x_esw *esw)
574 + reg = esw_r32(esw, RT305X_ESW_REG_POC0);
575 + return (reg >> RT305X_ESW_POC0_DIS_PORT_S) &
576 + RT305X_ESW_POC0_DIS_PORT_M;
579 +static void esw_set_port_disable(struct rt305x_esw *esw, unsigned disable_mask)
582 + unsigned enable_mask;
586 + old_mask = esw_get_port_disable(esw);
587 + changed = old_mask ^ disable_mask;
588 + enable_mask = old_mask & disable_mask;
590 + /* enable before writing to MII */
591 + esw_rmw(esw, RT305X_ESW_REG_POC0,
592 + (RT305X_ESW_POC0_DIS_PORT_M <<
593 + RT305X_ESW_POC0_DIS_PORT_S),
594 + enable_mask << RT305X_ESW_POC0_DIS_PORT_S);
596 + for (i = 0; i < RT305X_ESW_NUM_LEDS; i++) {
597 + if (!(changed & (1 << i)))
599 + if (disable_mask & (1 << i)) {
601 + rt305x_mii_write(esw, i, MII_BMCR,
605 + rt305x_mii_write(esw, i, MII_BMCR,
613 + /* disable after writing to MII */
614 + esw_rmw(esw, RT305X_ESW_REG_POC0,
615 + (RT305X_ESW_POC0_DIS_PORT_M <<
616 + RT305X_ESW_POC0_DIS_PORT_S),
617 + disable_mask << RT305X_ESW_POC0_DIS_PORT_S);
620 +static void esw_set_gsc(struct rt305x_esw *esw)
622 + esw_rmw(esw, RT305X_ESW_REG_SGC,
623 + RT305X_ESW_GSC_BC_STROM_MASK << RT305X_ESW_GSC_BC_STROM_SHIFT,
624 + esw->bc_storm_protect << RT305X_ESW_GSC_BC_STROM_SHIFT);
625 + esw_rmw(esw, RT305X_ESW_REG_SGC,
626 + RT305X_ESW_GSC_LED_FREQ_MASK << RT305X_ESW_GSC_LED_FREQ_SHIFT,
627 + esw->led_frequency << RT305X_ESW_GSC_LED_FREQ_SHIFT);
630 +static int esw_apply_config(struct switch_dev *dev);
632 +static void esw_hw_init(struct rt305x_esw *esw)
635 + u8 port_disable = 0;
636 + u8 port_map = RT305X_ESW_PMAP_LLLLLL;
638 + /* vodoo from original driver */
639 + esw_w32(esw, 0xC8A07850, RT305X_ESW_REG_FCT0);
640 + esw_w32(esw, 0x00000000, RT305X_ESW_REG_SGC2);
641 + /* Port priority 1 for all ports, vlan enabled. */
642 + esw_w32(esw, 0x00005555 |
643 + (RT305X_ESW_PORTS_ALL << RT305X_ESW_PFC1_EN_VLAN_S),
644 + RT305X_ESW_REG_PFC1);
646 + /* Enable Back Pressure, and Flow Control */
648 + ((RT305X_ESW_PORTS_ALL << RT305X_ESW_POC0_EN_BP_S) |
649 + (RT305X_ESW_PORTS_ALL << RT305X_ESW_POC0_EN_FC_S)),
650 + RT305X_ESW_REG_POC0);
652 + /* Enable Aging, and VLAN TAG removal */
654 + ((RT305X_ESW_PORTS_ALL << RT305X_ESW_POC2_ENAGING_S) |
655 + (RT305X_ESW_PORTS_NOCPU << RT305X_ESW_POC2_UNTAG_EN_S)),
656 + RT305X_ESW_REG_POC2);
658 + if (esw->reg_initval_fct2)
659 + esw_w32(esw, esw->reg_initval_fct2, RT305X_ESW_REG_FCT2);
661 + esw_w32(esw, esw->pdata->reg_initval_fct2, RT305X_ESW_REG_FCT2);
664 + * 300s aging timer, max packet len 1536, broadcast storm prevention
665 + * disabled, disable collision abort, mac xor48 hash, 10 packet back
666 + * pressure jam, GMII disable was_transmit, back pressure disabled,
667 + * 30ms led flash, unmatched IGMP as broadcast, rmc tb fault to all
670 + esw_w32(esw, 0x0008a301, RT305X_ESW_REG_SGC);
672 + /* Setup SoC Port control register */
674 + (RT305X_ESW_SOCPC_CRC_PADDING |
675 + (RT305X_ESW_PORTS_CPU << RT305X_ESW_SOCPC_DISUN2CPU_S) |
676 + (RT305X_ESW_PORTS_CPU << RT305X_ESW_SOCPC_DISMC2CPU_S) |
677 + (RT305X_ESW_PORTS_CPU << RT305X_ESW_SOCPC_DISBC2CPU_S)),
678 + RT305X_ESW_REG_SOCPC);
680 + if (esw->reg_initval_fpa2)
681 + esw_w32(esw, esw->reg_initval_fpa2, RT305X_ESW_REG_FPA2);
683 + esw_w32(esw, esw->pdata->reg_initval_fpa2, RT305X_ESW_REG_FPA2);
684 + esw_w32(esw, 0x00000000, RT305X_ESW_REG_FPA);
686 + /* Force Link/Activity on ports */
687 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P0LED);
688 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P1LED);
689 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P2LED);
690 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P3LED);
691 + esw_w32(esw, 0x00000005, RT305X_ESW_REG_P4LED);
693 + /* Copy disabled port configuration from bootloader setup */
694 + port_disable = esw_get_port_disable(esw);
695 + for (i = 0; i < 6; i++)
696 + esw->ports[i].disable = (port_disable & (1 << i)) != 0;
698 + if (soc_is_rt3352()) {
700 + u32 val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
701 + rt_sysc_w32(val | RT5350_RESET_EPHY, SYSC_REG_RESET_CTRL);
702 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
704 + rt305x_mii_write(esw, 0, 31, 0x8000);
705 + for (i = 0; i < 5; i++) {
706 + if (esw->ports[i].disable) {
707 + rt305x_mii_write(esw, i, MII_BMCR, BMCR_PDOWN);
709 + rt305x_mii_write(esw, i, MII_BMCR,
714 + /* TX10 waveform coefficient LSB=0 disable PHY */
715 + rt305x_mii_write(esw, i, 26, 0x1601);
716 + /* TX100/TX10 AD/DA current bias */
717 + rt305x_mii_write(esw, i, 29, 0x7016);
718 + /* TX100 slew rate control */
719 + rt305x_mii_write(esw, i, 30, 0x0038);
722 + /* select global register */
723 + rt305x_mii_write(esw, 0, 31, 0x0);
724 + /* enlarge agcsel threshold 3 and threshold 2 */
725 + rt305x_mii_write(esw, 0, 1, 0x4a40);
726 + /* enlarge agcsel threshold 5 and threshold 4 */
727 + rt305x_mii_write(esw, 0, 2, 0x6254);
728 + /* enlarge agcsel threshold */
729 + rt305x_mii_write(esw, 0, 3, 0xa17f);
730 + rt305x_mii_write(esw, 0,12, 0x7eaa);
731 + /* longer TP_IDL tail length */
732 + rt305x_mii_write(esw, 0, 14, 0x65);
733 + /* increased squelch pulse count threshold. */
734 + rt305x_mii_write(esw, 0, 16, 0x0684);
735 + /* set TX10 signal amplitude threshold to minimum */
736 + rt305x_mii_write(esw, 0, 17, 0x0fe0);
737 + /* set squelch amplitude to higher threshold */
738 + rt305x_mii_write(esw, 0, 18, 0x40ba);
739 + /* tune TP_IDL tail and head waveform, enable power down slew rate control */
740 + rt305x_mii_write(esw, 0, 22, 0x253f);
741 + /* set PLL/Receive bias current are calibrated */
742 + rt305x_mii_write(esw, 0, 27, 0x2fda);
743 + /* change PLL/Receive bias current to internal(RT3350) */
744 + rt305x_mii_write(esw, 0, 28, 0xc410);
745 + /* change PLL bias current to internal(RT3052_MP3) */
746 + rt305x_mii_write(esw, 0, 29, 0x598b);
747 + /* select local register */
748 + rt305x_mii_write(esw, 0, 31, 0x8000);
749 + } else if (soc_is_rt5350()) {
751 + u32 val = rt_sysc_r32(SYSC_REG_RESET_CTRL);
752 + rt_sysc_w32(val | RT5350_RESET_EPHY, SYSC_REG_RESET_CTRL);
753 + rt_sysc_w32(val, SYSC_REG_RESET_CTRL);
755 + /* set the led polarity */
756 + esw_w32(esw, esw->reg_led_polarity & 0x1F, RT5350_EWS_REG_LED_POLARITY);
758 + /* local registers */
759 + rt305x_mii_write(esw, 0, 31, 0x8000);
760 + for (i = 0; i < 5; i++) {
761 + if (esw->ports[i].disable) {
762 + rt305x_mii_write(esw, i, MII_BMCR, BMCR_PDOWN);
764 + rt305x_mii_write(esw, i, MII_BMCR,
769 + /* TX10 waveform coefficient LSB=0 disable PHY */
770 + rt305x_mii_write(esw, i, 26, 0x1601);
771 + /* TX100/TX10 AD/DA current bias */
772 + rt305x_mii_write(esw, i, 29, 0x7015);
773 + /* TX100 slew rate control */
774 + rt305x_mii_write(esw, i, 30, 0x0038);
777 + /* global registers */
778 + rt305x_mii_write(esw, 0, 31, 0x0);
779 + /* enlarge agcsel threshold 3 and threshold 2 */
780 + rt305x_mii_write(esw, 0, 1, 0x4a40);
781 + /* enlarge agcsel threshold 5 and threshold 4 */
782 + rt305x_mii_write(esw, 0, 2, 0x6254);
783 + /* enlarge agcsel threshold 6 */
784 + rt305x_mii_write(esw, 0, 3, 0xa17f);
785 + rt305x_mii_write(esw, 0, 12, 0x7eaa);
786 + /* longer TP_IDL tail length */
787 + rt305x_mii_write(esw, 0, 14, 0x65);
788 + /* increased squelch pulse count threshold. */
789 + rt305x_mii_write(esw, 0, 16, 0x0684);
790 + /* set TX10 signal amplitude threshold to minimum */
791 + rt305x_mii_write(esw, 0, 17, 0x0fe0);
792 + /* set squelch amplitude to higher threshold */
793 + rt305x_mii_write(esw, 0, 18, 0x40ba);
794 + /* tune TP_IDL tail and head waveform, enable power down slew rate control */
795 + rt305x_mii_write(esw, 0, 22, 0x253f);
796 + /* set PLL/Receive bias current are calibrated */
797 + rt305x_mii_write(esw, 0, 27, 0x2fda);
798 + /* change PLL/Receive bias current to internal(RT3350) */
799 + rt305x_mii_write(esw, 0, 28, 0xc410);
800 + /* change PLL bias current to internal(RT3052_MP3) */
801 + rt305x_mii_write(esw, 0, 29, 0x598b);
802 + /* select local register */
803 + rt305x_mii_write(esw, 0, 31, 0x8000);
805 + rt305x_mii_write(esw, 0, 31, 0x8000);
806 + for (i = 0; i < 5; i++) {
807 + if (esw->ports[i].disable) {
808 + rt305x_mii_write(esw, i, MII_BMCR, BMCR_PDOWN);
810 + rt305x_mii_write(esw, i, MII_BMCR,
815 + /* TX10 waveform coefficient */
816 + rt305x_mii_write(esw, i, 26, 0x1601);
817 + /* TX100/TX10 AD/DA current bias */
818 + rt305x_mii_write(esw, i, 29, 0x7058);
819 + /* TX100 slew rate control */
820 + rt305x_mii_write(esw, i, 30, 0x0018);
824 + /* select global register */
825 + rt305x_mii_write(esw, 0, 31, 0x0);
826 + /* tune TP_IDL tail and head waveform */
827 + rt305x_mii_write(esw, 0, 22, 0x052f);
828 + /* set TX10 signal amplitude threshold to minimum */
829 + rt305x_mii_write(esw, 0, 17, 0x0fe0);
830 + /* set squelch amplitude to higher threshold */
831 + rt305x_mii_write(esw, 0, 18, 0x40ba);
832 + /* longer TP_IDL tail length */
833 + rt305x_mii_write(esw, 0, 14, 0x65);
834 + /* select local register */
835 + rt305x_mii_write(esw, 0, 31, 0x8000);
839 + port_map = esw->port_map;
841 + port_map = RT305X_ESW_PMAP_LLLLLL;
844 + * Unused HW feature, but still nice to be consistent here...
845 + * This is also exported to userspace ('lan' attribute) so it's
846 + * conveniently usable to decide which ports go into the wan vlan by
849 + esw_rmw(esw, RT305X_ESW_REG_SGC2,
850 + RT305X_ESW_SGC2_LAN_PMAP_M << RT305X_ESW_SGC2_LAN_PMAP_S,
851 + port_map << RT305X_ESW_SGC2_LAN_PMAP_S);
853 + /* make the switch leds blink */
854 + for (i = 0; i < RT305X_ESW_NUM_LEDS; i++)
855 + esw->ports[i].led = 0x05;
857 + /* Apply the empty config. */
858 + esw_apply_config(&esw->swdev);
860 + /* Only unmask the port change interrupt */
861 + esw_w32(esw, ~RT305X_ESW_PORT_ST_CHG, RT305X_ESW_REG_IMR);
864 +static irqreturn_t esw_interrupt(int irq, void *_esw)
866 + struct rt305x_esw *esw = (struct rt305x_esw *) _esw;
869 + status = esw_r32(esw, RT305X_ESW_REG_ISR);
870 + if (status & RT305X_ESW_PORT_ST_CHG) {
871 + u32 link = esw_r32(esw, RT305X_ESW_REG_POA);
872 + link >>= RT305X_ESW_POA_LINK_SHIFT;
873 + link &= RT305X_ESW_POA_LINK_MASK;
874 + dev_info(esw->dev, "link changed 0x%02X\n", link);
876 + esw_w32(esw, status, RT305X_ESW_REG_ISR);
878 + return IRQ_HANDLED;
881 +static int esw_apply_config(struct switch_dev *dev)
883 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
890 + for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
892 + if (esw->global_vlan_enable) {
893 + vid = esw->vlans[i].vid;
894 + vmsc = esw->vlans[i].ports;
896 + vid = RT305X_ESW_VLAN_NONE;
897 + vmsc = RT305X_ESW_PORTS_NONE;
899 + esw_set_vlan_id(esw, i, vid);
900 + esw_set_vmsc(esw, i, vmsc);
903 + for (i = 0; i < RT305X_ESW_NUM_PORTS; i++) {
905 + disable |= esw->ports[i].disable << i;
906 + if (esw->global_vlan_enable) {
907 + doubletag |= esw->ports[i].doubletag << i;
909 + untag |= esw->ports[i].untag << i;
910 + pvid = esw->ports[i].pvid;
912 + int x = esw->alt_vlan_disable ? 0 : 1;
913 + doubletag |= x << i;
918 + esw_set_pvid(esw, i, pvid);
919 + if (i < RT305X_ESW_NUM_LEDS)
920 + esw_w32(esw, esw->ports[i].led,
921 + RT305X_ESW_REG_P0LED + 4*i);
925 + esw_set_port_disable(esw, disable);
926 + esw_rmw(esw, RT305X_ESW_REG_SGC2,
927 + (RT305X_ESW_SGC2_DOUBLE_TAG_M <<
928 + RT305X_ESW_SGC2_DOUBLE_TAG_S),
929 + doubletag << RT305X_ESW_SGC2_DOUBLE_TAG_S);
930 + esw_rmw(esw, RT305X_ESW_REG_PFC1,
931 + RT305X_ESW_PFC1_EN_VLAN_M << RT305X_ESW_PFC1_EN_VLAN_S,
932 + en_vlan << RT305X_ESW_PFC1_EN_VLAN_S);
933 + esw_rmw(esw, RT305X_ESW_REG_POC2,
934 + RT305X_ESW_POC2_UNTAG_EN_M << RT305X_ESW_POC2_UNTAG_EN_S,
935 + untag << RT305X_ESW_POC2_UNTAG_EN_S);
937 + if (!esw->global_vlan_enable) {
939 + * Still need to put all ports into vlan 0 or they'll be
941 + * NOTE: vlan 0 is special, no vlan tag is prepended
943 + esw_set_vlan_id(esw, 0, 0);
944 + esw_set_vmsc(esw, 0, RT305X_ESW_PORTS_ALL);
950 +static int esw_reset_switch(struct switch_dev *dev)
952 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
954 + esw->global_vlan_enable = 0;
955 + memset(esw->ports, 0, sizeof(esw->ports));
956 + memset(esw->vlans, 0, sizeof(esw->vlans));
962 +static int esw_get_vlan_enable(struct switch_dev *dev,
963 + const struct switch_attr *attr,
964 + struct switch_val *val)
966 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
968 + val->value.i = esw->global_vlan_enable;
973 +static int esw_set_vlan_enable(struct switch_dev *dev,
974 + const struct switch_attr *attr,
975 + struct switch_val *val)
977 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
979 + esw->global_vlan_enable = val->value.i != 0;
984 +static int esw_get_alt_vlan_disable(struct switch_dev *dev,
985 + const struct switch_attr *attr,
986 + struct switch_val *val)
988 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
990 + val->value.i = esw->alt_vlan_disable;
995 +static int esw_set_alt_vlan_disable(struct switch_dev *dev,
996 + const struct switch_attr *attr,
997 + struct switch_val *val)
999 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1001 + esw->alt_vlan_disable = val->value.i != 0;
1007 +rt305x_esw_set_bc_status(struct switch_dev *dev,
1008 + const struct switch_attr *attr,
1009 + struct switch_val *val)
1011 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1013 + esw->bc_storm_protect = val->value.i & RT305X_ESW_GSC_BC_STROM_MASK;
1019 +rt305x_esw_get_bc_status(struct switch_dev *dev,
1020 + const struct switch_attr *attr,
1021 + struct switch_val *val)
1023 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1025 + val->value.i = esw->bc_storm_protect;
1031 +rt305x_esw_set_led_freq(struct switch_dev *dev,
1032 + const struct switch_attr *attr,
1033 + struct switch_val *val)
1035 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1037 + esw->led_frequency = val->value.i & RT305X_ESW_GSC_LED_FREQ_MASK;
1043 +rt305x_esw_get_led_freq(struct switch_dev *dev,
1044 + const struct switch_attr *attr,
1045 + struct switch_val *val)
1047 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1049 + val->value.i = esw->led_frequency;
1054 +static int esw_get_port_link(struct switch_dev *dev,
1056 + struct switch_port_link *link)
1058 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1061 + if (port < 0 || port >= RT305X_ESW_NUM_PORTS)
1064 + poa = esw_r32(esw, RT305X_ESW_REG_POA) >> port;
1066 + link->link = (poa >> RT305X_ESW_LINK_S) & 1;
1067 + link->duplex = (poa >> RT305X_ESW_DUPLEX_S) & 1;
1068 + if (port < RT305X_ESW_NUM_LEDS) {
1069 + speed = (poa >> RT305X_ESW_SPD_S) & 1;
1071 + if (port == RT305X_ESW_NUM_PORTS - 1)
1073 + speed = (poa >> RT305X_ESW_SPD_S) & 3;
1077 + link->speed = SWITCH_PORT_SPEED_10;
1080 + link->speed = SWITCH_PORT_SPEED_100;
1083 + case 3: /* forced gige speed can be 2 or 3 */
1084 + link->speed = SWITCH_PORT_SPEED_1000;
1087 + link->speed = SWITCH_PORT_SPEED_UNKNOWN;
1094 +static int esw_get_port_bool(struct switch_dev *dev,
1095 + const struct switch_attr *attr,
1096 + struct switch_val *val)
1098 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1099 + int idx = val->port_vlan;
1100 + u32 x, reg, shift;
1102 + if (idx < 0 || idx >= RT305X_ESW_NUM_PORTS)
1105 + switch (attr->id) {
1106 + case RT305X_ESW_ATTR_PORT_DISABLE:
1107 + reg = RT305X_ESW_REG_POC0;
1108 + shift = RT305X_ESW_POC0_DIS_PORT_S;
1110 + case RT305X_ESW_ATTR_PORT_DOUBLETAG:
1111 + reg = RT305X_ESW_REG_SGC2;
1112 + shift = RT305X_ESW_SGC2_DOUBLE_TAG_S;
1114 + case RT305X_ESW_ATTR_PORT_UNTAG:
1115 + reg = RT305X_ESW_REG_POC2;
1116 + shift = RT305X_ESW_POC2_UNTAG_EN_S;
1118 + case RT305X_ESW_ATTR_PORT_LAN:
1119 + reg = RT305X_ESW_REG_SGC2;
1120 + shift = RT305X_ESW_SGC2_LAN_PMAP_S;
1121 + if (idx >= RT305X_ESW_NUM_LANWAN)
1128 + x = esw_r32(esw, reg);
1129 + val->value.i = (x >> (idx + shift)) & 1;
1134 +static int esw_set_port_bool(struct switch_dev *dev,
1135 + const struct switch_attr *attr,
1136 + struct switch_val *val)
1138 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1139 + int idx = val->port_vlan;
1141 + if (idx < 0 || idx >= RT305X_ESW_NUM_PORTS ||
1142 + val->value.i < 0 || val->value.i > 1)
1145 + switch (attr->id) {
1146 + case RT305X_ESW_ATTR_PORT_DISABLE:
1147 + esw->ports[idx].disable = val->value.i;
1149 + case RT305X_ESW_ATTR_PORT_DOUBLETAG:
1150 + esw->ports[idx].doubletag = val->value.i;
1152 + case RT305X_ESW_ATTR_PORT_UNTAG:
1153 + esw->ports[idx].untag = val->value.i;
1162 +static int esw_get_port_recv_badgood(struct switch_dev *dev,
1163 + const struct switch_attr *attr,
1164 + struct switch_val *val)
1166 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1167 + int idx = val->port_vlan;
1168 + int shift = attr->id == RT305X_ESW_ATTR_PORT_RECV_GOOD ? 0 : 16;
1171 + if (idx < 0 || idx >= RT305X_ESW_NUM_LANWAN)
1173 + reg = esw_r32(esw, RT305X_ESW_REG_PXPC(idx));
1174 + val->value.i = (reg >> shift) & 0xffff;
1180 +esw_get_port_tr_badgood(struct switch_dev *dev,
1181 + const struct switch_attr *attr,
1182 + struct switch_val *val)
1184 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1186 + int idx = val->port_vlan;
1187 + int shift = attr->id == RT5350_ESW_ATTR_PORT_TR_GOOD ? 0 : 16;
1190 + if (!soc_is_rt5350())
1193 + if (idx < 0 || idx >= RT305X_ESW_NUM_LANWAN)
1196 + reg = esw_r32(esw, RT5350_ESW_REG_PXTPC(idx));
1197 + val->value.i = (reg >> shift) & 0xffff;
1202 +static int esw_get_port_led(struct switch_dev *dev,
1203 + const struct switch_attr *attr,
1204 + struct switch_val *val)
1206 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1207 + int idx = val->port_vlan;
1209 + if (idx < 0 || idx >= RT305X_ESW_NUM_PORTS ||
1210 + idx >= RT305X_ESW_NUM_LEDS)
1213 + val->value.i = esw_r32(esw, RT305X_ESW_REG_P0LED + 4*idx);
1218 +static int esw_set_port_led(struct switch_dev *dev,
1219 + const struct switch_attr *attr,
1220 + struct switch_val *val)
1222 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1223 + int idx = val->port_vlan;
1225 + if (idx < 0 || idx >= RT305X_ESW_NUM_LEDS)
1228 + esw->ports[idx].led = val->value.i;
1233 +static int esw_get_port_pvid(struct switch_dev *dev, int port, int *val)
1235 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1237 + if (port >= RT305X_ESW_NUM_PORTS)
1240 + *val = esw_get_pvid(esw, port);
1245 +static int esw_set_port_pvid(struct switch_dev *dev, int port, int val)
1247 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1249 + if (port >= RT305X_ESW_NUM_PORTS)
1252 + esw->ports[port].pvid = val;
1257 +static int esw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val)
1259 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1261 + int vlan_idx = -1;
1266 + if (val->port_vlan < 0 || val->port_vlan >= RT305X_ESW_NUM_VIDS)
1270 + for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
1271 + if (esw_get_vlan_id(esw, i) == val->port_vlan &&
1272 + esw_get_vmsc(esw, i) != RT305X_ESW_PORTS_NONE) {
1278 + if (vlan_idx == -1)
1281 + vmsc = esw_get_vmsc(esw, vlan_idx);
1282 + poc2 = esw_r32(esw, RT305X_ESW_REG_POC2);
1284 + for (i = 0; i < RT305X_ESW_NUM_PORTS; i++) {
1285 + struct switch_port *p;
1286 + int port_mask = 1 << i;
1288 + if (!(vmsc & port_mask))
1291 + p = &val->value.ports[val->len++];
1293 + if (poc2 & (port_mask << RT305X_ESW_POC2_UNTAG_EN_S))
1296 + p->flags = 1 << SWITCH_PORT_FLAG_TAGGED;
1302 +static int esw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val)
1304 + struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev);
1306 + int vlan_idx = -1;
1309 + if (val->port_vlan < 0 || val->port_vlan >= RT305X_ESW_NUM_VIDS ||
1310 + val->len > RT305X_ESW_NUM_PORTS)
1313 + /* one of the already defined vlans? */
1314 + for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
1315 + if (esw->vlans[i].vid == val->port_vlan &&
1316 + esw->vlans[i].ports != RT305X_ESW_PORTS_NONE) {
1322 + /* select a free slot */
1323 + for (i = 0; vlan_idx == -1 && i < RT305X_ESW_NUM_VLANS; i++) {
1324 + if (esw->vlans[i].ports == RT305X_ESW_PORTS_NONE)
1328 + /* bail if all slots are in use */
1329 + if (vlan_idx == -1)
1332 + ports = RT305X_ESW_PORTS_NONE;
1333 + for (i = 0; i < val->len; i++) {
1334 + struct switch_port *p = &val->value.ports[i];
1335 + int port_mask = 1 << p->id;
1336 + bool untagged = !(p->flags & (1 << SWITCH_PORT_FLAG_TAGGED));
1338 + if (p->id >= RT305X_ESW_NUM_PORTS)
1341 + ports |= port_mask;
1342 + esw->ports[p->id].untag = untagged;
1344 + esw->vlans[vlan_idx].ports = ports;
1345 + if (ports == RT305X_ESW_PORTS_NONE)
1346 + esw->vlans[vlan_idx].vid = RT305X_ESW_VLAN_NONE;
1348 + esw->vlans[vlan_idx].vid = val->port_vlan;
1353 +static const struct switch_attr esw_global[] = {
1355 + .type = SWITCH_TYPE_INT,
1356 + .name = "enable_vlan",
1357 + .description = "VLAN mode (1:enabled)",
1359 + .id = RT305X_ESW_ATTR_ENABLE_VLAN,
1360 + .get = esw_get_vlan_enable,
1361 + .set = esw_set_vlan_enable,
1364 + .type = SWITCH_TYPE_INT,
1365 + .name = "alternate_vlan_disable",
1366 + .description = "Use en_vlan instead of doubletag to disable"
1369 + .id = RT305X_ESW_ATTR_ALT_VLAN_DISABLE,
1370 + .get = esw_get_alt_vlan_disable,
1371 + .set = esw_set_alt_vlan_disable,
1374 + .type = SWITCH_TYPE_INT,
1375 + .name = "bc_storm_protect",
1376 + .description = "Global broadcast storm protection (0:Disable, 1:64 blocks, 2:96 blocks, 3:128 blocks)",
1378 + .id = RT305X_ESW_ATTR_BC_STATUS,
1379 + .get = rt305x_esw_get_bc_status,
1380 + .set = rt305x_esw_set_bc_status,
1383 + .type = SWITCH_TYPE_INT,
1384 + .name = "led_frequency",
1385 + .description = "LED Flash frequency (0:30mS, 1:60mS, 2:240mS, 3:480mS)",
1387 + .id = RT305X_ESW_ATTR_LED_FREQ,
1388 + .get = rt305x_esw_get_led_freq,
1389 + .set = rt305x_esw_set_led_freq,
1393 +static const struct switch_attr esw_port[] = {
1395 + .type = SWITCH_TYPE_INT,
1396 + .name = "disable",
1397 + .description = "Port state (1:disabled)",
1399 + .id = RT305X_ESW_ATTR_PORT_DISABLE,
1400 + .get = esw_get_port_bool,
1401 + .set = esw_set_port_bool,
1404 + .type = SWITCH_TYPE_INT,
1405 + .name = "doubletag",
1406 + .description = "Double tagging for incoming vlan packets "
1409 + .id = RT305X_ESW_ATTR_PORT_DOUBLETAG,
1410 + .get = esw_get_port_bool,
1411 + .set = esw_set_port_bool,
1414 + .type = SWITCH_TYPE_INT,
1416 + .description = "Untag (1:strip outgoing vlan tag)",
1418 + .id = RT305X_ESW_ATTR_PORT_UNTAG,
1419 + .get = esw_get_port_bool,
1420 + .set = esw_set_port_bool,
1423 + .type = SWITCH_TYPE_INT,
1425 + .description = "LED mode (0:link, 1:100m, 2:duplex, 3:activity,"
1426 + " 4:collision, 5:linkact, 6:duplcoll, 7:10mact,"
1427 + " 8:100mact, 10:blink, 11:off, 12:on)",
1429 + .id = RT305X_ESW_ATTR_PORT_LED,
1430 + .get = esw_get_port_led,
1431 + .set = esw_set_port_led,
1434 + .type = SWITCH_TYPE_INT,
1436 + .description = "HW port group (0:wan, 1:lan)",
1438 + .id = RT305X_ESW_ATTR_PORT_LAN,
1439 + .get = esw_get_port_bool,
1442 + .type = SWITCH_TYPE_INT,
1443 + .name = "recv_bad",
1444 + .description = "Receive bad packet counter",
1445 + .id = RT305X_ESW_ATTR_PORT_RECV_BAD,
1446 + .get = esw_get_port_recv_badgood,
1449 + .type = SWITCH_TYPE_INT,
1450 + .name = "recv_good",
1451 + .description = "Receive good packet counter",
1452 + .id = RT305X_ESW_ATTR_PORT_RECV_GOOD,
1453 + .get = esw_get_port_recv_badgood,
1456 + .type = SWITCH_TYPE_INT,
1459 + .description = "Transmit bad packet counter. rt5350 only",
1460 + .id = RT5350_ESW_ATTR_PORT_TR_BAD,
1461 + .get = esw_get_port_tr_badgood,
1464 + .type = SWITCH_TYPE_INT,
1465 + .name = "tr_good",
1467 + .description = "Transmit good packet counter. rt5350 only",
1468 + .id = RT5350_ESW_ATTR_PORT_TR_GOOD,
1469 + .get = esw_get_port_tr_badgood,
1473 +static const struct switch_attr esw_vlan[] = {
1476 +static const struct switch_dev_ops esw_ops = {
1478 + .attr = esw_global,
1479 + .n_attr = ARRAY_SIZE(esw_global),
1483 + .n_attr = ARRAY_SIZE(esw_port),
1487 + .n_attr = ARRAY_SIZE(esw_vlan),
1489 + .get_vlan_ports = esw_get_vlan_ports,
1490 + .set_vlan_ports = esw_set_vlan_ports,
1491 + .get_port_pvid = esw_get_port_pvid,
1492 + .set_port_pvid = esw_set_port_pvid,
1493 + .get_port_link = esw_get_port_link,
1494 + .apply_config = esw_apply_config,
1495 + .reset_switch = esw_reset_switch,
1498 +static struct rt305x_esw_platform_data rt3050_esw_data = {
1499 + /* All ports are LAN ports. */
1500 + .vlan_config = RT305X_ESW_VLAN_CONFIG_NONE,
1501 + .reg_initval_fct2 = 0x00d6500c,
1503 + * ext phy base addr 31, enable port 5 polling, rx/tx clock skew 1,
1504 + * turbo mii off, rgmi 3.3v off
1506 + * port6: enabled, gige, full-duplex, rx/tx-flow-control
1508 + .reg_initval_fpa2 = 0x3f502b28,
1511 +static const struct of_device_id ralink_esw_match[] = {
1512 + { .compatible = "ralink,rt3050-esw", .data = &rt3050_esw_data },
1515 +MODULE_DEVICE_TABLE(of, ralink_esw_match);
1517 +static int esw_probe(struct platform_device *pdev)
1519 + struct device_node *np = pdev->dev.of_node;
1520 + const struct rt305x_esw_platform_data *pdata;
1521 + const __be32 *port_map, *reg_init;
1522 + struct rt305x_esw *esw;
1523 + struct switch_dev *swdev;
1524 + struct resource *res, *irq;
1527 + pdata = pdev->dev.platform_data;
1529 + const struct of_device_id *match;
1530 + match = of_match_device(ralink_esw_match, &pdev->dev);
1532 + pdata = (struct rt305x_esw_platform_data *) match->data;
1537 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1539 + dev_err(&pdev->dev, "no memory resource found\n");
1543 + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1545 + dev_err(&pdev->dev, "no irq resource found\n");
1549 + esw = kzalloc(sizeof(struct rt305x_esw), GFP_KERNEL);
1551 + dev_err(&pdev->dev, "no memory for private data\n");
1555 + esw->dev = &pdev->dev;
1556 + esw->irq = irq->start;
1557 + esw->base = ioremap(res->start, resource_size(res));
1559 + dev_err(&pdev->dev, "ioremap failed\n");
1564 + port_map = of_get_property(np, "ralink,portmap", NULL);
1566 + esw->port_map = be32_to_cpu(*port_map);
1568 + reg_init = of_get_property(np, "ralink,fct2", NULL);
1570 + esw->reg_initval_fct2 = be32_to_cpu(*reg_init);
1572 + reg_init = of_get_property(np, "ralink,fpa2", NULL);
1574 + esw->reg_initval_fpa2 = be32_to_cpu(*reg_init);
1576 + reg_init = of_get_property(np, "ralink,led_polarity", NULL);
1578 + esw->reg_led_polarity = be32_to_cpu(*reg_init);
1580 + swdev = &esw->swdev;
1581 + swdev->of_node = pdev->dev.of_node;
1582 + swdev->name = "rt305x-esw";
1583 + swdev->alias = "rt305x";
1584 + swdev->cpu_port = RT305X_ESW_PORT6;
1585 + swdev->ports = RT305X_ESW_NUM_PORTS;
1586 + swdev->vlans = RT305X_ESW_NUM_VIDS;
1587 + swdev->ops = &esw_ops;
1589 + err = register_switch(swdev, NULL);
1591 + dev_err(&pdev->dev, "register_switch failed\n");
1595 + platform_set_drvdata(pdev, esw);
1597 + esw->pdata = pdata;
1598 + spin_lock_init(&esw->reg_rw_lock);
1602 + esw_w32(esw, RT305X_ESW_PORT_ST_CHG, RT305X_ESW_REG_ISR);
1603 + esw_w32(esw, ~RT305X_ESW_PORT_ST_CHG, RT305X_ESW_REG_IMR);
1604 + request_irq(esw->irq, esw_interrupt, 0, "esw", esw);
1609 + iounmap(esw->base);
1615 +static int esw_remove(struct platform_device *pdev)
1617 + struct rt305x_esw *esw;
1619 + esw = platform_get_drvdata(pdev);
1621 + unregister_switch(&esw->swdev);
1622 + platform_set_drvdata(pdev, NULL);
1623 + iounmap(esw->base);
1630 +static struct platform_driver esw_driver = {
1631 + .probe = esw_probe,
1632 + .remove = esw_remove,
1634 + .name = "rt305x-esw",
1635 + .owner = THIS_MODULE,
1636 + .of_match_table = ralink_esw_match,
1640 +int __init rtesw_init(void)
1642 + return platform_driver_register(&esw_driver);
1645 +void rtesw_exit(void)
1647 + platform_driver_unregister(&esw_driver);
1649 Index: linux-3.14.18/drivers/net/ethernet/ralink/esw_rt3052.h
1650 ===================================================================
1651 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1652 +++ linux-3.14.18/drivers/net/ethernet/ralink/esw_rt3052.h 2014-10-28 10:43:11.886131208 +0100
1655 + * This program is free software; you can redistribute it and/or modify
1656 + * it under the terms of the GNU General Public License as published by
1657 + * the Free Software Foundation; version 2 of the License
1659 + * This program is distributed in the hope that it will be useful,
1660 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1661 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1662 + * GNU General Public License for more details.
1664 + * You should have received a copy of the GNU General Public License
1665 + * along with this program; if not, write to the Free Software
1666 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
1668 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
1671 +#ifndef _RALINK_ESW_RT3052_H__
1672 +#define _RALINK_ESW_RT3052_H__
1674 +#ifdef CONFIG_NET_RALINK_ESW_RT3052
1676 +int __init rtesw_init(void);
1677 +void rtesw_exit(void);
1681 +static inline int __init rtesw_init(void) { return 0; }
1682 +static inline void rtesw_exit(void) { }
1686 Index: linux-3.14.18/drivers/net/ethernet/ralink/gsw_mt7620a.c
1687 ===================================================================
1688 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1689 +++ linux-3.14.18/drivers/net/ethernet/ralink/gsw_mt7620a.c 2014-10-29 14:58:32.303564882 +0100
1692 + * This program is free software; you can redistribute it and/or modify
1693 + * it under the terms of the GNU General Public License as published by
1694 + * the Free Software Foundation; version 2 of the License
1696 + * This program is distributed in the hope that it will be useful,
1697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1699 + * GNU General Public License for more details.
1701 + * You should have received a copy of the GNU General Public License
1702 + * along with this program; if not, write to the Free Software
1703 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
1705 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
1708 +#include <linux/module.h>
1709 +#include <linux/kernel.h>
1710 +#include <linux/types.h>
1711 +#include <linux/dma-mapping.h>
1712 +#include <linux/init.h>
1713 +#include <linux/skbuff.h>
1714 +#include <linux/etherdevice.h>
1715 +#include <linux/ethtool.h>
1716 +#include <linux/platform_device.h>
1717 +#include <linux/of_device.h>
1718 +#include <linux/clk.h>
1719 +#include <linux/of_net.h>
1720 +#include <linux/of_mdio.h>
1721 +#include <linux/of_irq.h>
1722 +#include <linux/of_address.h>
1723 +#include <linux/switch.h>
1725 +#include <asm/mach-ralink/ralink_regs.h>
1727 +#include "ralink_soc_eth.h"
1729 +#include <linux/ioport.h>
1730 +#include <linux/switch.h>
1731 +#include <linux/mii.h>
1733 +#include <ralink_regs.h>
1734 +#include <asm/mach-ralink/mt7620.h>
1736 +#include "ralink_soc_eth.h"
1737 +#include "gsw_mt7620a.h"
1738 +#include "mt7530.h"
1741 +#define GSW_REG_PHY_TIMEOUT (5 * HZ)
1743 +#define MT7620A_GSW_REG_PIAC 0x7004
1745 +#define GSW_NUM_VLANS 16
1746 +#define GSW_NUM_VIDS 4096
1747 +#define GSW_NUM_PORTS 7
1748 +#define GSW_PORT6 6
1750 +#define GSW_MDIO_ACCESS BIT(31)
1751 +#define GSW_MDIO_READ BIT(19)
1752 +#define GSW_MDIO_WRITE BIT(18)
1753 +#define GSW_MDIO_START BIT(16)
1754 +#define GSW_MDIO_ADDR_SHIFT 20
1755 +#define GSW_MDIO_REG_SHIFT 25
1757 +#define GSW_REG_PORT_PMCR(x) (0x3000 + (x * 0x100))
1758 +#define GSW_REG_PORT_STATUS(x) (0x3008 + (x * 0x100))
1759 +#define GSW_REG_SMACCR0 0x3fE4
1760 +#define GSW_REG_SMACCR1 0x3fE8
1761 +#define GSW_REG_CKGCR 0x3ff0
1763 +#define GSW_REG_IMR 0x7008
1764 +#define GSW_REG_ISR 0x700c
1766 +#define SYSC_REG_CFG1 0x14
1768 +#define PORT_IRQ_ST_CHG 0x7f
1770 +#define SYSCFG1 0x14
1772 +#define ESW_PHY_POLLING 0x7000
1774 +#define PMCR_IPG BIT(18)
1775 +#define PMCR_MAC_MODE BIT(16)
1776 +#define PMCR_FORCE BIT(15)
1777 +#define PMCR_TX_EN BIT(14)
1778 +#define PMCR_RX_EN BIT(13)
1779 +#define PMCR_BACKOFF BIT(9)
1780 +#define PMCR_BACKPRES BIT(8)
1781 +#define PMCR_RX_FC BIT(5)
1782 +#define PMCR_TX_FC BIT(4)
1783 +#define PMCR_SPEED(_x) (_x << 2)
1784 +#define PMCR_DUPLEX BIT(1)
1785 +#define PMCR_LINK BIT(0)
1787 +#define PHY_AN_EN BIT(31)
1788 +#define PHY_PRE_EN BIT(30)
1789 +#define PMY_MDC_CONF(_x) ((_x & 0x3f) << 24)
1792 + /* Global attributes. */
1793 + GSW_ATTR_ENABLE_VLAN,
1794 + /* Port attributes. */
1795 + GSW_ATTR_PORT_UNTAG,
1803 +struct mt7620_gsw {
1804 + struct device *dev;
1805 + void __iomem *base;
1808 + long unsigned int autopoll;
1811 +static inline void gsw_w32(struct mt7620_gsw *gsw, u32 val, unsigned reg)
1813 + iowrite32(val, gsw->base + reg);
1816 +static inline u32 gsw_r32(struct mt7620_gsw *gsw, unsigned reg)
1818 + return ioread32(gsw->base + reg);
1821 +static int mt7620_mii_busy_wait(struct mt7620_gsw *gsw)
1823 + unsigned long t_start = jiffies;
1826 + if (!(gsw_r32(gsw, MT7620A_GSW_REG_PIAC) & GSW_MDIO_ACCESS))
1828 + if (time_after(jiffies, t_start + GSW_REG_PHY_TIMEOUT)) {
1833 + printk(KERN_ERR "mdio: MDIO timeout\n");
1837 +static u32 _mt7620_mii_write(struct mt7620_gsw *gsw, u32 phy_addr, u32 phy_register,
1840 + if (mt7620_mii_busy_wait(gsw))
1843 + write_data &= 0xffff;
1845 + gsw_w32(gsw, GSW_MDIO_ACCESS | GSW_MDIO_START | GSW_MDIO_WRITE |
1846 + (phy_register << GSW_MDIO_REG_SHIFT) |
1847 + (phy_addr << GSW_MDIO_ADDR_SHIFT) | write_data,
1848 + MT7620A_GSW_REG_PIAC);
1850 + if (mt7620_mii_busy_wait(gsw))
1856 +static u32 _mt7620_mii_read(struct mt7620_gsw *gsw, int phy_addr, int phy_reg)
1860 + if (mt7620_mii_busy_wait(gsw))
1863 + gsw_w32(gsw, GSW_MDIO_ACCESS | GSW_MDIO_START | GSW_MDIO_READ |
1864 + (phy_reg << GSW_MDIO_REG_SHIFT) |
1865 + (phy_addr << GSW_MDIO_ADDR_SHIFT),
1866 + MT7620A_GSW_REG_PIAC);
1868 + if (mt7620_mii_busy_wait(gsw))
1871 + d = gsw_r32(gsw, MT7620A_GSW_REG_PIAC) & 0xffff;
1876 +int mt7620_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val)
1878 + struct fe_priv *priv = bus->priv;
1879 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1881 + return _mt7620_mii_write(gsw, phy_addr, phy_reg, val);
1884 +int mt7620_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg)
1886 + struct fe_priv *priv = bus->priv;
1887 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1889 + return _mt7620_mii_read(gsw, phy_addr, phy_reg);
1892 +static unsigned char *fe_speed_str(int speed)
1909 +int mt7620a_has_carrier(struct fe_priv *priv)
1911 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1914 + for (i = 0; i < GSW_PORT6; i++)
1915 + if (gsw_r32(gsw, GSW_REG_PORT_STATUS(i)) & 0x1)
1920 +static void mt7620a_handle_carrier(struct fe_priv *priv)
1925 + if (mt7620a_has_carrier(priv))
1926 + netif_carrier_on(priv->netdev);
1928 + netif_carrier_off(priv->netdev);
1931 +void mt7620_mdio_link_adjust(struct fe_priv *priv, int port)
1933 + if (priv->link[port])
1934 + netdev_info(priv->netdev, "port %d link up (%sMbps/%s duplex)\n",
1935 + port, fe_speed_str(priv->phy->speed[port]),
1936 + (DUPLEX_FULL == priv->phy->duplex[port]) ? "Full" : "Half");
1938 + netdev_info(priv->netdev, "port %d link down\n", port);
1939 + mt7620a_handle_carrier(priv);
1942 +static irqreturn_t gsw_interrupt(int irq, void *_priv)
1944 + struct fe_priv *priv = (struct fe_priv *) _priv;
1945 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1947 + int i, max = (gsw->port4 == PORT4_EPHY) ? (4) : (3);
1949 + status = gsw_r32(gsw, GSW_REG_ISR);
1950 + if (status & PORT_IRQ_ST_CHG)
1951 + for (i = 0; i <= max; i++) {
1952 + u32 status = gsw_r32(gsw, GSW_REG_PORT_STATUS(i));
1953 + int link = status & 0x1;
1955 + if (link != priv->link[i]) {
1957 + netdev_info(priv->netdev, "port %d link up (%sMbps/%s duplex)\n",
1958 + i, fe_speed_str((status >> 2) & 3),
1959 + (status & 0x2) ? "Full" : "Half");
1961 + netdev_info(priv->netdev, "port %d link down\n", i);
1964 + priv->link[i] = link;
1966 + mt7620a_handle_carrier(priv);
1968 + gsw_w32(gsw, status, GSW_REG_ISR);
1970 + return IRQ_HANDLED;
1973 +static int mt7620_is_bga(void)
1975 + u32 bga = rt_sysc_r32(0x0c);
1977 + return (bga >> 16) & 1;
1980 +static void gsw_auto_poll(struct mt7620_gsw *gsw)
1983 + int lsb = -1, msb = 0;
1985 + for_each_set_bit(phy, &gsw->autopoll, 32) {
1991 + gsw_w32(gsw, PHY_AN_EN | PHY_PRE_EN | PMY_MDC_CONF(5) | (msb << 8) | lsb, ESW_PHY_POLLING);
1994 +void mt7620_port_init(struct fe_priv *priv, struct device_node *np)
1996 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
1997 + const __be32 *_id = of_get_property(np, "reg", NULL);
1998 + int phy_mode, size, id;
2000 + u32 val, mask = 0;
2001 + int min = (gsw->port4 == PORT4_EPHY) ? (5) : (4);
2003 + if (!_id || (be32_to_cpu(*_id) < min) || (be32_to_cpu(*_id) > 5)) {
2005 + pr_err("%s: invalid port id %d\n", np->name, be32_to_cpu(*_id));
2007 + pr_err("%s: invalid port id\n", np->name);
2011 + id = be32_to_cpu(*_id);
2016 + priv->phy->phy_fixed[id] = of_get_property(np, "ralink,fixed-link", &size);
2017 + if (priv->phy->phy_fixed[id] && (size != (4 * sizeof(*priv->phy->phy_fixed[id])))) {
2018 + pr_err("%s: invalid fixed link property\n", np->name);
2019 + priv->phy->phy_fixed[id] = NULL;
2023 + phy_mode = of_get_phy_mode(np);
2024 + switch (phy_mode) {
2025 + case PHY_INTERFACE_MODE_RGMII:
2028 + case PHY_INTERFACE_MODE_MII:
2031 + case PHY_INTERFACE_MODE_RMII:
2035 + dev_err(priv->device, "port %d - invalid phy mode\n", id);
2039 + priv->phy->phy_node[id] = of_parse_phandle(np, "phy-handle", 0);
2040 + if (!priv->phy->phy_node[id] && !priv->phy->phy_fixed[id])
2043 + val = rt_sysc_r32(SYSCFG1);
2044 + val &= ~(3 << shift);
2045 + val |= mask << shift;
2046 + rt_sysc_w32(val, SYSCFG1);
2048 + if (priv->phy->phy_fixed[id]) {
2049 + const __be32 *link = priv->phy->phy_fixed[id];
2053 + priv->phy->speed[id] = be32_to_cpup(link++);
2054 + tx_fc = be32_to_cpup(link++);
2055 + rx_fc = be32_to_cpup(link++);
2056 + priv->phy->duplex[id] = be32_to_cpup(link++);
2057 + priv->link[id] = 1;
2059 + switch (priv->phy->speed[id]) {
2070 + dev_err(priv->device, "invalid link speed: %d\n", priv->phy->speed[id]);
2071 + priv->phy->phy_fixed[id] = 0;
2074 + val = PMCR_SPEED(val);
2075 + val |= PMCR_LINK | PMCR_BACKPRES | PMCR_BACKOFF | PMCR_RX_EN |
2076 + PMCR_TX_EN | PMCR_FORCE | PMCR_MAC_MODE | PMCR_IPG;
2078 + val |= PMCR_TX_FC;
2080 + val |= PMCR_RX_FC;
2081 + if (priv->phy->duplex[id])
2082 + val |= PMCR_DUPLEX;
2083 + gsw_w32(gsw, val, GSW_REG_PORT_PMCR(id));
2084 + dev_info(priv->device, "using fixed link parameters\n");
2088 + if (priv->phy->phy_node[id] && priv->mii_bus->phy_map[id]) {
2089 + u32 val = PMCR_BACKPRES | PMCR_BACKOFF | PMCR_RX_EN |
2090 + PMCR_TX_EN | PMCR_MAC_MODE | PMCR_IPG;
2092 + gsw_w32(gsw, val, GSW_REG_PORT_PMCR(id));
2093 + fe_connect_phy_node(priv, priv->phy->phy_node[id]);
2094 + gsw->autopoll |= BIT(id);
2095 + gsw_auto_poll(gsw);
2100 +static void gsw_hw_init(struct mt7620_gsw *gsw)
2102 + u32 is_BGA = mt7620_is_bga();
2104 + rt_sysc_w32(rt_sysc_r32(SYSC_REG_CFG1) | BIT(8), SYSC_REG_CFG1);
2105 + gsw_w32(gsw, gsw_r32(gsw, GSW_REG_CKGCR) & ~(0x3 << 4), GSW_REG_CKGCR);
2107 + /*correct PHY setting L3.0 BGA*/
2108 + _mt7620_mii_write(gsw, 1, 31, 0x4000); //global, page 4
2110 + _mt7620_mii_write(gsw, 1, 17, 0x7444);
2112 + _mt7620_mii_write(gsw, 1, 19, 0x0114);
2114 + _mt7620_mii_write(gsw, 1, 19, 0x0117);
2116 + _mt7620_mii_write(gsw, 1, 22, 0x10cf);
2117 + _mt7620_mii_write(gsw, 1, 25, 0x6212);
2118 + _mt7620_mii_write(gsw, 1, 26, 0x0777);
2119 + _mt7620_mii_write(gsw, 1, 29, 0x4000);
2120 + _mt7620_mii_write(gsw, 1, 28, 0xc077);
2121 + _mt7620_mii_write(gsw, 1, 24, 0x0000);
2123 + _mt7620_mii_write(gsw, 1, 31, 0x3000); //global, page 3
2124 + _mt7620_mii_write(gsw, 1, 17, 0x4838);
2126 + _mt7620_mii_write(gsw, 1, 31, 0x2000); //global, page 2
2128 + _mt7620_mii_write(gsw, 1, 21, 0x0515);
2129 + _mt7620_mii_write(gsw, 1, 22, 0x0053);
2130 + _mt7620_mii_write(gsw, 1, 23, 0x00bf);
2131 + _mt7620_mii_write(gsw, 1, 24, 0x0aaf);
2132 + _mt7620_mii_write(gsw, 1, 25, 0x0fad);
2133 + _mt7620_mii_write(gsw, 1, 26, 0x0fc1);
2135 + _mt7620_mii_write(gsw, 1, 21, 0x0517);
2136 + _mt7620_mii_write(gsw, 1, 22, 0x0fd2);
2137 + _mt7620_mii_write(gsw, 1, 23, 0x00bf);
2138 + _mt7620_mii_write(gsw, 1, 24, 0x0aab);
2139 + _mt7620_mii_write(gsw, 1, 25, 0x00ae);
2140 + _mt7620_mii_write(gsw, 1, 26, 0x0fff);
2142 + _mt7620_mii_write(gsw, 1, 31, 0x1000); //global, page 1
2143 + _mt7620_mii_write(gsw, 1, 17, 0xe7f8);
2145 + _mt7620_mii_write(gsw, 1, 31, 0x8000); //local, page 0
2146 + _mt7620_mii_write(gsw, 0, 30, 0xa000);
2147 + _mt7620_mii_write(gsw, 1, 30, 0xa000);
2148 + _mt7620_mii_write(gsw, 2, 30, 0xa000);
2149 + _mt7620_mii_write(gsw, 3, 30, 0xa000);
2151 + _mt7620_mii_write(gsw, 0, 4, 0x05e1);
2152 + _mt7620_mii_write(gsw, 1, 4, 0x05e1);
2153 + _mt7620_mii_write(gsw, 2, 4, 0x05e1);
2154 + _mt7620_mii_write(gsw, 3, 4, 0x05e1);
2155 + _mt7620_mii_write(gsw, 1, 31, 0xa000); //local, page 2
2156 + _mt7620_mii_write(gsw, 0, 16, 0x1111);
2157 + _mt7620_mii_write(gsw, 1, 16, 0x1010);
2158 + _mt7620_mii_write(gsw, 2, 16, 0x1515);
2159 + _mt7620_mii_write(gsw, 3, 16, 0x0f0f);
2161 + /* CPU Port6 Force Link 1G, FC ON */
2162 + gsw_w32(gsw, 0x5e33b, GSW_REG_PORT_PMCR(6));
2163 + /* Set Port6 CPU Port */
2164 + gsw_w32(gsw, 0x7f7f7fe0, 0x0010);
2166 + /* setup port 4 */
2167 + if (gsw->port4 == PORT4_EPHY) {
2168 + u32 val = rt_sysc_r32(SYSCFG1);
2170 + rt_sysc_w32(val, SYSCFG1);
2171 + _mt7620_mii_write(gsw, 4, 30, 0xa000);
2172 + _mt7620_mii_write(gsw, 4, 4, 0x05e1);
2173 + _mt7620_mii_write(gsw, 4, 16, 0x1313);
2174 + pr_info("gsw: setting port4 to ephy mode\n");
2178 +void mt7620_set_mac(struct fe_priv *priv, unsigned char *mac)
2180 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
2181 + unsigned long flags;
2183 + spin_lock_irqsave(&priv->page_lock, flags);
2184 + gsw_w32(gsw, (mac[0] << 8) | mac[1], GSW_REG_SMACCR1);
2185 + gsw_w32(gsw, (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
2187 + spin_unlock_irqrestore(&priv->page_lock, flags);
2190 +static struct of_device_id gsw_match[] = {
2191 + { .compatible = "ralink,mt7620a-gsw" },
2195 +int mt7620_gsw_config(struct fe_priv *priv)
2197 + struct mt7620_gsw *gsw = (struct mt7620_gsw *) priv->soc->swpriv;
2199 + /* is the mt7530 internal or external */
2200 + if ((_mt7620_mii_read(gsw, 0x1f, 2) == 1) && (_mt7620_mii_read(gsw, 0x1f, 3) == 0xbeef)) {
2201 + mt7530_probe(priv->device, gsw->base, NULL, 0);
2202 + mt7530_probe(priv->device, NULL, priv->mii_bus, 1);
2204 + mt7530_probe(priv->device, gsw->base, NULL, 1);
2210 +int mt7620_gsw_probe(struct fe_priv *priv)
2212 + struct mt7620_gsw *gsw;
2213 + struct device_node *np;
2214 + const char *port4 = NULL;
2216 + np = of_find_matching_node(NULL, gsw_match);
2218 + dev_err(priv->device, "no gsw node found\n");
2221 + np = of_node_get(np);
2223 + gsw = devm_kzalloc(priv->device, sizeof(struct mt7620_gsw), GFP_KERNEL);
2225 + dev_err(priv->device, "no gsw memory for private data\n");
2229 + gsw->irq = irq_of_parse_and_map(np, 0);
2231 + dev_err(priv->device, "no gsw irq resource found\n");
2235 + gsw->base = of_iomap(np, 0);
2237 + dev_err(priv->device, "gsw ioremap failed\n");
2241 + gsw->dev = priv->device;
2242 + priv->soc->swpriv = gsw;
2244 + of_property_read_string(np, "ralink,port4", &port4);
2245 + if (port4 && !strcmp(port4, "ephy"))
2246 + gsw->port4 = PORT4_EPHY;
2247 + else if (port4 && !strcmp(port4, "gmac"))
2248 + gsw->port4 = PORT4_EXT;
2254 + gsw_w32(gsw, ~PORT_IRQ_ST_CHG, GSW_REG_IMR);
2255 + request_irq(gsw->irq, gsw_interrupt, 0, "gsw", priv);
2259 Index: linux-3.14.18/drivers/net/ethernet/ralink/gsw_mt7620a.h
2260 ===================================================================
2261 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2262 +++ linux-3.14.18/drivers/net/ethernet/ralink/gsw_mt7620a.h 2014-10-28 10:43:11.890131215 +0100
2265 + * This program is free software; you can redistribute it and/or modify
2266 + * it under the terms of the GNU General Public License as published by
2267 + * the Free Software Foundation; version 2 of the License
2269 + * This program is distributed in the hope that it will be useful,
2270 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2271 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2272 + * GNU General Public License for more details.
2274 + * You should have received a copy of the GNU General Public License
2275 + * along with this program; if not, write to the Free Software
2276 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2278 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2281 +#ifndef _RALINK_GSW_MT7620_H__
2282 +#define _RALINK_GSW_MT7620_H__
2284 +extern int mt7620_gsw_config(struct fe_priv *priv);
2285 +extern int mt7620_gsw_probe(struct fe_priv *priv);
2286 +extern void mt7620_set_mac(struct fe_priv *priv, unsigned char *mac);
2287 +extern int mt7620_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val);
2288 +extern int mt7620_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg);
2289 +extern void mt7620_mdio_link_adjust(struct fe_priv *priv, int port);
2290 +extern void mt7620_port_init(struct fe_priv *priv, struct device_node *np);
2291 +extern int mt7620a_has_carrier(struct fe_priv *priv);
2294 Index: linux-3.14.18/drivers/net/ethernet/ralink/mdio.c
2295 ===================================================================
2296 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2297 +++ linux-3.14.18/drivers/net/ethernet/ralink/mdio.c 2014-10-28 10:43:11.890131215 +0100
2300 + * This program is free software; you can redistribute it and/or modify
2301 + * it under the terms of the GNU General Public License as published by
2302 + * the Free Software Foundation; version 2 of the License
2304 + * This program is distributed in the hope that it will be useful,
2305 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2306 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2307 + * GNU General Public License for more details.
2309 + * You should have received a copy of the GNU General Public License
2310 + * along with this program; if not, write to the Free Software
2311 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2313 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2316 +#include <linux/module.h>
2317 +#include <linux/kernel.h>
2318 +#include <linux/types.h>
2319 +#include <linux/dma-mapping.h>
2320 +#include <linux/init.h>
2321 +#include <linux/skbuff.h>
2322 +#include <linux/etherdevice.h>
2323 +#include <linux/ethtool.h>
2324 +#include <linux/platform_device.h>
2325 +#include <linux/phy.h>
2326 +#include <linux/of_device.h>
2327 +#include <linux/clk.h>
2328 +#include <linux/of_net.h>
2329 +#include <linux/of_mdio.h>
2331 +#include "ralink_soc_eth.h"
2334 +static int fe_mdio_reset(struct mii_bus *bus)
2340 +static void fe_phy_link_adjust(struct net_device *dev)
2342 + struct fe_priv *priv = netdev_priv(dev);
2343 + unsigned long flags;
2346 + spin_lock_irqsave(&priv->phy->lock, flags);
2347 + for (i = 0; i < 8; i++) {
2348 + if (priv->phy->phy_node[i]) {
2349 + struct phy_device *phydev = priv->phy->phy[i];
2350 + int status_change = 0;
2353 + if (priv->phy->duplex[i] != phydev->duplex ||
2354 + priv->phy->speed[i] != phydev->speed)
2355 + status_change = 1;
2357 + if (phydev->link != priv->link[i])
2358 + status_change = 1;
2360 + switch (phydev->speed) {
2364 + priv->link[i] = phydev->link;
2365 + priv->phy->duplex[i] = phydev->duplex;
2366 + priv->phy->speed[i] = phydev->speed;
2368 + if (status_change && priv->soc->mdio_adjust_link)
2369 + priv->soc->mdio_adjust_link(priv, i);
2376 +int fe_connect_phy_node(struct fe_priv *priv, struct device_node *phy_node)
2378 + const __be32 *_port = NULL;
2379 + struct phy_device *phydev;
2380 + int phy_mode, port;
2382 + _port = of_get_property(phy_node, "reg", NULL);
2384 + if (!_port || (be32_to_cpu(*_port) >= 0x20)) {
2385 + pr_err("%s: invalid port id\n", phy_node->name);
2388 + port = be32_to_cpu(*_port);
2389 + phy_mode = of_get_phy_mode(phy_node);
2390 + if (phy_mode < 0) {
2391 + dev_err(priv->device, "incorrect phy-mode %d\n", phy_mode);
2392 + priv->phy->phy_node[port] = NULL;
2396 + phydev = of_phy_connect(priv->netdev, phy_node, fe_phy_link_adjust,
2398 + if (IS_ERR(phydev)) {
2399 + dev_err(priv->device, "could not connect to PHY\n");
2400 + priv->phy->phy_node[port] = NULL;
2401 + return PTR_ERR(phydev);
2404 + phydev->supported &= PHY_GBIT_FEATURES;
2405 + phydev->advertising = phydev->supported;
2406 + phydev->no_auto_carrier_off = 1;
2408 + dev_info(priv->device,
2409 + "connected port %d to PHY at %s [uid=%08x, driver=%s]\n",
2410 + port, dev_name(&phydev->dev), phydev->phy_id,
2411 + phydev->drv->name);
2413 + priv->phy->phy[port] = phydev;
2414 + priv->link[port] = 0;
2419 +static int fe_phy_connect(struct fe_priv *priv)
2424 +static void fe_phy_disconnect(struct fe_priv *priv)
2426 + unsigned long flags;
2429 + for (i = 0; i < 8; i++)
2430 + if (priv->phy->phy_fixed[i]) {
2431 + spin_lock_irqsave(&priv->phy->lock, flags);
2432 + priv->link[i] = 0;
2433 + if (priv->soc->mdio_adjust_link)
2434 + priv->soc->mdio_adjust_link(priv, i);
2435 + spin_unlock_irqrestore(&priv->phy->lock, flags);
2436 + } else if (priv->phy->phy[i]) {
2437 + phy_disconnect(priv->phy->phy[i]);
2441 +static void fe_phy_start(struct fe_priv *priv)
2443 + unsigned long flags;
2446 + for (i = 0; i < 8; i++) {
2447 + if (priv->phy->phy_fixed[i]) {
2448 + spin_lock_irqsave(&priv->phy->lock, flags);
2449 + priv->link[i] = 1;
2450 + if (priv->soc->mdio_adjust_link)
2451 + priv->soc->mdio_adjust_link(priv, i);
2452 + spin_unlock_irqrestore(&priv->phy->lock, flags);
2453 + } else if (priv->phy->phy[i]) {
2454 + phy_start(priv->phy->phy[i]);
2459 +static void fe_phy_stop(struct fe_priv *priv)
2461 + unsigned long flags;
2464 + for (i = 0; i < 8; i++)
2465 + if (priv->phy->phy_fixed[i]) {
2466 + spin_lock_irqsave(&priv->phy->lock, flags);
2467 + priv->link[i] = 0;
2468 + if (priv->soc->mdio_adjust_link)
2469 + priv->soc->mdio_adjust_link(priv, i);
2470 + spin_unlock_irqrestore(&priv->phy->lock, flags);
2471 + } else if (priv->phy->phy[i]) {
2472 + phy_stop(priv->phy->phy[i]);
2476 +static struct fe_phy phy_ralink = {
2477 + .connect = fe_phy_connect,
2478 + .disconnect = fe_phy_disconnect,
2479 + .start = fe_phy_start,
2480 + .stop = fe_phy_stop,
2483 +int fe_mdio_init(struct fe_priv *priv)
2485 + struct device_node *mii_np;
2488 + if (!priv->soc->mdio_read || !priv->soc->mdio_write)
2491 + spin_lock_init(&phy_ralink.lock);
2492 + priv->phy = &phy_ralink;
2494 + mii_np = of_get_child_by_name(priv->device->of_node, "mdio-bus");
2496 + dev_err(priv->device, "no %s child node found", "mdio-bus");
2500 + if (!of_device_is_available(mii_np)) {
2502 + goto err_put_node;
2505 + priv->mii_bus = mdiobus_alloc();
2506 + if (priv->mii_bus == NULL) {
2508 + goto err_put_node;
2511 + priv->mii_bus->name = "mdio";
2512 + priv->mii_bus->read = priv->soc->mdio_read;
2513 + priv->mii_bus->write = priv->soc->mdio_write;
2514 + priv->mii_bus->reset = fe_mdio_reset;
2515 + priv->mii_bus->irq = priv->mii_irq;
2516 + priv->mii_bus->priv = priv;
2517 + priv->mii_bus->parent = priv->device;
2519 + snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s", mii_np->name);
2520 + err = of_mdiobus_register(priv->mii_bus, mii_np);
2522 + goto err_free_bus;
2527 + kfree(priv->mii_bus);
2529 + of_node_put(mii_np);
2530 + priv->mii_bus = NULL;
2534 +void fe_mdio_cleanup(struct fe_priv *priv)
2536 + if (!priv->mii_bus)
2539 + mdiobus_unregister(priv->mii_bus);
2540 + of_node_put(priv->mii_bus->dev.of_node);
2541 + kfree(priv->mii_bus);
2543 Index: linux-3.14.18/drivers/net/ethernet/ralink/mdio.h
2544 ===================================================================
2545 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2546 +++ linux-3.14.18/drivers/net/ethernet/ralink/mdio.h 2014-10-28 10:43:11.890131215 +0100
2549 + * This program is free software; you can redistribute it and/or modify
2550 + * it under the terms of the GNU General Public License as published by
2551 + * the Free Software Foundation; version 2 of the License
2553 + * This program is distributed in the hope that it will be useful,
2554 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2555 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2556 + * GNU General Public License for more details.
2558 + * You should have received a copy of the GNU General Public License
2559 + * along with this program; if not, write to the Free Software
2560 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2562 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2565 +#ifndef _RALINK_MDIO_H__
2566 +#define _RALINK_MDIO_H__
2568 +#ifdef CONFIG_NET_RALINK_MDIO
2569 +extern int fe_mdio_init(struct fe_priv *priv);
2570 +extern void fe_mdio_cleanup(struct fe_priv *priv);
2571 +extern int fe_connect_phy_node(struct fe_priv *priv, struct device_node *phy_node);
2573 +static inline int fe_mdio_init(struct fe_priv *priv) { return 0; }
2574 +static inline void fe_mdio_cleanup(struct fe_priv *priv) {}
2577 Index: linux-3.14.18/drivers/net/ethernet/ralink/mdio_rt2880.c
2578 ===================================================================
2579 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2580 +++ linux-3.14.18/drivers/net/ethernet/ralink/mdio_rt2880.c 2014-10-28 10:43:11.890131215 +0100
2583 + * This program is free software; you can redistribute it and/or modify
2584 + * it under the terms of the GNU General Public License as published by
2585 + * the Free Software Foundation; version 2 of the License
2587 + * This program is distributed in the hope that it will be useful,
2588 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2589 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2590 + * GNU General Public License for more details.
2592 + * You should have received a copy of the GNU General Public License
2593 + * along with this program; if not, write to the Free Software
2594 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2596 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2599 +#include <linux/module.h>
2600 +#include <linux/kernel.h>
2601 +#include <linux/types.h>
2602 +#include <linux/dma-mapping.h>
2603 +#include <linux/init.h>
2604 +#include <linux/skbuff.h>
2605 +#include <linux/etherdevice.h>
2606 +#include <linux/ethtool.h>
2607 +#include <linux/platform_device.h>
2608 +#include <linux/phy.h>
2609 +#include <linux/of_device.h>
2610 +#include <linux/clk.h>
2611 +#include <linux/of_net.h>
2612 +#include <linux/of_mdio.h>
2614 +#include "ralink_soc_eth.h"
2615 +#include "mdio_rt2880.h"
2618 +#define FE_MDIO_RETRY 1000
2620 +static unsigned char *rt2880_speed_str(struct fe_priv *priv)
2622 + switch (priv->phy->speed[0]) {
2634 +void rt2880_mdio_link_adjust(struct fe_priv *priv, int port)
2638 + if (!priv->link[0]) {
2639 + netif_carrier_off(priv->netdev);
2640 + netdev_info(priv->netdev, "link down\n");
2644 + mdio_cfg = FE_MDIO_CFG_TX_CLK_SKEW_200 |
2645 + FE_MDIO_CFG_RX_CLK_SKEW_200 |
2646 + FE_MDIO_CFG_GP1_FRC_EN;
2648 + if (priv->phy->duplex[0] == DUPLEX_FULL)
2649 + mdio_cfg |= FE_MDIO_CFG_GP1_DUPLEX;
2651 + if (priv->phy->tx_fc[0])
2652 + mdio_cfg |= FE_MDIO_CFG_GP1_FC_TX;
2654 + if (priv->phy->rx_fc[0])
2655 + mdio_cfg |= FE_MDIO_CFG_GP1_FC_RX;
2657 + switch (priv->phy->speed[0]) {
2659 + mdio_cfg |= FE_MDIO_CFG_GP1_SPEED_10;
2662 + mdio_cfg |= FE_MDIO_CFG_GP1_SPEED_100;
2665 + mdio_cfg |= FE_MDIO_CFG_GP1_SPEED_1000;
2671 + fe_w32(mdio_cfg, FE_MDIO_CFG);
2673 + netif_carrier_on(priv->netdev);
2674 + netdev_info(priv->netdev, "link up (%sMbps/%s duplex)\n",
2675 + rt2880_speed_str(priv),
2676 + (DUPLEX_FULL == priv->phy->duplex[0]) ? "Full" : "Half");
2679 +static int rt2880_mdio_wait_ready(struct fe_priv *priv)
2683 + retries = FE_MDIO_RETRY;
2687 + t = fe_r32(FE_MDIO_ACCESS);
2688 + if ((t & (0x1 << 31)) == 0)
2691 + if (retries-- == 0)
2697 + dev_err(priv->device, "MDIO operation timed out\n");
2698 + return -ETIMEDOUT;
2701 +int rt2880_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg)
2703 + struct fe_priv *priv = bus->priv;
2707 + err = rt2880_mdio_wait_ready(priv);
2711 + t = (phy_addr << 24) | (phy_reg << 16);
2712 + fe_w32(t, FE_MDIO_ACCESS);
2714 + fe_w32(t, FE_MDIO_ACCESS);
2716 + err = rt2880_mdio_wait_ready(priv);
2720 + pr_debug("%s: addr=%04x, reg=%04x, value=%04x\n", __func__,
2721 + phy_addr, phy_reg, fe_r32(FE_MDIO_ACCESS) & 0xffff);
2723 + return fe_r32(FE_MDIO_ACCESS) & 0xffff;
2726 +int rt2880_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val)
2728 + struct fe_priv *priv = bus->priv;
2732 + pr_debug("%s: addr=%04x, reg=%04x, value=%04x\n", __func__,
2733 + phy_addr, phy_reg, fe_r32(FE_MDIO_ACCESS) & 0xffff);
2735 + err = rt2880_mdio_wait_ready(priv);
2739 + t = (1 << 30) | (phy_addr << 24) | (phy_reg << 16) | val;
2740 + fe_w32(t, FE_MDIO_ACCESS);
2742 + fe_w32(t, FE_MDIO_ACCESS);
2744 + return rt2880_mdio_wait_ready(priv);
2747 +void rt2880_port_init(struct fe_priv *priv, struct device_node *np)
2749 + const __be32 *id = of_get_property(np, "reg", NULL);
2750 + const __be32 *link;
2754 + if (!id || (be32_to_cpu(*id) != 0)) {
2755 + pr_err("%s: invalid port id\n", np->name);
2759 + priv->phy->phy_fixed[0] = of_get_property(np, "ralink,fixed-link", &size);
2760 + if (priv->phy->phy_fixed[0] && (size != (4 * sizeof(*priv->phy->phy_fixed[0])))) {
2761 + pr_err("%s: invalid fixed link property\n", np->name);
2762 + priv->phy->phy_fixed[0] = NULL;
2766 + phy_mode = of_get_phy_mode(np);
2767 + switch (phy_mode) {
2768 + case PHY_INTERFACE_MODE_RGMII:
2770 + case PHY_INTERFACE_MODE_MII:
2772 + case PHY_INTERFACE_MODE_RMII:
2775 + if (!priv->phy->phy_fixed[0])
2776 + dev_err(priv->device, "port %d - invalid phy mode\n", priv->phy->speed[0]);
2780 + priv->phy->phy_node[0] = of_parse_phandle(np, "phy-handle", 0);
2781 + if (!priv->phy->phy_node[0] && !priv->phy->phy_fixed[0])
2784 + if (priv->phy->phy_fixed[0]) {
2785 + link = priv->phy->phy_fixed[0];
2786 + priv->phy->speed[0] = be32_to_cpup(link++);
2787 + priv->phy->duplex[0] = be32_to_cpup(link++);
2788 + priv->phy->tx_fc[0] = be32_to_cpup(link++);
2789 + priv->phy->rx_fc[0] = be32_to_cpup(link++);
2791 + priv->link[0] = 1;
2792 + switch (priv->phy->speed[0]) {
2800 + dev_err(priv->device, "invalid link speed: %d\n", priv->phy->speed[0]);
2801 + priv->phy->phy_fixed[0] = 0;
2804 + dev_info(priv->device, "using fixed link parameters\n");
2805 + rt2880_mdio_link_adjust(priv, 0);
2808 + if (priv->phy->phy_node[0] && priv->mii_bus->phy_map[0]) {
2809 + fe_connect_phy_node(priv, priv->phy->phy_node[0]);
2814 Index: linux-3.14.18/drivers/net/ethernet/ralink/mdio_rt2880.h
2815 ===================================================================
2816 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2817 +++ linux-3.14.18/drivers/net/ethernet/ralink/mdio_rt2880.h 2014-10-28 10:43:11.890131215 +0100
2820 + * This program is free software; you can redistribute it and/or modify
2821 + * it under the terms of the GNU General Public License as published by
2822 + * the Free Software Foundation; version 2 of the License
2824 + * This program is distributed in the hope that it will be useful,
2825 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2826 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2827 + * GNU General Public License for more details.
2829 + * You should have received a copy of the GNU General Public License
2830 + * along with this program; if not, write to the Free Software
2831 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
2833 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
2836 +#ifndef _RALINK_MDIO_RT2880_H__
2837 +#define _RALINK_MDIO_RT2880_H__
2839 +void rt2880_mdio_link_adjust(struct fe_priv *priv, int port);
2840 +int rt2880_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg);
2841 +int rt2880_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val);
2842 +void rt2880_port_init(struct fe_priv *priv, struct device_node *np);
2845 Index: linux-3.14.18/drivers/net/ethernet/ralink/mt7530.c
2846 ===================================================================
2847 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2848 +++ linux-3.14.18/drivers/net/ethernet/ralink/mt7530.c 2014-10-29 14:58:52.303587070 +0100
2851 + * This program is free software; you can redistribute it and/or
2852 + * modify it under the terms of the GNU General Public License
2853 + * as published by the Free Software Foundation; either version 2
2854 + * of the License, or (at your option) any later version.
2856 + * This program is distributed in the hope that it will be useful,
2857 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2858 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2859 + * GNU General Public License for more details.
2861 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
2864 +#include <linux/if.h>
2865 +#include <linux/module.h>
2866 +#include <linux/init.h>
2867 +#include <linux/list.h>
2868 +#include <linux/if_ether.h>
2869 +#include <linux/skbuff.h>
2870 +#include <linux/netdevice.h>
2871 +#include <linux/netlink.h>
2872 +#include <linux/bitops.h>
2873 +#include <net/genetlink.h>
2874 +#include <linux/switch.h>
2875 +#include <linux/delay.h>
2876 +#include <linux/phy.h>
2877 +#include <linux/netdevice.h>
2878 +#include <linux/etherdevice.h>
2879 +#include <linux/lockdep.h>
2880 +#include <linux/workqueue.h>
2881 +#include <linux/of_device.h>
2883 +#include "mt7530.h"
2885 +#define MT7530_CPU_PORT 6
2886 +#define MT7530_NUM_PORTS 8
2887 +#define MT7530_NUM_VLANS 16
2888 +#define MT7530_MAX_VID 4095
2889 +#define MT7530_MIN_VID 0
2892 +#define REG_ESW_VLAN_VTCR 0x90
2893 +#define REG_ESW_VLAN_VAWD1 0x94
2894 +#define REG_ESW_VLAN_VAWD2 0x98
2895 +#define REG_ESW_VLAN_VTIM(x) (0x100 + 4 * ((x) / 2))
2897 +#define REG_ESW_VLAN_VAWD1_IVL_MAC BIT(30)
2898 +#define REG_ESW_VLAN_VAWD1_VTAG_EN BIT(28)
2899 +#define REG_ESW_VLAN_VAWD1_VALID BIT(0)
2901 +/* vlan egress mode */
2903 + ETAG_CTRL_UNTAG = 0,
2904 + ETAG_CTRL_TAG = 2,
2905 + ETAG_CTRL_SWAP = 1,
2906 + ETAG_CTRL_STACK = 3,
2909 +#define REG_ESW_PORT_PCR(x) (0x2004 | ((x) << 8))
2910 +#define REG_ESW_PORT_PVC(x) (0x2010 | ((x) << 8))
2911 +#define REG_ESW_PORT_PPBV1(x) (0x2014 | ((x) << 8))
2913 + /* Global attributes. */
2914 + MT7530_ATTR_ENABLE_VLAN,
2917 +struct mt7530_port_entry {
2921 +struct mt7530_vlan_entry {
2927 +struct mt7530_priv {
2928 + void __iomem *base;
2929 + struct mii_bus *bus;
2930 + struct switch_dev swdev;
2932 + bool global_vlan_enable;
2933 + struct mt7530_vlan_entry vlan_entries[MT7530_NUM_VLANS];
2934 + struct mt7530_port_entry port_entries[MT7530_NUM_PORTS];
2937 +struct mt7530_mapping {
2939 + u16 pvids[MT7530_NUM_PORTS];
2940 + u8 members[MT7530_NUM_VLANS];
2941 + u8 etags[MT7530_NUM_VLANS];
2942 + u16 vids[MT7530_NUM_VLANS];
2943 +} mt7530_defaults[] = {
2946 + .pvids = { 1, 1, 1, 1, 2, 1, 1 },
2947 + .members = { 0, 0x6f, 0x50 },
2948 + .etags = { 0, 0x40, 0x40 },
2949 + .vids = { 0, 1, 2 },
2952 + .pvids = { 2, 1, 1, 1, 1, 1, 1 },
2953 + .members = { 0, 0x7e, 0x41 },
2954 + .etags = { 0, 0x40, 0x40 },
2955 + .vids = { 0, 1, 2 },
2959 +struct mt7530_mapping*
2960 +mt7530_find_mapping(struct device_node *np)
2965 + if (of_property_read_string(np, "ralink,port-map", &map))
2968 + for (i = 0; i < ARRAY_SIZE(mt7530_defaults); i++)
2969 + if (!strcmp(map, mt7530_defaults[i].name))
2970 + return &mt7530_defaults[i];
2976 +mt7530_apply_mapping(struct mt7530_priv *mt7530, struct mt7530_mapping *map)
2980 + for (i = 0; i < MT7530_NUM_PORTS; i++)
2981 + mt7530->port_entries[i].pvid = map->pvids[i];
2983 + for (i = 0; i < MT7530_NUM_VLANS; i++) {
2984 + mt7530->vlan_entries[i].member = map->members[i];
2985 + mt7530->vlan_entries[i].etags = map->etags[i];
2986 + mt7530->vlan_entries[i].vid = map->vids[i];
2991 +mt7530_reset_switch(struct switch_dev *dev)
2993 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
2996 + memset(priv->port_entries, 0, sizeof(priv->port_entries));
2997 + memset(priv->vlan_entries, 0, sizeof(priv->vlan_entries));
2999 + /* set default vid of each vlan to the same number of vlan, so the vid
3000 + * won't need be set explicitly.
3002 + for (i = 0; i < MT7530_NUM_VLANS; i++) {
3003 + priv->vlan_entries[i].vid = i;
3010 +mt7530_get_vlan_enable(struct switch_dev *dev,
3011 + const struct switch_attr *attr,
3012 + struct switch_val *val)
3014 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3016 + val->value.i = priv->global_vlan_enable;
3022 +mt7530_set_vlan_enable(struct switch_dev *dev,
3023 + const struct switch_attr *attr,
3024 + struct switch_val *val)
3026 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3028 + priv->global_vlan_enable = val->value.i != 0;
3034 +mt7530_r32(struct mt7530_priv *priv, u32 reg)
3040 + mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
3041 + low = mdiobus_read(priv->bus, 0x1f, (reg >> 2) & 0xf);
3042 + high = mdiobus_read(priv->bus, 0x1f, 0x10);
3044 + return (high << 16) | (low & 0xffff);
3047 + val = ioread32(priv->base + reg);
3048 + pr_debug("MT7530 MDIO Read [%04x]=%08x\n", reg, val);
3054 +mt7530_w32(struct mt7530_priv *priv, u32 reg, u32 val)
3057 + mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
3058 + mdiobus_write(priv->bus, 0x1f, (reg >> 2) & 0xf, val & 0xffff);
3059 + mdiobus_write(priv->bus, 0x1f, 0x10, val >> 16);
3063 + pr_debug("MT7530 MDIO Write[%04x]=%08x\n", reg, val);
3064 + iowrite32(val, priv->base + reg);
3068 +mt7530_vtcr(struct mt7530_priv *priv, u32 cmd, u32 val)
3072 + mt7530_w32(priv, REG_ESW_VLAN_VTCR, BIT(31) | (cmd << 12) | val);
3074 + for (i = 0; i < 20; i++) {
3075 + u32 val = mt7530_r32(priv, REG_ESW_VLAN_VTCR);
3077 + if ((val & BIT(31)) == 0)
3083 + printk("mt7530: vtcr timeout\n");
3087 +mt7530_get_port_pvid(struct switch_dev *dev, int port, int *val)
3089 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3091 + if (port >= MT7530_NUM_PORTS)
3094 + *val = mt7530_r32(priv, REG_ESW_PORT_PPBV1(port));
3101 +mt7530_set_port_pvid(struct switch_dev *dev, int port, int pvid)
3103 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3105 + if (port >= MT7530_NUM_PORTS)
3108 + if (pvid < MT7530_MIN_VID || pvid > MT7530_MAX_VID)
3111 + priv->port_entries[port].pvid = pvid;
3117 +mt7530_get_vlan_ports(struct switch_dev *dev, struct switch_val *val)
3119 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3126 + if (val->port_vlan < 0 || val->port_vlan >= MT7530_NUM_VLANS)
3129 + mt7530_vtcr(priv, 0, val->port_vlan);
3131 + member = mt7530_r32(priv, REG_ESW_VLAN_VAWD1);
3135 + etags = mt7530_r32(priv, REG_ESW_VLAN_VAWD2);
3137 + for (i = 0; i < MT7530_NUM_PORTS; i++) {
3138 + struct switch_port *p;
3141 + if (!(member & BIT(i)))
3144 + p = &val->value.ports[val->len++];
3147 + etag = (etags >> (i * 2)) & 0x3;
3149 + if (etag == ETAG_CTRL_TAG)
3150 + p->flags |= BIT(SWITCH_PORT_FLAG_TAGGED);
3151 + else if (etag != ETAG_CTRL_UNTAG)
3152 + printk("vlan egress tag control neither untag nor tag.\n");
3159 +mt7530_set_vlan_ports(struct switch_dev *dev, struct switch_val *val)
3161 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3166 + if (val->port_vlan < 0 || val->port_vlan >= MT7530_NUM_VLANS ||
3167 + val->len > MT7530_NUM_PORTS)
3170 + for (i = 0; i < val->len; i++) {
3171 + struct switch_port *p = &val->value.ports[i];
3173 + if (p->id >= MT7530_NUM_PORTS)
3176 + member |= BIT(p->id);
3178 + if (p->flags & BIT(SWITCH_PORT_FLAG_TAGGED))
3179 + etags |= BIT(p->id);
3181 + priv->vlan_entries[val->port_vlan].member = member;
3182 + priv->vlan_entries[val->port_vlan].etags = etags;
3188 +mt7530_set_vid(struct switch_dev *dev, const struct switch_attr *attr,
3189 + struct switch_val *val)
3191 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3195 + vlan = val->port_vlan;
3196 + vid = (u16)val->value.i;
3198 + if (vlan < 0 || vlan >= MT7530_NUM_VLANS)
3201 + if (vid < MT7530_MIN_VID || vid > MT7530_MAX_VID)
3204 + priv->vlan_entries[vlan].vid = vid;
3209 +mt7530_get_vid(struct switch_dev *dev, const struct switch_attr *attr,
3210 + struct switch_val *val)
3212 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3216 + vlan = val->port_vlan;
3218 + vid = mt7530_r32(priv, REG_ESW_VLAN_VTIM(vlan));
3223 + val->value.i = vid;
3228 +mt7530_apply_config(struct switch_dev *dev)
3230 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3233 + if (!priv->global_vlan_enable) {
3234 + for (i = 0; i < MT7530_NUM_PORTS; i++)
3235 + mt7530_w32(priv, REG_ESW_PORT_PCR(i), 0x00ff0000);
3237 + for (i = 0; i < MT7530_NUM_PORTS; i++)
3238 + mt7530_w32(priv, REG_ESW_PORT_PVC(i), 0x810000c0);
3243 + /* set all ports as security mode */
3244 + for (i = 0; i < MT7530_NUM_PORTS; i++)
3245 + mt7530_w32(priv, REG_ESW_PORT_PCR(i), 0x00ff0003);
3247 + /* set all ports as user port */
3248 + for (i = 0; i < MT7530_NUM_PORTS; i++)
3249 + mt7530_w32(priv, REG_ESW_PORT_PVC(i), 0x81000000);
3251 + for (i = 0; i < MT7530_NUM_VLANS; i++) {
3252 + u16 vid = priv->vlan_entries[i].vid;
3253 + u8 member = priv->vlan_entries[i].member;
3254 + u8 etags = priv->vlan_entries[i].etags;
3258 + val = mt7530_r32(priv, REG_ESW_VLAN_VTIM(i));
3264 + val |= (vid << 12);
3266 + mt7530_w32(priv, REG_ESW_VLAN_VTIM(i), val);
3268 + /* vlan port membership */
3270 + mt7530_w32(priv, REG_ESW_VLAN_VAWD1, REG_ESW_VLAN_VAWD1_IVL_MAC |
3271 + REG_ESW_VLAN_VAWD1_VTAG_EN | (member << 16) |
3272 + REG_ESW_VLAN_VAWD1_VALID);
3274 + mt7530_w32(priv, REG_ESW_VLAN_VAWD1, 0);
3278 + for (j = 0; j < MT7530_NUM_PORTS; j++) {
3279 + if (etags & BIT(j))
3280 + val |= ETAG_CTRL_TAG << (j * 2);
3282 + val |= ETAG_CTRL_UNTAG << (j * 2);
3284 + mt7530_w32(priv, REG_ESW_VLAN_VAWD2, val);
3286 + /* write to vlan table */
3287 + mt7530_vtcr(priv, 1, i);
3290 + /* Port Default PVID */
3291 + for (i = 0; i < MT7530_NUM_PORTS; i++) {
3293 + val = mt7530_r32(priv, REG_ESW_PORT_PPBV1(i));
3295 + val |= priv->port_entries[i].pvid;
3296 + mt7530_w32(priv, REG_ESW_PORT_PPBV1(i), val);
3303 +mt7530_get_port_link(struct switch_dev *dev, int port,
3304 + struct switch_port_link *link)
3306 + struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev);
3309 + if (port < 0 || port >= MT7530_NUM_PORTS)
3312 + pmsr = mt7530_r32(priv, 0x3008 + (0x100 * port));
3314 + link->link = pmsr & 1;
3315 + link->duplex = (pmsr >> 1) & 1;
3316 + speed = (pmsr >> 2) & 3;
3320 + link->speed = SWITCH_PORT_SPEED_10;
3323 + link->speed = SWITCH_PORT_SPEED_100;
3326 + case 3: /* forced gige speed can be 2 or 3 */
3327 + link->speed = SWITCH_PORT_SPEED_1000;
3330 + link->speed = SWITCH_PORT_SPEED_UNKNOWN;
3337 +static const struct switch_attr mt7530_global[] = {
3339 + .type = SWITCH_TYPE_INT,
3340 + .name = "enable_vlan",
3341 + .description = "VLAN mode (1:enabled)",
3343 + .id = MT7530_ATTR_ENABLE_VLAN,
3344 + .get = mt7530_get_vlan_enable,
3345 + .set = mt7530_set_vlan_enable,
3349 +static const struct switch_attr mt7530_port[] = {
3352 +static const struct switch_attr mt7530_vlan[] = {
3354 + .type = SWITCH_TYPE_INT,
3356 + .description = "VLAN ID (0-4094)",
3357 + .set = mt7530_set_vid,
3358 + .get = mt7530_get_vid,
3363 +static const struct switch_dev_ops mt7530_ops = {
3365 + .attr = mt7530_global,
3366 + .n_attr = ARRAY_SIZE(mt7530_global),
3369 + .attr = mt7530_port,
3370 + .n_attr = ARRAY_SIZE(mt7530_port),
3373 + .attr = mt7530_vlan,
3374 + .n_attr = ARRAY_SIZE(mt7530_vlan),
3376 + .get_vlan_ports = mt7530_get_vlan_ports,
3377 + .set_vlan_ports = mt7530_set_vlan_ports,
3378 + .get_port_pvid = mt7530_get_port_pvid,
3379 + .set_port_pvid = mt7530_set_port_pvid,
3380 + .get_port_link = mt7530_get_port_link,
3381 + .apply_config = mt7530_apply_config,
3382 + .reset_switch = mt7530_reset_switch,
3386 +mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus, int vlan)
3388 + struct switch_dev *swdev;
3389 + struct mt7530_priv *mt7530;
3390 + struct mt7530_mapping *map;
3393 + if (bus && bus->phy_map[0x1f]->phy_id != 0x1beef)
3396 + mt7530 = devm_kzalloc(dev, sizeof(struct mt7530_priv), GFP_KERNEL);
3400 + mt7530->base = base;
3401 + mt7530->bus = bus;
3402 + mt7530->global_vlan_enable = vlan;
3404 + swdev = &mt7530->swdev;
3406 + swdev->alias = "mt7530";
3407 + swdev->name = "mt7530";
3409 + swdev->alias = "mt7620";
3410 + swdev->name = "mt7620";
3412 + swdev->cpu_port = MT7530_CPU_PORT;
3413 + swdev->ports = MT7530_NUM_PORTS;
3414 + swdev->vlans = MT7530_NUM_VLANS;
3415 + swdev->ops = &mt7530_ops;
3417 + ret = register_switch(swdev, NULL);
3419 + dev_err(dev, "failed to register mt7530\n");
3423 + dev_info(dev, "loaded %s driver\n", swdev->name);
3425 + map = mt7530_find_mapping(dev->of_node);
3427 + mt7530_apply_mapping(mt7530, map);
3428 + mt7530_apply_config(swdev);
3432 Index: linux-3.14.18/drivers/net/ethernet/ralink/mt7530.h
3433 ===================================================================
3434 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3435 +++ linux-3.14.18/drivers/net/ethernet/ralink/mt7530.h 2014-10-28 12:34:25.187728544 +0100
3438 + * This program is free software; you can redistribute it and/or
3439 + * modify it under the terms of the GNU General Public License
3440 + * as published by the Free Software Foundation; either version 2
3441 + * of the License, or (at your option) any later version.
3443 + * This program is distributed in the hope that it will be useful,
3444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3446 + * GNU General Public License for more details.
3448 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
3451 +#ifndef _MT7530_H__
3452 +#define _MT7530_H__
3454 +int mt7530_probe(struct device *dev, void __iomem *base, struct mii_bus *bus, int vlan);
3457 Index: linux-3.14.18/drivers/net/ethernet/ralink/ralink_soc_eth.c
3458 ===================================================================
3459 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3460 +++ linux-3.14.18/drivers/net/ethernet/ralink/ralink_soc_eth.c 2014-10-28 10:43:11.890131215 +0100
3463 + * This program is free software; you can redistribute it and/or modify
3464 + * it under the terms of the GNU General Public License as published by
3465 + * the Free Software Foundation; version 2 of the License
3467 + * This program is distributed in the hope that it will be useful,
3468 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3469 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3470 + * GNU General Public License for more details.
3472 + * You should have received a copy of the GNU General Public License
3473 + * along with this program; if not, write to the Free Software
3474 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
3476 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
3479 +#include <linux/module.h>
3480 +#include <linux/kernel.h>
3481 +#include <linux/types.h>
3482 +#include <linux/dma-mapping.h>
3483 +#include <linux/init.h>
3484 +#include <linux/skbuff.h>
3485 +#include <linux/etherdevice.h>
3486 +#include <linux/ethtool.h>
3487 +#include <linux/platform_device.h>
3488 +#include <linux/of_device.h>
3489 +#include <linux/clk.h>
3490 +#include <linux/of_net.h>
3491 +#include <linux/of_mdio.h>
3492 +#include <linux/if_vlan.h>
3493 +#include <linux/reset.h>
3495 +#include <asm/mach-ralink/ralink_regs.h>
3497 +#include "ralink_soc_eth.h"
3498 +#include "esw_rt3052.h"
3501 +#define TX_TIMEOUT (2 * HZ)
3502 +#define MAX_RX_LENGTH 1536
3503 +#define DMA_DUMMY_DESC 0xffffffff
3505 +static const u32 fe_reg_table_default[FE_REG_COUNT] = {
3506 + [FE_REG_PDMA_GLO_CFG] = FE_PDMA_GLO_CFG,
3507 + [FE_REG_PDMA_RST_CFG] = FE_PDMA_RST_CFG,
3508 + [FE_REG_DLY_INT_CFG] = FE_DLY_INT_CFG,
3509 + [FE_REG_TX_BASE_PTR0] = FE_TX_BASE_PTR0,
3510 + [FE_REG_TX_MAX_CNT0] = FE_TX_MAX_CNT0,
3511 + [FE_REG_TX_CTX_IDX0] = FE_TX_CTX_IDX0,
3512 + [FE_REG_RX_BASE_PTR0] = FE_RX_BASE_PTR0,
3513 + [FE_REG_RX_MAX_CNT0] = FE_RX_MAX_CNT0,
3514 + [FE_REG_RX_CALC_IDX0] = FE_RX_CALC_IDX0,
3515 + [FE_REG_FE_INT_ENABLE] = FE_FE_INT_ENABLE,
3516 + [FE_REG_FE_INT_STATUS] = FE_FE_INT_STATUS,
3519 +static const u32 *fe_reg_table = fe_reg_table_default;
3521 +static void __iomem *fe_base = 0;
3523 +void fe_w32(u32 val, unsigned reg)
3525 + __raw_writel(val, fe_base + reg);
3528 +u32 fe_r32(unsigned reg)
3530 + return __raw_readl(fe_base + reg);
3533 +static inline void fe_reg_w32(u32 val, enum fe_reg reg)
3535 + fe_w32(val, fe_reg_table[reg]);
3538 +static inline u32 fe_reg_r32(enum fe_reg reg)
3540 + return fe_r32(fe_reg_table[reg]);
3543 +static inline void fe_int_disable(u32 mask)
3545 + fe_reg_w32(fe_reg_r32(FE_REG_FE_INT_ENABLE) & ~mask,
3546 + FE_REG_FE_INT_ENABLE);
3548 + fe_reg_r32(FE_REG_FE_INT_ENABLE);
3551 +static inline void fe_int_enable(u32 mask)
3553 + fe_reg_w32(fe_reg_r32(FE_REG_FE_INT_ENABLE) | mask,
3554 + FE_REG_FE_INT_ENABLE);
3556 + fe_reg_r32(FE_REG_FE_INT_ENABLE);
3559 +static inline void fe_hw_set_macaddr(struct fe_priv *priv, unsigned char *mac)
3561 + unsigned long flags;
3563 + spin_lock_irqsave(&priv->page_lock, flags);
3564 + fe_w32((mac[0] << 8) | mac[1], FE_GDMA1_MAC_ADRH);
3565 + fe_w32((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
3566 + FE_GDMA1_MAC_ADRL);
3567 + spin_unlock_irqrestore(&priv->page_lock, flags);
3570 +static int fe_set_mac_address(struct net_device *dev, void *p)
3572 + int ret = eth_mac_addr(dev, p);
3575 + struct fe_priv *priv = netdev_priv(dev);
3577 + if (priv->soc->set_mac)
3578 + priv->soc->set_mac(priv, dev->dev_addr);
3580 + fe_hw_set_macaddr(priv, p);
3586 +static struct sk_buff* fe_alloc_skb(struct fe_priv *priv)
3588 + struct sk_buff *skb;
3590 + skb = netdev_alloc_skb(priv->netdev, MAX_RX_LENGTH + NET_IP_ALIGN);
3594 + skb_reserve(skb, NET_IP_ALIGN);
3599 +static int fe_alloc_rx(struct fe_priv *priv)
3601 + int size = NUM_DMA_DESC * sizeof(struct fe_rx_dma);
3604 + priv->rx_dma = dma_alloc_coherent(&priv->netdev->dev, size,
3605 + &priv->rx_phys, GFP_ATOMIC);
3606 + if (!priv->rx_dma)
3609 + memset(priv->rx_dma, 0, size);
3611 + for (i = 0; i < NUM_DMA_DESC; i++) {
3612 + priv->rx_skb[i] = fe_alloc_skb(priv);
3613 + if (!priv->rx_skb[i])
3617 + for (i = 0; i < NUM_DMA_DESC; i++) {
3618 + dma_addr_t dma_addr = dma_map_single(&priv->netdev->dev,
3619 + priv->rx_skb[i]->data,
3622 + priv->rx_dma[i].rxd1 = (unsigned int) dma_addr;
3624 + if (priv->soc->rx_dma)
3625 + priv->soc->rx_dma(priv, i, MAX_RX_LENGTH);
3627 + priv->rx_dma[i].rxd2 = RX_DMA_LSO;
3631 + fe_reg_w32(priv->rx_phys, FE_REG_RX_BASE_PTR0);
3632 + fe_reg_w32(NUM_DMA_DESC, FE_REG_RX_MAX_CNT0);
3633 + fe_reg_w32((NUM_DMA_DESC - 1), FE_REG_RX_CALC_IDX0);
3634 + fe_reg_w32(FE_PST_DRX_IDX0, FE_REG_PDMA_RST_CFG);
3639 +static int fe_alloc_tx(struct fe_priv *priv)
3641 + int size = NUM_DMA_DESC * sizeof(struct fe_tx_dma);
3644 + priv->tx_free_idx = 0;
3646 + priv->tx_dma = dma_alloc_coherent(&priv->netdev->dev, size,
3647 + &priv->tx_phys, GFP_ATOMIC);
3648 + if (!priv->tx_dma)
3651 + memset(priv->tx_dma, 0, size);
3653 + for (i = 0; i < NUM_DMA_DESC; i++) {
3654 + if (priv->soc->tx_dma) {
3655 + priv->soc->tx_dma(priv, i, NULL);
3659 + priv->tx_dma[i].txd2 = TX_DMA_LSO | TX_DMA_DONE;
3660 + priv->tx_dma[i].txd4 = TX_DMA_QN(3) | TX_DMA_PN(1);
3663 + fe_reg_w32(priv->tx_phys, FE_REG_TX_BASE_PTR0);
3664 + fe_reg_w32(NUM_DMA_DESC, FE_REG_TX_MAX_CNT0);
3665 + fe_reg_w32(0, FE_REG_TX_CTX_IDX0);
3666 + fe_reg_w32(FE_PST_DTX_IDX0, FE_REG_PDMA_RST_CFG);
3671 +static void fe_free_dma(struct fe_priv *priv)
3675 + for (i = 0; i < NUM_DMA_DESC; i++) {
3676 + if (priv->rx_skb[i]) {
3677 + dma_unmap_single(&priv->netdev->dev, priv->rx_dma[i].rxd1,
3678 + MAX_RX_LENGTH, DMA_FROM_DEVICE);
3679 + dev_kfree_skb_any(priv->rx_skb[i]);
3680 + priv->rx_skb[i] = NULL;
3683 + if (priv->tx_skb[i]) {
3684 + dev_kfree_skb_any(priv->tx_skb[i]);
3685 + priv->tx_skb[i] = NULL;
3689 + if (priv->rx_dma) {
3690 + int size = NUM_DMA_DESC * sizeof(struct fe_rx_dma);
3691 + dma_free_coherent(&priv->netdev->dev, size, priv->rx_dma,
3695 + if (priv->tx_dma) {
3696 + int size = NUM_DMA_DESC * sizeof(struct fe_tx_dma);
3697 + dma_free_coherent(&priv->netdev->dev, size, priv->tx_dma,
3701 + netdev_reset_queue(priv->netdev);
3704 +static void fe_start_tso(struct sk_buff *skb, struct net_device *dev, unsigned int nr_frags, int idx)
3706 + struct fe_priv *priv = netdev_priv(dev);
3707 + struct skb_frag_struct *frag;
3710 + for (i = 0; i < nr_frags; i++) {
3711 + dma_addr_t mapped_addr;
3713 + frag = &skb_shinfo(skb)->frags[i];
3714 + mapped_addr = skb_frag_dma_map(&dev->dev, frag, 0, skb_frag_size(frag), DMA_TO_DEVICE);
3716 + idx = (idx + 1) % NUM_DMA_DESC;
3717 + priv->tx_dma[idx].txd1 = mapped_addr;
3718 + if (i == nr_frags - 1)
3719 + priv->tx_dma[idx].txd2 = TX_DMA_LSO | TX_DMA_PLEN0(frag->size);
3721 + priv->tx_dma[idx].txd2 = TX_DMA_PLEN0(frag->size);
3723 + priv->tx_dma[idx].txd3 = mapped_addr;
3724 + if (i == nr_frags - 1)
3725 + priv->tx_dma[idx].txd2 |= TX_DMA_LS1 | TX_DMA_PLEN1(frag->size);
3727 + priv->tx_dma[idx].txd2 |= TX_DMA_PLEN1(frag->size);
3732 +static int fe_start_xmit(struct sk_buff *skb, struct net_device *dev)
3734 + unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3735 + struct fe_priv *priv = netdev_priv(dev);
3736 + dma_addr_t mapped_addr;
3737 + u32 tx_next, tx, tx_num = 1;
3740 + if (priv->soc->min_pkt_len) {
3741 + if (skb->len < priv->soc->min_pkt_len) {
3742 + if (skb_padto(skb, priv->soc->min_pkt_len)) {
3744 + "fe_eth: skb_padto failed\n");
3748 + skb_put(skb, priv->soc->min_pkt_len - skb->len);
3752 + dev->trans_start = jiffies;
3753 + mapped_addr = dma_map_single(&priv->netdev->dev, skb->data,
3754 + skb->len, DMA_TO_DEVICE);
3756 + spin_lock(&priv->page_lock);
3758 + tx = fe_reg_r32(FE_REG_TX_CTX_IDX0);
3759 + if (priv->soc->tso && nr_frags)
3760 + tx_num += nr_frags >> 1;
3761 + tx_next = (tx + tx_num) % NUM_DMA_DESC;
3762 + if ((priv->tx_skb[tx]) || (priv->tx_skb[tx_next]) ||
3763 + !(priv->tx_dma[tx].txd2 & TX_DMA_DONE) ||
3764 + !(priv->tx_dma[tx_next].txd2 & TX_DMA_DONE))
3766 + spin_unlock(&priv->page_lock);
3767 + dev->stats.tx_dropped++;
3770 + return NETDEV_TX_OK;
3773 + if (priv->soc->tso) {
3776 + priv->tx_skb[(tx + t - 1) % NUM_DMA_DESC] = skb;
3778 + priv->tx_skb[(tx + t - 1) % NUM_DMA_DESC] = (struct sk_buff *) DMA_DUMMY_DESC;
3780 + priv->tx_skb[tx] = skb;
3782 + priv->tx_dma[tx].txd1 = (unsigned int) mapped_addr;
3785 + priv->tx_dma[tx].txd4 &= ~0x80;
3786 + if (priv->soc->tx_dma)
3787 + priv->soc->tx_dma(priv, tx, skb);
3789 + priv->tx_dma[tx].txd2 = TX_DMA_LSO | TX_DMA_PLEN0(skb->len);
3791 + if (skb->ip_summed == CHECKSUM_PARTIAL)
3792 + priv->tx_dma[tx].txd4 |= TX_DMA_CHKSUM;
3794 + priv->tx_dma[tx].txd4 &= ~TX_DMA_CHKSUM;
3796 + if (priv->soc->tso)
3797 + fe_start_tso(skb, dev, nr_frags, tx);
3799 + if (priv->soc->tso && (skb_shinfo(skb)->gso_segs > 1)) {
3800 + struct iphdr *iph = NULL;
3801 + struct tcphdr *th = NULL;
3802 + struct ipv6hdr *ip6h = NULL;
3804 + ip6h = (struct ipv6hdr *) skb_network_header(skb);
3805 + iph = (struct iphdr *) skb_network_header(skb);
3806 + if ((iph->version == 4) && (iph->protocol == IPPROTO_TCP)) {
3807 + th = (struct tcphdr *)skb_transport_header(skb);
3808 + priv->tx_dma[tx].txd4 |= BIT(28);
3809 + th->check = htons(skb_shinfo(skb)->gso_size);
3810 + dma_cache_sync(NULL, th, sizeof(struct tcphdr), DMA_TO_DEVICE);
3811 + } else if ((ip6h->version == 6) && (ip6h->nexthdr == NEXTHDR_TCP)) {
3812 + th = (struct tcphdr *)skb_transport_header(skb);
3813 + priv->tx_dma[tx].txd4 |= BIT(28);
3814 + th->check = htons(skb_shinfo(skb)->gso_size);
3815 + dma_cache_sync(NULL, th, sizeof(struct tcphdr), DMA_TO_DEVICE);
3819 + for (i = 0; i < tx_num; i++)
3820 + dma_cache_sync(NULL, &priv->tx_dma[tx + i], sizeof(struct fe_tx_dma), DMA_TO_DEVICE);
3822 + dev->stats.tx_packets++;
3823 + dev->stats.tx_bytes += skb->len;
3826 + fe_reg_w32(tx_next, FE_REG_TX_CTX_IDX0);
3827 + netdev_sent_queue(dev, skb->len);
3829 + spin_unlock(&priv->page_lock);
3831 + return NETDEV_TX_OK;
3834 +static int fe_poll_rx(struct napi_struct *napi, int budget)
3836 + struct fe_priv *priv = container_of(napi, struct fe_priv, rx_napi);
3837 + int idx = fe_reg_r32(FE_REG_RX_CALC_IDX0);
3841 + while ((rx < budget) && !complete) {
3842 + idx = (idx + 1) % NUM_DMA_DESC;
3844 + if (priv->rx_dma[idx].rxd2 & RX_DMA_DONE) {
3845 + struct sk_buff *new_skb = fe_alloc_skb(priv);
3848 + int pktlen = RX_DMA_PLEN0(priv->rx_dma[idx].rxd2);
3849 + dma_addr_t dma_addr;
3851 + dma_unmap_single(&priv->netdev->dev, priv->rx_dma[idx].rxd1,
3852 + MAX_RX_LENGTH, DMA_FROM_DEVICE);
3854 + skb_put(priv->rx_skb[idx], pktlen);
3855 + priv->rx_skb[idx]->dev = priv->netdev;
3856 + priv->rx_skb[idx]->protocol = eth_type_trans(priv->rx_skb[idx], priv->netdev);
3857 + if (priv->rx_dma[idx].rxd4 & priv->soc->checksum_bit)
3858 + priv->rx_skb[idx]->ip_summed = CHECKSUM_UNNECESSARY;
3860 + priv->rx_skb[idx]->ip_summed = CHECKSUM_NONE;
3861 + priv->netdev->stats.rx_packets++;
3862 + priv->netdev->stats.rx_bytes += pktlen;
3864 +#ifdef CONFIG_INET_LRO
3865 + if (priv->soc->get_skb_header && priv->rx_skb[idx]->ip_summed == CHECKSUM_UNNECESSARY)
3866 + lro_receive_skb(&priv->lro_mgr, priv->rx_skb[idx], NULL);
3869 + netif_receive_skb(priv->rx_skb[idx]);
3871 + priv->rx_skb[idx] = new_skb;
3873 + dma_addr = dma_map_single(&priv->netdev->dev,
3877 + priv->rx_dma[idx].rxd1 = (unsigned int) dma_addr;
3880 + priv->netdev->stats.rx_dropped++;
3883 + if (priv->soc->rx_dma)
3884 + priv->soc->rx_dma(priv, idx, MAX_RX_LENGTH);
3886 + priv->rx_dma[idx].rxd2 = RX_DMA_LSO;
3887 + fe_reg_w32(idx, FE_REG_RX_CALC_IDX0);
3895 +#ifdef CONFIG_INET_LRO
3896 + if (priv->soc->get_skb_header)
3897 + lro_flush_all(&priv->lro_mgr);
3900 + napi_complete(&priv->rx_napi);
3901 + fe_int_enable(priv->soc->rx_dly_int);
3907 +static void fe_tx_housekeeping(unsigned long ptr)
3909 + struct net_device *dev = (struct net_device*)ptr;
3910 + struct fe_priv *priv = netdev_priv(dev);
3911 + unsigned int bytes_compl = 0;
3912 + unsigned int pkts_compl = 0;
3914 + spin_lock(&priv->page_lock);
3916 + struct fe_tx_dma *txd;
3918 + txd = &priv->tx_dma[priv->tx_free_idx];
3920 + if (!(txd->txd2 & TX_DMA_DONE) || !(priv->tx_skb[priv->tx_free_idx]))
3923 + if (priv->tx_skb[priv->tx_free_idx] != (struct sk_buff *) DMA_DUMMY_DESC) {
3924 + bytes_compl += priv->tx_skb[priv->tx_free_idx]->len;
3925 + dev_kfree_skb_irq(priv->tx_skb[priv->tx_free_idx]);
3928 + priv->tx_skb[priv->tx_free_idx] = NULL;
3929 + priv->tx_free_idx++;
3930 + if (priv->tx_free_idx >= NUM_DMA_DESC)
3931 + priv->tx_free_idx = 0;
3934 + netdev_completed_queue(priv->netdev, pkts_compl, bytes_compl);
3935 + spin_unlock(&priv->page_lock);
3937 + fe_int_enable(priv->soc->tx_dly_int);
3940 +static void fe_tx_timeout(struct net_device *dev)
3942 + struct fe_priv *priv = netdev_priv(dev);
3944 + tasklet_schedule(&priv->tx_tasklet);
3945 + priv->netdev->stats.tx_errors++;
3946 + netdev_err(dev, "transmit timed out, waking up the queue\n");
3947 + netif_wake_queue(dev);
3950 +static irqreturn_t fe_handle_irq(int irq, void *dev)
3952 + struct fe_priv *priv = netdev_priv(dev);
3953 + unsigned int status;
3954 + unsigned int mask;
3956 + status = fe_reg_r32(FE_REG_FE_INT_STATUS);
3957 + mask = fe_reg_r32(FE_REG_FE_INT_ENABLE);
3959 + if (!(status & mask))
3962 + if (status & priv->soc->rx_dly_int) {
3963 + fe_int_disable(priv->soc->rx_dly_int);
3964 + napi_schedule(&priv->rx_napi);
3967 + if (status & priv->soc->tx_dly_int) {
3968 + fe_int_disable(priv->soc->tx_dly_int);
3969 + tasklet_schedule(&priv->tx_tasklet);
3972 + fe_reg_w32(status, FE_REG_FE_INT_STATUS);
3974 + return IRQ_HANDLED;
3977 +static int fe_hw_init(struct net_device *dev)
3979 + struct fe_priv *priv = netdev_priv(dev);
3982 + err = devm_request_irq(priv->device, dev->irq, fe_handle_irq, 0,
3983 + dev_name(priv->device), dev);
3987 + err = fe_alloc_rx(priv);
3989 + err = fe_alloc_tx(priv);
3993 + if (priv->soc->set_mac)
3994 + priv->soc->set_mac(priv, dev->dev_addr);
3996 + fe_hw_set_macaddr(priv, dev->dev_addr);
3998 + fe_reg_w32(FE_DELAY_INIT, FE_REG_DLY_INT_CFG);
4000 + fe_int_disable(priv->soc->tx_dly_int | priv->soc->rx_dly_int);
4002 + tasklet_init(&priv->tx_tasklet, fe_tx_housekeeping, (unsigned long)dev);
4004 + if (priv->soc->fwd_config) {
4005 + priv->soc->fwd_config(priv);
4007 + unsigned long sysclk = priv->sysclk;
4010 + netdev_err(dev, "unable to get clock\n");
4014 + sysclk /= FE_US_CYC_CNT_DIVISOR;
4015 + sysclk <<= FE_US_CYC_CNT_SHIFT;
4017 + fe_w32((fe_r32(FE_FE_GLO_CFG) &
4018 + ~(FE_US_CYC_CNT_MASK << FE_US_CYC_CNT_SHIFT)) | sysclk,
4021 + fe_w32(fe_r32(FE_GDMA1_FWD_CFG) & ~0xffff, FE_GDMA1_FWD_CFG);
4022 + fe_w32(fe_r32(FE_GDMA1_FWD_CFG) | (FE_GDM1_ICS_EN | FE_GDM1_TCS_EN | FE_GDM1_UCS_EN),
4023 + FE_GDMA1_FWD_CFG);
4024 + fe_w32(fe_r32(FE_CDMA_CSG_CFG) | (FE_ICS_GEN_EN | FE_TCS_GEN_EN | FE_UCS_GEN_EN),
4026 + fe_w32(FE_PSE_FQFC_CFG_INIT, FE_PSE_FQ_CFG);
4029 + fe_w32(1, FE_FE_RST_GL);
4030 + fe_w32(0, FE_FE_RST_GL);
4035 +static int fe_open(struct net_device *dev)
4037 + struct fe_priv *priv = netdev_priv(dev);
4038 + unsigned long flags;
4041 + spin_lock_irqsave(&priv->page_lock, flags);
4042 + napi_enable(&priv->rx_napi);
4044 + val = FE_TX_WB_DDONE | FE_RX_DMA_EN | FE_TX_DMA_EN;
4045 + val |= priv->soc->pdma_glo_cfg;
4046 + fe_reg_w32(val, FE_REG_PDMA_GLO_CFG);
4048 + spin_unlock_irqrestore(&priv->page_lock, flags);
4051 + priv->phy->start(priv);
4053 + if (priv->soc->has_carrier && priv->soc->has_carrier(priv))
4054 + netif_carrier_on(dev);
4056 + netif_start_queue(dev);
4057 + fe_int_enable(priv->soc->tx_dly_int | priv->soc->rx_dly_int);
4062 +static int fe_stop(struct net_device *dev)
4064 + struct fe_priv *priv = netdev_priv(dev);
4065 + unsigned long flags;
4067 + fe_int_disable(priv->soc->tx_dly_int | priv->soc->rx_dly_int);
4069 + netif_stop_queue(dev);
4072 + priv->phy->stop(priv);
4074 + spin_lock_irqsave(&priv->page_lock, flags);
4075 + napi_disable(&priv->rx_napi);
4077 + fe_reg_w32(fe_reg_r32(FE_REG_PDMA_GLO_CFG) &
4078 + ~(FE_TX_WB_DDONE | FE_RX_DMA_EN | FE_TX_DMA_EN),
4079 + FE_REG_PDMA_GLO_CFG);
4080 + spin_unlock_irqrestore(&priv->page_lock, flags);
4085 +static int __init fe_init(struct net_device *dev)
4087 + struct fe_priv *priv = netdev_priv(dev);
4088 + struct device_node *port;
4091 + BUG_ON(!priv->soc->reset_fe);
4092 + priv->soc->reset_fe();
4094 + if (priv->soc->switch_init)
4095 + priv->soc->switch_init(priv);
4097 + memcpy(dev->dev_addr, priv->soc->mac, ETH_ALEN);
4098 + of_get_mac_address_mtd(priv->device->of_node, dev->dev_addr);
4100 + err = fe_mdio_init(priv);
4105 + err = priv->phy->connect(priv);
4107 + goto err_mdio_cleanup;
4110 + if (priv->soc->port_init)
4111 + for_each_child_of_node(priv->device->of_node, port)
4112 + if (of_device_is_compatible(port, "ralink,eth-port") && of_device_is_available(port))
4113 + priv->soc->port_init(priv, port);
4115 + err = fe_hw_init(dev);
4117 + goto err_phy_disconnect;
4119 + if (priv->soc->switch_config)
4120 + priv->soc->switch_config(priv);
4124 +err_phy_disconnect:
4126 + priv->phy->disconnect(priv);
4128 + fe_mdio_cleanup(priv);
4133 +static void fe_uninit(struct net_device *dev)
4135 + struct fe_priv *priv = netdev_priv(dev);
4137 + tasklet_kill(&priv->tx_tasklet);
4140 + priv->phy->disconnect(priv);
4141 + fe_mdio_cleanup(priv);
4143 + fe_reg_w32(0, FE_REG_FE_INT_ENABLE);
4144 + free_irq(dev->irq, dev);
4146 + fe_free_dma(priv);
4149 +static const struct net_device_ops fe_netdev_ops = {
4150 + .ndo_init = fe_init,
4151 + .ndo_uninit = fe_uninit,
4152 + .ndo_open = fe_open,
4153 + .ndo_stop = fe_stop,
4154 + .ndo_start_xmit = fe_start_xmit,
4155 + .ndo_tx_timeout = fe_tx_timeout,
4156 + .ndo_set_mac_address = fe_set_mac_address,
4157 + .ndo_change_mtu = eth_change_mtu,
4158 + .ndo_validate_addr = eth_validate_addr,
4161 +static int fe_probe(struct platform_device *pdev)
4163 + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4164 + const struct of_device_id *match;
4165 + struct fe_soc_data *soc = NULL;
4166 + struct net_device *netdev;
4167 + struct fe_priv *priv;
4168 + struct clk *sysclk;
4171 + device_reset(&pdev->dev);
4173 + match = of_match_device(of_fe_match, &pdev->dev);
4174 + soc = (struct fe_soc_data *) match->data;
4176 + if (soc->init_data)
4177 + soc->init_data(soc);
4178 + if (soc->reg_table)
4179 + fe_reg_table = soc->reg_table;
4181 + fe_base = devm_request_and_ioremap(&pdev->dev, res);
4185 + netdev = alloc_etherdev(sizeof(struct fe_priv));
4187 + dev_err(&pdev->dev, "alloc_etherdev failed\n");
4191 + strcpy(netdev->name, "eth%d");
4192 + netdev->netdev_ops = &fe_netdev_ops;
4193 + netdev->base_addr = (unsigned long) fe_base;
4194 + netdev->watchdog_timeo = TX_TIMEOUT;
4195 + netdev->features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
4197 + if (fe_reg_table[FE_REG_FE_DMA_VID_BASE])
4198 + netdev->features |= NETIF_F_HW_VLAN_CTAG_TX;
4201 + dev_info(&pdev->dev, "Enabling TSO\n");
4202 + netdev->features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_IPV6_CSUM;
4204 + netdev->hw_features = netdev->features;
4206 + netdev->irq = platform_get_irq(pdev, 0);
4207 + if (netdev->irq < 0) {
4208 + dev_err(&pdev->dev, "no IRQ resource found\n");
4213 + priv = netdev_priv(netdev);
4214 + memset(priv, 0, sizeof(struct fe_priv));
4215 + spin_lock_init(&priv->page_lock);
4217 + sysclk = devm_clk_get(&pdev->dev, NULL);
4218 + if (!IS_ERR(sysclk))
4219 + priv->sysclk = clk_get_rate(sysclk);
4221 + priv->netdev = netdev;
4222 + priv->device = &pdev->dev;
4225 + err = register_netdev(netdev);
4227 + dev_err(&pdev->dev, "error bringing up device\n");
4231 + netif_napi_add(netdev, &priv->rx_napi, fe_poll_rx, 32);
4233 +#ifdef CONFIG_INET_LRO
4234 + if (priv->soc->get_skb_header) {
4235 + priv->lro_mgr.dev = netdev;
4236 + memset(&priv->lro_mgr.stats, 0, sizeof(priv->lro_mgr.stats));
4237 + priv->lro_mgr.features = LRO_F_NAPI;
4238 + priv->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
4239 + priv->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
4240 + priv->lro_mgr.max_desc = ARRAY_SIZE(priv->lro_arr);
4241 + priv->lro_mgr.max_aggr = 64;
4242 + priv->lro_mgr.frag_align_pad = 0;
4243 + priv->lro_mgr.lro_arr = priv->lro_arr;
4244 + priv->lro_mgr.get_skb_header = priv->soc->get_skb_header;
4248 + platform_set_drvdata(pdev, netdev);
4250 + netdev_info(netdev, "done loading\n");
4255 +static int fe_remove(struct platform_device *pdev)
4257 + struct net_device *dev = platform_get_drvdata(pdev);
4258 + struct fe_priv *priv = netdev_priv(dev);
4260 + netif_stop_queue(dev);
4261 + netif_napi_del(&priv->rx_napi);
4263 + unregister_netdev(dev);
4269 +static struct platform_driver fe_driver = {
4270 + .probe = fe_probe,
4271 + .remove = fe_remove,
4273 + .name = "ralink_soc_eth",
4274 + .owner = THIS_MODULE,
4275 + .of_match_table = of_fe_match,
4279 +static int __init init_rtfe(void)
4283 + ret = rtesw_init();
4287 + ret = platform_driver_register(&fe_driver);
4294 +static void __exit exit_rtfe(void)
4296 + platform_driver_unregister(&fe_driver);
4300 +module_init(init_rtfe);
4301 +module_exit(exit_rtfe);
4303 +MODULE_LICENSE("GPL");
4304 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
4305 +MODULE_DESCRIPTION("Ethernet driver for Ralink SoC");
4306 Index: linux-3.14.18/drivers/net/ethernet/ralink/ralink_soc_eth.h
4307 ===================================================================
4308 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4309 +++ linux-3.14.18/drivers/net/ethernet/ralink/ralink_soc_eth.h 2014-10-28 10:43:11.894131220 +0100
4312 + * This program is free software; you can redistribute it and/or modify
4313 + * it under the terms of the GNU General Public License as published by
4314 + * the Free Software Foundation; version 2 of the License
4316 + * This program is distributed in the hope that it will be useful,
4317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4319 + * GNU General Public License for more details.
4321 + * You should have received a copy of the GNU General Public License
4322 + * along with this program; if not, write to the Free Software
4323 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4325 + * based on Ralink SDK3.3
4326 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4332 +#include <linux/mii.h>
4333 +#include <linux/interrupt.h>
4334 +#include <linux/netdevice.h>
4335 +#include <linux/dma-mapping.h>
4336 +#include <linux/phy.h>
4337 +#include <linux/inet_lro.h>
4341 + FE_REG_PDMA_GLO_CFG = 0,
4342 + FE_REG_PDMA_RST_CFG,
4343 + FE_REG_DLY_INT_CFG,
4344 + FE_REG_TX_BASE_PTR0,
4345 + FE_REG_TX_MAX_CNT0,
4346 + FE_REG_TX_CTX_IDX0,
4347 + FE_REG_RX_BASE_PTR0,
4348 + FE_REG_RX_MAX_CNT0,
4349 + FE_REG_RX_CALC_IDX0,
4350 + FE_REG_FE_INT_ENABLE,
4351 + FE_REG_FE_INT_STATUS,
4352 + FE_REG_FE_DMA_VID_BASE,
4356 +#define NUM_DMA_DESC 0x100
4358 +#define FE_DELAY_EN_INT 0x80
4359 +#define FE_DELAY_MAX_INT 0x04
4360 +#define FE_DELAY_MAX_TOUT 0x04
4361 +#define FE_DELAY_CHAN (((FE_DELAY_EN_INT | FE_DELAY_MAX_INT) << 8) | FE_DELAY_MAX_TOUT)
4362 +#define FE_DELAY_INIT ((FE_DELAY_CHAN << 16) | FE_DELAY_CHAN)
4363 +#define FE_PSE_FQFC_CFG_INIT 0x80504000
4365 +/* interrupt bits */
4366 +#define FE_CNT_PPE_AF BIT(31)
4367 +#define FE_CNT_GDM_AF BIT(29)
4368 +#define FE_PSE_P2_FC BIT(26)
4369 +#define FE_PSE_BUF_DROP BIT(24)
4370 +#define FE_GDM_OTHER_DROP BIT(23)
4371 +#define FE_PSE_P1_FC BIT(22)
4372 +#define FE_PSE_P0_FC BIT(21)
4373 +#define FE_PSE_FQ_EMPTY BIT(20)
4374 +#define FE_GE1_STA_CHG BIT(18)
4375 +#define FE_TX_COHERENT BIT(17)
4376 +#define FE_RX_COHERENT BIT(16)
4377 +#define FE_TX_DONE_INT3 BIT(11)
4378 +#define FE_TX_DONE_INT2 BIT(10)
4379 +#define FE_TX_DONE_INT1 BIT(9)
4380 +#define FE_TX_DONE_INT0 BIT(8)
4381 +#define FE_RX_DONE_INT0 BIT(2)
4382 +#define FE_TX_DLY_INT BIT(1)
4383 +#define FE_RX_DLY_INT BIT(0)
4385 +#define RT5350_RX_DLY_INT BIT(30)
4386 +#define RT5350_TX_DLY_INT BIT(28)
4389 +#define FE_FE_OFFSET 0x0000
4390 +#define FE_GDMA_OFFSET 0x0020
4391 +#define FE_PSE_OFFSET 0x0040
4392 +#define FE_GDMA2_OFFSET 0x0060
4393 +#define FE_CDMA_OFFSET 0x0080
4394 +#define FE_DMA_VID0 0x00a8
4395 +#define FE_PDMA_OFFSET 0x0100
4396 +#define FE_PPE_OFFSET 0x0200
4397 +#define FE_CMTABLE_OFFSET 0x0400
4398 +#define FE_POLICYTABLE_OFFSET 0x1000
4400 +#define RT5350_PDMA_OFFSET 0x0800
4401 +#define RT5350_SDM_OFFSET 0x0c00
4403 +#define FE_MDIO_ACCESS (FE_FE_OFFSET + 0x00)
4404 +#define FE_MDIO_CFG (FE_FE_OFFSET + 0x04)
4405 +#define FE_FE_GLO_CFG (FE_FE_OFFSET + 0x08)
4406 +#define FE_FE_RST_GL (FE_FE_OFFSET + 0x0C)
4407 +#define FE_FE_INT_STATUS (FE_FE_OFFSET + 0x10)
4408 +#define FE_FE_INT_ENABLE (FE_FE_OFFSET + 0x14)
4409 +#define FE_MDIO_CFG2 (FE_FE_OFFSET + 0x18)
4410 +#define FE_FOC_TS_T (FE_FE_OFFSET + 0x1C)
4412 +#define FE_GDMA1_FWD_CFG (FE_GDMA_OFFSET + 0x00)
4413 +#define FE_GDMA1_SCH_CFG (FE_GDMA_OFFSET + 0x04)
4414 +#define FE_GDMA1_SHPR_CFG (FE_GDMA_OFFSET + 0x08)
4415 +#define FE_GDMA1_MAC_ADRL (FE_GDMA_OFFSET + 0x0C)
4416 +#define FE_GDMA1_MAC_ADRH (FE_GDMA_OFFSET + 0x10)
4418 +#define FE_GDMA2_FWD_CFG (FE_GDMA2_OFFSET + 0x00)
4419 +#define FE_GDMA2_SCH_CFG (FE_GDMA2_OFFSET + 0x04)
4420 +#define FE_GDMA2_SHPR_CFG (FE_GDMA2_OFFSET + 0x08)
4421 +#define FE_GDMA2_MAC_ADRL (FE_GDMA2_OFFSET + 0x0C)
4422 +#define FE_GDMA2_MAC_ADRH (FE_GDMA2_OFFSET + 0x10)
4424 +#define FE_PSE_FQ_CFG (FE_PSE_OFFSET + 0x00)
4425 +#define FE_CDMA_FC_CFG (FE_PSE_OFFSET + 0x04)
4426 +#define FE_GDMA1_FC_CFG (FE_PSE_OFFSET + 0x08)
4427 +#define FE_GDMA2_FC_CFG (FE_PSE_OFFSET + 0x0C)
4429 +#define FE_CDMA_CSG_CFG (FE_CDMA_OFFSET + 0x00)
4430 +#define FE_CDMA_SCH_CFG (FE_CDMA_OFFSET + 0x04)
4432 +#define MT7620A_GDMA_OFFSET 0x0600
4433 +#define MT7620A_GDMA1_FWD_CFG (MT7620A_GDMA_OFFSET + 0x00)
4434 +#define MT7620A_FE_GDMA1_SCH_CFG (MT7620A_GDMA_OFFSET + 0x04)
4435 +#define MT7620A_FE_GDMA1_SHPR_CFG (MT7620A_GDMA_OFFSET + 0x08)
4436 +#define MT7620A_FE_GDMA1_MAC_ADRL (MT7620A_GDMA_OFFSET + 0x0C)
4437 +#define MT7620A_FE_GDMA1_MAC_ADRH (MT7620A_GDMA_OFFSET + 0x10)
4439 +#define RT5350_TX_BASE_PTR0 (RT5350_PDMA_OFFSET + 0x00)
4440 +#define RT5350_TX_MAX_CNT0 (RT5350_PDMA_OFFSET + 0x04)
4441 +#define RT5350_TX_CTX_IDX0 (RT5350_PDMA_OFFSET + 0x08)
4442 +#define RT5350_TX_DTX_IDX0 (RT5350_PDMA_OFFSET + 0x0C)
4443 +#define RT5350_TX_BASE_PTR1 (RT5350_PDMA_OFFSET + 0x10)
4444 +#define RT5350_TX_MAX_CNT1 (RT5350_PDMA_OFFSET + 0x14)
4445 +#define RT5350_TX_CTX_IDX1 (RT5350_PDMA_OFFSET + 0x18)
4446 +#define RT5350_TX_DTX_IDX1 (RT5350_PDMA_OFFSET + 0x1C)
4447 +#define RT5350_TX_BASE_PTR2 (RT5350_PDMA_OFFSET + 0x20)
4448 +#define RT5350_TX_MAX_CNT2 (RT5350_PDMA_OFFSET + 0x24)
4449 +#define RT5350_TX_CTX_IDX2 (RT5350_PDMA_OFFSET + 0x28)
4450 +#define RT5350_TX_DTX_IDX2 (RT5350_PDMA_OFFSET + 0x2C)
4451 +#define RT5350_TX_BASE_PTR3 (RT5350_PDMA_OFFSET + 0x30)
4452 +#define RT5350_TX_MAX_CNT3 (RT5350_PDMA_OFFSET + 0x34)
4453 +#define RT5350_TX_CTX_IDX3 (RT5350_PDMA_OFFSET + 0x38)
4454 +#define RT5350_TX_DTX_IDX3 (RT5350_PDMA_OFFSET + 0x3C)
4455 +#define RT5350_RX_BASE_PTR0 (RT5350_PDMA_OFFSET + 0x100)
4456 +#define RT5350_RX_MAX_CNT0 (RT5350_PDMA_OFFSET + 0x104)
4457 +#define RT5350_RX_CALC_IDX0 (RT5350_PDMA_OFFSET + 0x108)
4458 +#define RT5350_RX_DRX_IDX0 (RT5350_PDMA_OFFSET + 0x10C)
4459 +#define RT5350_RX_BASE_PTR1 (RT5350_PDMA_OFFSET + 0x110)
4460 +#define RT5350_RX_MAX_CNT1 (RT5350_PDMA_OFFSET + 0x114)
4461 +#define RT5350_RX_CALC_IDX1 (RT5350_PDMA_OFFSET + 0x118)
4462 +#define RT5350_RX_DRX_IDX1 (RT5350_PDMA_OFFSET + 0x11C)
4463 +#define RT5350_PDMA_GLO_CFG (RT5350_PDMA_OFFSET + 0x204)
4464 +#define RT5350_PDMA_RST_CFG (RT5350_PDMA_OFFSET + 0x208)
4465 +#define RT5350_DLY_INT_CFG (RT5350_PDMA_OFFSET + 0x20c)
4466 +#define RT5350_FE_INT_STATUS (RT5350_PDMA_OFFSET + 0x220)
4467 +#define RT5350_FE_INT_ENABLE (RT5350_PDMA_OFFSET + 0x228)
4468 +#define RT5350_PDMA_SCH_CFG (RT5350_PDMA_OFFSET + 0x280)
4470 +#define FE_PDMA_GLO_CFG (FE_PDMA_OFFSET + 0x00)
4471 +#define FE_PDMA_RST_CFG (FE_PDMA_OFFSET + 0x04)
4472 +#define FE_PDMA_SCH_CFG (FE_PDMA_OFFSET + 0x08)
4473 +#define FE_DLY_INT_CFG (FE_PDMA_OFFSET + 0x0C)
4474 +#define FE_TX_BASE_PTR0 (FE_PDMA_OFFSET + 0x10)
4475 +#define FE_TX_MAX_CNT0 (FE_PDMA_OFFSET + 0x14)
4476 +#define FE_TX_CTX_IDX0 (FE_PDMA_OFFSET + 0x18)
4477 +#define FE_TX_DTX_IDX0 (FE_PDMA_OFFSET + 0x1C)
4478 +#define FE_TX_BASE_PTR1 (FE_PDMA_OFFSET + 0x20)
4479 +#define FE_TX_MAX_CNT1 (FE_PDMA_OFFSET + 0x24)
4480 +#define FE_TX_CTX_IDX1 (FE_PDMA_OFFSET + 0x28)
4481 +#define FE_TX_DTX_IDX1 (FE_PDMA_OFFSET + 0x2C)
4482 +#define FE_RX_BASE_PTR0 (FE_PDMA_OFFSET + 0x30)
4483 +#define FE_RX_MAX_CNT0 (FE_PDMA_OFFSET + 0x34)
4484 +#define FE_RX_CALC_IDX0 (FE_PDMA_OFFSET + 0x38)
4485 +#define FE_RX_DRX_IDX0 (FE_PDMA_OFFSET + 0x3C)
4486 +#define FE_TX_BASE_PTR2 (FE_PDMA_OFFSET + 0x40)
4487 +#define FE_TX_MAX_CNT2 (FE_PDMA_OFFSET + 0x44)
4488 +#define FE_TX_CTX_IDX2 (FE_PDMA_OFFSET + 0x48)
4489 +#define FE_TX_DTX_IDX2 (FE_PDMA_OFFSET + 0x4C)
4490 +#define FE_TX_BASE_PTR3 (FE_PDMA_OFFSET + 0x50)
4491 +#define FE_TX_MAX_CNT3 (FE_PDMA_OFFSET + 0x54)
4492 +#define FE_TX_CTX_IDX3 (FE_PDMA_OFFSET + 0x58)
4493 +#define FE_TX_DTX_IDX3 (FE_PDMA_OFFSET + 0x5C)
4494 +#define FE_RX_BASE_PTR1 (FE_PDMA_OFFSET + 0x60)
4495 +#define FE_RX_MAX_CNT1 (FE_PDMA_OFFSET + 0x64)
4496 +#define FE_RX_CALC_IDX1 (FE_PDMA_OFFSET + 0x68)
4497 +#define FE_RX_DRX_IDX1 (FE_PDMA_OFFSET + 0x6C)
4499 +#define RT5350_SDM_CFG (RT5350_SDM_OFFSET + 0x00) //Switch DMA configuration
4500 +#define RT5350_SDM_RRING (RT5350_SDM_OFFSET + 0x04) //Switch DMA Rx Ring
4501 +#define RT5350_SDM_TRING (RT5350_SDM_OFFSET + 0x08) //Switch DMA Tx Ring
4502 +#define RT5350_SDM_MAC_ADRL (RT5350_SDM_OFFSET + 0x0C) //Switch MAC address LSB
4503 +#define RT5350_SDM_MAC_ADRH (RT5350_SDM_OFFSET + 0x10) //Switch MAC Address MSB
4504 +#define RT5350_SDM_TPCNT (RT5350_SDM_OFFSET + 0x100) //Switch DMA Tx packet count
4505 +#define RT5350_SDM_TBCNT (RT5350_SDM_OFFSET + 0x104) //Switch DMA Tx byte count
4506 +#define RT5350_SDM_RPCNT (RT5350_SDM_OFFSET + 0x108) //Switch DMA rx packet count
4507 +#define RT5350_SDM_RBCNT (RT5350_SDM_OFFSET + 0x10C) //Switch DMA rx byte count
4508 +#define RT5350_SDM_CS_ERR (RT5350_SDM_OFFSET + 0x110) //Switch DMA rx checksum error count
4510 +#define RT5350_SDM_ICS_EN BIT(16)
4511 +#define RT5350_SDM_TCS_EN BIT(17)
4512 +#define RT5350_SDM_UCS_EN BIT(18)
4515 +/* MDIO_CFG register bits */
4516 +#define FE_MDIO_CFG_AUTO_POLL_EN BIT(29)
4517 +#define FE_MDIO_CFG_GP1_BP_EN BIT(16)
4518 +#define FE_MDIO_CFG_GP1_FRC_EN BIT(15)
4519 +#define FE_MDIO_CFG_GP1_SPEED_10 (0 << 13)
4520 +#define FE_MDIO_CFG_GP1_SPEED_100 (1 << 13)
4521 +#define FE_MDIO_CFG_GP1_SPEED_1000 (2 << 13)
4522 +#define FE_MDIO_CFG_GP1_DUPLEX BIT(12)
4523 +#define FE_MDIO_CFG_GP1_FC_TX BIT(11)
4524 +#define FE_MDIO_CFG_GP1_FC_RX BIT(10)
4525 +#define FE_MDIO_CFG_GP1_LNK_DWN BIT(9)
4526 +#define FE_MDIO_CFG_GP1_AN_FAIL BIT(8)
4527 +#define FE_MDIO_CFG_MDC_CLK_DIV_1 (0 << 6)
4528 +#define FE_MDIO_CFG_MDC_CLK_DIV_2 (1 << 6)
4529 +#define FE_MDIO_CFG_MDC_CLK_DIV_4 (2 << 6)
4530 +#define FE_MDIO_CFG_MDC_CLK_DIV_8 (3 << 6)
4531 +#define FE_MDIO_CFG_TURBO_MII_FREQ BIT(5)
4532 +#define FE_MDIO_CFG_TURBO_MII_MODE BIT(4)
4533 +#define FE_MDIO_CFG_RX_CLK_SKEW_0 (0 << 2)
4534 +#define FE_MDIO_CFG_RX_CLK_SKEW_200 (1 << 2)
4535 +#define FE_MDIO_CFG_RX_CLK_SKEW_400 (2 << 2)
4536 +#define FE_MDIO_CFG_RX_CLK_SKEW_INV (3 << 2)
4537 +#define FE_MDIO_CFG_TX_CLK_SKEW_0 0
4538 +#define FE_MDIO_CFG_TX_CLK_SKEW_200 1
4539 +#define FE_MDIO_CFG_TX_CLK_SKEW_400 2
4540 +#define FE_MDIO_CFG_TX_CLK_SKEW_INV 3
4542 +/* uni-cast port */
4543 +#define FE_GDM1_ICS_EN BIT(22)
4544 +#define FE_GDM1_TCS_EN BIT(21)
4545 +#define FE_GDM1_UCS_EN BIT(20)
4546 +#define FE_GDM1_JMB_EN BIT(19)
4547 +#define FE_GDM1_STRPCRC BIT(16)
4548 +#define FE_GDM1_UFRC_P_CPU (0 << 12)
4549 +#define FE_GDM1_UFRC_P_GDMA1 (1 << 12)
4550 +#define FE_GDM1_UFRC_P_PPE (6 << 12)
4553 +#define FE_ICS_GEN_EN BIT(2)
4554 +#define FE_UCS_GEN_EN BIT(1)
4555 +#define FE_TCS_GEN_EN BIT(0)
4558 +#define FE_PST_DRX_IDX0 BIT(16)
4559 +#define FE_PST_DTX_IDX3 BIT(3)
4560 +#define FE_PST_DTX_IDX2 BIT(2)
4561 +#define FE_PST_DTX_IDX1 BIT(1)
4562 +#define FE_PST_DTX_IDX0 BIT(0)
4564 +#define FE_TX_WB_DDONE BIT(6)
4565 +#define FE_RX_DMA_BUSY BIT(3)
4566 +#define FE_TX_DMA_BUSY BIT(1)
4567 +#define FE_RX_DMA_EN BIT(2)
4568 +#define FE_TX_DMA_EN BIT(0)
4570 +#define FE_PDMA_SIZE_4DWORDS (0 << 4)
4571 +#define FE_PDMA_SIZE_8DWORDS (1 << 4)
4572 +#define FE_PDMA_SIZE_16DWORDS (2 << 4)
4574 +#define FE_US_CYC_CNT_MASK 0xff
4575 +#define FE_US_CYC_CNT_SHIFT 0x8
4576 +#define FE_US_CYC_CNT_DIVISOR 1000000
4578 +#define RX_DMA_PLEN0(_x) (((_x) >> 16) & 0x3fff)
4579 +#define RX_DMA_LSO BIT(30)
4580 +#define RX_DMA_DONE BIT(31)
4581 +#define RX_DMA_L4VALID BIT(30)
4584 + unsigned int rxd1;
4585 + unsigned int rxd2;
4586 + unsigned int rxd3;
4587 + unsigned int rxd4;
4588 +} __packed __aligned(4);
4590 +#define TX_DMA_PLEN0_MASK ((0x3fff) << 16)
4591 +#define TX_DMA_PLEN0(_x) (((_x) & 0x3fff) << 16)
4592 +#define TX_DMA_PLEN1(_x) ((_x) & 0x3fff)
4593 +#define TX_DMA_LS1 BIT(14)
4594 +#define TX_DMA_LSO BIT(30)
4595 +#define TX_DMA_DONE BIT(31)
4596 +#define TX_DMA_QN(_x) ((_x) << 16)
4597 +#define TX_DMA_PN(_x) ((_x) << 24)
4598 +#define TX_DMA_QN_MASK TX_DMA_QN(0x7)
4599 +#define TX_DMA_PN_MASK TX_DMA_PN(0x7)
4600 +#define TX_DMA_CHKSUM (0x7 << 29)
4603 + unsigned int txd1;
4604 + unsigned int txd2;
4605 + unsigned int txd3;
4606 + unsigned int txd4;
4607 +} __packed __aligned(4);
4612 + struct phy_device *phy[8];
4613 + struct device_node *phy_node[8];
4614 + const __be32 *phy_fixed[8];
4621 + int (*connect)(struct fe_priv *priv);
4622 + void (*disconnect)(struct fe_priv *priv);
4623 + void (*start)(struct fe_priv *priv);
4624 + void (*stop)(struct fe_priv *priv);
4629 + unsigned char mac[6];
4630 + const u32 *reg_table;
4632 + void (*init_data)(struct fe_soc_data *data);
4633 + void (*reset_fe)(void);
4634 + void (*set_mac)(struct fe_priv *priv, unsigned char *mac);
4635 + void (*fwd_config)(struct fe_priv *priv);
4636 + void (*tx_dma)(struct fe_priv *priv, int idx, struct sk_buff *skb);
4637 + void (*rx_dma)(struct fe_priv *priv, int idx, int len);
4638 + int (*switch_init)(struct fe_priv *priv);
4639 + int (*switch_config)(struct fe_priv *priv);
4640 + void (*port_init)(struct fe_priv *priv, struct device_node *port);
4641 + int (*has_carrier)(struct fe_priv *priv);
4642 + int (*mdio_init)(struct fe_priv *priv);
4643 + void (*mdio_cleanup)(struct fe_priv *priv);
4644 + int (*mdio_write)(struct mii_bus *bus, int phy_addr, int phy_reg, u16 val);
4645 + int (*mdio_read)(struct mii_bus *bus, int phy_addr, int phy_reg);
4646 + void (*mdio_adjust_link)(struct fe_priv *priv, int port);
4647 + int (*get_skb_header)(struct sk_buff *skb, void **iphdr, void **tcph, u64 *hdr_flags, void *priv);
4661 + spinlock_t page_lock;
4663 + struct fe_soc_data *soc;
4664 + struct net_device *netdev;
4665 + struct device *device;
4666 + unsigned long sysclk;
4668 + struct fe_rx_dma *rx_dma;
4669 + struct napi_struct rx_napi;
4670 + struct sk_buff *rx_skb[NUM_DMA_DESC];
4671 + dma_addr_t rx_phys;
4673 + struct fe_tx_dma *tx_dma;
4674 + struct tasklet_struct tx_tasklet;
4675 + struct sk_buff *tx_skb[NUM_DMA_DESC];
4676 + dma_addr_t tx_phys;
4677 + unsigned int tx_free_idx;
4679 + struct fe_phy *phy;
4680 + struct mii_bus *mii_bus;
4681 + int mii_irq[PHY_MAX_ADDR];
4685 + struct net_lro_mgr lro_mgr;
4686 + struct net_lro_desc lro_arr[8];
4689 +extern const struct of_device_id of_fe_match[];
4691 +void fe_w32(u32 val, unsigned reg);
4692 +u32 fe_r32(unsigned reg);
4694 +#endif /* FE_ETH_H */
4695 Index: linux-3.14.18/drivers/net/ethernet/ralink/soc_mt7620.c
4696 ===================================================================
4697 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4698 +++ linux-3.14.18/drivers/net/ethernet/ralink/soc_mt7620.c 2014-10-28 10:43:11.894131220 +0100
4701 + * This program is free software; you can redistribute it and/or modify
4702 + * it under the terms of the GNU General Public License as published by
4703 + * the Free Software Foundation; version 2 of the License
4705 + * This program is distributed in the hope that it will be useful,
4706 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4707 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4708 + * GNU General Public License for more details.
4710 + * You should have received a copy of the GNU General Public License
4711 + * along with this program; if not, write to the Free Software
4712 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4714 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4717 +#include <linux/module.h>
4718 +#include <linux/platform_device.h>
4719 +#include <linux/if_vlan.h>
4721 +#include <asm/mach-ralink/ralink_regs.h>
4723 +#include <mt7620.h>
4724 +#include "ralink_soc_eth.h"
4725 +#include "gsw_mt7620a.h"
4727 +#define MT7620A_CDMA_CSG_CFG 0x400
4728 +#define MT7620_DMA_VID (MT7620A_CDMA_CSG_CFG | 0x30)
4729 +#define MT7620A_DMA_2B_OFFSET BIT(31)
4730 +#define MT7620A_RESET_FE BIT(21)
4731 +#define MT7620A_RESET_ESW BIT(23)
4732 +#define MT7620_L4_VALID BIT(23)
4734 +#define SYSC_REG_RESET_CTRL 0x34
4735 +#define MAX_RX_LENGTH 1536
4737 +#define CDMA_ICS_EN BIT(2)
4738 +#define CDMA_UCS_EN BIT(1)
4739 +#define CDMA_TCS_EN BIT(0)
4741 +#define GDMA_ICS_EN BIT(22)
4742 +#define GDMA_TCS_EN BIT(21)
4743 +#define GDMA_UCS_EN BIT(20)
4745 +static const u32 rt5350_reg_table[FE_REG_COUNT] = {
4746 + [FE_REG_PDMA_GLO_CFG] = RT5350_PDMA_GLO_CFG,
4747 + [FE_REG_PDMA_RST_CFG] = RT5350_PDMA_RST_CFG,
4748 + [FE_REG_DLY_INT_CFG] = RT5350_DLY_INT_CFG,
4749 + [FE_REG_TX_BASE_PTR0] = RT5350_TX_BASE_PTR0,
4750 + [FE_REG_TX_MAX_CNT0] = RT5350_TX_MAX_CNT0,
4751 + [FE_REG_TX_CTX_IDX0] = RT5350_TX_CTX_IDX0,
4752 + [FE_REG_RX_BASE_PTR0] = RT5350_RX_BASE_PTR0,
4753 + [FE_REG_RX_MAX_CNT0] = RT5350_RX_MAX_CNT0,
4754 + [FE_REG_RX_CALC_IDX0] = RT5350_RX_CALC_IDX0,
4755 + [FE_REG_FE_INT_ENABLE] = RT5350_FE_INT_ENABLE,
4756 + [FE_REG_FE_INT_STATUS] = RT5350_FE_INT_STATUS,
4757 + [FE_REG_FE_DMA_VID_BASE] = MT7620_DMA_VID,
4760 +static void mt7620_fe_reset(void)
4762 + rt_sysc_w32(MT7620A_RESET_FE | MT7620A_RESET_ESW, SYSC_REG_RESET_CTRL);
4763 + rt_sysc_w32(0, SYSC_REG_RESET_CTRL);
4766 +static void mt7620_fwd_config(struct fe_priv *priv)
4770 + /* frame engine will push VLAN tag regarding to VIDX feild in Tx desc. */
4771 + for (i = 0; i < 16; i += 2)
4772 + fe_w32(((i + 1) << 16) + i, MT7620_DMA_VID + (i * 2));
4774 + fe_w32(fe_r32(MT7620A_GDMA1_FWD_CFG) & ~7, MT7620A_GDMA1_FWD_CFG);
4775 + fe_w32(fe_r32(MT7620A_GDMA1_FWD_CFG) | (GDMA_ICS_EN | GDMA_TCS_EN | GDMA_UCS_EN), MT7620A_GDMA1_FWD_CFG);
4776 + fe_w32(fe_r32(MT7620A_CDMA_CSG_CFG) | (CDMA_ICS_EN | CDMA_UCS_EN | CDMA_TCS_EN), MT7620A_CDMA_CSG_CFG);
4779 +static void mt7620_tx_dma(struct fe_priv *priv, int idx, struct sk_buff *skb)
4781 + unsigned int nr_frags = 0;
4782 + unsigned int len = 0;
4785 + nr_frags = skb_shinfo(skb)->nr_frags;
4786 + len = skb->len - skb->data_len;
4790 + priv->tx_dma[idx].txd2 = TX_DMA_LSO | TX_DMA_DONE;
4791 + else if (!nr_frags)
4792 + priv->tx_dma[idx].txd2 = TX_DMA_LSO | TX_DMA_PLEN0(len);
4794 + priv->tx_dma[idx].txd2 = TX_DMA_PLEN0(len);
4796 + if(skb && vlan_tx_tag_present(skb))
4797 + priv->tx_dma[idx].txd4 = 0x80 | (vlan_tx_tag_get(skb) >> 13) << 4 | (vlan_tx_tag_get(skb) & 0xF);
4799 + priv->tx_dma[idx].txd4 = 0;
4802 +static void mt7620_rx_dma(struct fe_priv *priv, int idx, int len)
4804 + priv->rx_dma[idx].rxd2 = RX_DMA_PLEN0(len);
4807 +#ifdef CONFIG_INET_LRO
4809 +mt7620_get_skb_header(struct sk_buff *skb, void **iphdr, void **tcph,
4810 + u64 *hdr_flags, void *_priv)
4812 + struct iphdr *iph = NULL;
4816 + * Make sure that this packet is Ethernet II, is not VLAN
4817 + * tagged, is IPv4, has a valid IP header, and is TCP.
4819 + if (skb->protocol == 0x0081)
4820 + vhdr_len = VLAN_HLEN;
4822 + iph = (struct iphdr *)(skb->data + vhdr_len);
4823 + if(iph->protocol != IPPROTO_TCP)
4827 + *tcph = skb->data + (iph->ihl << 2) + vhdr_len;
4828 + *hdr_flags = LRO_IPV4 | LRO_TCP;
4834 +static void mt7620_init_data(struct fe_soc_data *data)
4836 + if (mt7620_get_eco() >= 5)
4840 +static struct fe_soc_data mt7620_data = {
4841 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
4842 + .init_data = mt7620_init_data,
4843 + .reset_fe = mt7620_fe_reset,
4844 + .set_mac = mt7620_set_mac,
4845 + .fwd_config = mt7620_fwd_config,
4846 + .tx_dma = mt7620_tx_dma,
4847 + .rx_dma = mt7620_rx_dma,
4848 + .switch_init = mt7620_gsw_probe,
4849 + .switch_config = mt7620_gsw_config,
4850 + .port_init = mt7620_port_init,
4852 + .reg_table = rt5350_reg_table,
4853 + .pdma_glo_cfg = FE_PDMA_SIZE_16DWORDS | MT7620A_DMA_2B_OFFSET,
4854 + .rx_dly_int = RT5350_RX_DLY_INT,
4855 + .tx_dly_int = RT5350_TX_DLY_INT,
4856 + .checksum_bit = MT7620_L4_VALID,
4857 + .has_carrier = mt7620a_has_carrier,
4858 + .mdio_read = mt7620_mdio_read,
4859 + .mdio_write = mt7620_mdio_write,
4860 + .mdio_adjust_link = mt7620_mdio_link_adjust,
4861 +#ifdef CONFIG_INET_LRO
4862 + .get_skb_header = mt7620_get_skb_header,
4866 +const struct of_device_id of_fe_match[] = {
4867 + { .compatible = "ralink,mt7620a-eth", .data = &mt7620_data },
4871 +MODULE_DEVICE_TABLE(of, of_fe_match);
4872 Index: linux-3.14.18/drivers/net/ethernet/ralink/soc_rt2880.c
4873 ===================================================================
4874 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4875 +++ linux-3.14.18/drivers/net/ethernet/ralink/soc_rt2880.c 2014-10-28 10:43:11.894131220 +0100
4878 + * This program is free software; you can redistribute it and/or modify
4879 + * it under the terms of the GNU General Public License as published by
4880 + * the Free Software Foundation; version 2 of the License
4882 + * This program is distributed in the hope that it will be useful,
4883 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4884 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4885 + * GNU General Public License for more details.
4887 + * You should have received a copy of the GNU General Public License
4888 + * along with this program; if not, write to the Free Software
4889 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4891 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4894 +#include <linux/module.h>
4896 +#include <asm/mach-ralink/ralink_regs.h>
4898 +#include "ralink_soc_eth.h"
4899 +#include "mdio_rt2880.h"
4901 +#define SYSC_REG_RESET_CTRL 0x034
4902 +#define RT2880_RESET_FE BIT(18)
4904 +void rt2880_fe_reset(void)
4906 + rt_sysc_w32(RT2880_RESET_FE, SYSC_REG_RESET_CTRL);
4909 +struct fe_soc_data rt2880_data = {
4910 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
4911 + .reset_fe = rt2880_fe_reset,
4912 + .min_pkt_len = 64,
4913 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
4914 + .checksum_bit = RX_DMA_L4VALID,
4915 + .rx_dly_int = FE_RX_DLY_INT,
4916 + .tx_dly_int = FE_TX_DLY_INT,
4917 + .mdio_read = rt2880_mdio_read,
4918 + .mdio_write = rt2880_mdio_write,
4919 + .mdio_adjust_link = rt2880_mdio_link_adjust,
4920 + .port_init = rt2880_port_init,
4923 +const struct of_device_id of_fe_match[] = {
4924 + { .compatible = "ralink,rt2880-eth", .data = &rt2880_data },
4928 +MODULE_DEVICE_TABLE(of, of_fe_match);
4929 Index: linux-3.14.18/drivers/net/ethernet/ralink/soc_rt305x.c
4930 ===================================================================
4931 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4932 +++ linux-3.14.18/drivers/net/ethernet/ralink/soc_rt305x.c 2014-10-28 10:43:11.894131220 +0100
4935 + * This program is free software; you can redistribute it and/or modify
4936 + * it under the terms of the GNU General Public License as published by
4937 + * the Free Software Foundation; version 2 of the License
4939 + * This program is distributed in the hope that it will be useful,
4940 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4941 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4942 + * GNU General Public License for more details.
4944 + * You should have received a copy of the GNU General Public License
4945 + * along with this program; if not, write to the Free Software
4946 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
4948 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
4951 +#include <linux/module.h>
4953 +#include <asm/mach-ralink/ralink_regs.h>
4955 +#include "ralink_soc_eth.h"
4957 +#define RT305X_RESET_FE BIT(21)
4958 +#define RT305X_RESET_ESW BIT(23)
4959 +#define SYSC_REG_RESET_CTRL 0x034
4961 +static const u32 rt5350_reg_table[FE_REG_COUNT] = {
4962 + [FE_REG_PDMA_GLO_CFG] = RT5350_PDMA_GLO_CFG,
4963 + [FE_REG_PDMA_RST_CFG] = RT5350_PDMA_RST_CFG,
4964 + [FE_REG_DLY_INT_CFG] = RT5350_DLY_INT_CFG,
4965 + [FE_REG_TX_BASE_PTR0] = RT5350_TX_BASE_PTR0,
4966 + [FE_REG_TX_MAX_CNT0] = RT5350_TX_MAX_CNT0,
4967 + [FE_REG_TX_CTX_IDX0] = RT5350_TX_CTX_IDX0,
4968 + [FE_REG_RX_BASE_PTR0] = RT5350_RX_BASE_PTR0,
4969 + [FE_REG_RX_MAX_CNT0] = RT5350_RX_MAX_CNT0,
4970 + [FE_REG_RX_CALC_IDX0] = RT5350_RX_CALC_IDX0,
4971 + [FE_REG_FE_INT_ENABLE] = RT5350_FE_INT_ENABLE,
4972 + [FE_REG_FE_INT_STATUS] = RT5350_FE_INT_STATUS,
4973 + [FE_REG_FE_DMA_VID_BASE] = 0,
4976 +static void rt305x_fe_reset(void)
4978 + rt_sysc_w32(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
4979 + rt_sysc_w32(0, SYSC_REG_RESET_CTRL);
4982 +static void rt5350_set_mac(struct fe_priv *priv, unsigned char *mac)
4984 + unsigned long flags;
4986 + spin_lock_irqsave(&priv->page_lock, flags);
4987 + fe_w32((mac[0] << 8) | mac[1], RT5350_SDM_MAC_ADRH);
4988 + fe_w32((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
4989 + RT5350_SDM_MAC_ADRL);
4990 + spin_unlock_irqrestore(&priv->page_lock, flags);
4993 +static void rt5350_fwd_config(struct fe_priv *priv)
4995 + unsigned long sysclk = priv->sysclk;
4998 + sysclk /= FE_US_CYC_CNT_DIVISOR;
4999 + sysclk <<= FE_US_CYC_CNT_SHIFT;
5001 + fe_w32((fe_r32(FE_FE_GLO_CFG) &
5002 + ~(FE_US_CYC_CNT_MASK << FE_US_CYC_CNT_SHIFT)) | sysclk,
5006 + fe_w32(fe_r32(RT5350_SDM_CFG) & ~0xffff, RT5350_SDM_CFG);
5007 + fe_w32(fe_r32(RT5350_SDM_CFG) | RT5350_SDM_ICS_EN | RT5350_SDM_TCS_EN | RT5350_SDM_UCS_EN,
5011 +static void rt5350_fe_reset(void)
5013 + rt_sysc_w32(RT305X_RESET_FE | RT305X_RESET_ESW, SYSC_REG_RESET_CTRL);
5014 + rt_sysc_w32(0, SYSC_REG_RESET_CTRL);
5017 +static struct fe_soc_data rt3050_data = {
5018 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
5019 + .reset_fe = rt305x_fe_reset,
5020 + .min_pkt_len = 64,
5021 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
5022 + .checksum_bit = RX_DMA_L4VALID,
5023 + .rx_dly_int = FE_RX_DLY_INT,
5024 + .tx_dly_int = FE_TX_DLY_INT,
5027 +static struct fe_soc_data rt5350_data = {
5028 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
5029 + .reg_table = rt5350_reg_table,
5030 + .reset_fe = rt5350_fe_reset,
5031 + .set_mac = rt5350_set_mac,
5032 + .fwd_config = rt5350_fwd_config,
5033 + .min_pkt_len = 64,
5034 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
5035 + .checksum_bit = RX_DMA_L4VALID,
5036 + .rx_dly_int = RT5350_RX_DLY_INT,
5037 + .tx_dly_int = RT5350_TX_DLY_INT,
5040 +const struct of_device_id of_fe_match[] = {
5041 + { .compatible = "ralink,rt3050-eth", .data = &rt3050_data },
5042 + { .compatible = "ralink,rt5350-eth", .data = &rt5350_data },
5046 +MODULE_DEVICE_TABLE(of, of_fe_match);
5047 Index: linux-3.14.18/drivers/net/ethernet/ralink/soc_rt3883.c
5048 ===================================================================
5049 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
5050 +++ linux-3.14.18/drivers/net/ethernet/ralink/soc_rt3883.c 2014-10-28 10:43:11.894131220 +0100
5053 + * This program is free software; you can redistribute it and/or modify
5054 + * it under the terms of the GNU General Public License as published by
5055 + * the Free Software Foundation; version 2 of the License
5057 + * This program is distributed in the hope that it will be useful,
5058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5060 + * GNU General Public License for more details.
5062 + * You should have received a copy of the GNU General Public License
5063 + * along with this program; if not, write to the Free Software
5064 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
5066 + * Copyright (C) 2009-2013 John Crispin <blogic@openwrt.org>
5069 +#include <linux/module.h>
5071 +#include <asm/mach-ralink/ralink_regs.h>
5073 +#include "ralink_soc_eth.h"
5074 +#include "mdio_rt2880.h"
5076 +#define RT3883_SYSC_REG_RSTCTRL 0x34
5077 +#define RT3883_RSTCTRL_FE BIT(21)
5079 +static void rt3883_fe_reset(void)
5083 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
5084 + t |= RT3883_RSTCTRL_FE;
5085 + rt_sysc_w32(t , RT3883_SYSC_REG_RSTCTRL);
5087 + t &= ~RT3883_RSTCTRL_FE;
5088 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
5091 +static struct fe_soc_data rt3883_data = {
5092 + .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
5093 + .reset_fe = rt3883_fe_reset,
5094 + .min_pkt_len = 64,
5095 + .pdma_glo_cfg = FE_PDMA_SIZE_4DWORDS,
5096 + .rx_dly_int = FE_RX_DLY_INT,
5097 + .tx_dly_int = FE_TX_DLY_INT,
5098 + .checksum_bit = RX_DMA_L4VALID,
5099 + .mdio_read = rt2880_mdio_read,
5100 + .mdio_write = rt2880_mdio_write,
5101 + .mdio_adjust_link = rt2880_mdio_link_adjust,
5102 + .port_init = rt2880_port_init,
5105 +const struct of_device_id of_fe_match[] = {
5106 + { .compatible = "ralink,rt3883-eth", .data = &rt3883_data },
5110 +MODULE_DEVICE_TABLE(of, of_fe_match);