1 From 3bb0844e7bcd0fb0bcfab6202b5edd349ef5250a Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 27 Jul 2022 13:35:10 +0200
4 Subject: [PATCH 01/14] net: dsa: qca8k: cache match data to speed up access
6 Using of_device_get_match_data is expensive. Cache match data to speed
7 up access and rework user of match data to use the new cached value.
9 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
10 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
11 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
13 drivers/net/dsa/qca/qca8k.c | 35 +++++++++++------------------------
14 drivers/net/dsa/qca/qca8k.h | 1 +
15 2 files changed, 12 insertions(+), 24 deletions(-)
17 --- a/drivers/net/dsa/qca/qca8k.c
18 +++ b/drivers/net/dsa/qca/qca8k.c
19 @@ -1462,8 +1462,8 @@ static int qca8k_find_cpu_port(struct ds
21 qca8k_setup_of_pws_reg(struct qca8k_priv *priv)
23 + const struct qca8k_match_data *data = priv->info;
24 struct device_node *node = priv->dev->of_node;
25 - const struct qca8k_match_data *data;
29 @@ -1472,8 +1472,6 @@ qca8k_setup_of_pws_reg(struct qca8k_priv
30 * Should be applied by default but we set this just to make sure.
32 if (priv->switch_id == QCA8K_ID_QCA8327) {
33 - data = of_device_get_match_data(priv->dev);
35 /* Set the correct package of 148 pin for QCA8327 */
36 if (data->reduced_package)
37 val |= QCA8327_PWS_PACKAGE148_EN;
38 @@ -2146,23 +2144,19 @@ qca8k_phylink_mac_link_up(struct dsa_swi
40 qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data)
42 - const struct qca8k_match_data *match_data;
43 struct qca8k_priv *priv = ds->priv;
46 if (stringset != ETH_SS_STATS)
49 - match_data = of_device_get_match_data(priv->dev);
51 - for (i = 0; i < match_data->mib_count; i++)
52 + for (i = 0; i < priv->info->mib_count; i++)
53 strncpy(data + i * ETH_GSTRING_LEN, ar8327_mib[i].name,
57 static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *skb)
59 - const struct qca8k_match_data *match_data;
60 struct qca8k_mib_eth_data *mib_eth_data;
61 struct qca8k_priv *priv = ds->priv;
62 const struct qca8k_mib_desc *mib;
63 @@ -2181,10 +2175,9 @@ static void qca8k_mib_autocast_handler(s
64 if (port != mib_eth_data->req_port)
67 - match_data = device_get_match_data(priv->dev);
68 data = mib_eth_data->data;
70 - for (i = 0; i < match_data->mib_count; i++) {
71 + for (i = 0; i < priv->info->mib_count; i++) {
74 /* First 3 mib are present in the skb head */
75 @@ -2256,7 +2249,6 @@ qca8k_get_ethtool_stats(struct dsa_switc
78 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
79 - const struct qca8k_match_data *match_data;
80 const struct qca8k_mib_desc *mib;
83 @@ -2266,9 +2258,7 @@ qca8k_get_ethtool_stats(struct dsa_switc
84 qca8k_get_ethtool_stats_eth(ds, port, data) > 0)
87 - match_data = of_device_get_match_data(priv->dev);
89 - for (i = 0; i < match_data->mib_count; i++) {
90 + for (i = 0; i < priv->info->mib_count; i++) {
92 reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
94 @@ -2291,15 +2281,12 @@ qca8k_get_ethtool_stats(struct dsa_switc
96 qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset)
98 - const struct qca8k_match_data *match_data;
99 struct qca8k_priv *priv = ds->priv;
101 if (sset != ETH_SS_STATS)
104 - match_data = of_device_get_match_data(priv->dev);
106 - return match_data->mib_count;
107 + return priv->info->mib_count;
111 @@ -3037,14 +3024,11 @@ static const struct dsa_switch_ops qca8k
113 static int qca8k_read_switch_id(struct qca8k_priv *priv)
115 - const struct qca8k_match_data *data;
120 - /* get the switches ID from the compatible */
121 - data = of_device_get_match_data(priv->dev);
126 ret = qca8k_read(priv, QCA8K_REG_MASK_CTRL, &val);
127 @@ -3052,8 +3036,10 @@ static int qca8k_read_switch_id(struct q
130 id = QCA8K_MASK_CTRL_DEVICE_ID(val);
131 - if (id != data->id) {
132 - dev_err(priv->dev, "Switch id detected %x but expected %x", id, data->id);
133 + if (id != priv->info->id) {
135 + "Switch id detected %x but expected %x",
136 + id, priv->info->id);
140 @@ -3078,6 +3064,7 @@ qca8k_sw_probe(struct mdio_device *mdiod
144 + priv->info = of_device_get_match_data(priv->dev);
145 priv->bus = mdiodev->bus;
146 priv->dev = &mdiodev->dev;
148 --- a/drivers/net/dsa/qca/qca8k.h
149 +++ b/drivers/net/dsa/qca/qca8k.h
150 @@ -393,6 +393,7 @@ struct qca8k_priv {
151 struct qca8k_mgmt_eth_data mgmt_eth_data;
152 struct qca8k_mib_eth_data mib_eth_data;
153 struct qca8k_mdio_cache mdio_cache;
154 + const struct qca8k_match_data *info;
157 struct qca8k_mib_desc {