| @@ -1394,26 +1394,45 @@ static int devlink_nl_cmd_sb_occ_max_clear_doit(struct sk_buff *skb, · 1393 unmodified lines |
| 1394 | 1394 | |
| 1395 | 1395 | static int devlink_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, |
| 1396 | 1396 | enum devlink_command cmd, u32 portid, |
| 1397 | | − u32 seq, int flags, u16 mode) |
| 1397 | + u32 seq, int flags) |
| 1398 | 1398 | { |
| 1399 | + const struct devlink_ops *ops = devlink->ops; |
| 1399 | 1400 | void *hdr; |
| 1401 | + int err = 0; |
| 1402 | + u16 mode; |
| 1403 | + u8 inline_mode; |
| 1400 | 1404 | |
| 1401 | 1405 | hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); |
| 1402 | 1406 | if (!hdr) |
| 1403 | 1407 | return -EMSGSIZE; |
| 1404 | 1408 | |
| 1405 | | − if (devlink_nl_put_handle(msg, devlink)) |
| 1406 | | − goto nla_put_failure; |
| 1409 | + err = devlink_nl_put_handle(msg, devlink); |
| 1410 | + if (err) |
| 1411 | + goto out; |
| 1407 | 1412 | |
| 1408 | | − if (nla_put_u16(msg, DEVLINK_ATTR_ESWITCH_MODE, mode)) |
| 1409 | | − goto nla_put_failure; |
| 1413 | + err = ops->eswitch_mode_get(devlink, &mode); |
| 1414 | + if (err) |
| 1415 | + goto out; |
| 1416 | + err = nla_put_u16(msg, DEVLINK_ATTR_ESWITCH_MODE, mode); |
| 1417 | + if (err) |
| 1418 | + goto out; |
| 1419 | + |
| 1420 | + if (ops->eswitch_inline_mode_get) { |
| 1421 | + err = ops->eswitch_inline_mode_get(devlink, &inline_mode); |
| 1422 | + if (err) |
| 1423 | + goto out; |
| 1424 | + err = nla_put_u8(msg, DEVLINK_ATTR_ESWITCH_INLINE_MODE, |
| 1425 | + inline_mode); |
| 1426 | + if (err) |
| 1427 | + goto out; |
| 1428 | + } |
| 1410 | 1429 | |
| 1411 | 1430 | genlmsg_end(msg, hdr); |
| 1412 | 1431 | return 0; |
| 1413 | 1432 | |
| 1414 | | −nla_put_failure: |
| 1433 | +out: |
| 1415 | 1434 | genlmsg_cancel(msg, hdr); |
| 1416 | | − return -EMSGSIZE; |
| 1435 | + return err; |
| 1417 | 1436 | } |
| 1418 | 1437 | |
| 1419 | 1438 | static int devlink_nl_cmd_eswitch_mode_get_doit(struct sk_buff *skb, |
| @@ -1422,22 +1441,17 @@ static int devlink_nl_cmd_eswitch_mode_get_doit(struct sk_buff *skb, · 2 unmodified lines |
| 1422 | 1441 | struct devlink *devlink = info->user_ptr[0]; |
| 1423 | 1442 | const struct devlink_ops *ops = devlink->ops; |
| 1424 | 1443 | struct sk_buff *msg; |
| 1425 | | − u16 mode; |
| 1426 | 1444 | int err; |
| 1427 | 1445 | |
| 1428 | 1446 | if (!ops || !ops->eswitch_mode_get) |
| 1429 | 1447 | return -EOPNOTSUPP; |
| 1430 | 1448 | |
| 1431 | | − err = ops->eswitch_mode_get(devlink, &mode); |
| 1432 | | − if (err) |
| 1433 | | − return err; |
| 1434 | | − |
| 1435 | 1449 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 1436 | 1450 | if (!msg) |
| 1437 | 1451 | return -ENOMEM; |
| 1438 | 1452 | |
| 1439 | 1453 | err = devlink_eswitch_fill(msg, devlink, DEVLINK_CMD_ESWITCH_MODE_GET, |
| 1440 | | − info->snd_portid, info->snd_seq, 0, mode); |
| 1454 | + info->snd_portid, info->snd_seq, 0); |
| 1441 | 1455 | |
| 1442 | 1456 | if (err) { |
| 1443 | 1457 | nlmsg_free(msg); |
| @@ -1453,15 +1467,32 @@ static int devlink_nl_cmd_eswitch_mode_set_doit(struct sk_buff *skb, · 9 unmodified lines |
| 1453 | 1467 | struct devlink *devlink = info->user_ptr[0]; |
| 1454 | 1468 | const struct devlink_ops *ops = devlink->ops; |
| 1455 | 1469 | u16 mode; |
| 1470 | + u8 inline_mode; |
| 1471 | + int err = 0; |
| 1456 | 1472 | |
| 1457 | | − if (!info->attrs[DEVLINK_ATTR_ESWITCH_MODE]) |
| 1458 | | − return -EINVAL; |
| 1473 | + if (!ops) |
| 1474 | + return -EOPNOTSUPP; |
| 1459 | 1475 | |
| 1460 | | − mode = nla_get_u16(info->attrs[DEVLINK_ATTR_ESWITCH_MODE]); |
| 1476 | + if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE]) { |
| 1477 | + if (!ops->eswitch_mode_set) |
| 1478 | + return -EOPNOTSUPP; |
| 1479 | + mode = nla_get_u16(info->attrs[DEVLINK_ATTR_ESWITCH_MODE]); |
| 1480 | + err = ops->eswitch_mode_set(devlink, mode); |
| 1481 | + if (err) |
| 1482 | + return err; |
| 1483 | + } |
| 1461 | 1484 | |
| 1462 | | − if (ops && ops->eswitch_mode_set) |
| 1463 | | − return ops->eswitch_mode_set(devlink, mode); |
| 1464 | | − return -EOPNOTSUPP; |
| 1485 | + if (info->attrs[DEVLINK_ATTR_ESWITCH_INLINE_MODE]) { |
| 1486 | + if (!ops->eswitch_inline_mode_set) |
| 1487 | + return -EOPNOTSUPP; |
| 1488 | + inline_mode = nla_get_u8( |
| 1489 | + info->attrs[DEVLINK_ATTR_ESWITCH_INLINE_MODE]); |
| 1490 | + err = ops->eswitch_inline_mode_set(devlink, inline_mode); |
| 1491 | + if (err) |
| 1492 | + return err; |
| 1493 | + } |
| 1494 | + |
| 1495 | + return 0; |
| 1465 | 1496 | } |
| 1466 | 1497 | |
| 1467 | 1498 | static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { |
| @@ -1478,6 +1509,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { · 10 unmodified lines |
| 1478 | 1509 | [DEVLINK_ATTR_SB_THRESHOLD] = { .type = NLA_U32 }, |
| 1479 | 1510 | [DEVLINK_ATTR_SB_TC_INDEX] = { .type = NLA_U16 }, |
| 1480 | 1511 | [DEVLINK_ATTR_ESWITCH_MODE] = { .type = NLA_U16 }, |
| 1512 | + [DEVLINK_ATTR_ESWITCH_INLINE_MODE] = { .type = NLA_U8 }, |
| 1481 | 1513 | }; |
| 1482 | 1514 | |
| 1483 | 1515 | static const struct genl_ops devlink_nl_ops[] = { |