Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3351137rdb; Thu, 16 Nov 2023 07:21:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3z5zH6o0dhF1sSOmqZ9eSLNuyuI9YXPCj62EEdghti/i0Omue1+lmqO1vOGQ7/SUlWzYX X-Received: by 2002:a17:902:a985:b0:1cc:2094:52af with SMTP id bh5-20020a170902a98500b001cc209452afmr7435335plb.52.1700148104222; Thu, 16 Nov 2023 07:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700148104; cv=none; d=google.com; s=arc-20160816; b=pGSi1i9fj/V5Q+Ohv7KJynoX26N8Vlf0OVtt3afmGKaEk8bbk4A+/odHj1kSkMXI1Z tHijIha2OFqL2naFV+L7ksxYH+70krpo9DfkUpuAf9DX1gcqEFLTpkuCVjtmHjyOcmgr k9B0rODPApEfaP3YISJ1VQOe+QjaGRJkbih4ZuyPJkIkR1d0fxPnUrcLJaidBqB6AWcL +lbrRQSnZzimA2gg6KZ/RoUEwXzCiXa4wADPvj4py1yHe1Chg1uxQQs3nLKX0+o2c8Uf ChPhBZOF19aQSn99FlxzMsiRIlziqEFPofCmW4s1LT0moKYxQOVN7+E6SjvBUYaGVi9+ BoSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XW/iVfQyiraKBX/qX4dMONyaPD2cblNliSYriy+fjSk=; fh=kvfv/EcVrM+FmMMohF8o5ktR9b5wmFZMHSKroS/TsO4=; b=uia2xYtoHBwtNsdEZNZzUZ9wUuOwFOxVLnqEZTbk+wzuR81QXu9xLxg6hxwHd9Gv2s tgaMufQ8BTLDvIo2OdhOi+ZLP0awCRvHCwMd27oRMq8mr/Hp7dK3c1CQa+ebpecwLILZ WdbVZWCSkM1Cljo9T8wC44syE/XK53e435x/8dvouFIDbVRW73UMf2jNgY8pRPUSWYwY aF7YuDgIGGarUO/gzaIZ0uN9m6EPN8U8tjO3kEfNSULuLZzVT5T8RXFRtkY9rbQD11/E s5teW5CD46vbicg18Kto9TeSB97CrR9eRGIslKuAptWh/o6ORaCs+cF4v3cLFhDjWjj1 SdpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gMT8BRpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i14-20020a17090332ce00b001bc079974dbsi13184315plr.355.2023.11.16.07.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 07:21:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gMT8BRpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 209128030B9E; Thu, 16 Nov 2023 07:21:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345299AbjKPPVf (ORCPT + 99 others); Thu, 16 Nov 2023 10:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbjKPPVc (ORCPT ); Thu, 16 Nov 2023 10:21:32 -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 63B56D4E for ; Thu, 16 Nov 2023 07:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700148087; 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=XW/iVfQyiraKBX/qX4dMONyaPD2cblNliSYriy+fjSk=; b=gMT8BRprfe2d7ku+smVB+R4ieL3t+wVLnrpq3MlFqLhM83b3bgteF7UL34qzSjaM6ECYOs LF7yYzzIgDhdUH0Kchmyw+2jQSgzkOm/9lf814QVJ5y/0qC002YcZmlvjySkur2UwKvzwo VVpzv3ZkHTa49ZPTwcqnOtI3LYxJckM= 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-335-4T8VB4YSMsSAqPUHAqr1Mg-1; Thu, 16 Nov 2023 10:21:24 -0500 X-MC-Unique: 4T8VB4YSMsSAqPUHAqr1Mg-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 B052A881E21; Thu, 16 Nov 2023 15:21:23 +0000 (UTC) Received: from p1.luc.cera.cz (unknown [10.45.225.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5F7240C6EB9; Thu, 16 Nov 2023 15:21:21 +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 iwl-next v3 3/5] i40e: Add helpers to find VSI and VEB by SEID and use them Date: Thu, 16 Nov 2023 16:21:12 +0100 Message-ID: <20231116152114.88515-4-ivecera@redhat.com> In-Reply-To: <20231116152114.88515-1-ivecera@redhat.com> References: <20231116152114.88515-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 16 Nov 2023 07:21:43 -0800 (PST) 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 --- drivers/net/ethernet/intel/i40e/i40e.h | 34 +++++++++ .../net/ethernet/intel/i40e/i40e_debugfs.c | 38 ++-------- drivers/net/ethernet/intel/i40e/i40e_main.c | 76 ++++++------------- 3 files changed, 64 insertions(+), 84 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h index 1e9266de270b..ca8997d29c02 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -1360,4 +1360,38 @@ static inline struct i40e_pf *i40e_hw_to_pf(struct i40e_hw *hw) struct device *i40e_hw_to_dev(struct i40e_hw *hw); +/** + * i40e_pf_get_vsi_by_seid - find VSI by SEID + * @pf: pointer to a PF + **/ +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 == seid) + return vsi; + + return NULL; +} + +/** + * i40e_pf_get_veb_by_seid - find VEB by SEID + * @pf: pointer to a PF + **/ +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 == seid) + return veb; + + return NULL; +} + #endif /* _I40E_H_ */ diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/ethernet/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); return NULL; } - i40e_pf_for_each_vsi(pf, i, vsi) - if (vsi->seid == 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 == seid) - return veb; - - return NULL; + return i40e_pf_get_vsi_by_seid(pf, seid); } /************************************************************** @@ -701,7 +677,7 @@ static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, int seid) { struct i40e_veb *veb; - veb = i40e_dbg_find_veb(pf, seid); + veb = 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, } else if (strncmp(cmd_buf, "add relay", 9) == 0) { struct i40e_veb *veb; - int uplink_seid, i; + int uplink_seid; cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid); if (cnt != 2) { @@ -875,12 +851,8 @@ static ssize_t i40e_dbg_command_write(struct file *filp, goto command_write_done; } - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid == uplink_seid) - break; - - if (i >= I40E_MAX_VEB && uplink_seid != 0 && - uplink_seid != pf->mac_seid) { + veb = i40e_pf_get_veb_by_seid(pf, uplink_seid); + if (!veb && uplink_seid != 0 && uplink_seid != 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/ethernet/intel/i40e/i40e_main.c index c410fc31a051..9f08224d5415 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_device *dev, struct i40e_pf *pf = vsi->back; struct nlattr *attr, *br_spec; struct i40e_veb *veb; - int i, rem; + int rem; /* Only for PF VSI for now */ if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) return -EOPNOTSUPP; /* Find the HW bridge for PF VSI */ - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid == vsi->uplink_seid) - break; - if (i == I40E_MAX_VEB) - veb = NULL; /* No VEB found */ + veb = i40e_pf_get_veb_by_seid(pf, vsi->uplink_seid); br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); if (!br_spec) @@ -13197,17 +13193,14 @@ static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct i40e_vsi *vsi = np->vsi; struct i40e_pf *pf = vsi->back; struct i40e_veb *veb = NULL; - int i; /* Only for PF VSI for now */ if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) return -EOPNOTSUPP; /* Find the HW bridge for the PF VSI */ - i40e_pf_for_each_veb(pf, i, veb) - if (veb->seid == vsi->uplink_seid) - break; - if (i == I40E_MAX_VEB) + veb = i40e_pf_get_veb_by_seid(pf, vsi->uplink_seid); + if (!vsi) return 0; 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 = NULL; struct i40e_veb *veb = NULL; u16 alloc_queue_pairs; - int ret, i; int v_idx; + int ret; /* 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 *pf, 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 == uplink_seid) - break; - if (i == I40E_MAX_VEB) - veb = NULL; - + veb = i40e_pf_get_veb_by_seid(pf, uplink_seid); if (!veb && uplink_seid != pf->mac_seid) { - i40e_pf_for_each_vsi(pf, i, vsi) - if (vsi->seid == uplink_seid) - break; - - if (i == pf->num_alloc_vsi) { + vsi = 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 == vsi->uplink_seid) - break; - if (i == I40E_MAX_VEB) { + veb = i40e_pf_get_veb_by_seid(pf, vsi->uplink_seid); + if (!veb) { dev_info(&pf->pdev->dev, "couldn't add VEB\n"); return NULL; } @@ -14835,7 +14818,7 @@ struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, { struct i40e_veb *veb, *uplink_veb = NULL; struct i40e_vsi *vsi; - int vsi_idx, veb_idx; + int veb_idx; int ret; /* 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 *pf, u16 flags, } /* make sure there is such a vsi and uplink */ - i40e_pf_for_each_vsi(pf, vsi_idx, vsi) - if (vsi->seid == vsi_seid) - break; - - if (vsi_idx == pf->num_alloc_vsi && vsi_seid != 0) { - dev_info(&pf->pdev->dev, "vsi seid %d not found\n", - vsi_seid); - return NULL; + if (vsi_seid) { + vsi = 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 != pf->mac_seid) { - i40e_pf_for_each_veb(pf, veb_idx, veb) { - if (veb->seid == uplink_seid) { - uplink_veb = veb; - break; - } - } + uplink_veb = 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 = i40e_add_veb(veb, vsi); if (ret) goto err_veb; - if (vsi_idx == pf->lan_vsi) + + if (vsi && vsi->idx == pf->lan_vsi) pf->lan_veb = veb->idx; return veb; @@ -14933,13 +14910,10 @@ static void i40e_setup_pf_switch_element(struct i40e_pf *pf, int v; /* find existing or else empty VEB */ - i40e_pf_for_each_veb(pf, v, veb) - if (veb->seid == seid) { - pf->lan_veb = v; - break; - } - - if (pf->lan_veb >= I40E_MAX_VEB) { + veb = i40e_pf_get_veb_by_seid(pf, seid); + if (veb) { + pf->lan_veb = veb->idx; + } else { v = i40e_veb_mem_alloc(pf); if (v < 0) break; -- 2.41.0