ER-X-SFP - SFP (eth5) port has link-state (LED = lit), but swconfig says link: port:5 link:down

Are aware of these patches? https://git.openwrt.org/?p=openwrt/openwrt.git;a=tree;f=target/linux/mediatek/patches-4.14;h=8f346d1ae96773d5ad7ff1ac611fdc5449288c14;hb=HEAD
Like: 0033-dsa-multi-cpu.patch

Thats for the MT7622 and MT7623 SoCs

Correct, but switch peripheral is the same.

https://lkml.org/lkml/2018/3/14/1046:

The GSW is found in all of the 1000mbit SoCs. it has 5 external ports,
1-2 cpu ports and 1 further port that the internal HW offloading engine
connects to. The switch core used is a MT7530, which also exists as a
standalone chip. Although these SoCs (mt7620/1/3) share the same switch
core, the bring up of these is slightly different. One of the reasons is
that on mt7620 the switch core is mmio mapped while MT7621/3 talks to the
switch via MDIO addr 0x1f. Additionally, the SoCs have different MAC types
and some of them have TRGMII support. MT7621 can do 1,2gbit and MT7623 is
able to do 2,6gbit. The support for the TRGMII bring up is not part of this
series as the code is based on the SDK driver and has between 1500 and 2000
magic values that still need to be converted to defines.

As John Crispin mention in a mailing list, it should be easy to adapt the code for mt7621.

1 Like

I have some results.
I have inserted a FS - SFP-GB-GE-T sfp to RJ45 in erx-sfp.

SFP port 5 is working but only RX is not working.
I see with tcpdump packets from my erx-sfp but it doesn't gets anything back.
I think a vlan or RX setting issue.
swconfig show link is up even without a cable plug-in.

SFP port is is an extra port on the switch (port 5) and is not a separate interface in linux.

Current state: https://github.com/vdorst/openwrt/tree/er-x-sfp

I also spoke with John and he points me to the mt7620 code. Converting mt7621 code to mt7620 should be an improvement.

SWCONFIG looks like.
VLAN 1:
vid: 1
ports: 1 2 3 4 6t
VLAN 2:
vid: 2
ports: 0 6t
VLAN 3:
vid: 3
ports: 5 6t

Awesome work.

I try to use the mt7623 and mt7530 mainline driver.

Drivers are loading but irq's, resets, mt7623 stuff needs to be checked.
The driver also uses the many sub-systems that mt7623 has.
Many do not exists or I not aware of because lake of up-to-data datasheet.
For me it is hard to map the "current" code with the new OF/dsa/mainline code.

Current DMESG

Starting kernel ...

[ 0.000000] Linux version 4.14.50 (buildbot@ipa) (gcc version 7.3.0 (OpenWrt GCC 7.3.0 r7284-3d20bee2cd)) #0 SMP Mon Jul 2 21:10:53 2018
[ 0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
[ 0.000000] bootconsole [early0] enabled
[ 0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
[ 0.000000] MIPS: machine is UBNT-ERX-SFP
[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 10000000 @ 00000000 (usable)
[ 0.000000] Initrd not found or empty - disabling initrd
[ 0.000000] VPE topology {2,2} total 4
[ 0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.000000] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x0000000000000000-0x000000000fffffff]
[ 0.000000] HighMem empty
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000000000000-0x000000000fffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000000fffffff]
[ 0.000000] random: get_random_bytes called from start_kernel+0x90/0x4a4 with crng_init=0
[ 0.000000] percpu: Embedded 14 pages/cpu @81211000 s26192 r8192 d22960 u57344
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 65024
[ 0.000000] Kernel command line: console=ttyS0,57600 rootfstype=squashfs,jffs2
[ 0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[ 0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[ 0.000000] Writing ErrCtl register=00018410
[ 0.000000] Readback ErrCtl register=00018410
[ 0.000000] Memory: 251464K/262144K available (4477K kernel code, 182K rwdata, 1004K rodata, 2132K init, 289K bss, 10680K reserved, 0K cma-reserved, 0K highmem)
[ 0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[ 0.000000] Hierarchical RCU implementation.
[ 0.000000] NR_IRQS: 256
[ 0.000000] clocksource: GIC: mask: 0xffffffffffffffff max_cycles: 0xcaf478abb4, max_idle_ns: 440795247997 ns
[ 0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 4343773742 ns
[ 0.000009] sched_clock: 32 bits at 440MHz, resolution 2ns, wraps every 4880645118ns
[ 0.015484] Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)
[ 0.087800] pid_max: default: 32768 minimum: 301
[ 0.097104] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.110121] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.125660] Hierarchical SRCU implementation.
[ 0.134953] smp: Bringing up secondary CPUs ...
[ 0.144403] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.144412] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.144424] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.144554] CPU1 revision is: 0001992f (MIPS 1004Kc)
[ 0.204450] Synchronize counters for CPU 1: done.
[ 0.267885] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.267893] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.267902] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.267974] CPU2 revision is: 0001992f (MIPS 1004Kc)
[ 0.324965] Synchronize counters for CPU 2: done.
[ 0.385093] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.385100] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.385107] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.385186] CPU3 revision is: 0001992f (MIPS 1004Kc)
[ 0.444530] Synchronize counters for CPU 3: done.
[ 0.504128] smp: Brought up 1 node, 4 CPUs
[ 0.516013] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.535477] futex hash table entries: 1024 (order: 3, 32768 bytes)
[ 0.547902] pinctrl core: initialized pinctrl subsystem
[ 0.559471] NET: Registered protocol family 16
[ 0.585216] mt7621_gpio 1e000600.gpio: registering 32 gpios
[ 0.596467] mt7621_gpio 1e000600.gpio: registering 32 gpios
[ 0.607651] mt7621_gpio 1e000600.gpio: registering 32 gpios
[ 0.619613] fixed-3.3V: Failed to create debugfs directory
[ 0.632543] clocksource: Switched to clocksource GIC
[ 0.643864] NET: Registered protocol family 2
[ 0.653084] TCP established hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.666845] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.679611] TCP: Hash tables configured (established 2048 bind 2048)
[ 0.692324] UDP hash table entries: 256 (order: 1, 8192 bytes)
[ 0.703827] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[ 0.716503] NET: Registered protocol family 1
[ 2.592495] 4 CPUs re-calibrate udelay(lpj = 2924544)
[ 2.603794] Crashlog allocated RAM at address 0x3f00000
[ 2.614246] workingset: timestamp_bits=30 max_order=16 bucket_order=0
[ 2.629040] random: fast init done
[ 2.633459] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[ 2.633466] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[ 2.637107] io scheduler noop registered
[ 2.637116] io scheduler deadline registered (default)
[ 2.687870] Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
[ 2.701862] console [ttyS0] disabled
[ 2.708960] 1e000c00.uartlite: ttyS0 at MMIO 0x1e000c00 (irq = 18, base_baud = 3125000) is a 16550A
[ 2.726849] console [ttyS0] enabled
[ 2.726849] console [ttyS0] enabled
[ 2.740634] bootconsole [early0] disabled
[ 2.740634] bootconsole [early0] disabled
[ 2.757206] cacheinfo: Unable to detect cache hierarchy for CPU 0
[ 2.770091] MediaTek Nand driver init, version v2.1 Fix AHB virt2phys error
[ 2.784196] Allocate 16 byte aligned buffer: 807d6ce0
[ 2.794251] Enable NFI Clock
[ 2.799967] # MTK NAND # : Use HW ECC
[ 2.807267] Device found in MTK table, ID: 1da, EXT_ID: 909546
[ 2.818882] Support this Device in MTK table! 1da
[ 2.828593] [NAND]select ecc bit:12, sparesize :112 spare_per_sector=28
[ 2.841803] nand: device found, Manufacturer ID: 0x01, Chip ID: 0xda
[ 2.854446] nand: AMD/Spansion NAND 256MiB 3,3V 8-bit
[ 2.864497] nand: 256 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[ 2.879572] Scanning device for bad blocks
[ 3.522926] 6 fixed-partitions partitions found on MTD device MT7621-NAND
[ 3.536438] Creating 6 MTD partitions on "MT7621-NAND":
[ 3.546844] 0x000000000000-0x000000080000 : "u-boot"
[ 3.557758] 0x000000080000-0x0000000e0000 : "u-boot-env"
[ 3.569294] 0x0000000e0000-0x000000140000 : "factory"
[ 3.580342] 0x000000140000-0x000000440000 : "kernel1"
[ 3.591402] 0x000000440000-0x000000740000 : "kernel2"
[ 3.602442] 0x000000740000-0x00000ff00000 : "ubi"
[ 3.614709] [mtk_nand] probe successfully!
[ 3.623628] Signature matched and data read!
[ 3.632109] load_fact_bbt success 2047
[ 3.641370] libphy: Fixed MDIO Bus: probed
[ 3.649753] mt7530 0.switch: MT7530 adapts as multi-chip module
[ 3.702539] MT7621: GE2: Pininit
[ 3.708975] mtk_soc_eth 1e100000.ethernet: chip id = 7621
[ 3.720027] libphy: mdio: probed
[ 3.758114] drivers/net/ethernet/mediatek/mtk_eth_soc.c:mtk_mdio_init[418]0 8ff1cc00
[ 3.773629] mtk_soc_eth 1e100000.ethernet: generated random MAC address da:2f:31:b0:25:32
[ 3.805627] mtk_soc_eth 1e100000.ethernet: connected mac 0 to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]
[ 3.826934] mtk_soc_eth 1e100000.ethernet eth0: mediatek frame engine at 0xbe100000, irq 21
[ 3.843632] mtk_soc_eth 1e100000.ethernet: generated random MAC address ee:30:12:a2:3c:d9
[ 3.875341] mtk_soc_eth 1e100000.ethernet: connected mac 1 to PHY at fixed-0:01 [uid=00000000, driver=Generic PHY]
[ 3.896660] mtk_soc_eth 1e100000.ethernet eth1: mediatek frame engine at 0xbe100000, irq 21
[ 3.915356] NET: Registered protocol family 10
[ 3.925930] Segment Routing with IPv6
[ 3.933387] NET: Registered protocol family 17
[ 3.942675] 8021q: 802.1Q VLAN Support v1.8
[ 3.953075] mt7530 0.switch: MT7530 adapts as multi-chip module
[ 3.965188] DSA: switch 0 0 parsed
[ 3.971952] DSA: tree 0 parsed
[ 5.847620] libphy: dsa slave smi: probed
[ 5.892544] Generic PHY dsa-0.0:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:00, irq=POLL)
[ 5.952551] Generic PHY dsa-0.0:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:01, irq=POLL)
[ 6.012543] Generic PHY dsa-0.0:02: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:02, irq=POLL)
[ 6.072548] Generic PHY dsa-0.0:03: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:03, irq=POLL)
[ 6.132537] Generic PHY dsa-0.0:04: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:04, irq=POLL)
[ 7.392530] mt7530 0.switch: failed to priv write register
[ 7.403469] mt7530 0.switch: failed to priv write register
[ 7.414387] mt7530 0.switch: failed to priv write register
[ 7.425305] mt7530 0.switch: failed to priv write register
[ 7.436224] mt7530 0.switch: failed to priv write register
[ 7.447144] mt7530 0.switch: failed to priv read register
[ 7.457890] mt7530 0.switch: failed to priv write register
[ 7.468813] mt7530 0.switch: failed to priv read register
[ 7.479558] mt7530 0.switch: failed to priv write register
[ 7.491520] UBI: auto-attach mtd5
[ 7.498142] ubi0: attaching mtd5
[ 9.948713] ubi0: scanning is finished
[ 9.973985] ubi0: attached mtd5 (name "ubi", size 247 MiB)
[ 9.984962] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 9.998646] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 10.012161] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 10.026021] ubi0: good PEBs: 1982, bad PEBs: 0, corrupted PEBs: 0
[ 10.038168] ubi0: user volume: 2, internal volumes: 1, max. volumes count: 128
[ 10.052551] ubi0: max/mean erase counter: 12/6, WL threshold: 4096, image sequence number: 162887144
[ 10.070735] ubi0: available PEBs: 0, total reserved PEBs: 1982, PEBs reserved for bad PEB handling: 40
[ 10.089295] ubi0: background thread "ubi_bgt0d" started, PID 409
[ 10.091162] block ubiblock0_0: created from ubi0:0(rootfs)
[ 10.091174] ubiblock: device ubiblock0_0 (rootfs) set to be root filesystem
[ 10.091191] hctosys: unable to open rtc device (rtc0)
[ 10.143949] Freeing unused kernel memory: 2132K
[ 10.153035] This architecture does not have kernel memory protection.
[ 10.176141] init: Console is alive
[ 10.183222] init: - watchdog -
[ 10.204605] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[ 10.221386] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[ 10.242811] init: - preinit -
Failed to connect to the switch. Use the "list" command to see which switches are available.
Failed to connect to the switch. Use the "list" command to see which switches are available.
Failed to connect to the switch. Use the "list" command to see which switches are available.
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[ 13.482884] procd: - early -
[ 13.488701] procd: - watchdog -
[ 14.102668] procd: - watchdog -
[ 14.109202] procd: - ubus -
[ 14.119518] random: ubusd: uninitialized urandom read (4 bytes read)
[ 14.173179] random: ubusd: uninitialized urandom read (4 bytes read)
[ 14.186202] random: ubusd: uninitialized urandom read (4 bytes read)
[ 14.199712] procd: - init -
Please press Enter to activate this console.
[ 14.332117] kmodloader: loading kernel modules from /etc/modules.d/*
[ 14.347906] ip6_tables: (C) 2000-2006 Netfilter Core Team
[ 14.715966] i2c /dev entries driver
[ 14.727404] pca953x 0-0025: 0-0025 supply vcc not found, using dummy regulator
[ 14.751824] pca953x 0-0025: interrupt support not compiled in
[ 14.763453] i2c-gpio i2c-gpio: using pins 3 (SDA) and 4 (SCL)
[ 14.778725] ip_tables: (C) 2000-2006 Netfilter Core Team
[ 15.138118] nf_conntrack version 0.5.0 (4096 buckets, 16384 max)
[ 15.358422] Netfilter messages via NETLINK v0.30.
[ 15.377340] xt_time: kernel timezone is -0000
[ 15.547309] nf_tables: (c) 2007-2009 Patrick McHardy kaber@trash.net
[ 15.580534] PPP generic driver version 2.4.2
[ 15.590338] NET: Registered protocol family 24
[ 15.603598] kmodloader: done loading kernel modules from /etc/modules.d/*
[ 16.684372] urandom_read: 5 callbacks suppressed
[ 16.684382] random: jshn: uninitialized urandom read (4 bytes read)
[ 16.751593] random: jshn: uninitialized urandom read (4 bytes read)
[ 20.064130] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 20.076021] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 20.294104] br-lan: port 1(lan0) entered blocking state
[ 20.304552] br-lan: port 1(lan0) entered disabled state
[ 20.372647] device lan0 entered promiscuous mode
[ 20.381855] device eth0 entered promiscuous mode
[ 20.523236] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
[ 20.783566] br-lan: port 2(lan1) entered blocking state
[ 20.794020] br-lan: port 2(lan1) entered disabled state
[ 20.922550] device lan1 entered promiscuous mode
[ 21.313578] br-lan: port 3(lan2) entered blocking state
[ 21.324031] br-lan: port 3(lan2) entered disabled state
[ 21.532547] device lan2 entered promiscuous mode
[ 21.924036] br-lan: port 4(lan3) entered blocking state
[ 21.934505] br-lan: port 4(lan3) entered disabled state
[ 22.212556] device lan3 entered promiscuous mode
[ 22.382552] mt7530 0.switch lan0: Link is Down
[ 22.633591] br-lan: port 5(lan4) entered blocking state
[ 22.644050] br-lan: port 5(lan4) entered disabled state
[ 22.992556] device lan4 entered promiscuous mode
[ 23.182631] mt7530 0.switch lan1: Link is Down
[ 23.312786] mt7530 0.switch lan2: Link is Down
[ 24.122569] mt7530 0.switch lan3: Link is Down
[ 24.482535] mt7530 0.switch lan4: Link is Down
[ 24.582602] br-lan: port 1(lan0) entered blocking state
[ 24.593031] br-lan: port 1(lan0) entered forwarding state
[ 24.622550] mt7530 0.switch lan0: Link is Up - 1Gbps/Full - flow control rx/tx
[ 24.752575] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[ 25.774369] random: crng init done

BusyBox v1.28.4 () built-in shell (ash)


| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -| || | | || || |
|
_____|| |
||||___||| |____|
|
| W I R E L E S S F R E E D O M

OpenWrt SNAPSHOT, r7284+5-3d20bee2cd

=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.

root@OpenWrt:/# [ 50.512513] ------------[ cut here ]------------
[ 50.521748] WARNING: CPU: 2 PID: 0 at net/sched/sch_generic.c:320 dev_watchdog+0x1ac/0x324
[ 50.538203] NETDEV WATCHDOG: eth0 (mtk_soc_eth): transmit queue 0 timed out
[ 50.552049] Modules linked in: pppoe ppp_async nf_flow_table_ipv6 nf_flow_table_ipv4 nf_flow_table_inet pppox ppp_generic nft_set_rbtree nft_set_hash nft_reject_ipv6 nft_reject_ipv4 nft_reject_inet nft_reject nft_redir_ipv4 nft_redir nft_quota nft_numgen nft_nat nft_meta nft_masq_ipv4 nft_masq nft_log nft_limit nft_flow_offload nft_exthdr nft_ct nft_counter nft_chain_route_ipv6 nft_chain_route_ipv4 nft_chain_nat_ipv4 nf_tables_ipv6 nf_tables_ipv4 nf_tables_inet nf_tables nf_conntrack_ipv6 iptable_nat ipt_REJECT ipt_MASQUERADE xt_time xt_tcpudp xt_state xt_nat xt_multiport xt_mark xt_mac xt_limit xt_conntrack xt_comment xt_TCPMSS xt_REDIRECT xt_LOG xt_FLOWOFFLOAD slhc nfnetlink nf_reject_ipv4 nf_nat_redirect nf_nat_masquerade_ipv4 nf_conntrack_ipv4 nf_nat_ipv4 nf_nat nf_log_ipv4 nf_flow_table_hw nf_flow_table
[ 50.694703] nf_defrag_ipv6 nf_defrag_ipv4 nf_conntrack_rtcache nf_conntrack mdio_gpio mdio_bitbang iptable_mangle iptable_filter ip_tables crc_ccitt i2c_gpio i2c_algo_pca i2c_algo_bit gpio_pca953x i2c_dev ip6t_REJECT nf_reject_ipv6 nf_log_ipv6 nf_log_common ip6table_mangle ip6table_filter ip6_tables x_tables leds_gpio gpio_button_hotplug
[ 50.754445] CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.14.50 #0
[ 50.766381] Stack : 00000000 00000000 00000000 00000000 807a7ad2 00000034 00000000 00000000
[ 50.783009] 8fc44834 80570947 804fe7bc 00000002 00000000 00000001 8fc11d68 532616d3
[ 50.799636] 00000000 00000000 807a0000 00004808 00000000 000000ea 00000007 00000000
[ 50.816262] 00000000 80570000 000b830d 00000000 00000000 00000000 80590000 80362bd8
[ 50.832888] 00000009 00000140 00000002 8ffa0840 00000003 802883c8 00000008 807a0008
[ 50.849514] ...
[ 50.854371] Call Trace:
[ 50.859243] [<80010558>] show_stack+0x58/0x100
[ 50.868085] [<8044213c>] dump_stack+0x9c/0xe0
[ 50.876748] [<8002e218>] __warn+0xe0/0x114
[ 50.884889] [<8002e27c>] warn_slowpath_fmt+0x30/0x3c
[ 50.894761] [<80362bd8>] dev_watchdog+0x1ac/0x324
[ 50.904127] [<80086014>] call_timer_fn.isra.3+0x24/0x84
[ 50.914516] [<8008622c>] run_timer_softirq+0x1b8/0x244
[ 50.924742] [<8045f308>] __do_softirq+0x128/0x2ec
[ 50.934100] [<80032920>] irq_exit+0x98/0xcc
[ 50.942428] [<8023a03c>] plat_irq_dispatch+0xfc/0x138
[ 50.952469] [<8000b5a8>] except_vec_vi_end+0xb8/0xc4
[ 50.962338] [<8000cf70>] r4k_wait_irqoff+0x1c/0x24
[ 50.971883] [<800662cc>] do_idle+0xe4/0x168
[ 50.980198] [<80066548>] cpu_startup_entry+0x24/0x2c
[ 50.990078] [<800180b4>] not_nmi+0x8c/0x1d8
[ 50.998509] ---[ end trace 009feb55999f6440 ]---
[ 51.007701] mtk_soc_eth 1e100000.ethernet eth0: transmit timed out
[ 51.062528] MT7621: GE2: Pininit

Use the kernel source to make a patch for buildroot
like: git diff v4.14.50-owrt > ../openwrt/target/linux/ramips/patches-4.14/2000-mt7621-ethernet.patch

Kernel: https://github.com/vDorst/linux-1/commits/v4.14.50-dsa
Buildroot: https://github.com/vDorst/openwrt/tree/mt7621-ramips-dsa

1 Like

Don't waste your time. "The MT7621 is just as completely different as night and day from MT7622." (C) Mediatek, so MT762[01] - based on RALINK IP-blocks, all other - on Mediatek vision of same IP-blocks.
For MT7621 you need program, at least, 3 parts - SoC (DMA, interrupts, GPIO), SoC-FE (FrameEngine - DMA queues, interrupts, MDIO-bus) and GSW (MT7630). Programming MT7630 is trivial, but other...

Remember about "SFP is a class 1 laser device." Protect your eyes.
SFP module controlled via GPIO (at least TX_DISABLE must be pulled down when LOS is cleared).
Read https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/net/sff%2Csfp.txt and construct right dts node for SFP.

"The MT7621 is just as completely different as night and day from MT7622." (C) Mediatek, so MT762[01] - based on RALINK IP-blocks, all other - on Mediatek vision of same IP-blocks.

I don't think it is a waste of time.
Is mostly true for interrupt controller and CPU but FE, ETH and GSW are very similar.

MDIO and GSW are working.
Most problem is the setup of the right IRQ, TRGMII CLK, ETH.

Remember about "SFP is a class 1 laser device." Protect your eyes.
SFP module controlled via GPIO (at least TX_DISABLE must be pulled down when LOS is cleared).
Read https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/net/sff%2Csfp.txt and construct right dts node for SFP.

I am using SFP RJ45 module. AR8033 seems to work out of the box. (LED eth5 is blinking of traffic).
Also in the Ubiquiti source code I can't find any GPIO usage for I2C and GPIO to SFP cage.
I did a I2C scan on the bus but only find the io expander. I know there was an example code on the ubiquiti forum to readout SFP data but can't find it back to see where the get the data from.

So a DTS binding is not needed at the moment. If I want a ether port to work right I can also select P0 or P4 which connects to P5.

For now it is important to setup the DMA and IRQ right. Probably a simple register which is different.

Step further right now. Mainline driver was missing IRQ handler for MT7621.
MT7621 seems only have 1 IRQ for ethernet subsysem (incl, PDMA and QDMA).
MT7623 is using the DMAs in the same way MT7621 does. PDMA for RX and QDMA for TX.

The mainline driver supports also the second GMAC.
But I did not have time the further explore the GSW settings to setup P5.

I pushed work the my github see links above.

So DSA is almost working out of the box, I had to disable the powerctl.
Eth5 is not working. It needs more setup code. May to try connect P4 to 2nd GMAC and see how that goes.

DMESG LOG, Click here

Starting kernel ...

[ 0.000000] Linux version 4.14.50 (buildbot@ipa) (gcc version 7.3.0 (OpenWrt GCC 7.3.0 r7284-3d20be e2cd)) #0 SMP Mon Jul 2 22:17:22 2018
[ 0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
[ 0.000000] bootconsole [early0] enabled
[ 0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
[ 0.000000] MIPS: machine is UBNT-ERX-SFP
[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 10000000 @ 00000000 (usable)
[ 0.000000] Initrd not found or empty - disabling initrd
[ 0.000000] VPE topology {2,2} total 4
[ 0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.000000] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x0000000000000000-0x000000000fffffff]
[ 0.000000] HighMem empty
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000000000000-0x000000000fffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000000fffffff]
[ 0.000000] random: get_random_bytes called from start_kernel+0x90/0x4a4 with crng_init=0
[ 0.000000] percpu: Embedded 14 pages/cpu @81211000 s26192 r8192 d22960 u57344
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 65024
[ 0.000000] Kernel command line: console=ttyS0,57600 rootfstype=squashfs,jffs2
[ 0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[ 0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[ 0.000000] Writing ErrCtl register=000586d0
[ 0.000000] Readback ErrCtl register=000586d0
[ 0.000000] Memory: 251464K/262144K available (4477K kernel code, 182K rwdata, 1004K rodata, 2132K init, 289K bss, 10680K reserved, 0K cma-reserved, 0K highmem)
[ 0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[ 0.000000] Hierarchical RCU implementation.
[ 0.000000] NR_IRQS: 256
[ 0.000000] clocksource: GIC: mask: 0xffffffffffffffff max_cycles: 0xcaf478abb4, max_idle_ns: 440795247997 ns
[ 0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 4343773742 ns
[ 0.000009] sched_clock: 32 bits at 440MHz, resolution 2ns, wraps every 4880645118ns
[ 0.015489] Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)
[ 0.087812] pid_max: default: 32768 minimum: 301
[ 0.097123] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.110141] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.125740] Hierarchical SRCU implementation.
[ 0.135092] smp: Bringing up secondary CPUs ...
[ 0.156882] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.156892] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.156903] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.157038] CPU1 revision is: 0001992f (MIPS 1004Kc)
[ 0.204565] Synchronize counters for CPU 1: done.
[ 0.280767] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.280776] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.280785] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.280859] CPU2 revision is: 0001992f (MIPS 1004Kc)
[ 0.325336] Synchronize counters for CPU 2: done.
[ 0.397774] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[ 0.397782] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[ 0.397789] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[ 0.397868] CPU3 revision is: 0001992f (MIPS 1004Kc)
[ 0.444901] Synchronize counters for CPU 3: done.
[ 0.504502] smp: Brought up 1 node, 4 CPUs
[ 0.516491] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.535956] futex hash table entries: 1024 (order: 3, 32768 bytes)
[ 0.548383] pinctrl core: initialized pinctrl subsystem
[ 0.559960] NET: Registered protocol family 16
[ 0.585735] mt7621_gpio 1e000600.gpio: registering 32 gpios
[ 0.597024] mt7621_gpio 1e000600.gpio: registering 32 gpios
[ 0.608238] mt7621_gpio 1e000600.gpio: registering 32 gpios
[ 0.621899] clocksource: Switched to clocksource GIC
[ 0.633249] NET: Registered protocol family 2
[ 0.642492] TCP established hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.656235] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.669016] TCP: Hash tables configured (established 2048 bind 2048)
[ 0.681733] UDP hash table entries: 256 (order: 1, 8192 bytes)
[ 0.693239] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[ 0.705894] NET: Registered protocol family 1
[ 2.581849] 4 CPUs re-calibrate udelay(lpj = 2924544)
[ 2.593177] Crashlog allocated RAM at address 0x3f00000
[ 2.603661] workingset: timestamp_bits=30 max_order=16 bucket_order=0
[ 2.620801] random: fast init done
[ 2.623370] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[ 2.623380] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[ 2.626831] io scheduler noop registered
[ 2.626839] io scheduler deadline registered (default)
[ 2.677814] Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
[ 2.691487] console [ttyS0] disabled
[ 2.698516] 1e000c00.uartlite: ttyS0 at MMIO 0x1e000c00 (irq = 18, base_baud = 3125000) is a 16550A
[ 2.716464] console [ttyS0] enabled
[ 2.716464] console [ttyS0] enabled
[ 2.730252] bootconsole [early0] disabled
[ 2.730252] bootconsole [early0] disabled
[ 2.746760] cacheinfo: Unable to detect cache hierarchy for CPU 0
[ 2.759770] MediaTek Nand driver init, version v2.1 Fix AHB virt2phys error
[ 2.773822] Allocate 16 byte aligned buffer: 807d6ce0
[ 2.783965] Enable NFI Clock
[ 2.789682] # MTK NAND # : Use HW ECC
[ 2.796986] Device found in MTK table, ID: 1da, EXT_ID: 909546
[ 2.808604] Support this Device in MTK table! 1da
[ 2.818316] [NAND]select ecc bit:12, sparesize :112 spare_per_sector=28
[ 2.831529] nand: device found, Manufacturer ID: 0x01, Chip ID: 0xda
[ 2.844176] nand: AMD/Spansion NAND 256MiB 3,3V 8-bit
[ 2.854226] nand: 256 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[ 2.869304] Scanning device for bad blocks
[ 3.512645] 6 fixed-partitions partitions found on MTD device MT7621-NAND
[ 3.526156] Creating 6 MTD partitions on "MT7621-NAND":
[ 3.536566] 0x000000000000-0x000000080000 : "u-boot"
[ 3.547482] 0x000000080000-0x0000000e0000 : "u-boot-env"
[ 3.559073] 0x0000000e0000-0x000000140000 : "factory"
[ 3.570086] 0x000000140000-0x000000440000 : "kernel1"
[ 3.581128] 0x000000440000-0x000000740000 : "kernel2"
[ 3.592241] 0x000000740000-0x00000ff00000 : "ubi"
[ 3.604499] [mtk_nand] probe successfully!
[ 3.613424] Signature matched and data read!
[ 3.621919] load_fact_bbt success 2047
[ 3.631182] libphy: Fixed MDIO Bus: probed
[ 3.639625] mt7530 0.switch: mt7530_probe
[ 3.647623] mt7530 0.switch: MT7530 adapts as multi-chip module
[ 3.691881] MT7621: GE2: Pininit
[ 3.698314] mtk_soc_eth 1e100000.ethernet: chip id = 7621
[ 3.709486] libphy: mdio: probed
[ 3.747453] drivers/net/ethernet/mediatek/mtk_eth_soc.c:mtk_mdio_init[421]0 8fdc5800
[ 3.762976] mtk_soc_eth 1e100000.ethernet: generated random MAC address f2:13:c6:a6:8f:9d
[ 3.795049] mtk_soc_eth 1e100000.ethernet: connected mac 0 to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]
[ 3.816364] mtk_soc_eth 1e100000.ethernet eth0: mediatek frame engine at 0xbe100000, irq 21
[ 3.833063] mtk_soc_eth 1e100000.ethernet: generated random MAC address 92:82:bc:41:9a:24
[ 3.864922] mtk_soc_eth 1e100000.ethernet: connected mac 1 to PHY at fixed-0:01 [uid=00000000, driver=Generic PHY]
[ 3.886227] mtk_soc_eth 1e100000.ethernet eth1: mediatek frame engine at 0xbe100000, irq 21
[ 3.904889] NET: Registered protocol family 10
[ 3.915444] Segment Routing with IPv6
[ 3.922911] NET: Registered protocol family 17
[ 3.932301] 8021q: 802.1Q VLAN Support v1.8
[ 3.942711] mt7530 0.switch: mt7530_probe
[ 3.950707] mt7530 0.switch: MT7530 adapts as multi-chip module
[ 3.962641] DSA: switch 0 0 parsed
[ 3.969406] DSA: tree 0 parsed
[ 5.937228] libphy: dsa slave smi: probed
[ 5.981904] Generic PHY dsa-0.0:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:00, irq=POLL)
[ 6.041900] Generic PHY dsa-0.0:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:01, irq=POLL)
[ 6.101911] Generic PHY dsa-0.0:02: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:02, irq=POLL)
[ 6.161904] Generic PHY dsa-0.0:03: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:03, irq=POLL)
[ 6.221895] Generic PHY dsa-0.0:04: attached PHY driver [Generic PHY] (mii_bus:phy_addr=dsa-0.0:04, irq=POLL)
[ 7.481889] mt7530 0.switch: failed to priv write register
[ 7.492836] mt7530 0.switch: failed to priv write register
[ 7.503755] mt7530 0.switch: failed to priv write register
[ 7.514673] mt7530 0.switch: failed to priv write register
[ 7.525590] mt7530 0.switch: failed to priv write register
[ 7.536511] mt7530 0.switch: failed to priv read register
[ 7.547257] mt7530 0.switch: failed to priv write register
[ 7.558178] mt7530 0.switch: failed to priv read register
[ 7.568924] mt7530 0.switch: failed to priv write register
[ 8.821889] mt7530 0.switch: failed to priv write register
[ 8.832830] mt7530 0.switch: failed to priv write register
[ 8.843748] mt7530 0.switch: failed to priv write register
[ 8.854666] mt7530 0.switch: failed to priv write register
[ 8.865585] mt7530 0.switch: failed to priv write register
[ 8.876507] mt7530 0.switch: failed to priv read register
[ 8.887254] mt7530 0.switch: failed to priv write register
[ 8.898180] mt7530 0.switch: failed to priv read register
[ 8.908926] mt7530 0.switch: failed to priv write register
[ 8.920855] UBI: auto-attach mtd5
[ 8.927479] ubi0: attaching mtd5
[ 11.378000] ubi0: scanning is finished
[ 11.403280] ubi0: attached mtd5 (name "ubi", size 247 MiB)
[ 11.414224] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 11.427903] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 11.441410] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 11.455265] ubi0: good PEBs: 1982, bad PEBs: 0, corrupted PEBs: 0
[ 11.467388] ubi0: user volume: 2, internal volumes: 1, max. volumes count: 128
[ 11.481760] ubi0: max/mean erase counter: 12/6, WL threshold: 4096, image sequence number: 162887144
[ 11.499935] ubi0: available PEBs: 0, total reserved PEBs: 1982, PEBs reserved for bad PEB handling: 40
[ 11.518479] ubi0: background thread "ubi_bgt0d" started, PID 404
[ 11.520216] block ubiblock0_0: created from ubi0:0(rootfs)
[ 11.520226] ubiblock: device ubiblock0_0 (rootfs) set to be root filesystem
[ 11.520242] hctosys: unable to open rtc device (rtc0)
[ 11.572880] Freeing unused kernel memory: 2132K
[ 11.581941] This architecture does not have kernel memory protection.
[ 11.605046] init: Console is alive
[ 11.612184] init: - watchdog -
[ 11.633652] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[ 11.650461] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[ 11.672225] init: - preinit -
Failed to connect to the switch. Use the "list" command to see which switches are available.
Failed to connect to the switch. Use the "list" command to see which switches are available.
Failed to connect to the switch. Use the "list" command to see which switches are available.
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[ 14.912954] procd: - early -
[ 14.918780] procd: - watchdog -
[ 15.542029] procd: - watchdog -
[ 15.548574] procd: - ubus -
[ 15.559001] random: ubusd: uninitialized urandom read (4 bytes read)
[ 15.612574] random: ubusd: uninitialized urandom read (4 bytes read)
[ 15.625611] random: ubusd: uninitialized urandom read (4 bytes read)
[ 15.639114] procd: - init -
Please press Enter to activate this console.
[ 15.772413] kmodloader: loading kernel modules from /etc/modules.d/*
[ 15.788209] ip6_tables: (C) 2000-2006 Netfilter Core Team
[ 16.115495] i2c /dev entries driver
[ 16.127113] pca953x 0-0025: 0-0025 supply vcc not found, using dummy regulator
[ 16.151579] pca953x 0-0025: interrupt support not compiled in
[ 16.163198] i2c-gpio i2c-gpio: using pins 3 (SDA) and 4 (SCL)
[ 16.178451] ip_tables: (C) 2000-2006 Netfilter Core Team
[ 16.537591] nf_conntrack version 0.5.0 (4096 buckets, 16384 max)
[ 16.757964] Netfilter messages via NETLINK v0.30.
[ 16.777511] xt_time: kernel timezone is -0000
[ 16.966879] nf_tables: (c) 2007-2009 Patrick McHardy kaber@trash.net
[ 17.001032] PPP generic driver version 2.4.2
[ 17.010892] NET: Registered protocol family 24
[ 17.024437] kmodloader: done loading kernel modules from /etc/modules.d/*
[ 18.104327] urandom_read: 5 callbacks suppressed
[ 18.104337] random: jshn: uninitialized urandom read (4 bytes read)
[ 18.171795] random: jshn: uninitialized urandom read (4 bytes read)
[ 21.501835] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 21.513722] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 21.733204] br-lan: port 1(lan0) entered blocking state
[ 21.743675] br-lan: port 1(lan0) entered disabled state
[ 21.812039] device lan0 entered promiscuous mode
[ 21.821253] device eth0 entered promiscuous mode
[ 21.962402] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
[ 22.212935] br-lan: port 2(lan1) entered blocking state
[ 22.223392] br-lan: port 2(lan1) entered disabled state
[ 22.351901] device lan1 entered promiscuous mode
[ 22.742893] br-lan: port 3(lan2) entered blocking state
[ 22.753366] br-lan: port 3(lan2) entered disabled state
[ 22.961910] device lan2 entered promiscuous mode
[ 23.352959] br-lan: port 4(lan3) entered blocking state
[ 23.363420] br-lan: port 4(lan3) entered disabled state
[ 23.631936] device lan3 entered promiscuous mode
[ 23.911899] mt7530 0.switch lan0: Link is Down
[ 24.052069] IPv6: ADDRCONF(NETDEV_UP): wan: link is not ready
[ 24.211928] mt7530 0.switch lan1: Link is Down
[ 24.521990] mt7530 0.switch lan2: Link is Down
[ 25.241902] mt7530 0.switch lan3: Link is Down
[ 25.401878] mt7530 0.switch wan: Link is Down
[ 26.181946] br-lan: port 1(lan0) entered blocking state
[ 26.192365] br-lan: port 1(lan0) entered forwarding state
[ 26.221914] mt7530 0.switch lan0: Link is Up - 1Gbps/Full - flow control rx/tx
[ 26.351934] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[ 27.373486] random: crng init done
[ 28.742049] IPv6: ADDRCONF(NETDEV_CHANGE): wan: link becomes ready
[ 28.772259] mt7530 0.switch wan: Link is Up - 1Gbps/Full - flow control rx/tx

root@OpenWrt:/# ping nu.nl
PING nu.nl (52.85.201.184) 56(84) bytes of data.
64 bytes from server-52-85-201-184.dub2.r.cloudfront.net (52.85.201.184): icmp_req=1 ttl=245 time=24.5 ms
64 bytes from server-52-85-201-184.dub2.r.cloudfront.net (52.85.201.184): icmp_req=2 ttl=245 time=24.4 ms
root@OpenWrt:/#
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1763 (1.7 KiB)  TX bytes:3158 (3.0 KiB)

eth0      Link encap:Ethernet  HWaddr F2:13:C6:A6:8F:9D
          inet6 addr: fe80::f013:c6ff:fea6:8f9d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:401 errors:0 dropped:0 overruns:0 frame:0
          TX packets:101 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:111329 (108.7 KiB)  TX bytes:13071 (12.7 KiB)
          Interrupt:21

lan0      Link encap:Ethernet  HWaddr F2:13:C6:A6:8F:9D
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1763 (1.7 KiB)  TX bytes:3158 (3.0 KiB)

lan1      Link encap:Ethernet  HWaddr F2:13:C6:A6:8F:9D
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lan2      Link encap:Ethernet  HWaddr F2:13:C6:A6:8F:9D
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lan3      Link encap:Ethernet  HWaddr F2:13:C6:A6:8F:9D
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0
          TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2731 (2.6 KiB)  TX bytes:2731 (2.6 KiB)

wan       Link encap:Ethernet  HWaddr F2:13:C6:A6:8F:9E
          inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: <SNIP IPV6>:f213:c6ff:fea6:8f9e/128 Scope:Global
          inet6 addr: fe80::f013:c6ff:fea6:8f9e/64 Scope:Link
          inet6 addr: <SNIP IPV6>:f013:c6ff:fea6:8f9e/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:385 errors:0 dropped:0 overruns:0 frame:0
          TX packets:66 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:102348 (99.9 KiB)  TX bytes:6692 (6.5 KiB)
1 Like

Awesome job.
Are you using the Programming guide for MT7621 and its switch?
All of the needed stuff for second MAC is there

Mt7621 and GSW Programming guide that I have is missing a lot about the switch and GMAC settings. Missing in depth information.
MT7620 Programming Guide that I have is lot better, also tells about clock structures. But the chips are not the same so it is not always usable.
I have multiple versions of the SDK were to looking in, look how stuff is done.

Update: sfp port is still not talking :frowning: but link detects works
2 options:
A) Hardware timings are wrong RX clk delay stuff....
B) ethernet driver is not configuring gmac1 of FE properly.

External PHY is detect but the linux driver needs some patching to support the way we using the phy (SGMII (sfp 1000BX) to RGMII converter).
Phy is correctly setup on powerup. It has some bootstrap resistors.

Currently also try to map out some of the gpio pins.

sfp_i2c_clk_en: gpio7 active_low: This connects the i2c_clk to SFP module. Without it you can't readout your SFP module.
sfp mod-def0-gpio (SFP Pressent) is connected to pca9555 at pin 0.5 active_low
I am not sure of other SFP pins are connected to PCA9555. It is not so easy to probe the pins.

Connector J9 (PIN round = GPIO34) Square = 3.3V.

PCA9555 Interrupt is GPIO8 Active_low.

Also try to find the AR8033 reset/interrupt lines.
Reset of AR8033 seem connected to RESET of the CPU(MT7621). Is pull down the cpu also reset.
Pulling interrupts down gives no results on gpio inputs. So I assume it is not connected.

With the tool "io" you can set the GPIO pins.

# Set gpio7 to output
io -4 -o 0x1e000600 0x80
# Clear gpio7 output to low.
io -4 -o 0x1e000640 0x80
1 Like

Finally SFP is talking... Not with 2nd GMAC but with the P5 of the switch.
I tried many many settings to enable 2nd GMAC but it did not talk to AT8033. Today I reinstalled UBNT os and looked at the IO settings.
UBNT has the 2nd GMAC disabled and 2nd GMAC pins are in GPIO mode.
Enabling P5 on the switch did the trick.
Speed detection on SFP is still wrong, forcing it and your port will talk :slight_smile:

My work: https://github.com/vdorst/openwrt/tree/mt7621-ramips-dsa2

2 Likes

Great work!

Sorry for pointing you in the wrong direction there... Good you managed to figure it out.

FWIW I've been playing with your code to enable the second GMAC and finally got that to work with the ZyXEL WAP6805 I'm using. So thanks a lot for doing that. Looking at the proposals for the next release, I guess that the switch to DSA is worthwile in any case. But most important to me at the moment is that I am now able to talk to the RGMII connected Quanteanna module on the WAP6805. Now I only have to figure out how to manage it in some remotely sane way as a wifi-module, using Quantennas weird RPC API.

One question: You wouln'd happen to know what this write does on the MT7621:

# Support QTN 5G
if [ "$CONFIG_QTN_5G" = "y" ]; then
   reg s 0xbe110000
   reg w 8 0x9000c

I found that in ZyXELs OEM firmware, and it proved to be the key to getting the RGMII GMAC2 actually working on this platform. Without that I only got FCS errors on eth1.

Note: The "reg" utility is a frontend to a driver providing generic register access - obviously a debug thing which never was meant for use outside the lab. But ZyXEL use it everywhere in true OEM firmware tradtion :slight_smile: The two commands sets the base address to 0xbe110000 and then writes 0x9000c to register 8. I am guessing that 0xbe110000 is some shadow address for 0x1e110000 and simply re-implemented the write as

mt7623_trgmii_write(priv, 8, 0x9000c);

in the mt7530 code. Which I am sure is wrong on many levels, but works. Would be nice to know exactly what is hiding behind that 0x1e110008 address. Based on the FCS errors it might be some part of the switch jamming the external RGMII interface? The default value seems to be 0xc000c, so the important change must be bits 16 and/or 18 only.

Do you have a link to the code? Or show reg funcion?

It is a register after /* PHY Indirect Access Control registers */.
Not documented in the MT7620, MT7621 or MT7623 pdf I have.

I did a quick test with with 2nd GMAC and updated you register. But still no response.

To the ZyXEL script you mean? That's only a slightly modified script from the SDK, and not particularily interesting with the exception of the Quantenna module stuff specific to this device. This is almost the full script (had to remove parts to keep the post within size limits):

internet.sh
#!/bin/sh
#
# $Id: //WIFI_SOC/MP/SDK_4_2_0_0/RT288x_SDK/source/user/rt2880_app/scripts/internet.sh#4 $
#
# usage: internet.sh
#

. /sbin/config.sh
. /sbin/global.sh

touch /var/internet_configuring

lan_ip=`nvram_get 2860 lan_ipaddr`
stp_en=`nvram_get 2860 stpEnabled`
nat_en=`nvram_get 2860 natEnabled`
wlan_enabled=`nvram_get 2860 WlanEnabled`
radio_off1=`nvram_get 2860 RadioOff`
if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
	radio_off2=`nvram_get rtdev RadioOff`
fi
wifi_off=`nvram_get 2860 WiFiOff`
ra_Bssidnum=`nvram_get 2860 BssidNum`
if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
	rai_Bssidnum=`nvram_get rtdev BssidNum`
fi

genDevNode()
{
#Linux2.6 uses udev instead of devfs, we have to create static dev node by myself.
if [ "$CONFIG_HOTPLUG" == "y" -a "$CONFIG_USB" == "y" -o "$CONFIG_MMC" == "y" ]; then
	mounted=`mount | grep mdev | wc -l`
	if [ $mounted -eq 0 ]; then
	mount -t ramfs mdev /dev
	mkdir /dev/pts
	mount -t devpts devpts /dev/pts

        mknod   /dev/video0      c       81      0
	mknod	/dev/ppp	 c	 108	 0   $cons
        mknod   /dev/spiS0       c       217     0
        mknod   /dev/i2cM0       c       218     0
        mknod   /dev/mt6605      c       219     0
        mknod   /dev/flash0      c       200     0
        mknod   /dev/swnat0      c       210     0
        mknod   /dev/hwnat0      c       220     0
        mknod   /dev/acl0        c       230     0
        mknod   /dev/ac0         c       240     0
        mknod   /dev/mtr0        c       250     0
        mknod   /dev/nvram       c       251     0
        mknod   /dev/gpio        c       252     0
        mknod   /dev/rdm0        c       253     0
        mknod   /dev/pcm0        c       233     0
        mknod   /dev/i2s0        c       234     0	
        mknod   /dev/cls0        c       235     0
	mknod   /dev/spdif0      c       236     0

	fi
	echo "# <device regex> <uid>:<gid> <octal permissions> [<@|$|*> <command>]" > /etc/mdev.conf
        echo "# The special characters have the meaning:" >> /etc/mdev.conf
        echo "# @ Run after creating the device." >> /etc/mdev.conf
        echo "# $ Run before removing the device." >> /etc/mdev.conf
        echo "# * Run both after creating and before removing the device." >> /etc/mdev.conf
        echo "sd[a-z][1-9] 0:0 0660 */sbin/automount_boot.sh \$MDEV" >> /etc/mdev.conf
        echo "sd[a-z] 0:0 0660 */sbin/automount_boot.sh \$MDEV" >> /etc/mdev.conf
	echo "mmcblk[0-9]p[0-9] 0:0 0660 */sbin/automount_boot.sh \$MDEV" >> /etc/mdev.conf
	echo "mmcblk[0-9] 0:0 0660 */sbin/automount_boot.sh \$MDEV" >> /etc/mdev.conf
	if [ "$CONFIG_USB_SERIAL" = "y" ] || [ "$CONFIG_USB_SERIAL" = "m" ]; then
		echo "ttyUSB0 0:0 0660 @/sbin/autoconn3G.sh connect" >> /etc/mdev.conf
	fi
	if [ "$CONFIG_BLK_DEV_SR" = "y" ] || [ "$CONFIG_BLK_DEV_SR" = "m" ]; then
		echo "sr0 0:0 0660 @/sbin/autoconn3G.sh connect" >> /etc/mdev.conf
	fi
	if [ "$CONFIG_USB_SERIAL_HSO" = "y" ] || [ "$CONFIG_USB_SERIAL_HSO" = "m" ]; then
		echo "ttyHS0 0:0 0660 @/sbin/autoconn3G.sh connect" >> /etc/mdev.conf
	fi
fi
}

###### deleted a part here - bmork ######

addRax2Br0()
{
	#if radio_off is 1, do not init all interface, so wlan led will down 
	if [ "$radio_off1" = "1" ]; then	
		return
	fi

	num=0
	tmp=`echo $wlan_enabled|sed -e 's/;/ /g'`
:<<! #__MSTC__,Andrew for MBSSID ra0, ra2, ra3, ra4	  
	for enbl in $tmp
	do
		if [ "$enbl" == "1" ]; then
			ifconfig ra$num 0.0.0.0 1>/dev/null 2>&1
			brctl addif br0 ra$num			
		fi

		num=`expr $num + 1`
		if [ "$num" == "1" ]; then
		  num=`expr $num + 1`
		fi
	done
	num=`expr $num - 1`
	if [ "$num" != "$ra_Bssidnum" ]; then
		echo "Error: WlanEnabled maybe have wrong format!"
	fi 
!
#__MSTC__,Andrew for MBSSID ra0, ra1, ra2, ra3	
	for enbl in $tmp
	do
		if [ "$enbl" == "1" ]; then
			ifconfig ra$num 0.0.0.0 1>/dev/null 2>&1
			brctl addif br0 ra$num			
		fi

		num=`expr $num + 1` 
	done
	
	if [ "$num" != "$ra_Bssidnum" ]; then
		echo "Error: WlanEnabled maybe have wrong format!"
	fi

}

addWds2Br0()
{
	wds_en=`nvram_get 2860 WdsEnable`
	if [ "$wds_en" != "0" ]; then
		ifconfig wds0 up 1>/dev/null 2>&1
		ifconfig wds1 up 1>/dev/null 2>&1
		ifconfig wds2 up 1>/dev/null 2>&1
		ifconfig wds3 up 1>/dev/null 2>&1
		brctl addif br0 wds0
		brctl addif br0 wds1
		brctl addif br0 wds2
		brctl addif br0 wds3
	fi
}

addMesh2Br0()
{
	meshenabled=`nvram_get 2860 MeshEnabled`
	if [ "$meshenabled" = "1" ]; then
		ifconfig mesh0 up 1>/dev/null 2>&1
		brctl addif br0 mesh0
		meshhostname=`nvram_get 2860 MeshHostName`
		iwpriv mesh0 set  MeshHostName="$meshhostname"
	fi
}

addRaix2Br0()
{
	if [ "$CONFIG_RT2880_INIC" == "" -a "$CONFIG_RTDEV" == "" ]; then
		return
	fi
	brctl addif br0 rai0
	num=1
	while [ "$num" -lt "$rai_Bssidnum" ]
	do
		ifconfig rai$num up 1>/dev/null 2>&1
		brctl addif br0 rai$num
		num=`expr $num + 1`
	done
	echo -e "\n##### enable 2nd wireless interface #####"
}

addInicWds2Br0()
{
	if [ "$CONFIG_RT2880_INIC" == "" -a "$CONFIG_RTDEV" == "" ]; then
		return
	fi
	wds_en=`nvram_get rtdev WdsEnable`
	if [ "$wds_en" != "0" ]; then
		ifconfig wdsi0 up 1>/dev/null 2>&1
		ifconfig wdsi1 up 1>/dev/null 2>&1
		ifconfig wdsi2 up 1>/dev/null 2>&1
		ifconfig wdsi3 up 1>/dev/null 2>&1
		brctl addif br0 wdsi0
		brctl addif br0 wdsi1
		brctl addif br0 wdsi2
		brctl addif br0 wdsi3
	fi
}

addRaL02Br0()
{
	if [ "$CONFIG_RT2561_AP" != "" ]; then
		brctl addif br0 raL0
	fi
}

#
#	ipv6 config#
#	$1:	interface name
#	$2:	dad_transmit number
#
enableIPv6dad()
{
	if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
		echo "2" > /proc/sys/net/ipv6/conf/$1/accept_dad
		echo $2 > /proc/sys/net/ipv6/conf/$1/dad_transmits
	fi
}

disableIPv6dad()
{
	if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
		echo "0" > /proc/sys/net/ipv6/conf/$1/accept_dad
	fi
}


genSysFiles()
{
	login=`nvram_get 2860 Login`
	pass=`nvram_get 2860 Password`
	if [ "$login" != "" -a "$pass" != "" ]; then
	echo "$login::0:0:Adminstrator:/:/bin/sh" > /etc/passwd
	echo "$login:x:0:$login" > /etc/group
		chpasswd.sh $login $pass
	fi
	if [ "$CONFIG_PPPOL2TP" == "y" ]; then
	echo "l2tp 1701/tcp l2f" > /etc/services
	echo "l2tp 1701/udp l2f" >> /etc/services
	fi
}

configVIF()
{
	if [ "$CONFIG_TASKLET_WORKQUEUE_SW" == "y" ]; then
		ifconfig eth2 down
		PLATFORM=`nvram_get 2860 Platform | tr A-Z a-z`
		if [ "$wanmode" == "PPPOE" -o "$wanmode" == "L2TP" -o "$wanmode" == "PPTP" ]; then
			echo 1 > /proc/$PLATFORM/schedule
		else
			echo 0 > /proc/$PLATFORM/schedule
		fi
	fi
	ifconfig eth2 0.0.0.0

	if [ "$CONFIG_RAETH_ROUTER" = "y" -o "$CONFIG_MAC_TO_MAC_MODE" = "y" -o "$CONFIG_RT_3052_ESW" = "y" ]; then
		if [ "$CONFIG_GE2_RGMII_AN" = "y" -o "$CONFIG_GE2_INTERNAL_GPHY" = "y" -o "$CONFIG_GE2_RGMII_FORCE_1000" = "y"]; then
			ifconfig eth3 up
		fi
		vconfig rem eth2.1
		vconfig rem eth2.2
		if [ "$CONFIG_RAETH_SPECIAL_TAG" == "y" ]; then
			vconfig rem eth2.3
			vconfig rem eth2.4

			vconfig rem $wan_if
			vconfig rem $wan_if2
			vconfig rem $wan_if3
			vconfig rem $wan_if4
		fi
		rmmod 8021q
		if [ "$CONFIG_VLAN_8021Q" == "m" ]; then
		insmod -q 8021q
		fi
#		vconfig add eth2 1
#		set_vlan_map eth2.1
#		vconfig add eth2 2
#		set_vlan_map eth2.2
		if [ "$CONFIG_RAETH_SPECIAL_TAG" == "y" ]; then
			vconfig add eth2 3
			set_vlan_map eth2.3
			vconfig add eth2 4
			set_vlan_map eth2.4

			vconfig add eth2 $wan1Vid
			set_vlan_map $wan_if
			ifconfig $wan_if down

			if [ "$wan1Vid" -le 15 ]; then
				vconfig set_wantags $wan_if 0
			else
				vconfig set_wantags $wan_if 1
			fi

			if [ "$supportWan2" = "1" ]; then
				vconfig add eth2 $wan2Vid
				set_vlan_map $wan_if2
				ifconfig $wan_if2 down

				if [ "$vlanEnabled2" = "1" ]; then
					vconfig set_wantags $wan_if2 1
				else
					vconfig set_wantags $wan_if2 0
				fi
			fi
			if [ "$supportWan3" = "1" ]; then
				vconfig add eth2 $wan3Vid
				set_vlan_map $wan_if3
				ifconfig $wan_if3 down

				if [ "$vlanEnabled3" = "1" ]; then
					vconfig set_wantags $wan_if3 1
				else
					vconfig set_wantags $wan_if3 0
				fi
			fi
			if [ "$supportWan4" = "1" ]; then
				vconfig add eth2 $wan4Vid
				set_vlan_map $wan_if4
				ifconfig $wan_if4 down

				if [ "$vlanEnabled4" = "1" ]; then
					vconfig set_wantags $wan_if4 1
				else
					vconfig set_wantags $wan_if4 0
				fi
			fi


			if [ "$CONFIG_WAN_AT_P0" = "y" ]; then
#Set WAN1 MAC
				wan_mac=`nvram_get 2860 WAN_MAC_ADDR`
				if [ "$wan_mac" != "FF:FF:FF:FF:FF:FF" ]; then
					ifconfig $wan_if hw ether $wan_mac
				fi

#Set WAN2 MAC
				if [ "$supportWan2" = "1" ]; then
					wan_mac=`nvram_get 2860 WAN2_MAC_ADDR`
					if [ "$wan_mac" != "FF:FF:FF:FF:FF:FF" ]; then
						ifconfig $wan_if2 hw ether $wan_mac
					fi
				fi
			else
#Set WAN1 MAC
				wan_mac=`nvram_get 2860 WAN_MAC_ADDR`
				if [ "$wan_mac" != "FF:FF:FF:FF:FF:FF" ]; then
					ifconfig $wan_if hw ether $wan_mac
				fi

#Set WAN2 MAC
				if [ "$supportWan2" = "1" ]; then
					wan_mac=`nvram_get 2860 WAN2_MAC_ADDR`
					if [ "$wan_mac" != "FF:FF:FF:FF:FF:FF" ]; then
						ifconfig $wan_if2 hw ether $wan_mac
					fi
				fi

#Set WAN3 MAC
				if [ "$supportWan3" = "1" ]; then
					wan_mac=`nvram_get 2860 WAN3_MAC_ADDR`
					if [ "$wan_mac" != "FF:FF:FF:FF:FF:FF" ]; then
						ifconfig $wan_if3 hw ether $wan_mac
					fi
				fi

#Set WAN4 MAC
				if [ "$supportWan4" = "1" ]; then
					wan_mac=`nvram_get 2860 WAN4_MAC_ADDR`
					if [ "$wan_mac" != "FF:FF:FF:FF:FF:FF" ]; then
						ifconfig $wan_if4 hw ether $wan_mac
					fi
				fi

				enableIPv6dad $wan_if 1
			fi
		else
			ifconfig eth2.2 down
			wan_mac=`nvram_get 2860 WAN_MAC_ADDR`
			if [ "$wan_mac" != "FF:FF:FF:FF:FF:FF" ]; then
				ifconfig eth2.2 hw ether $wan_mac
			fi
			enableIPv6dad eth2.2 1
		fi

#		ifconfig eth2.1 0.0.0.0
#		ifconfig eth2.2 0.0.0.0
		if [ "$CONFIG_RAETH_SPECIAL_TAG" == "y" ]; then
			ifconfig eth2.3 0.0.0.0
			ifconfig eth2.4 0.0.0.0
			ifconfig $wan_if 0.0.0.0
			if [ "$supportWan2" = "1" ]; then
				ifconfig $wan_if2 0.0.0.0
			fi
			if [ "$supportWan3" = "1" ]; then
				ifconfig $wan_if3 0.0.0.0
			fi
			if [ "$supportWan4" = "1" ]; then
				ifconfig $wan_if4 0.0.0.0
			fi
		fi

	elif [ "$CONFIG_ICPLUS_PHY" = "y" ]; then
		#remove ip alias
		# it seems busybox has no command to remove ip alias...
		ifconfig eth2:1 0.0.0.0 1>&2 2>/dev/null
	fi
}

# opmode adjustment:
#   if AP client was not compiled and operation mode was set "3" -> set $opmode "1"
#   if Station was not compiled and operation mode was set "2" -> set $opmode "1"
if [ "$opmode" = "3" -a "$CONFIG_RT2860V2_AP_APCLI$CONFIG_RT3090_AP_APCLI$CONFIG_RT5392_AP_APCLI$CONFIG_RT5592_AP_APCLI$CONFIG_RT3593_AP_APCLI$CONFIG_MT7610_AP_APCLI$CONFIG_RT3572_AP_APCLI$CONFIG_RT5572_AP_APCLI$CONFIG_RT3680_iNIC_AP_APCLI$CONFIG_RTPCI_AP_APCLI" == "" ]; then
	nvram_set 2860 OperationMode 1
	opmode="1"
fi
if [ "$opmode" = "2" -a "$CONFIG_RT2860V2_STA" == "" ]; then
	nvram_set 2860 OperationMode 1
	opmode="1"
fi

genDevNode
genSysFiles

echo 0 > /proc/sys/net/ipv4/ip_forward

# disable ipv6 DAD on all interfaces by default
if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
	echo "0" > /proc/sys/net/ipv6/conf/default/accept_dad
fi

if [ "$CONFIG_DWC_OTG" == "m" ]; then
usbmod_exist=`lsmod | grep dwc_otg | wc -l`
if [ $usbmod_exist == 0 ]; then
insmod -q lm
insmod -q dwc_otg
fi
fi

if [ "$CONFIG_USB_EHCI_HCD" == "m" ]; then
usbmod_exist=`lsmod | grep ehci-hcd | wc -l`
if [ $usbmod_exist == 0 ]; then
insmod -q ehci-hcd
fi
fi

if [ "$CONFIG_USB_OHCI_HCD" == "m" ]; then
usbmod_exist=`lsmod | grep ohci-hcd | wc -l`
if [ $usbmod_exist == 0 ]; then
insmod -q ohci-hcd
fi
fi

if [ "$CONFIG_MTK_MMC" == "m" ]; then
msdcmod_exist=`lsmod | grep mtk_sd | wc -l`
if [ $msdcmod_exist == 0 ]; then
insmod -q mtk_sd
fi
fi

if [ "$CONFIG_UFSD_FS" == "m" -o "$CONFIG_UFSD_FS" == "y" ]; then
ufsdmod_exist=`lsmod | grep ufsd | wc -l`
if [ $ufsdmod_exist == 0 ]; then
	insmod -q ufsd
fi
fi

if [ "$CONFIG_GE2_RGMII_AN" = "y" -o "$CONFIG_GE2_INTERNAL_GPHY" = "y" ]; then
	ifconfig eth3 down
fi
killall -9 watchdog 1>/dev/null 2>&1
if [ "$CONFIG_RALINK_WATCHDOG" = "m" -o "$CONFIG_RALINK_TIMER_WDG" = "m" ]; then
rmmod ralink_wdt
fi
if [ "$CONFIG_RA_CLASSIFIER" = "y" -o "$CONFIG_RA_CLASSIFIER" = "m" ]; then
rmmod cls
fi
if [ "$CONFIG_RA_HW_NAT" = "m" ]; then
rmmod hw_nat
fi

# insmod all
if [ "$CONFIG_BRIDG" = "m" ]; then
insmod -q bridge
fi
if [ "$CONFIG_MII" = "m" ]; then
insmod -q mii
fi
if [ "$CONFIG_RAETH" = "m" ]; then
rmmod raeth
insmod -q raeth
fi

# avoid eth2 doing ipv6 DAD
disableIPv6dad eth2

# In 2.6.36 kernel(MT7620& MT7621), avoid ipv6 traffic unless everything ready
if [ "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
fi
fi

ifRaxWdsxDown
if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
	ifRaixWdsxDown
fi
if [ "$CONFIG_RT2860V2_AP" != "" ]; then
	rmmod rt2860v2_ap_net
	rmmod rt2860v2_ap
	rmmod rt2860v2_ap_util
fi
if [ "$CONFIG_RT2860V2_STA" != "" ]; then
	rmmod rt2860v2_sta_net
	rmmod rt2860v2_sta
	rmmod rt2860v2_sta_util
fi
if [ "$RT2880v2_INIC_PCI" != "" ]; then
	rmmod iNIC_pci
fi
if [ "$CONFIG_RLT_AP_SUPPORT" != "" ]; then
        rmmod rlt_wifi
fi
if [ "$CONFIG_RT3090_AP" != "" ]; then
	rmmod RT3090_ap_net
	rmmod RT3090_ap
	rmmod RT3090_ap_util
fi
if [ "$CONFIG_RT5392_AP" != "" ]; then
	rmmod RT5392_ap
fi
if [ "$CONFIG_RT5592_AP" != "" ]; then
	rmmod RT5592_ap
fi
if [ "$CONFIG_RT3593_AP" != "" ]; then
	rmmod RT3593_ap
fi
if [ "$CONFIG_MT7610_AP" != "" ]; then
	rmmod MT7610_ap
fi
if [ "$CONFIG_RTPCI_AP" != "" ]; then
	rmmod RTPCI_ap
fi
if [ "$CONFIG_RT3572_AP" != "" ]; then
	rmmod RT3572_ap_net
	rmmod RT3572_ap
	rmmod RT3572_ap_util
fi
if [ "$CONFIG_RT5572_AP" != "" ]; then
	rmmod RT5572_ap_net
	rmmod RT5572_ap
	rmmod RT5572_ap_util
fi
if [ "$RT305x_INIC_USB" != "" ]; then
	rmmod iNIC_usb
fi
if [ "$CONFIG_RT3680_iNIC_AP" != "" ]; then
	rmmod RT3680_ap
fi
if [ "$CONFIG_RT2561_AP" != "" ]; then
	rmmod rt2561ap
fi

if [ "$CONFIG_RT2860V2_AP_WAPI$CONFIG_RT3090_AP_WAPI$CONFIG_RT5392_AP_WAPI$CONFIG_RT5592_AP_WAPI$CONFIG_RT3593_AP_WAPI$CONFIG_MT7610_AP_WAPI$CONFIG_RT3572_AP_WAPI$CONFIG_RT5572_AP_WAPI$CONFIG_RT3680_iNIC_AP_WAPI$CONFIG_RTPCI_AP_WAPI" != "" ]; then
	ralink_init gen wapi
fi
ralink_init make_wireless_config rt2860
if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
	ralink_init make_wireless_config rtdev
fi
if [ "$CONFIG_RT2860V2_AP_DFS$CONFIG_RT5592_AP_DFS$CONFIG_RT3593_AP_DFS$CONFIG_MT7610_AP_DFS$CONFIG_RT3572_AP_DFS$CONFIG_RT5572_AP_DFS$CONFIG_RTPCI_AP_DFS" != "" ]; then
	insmod -q rt_timer
fi
if [ "$CONFIG_RT2860V2_STA" != "" -a "$stamode" = "y" ]; then
	insmod -q rt2860v2_sta_util
	insmod -q rt2860v2_sta
	insmod -q rt2860v2_sta_net

	if [ "$CONFIG_RT2860V2_STA_WPA_SUPPLICANT" == "y" ]; then
		ralink_init gen cert
	fi
elif [ "$CONFIG_RT2860V2_AP" != "" ]; then
	insmod -q rt2860v2_ap_util
	insmod -q rt2860v2_ap
	insmod -q rt2860v2_ap_net
fi
# RTDEV_PCI support
if [ "$RT2880v2_INIC_PCI" != "" ]; then
	insmod -q iNIC_pci 
fi
if [ "$CONFIG_RLT_AP_SUPPORT" != "" ]; then
        insmod -q rlt_wifi
fi
if [ "$CONFIG_RT3090_AP" != "" ]; then
	insmod -q RT3090_ap_util
	insmod -q RT3090_ap
	insmod -q RT3090_ap_net
fi
if [ "$CONFIG_RT5392_AP" != "" ]; then
	insmod -q RT5392_ap
fi
if [ "$CONFIG_RT5592_AP" != "" ]; then
	insmod -q RT5592_ap
fi
if [ "$CONFIG_MT7610_AP" != "" ]; then
	insmod -q MT7610_ap
fi
if [ "$CONFIG_RT3593_AP" != "" ]; then
	insmod -q RT3593_ap
fi
if [ "$CONFIG_RTPCI_AP" != "" ]; then
	insmod -q RTPCI_ap
fi
# RTDEV_USB support
if [ "$RT305x_INIC_USB" != "" ]; then
	insmod -q iNIC_usb 
fi
if [ "$CONFIG_RT3572_AP" != "" ]; then
	insmod -q RT3572_ap_util
	insmod -q RT3572_ap
	insmod -q RT3572_ap_net
fi
if [ "$CONFIG_RT5572_AP" != "" ]; then
	insmod -q RT5572_ap_util
	insmod -q RT5572_ap
	insmod -q RT5572_ap_net
fi
if [ "$CONFIG_RT3680_iNIC_AP" != "" ]; then
	insmod -q RT3680_ap
fi

# RT2561(Legacy) support
if [ "$CONFIG_RT2561_AP" != "" ]; then
	insmod -q rt2561ap
fi
if [ "$CONFIG_RTDEV_PLC" != "" ]; then
	ifconfig plc0 up
fi
vpn-passthru.sh

# config interface
ifconfig ra0 0.0.0.0 1>/dev/null 2>&1
if [ "$ethconv" = "y" ]; then
	iwpriv ra0 set EthConvertMode=hybrid
	iwpriv ra0 set EthCloneMac=`nvram_get 2860 ethConvertMAC`
fi
if [ "$radio_off1" = "1" ]; then
	iwpriv ra0 set RadioOn=0
fi
if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
	ifconfig rai0 0.0.0.0 1>/dev/null 2>&1
	if [ "$radio_off2" = "1" ]; then
		iwpriv rai0 set RadioOn=0
	fi
fi

killall -q igmpproxy

ifconfig lo 127.0.0.1
ifconfig br0 down
brctl delbr br0

# stop all
iptables --flush
iptables --flush -t nat
iptables --flush -t mangle

# stop all
killall -q syslogd
killall -q udhcpc
killall -q pppd
killall -q l2tpd
killall -q openl2tpd

# configure /etc/resolv.conf
config-dns.sh "127.0.0.1" "0.0.0.0" "/etc/resolv.conf"
# configure /etc/resolv.dnsmasq.conf
config-dns.sh "0.0.0.0" "0.0.0.0" "/etc/resolv.dnsmasq.conf"
# config-dnsmasq.sh -r

mdev -s
setMDEV
switch reg w 4fe0 800000a0
#
# init ip address to all interfaces for different OperationMode:
#   0 = Bridge Mode
#   1 = Gateway Mode
#   2 = Ethernet Converter Mode
#   3 = AP Client
#
if [ "$opmode" = "0" ]; then
	configVIF
	if [ "$CONFIG_RAETH_ROUTER" = "y" -a "$CONFIG_LAN_WAN_SUPPORT" = "y" ]; then
		echo "##### restore IC+ to dump switch #####"
		config-vlan.sh 0 0
	elif [ "$CONFIG_MAC_TO_MAC_MODE" = "y" ]; then
		echo "##### restore Vtss to dump switch #####"
		config-vlan.sh 1 0
		if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
			sleep 3
		fi
	elif [ "$CONFIG_RT_3052_ESW" = "y" ]; then
		echo "##### restore Ralink ESW to dump switch #####"
		if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
			config-vlan.sh 3 0
		else
			config-vlan.sh 2 0
		fi
	fi
	if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
		sleep 2
	fi
	addBr0
	addRax2Br0
	addWds2Br0
	addMesh2Br0
	APCLI=`nvram_get 2860 apClient`
	if [ "$CONFIG_RT2860V2_AP_APCLI$CONFIG_RT3090_AP_APCLI$CONFIG_RT5392_AP_APCLI$CONFIG_RT5592_AP_APCLI$CONFIG_RT3593_AP_APCLI$CONFIG_MT7610_AP_APCLI$CONFIG_RT3572_AP_APCLI$CONFIG_RT5572_AP_APCLI$CONFIG_RT3680_iNIC_AP_APCLI$CONFIG_RTPCI_AP_APCLI" != "" -a "$APCLI" = "1" ]; then
		ifconfig apcli0 up
		brctl addif br0 apcli0
	fi
	brctl addif br0 eth2
#	if [ "$CONFIG_GE2_RGMII_AN" = "y" -o "$CONFIG_GE2_INTERNAL_GPHY" = "y" ]; then
#		brctl addif br0 eth3
#	fi

# RTDEV_MII support: start mii iNIC after network interface is working
	if [ "$CONFIG_RTDEV_MII" != "" ]; then
		rmmod iNIC_mii
		iNIC_Mii_en=`nvram_get rtdev InicMiiEnable`
		if [ "$iNIC_Mii_en" == "1" ]; then
			ifconfig rai0 down 1>/dev/null 2>&1
			insmod -q iNIC_mii miimaster=eth2
			ifconfig rai0 up 1>/dev/null 2>&1
		fi
	fi

	if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
		addRaix2Br0
		addInicWds2Br0
		addRaL02Br0
	fi
	wan.sh
	lan.sh
elif [ "$opmode" = "1" ]; then
	configVIF
	if [ "$CONFIG_RAETH_ROUTER" = "y" -a "$CONFIG_LAN_WAN_SUPPORT" = "y" ]; then
		if [ "$CONFIG_WAN_AT_P0" = "y" ]; then
			echo '##### config IC+ vlan partition (WLLLL) #####'
			config-vlan.sh 0 WLLLL
		else
			echo '##### config IC+ vlan partition (LLLLW) #####'
			config-vlan.sh 0 LLLLW
		fi
	fi
	if [ "$CONFIG_MAC_TO_MAC_MODE" = "y" ]; then
		if [ "$CONFIG_WAN_AT_P0" = "y" ]; then
			echo '##### config Vtss vlan partition (WLLLL) #####'
			config-vlan.sh 1 WLLLL
		else
			echo '##### config Vtss vlan partition (LLLLW) #####'
			config-vlan.sh 1 LLLLW
		fi
		if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
			sleep 3
		fi
	fi
	if [ "$CONFIG_RT_3052_ESW" = "y" -a "$CONFIG_LAN_WAN_SUPPORT" = "y" ]; then
		if [ "$CONFIG_P5_RGMII_TO_MAC_MODE" = "y" -o  "$CONFIG_GE2_RGMII_AN" = "y" ]; then
			echo "##### restore Ralink ESW to dump switch #####"
			if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
				config-vlan.sh 3 0 
			else
				config-vlan.sh 2 0
			fi
			if [ "$CONFIG_WAN_AT_P0" = "y" ]; then
				echo '##### config External Switch vlan partition (WLLLL) #####'
				if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
					echo "initialize external switch (WLLLL)"
				else
					config-vlan.sh 1 WLLLL
				fi
			else
				echo '##### config External Switch vlan partition (LLLLW) #####'
				if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
					echo "initialize external switch (LLLLW)"
				else
					config-vlan.sh 1 LLLLW
				fi
			fi
		else
			if [ "$CONFIG_WAN_AT_P0" = "y" ]; then
				echo '##### config Ralink ESW vlan partition (WLLLL) #####'
				if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
					config-vlan.sh 3 12345
				else
					config-vlan.sh 2 WLLLL
				fi
			else
				echo '##### config Ralink ESW vlan partition (LLLLW) #####'
				if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
					config-vlan.sh 3 12345
				else
					config-vlan.sh 2 LLLLW
				fi
			fi
		fi
	fi

	if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
		sleep 4
	fi

	addBr0
	addRax2Br0
	addWds2Br0
	addMesh2Br0
	if [ "$CONFIG_RAETH_ROUTER" = "y" -o "$CONFIG_MAC_TO_MAC_MODE" = "y" -o "$CONFIG_RT_3052_ESW" = "y" ]; then
		if [ "$CONFIG_RAETH_SPECIAL_TAG" == "y" ]; then
			if [ "$CONFIG_WAN_AT_P4" = "y" ]; then
				brctl addif br0 eth2.1
			fi
			brctl addif br0 eth2.2
			brctl addif br0 eth2.3
			brctl addif br0 eth2.4
			if [ "$CONFIG_WAN_AT_P0" = "y" ]; then
				brctl addif br0 eth2.5
			fi
		elif [ "$CONFIG_GE2_RGMII_AN" = "y" -o "$CONFIG_GE2_INTERNAL_GPHY" = "y" ]; then
			brctl addif br0 eth2
		else
			brctl addif br0 eth2.1
		fi
	fi

	# IC+ 100 PHY (one port only)
	if [ "$CONFIG_ICPLUS_PHY" = "y" ]; then
		echo '##### connected to one port 100 PHY #####'
		#
		# setup ip alias for user to access web page.
		#
		ifconfig eth2:1 172.32.1.254 netmask 255.255.255.0 up
	fi
	if [ "$CONFIG_GE1_RGMII_AN" = "y" -a "$CONFIG_GE2_RGMII_AN" = "y" ]; then
		echo "##### connected to two Giga PHY port #####"
		brctl addif br0 eth2
	fi
	if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
		addRaix2Br0
		addInicWds2Br0
		addRaL02Br0
	fi
	if [ "$supportWan1" = "1" ]; then
		echo "support WAN 1"
		wan.sh
	fi

	if [ "$supportWan2" = "1" ]; then
		echo "support WAN 2"
		wan2.sh
	fi
	if [ "$supportWan3" = "1" ]; then
		echo "support WAN 3"
		wan3.sh
	fi
	if [ "$supportWan4" = "1" ]; then
		echo "support WAN 4"
		wan4.sh
	fi

	lan.sh
	nat.sh

	# set the global ipv6 address for LAN/WAN, enable ipv6 forwarding,
	# enable ecmh(multicast) daemon
elif [ "$opmode" = "2" ]; then
	configVIF
	# if (-1 == initStaProfile())
	#   error(E_L, E_LOG, T("internet.c: profiles in nvram is broken"));
	# else
	#   initStaConnection();

	if [ "$CONFIG_RAETH_ROUTER" = "y" -a "$CONFIG_LAN_WAN_SUPPORT" = "y" ]; then
		echo "##### restore IC+ to dump switch #####"
		config-vlan.sh 0 0
	fi
	if [ "$CONFIG_MAC_TO_MAC_MODE" = "y" ]; then
		echo "##### restore External Switch to dump switch #####"
		config-vlan.sh 1 0
	fi
	if [ "$CONFIG_RT_3052_ESW" = "y" ]; then
		if [ "$CONFIG_P5_RGMII_TO_MAC_MODE" = "y" -o "$CONFIG_GE1_RGMII_FORCE_1000" = "y" -o "$CONFIG_GE1_RGMII_FORCE_1200" = "y" ]; then
			echo "##### restore Ralink ESW to dump switch #####"
			if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
				config-vlan.sh 3 0
			else
				config-vlan.sh 2 0
			fi
			echo "##### restore External Switch to dump switch #####"
			if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
				echo "initialize external switch"
			else
				config-vlan.sh 1 0
			fi
		else
			echo "##### restore Ralink ESW to dump switch #####"
			if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
				config-vlan.sh 3 0
			else
				config-vlan.sh 2 0
			fi
		fi
	fi
	if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
		sleep 4
	fi
	addBr0
	brctl addif br0 eth2
	if [ "$CONFIG_GE2_RGMII_AN" = "y" -o "$CONFIG_GE2_INTERNAL_GPHY" = "y" ]; then
		brctl addif br0 eth3
	fi
	enableIPv6dad $lan_if 1
	enableIPv6dad $wan_if 1

	if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
		addRaix2Br0
		addInicWds2Br0
		addRaL02Br0
	fi
	wan.sh
	lan.sh
	nat.sh
elif [ "$opmode" = "3" ]; then
	configVIF
	if [ "$CONFIG_RAETH_ROUTER" = "y" -o "$CONFIG_MAC_TO_MAC_MODE" = "y" -o "$CONFIG_RT_3052_ESW" = "y" ]; then
		if [ "$CONFIG_RAETH_ROUTER" = "y" ]; then
			echo "##### restore IC+ to dump switch #####"
			config-vlan.sh 0 0
		fi
		if [ "$CONFIG_MAC_TO_MAC_MODE" = "y" ]; then
			echo "##### restore Vtss to dump switch #####"
			config-vlan.sh 1 0
		fi
		if [ "$CONFIG_RT_3052_ESW" = "y" ]; then
			if [ "$CONFIG_P5_RGMII_TO_MAC_MODE" = "y" -o "$CONFIG_GE1_RGMII_FORCE_1000" = "y" -o "$CONFIG_GE1_RGMII_FORCE_1200" = "y" ]; then
				echo "##### restore Ralink ESW to dump switch #####"
				if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
					config-vlan.sh 3 0
				else
					config-vlan.sh 2 0
				fi
				echo "##### restore External Switch to dump switch #####"
				if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
					echo "initialize external switch"
				else
					config-vlan.sh 1 0
				fi
			else
				echo "##### restore Ralink ESW to dump switch #####"
				if [ "$CONFIG_RALINK_RT6855" = "y" -o "$CONFIG_RALINK_RT6855A" = "y" -o "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
					config-vlan.sh 3 0
				else
					config-vlan.sh 2 0
				fi
			fi
		fi
	fi
	if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
		sleep 4
	fi
	addBr0
	addRax2Br0
	brctl addif br0 eth2
	if [ "$CONFIG_GE2_RGMII_AN" = "y" -o "$CONFIG_GE2_INTERNAL_GPHY" = "y" ]; then
		brctl addif br0 eth3
	fi
	if [ "$CONFIG_RTDEV" != "" -o "$CONFIG_RT2561_AP" != "" ]; then
		addRaix2Br0
		addInicWds2Br0
		addRaL02Br0
	fi
	wan.sh
	lan.sh
	nat.sh
else
	echo "unknown OperationMode: $opmode"
	exit 1
fi

# INIC support
#if [ "$CONFIG_RT2880_INIC" != "" ]; then
#	ifconfig rai0 down
#	rmmod rt_pci_dev
#	ralink_init make_wireless_config rtdev
#	insmod -q rt_pci_dev
#	ifconfig rai0 up
#	RaAP&
#	sleep 3
#fi

if [ "$opmode" != "0" ]; then
	echo 1 > /proc/sys/net/ipv4/ip_forward
fi

# in order to use broadcast IP address in L2 management daemon
if [ "$CONFIG_ICPLUS_PHY" = "y" ]; then
	route add -host 255.255.255.255 dev $wan_if
else
	route add -host 255.255.255.255 dev $lan_if
fi


m2uenabled=`nvram_get 2860 M2UEnabled`
if [ "$m2uenabled" = "1" ]; then
	iwpriv ra0 set IgmpSnEnable=1
	echo "iwpriv ra0 set IgmpSnEnable=1"
fi

if [ "$wifi_off" = "1" ]; then
	ifRaxWdsxDown
	reg s b0180000
	reg w 400 0x1080
	reg w 1204 8
	reg w 1004 3
fi

RVT=`nvram_get 2860 RVT`
if [ "$RVT" = "1" ]; then
	if [ "$CONFIG_RA_CLASSIFIER" = "y" -o "$CONFIG_RA_CLASSIFIER" = "m" ]; then
	insmod -q cls
	fi
fi

#HWNAT=`nvram_get 2860 hwnatEnabled`
#if [ "$HWNAT" = "1" ]; then
#	insmod -q hw_nat
#fi

#__MSTC__, YenCheng
IGMPEn=`nvram_get 2860 igmpEnabled`
if [ "$IGMPEn" = "1" ]; then
	switch mcast $wan1Vid
elif [ "$IGMPEn" = "2" ]; then
	switch mcast $wan2Vid
elif [ "$IGMPEn" = "3" ]; then
	switch mcast $wan3Vid
elif [ "$IGMPEn" = "4" ]; then
	switch mcast $wan4Vid
else
	switch mcast 0
fi

WDGE=`nvram_get 2860 WatchDogEnable`
if [ "$WDGE" = "1" ]; then
	if [ "$CONFIG_RALINK_WATCHDOG" = "m" -o "$CONFIG_RALINK_TIMER_WDG" = "m" ]; then
	insmod -q ralink_wdt
	fi
	wdg.sh
	watchdog
fi

# In 2.6.36 kernel(MT7620& MT7621), avoid ipv6 traffic unless everything ready
if [ "$CONFIG_RALINK_MT7620" = "y" -o "$CONFIG_RALINK_MT7621" = "y" ]; then
if [ "$CONFIG_IPV6" == "y" -o "$CONFIG_IPV6" == "m" ]; then
echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6
fi
fi

if [ "$CONFIG_RALINK_MT7621" = "y" ]; then
	smp.sh wifi
fi

# radvd
radvd.sh

#ipv6_logo.sh

if [ "$CONFIG_RALINKAPP_HOTSPOT" == "y" ]; then
	hotspot.sh
fi

# Support TR069 client
# Marked by Max, change tr69 daemon up timing
#if [ "$CONFIG_TR069" = "y" ]; then
#	acsUrl=`nvram_get 2860 Cwmp_Entry.acsUrl`
#	if [ "$acsUrl" != "" ]; then
#		tr069.sh
#	fi
#   
	# Support STUN client
#	if [ "$CONFIG_USER_TR111" = "y" ]; then
#		stun.sh
#	fi
#fi

# Support QTN 5G
if [ "$CONFIG_QTN_5G" = "y" ]; then
   reg s 0xbe110000
   reg w 8 0x9000c
   mii_mgr -s -p 0 -r 0 -v 0x3900
   mii_mgr -s -p 1 -r 0 -v 0x3900
   mii_mgr -s -p 2 -r 0 -v 0x3900
   mii_mgr -s -p 3 -r 0 -v 0x3900
	#switch reg w 2004 20ff0400
	#switch reg w 2104 20ff0400
	#switch reg w 2204 20ff0400
	#switch reg w 2304 20ff0400
   ifconfig eth3 up
   brctl addif br0 eth3
   ifconfig br0:9 1.1.1.1 netmask 255.255.255.0 broadcast 1.1.1.255
   cp /usr/etc/protocols /etc/
   cp /usr/etc/rmt_ip.conf /etc/
   rmt_qcsmngr -m 0 &
fi

# netbiosservice.sh wap6805.setup home

echo 4096 > /proc/sys/net/ipv4/tcp_max_tw_buckets
#restart8021XDaemon(RT2860_NVRAM);
#firewall_init();
#management_init();
rm /var/internet_configuring

#AP Client
if [ "$CONFIG_MT_APCLI_SUPPORT" = "y" ]; then
    if [ "$CONFIG_USER_APCLI_LINK_SUPPORT" = "y" ]; then
        ifconfig apcli0 up
        brctl addif br0 apcli0
    fi
fi

I only have the object code for the reg userspace utility, but I do have the driver it uses. Which is even less interesting. It's a simple ioctl interface allowing userspace to read and write any register address. I assume it also comes from the SDK. Will eventually dump all this stuff, but don't think it helps much. It's just the SDK with some very system specific ZyXEL/Mitrastar hacks added.

Yes, that's what I found too. This register between MTK_PHY_IAC and MTK_MAC_MISC is completely undocumented.

I wouldn't expect it to make any difference on any router which doesn't use the RGMII pins to connect to something. It could also be completely system specific, related to how the Quantenna module is wired to the rest of the system. Which I know almost nothing about.

What come in mind: may be MDIO frequency setting. I have seens it some ware in á SDK they set the MDIO frequency for external phy's.

RGMII_2 pins are connected! Too ephy and internal switch P5. But I am not sure how that changes from one state to the other.

This indeed makes the router detect the SFP and the link, many thanks!

However, I don't see the switch itself anymore, swconfig list doesn't show anything. Do I miss something? Further, are there any plans to have this included in the official OpenWRT release?

1 Like

Correct! switch code is converted to DSA.

Today new patches are posted to support MT7621 and MT7530 in the mainline kernel. https://marc.info/?l=linux-netdev&m=154805471408751&w=2

When that is in we can include it in the openwrt.
I have a working version of this code and it seems great at the moment.

1 Like

Awesome stuff.
How hard would it be to backport it to 4.19 since its pretty much only matter of time when ramips is bumped to 4.19