Message ID | 1486990410-14928-5-git-send-email-petri.savolainen@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | Packet references as copy | expand |
I suggest this be reposted as the initial skeleton implementation of packet references to odp-dpdk since that platform currently does not support these APIs and this would allow v1.14 functional parity with odp-linux. On Mon, Feb 13, 2017 at 6:53 AM, Petri Savolainen <petri.savolainen@linaro.org> wrote: > Implement packet references API as packet copy. This is the > simplest way to support the API, as other packet functions > are not affected at all. > > Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org> > --- > platform/linux-generic/odp_packet.c | 78 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 78 insertions(+) > > diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c > index 024f694..1d2b506 100644 > --- a/platform/linux-generic/odp_packet.c > +++ b/platform/linux-generic/odp_packet.c > @@ -2221,3 +2221,81 @@ uint64_t odp_packet_seg_to_u64(odp_packet_seg_t hdl) > { > return _odp_pri(hdl); > } > + > +odp_packet_t odp_packet_ref_static(odp_packet_t pkt) > +{ > + odp_packet_t new; > + > + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); > + > + return new; This could be simplified to just: return odp_packet_copy(pkt, odp_packet_pool(pkt)); > +} > + > +odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) > +{ > + odp_packet_t new; > + int ret; > + > + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); > + > + if (new == ODP_PACKET_INVALID) { > + ODP_ERR("copy failed\n"); > + return ODP_PACKET_INVALID; > + } > + > + ret = odp_packet_trunc_head(&new, offset, NULL, NULL); > + > + if (ret < 0) { > + ODP_ERR("trunk_head failed\n"); > + odp_packet_free(new); > + return ODP_PACKET_INVALID; > + } > + > + return new; > +} > + > +odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, > + odp_packet_t hdr) > +{ > + odp_packet_t new; > + int ret; > + > + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); > + > + if (new == ODP_PACKET_INVALID) { > + ODP_ERR("copy failed\n"); > + return ODP_PACKET_INVALID; > + } > + > + if (offset) { > + ret = odp_packet_trunc_head(&new, offset, NULL, NULL); > + > + if (ret < 0) { > + ODP_ERR("trunk_head failed\n"); > + odp_packet_free(new); > + return ODP_PACKET_INVALID; > + } > + } > + > + ret = odp_packet_concat(&hdr, new); > + > + if (ret < 0) { > + ODP_ERR("concat failed\n"); > + odp_packet_free(new); > + return ODP_PACKET_INVALID; > + } > + > + return hdr; > +} > + > +int odp_packet_has_ref(odp_packet_t pkt) > +{ > + (void)pkt; > + > + return 0; > +} > + > +uint32_t odp_packet_unshared_len(odp_packet_t pkt) > +{ > + return odp_packet_len(pkt); > +} > -- > 2.8.1 >
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 024f694..1d2b506 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -2221,3 +2221,81 @@ uint64_t odp_packet_seg_to_u64(odp_packet_seg_t hdl) { return _odp_pri(hdl); } + +odp_packet_t odp_packet_ref_static(odp_packet_t pkt) +{ + odp_packet_t new; + + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); + + return new; +} + +odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) +{ + odp_packet_t new; + int ret; + + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); + + if (new == ODP_PACKET_INVALID) { + ODP_ERR("copy failed\n"); + return ODP_PACKET_INVALID; + } + + ret = odp_packet_trunc_head(&new, offset, NULL, NULL); + + if (ret < 0) { + ODP_ERR("trunk_head failed\n"); + odp_packet_free(new); + return ODP_PACKET_INVALID; + } + + return new; +} + +odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, + odp_packet_t hdr) +{ + odp_packet_t new; + int ret; + + new = odp_packet_copy(pkt, odp_packet_pool(pkt)); + + if (new == ODP_PACKET_INVALID) { + ODP_ERR("copy failed\n"); + return ODP_PACKET_INVALID; + } + + if (offset) { + ret = odp_packet_trunc_head(&new, offset, NULL, NULL); + + if (ret < 0) { + ODP_ERR("trunk_head failed\n"); + odp_packet_free(new); + return ODP_PACKET_INVALID; + } + } + + ret = odp_packet_concat(&hdr, new); + + if (ret < 0) { + ODP_ERR("concat failed\n"); + odp_packet_free(new); + return ODP_PACKET_INVALID; + } + + return hdr; +} + +int odp_packet_has_ref(odp_packet_t pkt) +{ + (void)pkt; + + return 0; +} + +uint32_t odp_packet_unshared_len(odp_packet_t pkt) +{ + return odp_packet_len(pkt); +}
Implement packet references API as packet copy. This is the simplest way to support the API, as other packet functions are not affected at all. Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org> --- platform/linux-generic/odp_packet.c | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) -- 2.8.1