From patchwork Thu Jun 28 23:21:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10495355 X-Patchwork-Delegate: idosch@idosch.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 31A986022E for ; Thu, 28 Jun 2018 23:22:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2052A29965 for ; Thu, 28 Jun 2018 23:22:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11EBA29989; Thu, 28 Jun 2018 23:22:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 42D3929965 for ; Thu, 28 Jun 2018 23:22:20 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41GwmB2tXbzF1RK for ; Fri, 29 Jun 2018 09:22:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="mjoUOTJG"; dkim-atps=neutral X-Original-To: linux-mlxsw@lists.ozlabs.org Delivered-To: linux-mlxsw@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mellanox.com (client-ip=40.107.4.49; helo=eur03-db5-obe.outbound.protection.outlook.com; envelope-from=petrm@mellanox.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="mjoUOTJG"; dkim-atps=neutral Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40049.outbound.protection.outlook.com [40.107.4.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41Gwm43D1QzF1QL for ; Fri, 29 Jun 2018 09:22:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2YbaALqX/3VfshFNIW5zHbXwFB9zHzgAH9T6mxERFow=; b=mjoUOTJGOe7SfFLOYOs3ghaC6bAJcCedb3WXKStHF2VMATW8HBqO+pHyyt6B/jmi5l9KZwsSQ/I/OBBMZSQksz4xpBAooH8N3Ind7B2RdtPHCBpuL3JNf3UF/wI8Mw838T6OmVbZkn0qMuhXJCyZFqHWWEfoBfWXbVNlns4vxcI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (89.176.83.59) by VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.23; Thu, 28 Jun 2018 23:22:05 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw v2 2/3] net: Add lag.h, net_lag_port_dev_txable() In-Reply-To: References: Message-Id: <00c18016865fb1ba7350b77b00f723228b39411e.1530227929.git.petrm@mellanox.com> Date: Fri, 29 Jun 2018 01:21:50 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [89.176.83.59] X-ClientProxiedBy: VI1PR0202CA0015.eurprd02.prod.outlook.com (2603:10a6:803:14::28) To VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 07bb63dc-8495-46ad-9cb1-08d5dd4df62e X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:VI1PR05MB4191; X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 3:qhVDpJ2tKKSqp061d49yiIOcypxsr9DkS6TXUJu/dx32RmfhxD3NLQin7OAwjMydtTmk588X28Z24Ue7Ur1u9AWVGwkChDcHkU3nB6s5wrhpehogQ33qk96IBKk3kaTfRsuPBdUQ0E/eFOl/Mzoqym04MN9NQAPnVC7ey/WnJ3eAftxRhscCzSfdI2GCzOOHNrscB8Y6bcY+i291lK4u06QblL+7OO3uioLYbXoLNdOKFj9sdKrn+0E0+t5RQ8NN; 25:TdY4cjQ759TP1TnbEl5B4nqdSl4tWpsfALtjVXe8FNtMqw+/xHgBiXA9KxM+LquCwoxfqiU93jSgQAbF6u5PkQEhhrqIOAHDucHNd5MwvVVB2WjW2YFkAuRnX+TFgj/tDOqrXzH+owiE0ZFTmJ46tE8XhyliprF4q7npieTKFgmz3+lF55r5VPJI3aq8VMxHjj3nkDGfB5/t32efMLWfTR22Tjs8LADF4P6slDt4iou7k58jTM8SfyGY31T1p1hdSym5H8Scwrb1BCgeBzkBWjvOppxp0LFUmiB8SZkuG3XpYETw/q1xCuQ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7NsvByb3/1DktLW05qCsiJm9i9EhfSpg6TpCabsAux8jMrr8Wy5dgw39DPU5CtR4Oeg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:VI1PR05MB4191; BCL:0; PCL:0; RULEID:; SRVR:VI1PR05MB4191; X-Forefront-PRVS: 0717E25089 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(396003)(376002)(366004)(346002)(189003)(199004)(186003)(11346002)(26005)(5660300001)(97736004)(36756003)(16526019)(446003)(48376002)(486006)(6666003)(86362001)(76176011)(50466002)(386003)(14444005)(956004)(476003)(6636002)(2616005)(6486002)(16586007)(6496006)(6116002)(3846002)(316002)(52116002)(47776003)(118296001)(81166006)(66066001)(51416003)(2351001)(2906002)(81156014)(305945005)(8936002)(53936002)(7736002)(6862004)(106356001)(105586002)(8676002)(25786009)(478600001)(68736007)(58126008)(37006003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB4191; H:t540p; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR05MB4191; 23:JuGeDmY5lcQEmHAWNpMduWZA7b5qbPBZGDZOFJUHJ?= =?us-ascii?Q?i2YHG1nYq6rZqQFbXp1lg4XDtQIERJqoB/aW8YZptXp96TcMKRRyKsuqWa9t?= =?us-ascii?Q?DLx5+apCvnciaKXQppE6f/QAtq1F8fvhjtyd+/YAb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zXbhmcHQkJVXNzgwEEE+IyBkDAFsybxwC0jUzPVDqaFcemwCZImddyQcHa?= =?us-ascii?Q?krPzr+R7w0sESgVApaevdRXWJ1GZ0FT8TYXyhIDkG8Mr5kRuy7UJo3DeQtIP?= =?us-ascii?Q?UsJxlOOWauXvYnuonDeyCTJ9mPXypZ+zAjPuYID/ub8KDotStjWDDANXBKno?= =?us-ascii?Q?PCiJxThKpNPJxR3auk8TyUxgbKPIzAP8f+tkQDP5TBkeHzTewwn9+pTeQ=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Antispam-Message-Info: qyaSgM3GoeZfWKQOoaya7jilassehNxR1zgK+RXDaXEuRVDjxfdA5NBGBskv8xyTJ5udrXR3HMcfUtAzfLH9XlWLgc8DLI28cp17ocXugrRKNM42i9fcFbXbMjgbZu0KMEt3EHQ9l6jhronmAyxaZKqHr8J0JzbDuFmFHfeinHjdbTXXwEzq8c08imerdiA18ku8jRgt2CwjnFFknr9dxuJrfzCcI37ZQmoZYCwUeHgwaSITa8+X98eAKQyA3zByrhn08PnpQpmYzLMbUe/HuRkd9FARyWI2IthYTtmxy9VfgoZLPWi8UL4mcJEu9c2WVDKKMlzqoYRHAjHZ6y761tSqfBatcxD4095RMGNnn0g= X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 6:KVdxLsA/T8vbbLX2rhtaLks9w/MU/9O87sfgXYCV2TyzvP5xyldQBVAaqi766/11PKoO6ecv8hk1bEwKgAkxqb/PYYxGMDmJnWzDkrj1zzheG7qiC8ZFo83ww+W6Du4NMjVh+1xw3uwDViwNGsqQce7waMpZoJ2CO54zXxGOe7Q/Y96n8ZivVeTNRWGMTYXNcrZcFT6DQie2v6nniMvZ1Hxm64ACST5tYVTYJkbjjOyY9AOF6balA69xznwUZU8OfQa4Vlx9XINlOXr9osAnGiapLU9cR9xXFCg1D6dI6xYoAJeTBdklUfJtETcQJRivZqcjJRm8ikaF82CNRRYnI9fSIFRa+kOLRQ3HLvrMV9PsVpV0gdyJ2UFFyioqduFNRGQp+J5FmoVe/mAmnCRv6alNtlCNAKFUuaKekUWrdD/cKfsef/pGt6g5znhyvYhyJOUvOSXP4jhzHtEHzAKfAQ==; 5:Cz2QSX6YyYdmKSLSMV93nTN3jkU7juPbvXJwTdggca+YIAgpxGz8KjmAYO7TrCi7JnkR72uhrCpC6Anovm/DvJeoIHZ/t9SBWk40H1IVaf9lfbFUmN2Fv2eE0kMjvhnO/5mIjf12BlJX4UfQR5ADMbm9Ju43Xb9qGRM0n1uTJZ4=; 24:Ymm1Crk8d4R1e5WW9Ukhfa3vklA9ibAtcYSry0OSifnEHK7d8a3RVBTtQ/wRg/92bCW+3or69nmDMVQbEjgqzXhkEtJ1Kj3uqR6xDD/AerI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 7:4QXpGexmI5UhlNv6LCVo3tfU324hvMPnofq4s35tYhR6UYXRak3DzvI/XMaXQl2zKSNEpoNKTgmE22DOMZuebxtYo8RGlxy+lN/bLL6Yvt+lpIbLkLLdapX55kyEW+OJUdaFYdQTC6Pb2IyA1z1KA1JOAYJWEjOG8EJH0YA/TTb8ZHXFOIGV41xrh2Wf8tytGI3dJS1ZN8Nm2CjYs1DpPGGVuRuTaLmVeeDveMbah5znWLxpQR/pn4au//3Z/M/p X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2018 23:22:05.4169 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 07bb63dc-8495-46ad-9cb1-08d5dd4df62e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB4191 X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org X-Virus-Scanned: ClamAV using ClamSMTP LAG devices (team or bond) recognize for each one of their slave devices whether LAG traffic is going to be send through that device. Bond calls such devices "active", team calls them "txable". When this state changes, a NETDEV_CHANGELOWERSTATE notification is distributed, together with a netdev_notifier_changelowerstate_info structure that for LAG devices includes a tx_enabled flag that refers to the new state. The notification thus makes it possible to react to the changes in txability in drivers. However there's no way to query txability from the outside on demand. That is problematic namely for mlxsw, which when resolving ERSPAN packet path, may encounter a LAG device, and needs to determine which of the slaves it should choose. To that end, introduce a new function, net_lag_port_dev_txable(), which determines whether a given slave device is "active" or "txable" (depending on the flavor of the LAG device). That function then dispatches to per-LAG-flavor helpers, bond_is_active_slave_dev() resp. team_port_dev_txable(). Because there currently is no good place where net_lag_port_dev_txable() should be added, introduce a new header file, lag.h, which should from now on hold any logic common to both team and bond. (But keep netif_is_lag_master() together with the rest of netif_is_*_master() functions). Signed-off-by: Petr Machata --- include/linux/if_team.h | 13 +++++++++++++ include/net/bonding.h | 13 +++++++++++++ include/net/lag.h | 17 +++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 include/net/lag.h diff --git a/include/linux/if_team.h b/include/linux/if_team.h index 0d07c6655cce..ac42da56f7a2 100644 --- a/include/linux/if_team.h +++ b/include/linux/if_team.h @@ -89,6 +89,19 @@ static inline bool team_port_txable(struct team_port *port) return port->linkup && team_port_enabled(port); } +static inline bool team_port_dev_txable(const struct net_device *port_dev) +{ + struct team_port *port; + bool txable; + + rcu_read_lock(); + port = team_port_get_rcu(port_dev); + txable = port ? team_port_txable(port) : false; + rcu_read_unlock(); + + return txable; +} + #ifdef CONFIG_NET_POLL_CONTROLLER static inline void team_netpoll_send_skb(struct team_port *port, struct sk_buff *skb) diff --git a/include/net/bonding.h b/include/net/bonding.h index 808f1d167349..a2d058170ea3 100644 --- a/include/net/bonding.h +++ b/include/net/bonding.h @@ -411,6 +411,19 @@ static inline bool bond_slave_can_tx(struct slave *slave) bond_is_active_slave(slave); } +static inline bool bond_is_active_slave_dev(const struct net_device *slave_dev) +{ + struct slave *slave; + bool active; + + rcu_read_lock(); + slave = bond_slave_get_rcu(slave_dev); + active = bond_is_active_slave(slave); + rcu_read_unlock(); + + return active; +} + static inline void bond_hw_addr_copy(u8 *dst, const u8 *src, unsigned int len) { if (len == ETH_ALEN) { diff --git a/include/net/lag.h b/include/net/lag.h new file mode 100644 index 000000000000..95b880e6fdde --- /dev/null +++ b/include/net/lag.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_IF_LAG_H +#define _LINUX_IF_LAG_H + +#include +#include +#include + +static inline bool net_lag_port_dev_txable(const struct net_device *port_dev) +{ + if (netif_is_team_port(port_dev)) + return team_port_dev_txable(port_dev); + else + return bond_is_active_slave_dev(port_dev); +} + +#endif /* _LINUX_IF_LAG_H */