ebd08845bcfc53accf0ae3ac22007ac0ce4ae124
[openwrt/staging/981213.git] /
1 From 4f3701fc599820568ba4395070d34e4248800fc0 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Wed, 2 Feb 2022 01:03:35 +0100
4 Subject: [PATCH 16/16] net: dsa: qca8k: introduce qca8k_bulk_read/write
5 function
6
7 Introduce qca8k_bulk_read/write() function to use mgmt Ethernet way to
8 read/write packet in bulk. Make use of this new function in the fdb
9 function and while at it reduce the reg for fdb_read from 4 to 3 as the
10 max bit for the ARL(fdb) table is 83 bits.
11
12 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/net/dsa/qca8k.c | 55 ++++++++++++++++++++++++++++++++---------
16 1 file changed, 43 insertions(+), 12 deletions(-)
17
18 diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
19 index a1b76dcd2eb6..52ec2800dd89 100644
20 --- a/drivers/net/dsa/qca8k.c
21 +++ b/drivers/net/dsa/qca8k.c
22 @@ -411,6 +411,43 @@ qca8k_regmap_update_bits_eth(struct qca8k_priv *priv, u32 reg, u32 mask, u32 wri
23 return qca8k_write_eth(priv, reg, &val, sizeof(val));
24 }
25
26 +static int
27 +qca8k_bulk_read(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
28 +{
29 + int i, count = len / sizeof(u32), ret;
30 +
31 + if (priv->mgmt_master && !qca8k_read_eth(priv, reg, val, len))
32 + return 0;
33 +
34 + for (i = 0; i < count; i++) {
35 + ret = regmap_read(priv->regmap, reg + (i * 4), val + i);
36 + if (ret < 0)
37 + return ret;
38 + }
39 +
40 + return 0;
41 +}
42 +
43 +static int
44 +qca8k_bulk_write(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
45 +{
46 + int i, count = len / sizeof(u32), ret;
47 + u32 tmp;
48 +
49 + if (priv->mgmt_master && !qca8k_write_eth(priv, reg, val, len))
50 + return 0;
51 +
52 + for (i = 0; i < count; i++) {
53 + tmp = val[i];
54 +
55 + ret = regmap_write(priv->regmap, reg + (i * 4), tmp);
56 + if (ret < 0)
57 + return ret;
58 + }
59 +
60 + return 0;
61 +}
62 +
63 static int
64 qca8k_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
65 {
66 @@ -546,17 +583,13 @@ qca8k_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask)
67 static int
68 qca8k_fdb_read(struct qca8k_priv *priv, struct qca8k_fdb *fdb)
69 {
70 - u32 reg[4], val;
71 - int i, ret;
72 + u32 reg[3];
73 + int ret;
74
75 /* load the ARL table into an array */
76 - for (i = 0; i < 4; i++) {
77 - ret = qca8k_read(priv, QCA8K_REG_ATU_DATA0 + (i * 4), &val);
78 - if (ret < 0)
79 - return ret;
80 -
81 - reg[i] = val;
82 - }
83 + ret = qca8k_bulk_read(priv, QCA8K_REG_ATU_DATA0, reg, sizeof(reg));
84 + if (ret)
85 + return ret;
86
87 /* vid - 83:72 */
88 fdb->vid = FIELD_GET(QCA8K_ATU_VID_MASK, reg[2]);
89 @@ -580,7 +613,6 @@ qca8k_fdb_write(struct qca8k_priv *priv, u16 vid, u8 port_mask, const u8 *mac,
90 u8 aging)
91 {
92 u32 reg[3] = { 0 };
93 - int i;
94
95 /* vid - 83:72 */
96 reg[2] = FIELD_PREP(QCA8K_ATU_VID_MASK, vid);
97 @@ -597,8 +629,7 @@ qca8k_fdb_write(struct qca8k_priv *priv, u16 vid, u8 port_mask, const u8 *mac,
98 reg[0] |= FIELD_PREP(QCA8K_ATU_ADDR5_MASK, mac[5]);
99
100 /* load the array into the ARL table */
101 - for (i = 0; i < 3; i++)
102 - qca8k_write(priv, QCA8K_REG_ATU_DATA0 + (i * 4), reg[i]);
103 + qca8k_bulk_write(priv, QCA8K_REG_ATU_DATA0, reg, sizeof(reg));
104 }
105
106 static int
107 --
108 2.34.1
109