1 From 910746444313dc463396cd63024cdf54ef04ef39 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 27 Jul 2022 13:35:14 +0200
4 Subject: [PATCH 05/14] net: dsa: qca8k: move qca8k bulk read/write helper to
7 The same ATU function are used by drivers based on qca8k family switch.
8 Move the bulk read/write helper to common code to declare these shared
9 ATU functions in common code.
10 These helper will be dropped when regmap correctly support bulk
13 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
14 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
15 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 drivers/net/dsa/qca/qca8k-8xxx.c | 39 ++----------------------------
18 drivers/net/dsa/qca/qca8k-common.c | 39 ++++++++++++++++++++++++++++++
19 drivers/net/dsa/qca/qca8k.h | 8 ++++++
20 3 files changed, 49 insertions(+), 37 deletions(-)
22 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
23 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
24 @@ -343,43 +343,6 @@ qca8k_regmap_update_bits_eth(struct qca8
28 -qca8k_bulk_read(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
30 - int i, count = len / sizeof(u32), ret;
32 - if (priv->mgmt_master && !qca8k_read_eth(priv, reg, val, len))
35 - for (i = 0; i < count; i++) {
36 - ret = regmap_read(priv->regmap, reg + (i * 4), val + i);
45 -qca8k_bulk_write(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
47 - int i, count = len / sizeof(u32), ret;
50 - if (priv->mgmt_master && !qca8k_write_eth(priv, reg, val, len))
53 - for (i = 0; i < count; i++) {
56 - ret = regmap_write(priv->regmap, reg + (i * 4), tmp);
65 qca8k_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
67 struct qca8k_priv *priv = (struct qca8k_priv *)ctx;
68 @@ -3096,6 +3059,8 @@ static SIMPLE_DEV_PM_OPS(qca8k_pm_ops,
70 static const struct qca8k_info_ops qca8xxx_ops = {
71 .autocast_mib = qca8k_get_ethtool_stats_eth,
72 + .read_eth = qca8k_read_eth,
73 + .write_eth = qca8k_write_eth,
76 static const struct qca8k_match_data qca8327 = {
77 --- a/drivers/net/dsa/qca/qca8k-common.c
78 +++ b/drivers/net/dsa/qca/qca8k-common.c
79 @@ -99,3 +99,42 @@ const struct regmap_access_table qca8k_r
80 .yes_ranges = qca8k_readable_ranges,
81 .n_yes_ranges = ARRAY_SIZE(qca8k_readable_ranges),
84 +/* TODO: remove these extra ops when we can support regmap bulk read/write */
85 +int qca8k_bulk_read(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
87 + int i, count = len / sizeof(u32), ret;
89 + if (priv->mgmt_master && priv->info->ops->read_eth &&
90 + !priv->info->ops->read_eth(priv, reg, val, len))
93 + for (i = 0; i < count; i++) {
94 + ret = regmap_read(priv->regmap, reg + (i * 4), val + i);
102 +/* TODO: remove these extra ops when we can support regmap bulk read/write */
103 +int qca8k_bulk_write(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
105 + int i, count = len / sizeof(u32), ret;
108 + if (priv->mgmt_master && priv->info->ops->write_eth &&
109 + !priv->info->ops->write_eth(priv, reg, val, len))
112 + for (i = 0; i < count; i++) {
115 + ret = regmap_write(priv->regmap, reg + (i * 4), tmp);
122 --- a/drivers/net/dsa/qca/qca8k.h
123 +++ b/drivers/net/dsa/qca/qca8k.h
124 @@ -324,8 +324,13 @@ enum qca8k_mid_cmd {
130 struct qca8k_info_ops {
131 int (*autocast_mib)(struct dsa_switch *ds, int port, u64 *data);
132 + /* TODO: remove these extra ops when we can support regmap bulk read/write */
133 + int (*read_eth)(struct qca8k_priv *priv, u32 reg, u32 *val, int len);
134 + int (*write_eth)(struct qca8k_priv *priv, u32 reg, u32 *val, int len);
137 struct qca8k_match_data {
138 @@ -423,4 +428,7 @@ int qca8k_read(struct qca8k_priv *priv,
139 int qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val);
140 int qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 write_val);
142 +int qca8k_bulk_read(struct qca8k_priv *priv, u32 reg, u32 *val, int len);
143 +int qca8k_bulk_write(struct qca8k_priv *priv, u32 reg, u32 *val, int len);
145 #endif /* __QCA8K_H */