net: dsa: qca8k: code split for qca8k
Christian Marangi
maintainerv2 cover net: dsa: qca8k: code split for qca8k
This is needed ad ipq4019 SoC have an internal switch that is based on qca8k with very minor changes. The general function is equal.
Because of this we split the driver to common and specific code.
As the common function needs to be moved to a different file to be reused, we had to convert every remaining user of qca8k_read/write/rmw to regmap variant.
We had also to generilized the special handling for the ethtool_stats function that makes use of the autocast mib. (ipq4019 will have a different tagger and use mmio so it could be quicker to use mmio instead of automib feature)
And we had to convert the regmap read/write to bulk implementation to drop the special function that makes use of it. This will be compatible with ipq4019 and at the same time permits normal switch to use the eth mgmt way to send the entire ATU table read/write in one go.
v2:
- Rework patch to drop dependency with bulk regmap (will be converted later)
- Split the split patch to additional patch
- Rework autocast_mib function and move it to match data
Christian Marangi (15):
net: dsa: qca8k: make mib autocast feature optional
net: dsa: qca8k: move mib struct to common code
net: dsa: qca8k: move qca8k read/write/rmw and reg table to common
code
net: dsa: qca8k: move qca8k bulk read/write helper to common code
net: dsa: qca8k: move fdb/vlan/mib init functions to common code
net: dsa: qca8k: move port set status/eee/ethtool stats function to
common code
net: dsa: qca8k: move bridge functions to common code
net: dsa: qca8k: move fast age/MTU/port enable/disable functions to
common code
net: dsa: qca8k: move port FDB function to common code
net: dsa: qca8k: move port MDB functions to common code
net: dsa: qca8k: move port mirror functions to common code
net: dsa: qca8k: move port VLAN functions to common code
net: dsa: qca8k: move port LAG functions to common code
net: dsa: qca8k: move read_switch_id function to common code
net: dsa: qca8k: drop unnecessary exposed function and make them
static
drivers/net/dsa/qca/Makefile | 1 +
drivers/net/dsa/qca/{qca8k.c => qca8k-8xxx.c} | 1505 ++---------------
drivers/net/dsa/qca/qca8k-common.c | 1256 ++++++++++++++
drivers/net/dsa/qca/qca8k.h | 95 ++
4 files changed, 1489 insertions(+), 1368 deletions(-)
rename drivers/net/dsa/qca/{qca8k.c => qca8k-8xxx.c} (63%)
create mode 100644 drivers/net/dsa/qca/qca8k-common.cSignature · 1 line
2.36.1
Christian Marangi
maintainerPATCH v2 1/15 net: dsa: qca8k: make mib autocast feature optional
Some switch may not support mib autocast feature and require the legacy way of reading the regs directly.
Make the mib autocast feature optional and permit to declare support for it using match_data struct.
--- drivers/net/dsa/qca/qca8k.c | 11 +++++++---- drivers/net/dsa/qca/qca8k.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/net/dsa/qca/qca8k.c +7 -4
@@ -2112,12 +2112,12 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,u32 hi =0 ;int ret; -if (priv->mgmt_master && -qca8k_get_ethtool_stats_eth (ds, port, data) >0 ) -return ; - match_data =of_device_get_match_data (priv->dev); +if (priv->mgmt_master && match_data->autocast_mib && + match_data->autocast_mib (ds, port, data) >0 ) +return ; +for (i =0 ; i < match_data->mib_count; i++) { mib = &ar8327_mib[i]; reg =QCA8K_PORT_MIB_COUNTER (port) + mib->offset;
@@ -3260,16 +3260,19 @@ static const struct qca8k_match_data qca8327 = { .id = QCA8K_ID_QCA8327, .reduced_package = true, .mib_count = QCA8K_QCA832X_MIB_COUNT, + .autocast_mib = qca8k_get_ethtool_stats_eth, };static const struct qca8k_match_data qca8328 = { .id =QCA8K_ID_QCA8327 , .mib_count =QCA8K_QCA832X_MIB_COUNT , + .autocast_mib = qca8k_get_ethtool_stats_eth, };static const struct qca8k_match_data qca833x = { .id =QCA8K_ID_QCA8337 , .mib_count =QCA8K_QCA833X_MIB_COUNT , + .autocast_mib = qca8k_get_ethtool_stats_eth, };static const struct of_device_id qca8k_of_match[] = {
drivers/net/dsa/qca/qca8k.h +1 -0
@@ -328,6 +328,7 @@ struct qca8k_match_data {u8 id;bool reduced_package;u8 mib_count; +int (*autocast_mib)(struct dsa_switch *ds,int port,u64 *data); };enum {
Signature · 1 line
2.36.1
Vladimir Oltean
maintainerRe: [net-next PATCH v2 01/15] net: dsa: qca8k: make mib autocast feature optional
Quoted 16 lines · Christian Marangi
Some switch may not support mib autocast feature and require the legacy way of reading the regs directly.
Make the mib autocast feature optional and permit to declare support for it usingmatch_datastruct.Signed-off-by Christian Marangi <[email protected]>--- drivers/net/dsa/qca/qca8k.c | 11 +++++++---- drivers/net/dsa/qca/qca8k.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-)drivers/net/dsa/qca/qca8k.c +0
-0
drivers/net/dsa/qca/qca8k.c qca8k_get_ethtool_stats(struct dsa_switch *ds, int port, · line 2115
Quoted 8 lines
drivers/net/dsa/qca/qca8k.c +0
-4@@ -2112,12 +2112,12 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,u32 hi =0 ;int ret; -if (priv->mgmt_master && -qca8k_get_ethtool_stats_eth (ds, port, data) >0 ) -return ; - match_data =of_device_get_match_data (priv->dev);
I didn't notice at the time that you already call of_device_get_match_data() at driver runtime, but please be aware that it is a relatively expensive operation (takes raw spinlocks, iterates etc), or at least much more expensive than it needs to be. What other drivers do is cache the result of this function once in priv->info and just use priv->info, since it won't change during the lifetime of the driver.
drivers/net/dsa/qca/qca8k.c static const struct qca8k_match_data qca8327 = { · line 3263
Quoted 13 lines
drivers/net/dsa/qca/qca8k.c +5
-0+if (priv->mgmt_master && match_data->autocast_mib && + match_data->autocast_mib (ds, port, data) >0 ) +return ; +for (i =0 ; i < match_data->mib_count; i++) { mib = &ar8327_mib[i]; reg =QCA8K_PORT_MIB_COUNTER (port) + mib->offset;@@ -3260,16 +3260,19 @@ static const struct qca8k_match_data qca8327 = { .id = QCA8K_ID_QCA8327, .reduced_package = true, .mib_count = QCA8K_QCA832X_MIB_COUNT, + .autocast_mib = qca8k_get_ethtool_stats_eth,
I thought you were going to create a dedicated sub-structure for function pointers?
Quoted 30 lines
drivers/net/dsa/qca/qca8k.c +2
-0};static const struct qca8k_match_data qca8328 = { .id =QCA8K_ID_QCA8327 , .mib_count =QCA8K_QCA832X_MIB_COUNT , + .autocast_mib = qca8k_get_ethtool_stats_eth, };static const struct qca8k_match_data qca833x = { .id =QCA8K_ID_QCA8337 , .mib_count =QCA8K_QCA833X_MIB_COUNT , + .autocast_mib = qca8k_get_ethtool_stats_eth, };static const struct of_device_id qca8k_of_match[] = {drivers/net/dsa/qca/qca8k.h +1
-0@@ -328,6 +328,7 @@ struct qca8k_match_data {u8 id;bool reduced_package;u8 mib_count; +int (*autocast_mib)(struct dsa_switch *ds,int port,u64 *data); };enum {Signature · 1 line
2.36.1
Christian Marangi
maintainerRe: [net-next PATCH v2 01/15] net: dsa: qca8k: make mib autocast feature optional
Quoted 20 lines · Vladimir Oltean
Quoted 19 lines · Christian Marangi
Some switch may not support mib autocast feature and require the legacy way of reading the regs directly.
Make the mib autocast feature optional and permit to declare support for it usingmatch_datastruct.Signed-off-by Christian Marangi <[email protected]>--- drivers/net/dsa/qca/qca8k.c | 11 +++++++---- drivers/net/dsa/qca/qca8k.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-)drivers/net/dsa/qca/qca8k.c +0
-0@@ -2112,12 +2112,12 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,u32 hi =0 ;int ret;
Quoted 13 lines
drivers/net/dsa/qca/qca8k.c qca8k_get_ethtool_stats(struct dsa_switch *ds, int port, · line 2115
Quoted 5 lines
drivers/net/dsa/qca/qca8k.c +0
-4-if (priv->mgmt_master && -qca8k_get_ethtool_stats_eth (ds, port, data) >0 ) -return ; - match_data =of_device_get_match_data (priv->dev);I didn't notice at the time that you already call
of_device_get_match_data()at driver runtime, but please be aware that it is a relatively expensive operation (takes raw spinlocks, iterates etc), or at least much more expensive than it needs to be. What other drivers do is cache the result of this function once inpriv->infoand just usepriv->info, since it won't change during the lifetime of the driver.
Ok makes sense. Can I make a patch drop the use of of_device_get_match_data and then apply this on top?
(we use of_device_get_match_data also in other functions)
Quoted 17 lines
drivers/net/dsa/qca/qca8k.c static const struct qca8k_match_data qca8327 = { · line 3263
Quoted 13 lines
drivers/net/dsa/qca/qca8k.c +5
-0+if (priv->mgmt_master && match_data->autocast_mib && + match_data->autocast_mib (ds, port, data) >0 ) +return ; +for (i =0 ; i < match_data->mib_count; i++) { mib = &ar8327_mib[i]; reg =QCA8K_PORT_MIB_COUNTER (port) + mib->offset;@@ -3260,16 +3260,19 @@ static const struct qca8k_match_data qca8327 = { .id = QCA8K_ID_QCA8327, .reduced_package = true, .mib_count = QCA8K_QCA832X_MIB_COUNT, + .autocast_mib = qca8k_get_ethtool_stats_eth,I thought you were going to create a dedicated sub-structure for function pointers?
Sorry... totally forgot this as I was very busy with giving good series. Will handle this in the next version.
(will be also useful later for the single dsa_switch_ops transition if we want to put all of them there)
Quoted 31 lines
Quoted 30 lines
drivers/net/dsa/qca/qca8k.c +2
-0};static const struct qca8k_match_data qca8328 = { .id =QCA8K_ID_QCA8327 , .mib_count =QCA8K_QCA832X_MIB_COUNT , + .autocast_mib = qca8k_get_ethtool_stats_eth, };static const struct qca8k_match_data qca833x = { .id =QCA8K_ID_QCA8337 , .mib_count =QCA8K_QCA833X_MIB_COUNT , + .autocast_mib = qca8k_get_ethtool_stats_eth, };static const struct of_device_id qca8k_of_match[] = {drivers/net/dsa/qca/qca8k.h +1
-0@@ -328,6 +328,7 @@ struct qca8k_match_data {u8 id;bool reduced_package;u8 mib_count; +int (*autocast_mib)(struct dsa_switch *ds,int port,u64 *data); };enum {Signature · 1 line
2.36.1
Signature · 1 line
Ansuel
Vladimir Oltean
maintainerRe: [net-next PATCH v2 01/15] net: dsa: qca8k: make mib autocast feature optional
Quoted 2 lines · Christian Marangi
Ok makes sense. Can I make a patch drop the use of
of_device_get_match_dataand then apply this on top?
Yes, that would be the idea, thanks.
Christian Marangi
maintainerPATCH v2 2/15 net: dsa: qca8k: move mib struct to common code
In reply to Christian MarangiThe same MIB struct is used by drivers based on qca8k family switch. Move it to common code to make it accessible also by other drivers.
---
drivers/net/dsa/qca/Makefile | 1 +
drivers/net/dsa/qca/{qca8k.c => qca8k-8xxx.c} | 51 ---------------
drivers/net/dsa/qca/qca8k-common.c | 63 +++++++++++++++++++
drivers/net/dsa/qca/qca8k.h | 3 +
4 files changed, 67 insertions(+), 51 deletions(-)
rename drivers/net/dsa/qca/{qca8k.c => qca8k-8xxx.c} (98%)
create mode 100644 drivers/net/dsa/qca/qca8k-common.cdrivers/net/dsa/qca/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_NET_DSA_AR9331) += ar9331.o obj-$(CONFIG_NET_DSA_QCA8K) += qca8k.o +qca8k-y += qca8k-common.o qca8k-8xxx.o
drivers/net/dsa/qca/qca8k-8xxx.c renamed from drivers/net/dsa/qca/qca8k.c +0 -51
57 lines not on this page · raw message
drivers/net/dsa/qca/qca8k-common.c new file +63 -0
63 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +3 -0
@@ -417,4 +417,7 @@ struct qca8k_fdb { u8 mac[6]; }; +/* Common setup function */ +extern const struct qca8k_mib_desc ar8327_mib[]; +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Re: [net-next PATCH v2 02/15] net: dsa: qca8k: move mib struct to common code
Quoted 5 lines · Christian Marangi
The same MIB struct is used by drivers based on qca8k family switch. Move it to common code to make it accessible also by other drivers.
Signed-off-by Christian Marangi <[email protected]>---
Christian Marangi
maintainerPATCH v2 3/15 net: dsa: qca8k: move qca8k read/write/rmw and reg table to common code
In reply to Christian MarangiThe same reg table and read/write/rmw function are used by drivers based on qca8k family switch.
Move them to common code to make it accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 42 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 39 +++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 6 +++++ 3 files changed, 45 insertions(+), 42 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -42
@@ -133,24 +133,6 @@ qca8k_set_page(struct qca8k_priv *priv, u16 page)return 0 ; } -static int -qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) -{ -return regmap_read (priv->regmap, reg, val); -} - -static int -qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) -{ -return regmap_write (priv->regmap, reg, val); -} - -static int -qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) -{ -return regmap_update_bits (priv->regmap, reg, mask, write_val); -} -static void qca8k_rw_reg_ack_handler (struct dsa_switch *ds,struct sk_buff *skb) {struct qca8k_mgmt_eth_data *mgmt_eth_data;
@@ -483,30 +465,6 @@ qca8k_regmap_update_bits(void *ctx, uint32_t reg, uint32_t mask, uint32_t write_return ret; } -static const struct regmap_range qca8k_readable_ranges[] = { -regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ -regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ -regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ -regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ -regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ -regmap_reg_range (0x0800 ,0x0b70 ),/* QM */ -regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ -regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ -regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ -regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ -regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ -regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ -regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ -regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ -regmap_reg_range (0x1600 ,0x16ac ),/* MIB - Port6 */ - -}; - -static const struct regmap_access_table qca8k_readable_table = { - .yes_ranges = qca8k_readable_ranges, - .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), -}; -static struct regmap_config qca8k_regmap_config = { .reg_bits =16 , .val_bits =32 ,
drivers/net/dsa/qca/qca8k-common.c +39 -0
@@ -61,3 +61,42 @@ const struct qca8k_mib_desc ar8327_mib[] = {MIB_DESC (1 ,0xa8 ,"RXUnicast" ), MIB_DESC(1, 0xac, "TXUnicast"), }; + +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) +{ +return regmap_read (priv->regmap, reg, val); +} + +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) +{ +return regmap_write (priv->regmap, reg, val); +} + +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) +{ +return regmap_update_bits (priv->regmap, reg, mask, write_val); +} + +static const struct regmap_range qca8k_readable_ranges[] = { +regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ +regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ +regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ +regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ +regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ +regmap_reg_range (0x0800 ,0x0b70 ),/* QM */ +regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ +regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ +regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ +regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ +regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ +regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ +regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ +regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ +regmap_reg_range (0x1600 ,0x16ac ),/* MIB - Port6 */ + +}; + +const struct regmap_access_table qca8k_readable_table = { + .yes_ranges = qca8k_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), +};
drivers/net/dsa/qca/qca8k.h +6 -0
@@ -419,5 +419,11 @@ struct qca8k_fdb {/* Common setup function */ extern const struct qca8k_mib_desc ar8327_mib[]; +extern const struct regmap_access_table qca8k_readable_table; + +/* Common read/write/rmw function */ +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val); +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val); +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val);#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Re: [net-next PATCH v2 03/15] net: dsa: qca8k: move qca8k read/write/rmw and reg table to common code
Quoted 6 lines · Christian Marangi
The same reg table and read/write/rmw function are used by drivers based on qca8k family switch.
Move them to common code to make it accessible also by other drivers.Signed-off-by Christian Marangi <[email protected]>---
Note for this and future patches: I can't actually double-check what is indeed common with ipq4019 and what isn't, I'll just review the correctness of the movement.
In this case
with one comment below
Quoted 96 lines
drivers/net/dsa/qca/qca8k-8xxx.c | 42 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 39 +++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 6 +++++ 3 files changed, 45 insertions(+), 42 deletions(-)drivers/net/dsa/qca/qca8k-8xxx.c +0
-42@@ -133,24 +133,6 @@ qca8k_set_page(struct qca8k_priv *priv, u16 page)return 0 ; } -static int -qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) -{ -return regmap_read (priv->regmap, reg, val); -} - -static int -qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) -{ -return regmap_write (priv->regmap, reg, val); -} - -static int -qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) -{ -return regmap_update_bits (priv->regmap, reg, mask, write_val); -} -static void qca8k_rw_reg_ack_handler (struct dsa_switch *ds,struct sk_buff *skb) {struct qca8k_mgmt_eth_data *mgmt_eth_data;@@ -483,30 +465,6 @@ qca8k_regmap_update_bits(void *ctx, uint32_t reg, uint32_t mask, uint32_t write_return ret; } -static const struct regmap_range qca8k_readable_ranges[] = { -regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ -regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ -regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ -regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ -regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ -regmap_reg_range (0x0800 ,0x0b70 ),/* QM */ -regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ -regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ -regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ -regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ -regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ -regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ -regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ -regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ -regmap_reg_range (0x1600 ,0x16ac ),/* MIB - Port6 */ - -}; - -static const struct regmap_access_table qca8k_readable_table = { - .yes_ranges = qca8k_readable_ranges, - .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), -}; -static struct regmap_config qca8k_regmap_config = { .reg_bits =16 , .val_bits =32 ,drivers/net/dsa/qca/qca8k-common.c +23
-0@@ -61,3 +61,42 @@ const struct qca8k_mib_desc ar8327_mib[] = {MIB_DESC (1 ,0xa8 ,"RXUnicast" ), MIB_DESC(1, 0xac, "TXUnicast"), }; + +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) +{ +return regmap_read (priv->regmap, reg, val); +} + +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) +{ +return regmap_write (priv->regmap, reg, val); +} + +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) +{ +return regmap_update_bits (priv->regmap, reg, mask, write_val); +} + +static const struct regmap_range qca8k_readable_ranges[] = { +regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ +regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ +regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ +regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ +regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ + regmap_reg_range(0x0800, 0x0b70), /* QM */
drivers/net/dsa/qca/qca8k-common.c const struct qca8k_mib_desc ar8327_mib[] = { · line 96
Quoted 10 lines
drivers/net/dsa/qca/qca8k-common.c +10
-0+regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ +regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ +regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ +regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ +regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ +regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ +regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ +regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ + regmap_reg_range(0x1600, 0x16ac), /* MIB - Port6 */ +
Please delete the extra newline.
Quoted 25 lines
drivers/net/dsa/qca/qca8k-common.c +6
-0+}; + +const struct regmap_access_table qca8k_readable_table = { + .yes_ranges = qca8k_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), +};drivers/net/dsa/qca/qca8k.h +6
-0@@ -419,5 +419,11 @@ struct qca8k_fdb {/* Common setup function */ extern const struct qca8k_mib_desc ar8327_mib[]; +extern const struct regmap_access_table qca8k_readable_table; + +/* Common read/write/rmw function */ +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val); +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val); +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val);#endif /* __QCA8K_H */ Signature · 1 line
2.36.1
Christian Marangi
maintainerPATCH v2 3/15 net: dsa: qca8k: move qca8kread/write/rmw and reg table to common code
In reply to Christian MarangiThe same reg table and function are used by drivers based on qca8k family switch. Move them to common code to make it accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 42 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 39 +++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 6 +++++ 3 files changed, 45 insertions(+), 42 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -42
@@ -133,24 +133,6 @@ qca8k_set_page(struct qca8k_priv *priv, u16 page)return 0 ; } -static int -qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) -{ -return regmap_read (priv->regmap, reg, val); -} - -static int -qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) -{ -return regmap_write (priv->regmap, reg, val); -} - -static int -qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) -{ -return regmap_update_bits (priv->regmap, reg, mask, write_val); -} -static void qca8k_rw_reg_ack_handler (struct dsa_switch *ds,struct sk_buff *skb) {struct qca8k_mgmt_eth_data *mgmt_eth_data;
@@ -483,30 +465,6 @@ qca8k_regmap_update_bits(void *ctx, uint32_t reg, uint32_t mask, uint32_t write_return ret; } -static const struct regmap_range qca8k_readable_ranges[] = { -regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ -regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ -regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ -regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ -regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ -regmap_reg_range (0x0800 ,0x0b70 ),/* QM */ -regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ -regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ -regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ -regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ -regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ -regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ -regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ -regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ -regmap_reg_range (0x1600 ,0x16ac ),/* MIB - Port6 */ - -}; - -static const struct regmap_access_table qca8k_readable_table = { - .yes_ranges = qca8k_readable_ranges, - .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), -}; -static struct regmap_config qca8k_regmap_config = { .reg_bits =16 , .val_bits =32 ,
drivers/net/dsa/qca/qca8k-common.c +39 -0
@@ -61,3 +61,42 @@ const struct qca8k_mib_desc ar8327_mib[] = {MIB_DESC (1 ,0xa8 ,"RXUnicast" ), MIB_DESC(1, 0xac, "TXUnicast"), }; + +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) +{ +return regmap_read (priv->regmap, reg, val); +} + +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) +{ +return regmap_write (priv->regmap, reg, val); +} + +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) +{ +return regmap_update_bits (priv->regmap, reg, mask, write_val); +} + +static const struct regmap_range qca8k_readable_ranges[] = { +regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ +regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ +regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ +regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ +regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ +regmap_reg_range (0x0800 ,0x0b70 ),/* QM */ +regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ +regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ +regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ +regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ +regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ +regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ +regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ +regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ +regmap_reg_range (0x1600 ,0x16ac ),/* MIB - Port6 */ + +}; + +const struct regmap_access_table qca8k_readable_table = { + .yes_ranges = qca8k_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), +};
drivers/net/dsa/qca/qca8k.h +6 -0
@@ -419,5 +419,11 @@ struct qca8k_fdb {/* Common setup function */ extern const struct qca8k_mib_desc ar8327_mib[]; +extern const struct regmap_access_table qca8k_readable_table; + +/* Common read/write/rmw function */ +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val); +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val); +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val);#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Christian Marangi
maintainerRe: [net-next PATCH v2 03/15] net: dsa: qca8k: move qca8kread/write/rmw and reg table to common code
Quoted 137 lines · Christian Marangi
The same reg table and function are used by drivers based on qca8k family switch. Move them to common code to make it accessible also by other drivers.
Signed-off-by Christian Marangi <[email protected]>--- drivers/net/dsa/qca/qca8k-8xxx.c | 42 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 39 +++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 6 +++++ 3 files changed, 45 insertions(+), 42 deletions(-)drivers/net/dsa/qca/qca8k-8xxx.c +0
-42@@ -133,24 +133,6 @@ qca8k_set_page(struct qca8k_priv *priv, u16 page)return 0 ; } -static int -qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) -{ -return regmap_read (priv->regmap, reg, val); -} - -static int -qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) -{ -return regmap_write (priv->regmap, reg, val); -} - -static int -qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) -{ -return regmap_update_bits (priv->regmap, reg, mask, write_val); -} -static void qca8k_rw_reg_ack_handler (struct dsa_switch *ds,struct sk_buff *skb) {struct qca8k_mgmt_eth_data *mgmt_eth_data;@@ -483,30 +465,6 @@ qca8k_regmap_update_bits(void *ctx, uint32_t reg, uint32_t mask, uint32_t write_return ret; } -static const struct regmap_range qca8k_readable_ranges[] = { -regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ -regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ -regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ -regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ -regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ -regmap_reg_range (0x0800 ,0x0b70 ),/* QM */ -regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ -regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ -regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ -regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ -regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ -regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ -regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ -regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ -regmap_reg_range (0x1600 ,0x16ac ),/* MIB - Port6 */ - -}; - -static const struct regmap_access_table qca8k_readable_table = { - .yes_ranges = qca8k_readable_ranges, - .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), -}; -static struct regmap_config qca8k_regmap_config = { .reg_bits =16 , .val_bits =32 ,drivers/net/dsa/qca/qca8k-common.c +39
-0@@ -61,3 +61,42 @@ const struct qca8k_mib_desc ar8327_mib[] = {MIB_DESC (1 ,0xa8 ,"RXUnicast" ), MIB_DESC(1, 0xac, "TXUnicast"), }; + +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val) +{ +return regmap_read (priv->regmap, reg, val); +} + +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val) +{ +return regmap_write (priv->regmap, reg, val); +} + +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val) +{ +return regmap_update_bits (priv->regmap, reg, mask, write_val); +} + +static const struct regmap_range qca8k_readable_ranges[] = { +regmap_reg_range (0x0000 ,0x00e4 ),/* Global control */ +regmap_reg_range (0x0100 ,0x0168 ),/* EEE control */ +regmap_reg_range (0x0200 ,0x0270 ),/* Parser control */ +regmap_reg_range (0x0400 ,0x0454 ),/* ACL */ +regmap_reg_range (0x0600 ,0x0718 ),/* Lookup */ +regmap_reg_range (0x0800 ,0x0b70 ),/* QM */ +regmap_reg_range (0x0c00 ,0x0c80 ),/* PKT */ +regmap_reg_range (0x0e00 ,0x0e98 ),/* L3 */ +regmap_reg_range (0x1000 ,0x10ac ),/* MIB - Port0 */ +regmap_reg_range (0x1100 ,0x11ac ),/* MIB - Port1 */ +regmap_reg_range (0x1200 ,0x12ac ),/* MIB - Port2 */ +regmap_reg_range (0x1300 ,0x13ac ),/* MIB - Port3 */ +regmap_reg_range (0x1400 ,0x14ac ),/* MIB - Port4 */ +regmap_reg_range (0x1500 ,0x15ac ),/* MIB - Port5 */ +regmap_reg_range (0x1600 ,0x16ac ),/* MIB - Port6 */ + +}; + +const struct regmap_access_table qca8k_readable_table = { + .yes_ranges = qca8k_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (qca8k_readable_ranges), +};drivers/net/dsa/qca/qca8k.h +6
-0@@ -419,5 +419,11 @@ struct qca8k_fdb {/* Common setup function */ extern const struct qca8k_mib_desc ar8327_mib[]; +extern const struct regmap_access_table qca8k_readable_table; + +/* Common read/write/rmw function */ +int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val); +int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val); +int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val);#endif /* __QCA8K_H */ Signature · 1 line
2.36.1
This slipped and was sent by mistake (and was just a typo fixed in the title)
Please ignore. Sorry.
Signature · 1 line
Ansuel
Jakub Kicinski
maintainerRe: [net-next PATCH v2 03/15] net: dsa: qca8k: move qca8kread/write/rmw and reg table to common code
Quoted 4 lines · On Tue, 19 Jul 2022 03:00:13 +0200 Christian Marangi wrote:
This slipped and was sent by mistake (and was just a typo fixed in the title)
Please ignore. Sorry.
Please make sure you wait 24h before reposting, as per
BTW what is your name? Christian Marangi or Ansuel Smith? :S
Jakub Kicinski
maintainerRe: [net-next PATCH v2 03/15] net: dsa: qca8k: move qca8kread/write/rmw and reg table to common code
Quoted 9 lines · On Mon, 18 Jul 2022 18:30:06 -0700 Jakub Kicinski wrote:
Quoted 4 lines · On Tue, 19 Jul 2022 03:00:13 +0200 Christian Marangi wrote:
This slipped and was sent by mistake (and was just a typo fixed in the title)
Please ignore. Sorry.
Please make sure you wait 24h before reposting, as per
Looks like patchwork picked the right one, no? This is the patch we need:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
And this one is to be ignored:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Right? If so - no repost needed.
Christian Marangi
maintainerRe: [net-next PATCH v2 03/15] net: dsa: qca8k: move qca8kread/write/rmw and reg table to common code
Quoted 14 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 18 Jul 2022 18:30:06 -0700 Jakub Kicinski wrote:
Quoted 4 lines · On Tue, 19 Jul 2022 03:00:13 +0200 Christian Marangi wrote:
This slipped and was sent by mistake (and was just a typo fixed in the title)
Please ignore. Sorry.
Please make sure you wait 24h before reposting, as per
Looks like patchwork picked the right one, no? This is the patch we need:
Quoted 7 lines
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
And this one is to be ignored:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Right? If so - no repost needed.
Yes correct. I was lucky.
Signature · 1 line
Ansuel
Christian Marangi
maintainerRe: [net-next PATCH v2 03/15] net: dsa: qca8k: move qca8kread/write/rmw and reg table to common code
In reply to Jakub KicinskiQuoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 19 Jul 2022 03:00:13 +0200 Christian Marangi wrote:
This slipped and was sent by mistake (and was just a typo fixed in the title)
Please ignore. Sorry.
Please make sure you wait 24h before reposting, as per
Oh sorry... you are right, had a long discussion with Vladimir on the changes to do and I thought it was a good idea (since v1 was really not reviewable)
Quoted 4 lines
BTW what is your name? Christian Marangi or Ansuel Smith? :S
I would prefer Ansuel but Christian Marangi is the one.
Signature · 1 line
Ansuel
Vladimir Oltean
maintainerRe: [net-next PATCH v2 03/15] net: dsa: qca8k: move qca8kread/write/rmw and reg table to common code
Quoted 5 lines · Christian Marangi
Quoted 4 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 19 Jul 2022 03:00:13 +0200 Christian Marangi wrote:
This slipped and was sent by mistake (and was just a typo fixed in the title)
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Please ignore. Sorry.
Please make sure you wait 24h before reposting, as per
Oh sorry... you are right, had a long discussion with Vladimir on the changes to do and I thought it was a good idea (since v1 was really not reviewable)
I think Jakub said "please wait at least 24h until reposing v3". Your RFC v1 was posted 3 days ago, I believe we all agree that's more than 24 hours ago, and therefore not what Jakub was talking about.
Christian Marangi
maintainerPATCH v2 4/15 net: dsa: qca8k: move qca8k bulk read/write helper to common code
In reply to Christian MarangiThe same ATU function are used by drivers based on qca8k family switch. Move the bulk read/write helper to common code to declare these shared ATU functions in common code.
These helper will be dropped when regmap correctly support bulk read/write.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 43 ++++------------------------ drivers/net/dsa/qca/qca8k-common.c | 46 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 8 ++++++ 3 files changed, 60 insertions(+), 37 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +6 -37
@@ -342,43 +342,6 @@ qca8k_regmap_update_bits_eth(struct qca8k_priv *priv, u32 reg, u32 mask, u32 wrireturn qca8k_write_eth (priv, reg, &val,sizeof (val)); } -static int -qca8k_bulk_read (struct qca8k_priv *priv,u32 reg,u32 *val,int len) -{ -int i, count = len /sizeof (u32), ret; - -if (priv->mgmt_master && !qca8k_read_eth (priv, reg, val, len)) -return 0 ; - -for (i =0 ; i < count; i++) { - ret =regmap_read (priv->regmap, reg + (i *4 ), val + i); -if (ret <0 ) -return ret; - } - -return 0 ; -} - -static int -qca8k_bulk_write (struct qca8k_priv *priv,u32 reg,u32 *val,int len) -{ -int i, count = len /sizeof (u32), ret; -u32 tmp; - -if (priv->mgmt_master && !qca8k_write_eth (priv, reg, val, len)) -return 0 ; - -for (i =0 ; i < count; i++) { - tmp = val[i]; - - ret =regmap_write (priv->regmap, reg + (i *4 ), tmp); -if (ret <0 ) -return ret; - } - -return 0 ; -} -static int qca8k_regmap_read (void *ctx,uint32_t reg,uint32_t *val) {
@@ -3168,18 +3131,24 @@ static const struct qca8k_match_data qca8327 = { .reduced_package = true, .mib_count = QCA8K_QCA832X_MIB_COUNT, .autocast_mib = qca8k_get_ethtool_stats_eth, + .read_eth = qca8k_read_eth, + .write_eth = qca8k_write_eth, };static const struct qca8k_match_data qca8328 = { .id =QCA8K_ID_QCA8327 , .mib_count =QCA8K_QCA832X_MIB_COUNT , .autocast_mib = qca8k_get_ethtool_stats_eth, + .read_eth = qca8k_read_eth, + .write_eth = qca8k_write_eth, };static const struct qca8k_match_data qca833x = { .id =QCA8K_ID_QCA8337 , .mib_count =QCA8K_QCA833X_MIB_COUNT , .autocast_mib = qca8k_get_ethtool_stats_eth, + .read_eth = qca8k_read_eth, + .write_eth = qca8k_write_eth, };static const struct of_device_id qca8k_of_match[] = {
drivers/net/dsa/qca/qca8k-common.c +46 -0
55 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +8 -0
@@ -324,11 +324,16 @@ enum qca8k_mid_cmd { QCA8K_MIB_CAST = 3, }; +struct qca8k_priv ; +struct qca8k_match_data {u8 id;bool reduced_package;u8 mib_count;int (*autocast_mib)(struct dsa_switch *ds,int port,u64 *data); +/* TODO: remove these extra ops when we can support regmap bulk read/write */ +int (*read_eth)(struct qca8k_priv *priv,u32 reg,u32 *val,int len); +int (*write_eth)(struct qca8k_priv *priv,u32 reg,u32 *val,int len); };enum {
@@ -426,4 +431,7 @@ int qca8k_read(struct qca8k_priv *priv, u32 reg, u32 *val);int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val);int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val); +int qca8k_bulk_read (struct qca8k_priv *priv,u32 reg,u32 *val,int len); +int qca8k_bulk_write (struct qca8k_priv *priv,u32 reg,u32 *val,int len); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Vladimir Oltean
maintainerRe: [net-next PATCH v2 04/15] net: dsa: qca8k: move qca8k bulk read/write helper to common code
Quoted 8 lines · Christian Marangi
The same ATU function are used by drivers based on qca8k family switch. Move the bulk read/write helper to common code to declare these shared ATU functions in common code.
These helper will be dropped when regmap correctly support bulk read/write.Signed-off-by Christian Marangi <[email protected]>---
I'll re-review this patch after the changes w.r.t. of_device_get_match_data().
Christian Marangi
maintainerPATCH v2 5/15 net: dsa: qca8k: move fdb/vlan/mib init functions to common code
In reply to Christian MarangiThe same fdb,vlan and mib function are used by drivers based on qca8k family switch.
Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 364 ----------------------------- drivers/net/dsa/qca/qca8k-common.c | 361 ++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 15 ++ 3 files changed, 376 insertions(+), 364 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -364
@@ -441,370 +441,6 @@ static struct regmap_config qca8k_regmap_config = { .cache_type = REGCACHE_NONE, /* Explicitly disable CACHE */ }; -static int -qca8k_busy_wait (struct qca8k_priv *priv,u32 reg,u32 mask) -{ -u32 val; - -return regmap_read_poll_timeout (priv->regmap, reg, val, !(val & mask),0 , -QCA8K_BUSY_WAIT_TIMEOUT *USEC_PER_MSEC ); -} - -static int -qca8k_fdb_read (struct qca8k_priv *priv,struct qca8k_fdb *fdb) -{ -u32 reg[3 ]; -int ret; - -/* load the ARL table into an array */ - ret =qca8k_bulk_read (priv,QCA8K_REG_ATU_DATA0 , reg,sizeof (reg)); -if (ret) -return ret; - -/* vid - 83:72 */ - fdb->vid =FIELD_GET (QCA8K_ATU_VID_MASK , reg[2 ]); -/* aging - 67:64 */ - fdb->aging =FIELD_GET (QCA8K_ATU_STATUS_MASK , reg[2 ]); -/* portmask - 54:48 */ - fdb->port_mask =FIELD_GET (QCA8K_ATU_PORT_MASK , reg[1 ]); -/* mac - 47:0 */ - fdb->mac[0 ] =FIELD_GET (QCA8K_ATU_ADDR0_MASK , reg[1 ]); - fdb->mac[1 ] =FIELD_GET (QCA8K_ATU_ADDR1_MASK , reg[1 ]); - fdb->mac[2 ] =FIELD_GET (QCA8K_ATU_ADDR2_MASK , reg[0 ]); - fdb->mac[3 ] =FIELD_GET (QCA8K_ATU_ADDR3_MASK , reg[0 ]); - fdb->mac[4 ] =FIELD_GET (QCA8K_ATU_ADDR4_MASK , reg[0 ]); - fdb->mac[5 ] =FIELD_GET (QCA8K_ATU_ADDR5_MASK , reg[0 ]); - -return 0 ; -} - -static void -qca8k_fdb_write (struct qca8k_priv *priv,u16 vid,u8 port_mask,const u8 *mac, -u8 aging) -{ -u32 reg[3 ] = {0 }; - -/* vid - 83:72 */ - reg[2 ] =FIELD_PREP (QCA8K_ATU_VID_MASK , vid); -/* aging - 67:64 */ - reg[2 ] |=FIELD_PREP (QCA8K_ATU_STATUS_MASK , aging); -/* portmask - 54:48 */ - reg[1 ] =FIELD_PREP (QCA8K_ATU_PORT_MASK , port_mask); -/* mac - 47:0 */ - reg[1 ] |=FIELD_PREP (QCA8K_ATU_ADDR0_MASK , mac[0 ]); - reg[1 ] |=FIELD_PREP (QCA8K_ATU_ADDR1_MASK , mac[1 ]); - reg[0 ] |=FIELD_PREP (QCA8K_ATU_ADDR2_MASK , mac[2 ]); - reg[0 ] |=FIELD_PREP (QCA8K_ATU_ADDR3_MASK , mac[3 ]); - reg[0 ] |=FIELD_PREP (QCA8K_ATU_ADDR4_MASK , mac[4 ]); - reg[0 ] |=FIELD_PREP (QCA8K_ATU_ADDR5_MASK , mac[5 ]); - -/* load the array into the ARL table */ -qca8k_bulk_write (priv,QCA8K_REG_ATU_DATA0 , reg,sizeof (reg)); -} - -static int -qca8k_fdb_access (struct qca8k_priv *priv,enum qca8k_fdb_cmd cmd,int port) -{ -u32 reg; -int ret; - -/* Set the command and FDB index */ - reg =QCA8K_ATU_FUNC_BUSY ; - reg |= cmd; -if (port >=0 ) { - reg |=QCA8K_ATU_FUNC_PORT_EN ; - reg |=FIELD_PREP (QCA8K_ATU_FUNC_PORT_MASK , port); - } - -/* Write the function register triggering the table access */ - ret =qca8k_write (priv,QCA8K_REG_ATU_FUNC , reg); -if (ret) -return ret; - -/* wait for completion */ - ret =qca8k_busy_wait (priv,QCA8K_REG_ATU_FUNC ,QCA8K_ATU_FUNC_BUSY ); -if (ret) -return ret; - -/* Check for table full violation when adding an entry */ -if (cmd ==QCA8K_FDB_LOAD ) { - ret =qca8k_read (priv,QCA8K_REG_ATU_FUNC , ®); -if (ret <0 ) -return ret; -if (reg &QCA8K_ATU_FUNC_FULL ) -return -1 ; - } - -return 0 ; -} - -static int -qca8k_fdb_next (struct qca8k_priv *priv,struct qca8k_fdb *fdb,int port) -{ -int ret; - -qca8k_fdb_write (priv, fdb->vid, fdb->port_mask, fdb->mac, fdb->aging); - ret =qca8k_fdb_access (priv,QCA8K_FDB_NEXT , port); -if (ret <0 ) -return ret; - -return qca8k_fdb_read (priv, fdb); -} - -static int -qca8k_fdb_add (struct qca8k_priv *priv,const u8 *mac,u16 port_mask, -u16 vid,u8 aging) -{ -int ret; - -mutex_lock (&priv->reg_mutex); -qca8k_fdb_write (priv, vid, port_mask, mac, aging); - ret =qca8k_fdb_access (priv,QCA8K_FDB_LOAD ,-1 ); -mutex_unlock (&priv->reg_mutex); - -return ret; -} - -static int -qca8k_fdb_del (struct qca8k_priv *priv,const u8 *mac,u16 port_mask,u16 vid) -{ -int ret; - -mutex_lock (&priv->reg_mutex); -qca8k_fdb_write (priv, vid, port_mask, mac,0 ); - ret =qca8k_fdb_access (priv,QCA8K_FDB_PURGE ,-1 ); -mutex_unlock (&priv->reg_mutex); - -return ret; -} - -static void -qca8k_fdb_flush (struct qca8k_priv *priv) -{ -mutex_lock (&priv->reg_mutex); -qca8k_fdb_access (priv,QCA8K_FDB_FLUSH ,-1 ); -mutex_unlock (&priv->reg_mutex); -} - -static int -qca8k_fdb_search_and_insert (struct qca8k_priv *priv,u8 port_mask, -const u8 *mac,u16 vid) -{ -struct qca8k_fdb fdb = {0 }; -int ret; - -mutex_lock (&priv->reg_mutex); - -qca8k_fdb_write (priv, vid,0 , mac,0 ); - ret =qca8k_fdb_access (priv,QCA8K_FDB_SEARCH ,-1 ); -if (ret <0 ) - goto exit; - - ret =qca8k_fdb_read (priv, &fdb); -if (ret <0 ) - goto exit; - -/* Rule exist. Delete first */ -if (!fdb.aging) { - ret =qca8k_fdb_access (priv,QCA8K_FDB_PURGE ,-1 ); -if (ret) - goto exit; - } - -/* Add port to fdb portmask */ - fdb.port_mask |= port_mask; - -qca8k_fdb_write (priv, vid, fdb.port_mask, mac, fdb.aging); - ret =qca8k_fdb_access (priv,QCA8K_FDB_LOAD ,-1 ); - -exit: -mutex_unlock (&priv->reg_mutex); -return ret; -} - -static int -qca8k_fdb_search_and_del (struct qca8k_priv *priv,u8 port_mask, -const u8 *mac,u16 vid) -{ -struct qca8k_fdb fdb = {0 }; -int ret; - -mutex_lock (&priv->reg_mutex); - -qca8k_fdb_write (priv, vid,0 , mac,0 ); - ret =qca8k_fdb_access (priv,QCA8K_FDB_SEARCH ,-1 ); -if (ret <0 ) - goto exit; - -/* Rule doesn't exist. Why delete? */ -if (!fdb.aging) { - ret = -EINVAL ; - goto exit; - } - - ret =qca8k_fdb_access (priv,QCA8K_FDB_PURGE ,-1 ); -if (ret) - goto exit; - -/* Only port in the rule is this port. Don't re insert */ -if (fdb.port_mask == port_mask) - goto exit; - -/* Remove port from port mask */ - fdb.port_mask &= ~port_mask; - -qca8k_fdb_write (priv, vid, fdb.port_mask, mac, fdb.aging); - ret =qca8k_fdb_access (priv,QCA8K_FDB_LOAD ,-1 ); - -exit: -mutex_unlock (&priv->reg_mutex); -return ret; -} - -static int -qca8k_vlan_access (struct qca8k_priv *priv,enum qca8k_vlan_cmd cmd,u16 vid) -{ -u32 reg; -int ret; - -/* Set the command and VLAN index */ - reg =QCA8K_VTU_FUNC1_BUSY ; - reg |= cmd; - reg |=FIELD_PREP (QCA8K_VTU_FUNC1_VID_MASK , vid); - -/* Write the function register triggering the table access */ - ret =qca8k_write (priv,QCA8K_REG_VTU_FUNC1 , reg); -if (ret) -return ret; - -/* wait for completion */ - ret =qca8k_busy_wait (priv,QCA8K_REG_VTU_FUNC1 ,QCA8K_VTU_FUNC1_BUSY ); -if (ret) -return ret; - -/* Check for table full violation when adding an entry */ -if (cmd ==QCA8K_VLAN_LOAD ) { - ret =qca8k_read (priv,QCA8K_REG_VTU_FUNC1 , ®); -if (ret <0 ) -return ret; -if (reg &QCA8K_VTU_FUNC1_FULL ) -return -ENOMEM ; - } - -return 0 ; -} - -static int -qca8k_vlan_add (struct qca8k_priv *priv,u8 port,u16 vid,bool untagged) -{ -u32 reg; -int ret; - -/* -We do the right thing with VLAN 0 and treat it as untagged while -preserving the tag on egress. -*/ -if (vid ==0 ) -return 0 ; - -mutex_lock (&priv->reg_mutex); - ret =qca8k_vlan_access (priv,QCA8K_VLAN_READ , vid); -if (ret <0 ) - goto out; - - ret =qca8k_read (priv,QCA8K_REG_VTU_FUNC0 , ®); -if (ret <0 ) - goto out; - reg |=QCA8K_VTU_FUNC0_VALID |QCA8K_VTU_FUNC0_IVL_EN ; - reg &= ~QCA8K_VTU_FUNC0_EG_MODE_PORT_MASK (port); -if (untagged) - reg |=QCA8K_VTU_FUNC0_EG_MODE_PORT_UNTAG (port); -else - reg |=QCA8K_VTU_FUNC0_EG_MODE_PORT_TAG (port); - - ret =qca8k_write (priv,QCA8K_REG_VTU_FUNC0 , reg); -if (ret) - goto out; - ret =qca8k_vlan_access (priv,QCA8K_VLAN_LOAD , vid); - -out: -mutex_unlock (&priv->reg_mutex); - -return ret; -} - -static int -qca8k_vlan_del (struct qca8k_priv *priv,u8 port,u16 vid) -{ -u32 reg, mask; -int ret, i; -bool del; - -mutex_lock (&priv->reg_mutex); - ret =qca8k_vlan_access (priv,QCA8K_VLAN_READ , vid); -if (ret <0 ) - goto out; - - ret =qca8k_read (priv,QCA8K_REG_VTU_FUNC0 , ®); -if (ret <0 ) - goto out; - reg &= ~QCA8K_VTU_FUNC0_EG_MODE_PORT_MASK (port); - reg |=QCA8K_VTU_FUNC0_EG_MODE_PORT_NOT (port); - -/* Check if we're the last member to be removed */ - del = true; -for (i =0 ; i <QCA8K_NUM_PORTS ; i++) { - mask =QCA8K_VTU_FUNC0_EG_MODE_PORT_NOT (i); - -if ((reg & mask) != mask) { - del = false; -break ; - } - } - -if (del) { - ret =qca8k_vlan_access (priv,QCA8K_VLAN_PURGE , vid); - }else { - ret =qca8k_write (priv,QCA8K_REG_VTU_FUNC0 , reg); -if (ret) - goto out; - ret =qca8k_vlan_access (priv,QCA8K_VLAN_LOAD , vid); - } - -out: -mutex_unlock (&priv->reg_mutex); - -return ret; -} - -static int -qca8k_mib_init (struct qca8k_priv *priv) -{ -int ret; - -mutex_lock (&priv->reg_mutex); - ret =regmap_update_bits (priv->regmap,QCA8K_REG_MIB , -QCA8K_MIB_FUNC |QCA8K_MIB_BUSY , -FIELD_PREP (QCA8K_MIB_FUNC ,QCA8K_MIB_FLUSH ) | -QCA8K_MIB_BUSY ); -if (ret) - goto exit; - - ret =qca8k_busy_wait (priv,QCA8K_REG_MIB ,QCA8K_MIB_BUSY ); -if (ret) - goto exit; - - ret =regmap_set_bits (priv->regmap,QCA8K_REG_MIB ,QCA8K_MIB_CPU_KEEP ); -if (ret) - goto exit; - - ret =qca8k_write (priv,QCA8K_REG_MODULE_EN ,QCA8K_MODULE_EN_MIB ); - -exit: -mutex_unlock (&priv->reg_mutex); -return ret; -} -static void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) {
drivers/net/dsa/qca/qca8k-common.c +361 -0
364 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +15 -0
@@ -425,6 +425,7 @@ struct qca8k_fdb {/* Common setup function */ extern const struct qca8k_mib_desc ar8327_mib[];extern const struct regmap_access_table qca8k_readable_table; +int qca8k_mib_init (struct qca8k_priv *priv);/* Common read/write/rmw function */ int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val);
@@ -434,4 +435,18 @@ int qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 write_val);int qca8k_bulk_read (struct qca8k_priv *priv,u32 reg,u32 *val,int len);int qca8k_bulk_write (struct qca8k_priv *priv,u32 reg,u32 *val,int len); +/* Common ops function */ +int qca8k_fdb_access (struct qca8k_priv *priv,enum qca8k_fdb_cmd cmd,int port); +int qca8k_fdb_next (struct qca8k_priv *priv,struct qca8k_fdb *fdb,int port); +int qca8k_fdb_add (struct qca8k_priv *priv,const u8 *mac,u16 port_mask, +u16 vid,u8 aging); +int qca8k_fdb_del (struct qca8k_priv *priv,const u8 *mac,u16 port_mask,u16 vid); +void qca8k_fdb_flush (struct qca8k_priv *priv); +int qca8k_fdb_search_and_insert (struct qca8k_priv *priv,u8 port_mask, +const u8 *mac,u16 vid); +int qca8k_fdb_search_and_del (struct qca8k_priv *priv,u8 port_mask, +const u8 *mac,u16 vid); +int qca8k_vlan_add (struct qca8k_priv *priv,u8 port,u16 vid,bool untagged); +int qca8k_vlan_del (struct qca8k_priv *priv,u8 port,u16 vid); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Vladimir Oltean
maintainerRe: [net-next PATCH v2 05/15] net: dsa: qca8k: move fdb/vlan/mib init functions to common code
Quoted 6 lines · Christian Marangi
The same fdb,vlan and mib function are used by drivers based on qca8k family switch.
Move them to common code to make them accessible also by other drivers.Signed-off-by Christian Marangi <[email protected]>---
Make port_fast_age be part of this patch too, it belongs to the FDB class of functions. This in turn makes it possible to avoid exporting qca8k_fdb_access().
Christian Marangi
maintainerPATCH v2 6/15 net: dsa: qca8k: move port set status/eee/ethtool stats function to common code
In reply to Christian MarangiThe same logic to disable/enable port, set eee and get ethtool stats is used by drivers based on qca8k family switch.
Move it to common code to make it accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 114 ----------------------------- drivers/net/dsa/qca/qca8k-common.c | 114 +++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 11 +++ 3 files changed, 125 insertions(+), 114 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -114
@@ -441,21 +441,6 @@ static struct regmap_config qca8k_regmap_config = { .cache_type = REGCACHE_NONE, /* Explicitly disable CACHE */ }; -static void -qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable) -{ -u32 mask =QCA8K_PORT_STATUS_TXMAC |QCA8K_PORT_STATUS_RXMAC ; - -/* Port 0 and 6 have no internal PHY */ -if (port >0 && port <6 ) - mask |=QCA8K_PORT_STATUS_LINK_AUTO ; - -if (enable) -regmap_set_bits (priv->regmap,QCA8K_REG_PORT_STATUS (port), mask); -else -regmap_clear_bits (priv->regmap,QCA8K_REG_PORT_STATUS (port), mask); -} -static int qca8k_phy_eth_busy_wait (struct qca8k_mgmt_eth_data *mgmt_eth_data,struct sk_buff *read_skb,u32 *val)
@@ -1499,23 +1484,6 @@ static void qca8k_setup_pcs(struct qca8k_priv *priv, struct qca8k_pcs *qpcs, qpcs->port = port; } -static void -qca8k_get_strings (struct dsa_switch *ds,int port,u32 stringset,uint8_t *data) -{ -const struct qca8k_match_data *match_data; -struct qca8k_priv *priv = ds->priv; -int i; - -if (stringset !=ETH_SS_STATS ) -return ; - - match_data =of_device_get_match_data (priv->dev); - -for (i =0 ; i < match_data->mib_count; i++) -strncpy (data + i *ETH_GSTRING_LEN , ar8327_mib[i].name, -ETH_GSTRING_LEN ); -} -static void qca8k_mib_autocast_handler (struct dsa_switch *ds,struct sk_buff *skb) {const struct qca8k_match_data *match_data;
@@ -1607,88 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)return ret; } -static void -qca8k_get_ethtool_stats (struct dsa_switch *ds,int port, -uint64_t *data) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -const struct qca8k_match_data *match_data; -const struct qca8k_mib_desc *mib; -u32 reg, i, val; -u32 hi =0 ; -int ret; - - match_data =of_device_get_match_data (priv->dev); - -if (priv->mgmt_master && match_data->autocast_mib && - match_data->autocast_mib (ds, port, data) >0 ) -return ; - -for (i =0 ; i < match_data->mib_count; i++) { - mib = &ar8327_mib[i]; - reg =QCA8K_PORT_MIB_COUNTER (port) + mib->offset; - - ret =qca8k_read (priv, reg, &val); -if (ret <0 ) -continue ; - -if (mib->size ==2 ) { - ret =qca8k_read (priv, reg +4 , &hi); -if (ret <0 ) -continue ; - } - - data[i] = val; -if (mib->size ==2 ) - data[i] |= (u64 )hi <<32 ; - } -} - -static int -qca8k_get_sset_count (struct dsa_switch *ds,int port,int sset) -{ -const struct qca8k_match_data *match_data; -struct qca8k_priv *priv = ds->priv; - -if (sset !=ETH_SS_STATS ) -return 0 ; - - match_data =of_device_get_match_data (priv->dev); - -return match_data->mib_count; -} - -static int -qca8k_set_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *eee) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -u32 lpi_en =QCA8K_REG_EEE_CTRL_LPI_EN (port); -u32 reg; -int ret; - -mutex_lock (&priv->reg_mutex); - ret =qca8k_read (priv,QCA8K_REG_EEE_CTRL , ®); -if (ret <0 ) - goto exit; - -if (eee->eee_enabled) - reg |= lpi_en; -else - reg &= ~lpi_en; - ret =qca8k_write (priv,QCA8K_REG_EEE_CTRL , reg); - -exit: -mutex_unlock (&priv->reg_mutex); -return ret; -} - -static int -qca8k_get_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *e) -{ -/* Nothing to do on the port's MAC */ -return 0 ; -} -static void qca8k_port_stp_state_set (struct dsa_switch *ds,int port,u8 state) {
drivers/net/dsa/qca/qca8k-common.c +114 -0
117 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +11 -0
@@ -426,6 +426,7 @@ struct qca8k_fdb {extern const struct qca8k_mib_desc ar8327_mib[];extern const struct regmap_access_table qca8k_readable_table;int qca8k_mib_init (struct qca8k_priv *priv); +void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable);/* Common read/write/rmw function */ int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val);
@@ -449,4 +450,14 @@ int qca8k_fdb_search_and_del(struct qca8k_priv *priv, u8 port_mask,int qca8k_vlan_add (struct qca8k_priv *priv,u8 port,u16 vid,bool untagged);int qca8k_vlan_del (struct qca8k_priv *priv,u8 port,u16 vid); +/* Common ethtool stats function */ +void qca8k_get_strings (struct dsa_switch *ds,int port,u32 stringset,uint8_t *data); +void qca8k_get_ethtool_stats (struct dsa_switch *ds,int port, +uint64_t *data); +int qca8k_get_sset_count (struct dsa_switch *ds,int port,int sset); + +/* Common eee function */ +int qca8k_set_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *eee); +int qca8k_get_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *e); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Re: [net-next PATCH v2 06/15] net: dsa: qca8k: move port set status/eee/ethtool stats function to common code
Quoted 6 lines · Christian Marangi
The same logic to disable/enable port, set eee and get ethtool stats is used by drivers based on qca8k family switch.
Move it to common code to make it accessible also by other drivers.Signed-off-by Christian Marangi <[email protected]>---
Christian Marangi
maintainerRe: [net-next PATCH v2 06/15] net: dsa: qca8k: move port set status/eee/ethtool stats function to common code
Quoted 9 lines · Vladimir Oltean
Quoted 6 lines · Christian Marangi
The same logic to disable/enable port, set eee and get ethtool stats is used by drivers based on qca8k family switch.
Move it to common code to make it accessible also by other drivers.Signed-off-by Christian Marangi <[email protected]>---
Reviewed-by Vladimir Oltean <[email protected]>
(considering the ethtool function will change, is it OK to keep the review tag on the next revision?)
Signature · 1 line
Ansuel
Vladimir Oltean
maintainerRe: [net-next PATCH v2 06/15] net: dsa: qca8k: move port set status/eee/ethtool stats function to common code
Quoted 6 lines · Christian Marangi
Quoted 5 lines · Vladimir Oltean
Quoted 4 lines · Christian Marangi
The same logic to disable/enable port, set eee and get ethtool stats is used by drivers based on qca8k family switch.
Move it to common code to make it accessible also by other drivers.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Christian Marangi <[email protected]>---
Reviewed-by Vladimir Oltean <[email protected]>(considering the ethtool function will change, is it OK to keep the review tag on the next revision?)
As long as the removed code is identical to the added one, yes. If there are problems with the changes on the ethtool_stats function, I'll leave my comments there.
Christian Marangi
maintainerPATCH v2 7/15 net: dsa: qca8k: move bridge functions to common code
In reply to Christian MarangiThe same bridge functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 93 ----------------------------- drivers/net/dsa/qca/qca8k-common.c | 94 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 9 +++ 3 files changed, 103 insertions(+), 93 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -93
@@ -1575,99 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)return ret; } -static void -qca8k_port_stp_state_set (struct dsa_switch *ds,int port,u8 state) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -u32 stp_state; - -switch (state) { -case BR_STATE_DISABLED : - stp_state =QCA8K_PORT_LOOKUP_STATE_DISABLED ; -break ; -case BR_STATE_BLOCKING : - stp_state =QCA8K_PORT_LOOKUP_STATE_BLOCKING ; -break ; -case BR_STATE_LISTENING : - stp_state =QCA8K_PORT_LOOKUP_STATE_LISTENING ; -break ; -case BR_STATE_LEARNING : - stp_state =QCA8K_PORT_LOOKUP_STATE_LEARNING ; -break ; -case BR_STATE_FORWARDING : -default : - stp_state =QCA8K_PORT_LOOKUP_STATE_FORWARD ; -break ; - } - -qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), -QCA8K_PORT_LOOKUP_STATE_MASK , stp_state); -} - -static int qca8k_port_bridge_join (struct dsa_switch *ds,int port, -struct dsa_bridge bridge, -bool *tx_fwd_offload, -struct netlink_ext_ack *extack) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -int port_mask, cpu_port; -int i, ret; - - cpu_port =dsa_to_port (ds, port)->cpu_dp->index; - port_mask =BIT (cpu_port); - -for (i =0 ; i <QCA8K_NUM_PORTS ; i++) { -if (dsa_is_cpu_port (ds, i)) -continue ; -if (!dsa_port_offloads_bridge (dsa_to_port (ds, i), &bridge)) -continue ; -/* Add this port to the portvlan mask of the other ports -* in the bridge -*/ - ret =regmap_set_bits (priv->regmap, -QCA8K_PORT_LOOKUP_CTRL (i), -BIT (port)); -if (ret) -return ret; -if (i != port) - port_mask |=BIT (i); - } - -/* Add all other ports to this ports portvlan mask */ - ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), -QCA8K_PORT_LOOKUP_MEMBER , port_mask); - -return ret; -} - -static void qca8k_port_bridge_leave (struct dsa_switch *ds,int port, -struct dsa_bridge bridge) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -int cpu_port, i; - - cpu_port =dsa_to_port (ds, port)->cpu_dp->index; - -for (i =0 ; i <QCA8K_NUM_PORTS ; i++) { -if (dsa_is_cpu_port (ds, i)) -continue ; -if (!dsa_port_offloads_bridge (dsa_to_port (ds, i), &bridge)) -continue ; -/* Remove this port to the portvlan mask of the other ports -* in the bridge -*/ -regmap_clear_bits (priv->regmap, -QCA8K_PORT_LOOKUP_CTRL (i), -BIT (port)); - } - -/* Set the cpu port to be the only one in the portvlan mask of -* this port -*/ -qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), -QCA8K_PORT_LOOKUP_MEMBER ,BIT (cpu_port)); -} -static void qca8k_port_fast_age (struct dsa_switch *ds,int port) {
drivers/net/dsa/qca/qca8k-common.c +94 -0
103 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +9 -0
@@ -460,4 +460,13 @@ int qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset);int qca8k_set_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *eee);int qca8k_get_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *e); +/* Common bridge function */ +void qca8k_port_stp_state_set (struct dsa_switch *ds,int port,u8 state); +int qca8k_port_bridge_join (struct dsa_switch *ds,int port, +struct dsa_bridge bridge, +bool *tx_fwd_offload, +struct netlink_ext_ack *extack); +void qca8k_port_bridge_leave (struct dsa_switch *ds,int port, +struct dsa_bridge bridge); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Re: [net-next PATCH v2 07/15] net: dsa: qca8k: move bridge functions to common code
Quoted 6 lines · Christian Marangi
The same bridge functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
Signed-off-by Christian Marangi <[email protected]>---
Christian Marangi
maintainerPATCH v2 8/15 net: dsa: qca8k: move fast age/MTU/port enable/disable functions to common code
In reply to Christian MarangiThe same fast age, MTU and port enable/disable function are used by driver based on qca8k family switch.
Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 98 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 98 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 13 ++++ 3 files changed, 111 insertions(+), 98 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -98
@@ -1575,104 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)return ret; } -static void -qca8k_port_fast_age (struct dsa_switch *ds,int port) -{ -struct qca8k_priv *priv = ds->priv; - -mutex_lock (&priv->reg_mutex); -qca8k_fdb_access (priv,QCA8K_FDB_FLUSH_PORT , port); -mutex_unlock (&priv->reg_mutex); -} - -static int -qca8k_set_ageing_time (struct dsa_switch *ds,unsigned int msecs) -{ -struct qca8k_priv *priv = ds->priv; -unsigned int secs = msecs /1000 ; -u32 val; - -/* AGE_TIME reg is set in 7s step */ - val = secs /7 ; - -/* Handle case with 0 as val to NOT disable -* learning -*/ -if (!val) - val =1 ; - -return regmap_update_bits (priv->regmap,QCA8K_REG_ATU_CTRL ,QCA8K_ATU_AGE_TIME_MASK , -QCA8K_ATU_AGE_TIME (val)); -} - -static int -qca8k_port_enable (struct dsa_switch *ds,int port, -struct phy_device *phy) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; - -qca8k_port_set_status (priv, port,1 ); - priv->port_enabled_map |=BIT (port); - -if (dsa_is_user_port (ds, port)) -phy_support_asym_pause (phy); - -return 0 ; -} - -static void -qca8k_port_disable (struct dsa_switch *ds,int port) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; - -qca8k_port_set_status (priv, port,0 ); - priv->port_enabled_map &= ~BIT (port); -} - -static int -qca8k_port_change_mtu (struct dsa_switch *ds,int port,int new_mtu) -{ -struct qca8k_priv *priv = ds->priv; -int ret; - -/* We have only have a general MTU setting. -* DSA always set the CPU port's MTU to the largest MTU of the slave -* ports. -* Setting MTU just for the CPU port is sufficient to correctly set a -* value for every port. -*/ -if (!dsa_is_cpu_port (ds, port)) -return 0 ; - -/* To change the MAX_FRAME_SIZE the cpu ports must be off or -* the switch panics. -* Turn off both cpu ports before applying the new value to prevent -* this. -*/ -if (priv->port_enabled_map &BIT (0 )) -qca8k_port_set_status (priv,0 ,0 ); - -if (priv->port_enabled_map &BIT (6 )) -qca8k_port_set_status (priv,6 ,0 ); - -/* Include L2 header / FCS length */ - ret =qca8k_write (priv,QCA8K_MAX_FRAME_SIZE , new_mtu +ETH_HLEN +ETH_FCS_LEN ); - -if (priv->port_enabled_map &BIT (0 )) -qca8k_port_set_status (priv,0 ,1 ); - -if (priv->port_enabled_map &BIT (6 )) -qca8k_port_set_status (priv,6 ,1 ); - -return ret; -} - -static int -qca8k_port_max_mtu (struct dsa_switch *ds,int port) -{ -return QCA8K_MAX_MTU ; -} -static int qca8k_port_fdb_insert (struct qca8k_priv *priv,const u8 *addr,u16 port_mask,u16 vid)
drivers/net/dsa/qca/qca8k-common.c +98 -0
101 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +13 -0
@@ -469,4 +469,17 @@ int qca8k_port_bridge_join(struct dsa_switch *ds, int port,void qca8k_port_bridge_leave (struct dsa_switch *ds,int port,struct dsa_bridge bridge); +/* Common fast age function */ +void qca8k_port_fast_age (struct dsa_switch *ds,int port); +int qca8k_set_ageing_time (struct dsa_switch *ds,unsigned int msecs); + +/* Common port enable/disable function */ +int qca8k_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy); +void qca8k_port_disable (struct dsa_switch *ds,int port); + +/* Common MTU function */ +int qca8k_port_change_mtu (struct dsa_switch *ds,int port,int new_mtu); +int qca8k_port_max_mtu (struct dsa_switch *ds,int port); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Vladimir Oltean
maintainerRe: [net-next PATCH v2 08/15] net: dsa: qca8k: move fast age/MTU/port enable/disable functions to common code
drivers/net/dsa/qca/qca8k-common.c void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, · line 753
Quoted 11 lines · Christian Marangi
The same fast age, MTU and port enable/disable function are used by driver based on qca8k family switch.
Move them to common code to make them accessible also by other drivers.Signed-off-by Christian Marangi <[email protected]>---
drivers/net/dsa/qca/qca8k-common.c +5
-0+int +qca8k_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy) +{ +struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
I think you can make slight tweaks to the code being moved (and document them in the commit message). For example, in C, there is no type casting necessary for void pointers (as evidenced by all other places which seem to do just fine with "priv = ds->priv").
Quoted 87 lines
drivers/net/dsa/qca/qca8k-common.c +62
-0+ +qca8k_port_set_status (priv, port,1 ); + priv->port_enabled_map |=BIT (port); + +if (dsa_is_user_port (ds, port)) +phy_support_asym_pause (phy); + +return 0 ; +} + +void +qca8k_port_disable (struct dsa_switch *ds,int port) +{ +struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; + +qca8k_port_set_status (priv, port,0 ); + priv->port_enabled_map &= ~BIT (port); +} + +int +qca8k_port_change_mtu (struct dsa_switch *ds,int port,int new_mtu) +{ +struct qca8k_priv *priv = ds->priv; +int ret; + +/* We have only have a general MTU setting. +* DSA always set the CPU port's MTU to the largest MTU of the slave +* ports. +* Setting MTU just for the CPU port is sufficient to correctly set a +* value for every port. +*/ +if (!dsa_is_cpu_port (ds, port)) +return 0 ; + +/* To change the MAX_FRAME_SIZE the cpu ports must be off or +* the switch panics. +* Turn off both cpu ports before applying the new value to prevent +* this. +*/ +if (priv->port_enabled_map &BIT (0 )) +qca8k_port_set_status (priv,0 ,0 ); + +if (priv->port_enabled_map &BIT (6 )) +qca8k_port_set_status (priv,6 ,0 ); + +/* Include L2 header / FCS length */ + ret =qca8k_write (priv,QCA8K_MAX_FRAME_SIZE , new_mtu +ETH_HLEN +ETH_FCS_LEN ); + +if (priv->port_enabled_map &BIT (0 )) +qca8k_port_set_status (priv,0 ,1 ); + +if (priv->port_enabled_map &BIT (6 )) +qca8k_port_set_status (priv,6 ,1 ); + +return ret; +} + +int +qca8k_port_max_mtu (struct dsa_switch *ds,int port) +{ +return QCA8K_MAX_MTU ; +}drivers/net/dsa/qca/qca8k.h +13
-0@@ -469,4 +469,17 @@ int qca8k_port_bridge_join(struct dsa_switch *ds, int port,void qca8k_port_bridge_leave (struct dsa_switch *ds,int port,struct dsa_bridge bridge); +/* Common fast age function */ +void qca8k_port_fast_age (struct dsa_switch *ds,int port); +int qca8k_set_ageing_time (struct dsa_switch *ds,unsigned int msecs); + +/* Common port enable/disable function */ +int qca8k_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phy); +void qca8k_port_disable (struct dsa_switch *ds,int port); + +/* Common MTU function */ +int qca8k_port_change_mtu (struct dsa_switch *ds,int port,int new_mtu); +int qca8k_port_max_mtu (struct dsa_switch *ds,int port); +#endif /* __QCA8K_H */ Signature · 1 line
2.36.1
Christian Marangi
maintainerPATCH v2 9/15 net: dsa: qca8k: move port FDB function to common code
In reply to Christian MarangiThe same port FDB function are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 61 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 61 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 12 ++++++ 3 files changed, 73 insertions(+), 61 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -61
@@ -1575,67 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)return ret; } -static int -qca8k_port_fdb_insert (struct qca8k_priv *priv,const u8 *addr, -u16 port_mask,u16 vid) -{ -/* Set the vid to the port vlan id if no vid is set */ -if (!vid) - vid =QCA8K_PORT_VID_DEF ; - -return qca8k_fdb_add (priv, addr, port_mask, vid, -QCA8K_ATU_STATUS_STATIC ); -} - -static int -qca8k_port_fdb_add (struct dsa_switch *ds,int port, -const unsigned char *addr,u16 vid, -struct dsa_db db) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -u16 port_mask =BIT (port); - -return qca8k_port_fdb_insert (priv, addr, port_mask, vid); -} - -static int -qca8k_port_fdb_del (struct dsa_switch *ds,int port, -const unsigned char *addr,u16 vid, -struct dsa_db db) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -u16 port_mask =BIT (port); - -if (!vid) - vid =QCA8K_PORT_VID_DEF ; - -return qca8k_fdb_del (priv, addr, port_mask, vid); -} - -static int -qca8k_port_fdb_dump (struct dsa_switch *ds,int port, -dsa_fdb_dump_cb_t *cb,void *data) -{ -struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -struct qca8k_fdb _fdb = {0 }; -int cnt =QCA8K_NUM_FDB_RECORDS ; -bool is_static; -int ret =0 ; - -mutex_lock (&priv->reg_mutex); -while (cnt-- && !qca8k_fdb_next (priv, &_fdb, port)) { -if (!_fdb.aging) -break ; - is_static = (_fdb.aging ==QCA8K_ATU_STATUS_STATIC ); - ret =cb (_fdb.mac, _fdb.vid, is_static, data); -if (ret) -break ; - } -mutex_unlock (&priv->reg_mutex); - -return 0 ; -} - static int qca8k_port_mdb_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb,
drivers/net/dsa/qca/qca8k-common.c +61 -0
64 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +12 -0
@@ -482,4 +482,16 @@ void qca8k_port_disable(struct dsa_switch *ds, int port);int qca8k_port_change_mtu (struct dsa_switch *ds,int port,int new_mtu);int qca8k_port_max_mtu (struct dsa_switch *ds,int port); +/* Common FDB function */ +int qca8k_port_fdb_insert (struct qca8k_priv *priv,const u8 *addr, +u16 port_mask,u16 vid); +int qca8k_port_fdb_add (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid, +struct dsa_db db); +int qca8k_port_fdb_del (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid, +struct dsa_db db); +int qca8k_port_fdb_dump (struct dsa_switch *ds,int port, +dsa_fdb_dump_cb_t *cb,void *data); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Christian Marangi
maintainerPATCH v2 10/15 net: dsa: qca8k: move port MDB functions to common code
In reply to Christian MarangiThe same port MDB functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 24 ------------------------ drivers/net/dsa/qca/qca8k-common.c | 24 ++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 8 ++++++++ 3 files changed, 32 insertions(+), 24 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -24
@@ -1575,30 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)return ret; } -static int -qca8k_port_mdb_add (struct dsa_switch *ds,int port, -const struct switchdev_obj_port_mdb *mdb, -struct dsa_db db) -{ -struct qca8k_priv *priv = ds->priv; -const u8 *addr = mdb->addr; -u16 vid = mdb->vid; - -return qca8k_fdb_search_and_insert (priv,BIT (port), addr, vid); -} - -static int -qca8k_port_mdb_del (struct dsa_switch *ds,int port, -const struct switchdev_obj_port_mdb *mdb, -struct dsa_db db) -{ -struct qca8k_priv *priv = ds->priv; -const u8 *addr = mdb->addr; -u16 vid = mdb->vid; - -return qca8k_fdb_search_and_del (priv,BIT (port), addr, vid); -} - static int qca8k_port_mirror_add(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror,
drivers/net/dsa/qca/qca8k-common.c +24 -0
@@ -874,3 +874,27 @@ qca8k_port_fdb_dump(struct dsa_switch *ds, int port,return 0 ; } + +int +qca8k_port_mdb_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_mdb *mdb, +struct dsa_db db) +{ +struct qca8k_priv *priv = ds->priv; +const u8 *addr = mdb->addr; +u16 vid = mdb->vid; + +return qca8k_fdb_search_and_insert (priv,BIT (port), addr, vid); +} + +int +qca8k_port_mdb_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_mdb *mdb, +struct dsa_db db) +{ +struct qca8k_priv *priv = ds->priv; +const u8 *addr = mdb->addr; +u16 vid = mdb->vid; + +return qca8k_fdb_search_and_del (priv,BIT (port), addr, vid); +}
drivers/net/dsa/qca/qca8k.h +8 -0
@@ -494,4 +494,12 @@ int qca8k_port_fdb_del(struct dsa_switch *ds, int port,int qca8k_port_fdb_dump (struct dsa_switch *ds,int port,dsa_fdb_dump_cb_t *cb,void *data); +/* Common MDB function */ +int qca8k_port_mdb_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_mdb *mdb, +struct dsa_db db); +int qca8k_port_mdb_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_mdb *mdb, +struct dsa_db db); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Christian Marangi
maintainerPATCH v2 11/15 net: dsa: qca8k: move port mirror functions to common code
In reply to Christian MarangiThe same port mirror functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 93 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 93 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 7 +++ 3 files changed, 100 insertions(+), 93 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -93
@@ -1575,99 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)return ret; } -static int -qca8k_port_mirror_add (struct dsa_switch *ds,int port, -struct dsa_mall_mirror_tc_entry *mirror, -bool ingress,struct netlink_ext_ack *extack) -{ -struct qca8k_priv *priv = ds->priv; -int monitor_port, ret; -u32 reg, val; - -/* Check for existent entry */ -if ((ingress ? priv->mirror_rx : priv->mirror_tx) &BIT (port)) -return -EEXIST ; - - ret =regmap_read (priv->regmap,QCA8K_REG_GLOBAL_FW_CTRL0 , &val); -if (ret) -return ret; - -/* QCA83xx can have only one port set to mirror mode. -* Check that the correct port is requested and return error otherwise. -* When no mirror port is set, the values is set to 0xF -*/ - monitor_port =FIELD_GET (QCA8K_GLOBAL_FW_CTRL0_MIRROR_PORT_NUM , val); -if (monitor_port !=0xF && monitor_port != mirror->to_local_port) -return -EEXIST ; - -/* Set the monitor port */ - val =FIELD_PREP (QCA8K_GLOBAL_FW_CTRL0_MIRROR_PORT_NUM , - mirror->to_local_port); - ret =regmap_update_bits (priv->regmap,QCA8K_REG_GLOBAL_FW_CTRL0 , -QCA8K_GLOBAL_FW_CTRL0_MIRROR_PORT_NUM , val); -if (ret) -return ret; - -if (ingress) { - reg =QCA8K_PORT_LOOKUP_CTRL (port); - val =QCA8K_PORT_LOOKUP_ING_MIRROR_EN ; - }else { - reg =QCA8K_REG_PORT_HOL_CTRL1 (port); - val =QCA8K_PORT_HOL_CTRL1_EG_MIRROR_EN ; - } - - ret =regmap_update_bits (priv->regmap, reg, val, val); -if (ret) -return ret; - -/* Track mirror port for tx and rx to decide when the -* mirror port has to be disabled. -*/ -if (ingress) - priv->mirror_rx |=BIT (port); -else - priv->mirror_tx |=BIT (port); - -return 0 ; -} - -static void -qca8k_port_mirror_del (struct dsa_switch *ds,int port, -struct dsa_mall_mirror_tc_entry *mirror) -{ -struct qca8k_priv *priv = ds->priv; -u32 reg, val; -int ret; - -if (mirror->ingress) { - reg =QCA8K_PORT_LOOKUP_CTRL (port); - val =QCA8K_PORT_LOOKUP_ING_MIRROR_EN ; - }else { - reg =QCA8K_REG_PORT_HOL_CTRL1 (port); - val =QCA8K_PORT_HOL_CTRL1_EG_MIRROR_EN ; - } - - ret =regmap_clear_bits (priv->regmap, reg, val); -if (ret) - goto err; - -if (mirror->ingress) - priv->mirror_rx &= ~BIT (port); -else - priv->mirror_tx &= ~BIT (port); - -/* No port set to send packet to mirror port. Disable mirror port */ -if (!priv->mirror_rx && !priv->mirror_tx) { - val =FIELD_PREP (QCA8K_GLOBAL_FW_CTRL0_MIRROR_PORT_NUM ,0xF ); - ret =regmap_update_bits (priv->regmap,QCA8K_REG_GLOBAL_FW_CTRL0 , -QCA8K_GLOBAL_FW_CTRL0_MIRROR_PORT_NUM , val); -if (ret) - goto err; - } -err: -dev_err (priv->dev,"Failed to del mirror port from %d" , port); -} -static int qca8k_port_vlan_filtering (struct dsa_switch *ds,int port,bool vlan_filtering,struct netlink_ext_ack *extack)
drivers/net/dsa/qca/qca8k-common.c +93 -0
96 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +7 -0
@@ -502,4 +502,11 @@ int qca8k_port_mdb_del(struct dsa_switch *ds, int port,const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); +/* Common port mirror function */ +int qca8k_port_mirror_add (struct dsa_switch *ds,int port, +struct dsa_mall_mirror_tc_entry *mirror, +bool ingress,struct netlink_ext_ack *extack); +void qca8k_port_mirror_del (struct dsa_switch *ds,int port, +struct dsa_mall_mirror_tc_entry *mirror); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Re: [net-next PATCH v2 11/15] net: dsa: qca8k: move port mirror functions to common code
Quoted 6 lines · Christian Marangi
The same port mirror functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
Signed-off-by Christian Marangi <[email protected]>---
Christian Marangi
maintainerPATCH v2 12/15 net: dsa: qca8k: move port VLAN functions to common code
In reply to Christian MarangiThe same port VLAN functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 65 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 65 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 9 +++++ 3 files changed, 74 insertions(+), 65 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -65
@@ -1575,71 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)return ret; } -static int -qca8k_port_vlan_filtering (struct dsa_switch *ds,int port,bool vlan_filtering, -struct netlink_ext_ack *extack) -{ -struct qca8k_priv *priv = ds->priv; -int ret; - -if (vlan_filtering) { - ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), -QCA8K_PORT_LOOKUP_VLAN_MODE_MASK , -QCA8K_PORT_LOOKUP_VLAN_MODE_SECURE ); - }else { - ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), -QCA8K_PORT_LOOKUP_VLAN_MODE_MASK , -QCA8K_PORT_LOOKUP_VLAN_MODE_NONE ); - } - -return ret; -} - -static int -qca8k_port_vlan_add (struct dsa_switch *ds,int port, -const struct switchdev_obj_port_vlan *vlan, -struct netlink_ext_ack *extack) -{ -bool untagged = vlan->flags &BRIDGE_VLAN_INFO_UNTAGGED ; -bool pvid = vlan->flags &BRIDGE_VLAN_INFO_PVID ; -struct qca8k_priv *priv = ds->priv; -int ret; - - ret =qca8k_vlan_add (priv, port, vlan->vid, untagged); -if (ret) { -dev_err (priv->dev,"Failed to add VLAN to port %d (%d)" , port, ret); -return ret; - } - -if (pvid) { - ret =qca8k_rmw (priv,QCA8K_EGRESS_VLAN (port), -QCA8K_EGREES_VLAN_PORT_MASK (port), -QCA8K_EGREES_VLAN_PORT (port, vlan->vid)); -if (ret) -return ret; - - ret =qca8k_write (priv,QCA8K_REG_PORT_VLAN_CTRL0 (port), -QCA8K_PORT_VLAN_CVID (vlan->vid) | -QCA8K_PORT_VLAN_SVID (vlan->vid)); - } - -return ret; -} - -static int -qca8k_port_vlan_del (struct dsa_switch *ds,int port, -const struct switchdev_obj_port_vlan *vlan) -{ -struct qca8k_priv *priv = ds->priv; -int ret; - - ret =qca8k_vlan_del (priv, port, vlan->vid); -if (ret) -dev_err (priv->dev,"Failed to delete VLAN from port %d (%d)" , port, ret); - -return ret; -} -static u32 qca8k_get_phy_flags (struct dsa_switch *ds,int port) {struct qca8k_priv *priv = ds->priv;
drivers/net/dsa/qca/qca8k-common.c +65 -0
68 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +9 -0
@@ -509,4 +509,13 @@ int qca8k_port_mirror_add(struct dsa_switch *ds, int port,void qca8k_port_mirror_del (struct dsa_switch *ds,int port,struct dsa_mall_mirror_tc_entry *mirror); +/* Common port VLAN function */ +int qca8k_port_vlan_filtering (struct dsa_switch *ds,int port,bool vlan_filtering, +struct netlink_ext_ack *extack); +int qca8k_port_vlan_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan, +struct netlink_ext_ack *extack); +int qca8k_port_vlan_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Re: [net-next PATCH v2 12/15] net: dsa: qca8k: move port VLAN functions to common code
Quoted 6 lines · Christian Marangi
The same port VLAN functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
Signed-off-by Christian Marangi <[email protected]>---
Christian Marangi
maintainerPATCH v2 13/15 net: dsa: qca8k: move port LAG functions to common code
In reply to Christian MarangiThe same port LAG functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 168 ----------------------------- drivers/net/dsa/qca/qca8k-common.c | 168 +++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 6 ++ 3 files changed, 174 insertions(+), 168 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -168
@@ -1598,174 +1598,6 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,return DSA_TAG_PROTO_QCA ; } -static bool -qca8k_lag_can_offload (struct dsa_switch *ds,struct dsa_lag lag, -struct netdev_lag_upper_info *info) -{ -struct dsa_port *dp; -int members =0 ; - -if (!lag.id) -return false; - -dsa_lag_foreach_port (dp, ds->dst, &lag) -/* Includes the port joining the LAG */ - members++; - -if (members >QCA8K_NUM_PORTS_FOR_LAG ) -return false; - -if (info->tx_type !=NETDEV_LAG_TX_TYPE_HASH ) -return false; - -if (info->hash_type !=NETDEV_LAG_HASH_L2 && - info->hash_type !=NETDEV_LAG_HASH_L23 ) -return false; - -return true; -} - -static int -qca8k_lag_setup_hash (struct dsa_switch *ds,struct dsa_lag lag, -struct netdev_lag_upper_info *info) -{ -struct net_device *lag_dev = lag.dev; -struct qca8k_priv *priv = ds->priv; -bool unique_lag = true; -unsigned int i; -u32 hash =0 ; - -switch (info->hash_type) { -case NETDEV_LAG_HASH_L23 : - hash |=QCA8K_TRUNK_HASH_SIP_EN ; - hash |=QCA8K_TRUNK_HASH_DIP_EN ; - fallthrough; -case NETDEV_LAG_HASH_L2 : - hash |=QCA8K_TRUNK_HASH_SA_EN ; - hash |=QCA8K_TRUNK_HASH_DA_EN ; -break ; -default :/* We should NEVER reach this */ -return -EOPNOTSUPP ; - } - -/* Check if we are the unique configured LAG */ - dsa_lags_foreach_id(i, ds->dst) -if (i != lag.id &&dsa_lag_by_id (ds->dst, i)) { - unique_lag = false; -break ; - } - -/* Hash Mode is global. Make sure the same Hash Mode -* is set to all the 4 possible lag. -* If we are the unique LAG we can set whatever hash -* mode we want. -* To change hash mode it's needed to remove all LAG -* and change the mode with the latest. -*/ -if (unique_lag) { - priv->lag_hash_mode = hash; - }else if (priv->lag_hash_mode != hash) { -netdev_err (lag_dev,"Error: Mismatched Hash Mode across different lag is not supported\n" ); -return -EOPNOTSUPP ; - } - -return regmap_update_bits (priv->regmap,QCA8K_TRUNK_HASH_EN_CTRL , -QCA8K_TRUNK_HASH_MASK , hash); -} - -static int -qca8k_lag_refresh_portmap (struct dsa_switch *ds,int port, -struct dsa_lag lag,bool delete) -{ -struct qca8k_priv *priv = ds->priv; -int ret, id, i; -u32 val; - -/* DSA LAG IDs are one-based, hardware is zero-based */ - id = lag.id -1 ; - -/* Read current port member */ - ret =regmap_read (priv->regmap,QCA8K_REG_GOL_TRUNK_CTRL0 , &val); -if (ret) -return ret; - -/* Shift val to the correct trunk */ - val >>=QCA8K_REG_GOL_TRUNK_SHIFT (id); - val &=QCA8K_REG_GOL_TRUNK_MEMBER_MASK ; -if (delete) - val &= ~BIT (port); -else - val |=BIT (port); - -/* Update port member. With empty portmap disable trunk */ - ret =regmap_update_bits (priv->regmap,QCA8K_REG_GOL_TRUNK_CTRL0 , -QCA8K_REG_GOL_TRUNK_MEMBER (id) | -QCA8K_REG_GOL_TRUNK_EN (id), - !val <<QCA8K_REG_GOL_TRUNK_SHIFT (id) | - val <<QCA8K_REG_GOL_TRUNK_SHIFT (id)); - -/* Search empty member if adding or port on deleting */ -for (i =0 ; i <QCA8K_NUM_PORTS_FOR_LAG ; i++) { - ret =regmap_read (priv->regmap,QCA8K_REG_GOL_TRUNK_CTRL (id), &val); -if (ret) -return ret; - - val >>=QCA8K_REG_GOL_TRUNK_ID_MEM_ID_SHIFT (id, i); - val &=QCA8K_REG_GOL_TRUNK_ID_MEM_ID_MASK ; - -if (delete) { -/* If port flagged to be disabled assume this member is -* empty -*/ -if (val !=QCA8K_REG_GOL_TRUNK_ID_MEM_ID_EN_MASK ) -continue ; - - val &=QCA8K_REG_GOL_TRUNK_ID_MEM_ID_PORT_MASK ; -if (val != port) -continue ; - }else { -/* If port flagged to be enabled assume this member is -* already set -*/ -if (val ==QCA8K_REG_GOL_TRUNK_ID_MEM_ID_EN_MASK ) -continue ; - } - -/* We have found the member to add/remove */ -break ; - } - -/* Set port in the correct port mask or disable port if in delete mode */ -return regmap_update_bits (priv->regmap,QCA8K_REG_GOL_TRUNK_CTRL (id), -QCA8K_REG_GOL_TRUNK_ID_MEM_ID_EN (id, i) | -QCA8K_REG_GOL_TRUNK_ID_MEM_ID_PORT (id, i), - !delete <<QCA8K_REG_GOL_TRUNK_ID_MEM_ID_SHIFT (id, i) | - port <<QCA8K_REG_GOL_TRUNK_ID_MEM_ID_SHIFT (id, i)); -} - -static int -qca8k_port_lag_join (struct dsa_switch *ds,int port,struct dsa_lag lag, -struct netdev_lag_upper_info *info) -{ -int ret; - -if (!qca8k_lag_can_offload (ds, lag, info)) -return -EOPNOTSUPP ; - - ret =qca8k_lag_setup_hash (ds, lag, info); -if (ret) -return ret; - -return qca8k_lag_refresh_portmap (ds, port, lag, false); -} - -static int -qca8k_port_lag_leave (struct dsa_switch *ds,int port, -struct dsa_lag lag) -{ -return qca8k_lag_refresh_portmap (ds, port, lag, true); -} -static void qca8k_master_change (struct dsa_switch *ds,const struct net_device *master,bool operational)
drivers/net/dsa/qca/qca8k-common.c +168 -0
171 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +6 -0
@@ -518,4 +518,10 @@ int qca8k_port_vlan_add(struct dsa_switch *ds, int port,int qca8k_port_vlan_del (struct dsa_switch *ds,int port,const struct switchdev_obj_port_vlan *vlan); +/* Common port LAG function */ +int qca8k_port_lag_join (struct dsa_switch *ds,int port,struct dsa_lag lag, +struct netdev_lag_upper_info *info); +int qca8k_port_lag_leave (struct dsa_switch *ds,int port, +struct dsa_lag lag); +#endif /* __QCA8K_H */
Signature · 1 line
2.36.1
Re: [net-next PATCH v2 13/15] net: dsa: qca8k: move port LAG functions to common code
Quoted 6 lines · Christian Marangi
The same port LAG functions are used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
Signed-off-by Christian Marangi <[email protected]>---
Christian Marangi
maintainerPATCH v2 14/15 net: dsa: qca8k: move read_switch_id function to common code
In reply to Christian MarangiThe same function to read the switch id is used by drivers based on qca8k family switch. Move them to common code to make them accessible also by other drivers.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 30 ------------------------------ drivers/net/dsa/qca/qca8k-common.c | 30 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 1 + 3 files changed, 31 insertions(+), 30 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -30
@@ -1881,36 +1881,6 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .connect_tag_protocol = qca8k_connect_tag_protocol, }; -static int qca8k_read_switch_id (struct qca8k_priv *priv) -{ -const struct qca8k_match_data *data; -u32 val; -u8 id; -int ret; - -/* get the switches ID from the compatible */ - data =of_device_get_match_data (priv->dev); -if (!data) -return -ENODEV ; - - ret =qca8k_read (priv,QCA8K_REG_MASK_CTRL , &val); -if (ret <0 ) -return -ENODEV ; - - id =QCA8K_MASK_CTRL_DEVICE_ID (val); -if (id != data->id) { -dev_err (priv->dev,"Switch id detected %x but expected %x" , id, data->id); -return -ENODEV ; - } - - priv->switch_id = id; - -/* Save revision to communicate to the internal PHY driver */ - priv->switch_revision =QCA8K_MASK_CTRL_REV_ID (val); - -return 0 ; -} -static int qca8k_sw_probe (struct mdio_device *mdiodev) {
drivers/net/dsa/qca/qca8k-common.c +30 -0
@@ -1224,3 +1224,33 @@ qca8k_port_lag_leave(struct dsa_switch *ds, int port, {return qca8k_lag_refresh_portmap (ds, port, lag, true); } + +int qca8k_read_switch_id (struct qca8k_priv *priv) +{ +const struct qca8k_match_data *data; +u32 val; +u8 id; +int ret; + +/* get the switches ID from the compatible */ + data =of_device_get_match_data (priv->dev); +if (!data) +return -ENODEV ; + + ret =qca8k_read (priv,QCA8K_REG_MASK_CTRL , &val); +if (ret <0 ) +return -ENODEV ; + + id =QCA8K_MASK_CTRL_DEVICE_ID (val); +if (id != data->id) { +dev_err (priv->dev,"Switch id detected %x but expected %x" , id, data->id); +return -ENODEV ; + } + + priv->switch_id = id; + +/* Save revision to communicate to the internal PHY driver */ + priv->switch_revision =QCA8K_MASK_CTRL_REV_ID (val); + +return 0 ; +}
drivers/net/dsa/qca/qca8k.h +1 -0
@@ -427,6 +427,7 @@ extern const struct qca8k_mib_desc ar8327_mib[];extern const struct regmap_access_table qca8k_readable_table;int qca8k_mib_init (struct qca8k_priv *priv);void qca8k_port_set_status (struct qca8k_priv *priv,int port,int enable); +int qca8k_read_switch_id (struct qca8k_priv *priv);/* Common read/write/rmw function */ int qca8k_read (struct qca8k_priv *priv,u32 reg,u32 *val);
Signature · 1 line
2.36.1
Christian Marangi
maintainerPATCH v2 15/15 net: dsa: qca8k: drop unnecessary exposed function and make them static
In reply to Christian MarangiSome function were exposed to permit migration to common code. Drop them and make them static now that the user are in the same common code.
--- drivers/net/dsa/qca/qca8k-common.c | 22 +++++++++++----------- drivers/net/dsa/qca/qca8k.h | 14 -------------- 2 files changed, 11 insertions(+), 25 deletions(-)
drivers/net/dsa/qca/qca8k-common.c +11 -11
@@ -104,7 +104,7 @@ const struct regmap_access_table qca8k_readable_table = { };/* TODO: remove these extra ops when we can support regmap bulk read/write */ -int qca8k_bulk_read (struct qca8k_priv *priv,u32 reg,u32 *val,int len) +static int qca8k_bulk_read (struct qca8k_priv *priv,u32 reg,u32 *val,int len) {int i, count = len /sizeof (u32), ret;const struct qca8k_match_data *data;
@@ -125,7 +125,7 @@ int qca8k_bulk_read(struct qca8k_priv *priv, u32 reg, u32 *val, int len) }/* TODO: remove these extra ops when we can support regmap bulk read/write */ -int qca8k_bulk_write (struct qca8k_priv *priv,u32 reg,u32 *val,int len) +static int qca8k_bulk_write (struct qca8k_priv *priv,u32 reg,u32 *val,int len) {int i, count = len /sizeof (u32), ret;const struct qca8k_match_data *data;
@@ -184,7 +184,7 @@ qca8k_fdb_read(struct qca8k_priv *priv, struct qca8k_fdb *fdb)return 0 ; } -void +static void qca8k_fdb_write (struct qca8k_priv *priv,u16 vid,u8 port_mask,const u8 *mac,u8 aging) {
@@ -208,7 +208,7 @@ qca8k_fdb_write(struct qca8k_priv *priv, u16 vid, u8 port_mask, const u8 *mac,qca8k_bulk_write (priv,QCA8K_REG_ATU_DATA0 , reg,sizeof (reg)); } -int +static int qca8k_fdb_access (struct qca8k_priv *priv,enum qca8k_fdb_cmd cmd,int port) {u32 reg;
@@ -244,7 +244,7 @@ qca8k_fdb_access(struct qca8k_priv *priv, enum qca8k_fdb_cmd cmd, int port)return 0 ; } -int +static int qca8k_fdb_next (struct qca8k_priv *priv,struct qca8k_fdb *fdb,int port) {int ret;
@@ -257,7 +257,7 @@ qca8k_fdb_next(struct qca8k_priv *priv, struct qca8k_fdb *fdb, int port)return qca8k_fdb_read (priv, fdb); } -int +static int qca8k_fdb_add (struct qca8k_priv *priv,const u8 *mac,u16 port_mask,u16 vid,u8 aging) {
@@ -271,7 +271,7 @@ qca8k_fdb_add(struct qca8k_priv *priv, const u8 *mac, u16 port_mask,return ret; } -int +static int qca8k_fdb_del (struct qca8k_priv *priv,const u8 *mac,u16 port_mask,u16 vid) {int ret;
@@ -292,7 +292,7 @@ qca8k_fdb_flush(struct qca8k_priv *priv)mutex_unlock (&priv->reg_mutex); } -int +static int qca8k_fdb_search_and_insert (struct qca8k_priv *priv,u8 port_mask,const u8 *mac,u16 vid) {
@@ -328,7 +328,7 @@ qca8k_fdb_search_and_insert(struct qca8k_priv *priv, u8 port_mask,return ret; } -int +static int qca8k_fdb_search_and_del (struct qca8k_priv *priv,u8 port_mask,const u8 *mac,u16 vid) {
@@ -400,7 +400,7 @@ qca8k_vlan_access(struct qca8k_priv *priv, enum qca8k_vlan_cmd cmd, u16 vid)return 0 ; } -int +static int qca8k_vlan_add (struct qca8k_priv *priv,u8 port,u16 vid,bool untagged) {u32 reg;
@@ -438,7 +438,7 @@ qca8k_vlan_add(struct qca8k_priv *priv, u8 port, u16 vid, bool untagged)return ret; } -int +static int qca8k_vlan_del (struct qca8k_priv *priv,u8 port,u16 vid) {u32 reg, mask;
drivers/net/dsa/qca/qca8k.h +0 -14
@@ -434,22 +434,8 @@ int qca8k_read(struct qca8k_priv *priv, u32 reg, u32 *val);int qca8k_write (struct qca8k_priv *priv,u32 reg,u32 val);int qca8k_rmw (struct qca8k_priv *priv,u32 reg,u32 mask,u32 write_val); -int qca8k_bulk_read (struct qca8k_priv *priv,u32 reg,u32 *val,int len); -int qca8k_bulk_write (struct qca8k_priv *priv,u32 reg,u32 *val,int len); -/* Common ops function */ -int qca8k_fdb_access (struct qca8k_priv *priv,enum qca8k_fdb_cmd cmd,int port); -int qca8k_fdb_next (struct qca8k_priv *priv,struct qca8k_fdb *fdb,int port); -int qca8k_fdb_add (struct qca8k_priv *priv,const u8 *mac,u16 port_mask, -u16 vid,u8 aging); -int qca8k_fdb_del (struct qca8k_priv *priv,const u8 *mac,u16 port_mask,u16 vid);void qca8k_fdb_flush (struct qca8k_priv *priv); -int qca8k_fdb_search_and_insert (struct qca8k_priv *priv,u8 port_mask, -const u8 *mac,u16 vid); -int qca8k_fdb_search_and_del (struct qca8k_priv *priv,u8 port_mask, -const u8 *mac,u16 vid); -int qca8k_vlan_add (struct qca8k_priv *priv,u8 port,u16 vid,bool untagged); -int qca8k_vlan_del (struct qca8k_priv *priv,u8 port,u16 vid);/* Common ethtool stats function */ void qca8k_get_strings (struct dsa_switch *ds,int port,u32 stringset,uint8_t *data);
Signature · 1 line
2.36.1
Vladimir Oltean
maintainerRe: [net-next PATCH v2 15/15] net: dsa: qca8k: drop unnecessary exposed function and make them static
Quoted 5 lines · Christian Marangi
Some function were exposed to permit migration to common code. Drop them and make them static now that the user are in the same common code.
Signed-off-by Christian Marangi <[email protected]>---
Hmm, ideally the last patch that removes a certain function from being called from qca8k-8xxx.c would also delete its prototype and make it static in qca8k-common.c. Would that be hard to change?
Christian Marangi
maintainerRe: [net-next PATCH v2 15/15] net: dsa: qca8k: drop unnecessary exposed function and make them static
Quoted 10 lines · Vladimir Oltean
Quoted 5 lines · Christian Marangi
Some function were exposed to permit migration to common code. Drop them and make them static now that the user are in the same common code.
Signed-off-by Christian Marangi <[email protected]>---
Hmm, ideally the last patch that removes a certain function from being called from
qca8k-8xxx.cwould also delete its prototype and make it static inqca8k-common.c. Would that be hard to change?
Can be done, it's really to compile check the changes and fix them. Problem is that the patch number would explode. (ok explode is a big thing but i think that would add 2-3 more patch to this big series... this is why I did the static change as the last patch instead of in the middle of the series)
But yes it's totally doable and not that hard honestly.
Signature · 1 line
Ansuel
Vladimir Oltean
maintainerRe: [net-next PATCH v2 15/15] net: dsa: qca8k: drop unnecessary exposed function and make them static
Quoted 12 lines · Christian Marangi
Quoted 10 lines · Vladimir Oltean
Quoted 5 lines · Christian Marangi
Some function were exposed to permit migration to common code. Drop them and make them static now that the user are in the same common code.
Signed-off-by Christian Marangi <[email protected]>---
Hmm, ideally the last patch that removes a certain function from being called from
qca8k-8xxx.cwould also delete its prototype and make it static inqca8k-common.c. Would that be hard to change?
Quoted 7 lines
Can be done, it's really to compile check the changes and fix them. Problem is that the patch number would explode. (ok explode is a big thing but i think that would add 2-3 more patch to this big series... this is why I did the static change as the last patch instead of in the middle of the series)
But yes it's totally doable and not that hard honestly.
Why would it add to the patch count? I don't think you understood what I meant.
Take for example qca8k_bulk_read(). You migrated it in patch 4, but there was still a user left in qca8k_fdb_read(), which you migrated in patch 5. After patch 5 and until the last one, the prototype of qca8k_bulk_read() was essentially dangling, but you only removed it in the last patch. My request is that you prune the dangling definitions after each patch that stops using something exported. That won't increase the number of changes, but eliminate the last one. Also, it would be great if you could create a dependency graph such that you could avoid temporarily exporting some functions that don't need to be.
Vladimir Oltean
maintainerRe: [net-next PATCH v2 15/15] net: dsa: qca8k: drop unnecessary exposed function and make them static
Quoted 2 lines · Vladimir Oltean
My request is that you prune the dangling definitions after each patch that stops using something exported.
Not "after" each patch, but "as part" of each patch.