| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 9f374df14572a9b4fb0940d8d6721c930bc27da1 Mon Sep 17 00:00:00 2001 |
| 2 | From: Vladimir Oltean <vladimir.oltean@nxp.com> |
| 3 | Date: Sat, 9 Nov 2019 15:02:52 +0200 |
| 4 | Subject: [PATCH] net: mscc: ocelot: refactor struct ocelot_port out of |
| 5 | function prototypes |
| 6 | |
| 7 | The ocelot_port structure has a net_device embedded in it, which makes |
| 8 | it unsuitable for leaving it in the driver implementation functions. |
| 9 | |
| 10 | Leave ocelot_flower.c untouched. In that file, ocelot_port is used as an |
| 11 | interface to the tc shared blocks. That will be addressed in the next |
| 12 | patch. |
| 13 | |
| 14 | Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> |
| 15 | Signed-off-by: David S. Miller <davem@davemloft.net> |
| 16 | --- |
| 17 | drivers/net/ethernet/mscc/ocelot.c | 79 ++++++++++++++----------------- |
| 18 | drivers/net/ethernet/mscc/ocelot_police.c | 36 +++++++------- |
| 19 | drivers/net/ethernet/mscc/ocelot_police.h | 4 +- |
| 20 | drivers/net/ethernet/mscc/ocelot_tc.c | 5 +- |
| 21 | 4 files changed, 59 insertions(+), 65 deletions(-) |
| 22 | |
| 23 | --- a/drivers/net/ethernet/mscc/ocelot.c |
| 24 | +++ b/drivers/net/ethernet/mscc/ocelot.c |
| 25 | @@ -133,11 +133,11 @@ static void ocelot_mact_init(struct ocel |
| 26 | ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS); |
| 27 | } |
| 28 | |
| 29 | -static void ocelot_vcap_enable(struct ocelot *ocelot, struct ocelot_port *port) |
| 30 | +static void ocelot_vcap_enable(struct ocelot *ocelot, int port) |
| 31 | { |
| 32 | ocelot_write_gix(ocelot, ANA_PORT_VCAP_S2_CFG_S2_ENA | |
| 33 | ANA_PORT_VCAP_S2_CFG_S2_IP6_CFG(0xa), |
| 34 | - ANA_PORT_VCAP_S2_CFG, port->chip_port); |
| 35 | + ANA_PORT_VCAP_S2_CFG, port); |
| 36 | } |
| 37 | |
| 38 | static inline u32 ocelot_vlant_read_vlanaccess(struct ocelot *ocelot) |
| 39 | @@ -170,19 +170,17 @@ static int ocelot_vlant_set_mask(struct |
| 40 | return ocelot_vlant_wait_for_completion(ocelot); |
| 41 | } |
| 42 | |
| 43 | -static void ocelot_vlan_mode(struct ocelot_port *port, |
| 44 | +static void ocelot_vlan_mode(struct ocelot *ocelot, int port, |
| 45 | netdev_features_t features) |
| 46 | { |
| 47 | - struct ocelot *ocelot = port->ocelot; |
| 48 | - u8 p = port->chip_port; |
| 49 | u32 val; |
| 50 | |
| 51 | /* Filtering */ |
| 52 | val = ocelot_read(ocelot, ANA_VLANMASK); |
| 53 | if (features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 54 | - val |= BIT(p); |
| 55 | + val |= BIT(port); |
| 56 | else |
| 57 | - val &= ~BIT(p); |
| 58 | + val &= ~BIT(port); |
| 59 | ocelot_write(ocelot, val, ANA_VLANMASK); |
| 60 | } |
| 61 | |
| 62 | @@ -1034,18 +1032,20 @@ static int ocelot_vlan_rx_kill_vid(struc |
| 63 | static int ocelot_set_features(struct net_device *dev, |
| 64 | netdev_features_t features) |
| 65 | { |
| 66 | - struct ocelot_port *port = netdev_priv(dev); |
| 67 | netdev_features_t changed = dev->features ^ features; |
| 68 | + struct ocelot_port *ocelot_port = netdev_priv(dev); |
| 69 | + struct ocelot *ocelot = ocelot_port->ocelot; |
| 70 | + int port = ocelot_port->chip_port; |
| 71 | |
| 72 | if ((dev->features & NETIF_F_HW_TC) > (features & NETIF_F_HW_TC) && |
| 73 | - port->tc.offload_cnt) { |
| 74 | + ocelot_port->tc.offload_cnt) { |
| 75 | netdev_err(dev, |
| 76 | "Cannot disable HW TC offload while offloads active\n"); |
| 77 | return -EBUSY; |
| 78 | } |
| 79 | |
| 80 | if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 81 | - ocelot_vlan_mode(port, features); |
| 82 | + ocelot_vlan_mode(ocelot, port, features); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | @@ -1583,11 +1583,9 @@ static int ocelot_port_obj_del(struct ne |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | -static int ocelot_port_bridge_join(struct ocelot_port *ocelot_port, |
| 91 | +static int ocelot_port_bridge_join(struct ocelot *ocelot, int port, |
| 92 | struct net_device *bridge) |
| 93 | { |
| 94 | - struct ocelot *ocelot = ocelot_port->ocelot; |
| 95 | - |
| 96 | if (!ocelot->bridge_mask) { |
| 97 | ocelot->hw_bridge_dev = bridge; |
| 98 | } else { |
| 99 | @@ -1597,17 +1595,14 @@ static int ocelot_port_bridge_join(struc |
| 100 | return -ENODEV; |
| 101 | } |
| 102 | |
| 103 | - ocelot->bridge_mask |= BIT(ocelot_port->chip_port); |
| 104 | + ocelot->bridge_mask |= BIT(port); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | -static int ocelot_port_bridge_leave(struct ocelot_port *ocelot_port, |
| 110 | +static int ocelot_port_bridge_leave(struct ocelot *ocelot, int port, |
| 111 | struct net_device *bridge) |
| 112 | { |
| 113 | - struct ocelot *ocelot = ocelot_port->ocelot; |
| 114 | - int port = ocelot_port->chip_port; |
| 115 | - |
| 116 | ocelot->bridge_mask &= ~BIT(port); |
| 117 | |
| 118 | if (!ocelot->bridge_mask) |
| 119 | @@ -1676,14 +1671,12 @@ static void ocelot_setup_lag(struct ocel |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | -static int ocelot_port_lag_join(struct ocelot_port *ocelot_port, |
| 124 | +static int ocelot_port_lag_join(struct ocelot *ocelot, int port, |
| 125 | struct net_device *bond) |
| 126 | { |
| 127 | - struct ocelot *ocelot = ocelot_port->ocelot; |
| 128 | - int p = ocelot_port->chip_port; |
| 129 | - int lag, lp; |
| 130 | struct net_device *ndev; |
| 131 | u32 bond_mask = 0; |
| 132 | + int lag, lp; |
| 133 | |
| 134 | rcu_read_lock(); |
| 135 | for_each_netdev_in_bond_rcu(bond, ndev) { |
| 136 | @@ -1698,17 +1691,17 @@ static int ocelot_port_lag_join(struct o |
| 137 | /* If the new port is the lowest one, use it as the logical port from |
| 138 | * now on |
| 139 | */ |
| 140 | - if (p == lp) { |
| 141 | - lag = p; |
| 142 | - ocelot->lags[p] = bond_mask; |
| 143 | - bond_mask &= ~BIT(p); |
| 144 | + if (port == lp) { |
| 145 | + lag = port; |
| 146 | + ocelot->lags[port] = bond_mask; |
| 147 | + bond_mask &= ~BIT(port); |
| 148 | if (bond_mask) { |
| 149 | lp = __ffs(bond_mask); |
| 150 | ocelot->lags[lp] = 0; |
| 151 | } |
| 152 | } else { |
| 153 | lag = lp; |
| 154 | - ocelot->lags[lp] |= BIT(p); |
| 155 | + ocelot->lags[lp] |= BIT(port); |
| 156 | } |
| 157 | |
| 158 | ocelot_setup_lag(ocelot, lag); |
| 159 | @@ -1717,34 +1710,32 @@ static int ocelot_port_lag_join(struct o |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | -static void ocelot_port_lag_leave(struct ocelot_port *ocelot_port, |
| 164 | +static void ocelot_port_lag_leave(struct ocelot *ocelot, int port, |
| 165 | struct net_device *bond) |
| 166 | { |
| 167 | - struct ocelot *ocelot = ocelot_port->ocelot; |
| 168 | - int p = ocelot_port->chip_port; |
| 169 | u32 port_cfg; |
| 170 | int i; |
| 171 | |
| 172 | /* Remove port from any lag */ |
| 173 | for (i = 0; i < ocelot->num_phys_ports; i++) |
| 174 | - ocelot->lags[i] &= ~BIT(ocelot_port->chip_port); |
| 175 | + ocelot->lags[i] &= ~BIT(port); |
| 176 | |
| 177 | /* if it was the logical port of the lag, move the lag config to the |
| 178 | * next port |
| 179 | */ |
| 180 | - if (ocelot->lags[p]) { |
| 181 | - int n = __ffs(ocelot->lags[p]); |
| 182 | + if (ocelot->lags[port]) { |
| 183 | + int n = __ffs(ocelot->lags[port]); |
| 184 | |
| 185 | - ocelot->lags[n] = ocelot->lags[p]; |
| 186 | - ocelot->lags[p] = 0; |
| 187 | + ocelot->lags[n] = ocelot->lags[port]; |
| 188 | + ocelot->lags[port] = 0; |
| 189 | |
| 190 | ocelot_setup_lag(ocelot, n); |
| 191 | } |
| 192 | |
| 193 | - port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, p); |
| 194 | + port_cfg = ocelot_read_gix(ocelot, ANA_PORT_PORT_CFG, port); |
| 195 | port_cfg &= ~ANA_PORT_PORT_CFG_PORTID_VAL_M; |
| 196 | - ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(p), |
| 197 | - ANA_PORT_PORT_CFG, p); |
| 198 | + ocelot_write_gix(ocelot, port_cfg | ANA_PORT_PORT_CFG_PORTID_VAL(port), |
| 199 | + ANA_PORT_PORT_CFG, port); |
| 200 | |
| 201 | ocelot_set_aggr_pgids(ocelot); |
| 202 | } |
| 203 | @@ -1760,24 +1751,26 @@ static int ocelot_netdevice_port_event(s |
| 204 | struct netdev_notifier_changeupper_info *info) |
| 205 | { |
| 206 | struct ocelot_port *ocelot_port = netdev_priv(dev); |
| 207 | + struct ocelot *ocelot = ocelot_port->ocelot; |
| 208 | + int port = ocelot_port->chip_port; |
| 209 | int err = 0; |
| 210 | |
| 211 | switch (event) { |
| 212 | case NETDEV_CHANGEUPPER: |
| 213 | if (netif_is_bridge_master(info->upper_dev)) { |
| 214 | if (info->linking) |
| 215 | - err = ocelot_port_bridge_join(ocelot_port, |
| 216 | + err = ocelot_port_bridge_join(ocelot, port, |
| 217 | info->upper_dev); |
| 218 | else |
| 219 | - err = ocelot_port_bridge_leave(ocelot_port, |
| 220 | + err = ocelot_port_bridge_leave(ocelot, port, |
| 221 | info->upper_dev); |
| 222 | } |
| 223 | if (netif_is_lag_master(info->upper_dev)) { |
| 224 | if (info->linking) |
| 225 | - err = ocelot_port_lag_join(ocelot_port, |
| 226 | + err = ocelot_port_lag_join(ocelot, port, |
| 227 | info->upper_dev); |
| 228 | else |
| 229 | - ocelot_port_lag_leave(ocelot_port, |
| 230 | + ocelot_port_lag_leave(ocelot, port, |
| 231 | info->upper_dev); |
| 232 | } |
| 233 | break; |
| 234 | @@ -2135,7 +2128,7 @@ int ocelot_probe_port(struct ocelot *oce |
| 235 | REW_PORT_VLAN_CFG, port); |
| 236 | |
| 237 | /* Enable vcap lookups */ |
| 238 | - ocelot_vcap_enable(ocelot, ocelot_port); |
| 239 | + ocelot_vcap_enable(ocelot, port); |
| 240 | |
| 241 | return 0; |
| 242 | |
| 243 | --- a/drivers/net/ethernet/mscc/ocelot_police.c |
| 244 | +++ b/drivers/net/ethernet/mscc/ocelot_police.c |
| 245 | @@ -40,13 +40,12 @@ struct qos_policer_conf { |
| 246 | u8 ipg; /* Size of IPG when MSCC_QOS_RATE_MODE_LINE is chosen */ |
| 247 | }; |
| 248 | |
| 249 | -static int qos_policer_conf_set(struct ocelot_port *port, u32 pol_ix, |
| 250 | +static int qos_policer_conf_set(struct ocelot *ocelot, int port, u32 pol_ix, |
| 251 | struct qos_policer_conf *conf) |
| 252 | { |
| 253 | u32 cf = 0, cir_ena = 0, frm_mode = POL_MODE_LINERATE; |
| 254 | u32 cir = 0, cbs = 0, pir = 0, pbs = 0; |
| 255 | bool cir_discard = 0, pir_discard = 0; |
| 256 | - struct ocelot *ocelot = port->ocelot; |
| 257 | u32 pbs_max = 0, cbs_max = 0; |
| 258 | u8 ipg = 20; |
| 259 | u32 value; |
| 260 | @@ -123,22 +122,26 @@ static int qos_policer_conf_set(struct o |
| 261 | |
| 262 | /* Check limits */ |
| 263 | if (pir > GENMASK(15, 0)) { |
| 264 | - netdev_err(port->dev, "Invalid pir\n"); |
| 265 | + dev_err(ocelot->dev, "Invalid pir for port %d: %u (max %lu)\n", |
| 266 | + port, pir, GENMASK(15, 0)); |
| 267 | return -EINVAL; |
| 268 | } |
| 269 | |
| 270 | if (cir > GENMASK(15, 0)) { |
| 271 | - netdev_err(port->dev, "Invalid cir\n"); |
| 272 | + dev_err(ocelot->dev, "Invalid cir for port %d: %u (max %lu)\n", |
| 273 | + port, cir, GENMASK(15, 0)); |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | |
| 277 | if (pbs > pbs_max) { |
| 278 | - netdev_err(port->dev, "Invalid pbs\n"); |
| 279 | + dev_err(ocelot->dev, "Invalid pbs for port %d: %u (max %u)\n", |
| 280 | + port, pbs, pbs_max); |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | |
| 284 | if (cbs > cbs_max) { |
| 285 | - netdev_err(port->dev, "Invalid cbs\n"); |
| 286 | + dev_err(ocelot->dev, "Invalid cbs for port %d: %u (max %u)\n", |
| 287 | + port, cbs, cbs_max); |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | |
| 291 | @@ -171,10 +174,9 @@ static int qos_policer_conf_set(struct o |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | -int ocelot_port_policer_add(struct ocelot_port *port, |
| 296 | +int ocelot_port_policer_add(struct ocelot *ocelot, int port, |
| 297 | struct ocelot_policer *pol) |
| 298 | { |
| 299 | - struct ocelot *ocelot = port->ocelot; |
| 300 | struct qos_policer_conf pp = { 0 }; |
| 301 | int err; |
| 302 | |
| 303 | @@ -185,11 +187,10 @@ int ocelot_port_policer_add(struct ocelo |
| 304 | pp.pir = pol->rate; |
| 305 | pp.pbs = pol->burst; |
| 306 | |
| 307 | - netdev_dbg(port->dev, |
| 308 | - "%s: port %u pir %u kbps, pbs %u bytes\n", |
| 309 | - __func__, port->chip_port, pp.pir, pp.pbs); |
| 310 | + dev_dbg(ocelot->dev, "%s: port %u pir %u kbps, pbs %u bytes\n", |
| 311 | + __func__, port, pp.pir, pp.pbs); |
| 312 | |
| 313 | - err = qos_policer_conf_set(port, POL_IX_PORT + port->chip_port, &pp); |
| 314 | + err = qos_policer_conf_set(ocelot, port, POL_IX_PORT + port, &pp); |
| 315 | if (err) |
| 316 | return err; |
| 317 | |
| 318 | @@ -198,22 +199,21 @@ int ocelot_port_policer_add(struct ocelo |
| 319 | ANA_PORT_POL_CFG_POL_ORDER(POL_ORDER), |
| 320 | ANA_PORT_POL_CFG_PORT_POL_ENA | |
| 321 | ANA_PORT_POL_CFG_POL_ORDER_M, |
| 322 | - ANA_PORT_POL_CFG, port->chip_port); |
| 323 | + ANA_PORT_POL_CFG, port); |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | -int ocelot_port_policer_del(struct ocelot_port *port) |
| 329 | +int ocelot_port_policer_del(struct ocelot *ocelot, int port) |
| 330 | { |
| 331 | - struct ocelot *ocelot = port->ocelot; |
| 332 | struct qos_policer_conf pp = { 0 }; |
| 333 | int err; |
| 334 | |
| 335 | - netdev_dbg(port->dev, "%s: port %u\n", __func__, port->chip_port); |
| 336 | + dev_dbg(ocelot->dev, "%s: port %u\n", __func__, port); |
| 337 | |
| 338 | pp.mode = MSCC_QOS_RATE_MODE_DISABLED; |
| 339 | |
| 340 | - err = qos_policer_conf_set(port, POL_IX_PORT + port->chip_port, &pp); |
| 341 | + err = qos_policer_conf_set(ocelot, port, POL_IX_PORT + port, &pp); |
| 342 | if (err) |
| 343 | return err; |
| 344 | |
| 345 | @@ -221,7 +221,7 @@ int ocelot_port_policer_del(struct ocelo |
| 346 | ANA_PORT_POL_CFG_POL_ORDER(POL_ORDER), |
| 347 | ANA_PORT_POL_CFG_PORT_POL_ENA | |
| 348 | ANA_PORT_POL_CFG_POL_ORDER_M, |
| 349 | - ANA_PORT_POL_CFG, port->chip_port); |
| 350 | + ANA_PORT_POL_CFG, port); |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | --- a/drivers/net/ethernet/mscc/ocelot_police.h |
| 355 | +++ b/drivers/net/ethernet/mscc/ocelot_police.h |
| 356 | @@ -14,9 +14,9 @@ struct ocelot_policer { |
| 357 | u32 burst; /* bytes */ |
| 358 | }; |
| 359 | |
| 360 | -int ocelot_port_policer_add(struct ocelot_port *port, |
| 361 | +int ocelot_port_policer_add(struct ocelot *ocelot, int port, |
| 362 | struct ocelot_policer *pol); |
| 363 | |
| 364 | -int ocelot_port_policer_del(struct ocelot_port *port); |
| 365 | +int ocelot_port_policer_del(struct ocelot *ocelot, int port); |
| 366 | |
| 367 | #endif /* _MSCC_OCELOT_POLICE_H_ */ |
| 368 | --- a/drivers/net/ethernet/mscc/ocelot_tc.c |
| 369 | +++ b/drivers/net/ethernet/mscc/ocelot_tc.c |
| 370 | @@ -58,7 +58,8 @@ static int ocelot_setup_tc_cls_matchall( |
| 371 | PSCHED_NS2TICKS(action->police.burst), |
| 372 | PSCHED_TICKS_PER_SEC); |
| 373 | |
| 374 | - err = ocelot_port_policer_add(port, &pol); |
| 375 | + err = ocelot_port_policer_add(port->ocelot, port->chip_port, |
| 376 | + &pol); |
| 377 | if (err) { |
| 378 | NL_SET_ERR_MSG_MOD(extack, "Could not add policer\n"); |
| 379 | return err; |
| 380 | @@ -71,7 +72,7 @@ static int ocelot_setup_tc_cls_matchall( |
| 381 | if (port->tc.police_id != f->cookie) |
| 382 | return -ENOENT; |
| 383 | |
| 384 | - err = ocelot_port_policer_del(port); |
| 385 | + err = ocelot_port_policer_del(port->ocelot, port->chip_port); |
| 386 | if (err) { |
| 387 | NL_SET_ERR_MSG_MOD(extack, |
| 388 | "Could not delete policer\n"); |