configure the ksz8765 5 port Ethernet switch

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

configure the ksz8765 5 port Ethernet switch

21,892 Views
pavansingpatil
Contributor I

Hello,

we have custom board based on imx6sx connected with ksz8765 switch over spi bus using rgmii interface. we have enabled the fixed link driver in kernel and also configure same in dts file. Port 5 of the switch is connected to imx6sx MAC interface.

device tree configuration:

&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet1>;
phy-mode = "mii";
phy-reset-gpios = <&gpio1 25 GPIO_ACTIVE_LOW>;
fixed-link = <0 1 100 0 0>;
phy-supply = <&reg_vref_3v3>;
status = "okay";
};

kernel logs:

fec 2188000.ethernet (unnamed net_device) (uninitialized): Invalid MAC address: 00:00:00:00:00:00
fec 2188000.ethernet (unnamed net_device) (uninitialized): Using random MAC address: 7e:20:8b:ff:4b:22
libphy: fec_enet_mii_bus: probed
fec 2188000.ethernet eth0: registered PHC device 0
fec 2188000.ethernet eth0: Freescale FEC PHY driver [Generic PHY] (mii_bus:phy_addr=fixed-0:00, irq=-1)
fec 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off

we could see RX packets are 0, and Tx packet are also in queue.

eth0 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX 
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:7538 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:828904 (809.4 KiB)

there is spi driver to configure switch over spi for ksz8995...but it should work for ksz8765 after minor modification as chip id and family id is same.

linux-fslc/spi_ks8995.c at 4.1-2.0.x-imx · Freescale/linux-fslc · GitHub 

spi-ks8995 spi3.2: chip family id mismatch: expected 0x87 but 0x00 read
mx51_ecspi_clkdiv: fin: 60000000, fspi: 48000000, post: 0, pre: 1
mx51_ecspi_clkdiv: fin: 60000000, fspi: 48000000, post: 0, pre: 1
spi-ks8995 spi3.2: unsupported chip id for KSZ8795 family: 0x00

but it always reads 0.

Thanks in advance.

Labels (2)
0 Kudos
25 Replies

1,556 Views
camilocolombia
Contributor I

Hi guys,

Just wanted to share how I got it working because this forum helped me to figure out the problem.

Linux version 5.4.142

dtb

&fec1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_enet1>;
phy-mode = "rmii";
phy-reset-gpios = <&gpio1 28 GPIO_ACTIVE_LOW>;/*my reset line*/
fixed-link = <0 1 100 0 0>;
phy-supply = <&reg_vref_3v3>;
status = "okay";
};

 

Outputs for 2184800 FEC1

camilocolombia_1-1704815132754.png

 

The KSZ8775-5 has the following configuration:

camilocolombia_0-1704814994788.png

Since it is a switch, you will only see one eth interface in my case eth1:

camilocolombia_2-1704815196802.png

 

I hope this helps.

 

 

 

 

 

0 Kudos

4,707 Views
mahendrasondaga
Contributor III

Hi.. there 
I'm also facing the similar issue with the KSZ8795 4 port LAN switch 
I'm dealing with the kernel version 5.10.

 

KSZ8795 is configured over SPI 
The device tree source file as follows 

 

&ecspi1 {

         fsl,spi-num-chipselects = <1>;
         cs-gpios = <&gpio4 26 GPIO_ACTIVE_LOW>;
         pinctrl-names = "default";
         pinctrl-0 = <&pinctrl_ecspi1_1>;
         status = "okay";


                      ksz8795@0 {
                         compatible = "microchip,ksz8795";
                         spi-max-frequency = <25000000>;
                         reg = <0>;
                         pinctrl-names = "default";
                         spi-cpha;
                         spi-cpol;
                         status = "okay";


                       ports {
                             #address-cells = <1>;
                             #size-cells = <0>;
                             port@0 {
                                    reg = <0>;
                                    label = "lan1";
                             };
                             port@1 {
                                    reg = <1>;
                                    label = "lan2";
                             };
                             port@2 {
                                    reg = <2>;
                                    label = "lan3";
                             };
                             port@3 {
                                    reg = <3>;
                                    label = "lan4";
                             };
                             port@4 {
                                    reg = <4>;
                                    label = "cpu";
                                    ethernet = <&fec2>;
                                    fixed-link {
                                               speed = <100>;
                                               full-duplex;
                                    };
                             };
                       };
                   };
};



&fec2 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet2>,<&pinctrl_enet2_gpio>;
    phy-mode = "rmii";
    fsl,magic-packet;
    local-mac-address = [00 11 22 33 44 55];
    phy-reset-gpios = <&gpio5 5 GPIO_ACTIVE_LOW>;
    phy-reset-duration = <100>;
    status = "okay";


    fixed-link {
        speed = <100>;
        full-duplex;
    };

};

 

The DSA drivers used at network layer.

the KSZ8795 has successfully recognised by the kernel 
here is the logs snippets 

 

[    3.895939] libphy: dsa slave smi: probed
[    3.900536] ksz8795-switch spi0.0 lan1 (uninitialized): PHY [dsa-0.0:00] driver [Micrel KSZ87XX Switch] (irq=POLL)
[    3.912845] ksz8795-switch spi0.0 lan2 (uninitialized): PHY [dsa-0.0:01] driver [Micrel KSZ87XX Switch] (irq=POLL)
[    3.924997] ksz8795-switch spi0.0 lan3 (uninitialized): PHY [dsa-0.0:02] driver [Micrel KSZ87XX Switch] (irq=POLL)
[    3.937086] ksz8795-switch spi0.0 lan4 (uninitialized): PHY [dsa-0.0:03] driver [Micrel KSZ87XX Switch] (irq=POLL)
[    3.948945] ksz8795-switch spi0.0: configuring for fixed/ link mode
[    3.955601] DSA: tree 0 setup
[    3.960179] ksz8795-switch spi0.0: Link is Up - 100Mbps/Full - flow control off



imx6ul-var-dart login: [   27.483627] flexcan 2090000.flexcan can0: bit-timing not yet defined
[   27.493695] fec 2188000.ethernet eth1: Unable to connect to phy
[   27.533722] ksz8795-switch spi0.0 lan1: configuring for phy/gmii link mode
[   27.564068] 8021q: adding VLAN 0 to HW filter on device lan1
[   27.594719] ksz8795-switch spi0.0 lan2: configuring for phy/gmii link mode
[   27.631830] 8021q: adding VLAN 0 to HW filter on device lan2
[   27.665559] ksz8795-switch spi0.0 lan3: configuring for phy/gmii link mode
[   27.701829] 8021q: adding VLAN 0 to HW filter on device lan3
[   27.736870] ksz8795-switch spi0.0 lan4: configuring for phy/gmii link mode
[   27.774003] 8021q: adding VLAN 0 to HW filter on device lan4
[   30.652041] ksz8795-switch spi0.0 lan1: Link is Up - 100Mbps/Full - flow control off
[   30.659829] IPv6: ADDRCONF(NETDEV_CHANGE): lan1: link becomes ready
[   35.051557] VSD_3V3: disabling

 

Not only that, but also detecting link-up and down event while inserting and removing the LAN cable

 

ifconfig status is as follows 

 

root@imx6ul-var-dart:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:11:22:33:44:55  
          inet addr:169.254.106.114  Bcast:169.254.255.255  Mask:255.255.0.0
          inet6 addr: fe80::9425:b17b:bc94:5809/64 Scope:Link
          inet6 addr: fe80::211:22ff:fe33:4455/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1501  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:184 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:14875 (14.5 KiB)

lan1      Link encap:Ethernet  HWaddr 00:11:22:33:44:55  
          inet addr:169.254.106.114  Bcast:169.254.255.255  Mask:255.255.0.0
          inet6 addr: fe80::9425:b17b:bc94:5809/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:3380 (3.3 KiB)

lan2      Link encap:Ethernet  HWaddr 00:11:22:33:44:55  
          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 00:11:22:33:44:55  
          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)

lan4      Link encap:Ethernet  HWaddr 00:11:22:33:44:55  
          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:150 errors:0 dropped:0 overruns:0 frame:0
          TX packets:150 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12380 (12.0 KiB)  TX bytes:12380 (12.0 KiB)

wwan0     Link encap:Ethernet  HWaddr 16:34:26:24:15:40  
          inet addr:169.254.185.11  Bcast:169.254.255.255  Mask:255.255.0.0
          inet6 addr: fe80::c875:b908:f785:6686/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:79 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:18014 (17.5 KiB)

 

Dose anyone success to resolve the issue ?

 

Thanks 

0 Kudos

11,616 Views
Yang2021
Contributor I

I have same issue。RX  is 0.Who have right way?

0 Kudos

14,307 Views
emintolgasivri
Contributor II

Hi everyone

I am using ksz8895 and spi .My connection is as below.ksz8895.png

Should I have to use dsa drivers.Is my dts file correct?

&ecspi1{
    id = <1>;
    status = "okay";
    ksz8895: ksz8895@0 {
        compatible = "microchip,ksz8895";
        reg = <0>;

        spi-max-frequency = <40000000>;
        spi-cpha;
        spi-cpol;
        status = "okay";
        ports {
            #address-cells = <1>;
            #size-cells = <0>;
            port@0 {
                reg = <0>;
                label = "lan1";
            };
            port@1 {
                reg = <1>;
                label = "lan2";
            };
            port@2 {
                reg = <2>;
                label = "lan3";
            };
            port@3 {
                reg = <3>;
                label = "lan4";
            };
            port@4 {
                reg = <4>;
                label = "cpu";
                ethernet = <&ethphy0>;
                fixed-link {
                    speed = <100>;
                    full-duplex;
                };
            };
        };
    };
};

&fec1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet1>;
    //pinctrl-assert-gpios = <&gpio7 15 GPIO_ACTIVE_LOW>;
    clocks = <&clks IMX7D_ENET_AXI_ROOT_CLK>,
        <&clks IMX7D_ENET_AXI_ROOT_CLK>,
        <&clks IMX7D_ENET1_TIME_ROOT_CLK>,
        <&clks IMX7D_PLL_ENET_MAIN_50M_CLK>,
        <&clks IMX7D_ENET1_REF_ROOT_CLK>;
        clock-names = "ipg", "ahb", "ptp","enet_clk_ref", "no_enet_out";
    assigned-clocks = <&clks IMX7D_ENET1_TIME_ROOT_SRC>,
              <&clks IMX7D_ENET1_TIME_ROOT_CLK>;
    assigned-clock-parents = <&clks IMX7D_PLL_ENET_MAIN_100M_CLK>;
    assigned-clock-rates = <0>, <100000000>;
    phy-mode = "rmii";
    phy-handle = <&ethphy0>;
    fsl,magic-packet;
    status = "okay";
    
    fixed-link {
      speed = <100>;
      full-duplex;
    };
    /*mdio {*/
        #address-cells = <1>;
        #size-cells = <0>;
        
        ethphy0: ethernet-phy@0 {
            compatible = "microchip,ksz8895";
            reg = <0>;
        };
        ethphy1: ethernet-phy@1 {
            compatible = "microchip,ksz8895";
            reg = <1>;
        };
    /*};*/
};

&fec2 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_enet2>;
    clocks = <&clks IMX7D_ENET_AXI_ROOT_CLK>,
        <&clks IMX7D_ENET_AXI_ROOT_CLK>,
        <&clks IMX7D_ENET1_TIME_ROOT_CLK>,
        <&clks IMX7D_PLL_ENET_MAIN_50M_CLK>,
        <&clks IMX7D_ENET1_REF_ROOT_CLK>;
        clock-names = "ipg", "ahb", "ptp","enet_clk_ref", "no_enet_out";
    assigned-clocks = <&clks IMX7D_ENET2_TIME_ROOT_SRC>,
              <&clks IMX7D_ENET2_TIME_ROOT_CLK>;
    assigned-clock-parents = <&clks IMX7D_PLL_ENET_MAIN_100M_CLK>;
    assigned-clock-rates = <0>, <100000000>;
    phy-mode = "rmii";
    phy-handle = <&ethphy1>;
    fsl,magic-packet;
    status = "okay";
};

0 Kudos

14,355 Views
pavansingpatil
Contributor I

Hi,

Yes, I have resolved the issue.

check the sys directory  /sys/bus/mdio_bus/devices/fixed-0\:00 you should see something like this.

you should configure you switch properly to make it work in phy mode either you put strap in hardware options or write switch register using spi bus.9

is it configure in MII mode? is it configure in MAC(CPU)-PHY(switch) connection?

Regards,

Pavan

0 Kudos

14,355 Views
lvmh
Contributor I

Hi  pavansingpatil,

I use the RMII and spi mode, the manual says

0 Kudos

14,355 Views
lvmh
Contributor I

Hi  pavansingpatil,

I use the RMII and spi mode, the manual says:

MAC/PHY mode in RMII is different than MAC/PHY mode in MII. There is no strap pin and register configuration request
in RMI. Follow the signals connection in Table 3-11.TIM图片20180105164426.png

0 Kudos

14,355 Views
lvmh
Contributor I

Hi  pavansingpatil,

Find this directory with the following information

TIM图片20180105171456.png

Can you give me some advice?thanks 

0 Kudos

14,355 Views
pavansingpatil
Contributor I

Hi,

what issue exactly are you facing? Can you please elaborate?

--Pavan

0 Kudos

14,355 Views
lvmh
Contributor I

Hi pavansingpatil,

we could see RX packets are 0, and Tx packet are also in queue.

eth1 Link encap:Ethernet HWaddr 08:00:3E:26:0A:5C
inet addr:192.168.1.127 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:3eff:fe26:a5c%1996281552/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:2722 dropped:0 overruns:0 frame:2722
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:648 (648.0 B)

The information above shows an error in the rx package

0 Kudos

14,355 Views
linwangzhao
Contributor II

Hi  lvmh,

I have a similar problem in debugging KSZ8895RQXCA, Can you give me a reference? Thanks.

root@imx6qsabresd:~# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 56:2e:8f:d5:53:a7
inet addr:192.168.1.4 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::542e:8fff:fed5:53a7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:1123 dropped:0 overruns:0 frame:1123
TX packets:280 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:137336 (134.1 KiB)

0 Kudos

14,355 Views
lvmh
Contributor I

Hi ,

请检查cpu端的网口gpio ER引脚是否接下拉电阻,或者代码配置成下拉.

lvmh@qiyangtech.com

0 Kudos

14,355 Views
suifengrumeng
Contributor II

你好,我现在应该遇到了跟你一样的问题。目前我也是imx6生成的eth0不能够ping通两个下行口,CPU接口是RGMII,与交换机芯片KSZ8775的通讯接口是spi接口。查看sys目录已经生成:

root@imx6qdlsolo:~# ls /sys/bus/spi/devices/spi5.0/
driver power subsystem sw0 sw2 sw4
modalias registers sw sw1 sw3 uevent

root@imx6qdlsolo:~# ls /sys/bus/mdio_bus/devices/fixed-0\:00
driver phy_id power subsystem uevent

运行ping命令一段时间后,得到如下的结果:

root@imx6qdlsolo:~#
root@imx6qdlsolo:~# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
^C
--- 192.168.1.1 ping statistics ---
655 packets transmitted, 0 packets received, 100% packet loss
root@imx6qdlsolo:~#
root@imx6qdlsolo:~#
root@imx6qdlsolo:~# ifconfig
eth0 Link encap:Ethernet HWaddr 6A:E2:44:00:BE:96
inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::68e2:44ff:fe00:be96/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1513 errors:0 dropped:0 overruns:0 frame:0
TX packets:891 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:129433 (126.3 KiB) TX bytes:88685 (86.6 KiB)

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:718 errors:0 dropped:0 overruns:0 frame:0
TX packets:718 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:79872 (78.0 KiB) TX bytes:79872 (78.0 KiB)

不知道这些能不能反应一些问题呢?求点播。。。。。。。我现在不确定是软件问题还是硬件问题,不知道这个有没有什么办法确定呢?我测量CPU的TX信号都是有的

0 Kudos

14,327 Views
zhangzhencai
Contributor II

你好,你们dts中是怎么配置的?

0 Kudos

14,308 Views
suifengrumeng
Contributor II

我是按照楼主那样配置的,不知道能否加个联系方式讨论下?我目前也是卡在这里了,QQ:541237941

0 Kudos

14,355 Views
linwangzhao
Contributor II

Hi lvmh,

          我向你的邮箱(lvmh@qiyangtech.com)发了邮件,请查收,谢谢!

0 Kudos

14,355 Views
pavansingpatil
Contributor I

Hi, 

in my case i had hardware issue. cross verify your schematics with micrel LAN service.

fixed-link and fec driver is enough to get Ethernet communication working.

Regards,

--Pavan

0 Kudos

14,355 Views
lvmh
Contributor I

Hi,

What's wrong with your hardware?Can you give me a reference?

0 Kudos

14,355 Views
lvmh
Contributor I

Hi,

My problem now is that ksz8794 can be fixed to the CPU, but the network doesn't ping.

0 Kudos

14,354 Views
igorpadykov
NXP Employee
NXP Employee

Hi pavansingpatil

from log: "spi-ks8995 spi3.2: unsupported chip id for KSZ8795 family: 0x00"

seems driver did not receive correct data and one can check with oscilloscope

what data actually sent from ksz8765.

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos