From patchwork Wed Feb 28 15:59:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larysa Zaremba X-Patchwork-Id: 207910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3446622dyb; Wed, 28 Feb 2024 08:11:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXLHAaGxionmUB6LONSRTsCXHGeyrsCUMzWVhMUSGaK8E2AcZbWFYR5KZBcBkQUxfEuYKqzPS+a26ee0BtHh97pFfkI8g== X-Google-Smtp-Source: AGHT+IF6am4P1zwyuZHCU/sKZ5zmu4lUwISoTPkXK586UJd9XBWajlFO3pjyTy7rJ8yXuf6iQ+3t X-Received: by 2002:aa7:db5a:0:b0:566:2be1:5277 with SMTP id n26-20020aa7db5a000000b005662be15277mr4903713edt.30.1709136714466; Wed, 28 Feb 2024 08:11:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709136714; cv=pass; d=google.com; s=arc-20160816; b=Crp8aO1rOHyS4ADObEnyKvaf1wXs2oK0cKK43dH76wcuJRRvoZNVluX8pJKodgylFh SuiNeKds16XUWwDQ/mRvITbBes6/bFO1+N6iVlNhy7J0OwBbfofGT+BsMs2Z7K4fLzkI 23XR9+qnsM0OE03Izmoshw8C7r+ZslpHROAGNWNHhk6iHHfmzgrR6ublDSawdroq/R4s JsORUVTnFwhpWxRb8P+ZxOXm5j7sOe5OxSg94MUdA+EVwk737g18fA45uIZRhtmVDVVz 0CP4e4ubsUrnJ1dWrTxkzerVrglywQ3dRdZnoAWxzZwAp2ewN+99SyqZD9YXyxqUK9U+ PUUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=suU515v4P/RN9aDdgILWwByW4yNO8k6eXfq9Cl0Uirw=; fh=XF5dR1hZ6bmHhiCesO+5NPfXhTaDjas2E0STvyrxXLQ=; b=0io01q12UNxjetw8i81hiu/FFE05aAdOQ2NYICHDRPBSwW1Qx5zx3jEF41MxhvA5ye bmGL8Or6/xFvtWZAF/2ZFVzbSStr9zZKMNFCqOQF4o2zcNUHhcgjEksg9HU10QK3Yvvy q/JqFZEAakYncDtfMdMh2eHgIKTld3XfvvHAOu8G8ULdyIhhqE0DSPqwd+kLfPviIYk2 Bb7104E0p4WgTWXESmczVjjW6g8q1c/3V7Vjo4dgnDEHQSOxZ9EnZgHrUXvufkuy0Bk4 Xnuc2LZrY4MGK946HM4cJ1sgWN2t/HVA1kQD+0oHpJ3oIUA0EJ7Sw8tdvyzSZxfJXvWx NhmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YEnWwjqM; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85316-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85316-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l2-20020a50d6c2000000b00564951ae492si1831582edj.118.2024.02.28.08.11.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 08:11:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85316-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YEnWwjqM; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85316-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85316-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F000C1F2A7D5 for ; Wed, 28 Feb 2024 16:04:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 617B915E5C3; Wed, 28 Feb 2024 16:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YEnWwjqM" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A918815D5CE; Wed, 28 Feb 2024 16:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709136255; cv=none; b=hFXTS0RPOd2mZrI40OblKjyyNwNoXSNuGKlLOzMtroKO9tMI1Imtf8djPRBLjUTiBL8JOLLZuvi+0isloByCCMaZMSTgPVLhgCgTgru01ovQPpDnGZl756pLiX7mtTstOHx9rhc+WrVMvY4OOI0RJf+LJEICeKuzYSAa79kLn8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709136255; c=relaxed/simple; bh=OUeJ0q/Q4TSugz58SFBLkzeTCYbClmf+g/buseTVPBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SzC0cZmO6LuZ9YApUlzV6cz154qwjHx31RPh4f+zlLm5uhCWLkdVZbFzxYfJL4s8nlIOXNMaCM1FNvvmB4hjp7eHKq43FydnXTV0sewhxPUyAPucvr77YDZXNGgQ2J4pFFtWFjIPBlE4rHlSj7DmR3ZE53t28JaQ79VvdZhF59k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YEnWwjqM; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709136254; x=1740672254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OUeJ0q/Q4TSugz58SFBLkzeTCYbClmf+g/buseTVPBw=; b=YEnWwjqMLxPo702o4EjLFENJMkCU1T2MkfjU0XXtM4bJU2yIKAF4Bzr9 OUxwAQTBH6Z3bDbx7MC5661Zdf/hK363VLFhIMN3oxrRFXnboKMyfuMY4 caE7MIEz4WOqp9bDBTf/o704VybhYlPHvV3tvEcZmDnGYPNWKJrIbaOve vjcJmd4MmjZ9maqd0602Gv3Ycxqfhr9Bfomfgyl2+UF/m+tQ5XwC6ZX6B zkDobeLm272P82f9EMKh6kqLgriZFJAt6SNF7WVO+kR/z8qZq8TltqHwh L+5eDdyBWKFrctcPOQDm+eC6Q6S/mlkxpIcXBzRCmw+pr3koY+cizO5ta g==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3706577" X-IronPort-AV: E=Sophos;i="6.06,190,1705392000"; d="scan'208";a="3706577" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 08:04:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,190,1705392000"; d="scan'208";a="7527702" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by orviesa009.jf.intel.com with ESMTP; 28 Feb 2024 08:04:10 -0800 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id DA1AD36825; Wed, 28 Feb 2024 16:04:04 +0000 (GMT) From: Larysa Zaremba To: intel-wired-lan@lists.osuosl.org Cc: Larysa Zaremba , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Mateusz Pacuszka , Tony Nguyen , Lukasz Plachno , Jakub Buchocki , Pawel Kaminski , Przemek Kitszel , Michal Swiatkowski , Mateusz Polchlopek , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Pawel Chmielewski , Jesse Brandeburg Subject: [PATCH iwl-net 1/5] ice: Add function to get VF from device struct Date: Wed, 28 Feb 2024 16:59:45 +0100 Message-ID: <20240228155957.408036-2-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228155957.408036-1-larysa.zaremba@intel.com> References: <20240228155957.408036-1-larysa.zaremba@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792159739321892439 X-GMAIL-MSGID: 1792159739321892439 From: Mateusz Polchlopek Introduce a helper ice_get_vf_by_dev() to look up VF for a given struct device. Signed-off-by: Mateusz Polchlopek Reviewed-by: Przemek Kitszel Signed-off-by: Larysa Zaremba --- drivers/net/ethernet/intel/ice/ice_vf_lib.c | 30 +++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_vf_lib.h | 6 +++++ 2 files changed, 36 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_vf_lib.c b/drivers/net/ethernet/intel/ice/ice_vf_lib.c index 2ffdae9a82df..21d22e3ad0ba 100644 --- a/drivers/net/ethernet/intel/ice/ice_vf_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_vf_lib.c @@ -45,6 +45,36 @@ struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id) return NULL; } +/** + * ice_get_vf_by_dev - Get pointer to VF by device + * @dev: the device structure + * + * Locate and return a pointer to the VF structure associated with a given + * device. + * Return: valid VF structure associated with the device, NULL if none exists + */ +struct ice_vf *ice_get_vf_by_dev(struct device *dev) +{ + struct pci_dev *vfdev; + struct pci_dev *pdev; + struct ice_pf *pf; + struct ice_vf *vf; + unsigned int bkt; + + vfdev = container_of(dev, struct pci_dev, dev); + pdev = vfdev->physfn; + pf = pci_get_drvdata(pdev); + + rcu_read_lock(); + ice_for_each_vf_rcu(pf, bkt, vf) { + if (vf->vfdev == vfdev) + break; + } + rcu_read_unlock(); + + return vf; +} + /** * ice_release_vf - Release VF associated with a refcount * @ref: the kref decremented to zero diff --git a/drivers/net/ethernet/intel/ice/ice_vf_lib.h b/drivers/net/ethernet/intel/ice/ice_vf_lib.h index 0cc9034065c5..48f4cdbd6d27 100644 --- a/drivers/net/ethernet/intel/ice/ice_vf_lib.h +++ b/drivers/net/ethernet/intel/ice/ice_vf_lib.h @@ -213,6 +213,7 @@ static inline u16 ice_vf_get_port_vlan_tpid(struct ice_vf *vf) #ifdef CONFIG_PCI_IOV struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id); +struct ice_vf *ice_get_vf_by_dev(struct device *dev); void ice_put_vf(struct ice_vf *vf); bool ice_has_vfs(struct ice_pf *pf); u16 ice_get_num_vfs(struct ice_pf *pf); @@ -237,6 +238,11 @@ static inline struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id) return NULL; } +static inline struct ice_vf *ice_get_vf_by_dev(struct device *dev) +{ + return NULL; +} + static inline void ice_put_vf(struct ice_vf *vf) { }