rk3399 mac to mac 连接switch

RK3399 MAC TO MAC 方式连接switch

RK3399的以太网控制器 通过mac to mac的方式连接 switch ksz9897交换芯片

1. 首先配置switch的mac口为千兆模式

在这里插入图片描述

2 .由于是mac to mac的模式,因此通讯速率需要固定

3.一路mdio最多可以扩展32路phy

4.原理就是在kernel的相应的代码处构造一个“伪phy”

5.更改代码

git diff  drivers/net/phy/phy_device.c
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 1f2f25a..a9c29fc 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -160,16 +160,31 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
                return ERR_PTR(-ENOMEM);
 
        dev->dev.release = phy_device_release;
-
-       dev->speed = 0;
-       dev->duplex = -1;
-       dev->pause = 0;
-       dev->asym_pause = 0;
-       dev->link = 1;
-       dev->interface = PHY_INTERFACE_MODE_GMII;
-
-       dev->autoneg = AUTONEG_ENABLE;
-
+       printk("%s has in addr is %x  \r\n", __func__, addr);
+       //对addR为0 的设备强制为千兆全双工
+       if(0 == addr)
+       {
+               //phydev->irq = PHY_IGNORE_INTERRUPT;
+               dev->speed = SPEED_1000;
+               dev->duplex = DUPLEX_FULL;
+               dev->pause = 0;
+               dev->asym_pause = 0;
+               dev->link = 1;
+               dev->interface = PHY_INTERFACE_MODE_RGMII;
+
+               dev->autoneg = AUTONEG_DISABLE;
+       }
+       else 
+       {
+               dev->speed = 0;
+               dev->duplex = -1;
+               dev->pause = 0;
+               dev->asym_pause = 0;
+               dev->link = 1;
+               dev->interface = PHY_INTERFACE_MODE_GMII;
+
+               dev->autoneg = AUTONEG_ENABLE;
+       }
        dev->is_c45 = is_c45;
        dev->addr = addr;
        dev->phy_id = phy_id;
@@ -368,6 +383,10 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
        /* If the phy_id is mostly Fs, there is no device there */
        if ((phy_id & 0x1fffffff) == 0x1fffffff)
                return NULL;
+       
+       //增加一个无效的phyid 0x0000ffff 如果为此 id 则返回 空指针
+       if ((addr != 0) && (phy_id == 0x0000ffff))
+               return NULL;
 
        return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids);
 }
@@ -1032,6 +1051,7 @@ int genphy_read_status(struct phy_device *phydev)
        int common_adv;
        int common_adv_gb = 0;
 
+       //printk("%s has in %d --%d !!!!\r\n", __func__ , phydev->addr ,phydev->phy_id );
        /* Update the link, but return if there was an error */
        err = genphy_update_link(phydev);
        if (err)
@@ -1112,6 +1132,19 @@ int genphy_read_status(struct phy_device *phydev)
                phydev->asym_pause = 0;
        }
 
+       //mac to mac 直接返回该值
+       if((0 == phydev->addr) && (0xffff == phydev->phy_id))
+       {
+               //phydev->irq = PHY_IGNORE_INTERRUPT;
+               phydev->speed = SPEED_1000;
+               phydev->duplex = DUPLEX_FULL;
+               phydev->pause = 0;
+               phydev->asym_pause = 0;
+               phydev->link = 1;
+               phydev->interface = PHY_INTERFACE_MODE_RGMII;
+
+               phydev->autoneg = AUTONEG_DISABLE;
+       }
        return 0;
 }
 EXPORT_SYMBOL(genphy_read_status);

更改后测试 可以进行ping 通 速率 在千兆

posted @ 2020-07-28 09:14  tccxy  阅读(2547)  评论(1编辑  收藏  举报