From patchwork Thu Dec 21 22:02:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13502688 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 141AF7946F for ; Thu, 21 Dec 2023 22:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="ZauCIoWa" Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3bb69f38855so848130b6e.1 for ; Thu, 21 Dec 2023 14:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1703196192; x=1703800992; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=mq+m9Q3AkQnR9BUZFgEt1bUY1FgNMbgX6AkDWJExz2I=; b=ZauCIoWaolzdFN6QcyI+cSdIE5ZsmOvMjK7yRnaVqSpxNNYLyOb7SSElPB1BApYFOC sJn0uGXQBEcXrL44PbZVxSljuLsPU35JZNPIVdVos+CLo+m8mxzfpXAuNKqK3MT6G9Yx GdY3dqkJuwDC7/7iwbhfmlfMf2VcUAsSLjPLo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703196192; x=1703800992; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mq+m9Q3AkQnR9BUZFgEt1bUY1FgNMbgX6AkDWJExz2I=; b=tNdSDDXQDqgg5g4nXQ0/+5PlQGSd9/tJKcCx8ZfWxKxkOLrUw6dENp/a9ocApTDwP6 wlg0TAIxjZSHobbjfqbSxiC/iSRPQceSNpB34DOdi0EF1tg/Ps7QJ9IEzGS1uTpg4NkH eJRU4paUc37LFPh6hPhLK0gtSuaIa2vEjVa8wiUitcWxPZpjbLnuB0sBdZQ7zOg0LNbv yOiDeVdf41ocJ8lMAwF7ozmCRyIfrwCBEsu5toOmMCJaN9b7ZdCM6yeNOY4uOBGpluqn O/cXzXYLRfKoTag+tXydjrHbN7Q4BenDaE7ffM5kIRnj89I/OdrvIEGQqGXMm6SH2+lw UwHQ== X-Gm-Message-State: AOJu0Yy3O3j9MVz0qwOEjTprGdvX+QQg/9qVm45SQiLBYI6MpC+1DiN2 q9T6NsLAt7h6eKDDh6ArmbkoRJptVIRV X-Google-Smtp-Source: AGHT+IEOlJfgXDrips9Xx8+UpomoxilI/HF5hdUQxPT6AyIhatZOA/GfkSJd6i5q6t0C90GcLH2eLw== X-Received: by 2002:a05:6808:319a:b0:3ba:951:dd45 with SMTP id cd26-20020a056808319a00b003ba0951dd45mr459895oib.61.1703196191904; Thu, 21 Dec 2023 14:03:11 -0800 (PST) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id ee14-20020a0562140a4e00b0067f712874fbsm905198qvb.129.2023.12.21.14.03.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Dec 2023 14:03:11 -0800 (PST) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pavan.chebbi@broadcom.com, andrew.gospodarek@broadcom.com Subject: [PATCH net-next 09/13] bnxt_en: Refactor the hash table logic for ntuple filters. Date: Thu, 21 Dec 2023 14:02:14 -0800 Message-Id: <20231221220218.197386-10-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231221220218.197386-1-michael.chan@broadcom.com> References: <20231221220218.197386-1-michael.chan@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Generalize the ethtool logic that walks the ntuple hash table now that we have the common bnxt_filter_base structure. This will allow the code to easily extend to cover user defined ntuple or ether filters. Reviewed-by: Vasundhara Volam Reviewed-by: Andy Gospodarek Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 1 + drivers/net/ethernet/broadcom/bnxt/bnxt.h | 1 + .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 85 +++++++++++++------ 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index f5d6c746f677..186c7dde51e2 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -5611,6 +5611,7 @@ static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp, struct hwrm_cfa_ntuple_filter_free_input *req; int rc; + set_bit(BNXT_FLTR_FW_DELETED, &fltr->base.state); rc = hwrm_req_init(bp, req, HWRM_CFA_NTUPLE_FILTER_FREE); if (rc) return rc; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h index 73e2fe705caf..f37d98d7962a 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h @@ -1349,6 +1349,7 @@ struct bnxt_filter_base { unsigned long state; #define BNXT_FLTR_VALID 0 #define BNXT_FLTR_INSERTED 1 +#define BNXT_FLTR_FW_DELETED 2 struct rcu_head rcu; }; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index 65edad2cfeab..8cc762a12a3e 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -1012,28 +1012,60 @@ static int bnxt_set_channels(struct net_device *dev, } #ifdef CONFIG_RFS_ACCEL -static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, - u32 *rule_locs) +static u32 bnxt_get_all_fltr_ids_rcu(struct bnxt *bp, struct hlist_head tbl[], + int tbl_size, u32 *ids, u32 start, + u32 id_cnt) { - int i, j = 0; + int i, j = start; - cmd->data = bp->ntp_fltr_count; - for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { + if (j >= id_cnt) + return j; + for (i = 0; i < tbl_size; i++) { struct hlist_head *head; - struct bnxt_ntuple_filter *fltr; + struct bnxt_filter_base *fltr; - head = &bp->ntp_fltr_hash_tbl[i]; - rcu_read_lock(); - hlist_for_each_entry_rcu(fltr, head, base.hash) { - if (j == cmd->rule_cnt) - break; - rule_locs[j++] = fltr->base.sw_id; + head = &tbl[i]; + hlist_for_each_entry_rcu(fltr, head, hash) { + if (!fltr->flags || + test_bit(BNXT_FLTR_FW_DELETED, &fltr->state)) + continue; + ids[j++] = fltr->sw_id; + if (j == id_cnt) + return j; } - rcu_read_unlock(); - if (j == cmd->rule_cnt) - break; } - cmd->rule_cnt = j; + return j; +} + +static struct bnxt_filter_base *bnxt_get_one_fltr_rcu(struct bnxt *bp, + struct hlist_head tbl[], + int tbl_size, u32 id) +{ + int i; + + for (i = 0; i < tbl_size; i++) { + struct hlist_head *head; + struct bnxt_filter_base *fltr; + + head = &tbl[i]; + hlist_for_each_entry_rcu(fltr, head, hash) { + if (fltr->flags && fltr->sw_id == id) + return fltr; + } + } + return NULL; +} + +static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, + u32 *rule_locs) +{ + cmd->data = bp->ntp_fltr_count; + rcu_read_lock(); + cmd->rule_cnt = bnxt_get_all_fltr_ids_rcu(bp, bp->ntp_fltr_hash_tbl, + BNXT_NTP_FLTR_HASH_SIZE, + rule_locs, 0, cmd->rule_cnt); + rcu_read_unlock(); + return 0; } @@ -1041,27 +1073,24 @@ static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) { struct ethtool_rx_flow_spec *fs = (struct ethtool_rx_flow_spec *)&cmd->fs; + struct bnxt_filter_base *fltr_base; struct bnxt_ntuple_filter *fltr; struct flow_keys *fkeys; - int i, rc = -EINVAL; + int rc = -EINVAL; if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR) return rc; - for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { - struct hlist_head *head; - - head = &bp->ntp_fltr_hash_tbl[i]; - rcu_read_lock(); - hlist_for_each_entry_rcu(fltr, head, base.hash) { - if (fltr->base.sw_id == fs->location) - goto fltr_found; - } + rcu_read_lock(); + fltr_base = bnxt_get_one_fltr_rcu(bp, bp->ntp_fltr_hash_tbl, + BNXT_NTP_FLTR_HASH_SIZE, + fs->location); + if (!fltr_base) { rcu_read_unlock(); + return rc; } - return rc; + fltr = container_of(fltr_base, struct bnxt_ntuple_filter, base); -fltr_found: fkeys = &fltr->fkeys; if (fkeys->basic.n_proto == htons(ETH_P_IP)) { if (fkeys->basic.ip_proto == IPPROTO_TCP)