kernel: qca-nss-dp: update to 12.5.r2 for kernel 6.6
[openwrt/staging/nbd.git] / package / kernel / qca-nss-dp / patches / 0006-nss_dp_main-Use-a-phy-handle-property-to-connect-to-.patch
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
5 the PHY
6
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".
11
12 Allow using a "phy-handle" property. Remove the following properties,
13 as they are no longer used:
14 * "qcom,link-poll"
15 * "qcom,phy-mdio-addr"
16 * "mdio-bus"
17 * "qcom,forced-speed"
18 * "qcom,forced-duplex"
19
20 Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
21 Signed-off-by: Robert Marko <robimarko@gmail.com>
22 ---
23 include/nss_dp_dev.h | 5 +--
24 nss_dp_main.c | 91 +++++++-------------------------------------
25 2 files changed, 14 insertions(+), 82 deletions(-)
26
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 */
31
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 */
43
44 --- a/nss_dp_main.c
45 +++ b/nss_dp_main.c
46 @@ -436,7 +436,7 @@ static int nss_dp_open(struct net_device
47
48 netif_start_queue(netdev);
49
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
56 return -EFAULT;
57 }
58
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);
62 + return -EFAULT;
63 + }
64 +
65 if (of_property_read_u32(np, "qcom,mactype", &hal_pdata->mactype)) {
66 pr_err("%s: error reading mactype\n", np->name);
67 return -EFAULT;
68 @@ -653,18 +659,6 @@ static int32_t nss_dp_of_get_pdata(struc
69 return -EFAULT;
70 #endif
71
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",
76 - np->name);
77 - return -EFAULT;
78 - }
79 -
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);
82 -
83 -
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
88 return 0;
89 }
90
91 -/*
92 - * nss_dp_mdio_attach()
93 - */
94 -static struct mii_bus *nss_dp_mdio_attach(struct platform_device *pdev)
95 -{
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;
100 -#endif
101 -
102 - /*
103 - * Find mii_bus using "mdio-bus" handle.
104 - */
105 - mdio_node = of_parse_phandle(pdev->dev.of_node, "mdio-bus", 0);
106 - if (mdio_node) {
107 - return of_mdio_find_bus(mdio_node);
108 - }
109 -
110 - mdio_node = of_find_compatible_node(NULL, NULL, "qcom,qca-mdio");
111 - if (!mdio_node) {
112 - mdio_node = of_find_compatible_node(NULL, NULL,
113 - "qcom,ipq40xx-mdio");
114 - if (!mdio_node) {
115 - dev_err(&pdev->dev, "cannot find mdio node by phandle\n");
116 - return NULL;
117 - }
118 - }
119 -
120 - mdio_plat = of_find_device_by_node(mdio_node);
121 - if (!mdio_plat) {
122 - dev_err(&pdev->dev, "cannot find platform device from mdio node\n");
123 - of_node_put(mdio_node);
124 - return NULL;
125 - }
126 -
127 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0))
128 - return dev_get_drvdata(&mdio_plat->dev);
129 -#else
130 - mdio_data = dev_get_drvdata(&mdio_plat->dev);
131 - if (!mdio_data) {
132 - dev_err(&pdev->dev, "cannot get mii bus reference from device data\n");
133 - of_node_put(mdio_node);
134 - return NULL;
135 - }
136 -
137 - return mdio_data->mii_bus;
138 -#endif
139 -}
140 -
141 #ifdef CONFIG_NET_SWITCHDEV
142 /*
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;
147 int32_t ret = 0;
148 - uint8_t phy_id[MII_BUS_ID_SIZE + 3];
149 #if defined(NSS_DP_PPE_SUPPORT)
150 uint32_t vsi_id;
151 fal_port_t port_id;
152 @@ -940,22 +883,15 @@ static int32_t nss_dp_probe(struct platf
153
154 dp_priv->drv_flags |= NSS_DP_PRIV_FLAG(INIT_DONE);
155
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;
161 - }
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) {
165
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;
172 - }
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;
179 + }
180 }
181
182 #if defined(NSS_DP_PPE_SUPPORT)