77fe64632f40195dfebd242825fb02bbb721a456
[openwrt/staging/xback.git] /
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
5
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.
8
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>
12 ---
13 drivers/net/dsa/qca/qca8k.c | 35 +++++++++++------------------------
14 drivers/net/dsa/qca/qca8k.h | 1 +
15 2 files changed, 12 insertions(+), 24 deletions(-)
16
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
20 static int
21 qca8k_setup_of_pws_reg(struct qca8k_priv *priv)
22 {
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;
26 u32 val = 0;
27 int ret;
28
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.
31 */
32 if (priv->switch_id == QCA8K_ID_QCA8327) {
33 - data = of_device_get_match_data(priv->dev);
34 -
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
39 static void
40 qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data)
41 {
42 - const struct qca8k_match_data *match_data;
43 struct qca8k_priv *priv = ds->priv;
44 int i;
45
46 if (stringset != ETH_SS_STATS)
47 return;
48
49 - match_data = of_device_get_match_data(priv->dev);
50 -
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,
54 ETH_GSTRING_LEN);
55 }
56
57 static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *skb)
58 {
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)
65 goto exit;
66
67 - match_data = device_get_match_data(priv->dev);
68 data = mib_eth_data->data;
69
70 - for (i = 0; i < match_data->mib_count; i++) {
71 + for (i = 0; i < priv->info->mib_count; i++) {
72 mib = &ar8327_mib[i];
73
74 /* First 3 mib are present in the skb head */
75 @@ -2256,7 +2249,6 @@ qca8k_get_ethtool_stats(struct dsa_switc
76 uint64_t *data)
77 {
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;
81 u32 reg, i, val;
82 u32 hi = 0;
83 @@ -2266,9 +2258,7 @@ qca8k_get_ethtool_stats(struct dsa_switc
84 qca8k_get_ethtool_stats_eth(ds, port, data) > 0)
85 return;
86
87 - match_data = of_device_get_match_data(priv->dev);
88 -
89 - for (i = 0; i < match_data->mib_count; i++) {
90 + for (i = 0; i < priv->info->mib_count; i++) {
91 mib = &ar8327_mib[i];
92 reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
93
94 @@ -2291,15 +2281,12 @@ qca8k_get_ethtool_stats(struct dsa_switc
95 static int
96 qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset)
97 {
98 - const struct qca8k_match_data *match_data;
99 struct qca8k_priv *priv = ds->priv;
100
101 if (sset != ETH_SS_STATS)
102 return 0;
103
104 - match_data = of_device_get_match_data(priv->dev);
105 -
106 - return match_data->mib_count;
107 + return priv->info->mib_count;
108 }
109
110 static int
111 @@ -3037,14 +3024,11 @@ static const struct dsa_switch_ops qca8k
112
113 static int qca8k_read_switch_id(struct qca8k_priv *priv)
114 {
115 - const struct qca8k_match_data *data;
116 u32 val;
117 u8 id;
118 int ret;
119
120 - /* get the switches ID from the compatible */
121 - data = of_device_get_match_data(priv->dev);
122 - if (!data)
123 + if (!priv->info)
124 return -ENODEV;
125
126 ret = qca8k_read(priv, QCA8K_REG_MASK_CTRL, &val);
127 @@ -3052,8 +3036,10 @@ static int qca8k_read_switch_id(struct q
128 return -ENODEV;
129
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) {
134 + dev_err(priv->dev,
135 + "Switch id detected %x but expected %x",
136 + id, priv->info->id);
137 return -ENODEV;
138 }
139
140 @@ -3078,6 +3064,7 @@ qca8k_sw_probe(struct mdio_device *mdiod
141 if (!priv)
142 return -ENOMEM;
143
144 + priv->info = of_device_get_match_data(priv->dev);
145 priv->bus = mdiodev->bus;
146 priv->dev = &mdiodev->dev;
147
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;
155 };
156
157 struct qca8k_mib_desc {