kernel: bump 6.1 to 6.1.77
[openwrt/staging/jow.git] / target / linux / generic / backport-6.1 / 780-v6.6-04-net-dsa-qca8k-use-dsa_for_each-macro-instead-of-for-.patch
1 From 01e6f8ad8d26ced14b0cf288c42e55d03a7c5070 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Sun, 30 Jul 2023 09:41:13 +0200
4 Subject: [PATCH 4/4] net: dsa: qca8k: use dsa_for_each macro instead of for
5 loop
6
7 Convert for loop to dsa_for_each macro to save some redundant write on
8 unconnected/unused port and tidy things up.
9
10 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
11 Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
12 Link: https://lore.kernel.org/r/20230730074113.21889-5-ansuelsmth@gmail.com
13 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
14 ---
15 drivers/net/dsa/qca/qca8k-8xxx.c | 107 ++++++++++++++++---------------
16 1 file changed, 54 insertions(+), 53 deletions(-)
17
18 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
19 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
20 @@ -1839,7 +1839,8 @@ static int
21 qca8k_setup(struct dsa_switch *ds)
22 {
23 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
24 - int cpu_port, ret, i;
25 + struct dsa_port *dp;
26 + int cpu_port, ret;
27 u32 mask;
28
29 cpu_port = qca8k_find_cpu_port(ds);
30 @@ -1890,27 +1891,27 @@ qca8k_setup(struct dsa_switch *ds)
31 dev_warn(priv->dev, "mib init failed");
32
33 /* Initial setup of all ports */
34 - for (i = 0; i < QCA8K_NUM_PORTS; i++) {
35 + dsa_switch_for_each_port(dp, ds) {
36 /* Disable forwarding by default on all ports */
37 - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
38 + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(dp->index),
39 QCA8K_PORT_LOOKUP_MEMBER, 0);
40 if (ret)
41 return ret;
42 + }
43
44 - /* Enable QCA header mode on all cpu ports */
45 - if (dsa_is_cpu_port(ds, i)) {
46 - ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(i),
47 - FIELD_PREP(QCA8K_PORT_HDR_CTRL_TX_MASK, QCA8K_PORT_HDR_CTRL_ALL) |
48 - FIELD_PREP(QCA8K_PORT_HDR_CTRL_RX_MASK, QCA8K_PORT_HDR_CTRL_ALL));
49 - if (ret) {
50 - dev_err(priv->dev, "failed enabling QCA header mode");
51 - return ret;
52 - }
53 + /* Disable MAC by default on all user ports */
54 + dsa_switch_for_each_user_port(dp, ds)
55 + qca8k_port_set_status(priv, dp->index, 0);
56 +
57 + /* Enable QCA header mode on all cpu ports */
58 + dsa_switch_for_each_cpu_port(dp, ds) {
59 + ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(dp->index),
60 + FIELD_PREP(QCA8K_PORT_HDR_CTRL_TX_MASK, QCA8K_PORT_HDR_CTRL_ALL) |
61 + FIELD_PREP(QCA8K_PORT_HDR_CTRL_RX_MASK, QCA8K_PORT_HDR_CTRL_ALL));
62 + if (ret) {
63 + dev_err(priv->dev, "failed enabling QCA header mode on port %d", dp->index);
64 + return ret;
65 }
66 -
67 - /* Disable MAC by default on all user ports */
68 - if (dsa_is_user_port(ds, i))
69 - qca8k_port_set_status(priv, i, 0);
70 }
71
72 /* Forward all unknown frames to CPU port for Linux processing
73 @@ -1932,48 +1933,48 @@ qca8k_setup(struct dsa_switch *ds)
74 return ret;
75
76 /* Setup connection between CPU port & user ports
77 - * Configure specific switch configuration for ports
78 + * Individual user ports get connected to CPU port only
79 */
80 - for (i = 0; i < QCA8K_NUM_PORTS; i++) {
81 - /* Individual user ports get connected to CPU port only */
82 - if (dsa_is_user_port(ds, i)) {
83 - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
84 - QCA8K_PORT_LOOKUP_MEMBER,
85 - BIT(cpu_port));
86 - if (ret)
87 - return ret;
88 -
89 - ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(i),
90 - QCA8K_PORT_LOOKUP_LEARN);
91 - if (ret)
92 - return ret;
93 -
94 - /* For port based vlans to work we need to set the
95 - * default egress vid
96 - */
97 - ret = qca8k_rmw(priv, QCA8K_EGRESS_VLAN(i),
98 - QCA8K_EGREES_VLAN_PORT_MASK(i),
99 - QCA8K_EGREES_VLAN_PORT(i, QCA8K_PORT_VID_DEF));
100 - if (ret)
101 - return ret;
102 -
103 - ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(i),
104 - QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
105 - QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
106 - if (ret)
107 - return ret;
108 - }
109 + dsa_switch_for_each_user_port(dp, ds) {
110 + u8 port = dp->index;
111
112 - /* The port 5 of the qca8337 have some problem in flood condition. The
113 - * original legacy driver had some specific buffer and priority settings
114 - * for the different port suggested by the QCA switch team. Add this
115 - * missing settings to improve switch stability under load condition.
116 - * This problem is limited to qca8337 and other qca8k switch are not affected.
117 + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
118 + QCA8K_PORT_LOOKUP_MEMBER,
119 + BIT(cpu_port));
120 + if (ret)
121 + return ret;
122 +
123 + ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(port),
124 + QCA8K_PORT_LOOKUP_LEARN);
125 + if (ret)
126 + return ret;
127 +
128 + /* For port based vlans to work we need to set the
129 + * default egress vid
130 */
131 - if (priv->switch_id == QCA8K_ID_QCA8337)
132 - qca8k_setup_hol_fixup(priv, i);
133 + ret = qca8k_rmw(priv, QCA8K_EGRESS_VLAN(port),
134 + QCA8K_EGREES_VLAN_PORT_MASK(port),
135 + QCA8K_EGREES_VLAN_PORT(port, QCA8K_PORT_VID_DEF));
136 + if (ret)
137 + return ret;
138 +
139 + ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(port),
140 + QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
141 + QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
142 + if (ret)
143 + return ret;
144 }
145
146 + /* The port 5 of the qca8337 have some problem in flood condition. The
147 + * original legacy driver had some specific buffer and priority settings
148 + * for the different port suggested by the QCA switch team. Add this
149 + * missing settings to improve switch stability under load condition.
150 + * This problem is limited to qca8337 and other qca8k switch are not affected.
151 + */
152 + if (priv->switch_id == QCA8K_ID_QCA8337)
153 + dsa_switch_for_each_available_port(dp, ds)
154 + qca8k_setup_hol_fixup(priv, dp->index);
155 +
156 /* Special GLOBAL_FC_THRESH value are needed for ar8327 switch */
157 if (priv->switch_id == QCA8K_ID_QCA8327) {
158 mask = QCA8K_GLOBAL_FC_GOL_XON_THRES(288) |