1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) 2016 Solarflare Communications Inc. 5 * All rights reserved. 6 * 7 * This software was jointly developed between OKTET Labs (under contract 8 * for Solarflare) and Solarflare Communications, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _SFC_DP_TX_H 33 #define _SFC_DP_TX_H 34 35 #include <rte_ethdev.h> 36 37 #include "sfc_dp.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /** 44 * Generic transmit queue information used on data path. 45 * It must be kept as small as it is possible since it is built into 46 * the structure used on datapath. 47 */ 48 struct sfc_dp_txq { 49 struct sfc_dp_queue dpq; 50 }; 51 52 /** 53 * Datapath transmit queue creation information. 54 * 55 * The structure is used just to pass information from control path to 56 * datapath. It could be just function arguments, but it would be hardly 57 * readable. 58 */ 59 struct sfc_dp_tx_qcreate_info { 60 /** Minimum number of unused Tx descriptors to do reap */ 61 unsigned int free_thresh; 62 /** Transmit queue configuration flags */ 63 unsigned int flags; 64 /** Tx queue size */ 65 unsigned int txq_entries; 66 /** Maximum size of data in the DMA descriptor */ 67 uint16_t dma_desc_size_max; 68 /** DMA-mapped Tx descriptors ring */ 69 void *txq_hw_ring; 70 /** Associated event queue size */ 71 unsigned int evq_entries; 72 /** Hardware event ring */ 73 void *evq_hw_ring; 74 /** The queue index in hardware (required to push right doorbell) */ 75 unsigned int hw_index; 76 /** Virtual address of the memory-mapped BAR to push Tx doorbell */ 77 volatile void *mem_bar; 78 }; 79 80 /** 81 * Allocate and initialize datapath transmit queue. 82 * 83 * @param port_id The port identifier 84 * @param queue_id The queue identifier 85 * @param pci_addr PCI function address 86 * @param socket_id Socket identifier to allocate memory 87 * @param info Tx queue details wrapped in structure 88 * @param dp_txqp Location for generic datapath transmit queue pointer 89 * 90 * @return 0 or positive errno. 91 */ 92 typedef int (sfc_dp_tx_qcreate_t)(uint16_t port_id, uint16_t queue_id, 93 const struct rte_pci_addr *pci_addr, 94 int socket_id, 95 const struct sfc_dp_tx_qcreate_info *info, 96 struct sfc_dp_txq **dp_txqp); 97 98 /** 99 * Free resources allocated for datapath transmit queue. 100 */ 101 typedef void (sfc_dp_tx_qdestroy_t)(struct sfc_dp_txq *dp_txq); 102 103 /** 104 * Transmit queue start callback. 105 * 106 * It handovers EvQ to the datapath. 107 */ 108 typedef int (sfc_dp_tx_qstart_t)(struct sfc_dp_txq *dp_txq, 109 unsigned int evq_read_ptr, 110 unsigned int txq_desc_index); 111 112 /** 113 * Transmit queue stop function called before the queue flush. 114 * 115 * It returns EvQ to the control path. 116 */ 117 typedef void (sfc_dp_tx_qstop_t)(struct sfc_dp_txq *dp_txq, 118 unsigned int *evq_read_ptr); 119 120 /** 121 * Transmit event handler used during queue flush only. 122 */ 123 typedef bool (sfc_dp_tx_qtx_ev_t)(struct sfc_dp_txq *dp_txq, unsigned int id); 124 125 /** 126 * Transmit queue function called after the queue flush. 127 */ 128 typedef void (sfc_dp_tx_qreap_t)(struct sfc_dp_txq *dp_txq); 129 130 /** 131 * Check Tx descriptor status 132 */ 133 typedef int (sfc_dp_tx_qdesc_status_t)(struct sfc_dp_txq *dp_txq, 134 uint16_t offset); 135 136 /** Transmit datapath definition */ 137 struct sfc_dp_tx { 138 struct sfc_dp dp; 139 140 unsigned int features; 141 #define SFC_DP_TX_FEAT_VLAN_INSERT 0x1 142 #define SFC_DP_TX_FEAT_TSO 0x2 143 #define SFC_DP_TX_FEAT_MULTI_SEG 0x4 144 #define SFC_DP_TX_FEAT_MULTI_PROCESS 0x8 145 #define SFC_DP_TX_FEAT_MULTI_POOL 0x10 146 #define SFC_DP_TX_FEAT_REFCNT 0x20 147 sfc_dp_tx_qcreate_t *qcreate; 148 sfc_dp_tx_qdestroy_t *qdestroy; 149 sfc_dp_tx_qstart_t *qstart; 150 sfc_dp_tx_qstop_t *qstop; 151 sfc_dp_tx_qtx_ev_t *qtx_ev; 152 sfc_dp_tx_qreap_t *qreap; 153 sfc_dp_tx_qdesc_status_t *qdesc_status; 154 eth_tx_burst_t pkt_burst; 155 }; 156 157 static inline struct sfc_dp_tx * 158 sfc_dp_find_tx_by_name(struct sfc_dp_list *head, const char *name) 159 { 160 struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_TX, name); 161 162 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp); 163 } 164 165 static inline struct sfc_dp_tx * 166 sfc_dp_find_tx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps) 167 { 168 struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_TX, avail_caps); 169 170 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp); 171 } 172 173 extern struct sfc_dp_tx sfc_efx_tx; 174 extern struct sfc_dp_tx sfc_ef10_tx; 175 extern struct sfc_dp_tx sfc_ef10_simple_tx; 176 177 #ifdef __cplusplus 178 } 179 #endif 180 #endif /* _SFC_DP_TX_H */ 181