Skip to content

Commit 2203cbf

Browse files
Russell Kingdavem330
authored andcommitted
net: sfp: move fwnode parsing into sfp-bus layer
Rather than parsing the sfp firmware node in phylink, parse it in the sfp-bus code, so we can re-use this code for PHYs without having to duplicate the parsing. Signed-off-by: Russell King <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9370f2d commit 2203cbf

File tree

3 files changed

+53
-43
lines changed

3 files changed

+53
-43
lines changed

drivers/net/phy/phylink.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -548,26 +548,17 @@ static const struct sfp_upstream_ops sfp_phylink_ops;
548548
static int phylink_register_sfp(struct phylink *pl,
549549
struct fwnode_handle *fwnode)
550550
{
551-
struct fwnode_reference_args ref;
551+
struct sfp_bus *bus;
552552
int ret;
553553

554-
if (!fwnode)
555-
return 0;
556-
557-
ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
558-
0, 0, &ref);
559-
if (ret < 0) {
560-
if (ret == -ENOENT)
561-
return 0;
562-
563-
phylink_err(pl, "unable to parse \"sfp\" node: %d\n",
564-
ret);
554+
bus = sfp_register_upstream_node(fwnode, pl, &sfp_phylink_ops);
555+
if (IS_ERR(bus)) {
556+
ret = PTR_ERR(bus);
557+
phylink_err(pl, "unable to attach SFP bus: %d\n", ret);
565558
return ret;
566559
}
567560

568-
pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl, &sfp_phylink_ops);
569-
if (!pl->sfp_bus)
570-
return -ENOMEM;
561+
pl->sfp_bus = bus;
571562

572563
return 0;
573564
}

drivers/net/phy/sfp-bus.c

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/list.h>
55
#include <linux/mutex.h>
66
#include <linux/phylink.h>
7+
#include <linux/property.h>
78
#include <linux/rtnetlink.h>
89
#include <linux/slab.h>
910

@@ -445,45 +446,63 @@ static void sfp_upstream_clear(struct sfp_bus *bus)
445446
}
446447

447448
/**
448-
* sfp_register_upstream() - Register the neighbouring device
449-
* @fwnode: firmware node for the SFP bus
449+
* sfp_register_upstream_node() - parse and register the neighbouring device
450+
* @fwnode: firmware node for the parent device (MAC or PHY)
450451
* @upstream: the upstream private data
451452
* @ops: the upstream's &struct sfp_upstream_ops
452453
*
453-
* Register the upstream device (eg, PHY) with the SFP bus. MAC drivers
454-
* should use phylink, which will call this function for them. Returns
455-
* a pointer to the allocated &struct sfp_bus.
454+
* Parse the parent device's firmware node for a SFP bus, and register the
455+
* SFP bus using sfp_register_upstream().
456456
*
457-
* On error, returns %NULL.
457+
* Returns: on success, a pointer to the sfp_bus structure,
458+
* %NULL if no SFP is specified,
459+
* on failure, an error pointer value:
460+
* corresponding to the errors detailed for
461+
* fwnode_property_get_reference_args().
462+
* %-ENOMEM if we failed to allocate the bus.
463+
* an error from the upstream's connect_phy() method.
458464
*/
459-
struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
460-
void *upstream,
461-
const struct sfp_upstream_ops *ops)
465+
struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
466+
void *upstream,
467+
const struct sfp_upstream_ops *ops)
462468
{
463-
struct sfp_bus *bus = sfp_bus_get(fwnode);
464-
int ret = 0;
469+
struct fwnode_reference_args ref;
470+
struct sfp_bus *bus;
471+
int ret;
465472

466-
if (bus) {
467-
rtnl_lock();
468-
bus->upstream_ops = ops;
469-
bus->upstream = upstream;
473+
ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
474+
0, 0, &ref);
475+
if (ret == -ENOENT)
476+
return NULL;
477+
else if (ret < 0)
478+
return ERR_PTR(ret);
470479

471-
if (bus->sfp) {
472-
ret = sfp_register_bus(bus);
473-
if (ret)
474-
sfp_upstream_clear(bus);
475-
}
476-
rtnl_unlock();
480+
bus = sfp_bus_get(ref.fwnode);
481+
fwnode_handle_put(ref.fwnode);
482+
if (!bus)
483+
return ERR_PTR(-ENOMEM);
484+
485+
rtnl_lock();
486+
bus->upstream_ops = ops;
487+
bus->upstream = upstream;
488+
489+
if (bus->sfp) {
490+
ret = sfp_register_bus(bus);
491+
if (ret)
492+
sfp_upstream_clear(bus);
493+
} else {
494+
ret = 0;
477495
}
496+
rtnl_unlock();
478497

479498
if (ret) {
480499
sfp_bus_put(bus);
481-
bus = NULL;
500+
bus = ERR_PTR(ret);
482501
}
483502

484503
return bus;
485504
}
486-
EXPORT_SYMBOL_GPL(sfp_register_upstream);
505+
EXPORT_SYMBOL_GPL(sfp_register_upstream_node);
487506

488507
/**
489508
* sfp_unregister_upstream() - Unregister sfp bus

include/linux/sfp.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
508508
u8 *data);
509509
void sfp_upstream_start(struct sfp_bus *bus);
510510
void sfp_upstream_stop(struct sfp_bus *bus);
511-
struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
512-
void *upstream,
513-
const struct sfp_upstream_ops *ops);
511+
struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
512+
void *upstream,
513+
const struct sfp_upstream_ops *ops);
514514
void sfp_unregister_upstream(struct sfp_bus *bus);
515515
#else
516516
static inline int sfp_parse_port(struct sfp_bus *bus,
@@ -553,11 +553,11 @@ static inline void sfp_upstream_stop(struct sfp_bus *bus)
553553
{
554554
}
555555

556-
static inline struct sfp_bus *sfp_register_upstream(
556+
static inline struct sfp_bus *sfp_register_upstream_node(
557557
struct fwnode_handle *fwnode, void *upstream,
558558
const struct sfp_upstream_ops *ops)
559559
{
560-
return (struct sfp_bus *)-1;
560+
return NULL;
561561
}
562562

563563
static inline void sfp_unregister_upstream(struct sfp_bus *bus)

0 commit comments

Comments
 (0)