efb486d323c01bca29f500e1a09ade94437c7722
[dpdk.git] / drivers / net / sfc / sfc_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_TX_H
11 #define _SFC_TX_H
12
13 #include <rte_mbuf.h>
14 #include <rte_ethdev_driver.h>
15
16 #include "efx.h"
17
18 #include "sfc_dp_tx.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 struct sfc_adapter;
25 struct sfc_evq;
26
27 /**
28  * Software Tx descriptor information associated with hardware Tx
29  * descriptor.
30  */
31 struct sfc_efx_tx_sw_desc {
32         struct rte_mbuf         *mbuf;
33         uint8_t                 *tsoh;  /* Buffer to store TSO header */
34 };
35
36 enum sfc_txq_state_bit {
37         SFC_TXQ_INITIALIZED_BIT = 0,
38 #define SFC_TXQ_INITIALIZED     (1 << SFC_TXQ_INITIALIZED_BIT)
39         SFC_TXQ_STARTED_BIT,
40 #define SFC_TXQ_STARTED         (1 << SFC_TXQ_STARTED_BIT)
41         SFC_TXQ_FLUSHING_BIT,
42 #define SFC_TXQ_FLUSHING        (1 << SFC_TXQ_FLUSHING_BIT)
43         SFC_TXQ_FLUSHED_BIT,
44 #define SFC_TXQ_FLUSHED         (1 << SFC_TXQ_FLUSHED_BIT)
45         SFC_TXQ_FLUSH_FAILED_BIT,
46 #define SFC_TXQ_FLUSH_FAILED    (1 << SFC_TXQ_FLUSH_FAILED_BIT)
47 };
48
49 /**
50  * Transmit queue control information. Not used on datapath.
51  * Allocated on the socket specified on the queue setup.
52  */
53 struct sfc_txq {
54         unsigned int                    state;
55         unsigned int                    hw_index;
56         struct sfc_evq                  *evq;
57         efsys_mem_t                     mem;
58         struct sfc_dp_txq               *dp;
59         efx_txq_t                       *common;
60 };
61
62 static inline unsigned int
63 sfc_txq_sw_index_by_hw_index(unsigned int hw_index)
64 {
65         return hw_index;
66 }
67
68 static inline unsigned int
69 sfc_txq_sw_index(const struct sfc_txq *txq)
70 {
71         return sfc_txq_sw_index_by_hw_index(txq->hw_index);
72 }
73
74 struct sfc_txq *sfc_txq_by_dp_txq(const struct sfc_dp_txq *dp_txq);
75
76 /**
77  * Transmit queue information used on libefx-based data path.
78  * Allocated on the socket specified on the queue setup.
79  */
80 struct sfc_efx_txq {
81         struct sfc_evq                  *evq;
82         struct sfc_efx_tx_sw_desc       *sw_ring;
83         unsigned int                    ptr_mask;
84         efx_desc_t                      *pend_desc;
85         efx_txq_t                       *common;
86         unsigned int                    added;
87         unsigned int                    pending;
88         unsigned int                    completed;
89         unsigned int                    max_fill_level;
90         unsigned int                    free_thresh;
91         uint16_t                        hw_vlan_tci;
92         uint16_t                        dma_desc_size_max;
93
94         unsigned int                    hw_index;
95         unsigned int                    flags;
96 #define SFC_EFX_TXQ_FLAG_STARTED        0x1
97 #define SFC_EFX_TXQ_FLAG_RUNNING        0x2
98
99         /* Datapath transmit queue anchor */
100         struct sfc_dp_txq               dp;
101 };
102
103 static inline struct sfc_efx_txq *
104 sfc_efx_txq_by_dp_txq(struct sfc_dp_txq *dp_txq)
105 {
106         return container_of(dp_txq, struct sfc_efx_txq, dp);
107 }
108
109 struct sfc_txq_info {
110         unsigned int            entries;
111         struct sfc_txq          *txq;
112         boolean_t               deferred_start;
113         boolean_t               deferred_started;
114         unsigned int            free_thresh;
115         uint64_t                offloads;
116 };
117
118 int sfc_tx_configure(struct sfc_adapter *sa);
119 void sfc_tx_close(struct sfc_adapter *sa);
120
121 int sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
122                  uint16_t nb_tx_desc, unsigned int socket_id,
123                  const struct rte_eth_txconf *tx_conf);
124 void sfc_tx_qfini(struct sfc_adapter *sa, unsigned int sw_index);
125
126 void sfc_tx_qflush_done(struct sfc_txq *txq);
127 int sfc_tx_qstart(struct sfc_adapter *sa, unsigned int sw_index);
128 void sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index);
129 int sfc_tx_start(struct sfc_adapter *sa);
130 void sfc_tx_stop(struct sfc_adapter *sa);
131
132 uint64_t sfc_tx_get_dev_offload_caps(struct sfc_adapter *sa);
133 uint64_t sfc_tx_get_queue_offload_caps(struct sfc_adapter *sa);
134
135 /* From 'sfc_tso.c' */
136 int sfc_efx_tso_alloc_tsoh_objs(struct sfc_efx_tx_sw_desc *sw_ring,
137                                 unsigned int txq_entries,
138                                 unsigned int socket_id);
139 void sfc_efx_tso_free_tsoh_objs(struct sfc_efx_tx_sw_desc *sw_ring,
140                                 unsigned int txq_entries);
141 int sfc_efx_tso_do(struct sfc_efx_txq *txq, unsigned int idx,
142                    struct rte_mbuf **in_seg, size_t *in_off, efx_desc_t **pend,
143                    unsigned int *pkt_descs, size_t *pkt_len);
144
145 #ifdef __cplusplus
146 }
147 #endif
148 #endif  /* _SFC_TX_H */