1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2018-2022 Advanced Micro Devices, Inc. 3 */ 4 5 #ifndef _IONIC_RXTX_H_ 6 #define _IONIC_RXTX_H_ 7 8 #include <stdint.h> 9 10 #include "ionic_if.h" 11 12 struct ionic_rx_qcq; 13 struct ionic_tx_qcq; 14 struct rte_eth_dev; 15 struct rte_eth_rxconf; 16 struct rte_eth_rxq_info; 17 struct rte_eth_txconf; 18 struct rte_eth_txq_info; 19 struct rte_mbuf; 20 struct rte_mempool; 21 22 struct ionic_rx_service { 23 /* cb in */ 24 struct rte_mbuf **rx_pkts; 25 /* cb out */ 26 uint16_t nb_rx; 27 }; 28 29 #define IONIC_CSUM_FLAG_MASK (IONIC_RXQ_COMP_CSUM_F_VLAN - 1) 30 31 extern const uint64_t ionic_csum_flags[IONIC_CSUM_FLAG_MASK]; 32 extern const uint32_t ionic_ptype_table[IONIC_RXQ_COMP_PKT_TYPE_MASK]; 33 34 /* ionic_rxtx.c */ 35 int ionic_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id, 36 uint16_t nb_desc, uint32_t socket_id, 37 const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp); 38 void ionic_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid); 39 int ionic_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id); 40 int ionic_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id); 41 42 int ionic_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id, 43 uint16_t nb_desc, uint32_t socket_id, 44 const struct rte_eth_txconf *tx_conf); 45 void ionic_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid); 46 int ionic_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id); 47 int ionic_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id); 48 49 /* Helpers for optimized dev_start() */ 50 int ionic_dev_rx_queue_start_firsthalf(struct rte_eth_dev *dev, 51 uint16_t rx_queue_id); 52 int ionic_dev_rx_queue_start_secondhalf(struct rte_eth_dev *dev, 53 uint16_t rx_queue_id); 54 int ionic_dev_tx_queue_start_firsthalf(struct rte_eth_dev *dev, 55 uint16_t tx_queue_id); 56 int ionic_dev_tx_queue_start_secondhalf(struct rte_eth_dev *dev, 57 uint16_t tx_queue_id); 58 59 /* Helpers for optimized dev_stop() */ 60 void ionic_dev_rx_queue_stop_firsthalf(struct rte_eth_dev *dev, 61 uint16_t rx_queue_id); 62 void ionic_dev_rx_queue_stop_secondhalf(struct rte_eth_dev *dev, 63 uint16_t rx_queue_id); 64 void ionic_dev_tx_queue_stop_firsthalf(struct rte_eth_dev *dev, 65 uint16_t tx_queue_id); 66 void ionic_dev_tx_queue_stop_secondhalf(struct rte_eth_dev *dev, 67 uint16_t tx_queue_id); 68 69 void ionic_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 70 struct rte_eth_rxq_info *qinfo); 71 void ionic_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 72 struct rte_eth_txq_info *qinfo); 73 74 int ionic_dev_rx_descriptor_status(void *rx_queue, uint16_t offset); 75 int ionic_dev_tx_descriptor_status(void *tx_queue, uint16_t offset); 76 77 const uint32_t *ionic_dev_supported_ptypes_get(struct rte_eth_dev *dev, 78 size_t *no_of_elements); 79 80 int ionic_tx_tso(struct ionic_tx_qcq *txq, struct rte_mbuf *txm); 81 82 uint16_t ionic_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, 83 uint16_t nb_pkts); 84 85 /* ionic_rxtx_simple.c */ 86 uint16_t ionic_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, 87 uint16_t nb_pkts); 88 uint16_t ionic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, 89 uint16_t nb_pkts); 90 91 int ionic_rx_fill(struct ionic_rx_qcq *rxq); 92 93 /* ionic_rxtx_sg.c */ 94 uint16_t ionic_recv_pkts_sg(void *rx_queue, struct rte_mbuf **rx_pkts, 95 uint16_t nb_pkts); 96 uint16_t ionic_xmit_pkts_sg(void *tx_queue, struct rte_mbuf **tx_pkts, 97 uint16_t nb_pkts); 98 99 int ionic_rx_fill_sg(struct ionic_rx_qcq *rxq); 100 101 static inline void 102 ionic_rxq_flush(struct ionic_queue *q) 103 { 104 struct ionic_rxq_desc *desc_base = q->base; 105 struct ionic_rxq_desc *cmb_desc_base = q->cmb_base; 106 107 if (q->cmb_base) { 108 if (q->head_idx < q->cmb_head_idx) { 109 /* copy [cmb_head, num_descs) */ 110 rte_memcpy((void *)&cmb_desc_base[q->cmb_head_idx], 111 (void *)&desc_base[q->cmb_head_idx], 112 (q->num_descs - q->cmb_head_idx) * sizeof(*desc_base)); 113 /* copy [0, head) */ 114 rte_memcpy((void *)&cmb_desc_base[0], 115 (void *)&desc_base[0], 116 q->head_idx * sizeof(*desc_base)); 117 } else { 118 /* copy [cmb_head, head) */ 119 rte_memcpy((void *)&cmb_desc_base[q->cmb_head_idx], 120 (void *)&desc_base[q->cmb_head_idx], 121 (q->head_idx - q->cmb_head_idx) * sizeof(*desc_base)); 122 } 123 q->cmb_head_idx = q->head_idx; 124 } 125 126 ionic_q_flush(q); 127 } 128 129 static inline void 130 ionic_txq_flush(struct ionic_queue *q) 131 { 132 struct ionic_txq_desc *desc_base = q->base; 133 struct ionic_txq_desc *cmb_desc_base = q->cmb_base; 134 135 if (q->cmb_base) { 136 if (q->head_idx < q->cmb_head_idx) { 137 /* copy [cmb_head, num_descs) */ 138 rte_memcpy((void *)&cmb_desc_base[q->cmb_head_idx], 139 (void *)&desc_base[q->cmb_head_idx], 140 (q->num_descs - q->cmb_head_idx) * sizeof(*desc_base)); 141 /* copy [0, head) */ 142 rte_memcpy((void *)&cmb_desc_base[0], 143 (void *)&desc_base[0], 144 q->head_idx * sizeof(*desc_base)); 145 } else { 146 /* copy [cmb_head, head) */ 147 rte_memcpy((void *)&cmb_desc_base[q->cmb_head_idx], 148 (void *)&desc_base[q->cmb_head_idx], 149 (q->head_idx - q->cmb_head_idx) * sizeof(*desc_base)); 150 } 151 q->cmb_head_idx = q->head_idx; 152 } 153 154 ionic_q_flush(q); 155 } 156 157 #endif /* _IONIC_RXTX_H_ */ 158