@@ -142,59 +142,64 @@ static int phylink_validate(struct phylink *pl, unsigned long *supported,
142
142
return phylink_is_empty_linkmode (supported ) ? - EINVAL : 0 ;
143
143
}
144
144
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 )
146
147
{
147
- struct device_node * fixed_node ;
148
+ struct fwnode_handle * fixed_node ;
148
149
const struct phy_setting * s ;
149
150
struct gpio_desc * desc ;
150
- const __be32 * fixed_prop ;
151
151
u32 speed ;
152
- int ret , len ;
152
+ int ret ;
153
153
154
- fixed_node = of_get_child_by_name ( np , "fixed-link" );
154
+ fixed_node = fwnode_get_named_child_node ( fwnode , "fixed-link" );
155
155
if (fixed_node ) {
156
- ret = of_property_read_u32 (fixed_node , "speed" , & speed );
156
+ ret = fwnode_property_read_u32 (fixed_node , "speed" , & speed );
157
157
158
158
pl -> link_config .speed = speed ;
159
159
pl -> link_config .duplex = DUPLEX_HALF ;
160
160
161
- if (of_property_read_bool (fixed_node , "full-duplex" ))
161
+ if (fwnode_property_read_bool (fixed_node , "full-duplex" ))
162
162
pl -> link_config .duplex = DUPLEX_FULL ;
163
163
164
164
/* We treat the "pause" and "asym-pause" terminology as
165
165
* defining the link partner's ability. */
166
- if (of_property_read_bool (fixed_node , "pause" ))
166
+ if (fwnode_property_read_bool (fixed_node , "pause" ))
167
167
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" ))
169
169
pl -> link_config .pause |= MLO_PAUSE_ASYM ;
170
170
171
171
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 , "?" );
175
174
176
175
if (!IS_ERR (desc ))
177
176
pl -> link_gpio = desc ;
178
177
else if (desc == ERR_PTR (- EPROBE_DEFER ))
179
178
ret = - EPROBE_DEFER ;
180
179
}
181
- of_node_put (fixed_node );
180
+ fwnode_handle_put (fixed_node );
182
181
183
182
if (ret )
184
183
return ret ;
185
184
} 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 )) {
188
190
netdev_err (pl -> netdev , "broken fixed-link?\n" );
189
191
return - EINVAL ;
190
192
}
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 ] ?
193
198
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 ])
196
201
pl -> link_config .pause |= MLO_PAUSE_SYM ;
197
- if (be32_to_cpu ( fixed_prop [4 ]) )
202
+ if (prop [4 ])
198
203
pl -> link_config .pause |= MLO_PAUSE_ASYM ;
199
204
}
200
205
}
@@ -230,17 +235,17 @@ static int phylink_parse_fixedlink(struct phylink *pl, struct device_node *np)
230
235
return 0 ;
231
236
}
232
237
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 )
234
239
{
235
- struct device_node * dn ;
240
+ struct fwnode_handle * dn ;
236
241
const char * managed ;
237
242
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" ))
240
245
pl -> link_an_mode = MLO_AN_FIXED ;
241
- of_node_put (dn );
246
+ fwnode_handle_put (dn );
242
247
243
- if (of_property_read_string ( np , "managed" , & managed ) == 0 &&
248
+ if (fwnode_property_read_string ( fwnode , "managed" , & managed ) == 0 &&
244
249
strcmp (managed , "in-band-status" ) == 0 ) {
245
250
if (pl -> link_an_mode == MLO_AN_FIXED ) {
246
251
netdev_err (pl -> netdev ,
@@ -491,16 +496,24 @@ static void phylink_run_resolve(struct phylink *pl)
491
496
492
497
static const struct sfp_upstream_ops sfp_phylink_ops ;
493
498
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 )
495
501
{
496
- struct device_node * sfp_np ;
502
+ struct fwnode_reference_args ref ;
503
+ int ret ;
497
504
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
+ }
501
515
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 ,
504
517
& sfp_phylink_ops );
505
518
if (!pl -> sfp_bus )
506
519
return - ENOMEM ;
@@ -511,7 +524,8 @@ static int phylink_register_sfp(struct phylink *pl, struct device_node *np)
511
524
/**
512
525
* phylink_create() - create a phylink instance
513
526
* @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
515
529
* @iface: the desired link mode defined by &typedef phy_interface_t
516
530
* @ops: a pointer to a &struct phylink_mac_ops for the MAC.
517
531
*
@@ -521,7 +535,8 @@ static int phylink_register_sfp(struct phylink *pl, struct device_node *np)
521
535
* Returns a pointer to a &struct phylink, or an error-pointer value. Users
522
536
* must use IS_ERR() to check for errors from this function.
523
537
*/
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 ,
525
540
phy_interface_t iface ,
526
541
const struct phylink_mac_ops * ops )
527
542
{
@@ -549,21 +564,21 @@ struct phylink *phylink_create(struct net_device *ndev, struct device_node *np,
549
564
linkmode_copy (pl -> link_config .advertising , pl -> supported );
550
565
phylink_validate (pl , pl -> supported , & pl -> link_config );
551
566
552
- ret = phylink_parse_mode (pl , np );
567
+ ret = phylink_parse_mode (pl , fwnode );
553
568
if (ret < 0 ) {
554
569
kfree (pl );
555
570
return ERR_PTR (ret );
556
571
}
557
572
558
573
if (pl -> link_an_mode == MLO_AN_FIXED ) {
559
- ret = phylink_parse_fixedlink (pl , np );
574
+ ret = phylink_parse_fixedlink (pl , fwnode );
560
575
if (ret < 0 ) {
561
576
kfree (pl );
562
577
return ERR_PTR (ret );
563
578
}
564
579
}
565
580
566
- ret = phylink_register_sfp (pl , np );
581
+ ret = phylink_register_sfp (pl , fwnode );
567
582
if (ret < 0 ) {
568
583
kfree (pl );
569
584
return ERR_PTR (ret );
0 commit comments