1 From 0100d1c5789018ba77bf2f4fab3bd91ecece7b3b Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Wed, 17 May 2023 11:38:12 +0100
4 Subject: [PATCH 14/21] net: sfp: add support for setting signalling rate
6 Add support to the SFP layer to allow phylink to set the signalling
7 rate for a SFP module. The rate given will be in units of kilo-baud
10 Reviewed-by: Simon Horman <simon.horman@corigine.com>
11 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
12 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
14 drivers/net/phy/phylink.c | 24 ++++++++++++++++++++++++
15 drivers/net/phy/sfp-bus.c | 20 ++++++++++++++++++++
16 drivers/net/phy/sfp.c | 5 +++++
17 drivers/net/phy/sfp.h | 1 +
18 include/linux/sfp.h | 6 ++++++
19 5 files changed, 56 insertions(+)
21 --- a/drivers/net/phy/phylink.c
22 +++ b/drivers/net/phy/phylink.c
23 @@ -156,6 +156,23 @@ static const char *phylink_an_mode_str(u
24 return mode < ARRAY_SIZE(modestr) ? modestr[mode] : "unknown";
27 +static unsigned int phylink_interface_signal_rate(phy_interface_t interface)
29 + switch (interface) {
30 + case PHY_INTERFACE_MODE_SGMII:
31 + case PHY_INTERFACE_MODE_1000BASEX: /* 1.25Mbd */
33 + case PHY_INTERFACE_MODE_2500BASEX: /* 3.125Mbd */
35 + case PHY_INTERFACE_MODE_5GBASER: /* 5.15625Mbd */
37 + case PHY_INTERFACE_MODE_10GBASER: /* 10.3125Mbd */
45 * phylink_interface_max_speed() - get the maximum speed of a phy interface
46 * @interface: phy interface mode defined by &typedef phy_interface_t
47 @@ -1024,6 +1041,7 @@ static void phylink_major_config(struct
49 struct phylink_pcs *pcs = NULL;
50 bool pcs_changed = false;
51 + unsigned int rate_kbd;
54 phylink_dbg(pl, "major config %s\n", phy_modes(state->interface));
55 @@ -1083,6 +1101,12 @@ static void phylink_major_config(struct
60 + rate_kbd = phylink_interface_signal_rate(state->interface);
62 + sfp_upstream_set_signal_rate(pl->sfp_bus, rate_kbd);
65 phylink_pcs_poll_start(pl);
68 --- a/drivers/net/phy/sfp-bus.c
69 +++ b/drivers/net/phy/sfp-bus.c
70 @@ -586,6 +586,26 @@ static void sfp_upstream_clear(struct sf
74 + * sfp_upstream_set_signal_rate() - set data signalling rate
75 + * @bus: a pointer to the &struct sfp_bus structure for the sfp module
76 + * @rate_kbd: signalling rate in units of 1000 baud
78 + * Configure the rate select settings on the SFP module for the signalling
79 + * rate (not the same as the data rate).
81 + * Locks that may be held:
82 + * Phylink's state_mutex
86 +void sfp_upstream_set_signal_rate(struct sfp_bus *bus, unsigned int rate_kbd)
88 + if (bus->registered)
89 + bus->socket_ops->set_signal_rate(bus->sfp, rate_kbd);
91 +EXPORT_SYMBOL_GPL(sfp_upstream_set_signal_rate);
94 * sfp_bus_find_fwnode() - parse and locate the SFP bus from fwnode
95 * @fwnode: firmware node for the parent device (MAC or PHY)
97 --- a/drivers/net/phy/sfp.c
98 +++ b/drivers/net/phy/sfp.c
99 @@ -2474,6 +2474,10 @@ static void sfp_stop(struct sfp *sfp)
100 sfp_sm_event(sfp, SFP_E_DEV_DOWN);
103 +static void sfp_set_signal_rate(struct sfp *sfp, unsigned int rate_kbd)
107 static int sfp_module_info(struct sfp *sfp, struct ethtool_modinfo *modinfo)
109 /* locking... and check module is present */
110 @@ -2552,6 +2556,7 @@ static const struct sfp_socket_ops sfp_m
111 .detach = sfp_detach,
114 + .set_signal_rate = sfp_set_signal_rate,
115 .module_info = sfp_module_info,
116 .module_eeprom = sfp_module_eeprom,
117 .module_eeprom_by_page = sfp_module_eeprom_by_page,
118 --- a/drivers/net/phy/sfp.h
119 +++ b/drivers/net/phy/sfp.h
120 @@ -19,6 +19,7 @@ struct sfp_socket_ops {
121 void (*detach)(struct sfp *sfp);
122 void (*start)(struct sfp *sfp);
123 void (*stop)(struct sfp *sfp);
124 + void (*set_signal_rate)(struct sfp *sfp, unsigned int rate_kbd);
125 int (*module_info)(struct sfp *sfp, struct ethtool_modinfo *modinfo);
126 int (*module_eeprom)(struct sfp *sfp, struct ethtool_eeprom *ee,
128 --- a/include/linux/sfp.h
129 +++ b/include/linux/sfp.h
130 @@ -547,6 +547,7 @@ int sfp_get_module_eeprom_by_page(struct
131 struct netlink_ext_ack *extack);
132 void sfp_upstream_start(struct sfp_bus *bus);
133 void sfp_upstream_stop(struct sfp_bus *bus);
134 +void sfp_upstream_set_signal_rate(struct sfp_bus *bus, unsigned int rate_kbd);
135 void sfp_bus_put(struct sfp_bus *bus);
136 struct sfp_bus *sfp_bus_find_fwnode(const struct fwnode_handle *fwnode);
137 int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
138 @@ -606,6 +607,11 @@ static inline void sfp_upstream_stop(str
142 +static inline void sfp_upstream_set_signal_rate(struct sfp_bus *bus,
143 + unsigned int rate_kbd)
147 static inline void sfp_bus_put(struct sfp_bus *bus)