1159d2131STariq Toukan /* 2159d2131STariq Toukan * Copyright (c) 2018, Mellanox Technologies. All rights reserved. 3159d2131STariq Toukan * 4159d2131STariq Toukan * This software is available to you under a choice of one of two 5159d2131STariq Toukan * licenses. You may choose to be licensed under the terms of the GNU 6159d2131STariq Toukan * General Public License (GPL) Version 2, available from the file 7159d2131STariq Toukan * COPYING in the main directory of this source tree, or the 8159d2131STariq Toukan * OpenIB.org BSD license below: 9159d2131STariq Toukan * 10159d2131STariq Toukan * Redistribution and use in source and binary forms, with or 11159d2131STariq Toukan * without modification, are permitted provided that the following 12159d2131STariq Toukan * conditions are met: 13159d2131STariq Toukan * 14159d2131STariq Toukan * - Redistributions of source code must retain the above 15159d2131STariq Toukan * copyright notice, this list of conditions and the following 16159d2131STariq Toukan * disclaimer. 17159d2131STariq Toukan * 18159d2131STariq Toukan * - Redistributions in binary form must reproduce the above 19159d2131STariq Toukan * copyright notice, this list of conditions and the following 20159d2131STariq Toukan * disclaimer in the documentation and/or other materials 21159d2131STariq Toukan * provided with the distribution. 22159d2131STariq Toukan * 23159d2131STariq Toukan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24159d2131STariq Toukan * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25159d2131STariq Toukan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26159d2131STariq Toukan * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27159d2131STariq Toukan * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28159d2131STariq Toukan * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29159d2131STariq Toukan * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30159d2131STariq Toukan * SOFTWARE. 31159d2131STariq Toukan */ 32159d2131STariq Toukan #ifndef __MLX5_EN_XDP_H__ 33159d2131STariq Toukan #define __MLX5_EN_XDP_H__ 34159d2131STariq Toukan 35159d2131STariq Toukan #include "en.h" 36159d2131STariq Toukan 37159d2131STariq Toukan #define MLX5E_XDP_MAX_MTU ((int)(PAGE_SIZE - \ 38159d2131STariq Toukan MLX5_SKB_FRAG_SZ(XDP_PACKET_HEADROOM))) 39159d2131STariq Toukan #define MLX5E_XDP_MIN_INLINE (ETH_HLEN + VLAN_HLEN) 405e0d2eefSTariq Toukan #define MLX5E_XDP_TX_EMPTY_DS_COUNT \ 415e0d2eefSTariq Toukan (sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS) 425e0d2eefSTariq Toukan #define MLX5E_XDP_TX_DS_COUNT (MLX5E_XDP_TX_EMPTY_DS_COUNT + 1 /* SG DS */) 43159d2131STariq Toukan 44159d2131STariq Toukan bool mlx5e_xdp_handle(struct mlx5e_rq *rq, struct mlx5e_dma_info *di, 45159d2131STariq Toukan void *va, u16 *rx_headroom, u32 *len); 46feb2ff9dSTariq Toukan bool mlx5e_poll_xdpsq_cq(struct mlx5e_cq *cq, struct mlx5e_rq *rq); 47feb2ff9dSTariq Toukan void mlx5e_free_xdpsq_descs(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq); 485e0d2eefSTariq Toukan void mlx5e_set_xmit_fp(struct mlx5e_xdpsq *sq, bool is_mpw); 494fb2f516STariq Toukan void mlx5e_xdp_rx_poll_complete(struct mlx5e_rq *rq); 5058b99ee3STariq Toukan int mlx5e_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, 5158b99ee3STariq Toukan u32 flags); 52159d2131STariq Toukan 53407e17b1SSaeed Mahameed static inline void mlx5e_xdp_tx_enable(struct mlx5e_priv *priv) 54407e17b1SSaeed Mahameed { 55407e17b1SSaeed Mahameed set_bit(MLX5E_STATE_XDP_TX_ENABLED, &priv->state); 56407e17b1SSaeed Mahameed } 57407e17b1SSaeed Mahameed 58407e17b1SSaeed Mahameed static inline void mlx5e_xdp_tx_disable(struct mlx5e_priv *priv) 59407e17b1SSaeed Mahameed { 60407e17b1SSaeed Mahameed clear_bit(MLX5E_STATE_XDP_TX_ENABLED, &priv->state); 61407e17b1SSaeed Mahameed /* let other device's napi(s) see our new state */ 62407e17b1SSaeed Mahameed synchronize_rcu(); 63407e17b1SSaeed Mahameed } 64407e17b1SSaeed Mahameed 65407e17b1SSaeed Mahameed static inline bool mlx5e_xdp_tx_is_enabled(struct mlx5e_priv *priv) 66407e17b1SSaeed Mahameed { 67407e17b1SSaeed Mahameed return test_bit(MLX5E_STATE_XDP_TX_ENABLED, &priv->state); 68407e17b1SSaeed Mahameed } 69407e17b1SSaeed Mahameed 70159d2131STariq Toukan static inline void mlx5e_xmit_xdp_doorbell(struct mlx5e_xdpsq *sq) 71159d2131STariq Toukan { 72b8180392STariq Toukan if (sq->doorbell_cseg) { 73b8180392STariq Toukan mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, sq->doorbell_cseg); 74b8180392STariq Toukan sq->doorbell_cseg = NULL; 75b8180392STariq Toukan } 76159d2131STariq Toukan } 77159d2131STariq Toukan 78fea28dd6STariq Toukan static inline void 795e0d2eefSTariq Toukan mlx5e_xdp_mpwqe_add_dseg(struct mlx5e_xdpsq *sq, dma_addr_t dma_addr, u16 dma_len) 805e0d2eefSTariq Toukan { 815e0d2eefSTariq Toukan struct mlx5e_xdp_mpwqe *session = &sq->mpwqe; 825e0d2eefSTariq Toukan struct mlx5_wqe_data_seg *dseg = 835e0d2eefSTariq Toukan (struct mlx5_wqe_data_seg *)session->wqe + session->ds_count++; 845e0d2eefSTariq Toukan 855e0d2eefSTariq Toukan dseg->addr = cpu_to_be64(dma_addr); 865e0d2eefSTariq Toukan dseg->byte_count = cpu_to_be32(dma_len); 875e0d2eefSTariq Toukan dseg->lkey = sq->mkey_be; 885e0d2eefSTariq Toukan } 895e0d2eefSTariq Toukan 905e0d2eefSTariq Toukan static inline void mlx5e_xdpsq_fetch_wqe(struct mlx5e_xdpsq *sq, 915e0d2eefSTariq Toukan struct mlx5e_tx_wqe **wqe) 925e0d2eefSTariq Toukan { 935e0d2eefSTariq Toukan struct mlx5_wq_cyc *wq = &sq->wq; 945e0d2eefSTariq Toukan u16 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc); 955e0d2eefSTariq Toukan 965e0d2eefSTariq Toukan *wqe = mlx5_wq_cyc_get_wqe(wq, pi); 975e0d2eefSTariq Toukan memset(*wqe, 0, sizeof(**wqe)); 985e0d2eefSTariq Toukan } 995e0d2eefSTariq Toukan 1005e0d2eefSTariq Toukan static inline void 101fea28dd6STariq Toukan mlx5e_xdpi_fifo_push(struct mlx5e_xdp_info_fifo *fifo, 102fea28dd6STariq Toukan struct mlx5e_xdp_info *xi) 103fea28dd6STariq Toukan { 104fea28dd6STariq Toukan u32 i = (*fifo->pc)++ & fifo->mask; 105fea28dd6STariq Toukan 106fea28dd6STariq Toukan fifo->xi[i] = *xi; 107fea28dd6STariq Toukan } 108fea28dd6STariq Toukan 109fea28dd6STariq Toukan static inline struct mlx5e_xdp_info 110fea28dd6STariq Toukan mlx5e_xdpi_fifo_pop(struct mlx5e_xdp_info_fifo *fifo) 111fea28dd6STariq Toukan { 112fea28dd6STariq Toukan return fifo->xi[(*fifo->cc)++ & fifo->mask]; 113fea28dd6STariq Toukan } 114fea28dd6STariq Toukan 115159d2131STariq Toukan #endif 116