2 * Copyright (c) 2007-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
34 #define EFX_TX_QSTAT_INCR(_etp, _stat)
37 __checkReturn efx_rc_t
41 const efx_tx_ops_t *etxop;
44 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
45 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
47 if (!(enp->en_mod_flags & EFX_MOD_EV)) {
52 if (enp->en_mod_flags & EFX_MOD_TX) {
57 switch (enp->en_family) {
65 EFSYS_ASSERT3U(enp->en_tx_qcount, ==, 0);
67 if ((rc = etxop->etxo_init(enp)) != 0)
70 enp->en_etxop = etxop;
71 enp->en_mod_flags |= EFX_MOD_TX;
81 EFSYS_PROBE1(fail1, efx_rc_t, rc);
84 enp->en_mod_flags &= ~EFX_MOD_TX;
92 const efx_tx_ops_t *etxop = enp->en_etxop;
94 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
95 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
96 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_TX);
97 EFSYS_ASSERT3U(enp->en_tx_qcount, ==, 0);
99 etxop->etxo_fini(enp);
101 enp->en_etxop = NULL;
102 enp->en_mod_flags &= ~EFX_MOD_TX;
105 __checkReturn efx_rc_t
108 __in unsigned int index,
109 __in unsigned int label,
110 __in efsys_mem_t *esmp,
115 __deref_out efx_txq_t **etpp,
116 __out unsigned int *addedp)
118 const efx_tx_ops_t *etxop = enp->en_etxop;
119 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
123 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
124 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_TX);
126 EFSYS_ASSERT3U(enp->en_tx_qcount + 1, <, encp->enc_txq_limit);
128 /* Allocate an TXQ object */
129 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_txq_t), etp);
136 etp->et_magic = EFX_TXQ_MAGIC;
138 etp->et_index = index;
139 etp->et_mask = n - 1;
142 /* Initial descriptor index may be modified by etxo_qcreate */
145 if ((rc = etxop->etxo_qcreate(enp, index, label, esmp,
146 n, id, flags, eep, etp, addedp)) != 0)
156 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_txq_t), etp);
158 EFSYS_PROBE1(fail1, efx_rc_t, rc);
166 efx_nic_t *enp = etp->et_enp;
167 const efx_tx_ops_t *etxop = enp->en_etxop;
169 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
171 EFSYS_ASSERT(enp->en_tx_qcount != 0);
174 etxop->etxo_qdestroy(etp);
176 /* Free the TXQ object */
177 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_txq_t), etp);
180 __checkReturn efx_rc_t
183 __in_ecount(n) efx_buffer_t *eb,
185 __in unsigned int completed,
186 __inout unsigned int *addedp)
188 efx_nic_t *enp = etp->et_enp;
189 const efx_tx_ops_t *etxop = enp->en_etxop;
192 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
194 if ((rc = etxop->etxo_qpost(etp, eb,
195 n, completed, addedp)) != 0)
201 EFSYS_PROBE1(fail1, efx_rc_t, rc);
208 __in unsigned int added,
209 __in unsigned int pushed)
211 efx_nic_t *enp = etp->et_enp;
212 const efx_tx_ops_t *etxop = enp->en_etxop;
214 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
216 etxop->etxo_qpush(etp, added, pushed);
219 __checkReturn efx_rc_t
222 __in unsigned int ns)
224 efx_nic_t *enp = etp->et_enp;
225 const efx_tx_ops_t *etxop = enp->en_etxop;
228 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
230 if ((rc = etxop->etxo_qpace(etp, ns)) != 0)
236 EFSYS_PROBE1(fail1, efx_rc_t, rc);
240 __checkReturn efx_rc_t
244 efx_nic_t *enp = etp->et_enp;
245 const efx_tx_ops_t *etxop = enp->en_etxop;
248 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
250 if ((rc = etxop->etxo_qflush(etp)) != 0)
256 EFSYS_PROBE1(fail1, efx_rc_t, rc);
264 efx_nic_t *enp = etp->et_enp;
265 const efx_tx_ops_t *etxop = enp->en_etxop;
267 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
269 etxop->etxo_qenable(etp);
272 __checkReturn efx_rc_t
276 efx_nic_t *enp = etp->et_enp;
277 const efx_tx_ops_t *etxop = enp->en_etxop;
280 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
282 if (~enp->en_features & EFX_FEATURE_PIO_BUFFERS) {
286 if (etxop->etxo_qpio_enable == NULL) {
290 if ((rc = etxop->etxo_qpio_enable(etp)) != 0)
300 EFSYS_PROBE1(fail1, efx_rc_t, rc);
308 efx_nic_t *enp = etp->et_enp;
309 const efx_tx_ops_t *etxop = enp->en_etxop;
311 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
313 if (etxop->etxo_qpio_disable != NULL)
314 etxop->etxo_qpio_disable(etp);
317 __checkReturn efx_rc_t
320 __in_ecount(buf_length) uint8_t *buffer,
321 __in size_t buf_length,
322 __in size_t pio_buf_offset)
324 efx_nic_t *enp = etp->et_enp;
325 const efx_tx_ops_t *etxop = enp->en_etxop;
328 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
330 if (etxop->etxo_qpio_write != NULL) {
331 if ((rc = etxop->etxo_qpio_write(etp, buffer, buf_length,
332 pio_buf_offset)) != 0)
340 EFSYS_PROBE1(fail1, efx_rc_t, rc);
344 __checkReturn efx_rc_t
347 __in size_t pkt_length,
348 __in unsigned int completed,
349 __inout unsigned int *addedp)
351 efx_nic_t *enp = etp->et_enp;
352 const efx_tx_ops_t *etxop = enp->en_etxop;
355 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
357 if (etxop->etxo_qpio_post != NULL) {
358 if ((rc = etxop->etxo_qpio_post(etp, pkt_length, completed,
367 EFSYS_PROBE1(fail1, efx_rc_t, rc);
371 __checkReturn efx_rc_t
374 __in_ecount(n) efx_desc_t *ed,
376 __in unsigned int completed,
377 __inout unsigned int *addedp)
379 efx_nic_t *enp = etp->et_enp;
380 const efx_tx_ops_t *etxop = enp->en_etxop;
383 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
385 if ((rc = etxop->etxo_qdesc_post(etp, ed,
386 n, completed, addedp)) != 0)
392 EFSYS_PROBE1(fail1, efx_rc_t, rc);
397 efx_tx_qdesc_dma_create(
399 __in efsys_dma_addr_t addr,
402 __out efx_desc_t *edp)
404 efx_nic_t *enp = etp->et_enp;
405 const efx_tx_ops_t *etxop = enp->en_etxop;
407 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
408 EFSYS_ASSERT(etxop->etxo_qdesc_dma_create != NULL);
410 etxop->etxo_qdesc_dma_create(etp, addr, size, eop, edp);
414 efx_tx_qdesc_tso_create(
416 __in uint16_t ipv4_id,
417 __in uint32_t tcp_seq,
418 __in uint8_t tcp_flags,
419 __out efx_desc_t *edp)
421 efx_nic_t *enp = etp->et_enp;
422 const efx_tx_ops_t *etxop = enp->en_etxop;
424 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
425 EFSYS_ASSERT(etxop->etxo_qdesc_tso_create != NULL);
427 etxop->etxo_qdesc_tso_create(etp, ipv4_id, tcp_seq, tcp_flags, edp);
431 efx_tx_qdesc_tso2_create(
433 __in uint16_t ipv4_id,
434 __in uint32_t tcp_seq,
436 __out_ecount(count) efx_desc_t *edp,
439 efx_nic_t *enp = etp->et_enp;
440 const efx_tx_ops_t *etxop = enp->en_etxop;
442 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
443 EFSYS_ASSERT(etxop->etxo_qdesc_tso2_create != NULL);
445 etxop->etxo_qdesc_tso2_create(etp, ipv4_id, tcp_seq, mss, edp, count);
449 efx_tx_qdesc_vlantci_create(
452 __out efx_desc_t *edp)
454 efx_nic_t *enp = etp->et_enp;
455 const efx_tx_ops_t *etxop = enp->en_etxop;
457 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
458 EFSYS_ASSERT(etxop->etxo_qdesc_vlantci_create != NULL);
460 etxop->etxo_qdesc_vlantci_create(etp, tci, edp);