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