Commit 4f2bd6b3 authored by David S. Miller's avatar David S. Miller

Merge branch 'devlink-small-cleanups'

Jiri Pirko says:

====================
devlink: small cleanup around eswitch [sg]et

Contains small devlink cleanup around eswitch get/set commands.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0d2164af 4456f61c
...@@ -57,8 +57,14 @@ enum devlink_command { ...@@ -57,8 +57,14 @@ enum devlink_command {
DEVLINK_CMD_SB_OCC_SNAPSHOT, DEVLINK_CMD_SB_OCC_SNAPSHOT,
DEVLINK_CMD_SB_OCC_MAX_CLEAR, DEVLINK_CMD_SB_OCC_MAX_CLEAR,
DEVLINK_CMD_ESWITCH_MODE_GET, DEVLINK_CMD_ESWITCH_GET,
DEVLINK_CMD_ESWITCH_MODE_SET, #define DEVLINK_CMD_ESWITCH_MODE_GET /* obsolete, never use this! */ \
DEVLINK_CMD_ESWITCH_GET
DEVLINK_CMD_ESWITCH_SET,
#define DEVLINK_CMD_ESWITCH_MODE_SET /* obsolete, never use this! */ \
DEVLINK_CMD_ESWITCH_SET
/* add new commands above here */ /* add new commands above here */
__DEVLINK_CMD_MAX, __DEVLINK_CMD_MAX,
......
...@@ -1392,7 +1392,7 @@ static int devlink_nl_cmd_sb_occ_max_clear_doit(struct sk_buff *skb, ...@@ -1392,7 +1392,7 @@ static int devlink_nl_cmd_sb_occ_max_clear_doit(struct sk_buff *skb,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static int devlink_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink,
enum devlink_command cmd, u32 portid, enum devlink_command cmd, u32 portid,
u32 seq, int flags) u32 seq, int flags)
{ {
...@@ -1408,34 +1408,36 @@ static int devlink_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, ...@@ -1408,34 +1408,36 @@ static int devlink_eswitch_fill(struct sk_buff *msg, struct devlink *devlink,
err = devlink_nl_put_handle(msg, devlink); err = devlink_nl_put_handle(msg, devlink);
if (err) if (err)
goto out; goto nla_put_failure;
if (ops->eswitch_mode_get) {
err = ops->eswitch_mode_get(devlink, &mode); err = ops->eswitch_mode_get(devlink, &mode);
if (err) if (err)
goto out; goto nla_put_failure;
err = nla_put_u16(msg, DEVLINK_ATTR_ESWITCH_MODE, mode); err = nla_put_u16(msg, DEVLINK_ATTR_ESWITCH_MODE, mode);
if (err) if (err)
goto out; goto nla_put_failure;
}
if (ops->eswitch_inline_mode_get) { if (ops->eswitch_inline_mode_get) {
err = ops->eswitch_inline_mode_get(devlink, &inline_mode); err = ops->eswitch_inline_mode_get(devlink, &inline_mode);
if (err) if (err)
goto out; goto nla_put_failure;
err = nla_put_u8(msg, DEVLINK_ATTR_ESWITCH_INLINE_MODE, err = nla_put_u8(msg, DEVLINK_ATTR_ESWITCH_INLINE_MODE,
inline_mode); inline_mode);
if (err) if (err)
goto out; goto nla_put_failure;
} }
genlmsg_end(msg, hdr); genlmsg_end(msg, hdr);
return 0; return 0;
out: nla_put_failure:
genlmsg_cancel(msg, hdr); genlmsg_cancel(msg, hdr);
return err; return err;
} }
static int devlink_nl_cmd_eswitch_mode_get_doit(struct sk_buff *skb, static int devlink_nl_cmd_eswitch_get_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink *devlink = info->user_ptr[0]; struct devlink *devlink = info->user_ptr[0];
...@@ -1443,14 +1445,14 @@ static int devlink_nl_cmd_eswitch_mode_get_doit(struct sk_buff *skb, ...@@ -1443,14 +1445,14 @@ static int devlink_nl_cmd_eswitch_mode_get_doit(struct sk_buff *skb,
struct sk_buff *msg; struct sk_buff *msg;
int err; int err;
if (!ops || !ops->eswitch_mode_get) if (!ops)
return -EOPNOTSUPP; return -EOPNOTSUPP;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
err = devlink_eswitch_fill(msg, devlink, DEVLINK_CMD_ESWITCH_MODE_GET, err = devlink_nl_eswitch_fill(msg, devlink, DEVLINK_CMD_ESWITCH_GET,
info->snd_portid, info->snd_seq, 0); info->snd_portid, info->snd_seq, 0);
if (err) { if (err) {
...@@ -1461,7 +1463,7 @@ static int devlink_nl_cmd_eswitch_mode_get_doit(struct sk_buff *skb, ...@@ -1461,7 +1463,7 @@ static int devlink_nl_cmd_eswitch_mode_get_doit(struct sk_buff *skb,
return genlmsg_reply(msg, info); return genlmsg_reply(msg, info);
} }
static int devlink_nl_cmd_eswitch_mode_set_doit(struct sk_buff *skb, static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink *devlink = info->user_ptr[0]; struct devlink *devlink = info->user_ptr[0];
...@@ -1629,15 +1631,15 @@ static const struct genl_ops devlink_nl_ops[] = { ...@@ -1629,15 +1631,15 @@ static const struct genl_ops devlink_nl_ops[] = {
DEVLINK_NL_FLAG_LOCK_PORTS, DEVLINK_NL_FLAG_LOCK_PORTS,
}, },
{ {
.cmd = DEVLINK_CMD_ESWITCH_MODE_GET, .cmd = DEVLINK_CMD_ESWITCH_GET,
.doit = devlink_nl_cmd_eswitch_mode_get_doit, .doit = devlink_nl_cmd_eswitch_get_doit,
.policy = devlink_nl_policy, .policy = devlink_nl_policy,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
}, },
{ {
.cmd = DEVLINK_CMD_ESWITCH_MODE_SET, .cmd = DEVLINK_CMD_ESWITCH_SET,
.doit = devlink_nl_cmd_eswitch_mode_set_doit, .doit = devlink_nl_cmd_eswitch_set_doit,
.policy = devlink_nl_policy, .policy = devlink_nl_policy,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment