kernel: refresh patches
[openwrt/openwrt.git] / target / linux / generic / pending-5.15 / 773-net-sfp-add-support-for-HALNy-GPON-SFP.patch
1 From 43ac680124bc57951a6d0356b41498c2324388bf Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Fri, 26 Aug 2022 08:43:45 +0100
4 Subject: [PATCH 4/6] net: sfp: add support for HALNy GPON SFP
5
6 Add a quirk for the HALNy HL-GSFP module, which appears to have an
7 inverted RX_LOS signal, and possibly uses TX_FAULT as an inverted
8 host-link status signal. As we can't be certain about the modules
9 use of TX_FAULT, we ignore it.
10
11 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
12 ---
13 drivers/net/phy/sfp-bus.c | 2 +-
14 drivers/net/phy/sfp.c | 29 ++++++++++++++++++++++++++---
15 2 files changed, 27 insertions(+), 4 deletions(-)
16
17 --- a/drivers/net/phy/sfp-bus.c
18 +++ b/drivers/net/phy/sfp-bus.c
19 @@ -283,7 +283,7 @@ void sfp_parse_support(struct sfp_bus *b
20 phylink_set(modes, 2500baseX_Full);
21 }
22
23 - if (bus->sfp_quirk)
24 + if (bus->sfp_quirk && bus->sfp_quirk->modes)
25 bus->sfp_quirk->modes(id, modes);
26
27 linkmode_or(support, support, modes);
28 --- a/drivers/net/phy/sfp.c
29 +++ b/drivers/net/phy/sfp.c
30 @@ -320,6 +320,23 @@ static void sfp_fixup_ignore_tx_fault(st
31 sfp->tx_fault_ignore = true;
32 }
33
34 +static void sfp_fixup_inverted_los(struct sfp *sfp)
35 +{
36 + const __be16 los_inverted = cpu_to_be16(SFP_OPTIONS_LOS_INVERTED);
37 + const __be16 los_normal = cpu_to_be16(SFP_OPTIONS_LOS_NORMAL);
38 +
39 + sfp->id.ext.options &= ~los_normal;
40 + sfp->id.ext.options |= los_inverted;
41 +}
42 +
43 +static void sfp_fixup_halny_gsfp(struct sfp *sfp)
44 +{
45 + /* LOS is inverted */
46 + sfp_fixup_inverted_los(sfp);
47 + /* TX fault might be inverted, but we don't know for certain. */
48 + sfp_fixup_ignore_tx_fault(sfp);
49 +}
50 +
51 static void sfp_quirk_2500basex(const struct sfp_eeprom_id *id,
52 unsigned long *modes)
53 {
54 @@ -352,6 +369,10 @@ static const struct sfp_quirk sfp_quirks
55 .modes = sfp_quirk_2500basex,
56 .fixup = sfp_fixup_long_startup,
57 }, {
58 + .vendor = "HALNy",
59 + .part = "HL-GSFP",
60 + .fixup = sfp_fixup_halny_gsfp,
61 + }, {
62 // Huawei MA5671A can operate at 2500base-X, but report 1.2GBd
63 // NRZ in their EEPROM
64 .vendor = "HUAWEI",
65 @@ -368,16 +389,18 @@ static const struct sfp_quirk sfp_quirks
66 .vendor = "UBNT",
67 .part = "UF-INSTANT",
68 .modes = sfp_quirk_ubnt_uf_instant,
69 - },
70 + }
71 };
72
73 static size_t sfp_strlen(const char *str, size_t maxlen)
74 {
75 size_t size, i;
76
77 - /* Trailing characters should be filled with space chars */
78 + /* Trailing characters should be filled with space chars, but
79 + * some manufacturers can't read SFF-8472 and use NUL.
80 + */
81 for (i = 0, size = 0; i < maxlen; i++)
82 - if (str[i] != ' ')
83 + if (str[i] != ' ' && str[i] != '\0')
84 size = i + 1;
85
86 return size;