From patchwork Tue May 8 16:02:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10386445 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 14478602C2 for ; Tue, 8 May 2018 16:02:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0388228CEE for ; Tue, 8 May 2018 16:02:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC3D7289BF; Tue, 8 May 2018 16:02:58 +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 15EE8289BF for ; Tue, 8 May 2018 16:02:58 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40gPQl6ZZhzF1lS for ; Wed, 9 May 2018 02:02:55 +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="bxBpU3Rh"; 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.1.62; helo=eur01-ve1-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="bxBpU3Rh"; dkim-atps=neutral Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0062.outbound.protection.outlook.com [104.47.1.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40gPQd4hQCzF1TN for ; Wed, 9 May 2018 02:02:49 +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=Uqopor9wI9VZa1pznsS9d3HgNz6N4lyNvPhUaa3gWnc=; b=bxBpU3RhLvZWsrgI/wwIjlejeIMHJS5iiQAQdVoWu+Y4Z2TZCL/lNBRVgIg2W1WUwIx/iSSPbPjo6TZnZqXkwWxdVGJzaF+4MOZ/YH85IZjrgOoDZrHj7Mvb8M53Tgn6nzPYDsf6Pux9RkJbR6hijqvOWB6cEd2qBBlBXYJMn9s= Received: from t540p (78.45.160.211) by AM0PR05MB4177.eurprd05.prod.outlook.com (2603:10a6:208:57::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.735.17; Tue, 8 May 2018 16:02:43 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw v2 3/4] mlxsw: spectrum_span: Support mirror-to-VLAN In-Reply-To: References: Message-Id: <6688cd2b53069898f310032bc2be9197e85244b0.1525792392.git.petrm@mellanox.com> Date: Tue, 08 May 2018 18:02:38 +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: VI1P189CA0011.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::24) To AM0PR05MB4177.eurprd05.prod.outlook.com (2603:10a6:208:57::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(2017052603328)(7153060)(7193020); SRVR:AM0PR05MB4177; X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4177; 3:uyWQ2XtullnutHP+GxqgqvkKR7L484mLggkzlDym8kYQkgGPYm2vdyu8wC+Z9u+awuRi5o/bxBD4fL/16wj4PUCcwCu0zg/vV4X/GMlEyv4lx1+z1+cyzyru2snljMDAlB6w2W8P1IN/szejq3HSjkxMBVw4qbcd/eemuZD77/49kmnA/kgsxgokF/ZZY77CNPnzROTmVkWynRi7SBa03VaO1Mhmj/+ieP43Rqhwwfq7xVQV6IDKqmOTjB3FwNTG; 25:TTQYSftYAZPNl/pvY/TvPMKlTmGjUME3j9RJCEHVA/u/1zH5QYO0C6mJviqn8/zrwWM8/MztddD0XNp0DDr0tu3GRfL4o/Y9GScO9tEySmYg+pixtSA3cOn8SOflfQ+H+puiKC3xEjXl/Qtb9NJuZtksQu6kzrBOM2QPFl76r+tmjHHkx9vXNkF/u4cktFAtfWYOcgwPAzxYQG6+HkwhtHiaSilbjZrBebl05sqYnI8AsDBkfyjubrkuj4H949I2MEFHpxESKuWxb69wWIJcribgxTzFve1Tb7Md/3XdBL/V9g0pYHGQl9K1FNsjuomWhRjj176qwxiAl/D93Q+Cfg==; 31:h9L++Qe9YEJFO1qduopnaCCIiiPbNb6jk9zjtRjZqmuncJDKQxrys7/yjinV62vy5YchpzJWoKKbgGUB6XSKn5WevcA0sP0DDtnX7dv4dyoHVwfajYvJtTkUzCHvMKTPAtg2cmjADAX/ygmOpcp8yV8dVpP7meoNV+XXoM1okEvJrOKGnus9Co3/dDwGaB85ujvDgKuNaDyBZc8kiEBbhEDQzRaE2098JzyvFcPhnj0= X-MS-TrafficTypeDiagnostic: AM0PR05MB4177: X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4177; 20:S48gUZvfOg2y0lxO7hNA7e1DersSUZ2XlGCceFxsl1rspi9Ka7hC5jSka7GraGFEwKLgMJvXaRsggkmj6BgUHO0wqStm2kOwS9vfVBEz7bY6zXK8jgOwW/Uk5rzgnisfyNCXIJHMHg3o4as/HP0gYqe5UsY4gigm2ToafSz97M62tKUsq36oohOxxmyVqZM8aCF3LdXwyM8aW8AOU89ELIYg+qZyKxtsRHOR41ysvjdsyFdffQykKsS8DvhHOcO+du3T4BJ2+/DEHJR/zTTHuidrShRUHezHDc7aVaOhGDG+JZEPmOW3gTjKb03OU/0YVGJJl1BmnVZr+Wmc4VSLhj1SWSnhfuMlGAWWNaPmEAli3zOWhCy7PeXPmlYeOfSb0lmnUh7vGlIv9BHwdbK2wRl4VVqScr4ptTYflV70JE/wOVBxZwpLlNCJvnqwga+sPT6OkD0AeLhGNdra9/Gw/XrrmQpRN/xHE5Igz/TIIttrMdlV+nN8qqJXjJ4bpGa9; 4:NgNn/buoUExc/55MNfaUSIj/liEW2Nq9zF+KvdbFfXVnzs6+lrtus2nC4GVjpehMrXCX+PkYWpFTbX7mjSkDTH4hKZ4n0Ogfu0qm4Ax0DMJ7lkwwUATwguV1yDkjtVTl0EGmnZd5T9q5J8uS2jOjzbeZWtPcSW/N8999P1xvD0rLXppRewmgSt0vBgjpoyJ2DcI/7FhJfYU96LO6ESDRIcms9PpWAXkPka1B9HdtvtvGwnf+Liu2zyht/+fw9GICqgn/gRU+XUe9SJkisVIrRA== 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)(3231254)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM0PR05MB4177; BCL:0; PCL:0; RULEID:; SRVR:AM0PR05MB4177; X-Forefront-PRVS: 0666E15D35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(366004)(396003)(376002)(346002)(189003)(199004)(6496006)(25786009)(86362001)(478600001)(53936002)(107886003)(16586007)(47776003)(5660300001)(97736004)(6346003)(105586002)(6116002)(3846002)(386003)(58126008)(4326008)(51416003)(26005)(52116002)(76176011)(2906002)(106356001)(66066001)(16526019)(6666003)(2351001)(2616005)(50466002)(7736002)(476003)(36756003)(305945005)(8936002)(6486002)(8676002)(81166006)(81156014)(486006)(956004)(11346002)(118296001)(446003)(6916009)(48376002)(68736007)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB4177; 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) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR05MB4177; 23:26n9bYWimhbBueY0enhwtZoaEGmxtCmNZ0nZKS/8N?= =?us-ascii?Q?WFzFGHtM/bNaa35uaCe6XB+bHCx1oyK2FvZR6ZWlF7MYV0Rzod72h2+pzHlv?= =?us-ascii?Q?5u0uDGFuQs0DtPdVdoEVMJEUTwTnkhXXNHpZY9ff9i/KZS3fStDg34rK5SjK?= =?us-ascii?Q?ujeWzTv0Zidof3FRTU73f8haiTmRl0Ug+rgiBibmjQuJrEBTeAjLnhOhC2l+?= =?us-ascii?Q?3PKVhBRjG4kWNuMFiHawfnB7S5PKB4iurp4nUZ0txv3sN1YczStz1BofgeLt?= =?us-ascii?Q?1D8YnSVaucxVYx6PkwdhjEdoW9rU2Uk++LRVjuZGw5fT+rj2bETITnEulryy?= =?us-ascii?Q?1ushQMQeALxDc9DEyGhxlry+9G084jinod+L208uXZffIpFqxLBrVxnRaDNw?= =?us-ascii?Q?IJyv4qy3JqY/zaojKIAsthkCSxAsKlBt39AAdi9VpjSGsefTI9jlUlGdx+XI?= =?us-ascii?Q?bMP+9Q2XEjLvP1UD2vyrYj4O/AIHUAltYJWlc0MW3sIJmYHYlh4ttw3cSH6y?= =?us-ascii?Q?lqrIcgvAif8kJg4KphjCls0n89KzLlbqUjBw8022PiotWphcGfSlgHyioMdH?= =?us-ascii?Q?lMULctFzUA8cHy2SyYV0sLxqNQCFmL4FQtXhRWjvv9Mt/ckvP/IiD196eAEL?= =?us-ascii?Q?ybLm78RZD6vj6DDa9vSrd3n0X2i8PyaXwciPRIPT760kbyQYFxvWJW1M8Oog?= =?us-ascii?Q?0SOCKCXe1i+KIpgqb7YbX5qftLsBVZ1i4dNd/AhJV/nJLDgKH+ADYcJYb3NT?= =?us-ascii?Q?d0T2YUEKuTpLO9qThRNeIBTlDbXajlsBTgsI2fTICZ163mQypvwVR8rsRtd9?= =?us-ascii?Q?DP3iHGkEPyNRCUbT/8ktYMXa0zt37T/x4a7H+GAlSHRJiB90avIKCOg/it6R?= =?us-ascii?Q?SYxZMuJdif1yqQXlIvlZaURIRXZdoRi3nJ8+XEsRZ21Uvvx7m6AUI9BD1a6I?= =?us-ascii?Q?8FyJSxcjAsEWpV043WR6ZXYzxTp792AyhtyiC67/qJlI8c/3yiT0MjZtQ+6o?= =?us-ascii?Q?EQaQQ40rFywnhpaI/ImV1Sotqq455+79eq0zNRwQvgGFkagSRugGnZIZmGVb?= =?us-ascii?Q?88KlBC5T9kw4Guc9WQOPv13QSeFvMbqdmW8d2k6PVXDncJ5DjYY6BVvch4pv?= =?us-ascii?Q?QgHBH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A2IheptHXRbpNSFSptV8rpOKYI44eUFGcOqLoFhyLzeUPqjkbjdeaLlZe2CwG53XYeBjHdRXQkXa8EydVEc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4177; 7:4+kdwwK4opv71873DQ4sOf0+zH6qrQG8qmzV+laK05QtoXdH6EF0E4tFwqCVrO05TIbPpZv5pa+YC+RoZHvzrDAy1ew3avlDs+4GxYKblg7CpMz482JIUQInL41GN80A25suLOFixAxCl3mWTBEnyvdc+ligCwTRjUFUvli1dX7kEnkUGmUhHTZkxInNhVT5undTVopzqz+6UpReyhhX2SNAYI30ylideYgbe1IlZQRauh9h4JJqxMMGK96YSH06 X-MS-Office365-Filtering-Correlation-Id: b9723d5a-7e3e-4d57-9d82-08d5b4fd225d X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2018 16:02:43.7360 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9723d5a-7e3e-4d57-9d82-08d5b4fd225d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4177 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 | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c index cd9071e..d90582e 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,61 @@ struct mlxsw_sp_span_entry_ops mlxsw_sp_span_entry_ops_gretap6 = { }; #endif +static bool +mlxsw_sp_span_vlan_can_handle(const struct net_device *dev) +{ + return is_vlan_dev(dev) && + mlxsw_sp_port_dev_check(vlan_dev_real_dev(dev)); +} + +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); + 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 = mlxsw_sp_span_vlan_can_handle, + .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 +549,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