18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2020, Mellanox Technologies inc. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _MLX5_IB_WR_H
78c2ecf20Sopenharmony_ci#define _MLX5_IB_WR_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "mlx5_ib.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cienum {
128c2ecf20Sopenharmony_ci	MLX5_IB_SQ_UMR_INLINE_THRESHOLD = 64,
138c2ecf20Sopenharmony_ci};
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct mlx5_wqe_eth_pad {
168c2ecf20Sopenharmony_ci	u8 rsvd0[16];
178c2ecf20Sopenharmony_ci};
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* get_sq_edge - Get the next nearby edge.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * An 'edge' is defined as the first following address after the end
238c2ecf20Sopenharmony_ci * of the fragment or the SQ. Accordingly, during the WQE construction
248c2ecf20Sopenharmony_ci * which repetitively increases the pointer to write the next data, it
258c2ecf20Sopenharmony_ci * simply should check if it gets to an edge.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * @sq - SQ buffer.
288c2ecf20Sopenharmony_ci * @idx - Stride index in the SQ buffer.
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci * Return:
318c2ecf20Sopenharmony_ci *	The new edge.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_cistatic inline void *get_sq_edge(struct mlx5_ib_wq *sq, u32 idx)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	void *fragment_end;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	fragment_end = mlx5_frag_buf_get_wqe
388c2ecf20Sopenharmony_ci		(&sq->fbc,
398c2ecf20Sopenharmony_ci		 mlx5_frag_buf_get_idx_last_contig_stride(&sq->fbc, idx));
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	return fragment_end + MLX5_SEND_WQE_BB;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciint mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
458c2ecf20Sopenharmony_ci		      const struct ib_send_wr **bad_wr, bool drain);
468c2ecf20Sopenharmony_ciint mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
478c2ecf20Sopenharmony_ci		      const struct ib_recv_wr **bad_wr, bool drain);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic inline int mlx5_ib_post_send_nodrain(struct ib_qp *ibqp,
508c2ecf20Sopenharmony_ci					    const struct ib_send_wr *wr,
518c2ecf20Sopenharmony_ci					    const struct ib_send_wr **bad_wr)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	return mlx5_ib_post_send(ibqp, wr, bad_wr, false);
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic inline int mlx5_ib_post_send_drain(struct ib_qp *ibqp,
578c2ecf20Sopenharmony_ci					  const struct ib_send_wr *wr,
588c2ecf20Sopenharmony_ci					  const struct ib_send_wr **bad_wr)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	return mlx5_ib_post_send(ibqp, wr, bad_wr, true);
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic inline int mlx5_ib_post_recv_nodrain(struct ib_qp *ibqp,
648c2ecf20Sopenharmony_ci					    const struct ib_recv_wr *wr,
658c2ecf20Sopenharmony_ci					    const struct ib_recv_wr **bad_wr)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	return mlx5_ib_post_recv(ibqp, wr, bad_wr, false);
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic inline int mlx5_ib_post_recv_drain(struct ib_qp *ibqp,
718c2ecf20Sopenharmony_ci					  const struct ib_recv_wr *wr,
728c2ecf20Sopenharmony_ci					  const struct ib_recv_wr **bad_wr)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	return mlx5_ib_post_recv(ibqp, wr, bad_wr, true);
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci#endif /* _MLX5_IB_WR_H */
77