2 * Copyright 2007-2009 Solarflare Communications Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
31 #include "efx_types.h"
36 #define EFX_TX_QSTAT_INCR(_etp, _stat) \
38 (_etp)->et_stat[_stat]++; \
39 _NOTE(CONSTANTCONDITION) \
42 #define EFX_TX_QSTAT_INCR(_etp, _stat)
52 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
53 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
55 if (!(enp->en_mod_flags & EFX_MOD_EV)) {
60 if (enp->en_mod_flags & EFX_MOD_TX) {
65 EFSYS_ASSERT3U(enp->en_tx_qcount, ==, 0);
68 * Disable the timer-based TX DMA backoff and allow TX DMA to be
69 * controlled by the RX FIFO fill level (although always allow a
72 EFX_BAR_READO(enp, FR_AZ_TX_RESERVED_REG, &oword);
73 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_RX_SPACER, 0xfe);
74 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_RX_SPACER_EN, 1);
75 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
76 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_PUSH_EN, 0);
77 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_DIS_NON_IP_EV, 1);
78 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_PREF_THRESHOLD, 2);
79 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff);
82 * Filter all packets less than 14 bytes to avoid parsing
85 EFX_SET_OWORD_FIELD(oword, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
86 EFX_BAR_WRITEO(enp, FR_AZ_TX_RESERVED_REG, &oword);
89 * Do not set TX_NO_EOP_DISC_EN, since it limits packets to 16
90 * descriptors (which is bad).
92 EFX_BAR_READO(enp, FR_AZ_TX_CFG_REG, &oword);
93 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
94 EFX_BAR_WRITEO(enp, FR_AZ_TX_CFG_REG, &oword);
96 enp->en_mod_flags |= EFX_MOD_TX;
102 EFSYS_PROBE1(fail1, int, rc);
108 extern __checkReturn int
109 efx_tx_filter_insert(
111 __inout efx_filter_spec_t *spec)
113 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
114 EFSYS_ASSERT3P(spec, !=, NULL);
116 spec->efs_dmaq_id = (uint16_t)etp->et_index;
117 return efx_filter_insert_filter(etp->et_enp, spec, B_FALSE);
122 extern __checkReturn int
123 efx_tx_filter_remove(
125 __inout efx_filter_spec_t *spec)
127 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
128 EFSYS_ASSERT3P(spec, !=, NULL);
130 spec->efs_dmaq_id = (uint16_t)etp->et_index;
131 return efx_filter_remove_filter(etp->et_enp, spec);
135 #define EFX_TX_DESC(_etp, _addr, _size, _eop, _added) \
141 id = (_added)++ & (_etp)->et_mask; \
142 offset = id * sizeof (efx_qword_t); \
144 EFSYS_PROBE5(tx_post, unsigned int, (_etp)->et_index, \
145 unsigned int, id, efsys_dma_addr_t, (_addr), \
146 size_t, (_size), boolean_t, (_eop)); \
148 EFX_POPULATE_QWORD_4(qword, \
149 FSF_AZ_TX_KER_CONT, (_eop) ? 0 : 1, \
150 FSF_AZ_TX_KER_BYTE_COUNT, (uint32_t)(_size), \
151 FSF_AZ_TX_KER_BUF_ADDR_DW0, \
152 (uint32_t)((_addr) & 0xffffffff), \
153 FSF_AZ_TX_KER_BUF_ADDR_DW1, \
154 (uint32_t)((_addr) >> 32)); \
155 EFSYS_MEM_WRITEQ((_etp)->et_esmp, offset, &qword); \
157 _NOTE(CONSTANTCONDITION) \
163 __in_ecount(n) efx_buffer_t *eb,
165 __in unsigned int completed,
166 __inout unsigned int *addedp)
168 unsigned int added = *addedp;
172 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
174 if (added - completed + n > EFX_TXQ_LIMIT(etp->et_mask + 1))
177 for (i = 0; i < n; i++) {
178 efx_buffer_t *ebp = &eb[i];
179 efsys_dma_addr_t start = ebp->eb_addr;
180 size_t size = ebp->eb_size;
181 efsys_dma_addr_t end = start + size;
183 /* Fragments must not span 4k boundaries. */
184 EFSYS_ASSERT(P2ROUNDUP(start + 1, 4096) >= end);
186 EFX_TX_DESC(etp, start, size, ebp->eb_eop, added);
189 EFX_TX_QSTAT_INCR(etp, TX_POST);
195 EFSYS_PROBE1(fail1, int, rc);
203 __in unsigned int added)
205 efx_nic_t *enp = etp->et_enp;
210 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
212 /* Guarantee ordering of memory (descriptors) and PIO (doorbell) */
213 EFSYS_PIO_WRITE_BARRIER();
215 /* Push the populated descriptors out */
216 wptr = added & etp->et_mask;
218 EFX_POPULATE_OWORD_1(oword, FRF_AZ_TX_DESC_WPTR, wptr);
220 /* Only write the third DWORD */
221 EFX_POPULATE_DWORD_1(dword,
222 EFX_DWORD_0, EFX_OWORD_FIELD(oword, EFX_DWORD_3));
223 EFX_BAR_TBL_WRITED3(enp, FR_BZ_TX_DESC_UPD_REGP0,
224 etp->et_index, &dword, B_FALSE);
231 efx_nic_t *enp = etp->et_enp;
235 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
237 label = etp->et_index;
239 /* Flush the queue */
240 EFX_POPULATE_OWORD_2(oword, FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
241 FRF_AZ_TX_FLUSH_DESCQ, label);
242 EFX_BAR_WRITEO(enp, FR_AZ_TX_FLUSH_DESCQ_REG, &oword);
249 efx_nic_t *enp = etp->et_enp;
252 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
254 EFX_BAR_TBL_READO(enp, FR_AZ_TX_DESC_PTR_TBL,
255 etp->et_index, &oword);
257 EFSYS_PROBE5(tx_descq_ptr, unsigned int, etp->et_index,
258 uint32_t, EFX_OWORD_FIELD(oword, EFX_DWORD_3),
259 uint32_t, EFX_OWORD_FIELD(oword, EFX_DWORD_2),
260 uint32_t, EFX_OWORD_FIELD(oword, EFX_DWORD_1),
261 uint32_t, EFX_OWORD_FIELD(oword, EFX_DWORD_0));
263 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_DC_HW_RPTR, 0);
264 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_DESCQ_HW_RPTR, 0);
265 EFX_SET_OWORD_FIELD(oword, FRF_AZ_TX_DESCQ_EN, 1);
267 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TX_DESC_PTR_TBL,
268 etp->et_index, &oword);
274 __in unsigned int index,
275 __in unsigned int label,
276 __in efsys_mem_t *esmp,
281 __deref_out efx_txq_t **etpp)
283 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
289 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
290 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_TX);
292 EFX_STATIC_ASSERT(EFX_EV_TX_NLABELS == (1 << FRF_AZ_TX_DESCQ_LABEL_WIDTH));
293 EFSYS_ASSERT3U(label, <, EFX_EV_TX_NLABELS);
294 EFSYS_ASSERT3U(enp->en_tx_qcount + 1, <, encp->enc_txq_limit);
296 if (!ISP2(n) || !(n & EFX_TXQ_NDESCS_MASK)) {
300 if (index >= encp->enc_txq_limit) {
304 for (size = 0; (1 << size) <= (EFX_TXQ_MAXNDESCS / EFX_TXQ_MINNDESCS);
306 if ((1 << size) == (int)(n / EFX_TXQ_MINNDESCS))
308 if (id + (1 << size) >= encp->enc_buftbl_limit) {
313 /* Allocate an TXQ object */
314 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_txq_t), etp);
321 etp->et_magic = EFX_TXQ_MAGIC;
323 etp->et_index = index;
324 etp->et_mask = n - 1;
327 /* Set up the new descriptor queue */
328 EFX_POPULATE_OWORD_6(oword,
329 FRF_AZ_TX_DESCQ_BUF_BASE_ID, id,
330 FRF_AZ_TX_DESCQ_EVQ_ID, eep->ee_index,
331 FRF_AZ_TX_DESCQ_OWNER_ID, 0,
332 FRF_AZ_TX_DESCQ_LABEL, label,
333 FRF_AZ_TX_DESCQ_SIZE, size,
334 FRF_AZ_TX_DESCQ_TYPE, 0);
336 EFX_SET_OWORD_FIELD(oword, FRF_BZ_TX_NON_IP_DROP_DIS, 1);
337 EFX_SET_OWORD_FIELD(oword, FRF_BZ_TX_IP_CHKSM_DIS,
338 (flags & EFX_CKSUM_IPV4) ? 0 : 1);
339 EFX_SET_OWORD_FIELD(oword, FRF_BZ_TX_TCP_CHKSM_DIS,
340 (flags & EFX_CKSUM_TCPUDP) ? 0 : 1);
342 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TX_DESC_PTR_TBL,
343 etp->et_index, &oword);
356 EFSYS_PROBE1(fail1, int, rc);
362 /* START MKCONFIG GENERATED EfxTransmitQueueStatNamesBlock 78ca9ab00287fffb */
363 static const char __cs * __cs __efx_tx_qstat_name[] = {
367 /* END MKCONFIG GENERATED EfxTransmitQueueStatNamesBlock */
372 __in unsigned int id)
374 _NOTE(ARGUNUSED(enp))
375 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
376 EFSYS_ASSERT3U(id, <, TX_NQSTATS);
378 return (__efx_tx_qstat_name[id]);
380 #endif /* EFSYS_OPT_NAMES */
384 efx_tx_qstats_update(
386 __inout_ecount(TX_NQSTATS) efsys_stat_t *stat)
390 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
392 for (id = 0; id < TX_NQSTATS; id++) {
393 efsys_stat_t *essp = &stat[id];
395 EFSYS_STAT_INCR(essp, etp->et_stat[id]);
396 etp->et_stat[id] = 0;
399 #endif /* EFSYS_OPT_QSTATS */
405 efx_nic_t *enp = etp->et_enp;
408 EFSYS_ASSERT3U(etp->et_magic, ==, EFX_TXQ_MAGIC);
410 EFSYS_ASSERT(enp->en_tx_qcount != 0);
413 /* Purge descriptor queue */
414 EFX_ZERO_OWORD(oword);
416 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TX_DESC_PTR_TBL,
417 etp->et_index, &oword);
419 /* Free the TXQ object */
420 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_txq_t), etp);
427 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
428 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
429 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_TX);
430 EFSYS_ASSERT3U(enp->en_tx_qcount, ==, 0);
432 enp->en_mod_flags &= ~EFX_MOD_TX;