[02/12] net/ice: tear down flow director

Message ID 20190906120058.108073-3-yahui.cao@intel.com (mailing list archive)
State Superseded, archived
Delegated to: xiaolong ye
Headers
Series net/ice: add ice Flow Director driver |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Cao, Yahui Sept. 6, 2019, noon UTC
  From: Beilei Xing <beilei.xing@intel.com>

Release resources on flow director, include:
 - Release queue.
 - Release VSI.

Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 40 ++++++++++++++++++++++
 drivers/net/ice/ice_rxtx.c        | 57 +++++++++++++++++++++++++++++++
 drivers/net/ice/ice_rxtx.h        |  2 ++
 3 files changed, 99 insertions(+)
  

Comments

Xiaolong Ye Sept. 7, 2019, 11:21 a.m. UTC | #1
On 09/06, Yahui Cao wrote:
>From: Beilei Xing <beilei.xing@intel.com>
>
>Release resources on flow director, include:
> - Release queue.
> - Release VSI.
>
>Signed-off-by: Beilei Xing <beilei.xing@intel.com>
>---
> drivers/net/ice/ice_fdir_filter.c | 40 ++++++++++++++++++++++
> drivers/net/ice/ice_rxtx.c        | 57 +++++++++++++++++++++++++++++++
> drivers/net/ice/ice_rxtx.h        |  2 ++

Update document and release as well, and what about combine this patch with
prior patch, I think together they enable the FDIR engine.

> 3 files changed, 99 insertions(+)
>
>diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
>index 03d143058..451ef92b2 100644
>--- a/drivers/net/ice/ice_fdir_filter.c
>+++ b/drivers/net/ice/ice_fdir_filter.c
>@@ -117,6 +117,37 @@ ice_fdir_setup(struct ice_pf *pf)
> 	return err;
> }
> 
>+/*
>+ * ice_fdir_teardown - release the Flow Director resources
>+ * @pf: board private structure
>+ */
>+static void
>+ice_fdir_teardown(struct ice_pf *pf)
>+{
>+	struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
>+	struct ice_vsi *vsi;
>+	int err;
>+
>+	vsi = pf->fdir.fdir_vsi;
>+	if (!vsi)
>+		return;
>+
>+	err = ice_fdir_tx_queue_stop(eth_dev, pf->fdir.txq->queue_id);
>+	if (err)
>+		PMD_DRV_LOG(ERR, "Failed to stop TX queue.");
>+
>+	err = ice_fdir_rx_queue_stop(eth_dev, pf->fdir.rxq->queue_id);
>+	if (err)
>+		PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
>+
>+	ice_tx_queue_release(pf->fdir.txq);
>+	pf->fdir.txq = NULL;
>+	ice_rx_queue_release(pf->fdir.rxq);
>+	pf->fdir.rxq = NULL;
>+	ice_release_vsi(vsi);
>+	pf->fdir.fdir_vsi = NULL;
>+}
>+
> static int
> ice_init_fdir_filter(struct ice_adapter *ad)
> {
>@@ -128,8 +159,17 @@ ice_init_fdir_filter(struct ice_adapter *ad)
> 	return ret;
> }
> 
>+static void
>+ice_uninit_fdir_filter(struct ice_adapter *ad)
>+{
>+	struct ice_pf *pf = &ad->pf;
>+
>+	ice_fdir_teardown(pf);
>+}
>+
> static struct ice_flow_engine ice_fdir_engine = {
> 	.init = ice_init_fdir_filter,
>+	.uninit = ice_uninit_fdir_filter,
> 	.type = ICE_FLOW_ENGINE_FDIR,
> };
> 
>diff --git a/drivers/net/ice/ice_rxtx.c b/drivers/net/ice/ice_rxtx.c
>index bd802e350..e41fcb194 100644
>--- a/drivers/net/ice/ice_rxtx.c
>+++ b/drivers/net/ice/ice_rxtx.c
>@@ -748,6 +748,63 @@ ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
> 	return 0;
> }
> 
>+int
>+ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
>+{
>+	struct ice_rx_queue *rxq;
>+	int err;
>+	struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
>+	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
>+
>+	rxq = pf->fdir.rxq;
>+
>+	err = ice_switch_rx_queue(hw, rxq->reg_idx, FALSE);
>+	if (err) {
>+		PMD_DRV_LOG(ERR, "Failed to switch FDIR RX queue %u off",
>+			    rx_queue_id);
>+		return -EINVAL;
>+	}
>+	ice_rx_queue_release_mbufs(rxq);
>+
>+	return 0;
>+}
>+
>+int
>+ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
>+{
>+	struct ice_tx_queue *txq;
>+	struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
>+	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
>+	struct ice_vsi *vsi = pf->main_vsi;
>+	enum ice_status status;
>+	uint16_t q_ids[1];
>+	uint32_t q_teids[1];
>+	uint16_t q_handle = tx_queue_id;
>+
>+	txq = pf->fdir.txq;
>+	if (!txq) {
>+		PMD_DRV_LOG(ERR, "TX queue %u is not available",
>+			    tx_queue_id);
>+		return -EINVAL;
>+	}
>+	vsi = txq->vsi;
>+
>+	q_ids[0] = txq->reg_idx;
>+	q_teids[0] = txq->q_teid;
>+
>+	/* Fix me, we assume TC always 0 here */
>+	status = ice_dis_vsi_txq(hw->port_info, vsi->idx, 0, 1, &q_handle,
>+				 q_ids, q_teids, ICE_NO_RESET, 0, NULL);
>+	if (status != ICE_SUCCESS) {
>+		PMD_DRV_LOG(DEBUG, "Failed to disable Lan Tx queue");
>+		return -EINVAL;
>+	}
>+
>+	ice_tx_queue_release_mbufs(txq);
>+
>+	return 0;
>+}

Better to reuse ice_rx/tx_queue_stop.

Thanks,
Xiaolong

>+
> int
> ice_rx_queue_setup(struct rte_eth_dev *dev,
> 		   uint16_t queue_idx,
>diff --git a/drivers/net/ice/ice_rxtx.h b/drivers/net/ice/ice_rxtx.h
>index 450db0244..24376c0d5 100644
>--- a/drivers/net/ice/ice_rxtx.h
>+++ b/drivers/net/ice/ice_rxtx.h
>@@ -151,6 +151,8 @@ int ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
> int ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
> int ice_fdir_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
> int ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
>+int ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
>+int ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
> void ice_rx_queue_release(void *rxq);
> void ice_tx_queue_release(void *txq);
> void ice_clear_queues(struct rte_eth_dev *dev);
>-- 
>2.17.1
>
  

Patch

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 03d143058..451ef92b2 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -117,6 +117,37 @@  ice_fdir_setup(struct ice_pf *pf)
 	return err;
 }
 
+/*
+ * ice_fdir_teardown - release the Flow Director resources
+ * @pf: board private structure
+ */
+static void
+ice_fdir_teardown(struct ice_pf *pf)
+{
+	struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
+	struct ice_vsi *vsi;
+	int err;
+
+	vsi = pf->fdir.fdir_vsi;
+	if (!vsi)
+		return;
+
+	err = ice_fdir_tx_queue_stop(eth_dev, pf->fdir.txq->queue_id);
+	if (err)
+		PMD_DRV_LOG(ERR, "Failed to stop TX queue.");
+
+	err = ice_fdir_rx_queue_stop(eth_dev, pf->fdir.rxq->queue_id);
+	if (err)
+		PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
+
+	ice_tx_queue_release(pf->fdir.txq);
+	pf->fdir.txq = NULL;
+	ice_rx_queue_release(pf->fdir.rxq);
+	pf->fdir.rxq = NULL;
+	ice_release_vsi(vsi);
+	pf->fdir.fdir_vsi = NULL;
+}
+
 static int
 ice_init_fdir_filter(struct ice_adapter *ad)
 {
@@ -128,8 +159,17 @@  ice_init_fdir_filter(struct ice_adapter *ad)
 	return ret;
 }
 
+static void
+ice_uninit_fdir_filter(struct ice_adapter *ad)
+{
+	struct ice_pf *pf = &ad->pf;
+
+	ice_fdir_teardown(pf);
+}
+
 static struct ice_flow_engine ice_fdir_engine = {
 	.init = ice_init_fdir_filter,
+	.uninit = ice_uninit_fdir_filter,
 	.type = ICE_FLOW_ENGINE_FDIR,
 };
 
diff --git a/drivers/net/ice/ice_rxtx.c b/drivers/net/ice/ice_rxtx.c
index bd802e350..e41fcb194 100644
--- a/drivers/net/ice/ice_rxtx.c
+++ b/drivers/net/ice/ice_rxtx.c
@@ -748,6 +748,63 @@  ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
 	return 0;
 }
 
+int
+ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+	struct ice_rx_queue *rxq;
+	int err;
+	struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+	rxq = pf->fdir.rxq;
+
+	err = ice_switch_rx_queue(hw, rxq->reg_idx, FALSE);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Failed to switch FDIR RX queue %u off",
+			    rx_queue_id);
+		return -EINVAL;
+	}
+	ice_rx_queue_release_mbufs(rxq);
+
+	return 0;
+}
+
+int
+ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
+{
+	struct ice_tx_queue *txq;
+	struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+	struct ice_vsi *vsi = pf->main_vsi;
+	enum ice_status status;
+	uint16_t q_ids[1];
+	uint32_t q_teids[1];
+	uint16_t q_handle = tx_queue_id;
+
+	txq = pf->fdir.txq;
+	if (!txq) {
+		PMD_DRV_LOG(ERR, "TX queue %u is not available",
+			    tx_queue_id);
+		return -EINVAL;
+	}
+	vsi = txq->vsi;
+
+	q_ids[0] = txq->reg_idx;
+	q_teids[0] = txq->q_teid;
+
+	/* Fix me, we assume TC always 0 here */
+	status = ice_dis_vsi_txq(hw->port_info, vsi->idx, 0, 1, &q_handle,
+				 q_ids, q_teids, ICE_NO_RESET, 0, NULL);
+	if (status != ICE_SUCCESS) {
+		PMD_DRV_LOG(DEBUG, "Failed to disable Lan Tx queue");
+		return -EINVAL;
+	}
+
+	ice_tx_queue_release_mbufs(txq);
+
+	return 0;
+}
+
 int
 ice_rx_queue_setup(struct rte_eth_dev *dev,
 		   uint16_t queue_idx,
diff --git a/drivers/net/ice/ice_rxtx.h b/drivers/net/ice/ice_rxtx.h
index 450db0244..24376c0d5 100644
--- a/drivers/net/ice/ice_rxtx.h
+++ b/drivers/net/ice/ice_rxtx.h
@@ -151,6 +151,8 @@  int ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
 int ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
 int ice_fdir_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
 int ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
+int ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
+int ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
 void ice_rx_queue_release(void *rxq);
 void ice_tx_queue_release(void *txq);
 void ice_clear_queues(struct rte_eth_dev *dev);