2020-02-23 12:20:11 +00:00
|
|
|
From 8df5dd55cef48c0769379e04dbc085a899b106d4 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Russell King <rmk+kernel@armlinux.org.uk>
|
|
|
|
Date: Fri, 8 Mar 2019 14:02:25 +0000
|
|
|
|
Subject: [PATCH 640/660] net: sfp: add support for module quirks
|
|
|
|
|
|
|
|
Add support for applying module quirks to the list of supported
|
|
|
|
ethtool link modes.
|
|
|
|
|
|
|
|
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
|
|
|
|
---
|
|
|
|
drivers/net/phy/sfp-bus.c | 54 +++++++++++++++++++++++++++++++++++++++
|
|
|
|
1 file changed, 54 insertions(+)
|
|
|
|
|
|
|
|
--- a/drivers/net/phy/sfp-bus.c
|
|
|
|
+++ b/drivers/net/phy/sfp-bus.c
|
2019-11-25 15:08:31 +00:00
|
|
|
@@ -10,6 +10,12 @@
|
2020-02-23 12:20:11 +00:00
|
|
|
|
|
|
|
#include "sfp.h"
|
|
|
|
|
|
|
|
+struct sfp_quirk {
|
|
|
|
+ const char *vendor;
|
|
|
|
+ const char *part;
|
|
|
|
+ void (*modes)(const struct sfp_eeprom_id *id, unsigned long *modes);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* struct sfp_bus - internal representation of a sfp bus
|
|
|
|
*/
|
2019-11-25 15:08:31 +00:00
|
|
|
@@ -22,6 +28,7 @@ struct sfp_bus {
|
2020-02-23 12:20:11 +00:00
|
|
|
const struct sfp_socket_ops *socket_ops;
|
|
|
|
struct device *sfp_dev;
|
|
|
|
struct sfp *sfp;
|
|
|
|
+ const struct sfp_quirk *sfp_quirk;
|
|
|
|
|
|
|
|
const struct sfp_upstream_ops *upstream_ops;
|
|
|
|
void *upstream;
|
2019-11-25 15:08:31 +00:00
|
|
|
@@ -31,6 +38,46 @@ struct sfp_bus {
|
2020-02-23 12:20:11 +00:00
|
|
|
bool started;
|
|
|
|
};
|
|
|
|
|
|
|
|
+static const struct sfp_quirk sfp_quirks[] = {
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static size_t sfp_strlen(const char *str, size_t maxlen)
|
|
|
|
+{
|
|
|
|
+ size_t size, i;
|
|
|
|
+
|
|
|
|
+ /* Trailing characters should be filled with space chars */
|
|
|
|
+ for (i = 0, size = 0; i < maxlen; i++)
|
|
|
|
+ if (str[i] != ' ')
|
|
|
|
+ size = i + 1;
|
|
|
|
+
|
|
|
|
+ return size;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static bool sfp_match(const char *qs, const char *str, size_t len)
|
|
|
|
+{
|
|
|
|
+ if (!qs)
|
|
|
|
+ return true;
|
|
|
|
+ if (strlen(qs) != len)
|
|
|
|
+ return false;
|
|
|
|
+ return !strncmp(qs, str, len);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id)
|
|
|
|
+{
|
|
|
|
+ const struct sfp_quirk *q;
|
|
|
|
+ unsigned int i;
|
|
|
|
+ size_t vs, ps;
|
|
|
|
+
|
|
|
|
+ vs = sfp_strlen(id->base.vendor_name, ARRAY_SIZE(id->base.vendor_name));
|
|
|
|
+ ps = sfp_strlen(id->base.vendor_pn, ARRAY_SIZE(id->base.vendor_pn));
|
|
|
|
+
|
|
|
|
+ for (i = 0, q = sfp_quirks; i < ARRAY_SIZE(sfp_quirks); i++, q++)
|
|
|
|
+ if (sfp_match(q->vendor, id->base.vendor_name, vs) &&
|
|
|
|
+ sfp_match(q->part, id->base.vendor_pn, ps))
|
|
|
|
+ return q;
|
|
|
|
+
|
|
|
|
+ return NULL;
|
|
|
|
+}
|
|
|
|
/**
|
|
|
|
* sfp_parse_port() - Parse the EEPROM base ID, setting the port type
|
|
|
|
* @bus: a pointer to the &struct sfp_bus structure for the sfp module
|
2019-11-25 15:08:31 +00:00
|
|
|
@@ -234,6 +281,9 @@ void sfp_parse_support(struct sfp_bus *b
|
2020-02-23 12:20:11 +00:00
|
|
|
phylink_set(modes, 1000baseX_Full);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if (bus->sfp_quirk)
|
|
|
|
+ bus->sfp_quirk->modes(id, modes);
|
|
|
|
+
|
|
|
|
bitmap_or(support, support, modes, __ETHTOOL_LINK_MODE_MASK_NBITS);
|
|
|
|
|
|
|
|
phylink_set(support, Autoneg);
|
2019-11-25 15:08:31 +00:00
|
|
|
@@ -610,6 +660,8 @@ int sfp_module_insert(struct sfp_bus *bu
|
2020-02-23 12:20:11 +00:00
|
|
|
const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
+ bus->sfp_quirk = sfp_lookup_quirk(id);
|
|
|
|
+
|
|
|
|
if (ops && ops->module_insert)
|
|
|
|
ret = ops->module_insert(bus->upstream, id);
|
|
|
|
|
2019-11-25 15:08:31 +00:00
|
|
|
@@ -623,6 +675,8 @@ void sfp_module_remove(struct sfp_bus *b
|
2020-02-23 12:20:11 +00:00
|
|
|
|
|
|
|
if (ops && ops->module_remove)
|
|
|
|
ops->module_remove(bus->upstream);
|
|
|
|
+
|
|
|
|
+ bus->sfp_quirk = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(sfp_module_remove);
|
|
|
|
|