Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1235321img; Tue, 26 Feb 2019 17:15:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IYrOEVyiyXACL9I1N0ojqvK2BbETy9/5tSyhUyU2V/wdnEU3yJ29akru8xO28eoQqpi6P7R X-Received: by 2002:a17:902:4081:: with SMTP id c1mr19775538pld.297.1551230127829; Tue, 26 Feb 2019 17:15:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551230127; cv=none; d=google.com; s=arc-20160816; b=EqIsvv9yJp+O32yq5VyvK5Qi0aahGe6H/aBqCBVtZwkTrYRgsjLRqrw1awvH6C2Zdx 9gWR0Zx+P/Xjxz9fHO6YpUuZG4ubJI2bvZrYGyW2AVJlFR454B+BAaTc7Cao6WSCzz8d 2S54/bFhhv35rHP2Bfrnrp8kRiI25y/q1iAgOT5Y2PlzrTEApGE6ACLrGTOVwJffzuo1 SOjq9cy1u5PpukNiI8dtK+02ux4Dv6Dua1tTCQqoaB0vem6OSCbgPUB9+ws72hXYw+y6 RkV2YIBdctjENvGnpB5LRIkQAZL//ZeQKkUSB+AH7JH/ujx3kgfDRnxH/zL1EVWCfiCg 25Yw== 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=ZICwACNBLinWfOFo5BNxpXhARueQcYuojmKLKdZqLXk=; b=TQ7g1IAvNozHod1uViCv67txUj//rulgvvJjextfOxJ2NhY8AXzcveecDSR4YqP07M IcDe7cP/7FyttCyPNH47hM4Yf4I2zaBCnQ98okEaNXpxxcIefLJX4bFWYELBIaphFBaT Eqj73zf5b7cQ8UH+hlkk0uJPeIGS55eBrTlXqIjIb0fs3NrGGVIGqoVZ5qNE2ISKgKg2 HUUnOs5+9OT8IaTnCV/ag4zcc2QdmE6N5JGJjbcOoGyXY+NaNnVggqhoOmv785ancYrG f03JU7x635Nj5LeMDftkKt/aJ2V759cOZQUzuJ924mIfUNK65BJ+fD1hWy1GOqYOPi2L MslA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vZkCtsIm; 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 ck9si15320302plb.196.2019.02.26.17.15.13; Tue, 26 Feb 2019 17:15:27 -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=vZkCtsIm; 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 S1729557AbfB0BOm (ORCPT + 99 others); Tue, 26 Feb 2019 20:14:42 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:47023 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727998AbfB0BOl (ORCPT ); Tue, 26 Feb 2019 20:14:41 -0500 Received: by mail-pl1-f195.google.com with SMTP id c17so3938081plz.13; Tue, 26 Feb 2019 17:14:41 -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=ZICwACNBLinWfOFo5BNxpXhARueQcYuojmKLKdZqLXk=; b=vZkCtsImSgiN4o2HP1QzeuDHH+LL/rES9XF7h1lhY705gSIhaJLRYD75GEzs7Yb1HK P/p2T61weQX35jAf32/fOvmP6km3GfU/0shiuZbfjodssmQX5gjxrThMUwSEuDNhejOl 5a+9ipzltAgBwiC1i0V1OB6pkqjEAOMZpfMvSjgKJtEh7zaX0ub1JkYefbUQaKYTbzBS qbtdcFFgjSLA8TjIwCQndk1UbLdnptiZeuQZbKitRUDxxdMlQ+R0SEG/BK/LvsKgtc8U lcwOPENTFoQoXI43h4hA2a+VoOtUDX1hu+bJP1MKRFY/Dfbt2WyUcDMH9b8SkzIj7rj+ hg4g== 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=ZICwACNBLinWfOFo5BNxpXhARueQcYuojmKLKdZqLXk=; b=CnJjvoJNuQGgh3PzWHTXR81F+sgy8JusIVLKAv909yRWW1UBCspeNAlcTr7wYahqhd 03BXxiop2zB4f/CvKItJf/6XHP4GcCd+ztXjKs74HuvYfaBZdnDyifInmEriXQfriNp1 0HlHX8SsPL8Dl9GJg+zECQxnW5vBfyxFIBUincGbjBVTZDep1a0+w+sV6YZ9BmgJrVqf W6/+NY/FuNAAL9QUWDilM6Sv8DDcC04jvLWC4tltd7Dxh12hpuPm1++ncK6lHCqjG7B9 bkW785x03oAa6vQbkxHlLT8amL0Kp2yeeWdH40PSfbMCkYzt8ObCHlSluU8MtDFI6zuw Hl5w== X-Gm-Message-State: AHQUAubc1qlrrxOVK9V0hFRfK5vVyd+fS9fCRfTAPFG0i6ESgcMP02cR QIk/iMe1CMTr+3CWB0RzVpBEwLId X-Received: by 2002:a17:902:b7c7:: with SMTP id v7mr28778771plz.148.1551230080781; Tue, 26 Feb 2019 17:14:40 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id q28sm21885221pgl.35.2019.02.26.17.14.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 17:14:40 -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 v2 1/8] switchdev: Add SWITCHDEV_PORT_ATTR_SET Date: Tue, 26 Feb 2019 17:14:20 -0800 Message-Id: <20190227011427.16487-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190227011427.16487-1-f.fainelli@gmail.com> References: <20190227011427.16487-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 be4b13e66668..5087c06ceb4b 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -132,6 +132,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, @@ -160,6 +161,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) { @@ -212,7 +220,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) @@ -299,6 +315,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 362413c9b389..3560c19aa7e2 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -655,3 +655,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