Skip to content

Commit 1f9127c

Browse files
Zach Browndavem330
authored andcommitted
net: phy: Create phy_supported_speeds function which lists speeds currently supported by a phydevice
phy_supported_speeds provides a means to get a list of all the speeds a phy device currently supports. Signed-off-by: Zach Brown <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 61a1796 commit 1f9127c

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

drivers/net/phy/phy.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,41 @@ static inline unsigned int phy_find_valid(unsigned int idx, u32 features)
260260
return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1;
261261
}
262262

263+
/**
264+
* phy_supported_speeds - return all speeds currently supported by a phy device
265+
* @phy: The phy device to return supported speeds of.
266+
* @speeds: buffer to store supported speeds in.
267+
* @size: size of speeds buffer.
268+
*
269+
* Description: Returns the number of supported speeds, and fills the speeds
270+
* buffer with the supported speeds. If speeds buffer is too small to contain
271+
* all currently supported speeds, will return as many speeds as can fit.
272+
*/
273+
unsigned int phy_supported_speeds(struct phy_device *phy,
274+
unsigned int *speeds,
275+
unsigned int size)
276+
{
277+
unsigned int count = 0;
278+
unsigned int idx = 0;
279+
280+
while (idx < MAX_NUM_SETTINGS && count < size) {
281+
idx = phy_find_valid(idx, phy->supported);
282+
283+
if (!(settings[idx].setting & phy->supported))
284+
break;
285+
286+
/* Assumes settings are grouped by speed */
287+
if ((count == 0) ||
288+
(speeds[count - 1] != settings[idx].speed)) {
289+
speeds[count] = settings[idx].speed;
290+
count++;
291+
}
292+
idx++;
293+
}
294+
295+
return count;
296+
}
297+
263298
/**
264299
* phy_check_valid - check if there is a valid PHY setting which matches
265300
* speed, duplex, and feature mask

include/linux/phy.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ typedef enum {
8484
PHY_INTERFACE_MODE_MAX,
8585
} phy_interface_t;
8686

87+
/**
88+
* phy_supported_speeds - return all speeds currently supported by a phy device
89+
* @phy: The phy device to return supported speeds of.
90+
* @speeds: buffer to store supported speeds in.
91+
* @size: size of speeds buffer.
92+
*
93+
* Description: Returns the number of supported speeds, and
94+
* fills the speeds * buffer with the supported speeds. If speeds buffer is
95+
* too small to contain * all currently supported speeds, will return as
96+
* many speeds as can fit.
97+
*/
98+
unsigned int phy_supported_speeds(struct phy_device *phy,
99+
unsigned int *speeds,
100+
unsigned int size);
101+
87102
/**
88103
* It maps 'enum phy_interface_t' found in include/linux/phy.h
89104
* into the device tree binding of 'phy-mode', so that Ethernet

0 commit comments

Comments
 (0)