From patchwork Fri Jun 24 07:38:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12894040 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25CE5C43334 for ; Fri, 24 Jun 2022 07:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229715AbiFXHit (ORCPT ); Fri, 24 Jun 2022 03:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbiFXHis (ORCPT ); Fri, 24 Jun 2022 03:38:48 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2128.outbound.protection.outlook.com [40.107.94.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3E6056FB3 for ; Fri, 24 Jun 2022 00:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XZvqF1NTTkhiQIY+DX0OFuJQLn7vbQCS34UfgG/PJZNE0GutUC6helJTQ4TAoIzbOPhqilO5bW/n+oBmv//hncbV4s+/cMatgXvbhuILOptI0i7iyH0nwnA7CUnoiF/aqSVJgmv2PTW/tNBbbLBVVmxNkbHR5d7QfhqVM1Fi+ozY7sEEzfvejOY567kG8IRp9UpUE9XIyhxh1TkyaqVBXaW2xYZOYxX/2XUw5mgnAKx9Fh8S3J+ntC00jvQNc1+SG+tXbLwHZCHzNAsDp3caJh2HWTagmWQW4NUFYm9QzFRASamjzvngI/aieayBoNY0MSP4IrvxAzKvHHUzfBTacA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=q1wkKi6Jt3OcQ8ZbxV7yPa83TDDRgZlMKzZyD5DQqRU=; b=McWCTue8Fx10ISSziK6+cKIS5y1Yjta5CclckpOQ86jZ8AHi0qiiIoA0oYzj8Z04NrWx1zVFnl9oDUYtTQ5oFirvxo2YhGeViLAnwcAr1+ApnRsHS+9vQN52URdk7FXw4TlWXaB4AXYfxhM0qHFVx8k0YWMsEYRV+9acyjJl12VKelJHYOBv5TxMs0F9DzvBvBAnRQHFNt3NX5oNzfM9kBkuiUH9i1+ycrZV9+rhhYPfzUzrK04ZN9XZdzkk3WRT7Wf81dUWyb4xATzSFa2yUG3uh9ha0xXyqDLzL0j7SBRwwvuAH88bbkZG2kpNDGyijCSMPIuBPtcFh1Dm613YGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q1wkKi6Jt3OcQ8ZbxV7yPa83TDDRgZlMKzZyD5DQqRU=; b=be+pmqrYC+b2zH5ClVRbWSHuHSFZ0XYRP1OU7s743atL3D9xa94xCazUGz/jM2EnVytI7aF01ZaU+C9mCG9wEqDBj8II3pZNy4v0rh2inN6+hpzM5tBKVNLiP9SGSLDOH2+8HrebPepftehQsteOgvNr4paz7/hLwcZgpI/8d/s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by CY4PR13MB1494.namprd13.prod.outlook.com (2603:10b6:903:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Fri, 24 Jun 2022 07:38:45 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::b18b:5e90:6805:a8fa]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::b18b:5e90:6805:a8fa%6]) with mapi id 15.20.5373.017; Fri, 24 Jun 2022 07:38:45 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com, Fei Qin Subject: [PATCH net-next 1/2] nfp: support vepa mode in HW bridge Date: Fri, 24 Jun 2022 09:38:15 +0200 Message-Id: <20220624073816.1272984-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220624073816.1272984-1-simon.horman@corigine.com> References: <20220624073816.1272984-1-simon.horman@corigine.com> X-ClientProxiedBy: AM9P192CA0003.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::8) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4529ec0a-df6a-47f6-58fc-08da55b491bf X-MS-TrafficTypeDiagnostic: CY4PR13MB1494:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2VGnZuuTZsbXzimPQnSeBhy93qBs8XYqWkajo5xLQEwow+MbMnuDZ7td8EfsXuHfCV3PGAHimMpxSjvy50lR+KgO0yUSbsyGabCTiAHu09AAZsk0JAm3WBGdSuq1ZqvVPKnXmwFx+GCmlwubhLFr/7NROt4uABgtkaRy7KqzXL5ZKJkTBgJ1RfRfUiuw085tFfNkoMgp7EYRWJpCRJbTwQdkHVnONlfvrhanafelHtH//HcUYF5wqZHiEZOKH95aI9o9pMwXEtstdajHGggbXP3TSf17/hdz6AmGdLLXC3fanABdr23GfND0pq4hOHNtXpZPZ4NaTirSZvkYhCSDz6NVpHm3SKf+yn4Tj4M+oPEOQt1E2B9CBob1gs25RfjyQRXzjOFfIGSwfW9cs6kBmA0Q1PErx5xPgD/DsVV+sVe/tMDTeQbvE2vDvvUQOB7qO0rHJCAok3p/vvLUkWji0qlwVB5jRj00/NY6i2ZZxkmLfM+cpirq2msorjKb/KPvFoYNWXd3zg8QnSDbJ4KKVxn20BufsPK9Cc4xL3M6jI+s/Fb4HL1yme/4HvgrPxR5v202BrAl7QjCYf2T+zZZCcJJPGt8V7NdJWvY2IDL74Mh6vkgfSwIIK0mgfGo1VtyoSkaomrdOXvmQX+ZkMfNKN8J+0tePTu0XKTF5brk16DsH4YpBchUianxqOTRqGhFOQaQiKoCeeKNBQZ8NDBkdq3lrlBzCZohlLzDuq4Hwy9f62fDFedC/5Cv+da781bh X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(136003)(39830400003)(366004)(376002)(396003)(346002)(316002)(86362001)(8936002)(83380400001)(110136005)(36756003)(6506007)(186003)(8676002)(6486002)(38100700002)(107886003)(6666004)(478600001)(66946007)(66556008)(6512007)(44832011)(66476007)(52116002)(4326008)(2616005)(1076003)(41300700001)(5660300002)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Mtp7bpfta0Ia5pW1eyJHtLPtMbTvEQeSqRtCRuJixNXlwBU1uYf5D4tWyI87yxn3u4Rc3Y4J7wSbZrKO2PIJAAOszAGsNFp2uIrkQJkbBowhzWjVAtOjZJErATUbt2FyOc1N4jEyJhU9cRRcDf+WuaflzUuC50m0m+XYsxPAkS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RBujBXkMl6noCX01P0e29g7WyA9ZKTUvh6tDJerIH4YgpPR7tW7IQPlIhvDg+pQMRfiU4H1vmKlyjKGnQ8f1WTw/VlGt3ImCjdI/KYpfNxp+LYWoie3PwO4L+GW0wrH1MMn/ZYya/0G/JKXxyJ4innVgXqwluO5D1vDJoB3xR6oTPE8bKyPBNgtTVZHaIGvVtDNqxMbgYM9YDo/QpjH0YEshR0MHDPZt+IjeSIOue+bF6lL2gr72odIk9F2V8k3ujGueP5IxZCRUPpLAqjUKcUbsrlNBHFPTP1qbuWpNYU7D6geAy+v0aJpEhuNTF9p4ZgK8+mwx0LvyZJWVUmV/w7AgiE8VNuHqswvfBRRGpeAnrFkkIOhHzCAbaH6mnnLA6VH8z4RQQKcRRi15wM0Nm5HkuX9QMhMDO1osX3uxc5w2SBJjmnW2F/Q== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4529ec0a-df6a-47f6-58fc-08da55b491bf X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2022 07:38:45.6244 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: B+ctv0C//ZzzRp28qFZ8TUfWHhQc6j/o7oS8m5+YnK5qjq/IZ6h9NwDj8lPrcbLhx1eUcvEJQ/yG/f9V47PTcH+L7WrWzymI8UY0YiFibpM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR13MB1494 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Yinjun Zhang Add support for VEPA mode of HW bridge. The default remains VEB mode. The mode may be configured using ndo_bridge_setlink, and inspected using ndo_bridge_getlink. Signed-off-by: Yinjun Zhang Reviewed-by: Louis Peens Signed-off-by: Simon Horman --- .../net/ethernet/netronome/nfp/nfd3/rings.c | 1 + .../net/ethernet/netronome/nfp/nfdk/rings.c | 2 +- .../ethernet/netronome/nfp/nfp_net_common.c | 71 ++++++++++++++++++- .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 1 + 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfd3/rings.c b/drivers/net/ethernet/netronome/nfp/nfd3/rings.c index f31eabdc0631..f65851ed5b50 100644 --- a/drivers/net/ethernet/netronome/nfp/nfd3/rings.c +++ b/drivers/net/ethernet/netronome/nfp/nfd3/rings.c @@ -251,6 +251,7 @@ nfp_nfd3_print_tx_descs(struct seq_file *file, NFP_NET_CFG_CTRL_CTAG_FILTER | NFP_NET_CFG_CTRL_CMSG_DATA | \ NFP_NET_CFG_CTRL_RINGCFG | NFP_NET_CFG_CTRL_RSS | \ NFP_NET_CFG_CTRL_IRQMOD | NFP_NET_CFG_CTRL_TXRWB | \ + NFP_NET_CFG_CTRL_VEPA | \ NFP_NET_CFG_CTRL_VXLAN | NFP_NET_CFG_CTRL_NVGRE | \ NFP_NET_CFG_CTRL_BPF | NFP_NET_CFG_CTRL_LSO2 | \ NFP_NET_CFG_CTRL_RSS2 | NFP_NET_CFG_CTRL_CSUM_COMPLETE | \ diff --git a/drivers/net/ethernet/netronome/nfp/nfdk/rings.c b/drivers/net/ethernet/netronome/nfp/nfdk/rings.c index f4d94ae0a349..222ee0e5302f 100644 --- a/drivers/net/ethernet/netronome/nfp/nfdk/rings.c +++ b/drivers/net/ethernet/netronome/nfp/nfdk/rings.c @@ -171,7 +171,7 @@ nfp_nfdk_print_tx_descs(struct seq_file *file, NFP_NET_CFG_CTRL_GATHER | NFP_NET_CFG_CTRL_LSO | \ NFP_NET_CFG_CTRL_CTAG_FILTER | NFP_NET_CFG_CTRL_CMSG_DATA | \ NFP_NET_CFG_CTRL_RINGCFG | NFP_NET_CFG_CTRL_IRQMOD | \ - NFP_NET_CFG_CTRL_TXRWB | \ + NFP_NET_CFG_CTRL_TXRWB | NFP_NET_CFG_CTRL_VEPA | \ NFP_NET_CFG_CTRL_VXLAN | NFP_NET_CFG_CTRL_NVGRE | \ NFP_NET_CFG_CTRL_BPF | NFP_NET_CFG_CTRL_LSO2 | \ NFP_NET_CFG_CTRL_RSS2 | NFP_NET_CFG_CTRL_CSUM_COMPLETE | \ diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index 57f284eefeb3..0991fc122998 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1892,6 +1893,69 @@ static int nfp_net_set_mac_address(struct net_device *netdev, void *addr) return 0; } +static int nfp_net_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, + struct net_device *dev, u32 filter_mask, + int nlflags) +{ + struct nfp_net *nn = netdev_priv(dev); + u16 mode; + + if (!(nn->cap & NFP_NET_CFG_CTRL_VEPA)) + return -EOPNOTSUPP; + + mode = (nn->dp.ctrl & NFP_NET_CFG_CTRL_VEPA) ? + BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB; + + return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode, 0, 0, + nlflags, filter_mask, NULL); +} + +static int nfp_net_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, + u16 flags, struct netlink_ext_ack *extack) +{ + struct nfp_net *nn = netdev_priv(dev); + struct nlattr *attr, *br_spec; + int rem, err; + u32 new_ctrl; + u16 mode; + + if (!(nn->cap & NFP_NET_CFG_CTRL_VEPA)) + return -EOPNOTSUPP; + + br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); + if (!br_spec) + return -EINVAL; + + nla_for_each_nested(attr, br_spec, rem) { + if (nla_type(attr) != IFLA_BRIDGE_MODE) + continue; + + if (nla_len(attr) < sizeof(mode)) + return -EINVAL; + + new_ctrl = nn->dp.ctrl; + mode = nla_get_u16(attr); + if (mode == BRIDGE_MODE_VEPA) + new_ctrl |= NFP_NET_CFG_CTRL_VEPA; + else if (mode == BRIDGE_MODE_VEB) + new_ctrl &= ~NFP_NET_CFG_CTRL_VEPA; + else + return -EOPNOTSUPP; + + if (new_ctrl == nn->dp.ctrl) + return 0; + + nn_writel(nn, NFP_NET_CFG_CTRL, new_ctrl); + err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_GEN); + if (!err) + nn->dp.ctrl = new_ctrl; + + return err; + } + + return -EINVAL; +} + const struct net_device_ops nfp_nfd3_netdev_ops = { .ndo_init = nfp_app_ndo_init, .ndo_uninit = nfp_app_ndo_uninit, @@ -1919,6 +1983,8 @@ const struct net_device_ops nfp_nfd3_netdev_ops = { .ndo_bpf = nfp_net_xdp, .ndo_xsk_wakeup = nfp_net_xsk_wakeup, .ndo_get_devlink_port = nfp_devlink_get_devlink_port, + .ndo_bridge_getlink = nfp_net_bridge_getlink, + .ndo_bridge_setlink = nfp_net_bridge_setlink, }; const struct net_device_ops nfp_nfdk_netdev_ops = { @@ -1946,6 +2012,8 @@ const struct net_device_ops nfp_nfdk_netdev_ops = { .ndo_get_phys_port_name = nfp_net_get_phys_port_name, .ndo_bpf = nfp_net_xdp, .ndo_get_devlink_port = nfp_devlink_get_devlink_port, + .ndo_bridge_getlink = nfp_net_bridge_getlink, + .ndo_bridge_setlink = nfp_net_bridge_setlink, }; static int nfp_udp_tunnel_sync(struct net_device *netdev, unsigned int table) @@ -1993,7 +2061,7 @@ void nfp_net_info(struct nfp_net *nn) nn->fw_ver.extend, nn->fw_ver.class, nn->fw_ver.major, nn->fw_ver.minor, nn->max_mtu); - nn_info(nn, "CAP: %#x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + nn_info(nn, "CAP: %#x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", nn->cap, nn->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "", nn->cap & NFP_NET_CFG_CTRL_L2BC ? "L2BCFILT " : "", @@ -2012,6 +2080,7 @@ void nfp_net_info(struct nfp_net *nn) nn->cap & NFP_NET_CFG_CTRL_MSIXAUTO ? "AUTOMASK " : "", nn->cap & NFP_NET_CFG_CTRL_IRQMOD ? "IRQMOD " : "", nn->cap & NFP_NET_CFG_CTRL_TXRWB ? "TXRWB " : "", + nn->cap & NFP_NET_CFG_CTRL_VEPA ? "VEPA " : "", nn->cap & NFP_NET_CFG_CTRL_VXLAN ? "VXLAN " : "", nn->cap & NFP_NET_CFG_CTRL_NVGRE ? "NVGRE " : "", nn->cap & NFP_NET_CFG_CTRL_CSUM_COMPLETE ? diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h index 8892a94f00c3..9007675db67f 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h @@ -94,6 +94,7 @@ #define NFP_NET_CFG_CTRL_IRQMOD (0x1 << 18) /* Interrupt moderation */ #define NFP_NET_CFG_CTRL_MSIXAUTO (0x1 << 20) /* MSI-X auto-masking */ #define NFP_NET_CFG_CTRL_TXRWB (0x1 << 21) /* Write-back of TX ring*/ +#define NFP_NET_CFG_CTRL_VEPA (0x1 << 22) /* Enable VEPA mode */ #define NFP_NET_CFG_CTRL_VXLAN (0x1 << 24) /* VXLAN tunnel support */ #define NFP_NET_CFG_CTRL_NVGRE (0x1 << 25) /* NVGRE tunnel support */ #define NFP_NET_CFG_CTRL_BPF (0x1 << 27) /* BPF offload capable */ From patchwork Fri Jun 24 07:38:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12894041 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BD32C433EF for ; Fri, 24 Jun 2022 07:38:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbiFXHiy (ORCPT ); Fri, 24 Jun 2022 03:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbiFXHiu (ORCPT ); Fri, 24 Jun 2022 03:38:50 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2128.outbound.protection.outlook.com [40.107.94.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3F0B56F9F for ; Fri, 24 Jun 2022 00:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ISAC9E7QXaaufP/RwXqWdbJFOFJvv0e0KErCdNVoGT73HobTSi8oFaSz/aW/BGvaBDrgSTGd65tUlB2Es7oPVfIQFOYtQlen+4A+H90OxNQSqeupsLIsBBwD9zjkzvPgi+egwX/XxmKWskZgWI2eNlY3GfbgpkmI2Bw73wMEvE64WHu/VAjeaJoKb133jHKocVVovP/hK6AMvMgETyD7sz2cLwYKZs35qvMISGCFjWSKvjvl/XCfcvubEYTFxdUZ9S+AeopIZd3HZr18ThQTQwydI9BmZwFcgUnerQgtmGYyE8fZ6ViWUBfsxXWbi5dOQYOGP2sKIxMyZfVvLW7e/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gZejlmLIBHfnyvwsVTnXcxFejPmCH71U2zXD/NWI5o0=; b=BNEEKcpufIcYB+pl2pYAp+yztD4tthoY97KAgx8qA7hbmOVdUsDtMrjkiA9SePe46kKJy4NyLHqON7kOcYzLKDC4cUqoeGabWxLeSQfOhROm1pagGPwcvdYY2j4nnYeeTVFkCtBBMANNDRr0eh/IsAP4ssfnyJsq4ol9xoSyJmDVIBD+k4hKfnVFrQkUuFnBfQzJn8sXiU4ST0iVtPZTzSqtT4rq9np8r47Ip21QhS2oT/UsTfS6Ud8TxDap2shpuIdlKhw+lufEG1x4us//RVMOxxqol1Ku3zVjhkYpRfM6q8/tAa6vo7EFzxkRsyY6Wbb8p1/5PVDvqQ9AKqcIGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gZejlmLIBHfnyvwsVTnXcxFejPmCH71U2zXD/NWI5o0=; b=kcAQsReh/PENy1fUv0P4W3GXqXMfM6rAeWFlgkqBDurLRFT+FnFJPb6zoJFFOBDOuYEM9LhuJQbnk6cB+seXi4tBAA9ZPW2O5Z1K08BNeWLFTk4SHgqn1NwGUljuAPCfwodifW9sWtkvqYnCec3oqQx4CYb5cesJVMtKHi1Z2ss= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by CY4PR13MB1494.namprd13.prod.outlook.com (2603:10b6:903:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Fri, 24 Jun 2022 07:38:47 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::b18b:5e90:6805:a8fa]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::b18b:5e90:6805:a8fa%6]) with mapi id 15.20.5373.017; Fri, 24 Jun 2022 07:38:47 +0000 From: Simon Horman To: David Miller , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, oss-drivers@corigine.com, Fei Qin Subject: [PATCH net-next 2/2] nfp: add support for 'ethtool -t DEVNAME' command Date: Fri, 24 Jun 2022 09:38:16 +0200 Message-Id: <20220624073816.1272984-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220624073816.1272984-1-simon.horman@corigine.com> References: <20220624073816.1272984-1-simon.horman@corigine.com> X-ClientProxiedBy: AM9P192CA0003.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::8) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4c6288b1-5154-4bea-5b3b-08da55b492ab X-MS-TrafficTypeDiagnostic: CY4PR13MB1494:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BlE29N2Uki+0dztadIexzuSKAL7JS5WMWxpuX9zGTWGEQcJCygbsowxr7Vw9dIhfJpBGdytRWfRZAxoOSOt0H2EJgnenZTfADwUrmwF6NH2hnCCgKZBEphJM8kjB60h0rFBm3nD3v/o1xlPeeH36cxa7zsYqNZtp2ZEiqGZ+wkINDx9U4TfnwabNpKXweIzcSkdukF1L8j8qRDqVxhxFrZE6iiwurlMRjs1PECLznkiNxQJvVACzUZMJ4nLsaGX1IU9rSbMCHRnXG3FaEECcx9odJwf0BAVmRtM+JGx+UJU3eaMkg+HHY+lWtGY80SvEOB+q5/4cv3jJS5hWCjiD9JwwAcqq86Ic0WspXzHoZ8+5jziyTOoxTqYkOac7LDxyY+8GLBm3AuhL1083RsBo3CL3zEarMj/HStcqRoXWKAeeOBMw6vQO0Q+bStdjrcfo9I13+Ef5jKQbclFl87Y+NtAvGx4xCwjshNfVb5rIv8f34nPQ6CbjnGtfc6q89LvyJqpQSG/nkr43H/J9pTwnqQIXLmoRLf4PtSicLF0/jkbpSgE4r4qoLSUFQvs/YTAc5edmzyMYYr1ffsPpOav7wlU5SmDsBJInjE6i8yRjRuf+Y+zukdlPRzgPqOq3x8uJ28VisWuwlKoRw7+FxA4VbOQhLcBZlpQNsYS3jumXYHSGR9MU26X8JMxZxXEh9e3+wtu3yX6Aps+2E6jhFOUQ5KWcWxEEkJoYOJcy75CYWao= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(136003)(39830400003)(366004)(376002)(396003)(346002)(316002)(86362001)(8936002)(83380400001)(110136005)(36756003)(6506007)(186003)(8676002)(6486002)(38100700002)(107886003)(6666004)(478600001)(66946007)(66556008)(6512007)(44832011)(66476007)(52116002)(4326008)(2616005)(1076003)(41300700001)(5660300002)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FotAKH0eQULFMegekPlEeYfyHZWVabqgnHWyhLC+oky7FVmAzK4BH4ak6G5qq2L/fDZOp1L4Lj+DskMTa2oaSWAHajAeZHwvrK6zFJdcW4RTzyxjw7slz7Qnjhy8fAeP+ysOJHvxUwItM6OYKpTxFqEH3/HoNoIMUYHY/XThQ6/EGdmQtk8H5h4+ZFao0kYHEIkuV11ASb3owgmByIRuB5wGg7Xhn6w28/Jggis3prFUtn/AA18ZvtA4pc1+vL+iafu2KzrFef3HgVSHYRzyXH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Y/KNshlGZuZ4+i7nBA8zMsH8xAo9htSmi15p3soB3SafPU1YCAHOBlTk9VvmTarMwQuzcMk7ZupyPznKsB0HmLNYnEb1I2DLK8R+ze7imkuwpry32SOYCndhJzW7TOpFI+8MWV1fCVIcapcsWn3/JURnEaaiy5IhDcVT5oUGafvRpaYLigdUN0m4qHo80X54YRD/4HC29WSBcyuLEmTG8EaUKn7KjRbs+JYI9rYfuTZuibB0r+3cOkhYeS9YQBxAB8CAQObyq2XoY30LPLF90rh4Q/gDwvhNf/tmzVyJuUzSBGPMB2WJg16eM8FYJABCMg== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c6288b1-5154-4bea-5b3b-08da55b492ab X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2022 07:38:47.1723 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 955V+V1+IbBNsWJMuy2Mjd/7/FUnwuQSnA/cx9fpQX63pl504Rk9cjstPB0CUjPDH1HhvMpUGiYr1GS1580YiUNR3PgvTXxZnAbhiQEIUtc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR13MB1494 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Fei Qin Add support for ethtool selftest. e.g. # ethtool -t DEVNAME test result like: The test result is PASS The test extra info: Link Test 0 NSP Test 0 Firmware Test 0 Register Test 0 Signed-off-by: Fei Qin Reviewed-by: Louis Peens Signed-off-by: Simon Horman --- .../ethernet/netronome/nfp/nfp_net_ethtool.c | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c index 7475b209353f..c922dfab8080 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c @@ -29,6 +29,7 @@ #include "nfp_net_dp.h" #include "nfp_net.h" #include "nfp_port.h" +#include "nfpcore/nfp_cpp.h" struct nfp_et_stat { char name[ETH_GSTRING_LEN]; @@ -442,6 +443,160 @@ static int nfp_net_set_ringparam(struct net_device *netdev, return nfp_net_set_ring_size(nn, rxd_cnt, txd_cnt); } +static int nfp_test_link(struct net_device *netdev) +{ + if (!netif_carrier_ok(netdev) || !(netdev->flags & IFF_UP)) + return 1; + + return 0; +} + +static int nfp_test_nsp(struct net_device *netdev) +{ + struct nfp_app *app = nfp_app_from_netdev(netdev); + struct nfp_nsp_identify *nspi; + struct nfp_nsp *nsp; + int err; + + nsp = nfp_nsp_open(app->cpp); + if (IS_ERR(nsp)) { + err = PTR_ERR(nsp); + netdev_info(netdev, "NSP Test: failed to access the NSP: %d\n", err); + goto exit; + } + + if (nfp_nsp_get_abi_ver_minor(nsp) < 15) { + err = -EOPNOTSUPP; + goto exit_close_nsp; + } + + nspi = kzalloc(sizeof(*nspi), GFP_KERNEL); + if (!nspi) { + err = -ENOMEM; + goto exit_close_nsp; + } + + err = nfp_nsp_read_identify(nsp, nspi, sizeof(*nspi)); + if (err < 0) + netdev_info(netdev, "NSP Test: reading bsp version failed %d\n", err); + + kfree(nspi); +exit_close_nsp: + nfp_nsp_close(nsp); +exit: + return err; +} + +static int nfp_test_fw(struct net_device *netdev) +{ + struct nfp_net *nn = netdev_priv(netdev); + int err; + + err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_GEN); + if (err) + netdev_info(netdev, "FW Test: update failed %d\n", err); + + return err; +} + +static int nfp_test_reg(struct net_device *netdev) +{ + struct nfp_app *app = nfp_app_from_netdev(netdev); + struct nfp_cpp *cpp = app->cpp; + u32 model = nfp_cpp_model(cpp); + u32 value; + int err; + + err = nfp_cpp_model_autodetect(cpp, &value); + if (err < 0) { + netdev_info(netdev, "REG Test: NFP model detection failed %d\n", err); + return err; + } + + return (value == model) ? 0 : 1; +} + +static bool link_test_supported(struct net_device *netdev) +{ + return true; +} + +static bool nsp_test_supported(struct net_device *netdev) +{ + if (nfp_app_from_netdev(netdev)) + return true; + + return false; +} + +static bool fw_test_supported(struct net_device *netdev) +{ + if (nfp_netdev_is_nfp_net(netdev)) + return true; + + return false; +} + +static bool reg_test_supported(struct net_device *netdev) +{ + if (nfp_app_from_netdev(netdev)) + return true; + + return false; +} + +static struct nfp_self_test_item { + char name[ETH_GSTRING_LEN]; + bool (*is_supported)(struct net_device *dev); + int (*func)(struct net_device *dev); +} nfp_self_test[] = { + {"Link Test", link_test_supported, nfp_test_link}, + {"NSP Test", nsp_test_supported, nfp_test_nsp}, + {"Firmware Test", fw_test_supported, nfp_test_fw}, + {"Register Test", reg_test_supported, nfp_test_reg} +}; + +#define NFP_TEST_TOTAL_NUM ARRAY_SIZE(nfp_self_test) + +static void nfp_get_self_test_strings(struct net_device *netdev, u8 *data) +{ + int i; + + for (i = 0; i < NFP_TEST_TOTAL_NUM; i++) + if (nfp_self_test[i].is_supported(netdev)) + ethtool_sprintf(&data, nfp_self_test[i].name); +} + +static int nfp_get_self_test_count(struct net_device *netdev) +{ + int i, count = 0; + + for (i = 0; i < NFP_TEST_TOTAL_NUM; i++) + if (nfp_self_test[i].is_supported(netdev)) + count++; + + return count; +} + +static void nfp_net_self_test(struct net_device *netdev, struct ethtool_test *eth_test, + u64 *data) +{ + int i, ret, count = 0; + + netdev_info(netdev, "Start self test\n"); + + for (i = 0; i < NFP_TEST_TOTAL_NUM; i++) { + if (nfp_self_test[i].is_supported(netdev)) { + ret = nfp_self_test[i].func(netdev); + if (ret) + eth_test->flags |= ETH_TEST_FL_FAILED; + data[count++] = ret; + } + } + + netdev_info(netdev, "Test end\n"); +} + static unsigned int nfp_vnic_get_sw_stats_count(struct net_device *netdev) { struct nfp_net *nn = netdev_priv(netdev); @@ -705,6 +860,9 @@ static void nfp_net_get_strings(struct net_device *netdev, data = nfp_mac_get_stats_strings(netdev, data); data = nfp_app_port_get_stats_strings(nn->port, data); break; + case ETH_SS_TEST: + nfp_get_self_test_strings(netdev, data); + break; } } @@ -739,6 +897,8 @@ static int nfp_net_get_sset_count(struct net_device *netdev, int sset) cnt += nfp_mac_get_stats_count(netdev); cnt += nfp_app_port_get_stats_count(nn->port); return cnt; + case ETH_SS_TEST: + return nfp_get_self_test_count(netdev); default: return -EOPNOTSUPP; } @@ -757,6 +917,9 @@ static void nfp_port_get_strings(struct net_device *netdev, data = nfp_mac_get_stats_strings(netdev, data); data = nfp_app_port_get_stats_strings(port, data); break; + case ETH_SS_TEST: + nfp_get_self_test_strings(netdev, data); + break; } } @@ -786,6 +949,8 @@ static int nfp_port_get_sset_count(struct net_device *netdev, int sset) count = nfp_mac_get_stats_count(netdev); count += nfp_app_port_get_stats_count(port); return count; + case ETH_SS_TEST: + return nfp_get_self_test_count(netdev); default: return -EOPNOTSUPP; } @@ -1517,6 +1682,7 @@ static const struct ethtool_ops nfp_net_ethtool_ops = { .get_link = ethtool_op_get_link, .get_ringparam = nfp_net_get_ringparam, .set_ringparam = nfp_net_set_ringparam, + .self_test = nfp_net_self_test, .get_strings = nfp_net_get_strings, .get_ethtool_stats = nfp_net_get_stats, .get_sset_count = nfp_net_get_sset_count, @@ -1550,6 +1716,7 @@ const struct ethtool_ops nfp_port_ethtool_ops = { .get_link = ethtool_op_get_link, .get_strings = nfp_port_get_strings, .get_ethtool_stats = nfp_port_get_stats, + .self_test = nfp_net_self_test, .get_sset_count = nfp_port_get_sset_count, .set_dump = nfp_app_set_dump, .get_dump_flag = nfp_app_get_dump_flag,