@@ -170,6 +170,10 @@ typedef struct {
odp_buffer_t buffer_alloc(odp_pool_t pool, size_t size);
int buffer_alloc_multi(odp_pool_t pool_hdl, size_t size,
odp_buffer_t buf[], int num);
+int seg_alloc_head(odp_buffer_hdr_t *buf_hdr, int segcount);
+void seg_free_head(odp_buffer_hdr_t *buf_hdr, int segcount);
+int seg_alloc_tail(odp_buffer_hdr_t *buf_hdr, int segcount);
+void seg_free_tail(odp_buffer_hdr_t *buf_hdr, int segcount);
#ifdef __cplusplus
}
@@ -210,12 +210,60 @@ static inline void pull_head(odp_packet_hdr_t *pkt_hdr, size_t len)
pkt_hdr->frame_len -= len;
}
+static inline int push_head_seg(odp_packet_hdr_t *pkt_hdr, size_t len)
+{
+ uint32_t newsegcount =
+ (len - pkt_hdr->headroom + pkt_hdr->buf_hdr.size - 1) /
+ pkt_hdr->buf_hdr.size;
+
+ if (pkt_hdr->buf_hdr.segcount + newsegcount > ODP_BUFFER_MAX_SEG)
+ return -1;
+
+ if (seg_alloc_head(&pkt_hdr->buf_hdr, newsegcount))
+ return -1;
+
+ pkt_hdr->headroom += newsegcount * pkt_hdr->buf_hdr.size;
+ return 0;
+}
+
+static inline void pull_head_seg(odp_packet_hdr_t *pkt_hdr)
+{
+ uint32_t extrasegs = pkt_hdr->headroom / pkt_hdr->buf_hdr.size;
+
+ seg_free_head(&pkt_hdr->buf_hdr, extrasegs);
+ pkt_hdr->headroom -= extrasegs * pkt_hdr->buf_hdr.size;
+}
+
static inline void push_tail(odp_packet_hdr_t *pkt_hdr, size_t len)
{
pkt_hdr->tailroom -= len;
pkt_hdr->frame_len += len;
}
+static inline int push_tail_seg(odp_packet_hdr_t *pkt_hdr, size_t len)
+{
+ uint32_t newsegcount =
+ (len - pkt_hdr->tailroom + pkt_hdr->buf_hdr.size - 1) /
+ pkt_hdr->buf_hdr.size;
+
+ if (pkt_hdr->buf_hdr.segcount + newsegcount > ODP_BUFFER_MAX_SEG)
+ return -1;
+
+ if (seg_alloc_tail(&pkt_hdr->buf_hdr, newsegcount))
+ return -1;
+
+ pkt_hdr->tailroom += newsegcount * pkt_hdr->buf_hdr.size;
+ return 0;
+}
+
+static inline void pull_tail_seg(odp_packet_hdr_t *pkt_hdr)
+{
+ uint32_t extrasegs = pkt_hdr->tailroom / pkt_hdr->buf_hdr.size;
+
+ seg_free_tail(&pkt_hdr->buf_hdr, extrasegs);
+
+ pkt_hdr->tailroom -= extrasegs * pkt_hdr->buf_hdr.size;
+}
static inline void pull_tail(odp_packet_hdr_t *pkt_hdr, size_t len)
{
@@ -264,6 +264,21 @@ void *odp_packet_push_head(odp_packet_t pkt, uint32_t len)
return packet_map(pkt_hdr, 0, NULL);
}
+int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len,
+ void **data_ptr, uint32_t *seg_len)
+{
+ odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt);
+
+ if (len > pkt_hdr->headroom && push_head_seg(pkt_hdr, len))
+ return -1;
+
+ push_head(pkt_hdr, len);
+
+ if (data_ptr)
+ *data_ptr = packet_map(pkt_hdr, 0, seg_len);
+ return 0;
+}
+
void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len)
{
odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
@@ -275,6 +290,23 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len)
return packet_map(pkt_hdr, 0, NULL);
}
+int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len,
+ void **data_ptr, uint32_t *seg_len)
+{
+ odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt);
+
+ if (len > pkt_hdr->frame_len)
+ return -1;
+
+ pull_head(pkt_hdr, len);
+ if (pkt_hdr->headroom > pkt_hdr->buf_hdr.size)
+ pull_head_seg(pkt_hdr);
+
+ if (data_ptr)
+ *data_ptr = packet_map(pkt_hdr, 0, seg_len);
+ return 0;
+}
+
void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len)
{
odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
@@ -287,6 +319,22 @@ void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len)
return packet_map(pkt_hdr, origin, NULL);
}
+int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len,
+ void **data_ptr, uint32_t *seg_len)
+{
+ odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt);
+ uint32_t origin = pkt_hdr->frame_len;
+
+ if (len > pkt_hdr->tailroom && push_tail_seg(pkt_hdr, len))
+ return -1;
+
+ push_tail(pkt_hdr, len);
+
+ if (data_ptr)
+ *data_ptr = packet_map(pkt_hdr, origin, seg_len);
+ return 0;
+}
+
void *odp_packet_pull_tail(odp_packet_t pkt, uint32_t len)
{
odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
@@ -298,6 +346,25 @@ void *odp_packet_pull_tail(odp_packet_t pkt, uint32_t len)
return packet_map(pkt_hdr, pkt_hdr->frame_len, NULL);
}
+int odp_packet_trunc_tail(odp_packet_t *pkt, uint32_t len,
+ void **tail_ptr, uint32_t *tailroom)
+{
+ odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt);
+
+ if (len > pkt_hdr->frame_len)
+ return -1;
+
+ pull_tail(pkt_hdr, len);
+ if (pkt_hdr->tailroom > pkt_hdr->buf_hdr.size)
+ pull_tail_seg(pkt_hdr);
+
+ if (tail_ptr)
+ *tail_ptr = packet_map(pkt_hdr, pkt_hdr->frame_len, NULL);
+ if (tailroom)
+ *tailroom = pkt_hdr->tailroom;
+ return 0;
+}
+
void *odp_packet_offset(odp_packet_t pkt, uint32_t offset, uint32_t *len,
odp_packet_seg_t *seg)
{
@@ -510,6 +510,81 @@ int odp_pool_destroy(odp_pool_t pool_hdl)
return 0;
}
+int seg_alloc_head(odp_buffer_hdr_t *buf_hdr, int segcount)
+{
+ uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl);
+ pool_entry_t *pool = get_pool_entry(pool_id);
+ void *newsegs[segcount];
+ int i;
+
+ for (i = 0; i < segcount; i++) {
+ newsegs[i] = get_blk(&pool->s);
+ if (newsegs[i] == NULL) {
+ while (--i >= 0)
+ ret_blk(&pool->s, newsegs[i]);
+ return -1;
+ }
+ }
+
+ for (i = buf_hdr->segcount - 1; i >= 0; i--)
+ buf_hdr->addr[i + segcount] = buf_hdr->addr[i];
+
+ for (i = 0; i < segcount; i++)
+ buf_hdr->addr[i] = newsegs[i];
+
+ buf_hdr->segcount += segcount;
+ return 0;
+}
+
+void seg_free_head(odp_buffer_hdr_t *buf_hdr, int segcount)
+{
+ uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl);
+ pool_entry_t *pool = get_pool_entry(pool_id);
+ int s_cnt = buf_hdr->segcount;
+ int i;
+
+ for (i = 0; i < s_cnt; i++)
+ ret_blk(&pool->s, buf_hdr->addr[i]);
+
+ for (i = 0; i < s_cnt - segcount; i++)
+ buf_hdr->addr[i] = buf_hdr->addr[i + segcount];
+
+ buf_hdr->segcount -= segcount;
+}
+
+int seg_alloc_tail(odp_buffer_hdr_t *buf_hdr, int segcount)
+{
+ uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl);
+ pool_entry_t *pool = get_pool_entry(pool_id);
+ uint32_t s_cnt = buf_hdr->segcount;
+ int i;
+
+ for (i = 0; i < segcount; i++) {
+ buf_hdr->addr[s_cnt + i] = get_blk(&pool->s);
+ if (buf_hdr->addr[s_cnt + i] == NULL) {
+ while (--i >= 0)
+ ret_blk(&pool->s, buf_hdr->addr[s_cnt + i]);
+ return -1;
+ }
+ }
+
+ buf_hdr->segcount += segcount;
+ return 0;
+}
+
+void seg_free_tail(odp_buffer_hdr_t *buf_hdr, int segcount)
+{
+ uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl);
+ pool_entry_t *pool = get_pool_entry(pool_id);
+ int s_cnt = buf_hdr->segcount;
+ int i;
+
+ for (i = s_cnt - 1; i > s_cnt - segcount; i--)
+ ret_blk(&pool->s, buf_hdr->addr[i]);
+
+ buf_hdr->segcount -= segcount;
+}
+
odp_buffer_t buffer_alloc(odp_pool_t pool_hdl, size_t size)
{
uint32_t pool_id = pool_handle_to_index(pool_hdl);
Implement the following APIs: odp_packet_extend_head() odp_packet_trunc_head() odp_packet_extend_tail() odp_packet_trunc_tail() Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org> --- .../linux-generic/include/odp_buffer_internal.h | 4 ++ .../linux-generic/include/odp_packet_internal.h | 48 ++++++++++++++ platform/linux-generic/odp_packet.c | 67 +++++++++++++++++++ platform/linux-generic/odp_pool.c | 75 ++++++++++++++++++++++ 4 files changed, 194 insertions(+)