DPDK-dev Archive on lore.kernel.org
 help / color / Atom feed
From: Haiyue Wang <haiyue.wang@intel.com>
To: dev@dpdk.org, xiaolong.ye@intel.com, qi.z.zhang@intel.com,
	qiming.yang@intel.com, beilei.xing@intel.com
Cc: wei.zhao1@intel.com, Haiyue Wang <haiyue.wang@intel.com>
Subject: [dpdk-dev] [PATCH v2 7/7] net/ice: get the VF hardware index in DCF
Date: Tue, 10 Mar 2020 14:50:29 +0800
Message-ID: <20200310065029.40966-8-haiyue.wang@intel.com> (raw)
In-Reply-To: <20200310065029.40966-1-haiyue.wang@intel.com>

The DCF (Device Config Function) needs the hardware index of the VFs to
control the flow setting. And also if the VF resets, the index may be
changed, so it should handle this in VF reset event.

Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
---
 drivers/net/ice/ice_dcf.c        | 81 +++++++++++++++++++++++++++++++
 drivers/net/ice/ice_dcf.h        |  4 ++
 drivers/net/ice/ice_dcf_parent.c | 83 +++++++++++++++++++++++++++++++-
 3 files changed, 167 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ice/ice_dcf.c b/drivers/net/ice/ice_dcf.c
index 480c449f5..1d3c8fa95 100644
--- a/drivers/net/ice/ice_dcf.c
+++ b/drivers/net/ice/ice_dcf.c
@@ -269,6 +269,63 @@ ice_dcf_get_vf_resource(struct ice_dcf_hw *hw)
 	return 0;
 }
 
+static int
+ice_dcf_get_vf_vsi_map(struct ice_dcf_hw *hw)
+{
+	struct virtchnl_dcf_vsi_map *vsi_map;
+	uint16_t len;
+	int err;
+
+	err = ice_dcf_send_cmd_req_no_irq(hw, VIRTCHNL_OP_DCF_GET_VSI_MAP,
+					  NULL, 0);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Fail to send msg OP_DCF_GET_VSI_MAP");
+		return err;
+	}
+
+	err = ice_dcf_recv_cmd_rsp_no_irq(hw, VIRTCHNL_OP_DCF_GET_VSI_MAP,
+					  hw->arq_buf, ICE_DCF_AQ_BUF_SZ,
+					  &len);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Fail to get response of OP_DCF_GET_VSI_MAP");
+		return err;
+	}
+
+	vsi_map = (struct virtchnl_dcf_vsi_map *)hw->arq_buf;
+	if (len < sizeof(*vsi_map) || !vsi_map->num_vfs ||
+	    len < sizeof(*vsi_map) +
+			(vsi_map->num_vfs - 1) * sizeof(vsi_map->vf_vsi[0])) {
+		PMD_DRV_LOG(ERR, "invalid vf vsi map response with length %u",
+			    len);
+		return -EINVAL;
+	}
+
+	if (hw->num_vfs != 0 && hw->num_vfs != vsi_map->num_vfs) {
+		PMD_DRV_LOG(ERR, "The number VSI map (%u) doesn't match the number of VFs (%u)",
+			    vsi_map->num_vfs, hw->num_vfs);
+		return -EINVAL;
+	}
+
+	len = vsi_map->num_vfs * sizeof(vsi_map->vf_vsi[0]);
+	if (!hw->vf_vsi_map) {
+		hw->num_vfs = vsi_map->num_vfs;
+		hw->vf_vsi_map = rte_zmalloc("vf_vsi_ctx", len, 0);
+	}
+
+	if (!hw->vf_vsi_map) {
+		PMD_DRV_LOG(ERR, "Fail to alloc memory for VSI context");
+		return -ENOMEM;
+	}
+
+	if (!memcmp(hw->vf_vsi_map, vsi_map->vf_vsi, len)) {
+		PMD_DRV_LOG(DEBUG, "VF VSI map doesn't change");
+		return 1;
+	}
+
+	rte_memcpy(hw->vf_vsi_map, vsi_map->vf_vsi, len);
+	return 0;
+}
+
 static int
 ice_dcf_mode_disable(struct ice_dcf_hw *hw)
 {
@@ -467,6 +524,23 @@ ice_dcf_send_aq_cmd(void *dcf_hw, struct ice_aq_desc *desc,
 	return err;
 }
 
+int
+ice_dcf_handle_vsi_update_event(struct ice_dcf_hw *hw)
+{
+	int err = 0;
+
+	rte_spinlock_lock(&hw->vc_cmd_send_lock);
+	ice_dcf_disable_irq0(hw);
+
+	if (ice_dcf_get_vf_resource(hw) || ice_dcf_get_vf_vsi_map(hw))
+		err = -1;
+
+	ice_dcf_enable_irq0(hw);
+	rte_spinlock_unlock(&hw->vc_cmd_send_lock);
+
+	return err;
+}
+
 int
 ice_dcf_init_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw)
 {
@@ -534,6 +608,12 @@ ice_dcf_init_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw)
 		goto err_alloc;
 	}
 
+	if (ice_dcf_get_vf_vsi_map(hw) < 0) {
+		PMD_INIT_LOG(ERR, "Failed to get VF VSI map");
+		ice_dcf_mode_disable(hw);
+		goto err_alloc;
+	}
+
 	rte_intr_callback_register(&pci_dev->intr_handle,
 				   ice_dcf_dev_interrupt_handler, hw);
 	rte_intr_enable(&pci_dev->intr_handle);
@@ -566,5 +646,6 @@ ice_dcf_uninit_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw)
 	iavf_shutdown_adminq(&hw->avf);
 
 	rte_free(hw->arq_buf);
+	rte_free(hw->vf_vsi_map);
 	rte_free(hw->vf_res);
 }
diff --git a/drivers/net/ice/ice_dcf.h b/drivers/net/ice/ice_dcf.h
index ecd6303a0..12bef4a2a 100644
--- a/drivers/net/ice/ice_dcf.h
+++ b/drivers/net/ice/ice_dcf.h
@@ -41,6 +41,9 @@ struct ice_dcf_hw {
 
 	uint8_t *arq_buf;
 
+	uint16_t num_vfs;
+	uint16_t *vf_vsi_map;
+
 	struct virtchnl_version_info virtchnl_version;
 	struct virtchnl_vf_resource *vf_res; /* VF resource */
 	struct virtchnl_vsi_resource *vsi_res; /* LAN VSI */
@@ -51,6 +54,7 @@ int ice_dcf_execute_virtchnl_cmd(struct ice_dcf_hw *hw,
 				 struct dcf_virtchnl_cmd *cmd);
 int ice_dcf_send_aq_cmd(void *dcf_hw, struct ice_aq_desc *desc,
 			void *buf, uint16_t buf_size);
+int ice_dcf_handle_vsi_update_event(struct ice_dcf_hw *hw);
 int ice_dcf_init_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw);
 void ice_dcf_uninit_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw);
 
diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c
index 4c3bb68b1..2735221e9 100644
--- a/drivers/net/ice/ice_dcf_parent.c
+++ b/drivers/net/ice/ice_dcf_parent.c
@@ -5,10 +5,76 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <rte_alarm.h>
+
 #include "ice_dcf_ethdev.h"
 
+#define ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL	100000 /* us */
+
+static __rte_always_inline void
+ice_dcf_update_vsi_ctx(struct ice_hw *hw, uint16_t vsi_handle,
+		       uint16_t vsi_map)
+{
+	struct ice_vsi_ctx *vsi_ctx;
+
+	if (unlikely(vsi_handle >= ICE_MAX_VSI)) {
+		PMD_DRV_LOG(ERR, "Invalid vsi handle %u", vsi_handle);
+		return;
+	}
+
+	vsi_ctx = hw->vsi_ctx[vsi_handle];
+
+	if (vsi_map & VIRTCHNL_DCF_VF_VSI_VALID) {
+		if (!vsi_ctx)
+			vsi_ctx = ice_malloc(hw, sizeof(*vsi_ctx));
+
+		if (!vsi_ctx) {
+			PMD_DRV_LOG(ERR, "No memory for vsi context %u",
+				    vsi_handle);
+			return;
+		}
+
+		vsi_ctx->vsi_num = (vsi_map & VIRTCHNL_DCF_VF_VSI_ID_M) >>
+					      VIRTCHNL_DCF_VF_VSI_ID_S;
+		hw->vsi_ctx[vsi_handle] = vsi_ctx;
+
+		PMD_DRV_LOG(DEBUG, "VF%u is assigned with vsi number %u",
+			    vsi_handle, vsi_ctx->vsi_num);
+	} else {
+		hw->vsi_ctx[vsi_handle] = NULL;
+
+		ice_free(hw, vsi_ctx);
+
+		PMD_DRV_LOG(NOTICE, "VF%u is disabled", vsi_handle);
+	}
+}
+
+static void
+ice_dcf_update_vf_vsi_map(struct ice_hw *hw, uint16_t num_vfs,
+			  uint16_t *vf_vsi_map)
+{
+	uint16_t vf_id;
+
+	for (vf_id = 0; vf_id < num_vfs; vf_id++)
+		ice_dcf_update_vsi_ctx(hw, vf_id, vf_vsi_map[vf_id]);
+}
+
+static void
+ice_dcf_vsi_update_service_handler(void *param)
+{
+	struct ice_dcf_hw *hw = param;
+
+	if (!ice_dcf_handle_vsi_update_event(hw)) {
+		struct ice_dcf_adapter *dcf_ad =
+			container_of(hw, struct ice_dcf_adapter, real_hw);
+
+		ice_dcf_update_vf_vsi_map(&dcf_ad->parent.hw,
+					  hw->num_vfs, hw->vf_vsi_map);
+	}
+}
+
 void
-ice_dcf_handle_pf_event_msg(__rte_unused struct ice_dcf_hw *dcf_hw,
+ice_dcf_handle_pf_event_msg(struct ice_dcf_hw *dcf_hw,
 			    uint8_t *msg, uint16_t msglen)
 {
 	struct virtchnl_pf_event *pf_msg = (struct virtchnl_pf_event *)msg;
@@ -21,6 +87,8 @@ ice_dcf_handle_pf_event_msg(__rte_unused struct ice_dcf_hw *dcf_hw,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		rte_eal_alarm_set(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL * 2,
+				  ice_dcf_vsi_update_service_handler, dcf_hw);
 		break;
 	case VIRTCHNL_EVENT_LINK_CHANGE:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
@@ -28,6 +96,13 @@ ice_dcf_handle_pf_event_msg(__rte_unused struct ice_dcf_hw *dcf_hw,
 	case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
 		break;
+	case VIRTCHNL_EVENT_DCF_VSI_MAP_UPDATE:
+		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_DCF_VSI_MAP_UPDATE event : VF%u with VSI num %u",
+			    pf_msg->event_data.vf_vsi_map.vf_id,
+			    pf_msg->event_data.vf_vsi_map.vsi_id);
+		rte_eal_alarm_set(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL,
+				  ice_dcf_vsi_update_service_handler, dcf_hw);
+		break;
 	default:
 		PMD_DRV_LOG(ERR, "Unknown event received %u", pf_msg->event);
 		break;
@@ -235,6 +310,9 @@ ice_dcf_init_parent_adapter(struct rte_eth_dev *eth_dev)
 	}
 	parent_adapter->active_pkg_type = ice_load_pkg_type(parent_hw);
 
+	ice_dcf_update_vf_vsi_map(parent_hw,
+				  hw->num_vfs, hw->vf_vsi_map);
+
 	mac = (const struct rte_ether_addr *)hw->avf.mac.addr;
 	if (rte_is_valid_assigned_ether_addr(mac))
 		rte_ether_addr_copy(mac, &parent_adapter->pf.dev_addr);
@@ -259,5 +337,8 @@ ice_dcf_uninit_parent_adapter(struct rte_eth_dev *eth_dev)
 
 	eth_dev->data->mac_addrs = NULL;
 
+	rte_eal_alarm_cancel(ice_dcf_vsi_update_service_handler,
+			     &adapter->real_hw);
+
 	ice_dcf_uninit_parent_hw(parent_hw);
 }
-- 
2.25.1


  parent reply index

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 14:14 [dpdk-dev] [PATCH v1 0/4] add Intel DCF PMD support Haiyue Wang
2020-03-09 14:14 ` [dpdk-dev] [PATCH v1 1/4] net/iavf: stop the PCI probe in DCF mode Haiyue Wang
2020-03-09 15:38   ` Ye Xiaolong
2020-03-10  2:19     ` Wang, Haiyue
2020-03-10  3:37       ` Ye Xiaolong
2020-03-10  4:26         ` Wang, Haiyue
2020-03-23  1:50   ` Wu, Jingjing
2020-03-23  1:55     ` Wang, Haiyue
2020-03-09 14:14 ` [dpdk-dev] [PATCH v1 2/4] net/ice: export the DDP definition symbols Haiyue Wang
2020-03-09 16:25   ` Ye Xiaolong
2020-03-09 14:14 ` [dpdk-dev] [PATCH v1 3/4] net/ice: add the DCF framework Haiyue Wang
2020-03-10  4:17   ` Ye Xiaolong
2020-03-10  5:09     ` Wang, Haiyue
2020-03-10  5:23       ` Ye Xiaolong
2020-03-09 14:14 ` [dpdk-dev] [PATCH v1 4/4] doc: add release notes for Intel ice PMD Haiyue Wang
2020-03-09 15:22   ` Ye Xiaolong
2020-03-10  2:16     ` Wang, Haiyue
2020-03-09 15:36 ` [dpdk-dev] [PATCH v1 0/4] add Intel DCF PMD support David Marchand
2020-03-09 16:20   ` Ye Xiaolong
2020-03-09 17:57     ` Thomas Monjalon
2020-03-09 19:34       ` Kevin Traynor
2020-03-10  2:00         ` Wang, Haiyue
2020-03-10  7:48           ` Thomas Monjalon
2020-03-10  9:36             ` Ferruh Yigit
2020-03-10 14:11               ` Aaron Conole
2020-03-10 14:09   ` Aaron Conole
2020-03-10  6:50 ` [dpdk-dev] [PATCH v2 0/7] " Haiyue Wang
2020-03-10  6:50   ` [dpdk-dev] [PATCH v2 1/7] net/iavf: stop the PCI probe in DCF mode Haiyue Wang
2020-03-13  5:27     ` Ye Xiaolong
2020-03-10  6:50   ` [dpdk-dev] [PATCH v2 2/7] net/ice: add the DCF hardware initialization Haiyue Wang
2020-03-10  6:50   ` [dpdk-dev] [PATCH v2 3/7] net/ice: initiate to acquire the DCF capability Haiyue Wang
2020-03-13  5:51     ` Ye Xiaolong
2020-03-13  6:19       ` Wang, Haiyue
2020-03-13  6:04     ` Ye Xiaolong
2020-03-13  6:10       ` Wang, Haiyue
2020-03-10  6:50   ` [dpdk-dev] [PATCH v2 4/7] net/ice: handle the AdminQ command by DCF Haiyue Wang
2020-03-10  6:50   ` [dpdk-dev] [PATCH v2 5/7] net/ice: export the DDP definition symbols Haiyue Wang
2020-03-10  6:50   ` [dpdk-dev] [PATCH v2 6/7] net/ice: handle the PF initialization by DCF Haiyue Wang
2020-03-13  7:59     ` Ye Xiaolong
2020-03-13  8:03       ` Ye Xiaolong
2020-03-16  4:52       ` Wang, Haiyue
2020-03-13 14:06     ` Ye Xiaolong
2020-03-13 14:11       ` Wang, Haiyue
2020-03-10  6:50   ` Haiyue Wang [this message]
2020-03-13  7:01     ` [dpdk-dev] [PATCH v2 7/7] net/ice: get the VF hardware index in DCF Ye Xiaolong
2020-03-16  5:58       ` Wang, Haiyue
2020-03-13 16:19   ` [dpdk-dev] [PATCH v2 0/7] add Intel DCF PMD support Stillwell Jr, Paul M
2020-03-13 16:25     ` Wang, Haiyue
2020-03-13 16:50       ` Stillwell Jr, Paul M
2020-03-13 17:05         ` Wang, Haiyue
2020-03-13 17:47           ` Stillwell Jr, Paul M
2020-03-14  1:57             ` Wang, Haiyue
2020-03-15  1:49     ` Zhang, Qi Z
2020-03-16 18:54       ` Stillwell Jr, Paul M
2020-03-17  2:35         ` Wang, Haiyue
2020-03-16  5:52 ` [dpdk-dev] [PATCH v3 " Haiyue Wang
2020-03-16  5:52   ` [dpdk-dev] [PATCH v3 1/7] net/iavf: stop the PCI probe in DCF mode Haiyue Wang
2020-03-16  5:52   ` [dpdk-dev] [PATCH v3 2/7] net/ice: add the DCF hardware initialization Haiyue Wang
2020-03-16  5:52   ` [dpdk-dev] [PATCH v3 3/7] net/ice: acquire and disable the DCF capability Haiyue Wang
2020-03-16  5:52   ` [dpdk-dev] [PATCH v3 4/7] net/ice: handle the AdminQ command by DCF Haiyue Wang
2020-03-16  5:52   ` [dpdk-dev] [PATCH v3 5/7] net/ice: export the DDP definition symbols Haiyue Wang
2020-03-16  5:52   ` [dpdk-dev] [PATCH v3 6/7] net/ice: handle the PF initialization by DCF Haiyue Wang
2020-03-16  5:52   ` [dpdk-dev] [PATCH v3 7/7] net/ice: get the VF hardware index in DCF Haiyue Wang
2020-03-26  3:03 ` [dpdk-dev] [PATCH v4 0/7] add Intel DCF PMD support Haiyue Wang
2020-03-26  3:03   ` [dpdk-dev] [PATCH v4 1/7] net/iavf: stop the PCI probe in DCF mode Haiyue Wang
2020-03-26  3:28     ` Wu, Jingjing
2020-03-26  3:03   ` [dpdk-dev] [PATCH v4 2/7] net/ice: add the DCF hardware initialization Haiyue Wang
2020-03-26  3:03   ` [dpdk-dev] [PATCH v4 3/7] net/ice: acquire and disable the DCF capability Haiyue Wang
2020-03-26  3:03   ` [dpdk-dev] [PATCH v4 4/7] net/ice: handle the AdminQ command by DCF Haiyue Wang
2020-03-26  3:03   ` [dpdk-dev] [PATCH v4 5/7] net/ice: export the DDP definition symbols Haiyue Wang
2020-03-26  3:03   ` [dpdk-dev] [PATCH v4 6/7] net/ice: handle the PF initialization by DCF Haiyue Wang
2020-03-26  3:03   ` [dpdk-dev] [PATCH v4 7/7] net/ice: get the VF hardware index in DCF Haiyue Wang
2020-03-26  4:11   ` [dpdk-dev] [PATCH v4 0/7] add Intel DCF PMD support Zhang, Qi Z
2020-03-26  5:05   ` Ye Xiaolong
2020-03-26  5:26     ` Wang, Haiyue
2020-03-26  7:15 ` [dpdk-dev] [PATCH v5 " Haiyue Wang
2020-03-26  7:15   ` [dpdk-dev] [PATCH v5 1/7] net/iavf: stop the PCI probe in DCF mode Haiyue Wang
2020-03-26  7:15   ` [dpdk-dev] [PATCH v5 2/7] net/ice: add the DCF hardware initialization Haiyue Wang
2020-03-26  7:15   ` [dpdk-dev] [PATCH v5 3/7] net/ice: acquire and disable the DCF capability Haiyue Wang
2020-03-26  7:15   ` [dpdk-dev] [PATCH v5 4/7] net/ice: handle the AdminQ command by DCF Haiyue Wang
2020-03-26  7:15   ` [dpdk-dev] [PATCH v5 5/7] net/ice: export the DDP definition symbols Haiyue Wang
2020-03-26  7:15   ` [dpdk-dev] [PATCH v5 6/7] net/ice: handle the PF initialization by DCF Haiyue Wang
2020-03-26  7:15   ` [dpdk-dev] [PATCH v5 7/7] net/ice: get the VF hardware index in DCF Haiyue Wang
2020-03-27  2:56 ` [dpdk-dev] [PATCH v6 0/7] add Intel DCF PMD support Haiyue Wang
2020-03-27  2:56   ` [dpdk-dev] [PATCH v6 1/7] net/iavf: stop the PCI probe in DCF mode Haiyue Wang
2020-03-27  2:56   ` [dpdk-dev] [PATCH v6 2/7] net/ice: add the DCF hardware initialization Haiyue Wang
2020-03-31  8:50     ` Ferruh Yigit
2020-03-31 12:17       ` Wang, Haiyue
2020-03-27  2:56   ` [dpdk-dev] [PATCH v6 3/7] net/ice: acquire and disable the DCF capability Haiyue Wang
2020-03-27  2:56   ` [dpdk-dev] [PATCH v6 4/7] net/ice: handle the AdminQ command by DCF Haiyue Wang
2020-03-27  2:56   ` [dpdk-dev] [PATCH v6 5/7] net/ice: export the DDP definition symbols Haiyue Wang
2020-03-27  2:56   ` [dpdk-dev] [PATCH v6 6/7] net/ice: handle the PF initialization by DCF Haiyue Wang
2020-03-27  2:56   ` [dpdk-dev] [PATCH v6 7/7] net/ice: get the VF hardware index in DCF Haiyue Wang
2020-03-27 15:26   ` [dpdk-dev] [PATCH v6 0/7] add Intel DCF PMD support Ye Xiaolong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200310065029.40966-8-haiyue.wang@intel.com \
    --to=haiyue.wang@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=wei.zhao1@intel.com \
    --cc=xiaolong.ye@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK-dev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dpdk-dev/0 dpdk-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dpdk-dev dpdk-dev/ https://lore.kernel.org/dpdk-dev \
		dev@dpdk.org
	public-inbox-index dpdk-dev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git