Lines Matching refs: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,
302 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,
389 dev_warn(bus->sfp_dev, "Unable to ascertain link mode\n");
398 static const struct sfp_upstream_ops *sfp_get_upstream_ops(struct sfp_bus *bus)
400 return bus->registered ? bus->upstream_ops : NULL;
436 struct sfp_bus *bus = container_of(kref, struct sfp_bus, kref);
438 list_del(&bus->node);
440 kfree(bus);
445 * @bus: the &struct sfp_bus found via sfp_bus_find_fwnode()
450 void sfp_bus_put(struct sfp_bus *bus)
452 if (bus)
453 kref_put_mutex(&bus->kref, sfp_bus_release, &sfp_mutex);
457 static int sfp_register_bus(struct sfp_bus *bus)
459 const struct sfp_upstream_ops *ops = bus->upstream_ops;
464 ops->link_down(bus->upstream);
465 if (ops->connect_phy && bus->phydev) {
466 ret = ops->connect_phy(bus->upstream, bus->phydev);
471 bus->registered = true;
472 bus->socket_ops->attach(bus->sfp);
473 if (bus->started)
474 bus->socket_ops->start(bus->sfp);
475 bus->upstream_ops->attach(bus->upstream, bus);
479 static void sfp_unregister_bus(struct sfp_bus *bus)
481 const struct sfp_upstream_ops *ops = bus->upstream_ops;
483 if (bus->registered) {
484 bus->upstream_ops->detach(bus->upstream, bus);
485 if (bus->started)
486 bus->socket_ops->stop(bus->sfp);
487 bus->socket_ops->detach(bus->sfp);
488 if (bus->phydev && ops && ops->disconnect_phy)
489 ops->disconnect_phy(bus->upstream);
491 bus->registered = false;
496 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
500 * the sfp bus specified by @bus.
504 int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
506 return bus->socket_ops->module_info(bus->sfp, modinfo);
512 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
521 int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
524 return bus->socket_ops->module_eeprom(bus->sfp, ee, data);
530 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
540 int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
544 return bus->socket_ops->module_eeprom_by_page(bus->sfp, page, extack);
550 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
557 void sfp_upstream_start(struct sfp_bus *bus)
559 if (bus->registered)
560 bus->socket_ops->start(bus->sfp);
561 bus->started = true;
567 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
574 void sfp_upstream_stop(struct sfp_bus *bus)
576 if (bus->registered)
577 bus->socket_ops->stop(bus->sfp);
578 bus->started = false;
582 static void sfp_upstream_clear(struct sfp_bus *bus)
584 bus->upstream_ops = NULL;
585 bus->upstream = NULL;
590 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
601 void sfp_upstream_set_signal_rate(struct sfp_bus *bus, unsigned int rate_kbd)
603 if (bus->registered)
604 bus->socket_ops->set_signal_rate(bus->sfp, rate_kbd);
609 * sfp_bus_find_fwnode() - parse and locate the SFP bus from fwnode
612 * Parse the parent device's firmware node for a SFP bus, and locate
623 * - %-ENOMEM if we failed to allocate the bus.
629 struct sfp_bus *bus;
644 bus = sfp_bus_get(ref.fwnode);
646 if (!bus)
649 return bus;
655 * @bus: the &struct sfp_bus found via sfp_bus_find_fwnode()
659 * Add upstream driver for the SFP bus, and if the bus is complete, register
660 * the SFP bus using sfp_register_upstream(). This takes a reference on the
661 * bus, so it is safe to put the bus after this call.
670 * - %-ENOMEM if we failed to allocate the bus.
673 int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
678 /* If no bus, return success */
679 if (!bus)
683 kref_get(&bus->kref);
684 bus->upstream_ops = ops;
685 bus->upstream = upstream;
687 if (bus->sfp) {
688 ret = sfp_register_bus(bus);
690 sfp_upstream_clear(bus);
697 sfp_bus_put(bus);
704 * sfp_bus_del_upstream() - Delete a sfp bus
705 * @bus: a pointer to the &struct sfp_bus structure for the sfp module
708 * module. @bus should have been added by sfp_bus_add_upstream().
710 void sfp_bus_del_upstream(struct sfp_bus *bus)
712 if (bus) {
714 if (bus->sfp)
715 sfp_unregister_bus(bus);
716 sfp_upstream_clear(bus);
719 sfp_bus_put(bus);
725 int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev)
727 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
731 ret = ops->connect_phy(bus->upstream, phydev);
734 bus->phydev = phydev;
740 void sfp_remove_phy(struct sfp_bus *bus)
742 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
745 ops->disconnect_phy(bus->upstream);
746 bus->phydev = NULL;
750 void sfp_link_up(struct sfp_bus *bus)
752 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
755 ops->link_up(bus->upstream);
759 void sfp_link_down(struct sfp_bus *bus)
761 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
764 ops->link_down(bus->upstream);
768 int sfp_module_insert(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
771 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
774 bus->sfp_quirk = quirk;
777 ret = ops->module_insert(bus->upstream, id);
783 void sfp_module_remove(struct sfp_bus *bus)
785 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
788 ops->module_remove(bus->upstream);
790 bus->sfp_quirk = NULL;
794 int sfp_module_start(struct sfp_bus *bus)
796 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
800 ret = ops->module_start(bus->upstream);
806 void sfp_module_stop(struct sfp_bus *bus)
808 const struct sfp_upstream_ops *ops = sfp_get_upstream_ops(bus);
811 ops->module_stop(bus->upstream);
815 static void sfp_socket_clear(struct sfp_bus *bus)
817 bus->sfp_dev = NULL;
818 bus->sfp = NULL;
819 bus->socket_ops = NULL;
825 struct sfp_bus *bus = sfp_bus_get(dev->fwnode);
828 if (bus) {
830 bus->sfp_dev = dev;
831 bus->sfp = sfp;
832 bus->socket_ops = ops;
834 if (bus->upstream_ops) {
835 ret = sfp_register_bus(bus);
837 sfp_socket_clear(bus);
843 sfp_bus_put(bus);
844 bus = NULL;
847 return bus;
851 void sfp_unregister_socket(struct sfp_bus *bus)
854 if (bus->upstream_ops)
855 sfp_unregister_bus(bus);
856 sfp_socket_clear(bus);
859 sfp_bus_put(bus);