[dpdk-dev,v2,4/7] i40e: function implement in i40e for flow director flush and info get

Message ID 1409105634-29980-5-git-send-email-jingjing.wu@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Jingjing Wu Aug. 27, 2014, 2:13 a.m. UTC
  support the API ops defined in ethdev, the behavior according to each command:
  RTE_CMD_FDIR_FLUSH   : clear all FDIR filter rules.
  RTE_CMD_FDIR_INFO_GET: get FDIR information.
 
Signed-off-by: jingjing.wu <jingjing.wu@intel.com>
Reviewed-by: Helin Zhang <helin.zhang@intel.com>
Reviewed-by: Jing Chen <jing.d.chen@intel.com>
Reviewed-by: Jijiang Liu <jijiang.liu@intel.com>
 
---
 lib/librte_pmd_i40e/i40e_ethdev.c |  8 +++++
 lib/librte_pmd_i40e/i40e_ethdev.h |  3 ++
 lib/librte_pmd_i40e/i40e_fdir.c   | 67 +++++++++++++++++++++++++++++++++++++++
 lib/librte_pmd_i40e/rte_i40e.h    | 14 ++++++++
 4 files changed, 92 insertions(+)
  

Patch

diff --git a/lib/librte_pmd_i40e/i40e_ethdev.c b/lib/librte_pmd_i40e/i40e_ethdev.c
index 7dcf964..10797ba 100644
--- a/lib/librte_pmd_i40e/i40e_ethdev.c
+++ b/lib/librte_pmd_i40e/i40e_ethdev.c
@@ -4221,6 +4221,14 @@  i40e_rx_classification_filter_ctl(struct rte_eth_dev *dev,
 			&fdir_entry->action,
 			FALSE);
 		break;
+	case RTE_CMD_FDIR_INFO_GET:
+		if (args == NULL)
+			return I40E_ERR_PARAM;
+		i40e_fdir_info_get(dev, (struct rte_i40e_fdir_info *)args);
+		break;
+	case RTE_CMD_FDIR_FLUSH:
+		ret = i40e_fdir_flush(pf);
+		break;
 	default:
 		PMD_DRV_LOG(ERR, "unknown command type %u\n", cmd);
 		ret = I40E_ERR_PARAM;
diff --git a/lib/librte_pmd_i40e/i40e_ethdev.h b/lib/librte_pmd_i40e/i40e_ethdev.h
index 5edb99e..7755f5a 100644
--- a/lib/librte_pmd_i40e/i40e_ethdev.h
+++ b/lib/librte_pmd_i40e/i40e_ethdev.h
@@ -334,11 +334,14 @@  i40e_fdir_setup_rx_resources(struct i40e_pf *pf,
 				    unsigned int socket_id);
 int i40e_fdir_setup(struct i40e_pf *pf);
 void i40e_fdir_teardown(struct i40e_pf *pf);
+int i40e_fdir_flush(struct i40e_pf *pf);
 int i40e_fdir_filter_programming(struct i40e_pf *pf,
 			uint16_t soft_id,
 			struct rte_i40e_fdir_input *fdir_filter,
 			struct rte_i40e_fdir_action *fdir_action,
 			bool add);
+void i40e_fdir_info_get(struct rte_eth_dev *dev,
+			   struct rte_i40e_fdir_info *fdir);
 
 /* I40E_DEV_PRIVATE_TO */
 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
diff --git a/lib/librte_pmd_i40e/i40e_fdir.c b/lib/librte_pmd_i40e/i40e_fdir.c
index df9a889..39e9e88 100644
--- a/lib/librte_pmd_i40e/i40e_fdir.c
+++ b/lib/librte_pmd_i40e/i40e_fdir.c
@@ -51,6 +51,9 @@ 
 /* Wait count and inteval for fdir filter programming */
 #define I40E_FDIR_WAIT_COUNT       10
 #define I40E_FDIR_WAIT_INTERVAL_US 1000
+/* Wait count and inteval for fdir filter flush */
+#define I40E_FDIR_FLUSH_RETRY       50
+#define I40E_FDIR_FLUSH_INTERVAL_MS 5
 
 #define I40E_COUNTER_PF           2
 /* Statistic counter index for one pf */
@@ -217,6 +220,45 @@  i40e_fdir_teardown(struct i40e_pf *pf)
 	return;
 }
 
+/*
+ * i40e_fdir_flush - clear all filters of Flow Director
+ * @pf: board private structure
+ */
+int
+i40e_fdir_flush(struct i40e_pf *pf)
+{
+	struct i40e_hw *hw = I40E_PF_TO_HW(pf);
+	uint32_t reg;
+	uint16_t guarant_cnt, best_cnt;
+	int i;
+
+	I40E_WRITE_REG(hw, I40E_PFQF_CTL_1, I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
+	I40E_WRITE_FLUSH(hw);
+
+	for (i = 0; i < I40E_FDIR_FLUSH_RETRY; i++) {
+		rte_delay_ms(I40E_FDIR_FLUSH_INTERVAL_MS);
+		reg = I40E_READ_REG(hw, I40E_PFQF_CTL_1);
+		if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
+			break;
+	}
+	if (i >= I40E_FDIR_FLUSH_RETRY) {
+		PMD_DRV_LOG(ERR, "FD table did not flush, may need more time\n");
+		return I40E_ERR_TIMEOUT;
+	}
+	guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
+				I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
+				I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
+	best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
+				I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
+				I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
+	if (guarant_cnt != 0 || best_cnt != 0) {
+		PMD_DRV_LOG(ERR, "Failed to flush FD table\n");
+		return I40E_ERR_CONFIG;
+	} else
+		PMD_DRV_LOG(INFO, "FD table Flush success\n");
+	return I40E_SUCCESS;
+}
+
 /* Construct the tx flags */
 static inline uint64_t
 i40e_build_ctob(uint32_t td_cmd,
@@ -431,3 +473,28 @@  i40e_fdir_filter_programming(struct i40e_pf *pf,
 	}
 	return I40E_SUCCESS;
 }
+
+/*
+ * i40e_fdir_info_get - get information of Flow Director
+ * @dev: ethernet device to add filter to
+ * @fdir: a pointer to a structure of type *rte_eth_dev_fdir* to be filled with
+ *    the flow director information.
+ **/
+void
+i40e_fdir_info_get(struct rte_eth_dev *dev, struct rte_i40e_fdir_info *fdir)
+{
+	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	uint32_t pfqf_ctl;
+
+	pfqf_ctl = I40E_READ_REG(hw, I40E_PFQF_CTL_0);
+	fdir->mode = pfqf_ctl & I40E_PFQF_CTL_0_FD_ENA_MASK ? 1 : 0;
+	fdir->guarant_spc = (uint16_t)hw->func_caps.fd_filters_guaranteed;
+	fdir->guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
+				I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
+				I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
+	fdir->best_spc = (uint16_t)hw->func_caps.fd_filters_best_effort;
+	fdir->best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
+				I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
+				I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
+	return;
+}
diff --git a/lib/librte_pmd_i40e/rte_i40e.h b/lib/librte_pmd_i40e/rte_i40e.h
index 3d9cc3d..1176a37 100644
--- a/lib/librte_pmd_i40e/rte_i40e.h
+++ b/lib/librte_pmd_i40e/rte_i40e.h
@@ -104,6 +104,20 @@  struct rte_i40e_fdir_entry {
 	struct rte_i40e_fdir_action action; /**< action taken when match */
 };
 
+/**
+ * For commands:
+ * 'RTE_CMD_FDIR_INFO_GET'
+ *
+ * A structure used for user to get the information of fdir feature.
+ */
+struct rte_i40e_fdir_info {
+	uint8_t  mode;         /**< 0 is disable, 1 is enable. */
+	uint16_t guarant_spc;  /**< guaranteed spaces.*/
+	uint16_t guarant_cnt;  /**< Number of filters in guaranteed spaces. */
+	uint16_t best_spc;     /**< best effort spaces.*/
+	uint16_t best_cnt;     /**< Number of filters in best effort spaces. */
+};
+
 #ifdef __cplusplus
 }
 #endif