Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6287561rwr; Tue, 9 May 2023 12:59:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7aib6R2cxfQiIL4APZbfzt3L5mim71INpDRjlJj64MXB+akdc50IEQvyQZr9lNv5koc/Ln X-Received: by 2002:a05:6a20:8f01:b0:ff:d067:351 with SMTP id b1-20020a056a208f0100b000ffd0670351mr13386034pzk.54.1683662381247; Tue, 09 May 2023 12:59:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683662381; cv=pass; d=google.com; s=arc-20160816; b=vBkN6pEjXTY+fEAb8IQC+smF6922+NoTZmwitpT2RBRbyHVOUMy8GtaMOxo1r+ml7p O6UmtqQ4z2uTznszc/3A6zgeowk8daTkIQdftZ5WcSl8Iz/rLZkchkMl721xat2G7SfY wnqeTGOODoFwIwN3713DSgu3jRj9LvtxGFFA7o6tMZuXzEivsiPS5w0UcxMr+0I5r4AK ffirhozUI+7VbSMBgbKmoPOVjMO+E5hHCL7wDN9qFxyRXoqzHq0N2u6v0F4n2rjlE+ZM 7UcobKVgdq3R3FtN9k+I49jl+7OwLXaIH0bNGtAYaHGdmkT/tAhNk2kMnGo6hDTHLqv8 G67w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=9EGPd5u6hNOZNDVhEzExkqKCgikBQi9KIyjSLctNLVo=; b=PXIqWZOf7lsSxzg2UWAa4pCdGaGmUr9UdnCGvkw1nZUeJOVP1qajql9QY8FfGww920 W2uk44f8D0tpup7YtqkSKvlgWZrVCaOcnOu5IsAtoh3Z7SdNdDqToAMA5+lg09o4oiD0 6O7NJgEdAdZYshdl3zNskdsk8uyGtexZkxbFxv5SODfGXu5rPQVKIP1Xf8xzOugS+DiP jIzGq4HxgSHPRZoB4n7bwd8XfpoiTUA9Xzx4JXNnyz1cjUGx7RD4Uszex4ODwbUSI4jY IMvxYujCe4OKOTgGBaX2tZ8Wxb544VdZaZ/Kcgk/KrgEY8gJYt0yLaz/2ODR8UaaE7Ub B+jg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=deThfI8Z; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k189-20020a6384c6000000b00518664086b1si2173432pgd.861.2023.05.09.12.59.29; Tue, 09 May 2023 12:59:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=deThfI8Z; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235240AbjEITjw (ORCPT + 99 others); Tue, 9 May 2023 15:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234622AbjEITj1 (ORCPT ); Tue, 9 May 2023 15:39:27 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2081.outbound.protection.outlook.com [40.107.8.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAC394EE4; Tue, 9 May 2023 12:39:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UebSHqaibrODI4hLl4K+8FII8JYVe1WQZcSRReBbyff0JCJvKV1c/Rfcp4Cn0hEGHSINA/aLZojmVOCH1fKvl7WDrvxd7z6q1P5MnxaIBhQcJZ6bKA+Jq6Q8eVRdha+/nHBaSvdg9bBDhqr9Irh0DnHpa340yyO+ItFwJJN7OmVtoFGuXq3MBh5RVJdicE6AHnl+LUMIxO3edZxKmCjXz1H7pkz9WUq8KVI2MnuWkS814hkUoKDySnxd5attZM3K/2kCaRq5+N2Za6QbV7v7/uwGTdgTEu9v4YXgwRZRQ1cDhvDKWCW+SCJCJ1nwiHLnc9rGQFqKcGUp9au3zGbBiQ== 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=9EGPd5u6hNOZNDVhEzExkqKCgikBQi9KIyjSLctNLVo=; b=fkD+SjK3OinAxVzFPhZukuj4igTWJj+ImrhnaAFOtbxPdLUyCimv9HdLvp25Xstd/pTltV1lgRcfd4dddmSnaNneRsEpq7FsgwMuFTCiBTT7VpVSDI+bsI2KwNxcPMWvgdL2wqWS18tqAlkDVWr2GSNxga3/7ZE/lqftot8YSFy89NQVBnWkNUPeUNE0EdHD1cVnYNaQevzBmQ8pR8URfxFERT4drWWoPmwmyv2+TEFzw+Jmoe5wd6l4ukctYsbcnD93Lu39a7B98D8VgZUjbnqdP3qz6ChuxD0P39PWOR83Y65Qq/DMf0tA83rTCU5JCwUw9f61AVoC8locb3Ipeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9EGPd5u6hNOZNDVhEzExkqKCgikBQi9KIyjSLctNLVo=; b=deThfI8ZIu5P4xqKKZPLEGko0T2HgXNi8EwYvhX3AWcwKt8zGAu1zZAZ0w/wwEZpe6KBh2mNsqw423QrsdgJ6MILKi2USseudeJA17R4061d2QjKsuACnSdZdfZZl7pT4UcINLy3CuDGb6H8UpfnUKToDcrbXrHzN4tAudXsW+o= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) by AM0PR04MB7041.eurprd04.prod.outlook.com (2603:10a6:208:19a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Tue, 9 May 2023 19:39:20 +0000 Received: from PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::28fb:82ec:7a6:62f3]) by PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::28fb:82ec:7a6:62f3%5]) with mapi id 15.20.6363.032; Tue, 9 May 2023 19:39:19 +0000 From: Shenwei Wang To: Wei Fang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Shenwei Wang , Clark Wang , NXP Linux Team , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Alexander Lobakin , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev Subject: [PATCH net 1/1] net: fec: using the standard return codes when xdp xmit errors Date: Tue, 9 May 2023 14:38:45 -0500 Message-Id: <20230509193845.1090040-1-shenwei.wang@nxp.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BY5PR04CA0010.namprd04.prod.outlook.com (2603:10b6:a03:1d0::20) To PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9185:EE_|AM0PR04MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 7b65eca2-f90d-4b28-a059-08db50c514df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G6UoftVEYAmW9oiET3d+0Dm58P1D5UoRDMATSB9DXGUpEG/Kuecf+TDsRfnEuDtnmjB93p5u2uqoYYtPl4LruPswNtdLvbrMs/YoK8aggr30CdyQ4nyebD1LVVoXmTLzn5T5RCFN+GRqD2FE1MNxPW7sKu2hyoynoWoE+zdmJqIzLHtE2QYk8cpSiWzeWZkcqKnGLFMKYMCMPHpd0Yl2/Bjf9ZwmNhvfrRza7qS4P0QKVACOKAsOJ0qeAT5kuVJa+0u3NyeVx2ysCrMQur9Y/ReJL8Yn1akmTDzs4r1mWUYLxhj38mU4tYL3q0xnXBmG9bG+DlFtjQ8Ootn01RTrW2wKaJbD5dskP03ou7w2kfJgvxxwZh4zF5l75l/r1WlTL/CX/s6p8Ydce0QCcXomYY//6irnwOybIO0wvymBsbKsh/TXuJbA3GXIgHqg4dLJT9x53PkHqj4ARbWeyAlWKMvFsfpH0508J3C/sjk3BhgXEmsCvGdZD5/OAe+n6o2vgoYuxOwPfp5trKF0k7YTk5tDMAMOm+P6MIpk2vll8Bh9Z4LjmrJEpwF1OJ9+jPfyqUYetuamz2dBjal/6c4W3ySyr50CNqYJWosTccKPbHw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9185.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(346002)(366004)(376002)(136003)(451199021)(52116002)(54906003)(110136005)(86362001)(316002)(6486002)(66476007)(6666004)(66946007)(41300700001)(4326008)(66556008)(5660300002)(44832011)(8936002)(7416002)(8676002)(478600001)(6512007)(186003)(1076003)(38100700002)(6506007)(26005)(2906002)(55236004)(2616005)(83380400001)(38350700002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6a7W9JppOyRdtQzHlaTGvZw94g4BgCpIAkGxXasK2Zlime7DGAvzJ1TNtKh2?= =?us-ascii?Q?BcPkzOTEAxq7vmT7cxf9Qy6oLRIB6skRLcQrlgIAr33H/mqXPSggY8wZi3ku?= =?us-ascii?Q?n8AE+PRiaPTTrVWaNkrdFdPCnJyRs8L+NLXzHk7XtkAVMTqZVG57HoiIzTr9?= =?us-ascii?Q?pCPh2TRusYSE/9CCxOxJ/YmKbJey59+Papdnxj0BKJKc2ZGZbAT21uQ+IypR?= =?us-ascii?Q?+fatOgGGwCPWT+14+reo6Cu4hDD/UZ4vW2CcUINe2CQPqKP4ivPIwuTHmkIk?= =?us-ascii?Q?c1t/WvPBTEZ9xcmCWDRud0J6PyWPj2X/owWLP5TDyoWPaceNDnXlYxI2x6tn?= =?us-ascii?Q?kFLOaXyScuHaKF8FAJ/ky/s/yPJrFRIr6jzOq6labrJOF7Hh5jUhJO0QBnvo?= =?us-ascii?Q?CAumuvAFVbhGMk1W9/iknKXmLUcADmtk1aVmiK6d+tgvwnutkKIxPItGu7cM?= =?us-ascii?Q?vRr9GVakRHD7969doTEX8P+6d8b7ynl5JcEY2P1ar98WX5bIS0w/c9G6jL3E?= =?us-ascii?Q?IdEI9ni1APW00PoNKEPJCBYJEsETcm7ihgtnJzybNYVEw+0Xogqk3PmOID7L?= =?us-ascii?Q?Tsj4zdNpI/cEI18UVpw0hndj39szZiDKIS6j155CxSGkvOMuPlAiiBzshHpE?= =?us-ascii?Q?In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AX7vrKJo?= =?us-ascii?Q?u++ETwPiFTdpZCiI65IZYEwUPpDgb65ogvs10eFW?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7b65eca2-f90d-4b28-a059-08db50c514df X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9185.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2023 19:39:19.5516 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cO+AjZjsZmhtj5SCwN/quCgVoexdQeFUEVRXVxsUmM/3mBdvZKLedtiBDNi9k5kJWFcTl6FsjHLMP2w7YbD3rw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7041 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The existing logic did not properly handle unsuccessful xdp xmit frames, this patch revises the logic to return standard error codes (-EBUSY or -ENOMEM) on unsuccessful transmit. Start the xmit of the frame immediately right after configuring the tx descriptors. Fixes: e8a17397180f ("net: fec: correct the counting of XDP sent frames") Signed-off-by: Shenwei Wang --- drivers/net/ethernet/freescale/fec_main.c | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 42ec6ca3bf03..438fc1c3aea2 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3798,8 +3798,7 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, entries_free = fec_enet_get_free_txdesc_num(txq); if (entries_free < MAX_SKB_FRAGS + 1) { netdev_err(fep->netdev, "NOT enough BD for SG!\n"); - xdp_return_frame(frame); - return NETDEV_TX_BUSY; + return -EBUSY; } /* Fill in a Tx ring entry */ @@ -3813,7 +3812,7 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, dma_addr = dma_map_single(&fep->pdev->dev, frame->data, frame->len, DMA_TO_DEVICE); if (dma_mapping_error(&fep->pdev->dev, dma_addr)) - return FEC_ENET_XDP_CONSUMED; + return -ENOMEM; status |= (BD_ENET_TX_INTR | BD_ENET_TX_LAST); if (fep->bufdesc_ex) @@ -3835,6 +3834,11 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, index = fec_enet_get_bd_index(last_bdp, &txq->bd); txq->tx_skbuff[index] = NULL; + /* Make sure the updates to rest of the descriptor are performed before + * transferring ownership. + */ + wmb(); + /* Send it on its way. Tell FEC it's ready, interrupt when done, * it's the last BD of the frame, and to put the CRC on the end. */ @@ -3844,8 +3848,15 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, /* If this was the last BD in the ring, start at the beginning again. */ bdp = fec_enet_get_nextdesc(last_bdp, &txq->bd); + /* Make sure the update to bdp and tx_skbuff are performed before + * txq->bd.cur. + */ + wmb(); txq->bd.cur = bdp; + /* Trigger transmission start */ + writel(0, txq->bd.reg_desc_active); + return 0; } @@ -3869,17 +3880,11 @@ static int fec_enet_xdp_xmit(struct net_device *dev, __netif_tx_lock(nq, cpu); for (i = 0; i < num_frames; i++) { - if (fec_enet_txq_xmit_frame(fep, txq, frames[i]) != 0) + if (fec_enet_txq_xmit_frame(fep, txq, frames[i]) < 0) break; sent_frames++; } - /* Make sure the update to bdp and tx_skbuff are performed. */ - wmb(); - - /* Trigger transmission start */ - writel(0, txq->bd.reg_desc_active); - __netif_tx_unlock(nq); return sent_frames; -- 2.34.1