diff mbox series

[API-NEXT,v4,3/6] linux-gen: packet: clean up error and output flags

Message ID 1516698014-28886-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v4,1/6] linux-gen: packet: single user ptr field | expand

Commit Message

Github ODP bot Jan. 23, 2018, 9 a.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Removed three unused error flags. Combined error and output
flags into a single uint32_t. This saves four bytes and init
of those bytes. There's still room for 12 flags in this word.
Later on, these and input flags could be also combined.

Moved the combined flag structure to packet types header,
so that it can be accessed from inlined packet code.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 392 (psavol:next-user-ptr-init-rebase)
 ** https://github.com/Linaro/odp/pull/392
 ** Patch: https://github.com/Linaro/odp/pull/392.patch
 ** Base sha: 4508f410a04cf1657d607d24aa2530a42ef011f7
 ** Merge commit sha: 3781732a78e4a3f0347b6b4299e9753da3929a42
 **/
 .../include/odp/api/plat/packet_inline_types.h     | 41 +++++++++++++++
 .../linux-generic/include/odp_packet_internal.h    | 59 +++-------------------
 platform/linux-generic/odp_classification.c        |  2 +-
 platform/linux-generic/odp_crypto.c                |  2 +-
 platform/linux-generic/odp_ipsec.c                 |  4 +-
 platform/linux-generic/odp_packet.c                | 40 +++++++--------
 platform/linux-generic/odp_packet_flags.c          | 14 +++--
 platform/linux-generic/pktio/dpdk.c                | 24 ++++-----
 8 files changed, 88 insertions(+), 98 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h
index 091598c27..dbfc66411 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h
@@ -101,6 +101,47 @@  typedef union {
 
 } _odp_packet_input_flags_t;
 
+/*
+ * Additional packet flags
+ */
+typedef union {
+	/* All flags */
+	uint32_t all_flags;
+
+	struct {
+		uint32_t reserved1:     12;
+
+	/*
+	 * Packet output flags
+	 */
+		uint32_t l3_chksum_set:  1; /* L3 chksum bit is valid */
+		uint32_t l3_chksum:      1; /* L3 chksum override */
+		uint32_t l4_chksum_set:  1; /* L4 chksum bit is valid */
+		uint32_t l4_chksum:      1; /* L4 chksum override  */
+		uint32_t shaper_len_adj: 8; /* Adjustment for traffic mgr */
+
+	/*
+	 * Error flags
+	 */
+		uint32_t snap_len_err:   1; /* Snap length error */
+		uint32_t ip_err:         1; /* IP error */
+		uint32_t l3_chksum_err:  1; /* L3 checksum error */
+		uint32_t tcp_err:        1; /* TCP error */
+		uint32_t udp_err:        1; /* UDP error */
+		uint32_t l4_chksum_err:  1; /* L4 checksum error */
+		uint32_t ipsec_err:      1; /* IPsec error */
+		uint32_t crypto_err:     1; /* Crypto packet operation error */
+	};
+
+	/* Flag groups */
+	struct {
+		uint32_t reserved2:     12;
+		uint32_t other:         12; /* All other flags */
+		uint32_t error:          8; /* All error flags */
+	} all;
+
+} _odp_packet_flags_t;
+
 /** @endcond */
 
 #ifdef __cplusplus
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 184b8f40e..83bc27b12 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -33,65 +33,21 @@  extern "C" {
 /** Minimum segment length expected by packet_parse_common() */
 #define PACKET_PARSE_SEG_LEN 96
 
-
 ODP_STATIC_ASSERT(sizeof(_odp_packet_input_flags_t) == sizeof(uint64_t),
 		  "INPUT_FLAGS_SIZE_ERROR");
 
-/**
- * Packet error flags
- */
-typedef union {
-	/* All error flags */
-	uint32_t all;
-
-	struct {
-		/* Bitfield flags for each detected error */
-		uint32_t app_error:1; /**< Error bit for application use */
-		uint32_t frame_len:1; /**< Frame length error */
-		uint32_t snap_len:1;  /**< Snap length error */
-		uint32_t l2_chksum:1; /**< L2 checksum error, checks TBD */
-		uint32_t ip_err:1;    /**< IP error,  checks TBD */
-		uint32_t l3_chksum:1; /**< L3 checksum error */
-		uint32_t tcp_err:1;   /**< TCP error, checks TBD */
-		uint32_t udp_err:1;   /**< UDP error, checks TBD */
-		uint32_t ipsec_err:1; /**< IPsec error */
-		uint32_t crypto_err:1; /**< Crypto packet operation error */
-		uint32_t l4_chksum:1; /**< L4 checksum error */
-	};
-} error_flags_t;
-
-ODP_STATIC_ASSERT(sizeof(error_flags_t) == sizeof(uint32_t),
-		  "ERROR_FLAGS_SIZE_ERROR");
-
-/**
- * Packet output flags
- */
-typedef union {
-	/* All output flags */
-	uint32_t all;
-
-	struct {
-		/** adjustment for traffic mgr */
-		uint32_t shaper_len_adj:8;
-
-		/* Bitfield flags for each output option */
-		uint32_t l3_chksum_set:1; /**< L3 chksum bit is valid */
-		uint32_t l3_chksum:1;     /**< L3 chksum override */
-		uint32_t l4_chksum_set:1; /**< L3 chksum bit is valid */
-		uint32_t l4_chksum:1;     /**< L4 chksum override  */
-	};
-} output_flags_t;
-
-ODP_STATIC_ASSERT(sizeof(output_flags_t) == sizeof(uint32_t),
-		  "OUTPUT_FLAGS_SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(_odp_packet_flags_t) == sizeof(uint32_t),
+		  "PACKET_FLAGS_SIZE_ERROR");
 
 /**
  * Packet parser metadata
  */
 typedef struct {
+	/* Packet input flags */
 	_odp_packet_input_flags_t  input_flags;
-	error_flags_t  error_flags;
-	output_flags_t output_flags;
+
+	/* Other flags */
+	_odp_packet_flags_t        flags;
 
 	 /* offset to L2 hdr, e.g. Eth */
 	uint16_t l2_offset;
@@ -232,8 +188,7 @@  static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len)
 	}
 
 	pkt_hdr->p.input_flags.all  = 0;
-	pkt_hdr->p.output_flags.all = 0;
-	pkt_hdr->p.error_flags.all  = 0;
+	pkt_hdr->p.flags.all_flags  = 0;
 
 	pkt_hdr->p.l2_offset = 0;
 	pkt_hdr->p.l3_offset = ODP_PACKET_OFFSET_INVALID;
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index 8c7eb0444..75757fe04 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -931,7 +931,7 @@  static inline cos_t *cls_select_cos(pktio_entry_t *entry,
 	default_cos = cls->default_cos;
 
 	/* Return error cos for error packet */
-	if (pkt_hdr->p.error_flags.all)
+	if (pkt_hdr->p.flags.all.error)
 		return cls->error_cos;
 	/* Calls all the PMRs attached at the PKTIO level*/
 	for (i = 0; i < odp_atomic_load_u32(&default_cos->s.num_rule); i++) {
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index bcb0541ba..e1d1c84b2 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -1418,7 +1418,7 @@  int odp_crypto_int(odp_packet_t pkt_in,
 		(rc_auth == ODP_CRYPTO_ALG_ERR_NONE);
 
 	pkt_hdr = odp_packet_hdr(out_pkt);
-	pkt_hdr->p.error_flags.crypto_err = !op_result->ok;
+	pkt_hdr->p.flags.crypto_err = !op_result->ok;
 
 	/* Synchronous, simply return results */
 	*pkt_out = out_pkt;
diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c
index e9ff9cbd6..b6192377e 100644
--- a/platform/linux-generic/odp_ipsec.c
+++ b/platform/linux-generic/odp_ipsec.c
@@ -831,7 +831,7 @@  static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt,
 
 err:
 	pkt_hdr = odp_packet_hdr(pkt);
-	pkt_hdr->p.error_flags.ipsec_err = 1;
+	pkt_hdr->p.flags.ipsec_err = 1;
 
 	*pkt_out = pkt;
 
@@ -1408,7 +1408,7 @@  static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt,
 err:
 	pkt_hdr = odp_packet_hdr(pkt);
 
-	pkt_hdr->p.error_flags.ipsec_err = 1;
+	pkt_hdr->p.flags.ipsec_err = 1;
 
 	*pkt_out = pkt;
 	return ipsec_sa;
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 735670479..c8ba69e25 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -339,9 +339,8 @@  void *_odp_packet_map(void *pkt_ptr, uint32_t offset, uint32_t *seg_len,
 void packet_parse_reset(odp_packet_hdr_t *pkt_hdr)
 {
 	/* Reset parser metadata before new parse */
-	pkt_hdr->p.error_flags.all  = 0;
 	pkt_hdr->p.input_flags.all  = 0;
-	pkt_hdr->p.output_flags.all = 0;
+	pkt_hdr->p.flags.all.error  = 0;
 	pkt_hdr->p.l2_offset        = ODP_PACKET_OFFSET_INVALID;
 	pkt_hdr->p.l3_offset        = ODP_PACKET_OFFSET_INVALID;
 	pkt_hdr->p.l4_offset        = ODP_PACKET_OFFSET_INVALID;
@@ -1310,16 +1309,16 @@  void odp_packet_l3_chksum_insert(odp_packet_t pkt, int insert)
 {
 	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
 
-	pkt_hdr->p.output_flags.l3_chksum_set = 1;
-	pkt_hdr->p.output_flags.l3_chksum = insert;
+	pkt_hdr->p.flags.l3_chksum_set = 1;
+	pkt_hdr->p.flags.l3_chksum = insert;
 }
 
 void odp_packet_l4_chksum_insert(odp_packet_t pkt, int insert)
 {
 	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
 
-	pkt_hdr->p.output_flags.l4_chksum_set = 1;
-	pkt_hdr->p.output_flags.l4_chksum = insert;
+	pkt_hdr->p.flags.l4_chksum_set = 1;
+	pkt_hdr->p.flags.l4_chksum = insert;
 }
 
 odp_packet_chksum_status_t odp_packet_l3_chksum_status(odp_packet_t pkt)
@@ -1329,7 +1328,7 @@  odp_packet_chksum_status_t odp_packet_l3_chksum_status(odp_packet_t pkt)
 	if (!pkt_hdr->p.input_flags.l3_chksum_done)
 		return ODP_PACKET_CHKSUM_UNKNOWN;
 
-	if (pkt_hdr->p.error_flags.l3_chksum)
+	if (pkt_hdr->p.flags.l3_chksum_err)
 		return ODP_PACKET_CHKSUM_BAD;
 
 	return ODP_PACKET_CHKSUM_OK;
@@ -1342,7 +1341,7 @@  odp_packet_chksum_status_t odp_packet_l4_chksum_status(odp_packet_t pkt)
 	if (!pkt_hdr->p.input_flags.l4_chksum_done)
 		return ODP_PACKET_CHKSUM_UNKNOWN;
 
-	if (pkt_hdr->p.error_flags.l4_chksum)
+	if (pkt_hdr->p.flags.l4_chksum_err)
 		return ODP_PACKET_CHKSUM_BAD;
 
 	return ODP_PACKET_CHKSUM_OK;
@@ -1784,11 +1783,8 @@  void odp_packet_print(odp_packet_t pkt)
 	len += odp_buffer_snprint(&str[len], n - len, buf);
 	len += snprintf(&str[len], n - len, "  input_flags  0x%" PRIx64 "\n",
 			hdr->p.input_flags.all);
-	len += snprintf(&str[len], n - len, "  error_flags  0x%" PRIx32 "\n",
-			hdr->p.error_flags.all);
-	len += snprintf(&str[len], n - len,
-			"  output_flags 0x%" PRIx32 "\n",
-			hdr->p.output_flags.all);
+	len += snprintf(&str[len], n - len, "  flags  0x%" PRIx32 "\n",
+			hdr->p.flags.all_flags);
 	len += snprintf(&str[len], n - len,
 			"  l2_offset    %" PRIu32 "\n", hdr->p.l2_offset);
 	len += snprintf(&str[len], n - len,
@@ -1990,7 +1986,7 @@  static inline uint16_t parse_eth(packet_parser_t *prs, const uint8_t **parseptr,
 	if (ethtype < _ODP_ETH_LEN_MAX) {
 		prs->input_flags.snap = 1;
 		if (ethtype > frame_len - *offset) {
-			prs->error_flags.snap_len = 1;
+			prs->flags.snap_len_err = 1;
 			return 0;
 		}
 		ethtype = _odp_be_to_cpu_16(*((const uint16_t *)(uintptr_t)
@@ -2037,7 +2033,7 @@  static inline uint8_t parse_ipv4(packet_parser_t *prs, const uint8_t **parseptr,
 	if (odp_unlikely(ihl < _ODP_IPV4HDR_IHL_MIN) ||
 	    odp_unlikely(ver != 4) ||
 	    (l3_len > frame_len - *offset)) {
-		prs->error_flags.ip_err = 1;
+		prs->flags.ip_err = 1;
 		return 0;
 	}
 
@@ -2079,7 +2075,7 @@  static inline uint8_t parse_ipv6(packet_parser_t *prs, const uint8_t **parseptr,
 	/* Basic sanity checks on IPv6 header */
 	if ((_odp_be_to_cpu_32(ipv6->ver_tc_flow) >> 28) != 6 ||
 	    l3_len > frame_len - *offset) {
-		prs->error_flags.ip_err = 1;
+		prs->flags.ip_err = 1;
 		return 0;
 	}
 
@@ -2108,7 +2104,7 @@  static inline uint8_t parse_ipv6(packet_parser_t *prs, const uint8_t **parseptr,
 
 		if (*offset >= prs->l3_offset +
 		    _odp_be_to_cpu_16(ipv6->payload_len)) {
-			prs->error_flags.ip_err = 1;
+			prs->flags.ip_err = 1;
 			return 0;
 		}
 
@@ -2135,7 +2131,7 @@  static inline void parse_tcp(packet_parser_t *prs,
 	const _odp_tcphdr_t *tcp = (const _odp_tcphdr_t *)*parseptr;
 
 	if (tcp->hl < sizeof(_odp_tcphdr_t) / sizeof(uint32_t))
-		prs->error_flags.tcp_err = 1;
+		prs->flags.tcp_err = 1;
 	else if ((uint32_t)tcp->hl * 4 > sizeof(_odp_tcphdr_t))
 		prs->input_flags.tcpopt = 1;
 
@@ -2154,7 +2150,7 @@  static inline void parse_udp(packet_parser_t *prs,
 	uint32_t udplen = _odp_be_to_cpu_16(udp->length);
 
 	if (odp_unlikely(udplen < sizeof(_odp_udphdr_t)))
-		prs->error_flags.udp_err = 1;
+		prs->flags.udp_err = 1;
 
 	if (_odp_cpu_to_be_16(_ODP_UDP_IPSEC_PORT) == udp->dst_port &&
 	    udplen > 4) {
@@ -2183,7 +2179,7 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 	prs->l3_offset = offset;
 
 	if (layer <= ODP_PROTO_LAYER_L2)
-		return prs->error_flags.all != 0;
+		return prs->flags.all.error != 0;
 
 	/* Set l3 flag only for known ethtypes */
 	prs->input_flags.l3 = 1;
@@ -2214,7 +2210,7 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 	}
 
 	if (layer == ODP_PROTO_LAYER_L3)
-		return prs->error_flags.all != 0;
+		return prs->flags.all.error != 0;
 
 	/* Set l4 flag only for known ip_proto */
 	prs->input_flags.l4 = 1;
@@ -2265,7 +2261,7 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 		break;
 	}
 
-	return prs->error_flags.all != 0;
+	return prs->flags.all.error != 0;
 }
 
 /**
diff --git a/platform/linux-generic/odp_packet_flags.c b/platform/linux-generic/odp_packet_flags.c
index adb1881e8..0c33666eb 100644
--- a/platform/linux-generic/odp_packet_flags.c
+++ b/platform/linux-generic/odp_packet_flags.c
@@ -24,7 +24,7 @@  int odp_packet_has_error(odp_packet_t pkt)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
-	return pkt_hdr->p.error_flags.all != 0;
+	return pkt_hdr->p.flags.all.error != 0;
 }
 
 /* Get Input Flags */
@@ -34,9 +34,7 @@  int odp_packet_has_l2_error(odp_packet_t pkt)
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 	/* L2 parsing is always done by default and hence
 	no additional check is required */
-	return pkt_hdr->p.error_flags.frame_len
-		| pkt_hdr->p.error_flags.snap_len
-		| pkt_hdr->p.error_flags.l2_chksum;
+	return pkt_hdr->p.flags.snap_len_err;
 }
 
 int odp_packet_has_l3(odp_packet_t pkt)
@@ -48,7 +46,7 @@  int odp_packet_has_l3_error(odp_packet_t pkt)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
-	return pkt_hdr->p.error_flags.ip_err;
+	return pkt_hdr->p.flags.ip_err;
 }
 
 int odp_packet_has_l4(odp_packet_t pkt)
@@ -60,7 +58,7 @@  int odp_packet_has_l4_error(odp_packet_t pkt)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
-	return pkt_hdr->p.error_flags.tcp_err | pkt_hdr->p.error_flags.udp_err;
+	return pkt_hdr->p.flags.tcp_err | pkt_hdr->p.flags.udp_err;
 }
 
 int odp_packet_has_eth_bcast(odp_packet_t pkt)
@@ -169,14 +167,14 @@  void odp_packet_drop_eligible_set(odp_packet_t pkt, odp_bool_t drop)
 
 int8_t odp_packet_shaper_len_adjust(odp_packet_t pkt)
 {
-	retflag(pkt, output_flags.shaper_len_adj);
+	retflag(pkt, flags.shaper_len_adj);
 }
 
 void odp_packet_shaper_len_adjust_set(odp_packet_t pkt, int8_t adj)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
-	pkt_hdr->p.output_flags.shaper_len_adj = adj;
+	pkt_hdr->p.flags.shaper_len_adj = adj;
 }
 
 /* Set Input Flags */
diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index 7078be80a..63942cece 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -380,8 +380,8 @@  static inline int pkt_set_ol_rx(odp_pktin_config_opt_t *pktin_cfg,
 				return -1;
 
 			pkt_hdr->p.input_flags.l3_chksum_done = 1;
-			pkt_hdr->p.error_flags.ip_err = 1;
-			pkt_hdr->p.error_flags.l3_chksum = 1;
+			pkt_hdr->p.flags.ip_err = 1;
+			pkt_hdr->p.flags.l3_chksum_err = 1;
 		}
 	}
 
@@ -396,8 +396,8 @@  static inline int pkt_set_ol_rx(odp_pktin_config_opt_t *pktin_cfg,
 				return -1;
 
 			pkt_hdr->p.input_flags.l4_chksum_done = 1;
-			pkt_hdr->p.error_flags.udp_err = 1;
-			pkt_hdr->p.error_flags.l4_chksum = 1;
+			pkt_hdr->p.flags.udp_err = 1;
+			pkt_hdr->p.flags.l4_chksum_err = 1;
 		}
 	} else if (pktin_cfg->bit.tcp_chksum &&
 		   HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_TCP)) {
@@ -410,8 +410,8 @@  static inline int pkt_set_ol_rx(odp_pktin_config_opt_t *pktin_cfg,
 				return -1;
 
 			pkt_hdr->p.input_flags.l4_chksum_done = 1;
-			pkt_hdr->p.error_flags.tcp_err = 1;
-			pkt_hdr->p.error_flags.l4_chksum = 1;
+			pkt_hdr->p.flags.tcp_err = 1;
+			pkt_hdr->p.flags.l4_chksum_err = 1;
 		}
 	}
 
@@ -572,18 +572,18 @@  static inline void pkt_set_ol_tx(odp_pktout_config_opt_t *pktout_cfg,
 	ipv4_chksum_pkt = OL_TX_CHKSUM_PKT(pktout_cfg->bit.ipv4_chksum,
 					   pktout_capa->bit.ipv4_chksum,
 					   l3_proto_v4,
-					   pkt_p->output_flags.l3_chksum_set,
-					   pkt_p->output_flags.l3_chksum);
+					   pkt_p->flags.l3_chksum_set,
+					   pkt_p->flags.l3_chksum);
 	udp_chksum_pkt =  OL_TX_CHKSUM_PKT(pktout_cfg->bit.udp_chksum,
 					   pktout_capa->bit.udp_chksum,
 					   (l4_proto == _ODP_IPPROTO_UDP),
-					   pkt_p->output_flags.l4_chksum_set,
-					   pkt_p->output_flags.l4_chksum);
+					   pkt_p->flags.l4_chksum_set,
+					   pkt_p->flags.l4_chksum);
 	tcp_chksum_pkt =  OL_TX_CHKSUM_PKT(pktout_cfg->bit.tcp_chksum,
 					   pktout_capa->bit.tcp_chksum,
 					   (l4_proto == _ODP_IPPROTO_TCP),
-					   pkt_p->output_flags.l4_chksum_set,
-					   pkt_p->output_flags.l4_chksum);
+					   pkt_p->flags.l4_chksum_set,
+					   pkt_p->flags.l4_chksum);
 
 	if (!ipv4_chksum_pkt && !udp_chksum_pkt && !tcp_chksum_pkt)
 		return;