Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp2178279img; Wed, 27 Feb 2019 11:46:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IYV+NSDMlKNVIY2ZyhTJyDJqFWH7XONTfKrtBP84Hb1jE1EUNMPOeXkVgjN2Kf2qVynsmKg X-Received: by 2002:a63:6cc8:: with SMTP id h191mr660185pgc.366.1551296770266; Wed, 27 Feb 2019 11:46:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551296770; cv=none; d=google.com; s=arc-20160816; b=JIDD6ZgDcc8yHwPgNgsOten7/zYRURQYjoQVwDnrhzZeUXjnriZK13B6W2z96aqUT0 ksfZWmKT6C1S2Q4NALXp0+NmtZ+v5L4lZZ69MN5T4nokbiZFQbDWQ3GLIj8JmktdWYbv pq3lOZvYvndzkSN3e+jqmXCKwLx4gAyfA1b/NAsjC9wj6I96igKs+Q4TLmieAr4pwve6 OCzKLSJ/F+SqZmEXJMeETyZQzgleTiPm1l/B1jT1Z3eRWVEdtgBudP0NDXOEeErSgoPc o1U6zyOtPFXyCnr1s2K4IsDqamwHxTxq0E7IVv00KxTgfq0cjHFKMRrp7loKv+5roJcK oiZw== 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=BqrkBPBZOpaqz5GXIcdMet1Dw1hbY5LkY4oijejMFis=; b=Q2M3KClssuzr4c+9EYb1SWyYx4zt+VF04z9TEvWXTIdpmZZanOwpik33O2ZsHP89dT x6/+1+zwiZLS+KKckkzPulUoV7ZW/2tbwhd6mO3W3JZAIymyA3FkzVwrEeipyLjUoxPQ sO+B4gV68ywTY+BY4yaQt3B6hxp2aFfyfv0wXcmAAiMoCgcsN/8TjfZyQkmMdOUPgysD /A1ReRSu/gTKHhfMAIlWDMo4JTjiRHVCpPdD3KakXHhREKb6n1l6kOaZKIj4PTq6UrnC naIuBmySaRTrMpqlLDKzX2OR7Ld/h6lbR0sy+vFvBYh7kqnvKcF+eoLH/M722lQuXG/j rJBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oDcSTu5W; 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 v3si14774883pgr.11.2019.02.27.11.45.54; Wed, 27 Feb 2019 11:46:10 -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=oDcSTu5W; 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 S1730316AbfB0Tp3 (ORCPT + 99 others); Wed, 27 Feb 2019 14:45:29 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34420 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728751AbfB0Tp1 (ORCPT ); Wed, 27 Feb 2019 14:45:27 -0500 Received: by mail-pl1-f194.google.com with SMTP id d15so8519327plr.1; Wed, 27 Feb 2019 11:45:27 -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=BqrkBPBZOpaqz5GXIcdMet1Dw1hbY5LkY4oijejMFis=; b=oDcSTu5Wgm7LNd8mow1o3qmHLWU/9uIdCKMHAQqm5Szth7y3Q0x5mYXKDuuRv32cE9 epemrQQEOG5hHUlPuB5F2+ITDQ7BvdBIW2PyuWX4GR6rM6bUde1XzpZ72j+Vq1K6Y7eY iom/4PqJS2Akdmf84MoBtAfBqxvI0/81minDv5eaeHJ3CKXPabKuwdFNeOyHsIYoCj3Z VOYssfnDcFvCVoUGOytsNQJ6VyBjfswz/1ABoxXa1zf6GjLYcGlCGzH9t1zPNQWcr1se ykVeRuo876XZ8a4cvExPhHwMyWHhXdXDVUKu/WNUzTymW3vCQIONAQqCy1NB/SC8+nH5 qTQw== 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=BqrkBPBZOpaqz5GXIcdMet1Dw1hbY5LkY4oijejMFis=; b=i+N5MfbWtoE0feyTiaSdFnM5FvEHKT2QjcsZuH+at8albgZODUUmn3+y2JyhJxdbYf q6lBlovA7Wc+LGX96r5Revuo7+VXcXbB8OpyE+D3N4H4/zobd6XKjHB4jHG1iyVINj6M aPaieZ+20lVwq2mJEKifn0Lb3x9pednL/Vlaa2P/XcPwC53jGixbFKAIfNO4jprBvV7g /q7/S0ZIgp444fnr0gD8kSttL2rzjS57oAaZJpBDw/9vlaiMbAbqRev68Hl/wnn6jxeG hCQSgQ44GdjRXWOcdFJ0Asb5oI9QhDzQ4CcSXFwtBz41LrQ4Dl5K1PsbifSXVFtETvvo KE2A== X-Gm-Message-State: AHQUAuZqso/hXw442t2cSOf9qLV6mbkXT0TNDQMM27zsEaEVvdBNVIdX sGKkjNIP4iF4ZUEhFTR8mWwFvQwp X-Received: by 2002:a17:902:5a42:: with SMTP id f2mr3865856plm.157.1551296725805; Wed, 27 Feb 2019 11:45:25 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id j6sm17044642pgq.33.2019.02.27.11.45.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Feb 2019 11:45:25 -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 v3 1/8] switchdev: Add SWITCHDEV_PORT_ATTR_SET Date: Wed, 27 Feb 2019 11:44:25 -0800 Message-Id: <20190227194432.725-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190227194432.725-1-f.fainelli@gmail.com> References: <20190227194432.725-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 Reviewed-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