* [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time
@ 2020-11-19 6:40 ` DENG Qingfang
0 siblings, 0 replies; 7+ messages in thread
From: DENG Qingfang @ 2020-11-19 6:40 UTC (permalink / raw)
To: netdev, linux-mediatek, Sean Wang, Landen Chao, Andrew Lunn,
Vivien Didelot, Florian Fainelli, Vladimir Oltean,
David S . Miller, Jakub Kicinski, Matthias Brugger, Russell King
Cc: René van Dorst, Frank Wunderlich, Greg Ungerer, Alex Dewar,
Chuanhong Guo
MT7530 has a global address age control register, so use it to set
ageing time.
The applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds
Signed-off-by: DENG Qingfang <dqfext@gmail.com>
---
drivers/net/dsa/mt7530.c | 41 ++++++++++++++++++++++++++++++++++++++++
drivers/net/dsa/mt7530.h | 13 +++++++++++++
2 files changed, 54 insertions(+)
RFC:
1. What is the expected behaviour if the timer is too big or too small?
- return -ERANGE or -EINVAL;
or
- if it is too big, apply the maximum value; if it is too small,
disable learning;
2. Is there a better algorithm to find the closest pair?
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 6408402a44f5..99bf8fed6536 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -870,6 +870,46 @@ mt7530_get_sset_count(struct dsa_switch *ds, int port, int sset)
return ARRAY_SIZE(mt7530_mib);
}
+static int
+mt7530_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
+{
+ struct mt7530_priv *priv = ds->priv;
+ unsigned int secs = msecs / 1000;
+ unsigned int tmp_age_count;
+ unsigned int error = -1;
+ unsigned int age_count;
+ unsigned int age_unit;
+
+ /* Applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds */
+ if (secs < 1 || secs > (AGE_CNT_MAX + 1) * (AGE_UNIT_MAX + 1))
+ return -ERANGE;
+
+ /* iterate through all possible age_count to find the closest pair */
+ for (tmp_age_count = 0; tmp_age_count <= AGE_CNT_MAX; ++tmp_age_count) {
+ unsigned int tmp_age_unit = secs / (tmp_age_count + 1) - 1;
+
+ if (tmp_age_unit <= AGE_UNIT_MAX) {
+ unsigned int tmp_error = secs -
+ (tmp_age_count + 1) * (tmp_age_unit + 1);
+
+ /* found a closer pair */
+ if (error > tmp_error) {
+ error = tmp_error;
+ age_count = tmp_age_count;
+ age_unit = tmp_age_unit;
+ }
+
+ /* found the exact match, so break the loop */
+ if (!error)
+ break;
+ }
+ }
+
+ mt7530_write(priv, MT7530_AAC, AGE_CNT(age_count) | AGE_UNIT(age_unit));
+
+ return 0;
+}
+
static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface)
{
struct mt7530_priv *priv = ds->priv;
@@ -2564,6 +2604,7 @@ static const struct dsa_switch_ops mt7530_switch_ops = {
.phy_write = mt753x_phy_write,
.get_ethtool_stats = mt7530_get_ethtool_stats,
.get_sset_count = mt7530_get_sset_count,
+ .set_ageing_time = mt7530_set_ageing_time,
.port_enable = mt7530_port_enable,
.port_disable = mt7530_port_disable,
.port_change_mtu = mt7530_port_change_mtu,
diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
index ee3523a7537e..32d8969b3ace 100644
--- a/drivers/net/dsa/mt7530.h
+++ b/drivers/net/dsa/mt7530.h
@@ -161,6 +161,19 @@ enum mt7530_vlan_egress_attr {
MT7530_VLAN_EGRESS_STACK = 3,
};
+/* Register for address age control */
+#define MT7530_AAC 0xa0
+/* Disable ageing */
+#define AGE_DIS BIT(20)
+/* Age count */
+#define AGE_CNT_MASK GENMASK(19, 12)
+#define AGE_CNT_MAX 0xff
+#define AGE_CNT(x) (AGE_CNT_MASK & ((x) << 12))
+/* Age unit */
+#define AGE_UNIT_MASK GENMASK(11, 0)
+#define AGE_UNIT_MAX 0xfff
+#define AGE_UNIT(x) (AGE_UNIT_MASK & (x))
+
/* Register for port STP state control */
#define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
#define FID_PST(x) ((x) & 0x3)
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time
@ 2020-11-19 6:40 ` DENG Qingfang
0 siblings, 0 replies; 7+ messages in thread
From: DENG Qingfang @ 2020-11-19 6:40 UTC (permalink / raw)
To: netdev, linux-mediatek, Sean Wang, Landen Chao, Andrew Lunn,
Vivien Didelot, Florian Fainelli, Vladimir Oltean,
David S . Miller, Jakub Kicinski, Matthias Brugger, Russell King
Cc: René van Dorst, Greg Ungerer, Chuanhong Guo, Alex Dewar,
Frank Wunderlich
MT7530 has a global address age control register, so use it to set
ageing time.
The applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds
Signed-off-by: DENG Qingfang <dqfext@gmail.com>
---
drivers/net/dsa/mt7530.c | 41 ++++++++++++++++++++++++++++++++++++++++
drivers/net/dsa/mt7530.h | 13 +++++++++++++
2 files changed, 54 insertions(+)
RFC:
1. What is the expected behaviour if the timer is too big or too small?
- return -ERANGE or -EINVAL;
or
- if it is too big, apply the maximum value; if it is too small,
disable learning;
2. Is there a better algorithm to find the closest pair?
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 6408402a44f5..99bf8fed6536 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -870,6 +870,46 @@ mt7530_get_sset_count(struct dsa_switch *ds, int port, int sset)
return ARRAY_SIZE(mt7530_mib);
}
+static int
+mt7530_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
+{
+ struct mt7530_priv *priv = ds->priv;
+ unsigned int secs = msecs / 1000;
+ unsigned int tmp_age_count;
+ unsigned int error = -1;
+ unsigned int age_count;
+ unsigned int age_unit;
+
+ /* Applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds */
+ if (secs < 1 || secs > (AGE_CNT_MAX + 1) * (AGE_UNIT_MAX + 1))
+ return -ERANGE;
+
+ /* iterate through all possible age_count to find the closest pair */
+ for (tmp_age_count = 0; tmp_age_count <= AGE_CNT_MAX; ++tmp_age_count) {
+ unsigned int tmp_age_unit = secs / (tmp_age_count + 1) - 1;
+
+ if (tmp_age_unit <= AGE_UNIT_MAX) {
+ unsigned int tmp_error = secs -
+ (tmp_age_count + 1) * (tmp_age_unit + 1);
+
+ /* found a closer pair */
+ if (error > tmp_error) {
+ error = tmp_error;
+ age_count = tmp_age_count;
+ age_unit = tmp_age_unit;
+ }
+
+ /* found the exact match, so break the loop */
+ if (!error)
+ break;
+ }
+ }
+
+ mt7530_write(priv, MT7530_AAC, AGE_CNT(age_count) | AGE_UNIT(age_unit));
+
+ return 0;
+}
+
static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface)
{
struct mt7530_priv *priv = ds->priv;
@@ -2564,6 +2604,7 @@ static const struct dsa_switch_ops mt7530_switch_ops = {
.phy_write = mt753x_phy_write,
.get_ethtool_stats = mt7530_get_ethtool_stats,
.get_sset_count = mt7530_get_sset_count,
+ .set_ageing_time = mt7530_set_ageing_time,
.port_enable = mt7530_port_enable,
.port_disable = mt7530_port_disable,
.port_change_mtu = mt7530_port_change_mtu,
diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
index ee3523a7537e..32d8969b3ace 100644
--- a/drivers/net/dsa/mt7530.h
+++ b/drivers/net/dsa/mt7530.h
@@ -161,6 +161,19 @@ enum mt7530_vlan_egress_attr {
MT7530_VLAN_EGRESS_STACK = 3,
};
+/* Register for address age control */
+#define MT7530_AAC 0xa0
+/* Disable ageing */
+#define AGE_DIS BIT(20)
+/* Age count */
+#define AGE_CNT_MASK GENMASK(19, 12)
+#define AGE_CNT_MAX 0xff
+#define AGE_CNT(x) (AGE_CNT_MASK & ((x) << 12))
+/* Age unit */
+#define AGE_UNIT_MASK GENMASK(11, 0)
+#define AGE_UNIT_MAX 0xfff
+#define AGE_UNIT(x) (AGE_UNIT_MASK & (x))
+
/* Register for port STP state control */
#define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
#define FID_PST(x) ((x) & 0x3)
--
2.25.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time
2020-11-19 6:40 ` DENG Qingfang
@ 2020-11-20 2:25 ` Andrew Lunn
-1 siblings, 0 replies; 7+ messages in thread
From: Andrew Lunn @ 2020-11-20 2:25 UTC (permalink / raw)
To: DENG Qingfang
Cc: netdev, linux-mediatek, Sean Wang, Landen Chao, Vivien Didelot,
Florian Fainelli, Vladimir Oltean, David S . Miller,
Jakub Kicinski, Matthias Brugger, Russell King,
René van Dorst, Frank Wunderlich, Greg Ungerer, Alex Dewar,
Chuanhong Guo
On Thu, Nov 19, 2020 at 02:40:20PM +0800, DENG Qingfang wrote:
> MT7530 has a global address age control register, so use it to set
> ageing time.
>
> The applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds
>
> Signed-off-by: DENG Qingfang <dqfext@gmail.com>
> ---
> drivers/net/dsa/mt7530.c | 41 ++++++++++++++++++++++++++++++++++++++++
> drivers/net/dsa/mt7530.h | 13 +++++++++++++
> 2 files changed, 54 insertions(+)
>
> RFC:
> 1. What is the expected behaviour if the timer is too big or too small?
> - return -ERANGE or -EINVAL;
ERANGE is good.
> or
> - if it is too big, apply the maximum value; if it is too small,
> disable learning;
>
> 2. Is there a better algorithm to find the closest pair?
The bridge code will default to 300 seconds. And after a topology
change, it sets it to 2 * the forwarding delay, which defaults to 15
seconds. So maybe you can look for these two values, and use
pre-computed values?
You still need to handle other values, the user can configure these.
Andrew
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time
@ 2020-11-20 2:25 ` Andrew Lunn
0 siblings, 0 replies; 7+ messages in thread
From: Andrew Lunn @ 2020-11-20 2:25 UTC (permalink / raw)
To: DENG Qingfang
Cc: Landen Chao, Florian Fainelli, Frank Wunderlich, netdev,
Sean Wang, Russell King, David S . Miller, René van Dorst,
Alex Dewar, Greg Ungerer, linux-mediatek, Matthias Brugger,
Jakub Kicinski, Vladimir Oltean, Chuanhong Guo, Vivien Didelot
On Thu, Nov 19, 2020 at 02:40:20PM +0800, DENG Qingfang wrote:
> MT7530 has a global address age control register, so use it to set
> ageing time.
>
> The applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds
>
> Signed-off-by: DENG Qingfang <dqfext@gmail.com>
> ---
> drivers/net/dsa/mt7530.c | 41 ++++++++++++++++++++++++++++++++++++++++
> drivers/net/dsa/mt7530.h | 13 +++++++++++++
> 2 files changed, 54 insertions(+)
>
> RFC:
> 1. What is the expected behaviour if the timer is too big or too small?
> - return -ERANGE or -EINVAL;
ERANGE is good.
> or
> - if it is too big, apply the maximum value; if it is too small,
> disable learning;
>
> 2. Is there a better algorithm to find the closest pair?
The bridge code will default to 300 seconds. And after a topology
change, it sets it to 2 * the forwarding delay, which defaults to 15
seconds. So maybe you can look for these two values, and use
pre-computed values?
You still need to handle other values, the user can configure these.
Andrew
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time
2020-11-20 2:25 ` Andrew Lunn
@ 2020-11-20 3:37 ` DENG Qingfang
-1 siblings, 0 replies; 7+ messages in thread
From: DENG Qingfang @ 2020-11-20 3:37 UTC (permalink / raw)
To: Andrew Lunn
Cc: netdev, moderated list:ARM/Mediatek SoC support, Sean Wang,
Landen Chao, Vivien Didelot, Florian Fainelli, Vladimir Oltean,
David S . Miller, Jakub Kicinski, Matthias Brugger, Russell King,
René van Dorst, Frank Wunderlich, Greg Ungerer, Alex Dewar,
Chuanhong Guo
On Fri, Nov 20, 2020 at 10:26 AM Andrew Lunn <andrew@lunn.ch> wrote:
> The bridge code will default to 300 seconds. And after a topology
> change, it sets it to 2 * the forwarding delay, which defaults to 15
> seconds. So maybe you can look for these two values, and use
> pre-computed values?
15 and 300 are not larger than 4096 (AGE_UNIT_MAX + 1) so the exact
match can always be found in the first iteration:
age_count = 0, age_unit = 14, secs = (0 + 1) * (14 + 1) = 15
age_count = 0, age_unit = 299, secs = (0 + 1) * (299 + 1) = 300
>
> You still need to handle other values, the user can configure these.
>
> Andrew
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time
@ 2020-11-20 3:37 ` DENG Qingfang
0 siblings, 0 replies; 7+ messages in thread
From: DENG Qingfang @ 2020-11-20 3:37 UTC (permalink / raw)
To: Andrew Lunn
Cc: Landen Chao, Florian Fainelli, Frank Wunderlich, netdev,
Sean Wang, Russell King, David S . Miller, René van Dorst,
Alex Dewar, Greg Ungerer,
moderated list:ARM/Mediatek SoC support, Matthias Brugger,
Jakub Kicinski, Vladimir Oltean, Chuanhong Guo, Vivien Didelot
On Fri, Nov 20, 2020 at 10:26 AM Andrew Lunn <andrew@lunn.ch> wrote:
> The bridge code will default to 300 seconds. And after a topology
> change, it sets it to 2 * the forwarding delay, which defaults to 15
> seconds. So maybe you can look for these two values, and use
> pre-computed values?
15 and 300 are not larger than 4096 (AGE_UNIT_MAX + 1) so the exact
match can always be found in the first iteration:
age_count = 0, age_unit = 14, secs = (0 + 1) * (14 + 1) = 15
age_count = 0, age_unit = 299, secs = (0 + 1) * (299 + 1) = 300
>
> You still need to handle other values, the user can configure these.
>
> Andrew
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time
@ 2020-11-25 6:00 kernel test robot
0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2020-11-25 6:00 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 4392 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20201119064020.19522-1-dqfext@gmail.com>
References: <20201119064020.19522-1-dqfext@gmail.com>
TO: DENG Qingfang <dqfext@gmail.com>
Hi DENG,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/DENG-Qingfang/net-dsa-mt7530-support-setting-ageing-time/20201119-144450
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e76d795ecb5bb67741fb9e304dcce7950c7aeea0
:::::: branch date: 6 days ago
:::::: commit date: 6 days ago
config: x86_64-randconfig-m001-20201125 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
drivers/net/dsa/mt7530.c:908 mt7530_set_ageing_time() error: uninitialized symbol 'age_count'.
drivers/net/dsa/mt7530.c:908 mt7530_set_ageing_time() error: uninitialized symbol 'age_unit'.
Old smatch warnings:
drivers/net/dsa/mt7530.c:469 mt7530_pad_clk_setup() error: uninitialized symbol 'ncpo1'.
vim +/age_count +908 drivers/net/dsa/mt7530.c
b8f126a8d54318b Sean Wang 2017-04-07 872
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 873 static int
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 874 mt7530_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 875 {
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 876 struct mt7530_priv *priv = ds->priv;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 877 unsigned int secs = msecs / 1000;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 878 unsigned int tmp_age_count;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 879 unsigned int error = -1;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 880 unsigned int age_count;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 881 unsigned int age_unit;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 882
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 883 /* Applied timer is (AGE_CNT + 1) * (AGE_UNIT + 1) seconds */
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 884 if (secs < 1 || secs > (AGE_CNT_MAX + 1) * (AGE_UNIT_MAX + 1))
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 885 return -ERANGE;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 886
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 887 /* iterate through all possible age_count to find the closest pair */
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 888 for (tmp_age_count = 0; tmp_age_count <= AGE_CNT_MAX; ++tmp_age_count) {
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 889 unsigned int tmp_age_unit = secs / (tmp_age_count + 1) - 1;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 890
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 891 if (tmp_age_unit <= AGE_UNIT_MAX) {
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 892 unsigned int tmp_error = secs -
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 893 (tmp_age_count + 1) * (tmp_age_unit + 1);
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 894
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 895 /* found a closer pair */
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 896 if (error > tmp_error) {
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 897 error = tmp_error;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 898 age_count = tmp_age_count;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 899 age_unit = tmp_age_unit;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 900 }
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 901
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 902 /* found the exact match, so break the loop */
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 903 if (!error)
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 904 break;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 905 }
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 906 }
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 907
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 @908 mt7530_write(priv, MT7530_AAC, AGE_CNT(age_count) | AGE_UNIT(age_unit));
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 909
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 910 return 0;
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 911 }
d11e5a9ab8bb73d DENG Qingfang 2020-11-19 912
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 33282 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-11-25 6:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 6:40 [RFC PATCH net-next] net: dsa: mt7530: support setting ageing time DENG Qingfang
2020-11-19 6:40 ` DENG Qingfang
2020-11-20 2:25 ` Andrew Lunn
2020-11-20 2:25 ` Andrew Lunn
2020-11-20 3:37 ` DENG Qingfang
2020-11-20 3:37 ` DENG Qingfang
2020-11-25 6:00 kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.