Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * 3 : : * Copyright(c) 2019-2021 Xilinx, Inc. 4 : : * Copyright(c) 2016-2019 Solarflare Communications Inc. 5 : : * 6 : : * This software was jointly developed between OKTET Labs (under contract 7 : : * for Solarflare) and Solarflare Communications, Inc. 8 : : */ 9 : : 10 : : #ifndef _SFC_DP_TX_H 11 : : #define _SFC_DP_TX_H 12 : : 13 : : #include <ethdev_driver.h> 14 : : 15 : : #include "sfc_dp.h" 16 : : #include "sfc_debug.h" 17 : : #include "sfc_tso.h" 18 : : #include "sfc_nic_dma_dp.h" 19 : : 20 : : #ifdef __cplusplus 21 : : extern "C" { 22 : : #endif 23 : : 24 : : /** 25 : : * Generic transmit queue information used on data path. 26 : : * It must be kept as small as it is possible since it is built into 27 : : * the structure used on datapath. 28 : : */ 29 : : struct sfc_dp_txq { 30 : : struct sfc_dp_queue dpq; 31 : : }; 32 : : 33 : : /** Datapath transmit queue descriptor number limitations */ 34 : : struct sfc_dp_tx_hw_limits { 35 : : unsigned int txq_max_entries; 36 : : unsigned int txq_min_entries; 37 : : }; 38 : : 39 : : /** 40 : : * Datapath transmit queue creation information. 41 : : * 42 : : * The structure is used just to pass information from control path to 43 : : * datapath. It could be just function arguments, but it would be hardly 44 : : * readable. 45 : : */ 46 : : struct sfc_dp_tx_qcreate_info { 47 : : /** Maximum number of pushed Tx descriptors */ 48 : : unsigned int max_fill_level; 49 : : /** Minimum number of unused Tx descriptors to do reap */ 50 : : unsigned int free_thresh; 51 : : /** Offloads enabled on the transmit queue */ 52 : : uint64_t offloads; 53 : : /** Tx queue size */ 54 : : unsigned int txq_entries; 55 : : /** Maximum size of data in the DMA descriptor */ 56 : : uint16_t dma_desc_size_max; 57 : : /** DMA-mapped Tx descriptors ring */ 58 : : void *txq_hw_ring; 59 : : /** Associated event queue size */ 60 : : unsigned int evq_entries; 61 : : /** Hardware event ring */ 62 : : void *evq_hw_ring; 63 : : /** The queue index in hardware (required to push right doorbell) */ 64 : : unsigned int hw_index; 65 : : /** Virtual address of the memory-mapped BAR to push Tx doorbell */ 66 : : volatile void *mem_bar; 67 : : /** VI window size shift */ 68 : : unsigned int vi_window_shift; 69 : : /** 70 : : * Maximum number of bytes into the packet the TCP header can start for 71 : : * the hardware to apply TSO packet edits. 72 : : */ 73 : : uint16_t tso_tcp_header_offset_limit; 74 : : /** Maximum number of header DMA descriptors per TSOv3 transaction */ 75 : : uint16_t tso_max_nb_header_descs; 76 : : /** Maximum header length acceptable by TSOv3 transaction */ 77 : : uint16_t tso_max_header_len; 78 : : /** Maximum number of payload DMA descriptors per TSOv3 transaction */ 79 : : uint16_t tso_max_nb_payload_descs; 80 : : /** Maximum payload length per TSOv3 transaction */ 81 : : uint32_t tso_max_payload_len; 82 : : /** Maximum number of frames to be generated per TSOv3 transaction */ 83 : : uint32_t tso_max_nb_outgoing_frames; 84 : : 85 : : /** NIC's DMA mapping information */ 86 : : const struct sfc_nic_dma_info *nic_dma_info; 87 : : 88 : : /** Maximum MAC PDU (frame size) */ 89 : : unsigned int max_pdu; 90 : : }; 91 : : 92 : : /** 93 : : * Get Tx datapath specific device info. 94 : : * 95 : : * @param dev_info Device info to be adjusted 96 : : */ 97 : : typedef void (sfc_dp_tx_get_dev_info_t)(struct rte_eth_dev_info *dev_info); 98 : : 99 : : /** 100 : : * Get size of transmit and event queue rings by the number of Tx 101 : : * descriptors. 102 : : * 103 : : * @param nb_tx_desc Number of Tx descriptors 104 : : * @param txq_entries Location for number of Tx ring entries 105 : : * @param evq_entries Location for number of event ring entries 106 : : * @param txq_max_fill_level Location for maximum Tx ring fill level 107 : : * 108 : : * @return 0 or positive errno. 109 : : */ 110 : : typedef int (sfc_dp_tx_qsize_up_rings_t)(uint16_t nb_tx_desc, 111 : : struct sfc_dp_tx_hw_limits *limits, 112 : : unsigned int *txq_entries, 113 : : unsigned int *evq_entries, 114 : : unsigned int *txq_max_fill_level); 115 : : 116 : : /** 117 : : * Allocate and initialize datapath transmit queue. 118 : : * 119 : : * @param port_id The port identifier 120 : : * @param queue_id The queue identifier 121 : : * @param pci_addr PCI function address 122 : : * @param socket_id Socket identifier to allocate memory 123 : : * @param info Tx queue details wrapped in structure 124 : : * @param dp_txqp Location for generic datapath transmit queue pointer 125 : : * 126 : : * @return 0 or positive errno. 127 : : */ 128 : : typedef int (sfc_dp_tx_qcreate_t)(uint16_t port_id, uint16_t queue_id, 129 : : const struct rte_pci_addr *pci_addr, 130 : : int socket_id, 131 : : const struct sfc_dp_tx_qcreate_info *info, 132 : : struct sfc_dp_txq **dp_txqp); 133 : : 134 : : /** 135 : : * Free resources allocated for datapath transmit queue. 136 : : */ 137 : : typedef void (sfc_dp_tx_qdestroy_t)(struct sfc_dp_txq *dp_txq); 138 : : 139 : : /** 140 : : * Transmit queue start callback. 141 : : * 142 : : * It handovers EvQ to the datapath. 143 : : */ 144 : : typedef int (sfc_dp_tx_qstart_t)(struct sfc_dp_txq *dp_txq, 145 : : unsigned int evq_read_ptr, 146 : : unsigned int txq_desc_index); 147 : : 148 : : /** 149 : : * Transmit queue stop function called before the queue flush. 150 : : * 151 : : * It returns EvQ to the control path. 152 : : */ 153 : : typedef void (sfc_dp_tx_qstop_t)(struct sfc_dp_txq *dp_txq, 154 : : unsigned int *evq_read_ptr); 155 : : 156 : : /** 157 : : * Transmit event handler used during queue flush only. 158 : : */ 159 : : typedef bool (sfc_dp_tx_qtx_ev_t)(struct sfc_dp_txq *dp_txq, unsigned int id); 160 : : 161 : : /** 162 : : * Transmit queue function called after the queue flush. 163 : : */ 164 : : typedef void (sfc_dp_tx_qreap_t)(struct sfc_dp_txq *dp_txq); 165 : : 166 : : /** 167 : : * Check Tx descriptor status 168 : : */ 169 : : typedef int (sfc_dp_tx_qdesc_status_t)(struct sfc_dp_txq *dp_txq, 170 : : uint16_t offset); 171 : : 172 : : /** Transmit datapath definition */ 173 : : struct sfc_dp_tx { 174 : : struct sfc_dp dp; 175 : : 176 : : unsigned int features; 177 : : #define SFC_DP_TX_FEAT_MULTI_PROCESS 0x1 178 : : #define SFC_DP_TX_FEAT_STATS 0x2 179 : : /** 180 : : * Tx offload capabilities supported by the datapath on device 181 : : * level only if HW/FW supports it. 182 : : */ 183 : : uint64_t dev_offload_capa; 184 : : /** 185 : : * Tx offload capabilities supported by the datapath per-queue 186 : : * if HW/FW supports it. 187 : : */ 188 : : uint64_t queue_offload_capa; 189 : : sfc_dp_tx_get_dev_info_t *get_dev_info; 190 : : sfc_dp_tx_qsize_up_rings_t *qsize_up_rings; 191 : : sfc_dp_tx_qcreate_t *qcreate; 192 : : sfc_dp_tx_qdestroy_t *qdestroy; 193 : : sfc_dp_tx_qstart_t *qstart; 194 : : sfc_dp_tx_qstop_t *qstop; 195 : : sfc_dp_tx_qtx_ev_t *qtx_ev; 196 : : sfc_dp_tx_qreap_t *qreap; 197 : : sfc_dp_tx_qdesc_status_t *qdesc_status; 198 : : eth_tx_prep_t pkt_prepare; 199 : : eth_tx_burst_t pkt_burst; 200 : : }; 201 : : 202 : : static inline struct sfc_dp_tx * 203 : : sfc_dp_find_tx_by_name(struct sfc_dp_list *head, const char *name) 204 : : { 205 : 0 : struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_TX, name); 206 : : 207 [ # # # # ]: 0 : return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp); 208 : : } 209 : : 210 : : static inline struct sfc_dp_tx * 211 : : sfc_dp_find_tx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps) 212 : : { 213 : 0 : struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_TX, avail_caps); 214 : : 215 [ # # ]: 0 : return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp); 216 : : } 217 : : 218 : : /** Get Tx datapath ops by the datapath TxQ handle */ 219 : : const struct sfc_dp_tx *sfc_dp_tx_by_dp_txq(const struct sfc_dp_txq *dp_txq); 220 : : 221 : : static inline uint64_t 222 : : sfc_dp_tx_offload_capa(const struct sfc_dp_tx *dp_tx) 223 : : { 224 [ # # # # ]: 0 : return dp_tx->dev_offload_capa | dp_tx->queue_offload_capa; 225 : : } 226 : : 227 : : static inline unsigned int 228 : : sfc_dp_tx_pkt_extra_hdr_segs(struct rte_mbuf **m_seg, 229 : : unsigned int *header_len_remaining) 230 : : { 231 : : unsigned int nb_extra_header_segs = 0; 232 : : 233 [ # # # # ]: 0 : while (rte_pktmbuf_data_len(*m_seg) < *header_len_remaining) { 234 : 0 : *header_len_remaining -= rte_pktmbuf_data_len(*m_seg); 235 : 0 : *m_seg = (*m_seg)->next; 236 : 0 : ++nb_extra_header_segs; 237 : : } 238 : : 239 : : return nb_extra_header_segs; 240 : : } 241 : : 242 : : static inline int 243 : 0 : sfc_dp_tx_prepare_pkt(struct rte_mbuf *m, 244 : : unsigned int max_nb_header_segs, 245 : : unsigned int tso_bounce_buffer_len, 246 : : uint32_t tso_tcp_header_offset_limit, 247 : : unsigned int max_fill_level, 248 : : unsigned int nb_tso_descs, 249 : : unsigned int nb_vlan_descs) 250 : : { 251 : 0 : unsigned int descs_required = m->nb_segs; 252 : 0 : unsigned int tcph_off = ((m->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ? 253 [ # # ]: 0 : m->outer_l2_len + m->outer_l3_len : 0) + 254 : 0 : m->l2_len + m->l3_len; 255 : 0 : unsigned int header_len = tcph_off + m->l4_len; 256 : : unsigned int header_len_remaining = header_len; 257 : : unsigned int nb_header_segs = 1; 258 : : struct rte_mbuf *m_seg = m; 259 : : 260 : : #ifdef RTE_LIBRTE_SFC_EFX_DEBUG 261 : : int ret; 262 : : 263 : : ret = rte_validate_tx_offload(m); 264 : : if (ret != 0) { 265 : : /* 266 : : * Negative error code is returned by rte_validate_tx_offload(), 267 : : * but positive are used inside net/sfc PMD. 268 : : */ 269 : : SFC_ASSERT(ret < 0); 270 : : return -ret; 271 : : } 272 : : #endif 273 : : 274 [ # # ]: 0 : if (max_nb_header_segs != 0) { 275 : : /* There is a limit on the number of header segments. */ 276 : : 277 : 0 : nb_header_segs += 278 : : sfc_dp_tx_pkt_extra_hdr_segs(&m_seg, 279 : : &header_len_remaining); 280 : : 281 [ # # ]: 0 : if (unlikely(nb_header_segs > max_nb_header_segs)) { 282 : : /* 283 : : * The number of header segments is too large. 284 : : * 285 : : * If TSO is requested and if the datapath supports 286 : : * linearisation of TSO headers, allow the packet 287 : : * to proceed with additional checks below. 288 : : * Otherwise, throw an error. 289 : : */ 290 [ # # # # ]: 0 : if ((m->ol_flags & RTE_MBUF_F_TX_TCP_SEG) == 0 || 291 : : tso_bounce_buffer_len == 0) 292 : : return EINVAL; 293 : : } 294 : : } 295 : : 296 [ # # ]: 0 : if (m->ol_flags & RTE_MBUF_F_TX_TCP_SEG) { 297 [ # # ]: 0 : switch (m->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) { 298 : : case 0: 299 : : break; 300 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN: 301 : : /* FALLTHROUGH */ 302 : : case RTE_MBUF_F_TX_TUNNEL_GENEVE: 303 [ # # ]: 0 : if (!(m->ol_flags & 304 : : (RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_OUTER_IPV6))) 305 : : return EINVAL; 306 : : } 307 : : 308 [ # # ]: 0 : if (unlikely(tcph_off > tso_tcp_header_offset_limit)) 309 : : return EINVAL; 310 : : 311 : 0 : descs_required += nb_tso_descs; 312 : : 313 : : /* 314 : : * If headers segments are already counted above, here 315 : : * nothing is done since remaining length is smaller 316 : : * then current segment size. 317 : : */ 318 : 0 : nb_header_segs += 319 : : sfc_dp_tx_pkt_extra_hdr_segs(&m_seg, 320 : : &header_len_remaining); 321 : : 322 : : /* 323 : : * Extra descriptor which is required when (a part of) payload 324 : : * shares the same segment with (a part of) the header. 325 : : */ 326 [ # # ]: 0 : if (rte_pktmbuf_data_len(m_seg) > header_len_remaining) 327 : 0 : descs_required++; 328 : : 329 [ # # ]: 0 : if (tso_bounce_buffer_len != 0) { 330 [ # # ]: 0 : if (nb_header_segs > 1 && 331 [ # # ]: 0 : unlikely(header_len > tso_bounce_buffer_len)) { 332 : : /* 333 : : * Header linearization is required and 334 : : * the header is too big to be linearized 335 : : */ 336 : : return EINVAL; 337 : : } 338 : : } 339 : : } 340 : : 341 : : /* 342 : : * The number of VLAN descriptors is added regardless of requested 343 : : * VLAN offload since VLAN is sticky and sending packet without VLAN 344 : : * insertion may require VLAN descriptor to reset the sticky to 0. 345 : : */ 346 : 0 : descs_required += nb_vlan_descs; 347 : : 348 : : /* 349 : : * Max fill level must be sufficient to hold all required descriptors 350 : : * to send the packet entirely. 351 : : */ 352 [ # # ]: 0 : if (descs_required > max_fill_level) 353 : 0 : return ENOBUFS; 354 : : 355 : : return 0; 356 : : } 357 : : 358 : : extern struct sfc_dp_tx sfc_efx_tx; 359 : : extern struct sfc_dp_tx sfc_ef10_tx; 360 : : extern struct sfc_dp_tx sfc_ef10_simple_tx; 361 : : extern struct sfc_dp_tx sfc_ef100_tx; 362 : : 363 : : #ifdef __cplusplus 364 : : } 365 : : #endif 366 : : #endif /* _SFC_DP_TX_H */