1 From 8df5dd55cef48c0769379e04dbc085a899b106d4 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Fri, 8 Mar 2019 14:02:25 +0000
4 Subject: [PATCH 640/660] net: sfp: add support for module quirks
6 Add support for applying module quirks to the list of supported
9 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
11 drivers/net/phy/sfp-bus.c | 54 +++++++++++++++++++++++++++++++++++++++
12 1 file changed, 54 insertions(+)
14 --- a/drivers/net/phy/sfp-bus.c
15 +++ b/drivers/net/phy/sfp-bus.c
23 + void (*modes)(const struct sfp_eeprom_id *id, unsigned long *modes);
27 * struct sfp_bus - internal representation of a sfp bus
29 @@ -21,6 +27,7 @@ struct sfp_bus {
30 const struct sfp_socket_ops *socket_ops;
31 struct device *sfp_dev;
33 + const struct sfp_quirk *sfp_quirk;
35 const struct sfp_upstream_ops *upstream_ops;
37 @@ -30,6 +37,46 @@ struct sfp_bus {
41 +static const struct sfp_quirk sfp_quirks[] = {
44 +static size_t sfp_strlen(const char *str, size_t maxlen)
48 + /* Trailing characters should be filled with space chars */
49 + for (i = 0, size = 0; i < maxlen; i++)
56 +static bool sfp_match(const char *qs, const char *str, size_t len)
60 + if (strlen(qs) != len)
62 + return !strncmp(qs, str, len);
65 +static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id)
67 + const struct sfp_quirk *q;
71 + vs = sfp_strlen(id->base.vendor_name, ARRAY_SIZE(id->base.vendor_name));
72 + ps = sfp_strlen(id->base.vendor_pn, ARRAY_SIZE(id->base.vendor_pn));
74 + for (i = 0, q = sfp_quirks; i < ARRAY_SIZE(sfp_quirks); i++, q++)
75 + if (sfp_match(q->vendor, id->base.vendor_name, vs) &&
76 + sfp_match(q->part, id->base.vendor_pn, ps))
82 * sfp_parse_port() - Parse the EEPROM base ID, setting the port type
83 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
84 @@ -233,6 +280,9 @@ void sfp_parse_support(struct sfp_bus *b
85 phylink_set(modes, 1000baseX_Full);
89 + bus->sfp_quirk->modes(id, modes);
91 bitmap_or(support, support, modes, __ETHTOOL_LINK_MODE_MASK_NBITS);
93 phylink_set(support, Autoneg);
94 @@ -609,6 +659,8 @@ int sfp_module_insert(struct sfp_bus *bu
95 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
98 + bus->sfp_quirk = sfp_lookup_quirk(id);
100 if (ops && ops->module_insert)
101 ret = ops->module_insert(bus->upstream, id);
103 @@ -622,6 +674,8 @@ void sfp_module_remove(struct sfp_bus *b
105 if (ops && ops->module_remove)
106 ops->module_remove(bus->upstream);
108 + bus->sfp_quirk = NULL;
110 EXPORT_SYMBOL_GPL(sfp_module_remove);