Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2519471ybb; Fri, 27 Mar 2020 07:08:55 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvHBFC3KKWcxE2oqwnjQUH2og103EAxAKj4iihGfRdrOqwxLGpkmripuGJcDekfJQjvMEVf X-Received: by 2002:a54:4482:: with SMTP id v2mr3989562oiv.114.1585318134994; Fri, 27 Mar 2020 07:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585318134; cv=none; d=google.com; s=arc-20160816; b=p0O1IdMe95MQ60uXfoQgFrZ2I/1Ob2kwvNWKl6Gg8qbA0wlFdZxrM84RaT3ABMg/L6 TPtl+OwUYXFSul47RDVkEw4IcX5GYS6eIWL8oENw7dYCZueUsFL8cVo8YBi2DZ0ek8Em FYemmTN/zAB5t9bzPT+xeEcY07LeEqU5c8ahYaXXSL2suT8zDrlLQFn6zBZ21Y1kwuT6 L/EKc0C3CI8HYYSc4zj1UNLgmKyynk/yeVbPPYNl7XkqVJDzvZ+xDx1fgYQcdFtf/3xj Yn9tKUGlPxIb92EYMEauosW7LyFDJkRkg10w7HfPBz/UCzb60IF5hkjdjAEyIP6+Qj/K K9zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=8WSf5HLiLLVYPsUVhlgPVJREAj5u7QPfcOqOZvv7m80=; b=dR5mf3ctfO0mfYlO5J6t/Lwfm75URL59fDXXAPRGLqAF/pnVJT9ukvh5jitwq90JV0 8IxeiExVl6flkAU6gLH6Rfx2AntPUjGVliZys+F1O97KWCOUXauc34tS8kdt+JLuqFHY 9kcHJOJyc0o9wh9gznOtfEeWTyGIoIxPc3q+0eE8MAJCYGtVPORjGJYPGniGcL5J39hX WsrRmtCiZ5sFEG1aK1wumw+M4t4ROYqMhFuM6np0zPqsBXB84gRZ5Ne30YI8OGXdmfM6 bR+pVLCQit593y/2JdWlJXOx2oCWiMjXxQdIQWRQNM1N1JkD7Qs8A/fP8SfSTa/TKpaB oeYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h59si2360933oth.233.2020.03.27.07.08.41; Fri, 27 Mar 2020 07:08:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727806AbgC0OHv (ORCPT + 99 others); Fri, 27 Mar 2020 10:07:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:40840 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbgC0OHu (ORCPT ); Fri, 27 Mar 2020 10:07:50 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CA947ADCD; Fri, 27 Mar 2020 14:07:47 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 7871CE009C; Fri, 27 Mar 2020 15:07:47 +0100 (CET) Message-Id: <97db666d087e47eff7d1a65baf2d16500595b0f0.1585316159.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v2 06/12] ethtool: set pause parameters with PAUSE_SET request To: David Miller , Jakub Kicinski , netdev@vger.kernel.org Cc: Jiri Pirko , Andrew Lunn , Florian Fainelli , John Linville , Johannes Berg , Richard Cochran , linux-kernel@vger.kernel.org Date: Fri, 27 Mar 2020 15:07:47 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement PAUSE_SET netlink request to set pause parameters of a network device. Thease are traditionally set with ETHTOOL_SPAUSEPARAM ioctl request. Signed-off-by: Michal Kubecek --- Documentation/networking/ethtool-netlink.rst | 3 +- include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/netlink.c | 5 ++ net/ethtool/netlink.h | 1 + net/ethtool/pause.c | 61 ++++++++++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 43c7baf36b32..dc7b3fe47f37 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -200,6 +200,7 @@ Userspace to kernel: ``ETHTOOL_MSG_COALESCE_GET`` get coalescing parameters ``ETHTOOL_MSG_COALESCE_SET`` set coalescing parameters ``ETHTOOL_MSG_PAUSE_GET`` get pause parameters + ``ETHTOOL_MSG_PAUSE_SET`` set pause parameters ===================================== ================================ Kernel to userspace: @@ -899,7 +900,7 @@ have their netlink replacement yet. ``ETHTOOL_GRINGPARAM`` ``ETHTOOL_MSG_RINGS_GET`` ``ETHTOOL_SRINGPARAM`` ``ETHTOOL_MSG_RINGS_SET`` ``ETHTOOL_GPAUSEPARAM`` ``ETHTOOL_MSG_PAUSE_GET`` - ``ETHTOOL_SPAUSEPARAM`` n/a + ``ETHTOOL_SPAUSEPARAM`` ``ETHTOOL_MSG_PAUSE_SET`` ``ETHTOOL_GRXCSUM`` ``ETHTOOL_MSG_FEATURES_GET`` ``ETHTOOL_SRXCSUM`` ``ETHTOOL_MSG_FEATURES_SET`` ``ETHTOOL_GTXCSUM`` ``ETHTOOL_MSG_FEATURES_GET`` diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 1c8d1228f63f..a9a35c7b81d4 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -35,6 +35,7 @@ enum { ETHTOOL_MSG_COALESCE_GET, ETHTOOL_MSG_COALESCE_SET, ETHTOOL_MSG_PAUSE_GET, + ETHTOOL_MSG_PAUSE_SET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index ca1695de8c9d..1ca30578e642 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -809,6 +809,11 @@ static const struct genl_ops ethtool_genl_ops[] = { .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, }, + { + .cmd = ETHTOOL_MSG_PAUSE_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_set_pause, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index e14ac089bfb1..49fee19bc6aa 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -353,5 +353,6 @@ int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info); int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info); int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info); int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info); +int ethnl_set_pause(struct sk_buff *skb, struct genl_info *info); #endif /* _NET_ETHTOOL_NETLINK_H */ diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c index 9feafeb7bb1c..c307b91fdfba 100644 --- a/net/ethtool/pause.c +++ b/net/ethtool/pause.c @@ -79,3 +79,64 @@ const struct ethnl_request_ops ethnl_pause_request_ops = { .reply_size = pause_reply_size, .fill_reply = pause_fill_reply, }; + +/* PAUSE_SET */ + +static const struct nla_policy +pause_set_policy[ETHTOOL_A_PAUSE_MAX + 1] = { + [ETHTOOL_A_PAUSE_UNSPEC] = { .type = NLA_REJECT }, + [ETHTOOL_A_PAUSE_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_PAUSE_AUTONEG] = { .type = NLA_U8 }, + [ETHTOOL_A_PAUSE_RX] = { .type = NLA_U8 }, + [ETHTOOL_A_PAUSE_TX] = { .type = NLA_U8 }, +}; + +int ethnl_set_pause(struct sk_buff *skb, struct genl_info *info) +{ + struct nlattr *tb[ETHTOOL_A_PAUSE_MAX + 1]; + struct ethtool_pauseparam params = {}; + struct ethnl_req_info req_info = {}; + const struct ethtool_ops *ops; + struct net_device *dev; + bool mod = false; + int ret; + + ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, ETHTOOL_A_PAUSE_MAX, + pause_set_policy, info->extack); + if (ret < 0) + return ret; + ret = ethnl_parse_header_dev_get(&req_info, + tb[ETHTOOL_A_PAUSE_HEADER], + genl_info_net(info), info->extack, + true); + if (ret < 0) + return ret; + dev = req_info.dev; + ops = dev->ethtool_ops; + ret = -EOPNOTSUPP; + if (!ops->get_pauseparam || !ops->set_pauseparam) + goto out_dev; + + rtnl_lock(); + ret = ethnl_ops_begin(dev); + if (ret < 0) + goto out_rtnl; + ops->get_pauseparam(dev, ¶ms); + + ethnl_update_bool32(¶ms.autoneg, tb[ETHTOOL_A_PAUSE_AUTONEG], &mod); + ethnl_update_bool32(¶ms.rx_pause, tb[ETHTOOL_A_PAUSE_RX], &mod); + ethnl_update_bool32(¶ms.tx_pause, tb[ETHTOOL_A_PAUSE_TX], &mod); + ret = 0; + if (!mod) + goto out_ops; + + ret = dev->ethtool_ops->set_pauseparam(dev, ¶ms); + +out_ops: + ethnl_ops_complete(dev); +out_rtnl: + rtnl_unlock(); +out_dev: + dev_put(dev); + return ret; +} -- 2.25.1