2 * Copyright (c) 2012-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.
35 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
37 #define EFX_TX_QSTAT_INCR(_etp, _stat)
39 static __checkReturn efx_rc_t
43 __in uint32_t target_evq,
45 __in uint32_t instance,
47 __in efsys_mem_t *esmp)
50 uint8_t payload[MAX(MC_CMD_INIT_TXQ_IN_LEN(EFX_TXQ_MAX_BUFS),
51 MC_CMD_INIT_TXQ_OUT_LEN)];
52 efx_qword_t *dma_addr;
58 EFSYS_ASSERT(EFX_TXQ_MAX_BUFS >=
59 EFX_TXQ_NBUFS(enp->en_nic_cfg.enc_txq_max_ndescs));
61 npages = EFX_TXQ_NBUFS(size);
62 if (npages > MC_CMD_INIT_TXQ_IN_DMA_ADDR_MAXNUM) {
67 (void) memset(payload, 0, sizeof (payload));
68 req.emr_cmd = MC_CMD_INIT_TXQ;
69 req.emr_in_buf = payload;
70 req.emr_in_length = MC_CMD_INIT_TXQ_IN_LEN(npages);
71 req.emr_out_buf = payload;
72 req.emr_out_length = MC_CMD_INIT_TXQ_OUT_LEN;
74 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_SIZE, size);
75 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_TARGET_EVQ, target_evq);
76 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_LABEL, label);
77 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_INSTANCE, instance);
79 MCDI_IN_POPULATE_DWORD_7(req, INIT_TXQ_IN_FLAGS,
80 INIT_TXQ_IN_FLAG_BUFF_MODE, 0,
81 INIT_TXQ_IN_FLAG_IP_CSUM_DIS,
82 (flags & EFX_TXQ_CKSUM_IPV4) ? 0 : 1,
83 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS,
84 (flags & EFX_TXQ_CKSUM_TCPUDP) ? 0 : 1,
85 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, (flags & EFX_TXQ_FATSOV2) ? 1 : 0,
86 INIT_TXQ_IN_FLAG_TCP_UDP_ONLY, 0,
87 INIT_TXQ_IN_CRC_MODE, 0,
88 INIT_TXQ_IN_FLAG_TIMESTAMP, 0);
90 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_OWNER_ID, 0);
91 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
93 dma_addr = MCDI_IN2(req, efx_qword_t, INIT_TXQ_IN_DMA_ADDR);
94 addr = EFSYS_MEM_ADDR(esmp);
96 for (i = 0; i < npages; i++) {
97 EFX_POPULATE_QWORD_2(*dma_addr,
98 EFX_DWORD_1, (uint32_t)(addr >> 32),
99 EFX_DWORD_0, (uint32_t)(addr & 0xffffffff));
102 addr += EFX_BUF_SIZE;
105 efx_mcdi_execute(enp, &req);
107 if (req.emr_rc != 0) {
117 EFSYS_PROBE1(fail1, efx_rc_t, rc);
122 static __checkReturn efx_rc_t
125 __in uint32_t instance)
128 uint8_t payload[MAX(MC_CMD_FINI_TXQ_IN_LEN,
129 MC_CMD_FINI_TXQ_OUT_LEN)];
132 (void) memset(payload, 0, sizeof (payload));
133 req.emr_cmd = MC_CMD_FINI_TXQ;
134 req.emr_in_buf = payload;
135 req.emr_in_length = MC_CMD_FINI_TXQ_IN_LEN;
136 req.emr_out_buf = payload;
137 req.emr_out_length = MC_CMD_FINI_TXQ_OUT_LEN;
139 MCDI_IN_SET_DWORD(req, FINI_TXQ_IN_INSTANCE, instance);
141 efx_mcdi_execute_quiet(enp, &req);
143 if ((req.emr_rc != 0) && (req.emr_rc != MC_CMD_ERR_EALREADY)) {
151 EFSYS_PROBE1(fail1, efx_rc_t, rc);
156 __checkReturn efx_rc_t
160 _NOTE(ARGUNUSED(enp))
168 _NOTE(ARGUNUSED(enp))
171 __checkReturn efx_rc_t
174 __in unsigned int index,
175 __in unsigned int label,
176 __in efsys_mem_t *esmp,
182 __out unsigned int *addedp)
189 if ((rc = efx_mcdi_init_txq(enp, n, eep->ee_index, label, index, flags,
194 * A previous user of this TX queue may have written a descriptor to the
195 * TX push collector, but not pushed the doorbell (e.g. after a crash).
196 * The next doorbell write would then push the stale descriptor.
198 * Ensure the (per network port) TX push collector is cleared by writing
199 * a no-op TX option descriptor. See bug29981 for details.
202 EFX_POPULATE_QWORD_4(desc,
203 ESF_DZ_TX_DESC_IS_OPT, 1,
204 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
205 ESF_DZ_TX_OPTION_UDP_TCP_CSUM,
206 (flags & EFX_TXQ_CKSUM_TCPUDP) ? 1 : 0,
207 ESF_DZ_TX_OPTION_IP_CSUM,
208 (flags & EFX_TXQ_CKSUM_IPV4) ? 1 : 0);
210 EFSYS_MEM_WRITEQ(etp->et_esmp, 0, &desc);
211 ef10_tx_qpush(etp, *addedp, 0);
216 EFSYS_PROBE1(fail1, efx_rc_t, rc);
226 _NOTE(ARGUNUSED(etp))
230 __checkReturn efx_rc_t
234 efx_nic_t *enp = etp->et_enp;
235 efx_piobuf_handle_t handle;
238 if (etp->et_pio_size != 0) {
243 /* Sub-allocate a PIO block from a piobuf */
244 if ((rc = ef10_nic_pio_alloc(enp,
249 &etp->et_pio_size)) != 0) {
252 EFSYS_ASSERT3U(etp->et_pio_size, !=, 0);
254 /* Link the piobuf to this TXQ */
255 if ((rc = ef10_nic_pio_link(enp, etp->et_index, handle)) != 0) {
260 * et_pio_offset is the offset of the sub-allocated block within the
261 * hardware PIO buffer. It is used as the buffer address in the PIO
264 * et_pio_write_offset is the offset of the sub-allocated block from the
265 * start of the write-combined memory mapping, and is used for writing
266 * data into the PIO buffer.
268 etp->et_pio_write_offset =
269 (etp->et_pio_bufnum * ER_DZ_TX_PIOBUF_STEP) +
270 ER_DZ_TX_PIOBUF_OFST + etp->et_pio_offset;
276 ef10_nic_pio_free(enp, etp->et_pio_bufnum, etp->et_pio_blknum);
277 etp->et_pio_size = 0;
281 EFSYS_PROBE1(fail1, efx_rc_t, rc);
287 ef10_tx_qpio_disable(
290 efx_nic_t *enp = etp->et_enp;
292 if (etp->et_pio_size != 0) {
293 /* Unlink the piobuf from this TXQ */
294 ef10_nic_pio_unlink(enp, etp->et_index);
296 /* Free the sub-allocated PIO block */
297 ef10_nic_pio_free(enp, etp->et_pio_bufnum, etp->et_pio_blknum);
298 etp->et_pio_size = 0;
299 etp->et_pio_write_offset = 0;
303 __checkReturn efx_rc_t
306 __in_ecount(length) uint8_t *buffer,
310 efx_nic_t *enp = etp->et_enp;
311 efsys_bar_t *esbp = enp->en_esbp;
312 uint32_t write_offset;
313 uint32_t write_offset_limit;
317 EFSYS_ASSERT(length % sizeof (efx_qword_t) == 0);
319 if (etp->et_pio_size == 0) {
323 if (offset + length > etp->et_pio_size) {
329 * Writes to PIO buffers must be 64 bit aligned, and multiples of
332 write_offset = etp->et_pio_write_offset + offset;
333 write_offset_limit = write_offset + length;
334 eqp = (efx_qword_t *)buffer;
335 while (write_offset < write_offset_limit) {
336 EFSYS_BAR_WC_WRITEQ(esbp, write_offset, eqp);
338 write_offset += sizeof (efx_qword_t);
346 EFSYS_PROBE1(fail1, efx_rc_t, rc);
351 __checkReturn efx_rc_t
354 __in size_t pkt_length,
355 __in unsigned int completed,
356 __inout unsigned int *addedp)
358 efx_qword_t pio_desc;
361 unsigned int added = *addedp;
365 if (added - completed + 1 > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
370 if (etp->et_pio_size == 0) {
375 id = added++ & etp->et_mask;
376 offset = id * sizeof (efx_qword_t);
378 EFSYS_PROBE4(tx_pio_post, unsigned int, etp->et_index,
379 unsigned int, id, uint32_t, etp->et_pio_offset,
382 EFX_POPULATE_QWORD_5(pio_desc,
383 ESF_DZ_TX_DESC_IS_OPT, 1,
384 ESF_DZ_TX_OPTION_TYPE, 1,
385 ESF_DZ_TX_PIO_CONT, 0,
386 ESF_DZ_TX_PIO_BYTE_CNT, pkt_length,
387 ESF_DZ_TX_PIO_BUF_ADDR, etp->et_pio_offset);
389 EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &pio_desc);
391 EFX_TX_QSTAT_INCR(etp, TX_POST_PIO);
399 EFSYS_PROBE1(fail1, efx_rc_t, rc);
404 __checkReturn efx_rc_t
407 __in_ecount(n) efx_buffer_t *eb,
409 __in unsigned int completed,
410 __inout unsigned int *addedp)
412 unsigned int added = *addedp;
416 if (added - completed + n > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
421 for (i = 0; i < n; i++) {
422 efx_buffer_t *ebp = &eb[i];
423 efsys_dma_addr_t addr = ebp->eb_addr;
424 size_t size = ebp->eb_size;
425 boolean_t eop = ebp->eb_eop;
430 /* Fragments must not span 4k boundaries. */
431 EFSYS_ASSERT(P2ROUNDUP(addr + 1, 4096) >= (addr + size));
433 id = added++ & etp->et_mask;
434 offset = id * sizeof (efx_qword_t);
436 EFSYS_PROBE5(tx_post, unsigned int, etp->et_index,
437 unsigned int, id, efsys_dma_addr_t, addr,
438 size_t, size, boolean_t, eop);
440 EFX_POPULATE_QWORD_5(qword,
441 ESF_DZ_TX_KER_TYPE, 0,
442 ESF_DZ_TX_KER_CONT, (eop) ? 0 : 1,
443 ESF_DZ_TX_KER_BYTE_CNT, (uint32_t)(size),
444 ESF_DZ_TX_KER_BUF_ADDR_DW0, (uint32_t)(addr & 0xffffffff),
445 ESF_DZ_TX_KER_BUF_ADDR_DW1, (uint32_t)(addr >> 32));
447 EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &qword);
450 EFX_TX_QSTAT_INCR(etp, TX_POST);
456 EFSYS_PROBE1(fail1, efx_rc_t, rc);
462 * This improves performance by pushing a TX descriptor at the same time as the
463 * doorbell. The descriptor must be added to the TXQ, so that can be used if the
464 * hardware decides not to use the pushed descriptor.
469 __in unsigned int added,
470 __in unsigned int pushed)
472 efx_nic_t *enp = etp->et_enp;
479 wptr = added & etp->et_mask;
480 id = pushed & etp->et_mask;
481 offset = id * sizeof (efx_qword_t);
483 EFSYS_MEM_READQ(etp->et_esmp, offset, &desc);
484 EFX_POPULATE_OWORD_3(oword,
485 ERF_DZ_TX_DESC_WPTR, wptr,
486 ERF_DZ_TX_DESC_HWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_1),
487 ERF_DZ_TX_DESC_LWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_0));
489 /* Guarantee ordering of memory (descriptors) and PIO (doorbell) */
490 EFX_DMA_SYNC_QUEUE_FOR_DEVICE(etp->et_esmp, etp->et_mask + 1, wptr, id);
491 EFSYS_PIO_WRITE_BARRIER();
492 EFX_BAR_TBL_DOORBELL_WRITEO(enp, ER_DZ_TX_DESC_UPD_REG, etp->et_index,
496 __checkReturn efx_rc_t
499 __in_ecount(n) efx_desc_t *ed,
501 __in unsigned int completed,
502 __inout unsigned int *addedp)
504 unsigned int added = *addedp;
508 if (added - completed + n > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
513 for (i = 0; i < n; i++) {
514 efx_desc_t *edp = &ed[i];
518 id = added++ & etp->et_mask;
519 offset = id * sizeof (efx_desc_t);
521 EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &edp->ed_eq);
524 EFSYS_PROBE3(tx_desc_post, unsigned int, etp->et_index,
525 unsigned int, added, unsigned int, n);
527 EFX_TX_QSTAT_INCR(etp, TX_POST);
533 EFSYS_PROBE1(fail1, efx_rc_t, rc);
539 ef10_tx_qdesc_dma_create(
541 __in efsys_dma_addr_t addr,
544 __out efx_desc_t *edp)
546 /* Fragments must not span 4k boundaries. */
547 EFSYS_ASSERT(P2ROUNDUP(addr + 1, 4096) >= addr + size);
549 EFSYS_PROBE4(tx_desc_dma_create, unsigned int, etp->et_index,
550 efsys_dma_addr_t, addr,
551 size_t, size, boolean_t, eop);
553 EFX_POPULATE_QWORD_5(edp->ed_eq,
554 ESF_DZ_TX_KER_TYPE, 0,
555 ESF_DZ_TX_KER_CONT, (eop) ? 0 : 1,
556 ESF_DZ_TX_KER_BYTE_CNT, (uint32_t)(size),
557 ESF_DZ_TX_KER_BUF_ADDR_DW0, (uint32_t)(addr & 0xffffffff),
558 ESF_DZ_TX_KER_BUF_ADDR_DW1, (uint32_t)(addr >> 32));
562 ef10_tx_qdesc_tso_create(
564 __in uint16_t ipv4_id,
565 __in uint32_t tcp_seq,
566 __in uint8_t tcp_flags,
567 __out efx_desc_t *edp)
569 EFSYS_PROBE4(tx_desc_tso_create, unsigned int, etp->et_index,
570 uint16_t, ipv4_id, uint32_t, tcp_seq,
573 EFX_POPULATE_QWORD_5(edp->ed_eq,
574 ESF_DZ_TX_DESC_IS_OPT, 1,
575 ESF_DZ_TX_OPTION_TYPE,
576 ESE_DZ_TX_OPTION_DESC_TSO,
577 ESF_DZ_TX_TSO_TCP_FLAGS, tcp_flags,
578 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
579 ESF_DZ_TX_TSO_TCP_SEQNO, tcp_seq);
583 ef10_tx_qdesc_tso2_create(
585 __in uint16_t ipv4_id,
586 __in uint32_t tcp_seq,
587 __in uint16_t tcp_mss,
588 __out_ecount(count) efx_desc_t *edp,
591 EFSYS_PROBE4(tx_desc_tso2_create, unsigned int, etp->et_index,
592 uint16_t, ipv4_id, uint32_t, tcp_seq,
595 EFSYS_ASSERT(count >= EFX_TX_FATSOV2_OPT_NDESCS);
597 EFX_POPULATE_QWORD_5(edp[0].ed_eq,
598 ESF_DZ_TX_DESC_IS_OPT, 1,
599 ESF_DZ_TX_OPTION_TYPE,
600 ESE_DZ_TX_OPTION_DESC_TSO,
601 ESF_DZ_TX_TSO_OPTION_TYPE,
602 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
603 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
604 ESF_DZ_TX_TSO_TCP_SEQNO, tcp_seq);
605 EFX_POPULATE_QWORD_4(edp[1].ed_eq,
606 ESF_DZ_TX_DESC_IS_OPT, 1,
607 ESF_DZ_TX_OPTION_TYPE,
608 ESE_DZ_TX_OPTION_DESC_TSO,
609 ESF_DZ_TX_TSO_OPTION_TYPE,
610 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
611 ESF_DZ_TX_TSO_TCP_MSS, tcp_mss);
615 ef10_tx_qdesc_vlantci_create(
618 __out efx_desc_t *edp)
620 EFSYS_PROBE2(tx_desc_vlantci_create, unsigned int, etp->et_index,
623 EFX_POPULATE_QWORD_4(edp->ed_eq,
624 ESF_DZ_TX_DESC_IS_OPT, 1,
625 ESF_DZ_TX_OPTION_TYPE,
626 ESE_DZ_TX_OPTION_DESC_VLAN,
627 ESF_DZ_TX_VLAN_OP, tci ? 1 : 0,
628 ESF_DZ_TX_VLAN_TAG1, tci);
632 __checkReturn efx_rc_t
635 __in unsigned int ns)
640 _NOTE(ARGUNUSED(etp, ns))
641 _NOTE(CONSTANTCONDITION)
651 EFSYS_PROBE1(fail1, efx_rc_t, rc);
656 __checkReturn efx_rc_t
660 efx_nic_t *enp = etp->et_enp;
663 if ((rc = efx_mcdi_fini_txq(enp, etp->et_index)) != 0)
669 EFSYS_PROBE1(fail1, efx_rc_t, rc);
679 _NOTE(ARGUNUSED(etp))
683 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */