06c348b1cdfa78a40579e52d65255a5569e85879
[openwrt/staging/pepe2k.git] /
1 From bf4de031052fe7c5309e8956c342d4e5ce79038e Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Mon, 17 Oct 2022 16:22:35 -0400
4 Subject: [PATCH 04/21] net: phylink: provide phylink_validate_mask_caps()
5 helper
6
7 Provide a helper that restricts the link modes according to the
8 phylink capabilities.
9
10 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
11 [rebased on net-next/master and added documentation]
12 Signed-off-by: Sean Anderson <sean.anderson@seco.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/net/phy/phylink.c | 41 +++++++++++++++++++++++++++------------
16 include/linux/phylink.h | 3 +++
17 2 files changed, 32 insertions(+), 12 deletions(-)
18
19 --- a/drivers/net/phy/phylink.c
20 +++ b/drivers/net/phy/phylink.c
21 @@ -564,31 +564,48 @@ unsigned long phylink_get_capabilities(p
22 EXPORT_SYMBOL_GPL(phylink_get_capabilities);
23
24 /**
25 - * phylink_generic_validate() - generic validate() callback implementation
26 - * @config: a pointer to a &struct phylink_config.
27 + * phylink_validate_mask_caps() - Restrict link modes based on caps
28 * @supported: ethtool bitmask for supported link modes.
29 - * @state: a pointer to a &struct phylink_link_state.
30 + * @state: an (optional) pointer to a &struct phylink_link_state.
31 + * @mac_capabilities: bitmask of MAC capabilities
32 *
33 - * Generic implementation of the validate() callback that MAC drivers can
34 - * use when they pass the range of supported interfaces and MAC capabilities.
35 - * This makes use of phylink_get_linkmodes().
36 + * Calculate the supported link modes based on @mac_capabilities, and restrict
37 + * @supported and @state based on that. Use this function if your capabiliies
38 + * aren't constant, such as if they vary depending on the interface.
39 */
40 -void phylink_generic_validate(struct phylink_config *config,
41 - unsigned long *supported,
42 - struct phylink_link_state *state)
43 +void phylink_validate_mask_caps(unsigned long *supported,
44 + struct phylink_link_state *state,
45 + unsigned long mac_capabilities)
46 {
47 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
48 unsigned long caps;
49
50 phylink_set_port_modes(mask);
51 phylink_set(mask, Autoneg);
52 - caps = phylink_get_capabilities(state->interface,
53 - config->mac_capabilities,
54 + caps = phylink_get_capabilities(state->interface, mac_capabilities,
55 state->rate_matching);
56 phylink_caps_to_linkmodes(mask, caps);
57
58 linkmode_and(supported, supported, mask);
59 - linkmode_and(state->advertising, state->advertising, mask);
60 + if (state)
61 + linkmode_and(state->advertising, state->advertising, mask);
62 +}
63 +EXPORT_SYMBOL_GPL(phylink_validate_mask_caps);
64 +
65 +/**
66 + * phylink_generic_validate() - generic validate() callback implementation
67 + * @config: a pointer to a &struct phylink_config.
68 + * @supported: ethtool bitmask for supported link modes.
69 + * @state: a pointer to a &struct phylink_link_state.
70 + *
71 + * Generic implementation of the validate() callback that MAC drivers can
72 + * use when they pass the range of supported interfaces and MAC capabilities.
73 + */
74 +void phylink_generic_validate(struct phylink_config *config,
75 + unsigned long *supported,
76 + struct phylink_link_state *state)
77 +{
78 + phylink_validate_mask_caps(supported, state, config->mac_capabilities);
79 }
80 EXPORT_SYMBOL_GPL(phylink_generic_validate);
81
82 --- a/include/linux/phylink.h
83 +++ b/include/linux/phylink.h
84 @@ -558,6 +558,9 @@ void phylink_caps_to_linkmodes(unsigned
85 unsigned long phylink_get_capabilities(phy_interface_t interface,
86 unsigned long mac_capabilities,
87 int rate_matching);
88 +void phylink_validate_mask_caps(unsigned long *supported,
89 + struct phylink_link_state *state,
90 + unsigned long caps);
91 void phylink_generic_validate(struct phylink_config *config,
92 unsigned long *supported,
93 struct phylink_link_state *state);