net/sfc: support Tx preparation in EFX datapath
[dpdk.git] / drivers / net / sfc / sfc_dp_tx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2016-2018 Solarflare Communications Inc.
4  * All rights reserved.
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 <rte_ethdev_driver.h>
14
15 #include "sfc_dp.h"
16 #include "sfc_debug.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /**
23  * Generic transmit queue information used on data path.
24  * It must be kept as small as it is possible since it is built into
25  * the structure used on datapath.
26  */
27 struct sfc_dp_txq {
28         struct sfc_dp_queue     dpq;
29 };
30
31 /** Datapath transmit queue descriptor number limitations */
32 struct sfc_dp_tx_hw_limits {
33         unsigned int txq_max_entries;
34         unsigned int txq_min_entries;
35 };
36
37 /**
38  * Datapath transmit queue creation information.
39  *
40  * The structure is used just to pass information from control path to
41  * datapath. It could be just function arguments, but it would be hardly
42  * readable.
43  */
44 struct sfc_dp_tx_qcreate_info {
45         /** Maximum number of pushed Tx descriptors */
46         unsigned int            max_fill_level;
47         /** Minimum number of unused Tx descriptors to do reap */
48         unsigned int            free_thresh;
49         /** Offloads enabled on the transmit queue */
50         uint64_t                offloads;
51         /** Tx queue size */
52         unsigned int            txq_entries;
53         /** Maximum size of data in the DMA descriptor */
54         uint16_t                dma_desc_size_max;
55         /** DMA-mapped Tx descriptors ring */
56         void                    *txq_hw_ring;
57         /** Associated event queue size */
58         unsigned int            evq_entries;
59         /** Hardware event ring */
60         void                    *evq_hw_ring;
61         /** The queue index in hardware (required to push right doorbell) */
62         unsigned int            hw_index;
63         /** Virtual address of the memory-mapped BAR to push Tx doorbell */
64         volatile void           *mem_bar;
65         /** VI window size shift */
66         unsigned int            vi_window_shift;
67         /**
68          * Maximum number of bytes into the packet the TCP header can start for
69          * the hardware to apply TSO packet edits.
70          */
71         uint16_t                tso_tcp_header_offset_limit;
72 };
73
74 /**
75  * Get Tx datapath specific device info.
76  *
77  * @param dev_info              Device info to be adjusted
78  */
79 typedef void (sfc_dp_tx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
80
81 /**
82  * Get size of transmit and event queue rings by the number of Tx
83  * descriptors.
84  *
85  * @param nb_tx_desc            Number of Tx descriptors
86  * @param txq_entries           Location for number of Tx ring entries
87  * @param evq_entries           Location for number of event ring entries
88  * @param txq_max_fill_level    Location for maximum Tx ring fill level
89  *
90  * @return 0 or positive errno.
91  */
92 typedef int (sfc_dp_tx_qsize_up_rings_t)(uint16_t nb_tx_desc,
93                                          struct sfc_dp_tx_hw_limits *limits,
94                                          unsigned int *txq_entries,
95                                          unsigned int *evq_entries,
96                                          unsigned int *txq_max_fill_level);
97
98 /**
99  * Allocate and initialize datapath transmit queue.
100  *
101  * @param port_id       The port identifier
102  * @param queue_id      The queue identifier
103  * @param pci_addr      PCI function address
104  * @param socket_id     Socket identifier to allocate memory
105  * @param info          Tx queue details wrapped in structure
106  * @param dp_txqp       Location for generic datapath transmit queue pointer
107  *
108  * @return 0 or positive errno.
109  */
110 typedef int (sfc_dp_tx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
111                                   const struct rte_pci_addr *pci_addr,
112                                   int socket_id,
113                                   const struct sfc_dp_tx_qcreate_info *info,
114                                   struct sfc_dp_txq **dp_txqp);
115
116 /**
117  * Free resources allocated for datapath transmit queue.
118  */
119 typedef void (sfc_dp_tx_qdestroy_t)(struct sfc_dp_txq *dp_txq);
120
121 /**
122  * Transmit queue start callback.
123  *
124  * It handovers EvQ to the datapath.
125  */
126 typedef int (sfc_dp_tx_qstart_t)(struct sfc_dp_txq *dp_txq,
127                                  unsigned int evq_read_ptr,
128                                  unsigned int txq_desc_index);
129
130 /**
131  * Transmit queue stop function called before the queue flush.
132  *
133  * It returns EvQ to the control path.
134  */
135 typedef void (sfc_dp_tx_qstop_t)(struct sfc_dp_txq *dp_txq,
136                                  unsigned int *evq_read_ptr);
137
138 /**
139  * Transmit event handler used during queue flush only.
140  */
141 typedef bool (sfc_dp_tx_qtx_ev_t)(struct sfc_dp_txq *dp_txq, unsigned int id);
142
143 /**
144  * Transmit queue function called after the queue flush.
145  */
146 typedef void (sfc_dp_tx_qreap_t)(struct sfc_dp_txq *dp_txq);
147
148 /**
149  * Check Tx descriptor status
150  */
151 typedef int (sfc_dp_tx_qdesc_status_t)(struct sfc_dp_txq *dp_txq,
152                                        uint16_t offset);
153
154 /** Transmit datapath definition */
155 struct sfc_dp_tx {
156         struct sfc_dp                   dp;
157
158         unsigned int                    features;
159 #define SFC_DP_TX_FEAT_VLAN_INSERT      0x1
160 #define SFC_DP_TX_FEAT_TSO              0x2
161 #define SFC_DP_TX_FEAT_MULTI_SEG        0x4
162 #define SFC_DP_TX_FEAT_MULTI_PROCESS    0x8
163 #define SFC_DP_TX_FEAT_MULTI_POOL       0x10
164 #define SFC_DP_TX_FEAT_REFCNT           0x20
165         sfc_dp_tx_get_dev_info_t        *get_dev_info;
166         sfc_dp_tx_qsize_up_rings_t      *qsize_up_rings;
167         sfc_dp_tx_qcreate_t             *qcreate;
168         sfc_dp_tx_qdestroy_t            *qdestroy;
169         sfc_dp_tx_qstart_t              *qstart;
170         sfc_dp_tx_qstop_t               *qstop;
171         sfc_dp_tx_qtx_ev_t              *qtx_ev;
172         sfc_dp_tx_qreap_t               *qreap;
173         sfc_dp_tx_qdesc_status_t        *qdesc_status;
174         eth_tx_prep_t                   pkt_prepare;
175         eth_tx_burst_t                  pkt_burst;
176 };
177
178 static inline struct sfc_dp_tx *
179 sfc_dp_find_tx_by_name(struct sfc_dp_list *head, const char *name)
180 {
181         struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_TX, name);
182
183         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp);
184 }
185
186 static inline struct sfc_dp_tx *
187 sfc_dp_find_tx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
188 {
189         struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_TX, avail_caps);
190
191         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp);
192 }
193
194 /** Get Tx datapath ops by the datapath TxQ handle */
195 const struct sfc_dp_tx *sfc_dp_tx_by_dp_txq(const struct sfc_dp_txq *dp_txq);
196
197 static inline int
198 sfc_dp_tx_prepare_pkt(struct rte_mbuf *m)
199 {
200 #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
201         int ret;
202
203         ret = rte_validate_tx_offload(m);
204         if (ret != 0) {
205                 /*
206                  * Negative error code is returned by rte_validate_tx_offload(),
207                  * but positive are used inside net/sfc PMD.
208                  */
209                 SFC_ASSERT(ret < 0);
210                 return -ret;
211         }
212 #else
213         RTE_SET_USED(m);
214 #endif
215
216         return 0;
217 }
218
219 extern struct sfc_dp_tx sfc_efx_tx;
220 extern struct sfc_dp_tx sfc_ef10_tx;
221 extern struct sfc_dp_tx sfc_ef10_simple_tx;
222
223 #ifdef __cplusplus
224 }
225 #endif
226 #endif /* _SFC_DP_TX_H */