kernel: backport the dev_set_threaded export to 5.10
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 734-v5.16-0001-net-bgmac-improve-handling-PHY.patch
1 From b5375509184dc23d2b7fa0c5ed8763899ccc9674 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Sat, 2 Oct 2021 19:58:11 +0200
4 Subject: [PATCH] net: bgmac: improve handling PHY
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 1. Use info from DT if available
10
11 It allows describing for example a fixed link. It's more accurate than
12 just guessing there may be one (depending on a chipset).
13
14 2. Verify PHY ID before trying to connect PHY
15
16 PHY addr 0x1e (30) is special in Broadcom routers and means a switch
17 connected as MDIO devices instead of a real PHY. Don't try connecting to
18 it.
19
20 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
22 ---
23 drivers/net/ethernet/broadcom/bgmac-bcma.c | 33 ++++++++++++++--------
24 1 file changed, 21 insertions(+), 12 deletions(-)
25
26 --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
27 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
28 @@ -11,6 +11,7 @@
29 #include <linux/bcma/bcma.h>
30 #include <linux/brcmphy.h>
31 #include <linux/etherdevice.h>
32 +#include <linux/of_mdio.h>
33 #include <linux/of_net.h>
34 #include "bgmac.h"
35
36 @@ -86,17 +87,28 @@ static int bcma_phy_connect(struct bgmac
37 struct phy_device *phy_dev;
38 char bus_id[MII_BUS_ID_SIZE + 3];
39
40 + /* DT info should be the most accurate */
41 + phy_dev = of_phy_get_and_connect(bgmac->net_dev, bgmac->dev->of_node,
42 + bgmac_adjust_link);
43 + if (phy_dev)
44 + return 0;
45 +
46 /* Connect to the PHY */
47 - snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
48 - bgmac->phyaddr);
49 - phy_dev = phy_connect(bgmac->net_dev, bus_id, bgmac_adjust_link,
50 - PHY_INTERFACE_MODE_MII);
51 - if (IS_ERR(phy_dev)) {
52 - dev_err(bgmac->dev, "PHY connection failed\n");
53 - return PTR_ERR(phy_dev);
54 + if (bgmac->mii_bus && bgmac->phyaddr != BGMAC_PHY_NOREGS) {
55 + snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
56 + bgmac->phyaddr);
57 + phy_dev = phy_connect(bgmac->net_dev, bus_id, bgmac_adjust_link,
58 + PHY_INTERFACE_MODE_MII);
59 + if (IS_ERR(phy_dev)) {
60 + dev_err(bgmac->dev, "PHY connection failed\n");
61 + return PTR_ERR(phy_dev);
62 + }
63 +
64 + return 0;
65 }
66
67 - return 0;
68 + /* Assume a fixed link to the switch port */
69 + return bgmac_phy_connect_direct(bgmac);
70 }
71
72 static const struct bcma_device_id bgmac_bcma_tbl[] = {
73 @@ -297,10 +309,7 @@ static int bgmac_probe(struct bcma_devic
74 bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset;
75 bgmac->get_bus_clock = bcma_bgmac_get_bus_clock;
76 bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32;
77 - if (bgmac->mii_bus)
78 - bgmac->phy_connect = bcma_phy_connect;
79 - else
80 - bgmac->phy_connect = bgmac_phy_connect_direct;
81 + bgmac->phy_connect = bcma_phy_connect;
82
83 err = bgmac_enet_probe(bgmac);
84 if (err)