1 From 5b05b1d7a2d2001d9711856608f61abaf7b9a9a5 Mon Sep 17 00:00:00 2001
2 From: Alexandru Gagniuc <mr.nuke.me@gmail.com>
3 Date: Fri, 23 Jun 2023 13:34:56 +0200
4 Subject: [PATCH 6/8] nss_dp_main: Use a 'phy-handle' property to connect to
7 The original method of connecting a PHY to the ethernet controller
8 requires the "qcom,link-poll", and "qcom,phy-mdio-addr" devicetree
9 properties. This is redundant. The PHY node already contains the MDIO
10 address, and attaching a PHY implies "link-poll".
12 Allow using a "phy-handle" property. Remove the following properties,
13 as they are no longer used:
15 * "qcom,phy-mdio-addr"
18 * "qcom,forced-duplex"
20 Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
21 Signed-off-by: Robert Marko <robimarko@gmail.com>
23 include/nss_dp_dev.h | 5 +--
24 nss_dp_main.c | 91 +++++++-------------------------------------
25 2 files changed, 14 insertions(+), 82 deletions(-)
27 --- a/include/nss_dp_dev.h
28 +++ b/include/nss_dp_dev.h
29 @@ -225,13 +225,10 @@ struct nss_dp_dev {
30 unsigned long drv_flags; /* Driver specific feature flags */
32 /* Phy related stuff */
33 + struct device_node *phy_node; /* Phy device OF node */
34 struct phy_device *phydev; /* Phy device */
35 struct mii_bus *miibus; /* MII bus */
36 uint32_t phy_mii_type; /* RGMII/SGMII/QSGMII */
37 - uint32_t phy_mdio_addr; /* Mdio address */
38 - bool link_poll; /* Link polling enable? */
39 - uint32_t forced_speed; /* Forced speed? */
40 - uint32_t forced_duplex; /* Forced duplex? */
41 uint32_t link_state; /* Current link state */
42 uint32_t pause; /* Current flow control settings */
46 @@ -436,7 +436,7 @@ static int nss_dp_open(struct net_device
48 netif_start_queue(netdev);
50 - if (!dp_priv->link_poll) {
51 + if (!dp_priv->phydev) {
52 /* Notify data plane link is up */
53 if (dp_priv->data_plane_ops->link_state(dp_priv->dpc, 1)) {
54 netdev_dbg(netdev, "Data plane set link failed\n");
55 @@ -633,6 +633,12 @@ static int32_t nss_dp_of_get_pdata(struc
59 + dp_priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
60 + if (!dp_priv->phy_node) {
61 + pr_err("%s: error parsing phy-handle\n", np->name);
65 if (of_property_read_u32(np, "qcom,mactype", &hal_pdata->mactype)) {
66 pr_err("%s: error reading mactype\n", np->name);
68 @@ -653,18 +659,6 @@ static int32_t nss_dp_of_get_pdata(struc
72 - dp_priv->link_poll = of_property_read_bool(np, "qcom,link-poll");
73 - if (of_property_read_u32(np, "qcom,phy-mdio-addr",
74 - &dp_priv->phy_mdio_addr) && dp_priv->link_poll) {
75 - pr_err("%s: mdio addr required if link polling is enabled\n",
80 - of_property_read_u32(np, "qcom,forced-speed", &dp_priv->forced_speed);
81 - of_property_read_u32(np, "qcom,forced-duplex", &dp_priv->forced_duplex);
84 #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
85 maddr = (uint8_t *)of_get_mac_address(np);
86 #if (LINUX_VERSION_CODE > KERNEL_VERSION(5, 4, 0))
87 @@ -753,56 +747,6 @@ static int32_t nss_dp_of_get_pdata(struc
92 - * nss_dp_mdio_attach()
94 -static struct mii_bus *nss_dp_mdio_attach(struct platform_device *pdev)
96 - struct device_node *mdio_node;
97 - struct platform_device *mdio_plat;
98 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6,1,0))
99 - struct ipq40xx_mdio_data *mdio_data;
103 - * Find mii_bus using "mdio-bus" handle.
105 - mdio_node = of_parse_phandle(pdev->dev.of_node, "mdio-bus", 0);
107 - return of_mdio_find_bus(mdio_node);
110 - mdio_node = of_find_compatible_node(NULL, NULL, "qcom,qca-mdio");
112 - mdio_node = of_find_compatible_node(NULL, NULL,
113 - "qcom,ipq40xx-mdio");
115 - dev_err(&pdev->dev, "cannot find mdio node by phandle\n");
120 - mdio_plat = of_find_device_by_node(mdio_node);
122 - dev_err(&pdev->dev, "cannot find platform device from mdio node\n");
123 - of_node_put(mdio_node);
127 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0))
128 - return dev_get_drvdata(&mdio_plat->dev);
130 - mdio_data = dev_get_drvdata(&mdio_plat->dev);
132 - dev_err(&pdev->dev, "cannot get mii bus reference from device data\n");
133 - of_node_put(mdio_node);
137 - return mdio_data->mii_bus;
141 #ifdef CONFIG_NET_SWITCHDEV
143 * nss_dp_is_phy_dev()
144 @@ -861,7 +805,6 @@ static int32_t nss_dp_probe(struct platf
145 struct device_node *np = pdev->dev.of_node;
146 struct nss_gmac_hal_platform_data gmac_hal_pdata;
148 - uint8_t phy_id[MII_BUS_ID_SIZE + 3];
149 #if defined(NSS_DP_PPE_SUPPORT)
152 @@ -940,22 +883,15 @@ static int32_t nss_dp_probe(struct platf
154 dp_priv->drv_flags |= NSS_DP_PRIV_FLAG(INIT_DONE);
156 - if (dp_priv->link_poll) {
157 - dp_priv->miibus = nss_dp_mdio_attach(pdev);
158 - if (!dp_priv->miibus) {
159 - netdev_dbg(netdev, "failed to find miibus\n");
160 - goto phy_setup_fail;
162 - snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
163 - dp_priv->miibus->id, dp_priv->phy_mdio_addr);
164 + if (dp_priv->phy_node) {
166 - dp_priv->phydev = phy_connect(netdev, phy_id,
167 - &nss_dp_adjust_link,
168 - dp_priv->phy_mii_type);
169 - if (IS_ERR(dp_priv->phydev)) {
170 - netdev_dbg(netdev, "failed to connect to phy device\n");
171 - goto phy_setup_fail;
173 + dp_priv->phydev = of_phy_connect(netdev, dp_priv->phy_node,
174 + &nss_dp_adjust_link, 0,
175 + dp_priv->phy_mii_type);
176 + if (!(dp_priv->phydev)) {
177 + netdev_err(netdev, "failed to connect to phy device\n");
178 + goto phy_setup_fail;
182 #if defined(NSS_DP_PPE_SUPPORT)