Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp2015435imc; Fri, 22 Feb 2019 16:01:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IaF1hv24rk8vyB1eaWgYBvtbCqICU3ih/bEsrHix1kb/dgHkg+/aMoy8VtfBa1Pov82xB44 X-Received: by 2002:a63:d34a:: with SMTP id u10mr6530003pgi.301.1550880072524; Fri, 22 Feb 2019 16:01:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550880072; cv=none; d=google.com; s=arc-20160816; b=LWVcOHCNf3uJ4hSu9J6sKyOTaGEhizUofSMeI/FTvACggkSYvAMgWp+j0VdOxQ+oL6 ggF0qO0/edXhZN1u/zgearYtkiLtloS6iYJqiHX+6SkYfL6yLxTSJeTMw1amFfkmtd1+ 6yINC6ff1618CdSYPaGTPurAHpKv0/3uSqQ/rUlEXAxKi+1aT1+Eik9hkQEtgqcxJSns 0uFHXhx8M9FI3IpgGHx3DdNt+/1GjGySeQC1GmDq7pzQMNGBUbBrO55FUyB7TAtqKv2E M0EshL/zfGwPhYCEGdhy8rDVVhg1rB2PMfsPZ3AxvbkE7s2+avCxcU0C3cdvLad7x3m4 AgBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=oBI12FenCDDfRE6eSCrjheZca+vUirHEjPRbN/cZFcI=; b=0VfshJRmcdp+uQPhaTYM2AG3LBNrIX9ZVQ6ylS20G7pxvrPAKTmh1Wfu8wwYYgz1O2 H9oiO3Ub3lRRTadvatQuxvzN8G6y1h4gW0Fe+s6dhCZZwFTIbFPDR6L6+WK9qRZTrmQR h+F7YDSIn4Ogg90K0Iffb6osd3rtFVBWX54aqvZ5AbJruQcvIWfS5oWGJXuZkuTGdS5t 0S7LmBR/xdHhKTKlOQX8E39avgBaRqdsuGKyTfC/otHTINHw0cAJBPofVlFMsSE+9UKh tGVXNfS5zcbfAQaw3sEdwlv120/z0esKiq5rq0TWZK6T0sKDQERZCgzsVXO+1S+FEZ8B aY0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nNH3vmPN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si2581647pgn.145.2019.02.22.16.00.57; Fri, 22 Feb 2019 16:01:12 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nNH3vmPN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbfBWAAa (ORCPT + 99 others); Fri, 22 Feb 2019 19:00:30 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38935 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbfBWAA3 (ORCPT ); Fri, 22 Feb 2019 19:00:29 -0500 Received: by mail-pf1-f195.google.com with SMTP id i20so1796276pfo.6; Fri, 22 Feb 2019 16:00:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oBI12FenCDDfRE6eSCrjheZca+vUirHEjPRbN/cZFcI=; b=nNH3vmPNCqA5lArtC+jLENEEu0G2foBRlxxfiElJzRy/33NReasyZgmXnLw+uN4PuP 2bgZaG7MLeswvSWoshu6mjKi4BBFZIR6gvz8nbqNOQLvtKskRaoOMYUSwDVToSMZDqHE eMNOteNFHw/w4lKuTz63z/XNLppIxCqQ4LGkrh579tQxnx4PUMT+PCiyMimreMffkQWS HPekdwFdcpn8A+HfwYSu3LZ/XI31m0erYxk5/gxLdV+pu1kiMDCmVGQ8yLSkzUAV1w71 VC/P3YKZDNfC84nhm3QS7ndAA6ZmepATDtYjviPTsVG0yfDGkg9te5DxtL5ReuD5L2n1 ZzJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oBI12FenCDDfRE6eSCrjheZca+vUirHEjPRbN/cZFcI=; b=DzZt9KmM8cztBFQYkSvoZ62Jlwr+stufP5SP+LIP+lOjevnaWccA4l7Q2L4nuMaTId Zm7t8coLk/SPaBY4MyV7NP2Qzw01w2+1TrEPL4ab6h+nA2Z7VkTrVF/HUlW0fKQ7ULjv apVj5lhGOQ/TzkU5RAHQ4vdxrJegL6zKY8Efe7QYNepGp+P5jTAHSaePHhWMgp5ADtfp LUHhizJAOFP/PL8w15qgZHvQWkoM+qXnbsk6T+KkDn2YBb0FI9dqFaoMJmcXmcX9hz+N b99hZeXCgKfGY+u12TL1q+YTcGbKoaXYNOupzStXNwsuY/pnPl5AbirRRmd6Hz0fKloZ H/+Q== X-Gm-Message-State: AHQUAuYGrNJdJEsALTwHRmg8kB0Y1LUkKTjfx8qms8lA0PnWHlWeSjCi TgQVe8vzxBS2e/5UQRLfVqttc7fe X-Received: by 2002:a62:b415:: with SMTP id h21mr6816213pfn.26.1550880027625; Fri, 22 Feb 2019 16:00:27 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id z12sm3327872pgv.0.2019.02.22.16.00.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 16:00:26 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , "David S. Miller" , Ido Schimmel , linux-kernel@vger.kernel.org (open list), devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM), bridge@lists.linux-foundation.org (moderated list:ETHERNET BRIDGE), jiri@mellanox.com, andrew@lunn.ch, vivien.didelot@gmail.com Subject: [PATCH net-next 1/8] switchdev: Add SWITCHDEV_PORT_ATTR_SET Date: Fri, 22 Feb 2019 15:59:19 -0800 Message-Id: <20190222235927.10295-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190222235927.10295-1-f.fainelli@gmail.com> References: <20190222235927.10295-1-f.fainelli@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for allowing switchdev enabled drivers to veto specific attribute settings from within the context of the caller, introduce a new switchdev notifier type for port attributes. Suggested-by: Ido Schimmel Signed-off-by: Florian Fainelli --- include/net/switchdev.h | 27 +++++++++++++++++++++ net/switchdev/switchdev.c | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/net/switchdev.h b/include/net/switchdev.h index 45310ddf2d7e..ca56b7487540 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -136,6 +136,7 @@ enum switchdev_notifier_type { SWITCHDEV_PORT_OBJ_ADD, /* Blocking. */ SWITCHDEV_PORT_OBJ_DEL, /* Blocking. */ + SWITCHDEV_PORT_ATTR_SET, /* May be blocking . */ SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE, SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE, @@ -164,6 +165,13 @@ struct switchdev_notifier_port_obj_info { bool handled; }; +struct switchdev_notifier_port_attr_info { + struct switchdev_notifier_info info; /* must be first */ + const struct switchdev_attr *attr; + struct switchdev_trans *trans; + bool handled; +}; + static inline struct net_device * switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info) { @@ -216,7 +224,15 @@ int switchdev_handle_port_obj_del(struct net_device *dev, int (*del_cb)(struct net_device *dev, const struct switchdev_obj *obj)); +int switchdev_handle_port_attr_set(struct net_device *dev, + struct switchdev_notifier_port_attr_info *port_attr_info, + bool (*check_cb)(const struct net_device *dev), + int (*set_cb)(struct net_device *dev, + const struct switchdev_attr *attr, + struct switchdev_trans *trans)); + #define SWITCHDEV_SET_OPS(netdev, ops) ((netdev)->switchdev_ops = (ops)) + #else static inline void switchdev_deferred_process(void) @@ -303,6 +319,17 @@ switchdev_handle_port_obj_del(struct net_device *dev, return 0; } +static inline int +switchdev_handle_port_attr_set(struct net_device *dev, + struct switchdev_notifier_port_attr_info *port_attr_info, + bool (*check_cb)(const struct net_device *dev), + int (*set_cb)(struct net_device *dev, + const struct switchdev_attr *attr, + struct switchdev_trans *trans)) +{ + return 0; +} + #define SWITCHDEV_SET_OPS(netdev, ops) do {} while (0) #endif diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 7e1357db33d7..94400f5b8e07 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -697,3 +697,54 @@ int switchdev_handle_port_obj_del(struct net_device *dev, return err; } EXPORT_SYMBOL_GPL(switchdev_handle_port_obj_del); + +static int __switchdev_handle_port_attr_set(struct net_device *dev, + struct switchdev_notifier_port_attr_info *port_attr_info, + bool (*check_cb)(const struct net_device *dev), + int (*set_cb)(struct net_device *dev, + const struct switchdev_attr *attr, + struct switchdev_trans *trans)) +{ + struct net_device *lower_dev; + struct list_head *iter; + int err = -EOPNOTSUPP; + + if (check_cb(dev)) { + port_attr_info->handled = true; + return set_cb(dev, port_attr_info->attr, + port_attr_info->trans); + } + + /* Switch ports might be stacked under e.g. a LAG. Ignore the + * unsupported devices, another driver might be able to handle them. But + * propagate to the callers any hard errors. + * + * If the driver does its own bookkeeping of stacked ports, it's not + * necessary to go through this helper. + */ + netdev_for_each_lower_dev(dev, lower_dev, iter) { + err = __switchdev_handle_port_attr_set(lower_dev, port_attr_info, + check_cb, set_cb); + if (err && err != -EOPNOTSUPP) + return err; + } + + return err; +} + +int switchdev_handle_port_attr_set(struct net_device *dev, + struct switchdev_notifier_port_attr_info *port_attr_info, + bool (*check_cb)(const struct net_device *dev), + int (*set_cb)(struct net_device *dev, + const struct switchdev_attr *attr, + struct switchdev_trans *trans)) +{ + int err; + + err = __switchdev_handle_port_attr_set(dev, port_attr_info, check_cb, + set_cb); + if (err == -EOPNOTSUPP) + err = 0; + return err; +} +EXPORT_SYMBOL_GPL(switchdev_handle_port_attr_set); -- 2.17.1