1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/export.h>
3 #include <linux/kref.h>
4 #include <linux/list.h>
5 #include <linux/mutex.h>
6 #include <linux/phylink.h>
7 #include <linux/property.h>
8 #include <linux/rtnetlink.h>
9 #include <linux/slab.h>
16 void (*modes)(const struct sfp_eeprom_id *id, unsigned long *modes);
20 * struct sfp_bus - internal representation of a sfp bus
25 struct list_head node;
26 struct fwnode_handle *fwnode;
28 const struct sfp_socket_ops *socket_ops;
29 struct device *sfp_dev;
31 const struct sfp_quirk *sfp_quirk;
33 const struct sfp_upstream_ops *upstream_ops;
35 struct phy_device *phydev;
41 static void sfp_quirk_2500basex(const struct sfp_eeprom_id *id,
44 phylink_set(modes, 2500baseX_Full);
47 static void sfp_quirk_ubnt_uf_instant(const struct sfp_eeprom_id *id,
50 /* Ubiquiti U-Fiber Instant module claims that support all transceiver
51 * types including 10G Ethernet which is not truth. So clear all claimed
52 * modes and set only one mode which module supports: 1000baseX_Full.
55 phylink_set(modes, 1000baseX_Full);
58 static const struct sfp_quirk sfp_quirks[] = {
60 // Alcatel Lucent G-010S-P can operate at 2500base-X, but
61 // incorrectly report 2500MBd NRZ in their EEPROM
62 .vendor = "ALCATELLUCENT",
64 .modes = sfp_quirk_2500basex,
66 // Alcatel Lucent G-010S-A can operate at 2500base-X, but
67 // report 3.2GBd NRZ in their EEPROM
68 .vendor = "ALCATELLUCENT",
70 .modes = sfp_quirk_2500basex,
72 // Huawei MA5671A can operate at 2500base-X, but report 1.2GBd
73 // NRZ in their EEPROM
76 .modes = sfp_quirk_2500basex,
78 // Lantech 8330-262D-E can operate at 2500base-X, but
79 // incorrectly report 2500MBd NRZ in their EEPROM
81 .part = "8330-262D-E",
82 .modes = sfp_quirk_2500basex,
86 .modes = sfp_quirk_ubnt_uf_instant,
90 static size_t sfp_strlen(const char *str, size_t maxlen)
94 /* Trailing characters should be filled with space chars */
95 for (i = 0, size = 0; i < maxlen; i++)
102 static bool sfp_match(const char *qs, const char *str, size_t len)
106 if (strlen(qs) != len)
108 return !strncmp(qs, str, len);
111 static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id)
113 const struct sfp_quirk *q;
117 vs = sfp_strlen(id->base.vendor_name, ARRAY_SIZE(id->base.vendor_name));
118 ps = sfp_strlen(id->base.vendor_pn, ARRAY_SIZE(id->base.vendor_pn));
120 for (i = 0, q = sfp_quirks; i < ARRAY_SIZE(sfp_quirks); i++, q++)
121 if (sfp_match(q->vendor, id->base.vendor_name, vs) &&
122 sfp_match(q->part, id->base.vendor_pn, ps))
129 * sfp_parse_port() - Parse the EEPROM base ID, setting the port type
130 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
131 * @id: a pointer to the module's &struct sfp_eeprom_id
132 * @support: optional pointer to an array of unsigned long for the
133 * ethtool support mask
135 * Parse the EEPROM identification given in @id, and return one of
136 * %PORT_TP, %PORT_FIBRE or %PORT_OTHER. If @support is non-%NULL,
137 * also set the ethtool %ETHTOOL_LINK_MODE_xxx_BIT corresponding with
138 * the connector type.
140 * If the port type is not known, returns %PORT_OTHER.
142 int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
143 unsigned long *support)
147 /* port is the physical connector, set this from the connector field. */
148 switch (id->base.connector) {
149 case SFF8024_CONNECTOR_SC:
150 case SFF8024_CONNECTOR_FIBERJACK:
151 case SFF8024_CONNECTOR_LC:
152 case SFF8024_CONNECTOR_MT_RJ:
153 case SFF8024_CONNECTOR_MU:
154 case SFF8024_CONNECTOR_OPTICAL_PIGTAIL:
155 case SFF8024_CONNECTOR_MPO_1X12:
156 case SFF8024_CONNECTOR_MPO_2X16:
160 case SFF8024_CONNECTOR_RJ45:
164 case SFF8024_CONNECTOR_COPPER_PIGTAIL:
168 case SFF8024_CONNECTOR_UNSPEC:
169 if (id->base.e1000_base_t) {
174 case SFF8024_CONNECTOR_SG: /* guess */
175 case SFF8024_CONNECTOR_HSSDC_II:
176 case SFF8024_CONNECTOR_NOSEPARATE:
177 case SFF8024_CONNECTOR_MXC_2X16:
181 dev_warn(bus->sfp_dev, "SFP: unknown connector id 0x%02x\n",
190 phylink_set(support, FIBRE);
194 phylink_set(support, TP);
201 EXPORT_SYMBOL_GPL(sfp_parse_port);
204 * sfp_may_have_phy() - indicate whether the module may have a PHY
205 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
206 * @id: a pointer to the module's &struct sfp_eeprom_id
208 * Parse the EEPROM identification given in @id, and return whether
209 * this module may have a PHY.
211 bool sfp_may_have_phy(struct sfp_bus *bus, const struct sfp_eeprom_id *id)
213 if (id->base.e1000_base_t)
216 if (id->base.phys_id != SFF8024_ID_DWDM_SFP) {
217 switch (id->base.extended_cc) {
218 case SFF8024_ECC_10GBASE_T_SFI:
219 case SFF8024_ECC_10GBASE_T_SR:
220 case SFF8024_ECC_5GBASE_T:
221 case SFF8024_ECC_2_5GBASE_T:
228 EXPORT_SYMBOL_GPL(sfp_may_have_phy);
231 * sfp_parse_support() - Parse the eeprom id for supported link modes
232 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
233 * @id: a pointer to the module's &struct sfp_eeprom_id
234 * @support: pointer to an array of unsigned long for the ethtool support mask
236 * Parse the EEPROM identification information and derive the supported
237 * ethtool link modes for the module.
239 void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
240 unsigned long *support)
242 unsigned int br_min, br_nom, br_max;
243 __ETHTOOL_DECLARE_LINK_MODE_MASK(modes) = { 0, };
245 /* Decode the bitrate information to MBd */
246 br_min = br_nom = br_max = 0;
247 if (id->base.br_nominal) {
248 if (id->base.br_nominal != 255) {
249 br_nom = id->base.br_nominal * 100;
250 br_min = br_nom - id->base.br_nominal * id->ext.br_min;
251 br_max = br_nom + id->base.br_nominal * id->ext.br_max;
252 } else if (id->ext.br_max) {
253 br_nom = 250 * id->ext.br_max;
254 br_max = br_nom + br_nom * id->ext.br_min / 100;
255 br_min = br_nom - br_nom * id->ext.br_min / 100;
258 /* When using passive cables, in case neither BR,min nor BR,max
259 * are specified, set br_min to 0 as the nominal value is then
260 * used as the maximum.
262 if (br_min == br_max && id->base.sfp_ct_passive)
266 /* Set ethtool support from the compliance fields. */
267 if (id->base.e10g_base_sr)
268 phylink_set(modes, 10000baseSR_Full);
269 if (id->base.e10g_base_lr)
270 phylink_set(modes, 10000baseLR_Full);
271 if (id->base.e10g_base_lrm)
272 phylink_set(modes, 10000baseLRM_Full);
273 if (id->base.e10g_base_er)
274 phylink_set(modes, 10000baseER_Full);
275 if (id->base.e1000_base_sx ||
276 id->base.e1000_base_lx ||
277 id->base.e1000_base_cx)
278 phylink_set(modes, 1000baseX_Full);
279 if (id->base.e1000_base_t) {
280 phylink_set(modes, 1000baseT_Half);
281 phylink_set(modes, 1000baseT_Full);
284 /* 1000Base-PX or 1000Base-BX10 */
285 if ((id->base.e_base_px || id->base.e_base_bx10) &&
286 br_min <= 1300 && br_max >= 1200)
287 phylink_set(modes, 1000baseX_Full);
289 /* 100Base-FX, 100Base-LX, 100Base-PX, 100Base-BX10 */
290 if (id->base.e100_base_fx || id->base.e100_base_lx)
291 phylink_set(modes, 100baseFX_Full);
292 if ((id->base.e_base_px || id->base.e_base_bx10) && br_nom == 100)
293 phylink_set(modes, 100baseFX_Full);
295 /* For active or passive cables, select the link modes
296 * based on the bit rates and the cable compliance bytes.
298 if ((id->base.sfp_ct_passive || id->base.sfp_ct_active) && br_nom) {
299 /* This may look odd, but some manufacturers use 12000MBd */
300 if (br_min <= 12000 && br_max >= 10300)
301 phylink_set(modes, 10000baseCR_Full);
302 if (br_min <= 3200 && br_max >= 3100)
303 phylink_set(modes, 2500baseX_Full);
304 if (br_min <= 1300 && br_max >= 1200)
305 phylink_set(modes, 1000baseX_Full);
307 if (id->base.sfp_ct_passive) {
308 if (id->base.passive.sff8431_app_e)
309 phylink_set(modes, 10000baseCR_Full);
311 if (id->base.sfp_ct_active) {
312 if (id->base.active.sff8431_app_e ||
313 id->base.active.sff8431_lim) {
314 phylink_set(modes, 10000baseCR_Full);
318 switch (id->base.extended_cc) {
319 case SFF8024_ECC_UNSPEC:
321 case SFF8024_ECC_100GBASE_SR4_25GBASE_SR:
322 phylink_set(modes, 100000baseSR4_Full);
323 phylink_set(modes, 25000baseSR_Full);
325 case SFF8024_ECC_100GBASE_LR4_25GBASE_LR:
326 case SFF8024_ECC_100GBASE_ER4_25GBASE_ER:
327 phylink_set(modes, 100000baseLR4_ER4_Full);
329 case SFF8024_ECC_100GBASE_CR4:
330 phylink_set(modes, 100000baseCR4_Full);
332 case SFF8024_ECC_25GBASE_CR_S:
333 case SFF8024_ECC_25GBASE_CR_N:
334 phylink_set(modes, 25000baseCR_Full);
336 case SFF8024_ECC_10GBASE_T_SFI:
337 case SFF8024_ECC_10GBASE_T_SR:
338 phylink_set(modes, 10000baseT_Full);
340 case SFF8024_ECC_5GBASE_T:
341 phylink_set(modes, 5000baseT_Full);
343 case SFF8024_ECC_2_5GBASE_T:
344 phylink_set(modes, 2500baseT_Full);
347 dev_warn(bus->sfp_dev,
348 "Unknown/unsupported extended compliance code: 0x%02x\n",
349 id->base.extended_cc);
353 /* For fibre channel SFP, derive possible BaseX modes */
354 if (id->base.fc_speed_100 ||
355 id->base.fc_speed_200 ||
356 id->base.fc_speed_400) {
357 if (id->base.br_nominal >= 31)
358 phylink_set(modes, 2500baseX_Full);
359 if (id->base.br_nominal >= 12)
360 phylink_set(modes, 1000baseX_Full);
363 /* If we haven't discovered any modes that this module supports, try
364 * the bitrate to determine supported modes. Some BiDi modules (eg,
365 * 1310nm/1550nm) are not 1000BASE-BX compliant due to the differing
366 * wavelengths, so do not set any transceiver bits.
368 * Do the same for modules supporting 2500BASE-X. Note that some
369 * modules use 2500Mbaud rather than 3100 or 3200Mbaud for
370 * 2500BASE-X, so we allow some slack here.
372 if (bitmap_empty(modes, __ETHTOOL_LINK_MODE_MASK_NBITS) && br_nom) {
373 if (br_min <= 1300 && br_max >= 1200)
374 phylink_set(modes, 1000baseX_Full);
375 if (br_min <= 3200 && br_max >= 2500)
376 phylink_set(modes, 2500baseX_Full);
380 bus->sfp_quirk->modes(id, modes);
382 linkmode_or(support, support, modes);
384 phylink_set(support, Autoneg);
385 phylink_set(support, Pause);
386 phylink_set(support, Asym_Pause);
388 EXPORT_SYMBOL_GPL(sfp_parse_support);
391 * sfp_select_interface() - Select appropriate phy_interface_t mode
392 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
393 * @link_modes: ethtool link modes mask
395 * Derive the phy_interface_t mode for the SFP module from the link
398 phy_interface_t sfp_select_interface(struct sfp_bus *bus,
399 unsigned long *link_modes)
401 if (phylink_test(link_modes, 25000baseCR_Full) ||
402 phylink_test(link_modes, 25000baseKR_Full) ||
403 phylink_test(link_modes, 25000baseSR_Full))
404 return PHY_INTERFACE_MODE_25GBASER;
406 if (phylink_test(link_modes, 10000baseCR_Full) ||
407 phylink_test(link_modes, 10000baseSR_Full) ||
408 phylink_test(link_modes, 10000baseLR_Full) ||
409 phylink_test(link_modes, 10000baseLRM_Full) ||
410 phylink_test(link_modes, 10000baseER_Full) ||
411 phylink_test(link_modes, 10000baseT_Full))
412 return PHY_INTERFACE_MODE_10GBASER;
414 if (phylink_test(link_modes, 5000baseT_Full))
415 return PHY_INTERFACE_MODE_5GBASER;
417 if (phylink_test(link_modes, 2500baseX_Full))
418 return PHY_INTERFACE_MODE_2500BASEX;
420 if (phylink_test(link_modes, 1000baseT_Half) ||
421 phylink_test(link_modes, 1000baseT_Full))
422 return PHY_INTERFACE_MODE_SGMII;
424 if (phylink_test(link_modes, 1000baseX_Full))
425 return PHY_INTERFACE_MODE_1000BASEX;
427 if (phylink_test(link_modes, 100baseFX_Full))
428 return PHY_INTERFACE_MODE_100BASEX;
430 dev_warn(bus->sfp_dev, "Unable to ascertain link mode\n");
432 return PHY_INTERFACE_MODE_NA;
434 EXPORT_SYMBOL_GPL(sfp_select_interface);
436 static LIST_HEAD(sfp_buses);
437 static DEFINE_MUTEX(sfp_mutex);
439 static const struct sfp_upstream_ops *sfp_get_upstream_ops(struct sfp_bus *bus)
441 return bus->registered ? bus->upstream_ops : NULL;
444 static struct sfp_bus *sfp_bus_get(struct fwnode_handle *fwnode)
446 struct sfp_bus *sfp, *new, *found = NULL;
448 new = kzalloc(sizeof(*new), GFP_KERNEL);
450 mutex_lock(&sfp_mutex);
452 list_for_each_entry(sfp, &sfp_buses, node) {
453 if (sfp->fwnode == fwnode) {
454 kref_get(&sfp->kref);
461 kref_init(&new->kref);
462 new->fwnode = fwnode;
463 list_add(&new->node, &sfp_buses);
468 mutex_unlock(&sfp_mutex);
475 static void sfp_bus_release(struct kref *kref)
477 struct sfp_bus *bus = container_of(kref, struct sfp_bus, kref);
479 list_del(&bus->node);
480 mutex_unlock(&sfp_mutex);
485 * sfp_bus_put() - put a reference on the &struct sfp_bus
486 * @bus: the &struct sfp_bus found via sfp_bus_find_fwnode()
488 * Put a reference on the &struct sfp_bus and free the underlying structure
489 * if this was the last reference.
491 void sfp_bus_put(struct sfp_bus *bus)
494 kref_put_mutex(&bus->kref, sfp_bus_release, &sfp_mutex);
496 EXPORT_SYMBOL_GPL(sfp_bus_put);
498 static int sfp_register_bus(struct sfp_bus *bus)
500 const struct sfp_upstream_ops *ops = bus->upstream_ops;
505 ops->link_down(bus->upstream);
506 if (ops->connect_phy && bus->phydev) {
507 ret = ops->connect_phy(bus->upstream, bus->phydev);
512 bus->registered = true;
513 bus->socket_ops->attach(bus->sfp);
515 bus->socket_ops->start(bus->sfp);
516 bus->upstream_ops->attach(bus->upstream, bus);
520 static void sfp_unregister_bus(struct sfp_bus *bus)
522 const struct sfp_upstream_ops *ops = bus->upstream_ops;
524 if (bus->registered) {
525 bus->upstream_ops->detach(bus->upstream, bus);
527 bus->socket_ops->stop(bus->sfp);
528 bus->socket_ops->detach(bus->sfp);
529 if (bus->phydev && ops && ops->disconnect_phy)
530 ops->disconnect_phy(bus->upstream);
532 bus->registered = false;
536 * sfp_get_module_info() - Get the ethtool_modinfo for a SFP module
537 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
538 * @modinfo: a &struct ethtool_modinfo
540 * Fill in the type and eeprom_len parameters in @modinfo for a module on
541 * the sfp bus specified by @bus.
543 * Returns 0 on success or a negative errno number.
545 int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
547 return bus->socket_ops->module_info(bus->sfp, modinfo);
549 EXPORT_SYMBOL_GPL(sfp_get_module_info);
552 * sfp_get_module_eeprom() - Read the SFP module EEPROM
553 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
554 * @ee: a &struct ethtool_eeprom
555 * @data: buffer to contain the EEPROM data (must be at least @ee->len bytes)
557 * Read the EEPROM as specified by the supplied @ee. See the documentation
558 * for &struct ethtool_eeprom for the region to be read.
560 * Returns 0 on success or a negative errno number.
562 int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
565 return bus->socket_ops->module_eeprom(bus->sfp, ee, data);
567 EXPORT_SYMBOL_GPL(sfp_get_module_eeprom);
570 * sfp_get_module_eeprom_by_page() - Read a page from the SFP module EEPROM
571 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
572 * @page: a &struct ethtool_module_eeprom
573 * @extack: extack for reporting problems
575 * Read an EEPROM page as specified by the supplied @page. See the
576 * documentation for &struct ethtool_module_eeprom for the page to be read.
578 * Returns 0 on success or a negative errno number. More error
579 * information might be provided via extack
581 int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
582 const struct ethtool_module_eeprom *page,
583 struct netlink_ext_ack *extack)
585 return bus->socket_ops->module_eeprom_by_page(bus->sfp, page, extack);
587 EXPORT_SYMBOL_GPL(sfp_get_module_eeprom_by_page);
590 * sfp_upstream_start() - Inform the SFP that the network device is up
591 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
593 * Inform the SFP socket that the network device is now up, so that the
594 * module can be enabled by allowing TX_DISABLE to be deasserted. This
595 * should be called from the network device driver's &struct net_device_ops
598 void sfp_upstream_start(struct sfp_bus *bus)
601 bus->socket_ops->start(bus->sfp);
604 EXPORT_SYMBOL_GPL(sfp_upstream_start);
607 * sfp_upstream_stop() - Inform the SFP that the network device is down
608 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
610 * Inform the SFP socket that the network device is now up, so that the
611 * module can be disabled by asserting TX_DISABLE, disabling the laser
612 * in optical modules. This should be called from the network device
613 * driver's &struct net_device_ops ndo_stop() method.
615 void sfp_upstream_stop(struct sfp_bus *bus)
618 bus->socket_ops->stop(bus->sfp);
619 bus->started = false;
621 EXPORT_SYMBOL_GPL(sfp_upstream_stop);
623 static void sfp_upstream_clear(struct sfp_bus *bus)
625 bus->upstream_ops = NULL;
626 bus->upstream = NULL;
630 * sfp_bus_find_fwnode() - parse and locate the SFP bus from fwnode
631 * @fwnode: firmware node for the parent device (MAC or PHY)
633 * Parse the parent device's firmware node for a SFP bus, and locate
634 * the sfp_bus structure, incrementing its reference count. This must
635 * be put via sfp_bus_put() when done.
638 * - on success, a pointer to the sfp_bus structure,
639 * - %NULL if no SFP is specified,
640 * - on failure, an error pointer value:
642 * - corresponding to the errors detailed for
643 * fwnode_property_get_reference_args().
644 * - %-ENOMEM if we failed to allocate the bus.
645 * - an error from the upstream's connect_phy() method.
647 struct sfp_bus *sfp_bus_find_fwnode(struct fwnode_handle *fwnode)
649 struct fwnode_reference_args ref;
653 ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
660 if (!fwnode_device_is_available(ref.fwnode)) {
661 fwnode_handle_put(ref.fwnode);
665 bus = sfp_bus_get(ref.fwnode);
666 fwnode_handle_put(ref.fwnode);
668 return ERR_PTR(-ENOMEM);
672 EXPORT_SYMBOL_GPL(sfp_bus_find_fwnode);
675 * sfp_bus_add_upstream() - parse and register the neighbouring device
676 * @bus: the &struct sfp_bus found via sfp_bus_find_fwnode()
677 * @upstream: the upstream private data
678 * @ops: the upstream's &struct sfp_upstream_ops
680 * Add upstream driver for the SFP bus, and if the bus is complete, register
681 * the SFP bus using sfp_register_upstream(). This takes a reference on the
682 * bus, so it is safe to put the bus after this call.
685 * - on success, a pointer to the sfp_bus structure,
686 * - %NULL if no SFP is specified,
687 * - on failure, an error pointer value:
689 * - corresponding to the errors detailed for
690 * fwnode_property_get_reference_args().
691 * - %-ENOMEM if we failed to allocate the bus.
692 * - an error from the upstream's connect_phy() method.
694 int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
695 const struct sfp_upstream_ops *ops)
699 /* If no bus, return success */
704 kref_get(&bus->kref);
705 bus->upstream_ops = ops;
706 bus->upstream = upstream;
709 ret = sfp_register_bus(bus);
711 sfp_upstream_clear(bus);
722 EXPORT_SYMBOL_GPL(sfp_bus_add_upstream);
725 * sfp_bus_del_upstream() - Delete a sfp bus
726 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
728 * Delete a previously registered upstream connection for the SFP
729 * module. @bus should have been added by sfp_bus_add_upstream().
731 void sfp_bus_del_upstream(struct sfp_bus *bus)
736 sfp_unregister_bus(bus);
737 sfp_upstream_clear(bus);
743 EXPORT_SYMBOL_GPL(sfp_bus_del_upstream);
745 /* Socket driver entry points */
746 int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev)
748 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
751 if (ops && ops->connect_phy)
752 ret = ops->connect_phy(bus->upstream, phydev);
755 bus->phydev = phydev;
759 EXPORT_SYMBOL_GPL(sfp_add_phy);
761 void sfp_remove_phy(struct sfp_bus *bus)
763 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
765 if (ops && ops->disconnect_phy)
766 ops->disconnect_phy(bus->upstream);
769 EXPORT_SYMBOL_GPL(sfp_remove_phy);
771 void sfp_link_up(struct sfp_bus *bus)
773 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
775 if (ops && ops->link_up)
776 ops->link_up(bus->upstream);
778 EXPORT_SYMBOL_GPL(sfp_link_up);
780 void sfp_link_down(struct sfp_bus *bus)
782 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
784 if (ops && ops->link_down)
785 ops->link_down(bus->upstream);
787 EXPORT_SYMBOL_GPL(sfp_link_down);
789 int sfp_module_insert(struct sfp_bus *bus, const struct sfp_eeprom_id *id)
791 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
794 bus->sfp_quirk = sfp_lookup_quirk(id);
796 if (ops && ops->module_insert)
797 ret = ops->module_insert(bus->upstream, id);
801 EXPORT_SYMBOL_GPL(sfp_module_insert);
803 void sfp_module_remove(struct sfp_bus *bus)
805 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
807 if (ops && ops->module_remove)
808 ops->module_remove(bus->upstream);
810 bus->sfp_quirk = NULL;
812 EXPORT_SYMBOL_GPL(sfp_module_remove);
814 int sfp_module_start(struct sfp_bus *bus)
816 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
819 if (ops && ops->module_start)
820 ret = ops->module_start(bus->upstream);
824 EXPORT_SYMBOL_GPL(sfp_module_start);
826 void sfp_module_stop(struct sfp_bus *bus)
828 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
830 if (ops && ops->module_stop)
831 ops->module_stop(bus->upstream);
833 EXPORT_SYMBOL_GPL(sfp_module_stop);
835 static void sfp_socket_clear(struct sfp_bus *bus)
839 bus->socket_ops = NULL;
842 struct sfp_bus *sfp_register_socket(struct device *dev, struct sfp *sfp,
843 const struct sfp_socket_ops *ops)
845 struct sfp_bus *bus = sfp_bus_get(dev->fwnode);
852 bus->socket_ops = ops;
854 if (bus->upstream_ops) {
855 ret = sfp_register_bus(bus);
857 sfp_socket_clear(bus);
869 EXPORT_SYMBOL_GPL(sfp_register_socket);
871 void sfp_unregister_socket(struct sfp_bus *bus)
874 if (bus->upstream_ops)
875 sfp_unregister_bus(bus);
876 sfp_socket_clear(bus);
881 EXPORT_SYMBOL_GPL(sfp_unregister_socket);