1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019 Mellanox Technologies. */
4 #ifndef __MLX5_EN_TXRX_H___
5 #define __MLX5_EN_TXRX_H___
9 #define MLX5E_SQ_NOPS_ROOM (MLX5_SEND_WQE_MAX_WQEBBS - 1)
10 #define MLX5E_SQ_STOP_ROOM (MLX5_SEND_WQE_MAX_WQEBBS +\
13 #ifndef CONFIG_MLX5_EN_TLS
14 #define MLX5E_SQ_TLS_ROOM (0)
16 /* TLS offload requires additional stop_room for:
18 * kTLS offload requires additional stop_room for:
19 * - static params WQE,
20 * - progress params WQE, and
21 * - resync DUMP per frag.
23 #define MLX5E_SQ_TLS_ROOM \
24 (MLX5_SEND_WQE_MAX_WQEBBS + \
25 MLX5E_KTLS_STATIC_WQEBBS + MLX5E_KTLS_PROGRESS_WQEBBS + \
26 MAX_SKB_FRAGS * MLX5E_KTLS_MAX_DUMP_WQEBBS)
29 #define INL_HDR_START_SZ (sizeof(((struct mlx5_wqe_eth_seg *)NULL)->inline_hdr.start))
32 mlx5e_wqc_has_room_for(struct mlx5_wq_cyc *wq, u16 cc, u16 pc, u16 n)
34 return (mlx5_wq_cyc_ctr2ix(wq, cc - pc) >= n) || (cc == pc);
38 mlx5e_sq_fetch_wqe(struct mlx5e_txqsq *sq, size_t size, u16 *pi)
40 struct mlx5_wq_cyc *wq = &sq->wq;
43 *pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
44 wqe = mlx5_wq_cyc_get_wqe(wq, *pi);
50 static inline struct mlx5e_tx_wqe *
51 mlx5e_post_nop(struct mlx5_wq_cyc *wq, u32 sqn, u16 *pc)
53 u16 pi = mlx5_wq_cyc_ctr2ix(wq, *pc);
54 struct mlx5e_tx_wqe *wqe = mlx5_wq_cyc_get_wqe(wq, pi);
55 struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl;
57 memset(cseg, 0, sizeof(*cseg));
59 cseg->opmod_idx_opcode = cpu_to_be32((*pc << 8) | MLX5_OPCODE_NOP);
60 cseg->qpn_ds = cpu_to_be32((sqn << 8) | 0x01);
67 static inline struct mlx5e_tx_wqe *
68 mlx5e_post_nop_fence(struct mlx5_wq_cyc *wq, u32 sqn, u16 *pc)
70 u16 pi = mlx5_wq_cyc_ctr2ix(wq, *pc);
71 struct mlx5e_tx_wqe *wqe = mlx5_wq_cyc_get_wqe(wq, pi);
72 struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl;
74 memset(cseg, 0, sizeof(*cseg));
76 cseg->opmod_idx_opcode = cpu_to_be32((*pc << 8) | MLX5_OPCODE_NOP);
77 cseg->qpn_ds = cpu_to_be32((sqn << 8) | 0x01);
78 cseg->fm_ce_se = MLX5_FENCE_MODE_INITIATOR_SMALL;
86 mlx5e_fill_sq_frag_edge(struct mlx5e_txqsq *sq, struct mlx5_wq_cyc *wq,
89 struct mlx5e_tx_wqe_info *edge_wi, *wi = &sq->db.wqe_info[pi];
93 /* fill sq frag edge with nops to avoid wqe wrapping two pages */
94 for (; wi < edge_wi; wi++) {
97 mlx5e_post_nop(wq, sq->sqn, &sq->pc);
99 sq->stats->nop += nnops;
103 mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc, void __iomem *uar_map,
104 struct mlx5_wqe_ctrl_seg *ctrl)
106 ctrl->fm_ce_se = MLX5_WQE_CTRL_CQ_UPDATE;
107 /* ensure wqe is visible to device before updating doorbell record */
110 *wq->db = cpu_to_be32(pc);
112 /* ensure doorbell record is visible to device before ringing the
117 mlx5_write64((__be32 *)ctrl, uar_map);
120 static inline bool mlx5e_transport_inline_tx_wqe(struct mlx5_wqe_ctrl_seg *cseg)
122 return cseg && !!cseg->tisn;
126 mlx5e_tx_wqe_inline_mode(struct mlx5e_txqsq *sq, struct mlx5_wqe_ctrl_seg *cseg,
131 if (mlx5e_transport_inline_tx_wqe(cseg))
132 return MLX5_INLINE_MODE_TCP_UDP;
134 mode = sq->min_inline_mode;
136 if (skb_vlan_tag_present(skb) &&
137 test_bit(MLX5E_SQ_STATE_VLAN_NEED_L2_INLINE, &sq->state))
138 mode = max_t(u8, MLX5_INLINE_MODE_L2, mode);
143 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
145 struct mlx5_core_cq *mcq;
148 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, cq->wq.cc);
151 static inline struct mlx5e_sq_dma *
152 mlx5e_dma_get(struct mlx5e_txqsq *sq, u32 i)
154 return &sq->db.dma_fifo[i & sq->dma_fifo_mask];
158 mlx5e_dma_push(struct mlx5e_txqsq *sq, dma_addr_t addr, u32 size,
159 enum mlx5e_dma_map_type map_type)
161 struct mlx5e_sq_dma *dma = mlx5e_dma_get(sq, sq->dma_fifo_pc++);
165 dma->type = map_type;
169 mlx5e_tx_dma_unmap(struct device *pdev, struct mlx5e_sq_dma *dma)
172 case MLX5E_DMA_MAP_SINGLE:
173 dma_unmap_single(pdev, dma->addr, dma->size, DMA_TO_DEVICE);
175 case MLX5E_DMA_MAP_PAGE:
176 dma_unmap_page(pdev, dma->addr, dma->size, DMA_TO_DEVICE);
179 WARN_ONCE(true, "mlx5e_tx_dma_unmap unknown DMA type!\n");
183 /* SW parser related functions */
185 struct mlx5e_swp_spec {
194 mlx5e_set_eseg_swp(struct sk_buff *skb, struct mlx5_wqe_eth_seg *eseg,
195 struct mlx5e_swp_spec *swp_spec)
197 /* SWP offsets are in 2-bytes words */
198 eseg->swp_outer_l3_offset = skb_network_offset(skb) / 2;
199 if (swp_spec->l3_proto == htons(ETH_P_IPV6))
200 eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L3_IPV6;
201 if (swp_spec->l4_proto) {
202 eseg->swp_outer_l4_offset = skb_transport_offset(skb) / 2;
203 if (swp_spec->l4_proto == IPPROTO_UDP)
204 eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L4_UDP;
207 if (swp_spec->is_tun) {
208 eseg->swp_inner_l3_offset = skb_inner_network_offset(skb) / 2;
209 if (swp_spec->tun_l3_proto == htons(ETH_P_IPV6))
210 eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
211 } else { /* typically for ipsec when xfrm mode != XFRM_MODE_TUNNEL */
212 eseg->swp_inner_l3_offset = skb_network_offset(skb) / 2;
213 if (swp_spec->l3_proto == htons(ETH_P_IPV6))
214 eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
216 switch (swp_spec->tun_l4_proto) {
218 eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L4_UDP;
221 eseg->swp_inner_l4_offset = skb_inner_transport_offset(skb) / 2;