From patchwork Wed Apr 17 14:20:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Swiatkowski X-Patchwork-Id: 13633437 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 08C961411DF for ; Wed, 17 Apr 2024 14:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713363360; cv=none; b=V9+e2Ghc/LhtrDj3LY6gaVRVYHCkpc74fdVSBNZZHcD5it98qow5VEVfbN/3XF77XPV+yq04fZqI6yT5K2saZX7c1u2eYaExB8lJuvvPVyeSRkodirhRXKcKqGLT+XuOCXMWL2dZ7wH2qLvylU3lRtVGfpLmGN4dwud1tSd0WZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713363360; c=relaxed/simple; bh=vZRDHiWOqk/qacREAwSR+CBUbk5+Gvm5iwkAwGLt7PE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sSmSFQtGa6on2i3omcJdjQAvcJMS9yiicXWRbuGcsvtQmQkks3YsRJrC5dQi/j6/6FXIxMiLZOyLO2to8njNhhYfFFxWG1RowDCrSUBat8KKiQqBjXdMDq0L0ENsGnlpRyqYYYfhc16f0CdLSDbhfzFtkActQvifZjkPwh18Poo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dN8zWcq/; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dN8zWcq/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713363360; x=1744899360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vZRDHiWOqk/qacREAwSR+CBUbk5+Gvm5iwkAwGLt7PE=; b=dN8zWcq/VRbO9EivjQm9aaOBijiltjRVkuzHuST8AjaQ8r0rutrhSQDA QyBCqjrq0eR/rL6GeUDd6qznl/IwW9Q81eVLvYhbsBntE3a1rNlZSnGKa 9yzniMXcMAd0nQTQD/3IKaYv+P0mHhoDXB7GpZ8iSDZSH28FK36uIcOVO 5dqGgyzvRSimLorbteVKLa4L3NMBc20KZx+sqK62TeyJh6aq19d0lSKGx 1jIAd4QsTfftY9KQn8tXnIt90A0/a7zIDHiTzCkDVmEDNZKSX+L2i8/8S oVAbONt7gMAfrsomw5s0ByWKAmo9qfS1x/DB54n6Q0oxJCCOa8EZ7KBuE Q==; X-CSE-ConnectionGUID: tFOeHCu3QO+gb6J4+OKa8Q== X-CSE-MsgGUID: y8xiurN+SbCtmh+yZ7i6EQ== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="8737153" X-IronPort-AV: E=Sophos;i="6.07,209,1708416000"; d="scan'208";a="8737153" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 07:15:59 -0700 X-CSE-ConnectionGUID: gF2F86odREOwdoR/1kWnVA== X-CSE-MsgGUID: SnxZv89lQSKGb3zLn3Hn8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,209,1708416000"; d="scan'208";a="60050482" Received: from wasp.igk.intel.com (HELO GK3153-DR2-R750-36946.localdomain.com) ([10.102.20.192]) by orviesa001.jf.intel.com with ESMTP; 17 Apr 2024 07:15:49 -0700 From: Michal Swiatkowski To: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org, jacob.e.keller@intel.com, michal.kubiak@intel.com, maciej.fijalkowski@intel.com, sridhar.samudrala@intel.com, przemyslaw.kitszel@intel.com, wojciech.drewek@intel.com, pio.raczynski@gmail.com, jiri@nvidia.com, mateusz.polchlopek@intel.com Subject: [iwl-next v4 5/8] ice: allocate devlink for subfunction Date: Wed, 17 Apr 2024 16:20:25 +0200 Message-ID: <20240417142028.2171-6-michal.swiatkowski@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240417142028.2171-1-michal.swiatkowski@linux.intel.com> References: <20240417142028.2171-1-michal.swiatkowski@linux.intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Piotr Raczynski Make devlink allocation function generic to use it for PF and for SF. Add function for SF devlink port creation. It will be used in next patch. Create header file for subfunction device. Define subfunction device structure there as it is needed for devlink allocation and port creation. Signed-off-by: Piotr Raczynski Signed-off-by: Michal Swiatkowski --- .../net/ethernet/intel/ice/devlink/devlink.c | 47 ++++++++++++++--- .../net/ethernet/intel/ice/devlink/devlink.h | 1 + .../ethernet/intel/ice/devlink/devlink_port.c | 50 +++++++++++++++++++ .../ethernet/intel/ice/devlink/devlink_port.h | 3 ++ drivers/net/ethernet/intel/ice/ice_sf_eth.h | 21 ++++++++ 5 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_sf_eth.h diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net/ethernet/intel/ice/devlink/devlink.c index 661af04c8eef..5a78bf08e731 100644 --- a/drivers/net/ethernet/intel/ice/devlink/devlink.c +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c @@ -10,6 +10,7 @@ #include "ice_eswitch.h" #include "ice_fw_update.h" #include "ice_dcb_lib.h" +#include "ice_sf_eth.h" /* context for devlink info version reporting */ struct ice_info_ctx { @@ -1286,6 +1287,8 @@ static const struct devlink_ops ice_devlink_ops = { .port_new = ice_devlink_port_new, }; +static const struct devlink_ops ice_sf_devlink_ops; + static int ice_devlink_enable_roce_get(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx) @@ -1417,18 +1420,23 @@ static void ice_devlink_free(void *devlink_ptr) } /** - * ice_allocate_pf - Allocate devlink and return PF structure pointer + * ice_devlink_alloc - Allocate devlink and return devlink priv pointer * @dev: the device to allocate for + * @priv_size: size of the priv memory + * @ops: pointer to devlink ops for this device + * + * Allocate a devlink instance for this device and return the private pointer + * The devlink memory is kept track of through devres by adding an action to + * remove it when unwinding. * - * Allocate a devlink instance for this device and return the private area as - * the PF structure. The devlink memory is kept track of through devres by - * adding an action to remove it when unwinding. + * Return: void pointer to allocated memory */ -struct ice_pf *ice_allocate_pf(struct device *dev) +static void *ice_devlink_alloc(struct device *dev, size_t priv_size, + const struct devlink_ops *ops) { struct devlink *devlink; - devlink = devlink_alloc(&ice_devlink_ops, sizeof(struct ice_pf), dev); + devlink = devlink_alloc(ops, priv_size, dev); if (!devlink) return NULL; @@ -1439,6 +1447,33 @@ struct ice_pf *ice_allocate_pf(struct device *dev) return devlink_priv(devlink); } +/** + * ice_allocate_pf - Allocate devlink and return PF structure pointer + * @dev: the device to allocate for + * + * Allocate a devlink instance for PF. + * + * Return: void pointer to allocated memory + */ +struct ice_pf *ice_allocate_pf(struct device *dev) +{ + return ice_devlink_alloc(dev, sizeof(struct ice_pf), &ice_devlink_ops); +} + +/** + * ice_allocate_sf - Allocate devlink and return SF structure pointer + * @dev: the device to allocate for + * + * Allocate a devlink instance for SF. + * + * Return: void pointer to allocated memory + */ +struct ice_sf_priv *ice_allocate_sf(struct device *dev) +{ + return ice_devlink_alloc(dev, sizeof(struct ice_sf_priv), + &ice_sf_devlink_ops); +} + /** * ice_devlink_register - Register devlink interface for this PF * @pf: the PF to register the devlink for. diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.h b/drivers/net/ethernet/intel/ice/devlink/devlink.h index d291c0e2e17b..1b2a5980d5e8 100644 --- a/drivers/net/ethernet/intel/ice/devlink/devlink.h +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.h @@ -5,6 +5,7 @@ #define _ICE_DEVLINK_H_ struct ice_pf *ice_allocate_pf(struct device *dev); +struct ice_sf_priv *ice_allocate_sf(struct device *dev); void ice_devlink_register(struct ice_pf *pf); void ice_devlink_unregister(struct ice_pf *pf); diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink_port.c b/drivers/net/ethernet/intel/ice/devlink/devlink_port.c index d80637f945b6..0ab4d687e311 100644 --- a/drivers/net/ethernet/intel/ice/devlink/devlink_port.c +++ b/drivers/net/ethernet/intel/ice/devlink/devlink_port.c @@ -432,6 +432,56 @@ void ice_devlink_destroy_vf_port(struct ice_vf *vf) devlink_port_unregister(&vf->devlink_port); } +/** + * ice_devlink_create_sf_dev_port - Register virtual port for a subfunction + * @sf_dev: the subfunction device to create a devlink port for + * + * Register virtual flavour devlink port for the subfunction auxiliary device + * created after activating a dynamically added devlink port. + * + * Return: zero on success or an error code on failure. + */ +int ice_devlink_create_sf_dev_port(struct ice_sf_dev *sf_dev) +{ + struct devlink_port_attrs attrs = {}; + struct devlink_port *devlink_port; + struct ice_dynamic_port *dyn_port; + struct devlink *devlink; + struct ice_vsi *vsi; + struct device *dev; + struct ice_pf *pf; + int err; + + dyn_port = sf_dev->dyn_port; + vsi = dyn_port->vsi; + pf = dyn_port->pf; + dev = ice_pf_to_dev(pf); + + devlink_port = &sf_dev->priv->devlink_port; + + attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL; + + devlink_port_attrs_set(devlink_port, &attrs); + devlink = priv_to_devlink(sf_dev->priv); + + err = devl_port_register(devlink, devlink_port, vsi->idx); + if (err) + dev_err(dev, "Failed to create virtual devlink port for auxiliary subfunction device"); + + return err; +} + +/** + * ice_devlink_destroy_sf_dev_port - Destroy virtual port for a subfunction + * @sf_dev: the subfunction device to create a devlink port for + * + * Unregisters the virtual port associated with this subfunction. + */ +void ice_devlink_destroy_sf_dev_port(struct ice_sf_dev *sf_dev) +{ + devl_port_unregister(&sf_dev->priv->devlink_port); +} + /** * ice_dealloc_dynamic_port - Deallocate and remove a dynamic port * @dyn_port: dynamic port instance to deallocate diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink_port.h b/drivers/net/ethernet/intel/ice/devlink/devlink_port.h index 196db6806019..33f07cec6bd6 100644 --- a/drivers/net/ethernet/intel/ice/devlink/devlink_port.h +++ b/drivers/net/ethernet/intel/ice/devlink/devlink_port.h @@ -5,6 +5,7 @@ #define _DEVLINK_PORT_H_ #include "../ice.h" +#include "ice_sf_eth.h" /** * struct ice_dynamic_port - Track dynamically added devlink port instance @@ -30,6 +31,8 @@ int ice_devlink_create_pf_port(struct ice_pf *pf); void ice_devlink_destroy_pf_port(struct ice_pf *pf); int ice_devlink_create_vf_port(struct ice_vf *vf); void ice_devlink_destroy_vf_port(struct ice_vf *vf); +int ice_devlink_create_sf_dev_port(struct ice_sf_dev *sf_dev); +void ice_devlink_destroy_sf_dev_port(struct ice_sf_dev *sf_dev); #define ice_devlink_port_to_dyn(p) \ container_of(port, struct ice_dynamic_port, devlink_port) diff --git a/drivers/net/ethernet/intel/ice/ice_sf_eth.h b/drivers/net/ethernet/intel/ice/ice_sf_eth.h new file mode 100644 index 000000000000..a08f8b2bceef --- /dev/null +++ b/drivers/net/ethernet/intel/ice/ice_sf_eth.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2024, Intel Corporation. */ + +#ifndef _ICE_SF_ETH_H_ +#define _ICE_SF_ETH_H_ + +#include +#include "ice.h" + +struct ice_sf_dev { + struct auxiliary_device adev; + struct ice_dynamic_port *dyn_port; + struct ice_sf_priv *priv; +}; + +struct ice_sf_priv { + struct ice_sf_dev *dev; + struct devlink_port devlink_port; +}; + +#endif /* _ICE_SF_ETH_H_ */