Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mlxsw: spectrum: Move flow offload binding into spectrum_flow.c

Move the code taking case of setup of flow offload into spectrum_flow.c
Do small renaming of callbacks on the way.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jiri Pirko and committed by
David S. Miller
19f06771 3c650136

+181 -191
-173
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
··· 1350 1350 return 0; 1351 1351 } 1352 1352 1353 - static int 1354 - mlxsw_sp_setup_tc_cls_matchall(struct mlxsw_sp_flow_block *flow_block, 1355 - struct tc_cls_matchall_offload *f) 1356 - { 1357 - switch (f->command) { 1358 - case TC_CLSMATCHALL_REPLACE: 1359 - return mlxsw_sp_mall_replace(flow_block, f); 1360 - case TC_CLSMATCHALL_DESTROY: 1361 - mlxsw_sp_mall_destroy(flow_block, f); 1362 - return 0; 1363 - default: 1364 - return -EOPNOTSUPP; 1365 - } 1366 - } 1367 - 1368 - static int 1369 - mlxsw_sp_setup_tc_cls_flower(struct mlxsw_sp_flow_block *flow_block, 1370 - struct flow_cls_offload *f) 1371 - { 1372 - struct mlxsw_sp *mlxsw_sp = mlxsw_sp_flow_block_mlxsw_sp(flow_block); 1373 - 1374 - switch (f->command) { 1375 - case FLOW_CLS_REPLACE: 1376 - return mlxsw_sp_flower_replace(mlxsw_sp, flow_block, f); 1377 - case FLOW_CLS_DESTROY: 1378 - mlxsw_sp_flower_destroy(mlxsw_sp, flow_block, f); 1379 - return 0; 1380 - case FLOW_CLS_STATS: 1381 - return mlxsw_sp_flower_stats(mlxsw_sp, flow_block, f); 1382 - case FLOW_CLS_TMPLT_CREATE: 1383 - return mlxsw_sp_flower_tmplt_create(mlxsw_sp, flow_block, f); 1384 - case FLOW_CLS_TMPLT_DESTROY: 1385 - mlxsw_sp_flower_tmplt_destroy(mlxsw_sp, flow_block, f); 1386 - return 0; 1387 - default: 1388 - return -EOPNOTSUPP; 1389 - } 1390 - } 1391 - 1392 - static int mlxsw_sp_setup_tc_block_cb(enum tc_setup_type type, 1393 - void *type_data, void *cb_priv) 1394 - { 1395 - struct mlxsw_sp_flow_block *flow_block = cb_priv; 1396 - 1397 - if (mlxsw_sp_flow_block_disabled(flow_block)) 1398 - return -EOPNOTSUPP; 1399 - 1400 - switch (type) { 1401 - case TC_SETUP_CLSMATCHALL: 1402 - return mlxsw_sp_setup_tc_cls_matchall(flow_block, type_data); 1403 - case TC_SETUP_CLSFLOWER: 1404 - return mlxsw_sp_setup_tc_cls_flower(flow_block, type_data); 1405 - default: 1406 - return -EOPNOTSUPP; 1407 - } 1408 - } 1409 - 1410 - static void mlxsw_sp_tc_block_release(void *cb_priv) 1411 - { 1412 - struct mlxsw_sp_flow_block *flow_block = cb_priv; 1413 - 1414 - mlxsw_sp_flow_block_destroy(flow_block); 1415 - } 1416 - 1417 - static LIST_HEAD(mlxsw_sp_block_cb_list); 1418 - 1419 - static int mlxsw_sp_setup_tc_block_bind(struct mlxsw_sp_port *mlxsw_sp_port, 1420 - struct flow_block_offload *f, 1421 - bool ingress) 1422 - { 1423 - struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 1424 - struct mlxsw_sp_flow_block *flow_block; 1425 - struct flow_block_cb *block_cb; 1426 - bool register_block = false; 1427 - int err; 1428 - 1429 - block_cb = flow_block_cb_lookup(f->block, mlxsw_sp_setup_tc_block_cb, 1430 - mlxsw_sp); 1431 - if (!block_cb) { 1432 - flow_block = mlxsw_sp_flow_block_create(mlxsw_sp, f->net); 1433 - if (!flow_block) 1434 - return -ENOMEM; 1435 - block_cb = flow_block_cb_alloc(mlxsw_sp_setup_tc_block_cb, 1436 - mlxsw_sp, flow_block, 1437 - mlxsw_sp_tc_block_release); 1438 - if (IS_ERR(block_cb)) { 1439 - mlxsw_sp_flow_block_destroy(flow_block); 1440 - err = PTR_ERR(block_cb); 1441 - goto err_cb_register; 1442 - } 1443 - register_block = true; 1444 - } else { 1445 - flow_block = flow_block_cb_priv(block_cb); 1446 - } 1447 - flow_block_cb_incref(block_cb); 1448 - err = mlxsw_sp_flow_block_bind(mlxsw_sp, flow_block, 1449 - mlxsw_sp_port, ingress, f->extack); 1450 - if (err) 1451 - goto err_block_bind; 1452 - 1453 - if (ingress) 1454 - mlxsw_sp_port->ing_flow_block = flow_block; 1455 - else 1456 - mlxsw_sp_port->eg_flow_block = flow_block; 1457 - 1458 - if (register_block) { 1459 - flow_block_cb_add(block_cb, f); 1460 - list_add_tail(&block_cb->driver_list, &mlxsw_sp_block_cb_list); 1461 - } 1462 - 1463 - return 0; 1464 - 1465 - err_block_bind: 1466 - if (!flow_block_cb_decref(block_cb)) 1467 - flow_block_cb_free(block_cb); 1468 - err_cb_register: 1469 - return err; 1470 - } 1471 - 1472 - static void mlxsw_sp_setup_tc_block_unbind(struct mlxsw_sp_port *mlxsw_sp_port, 1473 - struct flow_block_offload *f, 1474 - bool ingress) 1475 - { 1476 - struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 1477 - struct mlxsw_sp_flow_block *flow_block; 1478 - struct flow_block_cb *block_cb; 1479 - int err; 1480 - 1481 - block_cb = flow_block_cb_lookup(f->block, mlxsw_sp_setup_tc_block_cb, 1482 - mlxsw_sp); 1483 - if (!block_cb) 1484 - return; 1485 - 1486 - if (ingress) 1487 - mlxsw_sp_port->ing_flow_block = NULL; 1488 - else 1489 - mlxsw_sp_port->eg_flow_block = NULL; 1490 - 1491 - flow_block = flow_block_cb_priv(block_cb); 1492 - err = mlxsw_sp_flow_block_unbind(mlxsw_sp, flow_block, 1493 - mlxsw_sp_port, ingress); 1494 - if (!err && !flow_block_cb_decref(block_cb)) { 1495 - flow_block_cb_remove(block_cb, f); 1496 - list_del(&block_cb->driver_list); 1497 - } 1498 - } 1499 - 1500 - static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port, 1501 - struct flow_block_offload *f) 1502 - { 1503 - bool ingress; 1504 - 1505 - if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS) 1506 - ingress = true; 1507 - else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS) 1508 - ingress = false; 1509 - else 1510 - return -EOPNOTSUPP; 1511 - 1512 - f->driver_block_list = &mlxsw_sp_block_cb_list; 1513 - 1514 - switch (f->command) { 1515 - case FLOW_BLOCK_BIND: 1516 - return mlxsw_sp_setup_tc_block_bind(mlxsw_sp_port, f, ingress); 1517 - case FLOW_BLOCK_UNBIND: 1518 - mlxsw_sp_setup_tc_block_unbind(mlxsw_sp_port, f, ingress); 1519 - return 0; 1520 - default: 1521 - return -EOPNOTSUPP; 1522 - } 1523 - } 1524 - 1525 1353 static int mlxsw_sp_setup_tc(struct net_device *dev, enum tc_setup_type type, 1526 1354 void *type_data) 1527 1355 { ··· 1372 1544 return -EOPNOTSUPP; 1373 1545 } 1374 1546 } 1375 - 1376 1547 1377 1548 static int mlxsw_sp_feature_hw_tc(struct net_device *dev, bool enable) 1378 1549 {
+2 -9
drivers/net/ethernet/mellanox/mlxsw/spectrum.h
··· 708 708 struct mlxsw_sp_flow_block *mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp, 709 709 struct net *net); 710 710 void mlxsw_sp_flow_block_destroy(struct mlxsw_sp_flow_block *block); 711 - int mlxsw_sp_flow_block_bind(struct mlxsw_sp *mlxsw_sp, 712 - struct mlxsw_sp_flow_block *block, 713 - struct mlxsw_sp_port *mlxsw_sp_port, 714 - bool ingress, 715 - struct netlink_ext_ack *extack); 716 - int mlxsw_sp_flow_block_unbind(struct mlxsw_sp *mlxsw_sp, 717 - struct mlxsw_sp_flow_block *block, 718 - struct mlxsw_sp_port *mlxsw_sp_port, 719 - bool ingress); 711 + int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port, 712 + struct flow_block_offload *f); 720 713 721 714 /* spectrum_acl.c */ 722 715 struct mlxsw_sp_acl_ruleset;
+179 -9
drivers/net/ethernet/mellanox/mlxsw/spectrum_flow.c
··· 49 49 return block->ruleset_zero; 50 50 } 51 51 52 - int mlxsw_sp_flow_block_bind(struct mlxsw_sp *mlxsw_sp, 53 - struct mlxsw_sp_flow_block *block, 54 - struct mlxsw_sp_port *mlxsw_sp_port, 55 - bool ingress, 56 - struct netlink_ext_ack *extack) 52 + static int mlxsw_sp_flow_block_bind(struct mlxsw_sp *mlxsw_sp, 53 + struct mlxsw_sp_flow_block *block, 54 + struct mlxsw_sp_port *mlxsw_sp_port, 55 + bool ingress, 56 + struct netlink_ext_ack *extack) 57 57 { 58 58 struct mlxsw_sp_flow_block_binding *binding; 59 59 int err; ··· 104 104 return err; 105 105 } 106 106 107 - int mlxsw_sp_flow_block_unbind(struct mlxsw_sp *mlxsw_sp, 108 - struct mlxsw_sp_flow_block *block, 109 - struct mlxsw_sp_port *mlxsw_sp_port, 110 - bool ingress) 107 + static int mlxsw_sp_flow_block_unbind(struct mlxsw_sp *mlxsw_sp, 108 + struct mlxsw_sp_flow_block *block, 109 + struct mlxsw_sp_port *mlxsw_sp_port, 110 + bool ingress) 111 111 { 112 112 struct mlxsw_sp_flow_block_binding *binding; 113 113 ··· 130 130 mlxsw_sp_mall_port_unbind(block, mlxsw_sp_port); 131 131 132 132 return 0; 133 + } 134 + 135 + static int mlxsw_sp_flow_block_mall_cb(struct mlxsw_sp_flow_block *flow_block, 136 + struct tc_cls_matchall_offload *f) 137 + { 138 + switch (f->command) { 139 + case TC_CLSMATCHALL_REPLACE: 140 + return mlxsw_sp_mall_replace(flow_block, f); 141 + case TC_CLSMATCHALL_DESTROY: 142 + mlxsw_sp_mall_destroy(flow_block, f); 143 + return 0; 144 + default: 145 + return -EOPNOTSUPP; 146 + } 147 + } 148 + 149 + static int mlxsw_sp_flow_block_flower_cb(struct mlxsw_sp_flow_block *flow_block, 150 + struct flow_cls_offload *f) 151 + { 152 + struct mlxsw_sp *mlxsw_sp = mlxsw_sp_flow_block_mlxsw_sp(flow_block); 153 + 154 + switch (f->command) { 155 + case FLOW_CLS_REPLACE: 156 + return mlxsw_sp_flower_replace(mlxsw_sp, flow_block, f); 157 + case FLOW_CLS_DESTROY: 158 + mlxsw_sp_flower_destroy(mlxsw_sp, flow_block, f); 159 + return 0; 160 + case FLOW_CLS_STATS: 161 + return mlxsw_sp_flower_stats(mlxsw_sp, flow_block, f); 162 + case FLOW_CLS_TMPLT_CREATE: 163 + return mlxsw_sp_flower_tmplt_create(mlxsw_sp, flow_block, f); 164 + case FLOW_CLS_TMPLT_DESTROY: 165 + mlxsw_sp_flower_tmplt_destroy(mlxsw_sp, flow_block, f); 166 + return 0; 167 + default: 168 + return -EOPNOTSUPP; 169 + } 170 + } 171 + 172 + static int mlxsw_sp_flow_block_cb(enum tc_setup_type type, 173 + void *type_data, void *cb_priv) 174 + { 175 + struct mlxsw_sp_flow_block *flow_block = cb_priv; 176 + 177 + if (mlxsw_sp_flow_block_disabled(flow_block)) 178 + return -EOPNOTSUPP; 179 + 180 + switch (type) { 181 + case TC_SETUP_CLSMATCHALL: 182 + return mlxsw_sp_flow_block_mall_cb(flow_block, type_data); 183 + case TC_SETUP_CLSFLOWER: 184 + return mlxsw_sp_flow_block_flower_cb(flow_block, type_data); 185 + default: 186 + return -EOPNOTSUPP; 187 + } 188 + } 189 + 190 + static void mlxsw_sp_tc_block_release(void *cb_priv) 191 + { 192 + struct mlxsw_sp_flow_block *flow_block = cb_priv; 193 + 194 + mlxsw_sp_flow_block_destroy(flow_block); 195 + } 196 + 197 + static LIST_HEAD(mlxsw_sp_block_cb_list); 198 + 199 + static int mlxsw_sp_setup_tc_block_bind(struct mlxsw_sp_port *mlxsw_sp_port, 200 + struct flow_block_offload *f, 201 + bool ingress) 202 + { 203 + struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 204 + struct mlxsw_sp_flow_block *flow_block; 205 + struct flow_block_cb *block_cb; 206 + bool register_block = false; 207 + int err; 208 + 209 + block_cb = flow_block_cb_lookup(f->block, mlxsw_sp_flow_block_cb, 210 + mlxsw_sp); 211 + if (!block_cb) { 212 + flow_block = mlxsw_sp_flow_block_create(mlxsw_sp, f->net); 213 + if (!flow_block) 214 + return -ENOMEM; 215 + block_cb = flow_block_cb_alloc(mlxsw_sp_flow_block_cb, 216 + mlxsw_sp, flow_block, 217 + mlxsw_sp_tc_block_release); 218 + if (IS_ERR(block_cb)) { 219 + mlxsw_sp_flow_block_destroy(flow_block); 220 + err = PTR_ERR(block_cb); 221 + goto err_cb_register; 222 + } 223 + register_block = true; 224 + } else { 225 + flow_block = flow_block_cb_priv(block_cb); 226 + } 227 + flow_block_cb_incref(block_cb); 228 + err = mlxsw_sp_flow_block_bind(mlxsw_sp, flow_block, 229 + mlxsw_sp_port, ingress, f->extack); 230 + if (err) 231 + goto err_block_bind; 232 + 233 + if (ingress) 234 + mlxsw_sp_port->ing_flow_block = flow_block; 235 + else 236 + mlxsw_sp_port->eg_flow_block = flow_block; 237 + 238 + if (register_block) { 239 + flow_block_cb_add(block_cb, f); 240 + list_add_tail(&block_cb->driver_list, &mlxsw_sp_block_cb_list); 241 + } 242 + 243 + return 0; 244 + 245 + err_block_bind: 246 + if (!flow_block_cb_decref(block_cb)) 247 + flow_block_cb_free(block_cb); 248 + err_cb_register: 249 + return err; 250 + } 251 + 252 + static void mlxsw_sp_setup_tc_block_unbind(struct mlxsw_sp_port *mlxsw_sp_port, 253 + struct flow_block_offload *f, 254 + bool ingress) 255 + { 256 + struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 257 + struct mlxsw_sp_flow_block *flow_block; 258 + struct flow_block_cb *block_cb; 259 + int err; 260 + 261 + block_cb = flow_block_cb_lookup(f->block, mlxsw_sp_flow_block_cb, 262 + mlxsw_sp); 263 + if (!block_cb) 264 + return; 265 + 266 + if (ingress) 267 + mlxsw_sp_port->ing_flow_block = NULL; 268 + else 269 + mlxsw_sp_port->eg_flow_block = NULL; 270 + 271 + flow_block = flow_block_cb_priv(block_cb); 272 + err = mlxsw_sp_flow_block_unbind(mlxsw_sp, flow_block, 273 + mlxsw_sp_port, ingress); 274 + if (!err && !flow_block_cb_decref(block_cb)) { 275 + flow_block_cb_remove(block_cb, f); 276 + list_del(&block_cb->driver_list); 277 + } 278 + } 279 + 280 + int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port, 281 + struct flow_block_offload *f) 282 + { 283 + bool ingress; 284 + 285 + if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS) 286 + ingress = true; 287 + else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS) 288 + ingress = false; 289 + else 290 + return -EOPNOTSUPP; 291 + 292 + f->driver_block_list = &mlxsw_sp_block_cb_list; 293 + 294 + switch (f->command) { 295 + case FLOW_BLOCK_BIND: 296 + return mlxsw_sp_setup_tc_block_bind(mlxsw_sp_port, f, ingress); 297 + case FLOW_BLOCK_UNBIND: 298 + mlxsw_sp_setup_tc_block_unbind(mlxsw_sp_port, f, ingress); 299 + return 0; 300 + default: 301 + return -EOPNOTSUPP; 302 + } 133 303 }