aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-09-30 18:26:20 +0200
committerDamjan Marion <dmarion@me.com>2018-10-23 14:21:10 +0000
commit68b4da67deb2e8ca224bb5abaeb9dbc7ae8e378c (patch)
treecd1ee2c463aefdb31c73665eafb876568054f49e /src/plugins
parentfc3b8b8ad08d2d4cc375149ecdc10c37d4a80940 (diff)
Numa-aware, growable physical memory allocator (pmalloc)
Change-Id: Ic4c46bc733afae8bf0d8146623ed15633928de30 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/avf/avf.h4
-rw-r--r--src/plugins/avf/device.c103
-rw-r--r--src/plugins/avf/input.c12
-rw-r--r--src/plugins/avf/output.c4
-rw-r--r--src/plugins/dpdk/buffer.c34
-rw-r--r--src/plugins/dpdk/device/dpdk.h3
-rw-r--r--src/plugins/dpdk/ipsec/ipsec.c21
-rw-r--r--src/plugins/ixge/ixge.c35
-rw-r--r--src/plugins/ixge/ixge.h2
-rw-r--r--src/plugins/memif/memif.c10
-rw-r--r--src/plugins/vmxnet3/vmxnet3.c73
-rw-r--r--src/plugins/vmxnet3/vmxnet3.h6
12 files changed, 137 insertions, 170 deletions
diff --git a/src/plugins/avf/avf.h b/src/plugins/avf/avf.h
index 187e5c2cd69..4fa19b11b73 100644
--- a/src/plugins/avf/avf.h
+++ b/src/plugins/avf/avf.h
@@ -26,7 +26,7 @@
_(0, INITIALIZED, "initialized") \
_(1, ERROR, "error") \
_(2, ADMIN_UP, "admin-up") \
- _(3, IOVA, "iova") \
+ _(3, VA_DMA, "vaddr-dma") \
_(4, LINK_UP, "link-up") \
_(5, SHARED_TXQ_LOCK, "shared-txq-lock") \
_(6, ELOG, "elog")
@@ -188,8 +188,6 @@ typedef struct
avf_device_t *devices;
avf_per_thread_data_t *per_thread_data;
- vlib_physmem_region_index_t physmem_region;
- int physmem_region_alloc;
vlib_log_class_t log_class;
diff --git a/src/plugins/avf/device.c b/src/plugins/avf/device.c
index 914c32cab4b..713953fe4c6 100644
--- a/src/plugins/avf/device.c
+++ b/src/plugins/avf/device.c
@@ -215,18 +215,23 @@ avf_cmd_rx_ctl_reg_write (vlib_main_t * vm, avf_device_t * ad, u32 reg,
clib_error_t *
avf_rxq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 rxq_size)
{
- avf_main_t *am = &avf_main;
+ clib_error_t *err;
avf_rxq_t *rxq;
- clib_error_t *error = 0;
u32 n_alloc, i;
vec_validate_aligned (ad->rxqs, qid, CLIB_CACHE_LINE_BYTES);
rxq = vec_elt_at_index (ad->rxqs, qid);
rxq->size = rxq_size;
rxq->next = 0;
- rxq->descs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
- rxq->size * sizeof (avf_rx_desc_t),
+ rxq->descs = vlib_physmem_alloc_aligned (vm, rxq->size *
+ sizeof (avf_rx_desc_t),
2 * CLIB_CACHE_LINE_BYTES);
+ if (rxq->descs == 0)
+ return vlib_physmem_last_error (vm);
+
+ if ((err = vlib_pci_map_dma (vm, ad->pci_dev_handle, (void *) rxq->descs)))
+ return err;
+
clib_memset ((void *) rxq->descs, 0, rxq->size * sizeof (avf_rx_desc_t));
vec_validate_aligned (rxq->bufs, rxq->size, CLIB_CACHE_LINE_BYTES);
rxq->qrx_tail = ad->bar0 + AVF_QRX_TAIL (qid);
@@ -241,7 +246,7 @@ avf_rxq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 rxq_size)
for (i = 0; i < n_alloc; i++)
{
vlib_buffer_t *b = vlib_get_buffer (vm, rxq->bufs[i]);
- if (ad->flags & AVF_DEVICE_F_IOVA)
+ if (ad->flags & AVF_DEVICE_F_VA_DMA)
d->qword[0] = vlib_buffer_get_va (b);
else
d->qword[0] = vlib_buffer_get_pa (vm, b);
@@ -255,9 +260,8 @@ avf_rxq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 rxq_size)
clib_error_t *
avf_txq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 txq_size)
{
- avf_main_t *am = &avf_main;
+ clib_error_t *err;
avf_txq_t *txq;
- clib_error_t *error = 0;
if (qid >= ad->num_queue_pairs)
{
@@ -273,9 +277,15 @@ avf_txq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 txq_size)
txq = vec_elt_at_index (ad->txqs, qid);
txq->size = txq_size;
txq->next = 0;
- txq->descs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
- txq->size * sizeof (avf_tx_desc_t),
+ txq->descs = vlib_physmem_alloc_aligned (vm, txq->size *
+ sizeof (avf_tx_desc_t),
2 * CLIB_CACHE_LINE_BYTES);
+ if (txq->descs == 0)
+ return vlib_physmem_last_error (vm);
+
+ if ((err = vlib_pci_map_dma (vm, ad->pci_dev_handle, (void *) txq->descs)))
+ return err;
+
vec_validate_aligned (txq->bufs, txq->size, CLIB_CACHE_LINE_BYTES);
txq->qtx_tail = ad->bar0 + AVF_QTX_TAIL (qid);
@@ -305,10 +315,8 @@ avf_arq_slot_init (avf_device_t * ad, u16 slot)
static inline uword
avf_dma_addr (vlib_main_t * vm, avf_device_t * ad, void *p)
{
- avf_main_t *am = &avf_main;
- return (ad->flags & AVF_DEVICE_F_IOVA) ?
- pointer_to_uword (p) :
- vlib_physmem_virtual_to_physical (vm, am->physmem_region, p);
+ return (ad->flags & AVF_DEVICE_F_VA_DMA) ?
+ pointer_to_uword (p) : vlib_physmem_get_pa (vm, p);
}
static void
@@ -1126,16 +1134,16 @@ avf_delete_if (vlib_main_t * vm, avf_device_t * ad)
vlib_pci_device_close (vm, ad->pci_dev_handle);
- vlib_physmem_free (vm, am->physmem_region, ad->atq);
- vlib_physmem_free (vm, am->physmem_region, ad->arq);
- vlib_physmem_free (vm, am->physmem_region, ad->atq_bufs);
- vlib_physmem_free (vm, am->physmem_region, ad->arq_bufs);
+ vlib_physmem_free (vm, ad->atq);
+ vlib_physmem_free (vm, ad->arq);
+ vlib_physmem_free (vm, ad->atq_bufs);
+ vlib_physmem_free (vm, ad->arq_bufs);
/* *INDENT-OFF* */
vec_foreach_index (i, ad->rxqs)
{
avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, i);
- vlib_physmem_free (vm, am->physmem_region, (void *) rxq->descs);
+ vlib_physmem_free (vm, (void *) rxq->descs);
if (rxq->n_enqueued)
vlib_buffer_free_from_ring (vm, rxq->bufs, rxq->next, rxq->size,
rxq->n_enqueued);
@@ -1148,7 +1156,7 @@ avf_delete_if (vlib_main_t * vm, avf_device_t * ad)
vec_foreach_index (i, ad->txqs)
{
avf_txq_t *txq = vec_elt_at_index (ad->txqs, i);
- vlib_physmem_free (vm, am->physmem_region, (void *) txq->descs);
+ vlib_physmem_free (vm, (void *) txq->descs);
if (txq->n_enqueued)
{
u16 first = (txq->next - txq->n_enqueued) & (txq->size -1);
@@ -1226,44 +1234,51 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
goto error;
- if (am->physmem_region_alloc == 0)
+ if (!(ad->atq = vlib_physmem_alloc (vm, sizeof (avf_aq_desc_t) *
+ AVF_MBOX_LEN)))
{
- u32 flags = VLIB_PHYSMEM_F_INIT_MHEAP | VLIB_PHYSMEM_F_HUGETLB;
- error = vlib_physmem_region_alloc (vm, "avf descriptors", 4 << 20, 0,
- flags, &am->physmem_region);
- if (error)
- goto error;
- am->physmem_region_alloc = 1;
+ error = vlib_physmem_last_error (vm);
+ goto error;
}
- ad->atq = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
- sizeof (avf_aq_desc_t) * AVF_MBOX_LEN,
- 64);
- if (error)
+
+ if ((error = vlib_pci_map_dma (vm, h, ad->atq)))
goto error;
- ad->arq = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
- sizeof (avf_aq_desc_t) * AVF_MBOX_LEN,
- 64);
- if (error)
+ if (!(ad->arq = vlib_physmem_alloc (vm, sizeof (avf_aq_desc_t) *
+ AVF_MBOX_LEN)))
+ {
+ error = vlib_physmem_last_error (vm);
+ goto error;
+ }
+
+ if ((error = vlib_pci_map_dma (vm, h, ad->arq)))
goto error;
- ad->atq_bufs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
- AVF_MBOX_BUF_SZ * AVF_MBOX_LEN,
- 64);
- if (error)
+ if (!(ad->atq_bufs = vlib_physmem_alloc (vm, AVF_MBOX_BUF_SZ *
+ AVF_MBOX_LEN)))
+ {
+ error = vlib_physmem_last_error (vm);
+ goto error;
+ }
+
+ if ((error = vlib_pci_map_dma (vm, h, ad->atq_bufs)))
goto error;
- ad->arq_bufs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
- AVF_MBOX_BUF_SZ * AVF_MBOX_LEN,
- 64);
- if (error)
+ if (!(ad->arq_bufs = vlib_physmem_alloc (vm, AVF_MBOX_BUF_SZ *
+ AVF_MBOX_LEN)))
+ {
+ error = vlib_physmem_last_error (vm);
+ goto error;
+ }
+
+ if ((error = vlib_pci_map_dma (vm, h, ad->arq_bufs)))
goto error;
if ((error = vlib_pci_intr_enable (vm, h)))
goto error;
- /* FIXME detect */
- ad->flags |= AVF_DEVICE_F_IOVA;
+ if (vlib_pci_supports_virtual_addr_dma (vm, h))
+ ad->flags |= AVF_DEVICE_F_VA_DMA;
if ((error = avf_device_init (vm, am, ad, args)))
goto error;
diff --git a/src/plugins/avf/input.c b/src/plugins/avf/input.c
index efe3b0e0251..6d39ed646b5 100644
--- a/src/plugins/avf/input.c
+++ b/src/plugins/avf/input.c
@@ -48,7 +48,7 @@ static __clib_unused char *avf_input_error_strings[] = {
#define AVF_INPUT_REFILL_TRESHOLD 32
static_always_inline void
avf_rxq_refill (vlib_main_t * vm, vlib_node_runtime_t * node, avf_rxq_t * rxq,
- int use_iova)
+ int use_va_dma)
{
u16 n_refill, mask, n_alloc, slot;
u32 s0, s1, s2, s3;
@@ -103,7 +103,7 @@ avf_rxq_refill (vlib_main_t * vm, vlib_node_runtime_t * node, avf_rxq_t * rxq,
b[2] = vlib_get_buffer (vm, rxq->bufs[s2]);
b[3] = vlib_get_buffer (vm, rxq->bufs[s3]);
- if (use_iova)
+ if (use_va_dma)
{
d[0]->qword[0] = vlib_buffer_get_va (b[0]);
d[1]->qword[0] = vlib_buffer_get_va (b[1]);
@@ -132,7 +132,7 @@ avf_rxq_refill (vlib_main_t * vm, vlib_node_runtime_t * node, avf_rxq_t * rxq,
s0 = slot;
d[0] = ((avf_rx_desc_t *) rxq->descs) + s0;
b[0] = vlib_get_buffer (vm, rxq->bufs[s0]);
- if (use_iova)
+ if (use_va_dma)
d[0]->qword[0] = vlib_buffer_get_va (b[0]);
else
d[0]->qword[0] = vlib_buffer_get_pa (vm, b[0]);
@@ -433,10 +433,10 @@ avf_device_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
goto done;
/* refill rx ring */
- if (ad->flags & AVF_DEVICE_F_IOVA)
- avf_rxq_refill (vm, node, rxq, 1 /* use_iova */ );
+ if (ad->flags & AVF_DEVICE_F_VA_DMA)
+ avf_rxq_refill (vm, node, rxq, 1 /* use_va_dma */ );
else
- avf_rxq_refill (vm, node, rxq, 0 /* use_iova */ );
+ avf_rxq_refill (vm, node, rxq, 0 /* use_va_dma */ );
vlib_get_buffers (vm, buffer_indices, bufs, n_rxv);
n_rx_packets = n_rxv;
diff --git a/src/plugins/avf/output.c b/src/plugins/avf/output.c
index c2c4b01d022..72892d16dff 100644
--- a/src/plugins/avf/output.c
+++ b/src/plugins/avf/output.c
@@ -118,7 +118,7 @@ retry:
b2 = vlib_get_buffer (vm, bi2);
b3 = vlib_get_buffer (vm, bi3);
- if (ad->flags & AVF_DEVICE_F_IOVA)
+ if (ad->flags & AVF_DEVICE_F_VA_DMA)
{
d0->qword[0] = vlib_buffer_get_current_va (b0);
d1->qword[0] = vlib_buffer_get_current_va (b1);
@@ -151,7 +151,7 @@ retry:
txq->bufs[next] = bi0;
b0 = vlib_get_buffer (vm, bi0);
- if (ad->flags & AVF_DEVICE_F_IOVA)
+ if (ad->flags & AVF_DEVICE_F_VA_DMA)
d0->qword[0] = vlib_buffer_get_current_va (b0);
else
d0->qword[0] = vlib_buffer_get_current_pa (vm, b0);
diff --git a/src/plugins/dpdk/buffer.c b/src/plugins/dpdk/buffer.c
index f7ed932e35f..770e76d398e 100644
--- a/src/plugins/dpdk/buffer.c
+++ b/src/plugins/dpdk/buffer.c
@@ -393,12 +393,12 @@ dpdk_packet_template_init (vlib_main_t * vm,
clib_error_t *
dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
u32 num_elts, u32 pool_priv_size, u16 cache_size, u8 numa,
- struct rte_mempool **_mp, vlib_physmem_region_index_t * pri)
+ struct rte_mempool **_mp, u32 * map_index)
{
struct rte_mempool *mp;
enum rte_iova_mode iova_mode;
- vlib_physmem_region_t *pr;
dpdk_mempool_private_t priv;
+ vlib_physmem_map_t *pm;
clib_error_t *error = 0;
size_t min_chunk_size, align;
int map_dma = 1;
@@ -406,7 +406,6 @@ dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
i32 ret;
uword i;
-
mp = rte_mempool_create_empty ((char *) pool_name, num_elts, elt_size,
512, pool_priv_size, numa, 0);
if (!mp)
@@ -417,16 +416,13 @@ dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
size = rte_mempool_op_calc_mem_size_default (mp, num_elts, 21,
&min_chunk_size, &align);
- error = vlib_physmem_region_alloc (vm, (char *) pool_name, size, numa,
- VLIB_PHYSMEM_F_HUGETLB |
- VLIB_PHYSMEM_F_SHARED, pri);
- if (error)
+ if ((error = vlib_physmem_shared_map_create (vm, (char *) pool_name, size,
+ numa, map_index)))
{
rte_mempool_free (mp);
return error;
}
-
- pr = vlib_physmem_get_region (vm, pri[0]);
+ pm = vlib_physmem_get_map (vm, *map_index);
/* Call the mempool priv initializer */
priv.mbp_priv.mbuf_data_room_size = VLIB_BUFFER_PRE_DATA_SIZE +
@@ -438,12 +434,12 @@ dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
map_dma = 0;
iova_mode = rte_eal_iova_mode ();
- for (i = 0; i < pr->n_pages; i++)
+ for (i = 0; i < pm->n_pages; i++)
{
- size_t page_sz = 1ull << pr->log2_page_size;
- char *va = ((char *) pr->mem) + i * page_sz;
+ size_t page_sz = 1ULL << pm->log2_page_size;
+ char *va = ((char *) pm->base) + i * page_sz;
uword pa = iova_mode == RTE_IOVA_VA ?
- pointer_to_uword (va) : pr->page_table[i];
+ pointer_to_uword (va) : pm->page_table[i];
ret = rte_mempool_populate_iova (mp, va, pa, page_sz, 0, 0);
if (ret < 0)
{
@@ -467,10 +463,10 @@ dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
{
dpdk_main_t *dm = &dpdk_main;
struct rte_mempool *rmp;
- vlib_physmem_region_index_t pri;
clib_error_t *error = 0;
u8 *pool_name;
u32 elt_size, i;
+ u32 map_index;
vec_validate_aligned (dm->pktmbuf_pools, socket_id, CLIB_CACHE_LINE_BYTES);
@@ -484,10 +480,9 @@ dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
VLIB_BUFFER_HDR_SIZE /* priv size */ +
VLIB_BUFFER_PRE_DATA_SIZE + VLIB_BUFFER_DATA_SIZE; /*data room size */
- error =
- dpdk_pool_create (vm, pool_name, elt_size, num_mbufs,
- sizeof (dpdk_mempool_private_t), 512, socket_id,
- &rmp, &pri);
+ error = dpdk_pool_create (vm, pool_name, elt_size, num_mbufs,
+ sizeof (dpdk_mempool_private_t), 512, socket_id,
+ &rmp, &map_index);
vec_free (pool_name);
@@ -497,7 +492,8 @@ dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
rte_mempool_obj_iter (rmp, rte_pktmbuf_init, 0);
dpdk_mempool_private_t *privp = rte_mempool_get_priv (rmp);
- privp->buffer_pool_index = vlib_buffer_pool_create (vm, pri, 0);
+ privp->buffer_pool_index =
+ vlib_buffer_register_physmem_map (vm, map_index);
dm->pktmbuf_pools[socket_id] = rmp;
diff --git a/src/plugins/dpdk/device/dpdk.h b/src/plugins/dpdk/device/dpdk.h
index c4f908ea408..46d53f1d895 100644
--- a/src/plugins/dpdk/device/dpdk.h
+++ b/src/plugins/dpdk/device/dpdk.h
@@ -527,8 +527,7 @@ clib_error_t *unformat_hqos (unformat_input_t * input,
clib_error_t *dpdk_pool_create (vlib_main_t * vm, u8 * pool_name,
u32 elt_size, u32 num_elts,
u32 pool_priv_size, u16 cache_size, u8 numa,
- struct rte_mempool **_mp,
- vlib_physmem_region_index_t * pri);
+ struct rte_mempool **_mp, u32 * map_index);
clib_error_t *dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
unsigned socket_id);
diff --git a/src/plugins/dpdk/ipsec/ipsec.c b/src/plugins/dpdk/ipsec/ipsec.c
index ded8912e943..bcc4b62ad76 100644
--- a/src/plugins/dpdk/ipsec/ipsec.c
+++ b/src/plugins/dpdk/ipsec/ipsec.c
@@ -827,7 +827,7 @@ crypto_create_crypto_op_pool (vlib_main_t * vm, u8 numa)
struct rte_crypto_op_pool_private *priv;
struct rte_mempool *mp;
clib_error_t *error = NULL;
- vlib_physmem_region_index_t pri;
+ u32 map_index;
data = vec_elt_at_index (dcm->data, numa);
@@ -837,9 +837,8 @@ crypto_create_crypto_op_pool (vlib_main_t * vm, u8 numa)
pool_name = format (0, "crypto_pool_numa%u%c", numa, 0);
- error =
- dpdk_pool_create (vm, pool_name, crypto_op_len (), conf->num_mbufs,
- pool_priv_size, 512, numa, &mp, &pri);
+ error = dpdk_pool_create (vm, pool_name, crypto_op_len (), conf->num_mbufs,
+ pool_priv_size, 512, numa, &mp, &map_index);
vec_free (pool_name);
@@ -867,8 +866,8 @@ crypto_create_session_h_pool (vlib_main_t * vm, u8 numa)
u8 *pool_name;
struct rte_mempool *mp;
clib_error_t *error = NULL;
- vlib_physmem_region_index_t pri;
u32 elt_size;
+ u32 map_index;
data = vec_elt_at_index (dcm->data, numa);
@@ -880,9 +879,8 @@ crypto_create_session_h_pool (vlib_main_t * vm, u8 numa)
elt_size = rte_cryptodev_sym_get_header_session_size ();
- error =
- dpdk_pool_create (vm, pool_name, elt_size, DPDK_CRYPTO_NB_SESS_OBJS,
- 0, 512, numa, &mp, &pri);
+ error = dpdk_pool_create (vm, pool_name, elt_size, DPDK_CRYPTO_NB_SESS_OBJS,
+ 0, 512, numa, &mp, &map_index);
vec_free (pool_name);
@@ -902,9 +900,9 @@ crypto_create_session_drv_pool (vlib_main_t * vm, crypto_dev_t * dev)
u8 *pool_name;
struct rte_mempool *mp;
clib_error_t *error = NULL;
- vlib_physmem_region_index_t pri;
u32 elt_size;
u8 numa = dev->numa;
+ u32 map_index;
data = vec_elt_at_index (dcm->data, numa);
@@ -920,9 +918,8 @@ crypto_create_session_drv_pool (vlib_main_t * vm, crypto_dev_t * dev)
elt_size = rte_cryptodev_sym_get_private_session_size (dev->id);
- error =
- dpdk_pool_create (vm, pool_name, elt_size, DPDK_CRYPTO_NB_SESS_OBJS,
- 0, 512, numa, &mp, &pri);
+ error = dpdk_pool_create (vm, pool_name, elt_size, DPDK_CRYPTO_NB_SESS_OBJS,
+ 0, 512, numa, &mp, &map_index);
vec_free (pool_name);
diff --git a/src/plugins/ixge/ixge.c b/src/plugins/ixge/ixge.c
index 3c4a5b4bbfc..5dc22bed3a5 100644
--- a/src/plugins/ixge/ixge.c
+++ b/src/plugins/ixge/ixge.c
@@ -2488,13 +2488,11 @@ ixge_dma_init (ixge_device_t * xd, vlib_rx_or_tx_t rt, u32 queue_index)
round_pow2 (xm->n_descriptors[rt], xm->n_descriptors_per_cache_line);
dq->head_index = dq->tail_index = 0;
- dq->descriptors =
- vlib_physmem_alloc_aligned (vm, xm->physmem_region, &error,
- dq->n_descriptors *
- sizeof (dq->descriptors[0]),
- 128 /* per chip spec */ );
- if (error)
- return error;
+ dq->descriptors = vlib_physmem_alloc_aligned (vm, dq->n_descriptors *
+ sizeof (dq->descriptors[0]),
+ 128 /* per chip spec */ );
+ if (!dq->descriptors)
+ return vlib_physmem_last_error (vm);
clib_memset (dq->descriptors, 0,
dq->n_descriptors * sizeof (dq->descriptors[0]));
@@ -2518,10 +2516,10 @@ ixge_dma_init (ixge_device_t * xd, vlib_rx_or_tx_t rt, u32 queue_index)
{
u32 i;
- dq->tx.head_index_write_back = vlib_physmem_alloc (vm,
- xm->physmem_region,
- &error,
- CLIB_CACHE_LINE_BYTES);
+ dq->tx.head_index_write_back =
+ vlib_physmem_alloc (vm, CLIB_CACHE_LINE_BYTES);
+ if (!dq->tx.head_index_write_back)
+ return vlib_physmem_last_error (vm);
for (i = 0; i < dq->n_descriptors; i++)
dq->descriptors[i].tx = xm->tx_descriptor_template;
@@ -2533,9 +2531,7 @@ ixge_dma_init (ixge_device_t * xd, vlib_rx_or_tx_t rt, u32 queue_index)
ixge_dma_regs_t *dr = get_dma_regs (xd, rt, queue_index);
u64 a;
- a =
- vlib_physmem_virtual_to_physical (vm, xm->physmem_region,
- dq->descriptors);
+ a = vlib_physmem_get_pa (vm, dq->descriptors);
dr->descriptor_address[0] = a & 0xFFFFFFFF;
dr->descriptor_address[1] = a >> (u64) 32;
dr->n_descriptor_bytes = dq->n_descriptors * sizeof (dq->descriptors[0]);
@@ -2560,8 +2556,7 @@ ixge_dma_init (ixge_device_t * xd, vlib_rx_or_tx_t rt, u32 queue_index)
/* Make sure its initialized before hardware can get to it. */
dq->tx.head_index_write_back[0] = dq->head_index;
- a = vlib_physmem_virtual_to_physical (vm, xm->physmem_region,
- dq->tx.head_index_write_back);
+ a = vlib_physmem_get_pa (vm, dq->tx.head_index_write_back);
dr->tx.head_index_write_back_address[0] = /* enable bit */ 1 | a;
dr->tx.head_index_write_back_address[1] = (u64) a >> (u64) 32;
}
@@ -2848,14 +2843,6 @@ ixge_pci_init (vlib_main_t * vm, vlib_pci_dev_handle_t h)
vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, h);
vlib_pci_device_info_t *d = vlib_pci_get_device_info (vm, addr, 0);
- /* Allocate physmem region for DMA buffers */
- if (xm->physmem_region_allocated == 0)
- {
- error = vlib_physmem_region_alloc (vm, "ixge decriptors", 2 << 20, 0,
- VLIB_PHYSMEM_F_INIT_MHEAP,
- &xm->physmem_region);
- xm->physmem_region_allocated = 1;
- }
if (error)
return error;
diff --git a/src/plugins/ixge/ixge.h b/src/plugins/ixge/ixge.h
index c766397525b..f80d9c0e7cf 100644
--- a/src/plugins/ixge/ixge.h
+++ b/src/plugins/ixge/ixge.h
@@ -1265,8 +1265,6 @@ typedef struct
f64 time_last_stats_update;
- vlib_physmem_region_index_t physmem_region;
- int physmem_region_allocated;
} ixge_main_t;
extern ixge_main_t ixge_main;
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index 763572c2f0e..f976f16dec8 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -340,12 +340,12 @@ memif_init_regions_and_queues (memif_if_t * mif)
/* *INDENT-OFF* */
vec_foreach (bp, buffer_main.buffer_pools)
{
- vlib_physmem_region_t *pr;
- pr = vlib_physmem_get_region (vm, bp->physmem_region);
+ vlib_physmem_map_t *pm;
+ pm = vlib_physmem_get_map (vm, bp->physmem_map_index);
vec_add2_aligned (mif->regions, r, 1, CLIB_CACHE_LINE_BYTES);
- r->fd = pr->fd;
- r->region_size = pr->size;
- r->shm = pr->mem;
+ r->fd = pm->fd;
+ r->region_size = pm->n_pages << pm->log2_page_size;
+ r->shm = pm->base;
r->is_external = 1;
}
/* *INDENT-ON* */
diff --git a/src/plugins/vmxnet3/vmxnet3.c b/src/plugins/vmxnet3/vmxnet3.c
index e34b3e69a27..f60a8fe2215 100644
--- a/src/plugins/vmxnet3/vmxnet3.c
+++ b/src/plugins/vmxnet3/vmxnet3.c
@@ -139,19 +139,16 @@ vmxnet3_write_mac (vmxnet3_device_t * vd)
static clib_error_t *
vmxnet3_provision_driver_shared (vlib_main_t * vm, vmxnet3_device_t * vd)
{
- vmxnet3_main_t *vmxm = &vmxnet3_main;
vmxnet3_shared *shared;
vmxnet3_queues *q;
u64 shared_dma;
- clib_error_t *error;
u16 qid = 0, rid;
vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, qid);
- vd->dma = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
- sizeof (*vd->dma), 512);
- if (error)
- return error;
+ vd->dma = vlib_physmem_alloc_aligned (vm, sizeof (*vd->dma), 512);
+ if (vd->dma == 0)
+ return vlib_physmem_last_error (vm);
clib_memset (vd->dma, 0, sizeof (*vd->dma));
@@ -222,9 +219,7 @@ vmxnet3_disable_interrupt (vmxnet3_device_t * vd)
static clib_error_t *
vmxnet3_rxq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
{
- vmxnet3_main_t *vmxm = &vmxnet3_main;
vmxnet3_rxq_t *rxq;
- clib_error_t *error;
u16 rid;
vec_validate_aligned (vd->rxqs, qid, CLIB_CACHE_LINE_BYTES);
@@ -233,19 +228,19 @@ vmxnet3_rxq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
rxq->size = qsz;
for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
{
- rxq->rx_desc[rid] =
- vlib_physmem_alloc_aligned (vm, vmxm->physmem_region,
- &error, qsz * sizeof (*rxq->rx_desc[rid]),
- 512);
- if (error)
- return error;
+ rxq->rx_desc[rid] = vlib_physmem_alloc_aligned
+ (vm, qsz * sizeof (*rxq->rx_desc[rid]), 512);
+
+ if (rxq->rx_desc[rid] == 0)
+ return vlib_physmem_last_error (vm);
+
clib_memset (rxq->rx_desc[rid], 0, qsz * sizeof (*rxq->rx_desc[rid]));
}
- rxq->rx_comp = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
- qsz * sizeof (*rxq->rx_comp),
+ rxq->rx_comp = vlib_physmem_alloc_aligned (vm, qsz * sizeof (*rxq->rx_comp),
512);
- if (error)
- return error;
+ if (rxq->rx_comp == 0)
+ return vlib_physmem_last_error (vm);
+
clib_memset (rxq->rx_comp, 0, qsz * sizeof (*rxq->rx_comp));
for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
{
@@ -264,9 +259,7 @@ vmxnet3_rxq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
static clib_error_t *
vmxnet3_txq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
{
- vmxnet3_main_t *vmxm = &vmxnet3_main;
vmxnet3_txq_t *txq;
- clib_error_t *error;
if (qid >= vd->num_tx_queues)
{
@@ -282,17 +275,17 @@ vmxnet3_txq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
txq = vec_elt_at_index (vd->txqs, qid);
clib_memset (txq, 0, sizeof (*txq));
txq->size = qsz;
- txq->tx_desc = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
- qsz * sizeof (*txq->tx_desc),
+ txq->tx_desc = vlib_physmem_alloc_aligned (vm, qsz * sizeof (*txq->tx_desc),
512);
- if (error)
- return error;
- clib_memset (txq->tx_desc, 0, qsz * sizeof (*txq->tx_desc));
- txq->tx_comp = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
- qsz * sizeof (*txq->tx_comp),
+ if (txq->tx_desc == 0)
+ return vlib_physmem_last_error (vm);
+
+ memset (txq->tx_desc, 0, qsz * sizeof (*txq->tx_desc));
+ txq->tx_comp = vlib_physmem_alloc_aligned (vm, qsz * sizeof (*txq->tx_comp),
512);
- if (error)
- return error;
+ if (txq->tx_comp == 0)
+ return vlib_physmem_last_error (vm);
+
clib_memset (txq->tx_comp, 0, qsz * sizeof (*txq->tx_comp));
vec_validate_aligned (txq->tx_ring.bufs, txq->size, CLIB_CACHE_LINE_BYTES);
txq->tx_ring.gen = VMXNET3_TXF_GEN;
@@ -307,7 +300,6 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
{
clib_error_t *error = 0;
u32 ret, i;
- vmxnet3_main_t *vmxm = &vmxnet3_main;
vlib_thread_main_t *tm = vlib_get_thread_main ();
vd->num_tx_queues = 1;
@@ -372,17 +364,6 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_MACH);
clib_memcpy (vd->mac_addr + 4, &ret, 2);
- if (vmxm->physmem_region_alloc == 0)
- {
- u32 flags = VLIB_PHYSMEM_F_INIT_MHEAP | VLIB_PHYSMEM_F_HUGETLB;
- error =
- vlib_physmem_region_alloc (vm, "vmxnet3 descriptors", 4 << 20, 0,
- flags, &vmxm->physmem_region);
- if (error)
- return error;
- vmxm->physmem_region_alloc = 1;
- }
-
error = vmxnet3_rxq_init (vm, vd, 0, args->rxq_size);
if (error)
return error;
@@ -629,9 +610,9 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
vlib_buffer_free_from_ring (vm, ring->bufs, desc_idx, rxq->size,
ring->fill);
vec_free (ring->bufs);
- vlib_physmem_free (vm, vmxm->physmem_region, rxq->rx_desc[rid]);
+ vlib_physmem_free (vm, rxq->rx_desc[rid]);
}
- vlib_physmem_free (vm, vmxm->physmem_region, rxq->rx_comp);
+ vlib_physmem_free (vm, rxq->rx_comp);
}
/* *INDENT-ON* */
vec_free (vd->rxqs);
@@ -654,13 +635,13 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
}
clib_spinlock_free (&txq->lock);
vec_free (txq->tx_ring.bufs);
- vlib_physmem_free (vm, vmxm->physmem_region, txq->tx_desc);
- vlib_physmem_free (vm, vmxm->physmem_region, txq->tx_comp);
+ vlib_physmem_free (vm, txq->tx_desc);
+ vlib_physmem_free (vm, txq->tx_comp);
}
/* *INDENT-ON* */
vec_free (vd->txqs);
- vlib_physmem_free (vm, vmxm->physmem_region, vd->dma);
+ vlib_physmem_free (vm, vd->dma);
clib_error_free (vd->error);
clib_memset (vd, 0, sizeof (*vd));
diff --git a/src/plugins/vmxnet3/vmxnet3.h b/src/plugins/vmxnet3/vmxnet3.h
index 391ddc17113..befbe368d67 100644
--- a/src/plugins/vmxnet3/vmxnet3.h
+++ b/src/plugins/vmxnet3/vmxnet3.h
@@ -493,8 +493,6 @@ typedef struct
typedef struct
{
vmxnet3_device_t *devices;
- vlib_physmem_region_index_t physmem_region;
- u32 physmem_region_alloc;
u16 msg_id_base;
} vmxnet3_main_t;
@@ -546,10 +544,8 @@ vmxnet3_reg_read (vmxnet3_device_t * vd, u8 bar, u32 addr)
static_always_inline uword
vmxnet3_dma_addr (vlib_main_t * vm, vmxnet3_device_t * vd, void *p)
{
- vmxnet3_main_t *vmxm = &vmxnet3_main;
-
return (vd->flags & VMXNET3_DEVICE_F_IOVA) ? pointer_to_uword (p) :
- vlib_physmem_virtual_to_physical (vm, vmxm->physmem_region, p);
+ vlib_physmem_get_pa (vm, p);
}
static_always_inline void