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