Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp898717ybh; Thu, 12 Mar 2020 13:09:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vugy6wa2CqS9hAFOGdtTdO88U8SI5SqaP20wFKqua+erp0ZIUFj7h39WIz0nTmjoQaCUF1D X-Received: by 2002:aca:d645:: with SMTP id n66mr4026405oig.66.1584043784086; Thu, 12 Mar 2020 13:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584043784; cv=none; d=google.com; s=arc-20160816; b=XGCA+8iguDt3SzoKMsE9lR78NiOxEJL1q9+r9xxdtJIWP7tPx3Dwl8KpYfflIjbIjq CYM0CIzdHBlEmcz33AR5vCk20uEXzxL9PfRfhhGOTZjSNAuoL8PfRpolbT2fG33H7rzE kfeilGctpx5w2w5co0Ll6WsEtGhhfePNj+5L/vGsX7c2wGcm69O8PKCr5Y5tHRTfkzIi 5YSvz4LA4pAqzk+jGzatqlQ3QVK7dMz4yOgKOjUK6dQcvo52oRq4XFvl+btJwhoZ23xa ZpHHJFZOzF7DFzUtkwQMNNOo1aaoZHnbkLY53iQAyPWUo7VtY9IZEeYUgQb3hgXqZGzq voAw== 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=yDGCj0Y+tIc0S0O5mNSqSZ//VL/RQx8p7KKqdw7mUw4=; b=dRvrhQVcMEofMnBy2HIZqclP4GeApVioOGsYb55Uvim6XpGWQY36Sm03PQigfyQ9RK yijAAIZTi1+m6CSs4Jsn/F2B8e3G5BaZkbwLKJeG++re2lpEtDkH5D5lf6ZUKNL+nyeE ZA7Bd7Fb37vISSJ7Zc7SyyWSaZjlbvQoe6kMjoWw7jGnx3u/QzKta6DIWkVrausf4Wjx p2i58xhCuKww2soC1yADhqd65it1y6UDkRb6P4E/ym2S8Wa5sz8rzP5549OSOGEbB6B5 9pvTf9KZxOzLwQpqe4FWr+xD5c32g39L7dZgn7ZkkgBuWUB4w5VGzL1oqWqXK0zIKIaH KUJQ== 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 d5si3374420otc.161.2020.03.12.13.09.31; Thu, 12 Mar 2020 13:09:44 -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 S1727228AbgCLUII (ORCPT + 99 others); Thu, 12 Mar 2020 16:08:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:45260 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727133AbgCLUIF (ORCPT ); Thu, 12 Mar 2020 16:08:05 -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 E1166AE44; Thu, 12 Mar 2020 20:08:03 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 8FC58E0C79; Thu, 12 Mar 2020 21:08:03 +0100 (CET) Message-Id: <62c68681c338ae22b0d2924e9b8728f7858023d2.1584043144.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v2 06/15] ethtool: add FEATURES_NTF notification To: David Miller , Jakub Kicinski , netdev@vger.kernel.org Cc: Jiri Pirko , Andrew Lunn , Florian Fainelli , John Linville , Johannes Berg , linux-kernel@vger.kernel.org Date: Thu, 12 Mar 2020 21:08:03 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Send ETHTOOL_MSG_FEATURES_NTF notification whenever network device features are modified using ETHTOOL_MSG_FEATURES_SET netlink message, ethtool ioctl request or any other way resulting in call to netdev_update_features() or netdev_change_features() Signed-off-by: Michal Kubecek --- Documentation/networking/ethtool-netlink.rst | 6 ++++ include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/features.c | 4 +++ net/ethtool/netlink.c | 29 +++++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index d6706c4aa972..47542f042e9d 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -208,6 +208,7 @@ Kernel to userspace: ``ETHTOOL_MSG_WOL_NTF`` wake-on-lan settings notification ``ETHTOOL_MSG_FEATURES_GET_REPLY`` device features ``ETHTOOL_MSG_FEATURES_SET_REPLY`` optional reply to FEATURES_SET + ``ETHTOOL_MSG_FEATURES_NTF`` netdev features notification ===================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device @@ -591,6 +592,11 @@ reports the difference between old and new dev->features: mask consists of bits which have changed, values are their values in new dev->features (after the operation). +``ETHTOOL_MSG_FEATURES_NTF`` notification is sent not only if device features +are modified using ``ETHTOOL_MSG_FEATURES_SET`` request or on of ethtool ioctl +request but also each time features are modified with netdev_update_features() +or netdev_change_features(). + Request translation =================== diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 6f7aaa6b7f42..3d0204cf96a6 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -47,6 +47,7 @@ enum { ETHTOOL_MSG_WOL_NTF, ETHTOOL_MSG_FEATURES_GET_REPLY, ETHTOOL_MSG_FEATURES_SET_REPLY, + ETHTOOL_MSG_FEATURES_NTF, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, diff --git a/net/ethtool/features.c b/net/ethtool/features.c index 4ac1e05684ce..4e632dc987d8 100644 --- a/net/ethtool/features.c +++ b/net/ethtool/features.c @@ -230,6 +230,7 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info) struct nlattr *tb[ETHTOOL_A_FEATURES_MAX + 1]; struct ethnl_req_info req_info = {}; struct net_device *dev; + bool mod; int ret; ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, @@ -272,6 +273,7 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info) dev->wanted_features = ethnl_bitmap_to_features(req_wanted); __netdev_update_features(dev); ethnl_features_to_bitmap(new_active, dev->features); + mod = !bitmap_equal(old_active, new_active, NETDEV_FEATURE_COUNT); ret = 0; if (!(req_info.flags & ETHTOOL_FLAG_OMIT_REPLY)) { @@ -292,6 +294,8 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info) wanted_diff_mask, new_active, active_diff_mask, compact); } + if (mod) + ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL); out_rtnl: rtnl_unlock(); diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 757ea3fc98a0..5c0e361bfd66 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -528,6 +528,7 @@ ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { [ETHTOOL_MSG_LINKMODES_NTF] = ðnl_linkmodes_request_ops, [ETHTOOL_MSG_DEBUG_NTF] = ðnl_debug_request_ops, [ETHTOOL_MSG_WOL_NTF] = ðnl_wol_request_ops, + [ETHTOOL_MSG_FEATURES_NTF] = ðnl_features_request_ops, }; /* default notification handler */ @@ -613,6 +614,7 @@ static const ethnl_notify_handler_t ethnl_notify_handlers[] = { [ETHTOOL_MSG_LINKMODES_NTF] = ethnl_default_notify, [ETHTOOL_MSG_DEBUG_NTF] = ethnl_default_notify, [ETHTOOL_MSG_WOL_NTF] = ethnl_default_notify, + [ETHTOOL_MSG_FEATURES_NTF] = ethnl_default_notify, }; void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data) @@ -630,6 +632,29 @@ void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data) } EXPORT_SYMBOL(ethtool_notify); +static void ethnl_notify_features(struct netdev_notifier_info *info) +{ + struct net_device *dev = netdev_notifier_info_to_dev(info); + + ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL); +} + +static int ethnl_netdev_event(struct notifier_block *this, unsigned long event, + void *ptr) +{ + switch (event) { + case NETDEV_FEAT_CHANGE: + ethnl_notify_features(ptr); + break; + } + + return NOTIFY_DONE; +} + +static struct notifier_block ethnl_netdev_notifier = { + .notifier_call = ethnl_netdev_event, +}; + /* genetlink setup */ static const struct genl_ops ethtool_genl_ops[] = { @@ -736,7 +761,9 @@ static int __init ethnl_init(void) return ret; ethnl_ok = true; - return 0; + ret = register_netdevice_notifier(ðnl_netdev_notifier); + WARN(ret < 0, "ethtool: net device notifier registration failed"); + return ret; } subsys_initcall(ethnl_init); -- 2.25.1