Skip to content

Commit 8fa7b9b

Browse files
Russell Kingdavem330
authored andcommitted
phylink: convert to fwnode
Convert phylink to fwnode, switching phylink_create() from taking a device_node to taking a fwnode_handle. This will allow other firmware systems to take advantage of sfp/phylink support. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c19bb00 commit 8fa7b9b

File tree

2 files changed

+55
-39
lines changed

2 files changed

+55
-39
lines changed

drivers/net/phy/phylink.c

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -142,59 +142,64 @@ static int phylink_validate(struct phylink *pl, unsigned long *supported,
142142
return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
143143
}
144144

145-
static int phylink_parse_fixedlink(struct phylink *pl, struct device_node *np)
145+
static int phylink_parse_fixedlink(struct phylink *pl,
146+
struct fwnode_handle *fwnode)
146147
{
147-
struct device_node *fixed_node;
148+
struct fwnode_handle *fixed_node;
148149
const struct phy_setting *s;
149150
struct gpio_desc *desc;
150-
const __be32 *fixed_prop;
151151
u32 speed;
152-
int ret, len;
152+
int ret;
153153

154-
fixed_node = of_get_child_by_name(np, "fixed-link");
154+
fixed_node = fwnode_get_named_child_node(fwnode, "fixed-link");
155155
if (fixed_node) {
156-
ret = of_property_read_u32(fixed_node, "speed", &speed);
156+
ret = fwnode_property_read_u32(fixed_node, "speed", &speed);
157157

158158
pl->link_config.speed = speed;
159159
pl->link_config.duplex = DUPLEX_HALF;
160160

161-
if (of_property_read_bool(fixed_node, "full-duplex"))
161+
if (fwnode_property_read_bool(fixed_node, "full-duplex"))
162162
pl->link_config.duplex = DUPLEX_FULL;
163163

164164
/* We treat the "pause" and "asym-pause" terminology as
165165
* defining the link partner's ability. */
166-
if (of_property_read_bool(fixed_node, "pause"))
166+
if (fwnode_property_read_bool(fixed_node, "pause"))
167167
pl->link_config.pause |= MLO_PAUSE_SYM;
168-
if (of_property_read_bool(fixed_node, "asym-pause"))
168+
if (fwnode_property_read_bool(fixed_node, "asym-pause"))
169169
pl->link_config.pause |= MLO_PAUSE_ASYM;
170170

171171
if (ret == 0) {
172-
desc = fwnode_get_named_gpiod(&fixed_node->fwnode,
173-
"link-gpios", 0,
174-
GPIOD_IN, "?");
172+
desc = fwnode_get_named_gpiod(fixed_node, "link-gpios",
173+
0, GPIOD_IN, "?");
175174

176175
if (!IS_ERR(desc))
177176
pl->link_gpio = desc;
178177
else if (desc == ERR_PTR(-EPROBE_DEFER))
179178
ret = -EPROBE_DEFER;
180179
}
181-
of_node_put(fixed_node);
180+
fwnode_handle_put(fixed_node);
182181

183182
if (ret)
184183
return ret;
185184
} else {
186-
fixed_prop = of_get_property(np, "fixed-link", &len);
187-
if (!fixed_prop) {
185+
u32 prop[5];
186+
187+
ret = fwnode_property_read_u32_array(fwnode, "fixed-link",
188+
NULL, 0);
189+
if (ret != ARRAY_SIZE(prop)) {
188190
netdev_err(pl->netdev, "broken fixed-link?\n");
189191
return -EINVAL;
190192
}
191-
if (len == 5 * sizeof(*fixed_prop)) {
192-
pl->link_config.duplex = be32_to_cpu(fixed_prop[1]) ?
193+
194+
ret = fwnode_property_read_u32_array(fwnode, "fixed-link",
195+
prop, ARRAY_SIZE(prop));
196+
if (!ret) {
197+
pl->link_config.duplex = prop[1] ?
193198
DUPLEX_FULL : DUPLEX_HALF;
194-
pl->link_config.speed = be32_to_cpu(fixed_prop[2]);
195-
if (be32_to_cpu(fixed_prop[3]))
199+
pl->link_config.speed = prop[2];
200+
if (prop[3])
196201
pl->link_config.pause |= MLO_PAUSE_SYM;
197-
if (be32_to_cpu(fixed_prop[4]))
202+
if (prop[4])
198203
pl->link_config.pause |= MLO_PAUSE_ASYM;
199204
}
200205
}
@@ -230,17 +235,17 @@ static int phylink_parse_fixedlink(struct phylink *pl, struct device_node *np)
230235
return 0;
231236
}
232237

233-
static int phylink_parse_mode(struct phylink *pl, struct device_node *np)
238+
static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
234239
{
235-
struct device_node *dn;
240+
struct fwnode_handle *dn;
236241
const char *managed;
237242

238-
dn = of_get_child_by_name(np, "fixed-link");
239-
if (dn || of_find_property(np, "fixed-link", NULL))
243+
dn = fwnode_get_named_child_node(fwnode, "fixed-link");
244+
if (dn || fwnode_property_present(fwnode, "fixed-link"))
240245
pl->link_an_mode = MLO_AN_FIXED;
241-
of_node_put(dn);
246+
fwnode_handle_put(dn);
242247

243-
if (of_property_read_string(np, "managed", &managed) == 0 &&
248+
if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 &&
244249
strcmp(managed, "in-band-status") == 0) {
245250
if (pl->link_an_mode == MLO_AN_FIXED) {
246251
netdev_err(pl->netdev,
@@ -491,16 +496,24 @@ static void phylink_run_resolve(struct phylink *pl)
491496

492497
static const struct sfp_upstream_ops sfp_phylink_ops;
493498

494-
static int phylink_register_sfp(struct phylink *pl, struct device_node *np)
499+
static int phylink_register_sfp(struct phylink *pl,
500+
struct fwnode_handle *fwnode)
495501
{
496-
struct device_node *sfp_np;
502+
struct fwnode_reference_args ref;
503+
int ret;
497504

498-
sfp_np = of_parse_phandle(np, "sfp", 0);
499-
if (!sfp_np)
500-
return 0;
505+
ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
506+
0, 0, &ref);
507+
if (ret < 0) {
508+
if (ret == -ENOENT)
509+
return 0;
510+
511+
netdev_err(pl->netdev, "unable to parse \"sfp\" node: %d\n",
512+
ret);
513+
return ret;
514+
}
501515

502-
pl->sfp_bus = sfp_register_upstream(of_fwnode_handle(sfp_np),
503-
pl->netdev, pl,
516+
pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl->netdev, pl,
504517
&sfp_phylink_ops);
505518
if (!pl->sfp_bus)
506519
return -ENOMEM;
@@ -511,7 +524,8 @@ static int phylink_register_sfp(struct phylink *pl, struct device_node *np)
511524
/**
512525
* phylink_create() - create a phylink instance
513526
* @ndev: a pointer to the &struct net_device
514-
* @np: a pointer to a &struct device_node describing the network interface
527+
* @fwnode: a pointer to a &struct fwnode_handle describing the network
528+
* interface
515529
* @iface: the desired link mode defined by &typedef phy_interface_t
516530
* @ops: a pointer to a &struct phylink_mac_ops for the MAC.
517531
*
@@ -521,7 +535,8 @@ static int phylink_register_sfp(struct phylink *pl, struct device_node *np)
521535
* Returns a pointer to a &struct phylink, or an error-pointer value. Users
522536
* must use IS_ERR() to check for errors from this function.
523537
*/
524-
struct phylink *phylink_create(struct net_device *ndev, struct device_node *np,
538+
struct phylink *phylink_create(struct net_device *ndev,
539+
struct fwnode_handle *fwnode,
525540
phy_interface_t iface,
526541
const struct phylink_mac_ops *ops)
527542
{
@@ -549,21 +564,21 @@ struct phylink *phylink_create(struct net_device *ndev, struct device_node *np,
549564
linkmode_copy(pl->link_config.advertising, pl->supported);
550565
phylink_validate(pl, pl->supported, &pl->link_config);
551566

552-
ret = phylink_parse_mode(pl, np);
567+
ret = phylink_parse_mode(pl, fwnode);
553568
if (ret < 0) {
554569
kfree(pl);
555570
return ERR_PTR(ret);
556571
}
557572

558573
if (pl->link_an_mode == MLO_AN_FIXED) {
559-
ret = phylink_parse_fixedlink(pl, np);
574+
ret = phylink_parse_fixedlink(pl, fwnode);
560575
if (ret < 0) {
561576
kfree(pl);
562577
return ERR_PTR(ret);
563578
}
564579
}
565580

566-
ret = phylink_register_sfp(pl, np);
581+
ret = phylink_register_sfp(pl, fwnode);
567582
if (ret < 0) {
568583
kfree(pl);
569584
return ERR_PTR(ret);

include/linux/phylink.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
struct device_node;
99
struct ethtool_cmd;
10+
struct fwnode_handle;
1011
struct net_device;
1112

1213
enum {
@@ -182,7 +183,7 @@ void mac_link_up(struct net_device *ndev, unsigned int mode,
182183
struct phy_device *phy);
183184
#endif
184185

185-
struct phylink *phylink_create(struct net_device *, struct device_node *,
186+
struct phylink *phylink_create(struct net_device *, struct fwnode_handle *,
186187
phy_interface_t iface, const struct phylink_mac_ops *ops);
187188
void phylink_destroy(struct phylink *);
188189

0 commit comments

Comments
 (0)