From patchwork Thu Dec 21 22:02:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13502687 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 B1AD778E96 for ; Thu, 21 Dec 2023 22:03:11 +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="GxUfd6eU" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-67f91d48863so1870046d6.0 for ; Thu, 21 Dec 2023 14:03:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1703196190; x=1703800990; 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=P8gGcfNNc2KAPI3HEk9A1doa8CGHlSv5HW4n1p8PaIw=; b=GxUfd6eUEpLa3He7eztwYv9VnZd1VFPnev2Ij99WumLNeupa0vI3ue9w4JlzMd4rGr MvN1PNakXAVJrVnwDYczef2V7sud54+1Ce22p6PUB1e+tzdvI21HrDFOei6kor85cpHb trRFqsRE38UsLhYcXK8jVAhlEVQ5hPA+7Vw2M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703196190; x=1703800990; 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=P8gGcfNNc2KAPI3HEk9A1doa8CGHlSv5HW4n1p8PaIw=; b=mcEOPofwh52cPn4G0lvHZoDX0Xms5mW8RGPYJ5hIIXHF0jiD/jPPfomiO8kqXv9LMx uksCZuefSHQAY5Kg1xNjv0vv5tvSFlnhRvhiBO1DAUsrWHzPHnO8h9fjj5hLsm+lAmfA uZxM3EguvzImmQlS77Ya1JNICYZIlnZW6Ki15Oh8jhijsUhv6gItw6k9XV5Yw86DkHjt CXcQzFgl6xlh/13dNyGxKlu3gHKP163eMq5DjCpI742ZwYTqeZZcEq8lKBVc+sji0y64 taJV7qWwNvB0shcbO6sSVr01zFS6mdwQ2TO9imtNOceV2ZiCe+YpkS2CkdzcZsquVyd+ zXVw== X-Gm-Message-State: AOJu0Yze6HHsCX8lN1NocV1/BQyDZTVO+a74WZyfY0vOAfjFSuUA94ip Vy3b7bcyC9W8bA5TnXRRs3Nxun/SnUXRud4PTURmgqD2FQ== X-Google-Smtp-Source: AGHT+IE69cprUHrb8APYVFl/GgChehUQNievYpvtZSeFQiI2dnf6Msq/mv9XIYoYbw3E7aJSjylbiw== X-Received: by 2002:ad4:5d6c:0:b0:67f:35bc:8e68 with SMTP id fn12-20020ad45d6c000000b0067f35bc8e68mr553027qvb.11.1703196190553; Thu, 21 Dec 2023 14:03:10 -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.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Dec 2023 14:03:10 -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 08/13] bnxt_en: Refactor filter insertion logic in bnxt_rx_flow_steer(). Date: Thu, 21 Dec 2023 14:02:13 -0800 Message-Id: <20231221220218.197386-9-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 Add a new function bnxt_insert_ntp_filter() to insert the ntuple filter into the hash table and other basic setup. We'll use this function to insert a user defined filter from ethtool. Also, export bnxt_lookup_ntp_filter_from_idx() and bnxt_get_ntp_filter_idx() for similar purposes. All ntuple related functions are now no longer compiled only for CONFIG_RFS_ACCEL Reviewed-by: Vasundhara Volam Reviewed-by: Andy Gospodarek Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 +++++++++-------------- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 6 ++ 2 files changed, 41 insertions(+), 52 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 16eae3bd90e5..f5d6c746f677 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -4800,7 +4800,6 @@ static void bnxt_clear_ring_indices(struct bnxt *bp) static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool all) { -#ifdef CONFIG_RFS_ACCEL int i; /* Under rtnl_lock and all our NAPIs have been disabled. It's @@ -4828,12 +4827,10 @@ static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool all) bitmap_free(bp->ntp_fltr_bmap); bp->ntp_fltr_bmap = NULL; bp->ntp_fltr_count = 0; -#endif } static int bnxt_alloc_ntp_fltrs(struct bnxt *bp) { -#ifdef CONFIG_RFS_ACCEL int i, rc = 0; if (!(bp->flags & BNXT_FLAG_RFS) || bp->ntp_fltr_bmap) @@ -4849,9 +4846,6 @@ static int bnxt_alloc_ntp_fltrs(struct bnxt *bp) rc = -ENOMEM; return rc; -#else - return 0; -#endif } static void bnxt_free_l2_filters(struct bnxt *bp, bool all) @@ -5611,7 +5605,6 @@ int bnxt_hwrm_l2_filter_alloc(struct bnxt *bp, struct bnxt_l2_filter *fltr) return rc; } -#ifdef CONFIG_RFS_ACCEL static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp, struct bnxt_ntuple_filter *fltr) { @@ -5715,7 +5708,6 @@ static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp, hwrm_req_drop(bp, req); return rc; } -#endif static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx, const u8 *mac_addr) @@ -9673,7 +9665,6 @@ static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id) static int bnxt_alloc_rfs_vnics(struct bnxt *bp) { -#ifdef CONFIG_RFS_ACCEL int i, rc = 0; if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) @@ -9702,9 +9693,6 @@ static int bnxt_alloc_rfs_vnics(struct bnxt *bp) break; } return rc; -#else - return 0; -#endif } /* Allow PF, trusted VFs and VFs with default VLAN to be in promiscuous mode */ @@ -10032,7 +10020,6 @@ static int bnxt_setup_int_mode(struct bnxt *bp) return rc; } -#ifdef CONFIG_RFS_ACCEL static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp) { return bp->hw_resc.max_rsscos_ctxs; @@ -10042,7 +10029,6 @@ static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp) { return bp->hw_resc.max_vnics; } -#endif unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp) { @@ -12156,7 +12142,6 @@ static bool bnxt_rfs_supported(struct bnxt *bp) /* If runtime conditions support RFS */ static bool bnxt_rfs_capable(struct bnxt *bp) { -#ifdef CONFIG_RFS_ACCEL int vnics, max_vnics, max_rss_ctxs; if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) @@ -12192,9 +12177,6 @@ static bool bnxt_rfs_capable(struct bnxt *bp) netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n"); bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 0, 1); return false; -#else - return false; -#endif } static netdev_features_t bnxt_fix_features(struct net_device *dev, @@ -13857,8 +13839,8 @@ static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type, } } -static u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys, - const struct sk_buff *skb) +u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys, + const struct sk_buff *skb) { struct bnxt_vnic_info *vnic; @@ -13869,7 +13851,30 @@ static u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys, return bnxt_toeplitz(bp, fkeys, (void *)vnic->rss_hash_key); } -#ifdef CONFIG_RFS_ACCEL +int bnxt_insert_ntp_filter(struct bnxt *bp, struct bnxt_ntuple_filter *fltr, + u32 idx) +{ + struct hlist_head *head; + int bit_id; + + spin_lock_bh(&bp->ntp_fltr_lock); + bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, BNXT_MAX_FLTR, 0); + if (bit_id < 0) { + spin_unlock_bh(&bp->ntp_fltr_lock); + return -ENOMEM; + } + + fltr->base.sw_id = (u16)bit_id; + fltr->base.type = BNXT_FLTR_TYPE_NTUPLE; + fltr->base.flags |= BNXT_ACT_RING_DST; + head = &bp->ntp_fltr_hash_tbl[idx]; + hlist_add_head_rcu(&fltr->base.hash, head); + set_bit(BNXT_FLTR_INSERTED, &fltr->base.state); + bp->ntp_fltr_count++; + spin_unlock_bh(&bp->ntp_fltr_lock); + return 0; +} + static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1, struct bnxt_ntuple_filter *f2) { @@ -13900,7 +13905,7 @@ static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1, return false; } -static struct bnxt_ntuple_filter * +struct bnxt_ntuple_filter * bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp, struct bnxt_ntuple_filter *fltr, u32 idx) { @@ -13915,6 +13920,7 @@ bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp, return NULL; } +#ifdef CONFIG_RFS_ACCEL static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, u16 rxq_index, u32 flow_id) { @@ -13923,8 +13929,7 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, struct flow_keys *fkeys; struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb); struct bnxt_l2_filter *l2_fltr; - int rc = 0, idx, bit_id; - struct hlist_head *head; + int rc = 0, idx; u32 flags; if (ether_addr_equal(dev->dev_addr, eth->h_dest)) { @@ -13977,7 +13982,6 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, new_fltr->l2_fltr = l2_fltr; idx = bnxt_get_ntp_filter_idx(bp, fkeys, skb); - head = &bp->ntp_fltr_hash_tbl[idx]; rcu_read_lock(); fltr = bnxt_lookup_ntp_filter_from_idx(bp, new_fltr, idx); if (fltr) { @@ -13987,33 +13991,20 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, } rcu_read_unlock(); - spin_lock_bh(&bp->ntp_fltr_lock); - bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, BNXT_MAX_FLTR, 0); - if (bit_id < 0) { - spin_unlock_bh(&bp->ntp_fltr_lock); - rc = -ENOMEM; - goto err_free; - } - - new_fltr->base.sw_id = (u16)bit_id; new_fltr->flow_id = flow_id; new_fltr->base.rxq = rxq_index; - new_fltr->base.type = BNXT_FLTR_TYPE_NTUPLE; - new_fltr->base.flags = BNXT_ACT_RING_DST; - hlist_add_head_rcu(&new_fltr->base.hash, head); - set_bit(BNXT_FLTR_INSERTED, &new_fltr->base.state); - bp->ntp_fltr_count++; - spin_unlock_bh(&bp->ntp_fltr_lock); - - bnxt_queue_sp_work(bp, BNXT_RX_NTP_FLTR_SP_EVENT); - - return new_fltr->base.sw_id; + rc = bnxt_insert_ntp_filter(bp, new_fltr, idx); + if (!rc) { + bnxt_queue_sp_work(bp, BNXT_RX_NTP_FLTR_SP_EVENT); + return new_fltr->base.sw_id; + } err_free: bnxt_del_l2_filter(bp, l2_fltr); kfree(new_fltr); return rc; } +#endif static void bnxt_cfg_ntp_filters(struct bnxt *bp) { @@ -14066,14 +14057,6 @@ static void bnxt_cfg_ntp_filters(struct bnxt *bp) netdev_info(bp->dev, "Receive PF driver unload event!\n"); } -#else - -static void bnxt_cfg_ntp_filters(struct bnxt *bp) -{ -} - -#endif /* CONFIG_RFS_ACCEL */ - static int bnxt_udp_tunnel_set_port(struct net_device *netdev, unsigned int table, unsigned int entry, struct udp_tunnel_info *ti) { diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h index 867cab036e13..73e2fe705caf 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h @@ -2678,6 +2678,12 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, int bnxt_fw_init_one(struct bnxt *bp); bool bnxt_hwrm_reset_permitted(struct bnxt *bp); int bnxt_setup_mq_tc(struct net_device *dev, u8 tc); +struct bnxt_ntuple_filter *bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp, + struct bnxt_ntuple_filter *fltr, u32 idx); +u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys, + const struct sk_buff *skb); +int bnxt_insert_ntp_filter(struct bnxt *bp, struct bnxt_ntuple_filter *fltr, + u32 idx); int bnxt_get_max_rings(struct bnxt *, int *, int *, bool); int bnxt_restore_pf_fw_resources(struct bnxt *bp); int bnxt_get_port_parent_id(struct net_device *dev,