1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
9 #include <rte_atomic.h>
10 #include <rte_branch_prediction.h>
11 #include <rte_byteorder.h>
13 /* Verbs headers do not support -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/mlx4dv.h>
18 #include <infiniband/verbs.h>
20 #pragma GCC diagnostic error "-Wpedantic"
23 /* ConnectX-3 Tx queue basic block. */
24 #define MLX4_TXBB_SHIFT 6
25 #define MLX4_TXBB_SIZE (1 << MLX4_TXBB_SHIFT)
27 /* Typical TSO descriptor with 16 gather entries is 352 bytes. */
28 #define MLX4_MAX_SGE 32
29 #define MLX4_MAX_WQE_SIZE \
30 (MLX4_MAX_SGE * sizeof(struct mlx4_wqe_data_seg) + \
31 sizeof(struct mlx4_wqe_ctrl_seg))
32 #define MLX4_SEG_SHIFT 4
34 /* Send queue stamping/invalidating information. */
35 #define MLX4_SQ_STAMP_STRIDE 64
36 #define MLX4_SQ_STAMP_DWORDS (MLX4_SQ_STAMP_STRIDE / 4)
37 #define MLX4_SQ_OWNER_BIT 31
38 #define MLX4_SQ_STAMP_VAL 0x7fffffff
40 /* Work queue element (WQE) flags. */
41 #define MLX4_WQE_CTRL_IIP_HDR_CSUM (1 << 28)
42 #define MLX4_WQE_CTRL_IL4_HDR_CSUM (1 << 27)
44 /* CQE checksum flags. */
46 MLX4_CQE_L2_TUNNEL_IPV4 = (int)(1u << 25),
47 MLX4_CQE_L2_TUNNEL_L4_CSUM = (int)(1u << 26),
48 MLX4_CQE_L2_TUNNEL = (int)(1u << 27),
49 MLX4_CQE_L2_VLAN_MASK = (int)(3u << 29),
50 MLX4_CQE_L2_TUNNEL_IPOK = (int)(1u << 31),
53 /* CQE status flags. */
54 #define MLX4_CQE_STATUS_IPV4 (1 << 22)
55 #define MLX4_CQE_STATUS_IPV4F (1 << 23)
56 #define MLX4_CQE_STATUS_IPV6 (1 << 24)
57 #define MLX4_CQE_STATUS_IPV4OPT (1 << 25)
58 #define MLX4_CQE_STATUS_TCP (1 << 26)
59 #define MLX4_CQE_STATUS_UDP (1 << 27)
60 #define MLX4_CQE_STATUS_PTYPE_MASK \
61 (MLX4_CQE_STATUS_IPV4 | \
62 MLX4_CQE_STATUS_IPV4F | \
63 MLX4_CQE_STATUS_IPV6 | \
64 MLX4_CQE_STATUS_IPV4OPT | \
65 MLX4_CQE_STATUS_TCP | \
68 /* Send queue information. */
70 volatile uint8_t *buf; /**< SQ buffer. */
71 volatile uint8_t *eob; /**< End of SQ buffer */
72 uint32_t size; /**< SQ size includes headroom. */
73 uint32_t remain_size; /**< Remaining WQE room in SQ (bytes). */
74 uint32_t owner_opcode;
75 /**< Default owner opcode with HW valid owner bit. */
76 uint32_t stamp; /**< Stamp value with an invalid HW owner bit. */
77 volatile uint32_t *db; /**< Pointer to the doorbell. */
78 uint32_t doorbell_qpn; /**< qp number to write to the doorbell. */
81 /* Completion queue events, numbers and masks. */
82 #define MLX4_CQ_DB_GEQ_N_MASK 0x3
83 #define MLX4_CQ_DOORBELL 0x20
84 #define MLX4_CQ_DB_CI_MASK 0xffffff
86 /* Completion queue information. */
88 volatile void *cq_uar; /**< CQ user access region. */
89 volatile void *cq_db_reg; /**< CQ doorbell register. */
90 volatile uint32_t *set_ci_db; /**< Pointer to the CQ doorbell. */
91 volatile uint32_t *arm_db; /**< Arming Rx events doorbell. */
92 volatile uint8_t *buf; /**< Pointer to the completion queue buffer. */
93 uint32_t cqe_cnt; /**< Number of entries in the queue. */
94 uint32_t cqe_64:1; /**< CQ entry size is 64 bytes. */
95 uint32_t cons_index; /**< Last queue entry that was handled. */
96 uint32_t cqn; /**< CQ number. */
97 int arm_sn; /**< Rx event counter. */
101 * Retrieve a CQE entry from a CQ.
103 * cqe = cq->buf + cons_index * cqe_size + cqe_offset
105 * Where cqe_size is 32 or 64 bytes and cqe_offset is 0 or 32 (depending on
109 * CQ to retrieve entry from.
114 * Pointer to CQE entry.
116 static inline volatile struct mlx4_cqe *
117 mlx4_get_cqe(struct mlx4_cq *cq, uint32_t index)
119 return (volatile struct mlx4_cqe *)(cq->buf +
120 ((index & (cq->cqe_cnt - 1)) <<
126 * Transpose a flag in a value.
131 * Flag to retrieve from input value.
133 * Flag to set in output value.
136 * Output value with transposed flag enabled if present on input.
138 static inline uint64_t
139 mlx4_transpose(uint64_t val, uint64_t from, uint64_t to)
142 (val & from) / (from / to) :
143 (val & from) * (to / from));
146 #endif /* MLX4_PRM_H_ */