Skip to content

Commit 9fe1450

Browse files
committed
Merge branch 'net-remove-last-of-the-phylink-validate-methods-and-clean-up'
Russell King says: ==================== net: remove last of the phylink validate methods and clean up This four patch series removes the last of the phylink MAC .validate methods which can be found in the Freescale fman driver. fman has a requirement that half duplex may not be supported in RGMII mode, which is currently handled in its .validate method. In order to keep this functionality when removing the .validate method, we need to replace that with equivalent functionality, for which I propose the optional .mac_get_caps method in the first patch. The advantage of this approach over the .validate callback is that MAC drivers only have to deal with the MAC_* capabilities, and don't need to call back into phylink functions to do the masking of the ethtool linkmodes etc - which then becomes internal to phylink. This can be seen in the fourth patch where we make a load of these methods static. ==================== Link: https://lore.kernel.org/r/ZS1Z5DDfHyjMryYu@shell.armlinux.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 73b24e7 + 743f639 commit 9fe1450

File tree

4 files changed

+37
-85
lines changed

4 files changed

+37
-85
lines changed

Documentation/networking/sfp-phylink.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ this documentation.
200200
when the in-band link state changes - otherwise the link will never
201201
come up.
202202

203-
The :c:func:`validate` method should mask the supplied supported mask,
204-
and ``state->advertising`` with the supported ethtool link modes.
205-
These are the new ethtool link modes, so bitmask operations must be
206-
used. For an example, see ``drivers/net/ethernet/marvell/mvneta.c``.
203+
The :c:func:`mac_get_caps` method is optional, and if provided should
204+
return the phylink MAC capabilities that are supported for the passed
205+
``interface`` mode. In general, there is no need to implement this method.
206+
Phylink will use these capabilities in combination with permissible
207+
capabilities for ``interface`` to determine the allowable ethtool link
208+
modes.
207209

208210
The :c:func:`mac_link_state` method is used to read the link state
209211
from the MAC, and report back the settings that the MAC is currently

drivers/net/ethernet/freescale/fman/fman_memac.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,17 @@ static int memac_accept_rx_pause_frames(struct fman_mac *memac, bool en)
618618
return 0;
619619
}
620620

621-
static void memac_validate(struct phylink_config *config,
622-
unsigned long *supported,
623-
struct phylink_link_state *state)
621+
static unsigned long memac_get_caps(struct phylink_config *config,
622+
phy_interface_t interface)
624623
{
625624
struct fman_mac *memac = fman_config_to_mac(config)->fman_mac;
626625
unsigned long caps = config->mac_capabilities;
627626

628-
if (phy_interface_mode_is_rgmii(state->interface) &&
627+
if (phy_interface_mode_is_rgmii(interface) &&
629628
memac->rgmii_no_half_duplex)
630629
caps &= ~(MAC_10HD | MAC_100HD);
631630

632-
phylink_validate_mask_caps(supported, state, caps);
631+
return caps;
633632
}
634633

635634
/**
@@ -776,7 +775,7 @@ static void memac_link_down(struct phylink_config *config, unsigned int mode,
776775
}
777776

778777
static const struct phylink_mac_ops memac_mac_ops = {
779-
.validate = memac_validate,
778+
.mac_get_caps = memac_get_caps,
780779
.mac_select_pcs = memac_select_pcs,
781780
.mac_prepare = memac_prepare,
782781
.mac_config = memac_mac_config,

drivers/net/phy/phylink.c

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ static int phylink_interface_max_speed(phy_interface_t interface)
257257
* Set all possible pause, speed and duplex linkmodes in @linkmodes that are
258258
* supported by the @caps. @linkmodes must have been initialised previously.
259259
*/
260-
void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps)
260+
static void phylink_caps_to_linkmodes(unsigned long *linkmodes,
261+
unsigned long caps)
261262
{
262263
if (caps & MAC_SYM_PAUSE)
263264
__set_bit(ETHTOOL_LINK_MODE_Pause_BIT, linkmodes);
@@ -400,7 +401,6 @@ void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps)
400401
__set_bit(ETHTOOL_LINK_MODE_400000baseCR4_Full_BIT, linkmodes);
401402
}
402403
}
403-
EXPORT_SYMBOL_GPL(phylink_caps_to_linkmodes);
404404

405405
static struct {
406406
unsigned long mask;
@@ -477,9 +477,9 @@ static unsigned long phylink_cap_from_speed_duplex(int speed,
477477
* Get the MAC capabilities that are supported by the @interface mode and
478478
* @mac_capabilities.
479479
*/
480-
unsigned long phylink_get_capabilities(phy_interface_t interface,
481-
unsigned long mac_capabilities,
482-
int rate_matching)
480+
static unsigned long phylink_get_capabilities(phy_interface_t interface,
481+
unsigned long mac_capabilities,
482+
int rate_matching)
483483
{
484484
int max_speed = phylink_interface_max_speed(interface);
485485
unsigned long caps = MAC_SYM_PAUSE | MAC_ASYM_PAUSE;
@@ -606,7 +606,6 @@ unsigned long phylink_get_capabilities(phy_interface_t interface,
606606

607607
return (caps & mac_capabilities) | matched_caps;
608608
}
609-
EXPORT_SYMBOL_GPL(phylink_get_capabilities);
610609

611610
/**
612611
* phylink_validate_mask_caps() - Restrict link modes based on caps
@@ -618,9 +617,9 @@ EXPORT_SYMBOL_GPL(phylink_get_capabilities);
618617
* @supported and @state based on that. Use this function if your capabiliies
619618
* aren't constant, such as if they vary depending on the interface.
620619
*/
621-
void phylink_validate_mask_caps(unsigned long *supported,
622-
struct phylink_link_state *state,
623-
unsigned long mac_capabilities)
620+
static void phylink_validate_mask_caps(unsigned long *supported,
621+
struct phylink_link_state *state,
622+
unsigned long mac_capabilities)
624623
{
625624
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
626625
unsigned long caps;
@@ -634,29 +633,12 @@ void phylink_validate_mask_caps(unsigned long *supported,
634633
linkmode_and(supported, supported, mask);
635634
linkmode_and(state->advertising, state->advertising, mask);
636635
}
637-
EXPORT_SYMBOL_GPL(phylink_validate_mask_caps);
638-
639-
/**
640-
* phylink_generic_validate() - generic validate() callback implementation
641-
* @config: a pointer to a &struct phylink_config.
642-
* @supported: ethtool bitmask for supported link modes.
643-
* @state: a pointer to a &struct phylink_link_state.
644-
*
645-
* Generic implementation of the validate() callback that MAC drivers can
646-
* use when they pass the range of supported interfaces and MAC capabilities.
647-
*/
648-
void phylink_generic_validate(struct phylink_config *config,
649-
unsigned long *supported,
650-
struct phylink_link_state *state)
651-
{
652-
phylink_validate_mask_caps(supported, state, config->mac_capabilities);
653-
}
654-
EXPORT_SYMBOL_GPL(phylink_generic_validate);
655636

656637
static int phylink_validate_mac_and_pcs(struct phylink *pl,
657638
unsigned long *supported,
658639
struct phylink_link_state *state)
659640
{
641+
unsigned long capabilities;
660642
struct phylink_pcs *pcs;
661643
int ret;
662644

@@ -696,10 +678,13 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
696678
}
697679

698680
/* Then validate the link parameters with the MAC */
699-
if (pl->mac_ops->validate)
700-
pl->mac_ops->validate(pl->config, supported, state);
681+
if (pl->mac_ops->mac_get_caps)
682+
capabilities = pl->mac_ops->mac_get_caps(pl->config,
683+
state->interface);
701684
else
702-
phylink_generic_validate(pl->config, supported, state);
685+
capabilities = pl->config->mac_capabilities;
686+
687+
phylink_validate_mask_caps(supported, state, capabilities);
703688

704689
return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
705690
}

include/linux/phylink.h

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed);
227227

228228
/**
229229
* struct phylink_mac_ops - MAC operations structure.
230-
* @validate: Validate and update the link configuration.
230+
* @mac_get_caps: Get MAC capabilities for interface mode.
231231
* @mac_select_pcs: Select a PCS for the interface mode.
232232
* @mac_prepare: prepare for a major reconfiguration of the interface.
233233
* @mac_config: configure the MAC for the selected mode and state.
@@ -238,9 +238,8 @@ void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed);
238238
* The individual methods are described more fully below.
239239
*/
240240
struct phylink_mac_ops {
241-
void (*validate)(struct phylink_config *config,
242-
unsigned long *supported,
243-
struct phylink_link_state *state);
241+
unsigned long (*mac_get_caps)(struct phylink_config *config,
242+
phy_interface_t interface);
244243
struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
245244
phy_interface_t interface);
246245
int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
@@ -259,39 +258,17 @@ struct phylink_mac_ops {
259258

260259
#if 0 /* For kernel-doc purposes only. */
261260
/**
262-
* validate - Validate and update the link configuration
261+
* mac_get_caps: Get MAC capabilities for interface mode.
263262
* @config: a pointer to a &struct phylink_config.
264-
* @supported: ethtool bitmask for supported link modes.
265-
* @state: a pointer to a &struct phylink_link_state.
266-
*
267-
* Clear bits in the @supported and @state->advertising masks that
268-
* are not supportable by the MAC.
269-
*
270-
* Note that the PHY may be able to transform from one connection
271-
* technology to another, so, eg, don't clear 1000BaseX just
272-
* because the MAC is unable to BaseX mode. This is more about
273-
* clearing unsupported speeds and duplex settings. The port modes
274-
* should not be cleared; phylink_set_port_modes() will help with this.
275-
*
276-
* When @config->supported_interfaces has been set, phylink will iterate
277-
* over the supported interfaces to determine the full capability of the
278-
* MAC. The validation function must not print errors if @state->interface
279-
* is set to an unexpected value.
263+
* @interface: PHY interface mode.
280264
*
281-
* When @config->supported_interfaces is empty, phylink will call this
282-
* function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
283-
* expects the MAC driver to return all supported link modes.
284-
*
285-
* If the @state->interface mode is not supported, then the @supported
286-
* mask must be cleared.
287-
*
288-
* This member is optional; if not set, the generic validator will be
289-
* used making use of @config->mac_capabilities and
290-
* @config->supported_interfaces to determine which link modes are
291-
* supported.
265+
* Optional method. When not provided, config->mac_capabilities will be used.
266+
* When implemented, this returns the MAC capabilities for the specified
267+
* interface mode where there is some special handling required by the MAC
268+
* driver (e.g. not supporting half-duplex in certain interface modes.)
292269
*/
293-
void validate(struct phylink_config *config, unsigned long *supported,
294-
struct phylink_link_state *state);
270+
unsigned long mac_get_caps(struct phylink_config *config,
271+
phy_interface_t interface);
295272
/**
296273
* mac_select_pcs: Select a PCS for the interface mode.
297274
* @config: a pointer to a &struct phylink_config.
@@ -636,17 +613,6 @@ void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
636613
phy_interface_t interface, int speed, int duplex);
637614
#endif
638615

639-
void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
640-
unsigned long phylink_get_capabilities(phy_interface_t interface,
641-
unsigned long mac_capabilities,
642-
int rate_matching);
643-
void phylink_validate_mask_caps(unsigned long *supported,
644-
struct phylink_link_state *state,
645-
unsigned long caps);
646-
void phylink_generic_validate(struct phylink_config *config,
647-
unsigned long *supported,
648-
struct phylink_link_state *state);
649-
650616
struct phylink *phylink_create(struct phylink_config *,
651617
const struct fwnode_handle *,
652618
phy_interface_t,

0 commit comments

Comments
 (0)