2 * Copyright (c) 2016 Solarflare Communications Inc.
5 * This software was jointly developed between OKTET Labs (under contract
6 * for Solarflare) and Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 sfc_tx_qcheck_conf(struct sfc_adapter *sa,
37 const struct rte_eth_txconf *tx_conf)
39 unsigned int flags = tx_conf->txq_flags;
42 if (tx_conf->tx_rs_thresh != 0) {
43 sfc_err(sa, "RS bit in transmit descriptor is not supported");
47 if (tx_conf->tx_free_thresh != 0) {
49 "setting explicit TX free threshold is not supported");
53 if (tx_conf->tx_deferred_start != 0) {
54 sfc_err(sa, "TX queue deferred start is not supported (yet)");
58 if (tx_conf->tx_thresh.pthresh != 0 ||
59 tx_conf->tx_thresh.hthresh != 0 ||
60 tx_conf->tx_thresh.wthresh != 0) {
62 "prefetch/host/writeback thresholds are not supported");
66 if ((flags & ETH_TXQ_FLAGS_NOVLANOFFL) == 0) {
67 sfc_err(sa, "VLAN offload is not supported");
71 if ((flags & ETH_TXQ_FLAGS_NOXSUMSCTP) == 0) {
72 sfc_err(sa, "SCTP offload is not supported");
76 /* We either perform both TCP and UDP offload, or no offload at all */
77 if (((flags & ETH_TXQ_FLAGS_NOXSUMTCP) == 0) !=
78 ((flags & ETH_TXQ_FLAGS_NOXSUMUDP) == 0)) {
79 sfc_err(sa, "TCP and UDP offloads can't be set independently");
87 sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
88 uint16_t nb_tx_desc, unsigned int socket_id,
89 const struct rte_eth_txconf *tx_conf)
91 struct sfc_txq_info *txq_info;
94 unsigned int evq_index = sfc_evq_index_by_txq_sw_index(sa, sw_index);
97 sfc_log_init(sa, "TxQ = %u", sw_index);
99 rc = sfc_tx_qcheck_conf(sa, tx_conf);
103 SFC_ASSERT(sw_index < sa->txq_count);
104 txq_info = &sa->txq_info[sw_index];
106 SFC_ASSERT(nb_tx_desc <= sa->txq_max_entries);
107 txq_info->entries = nb_tx_desc;
109 rc = sfc_ev_qinit(sa, evq_index, txq_info->entries, socket_id);
113 evq = sa->evq_info[evq_index].evq;
116 txq = rte_zmalloc_socket("sfc-txq", sizeof(*txq), 0, socket_id);
120 rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_TXQ_SIZE(txq_info->entries),
121 socket_id, &txq->mem);
126 txq->pend_desc = rte_calloc_socket("sfc-txq-pend-desc",
127 EFX_TXQ_LIMIT(txq_info->entries),
128 sizeof(efx_desc_t), 0, socket_id);
129 if (txq->pend_desc == NULL)
130 goto fail_pend_desc_alloc;
133 txq->sw_ring = rte_calloc_socket("sfc-txq-desc", txq_info->entries,
134 sizeof(*txq->sw_ring), 0, socket_id);
135 if (txq->sw_ring == NULL)
136 goto fail_desc_alloc;
138 txq->state = SFC_TXQ_INITIALIZED;
139 txq->ptr_mask = txq_info->entries - 1;
140 txq->hw_index = sw_index;
141 txq->flags = tx_conf->txq_flags;
151 rte_free(txq->pend_desc);
153 fail_pend_desc_alloc:
154 sfc_dma_free(sa, &txq->mem);
160 sfc_ev_qfini(sa, evq_index);
163 txq_info->entries = 0;
166 sfc_log_init(sa, "failed (TxQ = %u, rc = %d)", sw_index, rc);
171 sfc_tx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
173 struct sfc_txq_info *txq_info;
176 sfc_log_init(sa, "TxQ = %u", sw_index);
178 SFC_ASSERT(sw_index < sa->txq_count);
179 txq_info = &sa->txq_info[sw_index];
182 SFC_ASSERT(txq != NULL);
183 SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
185 txq_info->txq = NULL;
186 txq_info->entries = 0;
188 rte_free(txq->sw_ring);
189 rte_free(txq->pend_desc);
190 sfc_dma_free(sa, &txq->mem);
195 sfc_tx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
197 sfc_log_init(sa, "TxQ = %u", sw_index);
203 sfc_tx_check_mode(struct sfc_adapter *sa, const struct rte_eth_txmode *txmode)
207 switch (txmode->mq_mode) {
211 sfc_err(sa, "Tx multi-queue mode %u not supported",
217 * These features are claimed to be i40e-specific,
218 * but it does make sense to double-check their absence
220 if (txmode->hw_vlan_reject_tagged) {
221 sfc_err(sa, "Rejecting tagged packets not supported");
225 if (txmode->hw_vlan_reject_untagged) {
226 sfc_err(sa, "Rejecting untagged packets not supported");
230 if (txmode->hw_vlan_insert_pvid) {
231 sfc_err(sa, "Port-based VLAN insertion not supported");
239 sfc_tx_init(struct sfc_adapter *sa)
241 const struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
242 unsigned int sw_index;
245 rc = sfc_tx_check_mode(sa, &dev_conf->txmode);
247 goto fail_check_mode;
249 sa->txq_count = sa->eth_dev->data->nb_tx_queues;
251 sa->txq_info = rte_calloc_socket("sfc-txqs", sa->txq_count,
252 sizeof(sa->txq_info[0]), 0,
254 if (sa->txq_info == NULL)
255 goto fail_txqs_alloc;
257 for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
258 rc = sfc_tx_qinit_info(sa, sw_index);
260 goto fail_tx_qinit_info;
266 rte_free(sa->txq_info);
273 sfc_log_init(sa, "failed (rc = %d)", rc);
278 sfc_tx_fini(struct sfc_adapter *sa)
282 sw_index = sa->txq_count;
283 while (--sw_index >= 0) {
284 if (sa->txq_info[sw_index].txq != NULL)
285 sfc_tx_qfini(sa, sw_index);
288 rte_free(sa->txq_info);