1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
13 #include <rte_ethdev_driver.h>
16 #include "sfc_debug.h"
24 * Generic transmit queue information used on data path.
25 * It must be kept as small as it is possible since it is built into
26 * the structure used on datapath.
29 struct sfc_dp_queue dpq;
32 /** Datapath transmit queue descriptor number limitations */
33 struct sfc_dp_tx_hw_limits {
34 unsigned int txq_max_entries;
35 unsigned int txq_min_entries;
39 * Datapath transmit queue creation information.
41 * The structure is used just to pass information from control path to
42 * datapath. It could be just function arguments, but it would be hardly
45 struct sfc_dp_tx_qcreate_info {
46 /** Maximum number of pushed Tx descriptors */
47 unsigned int max_fill_level;
48 /** Minimum number of unused Tx descriptors to do reap */
49 unsigned int free_thresh;
50 /** Offloads enabled on the transmit queue */
53 unsigned int txq_entries;
54 /** Maximum size of data in the DMA descriptor */
55 uint16_t dma_desc_size_max;
56 /** DMA-mapped Tx descriptors ring */
58 /** Associated event queue size */
59 unsigned int evq_entries;
60 /** Hardware event ring */
62 /** The queue index in hardware (required to push right doorbell) */
63 unsigned int hw_index;
64 /** Virtual address of the memory-mapped BAR to push Tx doorbell */
65 volatile void *mem_bar;
66 /** VI window size shift */
67 unsigned int vi_window_shift;
69 * Maximum number of bytes into the packet the TCP header can start for
70 * the hardware to apply TSO packet edits.
72 uint16_t tso_tcp_header_offset_limit;
76 * Get Tx datapath specific device info.
78 * @param dev_info Device info to be adjusted
80 typedef void (sfc_dp_tx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
83 * Get size of transmit and event queue rings by the number of Tx
86 * @param nb_tx_desc Number of Tx descriptors
87 * @param txq_entries Location for number of Tx ring entries
88 * @param evq_entries Location for number of event ring entries
89 * @param txq_max_fill_level Location for maximum Tx ring fill level
91 * @return 0 or positive errno.
93 typedef int (sfc_dp_tx_qsize_up_rings_t)(uint16_t nb_tx_desc,
94 struct sfc_dp_tx_hw_limits *limits,
95 unsigned int *txq_entries,
96 unsigned int *evq_entries,
97 unsigned int *txq_max_fill_level);
100 * Allocate and initialize datapath transmit queue.
102 * @param port_id The port identifier
103 * @param queue_id The queue identifier
104 * @param pci_addr PCI function address
105 * @param socket_id Socket identifier to allocate memory
106 * @param info Tx queue details wrapped in structure
107 * @param dp_txqp Location for generic datapath transmit queue pointer
109 * @return 0 or positive errno.
111 typedef int (sfc_dp_tx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
112 const struct rte_pci_addr *pci_addr,
114 const struct sfc_dp_tx_qcreate_info *info,
115 struct sfc_dp_txq **dp_txqp);
118 * Free resources allocated for datapath transmit queue.
120 typedef void (sfc_dp_tx_qdestroy_t)(struct sfc_dp_txq *dp_txq);
123 * Transmit queue start callback.
125 * It handovers EvQ to the datapath.
127 typedef int (sfc_dp_tx_qstart_t)(struct sfc_dp_txq *dp_txq,
128 unsigned int evq_read_ptr,
129 unsigned int txq_desc_index);
132 * Transmit queue stop function called before the queue flush.
134 * It returns EvQ to the control path.
136 typedef void (sfc_dp_tx_qstop_t)(struct sfc_dp_txq *dp_txq,
137 unsigned int *evq_read_ptr);
140 * Transmit event handler used during queue flush only.
142 typedef bool (sfc_dp_tx_qtx_ev_t)(struct sfc_dp_txq *dp_txq, unsigned int id);
145 * Transmit queue function called after the queue flush.
147 typedef void (sfc_dp_tx_qreap_t)(struct sfc_dp_txq *dp_txq);
150 * Check Tx descriptor status
152 typedef int (sfc_dp_tx_qdesc_status_t)(struct sfc_dp_txq *dp_txq,
155 /** Transmit datapath definition */
159 unsigned int features;
160 #define SFC_DP_TX_FEAT_VLAN_INSERT 0x1
161 #define SFC_DP_TX_FEAT_TSO 0x2
162 #define SFC_DP_TX_FEAT_MULTI_SEG 0x4
163 #define SFC_DP_TX_FEAT_MULTI_PROCESS 0x8
164 #define SFC_DP_TX_FEAT_MULTI_POOL 0x10
165 #define SFC_DP_TX_FEAT_REFCNT 0x20
166 sfc_dp_tx_get_dev_info_t *get_dev_info;
167 sfc_dp_tx_qsize_up_rings_t *qsize_up_rings;
168 sfc_dp_tx_qcreate_t *qcreate;
169 sfc_dp_tx_qdestroy_t *qdestroy;
170 sfc_dp_tx_qstart_t *qstart;
171 sfc_dp_tx_qstop_t *qstop;
172 sfc_dp_tx_qtx_ev_t *qtx_ev;
173 sfc_dp_tx_qreap_t *qreap;
174 sfc_dp_tx_qdesc_status_t *qdesc_status;
175 eth_tx_prep_t pkt_prepare;
176 eth_tx_burst_t pkt_burst;
179 static inline struct sfc_dp_tx *
180 sfc_dp_find_tx_by_name(struct sfc_dp_list *head, const char *name)
182 struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_TX, name);
184 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp);
187 static inline struct sfc_dp_tx *
188 sfc_dp_find_tx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
190 struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_TX, avail_caps);
192 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp);
195 /** Get Tx datapath ops by the datapath TxQ handle */
196 const struct sfc_dp_tx *sfc_dp_tx_by_dp_txq(const struct sfc_dp_txq *dp_txq);
199 sfc_dp_tx_prepare_pkt(struct rte_mbuf *m,
200 uint32_t tso_tcp_header_offset_limit,
201 unsigned int max_fill_level,
202 unsigned int nb_tso_descs,
203 unsigned int nb_vlan_descs)
205 unsigned int descs_required = m->nb_segs;
207 #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
210 ret = rte_validate_tx_offload(m);
213 * Negative error code is returned by rte_validate_tx_offload(),
214 * but positive are used inside net/sfc PMD.
221 if (m->ol_flags & PKT_TX_TCP_SEG) {
222 unsigned int tcph_off = m->l2_len + m->l3_len;
223 unsigned int header_len = tcph_off + m->l4_len;
225 if (unlikely(tcph_off > tso_tcp_header_offset_limit))
228 descs_required += nb_tso_descs;
231 * Extra descriptor that is required when a packet header
232 * is separated from remaining content of the first segment.
234 if (rte_pktmbuf_data_len(m) > header_len) {
236 } else if (rte_pktmbuf_data_len(m) < header_len &&
237 unlikely(header_len > SFC_TSOH_STD_LEN)) {
239 * Header linearization is required and
240 * the header is too big to be linearized
247 * The number of VLAN descriptors is added regardless of requested
248 * VLAN offload since VLAN is sticky and sending packet without VLAN
249 * insertion may require VLAN descriptor to reset the sticky to 0.
251 descs_required += nb_vlan_descs;
254 * Max fill level must be sufficient to hold all required descriptors
255 * to send the packet entirely.
257 if (descs_required > max_fill_level)
263 extern struct sfc_dp_tx sfc_efx_tx;
264 extern struct sfc_dp_tx sfc_ef10_tx;
265 extern struct sfc_dp_tx sfc_ef10_simple_tx;
270 #endif /* _SFC_DP_TX_H */