From patchwork Fri Sep 6 22:29:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 13794818 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 70DF115B12B for ; Fri, 6 Sep 2024 22:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725661819; cv=none; b=i/FkhuTfz3JUcrWAgzuBXvEssrhgOxkSzNecp6KmR91GyBzClsXcnp2iIyjFBgD5fn8E5eEl1aTq4q3UlkddJuZEoWhL+PfFeDmRxZquJuBttYABFFgi6FRs6JcyQEjuK43ongVv4Vjz0PDs7ziWq3N9fgsfD+KMEFlaCLxroQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725661819; c=relaxed/simple; bh=aPGTJwMEMsWDYpVoFVFc1DNApwkaXv7Uu543D+1ZYvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LFeOmsudFgmKKfEMgxQyswnQwfcf3EkUfmZ7moDY3NxAoXtLOyYTeXXLRMVZMR1VizFxQ/vj1hF9Wk0uUO/S+3J/jWjht1AMdEU2FFZKJZqXh+mVUS+jugwT5tu7KfIO87Z/f6LJCrAjcS0aehpPdh6xdm3mDPjMXa2tmjdVLAo= 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=QzBW2KE1; arc=none smtp.client-ip=192.198.163.11 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QzBW2KE1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725661818; x=1757197818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aPGTJwMEMsWDYpVoFVFc1DNApwkaXv7Uu543D+1ZYvg=; b=QzBW2KE14/ijqx/j6ICQX4W0MJlGQxPe+gQuBjz6OV8BvSEilQxLITIw K/6/TR7BuY4ZTfD/40zRSaaAnNlodDtH6eoxA4JFuiGwe+7a5SaB13rGD aCXQR9F7rRQZYG9zFo7Vl1/H/KXPFXg+mYnY/8TsKM2XeQWW+LNKdC0aM Pvkfi8aQnKggEMqq8RkfzT/kdmf/LYVsGq9IZfxRBpl2vklVs3eRmEZHp 9URr4DefIIKnsn8iFHHB78IiX6gSMsK/gAhG/xYiYWlstce42JenOHgPR y9lVmqODjjA0Q1xVMGwUaPL1Q7vosE4SnM3QT62mmHwMSrrFETMRQx29K w==; X-CSE-ConnectionGUID: oBf9DI2ITSytWb1rptgCdg== X-CSE-MsgGUID: YsDdRy9TQeme+EAZ69uM8w== X-IronPort-AV: E=McAfee;i="6700,10204,11187"; a="35030722" X-IronPort-AV: E=Sophos;i="6.10,209,1719903600"; d="scan'208";a="35030722" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2024 15:30:16 -0700 X-CSE-ConnectionGUID: XgC0f2QqSgazcEb6Z8bDhA== X-CSE-MsgGUID: zHEG+rLdSnuk404MI2WLQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,209,1719903600"; d="scan'208";a="70490432" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa005.fm.intel.com with ESMTP; 06 Sep 2024 15:30:15 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: anthony.l.nguyen@intel.com, michal.swiatkowski@linux.intel.com, jiri@nvidia.com, shayd@nvidia.com, wojciech.drewek@intel.com, horms@kernel.org, sridhar.samudrala@intel.com, mateusz.polchlopek@intel.com, kalesh-anakkur.purayil@broadcom.com, michal.kubiak@intel.com, pio.raczynski@gmail.com, przemyslaw.kitszel@intel.com, jacob.e.keller@intel.com, maciej.fijalkowski@intel.com, Rafal Romanowski Subject: [PATCH net-next v5 07/15] ice: implement netdev for subfunction Date: Fri, 6 Sep 2024 15:29:58 -0700 Message-ID: <20240906223010.2194591-8-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240906223010.2194591-1-anthony.l.nguyen@intel.com> References: <20240906223010.2194591-1-anthony.l.nguyen@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 Configure netdevice for subfunction usecase. Mostly it is reusing ops from the PF netdevice. SF netdev is linked to devlink port registered after SF activation. Reviewed-by: Simon Horman Reviewed-by: Jiri Pirko Signed-off-by: Piotr Raczynski Signed-off-by: Michal Swiatkowski Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_sf_eth.c | 86 ++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_sf_eth.c b/drivers/net/ethernet/intel/ice/ice_sf_eth.c index 02556f72b831..05d9e7384c5e 100644 --- a/drivers/net/ethernet/intel/ice/ice_sf_eth.c +++ b/drivers/net/ethernet/intel/ice/ice_sf_eth.c @@ -2,11 +2,86 @@ /* Copyright (c) 2024, Intel Corporation. */ #include "ice.h" #include "ice_lib.h" +#include "ice_txrx.h" #include "ice_fltr.h" #include "ice_sf_eth.h" #include "devlink/devlink_port.h" #include "devlink/devlink.h" +static const struct net_device_ops ice_sf_netdev_ops = { + .ndo_open = ice_open, + .ndo_stop = ice_stop, + .ndo_start_xmit = ice_start_xmit, + .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid, + .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid, + .ndo_change_mtu = ice_change_mtu, + .ndo_get_stats64 = ice_get_stats64, + .ndo_tx_timeout = ice_tx_timeout, + .ndo_bpf = ice_xdp, + .ndo_xdp_xmit = ice_xdp_xmit, + .ndo_xsk_wakeup = ice_xsk_wakeup, +}; + +/** + * ice_sf_cfg_netdev - Allocate, configure and register a netdev + * @dyn_port: subfunction associated with configured netdev + * @devlink_port: subfunction devlink port to be linked with netdev + * + * Return: 0 on success, negative value on failure + */ +static int ice_sf_cfg_netdev(struct ice_dynamic_port *dyn_port, + struct devlink_port *devlink_port) +{ + struct ice_vsi *vsi = dyn_port->vsi; + struct ice_netdev_priv *np; + struct net_device *netdev; + int err; + + netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq, + vsi->alloc_rxq); + if (!netdev) + return -ENOMEM; + + SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev); + set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); + vsi->netdev = netdev; + np = netdev_priv(netdev); + np->vsi = vsi; + + ice_set_netdev_features(netdev); + + netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | + NETDEV_XDP_ACT_XSK_ZEROCOPY | + NETDEV_XDP_ACT_RX_SG; + netdev->xdp_zc_max_segs = ICE_MAX_BUF_TXD; + + eth_hw_addr_set(netdev, dyn_port->hw_addr); + ether_addr_copy(netdev->perm_addr, dyn_port->hw_addr); + netdev->netdev_ops = &ice_sf_netdev_ops; + SET_NETDEV_DEVLINK_PORT(netdev, devlink_port); + + err = register_netdev(netdev); + if (err) { + free_netdev(netdev); + vsi->netdev = NULL; + return -ENOMEM; + } + set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state); + netif_carrier_off(netdev); + netif_tx_stop_all_queues(netdev); + + return 0; +} + +static void ice_sf_decfg_netdev(struct ice_vsi *vsi) +{ + unregister_netdev(vsi->netdev); + clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state); + free_netdev(vsi->netdev); + vsi->netdev = NULL; + clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); +} + /** * ice_sf_dev_probe - subfunction driver probe function * @adev: pointer to the auxiliary device @@ -57,10 +132,16 @@ static int ice_sf_dev_probe(struct auxiliary_device *adev, goto err_vsi_decfg; } + err = ice_sf_cfg_netdev(dyn_port, &sf_dev->priv->devlink_port); + if (err) { + dev_err(dev, "Subfunction netdev config failed"); + goto err_devlink_destroy; + } + err = devl_port_fn_devlink_set(&dyn_port->devlink_port, devlink); if (err) { dev_err(dev, "Can't link devlink instance to SF devlink port"); - goto err_devlink_destroy; + goto err_netdev_decfg; } ice_napi_add(vsi); @@ -70,6 +151,8 @@ static int ice_sf_dev_probe(struct auxiliary_device *adev, return 0; +err_netdev_decfg: + ice_sf_decfg_netdev(vsi); err_devlink_destroy: ice_devlink_destroy_sf_dev_port(sf_dev); err_vsi_decfg: @@ -98,6 +181,7 @@ static void ice_sf_dev_remove(struct auxiliary_device *adev) ice_vsi_close(vsi); + ice_sf_decfg_netdev(vsi); ice_devlink_destroy_sf_dev_port(sf_dev); devl_unregister(devlink); devl_unlock(devlink);