Convert xpcs to phylink_pcs_ops
Subsystems (6)
v3 cover Convert xpcs to phylink_pcs_ops
From: Vladimir Oltean <[email protected]>
Background: the sja1105 DSA driver currently drives a Designware XPCS for SGMII and 2500base-X, and it would be nice to reuse some code with the xpcs module. This would also help consolidate the phylink_pcs_ops, since the only other dedicated PCS driver, currently, is the lynx_pcs.
Therefore, this series makes the xpcs expose the same kind of API that the lynx_pcs module does. The main changes are getting rid of struct mdio_xpcs_ops, being compatible with struct phylink_pcs_ops and being less reliant on the phy_interface_t passed to xpcs_probe (now renamed to xpcs_create).
This patch series is partially tested (some code paths have been covered on the NXP SJA1105 and some others with the help of Vee Khee Wong on Intel Tiger Lake / stmmac) but further testing on 10G setups would be appreciated, if possible.
Vladimir Oltean (9):
net: pcs: xpcs: delete shim definition for mdio_xpcs_get_ops()
net: pcs: xpcs: there is only one PHY ID
net: pcs: xpcs: make the checks related to the PHY interface mode
stateless
net: pcs: xpcs: export xpcs_validate
net: pcs: xpcs: export xpcs_config_eee
net: pcs: xpcs: export xpcs_probe
net: pcs: xpcs: use mdiobus_c45_addr in xpcs_{read,write}
net: pcs: xpcs: convert to mdio_device
net: pcs: xpcs: convert to phylink_pcs_ops
drivers/net/ethernet/stmicro/stmmac/common.h | 3 +- drivers/net/ethernet/stmicro/stmmac/hwif.h | 14 - .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 12 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 39 +- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 47 +-- drivers/net/pcs/pcs-xpcs.c | 395 ++++++++++++------ include/linux/pcs/pcs-xpcs.h | 40 +- 7 files changed, 319 insertions(+), 231 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/9 net: pcs: xpcs: delete shim definition for mdio_xpcs_get_ops()
From: Vladimir Oltean <[email protected]>
CONFIG_STMMAC_ETH selects CONFIG_PCS_XPCS, so there should be no situation where the shim should be needed.
---v1->v2: nonev2->v3: none
include/linux/pcs/pcs-xpcs.h | 7 ------- 1 file changed, 7 deletions(-)
include/linux/pcs/pcs-xpcs.h +0 -7
@@ -36,13 +36,6 @@ struct mdio_xpcs_ops { int enable); }; -#if IS_ENABLED (CONFIG_PCS_XPCS )struct mdio_xpcs_ops *mdio_xpcs_get_ops (void ); -#else -static inline struct mdio_xpcs_ops *mdio_xpcs_get_ops (void ) -{ -return NULL ; -} -#endif #endif /* __LINUX_PCS_XPCS_H */
Signature · 1 line
2.25.1
PATCH v3 2/9 net: pcs: xpcs: there is only one PHY ID
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The xpcs driver has an apparently inadequate structure for the actual hardware it drives.
These defines and the xpcs_probe() function would suggest that there is one PHY ID per supported PHY interface type, and the driver simply validates whether the mode it should operate in (the argument of xpcs_probe) matches what the hardware is capable of:
#define SYNOPSYS_XPCS_USXGMII_ID 0x7996ced0 #define SYNOPSYS_XPCS_10GKR_ID 0x7996ced0 #define SYNOPSYS_XPCS_XLGMII_ID 0x7996ced0 #define SYNOPSYS_XPCS_SGMII_ID 0x7996ced0 #define SYNOPSYS_XPCS_MASK 0xffffffff
but that is not the case, because upon closer inspection, all the above 4 PHY ID definitions are in fact equal.
So it is the same XPCS that is compatible with all 4 sets of PHY interface types.
This change introduces an array of struct xpcs_compat which is populated by the single struct xpcs_id instance. It also eliminates the bogus defines for multiple Synopsys XPCS PHY IDs and replaces them with a single XPCS_ID, which better reflects the way in which the hardware operates.
Because we are touching this area of the code anyway, the new array of struct xpcs_compat, as well as the array of xpcs_id, have been moved towards the end of the file, since they are variable declarations not definitions. If whichever of struct xpcs_compat or struct xpcs_id need to gain a function pointer member in the future, it is easier to reference functions (no forward declarations needed) if we have the const variable declarations at the end of the file.
---v1->v2: patch is newv2->v3: move the xpcs_compat and xpcs_id declarations at the end, as
well as note this in the commit message (needed for sja1105 support)
drivers/net/pcs/pcs-xpcs.c | 129 ++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 51 deletions(-)
drivers/net/pcs/pcs-xpcs.c +78 -51
@@ -12,10 +12,7 @@#include <linux/phylink.h> #include <linux/workqueue.h> -#define SYNOPSYS_XPCS_USXGMII_ID 0x7996ced0 -#define SYNOPSYS_XPCS_10GKR_ID 0x7996ced0 -#define SYNOPSYS_XPCS_XLGMII_ID 0x7996ced0 -#define SYNOPSYS_XPCS_SGMII_ID 0x7996ced0 +#define SYNOPSYS_XPCS_ID 0x7996ced0#define SYNOPSYS_XPCS_MASK 0xffffffff/* Vendor regs access */
@@ -163,56 +160,39 @@ static const int xpcs_sgmii_features[] = {static const phy_interface_t xpcs_usxgmii_interfaces[] = {PHY_INTERFACE_MODE_USXGMII , -PHY_INTERFACE_MODE_MAX , };static const phy_interface_t xpcs_10gkr_interfaces[] = {PHY_INTERFACE_MODE_10GKR , -PHY_INTERFACE_MODE_MAX , };static const phy_interface_t xpcs_xlgmii_interfaces[] = {PHY_INTERFACE_MODE_XLGMII , -PHY_INTERFACE_MODE_MAX , };static const phy_interface_t xpcs_sgmii_interfaces[] = {PHY_INTERFACE_MODE_SGMII , -PHY_INTERFACE_MODE_MAX , }; -static struct xpcs_id { -u32 id; -u32 mask; +enum { +DW_XPCS_USXGMII , +DW_XPCS_10GKR , +DW_XPCS_XLGMII , +DW_XPCS_SGMII , +DW_XPCS_INTERFACE_MAX , +}; + +struct xpcs_compat {const int *supported;const phy_interface_t *interface; +int num_interfaces;int an_mode; -} xpcs_id_list[] = { - { - .id =SYNOPSYS_XPCS_USXGMII_ID , - .mask =SYNOPSYS_XPCS_MASK , - .supported = xpcs_usxgmii_features, - .interface = xpcs_usxgmii_interfaces, - .an_mode =DW_AN_C73 , - }, { - .id =SYNOPSYS_XPCS_10GKR_ID , - .mask =SYNOPSYS_XPCS_MASK , - .supported = xpcs_10gkr_features, - .interface = xpcs_10gkr_interfaces, - .an_mode =DW_AN_C73 , - }, { - .id =SYNOPSYS_XPCS_XLGMII_ID , - .mask =SYNOPSYS_XPCS_MASK , - .supported = xpcs_xlgmii_features, - .interface = xpcs_xlgmii_interfaces, - .an_mode =DW_AN_C73 , - }, { - .id =SYNOPSYS_XPCS_SGMII_ID , - .mask =SYNOPSYS_XPCS_MASK , - .supported = xpcs_sgmii_features, - .interface = xpcs_sgmii_interfaces, - .an_mode =DW_AN_C37_SGMII , - }, +}; + +struct xpcs_id { +u32 id; +u32 mask; +const struct xpcs_compat *compat; };static int xpcs_read (struct mdio_xpcs_args *xpcs,int dev,u32 reg)
@@ -911,35 +891,82 @@ static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs) }static bool xpcs_check_features (struct mdio_xpcs_args *xpcs, -struct xpcs_id *match, +const struct xpcs_id *match,phy_interface_t interface) { -int i; +int i, j; -for (i =0 ; match->interface[i] !=PHY_INTERFACE_MODE_MAX ; i++) { -if (match->interface[i] == interface) -break ; - } +for (i =0 ; i <DW_XPCS_INTERFACE_MAX ; i++) { +const struct xpcs_compat *compat = &match->compat[i]; +bool supports_interface = false; -if (match->interface[i] ==PHY_INTERFACE_MODE_MAX ) -return false; +for (j =0 ; j < compat->num_interfaces; j++) { +if (compat->interface[j] == interface) { + supports_interface = true; +break ; + } + } + +if (!supports_interface) +continue ; -for (i =0 ; match->supported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++) -set_bit (match->supported[i], xpcs->supported); +/* Populate the supported link modes for this +* PHY interface type +*/ +for (j =0 ; compat->supported[j] != __ETHTOOL_LINK_MODE_MASK_NBITS; j++) +set_bit (compat->supported[j], xpcs->supported); - xpcs->an_mode = match->an_mode; + xpcs->an_mode = compat->an_mode; -return true; +return true; + } + +return false; } +static const struct xpcs_compat synopsys_xpcs_compat[DW_XPCS_INTERFACE_MAX ] = { + [DW_XPCS_USXGMII ] = { + .supported = xpcs_usxgmii_features, + .interface = xpcs_usxgmii_interfaces, + .num_interfaces =ARRAY_SIZE (xpcs_usxgmii_interfaces), + .an_mode =DW_AN_C73 , + }, + [DW_XPCS_10GKR ] = { + .supported = xpcs_10gkr_features, + .interface = xpcs_10gkr_interfaces, + .num_interfaces =ARRAY_SIZE (xpcs_10gkr_interfaces), + .an_mode =DW_AN_C73 , + }, + [DW_XPCS_XLGMII ] = { + .supported = xpcs_xlgmii_features, + .interface = xpcs_xlgmii_interfaces, + .num_interfaces =ARRAY_SIZE (xpcs_xlgmii_interfaces), + .an_mode =DW_AN_C73 , + }, + [DW_XPCS_SGMII ] = { + .supported = xpcs_sgmii_features, + .interface = xpcs_sgmii_interfaces, + .num_interfaces =ARRAY_SIZE (xpcs_sgmii_interfaces), + .an_mode =DW_AN_C37_SGMII , + }, +}; + +static const struct xpcs_id xpcs_id_list[] = { + { + .id =SYNOPSYS_XPCS_ID , + .mask =SYNOPSYS_XPCS_MASK , + .compat = synopsys_xpcs_compat, + }, +}; +static int xpcs_probe (struct mdio_xpcs_args *xpcs,phy_interface_t interface) { +const struct xpcs_id *match =NULL ;u32 xpcs_id =xpcs_get_id (xpcs); -struct xpcs_id *match =NULL ;int i;for (i =0 ; i <ARRAY_SIZE (xpcs_id_list); i++) { -struct xpcs_id *entry = &xpcs_id_list[i]; +const struct xpcs_id *entry = &xpcs_id_list[i];if ((xpcs_id & entry->mask) == entry->id) { match = entry;
Signature · 1 line
2.25.1
PATCH v3 3/9 net: pcs: xpcs: make the checks related to the PHY interface mode stateless
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The operating mode of the driver is currently to populate its struct mdio_xpcs_args::supported and struct mdio_xpcs_args::an_mode statically in xpcs_probe(), based on the passed phy_interface_t, and work with those.
However this is not the operation that phylink expects from a PCS driver, because the port might be attached to an SFP cage that triggers changes of the phy_interface_t dynamically as one SFP module is unpluggged and another is plugged.
To migrate towards that model, the struct mdio_xpcs_args should not cache anything related to the phy_interface_t, but just look up the statically defined, const struct xpcs_compat structure corresponding to the detected PCS OUI/model number.
So we delete the "supported" and "an_mode" members of struct mdio_xpcs_args, and add the "id" structure there (since the ID is not expected to change at runtime).
Since xpcs->supported is used deep in the code in _xpcs_config_aneg_c73(), we need to modify some function headers to pass the xpcs_compat from all callers. In turn, the xpcs_compat is always supplied externally to the xpcs module:
- Most of the time by phylink
- In xpcs_probe() it is needed because xpcs_soft_reset() writes to MDIO_MMD_PCS or to MDIO_MMD_VEND2 depending on whether an_mode is clause 37 or clause 73. In order to not introduce functional changes related to when the soft reset is issued, we continue to require the initial phy_interface_t argument to be passed to xpcs_probe() so we can pass this on to xpcs_soft_reset().
- stmmac_open() wants to know whether to call stmmac_init_phy() or not, and for that it looks inside xpcs->an_mode, because the clause 73 (backplane) AN modes supposedly do not have a PHY. Because we moved an_mode outside of struct mdio_xpcs_args, this is now no longer directly possible, so we introduce a helper function xpcs_get_an_mode() which protects the data encapsulation of the xpcs module and requires a phy_interface_t to be passed as argument. This function can look up the appropriate compat based on the phy_interface_t.
---v1->v2: nonev2->v3: none
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +- drivers/net/pcs/pcs-xpcs.c | 175 +++++++++++------- include/linux/pcs/pcs-xpcs.h | 6 +- 3 files changed, 120 insertions(+), 65 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -1
@@ -3637,6 +3637,7 @@ static int stmmac_request_irq(struct net_device *dev)int stmmac_open (struct net_device *dev) {struct stmmac_priv *priv =netdev_priv (dev); +int mode = priv->plat->phy_interface;int bfsize =0 ;u32 chan;int ret;
@@ -3649,7 +3650,8 @@ int stmmac_open(struct net_device *dev)if (priv->hw->pcs !=STMMAC_PCS_TBI && priv->hw->pcs !=STMMAC_PCS_RTBI && - priv->hw->xpcs_args.an_mode !=DW_AN_C73 ) { + (!priv->hw->xpcs || +xpcs_get_an_mode (&priv->hw->xpcs_args, mode) !=DW_AN_C73 )) { ret =stmmac_init_phy (dev);if (ret) { netdev_err(priv->dev,
drivers/net/pcs/pcs-xpcs.c +113 -62
299 lines not on this page · raw message
include/linux/pcs/pcs-xpcs.h +4 -2
@@ -14,11 +14,12 @@#define DW_AN_C73 1#define DW_AN_C37_SGMII 2 +struct xpcs_id ; +struct mdio_xpcs_args { -__ETHTOOL_DECLARE_LINK_MODE_MASK (supported);struct mii_bus *bus; +const struct xpcs_id *id;int addr; -int an_mode; };struct mdio_xpcs_ops {
@@ -36,6 +37,7 @@ struct mdio_xpcs_ops { int enable); }; +int xpcs_get_an_mode (struct mdio_xpcs_args *xpcs,phy_interface_t interface);struct mdio_xpcs_ops *mdio_xpcs_get_ops (void );#endif /* __LINUX_PCS_XPCS_H */
Signature · 1 line
2.25.1
PATCH v3 4/9 net: pcs: xpcs: export xpcs_validate
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Calling a function pointer with a single implementation through struct mdio_xpcs_ops is clunky, and the stmmac_do_callback system forces this to return int, even though it always returns zero.
Simply remove the "validate" function pointer from struct mdio_xpcs_ops and replace it with an exported xpcs_validate symbol which is called directly by stmmac.
priv->hw->xpcs is of the type "const struct mdio_xpcs_ops *" and is used as a placeholder/synonym for priv->plat->mdio_bus_data->has_xpcs. It is done that way because the mdio_bus_data pointer might or might not be populated in all stmmac instantiations.
---v1->v2: guard against potential absence of xpcs on the port v2->v3: none
drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 -- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ++- drivers/net/pcs/pcs-xpcs.c | 11 ++++------- include/linux/pcs/pcs-xpcs.h | 5 ++--- 4 files changed, 8 insertions(+), 13 deletions(-)
drivers/net/ethernet/stmicro/stmmac/hwif.h +0 -2
@@ -613,8 +613,6 @@ struct stmmac_mmc_ops {stmmac_do_void_callback (__priv, mmc, read, __args) /* XPCS callbacks */ -#define stmmac_xpcs_validate(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, validate, __args) #define stmmac_xpcs_config(__priv, __args...) \ stmmac_do_callback(__priv, xpcs, config, __args) #define stmmac_xpcs_get_state(__priv, __args...) \
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
@@ -996,7 +996,8 @@ static void stmmac_validate(struct phylink_config *config,linkmode_andnot (state->advertising, state->advertising, mask);/* If PCS is supported, check which modes it supports. */ -stmmac_xpcs_validate (priv, &priv->hw->xpcs_args, supported, state); +if (priv->hw->xpcs) +xpcs_validate (&priv->hw->xpcs_args, supported, state); } static void stmmac_mac_pcs_get_state(struct phylink_config *config,
drivers/net/pcs/pcs-xpcs.c +4 -7
@@ -685,9 +685,8 @@ static void xpcs_resolve_pma(struct mdio_xpcs_args *xpcs, } } -static int xpcs_validate (struct mdio_xpcs_args *xpcs, -unsigned long *supported, -struct phylink_link_state *state) +void xpcs_validate (struct mdio_xpcs_args *xpcs,unsigned long *supported, +struct phylink_link_state *state) {__ETHTOOL_DECLARE_LINK_MODE_MASK (xpcs_supported);const struct xpcs_compat *compat;
@@ -698,7 +697,7 @@ static int xpcs_validate(struct mdio_xpcs_args *xpcs,* advertising masks and exit. */ if (state->interface ==PHY_INTERFACE_MODE_NA ) -return 0 ; +return ;bitmap_zero (xpcs_supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
@@ -713,9 +712,8 @@ static int xpcs_validate(struct mdio_xpcs_args *xpcs,linkmode_and (supported, supported, xpcs_supported);linkmode_and (state->advertising, state->advertising, xpcs_supported); - -return 0 ; } +EXPORT_SYMBOL_GPL (xpcs_validate);static int xpcs_config_eee (struct mdio_xpcs_args *xpcs,int mult_fact_100ns,int enable)
@@ -1031,7 +1029,6 @@ static int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) }static struct mdio_xpcs_ops xpcs_ops = { - .validate = xpcs_validate, .config = xpcs_config, .get_state = xpcs_get_state, .link_up = xpcs_link_up,
include/linux/pcs/pcs-xpcs.h +2 -3
@@ -23,9 +23,6 @@ struct mdio_xpcs_args { };struct mdio_xpcs_ops { -int (*validate)(struct mdio_xpcs_args *xpcs, -unsigned long *supported, -struct phylink_link_state *state);int (*config)(struct mdio_xpcs_args *xpcs,const struct phylink_link_state *state); int (*get_state)(struct mdio_xpcs_args *xpcs,
@@ -39,5 +36,7 @@ struct mdio_xpcs_ops {int xpcs_get_an_mode (struct mdio_xpcs_args *xpcs,phy_interface_t interface);struct mdio_xpcs_ops *mdio_xpcs_get_ops (void ); +void xpcs_validate (struct mdio_xpcs_args *xpcs,unsigned long *supported, +struct phylink_link_state *state);#endif /* __LINUX_PCS_XPCS_H */
Signature · 1 line
2.25.1
PATCH v3 5/9 net: pcs: xpcs: export xpcs_config_eee
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
There is no good reason why we need to go through:
stmmac_xpcs_config_eee
-> stmmac_do_callback
-> mdio_xpcs_ops->config_eee
-> xpcs_config_eee
when we can simply call xpcs_config_eee.
priv->hw->xpcs is of the type "const struct mdio_xpcs_ops *" and is used as a placeholder/synonym for priv->plat->mdio_bus_data->has_xpcs. It is done that way because the mdio_bus_data pointer might or might not be populated in all stmmac instantiations.
---v1->v2: guard against potential absence of xpcs on the port v2->v3: none
drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 -- drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 12 +++++++----- drivers/net/pcs/pcs-xpcs.c | 6 +++--- include/linux/pcs/pcs-xpcs.h | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/stmicro/stmmac/hwif.h +0 -2
@@ -621,8 +621,6 @@ struct stmmac_mmc_ops { stmmac_do_callback(__priv, xpcs, link_up, __args) #define stmmac_xpcs_probe(__priv, __args...) \ stmmac_do_callback(__priv, xpcs, probe, __args) -#define stmmac_xpcs_config_eee(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, config_eee, __args)struct stmmac_regs_off {u32 ptp_off;
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +7 -5
@@ -720,11 +720,13 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,netdev_warn (priv->dev,"Setting EEE tx-lpi is not supported\n" ); - ret =stmmac_xpcs_config_eee (priv, &priv->hw->xpcs_args, - priv->plat->mult_fact_100ns, - edata->eee_enabled); -if (ret) -return ret; +if (priv->hw->xpcs) { + ret =xpcs_config_eee (&priv->hw->xpcs_args, + priv->plat->mult_fact_100ns, + edata->eee_enabled); +if (ret) +return ret; + }if (!edata->eee_enabled)stmmac_disable_eee_mode (priv);
drivers/net/pcs/pcs-xpcs.c +3 -3
@@ -715,8 +715,8 @@ void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, }EXPORT_SYMBOL_GPL (xpcs_validate); -static int xpcs_config_eee (struct mdio_xpcs_args *xpcs,int mult_fact_100ns, -int enable) +int xpcs_config_eee (struct mdio_xpcs_args *xpcs,int mult_fact_100ns, +int enable) {int ret;
@@ -747,6 +747,7 @@ static int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, ret |=DW_VR_MII_EEE_TRN_LPI ;return xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_EEE_MCTRL1 , ret); } +EXPORT_SYMBOL_GPL (xpcs_config_eee);static int xpcs_config_aneg_c37_sgmii (struct mdio_xpcs_args *xpcs) {
@@ -1033,7 +1034,6 @@ static struct mdio_xpcs_ops xpcs_ops = { .get_state = xpcs_get_state, .link_up = xpcs_link_up, .probe = xpcs_probe, - .config_eee = xpcs_config_eee, };struct mdio_xpcs_ops *mdio_xpcs_get_ops (void )
include/linux/pcs/pcs-xpcs.h +2 -2
@@ -30,13 +30,13 @@ struct mdio_xpcs_ops {int (*link_up)(struct mdio_xpcs_args *xpcs,int speed,phy_interface_t interface); int (*probe)(struct mdio_xpcs_args *xpcs, phy_interface_t interface); -int (*config_eee)(struct mdio_xpcs_args *xpcs,int mult_fact_100ns, - int enable); };int xpcs_get_an_mode (struct mdio_xpcs_args *xpcs,phy_interface_t interface);struct mdio_xpcs_ops *mdio_xpcs_get_ops (void );void xpcs_validate (struct mdio_xpcs_args *xpcs,unsigned long *supported,struct phylink_link_state *state); +int xpcs_config_eee (struct mdio_xpcs_args *xpcs,int mult_fact_100ns, +int enable);#endif /* __LINUX_PCS_XPCS_H */
Signature · 1 line
2.25.1
PATCH v3 6/9 net: pcs: xpcs: export xpcs_probe
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Similar to the other recently functions, it is not necessary for xpcs_probe to be a function pointer, so export it so that it can be called directly.
---v1->v2: keep passing the phy_interface_t argument to xpcs_probe v2->v3: none
drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 -- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 +- drivers/net/pcs/pcs-xpcs.c | 4 ++-- include/linux/pcs/pcs-xpcs.h | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/hwif.h +0 -2
@@ -619,8 +619,6 @@ struct stmmac_mmc_ops { stmmac_do_callback(__priv, xpcs, get_state, __args) #define stmmac_xpcs_link_up(__priv, __args...) \ stmmac_do_callback(__priv, xpcs, link_up, __args) -#define stmmac_xpcs_probe(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, probe, __args)struct stmmac_regs_off {u32 ptp_off;
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +1 -1
@@ -521,7 +521,7 @@ int stmmac_mdio_register(struct net_device *ndev)for (addr =0 ; addr < max_addr; addr++) { xpcs->addr = addr; - ret =stmmac_xpcs_probe (priv, xpcs, mode); + ret =xpcs_probe (xpcs, mode);if (!ret) { found =1 ;break ;
drivers/net/pcs/pcs-xpcs.c +2 -2
@@ -1005,7 +1005,7 @@ static const struct xpcs_id xpcs_id_list[] = { }, }; -static int xpcs_probe (struct mdio_xpcs_args *xpcs,phy_interface_t interface) +int xpcs_probe (struct mdio_xpcs_args *xpcs,phy_interface_t interface) {u32 xpcs_id =xpcs_get_id (xpcs);int i;
@@ -1028,12 +1028,12 @@ static int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface)return -ENODEV ; } +EXPORT_SYMBOL_GPL (xpcs_probe);static struct mdio_xpcs_ops xpcs_ops = { .config = xpcs_config, .get_state = xpcs_get_state, .link_up = xpcs_link_up, - .probe = xpcs_probe, };struct mdio_xpcs_ops *mdio_xpcs_get_ops (void )
include/linux/pcs/pcs-xpcs.h +1 -1
@@ -29,7 +29,6 @@ struct mdio_xpcs_ops { struct phylink_link_state *state);int (*link_up)(struct mdio_xpcs_args *xpcs,int speed,phy_interface_t interface); -int (*probe)(struct mdio_xpcs_args *xpcs,phy_interface_t interface); };int xpcs_get_an_mode (struct mdio_xpcs_args *xpcs,phy_interface_t interface);
@@ -38,5 +37,6 @@ void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, struct phylink_link_state *state);int xpcs_config_eee (struct mdio_xpcs_args *xpcs,int mult_fact_100ns,int enable); +int xpcs_probe (struct mdio_xpcs_args *xpcs,phy_interface_t interface);#endif /* __LINUX_PCS_XPCS_H */
Signature · 1 line
2.25.1
PATCH v3 7/9 net: pcs: xpcs: use mdiobus_c45_addr in xpcs_{read,write}
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Use the dedicated helper for abstracting away how the clause 45 address is packed in reg_addr.
---v1->v2: nonev2->v3: none
drivers/net/pcs/pcs-xpcs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/pcs/pcs-xpcs.c +2 -2
@@ -240,14 +240,14 @@ static bool __xpcs_linkmode_supported(const struct xpcs_compat *compat,static int xpcs_read (struct mdio_xpcs_args *xpcs,int dev,u32 reg) { -u32 reg_addr =MII_ADDR_C45 | dev <<16 | reg; +u32 reg_addr =mdiobus_c45_addr (dev, reg);return mdiobus_read (xpcs->bus, xpcs->addr, reg_addr); }static int xpcs_write (struct mdio_xpcs_args *xpcs,int dev,u32 reg,u16 val) { -u32 reg_addr =MII_ADDR_C45 | dev <<16 | reg; +u32 reg_addr =mdiobus_c45_addr (dev, reg);return mdiobus_write (xpcs->bus, xpcs->addr, reg_addr, val); }
Signature · 1 line
2.25.1
PATCH v3 8/9 net: pcs: xpcs: convert to mdio_device
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Unify the 2 existing PCS drivers (lynx and xpcs) by doing a similar thing on probe, which is to have a *_create function that takes a struct mdio_device * given by the caller, and builds a private PCS structure around that.
This changes stmmac to hold only a pointer to the xpcs, as opposed to the full structure. This will be used in the next patch when struct mdio_xpcs_ops is removed. Currently a pointer to struct mdio_xpcs_ops is used as a shorthand to determine whether the port has an XPCS or not. We can do the same now with the mdio_xpcs_args pointer.
---v1->v2: move this patch in front of the phylink_pcs_ops conversion so
that stmmac has a pointer to check againstv2->v3: none
drivers/net/ethernet/stmicro/stmmac/common.h | 2 +- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 10 ++-- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 39 ++++++++------ drivers/net/pcs/pcs-xpcs.c | 53 +++++++++++++++---- include/linux/pcs/pcs-xpcs.h | 7 +-- 6 files changed, 76 insertions(+), 37 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -1
@@ -504,7 +504,7 @@ struct mac_device_info {const struct stmmac_tc_ops *tc;const struct stmmac_mmc_ops *mmc;const struct mdio_xpcs_ops *xpcs; -struct mdio_xpcs_args xpcs_args; +struct mdio_xpcs_args *xpcs_args;struct mii_regs mii;/* MII register Addresses */ struct mac_link link;void __iomem *pcsr;/* vpointer to device CSRs */
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1 -1
@@ -721,7 +721,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, "Setting EEE tx-lpi is not supported\n");if (priv->hw->xpcs) { - ret =xpcs_config_eee (&priv->hw->xpcs_args, + ret =xpcs_config_eee (priv->hw->xpcs_args, priv->plat->mult_fact_100ns, edata->eee_enabled);if (ret)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -5
@@ -997,7 +997,7 @@ static void stmmac_validate(struct phylink_config *config,/* If PCS is supported, check which modes it supports. */ if (priv->hw->xpcs) -xpcs_validate (&priv->hw->xpcs_args, supported, state); +xpcs_validate (priv->hw->xpcs_args, supported, state); } static void stmmac_mac_pcs_get_state(struct phylink_config *config,
@@ -1006,7 +1006,7 @@ static void stmmac_mac_pcs_get_state(struct phylink_config *config,struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); state->link =0 ; -stmmac_xpcs_get_state (priv, &priv->hw->xpcs_args, state); +stmmac_xpcs_get_state (priv, priv->hw->xpcs_args, state); } static void stmmac_mac_config(struct phylink_config *config, unsigned int mode,
@@ -1014,7 +1014,7 @@ static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, {struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); -stmmac_xpcs_config (priv, &priv->hw->xpcs_args, state); +stmmac_xpcs_config (priv, priv->hw->xpcs_args, state); }static void stmmac_mac_an_restart (struct phylink_config *config)
@@ -1061,7 +1061,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev));u32 ctrl; -stmmac_xpcs_link_up (priv, &priv->hw->xpcs_args, speed, interface); +stmmac_xpcs_link_up (priv, priv->hw->xpcs_args, speed, interface); ctrl =readl (priv->ioaddr +MAC_CTRL_REG ); ctrl &= ~priv->hw->link.speed_mask;
@@ -3652,7 +3652,7 @@ int stmmac_open(struct net_device *dev)if (priv->hw->pcs !=STMMAC_PCS_TBI && priv->hw->pcs !=STMMAC_PCS_RTBI && (!priv->hw->xpcs || -xpcs_get_an_mode (&priv->hw->xpcs_args, mode) !=DW_AN_C73 )) { +xpcs_get_an_mode (priv->hw->xpcs_args, mode) !=DW_AN_C73 )) { ret =stmmac_init_phy (dev);if (ret) { netdev_err(priv->dev,
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +23 -16
@@ -510,25 +510,27 @@ int stmmac_mdio_register(struct net_device *ndev) }/* Try to probe the XPCS by scanning all addresses. */ -if (priv->hw->xpcs) { -struct mdio_xpcs_args *xpcs = &priv->hw->xpcs_args; -int ret, mode = priv->plat->phy_interface; - max_addr =PHY_MAX_ADDR ; - - xpcs->bus = new_bus; - - found =0 ; -for (addr =0 ; addr < max_addr; addr++) { - xpcs->addr = addr; - - ret =xpcs_probe (xpcs, mode); -if (!ret) { - found =1 ; -break ; +if (mdio_bus_data->has_xpcs) { +int mode = priv->plat->phy_interface; +struct mdio_device *mdiodev; +struct mdio_xpcs_args *xpcs; + +for (addr =0 ; addr <PHY_MAX_ADDR ; addr++) { + mdiodev =mdio_device_create (new_bus, addr); +if (IS_ERR (mdiodev)) +continue ; + + xpcs =xpcs_create (mdiodev, mode); +if (IS_ERR_OR_NULL (xpcs)) { +mdio_device_free (mdiodev); +continue ; } + + priv->hw->xpcs_args = xpcs; +break ; } -if (!found && !mdio_node) { +if (!priv->hw->xpcs_args) {dev_warn (dev,"No XPCS found\n" ); err = -ENODEV ; goto no_xpcs_found;
@@ -560,6 +562,11 @@ int stmmac_mdio_unregister(struct net_device *ndev)if (!priv->mii)return 0 ; +if (priv->hw->xpcs) { +mdio_device_free (priv->hw->xpcs_args->mdiodev); +xpcs_destroy (priv->hw->xpcs_args); + } +mdiobus_unregister (priv->mii); priv->mii->priv =NULL ;mdiobus_free (priv->mii);
drivers/net/pcs/pcs-xpcs.c +42 -11
89 lines not on this page · raw message
include/linux/pcs/pcs-xpcs.h +4 -3
@@ -17,9 +17,8 @@struct xpcs_id ;struct mdio_xpcs_args { -struct mii_bus *bus; +struct mdio_device *mdiodev;const struct xpcs_id *id; -int addr; };struct mdio_xpcs_ops {
@@ -37,6 +36,8 @@ void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, struct phylink_link_state *state);int xpcs_config_eee (struct mdio_xpcs_args *xpcs,int mult_fact_100ns,int enable); -int xpcs_probe (struct mdio_xpcs_args *xpcs,phy_interface_t interface); +struct mdio_xpcs_args *xpcs_create (struct mdio_device *mdiodev, +phy_interface_t interface); +void xpcs_destroy (struct mdio_xpcs_args *xpcs);#endif /* __LINUX_PCS_XPCS_H */
Signature · 1 line
2.25.1
PATCH v3 9/9 net: pcs: xpcs: convert to phylink_pcs_ops
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Since all the remaining members of struct mdio_xpcs_ops have direct equivalents in struct phylink_pcs_ops, it is about time we remove it altogether.
Since the phylink ops return void, we need to remove the error propagation from the various xpcs methods and simply print an error message where appropriate.
Since xpcs_get_state_c73() detects link faults and attempts to reset the link on its own by calling xpcs_config(), but xpcs_config() now has a lot of phylink arguments which are not needed and cannot be simply fabricated by anybody else except phylink, the actual implementation has been moved into a smaller xpcs_do_config().
The const struct mdio_xpcs_ops *priv->hw->xpcs has been removed, so we need to look at the struct mdio_xpcs_args pointer now as an indication whether the port has an XPCS or not.
---v1->v2: resolve conflicts after patch reorderingv2->v3: leave stmmac_mac_config() in place since it is a required function.
drivers/net/ethernet/stmicro/stmmac/common.h | 3 +- drivers/net/ethernet/stmicro/stmmac/hwif.h | 8 -- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 36 +++---- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 16 +-- drivers/net/pcs/pcs-xpcs.c | 99 +++++++++++-------- include/linux/pcs/pcs-xpcs.h | 11 +-- 7 files changed, 78 insertions(+), 97 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -2
@@ -503,8 +503,7 @@ struct mac_device_info {const struct stmmac_hwtimestamp *ptp;const struct stmmac_tc_ops *tc;const struct stmmac_mmc_ops *mmc; -const struct mdio_xpcs_ops *xpcs; -struct mdio_xpcs_args *xpcs_args; +struct mdio_xpcs_args *xpcs;struct mii_regs mii;/* MII register Addresses */ struct mac_link link;void __iomem *pcsr;/* vpointer to device CSRs */
drivers/net/ethernet/stmicro/stmmac/hwif.h +0 -8
@@ -612,14 +612,6 @@ struct stmmac_mmc_ops { #define stmmac_mmc_read(__priv, __args...) \ stmmac_do_void_callback(__priv, mmc, read, __args) -/* XPCS callbacks */ -#define stmmac_xpcs_config(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, config, __args) -#define stmmac_xpcs_get_state(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, get_state, __args) -#define stmmac_xpcs_link_up(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, link_up, __args) -struct stmmac_regs_off {u32 ptp_off;u32 mmc_off;
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1 -1
@@ -721,7 +721,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, "Setting EEE tx-lpi is not supported\n");if (priv->hw->xpcs) { - ret =xpcs_config_eee (priv->hw->xpcs_args, + ret =xpcs_config_eee (priv->hw->xpcs, priv->plat->mult_fact_100ns, edata->eee_enabled);if (ret)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +11 -25
@@ -997,29 +997,13 @@ static void stmmac_validate(struct phylink_config *config,/* If PCS is supported, check which modes it supports. */ if (priv->hw->xpcs) -xpcs_validate (priv->hw->xpcs_args, supported, state); -} - -static void stmmac_mac_pcs_get_state (struct phylink_config *config, -struct phylink_link_state *state) -{ -struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); - - state->link =0 ; -stmmac_xpcs_get_state (priv, priv->hw->xpcs_args, state); +xpcs_validate (priv->hw->xpcs, supported, state); }static void stmmac_mac_config (struct phylink_config *config,unsigned int mode,const struct phylink_link_state *state) { -struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); - -stmmac_xpcs_config (priv, priv->hw->xpcs_args, state); -} - -static void stmmac_mac_an_restart (struct phylink_config *config) -{ -/* Not Supported */ +/* Nothing to do, xpcs_config() handles everything */ }static void stmmac_fpe_link_state_handle (struct stmmac_priv *priv,bool is_up)
@@ -1061,8 +1045,6 @@ static void stmmac_mac_link_up(struct phylink_config *config,struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev));u32 ctrl; -stmmac_xpcs_link_up (priv, priv->hw->xpcs_args, speed, interface); - ctrl =readl (priv->ioaddr +MAC_CTRL_REG ); ctrl &= ~priv->hw->link.speed_mask;
@@ -1155,9 +1137,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,static const struct phylink_mac_ops stmmac_phylink_mac_ops = { .validate = stmmac_validate, - .mac_pcs_get_state = stmmac_mac_pcs_get_state, .mac_config = stmmac_mac_config, - .mac_an_restart = stmmac_mac_an_restart, .mac_link_down = stmmac_mac_link_down, .mac_link_up = stmmac_mac_link_up, };
@@ -1234,6 +1214,7 @@ static int stmmac_init_phy(struct net_device *dev)static int stmmac_phy_setup (struct stmmac_priv *priv) { +struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;struct fwnode_handle *fwnode =of_fwnode_handle (priv->plat->phylink_node);int mode = priv->plat->phy_interface;struct phylink *phylink;
@@ -1241,8 +1222,7 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) priv->phylink_config.dev = &priv->dev->dev; priv->phylink_config.type =PHYLINK_NETDEV ; priv->phylink_config.pcs_poll = true; - priv->phylink_config.ovr_an_inband = - priv->plat->mdio_bus_data->xpcs_an_inband; + priv->phylink_config.ovr_an_inband = mdio_bus_data->xpcs_an_inband;if (!fwnode) fwnode =dev_fwnode (priv->device);
@@ -1252,6 +1232,12 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)if (IS_ERR (phylink))return PTR_ERR (phylink); +if (mdio_bus_data->has_xpcs) { +struct mdio_xpcs_args *xpcs = priv->hw->xpcs; + +phylink_set_pcs (phylink, &xpcs->pcs); + } + priv->phylink = phylink;return 0 ; }
@@ -3652,7 +3638,7 @@ int stmmac_open(struct net_device *dev)if (priv->hw->pcs !=STMMAC_PCS_TBI && priv->hw->pcs !=STMMAC_PCS_RTBI && (!priv->hw->xpcs || -xpcs_get_an_mode (priv->hw->xpcs_args, mode) !=DW_AN_C73 )) { +xpcs_get_an_mode (priv->hw->xpcs, mode) !=DW_AN_C73 )) { ret =stmmac_init_phy (dev);if (ret) { netdev_err(priv->dev,
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +4 -12
@@ -444,14 +444,6 @@ int stmmac_mdio_register(struct net_device *ndev) max_addr =PHY_MAX_ADDR ; } -if (mdio_bus_data->has_xpcs) { - priv->hw->xpcs =mdio_xpcs_get_ops (); -if (!priv->hw->xpcs) { - err = -ENODEV ; - goto bus_register_fail; - } - } -if (mdio_bus_data->needs_reset) new_bus->reset = &stmmac_mdio_reset;
@@ -526,11 +518,11 @@ int stmmac_mdio_register(struct net_device *ndev)continue ; } - priv->hw->xpcs_args = xpcs; + priv->hw->xpcs = xpcs;break ; } -if (!priv->hw->xpcs_args) { +if (!priv->hw->xpcs) {dev_warn (dev,"No XPCS found\n" ); err = -ENODEV ; goto no_xpcs_found;
@@ -563,8 +555,8 @@ int stmmac_mdio_unregister(struct net_device *ndev)return 0 ;if (priv->hw->xpcs) { -mdio_device_free (priv->hw->xpcs_args->mdiodev); -xpcs_destroy (priv->hw->xpcs_args); +mdio_device_free (priv->hw->xpcs->mdiodev); +xpcs_destroy (priv->hw->xpcs); }mdiobus_unregister (priv->mii);
drivers/net/pcs/pcs-xpcs.c +60 -39
207 lines not on this page · raw message
include/linux/pcs/pcs-xpcs.h +1 -10
@@ -19,19 +19,10 @@ struct xpcs_id;struct mdio_xpcs_args {struct mdio_device *mdiodev;const struct xpcs_id *id; -}; - -struct mdio_xpcs_ops { -int (*config)(struct mdio_xpcs_args *xpcs, -const struct phylink_link_state *state); -int (*get_state)(struct mdio_xpcs_args *xpcs, -struct phylink_link_state *state); -int (*link_up)(struct mdio_xpcs_args *xpcs,int speed, -phy_interface_t interface); +struct phylink_pcs pcs; };int xpcs_get_an_mode (struct mdio_xpcs_args *xpcs,phy_interface_t interface); -struct mdio_xpcs_ops *mdio_xpcs_get_ops (void );void xpcs_validate (struct mdio_xpcs_args *xpcs,unsigned long *supported,struct phylink_link_state *state); int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns,
Signature · 1 line
2.25.1