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
7 Convert for loop to dsa_for_each macro to save some redundant write on
8 unconnected/unused port and tidy things up.
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>
15 drivers/net/dsa/qca/qca8k-8xxx.c | 107 ++++++++++++++++---------------
16 1 file changed, 54 insertions(+), 53 deletions(-)
18 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
19 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
20 @@ -1828,7 +1828,8 @@ static int
21 qca8k_setup(struct dsa_switch *ds)
23 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
24 - int cpu_port, ret, i;
25 + struct dsa_port *dp;
29 cpu_port = qca8k_find_cpu_port(ds);
30 @@ -1879,27 +1880,27 @@ qca8k_setup(struct dsa_switch *ds)
31 dev_warn(priv->dev, "mib init failed");
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);
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));
50 - dev_err(priv->dev, "failed enabling QCA header mode");
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);
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));
63 + dev_err(priv->dev, "failed enabling QCA header mode on port %d", dp->index);
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);
72 /* Forward all unknown frames to CPU port for Linux processing
73 @@ -1921,48 +1922,48 @@ qca8k_setup(struct dsa_switch *ds)
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
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,
89 - ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(i),
90 - QCA8K_PORT_LOOKUP_LEARN);
94 - /* For port based vlans to work we need to set the
95 - * default egress vid
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));
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));
109 + dsa_switch_for_each_user_port(dp, ds) {
110 + u8 port = dp->index;
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,
123 + ret = regmap_clear_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(port),
124 + QCA8K_PORT_LOOKUP_LEARN);
128 + /* For port based vlans to work we need to set the
129 + * default egress vid
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));
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));
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.
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);
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) |