From patchwork Mon May 7 14:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10384247 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 30A3860318 for ; Mon, 7 May 2018 14:32:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B9FD28C86 for ; Mon, 7 May 2018 14:32:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A56128B7F; Mon, 7 May 2018 14:32:43 +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 8E2B228B7F for ; Mon, 7 May 2018 14:31:14 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40flRN6nQ8zF1gK for ; Tue, 8 May 2018 00:31:12 +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="RmdVpi0g"; 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=104.47.2.45; helo=eur01-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="RmdVpi0g"; dkim-atps=neutral Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0045.outbound.protection.outlook.com [104.47.2.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40flPj4NMvzF1gK for ; Tue, 8 May 2018 00:29:45 +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; bh=s3V2mPOiUK7vu9pDlFqSgzjwHF56ypM9UFr6UEpHFTM=; b=RmdVpi0g7LTj3UAH8p4X7dGl1Ly1Gv+iI5ThjNeIr9++/mNoYqErGThfNfSWrT9twOj8PRYDBwQAvFOcBnhHjkBHU62KP41Z+6iWnBIKWPScuNdjWNKaikMp/femgK63i4U39yq5p5ARUfUEvFjE8hDEUdrs6yxnEvjBOSh0Iss= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (78.45.160.211) by AM6PR05MB4183.eurprd05.prod.outlook.com (2603:10a6:209:40::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.735.16; Mon, 7 May 2018 14:29:39 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw 2/3] mlxsw: spectrum_span: Support mirror-to-VLAN In-Reply-To: References: Message-Id: <330693cd21ec0e3b277c5f2797802cd4cebffd7e.1525702327.git.petrm@mellanox.com> Date: Mon, 07 May 2018 16:29:34 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [78.45.160.211] X-ClientProxiedBy: VI1PR08CA0130.eurprd08.prod.outlook.com (2603:10a6:800:d4::32) To AM6PR05MB4183.eurprd05.prod.outlook.com (2603:10a6:209:40::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(2017052603328)(7153060)(7193020); SRVR:AM6PR05MB4183; X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4183; 3:adCI5aKrzH+KSBOWDvRNn448Y/q1ey+ZLWNoFQT1vXphRRC92/wtq59RV4Itj3WXiJfaos6NHE+yyXtmeMDL67xbqH5E3uzqOQwmaqYg4mfw+KTjheXgo8Fzi0CeduMUvZWEraHDdIVFyV65IlTwu3zil82hSCa9eljay+2M3vnh2KrEOAzClyV8iDsE5TUt2esSBdScNfpPJgTvhG8LYkwLOIoheEB5a/ioNQitTXW/gQtCdRNLgQQiDcpGj1oz; 25:4PnD8EJFzuZj/EnmdA8cSB8AvDgn4OxutYIxpZBi4B1jHUHpLPhpa1FOYCiD0AFxx9W4exdAvX0v4z1GaqfFCmr1wx8Hako0nc8lgRUgbU8tTgobNMPceCUeodnca3l/e8k5d+i3k6ITFJ9wWexi3Es8CYv09LeT8FJvLptuAunMOGdLuqLw1nsvG/7wQayYVIx5a36a4AZBv8jWJLQAbxPVIWpwFAEWsXq/2Mnpx7Lgw7Weok0+8H5a88gNmfi7rG4R+l2mo4uT57Bo4kh6RLpwhgQ3EH08CoaIdDJeT6z+UPC4CHrsFEqfBrHYOrnmVc1bzSoo0XEXA9k31x+k/g==; 31:HD+vWAjQgf0ifwEjHsw76Xi8ODy/+W81mmCBOYIDMXDI2H6nOu1SPyy40IlptnuySRLdj4/cb+4Ebux6JLT/bMg4uwhz6nvX241oxfFEnpzaKlbPPwukmTArvKvWy98PgBSX9g58VpToTeHvOgmF2fBDPUILy9DD0tC7vOV9bHatfmbH3VCYJ7y7eM31np5SHOB9P7g91j9ORUDJsQ+5horKGWr84lTC1yA8nQLLWtc= X-MS-TrafficTypeDiagnostic: AM6PR05MB4183: X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4183; 20:VY9sO0MVpBcQHbAE1oOjAobjFjcMwV3oFqX3+9OirHC9m53cLNeckC8VhhvC0D++FOIJR+0LXclY7ctgMRaTiDyTAX7wgcwMurCX9wroGGzJhQzAhlN1MRkYVbBclNOgLePRlOrO9cZ2PczXDJnBETMfFyegmOZfx3Ro2sAjXBDZGPVuJrvpE+mZU4Hb6DQxei3cS3DwVhg9g8kJBSh2WhZoY9unQQyVPIReAvVeyUsfgDkkjAnlAqDOq8yrqHhdqZMqgx36aIzPrT2BXu6uWotI+nPV/KOPXZOLTmnDoL20udZL0fTtfc1ZTysELYMk7+XzdAXmiD9hHOSMltxS0xw7oYI1ATqNalMZ3r5XgVYhuoSGt75grbjJjL5AFarRo1eJObcgoOhaRYPnEagLayLvQ8G49YG1psBpeJRLJxLXUmcbSgJYvk8XIBln3Q3NNhK/cg/8knroo7a4Yr3lIYmnhKHi70btDshKVpjIMxjOczUGX4rWSLlovpIMw3yB; 4:d1R0J7mYqVRomm2fwQsgKoaRNgPdt4AZhsU1OMs0Ljj3dWXaXWjOuC3pGZtn/BQ8vvar77aorAMmXIjH4UaKkYzpsycWHKrainp8b+9NPZsHaFgQEEMjTjxdabCvTM3MvaPnlYvBYyU4kfo1VY1MoqJ1pYkeDJtDSt3mGdSWEbq7thfUEDqREcw0Ii06hFfm5JntRQbCCb2wgE9CwZTFeZsymY597oQd8sb5s0qBXGAK4eKbYR088tWjJ2AOGOL8r8F/c7CyE6d00AK9biNBOw== 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)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:AM6PR05MB4183; BCL:0; PCL:0; RULEID:; SRVR:AM6PR05MB4183; X-Forefront-PRVS: 066517B35B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39380400002)(396003)(376002)(346002)(39860400002)(199004)(189003)(478600001)(68736007)(486006)(47776003)(3846002)(25786009)(16526019)(97736004)(476003)(105586002)(956004)(118296001)(4326008)(52116002)(6116002)(26005)(6496006)(446003)(11346002)(2616005)(76176011)(51416003)(66066001)(386003)(36756003)(106356001)(48376002)(107886003)(2906002)(6666003)(7736002)(86362001)(2351001)(5660300001)(16586007)(316002)(50466002)(58126008)(8676002)(6916009)(81166006)(81156014)(305945005)(8936002)(6486002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR05MB4183; H:t540p; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM6PR05MB4183; 23:iplHutuQ93rOW1PFzEjsvL1UTWXB+psAGFFpzhcAa?= =?us-ascii?Q?MnMmvubjQ8lfdBStPsD0ZZFsv6HAAzG2r/jQPP1jFUzAp2qc32LZV0J70A7q?= =?us-ascii?Q?EjUTG/RQfGK1WNM/o8n+xsOJ1F34z2hvCixInrdw7dXqWPG6ARkg0tHHVhoD?= =?us-ascii?Q?MutWOMnb/KAum4/7Io9AA1CapsU/BiZA1/RM/Mx3Oielpjg/M5Me4Os0/cZP?= =?us-ascii?Q?6X+np2Jc03H6QYH/0MXJMWjpULqcK26ZbhQQ2dKKzhZSG2euVKLrIeebuRgF?= =?us-ascii?Q?21KlcxSGeWjO4/Ij8czssuOcO7Dk3YtxKjI80/tgefcAns0SnlM6Rxc4TvWR?= =?us-ascii?Q?yPC6xZIrMVuid91RBU+qBnObnK0HuaFC2IndhtIxtBjBmExSqNxVHhuo1EVL?= =?us-ascii?Q?DN6xiERaf3XeGLTay1z584195a2ndptbO/uWXlzuTAkc4VkGdIrc0L9prEzY?= =?us-ascii?Q?DrO5opOeUfO3v/2tC4qiln3rORdXKlDImaYi4MxBPul4+1+wBkc0z34RJ2ZV?= =?us-ascii?Q?gupfpVODfYYhy8gAm8tlecjuWLHVL9VNCCwWY7AU+wliepTFFFNEPM4Z908D?= =?us-ascii?Q?XhkRmk3yFNc26vjl3Xe+tplp65OFXBR17Ww+y3PIyxvhYVZnPHqb5VzQQZLq?= =?us-ascii?Q?giPuCWCrF5J/ETqjS2wAmTqHT2mskE+q3GEO8jeDikNeAsys8JXi984XcThg?= =?us-ascii?Q?3ug6cYvVwttR2+w++FvhGRow58ZJLbcJAhw0ecb8uCd2A2cpeqP2bkCzAxA5?= =?us-ascii?Q?J/xxCvLGgwMbVULUVpS7LNKy1uR5kDzTIKKzGwkCBBMlIn4yXwX7J5yTQXjh?= =?us-ascii?Q?vPSlVJ5PvHToSkNrKgrsMVWEOf1129ehUxpu9JP2+DqKKm0L8onA9XRMflvv?= =?us-ascii?Q?WDrVIzeTrCll2cvfr1giQ8ETdeAu1nAOKYwveSLVnX/S3GtSYeCWPLVuLkSv?= =?us-ascii?Q?OKyNVRkCTaIlZkeborh1IoxFSozal2WFudP9XlK8H8mntg+LjEw/Qeb6eODS?= =?us-ascii?Q?SyoQ0Ihz8hKaVFvmmaVl/VwRf9GribzH95bnuULXyzIukM7Okg0dAdahiTw0?= =?us-ascii?Q?+J2gCYL/gxBgwe1rRkvuoEFDQzepEvy98K46rYNgnheWduzyjxQ+wM1fYkAD?= =?us-ascii?Q?JWUL36r7EwKowErpkjRgD6wIjf1GhE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D9X3nWSIDXNGG4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4183; 7:XL+JHKvjepX3aaFimssSlFLIDu+R58oFqSlZ7r4EDsgamQHJQhnt4ZNi7JaWDHUKBHb5wOYX8GEPzbEQb2E2G+kGbgN7b9gK/XmyZTYtSN6T8xDGbNHcbdUo0onomzcoXXfUG800DvlsE6Yru9t0jCi3j9Hx0Y/Gh0PI1j2fSHjeTyr0PcIA/S+87gjrYXgffEx3+vIXtCmzlYLIGQt8bcCjG/pkGKbXBVyi+sWVyds3xcUrohwtvp+8A3yl1V2Y X-MS-Office365-Filtering-Correlation-Id: 4e8bdaf8-6f04-4601-d07b-08d5b426f751 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2018 14:29:39.2009 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e8bdaf8-6f04-4601-d07b-08d5b426f751 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR05MB4183 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: , Cc: linux-internal@mellanox.com Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org X-Virus-Scanned: ClamAV using ClamSMTP Offload "tc action mirred mirror" to a device that is a vlan device on top of a front-panel port device. The hardware encapsulates the mirrored packets in a VLAN tag. That includes the case that the mirrored traffic is already VLAN-tagged--in that case the monitor traffic will be double-tagged, just like in the software path. Signed-off-by: Petr Machata --- .../net/ethernet/mellanox/mlxsw/spectrum_span.c | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index 50a1e60..f6b3ca9 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c @@ -235,6 +235,14 @@ mlxsw_sp_span_entry_bridge(const struct net_device *br_dev, return dev; } +static struct net_device * +mlxsw_sp_span_entry_vlan(const struct net_device *vlan_dev, + u16 *p_vid) +{ + *p_vid = vlan_dev_vlan_id(vlan_dev); + return vlan_dev_real_dev(vlan_dev); +} + static __maybe_unused int mlxsw_sp_span_entry_tunnel_parms_common(struct net_device *l3edev, union mlxsw_sp_l3addr saddr, @@ -477,6 +485,57 @@ struct mlxsw_sp_span_entry_ops mlxsw_sp_span_entry_ops_gretap6 = { }; #endif +static int +mlxsw_sp_span_entry_vlan_parms(const struct net_device *to_dev, + struct mlxsw_sp_span_parms *sparmsp) +{ + struct net_device *real_dev; + u16 vid; + + if (!(to_dev->flags & IFF_UP)) + return mlxsw_sp_span_entry_unoffloadable(sparmsp); + + real_dev = mlxsw_sp_span_entry_vlan(to_dev, &vid); + if (!mlxsw_sp_port_dev_check(real_dev)) + return mlxsw_sp_span_entry_unoffloadable(sparmsp); + + sparmsp->dest_port = netdev_priv(real_dev); + sparmsp->vid = vid; + return 0; +} + +static int +mlxsw_sp_span_entry_vlan_configure(struct mlxsw_sp_span_entry *span_entry, + struct mlxsw_sp_span_parms sparms) +{ + struct mlxsw_sp_port *dest_port = sparms.dest_port; + struct mlxsw_sp *mlxsw_sp = dest_port->mlxsw_sp; + u8 local_port = dest_port->local_port; + char mpat_pl[MLXSW_REG_MPAT_LEN]; + int pa_id = span_entry->id; + + mlxsw_reg_mpat_pack(mpat_pl, pa_id, local_port, true, + MLXSW_REG_MPAT_SPAN_TYPE_REMOTE_ETH); + mlxsw_reg_mpat_eth_rspan_pack(mpat_pl, sparms.vid); + + return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mpat), mpat_pl); +} + +static void +mlxsw_sp_span_entry_vlan_deconfigure(struct mlxsw_sp_span_entry *span_entry) +{ + mlxsw_sp_span_entry_deconfigure_common(span_entry, + MLXSW_REG_MPAT_SPAN_TYPE_REMOTE_ETH); +} + +static const +struct mlxsw_sp_span_entry_ops mlxsw_sp_span_entry_ops_vlan = { + .can_handle = is_vlan_dev, + .parms = mlxsw_sp_span_entry_vlan_parms, + .configure = mlxsw_sp_span_entry_vlan_configure, + .deconfigure = mlxsw_sp_span_entry_vlan_deconfigure, +}; + static const struct mlxsw_sp_span_entry_ops *const mlxsw_sp_span_entry_types[] = { &mlxsw_sp_span_entry_ops_phys, @@ -486,6 +545,7 @@ struct mlxsw_sp_span_entry_ops *const mlxsw_sp_span_entry_types[] = { #if IS_ENABLED(CONFIG_IPV6_GRE) &mlxsw_sp_span_entry_ops_gretap6, #endif + &mlxsw_sp_span_entry_ops_vlan, }; static int