net/mlx4: restore Rx offloads
[dpdk.git] / drivers / net / mlx4 / mlx4_prm.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 MLX4_PRM_H_
35 #define MLX4_PRM_H_
36
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_byteorder.h>
40
41 /* Verbs headers do not support -pedantic. */
42 #ifdef PEDANTIC
43 #pragma GCC diagnostic ignored "-Wpedantic"
44 #endif
45 #include <infiniband/mlx4dv.h>
46 #include <infiniband/verbs.h>
47 #ifdef PEDANTIC
48 #pragma GCC diagnostic error "-Wpedantic"
49 #endif
50
51 /* ConnectX-3 Tx queue basic block. */
52 #define MLX4_TXBB_SHIFT 6
53 #define MLX4_TXBB_SIZE (1 << MLX4_TXBB_SHIFT)
54
55 /* Typical TSO descriptor with 16 gather entries is 352 bytes. */
56 #define MLX4_MAX_WQE_SIZE 512
57 #define MLX4_MAX_WQE_TXBBS (MLX4_MAX_WQE_SIZE / MLX4_TXBB_SIZE)
58
59 /* Send queue stamping/invalidating information. */
60 #define MLX4_SQ_STAMP_STRIDE 64
61 #define MLX4_SQ_STAMP_DWORDS (MLX4_SQ_STAMP_STRIDE / 4)
62 #define MLX4_SQ_STAMP_SHIFT 31
63 #define MLX4_SQ_STAMP_VAL 0x7fffffff
64
65 /* Work queue element (WQE) flags. */
66 #define MLX4_BIT_WQE_OWN 0x80000000
67 #define MLX4_WQE_CTRL_IIP_HDR_CSUM (1 << 28)
68 #define MLX4_WQE_CTRL_IL4_HDR_CSUM (1 << 27)
69
70 #define MLX4_SIZE_TO_TXBBS(size) \
71         (RTE_ALIGN((size), (MLX4_TXBB_SIZE)) >> (MLX4_TXBB_SHIFT))
72
73 /* CQE checksum flags. */
74 enum {
75         MLX4_CQE_L2_TUNNEL_IPV4 = (int)(1u << 25),
76         MLX4_CQE_L2_TUNNEL_L4_CSUM = (int)(1u << 26),
77         MLX4_CQE_L2_TUNNEL = (int)(1u << 27),
78         MLX4_CQE_L2_TUNNEL_IPOK = (int)(1u << 31),
79 };
80
81 /* Send queue information. */
82 struct mlx4_sq {
83         uint8_t *buf; /**< SQ buffer. */
84         uint8_t *eob; /**< End of SQ buffer */
85         uint32_t head; /**< SQ head counter in units of TXBBS. */
86         uint32_t tail; /**< SQ tail counter in units of TXBBS. */
87         uint32_t txbb_cnt; /**< Num of WQEBB in the Q (should be ^2). */
88         uint32_t txbb_cnt_mask; /**< txbbs_cnt mask (txbb_cnt is ^2). */
89         uint32_t headroom_txbbs; /**< Num of txbbs that should be kept free. */
90         uint32_t *db; /**< Pointer to the doorbell. */
91         uint32_t doorbell_qpn; /**< qp number to write to the doorbell. */
92 };
93
94 #define mlx4_get_send_wqe(sq, n) ((sq)->buf + ((n) * (MLX4_TXBB_SIZE)))
95
96 /* Completion queue information. */
97 struct mlx4_cq {
98         uint8_t *buf; /**< Pointer to the completion queue buffer. */
99         uint32_t cqe_cnt; /**< Number of entries in the queue. */
100         uint32_t cqe_64:1; /**< CQ entry size is 64 bytes. */
101         uint32_t cons_index; /**< Last queue entry that was handled. */
102         uint32_t *set_ci_db; /**< Pointer to the completion queue doorbell. */
103 };
104
105 /**
106  * Retrieve a CQE entry from a CQ.
107  *
108  * cqe = cq->buf + cons_index * cqe_size + cqe_offset
109  *
110  * Where cqe_size is 32 or 64 bytes and cqe_offset is 0 or 32 (depending on
111  * cqe_size).
112  *
113  * @param cq
114  *   CQ to retrieve entry from.
115  * @param index
116  *   Entry index.
117  *
118  * @return
119  *   Pointer to CQE entry.
120  */
121 static inline struct mlx4_cqe *
122 mlx4_get_cqe(struct mlx4_cq *cq, uint32_t index)
123 {
124         return (struct mlx4_cqe *)(cq->buf +
125                                    ((index & (cq->cqe_cnt - 1)) <<
126                                     (5 + cq->cqe_64)) +
127                                    (cq->cqe_64 << 5));
128 }
129
130 /**
131  * Transpose a flag in a value.
132  *
133  * @param val
134  *   Input value.
135  * @param from
136  *   Flag to retrieve from input value.
137  * @param to
138  *   Flag to set in output value.
139  *
140  * @return
141  *   Output value with transposed flag enabled if present on input.
142  */
143 static inline uint64_t
144 mlx4_transpose(uint64_t val, uint64_t from, uint64_t to)
145 {
146         return (from >= to ?
147                 (val & from) / (from / to) :
148                 (val & from) * (to / from));
149 }
150
151 #endif /* MLX4_PRM_H_ */