aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include
diff options
context:
space:
mode:
authorBill Fischofer <bill.fischofer@linaro.org>2014-12-16 14:30:36 +0200
committerMaxim Uvarov <maxim.uvarov@linaro.org>2014-12-16 19:03:39 +0300
commitdf8a28363d75dd27476cc89cb1fae60c167f444c (patch)
tree48ffe9c02630ecaf7140a9a352dba1b8e18a2b80 /platform/linux-generic/include
parenta834a53925baa7196ed07ad8e0cd990979c33f19 (diff)
api: packet: change layer offset/pointer API
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform/linux-generic/include')
-rw-r--r--platform/linux-generic/include/api/odp_packet.h130
-rw-r--r--platform/linux-generic/include/odp_packet_internal.h11
2 files changed, 102 insertions, 39 deletions
diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h
index 9a151146c..96e1474f4 100644
--- a/platform/linux-generic/include/api/odp_packet.h
+++ b/platform/linux-generic/include/api/odp_packet.h
@@ -180,10 +180,11 @@ uint8_t *odp_packet_addr(odp_packet_t pkt);
size_t odp_packet_buf_size(odp_packet_t pkt);
/**
- * Packet data address
+ * Packet data pointer
*
- * Returns the current packet data address. When a packet is received from
- * packet input, the data address points to the first byte of the packet.
+ * Returns the current packet data pointer. When a packet is received
+ * from packet input, this points to the first byte of the received
+ * packet. Packet level offsets are calculated relative to this position.
*
* @param pkt Packet handle
*
@@ -191,94 +192,145 @@ size_t odp_packet_buf_size(odp_packet_t pkt);
*
* @see odp_packet_l2(), odp_packet_addr()
*/
-uint8_t *odp_packet_data(odp_packet_t pkt);
+void *odp_packet_data(odp_packet_t pkt);
/**
- * Get pointer to the start of the L2 frame
+ * Layer 2 start pointer
*
- * The L2 frame header address is not necessarily the same as the address of the
- * packet buffer, see odp_packet_addr()
+ * Returns pointer to the start of the layer 2 header. Optionally, outputs
+ * number of data bytes in the segment following the pointer.
*
- * @param pkt Packet handle
+ * @param pkt Packet handle
+ * @param[out] len Number of data bytes remaining in the segment (output).
+ * Ignored when NULL.
*
- * @return Pointer to L2 header or NULL if not found
+ * @return Layer 2 start pointer, or offset 0 by default
*
- * @see odp_packet_addr(), odp_packet_data()
+ * @see odp_packet_l2_offset(), odp_packet_l2_offset_set()
*/
-uint8_t *odp_packet_l2(odp_packet_t pkt);
+void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len);
/**
- * Return the byte offset from the packet buffer to the L2 frame
+ * Layer 2 start offset
+ *
+ * Returns offset to the start of the layer 2 header. The offset is calculated
+ * from the current odp_packet_data() position in bytes.
+ *
+ * User is responsible to update the offset when modifying the packet data
+ * pointer position.
*
* @param pkt Packet handle
*
- * @return L2 byte offset or ODP_PACKET_OFFSET_INVALID if not found
+ * @return Layer 2 start offset
*/
-size_t odp_packet_l2_offset(odp_packet_t pkt);
+uint32_t odp_packet_l2_offset(odp_packet_t pkt);
/**
- * Set the byte offset to the L2 frame
+ * Set layer 2 start offset
+ *
+ * Set offset to the start of the layer 2 header. The offset is calculated from
+ * the current odp_packet_data() position in bytes. Offset must not exceed
+ * packet data length. Packet is not modified on an error.
*
* @param pkt Packet handle
- * @param offset L2 byte offset
+ * @param offset Layer 2 start offset (0 ... odp_packet_len()-1)
+ *
+ * @retval 0 Success
+ * @retval Non-zero Failure
*/
-void odp_packet_set_l2_offset(odp_packet_t pkt, size_t offset);
-
+int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset);
/**
- * Get pointer to the start of the L3 packet
+ * Layer 3 start pointer
*
- * @param pkt Packet handle
+ * Returns pointer to the start of the layer 3 header. Optionally, outputs
+ * number of data bytes in the segment following the pointer.
+ *
+ * @param pkt Packet handle
+ * @param[out] len Number of data bytes remaining in the segment (output).
+ * Ignored when NULL.
*
- * @return Pointer to L3 packet or NULL if not found
+ * @return Layer 3 start pointer, or NULL
*
+ * @see odp_packet_l3_offset(), odp_packet_l3_offset_set()
*/
-uint8_t *odp_packet_l3(odp_packet_t pkt);
+void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len);
/**
- * Return the byte offset from the packet buffer to the L3 packet
+ * Layer 3 start offset
+ *
+ * Returns offset to the start of the layer 3 header. The offset is calculated
+ * from the current odp_packet_data() position in bytes.
+ *
+ * User is responsible to update the offset when modifying the packet data
+ * pointer position.
*
* @param pkt Packet handle
*
- * @return L3 byte offset or ODP_PACKET_OFFSET_INVALID if not found
+ * @return Layer 3 start offset or ODP_PACKET_OFFSET_INVALID if not found
*/
-size_t odp_packet_l3_offset(odp_packet_t pkt);
+uint32_t odp_packet_l3_offset(odp_packet_t pkt);
/**
- * Set the byte offset to the L3 packet
+ * Set layer 3 start offset
+ *
+ * Set offset to the start of the layer 3 header. The offset is calculated from
+ * the current odp_packet_data() position in bytes. Offset must not exceed
+ * packet data length. Packet is not modified on an error.
*
* @param pkt Packet handle
- * @param offset L3 byte offset
+ * @param offset Layer 3 start offset (0 ... odp_packet_len()-1)
+ *
+ * @retval 0 Success
+ * @retval Non-zero Failure
*/
-void odp_packet_set_l3_offset(odp_packet_t pkt, size_t offset);
-
+int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset);
/**
- * Get pointer to the start of the L4 packet
+ * Layer 4 start pointer
*
- * @param pkt Packet handle
+ * Returns pointer to the start of the layer 4 header. Optionally, outputs
+ * number of data bytes in the segment following the pointer.
+ *
+ * @param pkt Packet handle
+ * @param[out] len Number of data bytes remaining in the segment (output).
+ * Ignored when NULL.
*
- * @return Pointer to L4 packet or NULL if not found
+ * @return Layer 4 start pointer, or NULL
*
+ * @see odp_packet_l4_offset(), odp_packet_l4_offset_set()
*/
-uint8_t *odp_packet_l4(odp_packet_t pkt);
+void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len);
/**
- * Return the byte offset from the packet buffer to the L4 packet
+ * Layer 4 start offset
+ *
+ * Returns offset to the start of the layer 4 header. The offset is calculated
+ * from the current odp_packet_data() position in bytes.
+ *
+ * User is responsible to update the offset when modifying the packet data
+ * pointer position.
*
* @param pkt Packet handle
*
- * @return L4 byte offset or ODP_PACKET_OFFSET_INVALID if not found
+ * @return Layer 4 start offset or ODP_PACKET_OFFSET_INVALID if not found
*/
-size_t odp_packet_l4_offset(odp_packet_t pkt);
+uint32_t odp_packet_l4_offset(odp_packet_t pkt);
/**
- * Set the byte offset to the L4 packet
+ * Set layer 4 start offset
+ *
+ * Set offset to the start of the layer 4 header. The offset is calculated from
+ * the current odp_packet_data() position in bytes. Offset must not exceed
+ * packet data length. Packet is not modified on an error.
*
* @param pkt Packet handle
- * @param offset L4 byte offset
+ * @param offset Layer 4 start offset (0 ... odp_packet_len()-1)
+ *
+ * @retval 0 Success
+ * @retval Non-zero Failure
*/
-void odp_packet_set_l4_offset(odp_packet_t pkt, size_t offset);
+int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset);
/**
* Print (debug) information about the packet
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index eecdfd7a6..9338ec238 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -173,6 +173,17 @@ static inline void packet_init(pool_entry_t *pool,
(pool->s.headroom + size);
}
+static inline void *packet_map(odp_packet_hdr_t *pkt_hdr,
+ uint32_t offset, uint32_t *seglen)
+{
+ if (offset > pkt_hdr->frame_len)
+ return NULL;
+
+ return buffer_map(&pkt_hdr->buf_hdr,
+ pkt_hdr->headroom + offset, seglen,
+ pkt_hdr->headroom + pkt_hdr->frame_len);
+}
+
odp_packet_t _odp_packet_alloc(odp_buffer_pool_t pool_hdl);
#ifdef __cplusplus