src/dpdk/drivers/net/ice/ice_fdir_filter.c
static int
ice_fdir_setup(struct ice_pf *pf)
{
	struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
	struct ice_hw *hw = ICE_PF_TO_HW(pf);
	const struct rte_memzone *mz = NULL;
	char z_name[RTE_MEMZONE_NAMESIZE];
	struct ice_vsi *vsi;
	int err = ICE_SUCCESS;

	if ((pf->flags & ICE_FLAG_FDIR) == 0) {
		PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
		return -ENOTSUP;
	}

	PMD_DRV_LOG(INFO, "FDIR HW Capabilities: fd_fltr_guar = %u,"
		    " fd_fltr_best_effort = %u.",
		    hw->func_caps.fd_fltr_guar,
		    hw->func_caps.fd_fltr_best_effort);

	if (pf->fdir.fdir_vsi) {
		PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
		return ICE_SUCCESS;
	}

	/* make new FDIR VSI */
	vsi = ice_setup_vsi(pf, ICE_VSI_CTRL);
	if (!vsi) {
		PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
		return -EINVAL;
	}
	pf->fdir.fdir_vsi = vsi;

	err = ice_fdir_init_filter_list(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to init FDIR filter list.");
		return -EINVAL;
	}

	err = ice_fdir_counter_init(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to init FDIR counter.");
		return -EINVAL;
	}

	/*Fdir tx queue setup*/
	err = ice_fdir_setup_tx_resources(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
		goto fail_setup_tx;
	}

	/*Fdir rx queue setup*/
	err = ice_fdir_setup_rx_resources(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
		goto fail_setup_rx;
	}

	err = ice_fdir_tx_queue_start(eth_dev, pf->fdir.txq->queue_id);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to start FDIR TX queue.");
		goto fail_mem;
	}

	err = ice_fdir_rx_queue_start(eth_dev, pf->fdir.rxq->queue_id);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to start FDIR RX queue.");
		goto fail_mem;
	}

	/* Enable FDIR MSIX interrupt */
	vsi->nb_used_qps = 1;
	ice_vsi_queues_bind_intr(vsi);
	ice_vsi_enable_queues_intr(vsi);

	/* reserve memory for the fdir programming packet */
	snprintf(z_name, sizeof(z_name), "ICE_%s_%d",
		 ICE_FDIR_MZ_NAME,
		 eth_dev->data->port_id);
	mz = ice_memzone_reserve(z_name, ICE_FDIR_PKT_LEN, SOCKET_ID_ANY);
	if (!mz) {
		PMD_DRV_LOG(ERR, "Cannot init memzone for "
			    "flow director program packet.");
		err = -ENOMEM;
		goto fail_mem;
	}
	pf->fdir.prg_pkt = mz->addr;
	pf->fdir.dma_addr = mz->iova;
	pf->fdir.mz = mz;

	err = ice_fdir_prof_alloc(hw);
	if (err) {
		PMD_DRV_LOG(ERR, "Cannot allocate memory for "
			    "flow director profile.");
		err = -ENOMEM;
		goto fail_prof;
	}

	PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
		    vsi->base_queue);
	return ICE_SUCCESS;

fail_prof:
	rte_memzone_free(pf->fdir.mz);
	pf->fdir.mz = NULL;
fail_mem:
	ice_rx_queue_release(pf->fdir.rxq);
	pf->fdir.rxq = NULL;
fail_setup_rx:
	ice_tx_queue_release(pf->fdir.txq);
	pf->fdir.txq = NULL;
fail_setup_tx:
	ice_release_vsi(vsi);
	pf->fdir.fdir_vsi = NULL;
	return err;
}
/*
 * ice_fdir_setup - reserve and initialize the Flow Director resources
 * @pf: board private structure
 */
reserve and initialize the Flow Director resources
@pf: board private structure
reserve and initialize the Flow Director resources @pf : board private structure
static int
ice_fdir_setup(struct ice_pf *pf)
{
	struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
	struct ice_hw *hw = ICE_PF_TO_HW(pf);
	const struct rte_memzone *mz = NULL;
	char z_name[RTE_MEMZONE_NAMESIZE];
	struct ice_vsi *vsi;
	int err = ICE_SUCCESS;
	if ((pf->flags & ICE_FLAG_FDIR) == 0) {
		PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
		return -ENOTSUP;
	}
	PMD_DRV_LOG(INFO, "FDIR HW Capabilities: fd_fltr_guar = %u,"
		    " fd_fltr_best_effort = %u.",
		    hw->func_caps.fd_fltr_guar,
		    hw->func_caps.fd_fltr_best_effort);
	if (pf->fdir.fdir_vsi) {
		PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
		return ICE_SUCCESS;
	}
	vsi = ice_setup_vsi(pf, ICE_VSI_CTRL);
	if (!vsi) {
		PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
		return -EINVAL;
	}
	pf->fdir.fdir_vsi = vsi;
	err = ice_fdir_init_filter_list(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to init FDIR filter list.");
		return -EINVAL;
	}
	err = ice_fdir_counter_init(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to init FDIR counter.");
		return -EINVAL;
	}
	err = ice_fdir_setup_tx_resources(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
		goto fail_setup_tx;
	}
	err = ice_fdir_setup_rx_resources(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
		goto fail_setup_rx;
	}
	err = ice_fdir_tx_queue_start(eth_dev, pf->fdir.txq->queue_id);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to start FDIR TX queue.");
		goto fail_mem;
	}
	err = ice_fdir_rx_queue_start(eth_dev, pf->fdir.rxq->queue_id);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to start FDIR RX queue.");
		goto fail_mem;
	}
	vsi->nb_used_qps = 1;
	ice_vsi_queues_bind_intr(vsi);
	ice_vsi_enable_queues_intr(vsi);
	snprintf(z_name, sizeof(z_name), "ICE_%s_%d",
		 ICE_FDIR_MZ_NAME,
		 eth_dev->data->port_id);
	mz = ice_memzone_reserve(z_name, ICE_FDIR_PKT_LEN, SOCKET_ID_ANY);
	if (!mz) {
		PMD_DRV_LOG(ERR, "Cannot init memzone for "
			    "flow director program packet.");
		err = -ENOMEM;
		goto fail_mem;
	}
	pf->fdir.prg_pkt = mz->addr;
	pf->fdir.dma_addr = mz->iova;
	pf->fdir.mz = mz;
	err = ice_fdir_prof_alloc(hw);
	if (err) {
		PMD_DRV_LOG(ERR, "Cannot allocate memory for "
			    "flow director profile.");
		err = -ENOMEM;
		goto fail_prof;
	}
	PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
		    vsi->base_queue);
	return ICE_SUCCESS;
fail_prof:
	rte_memzone_free(pf->fdir.mz);
	pf->fdir.mz = NULL;
fail_mem:
	ice_rx_queue_release(pf->fdir.rxq);
	pf->fdir.rxq = NULL;
fail_setup_rx:
	ice_tx_queue_release(pf->fdir.txq);
	pf->fdir.txq = NULL;
fail_setup_tx:
	ice_release_vsi(vsi);
	pf->fdir.fdir_vsi = NULL;
	return err;
}
static int ice_fdir_setup ( struct ice_pf * pf ) { struct rte_eth_dev * eth_dev = pf -> adapter -> eth_dev ; struct ice_hw * hw = ICE_PF_TO_HW ( pf ) ; const struct rte_memzone * mz = NULL ; char z_name [ RTE_MEMZONE_NAMESIZE ] ; struct ice_vsi * vsi ; int err = ICE_SUCCESS ; if ( ( pf -> flags & ICE_FLAG_FDIR ) == 0 ) { PMD_INIT_LOG ( ERR , " " ) ; return - ENOTSUP ; } PMD_DRV_LOG ( INFO , " " " " , hw -> func_caps . fd_fltr_guar , hw -> func_caps . fd_fltr_best_effort ) ; if ( pf -> fdir . fdir_vsi ) { PMD_DRV_LOG ( INFO , " " ) ; return ICE_SUCCESS ; } vsi = ice_setup_vsi ( pf , ICE_VSI_CTRL ) ; if ( ! vsi ) { PMD_DRV_LOG ( ERR , " " ) ; return - EINVAL ; } pf -> fdir . fdir_vsi = vsi ; err = ice_fdir_init_filter_list ( pf ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; return - EINVAL ; } err = ice_fdir_counter_init ( pf ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; return - EINVAL ; } err = ice_fdir_setup_tx_resources ( pf ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_setup_tx ; } err = ice_fdir_setup_rx_resources ( pf ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_setup_rx ; } err = ice_fdir_tx_queue_start ( eth_dev , pf -> fdir . txq -> queue_id ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_mem ; } err = ice_fdir_rx_queue_start ( eth_dev , pf -> fdir . rxq -> queue_id ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_mem ; } vsi -> nb_used_qps = 1 ; ice_vsi_queues_bind_intr ( vsi ) ; ice_vsi_enable_queues_intr ( vsi ) ; snprintf ( z_name , sizeof ( z_name ) , " " , ICE_FDIR_MZ_NAME , eth_dev -> data -> port_id ) ; mz = ice_memzone_reserve ( z_name , ICE_FDIR_PKT_LEN , SOCKET_ID_ANY ) ; if ( ! mz ) { PMD_DRV_LOG ( ERR , " " " " ) ; err = - ENOMEM ; goto fail_mem ; } pf -> fdir . prg_pkt = mz -> addr ; pf -> fdir . dma_addr = mz -> iova ; pf -> fdir . mz = mz ; err = ice_fdir_prof_alloc ( hw ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " " " ) ; err = - ENOMEM ; goto fail_prof ; } PMD_DRV_LOG ( INFO , " " , vsi -> base_queue ) ; return ICE_SUCCESS ; fail_prof : rte_memzone_free ( pf -> fdir . mz ) ; pf -> fdir . mz = NULL ; fail_mem : ice_rx_queue_release ( pf -> fdir . rxq ) ; pf -> fdir . rxq = NULL ; fail_setup_rx : ice_tx_queue_release ( pf -> fdir . txq ) ; pf -> fdir . txq = NULL ; fail_setup_tx : ice_release_vsi ( vsi ) ; pf -> fdir . fdir_vsi = NULL ; return err ; }
ice_fdir_setup - reserve and initialize the Flow Director resources
 @pf: board private structure
ice_fdir_setup - reserve and initialize the Flow Director resources @pf : board private structure
/* make new FDIR VSI */ /*Fdir tx queue setup*/ /*Fdir rx queue setup*/ /* Enable FDIR MSIX interrupt */ /* reserve memory for the fdir programming packet */