2
0

0006-nss_dp_main-Use-a-phy-handle-property-to-connect-to-.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. From 5b05b1d7a2d2001d9711856608f61abaf7b9a9a5 Mon Sep 17 00:00:00 2001
  2. From: Alexandru Gagniuc <[email protected]>
  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. The original method of connecting a PHY to the ethernet controller
  7. requires the "qcom,link-poll", and "qcom,phy-mdio-addr" devicetree
  8. properties. This is redundant. The PHY node already contains the MDIO
  9. address, and attaching a PHY implies "link-poll".
  10. Allow using a "phy-handle" property. Remove the following properties,
  11. as they are no longer used:
  12. * "qcom,link-poll"
  13. * "qcom,phy-mdio-addr"
  14. * "mdio-bus"
  15. * "qcom,forced-speed"
  16. * "qcom,forced-duplex"
  17. Signed-off-by: Alexandru Gagniuc <[email protected]>
  18. Signed-off-by: Robert Marko <[email protected]>
  19. ---
  20. include/nss_dp_dev.h | 5 +--
  21. nss_dp_main.c | 91 +++++++-------------------------------------
  22. 2 files changed, 14 insertions(+), 82 deletions(-)
  23. --- a/include/nss_dp_dev.h
  24. +++ b/include/nss_dp_dev.h
  25. @@ -225,13 +225,10 @@ struct nss_dp_dev {
  26. unsigned long drv_flags; /* Driver specific feature flags */
  27. /* Phy related stuff */
  28. + struct device_node *phy_node; /* Phy device OF node */
  29. struct phy_device *phydev; /* Phy device */
  30. struct mii_bus *miibus; /* MII bus */
  31. uint32_t phy_mii_type; /* RGMII/SGMII/QSGMII */
  32. - uint32_t phy_mdio_addr; /* Mdio address */
  33. - bool link_poll; /* Link polling enable? */
  34. - uint32_t forced_speed; /* Forced speed? */
  35. - uint32_t forced_duplex; /* Forced duplex? */
  36. uint32_t link_state; /* Current link state */
  37. uint32_t pause; /* Current flow control settings */
  38. --- a/nss_dp_main.c
  39. +++ b/nss_dp_main.c
  40. @@ -436,7 +436,7 @@ static int nss_dp_open(struct net_device
  41. netif_start_queue(netdev);
  42. - if (!dp_priv->link_poll) {
  43. + if (!dp_priv->phydev) {
  44. /* Notify data plane link is up */
  45. if (dp_priv->data_plane_ops->link_state(dp_priv->dpc, 1)) {
  46. netdev_dbg(netdev, "Data plane set link failed\n");
  47. @@ -633,6 +633,12 @@ static int32_t nss_dp_of_get_pdata(struc
  48. return -EFAULT;
  49. }
  50. + dp_priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
  51. + if (!dp_priv->phy_node) {
  52. + pr_err("%s: error parsing phy-handle\n", np->name);
  53. + return -EFAULT;
  54. + }
  55. +
  56. if (of_property_read_u32(np, "qcom,mactype", &hal_pdata->mactype)) {
  57. pr_err("%s: error reading mactype\n", np->name);
  58. return -EFAULT;
  59. @@ -653,18 +659,6 @@ static int32_t nss_dp_of_get_pdata(struc
  60. return -EFAULT;
  61. #endif
  62. - dp_priv->link_poll = of_property_read_bool(np, "qcom,link-poll");
  63. - if (of_property_read_u32(np, "qcom,phy-mdio-addr",
  64. - &dp_priv->phy_mdio_addr) && dp_priv->link_poll) {
  65. - pr_err("%s: mdio addr required if link polling is enabled\n",
  66. - np->name);
  67. - return -EFAULT;
  68. - }
  69. -
  70. - of_property_read_u32(np, "qcom,forced-speed", &dp_priv->forced_speed);
  71. - of_property_read_u32(np, "qcom,forced-duplex", &dp_priv->forced_duplex);
  72. -
  73. -
  74. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
  75. maddr = (uint8_t *)of_get_mac_address(np);
  76. #if (LINUX_VERSION_CODE > KERNEL_VERSION(5, 4, 0))
  77. @@ -753,56 +747,6 @@ static int32_t nss_dp_of_get_pdata(struc
  78. return 0;
  79. }
  80. -/*
  81. - * nss_dp_mdio_attach()
  82. - */
  83. -static struct mii_bus *nss_dp_mdio_attach(struct platform_device *pdev)
  84. -{
  85. - struct device_node *mdio_node;
  86. - struct platform_device *mdio_plat;
  87. -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6,1,0))
  88. - struct ipq40xx_mdio_data *mdio_data;
  89. -#endif
  90. -
  91. - /*
  92. - * Find mii_bus using "mdio-bus" handle.
  93. - */
  94. - mdio_node = of_parse_phandle(pdev->dev.of_node, "mdio-bus", 0);
  95. - if (mdio_node) {
  96. - return of_mdio_find_bus(mdio_node);
  97. - }
  98. -
  99. - mdio_node = of_find_compatible_node(NULL, NULL, "qcom,qca-mdio");
  100. - if (!mdio_node) {
  101. - mdio_node = of_find_compatible_node(NULL, NULL,
  102. - "qcom,ipq40xx-mdio");
  103. - if (!mdio_node) {
  104. - dev_err(&pdev->dev, "cannot find mdio node by phandle\n");
  105. - return NULL;
  106. - }
  107. - }
  108. -
  109. - mdio_plat = of_find_device_by_node(mdio_node);
  110. - if (!mdio_plat) {
  111. - dev_err(&pdev->dev, "cannot find platform device from mdio node\n");
  112. - of_node_put(mdio_node);
  113. - return NULL;
  114. - }
  115. -
  116. -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0))
  117. - return dev_get_drvdata(&mdio_plat->dev);
  118. -#else
  119. - mdio_data = dev_get_drvdata(&mdio_plat->dev);
  120. - if (!mdio_data) {
  121. - dev_err(&pdev->dev, "cannot get mii bus reference from device data\n");
  122. - of_node_put(mdio_node);
  123. - return NULL;
  124. - }
  125. -
  126. - return mdio_data->mii_bus;
  127. -#endif
  128. -}
  129. -
  130. #ifdef CONFIG_NET_SWITCHDEV
  131. /*
  132. * nss_dp_is_phy_dev()
  133. @@ -861,7 +805,6 @@ static int32_t nss_dp_probe(struct platf
  134. struct device_node *np = pdev->dev.of_node;
  135. struct nss_gmac_hal_platform_data gmac_hal_pdata;
  136. int32_t ret = 0;
  137. - uint8_t phy_id[MII_BUS_ID_SIZE + 3];
  138. #if defined(NSS_DP_PPE_SUPPORT)
  139. uint32_t vsi_id;
  140. fal_port_t port_id;
  141. @@ -940,22 +883,16 @@ static int32_t nss_dp_probe(struct platf
  142. dp_priv->drv_flags |= NSS_DP_PRIV_FLAG(INIT_DONE);
  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. + if (dp_priv->phy_node) {
  152. - dp_priv->phydev = phy_connect(netdev, phy_id,
  153. - &nss_dp_adjust_link,
  154. - dp_priv->phy_mii_type);
  155. - if (IS_ERR(dp_priv->phydev)) {
  156. - netdev_dbg(netdev, "failed to connect to phy device\n");
  157. - goto phy_setup_fail;
  158. - }
  159. + dp_priv->phydev = of_phy_connect(netdev, dp_priv->phy_node,
  160. + &nss_dp_adjust_link, 0,
  161. + dp_priv->phy_mii_type);
  162. + if (!(dp_priv->phydev)) {
  163. + netdev_err(netdev, "failed to connect to phy device\n");
  164. + goto phy_setup_fail;
  165. + }
  166. + phy_attached_info(dp_priv->phydev);
  167. }
  168. #if defined(NSS_DP_PPE_SUPPORT)