src/dpdk/drivers/net/i40e/i40e_fdir.c
int
i40e_fdir_setup(struct i40e_pf *pf)
{
	struct i40e_hw *hw = I40E_PF_TO_HW(pf);
	struct i40e_vsi *vsi;
	int err = I40E_SUCCESS;
	char z_name[RTE_MEMZONE_NAMESIZE];
	const struct rte_memzone *mz = NULL;
	struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
	uint16_t i;

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

	PMD_DRV_LOG(INFO, "FDIR HW Capabilities: num_filters_guaranteed = %u,"
			" num_filters_best_effort = %u.",
			hw->func_caps.fd_filters_guaranteed,
			hw->func_caps.fd_filters_best_effort);

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

	/* make new FDIR VSI */
	vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->main_vsi, 0);
	if (!vsi) {
		PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
		return I40E_ERR_NO_AVAILABLE_VSI;
	}
	pf->fdir.fdir_vsi = vsi;

	/*Fdir tx queue setup*/
	err = i40e_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 = i40e_fdir_setup_rx_resources(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
		goto fail_setup_rx;
	}

	err = i40e_tx_queue_init(pf->fdir.txq);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do FDIR TX initialization.");
		goto fail_mem;
	}

	/* need switch on before dev start*/
	err = i40e_switch_tx_queue(hw, vsi->base_queue, TRUE);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do fdir TX switch on.");
		goto fail_mem;
	}

	/* Init the rx queue in hardware */
	err = i40e_fdir_rx_queue_init(pf->fdir.rxq);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do FDIR RX initialization.");
		goto fail_mem;
	}

	/* switch on rx queue */
	err = i40e_switch_rx_queue(hw, vsi->base_queue, TRUE);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do FDIR RX switch on.");
		goto fail_mem;
	}

	/* enable FDIR MSIX interrupt */
	vsi->nb_used_qps = 1;
	i40e_vsi_queues_bind_intr(vsi, I40E_ITR_INDEX_NONE);
	i40e_vsi_enable_queues_intr(vsi);

	/* reserve memory for the fdir programming packet */
	snprintf(z_name, sizeof(z_name), "%s_%s_%d",
			eth_dev->device->driver->name,
			I40E_FDIR_MZ_NAME,
			eth_dev->data->port_id);
	mz = i40e_memzone_reserve(z_name, I40E_FDIR_PKT_LEN *
			I40E_FDIR_PRG_PKT_CNT, SOCKET_ID_ANY);
	if (!mz) {
		PMD_DRV_LOG(ERR, "Cannot init memzone for "
				 "flow director program packet.");
		err = I40E_ERR_NO_MEMORY;
		goto fail_mem;
	}

	for (i = 0; i < I40E_FDIR_PRG_PKT_CNT; i++) {
		pf->fdir.prg_pkt[i] = (uint8_t *)mz->addr +
			I40E_FDIR_PKT_LEN * i;
		pf->fdir.dma_addr[i] = mz->iova +
			I40E_FDIR_PKT_LEN * i;
	}

	pf->fdir.match_counter_index = I40E_COUNTER_INDEX_FDIR(hw->pf_id);
	pf->fdir.fdir_actual_cnt = 0;
	pf->fdir.fdir_guarantee_free_space =
		pf->fdir.fdir_guarantee_total_space;

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

fail_mem:
	i40e_dev_rx_queue_release(pf->fdir.rxq);
	pf->fdir.rxq = NULL;
fail_setup_rx:
	i40e_dev_tx_queue_release(pf->fdir.txq);
	pf->fdir.txq = NULL;
fail_setup_tx:
	i40e_vsi_release(vsi);
	pf->fdir.fdir_vsi = NULL;
	return err;
}
/*
 * i40e_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
int
i40e_fdir_setup(struct i40e_pf *pf)
{
	struct i40e_hw *hw = I40E_PF_TO_HW(pf);
	struct i40e_vsi *vsi;
	int err = I40E_SUCCESS;
	char z_name[RTE_MEMZONE_NAMESIZE];
	const struct rte_memzone *mz = NULL;
	struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
	uint16_t i;
	if ((pf->flags & I40E_FLAG_FDIR) == 0) {
		PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
		return I40E_NOT_SUPPORTED;
	}
	PMD_DRV_LOG(INFO, "FDIR HW Capabilities: num_filters_guaranteed = %u,"
			" num_filters_best_effort = %u.",
			hw->func_caps.fd_filters_guaranteed,
			hw->func_caps.fd_filters_best_effort);
	vsi = pf->fdir.fdir_vsi;
	if (vsi) {
		PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
		return I40E_SUCCESS;
	}
	vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->main_vsi, 0);
	if (!vsi) {
		PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
		return I40E_ERR_NO_AVAILABLE_VSI;
	}
	pf->fdir.fdir_vsi = vsi;
	err = i40e_fdir_setup_tx_resources(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
		goto fail_setup_tx;
	}
	err = i40e_fdir_setup_rx_resources(pf);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
		goto fail_setup_rx;
	}
	err = i40e_tx_queue_init(pf->fdir.txq);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do FDIR TX initialization.");
		goto fail_mem;
	}
	err = i40e_switch_tx_queue(hw, vsi->base_queue, TRUE);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do fdir TX switch on.");
		goto fail_mem;
	}
	err = i40e_fdir_rx_queue_init(pf->fdir.rxq);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do FDIR RX initialization.");
		goto fail_mem;
	}
	err = i40e_switch_rx_queue(hw, vsi->base_queue, TRUE);
	if (err) {
		PMD_DRV_LOG(ERR, "Failed to do FDIR RX switch on.");
		goto fail_mem;
	}
	vsi->nb_used_qps = 1;
	i40e_vsi_queues_bind_intr(vsi, I40E_ITR_INDEX_NONE);
	i40e_vsi_enable_queues_intr(vsi);
	snprintf(z_name, sizeof(z_name), "%s_%s_%d",
			eth_dev->device->driver->name,
			I40E_FDIR_MZ_NAME,
			eth_dev->data->port_id);
	mz = i40e_memzone_reserve(z_name, I40E_FDIR_PKT_LEN *
			I40E_FDIR_PRG_PKT_CNT, SOCKET_ID_ANY);
	if (!mz) {
		PMD_DRV_LOG(ERR, "Cannot init memzone for "
				 "flow director program packet.");
		err = I40E_ERR_NO_MEMORY;
		goto fail_mem;
	}
	for (i = 0; i < I40E_FDIR_PRG_PKT_CNT; i++) {
		pf->fdir.prg_pkt[i] = (uint8_t *)mz->addr +
			I40E_FDIR_PKT_LEN * i;
		pf->fdir.dma_addr[i] = mz->iova +
			I40E_FDIR_PKT_LEN * i;
	}
	pf->fdir.match_counter_index = I40E_COUNTER_INDEX_FDIR(hw->pf_id);
	pf->fdir.fdir_actual_cnt = 0;
	pf->fdir.fdir_guarantee_free_space =
		pf->fdir.fdir_guarantee_total_space;
	PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
		    vsi->base_queue);
	return I40E_SUCCESS;
fail_mem:
	i40e_dev_rx_queue_release(pf->fdir.rxq);
	pf->fdir.rxq = NULL;
fail_setup_rx:
	i40e_dev_tx_queue_release(pf->fdir.txq);
	pf->fdir.txq = NULL;
fail_setup_tx:
	i40e_vsi_release(vsi);
	pf->fdir.fdir_vsi = NULL;
	return err;
}
int i40e_fdir_setup ( struct i40e_pf * pf ) { struct i40e_hw * hw = I40E_PF_TO_HW ( pf ) ; struct i40e_vsi * vsi ; int err = I40E_SUCCESS ; char z_name [ RTE_MEMZONE_NAMESIZE ] ; const struct rte_memzone * mz = NULL ; struct rte_eth_dev * eth_dev = pf -> adapter -> eth_dev ; uint16_t i ; if ( ( pf -> flags & I40E_FLAG_FDIR ) == 0 ) { PMD_INIT_LOG ( ERR , " " ) ; return I40E_NOT_SUPPORTED ; } PMD_DRV_LOG ( INFO , " " " " , hw -> func_caps . fd_filters_guaranteed , hw -> func_caps . fd_filters_best_effort ) ; vsi = pf -> fdir . fdir_vsi ; if ( vsi ) { PMD_DRV_LOG ( INFO , " " ) ; return I40E_SUCCESS ; } vsi = i40e_vsi_setup ( pf , I40E_VSI_FDIR , pf -> main_vsi , 0 ) ; if ( ! vsi ) { PMD_DRV_LOG ( ERR , " " ) ; return I40E_ERR_NO_AVAILABLE_VSI ; } pf -> fdir . fdir_vsi = vsi ; err = i40e_fdir_setup_tx_resources ( pf ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_setup_tx ; } err = i40e_fdir_setup_rx_resources ( pf ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_setup_rx ; } err = i40e_tx_queue_init ( pf -> fdir . txq ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_mem ; } err = i40e_switch_tx_queue ( hw , vsi -> base_queue , TRUE ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_mem ; } err = i40e_fdir_rx_queue_init ( pf -> fdir . rxq ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_mem ; } err = i40e_switch_rx_queue ( hw , vsi -> base_queue , TRUE ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " ) ; goto fail_mem ; } vsi -> nb_used_qps = 1 ; i40e_vsi_queues_bind_intr ( vsi , I40E_ITR_INDEX_NONE ) ; i40e_vsi_enable_queues_intr ( vsi ) ; snprintf ( z_name , sizeof ( z_name ) , " " , eth_dev -> device -> driver -> name , I40E_FDIR_MZ_NAME , eth_dev -> data -> port_id ) ; mz = i40e_memzone_reserve ( z_name , I40E_FDIR_PKT_LEN * I40E_FDIR_PRG_PKT_CNT , SOCKET_ID_ANY ) ; if ( ! mz ) { PMD_DRV_LOG ( ERR , " " " " ) ; err = I40E_ERR_NO_MEMORY ; goto fail_mem ; } for ( i = 0 ; i < I40E_FDIR_PRG_PKT_CNT ; i ++ ) { pf -> fdir . prg_pkt [ i ] = ( uint8_t * ) mz -> addr + I40E_FDIR_PKT_LEN * i ; pf -> fdir . dma_addr [ i ] = mz -> iova + I40E_FDIR_PKT_LEN * i ; } pf -> fdir . match_counter_index = I40E_COUNTER_INDEX_FDIR ( hw -> pf_id ) ; pf -> fdir . fdir_actual_cnt = 0 ; pf -> fdir . fdir_guarantee_free_space = pf -> fdir . fdir_guarantee_total_space ; PMD_DRV_LOG ( INFO , " " , vsi -> base_queue ) ; return I40E_SUCCESS ; fail_mem : i40e_dev_rx_queue_release ( pf -> fdir . rxq ) ; pf -> fdir . rxq = NULL ; fail_setup_rx : i40e_dev_tx_queue_release ( pf -> fdir . txq ) ; pf -> fdir . txq = NULL ; fail_setup_tx : i40e_vsi_release ( vsi ) ; pf -> fdir . fdir_vsi = NULL ; return err ; }
i40e_fdir_setup - reserve and initialize the Flow Director resources
 @pf: board private structure
i40e_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*/ /* need switch on before dev start*/ /* Init the rx queue in hardware */ /* switch on rx queue */ /* enable FDIR MSIX interrupt */ /* reserve memory for the fdir programming packet */