OpenWrt Forum Archive

Topic: Add external switch to the i2c bus and control it with swconfig

The content of this topic has been archived on 2 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello

I have a router that has an I2C bus (not native, but hackable) and no internal switch (just a single ethernet port). Actually I have a few different models, for the example let's say I would use the TP-LINK MR-3020 one.

I also have some external switches (standalone cheap TP-LINK switches) with 5 and 8 ports, models TP-SG1005D and TP-SG1008D, and they use chipsets Realtek RTL-8367 and RTL-8370, respectively. These chips are manageable, they can do VLANs and other stuff, but they have to be programmed to do so. Originally the switches have an i2c memory onboard that maps all the ports to a single vlan without tags. There is a header on the boards of both switch types to get access to the i2c bus, and talk both to the memory chip and also to the realtek processor (which starts as a i2c master, reads the memory chip and then turns into i2c slave to be controlled by the i2c bus receiving more external commands afterwards).

I know that there are models of routers supported by OpenWRT that use those switch chips inside them. For this to work, would it just be a matter of connecting the i2c bus on the switch to the i2c bus of the router and control it with swconfig?

Thank you!
Andre

Edit: ASUS RT-N56U is such a router with rtl8367.

(Last edited by token on 23 Nov 2015, 21:21)

Ok. Rainy day, nothing to do, let's play with this.

I took a spare Raspberry Pi 1 B+, loaded OpenWRT trunk of today in a sdcard and booted it, installed some packages:

root@OpenWrt:~# opkg install kmod-i2c-bcm2708
...
Configuring kmod-i2c-core.
Configuring kmod-i2c-bcm2708.

root@OpenWrt:~# dmesg | tail -n 2
[  496.102940] bcm2708_i2c 20205000.i2c: BSC0 Controller at 0x20205000 (irq 79) (baudrate 100000)
[  496.115797] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)

root@OpenWrt:~# ls -l /dev/i2c*
crw-r--r--    1 root     root       89,   0 Nov 24 21:47 /dev/i2c-0
crw-r--r--    1 root     root       89,   1 Nov 24 21:47 /dev/i2c-1

root@OpenWrt:~# opkg install i2c-tools
...
Configuring i2c-tools.

root@OpenWrt:~# i2cdetect -l
i2c-0    i2c           20205000.i2c                        I2C adapter
i2c-1    i2c           20804000.i2c                        I2C adapter

Then I wired the i2c bus of the switch to the raspberry. And, voila...

root@OpenWrt:~# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
root@OpenWrt:~# i2cdetect 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- 5c -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

There is something on the i2c bus #1. I'm pretty sure one of them is the memory EEPROM and the other is the realtek chip in slave mode (after booting in master mode).

I just need help to make swconfig control it (it may involve loading kernel drivers that were not compiled in this hardware profile).

Thanks!

Ok, some findings:

- looking on the web, there seems to be source code for rtl8367* on the openwrt kernel, but looking at the packages compiled, they are missing (even on the models that actually have this chip like the ramips / rt3883 / asus n56u). Installing the drivers for the 8366 does not seem to help.

- installing swconfig (app & kernel module) is not enough. creating a fake config in /etc/config/network for a switch does not help either.

- dumping both adresses on the i2c bus produce a 1224 bytes file that are almost but not tottaly identical.

- dumping the same address over and over producess identical dumps, they do not seem to change over time even plugging / unplugging ethernet cables on the switch

Any ideias?

Thanks



This is are dumps:

root@OpenWrt:~# hexdump dump-50.bin
0000000 2020 2020 3020 2020 2031 3220 2020 2033
0000010 3420 2020 2035 3620 2020 2037 3820 2020
0000020 2039 6120 2020 2062 6320 2020 2064 6520
0000030 2020 2066 2020 3020 3231 3433 3635 3837
0000040 6139 6362 6564 0a66 3030 203a 6165 3820
0000050 2030 3530 3120 2033 3030 6320 2030 6531
0000060 3120 2032 6163 3020 2033 3333 3120 2032
0000070 3235 3020 2033 3433 3120 2032 2020 3f20
0000080 3f3f 2e3f 3f3f 3f3f 333f 523f 343f 0a3f
0000090 3031 203a 3436 3020 2030 3733 3120 2032
00000a0 3639 3020 2030 3833 3120 2032 3837 3020
00000b0 2030 3933 3120 2032 3438 3020 2030 6133
00000c0 3120 2032 2020 6420 372e 3f3f 382e 783f
00000d0 392e 3f3f 3a2e 0a3f 3032 203a 3033 3020
00000e0 2030 3130 3020 2032 3436 3020 2030 3230
00000f0 3020 2032 3436 3020 2030 3330 3020 2032
0000100 3639 3020 2030 3430 3020 2032 2020 3020
0000110 3f2e 643f 3f2e 643f 3f2e 3f3f 3f2e 0a3f
0000120 3033 203a 3639 3020 2030 3530 3020 2032
0000130 3639 3020 2030 3630 3020 2032 3639 3020
0000140 2030 3730 3020 2032 3639 3020 2030 3330
0000150 3120 2062 2020 3f20 3f2e 3f3f 3f2e 3f3f
0000160 3f2e 3f3f 3f2e 0a3f 3034 203a 3230 3020
0000170 2030 6635 3220 2030 3230 3020 2030 3935
0000180 3220 2030 3030 3120 2061 6635 3220 2030
0000190 3030 3020 2030 6637 3220 2030 2020 3f20
00001a0 5f2e 3f20 592e 2e20 5f3f 2e20 3f2e 0a20
00001b0 3035 203a 3230 3020 2030 3737 3220 2030
00001c0 3030 3020 2030 3837 3220 2030 3030 3020
00001d0 2030 3937 3220 2030 3030 3020 2030 6137
00001e0 3220 2030 2020 3f20 772e 2e20 782e 2e20
00001f0 792e 2e20 7a2e 0a20 3036 203a 3030 3020
0000200 2030 6237 3220 2030 3030 3020 2030 6637
0000210 3220 2030 3030 3020 2030 6635 3220 2030
0000220 3230 3020 2030 3335 3220 2030 2020 2e20
0000230 7b2e 2e20 3f2e 2e20 5f2e 3f20 532e 0a20
0000240 3037 203a 3030 3020 2030 3435 3220 2030
0000250 3030 3020 2030 3535 3220 2030 3030 3020
0000260 2030 3635 3220 2030 3030 3020 2030 3735
0000270 3220 2030 2020 2e20 542e 2e20 552e 2e20
0000280 562e 2e20 572e 0a20 3038 203a 3030 3020
0000290 2030 6635 3220 2030 3030 3020 2030 6633
00002a0 3120 2033 3033 3020 2030 6533 3120 2033
00002b0 6530 3020 2030 6631 3220 2032 2020 2e20
00002c0 5f2e 2e20 3f2e 303f 3e2e 3f3f 3f2e 0a22
00002d0 3039 203a 3530 3020 2030 3530 3220 2032
00002e0 3638 3820 2062 3630 3220 2032 6530 3820
00002f0 2030 6631 3220 2032 3030 3020 2030 6633
0000300 3120 2033 2020 3f20 3f2e 3f22 3f3f 3f22
0000310 3f3f 2e22 3f2e 0a3f 3061 203a 3031 3020
0000320 2030 3361 3120 2032 3030 3220 2032 3730
0000330 3620 2031 6238 6520 2035 3330 3620 2031
0000340 3037 6120 2039 3030 3120 2032 2020 3f20
0000350 3f2e 2e3f 3f22 3f61 3f3f 7061 2e3f 0a3f
0000360 3062 203a 3463 3720 2066 6265 3120 2033
0000370 6262 3120 2031 3831 3020 2030 3030 3020
0000380 2066 3833 3020 2030 3030 3020 2066 3835
0000390 3020 2030 2020 3f20 3f3f 3f3f 3f3f 2e2e
00003a0 383f 2e2e 583f 0a2e 3063 203a 3030 3020
00003b0 2066 3837 3020 2030 3030 3020 2066 3839
00003c0 3020 2030 3030 3020 2066 6637 3220 2030
00003d0 3230 3020 2030 3337 3220 2030 2020 2e20
00003e0 783f 2e2e 3f3f 2e2e 3f3f 3f20 732e 0a20
00003f0 3064 203a 3232 3120 2064 6637 3220 2030
0000400 3030 3020 2030 6633 3120 2033 3033 3020
0000410 2030 6533 3120 2033 6530 3020 2030 3030
0000420 3220 2032 2020 2220 3f3f 2e20 3f2e 303f
0000430 3e2e 3f3f 2e2e 0a22 3065 203a 3034 3120
0000440 2033 6533 3120 2033 6530 3020 2030 6633
0000450 3120 2033 3031 3020 2030 6666 6620 2066
0000460 6666 6620 2066 6666 6620 2066 2020 4020
0000470 3e3f 3f3f 3f2e 3f3f 2e2e 2e2e 2e2e 0a2e
0000480 3066 203a 6666 6620 2066 6666 6620 2066
0000490 6666 6620 2066 6666 6620 2066 6666 6620
00004a0 2066 6666 6620 2066 6666 6620 2066 6666
00004b0 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
00004c0 2e2e 2e2e 2e2e 0a2e                    
00004c8
root@OpenWrt:~# hexdump dump-5c.bin
0000000 2020 2020 3020 2020 2031 3220 2020 2033
0000010 3420 2020 2035 3620 2020 2037 3820 2020
0000020 2039 6120 2020 2062 6320 2020 2064 6520
0000030 2020 2066 2020 3020 3231 3433 3635 3837
0000040 6139 6362 6564 0a66 3030 203a 6666 6620
0000050 2066 6666 6620 2066 6666 6620 2066 6666
0000060 6620 2066 6666 6620 2066 6666 6620 2066
0000070 6666 6620 2066 6666 6620 2066 2020 2e20
0000080 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
0000090 3031 203a 6666 6620 2066 6666 6620 2066
00000a0 6666 6620 2066 6666 6620 2066 6666 6620
00000b0 2066 6666 6620 2066 6666 6620 2066 6666
00000c0 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
00000d0 2e2e 2e2e 2e2e 0a2e 3032 203a 6666 6620
00000e0 2066 6666 6620 2066 6666 6620 2066 6666
00000f0 6620 2066 6666 6620 2066 6666 6620 2066
0000100 6666 6620 2066 6666 6620 2066 2020 2e20
0000110 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
0000120 3033 203a 6666 6620 2066 6666 6620 2066
0000130 6666 6620 2066 6666 6620 2066 6666 6620
0000140 2066 6666 6620 2066 6666 6620 2066 6666
0000150 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
0000160 2e2e 2e2e 2e2e 0a2e 3034 203a 6666 6620
0000170 2066 6666 6620 2066 6666 6620 2066 6666
0000180 6620 2066 6666 6620 2066 6666 6620 2066
0000190 6666 6620 2066 6666 6620 2066 2020 2e20
00001a0 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
00001b0 3035 203a 6666 6620 2066 6666 6620 2066
00001c0 6666 6620 2066 6666 6620 2066 6666 6620
00001d0 2066 6666 6620 2066 6666 6620 2066 6666
00001e0 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
00001f0 2e2e 2e2e 2e2e 0a2e 3036 203a 6666 6620
0000200 2066 6666 6620 2066 6666 6620 2066 6666
0000210 6620 2066 6666 6620 2066 6666 6620 2066
0000220 6666 6620 2066 6666 6620 2066 2020 2e20
0000230 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
0000240 3037 203a 6666 6620 2066 6666 6620 2066
0000250 6666 6620 2066 6666 6620 2066 6666 6620
0000260 2066 6666 6620 2066 6666 6620 2066 6666
0000270 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
0000280 2e2e 2e2e 2e2e 0a2e 3038 203a 6666 6620
0000290 2066 6666 6620 2066 6666 6620 2066 6666
00002a0 6620 2066 6666 6620 2066 6666 6620 2066
00002b0 6666 6620 2066 6666 6620 2066 2020 2e20
00002c0 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
00002d0 3039 203a 6666 6620 2066 6666 6620 2066
00002e0 6666 6620 2066 6666 6620 2066 6666 6620
00002f0 2066 6666 6620 2066 6666 6620 2066 6666
0000300 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
0000310 2e2e 2e2e 2e2e 0a2e 3061 203a 6666 6620
0000320 2066 6666 6620 2066 6666 6620 2066 6666
0000330 6620 2066 6666 6620 2066 6666 6620 2066
0000340 6666 6620 2066 6666 6620 2066 2020 2e20
0000350 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
0000360 3062 203a 6666 6620 2066 6666 6620 2066
0000370 6666 6620 2066 6666 6620 2066 6666 6620
0000380 2066 6666 6620 2066 6666 6620 2066 6666
0000390 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
00003a0 2e2e 2e2e 2e2e 0a2e 3063 203a 6666 6620
00003b0 2066 6666 6620 2066 6666 6620 2066 6666
00003c0 6620 2066 6666 6620 2066 6666 6620 2066
00003d0 6666 6620 2066 6666 6620 2066 2020 2e20
00003e0 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
00003f0 3064 203a 6666 6620 2066 6666 6620 2066
0000400 6666 6620 2066 6666 6620 2066 6666 6620
0000410 2066 6666 6620 2066 6666 6620 2066 6666
0000420 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
0000430 2e2e 2e2e 2e2e 0a2e 3065 203a 6666 6620
0000440 2066 6666 6620 2066 6666 6620 2066 6666
0000450 6620 2066 6666 6620 2066 6666 6620 2066
0000460 6666 6620 2066 6666 6620 2066 2020 2e20
0000470 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 0a2e
0000480 3066 203a 6666 6620 2066 6666 6620 2066
0000490 6666 6620 2066 6666 6620 2066 6666 6620
00004a0 2066 6666 6620 2066 6666 6620 2066 6666
00004b0 6620 2066 2020 2e20 2e2e 2e2e 2e2e 2e2e
00004c0 2e2e 2e2e 2e2e 0a2e                    
00004c8

I downloaded the trunk for the distro to try to compile it with the missing modules, but the modules do not appear in the menuconfig kernel drivers selection, inspite of existing on the downloaded source tree.

[root@dhcp108 openwrt]# find -iname "rtl8367*"
./target/linux/generic/files/drivers/net/phy/rtl8367.c
./target/linux/generic/files/drivers/net/phy/rtl8367b.c
./target/linux/generic/files/include/linux/rtl8367.h

But when making a "make menuconfig" and entering "Kernel Modules" >> "Network Devices" I get:

< > kmod-dummy.......................................... Dummy network device
< > kmod-gigaset...................... Siemens Gigaset support for isdn4linux
< > kmod-hfcmulti....... HFC multiport cards (HFC-4S/8S/E1) support for mISDN
< > kmod-hfcpci................ HFC PCI cards (single port) support for mISDN
{M} kmod-ifb........................... Intermediate Functional Block support
< > kmod-libphy.................................................. PHY library
< > kmod-macvlan............................................ MAC-VLAN support
< > kmod-mii..................................................... MII library
< > kmod-of-mdio................................... OpenFirmware MDIO support
< > kmod-phy-broadcom........................... Broadcom Ethernet PHY driver
< > kmod-spi-ks8995............. Micrel/Kendin KS8995 Ethernet switch control
< > kmod-swconfig................................... switch configuration API
< > kmod-switch-ip17xx............................. IC+ IP17XX switch support
< > kmod-switch-mvsw61xx...................... Marvell 88E61xx switch support
< > kmod-switch-rtl8366-smi..... Realtek RTL8366 SMI switch interface support
< > kmod-switch-rtl8366rb................... Realtek RTL8366RB switch support
< > kmod-switch-rtl8366s..................... Realtek RTL8366S switch support
< > kmod-tg3................................ Broadcom Tigon3 Gigabit Ethernet

       <Select>    < Exit >    < Help >    < Save >    < Load >              

There's only option for the rtl8366 chip, the rtl8367 does not appear in the list. Even if I select a target that have this switch onboard it does not appear.

What am I missing?

Thank you

The discussion might have continued from here.