From: Matias Elo <matias....@nokia.com>

Use separate defines for the maximum number of segments per packet
(CONFIG_PACKET_MAX_SEGS) and the number of segments stored in a packet
header (CONFIG_PACKET_SEGS_PER_HDR).

A separate define is also added for the maximum packet length.

Signed-off-by: Matias Elo <matias....@nokia.com>
---
/** Email created from pull request 233 (matiaselo:dev/pool_dyn_seg_len)
 ** https://github.com/Linaro/odp/pull/233
 ** Patch: https://github.com/Linaro/odp/pull/233.patch
 ** Base sha: ec0c3145fcafa09ae3a79875e7e07dd4794583cc
 ** Merge commit sha: ada95db815e81074651bb5a5fd0d751fdb17a97c
 **/
 .../linux-generic/include/odp_buffer_internal.h    |  6 ++---
 .../linux-generic/include/odp_config_internal.h    | 17 +++++++++++++-
 .../linux-generic/include/odp_packet_internal.h    |  2 +-
 platform/linux-generic/odp_packet.c                | 27 ++++++++++------------
 platform/linux-generic/odp_pool.c                  |  6 ++---
 5 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/platform/linux-generic/include/odp_buffer_internal.h 
b/platform/linux-generic/include/odp_buffer_internal.h
index 5d40303b3..aefb13527 100644
--- a/platform/linux-generic/include/odp_buffer_internal.h
+++ b/platform/linux-generic/include/odp_buffer_internal.h
@@ -71,7 +71,7 @@ struct odp_buffer_hdr_t {
        /* --- 40 bytes --- */
 
        /* Segments */
-       seg_entry_t seg[CONFIG_PACKET_MAX_SEGS];
+       seg_entry_t seg[CONFIG_PACKET_SEGS_PER_HDR];
 
        /* Burst counts */
        uint8_t   burst_num;
@@ -122,8 +122,8 @@ struct odp_buffer_hdr_t {
        uint8_t data[0];
 } ODP_ALIGNED_CACHE;
 
-ODP_STATIC_ASSERT(CONFIG_PACKET_MAX_SEGS < 256,
-                 "CONFIG_PACKET_MAX_SEGS_TOO_LARGE");
+ODP_STATIC_ASSERT(CONFIG_PACKET_SEGS_PER_HDR < 256,
+                 "CONFIG_PACKET_SEGS_PER_HDR_TOO_LARGE");
 
 ODP_STATIC_ASSERT(BUFFER_BURST_SIZE < 256, "BUFFER_BURST_SIZE_TOO_LARGE");
 
diff --git a/platform/linux-generic/include/odp_config_internal.h 
b/platform/linux-generic/include/odp_config_internal.h
index a798851fb..598f26e1c 100644
--- a/platform/linux-generic/include/odp_config_internal.h
+++ b/platform/linux-generic/include/odp_config_internal.h
@@ -75,7 +75,22 @@ extern "C" {
 /*
  * Maximum number of segments per packet
  */
-#define CONFIG_PACKET_MAX_SEGS 6
+#define CONFIG_PACKET_MAX_SEGS 255
+
+/*
+ * Packet segmentation disabled
+ */
+#define CONFIG_PACKET_SEG_DISABLED (CONFIG_PACKET_MAX_SEGS == 1)
+
+/*
+ * Number of segments stored in a packet header
+ */
+#define CONFIG_PACKET_SEGS_PER_HDR 6
+
+/*
+ * Maximum packet data length in bytes
+ */
+#define CONFIG_PACKET_MAX_LEN (64 * 1024)
 
 /*
  * Maximum packet segment size including head- and tailrooms
diff --git a/platform/linux-generic/include/odp_packet_internal.h 
b/platform/linux-generic/include/odp_packet_internal.h
index 15cb53f41..73a3e9349 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -197,7 +197,7 @@ static inline void packet_init(odp_packet_hdr_t *pkt_hdr, 
uint32_t len)
        uint32_t seg_len;
        int num = pkt_hdr->buf_hdr.segcount;
 
-       if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || num == 1)) {
+       if (odp_likely(CONFIG_PACKET_SEG_DISABLED || num == 1)) {
                seg_len = len;
                pkt_hdr->buf_hdr.seg[0].len = len;
        } else {
diff --git a/platform/linux-generic/odp_packet.c 
b/platform/linux-generic/odp_packet.c
index c330c629e..abd060447 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -179,7 +179,7 @@ static inline void *packet_seg_data(odp_packet_hdr_t 
*pkt_hdr, uint32_t seg_idx)
 
 static inline uint16_t packet_last_seg(odp_packet_hdr_t *pkt_hdr)
 {
-       if (CONFIG_PACKET_MAX_SEGS == 1)
+       if (CONFIG_PACKET_SEG_DISABLED)
                return 0;
        else
                return pkt_hdr->buf_hdr.segcount - 1;
@@ -291,7 +291,7 @@ static inline void *packet_map(odp_packet_hdr_t *pkt_hdr,
        if (odp_unlikely(offset >= pkt_hdr->frame_len))
                return NULL;
 
-       if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || seg_count == 1)) {
+       if (odp_likely(CONFIG_PACKET_SEG_DISABLED || seg_count == 1)) {
                addr = pkt_hdr->buf_hdr.seg[0].data + offset;
                len  = pkt_hdr->buf_hdr.seg[0].len - offset;
        } else {
@@ -347,7 +347,7 @@ static inline void link_segments(odp_packet_hdr_t 
*pkt_hdr[], int num)
        while (1) {
                hdr = pkt_hdr[cur];
 
-               for (i = 0; i < CONFIG_PACKET_MAX_SEGS; i++) {
+               for (i = 0; i < CONFIG_PACKET_SEGS_PER_HDR; i++) {
                        odp_buffer_hdr_t *buf_hdr;
 
                        buf_hdr = &pkt_hdr[cur]->buf_hdr;
@@ -365,7 +365,7 @@ static inline void link_segments(odp_packet_hdr_t 
*pkt_hdr[], int num)
                        }
                }
 
-               hdr->buf_hdr.num_seg  = CONFIG_PACKET_MAX_SEGS;
+               hdr->buf_hdr.num_seg  = CONFIG_PACKET_SEGS_PER_HDR;
                hdr->buf_hdr.next_seg = pkt_hdr[cur];
        }
 }
@@ -377,22 +377,19 @@ static inline void init_segments(odp_packet_hdr_t 
*pkt_hdr[], int num)
        /* First segment is the packet descriptor */
        hdr = pkt_hdr[0];
 
+       /* Defaults for single segment packet */
        hdr->buf_hdr.seg[0].data = hdr->buf_hdr.base_data;
        hdr->buf_hdr.seg[0].len  = BASE_LEN;
 
-       /* Link segments */
-       if (CONFIG_PACKET_MAX_SEGS != 1) {
+       if (!CONFIG_PACKET_SEG_DISABLED) {
                hdr->buf_hdr.segcount = num;
-
-               /* Defaults for single segment packet */
                hdr->buf_hdr.num_seg  = 1;
                hdr->buf_hdr.next_seg = NULL;
                hdr->buf_hdr.last_seg = &hdr->buf_hdr;
 
-               if (odp_unlikely(num > 1)) {
+               /* Link segments */
+               if (odp_unlikely(num > 1))
                        link_segments(pkt_hdr, num);
-
-               }
        }
 }
 
@@ -420,7 +417,7 @@ static inline int num_segments(uint32_t len)
        uint32_t max_seg_len;
        int num;
 
-       if (CONFIG_PACKET_MAX_SEGS == 1)
+       if (CONFIG_PACKET_SEG_DISABLED)
                return 1;
 
        num = 1;
@@ -850,7 +847,7 @@ void odp_packet_free(odp_packet_t pkt)
        odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
        int num_seg = pkt_hdr->buf_hdr.segcount;
 
-       if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1)) {
+       if (odp_likely(CONFIG_PACKET_SEG_DISABLED || num_seg == 1)) {
                odp_buffer_hdr_t *buf_hdr[2];
                int num = 1;
 
@@ -1027,7 +1024,7 @@ int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len,
 
        if (len < seg_len) {
                pull_head(pkt_hdr, len);
-       } else if (CONFIG_PACKET_MAX_SEGS != 1) {
+       } else if (!CONFIG_PACKET_SEG_DISABLED) {
                int num = 0;
                uint32_t pull_len = 0;
 
@@ -1131,7 +1128,7 @@ int odp_packet_trunc_tail(odp_packet_t *pkt, uint32_t len,
 
        if (len < seg_len) {
                pull_tail(pkt_hdr, len);
-       } else if (CONFIG_PACKET_MAX_SEGS != 1) {
+       } else if (!CONFIG_PACKET_SEG_DISABLED) {
                int num = 0;
                uint32_t pull_len = 0;
 
diff --git a/platform/linux-generic/odp_pool.c 
b/platform/linux-generic/odp_pool.c
index 44a40e83e..ab26bbf82 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -386,8 +386,8 @@ static odp_pool_t pool_create(const char *name, 
odp_pool_param_t *params,
                tailroom    = CONFIG_PACKET_TAILROOM;
                num         = params->pkt.num;
                uarea_size  = params->pkt.uarea_size;
-               seg_len   = CONFIG_PACKET_MAX_SEG_LEN;
-               max_len     = CONFIG_PACKET_MAX_SEGS * seg_len;
+               seg_len     = CONFIG_PACKET_MAX_SEG_LEN;
+               max_len     = CONFIG_PACKET_MAX_LEN;
                break;
 
        case ODP_POOL_TIMEOUT:
@@ -882,7 +882,7 @@ int odp_pool_capability(odp_pool_capability_t *capa)
 
        /* Packet pools */
        capa->pkt.max_pools        = ODP_CONFIG_POOLS;
-       capa->pkt.max_len          = CONFIG_PACKET_MAX_SEGS * max_seg_len;
+       capa->pkt.max_len          = CONFIG_PACKET_MAX_LEN;
        capa->pkt.max_num          = CONFIG_POOL_MAX_NUM;
        capa->pkt.min_headroom     = CONFIG_PACKET_HEADROOM;
        capa->pkt.min_tailroom     = CONFIG_PACKET_TAILROOM;

Reply via email to