Lines Matching defs:bus
14 * struct sfp_bus - internal representation of a sfp bus
37 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
49 int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
88 dev_warn(bus->sfp_dev, "SFP: unknown connector id 0x%02x\n",
112 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
118 bool sfp_may_have_phy(struct sfp_bus *bus, const struct sfp_eeprom_id *id)
139 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
148 void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
298 dev_warn(bus->sfp_dev,
342 if (bus->sfp_quirk && bus->sfp_quirk->modes)
343 bus->sfp_quirk->modes(id, modes, interfaces);
351 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
357 phy_interface_t sfp_select_interface(struct sfp_bus *bus,
390 dev_warn(bus->sfp_dev, "Unable to ascertain link mode\n");
399 static const struct sfp_upstream_ops *sfp_get_upstream_ops(struct sfp_bus *bus)
401 return bus->registered ? bus->upstream_ops : NULL;
437 struct sfp_bus *bus = container_of(kref, struct sfp_bus, kref);
439 list_del(&bus->node);
441 kfree(bus);
446 * @bus: the &struct sfp_bus found via sfp_bus_find_fwnode()
451 void sfp_bus_put(struct sfp_bus *bus)
453 if (bus)
454 kref_put_mutex(&bus->kref, sfp_bus_release, &sfp_mutex);
458 static int sfp_register_bus(struct sfp_bus *bus)
460 const struct sfp_upstream_ops *ops = bus->upstream_ops;
465 ops->link_down(bus->upstream);
466 if (ops->connect_phy && bus->phydev) {
467 ret = ops->connect_phy(bus->upstream, bus->phydev);
472 bus->registered = true;
473 bus->socket_ops->attach(bus->sfp);
474 if (bus->started)
475 bus->socket_ops->start(bus->sfp);
476 bus->upstream_ops->attach(bus->upstream, bus);
480 static void sfp_unregister_bus(struct sfp_bus *bus)
482 const struct sfp_upstream_ops *ops = bus->upstream_ops;
484 if (bus->registered) {
485 bus->upstream_ops->detach(bus->upstream, bus);
486 if (bus->started)
487 bus->socket_ops->stop(bus->sfp);
488 bus->socket_ops->detach(bus->sfp);
489 if (bus->phydev && ops && ops->disconnect_phy)
490 ops->disconnect_phy(bus->upstream, bus->phydev);
492 bus->registered = false;
497 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
501 * the sfp bus specified by @bus.
505 int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
507 return bus->socket_ops->module_info(bus->sfp, modinfo);
513 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
522 int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
525 return bus->socket_ops->module_eeprom(bus->sfp, ee, data);
531 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
541 int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
545 return bus->socket_ops->module_eeprom_by_page(bus->sfp, page, extack);
551 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
558 void sfp_upstream_start(struct sfp_bus *bus)
560 if (bus->registered)
561 bus->socket_ops->start(bus->sfp);
562 bus->started = true;
568 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
575 void sfp_upstream_stop(struct sfp_bus *bus)
577 if (bus->registered)
578 bus->socket_ops->stop(bus->sfp);
579 bus->started = false;
583 static void sfp_upstream_clear(struct sfp_bus *bus)
585 bus->upstream_ops = NULL;
586 bus->upstream = NULL;
591 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
602 void sfp_upstream_set_signal_rate(struct sfp_bus *bus, unsigned int rate_kbd)
604 if (bus->registered)
605 bus->socket_ops->set_signal_rate(bus->sfp, rate_kbd);
610 * sfp_bus_find_fwnode() - parse and locate the SFP bus from fwnode
613 * Parse the parent device's firmware node for a SFP bus, and locate
624 * - %-ENOMEM if we failed to allocate the bus.
630 struct sfp_bus *bus;
645 bus = sfp_bus_get(ref.fwnode);
647 if (!bus)
650 return bus;
656 * @bus: the &struct sfp_bus found via sfp_bus_find_fwnode()
660 * Add upstream driver for the SFP bus, and if the bus is complete, register
661 * the SFP bus using sfp_register_upstream(). This takes a reference on the
662 * bus, so it is safe to put the bus after this call.
671 * - %-ENOMEM if we failed to allocate the bus.
674 int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
679 /* If no bus, return success */
680 if (!bus)
684 kref_get(&bus->kref);
685 bus->upstream_ops = ops;
686 bus->upstream = upstream;
688 if (bus->sfp) {
689 ret = sfp_register_bus(bus);
691 sfp_upstream_clear(bus);
698 sfp_bus_put(bus);
705 * sfp_bus_del_upstream() - Delete a sfp bus
706 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
709 * module. @bus should have been added by sfp_bus_add_upstream().
711 void sfp_bus_del_upstream(struct sfp_bus *bus)
713 if (bus) {
715 if (bus->sfp)
716 sfp_unregister_bus(bus);
717 sfp_upstream_clear(bus);
720 sfp_bus_put(bus);
727 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
729 * Gets the SFP device's name, if @bus has a registered socket. Callers must
734 * - %NULL if no device was registered on @bus
736 const char *sfp_get_name(struct sfp_bus *bus)
740 if (bus->sfp_dev)
741 return dev_name(bus->sfp_dev);
748 int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev)
750 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
754 ret = ops->connect_phy(bus->upstream, phydev);
757 bus->phydev = phydev;
763 void sfp_remove_phy(struct sfp_bus *bus)
765 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
768 ops->disconnect_phy(bus->upstream, bus->phydev);
769 bus->phydev = NULL;
773 void sfp_link_up(struct sfp_bus *bus)
775 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
778 ops->link_up(bus->upstream);
782 void sfp_link_down(struct sfp_bus *bus)
784 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
787 ops->link_down(bus->upstream);
791 int sfp_module_insert(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
794 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
797 bus->sfp_quirk = quirk;
800 ret = ops->module_insert(bus->upstream, id);
806 void sfp_module_remove(struct sfp_bus *bus)
808 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
811 ops->module_remove(bus->upstream);
813 bus->sfp_quirk = NULL;
817 int sfp_module_start(struct sfp_bus *bus)
819 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
823 ret = ops->module_start(bus->upstream);
829 void sfp_module_stop(struct sfp_bus *bus)
831 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
834 ops->module_stop(bus->upstream);
838 static void sfp_socket_clear(struct sfp_bus *bus)
840 bus->sfp_dev = NULL;
841 bus->sfp = NULL;
842 bus->socket_ops = NULL;
848 struct sfp_bus *bus = sfp_bus_get(dev->fwnode);
851 if (bus) {
853 bus->sfp_dev = dev;
854 bus->sfp = sfp;
855 bus->socket_ops = ops;
857 if (bus->upstream_ops) {
858 ret = sfp_register_bus(bus);
860 sfp_socket_clear(bus);
866 sfp_bus_put(bus);
867 bus = NULL;
870 return bus;
874 void sfp_unregister_socket(struct sfp_bus *bus)
877 if (bus->upstream_ops)
878 sfp_unregister_bus(bus);
879 sfp_socket_clear(bus);
882 sfp_bus_put(bus);