mv88e6xxx: Allow config of ATU hash algorithm
Subsystems (6)
Andrew Lunn
maintainerv3 cover mv88e6xxx: Allow config of ATU hash algorithm
The Marvell switches allow the hash algorithm for MAC addresses in the address translation unit to be configured. Add support to the DSA core to allow DSA drivers to make use of devlink parameters, and allow the ATU hash to be get/set via such a parameter.
v2:
Pass a pointer for where the hash should be stored, return a plain errno, or 0.
Document the parameter.
v3:
Document type of parameter, and valid range
Add break statements to default clause of switch
Directly use ctx->val.vu8
Andrew Lunn (2):
net: dsa: Add support for devlink device parameters
net: dsa: mv88e6xxx: Add devlink param for ATU hash algorithm.
.../networking/devlink-params-mv88e6xxx.txt | 7 + MAINTAINERS | 1 + drivers/net/dsa/mv88e6xxx/chip.c | 131 +++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 4 + drivers/net/dsa/mv88e6xxx/global1.h | 3 + drivers/net/dsa/mv88e6xxx/global1_atu.c | 32 +++++ include/net/dsa.h | 23 +++ net/dsa/dsa.c | 48 +++++++ net/dsa/dsa2.c | 7 +- 9 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 Documentation/networking/devlink-params-mv88e6xxx.txt
Signature · 1 line
2.23.0
Andrew Lunn
maintainerPATCH v3 1/2 net: dsa: Add support for devlink device parameters
Add plumbing to allow DSA drivers to register parameters with devlink.
To keep with the abstraction, the DSA drivers pass the ds structure to these helpers, and the DSA core then translates that to the devlink structure associated to the device.
--- include/net/dsa.h | 23 +++++++++++++++++++++++ net/dsa/dsa.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ net/dsa/dsa2.c | 7 ++++++- 3 files changed, 77 insertions(+), 1 deletion(-)
include/net/dsa.h +23 -0
@@ -541,6 +541,29 @@ struct dsa_switch_ops {*/ netdev_tx_t (*port_deferred_xmit)(struct dsa_switch *ds,int port,struct sk_buff *skb); +/* Devlink parameters */ +int (*devlink_param_get)(struct dsa_switch *ds,u32 id, +struct devlink_param_gset_ctx *ctx); +int (*devlink_param_set)(struct dsa_switch *ds,u32 id, +struct devlink_param_gset_ctx *ctx); +}; + +#define DSA_DEVLINK_PARAM_DRIVER (_id, _name, _type, _cmodes) \ + DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ + dsa_dl_param_get, dsa_dl_param_set, NULL) + +int dsa_dl_param_get (struct devlink *dl,u32 id, +struct devlink_param_gset_ctx *ctx); +int dsa_dl_param_set (struct devlink *dl,u32 id, +struct devlink_param_gset_ctx *ctx); +int dsa_devlink_params_register (struct dsa_switch *ds, +const struct devlink_param *params, +size_t params_count); +void dsa_devlink_params_unregister (struct dsa_switch *ds, +const struct devlink_param *params, +size_t params_count); +struct dsa_devlink_priv { +struct dsa_switch *ds; };struct dsa_switch_driver {
net/dsa/dsa.c +48 -0
54 lines not on this page · raw message
net/dsa/dsa2.c +6 -1
@@ -367,6 +367,7 @@ static void dsa_port_teardown(struct dsa_port *dp)static int dsa_switch_setup (struct dsa_switch *ds) { +struct dsa_devlink_priv *dl_priv;int err =0 ;/* Initialize ds->phys_mii_mask before registering the slave MDIO bus
@@ -379,9 +380,11 @@ static int dsa_switch_setup(struct dsa_switch *ds)/* Add the switch to devlink before calling setup, so that setup can * add dpipe tables */ - ds->devlink =devlink_alloc (&dsa_devlink_ops,0 ); + ds->devlink =devlink_alloc (&dsa_devlink_ops,sizeof (*devlink_priv));if (!ds->devlink)return -ENOMEM ; + dl_priv =devlink_priv (ds->devlink); + dl_priv->ds = ds; err =devlink_register (ds->devlink, ds->dev);if (err)
@@ -395,6 +398,8 @@ static int dsa_switch_setup(struct dsa_switch *ds)if (err <0 ) goto unregister_notifier; +devlink_params_publish (ds->devlink); +if (!ds->slave_mii_bus && ds->ops->phy_read) { ds->slave_mii_bus =devm_mdiobus_alloc (ds->dev);if (!ds->slave_mii_bus) {
Signature · 1 line
2.23.0
Jiri Pirko
maintainerRe: [PATCH net-next v3 1/2] net: dsa: Add support for devlink device parameters
Quoted 27 lines · Thu, Oct 17, 2019 at 09:20:54PM CEST, [email protected] wrote:
Add plumbing to allow DSA drivers to register parameters with devlink.
To keep with the abstraction, the DSA drivers pass the ds structure to these helpers, and the DSA core then translates that to the devlink structure associated to the device.
Signed-off-by Andrew Lunn <[email protected]>---
include/net/dsa.h | 23 +++++++++++++++++++++++ net/dsa/dsa.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ net/dsa/dsa2.c | 7 ++++++- 3 files changed, 77 insertions(+), 1 deletion(-)include/net/dsa.h +6
-0@@ -541,6 +541,29 @@ struct dsa_switch_ops {*/ netdev_tx_t (*port_deferred_xmit)(struct dsa_switch *ds,int port,struct sk_buff *skb); +/* Devlink parameters */ +int (*devlink_param_get)(struct dsa_switch *ds,u32 id, +struct devlink_param_gset_ctx *ctx); +int (*devlink_param_set)(struct dsa_switch *ds,u32 id, +struct devlink_param_gset_ctx *ctx); +};
include/net/dsa.h struct dsa_switch_ops { · line 559
Quoted 10 lines
include/net/dsa.h +10
-0+ +#define DSA_DEVLINK_PARAM_DRIVER (_id, _name, _type, _cmodes) \ + DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ + dsa_dl_param_get, dsa_dl_param_set, NULL) + +int dsa_dl_param_get (struct devlink *dl,u32 id, +struct devlink_param_gset_ctx *ctx); +int dsa_dl_param_set (struct devlink *dl,u32 id, +struct devlink_param_gset_ctx *ctx); +int dsa_devlink_params_register(struct dsa_switch *ds,
"dl/devlink". I think that the names should be consistent.
Quoted 82 lines
include/net/dsa.h +7
-0+const struct devlink_param *params, + size_t params_count); +void dsa_devlink_params_unregister (struct dsa_switch *ds, +const struct devlink_param *params, +size_t params_count); +struct dsa_devlink_priv { +struct dsa_switch *ds; };struct dsa_switch_driver {net/dsa/dsa.c +48
-0@@ -329,6 +329,54 @@ int call_dsa_notifiers(unsigned long val, struct net_device *dev, }EXPORT_SYMBOL_GPL (call_dsa_notifiers); +int dsa_dl_param_get (struct devlink *dl,u32 id, +struct devlink_param_gset_ctx *ctx) +{ +struct dsa_devlink_priv *dl_priv; +struct dsa_switch *ds; + + dl_priv =devlink_priv (dl); + ds = dl_priv->ds; + +if (!ds->ops->devlink_param_get) +return -EOPNOTSUPP ; + +return ds->ops->devlink_param_get (ds, id, ctx); +} +EXPORT_SYMBOL_GPL (dsa_dl_param_get); + +int dsa_dl_param_set (struct devlink *dl,u32 id, +struct devlink_param_gset_ctx *ctx) +{ +struct dsa_devlink_priv *dl_priv; +struct dsa_switch *ds; + + dl_priv =devlink_priv (dl); + ds = dl_priv->ds; + +if (!ds->ops->devlink_param_set) +return -EOPNOTSUPP ; + +return ds->ops->devlink_param_set (ds, id, ctx); +} +EXPORT_SYMBOL_GPL (dsa_dl_param_set); + +int dsa_devlink_params_register (struct dsa_switch *ds, +const struct devlink_param *params, +size_t params_count) +{ +return devlink_params_register (ds->devlink, params, params_count); +} +EXPORT_SYMBOL_GPL (dsa_devlink_params_register); + +void dsa_devlink_params_unregister (struct dsa_switch *ds, +const struct devlink_param *params, +size_t params_count) +{ +devlink_params_unregister (ds->devlink, params, params_count); +} +EXPORT_SYMBOL_GPL (dsa_devlink_params_unregister); +static int __init dsa_init_module (void ) {int rc;net/dsa/dsa2.c +1
-0@@ -367,6 +367,7 @@ static void dsa_port_teardown(struct dsa_port *dp)static int dsa_switch_setup (struct dsa_switch *ds) { +struct dsa_devlink_priv *dl_priv;int err =0 ;/* Initialize ds->phys_mii_mask before registering the slave MDIO bus
net/dsa/dsa2.c static int dsa_switch_setup(struct dsa_switch *ds) · line 383
Quoted 5 lines
net/dsa/dsa2.c +1
-1@@ -379,9 +380,11 @@ static int dsa_switch_setup(struct dsa_switch *ds)/* Add the switch to devlink before calling setup, so that setup can * add dpipe tables */ - ds->devlink =devlink_alloc (&dsa_devlink_ops,0 ); + ds->devlink =devlink_alloc (&dsa_devlink_ops,sizeof (*devlink_priv));
This should most likely be:sizeof(*dl_priv)
Quoted 19 lines
net/dsa/dsa2.c +4
-0if (!ds->devlink)return -ENOMEM ; + dl_priv =devlink_priv (ds->devlink); + dl_priv->ds = ds; err =devlink_register (ds->devlink, ds->dev);if (err)@@ -395,6 +398,8 @@ static int dsa_switch_setup(struct dsa_switch *ds)if (err <0 ) goto unregister_notifier; +devlink_params_publish (ds->devlink); +if (!ds->slave_mii_bus && ds->ops->phy_read) { ds->slave_mii_bus =devm_mdiobus_alloc (ds->dev);if (!ds->slave_mii_bus) {Signature · 1 line
2.23.0
Andrew Lunn
maintainerPATCH v3 2/2 net: dsa: mv88e6xxx: Add devlink param for ATU hash algorithm.
In reply to Andrew LunnSome of the marvell switches have bits controlling the hash algorithm the ATU uses for MAC addresses. In some industrial settings, where all the devices are from the same manufacture, and hence use the same OUI, the default hashing algorithm is not optimal. Allow the other algorithms to be selected via devlink.
--- .../networking/devlink-params-mv88e6xxx.txt | 7 + MAINTAINERS | 1 + drivers/net/dsa/mv88e6xxx/chip.c | 131 +++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 4 + drivers/net/dsa/mv88e6xxx/global1.h | 3 + drivers/net/dsa/mv88e6xxx/global1_atu.c | 32 +++++ 6 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 Documentation/networking/devlink-params-mv88e6xxx.txt
Documentation/networking/devlink-params-mv88e6xxx.txt new file +7 -0
@@ -0,0 +1,7 @@ +ATU_hash [DEVICE, DRIVER-SPECIFIC] + Select one of four possible hashing algorithms for + MAC addresses in the Address Translation Unity. + A value of 3 seems to work better than the default of + 1 when many MAC addresses have the same OUI. + Configuration mode: runtime + Type: u8. 0-3 valid.
MAINTAINERS +1 -0
@@ -9740,6 +9740,7 @@ S: Maintained F: drivers/net/dsa/mv88e6xxx/ F: include/linux/platform_data/mv88e6xxx.h F: Documentation/devicetree/bindings/net/dsa/marvell.txt +F: Documentation/networking/devlink-params-mv88e6xxx.txt MARVELL ARMADA DRM SUPPORT M: Russell King <[email protected]>
drivers/net/dsa/mv88e6xxx/chip.c +130 -1
263 lines not on this page · raw message
drivers/net/dsa/mv88e6xxx/chip.h +4 -0
@@ -497,6 +497,10 @@ struct mv88e6xxx_ops {int (*serdes_get_stats)(struct mv88e6xxx_chip *chip,int port,uint64_t *data); +/* Address Translation Unit operations */ +int (*atu_get_hash)(struct mv88e6xxx_chip *chip,u8 *hash); +int (*atu_set_hash)(struct mv88e6xxx_chip *chip,u8 hash); +/* VLAN Translation Unit operations */ int (*vtu_getnext)(struct mv88e6xxx_chip *chip,struct mv88e6xxx_vtu_entry *entry);
drivers/net/dsa/mv88e6xxx/global1.h +3 -0
@@ -109,6 +109,7 @@/* Offset 0x0A: ATU Control Register */ #define MV88E6XXX_G1_ATU_CTL 0x0a#define MV88E6XXX_G1_ATU_CTL_LEARN2ALL 0x0008 +#define MV88E6161_G1_ATU_CTL_HASH_MASK 0x3/* Offset 0x0B: ATU Operation Register */ #define MV88E6XXX_G1_ATU_OP 0x0b
@@ -318,6 +319,8 @@ int mv88e6xxx_g1_atu_remove(struct mv88e6xxx_chip *chip, u16 fid, int port, bool all);int mv88e6xxx_g1_atu_prob_irq_setup (struct mv88e6xxx_chip *chip);void mv88e6xxx_g1_atu_prob_irq_free (struct mv88e6xxx_chip *chip); +int mv88e6165_g1_atu_get_hash (struct mv88e6xxx_chip *chip,u8 *hash); +int mv88e6165_g1_atu_set_hash (struct mv88e6xxx_chip *chip,u8 hash);int mv88e6185_g1_vtu_getnext (struct mv88e6xxx_chip *chip,struct mv88e6xxx_vtu_entry *entry);
drivers/net/dsa/mv88e6xxx/global1_atu.c +32 -0
@@ -73,6 +73,38 @@ int mv88e6xxx_g1_atu_set_age_time(struct mv88e6xxx_chip *chip,return 0 ; } +int mv88e6165_g1_atu_get_hash (struct mv88e6xxx_chip *chip,u8 *hash) +{ +int err; +u16 val; + + err =mv88e6xxx_g1_read (chip,MV88E6XXX_G1_ATU_CTL , &val); +if (err) +return err; + + *hash = val &MV88E6161_G1_ATU_CTL_HASH_MASK ; + +return 0 ; +} + +int mv88e6165_g1_atu_set_hash (struct mv88e6xxx_chip *chip,u8 hash) +{ +int err; +u16 val; + +if (hash & ~MV88E6161_G1_ATU_CTL_HASH_MASK ) +return -EINVAL ; + + err =mv88e6xxx_g1_read (chip,MV88E6XXX_G1_ATU_CTL , &val); +if (err) +return err; + + val &= ~MV88E6161_G1_ATU_CTL_HASH_MASK ; + val |= hash; + +return mv88e6xxx_g1_write (chip,MV88E6XXX_G1_ATU_CTL , val); +} +/* Offset 0x0B: ATU Operation Register */ static int mv88e6xxx_g1_atu_op_wait (struct mv88e6xxx_chip *chip)
Signature · 1 line
2.23.0
Re: [PATCH net-next v3 2/2] net: dsa: mv88e6xxx: Add devlink param for ATU hash algorithm.
Quoted 7 lines · Andrew Lunn
Some of the marvell switches have bits controlling the hash algorithm the ATU uses for MAC addresses. In some industrial settings, where all the devices are from the same manufacture, and hence use the same OUI, the default hashing algorithm is not optimal. Allow the other algorithms to be selected via devlink.
Signed-off-by Andrew Lunn <[email protected]>
Jiri Pirko
maintainerRe: [PATCH net-next v3 2/2] net: dsa: mv88e6xxx: Add devlink param for ATU hash algorithm.
In reply to Andrew LunnQuoted 1 line · Thu, Oct 17, 2019 at 09:20:55PM CEST, [email protected] wrote:
Some of the marvell switches have bits controlling the hash algorithm
s/marvell/Marvell/
Quoted 4 lines
the ATU uses for MAC addresses. In some industrial settings, where all the devices are from the same manufacture, and hence use the same OUI, the default hashing algorithm is not optimal. Allow the other algorithms to be selected via devlink.
s/via devlink/via devlink parameter/
Quoted 98 lines
Signed-off-by Andrew Lunn <[email protected]>---
.../networking/devlink-params-mv88e6xxx.txt | 7 + MAINTAINERS | 1 + drivers/net/dsa/mv88e6xxx/chip.c | 131 +++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 4 + drivers/net/dsa/mv88e6xxx/global1.h | 3 + drivers/net/dsa/mv88e6xxx/global1_atu.c | 32 +++++ 6 files changed, 177 insertions(+), 1 deletion(-)create mode 100644
Documentation/networking/devlink-params-mv88e6xxx.txtDocumentation/networking/devlink-params-mv88e6xxx.txt new file +7
-0@@ -0,0 +1,7 @@ +ATU_hash [DEVICE, DRIVER-SPECIFIC] + Select one of four possible hashing algorithms for + MAC addresses in the Address Translation Unity. + A value of 3 seems to work better than the default of + 1 when many MAC addresses have the same OUI. + Configuration mode: runtime + Type: u8. 0-3 valid.MAINTAINERS +0
-0@@ -9740,6 +9740,7 @@ S: MaintainedF:
drivers/net/dsa/mv88e6xxx/
F:include/linux/platform_data/mv88e6xxx.h
F:Documentation/devicetree/bindings/net/dsa/marvell.txt
+F:Documentation/networking/devlink-params-mv88e6xxx.txtMARVELL ARMADA DRM SUPPORT
M: Russell King <[email protected]>drivers/net/dsa/mv88e6xxx/chip.c +46
-0@@ -1370,6 +1370,22 @@ static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)return mv88e6xxx_g1_atu_flush (chip, *fid, true); } +static int mv88e6xxx_atu_get_hash (struct mv88e6xxx_chip *chip,u8 *hash) +{ +if (chip->info->ops->atu_get_hash) +return chip->info->ops->atu_get_hash (chip, hash); + +return -EOPNOTSUPP ; +} + +static int mv88e6xxx_atu_set_hash (struct mv88e6xxx_chip *chip,u8 hash) +{ +if (chip->info->ops->atu_set_hash) +return chip->info->ops->atu_set_hash (chip, hash); + +return -EOPNOTSUPP ; +} +static int mv88e6xxx_port_check_hw_vlan (struct dsa_switch *ds,int port,u16 vid_begin,u16 vid_end) {@@ -2641,6 +2657,78 @@ static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)return mv88e6xxx_software_reset (chip); } +enum mv88e6xxx_devlink_param_id { +MV88E6XXX_DEVLINK_PARAM_ID_BASE =DEVLINK_PARAM_GENERIC_ID_MAX , +MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH , +}; + +static int mv88e6xxx_devlink_param_get (struct dsa_switch *ds,u32 id, +struct devlink_param_gset_ctx *ctx) +{ +struct mv88e6xxx_chip *chip = ds->priv; +int err; + +mv88e6xxx_reg_lock (chip); + +switch (id) { +case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH : + err =mv88e6xxx_atu_get_hash (chip, &ctx->val.vu8); +break ; +default : + err = -EOPNOTSUPP ; +break ; + } + +mv88e6xxx_reg_unlock (chip); + +return err; +} + +static int mv88e6xxx_devlink_param_set (struct dsa_switch *ds,u32 id, +struct devlink_param_gset_ctx *ctx) +{
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip) · line 2699
Quoted 10 lines
drivers/net/dsa/mv88e6xxx/chip.c +10
-0+struct mv88e6xxx_chip *chip = ds->priv; +int err; + +mv88e6xxx_reg_lock (chip); + +switch (id) { +case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH : + err =mv88e6xxx_atu_set_hash (chip, ctx->val.vu8); +break ; +default :
WARN_ON could be here, this should never happen.
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip) · line 2711
Quoted 12 lines
drivers/net/dsa/mv88e6xxx/chip.c +12
-0+ err = -EOPNOTSUPP ; +break ; + } + +mv88e6xxx_reg_unlock (chip); + +return err; +} + +static const struct devlink_param mv88e6xxx_devlink_params[] = { + DSA_DEVLINK_PARAM_DRIVER(MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH, + "ATU_hash", DEVLINK_PARAM_TYPE_U8,
Can't this be lowercase please?
"atu_hash".
Quoted 20 lines
drivers/net/dsa/mv88e6xxx/chip.c +20
-0+ BIT(DEVLINK_PARAM_CMODE_RUNTIME)), +}; + +static int mv88e6xxx_setup_devlink_params (struct dsa_switch *ds) +{ +return dsa_devlink_params_register (ds, mv88e6xxx_devlink_params, +ARRAY_SIZE (mv88e6xxx_devlink_params)); +} + +static void mv88e6xxx_teardown_devlink_params (struct dsa_switch *ds) +{ +dsa_devlink_params_unregister (ds, mv88e6xxx_devlink_params, +ARRAY_SIZE (mv88e6xxx_devlink_params)); +} + +static void mv88e6xxx_teardown (struct dsa_switch *ds) +{ +mv88e6xxx_teardown_devlink_params (ds); +} +
[...]
Re: [PATCH net-next v3 2/2] net: dsa: mv88e6xxx: Add devlink param for ATU hash algorithm.
In reply to Andrew LunnHi Andrew,
drivers/net/dsa/mv88e6xxx/global1.h line 112
Quoted 7 lines · Andrew Lunn
drivers/net/dsa/mv88e6xxx/global1.h +1
-0@@ -109,6 +109,7 @@/* Offset 0x0A: ATU Control Register */ #define MV88E6XXX_G1_ATU_CTL 0x0a#define MV88E6XXX_G1_ATU_CTL_LEARN2ALL 0x0008 +#define MV88E6161_G1_ATU_CTL_HASH_MASK 0x3
If a respin is needed, can you use the 0x1234 format for this mask, so that the position of bits are documented as well like with the other macros.
Thank you,
Vivien