src/dpdk/drivers/net/bnxt/bnxt_ethdev.c
static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
{
	struct bnxt *bp = eth_dev->data->dev_private;
	uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
	int rc;

	bp->rx_queues = (void *)eth_dev->data->rx_queues;
	bp->tx_queues = (void *)eth_dev->data->tx_queues;
	bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
	bp->rx_nr_rings = eth_dev->data->nb_rx_queues;

	rc = is_bnxt_in_error(bp);
	if (rc)
		return rc;

	if (BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)) {
		rc = bnxt_hwrm_check_vf_rings(bp);
		if (rc) {
			PMD_DRV_LOG(ERR, "HWRM insufficient resources\n");
			return -ENOSPC;
		}

		/* If a resource has already been allocated - in this case
		 * it is the async completion ring, free it. Reallocate it after
		 * resource reservation. This will ensure the resource counts
		 * are calculated correctly.
		 */

		pthread_mutex_lock(&bp->def_cp_lock);

		if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
			bnxt_disable_int(bp);
			bnxt_free_cp_ring(bp, bp->async_cp_ring);
		}

		rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
		if (rc) {
			PMD_DRV_LOG(ERR, "HWRM resource alloc fail:%x\n", rc);
			pthread_mutex_unlock(&bp->def_cp_lock);
			return -ENOSPC;
		}

		if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
			rc = bnxt_alloc_async_cp_ring(bp);
			if (rc) {
				pthread_mutex_unlock(&bp->def_cp_lock);
				return rc;
			}
			bnxt_enable_int(bp);
		}

		pthread_mutex_unlock(&bp->def_cp_lock);
	}

	/* Inherit new configurations */
	if (eth_dev->data->nb_rx_queues > bp->max_rx_rings ||
	    eth_dev->data->nb_tx_queues > bp->max_tx_rings ||
	    eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues
		+ BNXT_NUM_ASYNC_CPR(bp) > bp->max_cp_rings ||
	    eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues >
	    bp->max_stat_ctx)
		goto resource_error;

	if (BNXT_HAS_RING_GRPS(bp) &&
	    (uint32_t)(eth_dev->data->nb_rx_queues) > bp->max_ring_grps)
		goto resource_error;

	if (!(eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS) &&
	    bp->max_vnics < eth_dev->data->nb_rx_queues)
		goto resource_error;

	bp->rx_cp_nr_rings = bp->rx_nr_rings;
	bp->tx_cp_nr_rings = bp->tx_nr_rings;

	if (eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
		rx_offloads |= DEV_RX_OFFLOAD_RSS_HASH;
	eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;

	if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
		eth_dev->data->mtu =
			eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
			RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN - VLAN_TAG_SIZE *
			BNXT_NUM_VLANS;
		bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
	}
	return 0;

resource_error:
	PMD_DRV_LOG(ERR,
		    "Insufficient resources to support requested config\n");
	PMD_DRV_LOG(ERR,
		    "Num Queues Requested: Tx %d, Rx %d\n",
		    eth_dev->data->nb_tx_queues,
		    eth_dev->data->nb_rx_queues);
	PMD_DRV_LOG(ERR,
		    "MAX: TxQ %d, RxQ %d, CQ %d Stat %d, Grp %d, Vnic %d\n",
		    bp->max_tx_rings, bp->max_rx_rings, bp->max_cp_rings,
		    bp->max_stat_ctx, bp->max_ring_grps, bp->max_vnics);
	return -ENOSPC;
}
/* Configure the device based on the configuration provided */
Configure the device based on the configuration provided
Configure the device based on the configuration provided
static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
{
	struct bnxt *bp = eth_dev->data->dev_private;
	uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
	int rc;
	bp->rx_queues = (void *)eth_dev->data->rx_queues;
	bp->tx_queues = (void *)eth_dev->data->tx_queues;
	bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
	bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
	rc = is_bnxt_in_error(bp);
	if (rc)
		return rc;
	if (BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)) {
		rc = bnxt_hwrm_check_vf_rings(bp);
		if (rc) {
			PMD_DRV_LOG(ERR, "HWRM insufficient resources\n");
			return -ENOSPC;
		}
		pthread_mutex_lock(&bp->def_cp_lock);
		if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
			bnxt_disable_int(bp);
			bnxt_free_cp_ring(bp, bp->async_cp_ring);
		}
		rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
		if (rc) {
			PMD_DRV_LOG(ERR, "HWRM resource alloc fail:%x\n", rc);
			pthread_mutex_unlock(&bp->def_cp_lock);
			return -ENOSPC;
		}
		if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
			rc = bnxt_alloc_async_cp_ring(bp);
			if (rc) {
				pthread_mutex_unlock(&bp->def_cp_lock);
				return rc;
			}
			bnxt_enable_int(bp);
		}
		pthread_mutex_unlock(&bp->def_cp_lock);
	}
	if (eth_dev->data->nb_rx_queues > bp->max_rx_rings ||
	    eth_dev->data->nb_tx_queues > bp->max_tx_rings ||
	    eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues
		+ BNXT_NUM_ASYNC_CPR(bp) > bp->max_cp_rings ||
	    eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues >
	    bp->max_stat_ctx)
		goto resource_error;
	if (BNXT_HAS_RING_GRPS(bp) &&
	    (uint32_t)(eth_dev->data->nb_rx_queues) > bp->max_ring_grps)
		goto resource_error;
	if (!(eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS) &&
	    bp->max_vnics < eth_dev->data->nb_rx_queues)
		goto resource_error;
	bp->rx_cp_nr_rings = bp->rx_nr_rings;
	bp->tx_cp_nr_rings = bp->tx_nr_rings;
	if (eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
		rx_offloads |= DEV_RX_OFFLOAD_RSS_HASH;
	eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;
	if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
		eth_dev->data->mtu =
			eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
			RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN - VLAN_TAG_SIZE *
			BNXT_NUM_VLANS;
		bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
	}
	return 0;
resource_error:
	PMD_DRV_LOG(ERR,
		    "Insufficient resources to support requested config\n");
	PMD_DRV_LOG(ERR,
		    "Num Queues Requested: Tx %d, Rx %d\n",
		    eth_dev->data->nb_tx_queues,
		    eth_dev->data->nb_rx_queues);
	PMD_DRV_LOG(ERR,
		    "MAX: TxQ %d, RxQ %d, CQ %d Stat %d, Grp %d, Vnic %d\n",
		    bp->max_tx_rings, bp->max_rx_rings, bp->max_cp_rings,
		    bp->max_stat_ctx, bp->max_ring_grps, bp->max_vnics);
	return -ENOSPC;
}
static int bnxt_dev_configure_op ( struct rte_eth_dev * eth_dev ) { struct bnxt * bp = eth_dev -> data -> dev_private ; uint64_t rx_offloads = eth_dev -> data -> dev_conf . rxmode . offloads ; int rc ; bp -> rx_queues = ( void * ) eth_dev -> data -> rx_queues ; bp -> tx_queues = ( void * ) eth_dev -> data -> tx_queues ; bp -> tx_nr_rings = eth_dev -> data -> nb_tx_queues ; bp -> rx_nr_rings = eth_dev -> data -> nb_rx_queues ; rc = is_bnxt_in_error ( bp ) ; if ( rc ) return rc ; if ( BNXT_VF ( bp ) && ( bp -> flags & BNXT_FLAG_NEW_RM ) ) { rc = bnxt_hwrm_check_vf_rings ( bp ) ; if ( rc ) { PMD_DRV_LOG ( ERR , " \n " ) ; return - ENOSPC ; } pthread_mutex_lock ( & bp -> def_cp_lock ) ; if ( ! BNXT_HAS_NQ ( bp ) && bp -> async_cp_ring ) { bnxt_disable_int ( bp ) ; bnxt_free_cp_ring ( bp , bp -> async_cp_ring ) ; } rc = bnxt_hwrm_func_reserve_vf_resc ( bp , false ) ; if ( rc ) { PMD_DRV_LOG ( ERR , " \n " , rc ) ; pthread_mutex_unlock ( & bp -> def_cp_lock ) ; return - ENOSPC ; } if ( ! BNXT_HAS_NQ ( bp ) && bp -> async_cp_ring ) { rc = bnxt_alloc_async_cp_ring ( bp ) ; if ( rc ) { pthread_mutex_unlock ( & bp -> def_cp_lock ) ; return rc ; } bnxt_enable_int ( bp ) ; } pthread_mutex_unlock ( & bp -> def_cp_lock ) ; } if ( eth_dev -> data -> nb_rx_queues > bp -> max_rx_rings || eth_dev -> data -> nb_tx_queues > bp -> max_tx_rings || eth_dev -> data -> nb_rx_queues + eth_dev -> data -> nb_tx_queues + BNXT_NUM_ASYNC_CPR ( bp ) > bp -> max_cp_rings || eth_dev -> data -> nb_rx_queues + eth_dev -> data -> nb_tx_queues > bp -> max_stat_ctx ) goto resource_error ; if ( BNXT_HAS_RING_GRPS ( bp ) && ( uint32_t ) ( eth_dev -> data -> nb_rx_queues ) > bp -> max_ring_grps ) goto resource_error ; if ( ! ( eth_dev -> data -> dev_conf . rxmode . mq_mode & ETH_MQ_RX_RSS ) && bp -> max_vnics < eth_dev -> data -> nb_rx_queues ) goto resource_error ; bp -> rx_cp_nr_rings = bp -> rx_nr_rings ; bp -> tx_cp_nr_rings = bp -> tx_nr_rings ; if ( eth_dev -> data -> dev_conf . rxmode . mq_mode & ETH_MQ_RX_RSS_FLAG ) rx_offloads |= DEV_RX_OFFLOAD_RSS_HASH ; eth_dev -> data -> dev_conf . rxmode . offloads = rx_offloads ; if ( rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME ) { eth_dev -> data -> mtu = eth_dev -> data -> dev_conf . rxmode . max_rx_pkt_len - RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN - VLAN_TAG_SIZE * BNXT_NUM_VLANS ; bnxt_mtu_set_op ( eth_dev , eth_dev -> data -> mtu ) ; } return 0 ; resource_error : PMD_DRV_LOG ( ERR , " \n " ) ; PMD_DRV_LOG ( ERR , " \n " , eth_dev -> data -> nb_tx_queues , eth_dev -> data -> nb_rx_queues ) ; PMD_DRV_LOG ( ERR , " \n " , bp -> max_tx_rings , bp -> max_rx_rings , bp -> max_cp_rings , bp -> max_stat_ctx , bp -> max_ring_grps , bp -> max_vnics ) ; return - ENOSPC ; }
Configure the device based on the configuration provided
Configure the device based on the configuration provided
/* If a resource has already been allocated - in this case
		 * it is the async completion ring, free it. Reallocate it after
		 * resource reservation. This will ensure the resource counts
		 * are calculated correctly.
		 */ /* Inherit new configurations */