/* * Allocates a completion ring with vmem and stats optionally also allocating * a TX and/or RX ring. Passing NULL as tx_ring_info and/or rx_ring_info * to not allocate them. * * Order in the allocation is: * stats - Always non-zero length * cp vmem - Always zero-length, supported for the bnxt_ring abstraction * tx vmem - Only non-zero length if tx_ring_info is not NULL * rx vmem - Only non-zero length if rx_ring_info is not NULL * cp bd ring - Always non-zero length * tx bd ring - Only non-zero length if tx_ring_info is not NULL * rx bd ring - Only non-zero length if rx_ring_info is not NULL */ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx, struct bnxt_tx_ring_info *tx_ring_info, struct bnxt_rx_ring_info *rx_ring_info, struct bnxt_cp_ring_info *cp_ring_info, const char *suffix) { struct bnxt_ring *cp_ring = cp_ring_info->cp_ring_struct; struct bnxt_ring *tx_ring; struct bnxt_ring *rx_ring; struct rte_pci_device *pdev = bp->pdev; const struct rte_memzone *mz = NULL; char mz_name[RTE_MEMZONE_NAMESIZE]; rte_iova_t mz_phys_addr; int sz; int stats_len = (tx_ring_info || rx_ring_info) ? RTE_CACHE_LINE_ROUNDUP(sizeof(struct ctx_hw_stats64)) : 0; int cp_vmem_start = stats_len; int cp_vmem_len = RTE_CACHE_LINE_ROUNDUP(cp_ring->vmem_size); int tx_vmem_start = cp_vmem_start + cp_vmem_len; int tx_vmem_len = tx_ring_info ? RTE_CACHE_LINE_ROUNDUP(tx_ring_info-> tx_ring_struct->vmem_size) : 0; int rx_vmem_start = tx_vmem_start + tx_vmem_len; int rx_vmem_len = rx_ring_info ? RTE_CACHE_LINE_ROUNDUP(rx_ring_info-> rx_ring_struct->vmem_size) : 0; int ag_vmem_start = 0; int ag_vmem_len = 0; int cp_ring_start = 0; ag_vmem_start = rx_vmem_start + rx_vmem_len; ag_vmem_len = rx_ring_info ? RTE_CACHE_LINE_ROUNDUP( rx_ring_info->ag_ring_struct->vmem_size) : 0; cp_ring_start = ag_vmem_start + ag_vmem_len; int cp_ring_len = RTE_CACHE_LINE_ROUNDUP(cp_ring->ring_size * sizeof(struct cmpl_base)); int tx_ring_start = cp_ring_start + cp_ring_len; int tx_ring_len = tx_ring_info ? RTE_CACHE_LINE_ROUNDUP(tx_ring_info->tx_ring_struct->ring_size * sizeof(struct tx_bd_long)) : 0; int rx_ring_start = tx_ring_start + tx_ring_len; int rx_ring_len = rx_ring_info ? RTE_CACHE_LINE_ROUNDUP(rx_ring_info->rx_ring_struct->ring_size * sizeof(struct rx_prod_pkt_bd)) : 0; int ag_ring_start = rx_ring_start + rx_ring_len; int ag_ring_len = rx_ring_len * AGG_RING_SIZE_FACTOR; int ag_bitmap_start = ag_ring_start + ag_ring_len; int ag_bitmap_len = rx_ring_info ? RTE_CACHE_LINE_ROUNDUP(rte_bitmap_get_memory_footprint( rx_ring_info->rx_ring_struct->ring_size * AGG_RING_SIZE_FACTOR)) : 0; int tpa_info_start = ag_bitmap_start + ag_bitmap_len; int tpa_info_len = rx_ring_info ? RTE_CACHE_LINE_ROUNDUP(BNXT_TPA_MAX * sizeof(struct bnxt_tpa_info)) : 0; int total_alloc_len = tpa_info_start; if (bp->eth_dev->data->dev_conf.rxmode.enable_lro) total_alloc_len += tpa_info_len; snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "bnxt_%04x:%02x:%02x:%02x-%04x_%s", pdev->addr.domain, pdev->addr.bus, pdev->addr.devid, pdev->addr.function, qidx, suffix); mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0; mz = rte_memzone_lookup(mz_name); if (!mz) { mz = rte_memzone_reserve_aligned(mz_name, total_alloc_len, SOCKET_ID_ANY, RTE_MEMZONE_2MB | RTE_MEMZONE_SIZE_HINT_ONLY, getpagesize()); if (mz == NULL) return -ENOMEM; } memset(mz->addr, 0, mz->len); mz_phys_addr = mz->iova; if ((unsigned long)mz->addr == mz_phys_addr) { RTE_LOG(WARNING, PMD, "Memzone physical address same as virtual.\n"); RTE_LOG(WARNING, PMD, "Using rte_mem_virt2iova()\n"); for (sz = 0; sz < total_alloc_len; sz += getpagesize()) rte_mem_lock_page(((char *)mz->addr) + sz); mz_phys_addr = rte_mem_virt2iova(mz->addr); if (mz_phys_addr == 0) { RTE_LOG(ERR, PMD, "unable to map ring address to physical memory\n"); return -ENOMEM; } } if (tx_ring_info) { tx_ring = tx_ring_info->tx_ring_struct; tx_ring->bd = ((char *)mz->addr + tx_ring_start); tx_ring_info->tx_desc_ring = (struct tx_bd_long *)tx_ring->bd; tx_ring->bd_dma = mz_phys_addr + tx_ring_start; tx_ring_info->tx_desc_mapping = tx_ring->bd_dma; tx_ring->mem_zone = (const void *)mz; if (!tx_ring->bd) return -ENOMEM; if (tx_ring->vmem_size) { tx_ring->vmem = (void **)((char *)mz->addr + tx_vmem_start); tx_ring_info->tx_buf_ring = (struct bnxt_sw_tx_bd *)tx_ring->vmem; } } if (rx_ring_info) { rx_ring = rx_ring_info->rx_ring_struct; rx_ring->bd = ((char *)mz->addr + rx_ring_start); rx_ring_info->rx_desc_ring = (struct rx_prod_pkt_bd *)rx_ring->bd; rx_ring->bd_dma = mz_phys_addr + rx_ring_start; rx_ring_info->rx_desc_mapping = rx_ring->bd_dma; rx_ring->mem_zone = (const void *)mz; if (!rx_ring->bd) return -ENOMEM; if (rx_ring->vmem_size) { rx_ring->vmem = (void **)((char *)mz->addr + rx_vmem_start); rx_ring_info->rx_buf_ring = (struct bnxt_sw_rx_bd *)rx_ring->vmem; } rx_ring = rx_ring_info->ag_ring_struct; rx_ring->bd = ((char *)mz->addr + ag_ring_start); rx_ring_info->ag_desc_ring = (struct rx_prod_pkt_bd *)rx_ring->bd; rx_ring->bd_dma = mz->iova + ag_ring_start; rx_ring_info->ag_desc_mapping = rx_ring->bd_dma; rx_ring->mem_zone = (const void *)mz; if (!rx_ring->bd) return -ENOMEM; if (rx_ring->vmem_size) { rx_ring->vmem = (void **)((char *)mz->addr + ag_vmem_start); rx_ring_info->ag_buf_ring = (struct bnxt_sw_rx_bd *)rx_ring->vmem; } rx_ring_info->ag_bitmap = rte_bitmap_init(rx_ring_info->rx_ring_struct->ring_size * AGG_RING_SIZE_FACTOR, (uint8_t *)mz->addr + ag_bitmap_start, ag_bitmap_len); /* TPA info */ if (bp->eth_dev->data->dev_conf.rxmode.enable_lro) rx_ring_info->tpa_info = ((struct bnxt_tpa_info *)((char *)mz->addr + tpa_info_start)); } cp_ring->bd = ((char *)mz->addr + cp_ring_start); cp_ring->bd_dma = mz_phys_addr + cp_ring_start; cp_ring_info->cp_desc_ring = cp_ring->bd; cp_ring_info->cp_desc_mapping = cp_ring->bd_dma; cp_ring->mem_zone = (const void *)mz; if (!cp_ring->bd) return -ENOMEM; if (cp_ring->vmem_size) *cp_ring->vmem = ((char *)mz->addr + stats_len); if (stats_len) { cp_ring_info->hw_stats = mz->addr; cp_ring_info->hw_stats_map = mz_phys_addr; } cp_ring_info->hw_stats_ctx_id = HWRM_NA_SIGNATURE; return 0; }
int rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) { struct bond_dev_private *internals = NULL; struct rte_eth_dev *eth_dev = NULL; uint32_t vlan_filter_bmp_size; /* now do all data allocation - for eth_dev structure, dummy pci driver * and internal (private) data */ if (name == NULL) { RTE_BOND_LOG(ERR, "Invalid name specified"); goto err; } if (socket_id >= number_of_sockets()) { RTE_BOND_LOG(ERR, "Invalid socket id specified to create bonded device on."); goto err; } internals = rte_zmalloc_socket(name, sizeof(*internals), 0, socket_id); if (internals == NULL) { RTE_BOND_LOG(ERR, "Unable to malloc internals on socket"); goto err; } /* reserve an ethdev entry */ eth_dev = rte_eth_dev_allocate(name); if (eth_dev == NULL) { RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev"); goto err; } eth_dev->data->dev_private = internals; eth_dev->data->nb_rx_queues = (uint16_t)1; eth_dev->data->nb_tx_queues = (uint16_t)1; eth_dev->data->mac_addrs = rte_zmalloc_socket(name, ETHER_ADDR_LEN, 0, socket_id); if (eth_dev->data->mac_addrs == NULL) { RTE_BOND_LOG(ERR, "Unable to malloc mac_addrs"); goto err; } eth_dev->dev_ops = &default_dev_ops; eth_dev->data->dev_flags = RTE_ETH_DEV_INTR_LSC | RTE_ETH_DEV_DETACHABLE; eth_dev->driver = NULL; eth_dev->data->kdrv = RTE_KDRV_NONE; eth_dev->data->drv_name = pmd_bond_drv.driver.name; eth_dev->data->numa_node = socket_id; rte_spinlock_init(&internals->lock); internals->port_id = eth_dev->data->port_id; internals->mode = BONDING_MODE_INVALID; internals->current_primary_port = RTE_MAX_ETHPORTS + 1; internals->balance_xmit_policy = BALANCE_XMIT_POLICY_LAYER2; internals->xmit_hash = xmit_l2_hash; internals->user_defined_mac = 0; internals->link_props_set = 0; internals->link_status_polling_enabled = 0; internals->link_status_polling_interval_ms = DEFAULT_POLLING_INTERVAL_10_MS; internals->link_down_delay_ms = 0; internals->link_up_delay_ms = 0; internals->slave_count = 0; internals->active_slave_count = 0; internals->rx_offload_capa = 0; internals->tx_offload_capa = 0; internals->candidate_max_rx_pktlen = 0; internals->max_rx_pktlen = 0; /* Initially allow to choose any offload type */ internals->flow_type_rss_offloads = ETH_RSS_PROTO_MASK; memset(internals->active_slaves, 0, sizeof(internals->active_slaves)); memset(internals->slaves, 0, sizeof(internals->slaves)); /* Set mode 4 default configuration */ bond_mode_8023ad_setup(eth_dev, NULL); if (bond_ethdev_mode_set(eth_dev, mode)) { RTE_BOND_LOG(ERR, "Failed to set bonded device %d mode too %d", eth_dev->data->port_id, mode); goto err; } vlan_filter_bmp_size = rte_bitmap_get_memory_footprint(ETHER_MAX_VLAN_ID + 1); internals->vlan_filter_bmpmem = rte_malloc(name, vlan_filter_bmp_size, RTE_CACHE_LINE_SIZE); if (internals->vlan_filter_bmpmem == NULL) { RTE_BOND_LOG(ERR, "Failed to allocate vlan bitmap for bonded device %u\n", eth_dev->data->port_id); goto err; } internals->vlan_filter_bmp = rte_bitmap_init(ETHER_MAX_VLAN_ID + 1, internals->vlan_filter_bmpmem, vlan_filter_bmp_size); if (internals->vlan_filter_bmp == NULL) { RTE_BOND_LOG(ERR, "Failed to init vlan bitmap for bonded device %u\n", eth_dev->data->port_id); rte_free(internals->vlan_filter_bmpmem); goto err; } return eth_dev->data->port_id; err: rte_free(internals); if (eth_dev != NULL) { rte_free(eth_dev->data->mac_addrs); rte_eth_dev_release_port(eth_dev); } return -1; }