net/mlx5: use static assert for compile-time sanity checks
[dpdk.git] / drivers / net / mlx5 / mlx5_rxtx_vec.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2017 6WIND S.A.
5  *   Copyright 2017 Mellanox.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of 6WIND S.A. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef RTE_PMD_MLX5_RXTX_VEC_H_
35 #define RTE_PMD_MLX5_RXTX_VEC_H_
36
37 #include <rte_common.h>
38 #include <rte_mbuf.h>
39
40 #include "mlx5_autoconf.h"
41 #include "mlx5_prm.h"
42
43 /*
44  * Compile time sanity check for vectorized functions.
45  */
46
47 #define S_ASSERT_RTE_MBUF(s) \
48         static_assert(s, "A field of struct rte_mbuf is changed")
49 #define S_ASSERT_MLX5_CQE(s) \
50         static_assert(s, "A field of struct mlx5_cqe is changed")
51
52 /* rxq_cq_decompress_v() */
53 S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, pkt_len) ==
54                   offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
55 S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, data_len) ==
56                   offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
57 S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, hash) ==
58                   offsetof(struct rte_mbuf, rx_descriptor_fields1) + 12);
59
60 /* rxq_cq_to_ptype_oflags_v() */
61 S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, ol_flags) ==
62                   offsetof(struct rte_mbuf, rearm_data) + 8);
63 S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, rearm_data) ==
64                   RTE_ALIGN(offsetof(struct rte_mbuf, rearm_data), 16));
65
66 /* rxq_burst_v() */
67 S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, pkt_len) ==
68                   offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
69 S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, data_len) ==
70                   offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
71 S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, pkt_info) == 0);
72 S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rx_hash_res) ==
73                   offsetof(struct mlx5_cqe, pkt_info) + 12);
74 S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rsvd1) +
75                   sizeof(((struct mlx5_cqe *)0)->rsvd1) ==
76                   offsetof(struct mlx5_cqe, hdr_type_etc));
77 S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, vlan_info) ==
78                   offsetof(struct mlx5_cqe, hdr_type_etc) + 2);
79 S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rsvd2) +
80                   sizeof(((struct mlx5_cqe *)0)->rsvd2) ==
81                   offsetof(struct mlx5_cqe, byte_cnt));
82 S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, sop_drop_qpn) ==
83                   RTE_ALIGN(offsetof(struct mlx5_cqe, sop_drop_qpn), 8));
84 S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, op_own) ==
85                   offsetof(struct mlx5_cqe, sop_drop_qpn) + 7);
86
87 #endif /* RTE_PMD_MLX5_RXTX_VEC_H_ */