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