zynq-7000系列基于zynq-zed的MAC->MAC 的实现(fixed-link)
作者:卢浩
时间:2017.2.20
转载请注明出处
前言:在项目实际使用中,我们有一些应用可以省去以太网phy芯片的,这里我就拿zynq-zed开发板做评估测试。
在VIVADO工程中去掉以太网的MDIO MDC配置,这样就无法读取PHY状态了,因为mac->mac这种连接就是无phy模式下的通讯。
@@ -383,27 +383,37 @@ static int macb_mii_probe(struct net_device *dev
int phy_irq;
int ret;
- phydev = phy_find_first(bp->mii_bus);
- if (!phydev) {
- netdev_err(dev, "no PHY found\n");
- return -ENXIO;
- }
+ if (bp->phy_node) {
+ phydev = of_phy_connect(dev, bp->phy_node,
+ &macb_handle_link_change, 0,
+ bp->phy_interface);
+ if (!phydev)
+ return -ENODEV;
+ } else {
+ phydev = phy_find_first(bp->mii_bus);
+ if (!phydev) {
+ netdev_err(dev, "no PHY found\n");
+ return -ENXIO;
+ }
- pdata = dev_get_platdata(&bp->pdev->dev);
- if (pdata && gpio_is_valid(pdata->phy_irq_pin)) {
- ret = devm_gpio_request(&bp->pdev->dev, pdata->phy_irq_pin, "phy int");
- if (!ret) {
- phy_irq = gpio_to_irq(pdata->phy_irq_pin);
- phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
+ pdata = dev_get_platdata(&bp->pdev->dev);
+ if (pdata && gpio_is_valid(pdata->phy_irq_pin)) {
+ ret = devm_gpio_request(&bp->pdev->dev,
+ pdata->phy_irq_pin, "phy int");
+ if (!ret) {
+ phy_irq = gpio_to_irq(pdata->phy_irq_pin);
+ phydev->irq = (phy_irq < 0) ?
+ PHY_POLL : phy_irq;
+ }
}
- }
- /* attach the mac to the phy */
- ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
- bp->phy_interface);
- if (ret) {
- netdev_err(dev, "Could not attach to PHY\n");
- return ret;
+ /* attach the mac to the phy */
+ ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
+ bp->phy_interface);
+ if (ret) {
+ netdev_err(dev, "Could not attach to PHY\n");
+ return ret;
+ }
}
/* mask with MAC supported features */
@@ -3461,14 +3471,21 @@ static int macb_probe(struct platform_device *pdev)
macb_get_hwaddr(bp);
/* Power up the PHY if there is a GPIO reset */
- phy_node = of_get_next_available_child(np, NULL);
- if (phy_node) {
+ phy_node = of_parse_phandle(np, "phy-handle", 0);
+ if (!phy_node && of_phy_is_fixed_link(np)) {
+ err = of_phy_register_fixed_link(np);
+ if (err < 0) {
+ dev_err(&pdev->dev, "broken fixed-link specification");
+ goto failed_phy;
+ }
+ phy_node = of_node_get(np);
+ bp->phy_node = phy_node;
+ } else {
int gpio = of_get_named_gpio(phy_node, "reset-gpios", 0);
if (gpio_is_valid(gpio))
bp->reset_gpio = gpio_to_desc(gpio);
gpiod_set_value(bp->reset_gpio, GPIOD_OUT_HIGH);
}
- of_node_put(phy_node);
err = of_get_phy_mode(np);
if (err < 0) {
@@ -3518,6 +3535,9 @@ static int macb_probe(struct platform_device *pdev)
err_out_free_netdev:
free_netdev(dev);
+failed_phy:
+ of_node_put(phy_node);
+
err_disable_clocks:
clk_disable_unprepare(tx_clk);
clk_disable_unprepare(hclk);
@@ -3547,6 +3567,7 @@ static int macb_remove(struct platform_device *pdev)
clk_disable_unprepare(bp->tx_clk);
clk_disable_unprepare(bp->hclk);
clk_disable_unprepare(bp->pclk);
+ of_node_put(bp->phy_node);
free_netdev(dev);
}
@@ -906,6 +906,7 @@ struct macb {
struct mii_bus *mii_bus;
struct phy_device *phy_dev;
+ struct device_node *phy_node;
int link;
int speed;
int duplex;
在内核配置文件中添加如下配置:
CONFIG_ETHERNET
CONFIG_NET_CADENCE
CONFIG_MACB
CONFIG_NETDEVICES
CONFIG_HAS_DMA
CONFIG_NET_CADENCE
CONFIG_MACB
CONFIG_NETDEVICES
CONFIG_HAS_DMA
在dts文件增加如下修改:
修改前:
51 &gem0 {
52 status = "okay";
53 phy-mode = "rgmii-id";
54 phy-handle = <ðernet_phy>;
55
56 ethernet_phy: ethernet-phy@0 {
57 reg = <0>;
58 };
59 };
52 status = "okay";
53 phy-mode = "rgmii-id";
54 phy-handle = <ðernet_phy>;
55
56 ethernet_phy: ethernet-phy@0 {
57 reg = <0>;
58 };
59 };
修改后:
55 &gem0 {
56 status = "okay";
57 phy-mode = "rgmii-id";
58 fixed-link {
59 speed = <1000>;
60 full-duplex;
61 };
68 };
56 status = "okay";
57 phy-mode = "rgmii-id";
58 fixed-link {
59 speed = <1000>;
60 full-duplex;
61 };
68 };
重新编译内核和dts文件。
上电启动zynq-zed开发板,对网卡进行测试,此时网卡被强制到1000M FULL模式。PHYADDR是0-31.
本文介绍如何在Zynq-Zed开发板上实现MAC到MAC的直连固定链路通信,通过修改内核文件和DTS配置,实现了无PHY模式下的网络通信,并提供了详细的步骤和代码示例。
&spm=1001.2101.3001.5002&articleId=56018542&d=1&t=3&u=e2d180dbbab74595bc4f0f5f81eb1f58)
2415

被折叠的 条评论
为什么被折叠?



