/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
/* Copyright (c) 2019 Mellanox Technologies. */

#ifndef __MLX5_EN_XSK_TX_H__
#define __MLX5_EN_XSK_TX_H__

#ifdef HAVE_XSK_ZERO_COPY_SUPPORT

#include "en.h"
#ifdef HAVE_NDO_XSK_WAKEUP
#ifdef HAVE_XDP_SOCK_DRV_H
#include <net/xdp_sock_drv.h>
#else
#include <net/xdp_sock.h>
#endif
#endif

/* TX data path */

int mlx5e_xsk_wakeup(struct net_device *dev, u32 qid
#ifdef HAVE_NDO_XSK_WAKEUP
		    , u32 flags
#endif
		    );

bool mlx5e_xsk_tx(struct mlx5e_xdpsq *sq, unsigned int budget);

#ifdef HAVE_NDO_XSK_WAKEUP
static inline void mlx5e_xsk_update_tx_wakeup(struct mlx5e_xdpsq *sq)
{
#ifdef HAVE_NETDEV_BPF_XSK_BUFF_POOL
	if (!xsk_uses_need_wakeup(sq->xsk_pool))
		return;

	if (sq->pc != sq->cc)
		xsk_clear_tx_need_wakeup(sq->xsk_pool);
	else
		xsk_set_tx_need_wakeup(sq->xsk_pool);
#else
	if (!xsk_umem_uses_need_wakeup(sq->umem))
		return;

	if (sq->pc != sq->cc)
		xsk_clear_tx_need_wakeup(sq->umem);
	else
		xsk_set_tx_need_wakeup(sq->umem);
#endif

}
#endif

#endif /* HAVE_XSK_ZERO_COPY_SUPPORT */
#endif /* __MLX5_EN_XSK_TX_H__ */
