From nobody Wed Dec 17 15:33:19 2025 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 407C2C624B4 for ; Fri, 24 Nov 2023 15:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345513AbjKXPDv (ORCPT ); Fri, 24 Nov 2023 10:03:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345384AbjKXPDr (ORCPT ); Fri, 24 Nov 2023 10:03:47 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 259D993 for ; Fri, 24 Nov 2023 07:03:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700838233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ntIwoh8nmo6x8jvo27voHZh3WCaqdVm0ct3IIneIzKs=; b=LaCJJGtUISR+Ew2EjgkasLSjQAlm2xQNQoLLo4jk5m1dKtd3Q44IM9pVI/g8eWrrTb01rv UvlciLCB87VilyCTSRegzA7NgK4lh5/rylws9/PGcdQbXar01wzsFtuqHAVRu8l6NntqCA DypccxvBZeQ8duFdfkpN6VmZ4Bpnc2M= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-J3KkISlDMFmYuwGt8AFG9w-1; Fri, 24 Nov 2023 10:03:49 -0500 X-MC-Unique: J3KkISlDMFmYuwGt8AFG9w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A558E85A58B; Fri, 24 Nov 2023 15:03:48 +0000 (UTC) Received: from p1.luc.cera.cz (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD8E340C6EB9; Fri, 24 Nov 2023 15:03:46 +0000 (UTC) From: Ivan Vecera To: intel-wired-lan@lists.osuosl.org Cc: Jesse Brandeburg , Tony Nguyen , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, Jacob Keller , Wojciech Drewek , Simon Horman , mschmidt@redhat.com, netdev@vger.kernel.org Subject: [PATCH v5 1/5] i40e: Use existing helper to find flow director VSI Date: Fri, 24 Nov 2023 16:03:39 +0100 Message-ID: <20231124150343.81520-2-ivecera@redhat.com> In-Reply-To: <20231124150343.81520-1-ivecera@redhat.com> References: <20231124150343.81520-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use existing i40e_find_vsi_by_type() to find a VSI associated with flow director. Reviewed-by: Wojciech Drewek Signed-off-by: Ivan Vecera Reviewed-by: Simon Horman Tested-by: Pucha Himasekhar Reddy (A Co= ntingent worker at Intel) --- drivers/net/ethernet/intel/i40e/i40e_main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethe= rnet/intel/i40e/i40e_main.c index 51ee870ffa36..90966878333c 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -15645,6 +15645,7 @@ static int i40e_probe(struct pci_dev *pdev, const s= truct pci_device_id *ent) #ifdef CONFIG_I40E_DCB enum i40e_get_fw_lldp_status_resp lldp_status; #endif /* CONFIG_I40E_DCB */ + struct i40e_vsi *vsi; struct i40e_pf *pf; struct i40e_hw *hw; u16 wol_nvm_bits; @@ -15655,7 +15656,6 @@ static int i40e_probe(struct pci_dev *pdev, const s= truct pci_device_id *ent) #endif /* CONFIG_I40E_DCB */ int err; u32 val; - u32 i; =20 err =3D pci_enable_device_mem(pdev); if (err) @@ -16005,12 +16005,9 @@ static int i40e_probe(struct pci_dev *pdev, const = struct pci_device_id *ent) INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list); =20 /* if FDIR VSI was set up, start it now */ - for (i =3D 0; i < pf->num_alloc_vsi; i++) { - if (pf->vsi[i] && pf->vsi[i]->type =3D=3D I40E_VSI_FDIR) { - i40e_vsi_open(pf->vsi[i]); - break; - } - } + vsi =3D i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); + if (vsi) + i40e_vsi_open(vsi); =20 /* The driver only wants link up/down and module qualification * reports from firmware. Note the negative logic. --=20 2.41.0 From nobody Wed Dec 17 15:33:19 2025 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 C6F20C624B4 for ; Fri, 24 Nov 2023 15:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345687AbjKXPEC (ORCPT ); Fri, 24 Nov 2023 10:04:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345533AbjKXPDy (ORCPT ); Fri, 24 Nov 2023 10:03:54 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 947F81725 for ; Fri, 24 Nov 2023 07:03:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700838237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GQ+t+W/xrppD1+nXBNxBNiovdtJ98LhjK1/N5Ct/MSE=; b=Je8AnBJNBuM9dCyoPRkH6anzsjP69tys5I2scbfYHzSwfIITZzNXc4LgsF/Ch6HdbUMv8/ sAX76GFRrYBXejN03inL5ALfNoDJYzDxrvMu22QrSMqiPbRarTcgeNh8n2wMfGsxP8FxuU 5T+54ZOSXvyUmJ1r6Xmv8ihSl853JBo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-gqfe9SthP4WW6mF-QhGZ-A-1; Fri, 24 Nov 2023 10:03:51 -0500 X-MC-Unique: gqfe9SthP4WW6mF-QhGZ-A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E79B53806299; Fri, 24 Nov 2023 15:03:50 +0000 (UTC) Received: from p1.luc.cera.cz (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB49B40C6EB9; Fri, 24 Nov 2023 15:03:48 +0000 (UTC) From: Ivan Vecera To: intel-wired-lan@lists.osuosl.org Cc: Jesse Brandeburg , Tony Nguyen , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, Jacob Keller , Wojciech Drewek , Simon Horman , mschmidt@redhat.com, netdev@vger.kernel.org Subject: [PATCH v5 2/5] i40e: Introduce and use macros for iterating VSIs and VEBs Date: Fri, 24 Nov 2023 16:03:40 +0100 Message-ID: <20231124150343.81520-3-ivecera@redhat.com> In-Reply-To: <20231124150343.81520-1-ivecera@redhat.com> References: <20231124150343.81520-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Introduce i40e_for_each_vsi() and i40e_for_each_veb() helper macros and use them to iterate relevant arrays. Replace pattern: for (i =3D 0; i < pf->num_alloc_vsi; i++) by: i40e_for_each_vsi(pf, i, vsi) and pattern: for (i =3D 0; i < I40E_MAX_VEB; i++) by i40e_for_each_veb(pf, i, veb) These macros also check if array item pf->vsi[i] or pf->veb[i] are not NULL and skip such items so we can remove redundant checks from loop bodies. Reviewed-by: Wojciech Drewek Signed-off-by: Ivan Vecera Reviewed-by: Simon Horman Tested-by: Pucha Himasekhar Reddy (A Co= ntingent worker at Intel) --- drivers/net/ethernet/intel/i40e/i40e.h | 56 ++- drivers/net/ethernet/intel/i40e/i40e_dcb_nl.c | 10 +- .../net/ethernet/intel/i40e/i40e_debugfs.c | 54 +-- drivers/net/ethernet/intel/i40e/i40e_main.c | 389 ++++++++---------- 4 files changed, 264 insertions(+), 245 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/= intel/i40e/i40e.h index f1627ab211cd..08cea99150bc 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -686,6 +686,54 @@ struct i40e_pf { struct list_head ddp_old_prof; }; =20 +/** + * __i40e_pf_next_vsi - get next valid VSI + * @pf: pointer to the PF struct + * @idx: pointer to start position number + * + * Find and return next non-NULL VSI pointer in pf->vsi array and + * updates idx position. Returns NULL if no VSI is found. + **/ +static __always_inline struct i40e_vsi * +__i40e_pf_next_vsi(struct i40e_pf *pf, int *idx) +{ + while (*idx < pf->num_alloc_vsi) { + if (pf->vsi[*idx]) + return pf->vsi[*idx]; + (*idx)++; + } + return NULL; +} + +#define i40e_pf_for_each_vsi(_pf, _i, _vsi) \ + for (_i =3D 0, _vsi =3D __i40e_pf_next_vsi(_pf, &_i); \ + _vsi; \ + _i++, _vsi =3D __i40e_pf_next_vsi(_pf, &_i)) + +/** + * __i40e_pf_next_veb - get next valid VEB + * @pf: pointer to the PF struct + * @idx: pointer to start position number + * + * Find and return next non-NULL VEB pointer in pf->veb array and + * updates idx position. Returns NULL if no VEB is found. + **/ +static __always_inline struct i40e_veb * +__i40e_pf_next_veb(struct i40e_pf *pf, int *idx) +{ + while (*idx < I40E_MAX_VEB) { + if (pf->veb[*idx]) + return pf->veb[*idx]; + (*idx)++; + } + return NULL; +} + +#define i40e_pf_for_each_veb(_pf, _i, _veb) \ + for (_i =3D 0, _veb =3D __i40e_pf_next_veb(_pf, &_i); \ + _veb; \ + _i++, _veb =3D __i40e_pf_next_veb(_pf, &_i)) + /** * i40e_mac_to_hkey - Convert a 6-byte MAC Address to a u64 hash key * @macaddr: the MAC Address as the base key @@ -1120,14 +1168,12 @@ struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_= pf *pf, u16 id); static inline struct i40e_vsi * i40e_find_vsi_by_type(struct i40e_pf *pf, u16 type) { + struct i40e_vsi *vsi; int i; =20 - for (i =3D 0; i < pf->num_alloc_vsi; i++) { - struct i40e_vsi *vsi =3D pf->vsi[i]; - - if (vsi && vsi->type =3D=3D type) + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->type =3D=3D type) return vsi; - } =20 return NULL; } diff --git a/drivers/net/ethernet/intel/i40e/i40e_dcb_nl.c b/drivers/net/et= hernet/intel/i40e/i40e_dcb_nl.c index 4721845fda6e..57020effd2c7 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_dcb_nl.c +++ b/drivers/net/ethernet/intel/i40e/i40e_dcb_nl.c @@ -948,16 +948,16 @@ static int i40e_dcbnl_vsi_del_app(struct i40e_vsi *vs= i, static void i40e_dcbnl_del_app(struct i40e_pf *pf, struct i40e_dcb_app_priority_table *app) { + struct i40e_vsi *vsi; int v, err; =20 - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (pf->vsi[v] && pf->vsi[v]->netdev) { - err =3D i40e_dcbnl_vsi_del_app(pf->vsi[v], app); + i40e_pf_for_each_vsi(pf, v, vsi) + if (vsi->netdev) { + err =3D i40e_dcbnl_vsi_del_app(vsi, app); dev_dbg(&pf->pdev->dev, "Deleting app for VSI seid=3D%d err=3D%d sel=3D= %d proto=3D0x%x prio=3D%d\n", - pf->vsi[v]->seid, err, app->selector, + vsi->seid, err, app->selector, app->protocolid, app->priority); } - } } =20 /** diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/e= thernet/intel/i40e/i40e_debugfs.c index ef70ddbe9c2f..b236b0f93202 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c +++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c @@ -24,14 +24,18 @@ enum ring_type { **/ static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid) { + struct i40e_vsi *vsi; int i; =20 - if (seid < 0) + if (seid < 0) { dev_info(&pf->pdev->dev, "%d: bad seid\n", seid); - else - for (i =3D 0; i < pf->num_alloc_vsi; i++) - if (pf->vsi[i] && (pf->vsi[i]->seid =3D=3D seid)) - return pf->vsi[i]; + + return NULL; + } + + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->seid =3D=3D seid) + return vsi; =20 return NULL; } @@ -43,11 +47,13 @@ static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_p= f *pf, int seid) **/ static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid) { + struct i40e_veb *veb; int i; =20 - for (i =3D 0; i < I40E_MAX_VEB; i++) - if (pf->veb[i] && pf->veb[i]->seid =3D=3D seid) - return pf->veb[i]; + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D seid) + return veb; + return NULL; } =20 @@ -653,12 +659,11 @@ static void i40e_dbg_dump_desc(int cnt, int vsi_seid,= int ring_id, int desc_n, **/ static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf) { + struct i40e_vsi *vsi; int i; =20 - for (i =3D 0; i < pf->num_alloc_vsi; i++) - if (pf->vsi[i]) - dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n", - i, pf->vsi[i]->seid); + i40e_pf_for_each_vsi(pf, i, vsi) + dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n", i, vsi->seid); } =20 /** @@ -718,11 +723,8 @@ static void i40e_dbg_dump_veb_all(struct i40e_pf *pf) struct i40e_veb *veb; int i; =20 - for (i =3D 0; i < I40E_MAX_VEB; i++) { - veb =3D pf->veb[i]; - if (veb) - i40e_dbg_dump_veb_seid(pf, veb->seid); - } + i40e_pf_for_each_veb(pf, i, veb) + i40e_dbg_dump_veb_seid(pf, veb->seid); } =20 /** @@ -873,9 +875,10 @@ static ssize_t i40e_dbg_command_write(struct file *fil= p, goto command_write_done; } =20 - for (i =3D 0; i < I40E_MAX_VEB; i++) - if (pf->veb[i] && pf->veb[i]->seid =3D=3D uplink_seid) + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D uplink_seid) break; + if (i >=3D I40E_MAX_VEB && uplink_seid !=3D 0 && uplink_seid !=3D pf->mac_seid) { dev_info(&pf->pdev->dev, @@ -892,7 +895,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp, dev_info(&pf->pdev->dev, "add relay failed\n"); =20 } else if (strncmp(cmd_buf, "del relay", 9) =3D=3D 0) { + struct i40e_veb *veb; int i; + cnt =3D sscanf(&cmd_buf[9], "%i", &veb_seid); if (cnt !=3D 1) { dev_info(&pf->pdev->dev, @@ -906,9 +911,10 @@ static ssize_t i40e_dbg_command_write(struct file *fil= p, } =20 /* find the veb */ - for (i =3D 0; i < I40E_MAX_VEB; i++) - if (pf->veb[i] && pf->veb[i]->seid =3D=3D veb_seid) + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D veb_seid) break; + if (i >=3D I40E_MAX_VEB) { dev_info(&pf->pdev->dev, "del relay: relay %d not found\n", veb_seid); @@ -916,7 +922,7 @@ static ssize_t i40e_dbg_command_write(struct file *filp, } =20 dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid); - i40e_veb_release(pf->veb[i]); + i40e_veb_release(veb); } else if (strncmp(cmd_buf, "add pvid", 8) =3D=3D 0) { unsigned int v; int ret; @@ -1251,8 +1257,8 @@ static ssize_t i40e_dbg_command_write(struct file *fi= lp, if (cnt =3D=3D 0) { int i; =20 - for (i =3D 0; i < pf->num_alloc_vsi; i++) - i40e_vsi_reset_stats(pf->vsi[i]); + i40e_pf_for_each_vsi(pf, i, vsi) + i40e_vsi_reset_stats(vsi); dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n"); } else if (cnt =3D=3D 1) { vsi =3D i40e_dbg_find_vsi(pf, vsi_seid); diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethe= rnet/intel/i40e/i40e_main.c index 90966878333c..3a973a92779f 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -304,11 +304,12 @@ static int i40e_put_lump(struct i40e_lump_tracking *p= ile, u16 index, u16 id) **/ struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) { + struct i40e_vsi *vsi; int i; =20 - for (i =3D 0; i < pf->num_alloc_vsi; i++) - if (pf->vsi[i] && (pf->vsi[i]->id =3D=3D id)) - return pf->vsi[i]; + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->id =3D=3D id) + return vsi; =20 return NULL; } @@ -546,24 +547,19 @@ void i40e_vsi_reset_stats(struct i40e_vsi *vsi) **/ void i40e_pf_reset_stats(struct i40e_pf *pf) { + struct i40e_veb *veb; int i; =20 memset(&pf->stats, 0, sizeof(pf->stats)); memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); pf->stat_offsets_loaded =3D false; =20 - for (i =3D 0; i < I40E_MAX_VEB; i++) { - if (pf->veb[i]) { - memset(&pf->veb[i]->stats, 0, - sizeof(pf->veb[i]->stats)); - memset(&pf->veb[i]->stats_offsets, 0, - sizeof(pf->veb[i]->stats_offsets)); - memset(&pf->veb[i]->tc_stats, 0, - sizeof(pf->veb[i]->tc_stats)); - memset(&pf->veb[i]->tc_stats_offsets, 0, - sizeof(pf->veb[i]->tc_stats_offsets)); - pf->veb[i]->stat_offsets_loaded =3D false; - } + i40e_pf_for_each_veb(pf, i, veb) { + memset(&veb->stats, 0, sizeof(veb->stats)); + memset(&veb->stats_offsets, 0, sizeof(veb->stats_offsets)); + memset(&veb->tc_stats, 0, sizeof(veb->tc_stats)); + memset(&veb->tc_stats_offsets, 0, sizeof(veb->tc_stats_offsets)); + veb->stat_offsets_loaded =3D false; } pf->hw_csum_rx_error =3D 0; } @@ -2875,6 +2871,7 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi) **/ static void i40e_sync_filters_subtask(struct i40e_pf *pf) { + struct i40e_vsi *vsi; int v; =20 if (!pf) @@ -2886,11 +2883,10 @@ static void i40e_sync_filters_subtask(struct i40e_p= f *pf) return; } =20 - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (pf->vsi[v] && - (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED) && - !test_bit(__I40E_VSI_RELEASING, pf->vsi[v]->state)) { - int ret =3D i40e_sync_vsi_filters(pf->vsi[v]); + i40e_pf_for_each_vsi(pf, v, vsi) { + if ((vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) && + !test_bit(__I40E_VSI_RELEASING, vsi->state)) { + int ret =3D i40e_sync_vsi_filters(vsi); =20 if (ret) { /* come back and try again later */ @@ -5162,6 +5158,7 @@ static void i40e_reset_interrupt_capability(struct i4= 0e_pf *pf) **/ static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) { + struct i40e_vsi *vsi; int i; =20 if (test_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) @@ -5171,9 +5168,10 @@ static void i40e_clear_interrupt_scheme(struct i40e_= pf *pf) I40E_IWARP_IRQ_PILE_ID); =20 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); - for (i =3D 0; i < pf->num_alloc_vsi; i++) - if (pf->vsi[i]) - i40e_vsi_free_q_vectors(pf->vsi[i]); + + i40e_pf_for_each_vsi(pf, i, vsi) + i40e_vsi_free_q_vectors(vsi); + i40e_reset_interrupt_capability(pf); } =20 @@ -5270,12 +5268,11 @@ static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) **/ static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) { + struct i40e_vsi *vsi; int v; =20 - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (pf->vsi[v]) - i40e_quiesce_vsi(pf->vsi[v]); - } + i40e_pf_for_each_vsi(pf, v, vsi) + i40e_quiesce_vsi(vsi); } =20 /** @@ -5284,12 +5281,11 @@ static void i40e_pf_quiesce_all_vsi(struct i40e_pf = *pf) **/ static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) { + struct i40e_vsi *vsi; int v; =20 - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (pf->vsi[v]) - i40e_unquiesce_vsi(pf->vsi[v]); - } + i40e_pf_for_each_vsi(pf, v, vsi) + i40e_unquiesce_vsi(vsi); } =20 /** @@ -5350,14 +5346,13 @@ int i40e_vsi_wait_queues_disabled(struct i40e_vsi *= vsi) **/ static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) { + struct i40e_vsi *vsi; int v, ret =3D 0; =20 - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (pf->vsi[v]) { - ret =3D i40e_vsi_wait_queues_disabled(pf->vsi[v]); - if (ret) - break; - } + i40e_pf_for_each_vsi(pf, v, vsi) { + ret =3D i40e_vsi_wait_queues_disabled(vsi); + if (ret) + break; } =20 return ret; @@ -6774,32 +6769,29 @@ int i40e_veb_config_tc(struct i40e_veb *veb, u8 ena= bled_tc) **/ static void i40e_dcb_reconfigure(struct i40e_pf *pf) { + struct i40e_vsi *vsi; + struct i40e_veb *veb; u8 tc_map =3D 0; int ret; - u8 v; + int v; =20 /* Enable the TCs available on PF to all VEBs */ tc_map =3D i40e_pf_get_tc_map(pf); if (tc_map =3D=3D I40E_DEFAULT_TRAFFIC_CLASS) return; =20 - for (v =3D 0; v < I40E_MAX_VEB; v++) { - if (!pf->veb[v]) - continue; - ret =3D i40e_veb_config_tc(pf->veb[v], tc_map); + i40e_pf_for_each_veb(pf, v, veb) { + ret =3D i40e_veb_config_tc(veb, tc_map); if (ret) { dev_info(&pf->pdev->dev, "Failed configuring TC for VEB seid=3D%d\n", - pf->veb[v]->seid); + veb->seid); /* Will try to configure as many components */ } } =20 /* Update each VSI */ - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (!pf->vsi[v]) - continue; - + i40e_pf_for_each_vsi(pf, v, vsi) { /* - Enable all TCs for the LAN VSI * - For all others keep them at TC0 for now */ @@ -6808,17 +6800,17 @@ static void i40e_dcb_reconfigure(struct i40e_pf *pf) else tc_map =3D I40E_DEFAULT_TRAFFIC_CLASS; =20 - ret =3D i40e_vsi_config_tc(pf->vsi[v], tc_map); + ret =3D i40e_vsi_config_tc(vsi, tc_map); if (ret) { dev_info(&pf->pdev->dev, "Failed configuring TC for VSI seid=3D%d\n", - pf->vsi[v]->seid); + vsi->seid); /* Will try to configure as many components */ } else { /* Re-configure VSI vectors based on updated TC map */ - i40e_vsi_map_rings_to_vectors(pf->vsi[v]); - if (pf->vsi[v]->netdev) - i40e_dcbnl_set_all(pf->vsi[v]); + i40e_vsi_map_rings_to_vectors(vsi); + if (vsi->netdev) + i40e_dcbnl_set_all(vsi); } } } @@ -9253,7 +9245,9 @@ int i40e_close(struct net_device *netdev) **/ void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired) { + struct i40e_vsi *vsi; u32 val; + int i; =20 /* do the biggest reset indicated */ if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { @@ -9309,29 +9303,20 @@ void i40e_do_reset(struct i40e_pf *pf, u32 reset_fl= ags, bool lock_acquired) "FW LLDP is enabled\n"); =20 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { - int v; - /* Find the VSI(s) that requested a re-init */ - dev_info(&pf->pdev->dev, - "VSI reinit requested\n"); - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - struct i40e_vsi *vsi =3D pf->vsi[v]; + dev_info(&pf->pdev->dev, "VSI reinit requested\n"); =20 - if (vsi !=3D NULL && - test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED, + i40e_pf_for_each_vsi(pf, i, vsi) { + if (test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED, vsi->state)) - i40e_vsi_reinit_locked(pf->vsi[v]); + i40e_vsi_reinit_locked(vsi); } } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { - int v; - /* Find the VSI(s) that needs to be brought down */ dev_info(&pf->pdev->dev, "VSI down requested\n"); - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - struct i40e_vsi *vsi =3D pf->vsi[v]; =20 - if (vsi !=3D NULL && - test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED, + i40e_pf_for_each_vsi(pf, i, vsi) { + if (test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED, vsi->state)) { set_bit(__I40E_VSI_DOWN, vsi->state); i40e_down(vsi); @@ -9886,6 +9871,8 @@ static void i40e_vsi_link_event(struct i40e_vsi *vsi,= bool link_up) **/ static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) { + struct i40e_veb *veb_it; + struct i40e_vsi *vsi; struct i40e_pf *pf; int i; =20 @@ -9894,14 +9881,14 @@ static void i40e_veb_link_event(struct i40e_veb *ve= b, bool link_up) pf =3D veb->pf; =20 /* depth first... */ - for (i =3D 0; i < I40E_MAX_VEB; i++) - if (pf->veb[i] && (pf->veb[i]->uplink_seid =3D=3D veb->seid)) - i40e_veb_link_event(pf->veb[i], link_up); + i40e_pf_for_each_veb(pf, i, veb_it) + if (veb_it->uplink_seid =3D=3D veb->seid) + i40e_veb_link_event(veb_it, link_up); =20 /* ... now the local VSIs */ - for (i =3D 0; i < pf->num_alloc_vsi; i++) - if (pf->vsi[i] && (pf->vsi[i]->uplink_seid =3D=3D veb->seid)) - i40e_vsi_link_event(pf->vsi[i], link_up); + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->uplink_seid =3D=3D veb->seid) + i40e_vsi_link_event(vsi, link_up); } =20 /** @@ -9995,6 +9982,8 @@ static void i40e_link_event(struct i40e_pf *pf) **/ static void i40e_watchdog_subtask(struct i40e_pf *pf) { + struct i40e_vsi *vsi; + struct i40e_veb *veb; int i; =20 /* if interface is down do nothing */ @@ -10016,15 +10005,14 @@ static void i40e_watchdog_subtask(struct i40e_pf = *pf) /* Update the stats for active netdevs so the network stack * can look at updated numbers whenever it cares to */ - for (i =3D 0; i < pf->num_alloc_vsi; i++) - if (pf->vsi[i] && pf->vsi[i]->netdev) - i40e_update_stats(pf->vsi[i]); + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->netdev) + i40e_update_stats(vsi); =20 if (test_bit(I40E_FLAG_VEB_STATS_ENA, pf->flags)) { /* Update the stats for the active switching components */ - for (i =3D 0; i < I40E_MAX_VEB; i++) - if (pf->veb[i]) - i40e_update_veb_stats(pf->veb[i]); + i40e_pf_for_each_veb(pf, i, veb) + i40e_update_veb_stats(veb); } =20 i40e_ptp_rx_hang(pf); @@ -10387,18 +10375,18 @@ static int i40e_reconstitute_veb(struct i40e_veb = *veb) { struct i40e_vsi *ctl_vsi =3D NULL; struct i40e_pf *pf =3D veb->pf; - int v, veb_idx; - int ret; + struct i40e_veb *veb_it; + struct i40e_vsi *vsi; + int v, ret; =20 /* build VSI that owns this VEB, temporarily attached to base VEB */ - for (v =3D 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { - if (pf->vsi[v] && - pf->vsi[v]->veb_idx =3D=3D veb->idx && - pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { - ctl_vsi =3D pf->vsi[v]; + i40e_pf_for_each_vsi(pf, v, vsi) + if (vsi->veb_idx =3D=3D veb->idx && + vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { + ctl_vsi =3D vsi; break; } - } + if (!ctl_vsi) { dev_info(&pf->pdev->dev, "missing owner VSI for veb_idx %d\n", veb->idx); @@ -10428,13 +10416,11 @@ static int i40e_reconstitute_veb(struct i40e_veb = *veb) i40e_config_bridge_mode(veb); =20 /* create the remaining VSIs attached to this VEB */ - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (!pf->vsi[v] || pf->vsi[v] =3D=3D ctl_vsi) + i40e_pf_for_each_vsi(pf, v, vsi) { + if (vsi =3D=3D ctl_vsi) continue; =20 - if (pf->vsi[v]->veb_idx =3D=3D veb->idx) { - struct i40e_vsi *vsi =3D pf->vsi[v]; - + if (vsi->veb_idx =3D=3D veb->idx) { vsi->uplink_seid =3D veb->seid; ret =3D i40e_add_vsi(vsi); if (ret) { @@ -10448,10 +10434,10 @@ static int i40e_reconstitute_veb(struct i40e_veb = *veb) } =20 /* create any VEBs attached to this VEB - RECURSION */ - for (veb_idx =3D 0; veb_idx < I40E_MAX_VEB; veb_idx++) { - if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx =3D=3D veb->idx) { - pf->veb[veb_idx]->uplink_seid =3D veb->seid; - ret =3D i40e_reconstitute_veb(pf->veb[veb_idx]); + i40e_pf_for_each_veb(pf, v, veb_it) { + if (veb_it->veb_idx =3D=3D veb->idx) { + veb_it->uplink_seid =3D veb->seid; + ret =3D i40e_reconstitute_veb(veb_it); if (ret) break; } @@ -10725,6 +10711,7 @@ static void i40e_clean_xps_state(struct i40e_vsi *v= si) static void i40e_prep_for_reset(struct i40e_pf *pf) { struct i40e_hw *hw =3D &pf->hw; + struct i40e_vsi *vsi; int ret =3D 0; u32 v; =20 @@ -10738,11 +10725,9 @@ static void i40e_prep_for_reset(struct i40e_pf *pf) /* quiesce the VSIs and their queues that are not already DOWN */ i40e_pf_quiesce_all_vsi(pf); =20 - for (v =3D 0; v < pf->num_alloc_vsi; v++) { - if (pf->vsi[v]) { - i40e_clean_xps_state(pf->vsi[v]); - pf->vsi[v]->seid =3D 0; - } + i40e_pf_for_each_vsi(pf, v, vsi) { + i40e_clean_xps_state(vsi); + vsi->seid =3D 0; } =20 i40e_shutdown_adminq(&pf->hw); @@ -10856,6 +10841,7 @@ static void i40e_rebuild(struct i40e_pf *pf, bool r= einit, bool lock_acquired) const bool is_recovery_mode_reported =3D i40e_check_recovery_mode(pf); struct i40e_vsi *vsi =3D pf->vsi[pf->lan_vsi]; struct i40e_hw *hw =3D &pf->hw; + struct i40e_veb *veb; int ret =3D EBADE; u32 val; int v; @@ -10998,14 +10984,10 @@ static void i40e_rebuild(struct i40e_pf *pf, bool= reinit, bool lock_acquired) if (vsi->uplink_seid !=3D pf->mac_seid) { dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); /* find the one VEB connected to the MAC, and find orphans */ - for (v =3D 0; v < I40E_MAX_VEB; v++) { - if (!pf->veb[v]) - continue; - - if (pf->veb[v]->uplink_seid =3D=3D pf->mac_seid || - pf->veb[v]->uplink_seid =3D=3D 0) { - ret =3D i40e_reconstitute_veb(pf->veb[v]); - + i40e_pf_for_each_veb(pf, v, veb) { + if (veb->uplink_seid =3D=3D pf->mac_seid || + veb->uplink_seid =3D=3D 0) { + ret =3D i40e_reconstitute_veb(veb); if (!ret) continue; =20 @@ -11015,13 +10997,13 @@ static void i40e_rebuild(struct i40e_pf *pf, bool= reinit, bool lock_acquired) * If orphan failed, we'll report the error * but try to keep going. */ - if (pf->veb[v]->uplink_seid =3D=3D pf->mac_seid) { + if (veb->uplink_seid =3D=3D pf->mac_seid) { dev_info(&pf->pdev->dev, "rebuild of switch failed: %d, will try to set up simple PF connect= ion\n", ret); vsi->uplink_seid =3D pf->mac_seid; break; - } else if (pf->veb[v]->uplink_seid =3D=3D 0) { + } else if (veb->uplink_seid =3D=3D 0) { dev_info(&pf->pdev->dev, "rebuild of orphan VEB failed: %d\n", ret); @@ -12112,6 +12094,7 @@ static int i40e_init_interrupt_scheme(struct i40e_p= f *pf) */ static int i40e_restore_interrupt_scheme(struct i40e_pf *pf) { + struct i40e_vsi *vsi; int err, i; =20 /* We cleared the MSI and MSI-X flags when disabling the old interrupt @@ -12128,13 +12111,12 @@ static int i40e_restore_interrupt_scheme(struct i= 40e_pf *pf) /* Now that we've re-acquired IRQs, we need to remap the vectors and * rings together again. */ - for (i =3D 0; i < pf->num_alloc_vsi; i++) { - if (pf->vsi[i]) { - err =3D i40e_vsi_alloc_q_vectors(pf->vsi[i]); - if (err) - goto err_unwind; - i40e_vsi_map_rings_to_vectors(pf->vsi[i]); - } + i40e_pf_for_each_vsi(pf, i, vsi) { + err =3D i40e_vsi_alloc_q_vectors(vsi); + if (err) + goto err_unwind; + + i40e_vsi_map_rings_to_vectors(vsi); } =20 err =3D i40e_setup_misc_vector(pf); @@ -13136,8 +13118,8 @@ static int i40e_ndo_bridge_setlink(struct net_devic= e *dev, struct i40e_netdev_priv *np =3D netdev_priv(dev); struct i40e_vsi *vsi =3D np->vsi; struct i40e_pf *pf =3D vsi->back; - struct i40e_veb *veb =3D NULL; struct nlattr *attr, *br_spec; + struct i40e_veb *veb; int i, rem; =20 /* Only for PF VSI for now */ @@ -13145,10 +13127,11 @@ static int i40e_ndo_bridge_setlink(struct net_dev= ice *dev, return -EOPNOTSUPP; =20 /* Find the HW bridge for PF VSI */ - for (i =3D 0; i < I40E_MAX_VEB && !veb; i++) { - if (pf->veb[i] && pf->veb[i]->seid =3D=3D vsi->uplink_seid) - veb =3D pf->veb[i]; - } + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D vsi->uplink_seid) + break; + if (i =3D=3D I40E_MAX_VEB) + veb =3D NULL; /* No VEB found */ =20 br_spec =3D nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); if (!br_spec) @@ -13221,12 +13204,10 @@ static int i40e_ndo_bridge_getlink(struct sk_buff= *skb, u32 pid, u32 seq, return -EOPNOTSUPP; =20 /* Find the HW bridge for the PF VSI */ - for (i =3D 0; i < I40E_MAX_VEB && !veb; i++) { - if (pf->veb[i] && pf->veb[i]->seid =3D=3D vsi->uplink_seid) - veb =3D pf->veb[i]; - } - - if (!veb) + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D vsi->uplink_seid) + break; + if (i =3D=3D I40E_MAX_VEB) return 0; =20 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, @@ -14157,9 +14138,9 @@ static int i40e_add_vsi(struct i40e_vsi *vsi) **/ int i40e_vsi_release(struct i40e_vsi *vsi) { + struct i40e_veb *veb, *veb_it; struct i40e_mac_filter *f; struct hlist_node *h; - struct i40e_veb *veb =3D NULL; struct i40e_pf *pf; u16 uplink_seid; int i, n, bkt; @@ -14229,20 +14210,18 @@ int i40e_vsi_release(struct i40e_vsi *vsi) * the orphan VEBs yet. We'll wait for an explicit remove request * from up the network stack. */ - for (n =3D 0, i =3D 0; i < pf->num_alloc_vsi; i++) { - if (pf->vsi[i] && - pf->vsi[i]->uplink_seid =3D=3D uplink_seid && - (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) =3D=3D 0) { + n =3D 0; + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->uplink_seid =3D=3D uplink_seid && + (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) =3D=3D 0) n++; /* count the VSIs */ - } - } - for (i =3D 0; i < I40E_MAX_VEB; i++) { - if (!pf->veb[i]) - continue; - if (pf->veb[i]->uplink_seid =3D=3D uplink_seid) + + veb =3D NULL; + i40e_pf_for_each_veb(pf, i, veb_it) { + if (veb_it->uplink_seid =3D=3D uplink_seid) n++; /* count the VEBs */ - if (pf->veb[i]->seid =3D=3D uplink_seid) - veb =3D pf->veb[i]; + if (veb_it->seid =3D=3D uplink_seid) + veb =3D veb_it; } if (n =3D=3D 0 && veb && veb->uplink_seid !=3D 0) i40e_veb_release(veb); @@ -14419,22 +14398,18 @@ struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *p= f, u8 type, * * Find which uplink_seid we were given and create a new VEB if needed */ - for (i =3D 0; i < I40E_MAX_VEB; i++) { - if (pf->veb[i] && pf->veb[i]->seid =3D=3D uplink_seid) { - veb =3D pf->veb[i]; + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D uplink_seid) break; - } - } + if (i =3D=3D I40E_MAX_VEB) + veb =3D NULL; =20 if (!veb && uplink_seid !=3D pf->mac_seid) { - - for (i =3D 0; i < pf->num_alloc_vsi; i++) { - if (pf->vsi[i] && pf->vsi[i]->seid =3D=3D uplink_seid) { - vsi =3D pf->vsi[i]; + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->seid =3D=3D uplink_seid) break; - } - } - if (!vsi) { + + if (i =3D=3D pf->num_alloc_vsi) { dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", uplink_seid); return NULL; @@ -14462,11 +14437,10 @@ struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *p= f, u8 type, } i40e_config_bridge_mode(veb); } - for (i =3D 0; i < I40E_MAX_VEB && !veb; i++) { - if (pf->veb[i] && pf->veb[i]->seid =3D=3D vsi->uplink_seid) - veb =3D pf->veb[i]; - } - if (!veb) { + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D vsi->uplink_seid) + break; + if (i =3D=3D I40E_MAX_VEB) { dev_info(&pf->pdev->dev, "couldn't add VEB\n"); return NULL; } @@ -14695,29 +14669,24 @@ static void i40e_switch_branch_release(struct i40= e_veb *branch) struct i40e_pf *pf =3D branch->pf; u16 branch_seid =3D branch->seid; u16 veb_idx =3D branch->idx; + struct i40e_vsi *vsi; + struct i40e_veb *veb; int i; =20 /* release any VEBs on this VEB - RECURSION */ - for (i =3D 0; i < I40E_MAX_VEB; i++) { - if (!pf->veb[i]) - continue; - if (pf->veb[i]->uplink_seid =3D=3D branch->seid) - i40e_switch_branch_release(pf->veb[i]); - } + i40e_pf_for_each_veb(pf, i, veb) + if (veb->uplink_seid =3D=3D branch->seid) + i40e_switch_branch_release(veb); =20 /* Release the VSIs on this VEB, but not the owner VSI. * * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing * the VEB itself, so don't use (*branch) after this loop. */ - for (i =3D 0; i < pf->num_alloc_vsi; i++) { - if (!pf->vsi[i]) - continue; - if (pf->vsi[i]->uplink_seid =3D=3D branch_seid && - (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) =3D=3D 0) { - i40e_vsi_release(pf->vsi[i]); - } - } + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->uplink_seid =3D=3D branch_seid && + (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) =3D=3D 0) + i40e_vsi_release(vsi); =20 /* There's one corner case where the VEB might not have been * removed, so double check it here and remove it if needed. @@ -14755,19 +14724,19 @@ static void i40e_veb_clear(struct i40e_veb *veb) **/ void i40e_veb_release(struct i40e_veb *veb) { - struct i40e_vsi *vsi =3D NULL; + struct i40e_vsi *vsi, *vsi_it; struct i40e_pf *pf; int i, n =3D 0; =20 pf =3D veb->pf; =20 /* find the remaining VSI and check for extras */ - for (i =3D 0; i < pf->num_alloc_vsi; i++) { - if (pf->vsi[i] && pf->vsi[i]->uplink_seid =3D=3D veb->seid) { + i40e_pf_for_each_vsi(pf, i, vsi_it) + if (vsi_it->uplink_seid =3D=3D veb->seid) { + vsi =3D vsi_it; n++; - vsi =3D pf->vsi[i]; } - } + if (n !=3D 1) { dev_info(&pf->pdev->dev, "can't remove VEB %d with %d VSIs left\n", @@ -14865,6 +14834,7 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,= u16 flags, u8 enabled_tc) { struct i40e_veb *veb, *uplink_veb =3D NULL; + struct i40e_vsi *vsi; int vsi_idx, veb_idx; int ret; =20 @@ -14878,9 +14848,10 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf= , u16 flags, } =20 /* make sure there is such a vsi and uplink */ - for (vsi_idx =3D 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) - if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid =3D=3D vsi_seid) + i40e_pf_for_each_vsi(pf, vsi_idx, vsi) + if (vsi->seid =3D=3D vsi_seid) break; + if (vsi_idx =3D=3D pf->num_alloc_vsi && vsi_seid !=3D 0) { dev_info(&pf->pdev->dev, "vsi seid %d not found\n", vsi_seid); @@ -14888,10 +14859,9 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf= , u16 flags, } =20 if (uplink_seid && uplink_seid !=3D pf->mac_seid) { - for (veb_idx =3D 0; veb_idx < I40E_MAX_VEB; veb_idx++) { - if (pf->veb[veb_idx] && - pf->veb[veb_idx]->seid =3D=3D uplink_seid) { - uplink_veb =3D pf->veb[veb_idx]; + i40e_pf_for_each_veb(pf, veb_idx, veb) { + if (veb->seid =3D=3D uplink_seid) { + uplink_veb =3D veb; break; } } @@ -14913,7 +14883,7 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,= u16 flags, veb->enabled_tc =3D (enabled_tc ? enabled_tc : 0x1); =20 /* create the VEB in the switch */ - ret =3D i40e_add_veb(veb, pf->vsi[vsi_idx]); + ret =3D i40e_add_veb(veb, vsi); if (ret) goto err_veb; if (vsi_idx =3D=3D pf->lan_vsi) @@ -14944,6 +14914,7 @@ static void i40e_setup_pf_switch_element(struct i40= e_pf *pf, u16 uplink_seid =3D le16_to_cpu(ele->uplink_seid); u8 element_type =3D ele->element_type; u16 seid =3D le16_to_cpu(ele->seid); + struct i40e_veb *veb; =20 if (printconfig) dev_info(&pf->pdev->dev, @@ -14962,12 +14933,12 @@ static void i40e_setup_pf_switch_element(struct i= 40e_pf *pf, int v; =20 /* find existing or else empty VEB */ - for (v =3D 0; v < I40E_MAX_VEB; v++) { - if (pf->veb[v] && (pf->veb[v]->seid =3D=3D seid)) { + i40e_pf_for_each_veb(pf, v, veb) + if (veb->seid =3D=3D seid) { pf->lan_veb =3D v; break; } - } + if (pf->lan_veb >=3D I40E_MAX_VEB) { v =3D i40e_veb_mem_alloc(pf); if (v < 0) @@ -16253,6 +16224,8 @@ static void i40e_remove(struct pci_dev *pdev) { struct i40e_pf *pf =3D pci_get_drvdata(pdev); struct i40e_hw *hw =3D &pf->hw; + struct i40e_vsi *vsi; + struct i40e_veb *veb; int ret_code; int i; =20 @@ -16310,24 +16283,19 @@ static void i40e_remove(struct pci_dev *pdev) /* If there is a switch structure or any orphans, remove them. * This will leave only the PF's VSI remaining. */ - for (i =3D 0; i < I40E_MAX_VEB; i++) { - if (!pf->veb[i]) - continue; - - if (pf->veb[i]->uplink_seid =3D=3D pf->mac_seid || - pf->veb[i]->uplink_seid =3D=3D 0) - i40e_switch_branch_release(pf->veb[i]); - } + i40e_pf_for_each_veb(pf, i, veb) + if (veb->uplink_seid =3D=3D pf->mac_seid || + veb->uplink_seid =3D=3D 0) + i40e_switch_branch_release(veb); =20 /* Now we can shutdown the PF's VSIs, just before we kill * adminq and hmc. */ - for (i =3D pf->num_alloc_vsi; i--;) - if (pf->vsi[i]) { - i40e_vsi_close(pf->vsi[i]); - i40e_vsi_release(pf->vsi[i]); - pf->vsi[i] =3D NULL; - } + i40e_pf_for_each_vsi(pf, i, vsi) { + i40e_vsi_close(vsi); + i40e_vsi_release(vsi); + pf->vsi[i] =3D NULL; + } =20 i40e_cloud_filter_exit(pf); =20 @@ -16364,18 +16332,17 @@ static void i40e_remove(struct pci_dev *pdev) /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ rtnl_lock(); i40e_clear_interrupt_scheme(pf); - for (i =3D 0; i < pf->num_alloc_vsi; i++) { - if (pf->vsi[i]) { - if (!test_bit(__I40E_RECOVERY_MODE, pf->state)) - i40e_vsi_clear_rings(pf->vsi[i]); - i40e_vsi_clear(pf->vsi[i]); - pf->vsi[i] =3D NULL; - } + i40e_pf_for_each_vsi(pf, i, vsi) { + if (!test_bit(__I40E_RECOVERY_MODE, pf->state)) + i40e_vsi_clear_rings(vsi); + + i40e_vsi_clear(vsi); + pf->vsi[i] =3D NULL; } rtnl_unlock(); =20 - for (i =3D 0; i < I40E_MAX_VEB; i++) { - kfree(pf->veb[i]); + i40e_pf_for_each_veb(pf, i, veb) { + kfree(veb); pf->veb[i] =3D NULL; } =20 --=20 2.41.0 From nobody Wed Dec 17 15:33:19 2025 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 87699C624B4 for ; Fri, 24 Nov 2023 15:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345518AbjKXPD6 (ORCPT ); Fri, 24 Nov 2023 10:03:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345384AbjKXPDx (ORCPT ); Fri, 24 Nov 2023 10:03:53 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5109199B for ; Fri, 24 Nov 2023 07:03:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700838238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qzT38EB5Vz7XmhOiADNWFVzR7hQPGPO4UzigtBxw1ew=; b=WQdPjpWX25SVoC0rjaw2qZBLhM/UgYNbnDn0ICnF9v0R1+8rjycfw/k7d82UXNeEylv3Pz hgdRJSUzZy1iX1bEGCoOZBUduOGKM2Ot+hvXp2tiYBYFDDwYhH/DnOhy8LTkJrbfBv4F4F jqGTJw+gImf3yAH+xy4TJWEdYPtpbws= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-Kbqmusr9PQ-benKtCl4rZA-1; Fri, 24 Nov 2023 10:03:53 -0500 X-MC-Unique: Kbqmusr9PQ-benKtCl4rZA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4FBB783B822; Fri, 24 Nov 2023 15:03:53 +0000 (UTC) Received: from p1.luc.cera.cz (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B0F140C6EB9; Fri, 24 Nov 2023 15:03:51 +0000 (UTC) From: Ivan Vecera To: intel-wired-lan@lists.osuosl.org Cc: Jesse Brandeburg , Tony Nguyen , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, Jacob Keller , Wojciech Drewek , Simon Horman , mschmidt@redhat.com, netdev@vger.kernel.org Subject: [PATCH v5 3/5] i40e: Add helpers to find VSI and VEB by SEID and use them Date: Fri, 24 Nov 2023 16:03:41 +0100 Message-ID: <20231124150343.81520-4-ivecera@redhat.com> In-Reply-To: <20231124150343.81520-1-ivecera@redhat.com> References: <20231124150343.81520-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add two helpers i40e_(veb|vsi)_get_by_seid() to find corresponding VEB or VSI by their SEID value and use these helpers to replace existing open-coded loops. Reviewed-by: Wojciech Drewek Signed-off-by: Ivan Vecera Reviewed-by: Simon Horman Tested-by: Pucha Himasekhar Reddy (A Co= ntingent worker at Intel) --- drivers/net/ethernet/intel/i40e/i40e.h | 36 +++++++++ .../net/ethernet/intel/i40e/i40e_debugfs.c | 38 ++------- drivers/net/ethernet/intel/i40e/i40e_main.c | 80 +++++++------------ 3 files changed, 68 insertions(+), 86 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/= intel/i40e/i40e.h index 08cea99150bc..000fd78cfa31 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -1360,4 +1360,40 @@ static inline struct i40e_pf *i40e_hw_to_pf(struct i= 40e_hw *hw) =20 struct device *i40e_hw_to_dev(struct i40e_hw *hw); =20 +/** + * i40e_pf_get_vsi_by_seid - find VSI by SEID + * @pf: pointer to a PF + * @seid: SEID of the VSI + **/ +static inline struct i40e_vsi * +i40e_pf_get_vsi_by_seid(struct i40e_pf *pf, u16 seid) +{ + struct i40e_vsi *vsi; + int i; + + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->seid =3D=3D seid) + return vsi; + + return NULL; +} + +/** + * i40e_pf_get_veb_by_seid - find VEB by SEID + * @pf: pointer to a PF + * @seid: SEID of the VSI + **/ +static inline struct i40e_veb * +i40e_pf_get_veb_by_seid(struct i40e_pf *pf, u16 seid) +{ + struct i40e_veb *veb; + int i; + + i40e_pf_for_each_veb(pf, i, veb) + if (veb->seid =3D=3D seid) + return veb; + + return NULL; +} + #endif /* _I40E_H_ */ diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/e= thernet/intel/i40e/i40e_debugfs.c index b236b0f93202..990a60889eef 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c +++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c @@ -24,37 +24,13 @@ enum ring_type { **/ static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid) { - struct i40e_vsi *vsi; - int i; - if (seid < 0) { dev_info(&pf->pdev->dev, "%d: bad seid\n", seid); =20 return NULL; } =20 - i40e_pf_for_each_vsi(pf, i, vsi) - if (vsi->seid =3D=3D seid) - return vsi; - - return NULL; -} - -/** - * i40e_dbg_find_veb - searches for the veb with the given seid - * @pf: the PF structure to search for the veb - * @seid: seid of the veb it is searching for - **/ -static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid) -{ - struct i40e_veb *veb; - int i; - - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid =3D=3D seid) - return veb; - - return NULL; + return i40e_pf_get_vsi_by_seid(pf, seid); } =20 /************************************************************** @@ -701,7 +677,7 @@ static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, = int seid) { struct i40e_veb *veb; =20 - veb =3D i40e_dbg_find_veb(pf, seid); + veb =3D i40e_pf_get_veb_by_seid(pf, seid); if (!veb) { dev_info(&pf->pdev->dev, "can't find veb %d\n", seid); return; @@ -853,7 +829,7 @@ static ssize_t i40e_dbg_command_write(struct file *filp, =20 } else if (strncmp(cmd_buf, "add relay", 9) =3D=3D 0) { struct i40e_veb *veb; - int uplink_seid, i; + int uplink_seid; =20 cnt =3D sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid); if (cnt !=3D 2) { @@ -875,12 +851,8 @@ static ssize_t i40e_dbg_command_write(struct file *fil= p, goto command_write_done; } =20 - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid =3D=3D uplink_seid) - break; - - if (i >=3D I40E_MAX_VEB && uplink_seid !=3D 0 && - uplink_seid !=3D pf->mac_seid) { + veb =3D i40e_pf_get_veb_by_seid(pf, uplink_seid); + if (!veb && uplink_seid !=3D 0 && uplink_seid !=3D pf->mac_seid) { dev_info(&pf->pdev->dev, "add relay: relay uplink %d not found\n", uplink_seid); diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethe= rnet/intel/i40e/i40e_main.c index 3a973a92779f..245de0d41f45 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -13120,18 +13120,14 @@ static int i40e_ndo_bridge_setlink(struct net_dev= ice *dev, struct i40e_pf *pf =3D vsi->back; struct nlattr *attr, *br_spec; struct i40e_veb *veb; - int i, rem; + int rem; =20 /* Only for PF VSI for now */ if (vsi->seid !=3D pf->vsi[pf->lan_vsi]->seid) return -EOPNOTSUPP; =20 /* Find the HW bridge for PF VSI */ - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid =3D=3D vsi->uplink_seid) - break; - if (i =3D=3D I40E_MAX_VEB) - veb =3D NULL; /* No VEB found */ + veb =3D i40e_pf_get_veb_by_seid(pf, vsi->uplink_seid); =20 br_spec =3D nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); if (!br_spec) @@ -13196,18 +13192,15 @@ static int i40e_ndo_bridge_getlink(struct sk_buff= *skb, u32 pid, u32 seq, struct i40e_netdev_priv *np =3D netdev_priv(dev); struct i40e_vsi *vsi =3D np->vsi; struct i40e_pf *pf =3D vsi->back; - struct i40e_veb *veb =3D NULL; - int i; + struct i40e_veb *veb; =20 /* Only for PF VSI for now */ if (vsi->seid !=3D pf->vsi[pf->lan_vsi]->seid) return -EOPNOTSUPP; =20 /* Find the HW bridge for the PF VSI */ - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid =3D=3D vsi->uplink_seid) - break; - if (i =3D=3D I40E_MAX_VEB) + veb =3D i40e_pf_get_veb_by_seid(pf, vsi->uplink_seid); + if (!veb) return 0; =20 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, @@ -14382,8 +14375,8 @@ struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf,= u8 type, struct i40e_vsi *vsi =3D NULL; struct i40e_veb *veb =3D NULL; u16 alloc_queue_pairs; - int ret, i; int v_idx; + int ret; =20 /* The requested uplink_seid must be either * - the PF's port seid @@ -14398,18 +14391,10 @@ struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *p= f, u8 type, * * Find which uplink_seid we were given and create a new VEB if needed */ - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid =3D=3D uplink_seid) - break; - if (i =3D=3D I40E_MAX_VEB) - veb =3D NULL; - + veb =3D i40e_pf_get_veb_by_seid(pf, uplink_seid); if (!veb && uplink_seid !=3D pf->mac_seid) { - i40e_pf_for_each_vsi(pf, i, vsi) - if (vsi->seid =3D=3D uplink_seid) - break; - - if (i =3D=3D pf->num_alloc_vsi) { + vsi =3D i40e_pf_get_vsi_by_seid(pf, uplink_seid); + if (!vsi) { dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", uplink_seid); return NULL; @@ -14437,10 +14422,8 @@ struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf= , u8 type, } i40e_config_bridge_mode(veb); } - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid =3D=3D vsi->uplink_seid) - break; - if (i =3D=3D I40E_MAX_VEB) { + veb =3D i40e_pf_get_veb_by_seid(pf, vsi->uplink_seid); + if (!veb) { dev_info(&pf->pdev->dev, "couldn't add VEB\n"); return NULL; } @@ -14834,8 +14817,8 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,= u16 flags, u8 enabled_tc) { struct i40e_veb *veb, *uplink_veb =3D NULL; - struct i40e_vsi *vsi; - int vsi_idx, veb_idx; + struct i40e_vsi *vsi =3D NULL; + int veb_idx; int ret; =20 /* if one seid is 0, the other must be 0 to create a floating relay */ @@ -14848,23 +14831,16 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *p= f, u16 flags, } =20 /* make sure there is such a vsi and uplink */ - i40e_pf_for_each_vsi(pf, vsi_idx, vsi) - if (vsi->seid =3D=3D vsi_seid) - break; - - if (vsi_idx =3D=3D pf->num_alloc_vsi && vsi_seid !=3D 0) { - dev_info(&pf->pdev->dev, "vsi seid %d not found\n", - vsi_seid); - return NULL; + if (vsi_seid) { + vsi =3D i40e_pf_get_vsi_by_seid(pf, vsi_seid); + if (!vsi) { + dev_err(&pf->pdev->dev, "vsi seid %d not found\n", + vsi_seid); + return NULL; + } } - if (uplink_seid && uplink_seid !=3D pf->mac_seid) { - i40e_pf_for_each_veb(pf, veb_idx, veb) { - if (veb->seid =3D=3D uplink_seid) { - uplink_veb =3D veb; - break; - } - } + uplink_veb =3D i40e_pf_get_veb_by_seid(pf, uplink_seid); if (!uplink_veb) { dev_info(&pf->pdev->dev, "uplink seid %d not found\n", uplink_seid); @@ -14886,7 +14862,8 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,= u16 flags, ret =3D i40e_add_veb(veb, vsi); if (ret) goto err_veb; - if (vsi_idx =3D=3D pf->lan_vsi) + + if (vsi && vsi->idx =3D=3D pf->lan_vsi) pf->lan_veb =3D veb->idx; =20 return veb; @@ -14933,13 +14910,10 @@ static void i40e_setup_pf_switch_element(struct i= 40e_pf *pf, int v; =20 /* find existing or else empty VEB */ - i40e_pf_for_each_veb(pf, v, veb) - if (veb->seid =3D=3D seid) { - pf->lan_veb =3D v; - break; - } - - if (pf->lan_veb >=3D I40E_MAX_VEB) { + veb =3D i40e_pf_get_veb_by_seid(pf, seid); + if (veb) { + pf->lan_veb =3D veb->idx; + } else { v =3D i40e_veb_mem_alloc(pf); if (v < 0) break; --=20 2.41.0 From nobody Wed Dec 17 15:33:19 2025 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 40381C61D97 for ; Fri, 24 Nov 2023 15:04:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345606AbjKXPEH (ORCPT ); Fri, 24 Nov 2023 10:04:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345549AbjKXPDz (ORCPT ); Fri, 24 Nov 2023 10:03:55 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BBD9D72 for ; Fri, 24 Nov 2023 07:03:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700838239; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2XWjwFS0rEr/Sg5D2cMhkrnL0ACQi6m2e7SIfzm94ng=; b=CFNL7tsD5QR/YjQc9d44fDJqlbIYubw3qXbTEjmwO2Jk6r3i+4LNUFROx6rwtB0GR3CLBk ie9XARe74efM9IWzsq0ghdD8Jk+SU2UQ4+Kkt4MG9D4PgUHx8Ic5Nm5i1M+Ex/nSFd1VFI GBst5bsmtuxLtl8EkdAtoYEeNbluZTU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-345-FGWGS-OIMmygamWi50yHcA-1; Fri, 24 Nov 2023 10:03:56 -0500 X-MC-Unique: FGWGS-OIMmygamWi50yHcA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61CA481B561; Fri, 24 Nov 2023 15:03:55 +0000 (UTC) Received: from p1.luc.cera.cz (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89E6140C6EB9; Fri, 24 Nov 2023 15:03:53 +0000 (UTC) From: Ivan Vecera To: intel-wired-lan@lists.osuosl.org Cc: Jesse Brandeburg , Tony Nguyen , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, Jacob Keller , Wojciech Drewek , Simon Horman , mschmidt@redhat.com, netdev@vger.kernel.org Subject: [PATCH v5 4/5] i40e: Fix broken support for floating VEBs Date: Fri, 24 Nov 2023 16:03:42 +0100 Message-ID: <20231124150343.81520-5-ivecera@redhat.com> In-Reply-To: <20231124150343.81520-1-ivecera@redhat.com> References: <20231124150343.81520-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Although the i40e supports so-called floating VEB (VEB without an uplink connection to external network), this support is broken. This functionality is currently unused (except debugfs) but it will be used by subsequent series for switchdev mode slow-path. Fix this by following: 1) Handle correctly floating VEB (VEB with uplink_seid =3D=3D 0) in i40e_reconstitute_veb() and look for owner VSI and create it only for non-floating VEBs and also set bridge mode only for such VEBs as the floating ones are using always VEB mode. 2) Handle correctly floating VEB in i40e_veb_release() and disallow its release when there are some VSIs. This is different from regular VEB that have owner VSI that is connected to VEB's uplink after VEB deletion by FW. 3) Fix i40e_add_veb() to handle 'vsi' that is NULL for floating VEBs. For floating VEB use 0 for downlink SEID and 'true' for 'default_port' parameters as per datasheet. 4) Fix 'add relay' command in i40e_dbg_command_write() to allow to create floating VEB by 'add relay 0 0' or 'add relay' Tested using debugfs: 1) Initial state [root@host net-next]# echo dump switch > $CMD [root@host net-next]# dmesg -c [ 173.701286] i40e 0000:02:00.0: header: 3 reported 3 total [ 173.706701] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 173.713241] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 173.719507] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 2) Add floating VEB [root@host net-next]# CMD=3D"/sys/kernel/debug/i40e/0000:02:00.0/command" [root@host net-next]# echo add relay > $CMD [root@host net-next]# dmesg -c [ 245.551720] i40e 0000:02:00.0: added relay 162 [root@host net-next]# echo dump switch > $CMD [root@host net-next]# dmesg -c [ 276.984371] i40e 0000:02:00.0: header: 4 reported 4 total [ 276.989779] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 276.996302] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 277.002569] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 [ 277.009091] i40e 0000:02:00.0: type=3D17 seid=3D162 uplink=3D0 downlink= =3D0 3) Add VMDQ2 VSI to this new VEB [root@host net-next]# echo add vsi 162 > $CMD [root@host net-next]# dmesg -c [ 332.314030] i40e 0000:02:00.0: added VSI 394 to relay 162 [ 332.337486] enp2s0f0np0v0: NIC Link is Up, 40 Gbps Full Duplex, Flow Con= trol: None [root@host net-next]# echo dump switch > $CMD [root@host net-next]# dmesg -c [ 387.284490] i40e 0000:02:00.0: header: 5 reported 5 total [ 387.289904] i40e 0000:02:00.0: type=3D19 seid=3D394 uplink=3D162 downlin= k=3D16 [ 387.296446] i40e 0000:02:00.0: type=3D17 seid=3D162 uplink=3D0 downlink= =3D0 [ 387.302708] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 387.309234] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 387.315500] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 4) Try to delete the VEB [root@host net-next]# echo del relay 162 > $CMD [root@host net-next]# dmesg -c [ 428.749297] i40e 0000:02:00.0: deleting relay 162 [ 428.754011] i40e 0000:02:00.0: can't remove VEB 162 with 1 VSIs left 5) Do PF reset and check switch status after rebuild [root@host net-next]# echo pfr > $CMD [root@host net-next]# echo dump switch > $CMD [root@host net-next]# dmesg -c [ 738.056172] i40e 0000:02:00.0: header: 5 reported 5 total [ 738.061577] i40e 0000:02:00.0: type=3D19 seid=3D394 uplink=3D162 downlin= k=3D16 [ 738.068104] i40e 0000:02:00.0: type=3D17 seid=3D162 uplink=3D0 downlink= =3D0 [ 738.074367] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 738.080892] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 738.087160] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 6) Delete VSI and delete VEB [root@host net-next]# echo del vsi 394 > $CMD [root@host net-next]# echo del relay 162 > $CMD [root@host net-next]# echo dump switch > $CMD [root@host net-next]# dmesg -c [ 1233.081126] i40e 0000:02:00.0: deleting VSI 394 [ 1239.345139] i40e 0000:02:00.0: deleting relay 162 [ 1244.886920] i40e 0000:02:00.0: header: 3 reported 3 total [ 1244.892328] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 1244.898853] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 1244.905119] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 Reviewed-by: Wojciech Drewek Signed-off-by: Ivan Vecera Reviewed-by: Simon Horman Tested-by: Pucha Himasekhar Reddy (A Co= ntingent worker at Intel) --- .../net/ethernet/intel/i40e/i40e_debugfs.c | 29 ++++--- drivers/net/ethernet/intel/i40e/i40e_main.c | 87 ++++++++++--------- 2 files changed, 67 insertions(+), 49 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/e= thernet/intel/i40e/i40e_debugfs.c index 990a60889eef..921a97d5479e 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c +++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c @@ -829,10 +829,14 @@ static ssize_t i40e_dbg_command_write(struct file *fi= lp, =20 } else if (strncmp(cmd_buf, "add relay", 9) =3D=3D 0) { struct i40e_veb *veb; + u8 enabled_tc =3D 0x1; int uplink_seid; =20 cnt =3D sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid); - if (cnt !=3D 2) { + if (cnt =3D=3D 0) { + uplink_seid =3D 0; + vsi_seid =3D 0; + } else if (cnt !=3D 2) { dev_info(&pf->pdev->dev, "add relay: bad command string, cnt=3D%d\n", cnt); @@ -844,23 +848,28 @@ static ssize_t i40e_dbg_command_write(struct file *fi= lp, goto command_write_done; } =20 - vsi =3D i40e_dbg_find_vsi(pf, vsi_seid); - if (!vsi) { - dev_info(&pf->pdev->dev, - "add relay: VSI %d not found\n", vsi_seid); - goto command_write_done; - } - veb =3D i40e_pf_get_veb_by_seid(pf, uplink_seid); if (!veb && uplink_seid !=3D 0 && uplink_seid !=3D pf->mac_seid) { dev_info(&pf->pdev->dev, "add relay: relay uplink %d not found\n", uplink_seid); goto command_write_done; + } else if (uplink_seid) { + vsi =3D i40e_pf_get_vsi_by_seid(pf, vsi_seid); + if (!vsi) { + dev_info(&pf->pdev->dev, + "add relay: VSI %d not found\n", + vsi_seid); + goto command_write_done; + } + enabled_tc =3D vsi->tc_config.enabled_tc; + } else if (vsi_seid) { + dev_info(&pf->pdev->dev, + "add relay: VSI must be 0 for floating relay\n"); + goto command_write_done; } =20 - veb =3D i40e_veb_setup(pf, 0, uplink_seid, vsi_seid, - vsi->tc_config.enabled_tc); + veb =3D i40e_veb_setup(pf, 0, uplink_seid, vsi_seid, enabled_tc); if (veb) dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid); else diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethe= rnet/intel/i40e/i40e_main.c index 245de0d41f45..05b79f590100 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -10379,41 +10379,48 @@ static int i40e_reconstitute_veb(struct i40e_veb = *veb) struct i40e_vsi *vsi; int v, ret; =20 - /* build VSI that owns this VEB, temporarily attached to base VEB */ - i40e_pf_for_each_vsi(pf, v, vsi) - if (vsi->veb_idx =3D=3D veb->idx && - vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { - ctl_vsi =3D vsi; - break; + if (veb->uplink_seid) { + /* Look for VSI that owns this VEB, temporarily attached to base VEB */ + i40e_pf_for_each_vsi(pf, v, vsi) + if (vsi->veb_idx =3D=3D veb->idx && + vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { + ctl_vsi =3D vsi; + break; + } + + if (!ctl_vsi) { + dev_info(&pf->pdev->dev, + "missing owner VSI for veb_idx %d\n", + veb->idx); + ret =3D -ENOENT; + goto end_reconstitute; } + if (ctl_vsi !=3D pf->vsi[pf->lan_vsi]) + ctl_vsi->uplink_seid =3D + pf->vsi[pf->lan_vsi]->uplink_seid; =20 - if (!ctl_vsi) { - dev_info(&pf->pdev->dev, - "missing owner VSI for veb_idx %d\n", veb->idx); - ret =3D -ENOENT; - goto end_reconstitute; - } - if (ctl_vsi !=3D pf->vsi[pf->lan_vsi]) - ctl_vsi->uplink_seid =3D pf->vsi[pf->lan_vsi]->uplink_seid; - ret =3D i40e_add_vsi(ctl_vsi); - if (ret) { - dev_info(&pf->pdev->dev, - "rebuild of veb_idx %d owner VSI failed: %d\n", - veb->idx, ret); - goto end_reconstitute; + ret =3D i40e_add_vsi(ctl_vsi); + if (ret) { + dev_info(&pf->pdev->dev, + "rebuild of veb_idx %d owner VSI failed: %d\n", + veb->idx, ret); + goto end_reconstitute; + } + i40e_vsi_reset_stats(ctl_vsi); } - i40e_vsi_reset_stats(ctl_vsi); =20 /* create the VEB in the switch and move the VSI onto the VEB */ ret =3D i40e_add_veb(veb, ctl_vsi); if (ret) goto end_reconstitute; =20 - if (test_bit(I40E_FLAG_VEB_MODE_ENA, pf->flags)) - veb->bridge_mode =3D BRIDGE_MODE_VEB; - else - veb->bridge_mode =3D BRIDGE_MODE_VEPA; - i40e_config_bridge_mode(veb); + if (veb->uplink_seid) { + if (test_bit(I40E_FLAG_VEB_MODE_ENA, pf->flags)) + veb->bridge_mode =3D BRIDGE_MODE_VEB; + else + veb->bridge_mode =3D BRIDGE_MODE_VEPA; + i40e_config_bridge_mode(veb); + } =20 /* create the remaining VSIs attached to this VEB */ i40e_pf_for_each_vsi(pf, v, vsi) { @@ -14716,29 +14723,29 @@ void i40e_veb_release(struct i40e_veb *veb) /* find the remaining VSI and check for extras */ i40e_pf_for_each_vsi(pf, i, vsi_it) if (vsi_it->uplink_seid =3D=3D veb->seid) { - vsi =3D vsi_it; + if (vsi_it->flags & I40E_VSI_FLAG_VEB_OWNER) + vsi =3D vsi_it; n++; } =20 - if (n !=3D 1) { + /* Floating VEB has to be empty and regular one must have + * single owner VSI. + */ + if ((veb->uplink_seid && n !=3D 1) || (!veb->uplink_seid && n !=3D 0)) { dev_info(&pf->pdev->dev, "can't remove VEB %d with %d VSIs left\n", veb->seid, n); return; } =20 - /* move the remaining VSI to uplink veb */ - vsi->flags &=3D ~I40E_VSI_FLAG_VEB_OWNER; + /* For regular VEB move the owner VSI to uplink VEB */ if (veb->uplink_seid) { + vsi->flags &=3D ~I40E_VSI_FLAG_VEB_OWNER; vsi->uplink_seid =3D veb->uplink_seid; if (veb->uplink_seid =3D=3D pf->mac_seid) vsi->veb_idx =3D I40E_NO_VEB; else vsi->veb_idx =3D veb->veb_idx; - } else { - /* floating VEB */ - vsi->uplink_seid =3D pf->vsi[pf->lan_vsi]->uplink_seid; - vsi->veb_idx =3D pf->vsi[pf->lan_vsi]->veb_idx; } =20 i40e_aq_delete_element(&pf->hw, veb->seid, NULL); @@ -14756,8 +14763,8 @@ static int i40e_add_veb(struct i40e_veb *veb, struc= t i40e_vsi *vsi) bool enable_stats =3D !!test_bit(I40E_FLAG_VEB_STATS_ENA, pf->flags); int ret; =20 - ret =3D i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, - veb->enabled_tc, false, + ret =3D i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi ? vsi->seid : 0, + veb->enabled_tc, vsi ? false : true, &veb->seid, enable_stats, NULL); =20 /* get a VEB from the hardware */ @@ -14789,9 +14796,11 @@ static int i40e_add_veb(struct i40e_veb *veb, stru= ct i40e_vsi *vsi) return -ENOENT; } =20 - vsi->uplink_seid =3D veb->seid; - vsi->veb_idx =3D veb->idx; - vsi->flags |=3D I40E_VSI_FLAG_VEB_OWNER; + if (vsi) { + vsi->uplink_seid =3D veb->seid; + vsi->veb_idx =3D veb->idx; + vsi->flags |=3D I40E_VSI_FLAG_VEB_OWNER; + } =20 return 0; } --=20 2.41.0 From nobody Wed Dec 17 15:33:19 2025 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 0EE8CC624B4 for ; Fri, 24 Nov 2023 15:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345552AbjKXPEL (ORCPT ); Fri, 24 Nov 2023 10:04:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345641AbjKXPD6 (ORCPT ); Fri, 24 Nov 2023 10:03:58 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B07210CA for ; Fri, 24 Nov 2023 07:04:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700838242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S3wtWtl+W5XhZPW5KGNTwO9GmykrpeEzuFfe5NadxqY=; b=C5OTg3Ra+khErJDnmIeraQdeOqyTpaxcHz2vENXX9UNQ6FMaNqyIKkl5zuX8gh6rYBY5LA bR1lrk0hvSskWLQj1uU8917JyouFYYcAEAqILCmzNMiEoWsQ/xCCowOJkjZVAfVRb2K1Vl vE1FDSn8YGWPt1VtXM7oJ79jMo6C0So= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-Bmddf3LuO8WwgFnMhplItg-1; Fri, 24 Nov 2023 10:03:58 -0500 X-MC-Unique: Bmddf3LuO8WwgFnMhplItg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 721F681B560; Fri, 24 Nov 2023 15:03:57 +0000 (UTC) Received: from p1.luc.cera.cz (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9873940C6EB9; Fri, 24 Nov 2023 15:03:55 +0000 (UTC) From: Ivan Vecera To: intel-wired-lan@lists.osuosl.org Cc: Jesse Brandeburg , Tony Nguyen , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, Jacob Keller , Wojciech Drewek , Simon Horman , mschmidt@redhat.com, netdev@vger.kernel.org Subject: [PATCH v5 5/5] i40e: Remove VEB recursion Date: Fri, 24 Nov 2023 16:03:43 +0100 Message-ID: <20231124150343.81520-6-ivecera@redhat.com> In-Reply-To: <20231124150343.81520-1-ivecera@redhat.com> References: <20231124150343.81520-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The VEB (virtual embedded switch) as a switch element can be connected according datasheet though its uplink to: - Physical port - Port Virtualizer (not used directly by i40e driver but can be present in MFP mode where the physical port is shared between PFs) - No uplink (aka floating VEB) But VEB uplink cannot be connected to another VEB and any attempt to do so results in: "i40e 0000:02:00.0: couldn't add VEB, err -EIO aq_err I40E_AQ_RC_ENOENT" that indicates "the uplink SEID does not point to valid element". Remove this logic from the driver code this way: 1) For debugfs only allow to build floating VEB (uplink_seid =3D=3D 0) or main VEB (uplink_seid =3D=3D mac_seid) 2) Do not recurse in i40e_veb_link_event() as no VEB cannot have sub-VEBs 3) Ditto for i40e_veb_rebuild() + simplify the function as we know that the VEB for rebuild can be only the main LAN VEB or some of the floating VEBs 4) In i40e_rebuild() there is no need to check veb->uplink_seid as the possible ones are 0 and MAC SEID 5) In i40e_vsi_release() do not take into account VEBs whose uplink is another VEB as this is not possible 6) Remove veb_idx field from i40e_veb as a VEB cannot have sub-VEBs Tested using i40e debugfs interface: 1) Initial state [root@cnb-03 net-next]# CMD=3D"/sys/kernel/debug/i40e/0000:02:00.0/command" [root@cnb-03 net-next]# echo dump switch > $CMD [root@cnb-03 net-next]# dmesg -c [ 98.440641] i40e 0000:02:00.0: header: 3 reported 3 total [ 98.446053] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 98.452593] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 98.458856] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 2) Add floating VEB [root@cnb-03 net-next]# echo add relay > $CMD [root@cnb-03 net-next]# dmesg -c [ 122.745630] i40e 0000:02:00.0: added relay 162 [root@cnb-03 net-next]# echo dump switch > $CMD [root@cnb-03 net-next]# dmesg -c [ 136.650049] i40e 0000:02:00.0: header: 4 reported 4 total [ 136.655466] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 136.661994] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 136.668264] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 [ 136.674787] i40e 0000:02:00.0: type=3D17 seid=3D162 uplink=3D0 downlink= =3D0 3) Add VMDQ2 VSI to this new VEB [root@cnb-03 net-next]# dmesg -c [ 168.351763] i40e 0000:02:00.0: added VSI 394 to relay 162 [ 168.374652] enp2s0f0np0v0: NIC Link is Up, 40 Gbps Full Duplex, Flow Con= trol: None [root@cnb-03 net-next]# echo dump switch > $CMD [root@cnb-03 net-next]# dmesg -c [ 195.683204] i40e 0000:02:00.0: header: 5 reported 5 total [ 195.688611] i40e 0000:02:00.0: type=3D19 seid=3D394 uplink=3D162 downlin= k=3D16 [ 195.695143] i40e 0000:02:00.0: type=3D17 seid=3D162 uplink=3D0 downlink= =3D0 [ 195.701410] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 195.707935] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 195.714201] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 4) Try to delete the VEB [root@cnb-03 net-next]# echo del relay 162 > $CMD [root@cnb-03 net-next]# dmesg -c [ 239.260901] i40e 0000:02:00.0: deleting relay 162 [ 239.265621] i40e 0000:02:00.0: can't remove VEB 162 with 1 VSIs left 5) Do PF reset and check switch status after rebuild [root@cnb-03 net-next]# echo pfr > $CMD [root@cnb-03 net-next]# echo dump switch > $CMD [root@cnb-03 net-next]# dmesg -c ... [ 272.333655] i40e 0000:02:00.0: header: 5 reported 5 total [ 272.339066] i40e 0000:02:00.0: type=3D19 seid=3D394 uplink=3D162 downlin= k=3D16 [ 272.345599] i40e 0000:02:00.0: type=3D17 seid=3D162 uplink=3D0 downlink= =3D0 [ 272.351862] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 272.358387] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 272.364654] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 6) Delete VSI and delete VEB [ 297.199116] i40e 0000:02:00.0: deleting VSI 394 [ 299.807580] i40e 0000:02:00.0: deleting relay 162 [ 309.767905] i40e 0000:02:00.0: header: 3 reported 3 total [ 309.773318] i40e 0000:02:00.0: type=3D19 seid=3D392 uplink=3D160 downlin= k=3D16 [ 309.779845] i40e 0000:02:00.0: type=3D17 seid=3D160 uplink=3D2 downlink= =3D0 [ 309.786111] i40e 0000:02:00.0: type=3D19 seid=3D390 uplink=3D160 downlin= k=3D16 Reviewed-by: Wojciech Drewek Signed-off-by: Ivan Vecera Reviewed-by: Simon Horman Tested-by: Pucha Himasekhar Reddy (A Co= ntingent worker at Intel) --- drivers/net/ethernet/intel/i40e/i40e.h | 1 - .../net/ethernet/intel/i40e/i40e_debugfs.c | 8 +- drivers/net/ethernet/intel/i40e/i40e_main.c | 176 ++++++++---------- 3 files changed, 76 insertions(+), 109 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/= intel/i40e/i40e.h index 000fd78cfa31..6f5ff6285c7f 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -783,7 +783,6 @@ struct i40e_new_mac_filter { struct i40e_veb { struct i40e_pf *pf; u16 idx; - u16 veb_idx; /* index of VEB parent */ u16 seid; u16 uplink_seid; u16 stats_idx; /* index of VEB parent */ diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/e= thernet/intel/i40e/i40e_debugfs.c index 921a97d5479e..f9ba45f596c9 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c +++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c @@ -683,9 +683,8 @@ static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, = int seid) return; } dev_info(&pf->pdev->dev, - "veb idx=3D%d,%d stats_ic=3D%d seid=3D%d uplink=3D%d mode=3D%s\n", - veb->idx, veb->veb_idx, veb->stats_idx, veb->seid, - veb->uplink_seid, + "veb idx=3D%d stats_ic=3D%d seid=3D%d uplink=3D%d mode=3D%s\n", + veb->idx, veb->stats_idx, veb->seid, veb->uplink_seid, veb->bridge_mode =3D=3D BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); i40e_dbg_dump_eth_stats(pf, &veb->stats); } @@ -848,8 +847,7 @@ static ssize_t i40e_dbg_command_write(struct file *filp, goto command_write_done; } =20 - veb =3D i40e_pf_get_veb_by_seid(pf, uplink_seid); - if (!veb && uplink_seid !=3D 0 && uplink_seid !=3D pf->mac_seid) { + if (uplink_seid !=3D 0 && uplink_seid !=3D pf->mac_seid) { dev_info(&pf->pdev->dev, "add relay: relay uplink %d not found\n", uplink_seid); diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethe= rnet/intel/i40e/i40e_main.c index 05b79f590100..7ee5cf5e893d 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -9871,7 +9871,6 @@ static void i40e_vsi_link_event(struct i40e_vsi *vsi,= bool link_up) **/ static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) { - struct i40e_veb *veb_it; struct i40e_vsi *vsi; struct i40e_pf *pf; int i; @@ -9880,12 +9879,7 @@ static void i40e_veb_link_event(struct i40e_veb *veb= , bool link_up) return; pf =3D veb->pf; =20 - /* depth first... */ - i40e_pf_for_each_veb(pf, i, veb_it) - if (veb_it->uplink_seid =3D=3D veb->seid) - i40e_veb_link_event(veb_it, link_up); - - /* ... now the local VSIs */ + /* Send link event to contained VSIs */ i40e_pf_for_each_vsi(pf, i, vsi) if (vsi->uplink_seid =3D=3D veb->seid) i40e_vsi_link_event(vsi, link_up); @@ -10363,56 +10357,57 @@ static void i40e_config_bridge_mode(struct i40e_v= eb *veb) } =20 /** - * i40e_reconstitute_veb - rebuild the VEB and anything connected to it + * i40e_reconstitute_veb - rebuild the VEB and VSIs connected to it * @veb: pointer to the VEB instance * - * This is a recursive function that first builds the attached VSIs then - * recurses in to build the next layer of VEB. We track the connections - * through our own index numbers because the seid's from the HW could - * change across the reset. + * This is a function that builds the attached VSIs. We track the connecti= ons + * through our own index numbers because the seid's from the HW could chan= ge + * across the reset. **/ static int i40e_reconstitute_veb(struct i40e_veb *veb) { struct i40e_vsi *ctl_vsi =3D NULL; struct i40e_pf *pf =3D veb->pf; - struct i40e_veb *veb_it; struct i40e_vsi *vsi; int v, ret; =20 - if (veb->uplink_seid) { - /* Look for VSI that owns this VEB, temporarily attached to base VEB */ - i40e_pf_for_each_vsi(pf, v, vsi) - if (vsi->veb_idx =3D=3D veb->idx && - vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { - ctl_vsi =3D vsi; - break; - } + /* As we do not maintain PV (port virtualizer) switch element then + * there can be only one non-floating VEB that have uplink to MAC SEID + * and its control VSI is the main one. + */ + if (WARN_ON(veb->uplink_seid && veb->uplink_seid !=3D pf->mac_seid)) { + dev_err(&pf->pdev->dev, + "Invalid uplink SEID for VEB %d\n", veb->idx); + return -ENOENT; + } =20 - if (!ctl_vsi) { - dev_info(&pf->pdev->dev, - "missing owner VSI for veb_idx %d\n", - veb->idx); - ret =3D -ENOENT; - goto end_reconstitute; + if (veb->uplink_seid =3D=3D pf->mac_seid) { + /* Check that the LAN VSI has VEB owning flag set */ + ctl_vsi =3D pf->vsi[pf->lan_vsi]; + + if (WARN_ON(ctl_vsi->veb_idx !=3D veb->idx || + !(ctl_vsi->flags & I40E_VSI_FLAG_VEB_OWNER))) { + dev_err(&pf->pdev->dev, + "Invalid control VSI for VEB %d\n", veb->idx); + return -ENOENT; } - if (ctl_vsi !=3D pf->vsi[pf->lan_vsi]) - ctl_vsi->uplink_seid =3D - pf->vsi[pf->lan_vsi]->uplink_seid; =20 + /* Add the control VSI to switch */ ret =3D i40e_add_vsi(ctl_vsi); if (ret) { - dev_info(&pf->pdev->dev, - "rebuild of veb_idx %d owner VSI failed: %d\n", - veb->idx, ret); - goto end_reconstitute; + dev_err(&pf->pdev->dev, + "Rebuild of owner VSI for VEB %d failed: %d\n", + veb->idx, ret); + return ret; } + i40e_vsi_reset_stats(ctl_vsi); } =20 /* create the VEB in the switch and move the VSI onto the VEB */ ret =3D i40e_add_veb(veb, ctl_vsi); if (ret) - goto end_reconstitute; + return ret; =20 if (veb->uplink_seid) { if (test_bit(I40E_FLAG_VEB_MODE_ENA, pf->flags)) @@ -10434,23 +10429,12 @@ static int i40e_reconstitute_veb(struct i40e_veb = *veb) dev_info(&pf->pdev->dev, "rebuild of vsi_idx %d failed: %d\n", v, ret); - goto end_reconstitute; + return ret; } i40e_vsi_reset_stats(vsi); } } =20 - /* create any VEBs attached to this VEB - RECURSION */ - i40e_pf_for_each_veb(pf, v, veb_it) { - if (veb_it->veb_idx =3D=3D veb->idx) { - veb_it->uplink_seid =3D veb->seid; - ret =3D i40e_reconstitute_veb(veb_it); - if (ret) - break; - } - } - -end_reconstitute: return ret; } =20 @@ -10990,31 +10974,29 @@ static void i40e_rebuild(struct i40e_pf *pf, bool= reinit, bool lock_acquired) */ if (vsi->uplink_seid !=3D pf->mac_seid) { dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); - /* find the one VEB connected to the MAC, and find orphans */ + + /* Rebuild VEBs */ i40e_pf_for_each_veb(pf, v, veb) { - if (veb->uplink_seid =3D=3D pf->mac_seid || - veb->uplink_seid =3D=3D 0) { - ret =3D i40e_reconstitute_veb(veb); - if (!ret) - continue; - - /* If Main VEB failed, we're in deep doodoo, - * so give up rebuilding the switch and set up - * for minimal rebuild of PF VSI. - * If orphan failed, we'll report the error - * but try to keep going. - */ - if (veb->uplink_seid =3D=3D pf->mac_seid) { - dev_info(&pf->pdev->dev, - "rebuild of switch failed: %d, will try to set up simple PF connect= ion\n", - ret); - vsi->uplink_seid =3D pf->mac_seid; - break; - } else if (veb->uplink_seid =3D=3D 0) { - dev_info(&pf->pdev->dev, - "rebuild of orphan VEB failed: %d\n", - ret); - } + ret =3D i40e_reconstitute_veb(veb); + if (!ret) + continue; + + /* If Main VEB failed, we're in deep doodoo, + * so give up rebuilding the switch and set up + * for minimal rebuild of PF VSI. + * If orphan failed, we'll report the error + * but try to keep going. + */ + if (veb->uplink_seid =3D=3D pf->mac_seid) { + dev_info(&pf->pdev->dev, + "rebuild of switch failed: %d, will try to set up simple PF connecti= on\n", + ret); + vsi->uplink_seid =3D pf->mac_seid; + break; + } else if (veb->uplink_seid =3D=3D 0) { + dev_info(&pf->pdev->dev, + "rebuild of orphan VEB failed: %d\n", + ret); } } } @@ -14138,9 +14120,9 @@ static int i40e_add_vsi(struct i40e_vsi *vsi) **/ int i40e_vsi_release(struct i40e_vsi *vsi) { - struct i40e_veb *veb, *veb_it; struct i40e_mac_filter *f; struct hlist_node *h; + struct i40e_veb *veb; struct i40e_pf *pf; u16 uplink_seid; int i, n, bkt; @@ -14204,27 +14186,28 @@ int i40e_vsi_release(struct i40e_vsi *vsi) =20 /* If this was the last thing on the VEB, except for the * controlling VSI, remove the VEB, which puts the controlling - * VSI onto the next level down in the switch. + * VSI onto the uplink port. * * Well, okay, there's one more exception here: don't remove - * the orphan VEBs yet. We'll wait for an explicit remove request + * the floating VEBs yet. We'll wait for an explicit remove request * from up the network stack. */ - n =3D 0; - i40e_pf_for_each_vsi(pf, i, vsi) - if (vsi->uplink_seid =3D=3D uplink_seid && - (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) =3D=3D 0) - n++; /* count the VSIs */ + veb =3D i40e_pf_get_veb_by_seid(pf, uplink_seid); + if (veb && veb->uplink_seid) { + n =3D 0; + + /* Count non-controlling VSIs present on the VEB */ + i40e_pf_for_each_vsi(pf, i, vsi) + if (vsi->uplink_seid =3D=3D uplink_seid && + (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) =3D=3D 0) + n++; =20 - veb =3D NULL; - i40e_pf_for_each_veb(pf, i, veb_it) { - if (veb_it->uplink_seid =3D=3D uplink_seid) - n++; /* count the VEBs */ - if (veb_it->seid =3D=3D uplink_seid) - veb =3D veb_it; + /* If there is no VSI except the control one then release + * the VEB and put the control VSI onto VEB uplink. + */ + if (!n) + i40e_veb_release(veb); } - if (n =3D=3D 0 && veb && veb->uplink_seid !=3D 0) - i40e_veb_release(veb); =20 return 0; } @@ -14738,14 +14721,11 @@ void i40e_veb_release(struct i40e_veb *veb) return; } =20 - /* For regular VEB move the owner VSI to uplink VEB */ + /* For regular VEB move the owner VSI to uplink port */ if (veb->uplink_seid) { vsi->flags &=3D ~I40E_VSI_FLAG_VEB_OWNER; vsi->uplink_seid =3D veb->uplink_seid; - if (veb->uplink_seid =3D=3D pf->mac_seid) - vsi->veb_idx =3D I40E_NO_VEB; - else - vsi->veb_idx =3D veb->veb_idx; + vsi->veb_idx =3D I40E_NO_VEB; } =20 i40e_aq_delete_element(&pf->hw, veb->seid, NULL); @@ -14825,8 +14805,8 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,= u16 flags, u16 uplink_seid, u16 vsi_seid, u8 enabled_tc) { - struct i40e_veb *veb, *uplink_veb =3D NULL; struct i40e_vsi *vsi =3D NULL; + struct i40e_veb *veb; int veb_idx; int ret; =20 @@ -14848,14 +14828,6 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf= , u16 flags, return NULL; } } - if (uplink_seid && uplink_seid !=3D pf->mac_seid) { - uplink_veb =3D i40e_pf_get_veb_by_seid(pf, uplink_seid); - if (!uplink_veb) { - dev_info(&pf->pdev->dev, - "uplink seid %d not found\n", uplink_seid); - return NULL; - } - } =20 /* get veb sw struct */ veb_idx =3D i40e_veb_mem_alloc(pf); @@ -14864,7 +14836,6 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,= u16 flags, veb =3D pf->veb[veb_idx]; veb->flags =3D flags; veb->uplink_seid =3D uplink_seid; - veb->veb_idx =3D (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); veb->enabled_tc =3D (enabled_tc ? enabled_tc : 0x1); =20 /* create the VEB in the switch */ @@ -14935,7 +14906,6 @@ static void i40e_setup_pf_switch_element(struct i40= e_pf *pf, pf->veb[pf->lan_veb]->seid =3D seid; pf->veb[pf->lan_veb]->uplink_seid =3D pf->mac_seid; pf->veb[pf->lan_veb]->pf =3D pf; - pf->veb[pf->lan_veb]->veb_idx =3D I40E_NO_VEB; break; case I40E_SWITCH_ELEMENT_TYPE_VSI: if (num_reported !=3D 1) --=20 2.41.0