3 #include "base/ice_fdir.h"
4 #include "base/ice_flow.h"
5 #include "base/ice_type.h"
6 #include "ice_ethdev.h"
8 #include "ice_generic_flow.h"
10 static const struct rte_memzone *
11 ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
13 return rte_memzone_reserve_aligned(name, len, socket_id,
14 RTE_MEMZONE_IOVA_CONTIG,
18 #define ICE_FDIR_MZ_NAME "FDIR_MEMZONE"
21 ice_fdir_prof_alloc(struct ice_hw *hw)
23 enum ice_fltr_ptype ptype, fltr_ptype;
26 hw->fdir_prof = (struct ice_fd_hw_prof **)
27 ice_malloc(hw, ICE_FLTR_PTYPE_MAX *
28 sizeof(*hw->fdir_prof));
32 for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
33 ptype < ICE_FLTR_PTYPE_MAX;
35 if (!hw->fdir_prof[ptype]) {
36 hw->fdir_prof[ptype] = (struct ice_fd_hw_prof *)
37 ice_malloc(hw, sizeof(**hw->fdir_prof));
38 if (!hw->fdir_prof[ptype])
45 for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
48 rte_free(hw->fdir_prof[fltr_ptype]);
49 rte_free(hw->fdir_prof);
54 * ice_fdir_setup - reserve and initialize the Flow Director resources
55 * @pf: board private structure
58 ice_fdir_setup(struct ice_pf *pf)
60 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
61 struct ice_hw *hw = ICE_PF_TO_HW(pf);
62 const struct rte_memzone *mz = NULL;
63 char z_name[RTE_MEMZONE_NAMESIZE];
65 int err = ICE_SUCCESS;
67 if ((pf->flags & ICE_FLAG_FDIR) == 0) {
68 PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
72 PMD_DRV_LOG(INFO, "FDIR HW Capabilities: fd_fltr_guar = %u,"
73 " fd_fltr_best_effort = %u.",
74 hw->func_caps.fd_fltr_guar,
75 hw->func_caps.fd_fltr_best_effort);
77 if (pf->fdir.fdir_vsi) {
78 PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
82 /* make new FDIR VSI */
83 vsi = ice_setup_vsi(pf, ICE_VSI_CTRL);
85 PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
88 pf->fdir.fdir_vsi = vsi;
90 /*Fdir tx queue setup*/
91 err = ice_fdir_setup_tx_resources(pf);
93 PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
97 /*Fdir rx queue setup*/
98 err = ice_fdir_setup_rx_resources(pf);
100 PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
104 err = ice_fdir_tx_queue_start(eth_dev, pf->fdir.txq->queue_id);
106 PMD_DRV_LOG(ERR, "Failed to start FDIR TX queue.");
110 err = ice_fdir_rx_queue_start(eth_dev, pf->fdir.rxq->queue_id);
112 PMD_DRV_LOG(ERR, "Failed to start FDIR RX queue.");
116 /* reserve memory for the fdir programming packet */
117 snprintf(z_name, sizeof(z_name), "ICE_%s_%d",
119 eth_dev->data->port_id);
120 mz = ice_memzone_reserve(z_name, ICE_FDIR_PKT_LEN, SOCKET_ID_ANY);
122 PMD_DRV_LOG(ERR, "Cannot init memzone for "
123 "flow director program packet.");
127 pf->fdir.prg_pkt = mz->addr;
128 pf->fdir.dma_addr = mz->iova;
130 err = ice_fdir_prof_alloc(hw);
132 PMD_DRV_LOG(ERR, "Cannot allocate memory for "
133 "flow director profile.");
138 PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
143 ice_rx_queue_release(pf->fdir.rxq);
146 ice_tx_queue_release(pf->fdir.txq);
149 ice_release_vsi(vsi);
150 pf->fdir.fdir_vsi = NULL;
155 ice_fdir_prof_free(struct ice_hw *hw)
157 enum ice_fltr_ptype ptype;
159 for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
160 ptype < ICE_FLTR_PTYPE_MAX;
162 rte_free(hw->fdir_prof[ptype]);
164 rte_free(hw->fdir_prof);
168 * ice_fdir_teardown - release the Flow Director resources
169 * @pf: board private structure
172 ice_fdir_teardown(struct ice_pf *pf)
174 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
175 struct ice_hw *hw = ICE_PF_TO_HW(pf);
179 vsi = pf->fdir.fdir_vsi;
183 err = ice_fdir_tx_queue_stop(eth_dev, pf->fdir.txq->queue_id);
185 PMD_DRV_LOG(ERR, "Failed to stop TX queue.");
187 err = ice_fdir_rx_queue_stop(eth_dev, pf->fdir.rxq->queue_id);
189 PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
191 ice_tx_queue_release(pf->fdir.txq);
193 ice_rx_queue_release(pf->fdir.rxq);
195 ice_release_vsi(vsi);
196 pf->fdir.fdir_vsi = NULL;
197 ice_fdir_prof_free(hw);
201 ice_fdir_init(struct ice_adapter *ad)
203 struct ice_pf *pf = &ad->pf;
205 return ice_fdir_setup(pf);
209 ice_fdir_uninit(struct ice_adapter *ad)
211 struct ice_pf *pf = &ad->pf;
213 ice_fdir_teardown(pf);
216 static struct ice_flow_engine ice_fdir_engine = {
217 .init = ice_fdir_init,
218 .uninit = ice_fdir_uninit,
219 .type = ICE_FLOW_ENGINE_FDIR,
222 RTE_INIT(ice_fdir_engine_register)
224 ice_register_flow_engine(&ice_fdir_engine);