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

Merge branch 'devlink-port_del-new-cleanup'

Jiri Pirko says:

====================
devlink: small port_new/del() cleanup

This patchset cleans up couple of leftovers after recent devlink locking
changes. Previously, both port_new/dev() commands were called without
holding instance lock. Currently all devlink commands are called with
instance lock held.

The first patch just removes redundant port notification.
The second one removes couple of outdated comments.
The last patch changes port_dev() to have devlink_port pointer as an arg
instead of port_index, which makes it similar to the rest of port
related ops.
====================

Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

+16 -72
+6 -8
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
··· 282 282 283 283 static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table, 284 284 const struct devlink_port_new_attrs *new_attr, 285 - struct netlink_ext_ack *extack, 286 - unsigned int *new_port_index) 285 + struct netlink_ext_ack *extack) 287 286 { 288 287 struct mlx5_eswitch *esw = dev->priv.eswitch; 289 288 struct mlx5_sf *sf; ··· 296 297 new_attr->controller, new_attr->sfnum); 297 298 if (err) 298 299 goto esw_err; 299 - *new_port_index = sf->port_index; 300 300 trace_mlx5_sf_add(dev, sf->port_index, sf->controller, sf->hw_fn_id, new_attr->sfnum); 301 301 return 0; 302 302 ··· 336 338 337 339 int mlx5_devlink_sf_port_new(struct devlink *devlink, 338 340 const struct devlink_port_new_attrs *new_attr, 339 - struct netlink_ext_ack *extack, 340 - unsigned int *new_port_index) 341 + struct netlink_ext_ack *extack) 341 342 { 342 343 struct mlx5_core_dev *dev = devlink_priv(devlink); 343 344 struct mlx5_sf_table *table; ··· 352 355 "Port add is only supported in eswitch switchdev mode or SF ports are disabled."); 353 356 return -EOPNOTSUPP; 354 357 } 355 - err = mlx5_sf_add(dev, table, new_attr, extack, new_port_index); 358 + err = mlx5_sf_add(dev, table, new_attr, extack); 356 359 mlx5_sf_table_put(table); 357 360 return err; 358 361 } ··· 376 379 } 377 380 } 378 381 379 - int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index, 382 + int mlx5_devlink_sf_port_del(struct devlink *devlink, 383 + struct devlink_port *dl_port, 380 384 struct netlink_ext_ack *extack) 381 385 { 382 386 struct mlx5_core_dev *dev = devlink_priv(devlink); ··· 392 394 "Port del is only supported in eswitch switchdev mode or SF ports are disabled."); 393 395 return -EOPNOTSUPP; 394 396 } 395 - sf = mlx5_sf_lookup_by_index(table, port_index); 397 + sf = mlx5_sf_lookup_by_index(table, dl_port->index); 396 398 if (!sf) { 397 399 err = -ENODEV; 398 400 goto sf_err;
+3 -3
drivers/net/ethernet/mellanox/mlx5/core/sf/sf.h
··· 20 20 21 21 int mlx5_devlink_sf_port_new(struct devlink *devlink, 22 22 const struct devlink_port_new_attrs *add_attr, 23 - struct netlink_ext_ack *extack, 24 - unsigned int *new_port_index); 25 - int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index, 23 + struct netlink_ext_ack *extack); 24 + int mlx5_devlink_sf_port_del(struct devlink *devlink, 25 + struct devlink_port *dl_port, 26 26 struct netlink_ext_ack *extack); 27 27 int mlx5_devlink_sf_port_fn_state_get(struct devlink_port *dl_port, 28 28 enum devlink_port_fn_state *state,
+3 -9
include/net/devlink.h
··· 1500 1500 * @devlink: Devlink instance 1501 1501 * @attrs: attributes of the new port 1502 1502 * @extack: extack for reporting error messages 1503 - * @new_port_index: index of the new port 1504 1503 * 1505 1504 * Devlink core will call this device driver function upon user request 1506 1505 * to create a new port function of a specified flavor and optional 1507 1506 * attributes 1508 1507 * 1509 1508 * Notes: 1510 - * - Called without devlink instance lock being held. Drivers must 1511 - * implement own means of synchronization 1512 1509 * - On success, drivers must register a port with devlink core 1513 1510 * 1514 1511 * Return: 0 on success, negative value otherwise. 1515 1512 */ 1516 1513 int (*port_new)(struct devlink *devlink, 1517 1514 const struct devlink_port_new_attrs *attrs, 1518 - struct netlink_ext_ack *extack, 1519 - unsigned int *new_port_index); 1515 + struct netlink_ext_ack *extack); 1520 1516 /** 1521 1517 * port_del() - Delete a port function 1522 1518 * @devlink: Devlink instance 1523 - * @port_index: port function index to delete 1519 + * @port: The devlink port 1524 1520 * @extack: extack for reporting error messages 1525 1521 * 1526 1522 * Devlink core will call this device driver function upon user request 1527 1523 * to delete a previously created port function 1528 1524 * 1529 1525 * Notes: 1530 - * - Called without devlink instance lock being held. Drivers must 1531 - * implement own means of synchronization 1532 1526 * - On success, drivers must unregister the corresponding devlink 1533 1527 * port 1534 1528 * 1535 1529 * Return: 0 on success, negative value otherwise. 1536 1530 */ 1537 - int (*port_del)(struct devlink *devlink, unsigned int port_index, 1531 + int (*port_del)(struct devlink *devlink, struct devlink_port *port, 1538 1532 struct netlink_ext_ack *extack); 1539 1533 /** 1540 1534 * port_fn_state_get() - Get the state of a port function
+4 -52
net/devlink/leftover.c
··· 1354 1354 return devlink->ops->port_unsplit(devlink, devlink_port, info->extack); 1355 1355 } 1356 1356 1357 - static int devlink_port_new_notify(struct devlink *devlink, 1358 - unsigned int port_index, 1359 - struct genl_info *info) 1360 - { 1361 - struct devlink_port *devlink_port; 1362 - struct sk_buff *msg; 1363 - int err; 1364 - 1365 - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 1366 - if (!msg) 1367 - return -ENOMEM; 1368 - 1369 - lockdep_assert_held(&devlink->lock); 1370 - devlink_port = devlink_port_get_by_index(devlink, port_index); 1371 - if (!devlink_port) { 1372 - err = -ENODEV; 1373 - goto out; 1374 - } 1375 - 1376 - err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW, 1377 - info->snd_portid, info->snd_seq, 0, NULL); 1378 - if (err) 1379 - goto out; 1380 - 1381 - return genlmsg_reply(msg, info); 1382 - 1383 - out: 1384 - nlmsg_free(msg); 1385 - return err; 1386 - } 1387 - 1388 1357 static int devlink_nl_cmd_port_new_doit(struct sk_buff *skb, 1389 1358 struct genl_info *info) 1390 1359 { 1391 1360 struct netlink_ext_ack *extack = info->extack; 1392 1361 struct devlink_port_new_attrs new_attrs = {}; 1393 1362 struct devlink *devlink = info->user_ptr[0]; 1394 - unsigned int new_port_index; 1395 - int err; 1396 1363 1397 1364 if (!devlink->ops->port_new || !devlink->ops->port_del) 1398 1365 return -EOPNOTSUPP; ··· 1390 1423 new_attrs.sfnum_valid = true; 1391 1424 } 1392 1425 1393 - err = devlink->ops->port_new(devlink, &new_attrs, extack, 1394 - &new_port_index); 1395 - if (err) 1396 - return err; 1397 - 1398 - err = devlink_port_new_notify(devlink, new_port_index, info); 1399 - if (err && err != -ENODEV) { 1400 - /* Fail to send the response; destroy newly created port. */ 1401 - devlink->ops->port_del(devlink, new_port_index, extack); 1402 - } 1403 - return err; 1426 + return devlink->ops->port_new(devlink, &new_attrs, extack); 1404 1427 } 1405 1428 1406 1429 static int devlink_nl_cmd_port_del_doit(struct sk_buff *skb, 1407 1430 struct genl_info *info) 1408 1431 { 1432 + struct devlink_port *devlink_port = info->user_ptr[1]; 1409 1433 struct netlink_ext_ack *extack = info->extack; 1410 1434 struct devlink *devlink = info->user_ptr[0]; 1411 - unsigned int port_index; 1412 1435 1413 1436 if (!devlink->ops->port_del) 1414 1437 return -EOPNOTSUPP; 1415 1438 1416 - if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PORT_INDEX)) { 1417 - NL_SET_ERR_MSG(extack, "Port index is not specified"); 1418 - return -EINVAL; 1419 - } 1420 - port_index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]); 1421 - 1422 - return devlink->ops->port_del(devlink, port_index, extack); 1439 + return devlink->ops->port_del(devlink, devlink_port, extack); 1423 1440 } 1424 1441 1425 1442 static int ··· 6335 6384 .cmd = DEVLINK_CMD_PORT_DEL, 6336 6385 .doit = devlink_nl_cmd_port_del_doit, 6337 6386 .flags = GENL_ADMIN_PERM, 6387 + .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, 6338 6388 }, 6339 6389 { 6340 6390 .cmd = DEVLINK_CMD_LINECARD_GET,