kernel: qca-ssdk: update to 12.4.5.r1
[openwrt/staging/mans0n.git] / package / kernel / qca-nss-dp / patches / 0013-nss_dp_main-Use-a-phy-handle-property-to-connect-to-.patch
1 From 8293a26ca56ee2e9a88e4efb5dcc7f647803cd8c Mon Sep 17 00:00:00 2001
2 From: Alexandru Gagniuc <mr.nuke.me@gmail.com>
3 Date: Sun, 5 Jun 2022 21:45:09 -0500
4 Subject: [PATCH] nss_dp_main: Use a 'phy-handle' property to connect to the
5 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 ---
22 include/nss_dp_dev.h | 5 +--
23 nss_dp_main.c | 91 +++++---------------------------------------
24 2 files changed, 10 insertions(+), 86 deletions(-)
25
26 --- a/include/nss_dp_dev.h
27 +++ b/include/nss_dp_dev.h
28 @@ -100,13 +100,10 @@ struct nss_dp_dev {
29 unsigned long drv_flags; /* Driver specific feature flags */
30
31 /* Phy related stuff */
32 + struct device_node *phy_node;
33 struct phy_device *phydev; /* Phy device */
34 struct mii_bus *miibus; /* MII bus */
35 phy_interface_t phy_mii_type; /* RGMII/SGMII/QSGMII */
36 - uint32_t phy_mdio_addr; /* Mdio address */
37 - bool link_poll; /* Link polling enable? */
38 - uint32_t forced_speed; /* Forced speed? */
39 - uint32_t forced_duplex; /* Forced duplex? */
40 uint32_t link_state; /* Current link state */
41 uint32_t pause; /* Current flow control settings */
42
43 --- a/nss_dp_main.c
44 +++ b/nss_dp_main.c
45 @@ -399,7 +399,7 @@ static int nss_dp_open(struct net_device
46
47 netif_start_queue(netdev);
48
49 - if (!dp_priv->link_poll) {
50 + if (!dp_priv->phydev) {
51 /* Notify data plane link is up */
52 if (dp_priv->data_plane_ops->link_state(dp_priv->dpc, 1)) {
53 netdev_dbg(netdev, "Data plane set link failed\n");
54 @@ -576,6 +576,8 @@ static int32_t nss_dp_of_get_pdata(struc
55 return -EFAULT;
56 }
57
58 + dp_priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
59 +
60 if (of_property_read_u32(np, "qcom,mactype", &hal_pdata->mactype)) {
61 pr_err("%s: error reading mactype\n", np->name);
62 return -EFAULT;
63 @@ -594,16 +596,6 @@ static int32_t nss_dp_of_get_pdata(struc
64 #else
65 of_get_phy_mode(np, &dp_priv->phy_mii_type);
66 #endif
67 - dp_priv->link_poll = of_property_read_bool(np, "qcom,link-poll");
68 - if (of_property_read_u32(np, "qcom,phy-mdio-addr",
69 - &dp_priv->phy_mdio_addr) && dp_priv->link_poll) {
70 - pr_err("%s: mdio addr required if link polling is enabled\n",
71 - np->name);
72 - return -EFAULT;
73 - }
74 -
75 - of_property_read_u32(np, "qcom,forced-speed", &dp_priv->forced_speed);
76 - of_property_read_u32(np, "qcom,forced-duplex", &dp_priv->forced_duplex);
77
78 ret = of_get_mac_address(np, maddr);
79 if (!ret && is_valid_ether_addr(maddr)) {
80 @@ -636,50 +628,6 @@ static int32_t nss_dp_of_get_pdata(struc
81 return 0;
82 }
83
84 -/*
85 - * nss_dp_mdio_attach()
86 - */
87 -static struct mii_bus *nss_dp_mdio_attach(struct platform_device *pdev)
88 -{
89 - struct device_node *mdio_node;
90 - struct platform_device *mdio_plat;
91 - struct ipq40xx_mdio_data *mdio_data;
92 -
93 - /*
94 - * Find mii_bus using "mdio-bus" handle.
95 - */
96 - mdio_node = of_parse_phandle(pdev->dev.of_node, "mdio-bus", 0);
97 - if (mdio_node) {
98 - return of_mdio_find_bus(mdio_node);
99 - }
100 -
101 - mdio_node = of_find_compatible_node(NULL, NULL, "qcom,qca-mdio");
102 - if (!mdio_node) {
103 - mdio_node = of_find_compatible_node(NULL, NULL,
104 - "qcom,ipq40xx-mdio");
105 - if (!mdio_node) {
106 - dev_err(&pdev->dev, "cannot find mdio node by phandle\n");
107 - return NULL;
108 - }
109 - }
110 -
111 - mdio_plat = of_find_device_by_node(mdio_node);
112 - if (!mdio_plat) {
113 - dev_err(&pdev->dev, "cannot find platform device from mdio node\n");
114 - of_node_put(mdio_node);
115 - return NULL;
116 - }
117 -
118 - mdio_data = dev_get_drvdata(&mdio_plat->dev);
119 - if (!mdio_data) {
120 - dev_err(&pdev->dev, "cannot get mii bus reference from device data\n");
121 - of_node_put(mdio_node);
122 - return NULL;
123 - }
124 -
125 - return mdio_data->mii_bus;
126 -}
127 -
128 #ifdef CONFIG_NET_SWITCHDEV
129 /*
130 * nss_dp_is_phy_dev()
131 @@ -738,7 +686,6 @@ static int32_t nss_dp_probe(struct platf
132 struct device_node *np = pdev->dev.of_node;
133 struct nss_gmac_hal_platform_data gmac_hal_pdata;
134 int32_t ret = 0;
135 - uint8_t phy_id[MII_BUS_ID_SIZE + 3];
136 #if defined(NSS_DP_PPE_SUPPORT)
137 uint32_t vsi_id;
138 fal_port_t port_id;
139 @@ -813,37 +760,17 @@ static int32_t nss_dp_probe(struct platf
140
141 dp_priv->drv_flags |= NSS_DP_PRIV_FLAG(INIT_DONE);
142
143 - if (dp_priv->link_poll) {
144 - dp_priv->miibus = nss_dp_mdio_attach(pdev);
145 - if (!dp_priv->miibus) {
146 - netdev_dbg(netdev, "failed to find miibus\n");
147 - goto phy_setup_fail;
148 - }
149 - snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
150 - dp_priv->miibus->id, dp_priv->phy_mdio_addr);
151 -
152 + if (dp_priv->phy_node) {
153 SET_NETDEV_DEV(netdev, &pdev->dev);
154 -
155 - dp_priv->phydev = phy_connect(netdev, phy_id,
156 - &nss_dp_adjust_link,
157 - dp_priv->phy_mii_type);
158 - if (IS_ERR(dp_priv->phydev)) {
159 - netdev_dbg(netdev, "failed to connect to phy device\n");
160 + dp_priv->phydev = of_phy_connect(netdev, dp_priv->phy_node,
161 + &nss_dp_adjust_link, 0,
162 + dp_priv->phy_mii_type);
163 + if (!(dp_priv->phydev)) {
164 + dev_err(&pdev->dev, "Could not attach to PHY\n");
165 goto phy_setup_fail;
166 }
167
168 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0))
169 - dp_priv->phydev->advertising |=
170 - (ADVERTISED_Pause | ADVERTISED_Asym_Pause);
171 - dp_priv->phydev->supported |=
172 - (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
173 -#else
174 - linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, dp_priv->phydev->advertising);
175 - linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, dp_priv->phydev->advertising);
176 -
177 - linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, dp_priv->phydev->supported);
178 - linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, dp_priv->phydev->supported);
179 -#endif
180 + phy_attached_info(dp_priv->phydev);
181 }
182
183 #if defined(NSS_DP_PPE_SUPPORT)