From patchwork Wed Mar 10 12:03:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 397233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D1BFC433E6 for ; Wed, 10 Mar 2021 12:05:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E04064FF3 for ; Wed, 10 Mar 2021 12:05:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232438AbhCJMEv (ORCPT ); Wed, 10 Mar 2021 07:04:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232929AbhCJMEo (ORCPT ); Wed, 10 Mar 2021 07:04:44 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B3BBC061761 for ; Wed, 10 Mar 2021 04:04:44 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id c10so38117501ejx.9 for ; Wed, 10 Mar 2021 04:04:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OJnVq8r2fzUNQAWLMQfE4OMc3vq4nuKCHOZGEnNktZ4=; b=CZeIHB+3kLnaiIA7T8Nb4iAWICAL1HEogtz7STJBIv2nIyNLkRQCATDXLyKlb0c6N2 mi5xlsIQ6X6zDb8BAME7zneL7Sgc1+YrNHssP8MJ/4/GzscfbRom7LI9UVxr9m3zuSrl 9kO12xXGJRlmyLkoFW46YwAyz4wHyZ02IuE9C2S3FvpG1gx0Ss1dgW8u7IbeiWUHQMoF BDOjn7XWdnaxYEjUnV37X30gR4Mf4gwGDWPUbq7rus9odIS+CKN/iPEVCSCfW41M1ag4 KzeIN/L09Y0SambdEC9qXvQT3Y5VBnAwxnDMwDhO/8zvlgNiEHP+5yhtA3uP5NGzLCe9 SOhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OJnVq8r2fzUNQAWLMQfE4OMc3vq4nuKCHOZGEnNktZ4=; b=Neoy8RzS2sLa3FjWr4/G2Y7Uk3lFNgntbBnEJmYi5lASiVBMWWOVPrlIzDy/z5Tmkn oDLe8FXvSXOHYtTgD2fZIz41RRzdz4tsSFlgNAM4/+krOCYchgmRYAPSC1EEi/NVvXoD xHRIAhYWYJU3OFr5W9AUY7x49+3OuTS8Wwx3aJgrjJw7jsHGIim+6/63MXCX3d+N3m9m HKQLoijExRw4/zOL9KtjqytfrKkW81QrwkPOf8UunqmPUpyUImffucuD+zz+s/NBAt8j QcEySlDFlG3YzYV/wQFO6ITbBcA3m2Sm27sSKdsUs6Do4g2qGqsdfxGSdkN9Y2EMx765 YApw== X-Gm-Message-State: AOAM530iW8CU5zsCLyYOtytnzFClOowsPfocKnCy4Nar870NvgszR2m2 NwMf8eBBT9c8OrTSxJB9w4I= X-Google-Smtp-Source: ABdhPJysXzemETsEpZxT3u/D0SiEr0FkTXiYsQwE+x/p82t0xqs6z8bBfSiFX7f1MbwfOh8bT1G4Ag== X-Received: by 2002:a17:906:688:: with SMTP id u8mr3221619ejb.38.1615377882675; Wed, 10 Mar 2021 04:04:42 -0800 (PST) Received: from localhost.localdomain ([188.25.219.167]) by smtp.gmail.com with ESMTPSA id q20sm9913239ejs.41.2021.03.10.04.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 04:04:42 -0800 (PST) From: Vladimir Oltean X-Google-Original-From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Alex Marginean , Claudiu Manoil Subject: [PATCH net-next 01/12] net: enetc: move the CBDR API to enetc_cbdr.c Date: Wed, 10 Mar 2021 14:03:40 +0200 Message-Id: <20210310120351.542292-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210310120351.542292-1-vladimir.oltean@nxp.com> References: <20210310120351.542292-1-vladimir.oltean@nxp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since there is a dedicated file in this driver for interacting with control BD rings, it makes sense to move these functions there. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/freescale/enetc/enetc.c | 54 ------------------- .../net/ethernet/freescale/enetc/enetc_cbdr.c | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 09471329f3a3..a6ae4ebaee7d 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -995,60 +995,6 @@ static void enetc_free_rxtx_rings(struct enetc_ndev_priv *priv) enetc_free_tx_ring(priv->tx_ring[i]); } -int enetc_alloc_cbdr(struct device *dev, struct enetc_cbdr *cbdr) -{ - int size = cbdr->bd_count * sizeof(struct enetc_cbd); - - cbdr->bd_base = dma_alloc_coherent(dev, size, &cbdr->bd_dma_base, - GFP_KERNEL); - if (!cbdr->bd_base) - return -ENOMEM; - - /* h/w requires 128B alignment */ - if (!IS_ALIGNED(cbdr->bd_dma_base, 128)) { - dma_free_coherent(dev, size, cbdr->bd_base, cbdr->bd_dma_base); - return -EINVAL; - } - - cbdr->next_to_clean = 0; - cbdr->next_to_use = 0; - - return 0; -} - -void enetc_free_cbdr(struct device *dev, struct enetc_cbdr *cbdr) -{ - int size = cbdr->bd_count * sizeof(struct enetc_cbd); - - dma_free_coherent(dev, size, cbdr->bd_base, cbdr->bd_dma_base); - cbdr->bd_base = NULL; -} - -void enetc_setup_cbdr(struct enetc_hw *hw, struct enetc_cbdr *cbdr) -{ - /* set CBDR cache attributes */ - enetc_wr(hw, ENETC_SICAR2, - ENETC_SICAR_RD_COHERENT | ENETC_SICAR_WR_COHERENT); - - enetc_wr(hw, ENETC_SICBDRBAR0, lower_32_bits(cbdr->bd_dma_base)); - enetc_wr(hw, ENETC_SICBDRBAR1, upper_32_bits(cbdr->bd_dma_base)); - enetc_wr(hw, ENETC_SICBDRLENR, ENETC_RTBLENR_LEN(cbdr->bd_count)); - - enetc_wr(hw, ENETC_SICBDRPIR, 0); - enetc_wr(hw, ENETC_SICBDRCIR, 0); - - /* enable ring */ - enetc_wr(hw, ENETC_SICBDRMR, BIT(31)); - - cbdr->pir = hw->reg + ENETC_SICBDRPIR; - cbdr->cir = hw->reg + ENETC_SICBDRCIR; -} - -void enetc_clear_cbdr(struct enetc_hw *hw) -{ - enetc_wr(hw, ENETC_SICBDRMR, 0); -} - static int enetc_setup_default_rss_table(struct enetc_si *si, int num_groups) { int *rss_table; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c index 201cbc362e33..ad6aecda6b47 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c @@ -3,6 +3,60 @@ #include "enetc.h" +int enetc_alloc_cbdr(struct device *dev, struct enetc_cbdr *cbdr) +{ + int size = cbdr->bd_count * sizeof(struct enetc_cbd); + + cbdr->bd_base = dma_alloc_coherent(dev, size, &cbdr->bd_dma_base, + GFP_KERNEL); + if (!cbdr->bd_base) + return -ENOMEM; + + /* h/w requires 128B alignment */ + if (!IS_ALIGNED(cbdr->bd_dma_base, 128)) { + dma_free_coherent(dev, size, cbdr->bd_base, cbdr->bd_dma_base); + return -EINVAL; + } + + cbdr->next_to_clean = 0; + cbdr->next_to_use = 0; + + return 0; +} + +void enetc_free_cbdr(struct device *dev, struct enetc_cbdr *cbdr) +{ + int size = cbdr->bd_count * sizeof(struct enetc_cbd); + + dma_free_coherent(dev, size, cbdr->bd_base, cbdr->bd_dma_base); + cbdr->bd_base = NULL; +} + +void enetc_setup_cbdr(struct enetc_hw *hw, struct enetc_cbdr *cbdr) +{ + /* set CBDR cache attributes */ + enetc_wr(hw, ENETC_SICAR2, + ENETC_SICAR_RD_COHERENT | ENETC_SICAR_WR_COHERENT); + + enetc_wr(hw, ENETC_SICBDRBAR0, lower_32_bits(cbdr->bd_dma_base)); + enetc_wr(hw, ENETC_SICBDRBAR1, upper_32_bits(cbdr->bd_dma_base)); + enetc_wr(hw, ENETC_SICBDRLENR, ENETC_RTBLENR_LEN(cbdr->bd_count)); + + enetc_wr(hw, ENETC_SICBDRPIR, 0); + enetc_wr(hw, ENETC_SICBDRCIR, 0); + + /* enable ring */ + enetc_wr(hw, ENETC_SICBDRMR, BIT(31)); + + cbdr->pir = hw->reg + ENETC_SICBDRPIR; + cbdr->cir = hw->reg + ENETC_SICBDRCIR; +} + +void enetc_clear_cbdr(struct enetc_hw *hw) +{ + enetc_wr(hw, ENETC_SICBDRMR, 0); +} + static void enetc_clean_cbdr(struct enetc_si *si) { struct enetc_cbdr *ring = &si->cbd_ring; From patchwork Wed Mar 10 12:03:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 397232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAA02C43381 for ; Wed, 10 Mar 2021 12:05:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89CFD64FF6 for ; Wed, 10 Mar 2021 12:05:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232901AbhCJMEw (ORCPT ); Wed, 10 Mar 2021 07:04:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232930AbhCJMEp (ORCPT ); Wed, 10 Mar 2021 07:04:45 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6A2EC061762 for ; Wed, 10 Mar 2021 04:04:44 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id x9so27607560edd.0 for ; Wed, 10 Mar 2021 04:04:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FT1x6x9ugdWaFZzEHSyMIq0oqTnCwmalm2czRraEjvg=; b=j5wi7JXT9jCdrYhhyMIQ0a7h5rhV2PV2w++mtOECUS2jc8Nscx1XOf0yaw3F1V4APn 6/LFc2rEVRDV7PMhblCoh7iic/DEY68HEU1xK2cxFbIpS7Bf9BDJ/+ZNHBPye2UAuH3Z TYHtGW9gAvvZ6buJ+2NjqXMpWE5PBCkUdwKlUK5Z7pR2VX69c8MYMGFzrn+5kvUutjCa K5DzJ1+Cj7qTD6zVLUiynpLFtYr9K9IE8oFGw7qN2aB2mzqGoSxL5gNtz2uo4MJF4tCb 1/7aRzPStnHe0E0dbmv5vfvPBY8OrksD0QERnrovfXA+f8XToOmp7JnKiRqtGARMD2HQ Kl3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FT1x6x9ugdWaFZzEHSyMIq0oqTnCwmalm2czRraEjvg=; b=f/rN9EbEYiAzVxqyquQPpt84tjCQwSCpPDnidd2ov7/qh2wMQ7v5pqqW5SdF8aoZs5 eFNjr04jovuax3QhlvpDJcBKUtob73kErZSRRwHp0z7Suy0eoFq/dWyDlaKKLvxhxhyS rjbwxzUnWlGznhpZB8qccWhBTU+cw81v4LebVfUEyDtL157bAqvmzhoFYepZI0PrfGba l8HUeGqi0snWM8gO+ddM62mjIVnvPGN3h5iDdT07TRgrLF8kE2rAYx2UB0lY4V234p5O 9r3Wu3UpEbHd8Sfd8cUv4zHfXIrS7fJf99kS5e2ayq9oTQ88RnHEoBVxm56udFykOB/N wLrQ== X-Gm-Message-State: AOAM5304x5eACQA2FuOTG6SItxOcj2K+FbNoeLKULWPuJJhV8K26PZuU ZKy9bIGMo2X9jaGo+Lda2ns= X-Google-Smtp-Source: ABdhPJy2dIUjTwde4JTPmpPpjFUKzg5l3YA1rBaHE3gAKYWy7l7kWcVSstBpO+IUOpqW1sGEFC44Bg== X-Received: by 2002:aa7:c386:: with SMTP id k6mr2782634edq.224.1615377883462; Wed, 10 Mar 2021 04:04:43 -0800 (PST) Received: from localhost.localdomain ([188.25.219.167]) by smtp.gmail.com with ESMTPSA id q20sm9913239ejs.41.2021.03.10.04.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 04:04:43 -0800 (PST) From: Vladimir Oltean X-Google-Original-From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Alex Marginean , Claudiu Manoil Subject: [PATCH net-next 02/12] net: enetc: save the DMA device for enetc_free_cbdr Date: Wed, 10 Mar 2021 14:03:41 +0200 Message-Id: <20210310120351.542292-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210310120351.542292-1-vladimir.oltean@nxp.com> References: <20210310120351.542292-1-vladimir.oltean@nxp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We shouldn't need to pass the struct device *dev to enetc CBDR APIs over and over again, so save this inside struct enetc_cbdr::dma_dev and avoid calling it from the enetc_free_cbdr functions. This breaks the dependency of the cbdr API from struct enetc_si (the station interface). Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/freescale/enetc/enetc.c | 4 +- drivers/net/ethernet/freescale/enetc/enetc.h | 3 +- .../net/ethernet/freescale/enetc/enetc_cbdr.c | 37 +++++++++++-------- .../net/ethernet/freescale/enetc/enetc_pf.c | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index a6ae4ebaee7d..ceecee42f0f1 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1081,7 +1081,7 @@ int enetc_alloc_si_resources(struct enetc_ndev_priv *priv) err_alloc_cls: enetc_clear_cbdr(&si->hw); - enetc_free_cbdr(priv->dev, &si->cbd_ring); + enetc_free_cbdr(&si->cbd_ring); return err; } @@ -1091,7 +1091,7 @@ void enetc_free_si_resources(struct enetc_ndev_priv *priv) struct enetc_si *si = priv->si; enetc_clear_cbdr(&si->hw); - enetc_free_cbdr(priv->dev, &si->cbd_ring); + enetc_free_cbdr(&si->cbd_ring); kfree(priv->cls_rules); } diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 8b380fc13314..b343d1002bb7 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -104,6 +104,7 @@ struct enetc_cbdr { int next_to_clean; dma_addr_t bd_dma_base; + struct device *dma_dev; }; #define ENETC_TXBD(BDR, i) (&(((union enetc_tx_bd *)((BDR).bd_base))[i])) @@ -311,7 +312,7 @@ void enetc_set_ethtool_ops(struct net_device *ndev); /* control buffer descriptor ring (CBDR) */ int enetc_alloc_cbdr(struct device *dev, struct enetc_cbdr *cbdr); -void enetc_free_cbdr(struct device *dev, struct enetc_cbdr *cbdr); +void enetc_free_cbdr(struct enetc_cbdr *cbdr); void enetc_setup_cbdr(struct enetc_hw *hw, struct enetc_cbdr *cbdr); void enetc_clear_cbdr(struct enetc_hw *hw); int enetc_set_mac_flt_entry(struct enetc_si *si, int index, diff --git a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c index ad6aecda6b47..7e84eb665ecd 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c @@ -14,22 +14,26 @@ int enetc_alloc_cbdr(struct device *dev, struct enetc_cbdr *cbdr) /* h/w requires 128B alignment */ if (!IS_ALIGNED(cbdr->bd_dma_base, 128)) { - dma_free_coherent(dev, size, cbdr->bd_base, cbdr->bd_dma_base); + dma_free_coherent(dev, size, cbdr->bd_base, + cbdr->bd_dma_base); return -EINVAL; } cbdr->next_to_clean = 0; cbdr->next_to_use = 0; + cbdr->dma_dev = dev; return 0; } -void enetc_free_cbdr(struct device *dev, struct enetc_cbdr *cbdr) +void enetc_free_cbdr(struct enetc_cbdr *cbdr) { int size = cbdr->bd_count * sizeof(struct enetc_cbd); - dma_free_coherent(dev, size, cbdr->bd_base, cbdr->bd_dma_base); + dma_free_coherent(cbdr->dma_dev, size, cbdr->bd_base, + cbdr->bd_dma_base); cbdr->bd_base = NULL; + cbdr->dma_dev = NULL; } void enetc_setup_cbdr(struct enetc_hw *hw, struct enetc_cbdr *cbdr) @@ -57,9 +61,8 @@ void enetc_clear_cbdr(struct enetc_hw *hw) enetc_wr(hw, ENETC_SICBDRMR, 0); } -static void enetc_clean_cbdr(struct enetc_si *si) +static void enetc_clean_cbdr(struct enetc_cbdr *ring) { - struct enetc_cbdr *ring = &si->cbd_ring; struct enetc_cbd *dest_cbd; int i, status; @@ -69,7 +72,7 @@ static void enetc_clean_cbdr(struct enetc_si *si) dest_cbd = ENETC_CBD(*ring, i); status = dest_cbd->status_flags & ENETC_CBD_STATUS_MASK; if (status) - dev_warn(&si->pdev->dev, "CMD err %04x for cmd %04x\n", + dev_warn(ring->dma_dev, "CMD err %04x for cmd %04x\n", status, dest_cbd->cmd); memset(dest_cbd, 0, sizeof(*dest_cbd)); @@ -97,7 +100,7 @@ int enetc_send_cmd(struct enetc_si *si, struct enetc_cbd *cbd) return -EIO; if (unlikely(!enetc_cbd_unused(ring))) - enetc_clean_cbdr(si); + enetc_clean_cbdr(ring); i = ring->next_to_use; dest_cbd = ENETC_CBD(*ring, i); @@ -123,7 +126,7 @@ int enetc_send_cmd(struct enetc_si *si, struct enetc_cbd *cbd) /* CBD may writeback data, feedback up level */ *cbd = *dest_cbd; - enetc_clean_cbdr(si); + enetc_clean_cbdr(ring); return 0; } @@ -171,6 +174,7 @@ int enetc_set_mac_flt_entry(struct enetc_si *si, int index, int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse, int index) { + struct enetc_cbdr *ring = &si->cbd_ring; struct enetc_cbd cbd = {.cmd = 0}; dma_addr_t dma, dma_align; void *tmp, *tmp_align; @@ -183,10 +187,10 @@ int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse, cbd.length = cpu_to_le16(sizeof(*rfse)); cbd.opt[3] = cpu_to_le32(0); /* SI */ - tmp = dma_alloc_coherent(&si->pdev->dev, sizeof(*rfse) + RFSE_ALIGN, + tmp = dma_alloc_coherent(ring->dma_dev, sizeof(*rfse) + RFSE_ALIGN, &dma, GFP_KERNEL); if (!tmp) { - dev_err(&si->pdev->dev, "DMA mapping of RFS entry failed!\n"); + dev_err(ring->dma_dev, "DMA mapping of RFS entry failed!\n"); return -ENOMEM; } @@ -199,9 +203,9 @@ int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse, err = enetc_send_cmd(si, &cbd); if (err) - dev_err(&si->pdev->dev, "FS entry add failed (%d)!", err); + dev_err(ring->dma_dev, "FS entry add failed (%d)!", err); - dma_free_coherent(&si->pdev->dev, sizeof(*rfse) + RFSE_ALIGN, + dma_free_coherent(ring->dma_dev, sizeof(*rfse) + RFSE_ALIGN, tmp, dma); return err; @@ -211,6 +215,7 @@ int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse, static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count, bool read) { + struct enetc_cbdr *ring = &si->cbd_ring; struct enetc_cbd cbd = {.cmd = 0}; dma_addr_t dma, dma_align; u8 *tmp, *tmp_align; @@ -220,10 +225,10 @@ static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count, /* HW only takes in a full 64 entry table */ return -EINVAL; - tmp = dma_alloc_coherent(&si->pdev->dev, count + RSSE_ALIGN, + tmp = dma_alloc_coherent(ring->dma_dev, count + RSSE_ALIGN, &dma, GFP_KERNEL); if (!tmp) { - dev_err(&si->pdev->dev, "DMA mapping of RSS table failed!\n"); + dev_err(ring->dma_dev, "DMA mapping of RSS table failed!\n"); return -ENOMEM; } dma_align = ALIGN(dma, RSSE_ALIGN); @@ -243,13 +248,13 @@ static int enetc_cmd_rss_table(struct enetc_si *si, u32 *table, int count, err = enetc_send_cmd(si, &cbd); if (err) - dev_err(&si->pdev->dev, "RSS cmd failed (%d)!", err); + dev_err(ring->dma_dev, "RSS cmd failed (%d)!", err); if (read) for (i = 0; i < count; i++) table[i] = tmp_align[i]; - dma_free_coherent(&si->pdev->dev, count + RSSE_ALIGN, tmp, dma); + dma_free_coherent(ring->dma_dev, count + RSSE_ALIGN, tmp, dma); return err; } diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index 224fc37a6757..a7195ec736f3 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -1098,7 +1098,7 @@ static void enetc_init_unused_port(struct enetc_si *si) enetc_init_port_rss_memory(si); enetc_clear_cbdr(hw); - enetc_free_cbdr(dev, &si->cbd_ring); + enetc_free_cbdr(&si->cbd_ring); } static int enetc_pf_probe(struct pci_dev *pdev, From patchwork Wed Mar 10 12:03:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 397231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A30DC4332E for ; Wed, 10 Mar 2021 12:05:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D01864FEE for ; Wed, 10 Mar 2021 12:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232923AbhCJME4 (ORCPT ); Wed, 10 Mar 2021 07:04:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232932AbhCJMEr (ORCPT ); Wed, 10 Mar 2021 07:04:47 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22894C061761 for ; Wed, 10 Mar 2021 04:04:47 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id e19so38231348ejt.3 for ; Wed, 10 Mar 2021 04:04:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DEAVvFDcDkzIv8+6LoQc58Y1go1M6iSGO4707+Npq+4=; b=E3/ymp0GVxMBCEHI8N5AZmKyR+6qAukat8UZlcgkOCHuWXTcM9I0dzTGDGgGAcWjJv QKNtwuEJiMJ4falBOTGoc81rGdOUlsP0L2yiydPPh1InuHWhzb46PHZ3K6ooYN2GHSG4 8LkfJAEsV8QtAEdG28Bmj+StiYQmkzKWqJ02cgtx0b/o3HigUgCLBIwsBQUCKKEsmAJS oNKwpUNACcTpV9eFE3ez8ahBY25IkJibcGUKRpFfgAy7BaadkELue2bj9NsCH+g6NBTc qCOs0mLOzpCLTQMkco5bx210/RqPSGglUDRMhNazrdnGgx61gcLlBWc3XkRKyMwY+Swq Z8SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DEAVvFDcDkzIv8+6LoQc58Y1go1M6iSGO4707+Npq+4=; b=dRAEGzZT+15NzfYjnCN6E8DxW6uoVsnDdgRA+BZpeIlyEahc/shabOHqgXInnhaLGB w/u2xulP3MSVuCPlidRLgWrL17O0OR2NuGsXAqLNQFs8OWouc/vZsvuBS/AQdSYcnK6m eoGmbLfJD1oOyODwZVuApfBy94Bju76i8sNAl1ine1acLtQ+EPOYD9JVAJricQbUsCaX Bj5Jx2KVYMR9pQm6pLorJEGggr7lCzEZxEXHx5CLF7bQ1ORl50Yn8kKLJUpXh+guPRns V1z1guCkTZmeBXfR+BFyBA+jEZukvMyFt5I3Hd4jUveRh2VA7qRzpl/Baktq4mslem6F Peww== X-Gm-Message-State: AOAM5317jXYDJqJBDLyrzRQ4XLB5PoRK8iFVROaUwC4BCNIauuhbK8YV cCA8tv57NesHLP49F2LLyZAUG0uQoOA= X-Google-Smtp-Source: ABdhPJynt9QzUSj9vkFJj3pkT88W7owSe4iIAWvzVH1W2Ly0hi6wSMTUxNeMjwoL6tLZxJeEgGmW1A== X-Received: by 2002:a17:906:607:: with SMTP id s7mr3190600ejb.495.1615377885937; Wed, 10 Mar 2021 04:04:45 -0800 (PST) Received: from localhost.localdomain ([188.25.219.167]) by smtp.gmail.com with ESMTPSA id q20sm9913239ejs.41.2021.03.10.04.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 04:04:45 -0800 (PST) From: Vladimir Oltean X-Google-Original-From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Alex Marginean , Claudiu Manoil Subject: [PATCH net-next 05/12] net: enetc: squash clear_cbdr and free_cbdr into teardown_cbdr Date: Wed, 10 Mar 2021 14:03:44 +0200 Message-Id: <20210310120351.542292-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210310120351.542292-1-vladimir.oltean@nxp.com> References: <20210310120351.542292-1-vladimir.oltean@nxp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org All call sites call enetc_clear_cbdr and enetc_free_cbdr one after another, so let's combine the two functions into a single method named enetc_teardown_cbdr which does both, and in the same order. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/freescale/enetc/enetc.c | 6 ++---- drivers/net/ethernet/freescale/enetc/enetc.h | 3 +-- drivers/net/ethernet/freescale/enetc/enetc_cbdr.c | 11 ++++------- drivers/net/ethernet/freescale/enetc/enetc_pf.c | 3 +-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index b1077a6e2b2b..a32283533408 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1078,8 +1078,7 @@ int enetc_alloc_si_resources(struct enetc_ndev_priv *priv) return 0; err_alloc_cls: - enetc_clear_cbdr(&si->cbd_ring); - enetc_free_cbdr(&si->cbd_ring); + enetc_teardown_cbdr(&si->cbd_ring); return err; } @@ -1088,8 +1087,7 @@ void enetc_free_si_resources(struct enetc_ndev_priv *priv) { struct enetc_si *si = priv->si; - enetc_clear_cbdr(&si->cbd_ring); - enetc_free_cbdr(&si->cbd_ring); + enetc_teardown_cbdr(&si->cbd_ring); kfree(priv->cls_rules); } diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 9d4dbeef61ac..19772be63a2c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -314,8 +314,7 @@ void enetc_set_ethtool_ops(struct net_device *ndev); /* control buffer descriptor ring (CBDR) */ int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, struct enetc_cbdr *cbdr); -void enetc_free_cbdr(struct enetc_cbdr *cbdr); -void enetc_clear_cbdr(struct enetc_cbdr *cbdr); +void enetc_teardown_cbdr(struct enetc_cbdr *cbdr); int enetc_set_mac_flt_entry(struct enetc_si *si, int index, char *mac_addr, int si_map); int enetc_clear_mac_flt_entry(struct enetc_si *si, int index); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c index bb20a58e8830..bee453be2240 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c @@ -44,22 +44,19 @@ int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, return 0; } -void enetc_free_cbdr(struct enetc_cbdr *cbdr) +void enetc_teardown_cbdr(struct enetc_cbdr *cbdr) { int size = cbdr->bd_count * sizeof(struct enetc_cbd); + /* disable ring */ + enetc_wr_reg(cbdr->mr, 0); + dma_free_coherent(cbdr->dma_dev, size, cbdr->bd_base, cbdr->bd_dma_base); cbdr->bd_base = NULL; cbdr->dma_dev = NULL; } -void enetc_clear_cbdr(struct enetc_cbdr *cbdr) -{ - /* disable ring */ - enetc_wr_reg(cbdr->mr, 0); -} - static void enetc_clean_cbdr(struct enetc_cbdr *ring) { struct enetc_cbd *dest_cbd; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index f083d49d7772..4dd7199d5007 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -1095,8 +1095,7 @@ static void enetc_init_unused_port(struct enetc_si *si) enetc_init_port_rfs_memory(si); enetc_init_port_rss_memory(si); - enetc_clear_cbdr(&si->cbd_ring); - enetc_free_cbdr(&si->cbd_ring); + enetc_teardown_cbdr(&si->cbd_ring); } static int enetc_pf_probe(struct pci_dev *pdev, From patchwork Wed Mar 10 12:03:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 397230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0B27C43332 for ; Wed, 10 Mar 2021 12:05:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6947864FF3 for ; Wed, 10 Mar 2021 12:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232932AbhCJME5 (ORCPT ); Wed, 10 Mar 2021 07:04:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232934AbhCJMEs (ORCPT ); Wed, 10 Mar 2021 07:04:48 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0490CC061762 for ; Wed, 10 Mar 2021 04:04:48 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id x9so27607869edd.0 for ; Wed, 10 Mar 2021 04:04:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sox2Ii9W50FhUaR8bUHhhLyqmibUnWMc7Ry439DSURE=; b=SDC9p8JqmmfrDqbr+eGudgzwqTkCJMgdqNa4jzAdvp8MNScih2frdKBv8wyRE6CdS8 cT3NICesJLD6MALwqx/lpBYqxwAPYR0z0mAoxcRYMGN5kRLNFrIuIEUq5GOJe3y7teLG tvM+jwooa/ORN8Q2E9+zhjt/IOzEzwq+5JcnoO7S2AFLedYeHDV/yGiZeDAWOYrHF3tw m6gXpCEu1GAVbRAKPP9FscSxpn4wl5y9R6VXhIAqCOiu9BbgKyaeaiR0X+2IJj4L1C5R xsqyM7QaurIpE9Mee4e/rIE1yqSMktxwdUeqhlF4If4Ja+H9WWLMAmARBlCQS7GR5YaR PWWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sox2Ii9W50FhUaR8bUHhhLyqmibUnWMc7Ry439DSURE=; b=J39f8MI4Dag3oWLvRgPzG3fCwAeit6nryFYwI6rT+cM+ESgwTRkVDNnxIT7pRlTpYv NeoZAfBoHQOvtWPhEemjKv9+L+/M+/p4onc3TTh1iO1FZznk0ByzW4X3+OyxcrdwdRCv zIi+kfevI2Wp4NI6ObKV1WrgjBmZ2pGUFudoozQ/SgxNmb7EXF5ttRM4EDk9QtmGkGrA iLmmnUF6dFePPLNl3laGwMRXh+53uvyL3G0CS3F23b1FIQYxlMSAVZMZfKz+tGzqLqJ0 lLv0XwmXLk9AxawiSMsoGHY3VliXG1gxJ1Wcb2x1SFKR5eNeRDN5zUHwbr8KZ3mjZGBA vZ5Q== X-Gm-Message-State: AOAM533alfdpjWh3mitaD25tpYZMGFeol8D1sHPy+wdLiurXEMZY22Dl EGO0tTWzaGQTiW4BskqtVYo= X-Google-Smtp-Source: ABdhPJzJDbXQGEp7eVN1xXjORdIJ+Nh0ugIsaSRJFZgj1rV/C0Ty9mz0PI9tdQfYdS9eQ+x5Dsrd9w== X-Received: by 2002:aa7:d841:: with SMTP id f1mr2813198eds.286.1615377886815; Wed, 10 Mar 2021 04:04:46 -0800 (PST) Received: from localhost.localdomain ([188.25.219.167]) by smtp.gmail.com with ESMTPSA id q20sm9913239ejs.41.2021.03.10.04.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 04:04:46 -0800 (PST) From: Vladimir Oltean X-Google-Original-From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Alex Marginean , Claudiu Manoil Subject: [PATCH net-next 06/12] net: enetc: pass bd_count as an argument to enetc_setup_cbdr Date: Wed, 10 Mar 2021 14:03:45 +0200 Message-Id: <20210310120351.542292-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210310120351.542292-1-vladimir.oltean@nxp.com> References: <20210310120351.542292-1-vladimir.oltean@nxp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It makes no sense from an API perspective to first initialize some portion of struct enetc_cbdr outside enetc_setup_cbdr, then leave that function to initialize the rest. enetc_setup_cbdr should be able to perform all initialization given a zero-initialized struct enetc_cbdr. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/freescale/enetc/enetc.c | 6 ++---- drivers/net/ethernet/freescale/enetc/enetc.h | 2 +- drivers/net/ethernet/freescale/enetc/enetc_cbdr.c | 5 +++-- drivers/net/ethernet/freescale/enetc/enetc_pf.c | 3 +-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index a32283533408..06fcab53c471 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1054,9 +1054,6 @@ void enetc_init_si_rings_params(struct enetc_ndev_priv *priv) priv->bdr_int_num = cpus; priv->ic_mode = ENETC_IC_RX_ADAPTIVE | ENETC_IC_TX_MANUAL; priv->tx_ictt = ENETC_TXIC_TIMETHR; - - /* SI specific */ - si->cbd_ring.bd_count = ENETC_CBDR_DEFAULT_SIZE; } int enetc_alloc_si_resources(struct enetc_ndev_priv *priv) @@ -1064,7 +1061,8 @@ int enetc_alloc_si_resources(struct enetc_ndev_priv *priv) struct enetc_si *si = priv->si; int err; - err = enetc_setup_cbdr(priv->dev, &si->hw, &si->cbd_ring); + err = enetc_setup_cbdr(priv->dev, &si->hw, ENETC_CBDR_DEFAULT_SIZE, + &si->cbd_ring); if (err) return err; diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 19772be63a2c..af8b8be114bd 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -312,7 +312,7 @@ int enetc_setup_tc(struct net_device *ndev, enum tc_setup_type type, void enetc_set_ethtool_ops(struct net_device *ndev); /* control buffer descriptor ring (CBDR) */ -int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, +int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count, struct enetc_cbdr *cbdr); void enetc_teardown_cbdr(struct enetc_cbdr *cbdr); int enetc_set_mac_flt_entry(struct enetc_si *si, int index, diff --git a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c index bee453be2240..073e56dcca4e 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_cbdr.c @@ -3,10 +3,10 @@ #include "enetc.h" -int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, +int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count, struct enetc_cbdr *cbdr) { - int size = cbdr->bd_count * sizeof(struct enetc_cbd); + int size = bd_count * sizeof(struct enetc_cbd); cbdr->bd_base = dma_alloc_coherent(dev, size, &cbdr->bd_dma_base, GFP_KERNEL); @@ -23,6 +23,7 @@ int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, cbdr->next_to_clean = 0; cbdr->next_to_use = 0; cbdr->dma_dev = dev; + cbdr->bd_count = bd_count; cbdr->pir = hw->reg + ENETC_SICBDRPIR; cbdr->cir = hw->reg + ENETC_SICBDRCIR; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index 4dd7199d5007..bf70b8f9943f 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -1087,8 +1087,7 @@ static void enetc_init_unused_port(struct enetc_si *si) struct enetc_hw *hw = &si->hw; int err; - si->cbd_ring.bd_count = ENETC_CBDR_DEFAULT_SIZE; - err = enetc_setup_cbdr(dev, hw, &si->cbd_ring); + err = enetc_setup_cbdr(dev, hw, ENETC_CBDR_DEFAULT_SIZE, &si->cbd_ring); if (err) return; From patchwork Wed Mar 10 12:03:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 397229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1385CC433E6 for ; Wed, 10 Mar 2021 12:05:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D046B64FFA for ; Wed, 10 Mar 2021 12:05:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232690AbhCJMF1 (ORCPT ); Wed, 10 Mar 2021 07:05:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232936AbhCJMEt (ORCPT ); Wed, 10 Mar 2021 07:04:49 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4F4C061760 for ; Wed, 10 Mar 2021 04:04:48 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id l12so27706118edt.3 for ; Wed, 10 Mar 2021 04:04:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VPKhDvpNanMg66h5KIXhooZXRDUExMMWXCLmke7I9Dw=; b=sFaLMgelmZrYovDwLApFBFhftVMZ71ZDCyHQRRDdA0eJ1ogi4BNCVjL3Ews1t1mhr/ /bM29hmX+xte9B7UkAsAiryCZuusm4yaaMdWjS8TIZA3Yikp8biq932ac+ygoXQ4Nuqs sO+56BpjDXGiKkHDbK0312Xw++7Cp7vzQuIFmqdkd02xaFkTYbLn94BWhz46zdSAhbL2 WHx4HYKQyFpYFsVqp+6duLPZKQ0hJrQO2P5YHhbCIpM9m4pTri2mpYma0af9/3tOK+zp h97pMexgQnHL+VZkWgyO9CYeww4FMh4CsGz2nK/7ZJSwPeyfHTtsOsXGYY4vUeqa8uFp K3ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VPKhDvpNanMg66h5KIXhooZXRDUExMMWXCLmke7I9Dw=; b=NRsa0p6cbQETdH14BrrU24jcF++oIrbZBvmi2nkkkMqoh/2+Evnt62qQhUSRI+eNL2 O0KbbQcBjzzQ09p1yYgTZJFV7QqgY/Glyg5Fbj12a7aWM5mpeQSnwFIgVAtOTJl9JPlb PbHKv6s40TWAi6oolcBlTlvuZ58kUXzWMBFTu8FKOv4nGOWagczGMunpk1xhmoTaF7Z4 8suPwapWsCsx5XdXD1qMZYQL8/cIBKQ1qSyqRmaDj1z3lMxwQnwOxuYjJ0RehSFVdaxD 848D5Rq2VU9Z00N9qs/OaKHUzpckW/by2+VknM6J6Z4yJsLxKyW4tNfrKAMPZgwJ8G4M 4JqQ== X-Gm-Message-State: AOAM5319eMEndzavh3+9mrTO+ITTMYnqpqkiRlB7TZAUdJGGu5h3aTC/ mi/JmlohfY0+SKQRk2inFBA= X-Google-Smtp-Source: ABdhPJxd9QHO9gcu9iwkedjzv41jyqUTGjG2On7nrw2C9ffJ/l4iWDdU6sSthM7WOgtq6/j2wd26zA== X-Received: by 2002:aa7:c98f:: with SMTP id c15mr2878798edt.231.1615377887547; Wed, 10 Mar 2021 04:04:47 -0800 (PST) Received: from localhost.localdomain ([188.25.219.167]) by smtp.gmail.com with ESMTPSA id q20sm9913239ejs.41.2021.03.10.04.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 04:04:47 -0800 (PST) From: Vladimir Oltean X-Google-Original-From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Alex Marginean , Claudiu Manoil Subject: [PATCH net-next 07/12] net: enetc: don't initialize unused ports from a separate code path Date: Wed, 10 Mar 2021 14:03:46 +0200 Message-Id: <20210310120351.542292-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210310120351.542292-1-vladimir.oltean@nxp.com> References: <20210310120351.542292-1-vladimir.oltean@nxp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since commit 3222b5b613db ("net: enetc: initialize RFS/RSS memories for unused ports too") there is a requirement to initialize the memories of unused PFs too, which has left the probe path in a bit of a rough shape, because we basically have a minimal initialization path for unused PFs which is separate from the main initialization path. Now that initializing a control BD ring is as simple as calling enetc_setup_cbdr, let's move that outside of enetc_alloc_si_resources (unused PFs don't need classification rules, so no point in allocating them just to free them later). But enetc_alloc_si_resources is called both for PFs and for VFs, so now that enetc_setup_cbdr is no longer called from this common function, it means that the VF probe path needs to explicitly call enetc_setup_cbdr too. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/freescale/enetc/enetc.c | 21 +------- .../net/ethernet/freescale/enetc/enetc_pf.c | 52 ++++++++----------- .../net/ethernet/freescale/enetc/enetc_vf.c | 7 +++ 3 files changed, 30 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 06fcab53c471..f92d29b62bae 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1059,34 +1059,17 @@ void enetc_init_si_rings_params(struct enetc_ndev_priv *priv) int enetc_alloc_si_resources(struct enetc_ndev_priv *priv) { struct enetc_si *si = priv->si; - int err; - - err = enetc_setup_cbdr(priv->dev, &si->hw, ENETC_CBDR_DEFAULT_SIZE, - &si->cbd_ring); - if (err) - return err; priv->cls_rules = kcalloc(si->num_fs_entries, sizeof(*priv->cls_rules), GFP_KERNEL); - if (!priv->cls_rules) { - err = -ENOMEM; - goto err_alloc_cls; - } + if (!priv->cls_rules) + return -ENOMEM; return 0; - -err_alloc_cls: - enetc_teardown_cbdr(&si->cbd_ring); - - return err; } void enetc_free_si_resources(struct enetc_ndev_priv *priv) { - struct enetc_si *si = priv->si; - - enetc_teardown_cbdr(&si->cbd_ring); - kfree(priv->cls_rules); } diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index bf70b8f9943f..c8b6110448d4 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -1081,22 +1081,6 @@ static int enetc_init_port_rss_memory(struct enetc_si *si) return err; } -static void enetc_init_unused_port(struct enetc_si *si) -{ - struct device *dev = &si->pdev->dev; - struct enetc_hw *hw = &si->hw; - int err; - - err = enetc_setup_cbdr(dev, hw, ENETC_CBDR_DEFAULT_SIZE, &si->cbd_ring); - if (err) - return; - - enetc_init_port_rfs_memory(si); - enetc_init_port_rss_memory(si); - - enetc_teardown_cbdr(&si->cbd_ring); -} - static int enetc_pf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -1120,8 +1104,24 @@ static int enetc_pf_probe(struct pci_dev *pdev, goto err_map_pf_space; } + err = enetc_setup_cbdr(&pdev->dev, &si->hw, ENETC_CBDR_DEFAULT_SIZE, + &si->cbd_ring); + if (err) + goto err_setup_cbdr; + + err = enetc_init_port_rfs_memory(si); + if (err) { + dev_err(&pdev->dev, "Failed to initialize RFS memory\n"); + goto err_init_port_rfs; + } + + err = enetc_init_port_rss_memory(si); + if (err) { + dev_err(&pdev->dev, "Failed to initialize RSS memory\n"); + goto err_init_port_rss; + } + if (node && !of_device_is_available(node)) { - enetc_init_unused_port(si); dev_info(&pdev->dev, "device is disabled, skipping\n"); err = -ENODEV; goto err_device_disabled; @@ -1154,18 +1154,6 @@ static int enetc_pf_probe(struct pci_dev *pdev, goto err_alloc_si_res; } - err = enetc_init_port_rfs_memory(si); - if (err) { - dev_err(&pdev->dev, "Failed to initialize RFS memory\n"); - goto err_init_port_rfs; - } - - err = enetc_init_port_rss_memory(si); - if (err) { - dev_err(&pdev->dev, "Failed to initialize RSS memory\n"); - goto err_init_port_rss; - } - err = enetc_configure_si(priv); if (err) { dev_err(&pdev->dev, "Failed to configure SI\n"); @@ -1201,15 +1189,17 @@ static int enetc_pf_probe(struct pci_dev *pdev, err_mdiobus_create: enetc_free_msix(priv); err_config_si: -err_init_port_rss: -err_init_port_rfs: err_alloc_msix: enetc_free_si_resources(priv); err_alloc_si_res: si->ndev = NULL; free_netdev(ndev); err_alloc_netdev: +err_init_port_rss: +err_init_port_rfs: err_device_disabled: + enetc_teardown_cbdr(&si->cbd_ring); +err_setup_cbdr: err_map_pf_space: enetc_pci_remove(pdev); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c index 9b755a84c2d6..371a34d3c6b4 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c @@ -165,6 +165,11 @@ static int enetc_vf_probe(struct pci_dev *pdev, enetc_init_si_rings_params(priv); + err = enetc_setup_cbdr(priv->dev, &si->hw, ENETC_CBDR_DEFAULT_SIZE, + &si->cbd_ring); + if (err) + goto err_setup_cbdr; + err = enetc_alloc_si_resources(priv); if (err) { dev_err(&pdev->dev, "SI resource alloc failed\n"); @@ -197,6 +202,8 @@ static int enetc_vf_probe(struct pci_dev *pdev, err_alloc_msix: enetc_free_si_resources(priv); err_alloc_si_res: + enetc_teardown_cbdr(&si->cbd_ring); +err_setup_cbdr: si->ndev = NULL; free_netdev(ndev); err_alloc_netdev: From patchwork Wed Mar 10 12:03:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 397228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 425ECC4332B for ; Wed, 10 Mar 2021 12:05:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 131B264FFE for ; Wed, 10 Mar 2021 12:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232943AbhCJMF3 (ORCPT ); Wed, 10 Mar 2021 07:05:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232940AbhCJMEt (ORCPT ); Wed, 10 Mar 2021 07:04:49 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F381C061761 for ; Wed, 10 Mar 2021 04:04:49 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id dx17so38200083ejb.2 for ; Wed, 10 Mar 2021 04:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/p6MuCdSjj8dGCJeSNxOi5fq7cl/jqB+h/TJZol4I48=; b=XSVV80yUzE2/Y92FrMZNN79Zp2fkKZvMaCagV4VEZDlSBDMruYhHvnmigoxBR4yety wlQIElfD1HJDJat54RGjtfz3UCD8YMUa4nWXu82vRlp76AcaKk+bFpcpsDVB8oV/h0Sj XTZ3R6YTp0Rxk58vf6rD7+8PsThRLsyh0C599noobXbld/5jrPzjeP43S9qAyoTyFHQ4 j+axPkX2RIgMGJlH+KpgkL8dGxKsOOEXCwR6QqwPTMH3K2Y8bSKYbleDLtBdTdCxOTVd MzwHaUdGLd5OmtsIjgwdVrKFBrt0tmVmqlxC+vBKZp8JNhdNNGzJBQZ83rljgSK+a6zR NtzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/p6MuCdSjj8dGCJeSNxOi5fq7cl/jqB+h/TJZol4I48=; b=AyOL+l1Nlvjdj3eq20BDeGmtCt9Sqwt0RNNA/Xr9NEYKJQ2QUwrUBY1VpnV8Ih5ajF kg1Q86YWe7FEJez5hp93uZ7N5O5IUUw1KzwEo2X/FTSIFSB3SsMSX4BaXWqFX7q+QWtR Pg95kxl/3UzfNuKqk+kpu9it5dDbOVHQalErmHeDAPZGXTZWJKEEQ4YToVvKmNJ4I1mQ n6UqavKECDYDpuF/9nF9DVlwP6J2zY/hBbYRc7tQlpIe48ST7FdDRnHXdUG9t10wLipf Jm5Ld6jC0reK+jMyW93ixVLF9ix8WmtfrPkvCj6W7xvSrT+x/y6/WCmbnbBw9A7UkXVy dM0g== X-Gm-Message-State: AOAM532lxLQfU5Wmyz1X1TBpIsWOPXE3ezevIKRL3EZlPCbInQJKKDHz HvAqpi8Icfk1gqhDWsvm0nA= X-Google-Smtp-Source: ABdhPJy6Ae276DfLs/4iMF3IqmNxbXnVBSMr28Sx9M8u0tXPMQ5+GkGwgBoX+b+la0Q546XYV7hzPA== X-Received: by 2002:a17:906:32da:: with SMTP id k26mr3251291ejk.483.1615377888288; Wed, 10 Mar 2021 04:04:48 -0800 (PST) Received: from localhost.localdomain ([188.25.219.167]) by smtp.gmail.com with ESMTPSA id q20sm9913239ejs.41.2021.03.10.04.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 04:04:48 -0800 (PST) From: Vladimir Oltean X-Google-Original-From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Alex Marginean , Claudiu Manoil Subject: [PATCH net-next 08/12] net: enetc: simplify callers of enetc_rxbd_next Date: Wed, 10 Mar 2021 14:03:47 +0200 Message-Id: <20210310120351.542292-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210310120351.542292-1-vladimir.oltean@nxp.com> References: <20210310120351.542292-1-vladimir.oltean@nxp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When we iterate through the BDs in the RX ring, the software producer index (which is already passed by value to enetc_rxbd_next) lags behind, and we end up with this funny looking "++i == rx_ring->bd_count" check so that we drag it after us. Let's pass the software producer index "i" by reference, so that enetc_rxbd_next can increment it by itself (mod rx_ring->bd_count), especially since enetc_rxbd_next has to increment the index anyway. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/freescale/enetc/enetc.c | 21 +++++------------- drivers/net/ethernet/freescale/enetc/enetc.h | 23 +++++++++++++------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index f92d29b62bae..3b04d7596d80 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -483,13 +483,8 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt) /* clear 'R" as well */ rxbd->r.lstatus = 0; - rxbd = enetc_rxbd_next(rx_ring, rxbd, i); - rx_swbd++; - i++; - if (unlikely(i == rx_ring->bd_count)) { - i = 0; - rx_swbd = rx_ring->rx_swbd; - } + enetc_rxbd_next(rx_ring, &rxbd, &i); + rx_swbd = &rx_ring->rx_swbd[i]; } if (likely(j)) { @@ -704,9 +699,7 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring, cleaned_cnt++; - rxbd = enetc_rxbd_next(rx_ring, rxbd, i); - if (unlikely(++i == rx_ring->bd_count)) - i = 0; + enetc_rxbd_next(rx_ring, &rxbd, &i); if (unlikely(bd_status & ENETC_RXBD_LSTATUS(ENETC_RXBD_ERR_MASK))) { @@ -715,9 +708,7 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring, dma_rmb(); bd_status = le32_to_cpu(rxbd->r.lstatus); - rxbd = enetc_rxbd_next(rx_ring, rxbd, i); - if (unlikely(++i == rx_ring->bd_count)) - i = 0; + enetc_rxbd_next(rx_ring, &rxbd, &i); } rx_ring->ndev->stats.rx_dropped++; @@ -740,9 +731,7 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring, cleaned_cnt++; - rxbd = enetc_rxbd_next(rx_ring, rxbd, i); - if (unlikely(++i == rx_ring->bd_count)) - i = 0; + enetc_rxbd_next(rx_ring, &rxbd, &i); } rx_byte_cnt += skb->len; diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index af8b8be114bd..30b9ad550d7b 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -121,19 +121,26 @@ static inline union enetc_rx_bd *enetc_rxbd(struct enetc_bdr *rx_ring, int i) return &(((union enetc_rx_bd *)rx_ring->bd_base)[hw_idx]); } -static inline union enetc_rx_bd *enetc_rxbd_next(struct enetc_bdr *rx_ring, - union enetc_rx_bd *rxbd, - int i) +static inline void enetc_rxbd_next(struct enetc_bdr *rx_ring, + union enetc_rx_bd **old_rxbd, int *old_index) { - rxbd++; + union enetc_rx_bd *new_rxbd = *old_rxbd; + int new_index = *old_index; + + new_rxbd++; + #ifdef CONFIG_FSL_ENETC_PTP_CLOCK if (rx_ring->ext_en) - rxbd++; + new_rxbd++; #endif - if (unlikely(++i == rx_ring->bd_count)) - rxbd = rx_ring->bd_base; - return rxbd; + if (unlikely(++new_index == rx_ring->bd_count)) { + new_rxbd = rx_ring->bd_base; + new_index = 0; + } + + *old_rxbd = new_rxbd; + *old_index = new_index; } static inline union enetc_rx_bd *enetc_rxbd_ext(union enetc_rx_bd *rxbd) From patchwork Wed Mar 10 12:03:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 397227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4AE0C43331 for ; Wed, 10 Mar 2021 12:05:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77E2F64FEE for ; Wed, 10 Mar 2021 12:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232958AbhCJMFc (ORCPT ); Wed, 10 Mar 2021 07:05:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232902AbhCJMEx (ORCPT ); Wed, 10 Mar 2021 07:04:53 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A17F9C061761 for ; Wed, 10 Mar 2021 04:04:52 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id dx17so38200400ejb.2 for ; Wed, 10 Mar 2021 04:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xA/ml8LK32aqYsuvbZVIyJ1xT0WmGfjBmjXYMFysg7Q=; b=nWNuqvMdNHXaNetrEAIl+oYi/B02EZmkHM+ngWtYvlcnx7Qw3dstdV5ED8IFmPUZpg mpPe8UypTu3u0DT2Icy9i4jvjN8qt/NqrSBjrzOHDyKKQ4JJ+40I1OFZ4d7YOo8XQQlX 43WKjL68cgCifWUSYtylum3iBdPjUZyzXEdVk0jtuuutTXkUyKATWo2DN117Kv+etDif IwLIoA13huo0Dm5cPRwij24LLucJj2fxkWOfDhy4lEKkTqV/iZAMBq95CsQOFH5v5t3l 3FTqeGwfnUM3BIc8KgC9/qBVbemRhbFI/DFLqlEs+2jSY0hYniFNdsgez+6uU7bsPXsX nFRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xA/ml8LK32aqYsuvbZVIyJ1xT0WmGfjBmjXYMFysg7Q=; b=T788bxrTURSnBDjK9cN5HJJFH7xfOUGTUZXt/NjpHtGDe810n5UCildnPkFUB94Y0/ h55hmMnHiLVfcZ1g0BxecDtF+asHcBjmBuS5tQG9aJPyIk+13W4Z9BcxTSHwjYJEk6oj 5CTB2jlFkCe+L7CWAVBqY5PM81IgIBFJLWd9aBPg1R35W9DiQj7LTC8dMyJDsx4uMuRO 60Uyss8CPD80tgA8/epX2YaY/Eze76hCXQ84RtI6A3ybJ66WbOgKMWB2zTX4lkvFCVdO Se0aLxd9h1VqD2SLoOoiQz4vUGthZp0Jf9vmjMmxqGrmynUBINRjBXcGS8NduEpks3l2 VkCQ== X-Gm-Message-State: AOAM530q/joLsYKATctza4+tNmb6afOjmaBvsOemjXKB49iVywZn1dch CUy1U9znwI7j7ag87xVIOrU= X-Google-Smtp-Source: ABdhPJzjAYLMWKPVVne4JDVZKQHfVpWvuKfJnnmnkiO3q5N49NHC6SJdb5DxZuMdxE66/pGLu1CYtg== X-Received: by 2002:a17:906:1754:: with SMTP id d20mr3210823eje.221.1615377891407; Wed, 10 Mar 2021 04:04:51 -0800 (PST) Received: from localhost.localdomain ([188.25.219.167]) by smtp.gmail.com with ESMTPSA id q20sm9913239ejs.41.2021.03.10.04.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 04:04:51 -0800 (PST) From: Vladimir Oltean X-Google-Original-From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: Alex Marginean , Claudiu Manoil Subject: [PATCH net-next 12/12] net: enetc: make enetc_refill_rx_ring update the consumer index Date: Wed, 10 Mar 2021 14:03:51 +0200 Message-Id: <20210310120351.542292-13-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210310120351.542292-1-vladimir.oltean@nxp.com> References: <20210310120351.542292-1-vladimir.oltean@nxp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since commit fd5736bf9f23 ("enetc: Workaround for MDIO register access issue"), enetc_refill_rx_ring no longer updates the RX BD ring's consumer index, that is left to be done by the caller. This has led to bugs such as the ones found in 96a5223b918c ("net: enetc: remove bogus write to SIRXIDR from enetc_setup_rxbdr") and 3a5d12c9be6f ("net: enetc: keep RX ring consumer index in sync with hardware"), so it is desirable that we move back the update of the consumer index into enetc_refill_rx_ring. The trouble with that is the different MDIO locking context for the two callers of enetc_refill_rx_ring: - enetc_clean_rx_ring runs under enetc_lock_mdio() - enetc_setup_rxbdr runs outside enetc_lock_mdio() Simplify the callers of enetc_refill_rx_ring by making enetc_setup_rxbdr explicitly take enetc_lock_mdio() around the call. It will be the only place in need of ensuring the hot accessors can be used. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/freescale/enetc/enetc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index c8b0b03f5ee7..e85dfccb9ed1 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -439,6 +439,9 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt) if (likely(j)) { rx_ring->next_to_alloc = i; /* keep track from page reuse */ rx_ring->next_to_use = i; + + /* update ENETC's consumer index */ + enetc_wr_reg_hot(rx_ring->rcir, rx_ring->next_to_use); } return j; @@ -624,13 +627,9 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring, u32 bd_status; u16 size; - if (cleaned_cnt >= ENETC_RXBD_BUNDLE) { - int count = enetc_refill_rx_ring(rx_ring, cleaned_cnt); - - /* update ENETC's consumer index */ - enetc_wr_reg_hot(rx_ring->rcir, rx_ring->next_to_use); - cleaned_cnt -= count; - } + if (cleaned_cnt >= ENETC_RXBD_BUNDLE) + cleaned_cnt -= enetc_refill_rx_ring(rx_ring, + cleaned_cnt); rxbd = enetc_rxbd(rx_ring, i); bd_status = le32_to_cpu(rxbd->r.lstatus); @@ -1122,9 +1121,9 @@ static void enetc_setup_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring) rx_ring->rcir = hw->reg + ENETC_BDR(RX, idx, ENETC_RBCIR); rx_ring->idr = hw->reg + ENETC_SIRXIDR; + enetc_lock_mdio(); enetc_refill_rx_ring(rx_ring, enetc_bd_unused(rx_ring)); - /* update ENETC's consumer index */ - enetc_rxbdr_wr(hw, idx, ENETC_RBCIR, rx_ring->next_to_use); + enetc_unlock_mdio(); /* enable ring */ enetc_rxbdr_wr(hw, idx, ENETC_RBMR, rbmr);