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 <rmk+kernel@armlinux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									9370f2d05a
								
							
						
					
					
						commit
						2203cbf2c8
					
				| @ -548,26 +548,17 @@ static const struct sfp_upstream_ops sfp_phylink_ops; | |||||||
| static int phylink_register_sfp(struct phylink *pl, | static int phylink_register_sfp(struct phylink *pl, | ||||||
| 				struct fwnode_handle *fwnode) | 				struct fwnode_handle *fwnode) | ||||||
| { | { | ||||||
| 	struct fwnode_reference_args ref; | 	struct sfp_bus *bus; | ||||||
| 	int ret; | 	int ret; | ||||||
| 
 | 
 | ||||||
| 	if (!fwnode) | 	bus = sfp_register_upstream_node(fwnode, pl, &sfp_phylink_ops); | ||||||
| 		return 0; | 	if (IS_ERR(bus)) { | ||||||
| 
 | 		ret = PTR_ERR(bus); | ||||||
| 	ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL, | 		phylink_err(pl, "unable to attach SFP bus: %d\n", ret); | ||||||
| 						 0, 0, &ref); |  | ||||||
| 	if (ret < 0) { |  | ||||||
| 		if (ret == -ENOENT) |  | ||||||
| 			return 0; |  | ||||||
| 
 |  | ||||||
| 		phylink_err(pl, "unable to parse \"sfp\" node: %d\n", |  | ||||||
| 			    ret); |  | ||||||
| 		return ret; | 		return ret; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl, &sfp_phylink_ops); | 	pl->sfp_bus = bus; | ||||||
| 	if (!pl->sfp_bus) |  | ||||||
| 		return -ENOMEM; |  | ||||||
| 
 | 
 | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | |||||||
| @ -4,6 +4,7 @@ | |||||||
| #include <linux/list.h> | #include <linux/list.h> | ||||||
| #include <linux/mutex.h> | #include <linux/mutex.h> | ||||||
| #include <linux/phylink.h> | #include <linux/phylink.h> | ||||||
|  | #include <linux/property.h> | ||||||
| #include <linux/rtnetlink.h> | #include <linux/rtnetlink.h> | ||||||
| #include <linux/slab.h> | #include <linux/slab.h> | ||||||
| 
 | 
 | ||||||
| @ -445,25 +446,42 @@ static void sfp_upstream_clear(struct sfp_bus *bus) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * sfp_register_upstream() - Register the neighbouring device |  * sfp_register_upstream_node() - parse and register the neighbouring device | ||||||
|  * @fwnode: firmware node for the SFP bus |  * @fwnode: firmware node for the parent device (MAC or PHY) | ||||||
|  * @upstream: the upstream private data |  * @upstream: the upstream private data | ||||||
|  * @ops: the upstream's &struct sfp_upstream_ops |  * @ops: the upstream's &struct sfp_upstream_ops | ||||||
|  * |  * | ||||||
|  * Register the upstream device (eg, PHY) with the SFP bus. MAC drivers |  * Parse the parent device's firmware node for a SFP bus, and register the | ||||||
|  * should use phylink, which will call this function for them. Returns |  * SFP bus using sfp_register_upstream(). | ||||||
|  * a pointer to the allocated &struct sfp_bus. |  | ||||||
|  * |  * | ||||||
|  * On error, returns %NULL. |  * Returns: on success, a pointer to the sfp_bus structure, | ||||||
|  |  *	    %NULL if no SFP is specified, | ||||||
|  |  * 	    on failure, an error pointer value: | ||||||
|  |  * 		corresponding to the errors detailed for | ||||||
|  |  * 		fwnode_property_get_reference_args(). | ||||||
|  |  * 	        %-ENOMEM if we failed to allocate the bus. | ||||||
|  |  *		an error from the upstream's connect_phy() method. | ||||||
|  */ |  */ | ||||||
| struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode, | struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode, | ||||||
| 					   void *upstream, | 					   void *upstream, | ||||||
| 					   const struct sfp_upstream_ops *ops) | 					   const struct sfp_upstream_ops *ops) | ||||||
| { | { | ||||||
| 	struct sfp_bus *bus = sfp_bus_get(fwnode); | 	struct fwnode_reference_args ref; | ||||||
| 	int ret = 0; | 	struct sfp_bus *bus; | ||||||
|  | 	int ret; | ||||||
|  | 
 | ||||||
|  | 	ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL, | ||||||
|  | 						 0, 0, &ref); | ||||||
|  | 	if (ret == -ENOENT) | ||||||
|  | 		return NULL; | ||||||
|  | 	else if (ret < 0) | ||||||
|  | 		return ERR_PTR(ret); | ||||||
|  | 
 | ||||||
|  | 	bus = sfp_bus_get(ref.fwnode); | ||||||
|  | 	fwnode_handle_put(ref.fwnode); | ||||||
|  | 	if (!bus) | ||||||
|  | 		return ERR_PTR(-ENOMEM); | ||||||
| 
 | 
 | ||||||
| 	if (bus) { |  | ||||||
| 	rtnl_lock(); | 	rtnl_lock(); | ||||||
| 	bus->upstream_ops = ops; | 	bus->upstream_ops = ops; | ||||||
| 	bus->upstream = upstream; | 	bus->upstream = upstream; | ||||||
| @ -472,18 +490,19 @@ struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode, | |||||||
| 		ret = sfp_register_bus(bus); | 		ret = sfp_register_bus(bus); | ||||||
| 		if (ret) | 		if (ret) | ||||||
| 			sfp_upstream_clear(bus); | 			sfp_upstream_clear(bus); | ||||||
|  | 	} else { | ||||||
|  | 		ret = 0; | ||||||
| 	} | 	} | ||||||
| 	rtnl_unlock(); | 	rtnl_unlock(); | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if (ret) { | 	if (ret) { | ||||||
| 		sfp_bus_put(bus); | 		sfp_bus_put(bus); | ||||||
| 		bus = NULL; | 		bus = ERR_PTR(ret); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return bus; | 	return bus; | ||||||
| } | } | ||||||
| EXPORT_SYMBOL_GPL(sfp_register_upstream); | EXPORT_SYMBOL_GPL(sfp_register_upstream_node); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * sfp_unregister_upstream() - Unregister sfp bus |  * sfp_unregister_upstream() - Unregister sfp bus | ||||||
|  | |||||||
| @ -508,7 +508,7 @@ int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee, | |||||||
| 			  u8 *data); | 			  u8 *data); | ||||||
| void sfp_upstream_start(struct sfp_bus *bus); | void sfp_upstream_start(struct sfp_bus *bus); | ||||||
| void sfp_upstream_stop(struct sfp_bus *bus); | void sfp_upstream_stop(struct sfp_bus *bus); | ||||||
| struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode, | struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode, | ||||||
| 					   void *upstream, | 					   void *upstream, | ||||||
| 					   const struct sfp_upstream_ops *ops); | 					   const struct sfp_upstream_ops *ops); | ||||||
| void sfp_unregister_upstream(struct sfp_bus *bus); | void sfp_unregister_upstream(struct sfp_bus *bus); | ||||||
| @ -553,11 +553,11 @@ static inline void sfp_upstream_stop(struct sfp_bus *bus) | |||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static inline struct sfp_bus *sfp_register_upstream( | static inline struct sfp_bus *sfp_register_upstream_node( | ||||||
| 	struct fwnode_handle *fwnode, void *upstream, | 	struct fwnode_handle *fwnode, void *upstream, | ||||||
| 	const struct sfp_upstream_ops *ops) | 	const struct sfp_upstream_ops *ops) | ||||||
| { | { | ||||||
| 	return (struct sfp_bus *)-1; | 	return NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static inline void sfp_unregister_upstream(struct sfp_bus *bus) | static inline void sfp_unregister_upstream(struct sfp_bus *bus) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user