New upstream version 18.02
[deb_dpdk.git] / lib / librte_mempool / rte_mempool.c
index d50dba4..54f7f4b 100644 (file)
@@ -1,35 +1,6 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   Copyright(c) 2016 6WIND S.A.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation.
+ * Copyright(c) 2016 6WIND S.A.
  */
 
 #include <stdio.h>
@@ -362,16 +333,12 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
        void *opaque)
 {
        unsigned total_elt_sz;
+       unsigned int mp_capa_flags;
        unsigned i = 0;
        size_t off;
        struct rte_mempool_memhdr *memhdr;
        int ret;
 
-       /* Notify memory area to mempool */
-       ret = rte_mempool_ops_register_memory_area(mp, vaddr, iova, len);
-       if (ret != -ENOTSUP && ret < 0)
-               return ret;
-
        /* create the internal ring if not already done */
        if ((mp->flags & MEMPOOL_F_POOL_CREATED) == 0) {
                ret = rte_mempool_ops_alloc(mp);
@@ -380,14 +347,28 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
                mp->flags |= MEMPOOL_F_POOL_CREATED;
        }
 
+       /* Notify memory area to mempool */
+       ret = rte_mempool_ops_register_memory_area(mp, vaddr, iova, len);
+       if (ret != -ENOTSUP && ret < 0)
+               return ret;
+
        /* mempool is already populated */
        if (mp->populated_size >= mp->size)
                return -ENOSPC;
 
        total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
 
+       /* Get mempool capabilities */
+       mp_capa_flags = 0;
+       ret = rte_mempool_ops_get_capabilities(mp, &mp_capa_flags);
+       if ((ret < 0) && (ret != -ENOTSUP))
+               return ret;
+
+       /* update mempool capabilities */
+       mp->flags |= mp_capa_flags;
+
        /* Detect pool area has sufficient space for elements */
-       if (mp->flags & MEMPOOL_F_CAPA_PHYS_CONTIG) {
+       if (mp_capa_flags & MEMPOOL_F_CAPA_PHYS_CONTIG) {
                if (len < total_elt_sz * mp->size) {
                        RTE_LOG(ERR, MEMPOOL,
                                "pool area %" PRIx64 " not enough\n",
@@ -407,7 +388,7 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
        memhdr->free_cb = free_cb;
        memhdr->opaque = opaque;
 
-       if (mp->flags & MEMPOOL_F_CAPA_BLK_ALIGNED_OBJECTS)
+       if (mp_capa_flags & MEMPOOL_F_CAPA_BLK_ALIGNED_OBJECTS)
                /* align object start address to a multiple of total_elt_sz */
                off = total_elt_sz - ((uintptr_t)vaddr % total_elt_sz);
        else if (mp->flags & MEMPOOL_F_NO_CACHE_ALIGN)