@@ -199,7 +199,7 @@ EXPORT_SYMBOL(phy_aneg_done);
199
199
struct phy_setting {
200
200
int speed ;
201
201
int duplex ;
202
- u32 setting ;
202
+ int bit ;
203
203
};
204
204
205
205
/* A mapping of all SUPPORTED settings to speed/duplex. This table
@@ -209,65 +209,66 @@ static const struct phy_setting settings[] = {
209
209
{
210
210
.speed = SPEED_10000 ,
211
211
.duplex = DUPLEX_FULL ,
212
- .setting = SUPPORTED_10000baseKR_Full ,
212
+ .bit = ETHTOOL_LINK_MODE_10000baseKR_Full_BIT ,
213
213
},
214
214
{
215
215
.speed = SPEED_10000 ,
216
216
.duplex = DUPLEX_FULL ,
217
- .setting = SUPPORTED_10000baseKX4_Full ,
217
+ .bit = ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT ,
218
218
},
219
219
{
220
220
.speed = SPEED_10000 ,
221
221
.duplex = DUPLEX_FULL ,
222
- .setting = SUPPORTED_10000baseT_Full ,
222
+ .bit = ETHTOOL_LINK_MODE_10000baseT_Full_BIT ,
223
223
},
224
224
{
225
225
.speed = SPEED_2500 ,
226
226
.duplex = DUPLEX_FULL ,
227
- .setting = SUPPORTED_2500baseX_Full ,
227
+ .bit = ETHTOOL_LINK_MODE_2500baseX_Full_BIT ,
228
228
},
229
229
{
230
230
.speed = SPEED_1000 ,
231
231
.duplex = DUPLEX_FULL ,
232
- .setting = SUPPORTED_1000baseKX_Full ,
232
+ .bit = ETHTOOL_LINK_MODE_1000baseKX_Full_BIT ,
233
233
},
234
234
{
235
235
.speed = SPEED_1000 ,
236
236
.duplex = DUPLEX_FULL ,
237
- .setting = SUPPORTED_1000baseT_Full ,
237
+ .bit = ETHTOOL_LINK_MODE_1000baseT_Full_BIT ,
238
238
},
239
239
{
240
240
.speed = SPEED_1000 ,
241
241
.duplex = DUPLEX_HALF ,
242
- .setting = SUPPORTED_1000baseT_Half ,
242
+ .bit = ETHTOOL_LINK_MODE_1000baseT_Half_BIT ,
243
243
},
244
244
{
245
245
.speed = SPEED_100 ,
246
246
.duplex = DUPLEX_FULL ,
247
- .setting = SUPPORTED_100baseT_Full ,
247
+ .bit = ETHTOOL_LINK_MODE_100baseT_Full_BIT ,
248
248
},
249
249
{
250
250
.speed = SPEED_100 ,
251
251
.duplex = DUPLEX_HALF ,
252
- .setting = SUPPORTED_100baseT_Half ,
252
+ .bit = ETHTOOL_LINK_MODE_100baseT_Half_BIT ,
253
253
},
254
254
{
255
255
.speed = SPEED_10 ,
256
256
.duplex = DUPLEX_FULL ,
257
- .setting = SUPPORTED_10baseT_Full ,
257
+ .bit = ETHTOOL_LINK_MODE_10baseT_Full_BIT ,
258
258
},
259
259
{
260
260
.speed = SPEED_10 ,
261
261
.duplex = DUPLEX_HALF ,
262
- .setting = SUPPORTED_10baseT_Half ,
262
+ .bit = ETHTOOL_LINK_MODE_10baseT_Half_BIT ,
263
263
},
264
264
};
265
265
266
266
/**
267
267
* phy_lookup_setting - lookup a PHY setting
268
268
* @speed: speed to match
269
269
* @duplex: duplex to match
270
- * @features: allowed link modes
270
+ * @mask: allowed link modes
271
+ * @maxbit: bit size of link modes
271
272
* @exact: an exact match is required
272
273
*
273
274
* Search the settings array for a setting that matches the speed and
@@ -281,13 +282,14 @@ static const struct phy_setting settings[] = {
281
282
* they all fail, %NULL will be returned.
282
283
*/
283
284
static const struct phy_setting *
284
- phy_lookup_setting (int speed , int duplex , u32 features , bool exact )
285
+ phy_lookup_setting (int speed , int duplex , const unsigned long * mask ,
286
+ size_t maxbit , bool exact )
285
287
{
286
288
const struct phy_setting * p , * match = NULL , * last = NULL ;
287
289
int i ;
288
290
289
291
for (i = 0 , p = settings ; i < ARRAY_SIZE (settings ); i ++ , p ++ ) {
290
- if (p -> setting & features ) {
292
+ if (p -> bit < maxbit && test_bit ( p -> bit , mask ) ) {
291
293
last = p ;
292
294
if (p -> speed == speed && p -> duplex == duplex ) {
293
295
/* Exact match for speed and duplex */
@@ -326,7 +328,9 @@ phy_lookup_setting(int speed, int duplex, u32 features, bool exact)
326
328
static const struct phy_setting *
327
329
phy_find_valid (int speed , int duplex , u32 supported )
328
330
{
329
- return phy_lookup_setting (speed , duplex , supported , false);
331
+ unsigned long mask = supported ;
332
+
333
+ return phy_lookup_setting (speed , duplex , & mask , BITS_PER_LONG , false);
330
334
}
331
335
332
336
/**
@@ -343,12 +347,14 @@ unsigned int phy_supported_speeds(struct phy_device *phy,
343
347
unsigned int * speeds ,
344
348
unsigned int size )
345
349
{
350
+ unsigned long supported = phy -> supported ;
346
351
unsigned int count = 0 ;
347
352
unsigned int idx = 0 ;
348
353
349
354
for (idx = 0 ; idx < ARRAY_SIZE (settings ) && count < size ; idx ++ )
350
355
/* Assumes settings are grouped by speed */
351
- if ((settings [idx ].setting & phy -> supported ) &&
356
+ if (settings [idx ].bit < BITS_PER_LONG &&
357
+ !test_bit (settings [idx ].bit , & supported ) &&
352
358
(count == 0 || speeds [count - 1 ] != settings [idx ].speed ))
353
359
speeds [count ++ ] = settings [idx ].speed ;
354
360
@@ -366,7 +372,9 @@ unsigned int phy_supported_speeds(struct phy_device *phy,
366
372
*/
367
373
static inline bool phy_check_valid (int speed , int duplex , u32 features )
368
374
{
369
- return !!phy_lookup_setting (speed , duplex , features , true);
375
+ unsigned long mask = features ;
376
+
377
+ return !!phy_lookup_setting (speed , duplex , & mask , BITS_PER_LONG , true);
370
378
}
371
379
372
380
/**
0 commit comments