xref: /linux/drivers/net/phy/phy-caps.h (revision 1a9239bb4253f9076b5b4b2a1a4e8d7defd77a95)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * link caps internal header, for link modes <-> capabilities <-> interfaces
4  * conversions.
5  */
6 
7 #ifndef __PHY_CAPS_H
8 #define __PHY_CAPS_H
9 
10 #include <linux/ethtool.h>
11 #include <linux/phy.h>
12 
13 enum {
14 	LINK_CAPA_10HD = 0,
15 	LINK_CAPA_10FD,
16 	LINK_CAPA_100HD,
17 	LINK_CAPA_100FD,
18 	LINK_CAPA_1000HD,
19 	LINK_CAPA_1000FD,
20 	LINK_CAPA_2500FD,
21 	LINK_CAPA_5000FD,
22 	LINK_CAPA_10000FD,
23 	LINK_CAPA_20000FD,
24 	LINK_CAPA_25000FD,
25 	LINK_CAPA_40000FD,
26 	LINK_CAPA_50000FD,
27 	LINK_CAPA_56000FD,
28 	LINK_CAPA_100000FD,
29 	LINK_CAPA_200000FD,
30 	LINK_CAPA_400000FD,
31 	LINK_CAPA_800000FD,
32 
33 	__LINK_CAPA_MAX,
34 };
35 
36 #define LINK_CAPA_ALL	GENMASK((__LINK_CAPA_MAX - 1), 0)
37 
38 struct link_capabilities {
39 	int speed;
40 	unsigned int duplex;
41 	__ETHTOOL_DECLARE_LINK_MODE_MASK(linkmodes);
42 };
43 
44 int phy_caps_init(void);
45 
46 size_t phy_caps_speeds(unsigned int *speeds, size_t size,
47 		       unsigned long *linkmodes);
48 void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes);
49 bool phy_caps_valid(int speed, int duplex, const unsigned long *linkmodes);
50 void phy_caps_linkmodes(unsigned long caps, unsigned long *linkmodes);
51 unsigned long phy_caps_from_interface(phy_interface_t interface);
52 
53 const struct link_capabilities *
54 phy_caps_lookup_by_linkmode(const unsigned long *linkmodes);
55 
56 const struct link_capabilities *
57 phy_caps_lookup_by_linkmode_rev(const unsigned long *linkmodes, bool fdx_only);
58 
59 const struct link_capabilities *
60 phy_caps_lookup(int speed, unsigned int duplex, const unsigned long *supported,
61 		bool exact);
62 
63 #endif /* __PHY_CAPS_H */
64