From patchwork Tue Nov 8 17:24:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036574 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 67F3AC433FE for ; Tue, 8 Nov 2022 17:26:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234488AbiKHR0X (ORCPT ); Tue, 8 Nov 2022 12:26:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234504AbiKHR0R (ORCPT ); Tue, 8 Nov 2022 12:26:17 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2079.outbound.protection.outlook.com [40.107.100.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F7F84C24B for ; Tue, 8 Nov 2022 09:26:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VDY9b81rMY6mw+Ky6Iur2eccZbfz6KvVBA2D0gMsMup4S7tytJzBoucrJzZofQPc8wJr/zyVtWj9dLJGjUu9A5pXm+JUhKOLX2YpI6RK8/aygVenC89IVXpByW6LICIBIj/d/frU72zqLZ0T6nWlYx+CidxmaauknUar6og/apEgQI2MWeDPu1Jv6jiml1hWcLGL9mQbQ/V+1J/qGCU8hImKQEN72YxZHEtoOa5mwYLVOBSuHhuCRFut4uM8ubkECBnFhKgvlrfa5NNZxr6yTTWGMwn8S/zNkIZlWesfKf6/yG2VVjEFOogVWJULATMxkneAZdRpL7IEr2GzMg6axQ== 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=TK8+jJEsnxXYC4XXgI4jJ5mB8zMC0i8kdqzlaOpGhJM=; b=ej6wpan1HSETikLxiqM8iDIwryo5pnOb7gKo5viTDb+PxWODnZrzyAJs+DfqTk2Z8NjF+w/q2vSSGxeJnp/XGLO8nsep3MGuaECwuOvD5yujYLZ2Z/nKY0ATN9nIrfswTNW0YN4F3NXg0wWIpzUaW1Aps5whmC2z4xqRyMPnz5xwG9NhLwS1mt59J7NftKNfJf+NsRoEGL/1to8cTpXgEoJ4MYx2o7HksHwW28qH9QtL0DfTNVQLdBU/d4B+xiQYkErRBEkQM9iioOmKTbqwlweEE4wkBgcchAodsz0Rk6mzT7V1O+8Ztj/7JG/eH7tvgZG+RCSR6ctpjQP0tZwyag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TK8+jJEsnxXYC4XXgI4jJ5mB8zMC0i8kdqzlaOpGhJM=; b=3feCc7dWmeawmHdTZ7bK2O0mTbDacPk7ltE/c8yby49tCLBM9dkhXUC+MtxzOJQ07dHDYvuopKzp7mSWbUj6eeBtbk/k4+5nDvXwX8Tvgxk9CLbUCL8ZNOCvcLzA+LQKadgL91kuBPSEsV2mUCIAzo6gKaloLfTbHF/lwaayhDY= Received: from MW4PR04CA0298.namprd04.prod.outlook.com (2603:10b6:303:89::33) by BY5PR12MB4210.namprd12.prod.outlook.com (2603:10b6:a03:203::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Tue, 8 Nov 2022 17:26:13 +0000 Received: from CO1NAM11FT077.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::96) by MW4PR04CA0298.outlook.office365.com (2603:10b6:303:89::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27 via Frontend Transport; Tue, 8 Nov 2022 17:26:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT077.mail.protection.outlook.com (10.13.175.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5813.12 via Frontend Transport; Tue, 8 Nov 2022 17:26:12 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:12 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:26:12 -0800 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:10 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 01/11] sfc: add ability for an RXQ to grant credits on refill Date: Tue, 8 Nov 2022 17:24:42 +0000 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT077:EE_|BY5PR12MB4210:EE_ X-MS-Office365-Filtering-Correlation-Id: c058736e-e871-4f4a-e741-08dac1ae5597 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /pP0Q+Gw6ddS68tH8NxM3rVlxCepCOGyTBpFjMtx+FC770pwnWaMeqa3kxE5LySvRVvMrl+JDERlV+vNp7filv8ECkdfakCG/BVx+fd5+mabmS1fFSOXixsask9uiG2pj6sbKJVJZI75KGSsadAdUjLxJD8G4jFdyjN8nCCs5AF+2jtO30OmHNe+aXAhhCf2NeUD7X5yDWuWfZ+pMVO9cntPHShEE6jrzw+AOOQ00zEuFIjLQOv63aSlgP4ALusg0h+/7VrFVB4dcOWf9j7a6fjtUGWJN3RE2toqd/LOAqVFk2jizQ2Y7hk6C2tbH0PFRkJsfEhwa18+wm44ZoBW0sxQFizIPHmxNgNHNost/bTaK5ym3+3VXMt9qcFUEpPFI2spUF5XJFA1P6b9vZ+fU/MSNL5+VLwkHc/N5s8scQW8EvIrkB3rN0iB9l7qqBB/MQ/vuo+3n/nardTUk0Qh6VBeAg9wXehKj9AeZ5XfBC+EK+omyLlfMNNiRhYMwN91TdaUgjPlL7ZSQbi+dFEYrBY+YXnQsSSlFIrRB8iKqLvqrUfmeMpxMGJUfrzmIOcx9Ut+6RfRj1fASoq1yRQUSysG2x+4NyP12gKod7TCxlLRZHYB8V6mcHb0b3zVcS92hCpPypI5uy7ztxOVLqCmRF3RvOHdsxpLXv9Gm5xcTeMAg4wFqenzPSEPbGNT6PFjAkeLzj7cmKGwDZq0ut8fTggxiJHdxFy/h48QGNEiTQ0F8dVb9WXcS+FYDT0EcJdeyV+CySXwC2dGv6A9Yfvt5E97zOBe3E/QLwV4l5OSYJw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(136003)(39860400002)(346002)(451199015)(46966006)(40470700004)(36840700001)(9686003)(70206006)(70586007)(4326008)(36756003)(8676002)(26005)(8936002)(40460700003)(5660300002)(356005)(41300700001)(316002)(6636002)(110136005)(83380400001)(2876002)(54906003)(55446002)(86362001)(36860700001)(82740400003)(186003)(336012)(81166007)(426003)(2906002)(82310400005)(478600001)(47076005)(40480700001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:12.9272 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c058736e-e871-4f4a-e741-08dac1ae5597 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT077.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4210 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree EF100 hardware streams MAE counter updates to the driver over a dedicated RX queue; however, the MCPU is not able to detect when RX buffers have been posted to the ring. Thus, the driver must call MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS; this patch adds the infrastructure to support that to the core RXQ handling code. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/ef100_rx.c | 14 +++++++++++--- drivers/net/ethernet/sfc/net_driver.h | 8 ++++++++ drivers/net/ethernet/sfc/rx_common.c | 3 +++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef100_rx.c b/drivers/net/ethernet/sfc/ef100_rx.c index 65bbe37753e6..24db44210acc 100644 --- a/drivers/net/ethernet/sfc/ef100_rx.c +++ b/drivers/net/ethernet/sfc/ef100_rx.c @@ -183,24 +183,32 @@ void efx_ef100_ev_rx(struct efx_channel *channel, const efx_qword_t *p_event) void ef100_rx_write(struct efx_rx_queue *rx_queue) { + unsigned int notified_count = rx_queue->notified_count; struct efx_rx_buffer *rx_buf; unsigned int idx; efx_qword_t *rxd; efx_dword_t rxdb; - while (rx_queue->notified_count != rx_queue->added_count) { - idx = rx_queue->notified_count & rx_queue->ptr_mask; + while (notified_count != rx_queue->added_count) { + idx = notified_count & rx_queue->ptr_mask; rx_buf = efx_rx_buffer(rx_queue, idx); rxd = efx_rx_desc(rx_queue, idx); EFX_POPULATE_QWORD_1(*rxd, ESF_GZ_RX_BUF_ADDR, rx_buf->dma_addr); - ++rx_queue->notified_count; + ++notified_count; } + if (notified_count == rx_queue->notified_count) + return; wmb(); EFX_POPULATE_DWORD_1(rxdb, ERF_GZ_RX_RING_PIDX, rx_queue->added_count & rx_queue->ptr_mask); efx_writed_page(rx_queue->efx, &rxdb, ER_GZ_RX_RING_DOORBELL, efx_rx_queue_index(rx_queue)); + if (rx_queue->grant_credits) + wmb(); + rx_queue->notified_count = notified_count; + if (rx_queue->grant_credits) + schedule_work(&rx_queue->grant_work); } diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 7ef823d7a89a..efb867b6556a 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -363,8 +363,12 @@ struct efx_rx_page_state { * @refill_enabled: Enable refill whenever fill level is low * @flush_pending: Set when a RX flush is pending. Has the same lifetime as * @rxq_flush_pending. + * @grant_credits: Posted RX descriptors need to be granted to the MAE with + * %MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS. For %EFX_EXTRA_CHANNEL_TC, + * and only supported on EF100. * @added_count: Number of buffers added to the receive queue. * @notified_count: Number of buffers given to NIC (<= @added_count). + * @granted_count: Number of buffers granted to the MAE (<= @notified_count). * @removed_count: Number of buffers removed from the receive queue. * @scatter_n: Used by NIC specific receive code. * @scatter_len: Used by NIC specific receive code. @@ -385,6 +389,7 @@ struct efx_rx_page_state { * refill was triggered. * @recycle_count: RX buffer recycle counter. * @slow_fill: Timer used to defer efx_nic_generate_fill_event(). + * @grant_work: workitem used to grant credits to the MAE if @grant_credits * @xdp_rxq_info: XDP specific RX queue information. * @xdp_rxq_info_valid: Is xdp_rxq_info valid data?. */ @@ -396,9 +401,11 @@ struct efx_rx_queue { unsigned int ptr_mask; bool refill_enabled; bool flush_pending; + bool grant_credits; unsigned int added_count; unsigned int notified_count; + unsigned int granted_count; unsigned int removed_count; unsigned int scatter_n; unsigned int scatter_len; @@ -416,6 +423,7 @@ struct efx_rx_queue { unsigned int recycle_count; struct timer_list slow_fill; unsigned int slow_fill_count; + struct work_struct grant_work; /* Statistics to supplement MAC stats */ unsigned long rx_packets; struct xdp_rxq_info xdp_rxq_info; diff --git a/drivers/net/ethernet/sfc/rx_common.c b/drivers/net/ethernet/sfc/rx_common.c index 9220afeddee8..d2f35ee15eff 100644 --- a/drivers/net/ethernet/sfc/rx_common.c +++ b/drivers/net/ethernet/sfc/rx_common.c @@ -229,6 +229,7 @@ void efx_init_rx_queue(struct efx_rx_queue *rx_queue) /* Initialise ptr fields */ rx_queue->added_count = 0; rx_queue->notified_count = 0; + rx_queue->granted_count = 0; rx_queue->removed_count = 0; rx_queue->min_fill = -1U; efx_init_rx_recycle_ring(rx_queue); @@ -281,6 +282,8 @@ void efx_fini_rx_queue(struct efx_rx_queue *rx_queue) "shutting down RX queue %d\n", efx_rx_queue_index(rx_queue)); del_timer_sync(&rx_queue->slow_fill); + if (rx_queue->grant_credits) + flush_work(&rx_queue->grant_work); /* Release RX buffers from the current read ptr to the write ptr */ if (rx_queue->buffer) { From patchwork Tue Nov 8 17:24:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036577 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 1BD3AC4332F for ; Tue, 8 Nov 2022 17:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234464AbiKHR01 (ORCPT ); Tue, 8 Nov 2022 12:26:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234479AbiKHR0W (ORCPT ); Tue, 8 Nov 2022 12:26:22 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2082.outbound.protection.outlook.com [40.107.94.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8070B1180B for ; Tue, 8 Nov 2022 09:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y5ZpO2ItYyJEueLvYhTBgybOWcQFqM9TFro/XGdvRhiTYCyifIByjOZhYI0D9D7CDwFTs2+N5kU2lJVpL8+gCxpB+B1cgrXlUS2an6DdoPkgnL4LaEvgW/18jCKes8QJrIrs9ABZPXFA8vEGO57Tdo534y8EXL4zegaMO0Bs7vI8MBgD/zefdJfB9+/LqMvXjzIsOsmTLw0NcqO75Ded7jW+XA4LGi7vCVeLhvszEHUuB6LN7xt+3U4ZaTlCFGbdIa8rKq26dm3CckJR0MFruWzjma/nPvU1xiD7c5JaqoXwfjBPkz3ktItTqNU7fCeosHj8lsVV4h60F/c1Pubvvg== 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=ur1v9i8cztku5khQmXg6iBWzYmQurLqOvhdyp37bJSo=; b=SgD9UfsqSJP3YrFYtCzJ/l/B5qfVEeR9QN7KDbtJ1g0UrVY34lcgk7TKNbwxhMles5RDmvOc0A8o+48Fzkn/eIbUQmrk4atJvCtRmzBT9F2VhWLFWoZoNtvmy/xmRGjOAZ9z+s4gr2bVyDiEPPnNF1kc9fToycoMwMOZXRdwdl/J9hkj1f/vk/0z7un5I8G47oA6BFGsJbtSUM1NayietvMLTQyMdll01MYzyl16Cfcz5n/koqFAoiuD9WKyN7VgHT+Lp3twnVRlV+K5fCXG4EwcJZH9tW9U+FBO4U04rho75wWxRI5Izsuh11JumtzGbIXldkOkxmSagud45HjNkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ur1v9i8cztku5khQmXg6iBWzYmQurLqOvhdyp37bJSo=; b=CXMvRy1DsyAhIVwMHyyVXxC1rECw7N9p9qnaJlZth3A33a7smFrL40SIohI65JHSrxIjGSJlGfySwLOF9Th7QYnliJ7cDQMNMpZI1Ll5YubnKjMuRAsIr0f9tKIHsgY5vvoDSc1m8d9rIUWsGR7DslhaTbfglG9+pHIR/4qmhvM= Received: from MW4PR02CA0020.namprd02.prod.outlook.com (2603:10b6:303:16d::26) by BL0PR12MB4898.namprd12.prod.outlook.com (2603:10b6:208:1c7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Tue, 8 Nov 2022 17:26:18 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:16d:cafe::96) by MW4PR02CA0020.outlook.office365.com (2603:10b6:303:16d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27 via Frontend Transport; Tue, 8 Nov 2022 17:26:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Tue, 8 Nov 2022 17:26:18 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:14 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:26:13 -0800 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:12 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 02/11] sfc: add start and stop methods to channels Date: Tue, 8 Nov 2022 17:24:43 +0000 Message-ID: <3a03be683b481c05be76c3d91ebff0b53d2f3b6b.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT047:EE_|BL0PR12MB4898:EE_ X-MS-Office365-Filtering-Correlation-Id: a0c25df4-3806-438b-095b-08dac1ae58e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YoPBgmaSHERZpjcRcUoDdxB0i5mrMrBnvDGMMitVufT2udlo9vYjHEpbp4Up8ORUaxJ29V/ev+aLp0/WYM7MNOf+aUELBh+XsKccOKtzzGHEp1krE3XO0ziPaOSThLpj4C6Hq+SAWb/OHBCs4d/OlitCgtRK4hhY2JfiK0ieeomCTd5e+KSf+IIerGEfev7c4sNhG5Map2V0YaKijIJMf+ZHE25NWPgldDTI1zHOlTAJpgyJYUfLx5/PkeBiK3rpr7MXBBHORAIDC5S9+iNXZGmwn6GyJX087i22e5qxIfXWZRHw5NNBXV/E7mqYNPh3yQehBr88BSY+0a/7fyMjZ7kDOhiAtVq6NrTp8epXVw2gcs2LzrDpFR4cakoN+GH/TpBbkdCIw72TpsmfofxEQGme9lZKm6UqSn5B17F0tucX5kzYxPi+FFmraUEqoZrrQ2i6SGhdT2V2pO7Ns4j14MmulEtJNGJTP3r9R4JwGkM9pJTiKScgaZewRmlb0sZH1gaJKN8Uu4aFHSffVFac3CXXVnbYJhLaYU/tjJqRO5aKBjC+3kjYpFsSoUpQDvLxH0xyO1Qhsl1WlOahkRflC+pZLVvLXzag9hxl1SywYb69RKYxVLmxRJzbQkWIy2/1WfaUSfRn9eVLpI2OS6mXLsCYmVPxoEH+miILIM8C8LKK4EH3GccaPfqvDtJmnhKXhtJpLREXMIZUPzFBq/XOSBm5D66ckNjMCoqGXsjZju/TBiOHWXw9IYROjlO4TbkteX1LuP0M/avOFCKrSqMVSmSUie+Dw53ybAxInfqPZVRKcNeyIIsjml0g1TadB8fkpkS2zP+K0MRZFQAx+BXS3w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(136003)(346002)(376002)(396003)(451199015)(46966006)(36840700001)(40470700004)(6636002)(82740400003)(316002)(9686003)(54906003)(86362001)(40460700003)(55446002)(478600001)(110136005)(186003)(426003)(83380400001)(6666004)(336012)(36860700001)(82310400005)(36756003)(47076005)(26005)(8936002)(5660300002)(41300700001)(70206006)(70586007)(8676002)(2876002)(4326008)(356005)(81166007)(40480700001)(2906002)(448954002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:18.4619 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0c25df4-3806-438b-095b-08dac1ae58e2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4898 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree The TC extra channel needs to do extra work in efx_{start,stop}_channels() to start/stop MAE counter streaming from the hardware. Add callbacks for it to implement. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/efx_channels.c | 9 ++++++++- drivers/net/ethernet/sfc/net_driver.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/sfc/efx_channels.c b/drivers/net/ethernet/sfc/efx_channels.c index aaa381743bca..fcea3ea809d7 100644 --- a/drivers/net/ethernet/sfc/efx_channels.c +++ b/drivers/net/ethernet/sfc/efx_channels.c @@ -1119,6 +1119,8 @@ void efx_start_channels(struct efx_nic *efx) struct efx_channel *channel; efx_for_each_channel_rev(channel, efx) { + if (channel->type->start) + channel->type->start(channel); efx_for_each_channel_tx_queue(tx_queue, channel) { efx_init_tx_queue(tx_queue); atomic_inc(&efx->active_queues); @@ -1143,8 +1145,13 @@ void efx_stop_channels(struct efx_nic *efx) struct efx_channel *channel; int rc = 0; - /* Stop RX refill */ + /* Stop special channels and RX refill. + * The channel's stop has to be called first, since it might wait + * for a sentinel RX to indicate the channel has fully drained. + */ efx_for_each_channel(channel, efx) { + if (channel->type->stop) + channel->type->stop(channel); efx_for_each_channel_rx_queue(rx_queue, channel) rx_queue->refill_enabled = false; } diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index efb867b6556a..b3d413896230 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -585,6 +585,8 @@ struct efx_msi_context { * struct efx_channel_type - distinguishes traffic and extra channels * @handle_no_channel: Handle failure to allocate an extra channel * @pre_probe: Set up extra state prior to initialisation + * @start: called early in efx_start_channels() + * @stop: called early in efx_stop_channels() * @post_remove: Tear down extra state after finalisation, if allocated. * May be called on channels that have not been probed. * @get_name: Generate the channel's name (used for its IRQ handler) @@ -601,6 +603,8 @@ struct efx_msi_context { struct efx_channel_type { void (*handle_no_channel)(struct efx_nic *); int (*pre_probe)(struct efx_channel *); + int (*start)(struct efx_channel *); + void (*stop)(struct efx_channel *); void (*post_remove)(struct efx_channel *); void (*get_name)(struct efx_channel *, char *buf, size_t len); struct efx_channel *(*copy)(const struct efx_channel *); From patchwork Tue Nov 8 17:24:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036578 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 8FAA6C433FE for ; Tue, 8 Nov 2022 17:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234481AbiKHR03 (ORCPT ); Tue, 8 Nov 2022 12:26:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234313AbiKHR0V (ORCPT ); Tue, 8 Nov 2022 12:26:21 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2040.outbound.protection.outlook.com [40.107.93.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28106B81 for ; Tue, 8 Nov 2022 09:26:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fHHxYEz9JXYjDujsI2OyrOZ3YHEU6w7enIBY3gkzSB/Fvw8wUv1dim9gcgnVRwN7qjXSjID+0/IuJyXZpNVvNHgs7iafsDPTIuG/yeG6aX1ArkFhnpVi4quFJZW0reJ0lQ7itJd1tf6topUzXuuk4OPXQBDZD4B0wzXyeY8+YIaHdtvRp0tG0sszuu0kgzMcHY5DZQGptLW7pPitHAL0lNECTCAuiXs78FKtFZnNvx9yPW7F7MAAB8+Mzr8FGRPew3DwAyfSOGnzOf1UUMNHHzy8qXeFAEdsNvXH82BH9KvEsAstGfUKwfaEzwEbfJ3rovje/iKVMdrVgCeHkF/LcQ== 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=kfoo7gnX3GSebhlbQu3T9XIm64uqzcP1dbIRFQSVFgs=; b=T6pz+s2EUWoX/9/rtkXookMOo/JNEUGi/ZWpOoa2WSF3t+Q5ykxIljyH1UXrbmYIKb5+kvgP1G2OavNg2eqYJzEArrpcXjoTpdX96ooaVC0QS3Hh+px2GH4G5jFIrN6Gm5xiJzY1GCaoi1fkZdKdQr3TZ6IsyoclOTdfuGxQHYHtT0bUEK/U+3250yxDxeNFN2T60qtTDj/D6liBtKgA+KMENEMnDnQD9zelb6uSgZ0QR8KYSkxWhho5n2yXS1hjhxzmx4H+I9aA8KAxx+8xEVgTTHdEqFqW+QKjWj52WK+yp33T5lypDNhsJloRPHHs8wQpG34XeUI2N0MBZoWW+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kfoo7gnX3GSebhlbQu3T9XIm64uqzcP1dbIRFQSVFgs=; b=nZHbMYZq7KfFYsfj+az1JC5L29PJNnGOg7fhQ+a00l0/fI1WgV8R1edn70XEggA5TlOFozGDTED8lpkOSrcELEtkLMQCwxJzYoxUZvjIDeBHN4eHtaoiDYttk9aXkUbwHCJ3VnhZAzEQ0XtJSykjONG2FTAA0EaCMMpbOYTinrw= Received: from MW4PR03CA0089.namprd03.prod.outlook.com (2603:10b6:303:b6::34) by DS0PR12MB6557.namprd12.prod.outlook.com (2603:10b6:8:d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26; Tue, 8 Nov 2022 17:26:17 +0000 Received: from CO1NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b6:cafe::b9) by MW4PR03CA0089.outlook.office365.com (2603:10b6:303:b6::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26 via Frontend Transport; Tue, 8 Nov 2022 17:26:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT101.mail.protection.outlook.com (10.13.175.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Tue, 8 Nov 2022 17:26:17 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:15 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:26:14 -0800 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:13 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 03/11] sfc: add ability for extra channels to receive raw RX buffers Date: Tue, 8 Nov 2022 17:24:44 +0000 Message-ID: <50ecccc725b9481c79f89e8dbd0eac9d043ce4a1.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT101:EE_|DS0PR12MB6557:EE_ X-MS-Office365-Filtering-Correlation-Id: e26621b1-84e8-499a-13a1-08dac1ae580b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T/NaMX/jqJMOwjfbN2eRcQ5qyDmCgr2CxBh0V/+10QbtuU5C9F5uw9uzqbbmCX1JywXFYBMxYyDWVZl55pByHtJez4Um2Bh1UoY1SOzbc1IhZF6gHnLhDAjHREy9/DDc4a/vtjP4CdQiWILZu554IIYSwnMa0FAqHLKYdcbcsFD93SkwBSdxor5LwNavGWFOj1/0wnDEnu9d9DiA82mEA1oHKD3D5v/pLDBMLTCGkxlfM0NOq3mcS0cfPbON5Hy+ig636H25L1QHxr5vDuna8OiW4xvDpqv4+scZekp+L4NS1tpVw98y03Jw+pcHhx0hYJw7ijxD/jJoCJxsOKlJgq/Sy45sgiOo8VxBsVab8Gsm0XdaaqRZOPCse0ulPo1xQpLEU1+lWMT7cFweo8HM3/52FY3TcEFPG0WVQZt04ASg2Ata41SzsEgDNmpVNwV+DW+xdzDOrXw0Gn9eNy1C5TfvBZEZibG3NOJlfIuYI7qghJMVKmio+5IlAof6wveZPkVQH91rop+a/Ze1hIXxrbQPuspRy5MXqa+/5PdWpmTEFoat35XsRNazW3mlnOODQbM53pZ4xNi357b/Ba5lfH23F77bEgD98e0HN4/P3LktKPO4VClrywlZxv/SgsFvhtkl1qMXr5dYf30Dik4sRGrgAQgev1vJFYdzzTfkFZSs/jNmY9sl0x+ITpL3c2UoZHAeFNGQaZNb8O/c9Sl7qu7nLigSWp5NSc4h5sqsrhWhG6vlBaqBJt9TRDmzkF2/C5uo1sAREm31x+vqGvr2cI/lZs8uz8GSZvzh0p85ugQYlUSQG6C0XQiEwycCkUV1 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(346002)(136003)(376002)(451199015)(36840700001)(40470700004)(46966006)(36756003)(86362001)(81166007)(82740400003)(356005)(55446002)(2906002)(9686003)(40460700003)(40480700001)(2876002)(26005)(36860700001)(47076005)(426003)(186003)(336012)(6666004)(70206006)(70586007)(6636002)(82310400005)(110136005)(478600001)(8676002)(54906003)(316002)(5660300002)(4326008)(8936002)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:17.0531 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e26621b1-84e8-499a-13a1-08dac1ae580b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6557 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree The TC extra channel will need its own special RX handling, which must operate before any code that expects the RX buffer to contain a network packet; buffers on this RX queue contain MAE counter packets in a special format that does not resemble an Ethernet frame, and many fields of the RX packet prefix are not populated. The USER_MARK field, however, is populated with the generation count from the counter subsystem, which needs to be passed on to the RX handler. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/ef100_rx.c | 7 +++++++ drivers/net/ethernet/sfc/net_driver.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef100_rx.c b/drivers/net/ethernet/sfc/ef100_rx.c index 24db44210acc..106afeb75c05 100644 --- a/drivers/net/ethernet/sfc/ef100_rx.c +++ b/drivers/net/ethernet/sfc/ef100_rx.c @@ -67,6 +67,13 @@ void __ef100_rx_packet(struct efx_channel *channel) prefix = (u32 *)(eh - ESE_GZ_RX_PKT_PREFIX_LEN); + if (channel->type->receive_raw) { + u32 mark = PREFIX_FIELD(prefix, USER_MARK); + + if (channel->type->receive_raw(rx_queue, mark)) + return; /* packet was consumed */ + } + if (ef100_has_fcs_error(channel, prefix) && unlikely(!(efx->net_dev->features & NETIF_F_RXALL))) goto out; diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index b3d413896230..1e42f3447b24 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -593,6 +593,7 @@ struct efx_msi_context { * @copy: Copy the channel state prior to reallocation. May be %NULL if * reallocation is not supported. * @receive_skb: Handle an skb ready to be passed to netif_receive_skb() + * @receive_raw: Handle an RX buffer ready to be passed to __efx_rx_packet() * @want_txqs: Determine whether this channel should have TX queues * created. If %NULL, TX queues are not created. * @keep_eventq: Flag for whether event queue should be kept initialised @@ -609,6 +610,7 @@ struct efx_channel_type { void (*get_name)(struct efx_channel *, char *buf, size_t len); struct efx_channel *(*copy)(const struct efx_channel *); bool (*receive_skb)(struct efx_channel *, struct sk_buff *); + bool (*receive_raw)(struct efx_rx_queue *, u32); bool (*want_txqs)(struct efx_channel *); bool keep_eventq; bool want_pio; From patchwork Tue Nov 8 17:24:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036576 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 EDB41C433FE for ; Tue, 8 Nov 2022 17:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234086AbiKHR00 (ORCPT ); Tue, 8 Nov 2022 12:26:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234481AbiKHR0W (ORCPT ); Tue, 8 Nov 2022 12:26:22 -0500 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2086.outbound.protection.outlook.com [40.107.95.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0389C110C for ; Tue, 8 Nov 2022 09:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dUd05AlF3PS4ARjmRCa6fBE41kD4GpcmJRLEkGKdmHone15O62PViZGNwKZnfAaPSNQBSmVwXzCpDri6OzSw4GPj5hwtQ12uArj9squcw4AdQps8njEWSht9LDpjhA6M1YyaubKhRjeUeXOJN+EGR6Ps7QCnGTaDzHp160U37v4driY/hPsjUEQVr0xZB5JdNLIH75yQfcsugQqMYG7MqMnaeT5OEmFe6lUod4OCl0FN6gCl/IvGmanouuwybJH8aQPHN5Yrqis48yT+B/eVN0dpDDrAZpXD+P7EoB342JmYoEPam61N2sjmSvQ0Qnqc3hezAyhFv6Eqjs1NPPScSA== 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=dLVBacy/udwPW6RbyJxchF44mJXCAfyMFW/wQPQk2Ag=; b=HXNsLpVWRJe1aD1dxEfBYEM8eNkl4mwDFWoNQR+T1eMIQXqXp7vzHy6oenDdOmM01OVjkFrv8L/inQ2J4L/0WrkZOSBLAO738AcuJGdUMjCARl4w3VB470ome0Q1u1yqICwMuQnAczxcuRAL+wPFFw72G4sE39zdd3EShVNeLIB0WYOpWzTdv86Dfnq+qtMhjjHhnRTuDxzVg4gp24/877VykOxvtZN/wnztJg3rNmQ3m4m4ZSqhhGHqzdmH2MhODjtwqKxpv0z/bNb4UwaGAC9Q61sAEzp4P6sonW5cS2fP/XgrInOni220ASTVU1V+W3t1aIYe4LQc3KvrpJ3lPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dLVBacy/udwPW6RbyJxchF44mJXCAfyMFW/wQPQk2Ag=; b=xVJ3h+OO4etZBw4iYETfjHRVqVg0nzVXI/VhU0QOJKT+btZEzv3XvsM1AcW0PcQmrwSbn7bHoqRlFLCBNc+0GwLI13kPxVfEwAw2deXRp6RL8Li2uLU6OpPYM/3CRiDgeks9Hn3Eyiq+s7gI5b4MSSpHYnVxsSLp/5NJL3M7USg= Received: from MW4PR03CA0073.namprd03.prod.outlook.com (2603:10b6:303:b6::18) by SN7PR12MB6887.namprd12.prod.outlook.com (2603:10b6:806:261::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.24; Tue, 8 Nov 2022 17:26:18 +0000 Received: from CO1NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b6:cafe::97) by MW4PR03CA0073.outlook.office365.com (2603:10b6:303:b6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27 via Frontend Transport; Tue, 8 Nov 2022 17:26:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT101.mail.protection.outlook.com (10.13.175.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Tue, 8 Nov 2022 17:26:17 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:17 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:26:16 -0800 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:15 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 04/11] sfc: add ef100 MAE counter support functions Date: Tue, 8 Nov 2022 17:24:45 +0000 Message-ID: <32a8072177e57d66e6046d03a68ea6b7f99b73a9.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT101:EE_|SN7PR12MB6887:EE_ X-MS-Office365-Filtering-Correlation-Id: 3375eb07-ac20-4a48-f9e1-08dac1ae5873 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ne14KNqy8we4R1vWe8z8WOeAufUkaYbieeJlGOyVU9j86mwsaFD4JbJcq+A6COAbDE4yK+ri+Ae670Oa9NjOXM5d5J8v8NQz4a9JdNucaJLltGcahNJB9OgyJ1n5mVSrnkd1Wx2W0tugaFYdcYyKlmt6u8YOLVUowz2Zzc1FOhJTu5xwvDupLJGkGsmZRlr4ypbxM/yi9dk/OR9QkXZUcvvKBngwHjbiCLWLkQO1eK4HhD9/LiGapjW1Y9DP0xgUUxm+jHlhEtJT4Re2P5hCoLcanbexUaq/h2SdsN8jl6ta8fPZbSCncUTCkTchCGC04walkGtftuS+fj2hZPqD1eEhx3TEQippO2Q/OmD/FnT9TNVtVOCj6+s3wVAFB8K1LVqYVvm3O313NNzm4mUV7P36UnPOKG0uytiu52A6qS4tTCbp+fDs/+REmReaMmsZZ9mmaEz25Dm8sLK54DuwqclG7kQ4oii7uWezsoFMCl834Y9GUX/dl8/x2OWsIm656ZxXcyJRg7HziBwoqOINfx9515+pLB0BgHSUtzyLyKDdtr9BlDqTzJCJTAg23vr+mW15LFI4BXjXoqZBxssyUuJB7TBuFOy2Pk5oFCqgyPSMPIcyvS0fDhxmOwoXGhjes3xumBvKlvHI/RQiHNf2NVayb7KD3zUSvNmpQ4uM4NZeDenvhHfthAZMGNd1rqSI3jYxzyHvYhAr8OjATPzdHzZHT5azU+mkhS/5YTYYtO/tD6f1yiUbaBgb4rFjZDuixiU44b729Q7l1fITEN7EPM6bNEVYQvjKhql+BRtRLq0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(346002)(136003)(39860400002)(376002)(451199015)(36840700001)(40470700004)(46966006)(36860700001)(2876002)(316002)(82740400003)(86362001)(81166007)(55446002)(6636002)(82310400005)(54906003)(356005)(2906002)(110136005)(70206006)(41300700001)(70586007)(47076005)(8936002)(8676002)(186003)(40460700003)(426003)(336012)(83380400001)(478600001)(4326008)(26005)(6666004)(5660300002)(9686003)(36756003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:17.7406 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3375eb07-ac20-4a48-f9e1-08dac1ae5873 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6887 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree Start and stop MAE counter streaming, and grant credits. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/mae.c | 111 ++++++++++++++++++++++++++++++++ drivers/net/ethernet/sfc/mae.h | 4 ++ drivers/net/ethernet/sfc/mcdi.h | 5 ++ drivers/net/ethernet/sfc/tc.c | 1 + drivers/net/ethernet/sfc/tc.h | 18 ++++++ 5 files changed, 139 insertions(+) diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c index 1e605e2a08c5..37722344c1cd 100644 --- a/drivers/net/ethernet/sfc/mae.c +++ b/drivers/net/ethernet/sfc/mae.c @@ -112,6 +112,117 @@ int efx_mae_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id) return 0; } +int efx_mae_start_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_COUNTERS_STREAM_START_V2_IN_LEN); + MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN); + u32 out_flags; + size_t outlen; + int rc; + + MCDI_SET_WORD(inbuf, MAE_COUNTERS_STREAM_START_V2_IN_QID, + efx_rx_queue_index(rx_queue)); + MCDI_SET_WORD(inbuf, MAE_COUNTERS_STREAM_START_V2_IN_PACKET_SIZE, + efx->net_dev->mtu); + MCDI_SET_DWORD(inbuf, MAE_COUNTERS_STREAM_START_V2_IN_COUNTER_TYPES_MASK, + BIT(MAE_COUNTER_TYPE_AR) | BIT(MAE_COUNTER_TYPE_CT) | + BIT(MAE_COUNTER_TYPE_OR)); + rc = efx_mcdi_rpc(efx, MC_CMD_MAE_COUNTERS_STREAM_START, + inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); + if (rc) + return rc; + if (outlen < sizeof(outbuf)) + return -EIO; + out_flags = MCDI_DWORD(outbuf, MAE_COUNTERS_STREAM_START_OUT_FLAGS); + if (out_flags & BIT(MC_CMD_MAE_COUNTERS_STREAM_START_OUT_USES_CREDITS_OFST)) { + netif_dbg(efx, drv, efx->net_dev, + "MAE counter stream uses credits\n"); + rx_queue->grant_credits = true; + out_flags &= ~BIT(MC_CMD_MAE_COUNTERS_STREAM_START_OUT_USES_CREDITS_OFST); + } + if (out_flags) { + netif_err(efx, drv, efx->net_dev, + "MAE counter stream start: unrecognised flags %x\n", + out_flags); + goto out_stop; + } + return 0; +out_stop: + efx_mae_stop_counters(efx, rx_queue); + return -EOPNOTSUPP; +} + +static bool efx_mae_counters_flushed(u32 *flush_gen, u32 *seen_gen) +{ + int i; + + for (i = 0; i < EFX_TC_COUNTER_TYPE_MAX; i++) + if ((s32)(flush_gen[i] - seen_gen[i]) > 0) + return false; + return true; +} + +int efx_mae_stop_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_COUNTERS_STREAM_STOP_V2_OUT_LENMAX); + MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_COUNTERS_STREAM_STOP_IN_LEN); + size_t outlen; + int rc, i; + + MCDI_SET_WORD(inbuf, MAE_COUNTERS_STREAM_STOP_IN_QID, + efx_rx_queue_index(rx_queue)); + rc = efx_mcdi_rpc(efx, MC_CMD_MAE_COUNTERS_STREAM_STOP, + inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); + + if (rc) + return rc; + + netif_dbg(efx, drv, efx->net_dev, "Draining counters:\n"); + /* Only process received generation counts */ + for (i = 0; (i < (outlen / 4)) && (i < EFX_TC_COUNTER_TYPE_MAX); i++) { + efx->tc->flush_gen[i] = MCDI_ARRAY_DWORD(outbuf, + MAE_COUNTERS_STREAM_STOP_V2_OUT_GENERATION_COUNT, + i); + netif_dbg(efx, drv, efx->net_dev, + "\ttype %u, awaiting gen %u\n", i, + efx->tc->flush_gen[i]); + } + + efx->tc->flush_counters = true; + + /* Drain can take up to 2 seconds owing to FWRIVERHD-2884; whatever + * timeout we use, that delay is added to unload on nonresponsive + * hardware, so 2500ms seems like a reasonable compromise. + */ + if (!wait_event_timeout(efx->tc->flush_wq, + efx_mae_counters_flushed(efx->tc->flush_gen, + efx->tc->seen_gen), + msecs_to_jiffies(2500))) + netif_warn(efx, drv, efx->net_dev, + "Failed to drain counters RXQ, FW may be unhappy\n"); + + efx->tc->flush_counters = false; + + return rc; +} + +void efx_mae_counters_grant_credits(struct work_struct *work) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_LEN); + struct efx_rx_queue *rx_queue = container_of(work, struct efx_rx_queue, + grant_work); + struct efx_nic *efx = rx_queue->efx; + unsigned int credits; + + BUILD_BUG_ON(MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_OUT_LEN); + credits = READ_ONCE(rx_queue->notified_count) - rx_queue->granted_count; + MCDI_SET_DWORD(inbuf, MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_NUM_CREDITS, + credits); + if (!efx_mcdi_rpc(efx, MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS, + inbuf, sizeof(inbuf), NULL, 0, NULL)) + rx_queue->granted_count += credits; +} + static int efx_mae_get_basic_caps(struct efx_nic *efx, struct mae_caps *caps) { MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_GET_CAPS_OUT_LEN); diff --git a/drivers/net/ethernet/sfc/mae.h b/drivers/net/ethernet/sfc/mae.h index 3e0cd238d523..8f5de01dd962 100644 --- a/drivers/net/ethernet/sfc/mae.h +++ b/drivers/net/ethernet/sfc/mae.h @@ -27,6 +27,10 @@ void efx_mae_mport_mport(struct efx_nic *efx, u32 mport_id, u32 *out); int efx_mae_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id); +int efx_mae_start_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue); +int efx_mae_stop_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue); +void efx_mae_counters_grant_credits(struct work_struct *work); + #define MAE_NUM_FIELDS (MAE_FIELD_ENC_VNET_ID + 1) struct mae_caps { diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h index fbeb58104936..7e35fec9da35 100644 --- a/drivers/net/ethernet/sfc/mcdi.h +++ b/drivers/net/ethernet/sfc/mcdi.h @@ -221,6 +221,11 @@ void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); #define MCDI_BYTE(_buf, _field) \ ((void)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 1), \ *MCDI_PTR(_buf, _field)) +#define MCDI_SET_WORD(_buf, _field, _value) do { \ + BUILD_BUG_ON(MC_CMD_ ## _field ## _LEN != 2); \ + BUILD_BUG_ON(MC_CMD_ ## _field ## _OFST & 1); \ + *(__force __le16 *)MCDI_PTR(_buf, _field) = cpu_to_le16(_value);\ + } while (0) #define MCDI_WORD(_buf, _field) \ ((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \ le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field))) diff --git a/drivers/net/ethernet/sfc/tc.c b/drivers/net/ethernet/sfc/tc.c index 17e1a3447554..894f578b3296 100644 --- a/drivers/net/ethernet/sfc/tc.c +++ b/drivers/net/ethernet/sfc/tc.c @@ -751,6 +751,7 @@ int efx_init_struct_tc(struct efx_nic *efx) INIT_LIST_HEAD(&efx->tc->block_list); mutex_init(&efx->tc->mutex); + init_waitqueue_head(&efx->tc->flush_wq); rc = rhashtable_init(&efx->tc->match_action_ht, &efx_tc_match_action_ht_params); if (rc < 0) goto fail_match_action_ht; diff --git a/drivers/net/ethernet/sfc/tc.h b/drivers/net/ethernet/sfc/tc.h index 4240c375a8e6..464fc92e2d37 100644 --- a/drivers/net/ethernet/sfc/tc.h +++ b/drivers/net/ethernet/sfc/tc.h @@ -14,6 +14,14 @@ #include #include #include "net_driver.h" +#include "mcdi_pcol.h" /* for MAE_COUNTER_TYPE_* */ + +enum efx_tc_counter_type { + EFX_TC_COUNTER_TYPE_AR = MAE_COUNTER_TYPE_AR, + EFX_TC_COUNTER_TYPE_CT = MAE_COUNTER_TYPE_CT, + EFX_TC_COUNTER_TYPE_OR = MAE_COUNTER_TYPE_OR, + EFX_TC_COUNTER_TYPE_MAX +}; #define IS_ALL_ONES(v) (!(typeof (v))~(v)) @@ -79,6 +87,12 @@ enum efx_tc_rule_prios { * @reps_filter_uc: VNIC filter for representor unicast RX (promisc) * @reps_filter_mc: VNIC filter for representor multicast RX (allmulti) * @reps_mport_vport_id: vport_id for representor RX filters + * @flush_counters: counters have been stopped, waiting for drain + * @flush_gen: final generation count per type array as reported by + * MC_CMD_MAE_COUNTERS_STREAM_STOP + * @seen_gen: most recent generation count per type as seen by efx_tc_rx() + * @flush_wq: wait queue used by efx_mae_stop_counters() to wait for + * MAE counters RXQ to finish draining * @dflt: Match-action rules for default switching; at priority * %EFX_TC_PRIO_DFLT. Named by *ingress* port * @dflt.pf: rule for traffic ingressing from PF (egresses to wire) @@ -92,6 +106,10 @@ struct efx_tc_state { struct rhashtable match_action_ht; u32 reps_mport_id, reps_mport_vport_id; s32 reps_filter_uc, reps_filter_mc; + bool flush_counters; + u32 flush_gen[EFX_TC_COUNTER_TYPE_MAX]; + u32 seen_gen[EFX_TC_COUNTER_TYPE_MAX]; + wait_queue_head_t flush_wq; struct { struct efx_tc_flow_rule pf; struct efx_tc_flow_rule wire; From patchwork Tue Nov 8 17:24:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036579 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 2BCA9C4332F for ; Tue, 8 Nov 2022 17:26:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234314AbiKHR0a (ORCPT ); Tue, 8 Nov 2022 12:26:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234373AbiKHR0Z (ORCPT ); Tue, 8 Nov 2022 12:26:25 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2061.outbound.protection.outlook.com [40.107.244.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4428C140AA for ; Tue, 8 Nov 2022 09:26:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZB2Z0t26BH/LX/gUu+9iyHpBp5Jmdn4c1F9Dn5UNcbHCZ6QtqX1zCBQ6o+vbIayF/Va3aQTuPMzJmBa911cj+TCyWK5bOfRReJboMxawl3zmPFgkaVlCKl/hvVpaLGIejmRUbVj2lgq8GLjtvd6HAZAW7LdjbRJUVZznOduDevaeBMazVJZ8J8F4oFoeUY2e+yENRSAG6zWhNbs6792mFRi/xHoOZOZ4ZF1Ax8yhFwWsOk422bP86+Z57b3Q7pLaHvUDRlR2gKA1UwrSDTU8CA9Fa3ZwsaQ4ktxEJjwZ2cc7cxxfWD0HHYlFvgVqzA1Zb1WtppqTXlCIYcX9EFG+cA== 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=604SiAMOnOU5pHLBflQy2q7gT2iPW4aRoqOIFwmVxlQ=; b=SgVdICubYCbjUGwJwhikrGSeh/z2StNPyAbczK16Uvlyfbf4+kccmtUrsjew5eFf1e55BcqSR7EpkL8RsfGtljFZ1usYYFizCIabxcZBbNH6yt7YiFtLR79MwGDSIiJMpg740ew2b8y4Go1r0ntJBK6I96A3lhm6bt7grokMJPzYw7S43nn3ZMMLeyvkAL9eZvzhpMa2TFQQUphs/A34mzm2bo1cgklGYlGWOsagdyjZXp8FU68vMfhvg06uCKtdqltetueigJkDy/0nlf9lWTdvllLhgbdwukRCxdFGHAtQFNX2cYjZCgHL9HS0WOa92b1cabUXN2cmrO+QULjB5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=604SiAMOnOU5pHLBflQy2q7gT2iPW4aRoqOIFwmVxlQ=; b=nQs+rD19rmQ5rZ5Es7wcJhTcu0/hz/+oMqqj8qjzkUB3F9q62AnLxwxRpHurggOSasbTKF2Va6qNrHGsAJycARmtf09TZP3oPMjL0NsAABFgRE6ScdHqJ3ARJuK9rkP6rEZR+f1YyFiCB1jO3lTLDpOwNcS9WYP3IkQqV1r3qEg= Received: from MW4PR02CA0016.namprd02.prod.outlook.com (2603:10b6:303:16d::22) by DS7PR12MB6143.namprd12.prod.outlook.com (2603:10b6:8:99::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.24; Tue, 8 Nov 2022 17:26:19 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:16d:cafe::90) by MW4PR02CA0016.outlook.office365.com (2603:10b6:303:16d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26 via Frontend Transport; Tue, 8 Nov 2022 17:26:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Tue, 8 Nov 2022 17:26:19 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:17 -0600 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:16 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 05/11] sfc: add extra RX channel to receive MAE counter updates on ef100 Date: Tue, 8 Nov 2022 17:24:46 +0000 Message-ID: <10275fd9ce0c26866f8e69f00fb1c785ffa0c8ea.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT047:EE_|DS7PR12MB6143:EE_ X-MS-Office365-Filtering-Correlation-Id: c9748bcf-6806-4eca-b435-08dac1ae594f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GufKVlUeRQglm4AbEeU53AmZxOpqDAXZQ/O7l0tVFOAEuKwDV4y/0RRtxfU6ktTk4hNLrfNapPXeTlm9UwhfXQsxGKhUFwoGsw3k0msiSxhKY3n1hNW5sSnIq6/KcQ5gkVBCwtSRi5W3qCsmKQVoRVrbyGwcdQelMKTVNCipqVWLKewsF+hFGMVfUR4ykAeKnJyWW0DB0EW3q7urOwgsvdPY9uZGRJj6EAmzgPHmO0kp+WBo38AGQ898akQ1e7XaMkzO6sIxMJGFYfAi5z2bChRVWJV4MMppc9qI93ONH0kVDGXWZOjAwsE2WNy//+HHS6NYJhbyPstjT1Z6TkO6gjWoWt6ckZRfGihuLM01Lcob3ccsRNWb+2vogcC6jGuMZ4qB3sjD74JshOTJL3qDVBKfIyMSVdyNkMX9iosnYcvV7VTrhRO/EibKsXXzdahVSom6W+UvbQCkByVzhXhQZ0nAKdV3GTrjXY7wvDTueVWVCEOTHsa5f7VhNh2H2sT7WCxckE1U1jVolwOMkPY4SQjLEx2KfB5PZIE8kS9Flsl59s+e31SVogMjPNK1naOVSI47cV6CoiVlf20rEeorl7ibUC8MXBHB0h3V3zvutVlufg5yhLKYrFmrB6RbnWColkEG8/I+Xz7sgaqLgMgqp8aeg6JRY1gqMCy9RLVKLhZxzRe7lj/XoAHhNisRL8A/KkRLYwMxgp8UGB2AW8T/fYzpS24kUor+lFg8xgJ5RHwXMd4tgN+2MbH0xEoRTgqMO4zxGaxXJqgjjGl9qspeqDLz3sxIHfcD1Pdz8eJpmmqJR40KUhijWa6T+EkwzbGpeY1848My/HP5wGbrg9MiNA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(136003)(346002)(39860400002)(451199015)(36840700001)(46966006)(40470700004)(82310400005)(36860700001)(47076005)(55446002)(8936002)(86362001)(356005)(81166007)(6636002)(5660300002)(41300700001)(316002)(82740400003)(70586007)(186003)(70206006)(4326008)(8676002)(110136005)(478600001)(54906003)(2876002)(40460700003)(6666004)(426003)(15650500001)(30864003)(9686003)(26005)(83380400001)(2906002)(40480700001)(336012)(36756003)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:19.1806 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c9748bcf-6806-4eca-b435-08dac1ae594f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6143 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree Currently there is no counter-allocating machinery to connect the resulting counter update values to; that will be added in a subsequent patch. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/Makefile | 2 +- drivers/net/ethernet/sfc/mae_counter_format.h | 73 +++++ drivers/net/ethernet/sfc/net_driver.h | 3 +- drivers/net/ethernet/sfc/tc.c | 1 + drivers/net/ethernet/sfc/tc.h | 9 +- drivers/net/ethernet/sfc/tc_counters.c | 269 ++++++++++++++++++ drivers/net/ethernet/sfc/tc_counters.h | 26 ++ 7 files changed, 373 insertions(+), 10 deletions(-) create mode 100644 drivers/net/ethernet/sfc/mae_counter_format.h create mode 100644 drivers/net/ethernet/sfc/tc_counters.c create mode 100644 drivers/net/ethernet/sfc/tc_counters.h diff --git a/drivers/net/ethernet/sfc/Makefile b/drivers/net/ethernet/sfc/Makefile index b5e45fc6337e..712a48d00069 100644 --- a/drivers/net/ethernet/sfc/Makefile +++ b/drivers/net/ethernet/sfc/Makefile @@ -9,7 +9,7 @@ sfc-y += efx.o efx_common.o efx_channels.o nic.o \ ef100_ethtool.o ef100_rx.o ef100_tx.o sfc-$(CONFIG_SFC_MTD) += mtd.o sfc-$(CONFIG_SFC_SRIOV) += sriov.o ef10_sriov.o ef100_sriov.o ef100_rep.o \ - mae.o tc.o tc_bindings.o + mae.o tc.o tc_bindings.o tc_counters.o obj-$(CONFIG_SFC) += sfc.o diff --git a/drivers/net/ethernet/sfc/mae_counter_format.h b/drivers/net/ethernet/sfc/mae_counter_format.h new file mode 100644 index 000000000000..7e252e393fbe --- /dev/null +++ b/drivers/net/ethernet/sfc/mae_counter_format.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/**************************************************************************** + * Driver for Solarflare network controllers and boards + * Copyright 2020 Xilinx, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, incorporated herein by reference. + */ + +/* Format of counter packets (version 2) from the ef100 Match-Action Engine */ + +#ifndef EFX_MAE_COUNTER_FORMAT_H +#define EFX_MAE_COUNTER_FORMAT_H + + +/*------------------------------------------------------------*/ +/* + * ER_RX_SL_PACKETISER_HEADER_WORD(160bit): + * + */ +#define ER_RX_SL_PACKETISER_HEADER_WORD_SIZE 20 +#define ER_RX_SL_PACKETISER_HEADER_WORD_WIDTH 160 + +#define ERF_SC_PACKETISER_HEADER_VERSION_LBN 0 +#define ERF_SC_PACKETISER_HEADER_VERSION_WIDTH 8 +#define ERF_SC_PACKETISER_HEADER_VERSION_VALUE 2 +#define ERF_SC_PACKETISER_HEADER_IDENTIFIER_LBN 8 +#define ERF_SC_PACKETISER_HEADER_IDENTIFIER_WIDTH 8 +#define ERF_SC_PACKETISER_HEADER_IDENTIFIER_AR 0 +#define ERF_SC_PACKETISER_HEADER_IDENTIFIER_CT 1 +#define ERF_SC_PACKETISER_HEADER_IDENTIFIER_OR 2 +#define ERF_SC_PACKETISER_HEADER_HEADER_OFFSET_LBN 16 +#define ERF_SC_PACKETISER_HEADER_HEADER_OFFSET_WIDTH 8 +#define ERF_SC_PACKETISER_HEADER_HEADER_OFFSET_DEFAULT 0x4 +#define ERF_SC_PACKETISER_HEADER_PAYLOAD_OFFSET_LBN 24 +#define ERF_SC_PACKETISER_HEADER_PAYLOAD_OFFSET_WIDTH 8 +#define ERF_SC_PACKETISER_HEADER_PAYLOAD_OFFSET_DEFAULT 0x14 +#define ERF_SC_PACKETISER_HEADER_INDEX_LBN 32 +#define ERF_SC_PACKETISER_HEADER_INDEX_WIDTH 16 +#define ERF_SC_PACKETISER_HEADER_COUNT_LBN 48 +#define ERF_SC_PACKETISER_HEADER_COUNT_WIDTH 16 +#define ERF_SC_PACKETISER_HEADER_RESERVED_0_LBN 64 +#define ERF_SC_PACKETISER_HEADER_RESERVED_0_WIDTH 32 +#define ERF_SC_PACKETISER_HEADER_RESERVED_1_LBN 96 +#define ERF_SC_PACKETISER_HEADER_RESERVED_1_WIDTH 32 +#define ERF_SC_PACKETISER_HEADER_RESERVED_2_LBN 128 +#define ERF_SC_PACKETISER_HEADER_RESERVED_2_WIDTH 32 + + +/*------------------------------------------------------------*/ +/* + * ER_RX_SL_PACKETISER_PAYLOAD_WORD(128bit): + * + */ +#define ER_RX_SL_PACKETISER_PAYLOAD_WORD_SIZE 16 +#define ER_RX_SL_PACKETISER_PAYLOAD_WORD_WIDTH 128 + +#define ERF_SC_PACKETISER_PAYLOAD_COUNTER_INDEX_LBN 0 +#define ERF_SC_PACKETISER_PAYLOAD_COUNTER_INDEX_WIDTH 24 +#define ERF_SC_PACKETISER_PAYLOAD_RESERVED_LBN 24 +#define ERF_SC_PACKETISER_PAYLOAD_RESERVED_WIDTH 8 +#define ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_OFST 4 +#define ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_SIZE 6 +#define ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_LBN 32 +#define ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_WIDTH 48 +#define ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_OFST 10 +#define ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_SIZE 6 +#define ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_LBN 80 +#define ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_WIDTH 48 + + +#endif /* EFX_MAE_COUNTER_FORMAT_H */ diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 1e42f3447b24..3b49e216768b 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -56,7 +56,8 @@ #define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS #define EFX_EXTRA_CHANNEL_IOV 0 #define EFX_EXTRA_CHANNEL_PTP 1 -#define EFX_MAX_EXTRA_CHANNELS 2U +#define EFX_EXTRA_CHANNEL_TC 2 +#define EFX_MAX_EXTRA_CHANNELS 3U /* Checksum generation is a per-queue option in hardware, so each * queue visible to the networking core is backed by two hardware TX diff --git a/drivers/net/ethernet/sfc/tc.c b/drivers/net/ethernet/sfc/tc.c index 894f578b3296..37d56a1ba958 100644 --- a/drivers/net/ethernet/sfc/tc.c +++ b/drivers/net/ethernet/sfc/tc.c @@ -761,6 +761,7 @@ int efx_init_struct_tc(struct efx_nic *efx) efx->tc->dflt.pf.fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL; INIT_LIST_HEAD(&efx->tc->dflt.wire.acts.list); efx->tc->dflt.wire.fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL; + efx->extra_channel_type[EFX_EXTRA_CHANNEL_TC] = &efx_tc_channel_type; return 0; fail_match_action_ht: mutex_destroy(&efx->tc->mutex); diff --git a/drivers/net/ethernet/sfc/tc.h b/drivers/net/ethernet/sfc/tc.h index 464fc92e2d37..97dc06f2e694 100644 --- a/drivers/net/ethernet/sfc/tc.h +++ b/drivers/net/ethernet/sfc/tc.h @@ -14,14 +14,7 @@ #include #include #include "net_driver.h" -#include "mcdi_pcol.h" /* for MAE_COUNTER_TYPE_* */ - -enum efx_tc_counter_type { - EFX_TC_COUNTER_TYPE_AR = MAE_COUNTER_TYPE_AR, - EFX_TC_COUNTER_TYPE_CT = MAE_COUNTER_TYPE_CT, - EFX_TC_COUNTER_TYPE_OR = MAE_COUNTER_TYPE_OR, - EFX_TC_COUNTER_TYPE_MAX -}; +#include "tc_counters.h" #define IS_ALL_ONES(v) (!(typeof (v))~(v)) diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c new file mode 100644 index 000000000000..4a310cd7f17f --- /dev/null +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -0,0 +1,269 @@ +// SPDX-License-Identifier: GPL-2.0-only +/**************************************************************************** + * Driver for Solarflare network controllers and boards + * Copyright 2022 Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, incorporated herein by reference. + */ + +#include "tc_counters.h" +#include "mae_counter_format.h" +#include "mae.h" +#include "rx_common.h" + +/* TC Channel. Counter updates are delivered on this channel's RXQ. */ + +static void efx_tc_handle_no_channel(struct efx_nic *efx) +{ + netif_warn(efx, drv, efx->net_dev, + "MAE counters require MSI-X and 1 additional interrupt vector.\n"); +} + +static int efx_tc_probe_channel(struct efx_channel *channel) +{ + struct efx_rx_queue *rx_queue = &channel->rx_queue; + + channel->irq_moderation_us = 0; + rx_queue->core_index = 0; + + INIT_WORK(&rx_queue->grant_work, efx_mae_counters_grant_credits); + + return 0; +} + +static int efx_tc_start_channel(struct efx_channel *channel) +{ + struct efx_rx_queue *rx_queue = efx_channel_get_rx_queue(channel); + struct efx_nic *efx = channel->efx; + + return efx_mae_start_counters(efx, rx_queue); +} + +static void efx_tc_stop_channel(struct efx_channel *channel) +{ + struct efx_rx_queue *rx_queue = efx_channel_get_rx_queue(channel); + struct efx_nic *efx = channel->efx; + int rc; + + rc = efx_mae_stop_counters(efx, rx_queue); + if (rc) + netif_warn(efx, drv, efx->net_dev, + "Failed to stop MAE counters streaming, rc=%d.\n", + rc); + rx_queue->grant_credits = false; + flush_work(&rx_queue->grant_work); +} + +static void efx_tc_remove_channel(struct efx_channel *channel) +{ +} + +static void efx_tc_get_channel_name(struct efx_channel *channel, + char *buf, size_t len) +{ + snprintf(buf, len, "%s-mae", channel->efx->name); +} + +static void efx_tc_counter_update(struct efx_nic *efx, + enum efx_tc_counter_type counter_type, + u32 counter_idx, u64 packets, u64 bytes, + u32 mark) +{ + /* Software counter objects do not exist yet, for now we ignore this */ +} + +static void efx_tc_rx_version_1(struct efx_nic *efx, const u8 *data, u32 mark) +{ + u16 n_counters, i; + + /* Header format: + * + | 0 | 1 | 2 | 3 | + * 0 |version | reserved | + * 4 | seq_index | n_counters | + */ + + n_counters = le16_to_cpu(*(const __le16 *)(data + 6)); + + /* Counter update entry format: + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e | f | + * | counter_idx | packet_count | byte_count | + */ + for (i = 0; i < n_counters; i++) { + const void *entry = data + 8 + 16 * i; + u64 packet_count, byte_count; + u32 counter_idx; + + counter_idx = le32_to_cpu(*(const __le32 *)entry); + packet_count = le32_to_cpu(*(const __le32 *)(entry + 4)) | + ((u64)le16_to_cpu(*(const __le16 *)(entry + 8)) << 32); + byte_count = le16_to_cpu(*(const __le16 *)(entry + 10)) | + ((u64)le32_to_cpu(*(const __le32 *)(entry + 12)) << 16); + efx_tc_counter_update(efx, EFX_TC_COUNTER_TYPE_AR, counter_idx, + packet_count, byte_count, mark); + } +} + +#define TCV2_HDR_PTR(pkt, field) \ + ((void)BUILD_BUG_ON_ZERO(ERF_SC_PACKETISER_HEADER_##field##_LBN & 7), \ + (pkt) + ERF_SC_PACKETISER_HEADER_##field##_LBN / 8) +#define TCV2_HDR_BYTE(pkt, field) \ + ((void)BUILD_BUG_ON_ZERO(ERF_SC_PACKETISER_HEADER_##field##_WIDTH != 8),\ + *TCV2_HDR_PTR(pkt, field)) +#define TCV2_HDR_WORD(pkt, field) \ + ((void)BUILD_BUG_ON_ZERO(ERF_SC_PACKETISER_HEADER_##field##_WIDTH != 16),\ + (void)BUILD_BUG_ON_ZERO(ERF_SC_PACKETISER_HEADER_##field##_LBN & 15), \ + *(__force const __le16 *)TCV2_HDR_PTR(pkt, field)) +#define TCV2_PKT_PTR(pkt, poff, i, field) \ + ((void)BUILD_BUG_ON_ZERO(ERF_SC_PACKETISER_PAYLOAD_##field##_LBN & 7), \ + (pkt) + ERF_SC_PACKETISER_PAYLOAD_##field##_LBN/8 + poff + \ + i * ER_RX_SL_PACKETISER_PAYLOAD_WORD_SIZE) + +/* Read a little-endian 48-bit field with 16-bit alignment */ +static u64 efx_tc_read48(const __le16 *field) +{ + u64 out = 0; + int i; + + for (i = 0; i < 3; i++) + out |= (u64)le16_to_cpu(field[i]) << (i * 16); + return out; +} + +static enum efx_tc_counter_type efx_tc_rx_version_2(struct efx_nic *efx, + const u8 *data, u32 mark) +{ + u8 payload_offset, header_offset, ident; + enum efx_tc_counter_type type; + u16 n_counters, i; + + ident = TCV2_HDR_BYTE(data, IDENTIFIER); + switch (ident) { + case ERF_SC_PACKETISER_HEADER_IDENTIFIER_AR: + type = EFX_TC_COUNTER_TYPE_AR; + break; + case ERF_SC_PACKETISER_HEADER_IDENTIFIER_CT: + type = EFX_TC_COUNTER_TYPE_CT; + break; + case ERF_SC_PACKETISER_HEADER_IDENTIFIER_OR: + type = EFX_TC_COUNTER_TYPE_OR; + break; + default: + if (net_ratelimit()) + netif_err(efx, drv, efx->net_dev, + "ignored v2 MAE counter packet (bad identifier %u" + "), counters may be inaccurate\n", ident); + return EFX_TC_COUNTER_TYPE_MAX; + } + header_offset = TCV2_HDR_BYTE(data, HEADER_OFFSET); + /* mae_counter_format.h implies that this offset is fixed, since it + * carries on with SOP-based LBNs for the fields in this header + */ + if (header_offset != ERF_SC_PACKETISER_HEADER_HEADER_OFFSET_DEFAULT) { + if (net_ratelimit()) + netif_err(efx, drv, efx->net_dev, + "choked on v2 MAE counter packet (bad header_offset %u" + "), counters may be inaccurate\n", header_offset); + return EFX_TC_COUNTER_TYPE_MAX; + } + payload_offset = TCV2_HDR_BYTE(data, PAYLOAD_OFFSET); + n_counters = le16_to_cpu(TCV2_HDR_WORD(data, COUNT)); + + for (i = 0; i < n_counters; i++) { + const void *counter_idx_p, *packet_count_p, *byte_count_p; + u64 packet_count, byte_count; + u32 counter_idx; + + /* 24-bit field with 32-bit alignment */ + counter_idx_p = TCV2_PKT_PTR(data, payload_offset, i, COUNTER_INDEX); + BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_COUNTER_INDEX_WIDTH != 24); + BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_COUNTER_INDEX_LBN & 31); + counter_idx = le32_to_cpu(*(const __le32 *)counter_idx_p) & 0xffffff; + /* 48-bit field with 16-bit alignment */ + packet_count_p = TCV2_PKT_PTR(data, payload_offset, i, PACKET_COUNT); + BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_WIDTH != 48); + BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_LBN & 15); + packet_count = efx_tc_read48((const __le16 *)packet_count_p); + /* 48-bit field with 16-bit alignment */ + byte_count_p = TCV2_PKT_PTR(data, payload_offset, i, BYTE_COUNT); + BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_WIDTH != 48); + BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_LBN & 15); + byte_count = efx_tc_read48((const __le16 *)byte_count_p); + + if (type == EFX_TC_COUNTER_TYPE_CT) { + /* CT counters are 1-bit saturating counters to update + * the lastuse time in CT stats. A received CT counter + * should have packet counter to 0 and only LSB bit on + * in byte counter. + */ + if (packet_count || byte_count != 1) + netdev_warn_once(efx->net_dev, + "CT counter with inconsistent state (%llu, %llu)\n", + packet_count, byte_count); + /* Do not increment the driver's byte counter */ + byte_count = 0; + } + + efx_tc_counter_update(efx, type, counter_idx, packet_count, + byte_count, mark); + } + return type; +} + +/* We always swallow the packet, whether successful or not, since it's not + * a network packet and shouldn't ever be forwarded to the stack. + * @mark is the generation count for counter allocations. + */ +static bool efx_tc_rx(struct efx_rx_queue *rx_queue, u32 mark) +{ + struct efx_channel *channel = efx_rx_queue_channel(rx_queue); + struct efx_rx_buffer *rx_buf = efx_rx_buffer(rx_queue, + channel->rx_pkt_index); + const u8 *data = efx_rx_buf_va(rx_buf); + struct efx_nic *efx = rx_queue->efx; + enum efx_tc_counter_type type; + u8 version; + + /* version is always first byte of packet */ + version = *data; + switch (version) { + case 1: + type = EFX_TC_COUNTER_TYPE_AR; + efx_tc_rx_version_1(efx, data, mark); + break; + case ERF_SC_PACKETISER_HEADER_VERSION_VALUE: // 2 + type = efx_tc_rx_version_2(efx, data, mark); + break; + default: + if (net_ratelimit()) + netif_err(efx, drv, efx->net_dev, + "choked on MAE counter packet (bad version %u" + "); counters may be inaccurate\n", + version); + goto out; + } + + /* Update seen_gen unconditionally, to avoid a missed wakeup if + * we race with efx_mae_stop_counters(). + */ + efx->tc->seen_gen[type] = mark; + if (efx->tc->flush_counters && + (s32)(efx->tc->flush_gen[type] - mark) <= 0) + wake_up(&efx->tc->flush_wq); +out: + efx_free_rx_buffers(rx_queue, rx_buf, 1); + channel->rx_pkt_n_frags = 0; + return true; +} + +const struct efx_channel_type efx_tc_channel_type = { + .handle_no_channel = efx_tc_handle_no_channel, + .pre_probe = efx_tc_probe_channel, + .start = efx_tc_start_channel, + .stop = efx_tc_stop_channel, + .post_remove = efx_tc_remove_channel, + .get_name = efx_tc_get_channel_name, + .receive_raw = efx_tc_rx, + .keep_eventq = true, +}; diff --git a/drivers/net/ethernet/sfc/tc_counters.h b/drivers/net/ethernet/sfc/tc_counters.h new file mode 100644 index 000000000000..400a39b00f01 --- /dev/null +++ b/drivers/net/ethernet/sfc/tc_counters.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/**************************************************************************** + * Driver for Solarflare network controllers and boards + * Copyright 2022 Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, incorporated herein by reference. + */ + +#ifndef EFX_TC_COUNTERS_H +#define EFX_TC_COUNTERS_H +#include "net_driver.h" + +#include "mcdi_pcol.h" /* for MAE_COUNTER_TYPE_* */ + +enum efx_tc_counter_type { + EFX_TC_COUNTER_TYPE_AR = MAE_COUNTER_TYPE_AR, + EFX_TC_COUNTER_TYPE_CT = MAE_COUNTER_TYPE_CT, + EFX_TC_COUNTER_TYPE_OR = MAE_COUNTER_TYPE_OR, + EFX_TC_COUNTER_TYPE_MAX +}; + +extern const struct efx_channel_type efx_tc_channel_type; + +#endif /* EFX_TC_COUNTERS_H */ From patchwork Tue Nov 8 17:24:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036580 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 00BECC43219 for ; Tue, 8 Nov 2022 17:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234508AbiKHR0c (ORCPT ); Tue, 8 Nov 2022 12:26:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234408AbiKHR00 (ORCPT ); Tue, 8 Nov 2022 12:26:26 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2072.outbound.protection.outlook.com [40.107.96.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B1A7B81 for ; Tue, 8 Nov 2022 09:26:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g+EsvHM6r1/e/tq4aBAsI19ddDwwGXa3fbWFnHyVWAFwhDOOS+pFV5CLLUO+kNDo1ykBSfYyZN+m2wklATi8YZ3TAW4DPjxupaN/BizVcbfwhndXLzwNvawIVkz9RfmDoN/SvJhAfqMsZ8yJJrt+8h6rXDLln7LKY41HRNjLNkrRMSbGMvPzcs8d9TvTkx9M+Ox5EYbeLcI2eeHD+VIEePoIbPtUSl0LpkO+AdUB0DTcmuoYVOuTkJmZPf5UpOqfJvKyUM3XXtweU1VDQQcBdgN+ylqSyhZPNsHTzfvZggc7sZ2Fk/NpVuyScReUCuUfrRUKvauxYQjEvxiMJMrPWA== 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=0STpD9VlgS/r/P+BMFrBIUlOsjfeEyn8GaI1km/PGgo=; b=A7bof2ibVn00UfQ4i1o3lepnVMjbPIEngUYZ+hP4wW6nwq1XG1Urh3tVtZP3wvrVHNrn16kacA2olw6xl9ffZ/oNwumfVB4/ppSPBrLX9RceJCosw35phaDNfpfCbezEbAlN5LK4jT175n+B1/wNzA34nFmhsapnU2c37K3LGBj6y0z/rVGFku490vgR7m+ZbO6RAQCZl0HDBAXgFF8tpW6v4sDVxci6bVFLShCdDJvrYj5/zQG1hG89y0s+i0Gj7xnWo0B1iPVQjs/1D1C+YcN0reO053I4rMmgIYpv7Y2bHPTZ/674fGgxAW+4u6IeCqRcxhXnGEOt2CNCBmbeVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0STpD9VlgS/r/P+BMFrBIUlOsjfeEyn8GaI1km/PGgo=; b=uS04ULNH/Enc2BEnzeYugagDqG4NlGrroC17Ky1qvcoPr2EMyqitjB9JkdVxCHsp1wvkN6nGoByUnpbLVvs3JoO/APCYjW+2+3Ywarnl3W7PicVfOpHY3aO17CmPOVnFarTvGZl0dahGDWJI1HDCpXwxx3QbV75vp5tO7kkLPQc= Received: from MW4PR04CA0388.namprd04.prod.outlook.com (2603:10b6:303:81::33) by SN7PR12MB7275.namprd12.prod.outlook.com (2603:10b6:806:2ae::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26; Tue, 8 Nov 2022 17:26:22 +0000 Received: from CO1NAM11FT090.eop-nam11.prod.protection.outlook.com (2603:10b6:303:81:cafe::cf) by MW4PR04CA0388.outlook.office365.com (2603:10b6:303:81::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25 via Frontend Transport; Tue, 8 Nov 2022 17:26:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT090.mail.protection.outlook.com (10.13.175.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5813.12 via Frontend Transport; Tue, 8 Nov 2022 17:26:22 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:19 -0600 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:18 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 06/11] sfc: add hashtables for MAE counters and counter ID mappings Date: Tue, 8 Nov 2022 17:24:47 +0000 Message-ID: <64a712ffb4ef488023d9934d65abfa9d6cbf061a.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT090:EE_|SN7PR12MB7275:EE_ X-MS-Office365-Filtering-Correlation-Id: 0dd8708a-83a4-49da-0111-08dac1ae5b04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CqujqrImN0BM3kg01aZH3HSX1nsU3IT6naZo6kw9FUeUxIW+Jj4fCWrpgbgiVafPN6weX+YpL7QPbJn1hE5DDVedOUNfPTm0yOp4Cgub6WeLyi0zS+8X00O0xS0E0PM1Ywie9Q0IOrr6z6ovAMDKroYiXEj29qBQ5f1ECWHbk9IEiHNh1n85cxrK+8g/sQ3s9wgSjnwyjdKkZ1m90WmX68XV6v0+YF8iWsC7l1BWJzWjpmXwPCm7b2Lfo621RtYgRe8md7cJliNfVqhAVjd8ZvcSkIW7+iDEu6Iq+a3lhP27l9P9d6p+LfcmSDISj9sqZcWcGl5BTvn22oazM4sbAuWOQZo1/3AzWuFt1GPi/qARoRXsCPjGdJGL6XnHHMiCBXS4n4SoC9067UuzDuPkULtbSY+Ea9M0hJAsqYPkLG5F6MUKuq5iRC3gwx+O6FasPUzYcU+MphgTg/7qcu2lBA2Z/SnfS/2NcLf2qEpwCcbWxiEJ7/ZHmMVoNpg0CHL5oWHuE+/F1tHSjxZ0ggr7OPmrTmjb4JNgSqhlzXOO9Bj43imhBafF6nDSIo4XsXDzrp0GfIXOIHCvN5+r8pWnWWXy7mNjuTlPYHWAuOVaHAqTWiR1nISp1rzlpPQau9cEPmTqdRAGloUkVGqleaQDm74TrXCn1ingOKpXDg56BduAKcLblMDDQbNKWniZ53lwZFxE9HMblla/i/cyrbzRAUCq3dUo5Ox30h6ygNcL0dSes6a3Zsz/3IgzxZ9tl1VlnHWY/8+ir08+G72blrgB+oJYLnFec93nKcnj/DG+3kE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(136003)(346002)(376002)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(186003)(336012)(9686003)(26005)(36860700001)(83380400001)(47076005)(426003)(6666004)(2906002)(2876002)(40480700001)(40460700003)(110136005)(478600001)(54906003)(82310400005)(5660300002)(6636002)(41300700001)(4326008)(8936002)(70586007)(316002)(8676002)(70206006)(82740400003)(81166007)(36756003)(356005)(86362001)(55446002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:22.0243 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0dd8708a-83a4-49da-0111-08dac1ae5b04 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT090.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7275 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree Nothing populates them yet. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/tc.c | 6 +++ drivers/net/ethernet/sfc/tc.h | 4 ++ drivers/net/ethernet/sfc/tc_counters.c | 61 ++++++++++++++++++++++++++ drivers/net/ethernet/sfc/tc_counters.h | 19 ++++++++ 4 files changed, 90 insertions(+) diff --git a/drivers/net/ethernet/sfc/tc.c b/drivers/net/ethernet/sfc/tc.c index 37d56a1ba958..8ea7f5213049 100644 --- a/drivers/net/ethernet/sfc/tc.c +++ b/drivers/net/ethernet/sfc/tc.c @@ -752,6 +752,9 @@ int efx_init_struct_tc(struct efx_nic *efx) mutex_init(&efx->tc->mutex); init_waitqueue_head(&efx->tc->flush_wq); + rc = efx_tc_init_counters(efx); + if (rc < 0) + goto fail_counters; rc = rhashtable_init(&efx->tc->match_action_ht, &efx_tc_match_action_ht_params); if (rc < 0) goto fail_match_action_ht; @@ -764,6 +767,8 @@ int efx_init_struct_tc(struct efx_nic *efx) efx->extra_channel_type[EFX_EXTRA_CHANNEL_TC] = &efx_tc_channel_type; return 0; fail_match_action_ht: + efx_tc_destroy_counters(efx); +fail_counters: mutex_destroy(&efx->tc->mutex); kfree(efx->tc->caps); fail_alloc_caps: @@ -784,6 +789,7 @@ void efx_fini_struct_tc(struct efx_nic *efx) MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL); rhashtable_free_and_destroy(&efx->tc->match_action_ht, efx_tc_flow_free, efx); + efx_tc_fini_counters(efx); mutex_unlock(&efx->tc->mutex); mutex_destroy(&efx->tc->mutex); kfree(efx->tc->caps); diff --git a/drivers/net/ethernet/sfc/tc.h b/drivers/net/ethernet/sfc/tc.h index 97dc06f2e694..6c8ebb2d79c0 100644 --- a/drivers/net/ethernet/sfc/tc.h +++ b/drivers/net/ethernet/sfc/tc.h @@ -75,6 +75,8 @@ enum efx_tc_rule_prios { * @caps: MAE capabilities reported by MCDI * @block_list: List of &struct efx_tc_block_binding * @mutex: Used to serialise operations on TC hashtables + * @counter_ht: Hashtable of TC counters (FW IDs and counter values) + * @counter_id_ht: Hashtable mapping TC counter cookies to counters * @match_action_ht: Hashtable of TC match-action rules * @reps_mport_id: MAE port allocated for representor RX * @reps_filter_uc: VNIC filter for representor unicast RX (promisc) @@ -96,6 +98,8 @@ struct efx_tc_state { struct mae_caps *caps; struct list_head block_list; struct mutex mutex; + struct rhashtable counter_ht; + struct rhashtable counter_id_ht; struct rhashtable match_action_ht; u32 reps_mport_id, reps_mport_vport_id; s32 reps_filter_uc, reps_filter_mc; diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index 4a310cd7f17f..9a4d1d2a1271 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -13,6 +13,67 @@ #include "mae.h" #include "rx_common.h" +/* Counter-management hashtables */ + +static const struct rhashtable_params efx_tc_counter_id_ht_params = { + .key_len = offsetof(struct efx_tc_counter_index, linkage), + .key_offset = 0, + .head_offset = offsetof(struct efx_tc_counter_index, linkage), +}; + +static const struct rhashtable_params efx_tc_counter_ht_params = { + .key_len = offsetof(struct efx_tc_counter, linkage), + .key_offset = 0, + .head_offset = offsetof(struct efx_tc_counter, linkage), +}; + +static void efx_tc_counter_free(void *ptr, void *__unused) +{ + struct efx_tc_counter *cnt = ptr; + + kfree(cnt); +} + +static void efx_tc_counter_id_free(void *ptr, void *__unused) +{ + struct efx_tc_counter_index *ctr = ptr; + + WARN_ON(refcount_read(&ctr->ref)); + kfree(ctr); +} + +int efx_tc_init_counters(struct efx_nic *efx) +{ + int rc; + + rc = rhashtable_init(&efx->tc->counter_id_ht, &efx_tc_counter_id_ht_params); + if (rc < 0) + goto fail_counter_id_ht; + rc = rhashtable_init(&efx->tc->counter_ht, &efx_tc_counter_ht_params); + if (rc < 0) + goto fail_counter_ht; + return 0; +fail_counter_ht: + rhashtable_destroy(&efx->tc->counter_id_ht); +fail_counter_id_ht: + return rc; +} + +/* Only call this in init failure teardown. + * Normal exit should fini instead as there may be entries in the table. + */ +void efx_tc_destroy_counters(struct efx_nic *efx) +{ + rhashtable_destroy(&efx->tc->counter_ht); + rhashtable_destroy(&efx->tc->counter_id_ht); +} + +void efx_tc_fini_counters(struct efx_nic *efx) +{ + rhashtable_free_and_destroy(&efx->tc->counter_id_ht, efx_tc_counter_id_free, NULL); + rhashtable_free_and_destroy(&efx->tc->counter_ht, efx_tc_counter_free, NULL); +} + /* TC Channel. Counter updates are delivered on this channel's RXQ. */ static void efx_tc_handle_no_channel(struct efx_nic *efx) diff --git a/drivers/net/ethernet/sfc/tc_counters.h b/drivers/net/ethernet/sfc/tc_counters.h index 400a39b00f01..f998cee324c7 100644 --- a/drivers/net/ethernet/sfc/tc_counters.h +++ b/drivers/net/ethernet/sfc/tc_counters.h @@ -10,6 +10,7 @@ #ifndef EFX_TC_COUNTERS_H #define EFX_TC_COUNTERS_H +#include #include "net_driver.h" #include "mcdi_pcol.h" /* for MAE_COUNTER_TYPE_* */ @@ -21,6 +22,24 @@ enum efx_tc_counter_type { EFX_TC_COUNTER_TYPE_MAX }; +struct efx_tc_counter { + u32 fw_id; /* index in firmware counter table */ + enum efx_tc_counter_type type; + struct rhash_head linkage; /* efx->tc->counter_ht */ +}; + +struct efx_tc_counter_index { + unsigned long cookie; + struct rhash_head linkage; /* efx->tc->counter_id_ht */ + refcount_t ref; + struct efx_tc_counter *cnt; +}; + +/* create/uncreate/teardown hashtables */ +int efx_tc_init_counters(struct efx_nic *efx); +void efx_tc_destroy_counters(struct efx_nic *efx); +void efx_tc_fini_counters(struct efx_nic *efx); + extern const struct efx_channel_type efx_tc_channel_type; #endif /* EFX_TC_COUNTERS_H */ From patchwork Tue Nov 8 17:24:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036583 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 B824FC433FE for ; Tue, 8 Nov 2022 17:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234055AbiKHR0g (ORCPT ); Tue, 8 Nov 2022 12:26:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234373AbiKHR0b (ORCPT ); Tue, 8 Nov 2022 12:26:31 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2058.outbound.protection.outlook.com [40.107.244.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABFB354B2A for ; Tue, 8 Nov 2022 09:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gchs9KkqaD3AdRJOEqsjNYgScwcndhvrja6B793DK1xyV5hZRiWh2yGetLrdYYnzwaJRz31H8Cl/oixVktIl/x+WyWmIOIXcm22REG3/Ba14lYPhylOcaJoNyJPhdO7TIvHwXl/S7DsLtLwKDJb9jownu0Rif38I7IYu9Hri09u/LnQJ2c/hwC1G92N/Vo86ISMrWSXJb+pygt6vd+iP2QWWhJkTrdO+FUq+mpRp7fydvQm913LzhNpkHVJqbAf8N/RmxcD/awg6ouxzROSPMNJhzUVYnY8lLLUe+v4wBU14z10iY/1+55jb1ug17Sgna09kEA6aJq0cvMfSxGab3g== 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=Wu2gnAQ3GdqgV2oCTvHTjYw4PahNJjVQeQDikoqum+Q=; b=eUCHt8NDTl5ptKocqBj1T96xGZkTmsUTwdlcjFfJEEyiq7Jz09Lrz5h/b/XVeO15/FBH/UBRQZ3q6y3ouCvn4ADICRVILZmB9wDMURT/WefnNWJQ+uaNykCG/oIrWX2VBhgAXrLqcbxeHzIi0V+h2dmWP0pVcZttA5MZI3kHYi0DT4o9vzhAy+0KJaSAsJLsDdT9hQ+QLA0keudYRntn8/hdVX52H62Iwwnz/yl4oFCKsBz3rJ8fWGLofTjHFbDDZLm05oe2SSqX0mmV1F1V/zMkkHu4muMQusA4kdyRLUd6y0uUNTTgYqqL9LkiuIiXHtoMi08NGvO0fnXRQ8uetA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Wu2gnAQ3GdqgV2oCTvHTjYw4PahNJjVQeQDikoqum+Q=; b=zC00IxX3gE9bqyChNd0nMcI62dI50xF/0Gl+di4jkLftvOvpAhrCiG6CIbgBni5Hl1Kj1M4C6mWE8pce4VdfuuwcpWnzBS5wrFVafaTJxJzXE/jZOIs2QI02pM7xaoA2NsCjVuIfrGBqJEqazCGjNF+NG0JgZh5mHqOLDsG5wtE= Received: from MW4P221CA0027.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::32) by MW4PR12MB5627.namprd12.prod.outlook.com (2603:10b6:303:16a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26; Tue, 8 Nov 2022 17:26:22 +0000 Received: from CO1NAM11FT110.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8b:cafe::d3) by MW4P221CA0027.outlook.office365.com (2603:10b6:303:8b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26 via Frontend Transport; Tue, 8 Nov 2022 17:26:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT110.mail.protection.outlook.com (10.13.175.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5813.12 via Frontend Transport; Tue, 8 Nov 2022 17:26:22 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:21 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:26:20 -0800 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:19 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 07/11] sfc: add functions to allocate/free MAE counters Date: Tue, 8 Nov 2022 17:24:48 +0000 Message-ID: <1c1ce96e588ed6116a33347dca4b5a5e9995a7f0.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT110:EE_|MW4PR12MB5627:EE_ X-MS-Office365-Filtering-Correlation-Id: 7eb64e30-7484-454f-a356-08dac1ae5b51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IN58Eff9EIqaROy5iERFfOK5mdsdRn/LGs2Tj4/nwvADJUDzXB5TXwY8UGA1YuAAanr6cigd6w4F2hPFZUdKV8L8/w724sQiIWJlX+9Hue3yFoWxISKHNutkUEV1VZcTULzHlZ733EYTNBjlVCm9AKtzrzugI1rjlsN3wfPyGgyCADLGN3o1YH7gSSldaFszydk0ki5xMJYl9x1O53darvpije9DTD2PD3ezomwkh2fSy6YZHXdMe7+1QVI4OII6pSnbQtCwjgjDS4PZeCSMW+vwbx79j0UviVdgMCZEE+OAw9aoNXEwxGJ6t3GtdUG9YKrU1tmRCpDa8Wp0U9AZYE7g+v1Gnv6N33lMtcTQlXdOqugH/5RSShwCtu5trOeP3Zy8rySpuDvoEkQjt+pDXghoChWN98XoOVjc8EZ+iV3IGqTulBi85L52Hv3NchbDW76DNaMNYNmCmZ1fio6Cnp8czm0fQmFDDfZdFHX8R9W7OfUcmMu007zQ9Bt7o+PmjWja3j24+dC4UHxaLH8jiMmB8w42bY7Rkh/w90hC56OdFBHLcQr4Tbawh8L8MKh+jrfbznYihYfcoXQj5QiC9uZTyBCbDL7iG9Sq9ZwuCK7SDXGBAswpxoREo1qnvebh/Q3tl1dtQeiQValGBFd4uZWHt9zxFca/Pj+NjzRz7hIHj2W+XBt93I3hpFzMFI4ZNfmuREkAQ/5V9KBQT712g+hmhW+DyPKAlRTQIGQ3cZYiJxEspYEa2+QURpl6ciaUTMfvzzmH/97uWxbuuvIhg9pfFjRpYKfu4nqx1w6y77UdBJmfvS0q85m4snm93ntx X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(376002)(39860400002)(346002)(136003)(451199015)(36840700001)(46966006)(40470700004)(426003)(186003)(47076005)(83380400001)(36860700001)(336012)(9686003)(40460700003)(6666004)(2876002)(5660300002)(26005)(82310400005)(2906002)(40480700001)(70206006)(4326008)(110136005)(8936002)(316002)(41300700001)(478600001)(8676002)(6636002)(54906003)(70586007)(36756003)(356005)(81166007)(55446002)(82740400003)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:22.5175 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7eb64e30-7484-454f-a356-08dac1ae5b51 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT110.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB5627 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree efx_tc_flower_get_counter_index() will create an MAE counter mapped to the passed (TC filter) cookie, or increment the reference if one already exists for that cookie. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/mae.c | 51 ++++++++++++ drivers/net/ethernet/sfc/mae.h | 3 + drivers/net/ethernet/sfc/tc_counters.c | 109 +++++++++++++++++++++++++ drivers/net/ethernet/sfc/tc_counters.h | 7 ++ 4 files changed, 170 insertions(+) diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c index 37722344c1cd..f227b4f2a9a0 100644 --- a/drivers/net/ethernet/sfc/mae.c +++ b/drivers/net/ethernet/sfc/mae.c @@ -434,6 +434,57 @@ int efx_mae_match_check_caps(struct efx_nic *efx, #undef CHECK_BIT #undef CHECK +int efx_mae_allocate_counter(struct efx_nic *efx, struct efx_tc_counter *cnt) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_COUNTER_ALLOC_OUT_LEN(1)); + MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_COUNTER_ALLOC_V2_IN_LEN); + size_t outlen; + int rc; + + if (!cnt) + return -EINVAL; + + MCDI_SET_DWORD(inbuf, MAE_COUNTER_ALLOC_V2_IN_REQUESTED_COUNT, 1); + MCDI_SET_DWORD(inbuf, MAE_COUNTER_ALLOC_V2_IN_COUNTER_TYPE, cnt->type); + rc = efx_mcdi_rpc(efx, MC_CMD_MAE_COUNTER_ALLOC, inbuf, sizeof(inbuf), + outbuf, sizeof(outbuf), &outlen); + if (rc) + return rc; + /* pcol says this can't happen, since count is 1 */ + if (outlen < sizeof(outbuf)) + return -EIO; + cnt->fw_id = MCDI_DWORD(outbuf, MAE_COUNTER_ALLOC_OUT_COUNTER_ID); + cnt->gen = MCDI_DWORD(outbuf, MAE_COUNTER_ALLOC_OUT_GENERATION_COUNT); + return 0; +} + +int efx_mae_free_counter(struct efx_nic *efx, struct efx_tc_counter *cnt) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_COUNTER_FREE_OUT_LEN(1)); + MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_COUNTER_FREE_V2_IN_LEN); + size_t outlen; + int rc; + + MCDI_SET_DWORD(inbuf, MAE_COUNTER_FREE_V2_IN_COUNTER_ID_COUNT, 1); + MCDI_SET_DWORD(inbuf, MAE_COUNTER_FREE_V2_IN_FREE_COUNTER_ID, cnt->fw_id); + MCDI_SET_DWORD(inbuf, MAE_COUNTER_FREE_V2_IN_COUNTER_TYPE, cnt->type); + rc = efx_mcdi_rpc(efx, MC_CMD_MAE_COUNTER_FREE, inbuf, sizeof(inbuf), + outbuf, sizeof(outbuf), &outlen); + if (rc) + return rc; + /* pcol says this can't happen, since count is 1 */ + if (outlen < sizeof(outbuf)) + return -EIO; + /* FW freed a different ID than we asked for, should also never happen. + * Warn because it means we've now got a different idea to the FW of + * what counters exist, which could cause mayhem later. + */ + if (WARN_ON(MCDI_DWORD(outbuf, MAE_COUNTER_FREE_OUT_FREED_COUNTER_ID) != + cnt->fw_id)) + return -EIO; + return 0; +} + static bool efx_mae_asl_id(u32 id) { return !!(id & BIT(31)); diff --git a/drivers/net/ethernet/sfc/mae.h b/drivers/net/ethernet/sfc/mae.h index 8f5de01dd962..72343e90e222 100644 --- a/drivers/net/ethernet/sfc/mae.h +++ b/drivers/net/ethernet/sfc/mae.h @@ -45,6 +45,9 @@ int efx_mae_match_check_caps(struct efx_nic *efx, const struct efx_tc_match_fields *mask, struct netlink_ext_ack *extack); +int efx_mae_allocate_counter(struct efx_nic *efx, struct efx_tc_counter *cnt); +int efx_mae_free_counter(struct efx_nic *efx, struct efx_tc_counter *cnt); + int efx_mae_alloc_action_set(struct efx_nic *efx, struct efx_tc_action_set *act); int efx_mae_free_action_set(struct efx_nic *efx, u32 fw_id); diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index 9a4d1d2a1271..6fd07ce61eb7 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -74,6 +74,115 @@ void efx_tc_fini_counters(struct efx_nic *efx) rhashtable_free_and_destroy(&efx->tc->counter_ht, efx_tc_counter_free, NULL); } +/* Counter allocation */ + +static struct efx_tc_counter *efx_tc_flower_allocate_counter(struct efx_nic *efx, + int type) +{ + struct efx_tc_counter *cnt; + int rc, rc2; + + cnt = kzalloc(sizeof(*cnt), GFP_USER); + if (!cnt) + return ERR_PTR(-ENOMEM); + + cnt->type = type; + + rc = efx_mae_allocate_counter(efx, cnt); + if (rc) + goto fail1; + rc = rhashtable_insert_fast(&efx->tc->counter_ht, &cnt->linkage, + efx_tc_counter_ht_params); + if (rc) + goto fail2; + return cnt; +fail2: + /* If we get here, it implies that we couldn't insert into the table, + * which in turn probably means that the fw_id was already taken. + * In that case, it's unclear whether we really 'own' the fw_id; but + * the firmware seemed to think we did, so it's proper to free it. + */ + rc2 = efx_mae_free_counter(efx, cnt); + if (rc2) + netif_warn(efx, hw, efx->net_dev, + "Failed to free MAE counter %u, rc %d\n", + cnt->fw_id, rc2); +fail1: + kfree(cnt); + return ERR_PTR(rc > 0 ? -EIO : rc); +} + +static void efx_tc_flower_release_counter(struct efx_nic *efx, + struct efx_tc_counter *cnt) +{ + int rc; + + rhashtable_remove_fast(&efx->tc->counter_ht, &cnt->linkage, + efx_tc_counter_ht_params); + rc = efx_mae_free_counter(efx, cnt); + if (rc) + netif_warn(efx, hw, efx->net_dev, + "Failed to free MAE counter %u, rc %d\n", + cnt->fw_id, rc); + /* This doesn't protect counter updates coming in arbitrarily long + * after we deleted the counter. The RCU just ensures that we won't + * free the counter while another thread has a pointer to it. + * Ensuring we don't update the wrong counter if the ID gets re-used + * is handled by the generation count. + */ + synchronize_rcu(); + kfree(cnt); +} + +/* TC cookie to counter mapping */ + +void efx_tc_flower_put_counter_index(struct efx_nic *efx, + struct efx_tc_counter_index *ctr) +{ + if (!refcount_dec_and_test(&ctr->ref)) + return; /* still in use */ + rhashtable_remove_fast(&efx->tc->counter_id_ht, &ctr->linkage, + efx_tc_counter_id_ht_params); + efx_tc_flower_release_counter(efx, ctr->cnt); + kfree(ctr); +} + +struct efx_tc_counter_index *efx_tc_flower_get_counter_index( + struct efx_nic *efx, unsigned long cookie, + enum efx_tc_counter_type type) +{ + struct efx_tc_counter_index *ctr, *old; + struct efx_tc_counter *cnt; + + ctr = kzalloc(sizeof(*ctr), GFP_USER); + if (!ctr) + return ERR_PTR(-ENOMEM); + ctr->cookie = cookie; + old = rhashtable_lookup_get_insert_fast(&efx->tc->counter_id_ht, + &ctr->linkage, + efx_tc_counter_id_ht_params); + if (old) { + /* don't need our new entry */ + kfree(ctr); + if (!refcount_inc_not_zero(&old->ref)) + return ERR_PTR(-EAGAIN); + /* existing entry found */ + ctr = old; + } else { + cnt = efx_tc_flower_allocate_counter(efx, type); + if (IS_ERR(cnt)) { + rhashtable_remove_fast(&efx->tc->counter_id_ht, + &ctr->linkage, + efx_tc_counter_id_ht_params); + kfree(ctr); + return (void *)cnt; /* it's an ERR_PTR */ + } + ctr->cnt = cnt; + refcount_set(&ctr->ref, 1); + } + return ctr; +} + /* TC Channel. Counter updates are delivered on this channel's RXQ. */ static void efx_tc_handle_no_channel(struct efx_nic *efx) diff --git a/drivers/net/ethernet/sfc/tc_counters.h b/drivers/net/ethernet/sfc/tc_counters.h index f998cee324c7..85f4919271eb 100644 --- a/drivers/net/ethernet/sfc/tc_counters.h +++ b/drivers/net/ethernet/sfc/tc_counters.h @@ -26,6 +26,7 @@ struct efx_tc_counter { u32 fw_id; /* index in firmware counter table */ enum efx_tc_counter_type type; struct rhash_head linkage; /* efx->tc->counter_ht */ + u32 gen; /* Generation count at which this counter is current */ }; struct efx_tc_counter_index { @@ -40,6 +41,12 @@ int efx_tc_init_counters(struct efx_nic *efx); void efx_tc_destroy_counters(struct efx_nic *efx); void efx_tc_fini_counters(struct efx_nic *efx); +struct efx_tc_counter_index *efx_tc_flower_get_counter_index( + struct efx_nic *efx, unsigned long cookie, + enum efx_tc_counter_type type); +void efx_tc_flower_put_counter_index(struct efx_nic *efx, + struct efx_tc_counter_index *ctr); + extern const struct efx_channel_type efx_tc_channel_type; #endif /* EFX_TC_COUNTERS_H */ From patchwork Tue Nov 8 17:24:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036581 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 1E1AAC4332F for ; Tue, 8 Nov 2022 17:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234129AbiKHR0d (ORCPT ); Tue, 8 Nov 2022 12:26:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234448AbiKHR01 (ORCPT ); Tue, 8 Nov 2022 12:26:27 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2066.outbound.protection.outlook.com [40.107.220.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F30FF1DDF9 for ; Tue, 8 Nov 2022 09:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bI10RYVmRl/foAg+Z26LxzvMyQzYNdMsvkosiXouM5Ta3BSzBWLKGusYYDrP0HRKoxXhCSaaH/b+2J8rsw2q4XuoSc3nBhX9sdeDYavXNWfCZ02OMGLUnyTdRSIufbqZZNeqmO0mNtCcokCQBEFf/MF/eXOGf6jJwVIgJsZO7VfEzGzpUE6gqS5+8Cp46kh0dwEX2R8HvOIxz1WPUGo4rvM7g1BswxMkE+Vq2VRjf+idxW9AfVLVySbfHTTfGmNjohWdEoUtBQ/XTUC2mGZ4hM5sffveNoVTIWKxIeQ1ytAQnFcUc0TssxsbyI0l61zAKM26AXmV6P4s+5D9Fj9CjA== 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=UkxebyFZ2MV5Vton5mGT73Yag+gyfrAJk+1Rs2+unkM=; b=lG72MsWoyJVzTdvP2JksrW2M509G594kwu1vJbtL5o7nG/G1O3Hy9l05f3A7my6iYwT7WOKnTZzLoNWs+s78JDd7rV5792YA9R3xvD2QeyvwaM0W4IOmnuKhgHZsy9DIN9p03gSb+B1k/3zzhLsg8wTpsU1ZDrEjWmHndrmi83FAW7HC2dYk9gGPY2fO1S8pEX9Bh6cC6B4cq0ZMXlaZxvuSL4Rok+twMQ2jq56ErNEq325AJ6exXI94FYfS7D3XrJUoCXCYe883qBh3T29a8Z5+EigTPQggDgdzmSKGheLc//r0+zgezHZRyKf4/DkzudBWMM3nxZbMCUDlPfP+2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UkxebyFZ2MV5Vton5mGT73Yag+gyfrAJk+1Rs2+unkM=; b=za+qYRcHQ2LqUrz0XCIHxXKRFV0afV7Rv/OdDsGdhe0QYKK9QCG3tumpxcsspZW8ijf6Rxq8+V6Okcl0JhbTOSQIuglcCGocwTyZWyJf/D0K5FyTwyQsBy3ayVFS1tzbd7xqeOML+tpbnsCWAEYHBuj6sfb4S2J39O+3YrkzXlM= Received: from MW4P223CA0009.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::14) by SA1PR12MB6946.namprd12.prod.outlook.com (2603:10b6:806:24d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25; Tue, 8 Nov 2022 17:26:24 +0000 Received: from CO1NAM11FT097.eop-nam11.prod.protection.outlook.com (2603:10b6:303:80:cafe::c0) by MW4P223CA0009.outlook.office365.com (2603:10b6:303:80::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27 via Frontend Transport; Tue, 8 Nov 2022 17:26:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT097.mail.protection.outlook.com (10.13.175.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5813.12 via Frontend Transport; Tue, 8 Nov 2022 17:26:23 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:22 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:26:22 -0800 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:21 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 08/11] sfc: accumulate MAE counter values from update packets Date: Tue, 8 Nov 2022 17:24:49 +0000 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT097:EE_|SA1PR12MB6946:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e4f42d7-a26a-4360-55d1-08dac1ae5c01 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WdIQbiqi6MCF4ARIrTPGlZybNCUKTbLQqa6fBuOA4b+dQ87HY7122EtL/MFlrzaC3LtGhBmsxPOSM1or9pE7mNP2VdWRqKzakyqtJ1c7o05P7QyU3yd9VlmO9RfyWjVjZEIKaMluFjKG2ufZv/6GlvVLqDyqH+MV1s7r5JvaeQnC6e7mDJdOJLP0RrXAYQsftROHjoiC0wpBDMAPFLCTzfBUJJagAXCdpy5p2lB4R8fsSuK2JNAI1FEcNe+UAfi4U4oKOfKKo6cVI3hpQKEyEKRndzuxk2+lKCslpd9xtvPR48RHXe3VvmjD2F+UVkwkEjuv8wIXNhPPTYfBOLSLWFHJmd6h3dpdHpb3T+uDk4UiBA9Bw7Pyy+YeEuxyrqyZuWwW2vM8o5rIT99rrdjorjF9ulbX0eh+oEy/tXAzxV8A4hPwlMiThu2kfV7h5jbnhPCZVmYp9SNPWarrgkMH7/Sh6pVyUEd1m8I6FbCT77mTdqYunIPDAMtiL6mHuEBsrrIewbXkb2BocfUkpAiEc+B7bQlVaeIP5Jr4zVWa/P0MYkeihbP1GVaJ50JiCM3U2BPLpUebwxGPz475s47RlYbKC0/TlspemF1z7fKNw5RkNeWfNE68Ib2wFLNIFMCw/1n9lJyFVP0aFiQF5KvDBJh0IjPoLL16HAWxL4qeJqiXwthv5OLKGBf05Ty3j0KlOyxreCwiMWdSPSuVSOStci+K/GJPHQ0ZP+Rr5OvwmzmZgHsjp4Nc8MDv9XxtAgxa4AO7alclNU0jf4XFnYENtOqj5LlvIbMn3/tlAShxuIpFWOtCXpixZy+GFQVS9YXH X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(136003)(39860400002)(346002)(396003)(376002)(451199015)(40470700004)(36840700001)(46966006)(82310400005)(36756003)(8936002)(81166007)(40480700001)(83380400001)(356005)(110136005)(4326008)(8676002)(478600001)(2906002)(15650500001)(41300700001)(70206006)(70586007)(82740400003)(316002)(9686003)(54906003)(186003)(426003)(336012)(47076005)(26005)(36860700001)(40460700003)(2876002)(5660300002)(6636002)(86362001)(55446002)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:23.6845 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e4f42d7-a26a-4360-55d1-08dac1ae5c01 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT097.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6946 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree Add the packet and byte counts to the software running total, and store the latest jiffies every time the counter is bumped. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/tc_counters.c | 54 +++++++++++++++++++++++++- drivers/net/ethernet/sfc/tc_counters.h | 4 ++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index 6fd07ce61eb7..76a2e8ac517a 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -86,6 +86,8 @@ static struct efx_tc_counter *efx_tc_flower_allocate_counter(struct efx_nic *efx if (!cnt) return ERR_PTR(-ENOMEM); + spin_lock_init(&cnt->lock); + cnt->touched = jiffies; cnt->type = type; rc = efx_mae_allocate_counter(efx, cnt); @@ -131,9 +133,22 @@ static void efx_tc_flower_release_counter(struct efx_nic *efx, * is handled by the generation count. */ synchronize_rcu(); + EFX_WARN_ON_PARANOID(spin_is_locked(&cnt->lock)); kfree(cnt); } +static struct efx_tc_counter *efx_tc_flower_find_counter_by_fw_id( + struct efx_nic *efx, int type, u32 fw_id) +{ + struct efx_tc_counter key = {}; + + key.fw_id = fw_id; + key.type = type; + + return rhashtable_lookup_fast(&efx->tc->counter_ht, &key, + efx_tc_counter_ht_params); +} + /* TC cookie to counter mapping */ void efx_tc_flower_put_counter_index(struct efx_nic *efx, @@ -241,7 +256,44 @@ static void efx_tc_counter_update(struct efx_nic *efx, u32 counter_idx, u64 packets, u64 bytes, u32 mark) { - /* Software counter objects do not exist yet, for now we ignore this */ + struct efx_tc_counter *cnt; + + rcu_read_lock(); /* Protect against deletion of 'cnt' */ + cnt = efx_tc_flower_find_counter_by_fw_id(efx, counter_type, counter_idx); + if (!cnt) { + /* This can legitimately happen when a counter is removed, + * with updates for the counter still in-flight; however this + * should be an infrequent occurrence. + */ + if (net_ratelimit()) + netif_dbg(efx, drv, efx->net_dev, + "Got update for unwanted MAE counter %u type %u\n", + counter_idx, counter_type); + goto out; + } + + spin_lock_bh(&cnt->lock); + if ((s32)mark - (s32)cnt->gen < 0) { + /* This counter update packet is from before the counter was + * allocated; thus it must be for a previous counter with + * the same ID that has since been freed, and it should be + * ignored. + */ + } else { + /* Update latest seen generation count. This ensures that + * even a long-lived counter won't start getting ignored if + * the generation count wraps around, unless it somehow + * manages to go 1<<31 generations without an update. + */ + cnt->gen = mark; + /* update counter values */ + cnt->packets += packets; + cnt->bytes += bytes; + cnt->touched = jiffies; + } + spin_unlock_bh(&cnt->lock); +out: + rcu_read_unlock(); } static void efx_tc_rx_version_1(struct efx_nic *efx, const u8 *data, u32 mark) diff --git a/drivers/net/ethernet/sfc/tc_counters.h b/drivers/net/ethernet/sfc/tc_counters.h index 85f4919271eb..a5a6d8cb1365 100644 --- a/drivers/net/ethernet/sfc/tc_counters.h +++ b/drivers/net/ethernet/sfc/tc_counters.h @@ -26,7 +26,11 @@ struct efx_tc_counter { u32 fw_id; /* index in firmware counter table */ enum efx_tc_counter_type type; struct rhash_head linkage; /* efx->tc->counter_ht */ + spinlock_t lock; /* Serialises updates to counter values */ u32 gen; /* Generation count at which this counter is current */ + u64 packets, bytes; + /* jiffies of the last time we saw packets increase */ + unsigned long touched; }; struct efx_tc_counter_index { From patchwork Tue Nov 8 17:24:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036582 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 2DFE3C4321E for ; Tue, 8 Nov 2022 17:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234504AbiKHR0f (ORCPT ); Tue, 8 Nov 2022 12:26:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234483AbiKHR03 (ORCPT ); Tue, 8 Nov 2022 12:26:29 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2081.outbound.protection.outlook.com [40.107.223.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C07731E705 for ; Tue, 8 Nov 2022 09:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XQR9IQL8lHwWeVnbEegJFwwTTWl5aPYFLDUFkBjt/swbJ4ZmCFJ6IvYe+x4j9MWZoG1VDLUNnIBFcfsIHlrPQqVhcDf4sex6XkI2BHcX0it7a465Bh3WzMLl99RUPoTW4KxwKljv4i/KQSKIgqIS+nQbswPkZrGpiRoyr7CUcr7W6FBb0ClEKiXqZktEuf+HgsB2XJdXnKsFrKW/yQre6gMYkzIm8WuKUUk8Y6s/t4BLFUh8pJE4SOIUZtxwrIP+vvSNytcKK6+xuM+OUDWPtY0YbCeAM3h+KqDbCgoGKDCL8QjqFVTMsh6q8x9fyrw0gy54t1vCJWpFOQ0hNdsx0g== 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=TGbFE90OGRjXfO9F94XuGIR3qOHb4ykwxgjQ3899dZA=; b=cOt2fDilHhqvuuG41z/mA/4t8fbpzpeTiujxM+/u1ujc1blbgWPXBu72yRgkX94fIurnIceKMitjzUzI6ZiupyFol1XqgltjDu5BDwT+eNjA5hvK3w97StdlnaYB0W4xx16Hc+bkhwhkMNsDrtZXrW7rWVJmc2ExIyTj7R+/q1Yex09NrEfgmY0o5yfh8iN/XxEqPTZVJkuNZeOylFcz4KpI9v3MFWDA9yg68kDpIJWc43isztg4ru6pbpYQyAPbtG7olEomGI5mKY3EaTTcdGD7JTYR+2zsWDzCUgEwDVhpGToQjsUk28rGpv13xCHdF8I1vADxMVlRkA92lPJXtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TGbFE90OGRjXfO9F94XuGIR3qOHb4ykwxgjQ3899dZA=; b=4g3TaCe0alAPu4kifJw2jdjbN7dj8YJ7xEkcwL0ZiI9QK3vfzEzJt2lR/1SlJT8EBO4iOBylnRXHXAClI/gdgoqEivo42p45RD3EV1JSVmd4hGQs27ERtZukjjHARlMJhng0XlnjmbwRzITjo5R6318QMhqR8p9jnVHYFbof7ds= Received: from MW4PR02CA0003.namprd02.prod.outlook.com (2603:10b6:303:16d::30) by CO6PR12MB5475.namprd12.prod.outlook.com (2603:10b6:5:354::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Tue, 8 Nov 2022 17:26:24 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:16d:cafe::39) by MW4PR02CA0003.outlook.office365.com (2603:10b6:303:16d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27 via Frontend Transport; Tue, 8 Nov 2022 17:26:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Tue, 8 Nov 2022 17:26:24 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:24 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:26:23 -0800 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:22 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 09/11] sfc: attach an MAE counter to TC actions that need it Date: Tue, 8 Nov 2022 17:24:50 +0000 Message-ID: <71a61a05259ecd0390ccf0e38ccf2bd755697b37.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT047:EE_|CO6PR12MB5475:EE_ X-MS-Office365-Filtering-Correlation-Id: 92cd9fe4-c7c5-4702-7674-08dac1ae5ca0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xx+T9u3V+BVBeIGGhS3diNaW5KDyWQFwBYjpuonhRN26Wz02+ANLAwetBOZyptG1toeDxusq4USUb4w2usrU00+vuwKkyKMPxsKJ8guNl5KAJ/Bq36BeSdVMAjR0zLjWZbt88tLGCe/FwTmlAClwRFPx3B1Ojctwce0GFrkdyMDKErovs9hilIcIA+rZyUTyTQvPWzW92qHFoG4pl6krHIiCTjKkdUlaWKJ1ghV7PmwP+a3RNxI1+uyX038T2WxEHIvCD4CVzeIsbGj5jPB9lkF8Z48xE5EwW2nRfke+JaO53LZNX5yaEZe3NO0jPJUUAmFkHVar8ZuXof+48c7QQ2NLYKkTq2rCme5+7SEPEgAGrUN/MHq/sZ3Bg2YYhGL2fMspsEgsvB3/SK2QMaYuw4FZ6Efuo4jf8Q1cwziXby1zQrqoQibjeL+0n6hq1Tv/cdAEKwb5j9SZaL1GYox7W4ExDQQgVgY1B32wudkZMSiAR87RreXtmCa8MjBhqaXf/i+hVeAQZntZX9jD2CzeXCNajAuULJhFeQkLvRAHr75G5tXCyOO8AxtfuLq2YCoMZ2vnpYnVZuCpHgyue344h7vRG66cm8CGNamqIWoBYP+DEfGgM6O2o48SS8kago47b0sDTnwbLGhIT9kbYuhCFJ5hL9CqkcBKgb1O4WgItWgnDeyZzFEBXf1yhqMXOnp54psUOpVjZdnbia+2WH3N14w46WOZ94Kc4YVI5Um7/dpclO5hXvfcwhL2M81dNp2p/BabHWEBe0vjiRs8yIAl/XkBBA7RG5XwFYPDNXQXuIk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(39860400002)(346002)(136003)(451199015)(36840700001)(46966006)(40470700004)(82740400003)(186003)(336012)(426003)(47076005)(26005)(9686003)(36860700001)(2876002)(83380400001)(2906002)(5660300002)(40460700003)(54906003)(110136005)(82310400005)(6636002)(40480700001)(6666004)(8676002)(4326008)(8936002)(41300700001)(478600001)(316002)(70586007)(70206006)(81166007)(356005)(55446002)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:24.7430 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92cd9fe4-c7c5-4702-7674-08dac1ae5ca0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5475 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree The only actions that expect stats (that sfc HW supports) are gact shot (drop), mirred redirect and mirred mirror. Since these are 'deliverish' actions that end an action-set, we only require at most one counter per action-set. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/mae.c | 8 ++++++-- drivers/net/ethernet/sfc/tc.c | 25 +++++++++++++++++++++++++ drivers/net/ethernet/sfc/tc.h | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c index f227b4f2a9a0..583baf69981c 100644 --- a/drivers/net/ethernet/sfc/mae.c +++ b/drivers/net/ethernet/sfc/mae.c @@ -501,8 +501,12 @@ int efx_mae_alloc_action_set(struct efx_nic *efx, struct efx_tc_action_set *act) MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL); MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID, MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL); - MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, - MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_NULL); + if (act->count && !WARN_ON(!act->count->cnt)) + MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, + act->count->cnt->fw_id); + else + MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, + MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_NULL); MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, MC_CMD_MAE_COUNTER_LIST_ALLOC_OUT_COUNTER_LIST_ID_NULL); MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID, diff --git a/drivers/net/ethernet/sfc/tc.c b/drivers/net/ethernet/sfc/tc.c index 8ea7f5213049..1cfc50f2398e 100644 --- a/drivers/net/ethernet/sfc/tc.c +++ b/drivers/net/ethernet/sfc/tc.c @@ -77,6 +77,8 @@ static void efx_tc_free_action_set(struct efx_nic *efx, */ list_del(&act->list); } + if (act->count) + efx_tc_flower_put_counter_index(efx, act->count); kfree(act); } @@ -376,6 +378,28 @@ static int efx_tc_flower_replace(struct efx_nic *efx, goto release; } + if ((fa->id == FLOW_ACTION_REDIRECT || + fa->id == FLOW_ACTION_MIRRED || + fa->id == FLOW_ACTION_DROP) && fa->hw_stats) { + struct efx_tc_counter_index *ctr; + + if (!(fa->hw_stats & FLOW_ACTION_HW_STATS_DELAYED)) { + NL_SET_ERR_MSG_FMT_MOD(extack, "hw_stats_type %u not supported (only 'delayed')", + fa->hw_stats); + rc = -EOPNOTSUPP; + goto release; + } + + ctr = efx_tc_flower_get_counter_index(efx, tc->cookie, + EFX_TC_COUNTER_TYPE_AR); + if (IS_ERR(ctr)) { + rc = PTR_ERR(ctr); + NL_SET_ERR_MSG_MOD(extack, "Failed to obtain a counter"); + goto release; + } + act->count = ctr; + } + switch (fa->id) { case FLOW_ACTION_DROP: rc = efx_mae_alloc_action_set(efx, act); @@ -412,6 +436,7 @@ static int efx_tc_flower_replace(struct efx_nic *efx, if (fa->id == FLOW_ACTION_REDIRECT) break; /* end of the line */ /* Mirror, so continue on with saved act */ + save.count = NULL; act = kzalloc(sizeof(*act), GFP_USER); if (!act) { rc = -ENOMEM; diff --git a/drivers/net/ethernet/sfc/tc.h b/drivers/net/ethernet/sfc/tc.h index 6c8ebb2d79c0..418ce8c13a06 100644 --- a/drivers/net/ethernet/sfc/tc.h +++ b/drivers/net/ethernet/sfc/tc.h @@ -20,6 +20,7 @@ struct efx_tc_action_set { u16 deliver:1; + struct efx_tc_counter_index *count; u32 dest_mport; u32 fw_id; /* index of this entry in firmware actions table */ struct list_head list; From patchwork Tue Nov 8 17:24:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036584 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 BBBE5C43217 for ; Tue, 8 Nov 2022 17:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234523AbiKHR0h (ORCPT ); Tue, 8 Nov 2022 12:26:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234089AbiKHR0b (ORCPT ); Tue, 8 Nov 2022 12:26:31 -0500 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2061.outbound.protection.outlook.com [40.107.95.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EEC44FFB7 for ; Tue, 8 Nov 2022 09:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ARLIQVh8PZNz73pUma9tRegwVb5l0/fUg9SMB8iDRwo3UC8Y/59cp/vwnbX0HPKrx7tb2LGDRSm/Mkh3z1x4n95VC/Oz7cf0OwJxV2MjwW0NP/Qgk6Ivhp4vinCEEoUmAy7/AnMkYgnVwRuypuJHWwAfHOS9LsFXTretzLo7gZFNToy/qI5h0HCmJSJxa2pku4a0ZNZBZs6D07iFnvnGgCykkeWLdvZaEnIL1lYdFZl4qHkkX/TkkEQeiN/x2cKuErXvy3mx3aWcIllQYaFe3C+VVm8As2qk7fDWeoVEog1NbfS1scW0c+JlwDnUPkDczhg7xecS98FYT5muThu0Bg== 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=JBqXvh/xxIlCyP1O7HuwysdOrMlm+f0BQPFvmuFBnrA=; b=IfOgiU5dBeiCLseyit277BHqNX2rs9rOwNRoBlCdJ+HrOd381KwRT7FuUpH0Bt7E2hdCC8s0hPKRSIHV9Phd105qM223O7iuhBRUbBDPjrGipcIMdzJ367ceY4XdjDUuEoCs8mJ44EJPEgzPpbTTHMiNjX8VWxVpZ6FW1fdSswLUU4x3KvAMqJDOBDmnoAvHEcyZNJZLiiHnpCud6sb47bfCjthUliD9ycaMfFDGkgmhJhvmmaPCX0nLeMi76zBqBwy+0aQLCYkm32qBDwaO6CfKjyB8O20HMNU3D6GgBSmuguBR5pVy+DwHCu5efNWiy4r0Axp3oJjcmgpYsWZxrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JBqXvh/xxIlCyP1O7HuwysdOrMlm+f0BQPFvmuFBnrA=; b=FMOW0hYupoo/aZhick+DKUbIhnZpiOErWh9flNhy6mXqmOqJ4+heXUo3jF2YE/Vt3PcCWj0/b2gu9a3ybndKgA1i3w39K/9ssiQ70EO/pyAeJObt9EEVbgUnc0vEpWm7s53Ygu5xd7umEGZERq7yYwqulMzgxY3g9m9WQfkbQ8k= Received: from MW4PR03CA0056.namprd03.prod.outlook.com (2603:10b6:303:8e::31) by SJ1PR12MB6074.namprd12.prod.outlook.com (2603:10b6:a03:45f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Tue, 8 Nov 2022 17:26:26 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8e:cafe::3e) by MW4PR03CA0056.outlook.office365.com (2603:10b6:303:8e::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25 via Frontend Transport; Tue, 8 Nov 2022 17:26:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Tue, 8 Nov 2022 17:26:26 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:25 -0600 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:24 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 10/11] sfc: validate MAE action order Date: Tue, 8 Nov 2022 17:24:51 +0000 Message-ID: <586b672920631f86885620a624de7de0a3b21419.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|SJ1PR12MB6074:EE_ X-MS-Office365-Filtering-Correlation-Id: 862d317a-ab2d-4daa-715c-08dac1ae5d96 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J2CWwCOKhl1omzQFezVhn+2LHkPbe0AkfpGyQq0/K+2ifSNyuyDsMnTzPJRVJN0roqPEFhlijqCa3y7vW3xQ3ZwLQV3sJnYcLrOmjBPiht6v15nBF2CCKWteKitGSn+hLPY3VggIVOeapBJVMRjHLKA1HIw2I11Hljnjs1tt9BvdTZbdXY1+a1Vv3OH9wIQFxD1ZxRmV/x9D2PHYzOw+2LLOvLsmMVkVI8WonaEQUR1gn9G48dC/HVI6TPSlMqMtDKZ5acMMkPGATp7JbqPv56YuolRk6f4fNmZ/r/dSSX/ajQzuyVf0P9NSxh6xNwpDORQh1wfWgtsH3vy4p3NM4PAuIhjIOuTt45TftP9ocYyJroMi4xOMDoxvmIeXv9dS3jk0EbStdvnjOSdfidTIqD1Ct8PLkir5Bmg1zbbWZqgUv4M1MEl6HdWRHfFmpn/tH5aGuen+V66k6GlOEKQ4AIFsMwU77UEjz+Qze5rITr6vro/jZnELaayJ4v2VsznJnGl6PKRaSUUVZHF1NEdwFsD+phJ+Otwi77ZbZ6nexM8206IDSi9uTVpG+b4MnjdTAxp+O6oCsk6TsTZfsMJ6eUTS2QIgkEsE0eJl3rrXiV81Z9i105Sm7Nebw1BPCEyD39yyk/wCOMgqFoOP0Q+YtgvnASB2E38WiBL7ffKsASGv5oJeXmWn4VvIsTUnaWaDNYZMJEwJ1LJ6u4cxwvKd+pW7DRqE/9L60wzNhmq5uJb96/HO2bVkuXf1tdjVqHi2UdGpeqbPx4sn3JkiIAJb/eE4g1J/ZEIEVpq/25o1mjqWFMoXSz/ckck/fLbLJI+Z X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(39860400002)(376002)(396003)(136003)(451199015)(36840700001)(40470700004)(46966006)(8676002)(41300700001)(4326008)(6636002)(70586007)(36860700001)(70206006)(316002)(2876002)(110136005)(81166007)(5660300002)(8936002)(54906003)(356005)(36756003)(426003)(40460700003)(47076005)(55446002)(26005)(40480700001)(9686003)(186003)(336012)(2906002)(86362001)(478600001)(82740400003)(83380400001)(6666004)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:26.3394 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 862d317a-ab2d-4daa-715c-08dac1ae5d96 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6074 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree Currently the only actions supported are COUNT and DELIVER, which can only happen in the right order; but when more actions are added, it will be necessary to check that they are only used in the same order in which the hardware performs them (since the hardware API takes an action *set* in which the order is implicit). For instance, a VLAN pop must not follow a VLAN push. Most practical use-cases should be unaffected by these restrictions. Add a function efx_tc_flower_action_order_ok() that checks whether it is appropriate to add a specified action to the existing action-set. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/tc.c | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/net/ethernet/sfc/tc.c b/drivers/net/ethernet/sfc/tc.c index 1cfc50f2398e..bf4979007f31 100644 --- a/drivers/net/ethernet/sfc/tc.c +++ b/drivers/net/ethernet/sfc/tc.c @@ -284,6 +284,29 @@ static int efx_tc_flower_parse_match(struct efx_nic *efx, return 0; } +/* For details of action order constraints refer to SF-123102-TC-1§12.6.1 */ +enum efx_tc_action_order { + EFX_TC_AO_COUNT, + EFX_TC_AO_DELIVER +}; +/* Determine whether we can add @new action without violating order */ +static bool efx_tc_flower_action_order_ok(const struct efx_tc_action_set *act, + enum efx_tc_action_order new) +{ + switch (new) { + case EFX_TC_AO_COUNT: + if (act->count) + return false; + fallthrough; + case EFX_TC_AO_DELIVER: + return !act->deliver; + default: + /* Bad caller. Whatever they wanted to do, say they can't. */ + WARN_ON_ONCE(1); + return false; + } +} + static int efx_tc_flower_replace(struct efx_nic *efx, struct net_device *net_dev, struct flow_cls_offload *tc, @@ -383,6 +406,25 @@ static int efx_tc_flower_replace(struct efx_nic *efx, fa->id == FLOW_ACTION_DROP) && fa->hw_stats) { struct efx_tc_counter_index *ctr; + /* Currently the only actions that want stats are + * mirred and gact (ok, shot, trap, goto-chain), which + * means we want stats just before delivery. Also, + * note that tunnel_key set shouldn't change the length + * — it's only the subsequent mirred that does that, + * and the stats are taken _before_ the mirred action + * happens. + */ + if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_COUNT)) { + /* All supported actions that count either steal + * (gact shot, mirred redirect) or clone act + * (mirred mirror), so we should never get two + * count actions on one action_set. + */ + NL_SET_ERR_MSG_MOD(extack, "Count-action conflict (can't happen)"); + rc = -EOPNOTSUPP; + goto release; + } + if (!(fa->hw_stats & FLOW_ACTION_HW_STATS_DELAYED)) { NL_SET_ERR_MSG_FMT_MOD(extack, "hw_stats_type %u not supported (only 'delayed')", fa->hw_stats); @@ -413,6 +455,14 @@ static int efx_tc_flower_replace(struct efx_nic *efx, case FLOW_ACTION_REDIRECT: case FLOW_ACTION_MIRRED: save = *act; + + if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_DELIVER)) { + /* can't happen */ + rc = -EOPNOTSUPP; + NL_SET_ERR_MSG_MOD(extack, "Deliver action violates action order (can't happen)"); + goto release; + } + to_efv = efx_tc_flower_lookup_efv(efx, fa->dev); if (IS_ERR(to_efv)) { NL_SET_ERR_MSG_MOD(extack, "Mirred egress device not on switch"); From patchwork Tue Nov 8 17:24:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: edward.cree@amd.com X-Patchwork-Id: 13036614 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 3139CC4332F for ; Tue, 8 Nov 2022 17:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231341AbiKHR1O (ORCPT ); Tue, 8 Nov 2022 12:27:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234517AbiKHR0f (ORCPT ); Tue, 8 Nov 2022 12:26:35 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2068.outbound.protection.outlook.com [40.107.92.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FB0F1DF13 for ; Tue, 8 Nov 2022 09:26:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jPSt0joG0P3g9PPHd0qtWSdc8woKYurmG48XwqdKva4GZ9uIXOV49eUcaL+R04jSmFsI2g6snag7MdR2NuCScxTH4tNqfRwXwKQrH8hf1j7iQ2tpSkoBuPOVgSLUxsHeUFTXSiW4oPAvu1mIxt5pq2b1ZD28t+ZQTZRSa03v0/slYowpqjxc3vcnxAy98GyEpxMamTofAo7iVpMY/oRcEv20AZIT6nxVzlD0ZbPcmTLGZimvYRgtivrWHlzLfa3uXKpd3Ki7yp+I/msWx4Jj1Gq23kKeCyVqxZU9ZBBo4QAiOGdu7JAvykL91JqtuJPseyA+ni7uHnvNqlqa7GEpaA== 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=otn9FCXXyxZkHyzx6LWrupE9D6NMNNjDbTcjs1N3ALw=; b=SG5nXJDA3Ax6/cxIm9FC7JUtvL9Ap/Py8Vn6j1MNbYCZq57xxCMh2SA6Xfn8XnwWeDr94SwlcU0m7DmHFndZnLQORLT9QJ9knNIbDbVETPXRrhgaZbEbS+wsLU10AynfcaVdzvJgboipVhaLKOh6ruJN8Pa6/fpzjrJrmcZ9tfTFk1W8JfGSSP8gti7ho3wq95o23E+28DaKz17x6TeUQiCL7dSJ57cCpfqUkCeDn6UUvdL3HOCQvUq/xmjFziAiluTc9A2/R4rIF5zFdkDq5oFpvPpsrGtSBJr/yfMnasp9lOnlQVsEuYgIPg5hOW2OkVO1WOF8gkOBETO4Nn5QYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=otn9FCXXyxZkHyzx6LWrupE9D6NMNNjDbTcjs1N3ALw=; b=e1wwivXkB3a5TF//gROm5c+Ml+75zFhYoJNO9ECOyysnwri39RV/2W9MALN5oENuzG6f1PoaN7WUtQLW4VNfKt12BLdYJrXnkiojxyMIMUF+LZuh9bWhzXD4um/F5i/8TQSbSiYpeMvoAU1pxrT/U2e96PzVkEPAX0Co+My9H/o= Received: from MW4PR03CA0039.namprd03.prod.outlook.com (2603:10b6:303:8e::14) by BY5PR12MB4290.namprd12.prod.outlook.com (2603:10b6:a03:20e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Tue, 8 Nov 2022 17:26:29 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8e:cafe::12) by MW4PR03CA0039.outlook.office365.com (2603:10b6:303:8e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26 via Frontend Transport; Tue, 8 Nov 2022 17:26:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Tue, 8 Nov 2022 17:26:29 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 11:26:26 -0600 Received: from xcbecree41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 8 Nov 2022 11:26:25 -0600 From: To: , CC: , , , , , Edward Cree Subject: [PATCH net-next 11/11] sfc: implement counters readout to TC stats Date: Tue, 8 Nov 2022 17:24:52 +0000 Message-ID: <7144a877c276bf5dc64a4a4325f35939ca75c262.1667923490.git.ecree.xilinx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|BY5PR12MB4290:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e9af9ec-62b2-4427-dae2-08dac1ae5f8f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GKvn9TH6AqMjQlO91YW7p8/+EsgUvziJ2o7BrryabsjFAjYjwt+P8biDKeEfhQxU78srGEu2CsBzmpAO+u1DDQ5VLOcgTqYfxk3I3sbyLRONnkbu+vdEP9XQRKh+Z2E4YBhjPZJsNYcILaopU0yiMQbn+4heUIrL/oDSToAr4HOve/wsGfG5nwPmIm4sOZkh+wlTxpSUgkyFHH5FVSdeuFNDa+owtGMtboI5qxfvf6v4EjTpXaIkrsBKxoJnRxn4Ow3jBu/XVBfcdTMrd7ODkaWwLavXfAekI/j5/M1tdDPvMriyqhavpghkJ5d9MReVVPbCsVdgcp4Rc8CYr0ydAbDoioNoyB2Rc9tRkwIRVt+vHAXTCYcSPT8H9JyjdkKnfI350C0Fz9f7h01Gb/t2RhdNMkFv7tB7GVz9ECw8oDicSF6Lu1xl5Oii5rYFuQZX15pZjNPLM+kF9YPusxOroY71srt929zWaCOD9AcaFueKpBOBjlhSGiadViCAe5dhYJOvWex8x+lbyE7ZW4JSTHDCImSc00cKOekw39hTMK1v1qM2JRtpsqfBz4MRm2a7bSECnovnTynMVdCVNmvtNXwxTZkY2yacecpA1PDOiOW3rpw+42KIqirIe0WOEB0fQn5JYHVpdbR8TEqZ5uhRCEgJPapAOJM9s7bXRm/XtrzcXQFENTYLwguqL2uVkRLMhkUvfMFXoFqBxGQGneStQ/GAbDqeWxYP5SiO7ona5R/oCRP3PoY9hwAx5Os/BfTLR4Meg6kPV9Pv03xMDiSTa70FrfxrqVFXJdaspvVZACQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(376002)(346002)(39860400002)(136003)(451199015)(46966006)(40470700004)(36840700001)(186003)(82740400003)(9686003)(26005)(81166007)(336012)(36756003)(40480700001)(356005)(86362001)(426003)(83380400001)(40460700003)(55446002)(82310400005)(47076005)(8676002)(36860700001)(4326008)(70206006)(2906002)(2876002)(5660300002)(8936002)(70586007)(41300700001)(478600001)(6666004)(6636002)(110136005)(54906003)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 17:26:29.6517 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e9af9ec-62b2-4427-dae2-08dac1ae5f8f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4290 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edward Cree On FLOW_CLS_STATS, look up the MAE counter by TC cookie, and report the change in packet and byte count since the last time FLOW_CLS_STATS read them. Signed-off-by: Edward Cree --- drivers/net/ethernet/sfc/tc.c | 39 ++++++++++++++++++++++++++ drivers/net/ethernet/sfc/tc_counters.c | 10 +++++++ drivers/net/ethernet/sfc/tc_counters.h | 3 ++ 3 files changed, 52 insertions(+) diff --git a/drivers/net/ethernet/sfc/tc.c b/drivers/net/ethernet/sfc/tc.c index bf4979007f31..deeaab9ee761 100644 --- a/drivers/net/ethernet/sfc/tc.c +++ b/drivers/net/ethernet/sfc/tc.c @@ -595,6 +595,42 @@ static int efx_tc_flower_destroy(struct efx_nic *efx, return 0; } +static int efx_tc_flower_stats(struct efx_nic *efx, struct net_device *net_dev, + struct flow_cls_offload *tc) +{ + struct netlink_ext_ack *extack = tc->common.extack; + struct efx_tc_counter_index *ctr; + struct efx_tc_counter *cnt; + u64 packets, bytes; + + ctr = efx_tc_flower_find_counter_index(efx, tc->cookie); + if (!ctr) { + /* See comment in efx_tc_flower_destroy() */ + if (!IS_ERR(efx_tc_flower_lookup_efv(efx, net_dev))) + if (net_ratelimit()) + netif_warn(efx, drv, efx->net_dev, + "Filter %lx not found for stats\n", + tc->cookie); + NL_SET_ERR_MSG_MOD(extack, "Flow cookie not found in offloaded rules"); + return -ENOENT; + } + if (WARN_ON(!ctr->cnt)) /* can't happen */ + return -EIO; + cnt = ctr->cnt; + + spin_lock_bh(&cnt->lock); + /* Report only new pkts/bytes since last time TC asked */ + packets = cnt->packets; + bytes = cnt->bytes; + flow_stats_update(&tc->stats, bytes - cnt->old_bytes, + packets - cnt->old_packets, 0, cnt->touched, + FLOW_ACTION_HW_STATS_DELAYED); + cnt->old_packets = packets; + cnt->old_bytes = bytes; + spin_unlock_bh(&cnt->lock); + return 0; +} + int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev, struct flow_cls_offload *tc, struct efx_rep *efv) { @@ -611,6 +647,9 @@ int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev, case FLOW_CLS_DESTROY: rc = efx_tc_flower_destroy(efx, net_dev, tc); break; + case FLOW_CLS_STATS: + rc = efx_tc_flower_stats(efx, net_dev, tc); + break; default: rc = -EOPNOTSUPP; break; diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c index 76a2e8ac517a..2bba5d3a2fdb 100644 --- a/drivers/net/ethernet/sfc/tc_counters.c +++ b/drivers/net/ethernet/sfc/tc_counters.c @@ -198,6 +198,16 @@ struct efx_tc_counter_index *efx_tc_flower_get_counter_index( return ctr; } +struct efx_tc_counter_index *efx_tc_flower_find_counter_index( + struct efx_nic *efx, unsigned long cookie) +{ + struct efx_tc_counter_index key = {}; + + key.cookie = cookie; + return rhashtable_lookup_fast(&efx->tc->counter_id_ht, &key, + efx_tc_counter_id_ht_params); +} + /* TC Channel. Counter updates are delivered on this channel's RXQ. */ static void efx_tc_handle_no_channel(struct efx_nic *efx) diff --git a/drivers/net/ethernet/sfc/tc_counters.h b/drivers/net/ethernet/sfc/tc_counters.h index a5a6d8cb1365..8fc7c4bbb29c 100644 --- a/drivers/net/ethernet/sfc/tc_counters.h +++ b/drivers/net/ethernet/sfc/tc_counters.h @@ -29,6 +29,7 @@ struct efx_tc_counter { spinlock_t lock; /* Serialises updates to counter values */ u32 gen; /* Generation count at which this counter is current */ u64 packets, bytes; + u64 old_packets, old_bytes; /* Values last time passed to userspace */ /* jiffies of the last time we saw packets increase */ unsigned long touched; }; @@ -50,6 +51,8 @@ struct efx_tc_counter_index *efx_tc_flower_get_counter_index( enum efx_tc_counter_type type); void efx_tc_flower_put_counter_index(struct efx_nic *efx, struct efx_tc_counter_index *ctr); +struct efx_tc_counter_index *efx_tc_flower_find_counter_index( + struct efx_nic *efx, unsigned long cookie); extern const struct efx_channel_type efx_tc_channel_type;