layerscape: add patches-5.4
[openwrt/staging/mkresin.git] / target / linux / layerscape / patches-5.4 / 701-net-0064-memac_init_phy-RGMII-fixed-link-pass-adjust_link-cal.patch
1 From 79eacb8b197f7459a75c7d3ec33ceef88475d5a1 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Fri, 4 May 2018 19:23:59 +0300
4 Subject: [PATCH] memac_init_phy: RGMII fixed-link: pass adjust_link callback
5 to of_phy_connect
6
7 * The mEMAC configuration for RGMII is held in the IF_MODE register
8 * In the driver, IF_MODE is configured in 2 places (both in fman_memac.c):
9 - fman_memac_init: sets the IF_MODE bit macro IF_MODE_RGMII_AUTO
10 (this translates to setting ENA = 1 - Enable automatic speed selection
11 - RGMII PHY in-band status information is used to select the speed
12 of operation).
13 - fman_memac_adjust_link: brings the RGMII port in ENA = 0 mode
14 (link speed not determined autonomously by the MAC, but set according
15 to SSP).
16 * The issue with the current code is that in the case of RGMII fixed-link,
17 the of_phy_attach function is being called, instead of of_phy_connect
18 with a callback that calls fman_memac_adjust_link.
19 * For this reason, the RGMII port is left in a state with ENA = 1. In
20 most (if not all) RGMII fixed-link setups, the link partner will not
21 send any in-bank link speed information that is expected by the mEMAC.
22 * The effect is that the link speed setting will probably not be correct
23 (and will definitely not be according to the "fixed-link" property in
24 the DTS).
25 * The adjust_link callback seems to be called by the PHY state machine,
26 even for fixed links, exactly once: on "link up". Therefore, this
27 patch ensures that on link up, RGMII fixed links are configured to the
28 link speed that is set in the DTS, and not left with IF_MODE[ENA] = 1.
29
30 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
31 ---
32 drivers/net/ethernet/freescale/sdk_dpaa/mac-api.c | 38 ++++++++++++++++++-----
33 1 file changed, 31 insertions(+), 7 deletions(-)
34
35 --- a/drivers/net/ethernet/freescale/sdk_dpaa/mac-api.c
36 +++ b/drivers/net/ethernet/freescale/sdk_dpaa/mac-api.c
37 @@ -502,17 +502,41 @@ static int memac_init_phy(struct net_dev
38 struct mac_device *mac_dev)
39 {
40 struct phy_device *phy_dev;
41 + void (*adjust_link_handler)(struct net_device *);
42
43 if ((macdev2enetinterface(mac_dev) == e_ENET_MODE_XGMII_10000) ||
44 - (macdev2enetinterface(mac_dev) == e_ENET_MODE_SGMII_2500) ||
45 - of_phy_is_fixed_link(mac_dev->phy_node)) {
46 - phy_dev = of_phy_connect(net_dev, mac_dev->phy_node,
47 - &adjust_link_void, 0,
48 - mac_dev->phy_if);
49 + (macdev2enetinterface(mac_dev) == e_ENET_MODE_SGMII_2500)) {
50 + /* Pass a void link state handler to the PHY state machine
51 + * for XGMII (10G) and SGMII 2.5G, as the hardware does not
52 + * permit dynamic link speed adjustments. */
53 + adjust_link_handler = adjust_link_void;
54 + } else if (macdev2enetinterface(mac_dev) & e_ENET_IF_RGMII) {
55 + /* Regular RGMII ports connected to a PHY, as well as
56 + * ports that are marked as "fixed-link" in the DTS,
57 + * will have the adjust_link callback. This calls
58 + * fman_memac_adjust_link in order to configure the
59 + * IF_MODE register, which is needed in both cases.
60 + */
61 + adjust_link_handler = adjust_link;
62 + } else if (of_phy_is_fixed_link(mac_dev->phy_node)) {
63 + /* Pass a void link state handler for fixed-link
64 + * interfaces that are not RGMII. Only RGMII has been
65 + * tested and confirmed to work with fixed-link. Other
66 + * MII interfaces may need further work.
67 + * TODO: Change this as needed.
68 + */
69 + adjust_link_handler = adjust_link_void;
70 } else {
71 - phy_dev = of_phy_connect(net_dev, mac_dev->phy_node,
72 - &adjust_link, 0, mac_dev->phy_if);
73 + /* MII, RMII, SMII, GMII, SGMII, BASEX ports,
74 + * that are NOT fixed-link.
75 + * TODO: May not be needed for interfaces that
76 + * pass through the SerDes block (*SGMII, XFI).
77 + */
78 + adjust_link_handler = adjust_link;
79 }
80 + phy_dev = of_phy_connect(net_dev, mac_dev->phy_node,
81 + adjust_link_handler, 0,
82 + mac_dev->phy_if);
83
84 if (unlikely(phy_dev == NULL) || IS_ERR(phy_dev)) {
85 netdev_err(net_dev, "Could not connect to PHY %s\n",