net/sfc: make TSO a datapath-dependent feature
[dpdk.git] / drivers / net / sfc / sfc_dp_tx.h
1 /*-
2  *   BSD LICENSE
3  *
4  * Copyright (c) 2016 Solarflare Communications Inc.
5  * All rights reserved.
6  *
7  * This software was jointly developed between OKTET Labs (under contract
8  * for Solarflare) and Solarflare Communications, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  *    this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  *    this list of conditions and the following disclaimer in the documentation
17  *    and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef _SFC_DP_TX_H
33 #define _SFC_DP_TX_H
34
35 #include <rte_ethdev.h>
36
37 #include "sfc_dp.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**
44  * Generic transmit queue information used on data path.
45  * It must be kept as small as it is possible since it is built into
46  * the structure used on datapath.
47  */
48 struct sfc_dp_txq {
49         struct sfc_dp_queue     dpq;
50 };
51
52 /**
53  * Datapath transmit queue creation information.
54  *
55  * The structure is used just to pass information from control path to
56  * datapath. It could be just function arguments, but it would be hardly
57  * readable.
58  */
59 struct sfc_dp_tx_qcreate_info {
60         /** Minimum number of unused Tx descriptors to do reap */
61         unsigned int            free_thresh;
62         /** Transmit queue configuration flags */
63         unsigned int            flags;
64         /** Tx queue size */
65         unsigned int            txq_entries;
66         /** Maximum size of data in the DMA descriptor */
67         uint16_t                dma_desc_size_max;
68 };
69
70 /**
71  * Allocate and initialize datapath transmit queue.
72  *
73  * @param port_id       The port identifier
74  * @param queue_id      The queue identifier
75  * @param pci_addr      PCI function address
76  * @param socket_id     Socket identifier to allocate memory
77  * @param info          Tx queue details wrapped in structure
78  * @param dp_txqp       Location for generic datapath transmit queue pointer
79  *
80  * @return 0 or positive errno.
81  */
82 typedef int (sfc_dp_tx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
83                                   const struct rte_pci_addr *pci_addr,
84                                   int socket_id,
85                                   const struct sfc_dp_tx_qcreate_info *info,
86                                   struct sfc_dp_txq **dp_txqp);
87
88 /**
89  * Free resources allocated for datapath transmit queue.
90  */
91 typedef void (sfc_dp_tx_qdestroy_t)(struct sfc_dp_txq *dp_txq);
92
93 /**
94  * Transmit queue start callback.
95  *
96  * It handovers EvQ to the datapath.
97  */
98 typedef int (sfc_dp_tx_qstart_t)(struct sfc_dp_txq *dp_txq,
99                                  unsigned int evq_read_ptr,
100                                  unsigned int txq_desc_index);
101
102 /**
103  * Transmit queue stop function called before the queue flush.
104  *
105  * It returns EvQ to the control path.
106  */
107 typedef void (sfc_dp_tx_qstop_t)(struct sfc_dp_txq *dp_txq,
108                                  unsigned int *evq_read_ptr);
109
110 /**
111  * Transmit queue function called after the queue flush.
112  */
113 typedef void (sfc_dp_tx_qreap_t)(struct sfc_dp_txq *dp_txq);
114
115 /** Transmit datapath definition */
116 struct sfc_dp_tx {
117         struct sfc_dp                   dp;
118
119         unsigned int                    features;
120 #define SFC_DP_TX_FEAT_VLAN_INSERT      0x1
121 #define SFC_DP_TX_FEAT_TSO              0x2
122         sfc_dp_tx_qcreate_t             *qcreate;
123         sfc_dp_tx_qdestroy_t            *qdestroy;
124         sfc_dp_tx_qstart_t              *qstart;
125         sfc_dp_tx_qstop_t               *qstop;
126         sfc_dp_tx_qreap_t               *qreap;
127         eth_tx_burst_t                  pkt_burst;
128 };
129
130 static inline struct sfc_dp_tx *
131 sfc_dp_find_tx_by_name(struct sfc_dp_list *head, const char *name)
132 {
133         struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_TX, name);
134
135         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp);
136 }
137
138 static inline struct sfc_dp_tx *
139 sfc_dp_find_tx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
140 {
141         struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_TX, avail_caps);
142
143         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_tx, dp);
144 }
145
146 extern struct sfc_dp_tx sfc_efx_tx;
147
148 #ifdef __cplusplus
149 }
150 #endif
151 #endif /* _SFC_DP_TX_H */