ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 701-net-0378-mii-Add-helpers-for-parsing-SGMII-auto-negotiation.patch
1 From 4f3ba90c37ec5aedd2227beb013bab59035fbb57 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Mon, 30 Sep 2019 19:20:26 +0300
4 Subject: [PATCH] mii: Add helpers for parsing SGMII auto-negotiation
5
6 Typically a MAC PCS auto-configures itself after it receives the
7 negotiated copper-side link settings from the PHY, but some MAC devices
8 are more special and need manual interpretation of the SGMII AN result.
9
10 In other cases, the PCS exposes the entire tx_config_reg base page as it
11 is transmitted on the wire during auto-negotiation, so it makes sense to
12 be able to decode the equivalent lp_advertised bit mask from the raw u16
13 (of course, "lp" considering the PCS to be the local PHY).
14
15 Therefore, add the bit definitions for the SGMII registers 4 and 5
16 (local device ability, link partner ability), as well as a link_mode
17 conversion helper that can be used to feed the AN results into
18 phy_resolve_aneg_linkmode.
19
20 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
21 ---
22  include/linux/mii.h      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
23  include/uapi/linux/mii.h | 12 ++++++++++++
24  2 files changed, 62 insertions(+)
25
26 --- a/include/linux/mii.h
27 +++ b/include/linux/mii.h
28 @@ -373,6 +373,56 @@ static inline u32 mii_lpa_to_ethtool_lpa
29  }
30  
31  /**
32 + * mii_lpa_mod_linkmode_adv_sgmii
33 + * @lp_advertising: pointer to destination link mode.
34 + * @lpa: value of the MII_LPA register
35 + *
36 + * A small helper function that translates MII_LPA bits to
37 + * linkmode advertisement settings for SGMII.
38 + * Leaves other bits unchanged.
39 + */
40 +static inline void
41 +mii_lpa_mod_linkmode_lpa_sgmii(unsigned long *lp_advertising, u32 lpa)
42 +{
43 +       u32 speed_duplex = lpa & LPA_SGMII_DPX_SPD_MASK;
44 +
45 +       linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, lp_advertising,
46 +                        speed_duplex == LPA_SGMII_1000HALF);
47 +
48 +       linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, lp_advertising,
49 +                        speed_duplex == LPA_SGMII_1000FULL);
50 +
51 +       linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, lp_advertising,
52 +                        speed_duplex == LPA_SGMII_100HALF);
53 +
54 +       linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, lp_advertising,
55 +                        speed_duplex == LPA_SGMII_100FULL);
56 +
57 +       linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, lp_advertising,
58 +                        speed_duplex == LPA_SGMII_10HALF);
59 +
60 +       linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, lp_advertising,
61 +                        speed_duplex == LPA_SGMII_10FULL);
62 +}
63 +
64 +/**
65 + * mii_lpa_to_linkmode_adv_sgmii
66 + * @advertising: pointer to destination link mode.
67 + * @lpa: value of the MII_LPA register
68 + *
69 + * A small helper function that translates MII_ADVERTISE bits
70 + * to linkmode advertisement settings when in SGMII mode.
71 + * Clears the old value of advertising.
72 + */
73 +static inline void mii_lpa_to_linkmode_lpa_sgmii(unsigned long *lp_advertising,
74 +                                                u32 lpa)
75 +{
76 +       linkmode_zero(lp_advertising);
77 +
78 +       mii_lpa_mod_linkmode_lpa_sgmii(lp_advertising, lpa);
79 +}
80 +
81 +/**
82   * mii_adv_mod_linkmode_adv_t
83   * @advertising:pointer to destination link mode.
84   * @adv: value of the MII_ADVERTISE register
85 --- a/include/uapi/linux/mii.h
86 +++ b/include/uapi/linux/mii.h
87 @@ -131,6 +131,18 @@
88  #define NWAYTEST_LOOPBACK      0x0100  /* Enable loopback for N-way   */
89  #define NWAYTEST_RESV2         0xfe00  /* Unused...                   */
90  
91 +/* MAC and PHY tx_config_Reg[15:0] for SGMII in-band auto-negotiation.*/
92 +#define ADVERTISE_SGMII                0x0001  /* MAC can do SGMII            */
93 +#define LPA_SGMII              0x0001  /* PHY can do SGMII            */
94 +#define LPA_SGMII_DPX_SPD_MASK 0x1C00  /* SGMII duplex and speed bits */
95 +#define LPA_SGMII_10HALF       0x0000  /* Can do 10mbps half-duplex   */
96 +#define LPA_SGMII_10FULL       0x1000  /* Can do 10mbps full-duplex   */
97 +#define LPA_SGMII_100HALF      0x0400  /* Can do 100mbps half-duplex  */
98 +#define LPA_SGMII_100FULL      0x1400  /* Can do 100mbps full-duplex  */
99 +#define LPA_SGMII_1000HALF     0x0800  /* Can do 1000mbps half-duplex */
100 +#define LPA_SGMII_1000FULL     0x1800  /* Can do 1000mbps full-duplex */
101 +#define LPA_SGMII_LINK         0x8000  /* PHY link with copper-side partner */
102 +
103  /* 1000BASE-T Control register */
104  #define ADVERTISE_1000FULL     0x0200  /* Advertise 1000BASE-T full duplex */
105  #define ADVERTISE_1000HALF     0x0100  /* Advertise 1000BASE-T half duplex */