1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2012-2018 Solarflare Communications Inc.
11 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
14 #define EFX_TX_QSTAT_INCR(_etp, _stat) \
16 (_etp)->et_stat[_stat]++; \
17 _NOTE(CONSTANTCONDITION) \
20 #define EFX_TX_QSTAT_INCR(_etp, _stat)
23 static __checkReturn efx_rc_t
27 __in uint32_t target_evq,
29 __in uint32_t instance,
31 __in efsys_mem_t *esmp)
34 EFX_MCDI_DECLARE_BUF(payload,
35 MC_CMD_INIT_TXQ_IN_LEN(EF10_TXQ_MAXNBUFS),
36 MC_CMD_INIT_TXQ_OUT_LEN);
37 efx_qword_t *dma_addr;
43 EFSYS_ASSERT(EF10_TXQ_MAXNBUFS >=
44 EFX_TXQ_NBUFS(enp->en_nic_cfg.enc_txq_max_ndescs));
46 if ((esmp == NULL) || (EFSYS_MEM_SIZE(esmp) < EFX_TXQ_SIZE(ndescs))) {
51 npages = EFX_TXQ_NBUFS(ndescs);
52 if (MC_CMD_INIT_TXQ_IN_LEN(npages) > sizeof (payload)) {
57 req.emr_cmd = MC_CMD_INIT_TXQ;
58 req.emr_in_buf = payload;
59 req.emr_in_length = MC_CMD_INIT_TXQ_IN_LEN(npages);
60 req.emr_out_buf = payload;
61 req.emr_out_length = MC_CMD_INIT_TXQ_OUT_LEN;
63 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_SIZE, ndescs);
64 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_TARGET_EVQ, target_evq);
65 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_LABEL, label);
66 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_INSTANCE, instance);
68 MCDI_IN_POPULATE_DWORD_9(req, INIT_TXQ_IN_FLAGS,
69 INIT_TXQ_IN_FLAG_BUFF_MODE, 0,
70 INIT_TXQ_IN_FLAG_IP_CSUM_DIS,
71 (flags & EFX_TXQ_CKSUM_IPV4) ? 0 : 1,
72 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS,
73 (flags & EFX_TXQ_CKSUM_TCPUDP) ? 0 : 1,
74 INIT_TXQ_EXT_IN_FLAG_INNER_IP_CSUM_EN,
75 (flags & EFX_TXQ_CKSUM_INNER_IPV4) ? 1 : 0,
76 INIT_TXQ_EXT_IN_FLAG_INNER_TCP_CSUM_EN,
77 (flags & EFX_TXQ_CKSUM_INNER_TCPUDP) ? 1 : 0,
78 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, (flags & EFX_TXQ_FATSOV2) ? 1 : 0,
79 INIT_TXQ_IN_FLAG_TCP_UDP_ONLY, 0,
80 INIT_TXQ_IN_CRC_MODE, 0,
81 INIT_TXQ_IN_FLAG_TIMESTAMP, 0);
83 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_OWNER_ID, 0);
84 MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
86 dma_addr = MCDI_IN2(req, efx_qword_t, INIT_TXQ_IN_DMA_ADDR);
87 addr = EFSYS_MEM_ADDR(esmp);
89 for (i = 0; i < npages; i++) {
90 EFX_POPULATE_QWORD_2(*dma_addr,
91 EFX_DWORD_1, (uint32_t)(addr >> 32),
92 EFX_DWORD_0, (uint32_t)(addr & 0xffffffff));
98 efx_mcdi_execute(enp, &req);
100 if (req.emr_rc != 0) {
112 EFSYS_PROBE1(fail1, efx_rc_t, rc);
117 static __checkReturn efx_rc_t
120 __in uint32_t instance)
123 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FINI_TXQ_IN_LEN,
124 MC_CMD_FINI_TXQ_OUT_LEN);
127 req.emr_cmd = MC_CMD_FINI_TXQ;
128 req.emr_in_buf = payload;
129 req.emr_in_length = MC_CMD_FINI_TXQ_IN_LEN;
130 req.emr_out_buf = payload;
131 req.emr_out_length = MC_CMD_FINI_TXQ_OUT_LEN;
133 MCDI_IN_SET_DWORD(req, FINI_TXQ_IN_INSTANCE, instance);
135 efx_mcdi_execute_quiet(enp, &req);
137 if (req.emr_rc != 0) {
146 * EALREADY is not an error, but indicates that the MC has rebooted and
147 * that the TXQ has already been destroyed.
150 EFSYS_PROBE1(fail1, efx_rc_t, rc);
155 __checkReturn efx_rc_t
159 _NOTE(ARGUNUSED(enp))
167 _NOTE(ARGUNUSED(enp))
170 __checkReturn efx_rc_t
173 __in unsigned int index,
174 __in unsigned int label,
175 __in efsys_mem_t *esmp,
181 __out unsigned int *addedp)
183 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
190 inner_csum = EFX_TXQ_CKSUM_INNER_IPV4 | EFX_TXQ_CKSUM_INNER_TCPUDP;
191 if (((flags & inner_csum) != 0) &&
192 (encp->enc_tunnel_encapsulations_supported == 0)) {
197 if ((rc = efx_mcdi_init_txq(enp, ndescs, eep->ee_index, label, index,
202 * A previous user of this TX queue may have written a descriptor to the
203 * TX push collector, but not pushed the doorbell (e.g. after a crash).
204 * The next doorbell write would then push the stale descriptor.
206 * Ensure the (per network port) TX push collector is cleared by writing
207 * a no-op TX option descriptor. See bug29981 for details.
210 ef10_tx_qdesc_checksum_create(etp, flags, &desc);
212 EFSYS_MEM_WRITEQ(etp->et_esmp, 0, &desc.ed_eq);
213 ef10_tx_qpush(etp, *addedp, 0);
220 EFSYS_PROBE1(fail1, efx_rc_t, rc);
230 _NOTE(ARGUNUSED(etp))
234 __checkReturn efx_rc_t
238 efx_nic_t *enp = etp->et_enp;
239 efx_piobuf_handle_t handle;
242 if (etp->et_pio_size != 0) {
247 /* Sub-allocate a PIO block from a piobuf */
248 if ((rc = ef10_nic_pio_alloc(enp,
253 &etp->et_pio_size)) != 0) {
256 EFSYS_ASSERT3U(etp->et_pio_size, !=, 0);
258 /* Link the piobuf to this TXQ */
259 if ((rc = ef10_nic_pio_link(enp, etp->et_index, handle)) != 0) {
264 * et_pio_offset is the offset of the sub-allocated block within the
265 * hardware PIO buffer. It is used as the buffer address in the PIO
268 * et_pio_write_offset is the offset of the sub-allocated block from the
269 * start of the write-combined memory mapping, and is used for writing
270 * data into the PIO buffer.
272 etp->et_pio_write_offset =
273 (etp->et_pio_bufnum * ER_DZ_TX_PIOBUF_STEP) +
274 ER_DZ_TX_PIOBUF_OFST + etp->et_pio_offset;
280 (void) ef10_nic_pio_free(enp, etp->et_pio_bufnum, etp->et_pio_blknum);
283 etp->et_pio_size = 0;
285 EFSYS_PROBE1(fail1, efx_rc_t, rc);
291 ef10_tx_qpio_disable(
294 efx_nic_t *enp = etp->et_enp;
296 if (etp->et_pio_size != 0) {
297 /* Unlink the piobuf from this TXQ */
298 if (ef10_nic_pio_unlink(enp, etp->et_index) != 0)
301 /* Free the sub-allocated PIO block */
302 (void) ef10_nic_pio_free(enp, etp->et_pio_bufnum,
304 etp->et_pio_size = 0;
305 etp->et_pio_write_offset = 0;
309 __checkReturn efx_rc_t
312 __in_ecount(length) uint8_t *buffer,
316 efx_nic_t *enp = etp->et_enp;
317 efsys_bar_t *esbp = enp->en_esbp;
318 uint32_t write_offset;
319 uint32_t write_offset_limit;
323 EFSYS_ASSERT(length % sizeof (efx_qword_t) == 0);
325 if (etp->et_pio_size == 0) {
329 if (offset + length > etp->et_pio_size) {
335 * Writes to PIO buffers must be 64 bit aligned, and multiples of
338 write_offset = etp->et_pio_write_offset + offset;
339 write_offset_limit = write_offset + length;
340 eqp = (efx_qword_t *)buffer;
341 while (write_offset < write_offset_limit) {
342 EFSYS_BAR_WC_WRITEQ(esbp, write_offset, eqp);
344 write_offset += sizeof (efx_qword_t);
352 EFSYS_PROBE1(fail1, efx_rc_t, rc);
357 __checkReturn efx_rc_t
360 __in size_t pkt_length,
361 __in unsigned int completed,
362 __inout unsigned int *addedp)
364 efx_qword_t pio_desc;
367 unsigned int added = *addedp;
371 if (added - completed + 1 > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
376 if (etp->et_pio_size == 0) {
381 id = added++ & etp->et_mask;
382 offset = id * sizeof (efx_qword_t);
384 EFSYS_PROBE4(tx_pio_post, unsigned int, etp->et_index,
385 unsigned int, id, uint32_t, etp->et_pio_offset,
388 EFX_POPULATE_QWORD_5(pio_desc,
389 ESF_DZ_TX_DESC_IS_OPT, 1,
390 ESF_DZ_TX_OPTION_TYPE, 1,
391 ESF_DZ_TX_PIO_CONT, 0,
392 ESF_DZ_TX_PIO_BYTE_CNT, pkt_length,
393 ESF_DZ_TX_PIO_BUF_ADDR, etp->et_pio_offset);
395 EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &pio_desc);
397 EFX_TX_QSTAT_INCR(etp, TX_POST_PIO);
405 EFSYS_PROBE1(fail1, efx_rc_t, rc);
410 __checkReturn efx_rc_t
413 __in_ecount(ndescs) efx_buffer_t *eb,
414 __in unsigned int ndescs,
415 __in unsigned int completed,
416 __inout unsigned int *addedp)
418 unsigned int added = *addedp;
422 if (added - completed + ndescs > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
427 for (i = 0; i < ndescs; i++) {
428 efx_buffer_t *ebp = &eb[i];
429 efsys_dma_addr_t addr = ebp->eb_addr;
430 size_t size = ebp->eb_size;
431 boolean_t eop = ebp->eb_eop;
436 /* No limitations on boundary crossing */
438 etp->et_enp->en_nic_cfg.enc_tx_dma_desc_size_max);
440 id = added++ & etp->et_mask;
441 offset = id * sizeof (efx_qword_t);
443 EFSYS_PROBE5(tx_post, unsigned int, etp->et_index,
444 unsigned int, id, efsys_dma_addr_t, addr,
445 size_t, size, boolean_t, eop);
447 EFX_POPULATE_QWORD_5(qword,
448 ESF_DZ_TX_KER_TYPE, 0,
449 ESF_DZ_TX_KER_CONT, (eop) ? 0 : 1,
450 ESF_DZ_TX_KER_BYTE_CNT, (uint32_t)(size),
451 ESF_DZ_TX_KER_BUF_ADDR_DW0, (uint32_t)(addr & 0xffffffff),
452 ESF_DZ_TX_KER_BUF_ADDR_DW1, (uint32_t)(addr >> 32));
454 EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &qword);
457 EFX_TX_QSTAT_INCR(etp, TX_POST);
463 EFSYS_PROBE1(fail1, efx_rc_t, rc);
469 * This improves performance by, when possible, pushing a TX descriptor at the
470 * same time as the doorbell. The descriptor must be added to the TXQ, so that
471 * can be used if the hardware decides not to use the pushed descriptor.
476 __in unsigned int added,
477 __in unsigned int pushed)
479 efx_nic_t *enp = etp->et_enp;
486 wptr = added & etp->et_mask;
487 id = pushed & etp->et_mask;
488 offset = id * sizeof (efx_qword_t);
490 EFSYS_MEM_READQ(etp->et_esmp, offset, &desc);
493 * Bug 65776: TSO option descriptors cannot be pushed if pacer bypass is
494 * enabled on the event queue this transmit queue is attached to.
496 * To ensure the code is safe, it is easiest to simply test the type of
497 * the descriptor to push, and only push it is if it not a TSO option
500 if ((EFX_QWORD_FIELD(desc, ESF_DZ_TX_DESC_IS_OPT) != 1) ||
501 (EFX_QWORD_FIELD(desc, ESF_DZ_TX_OPTION_TYPE) !=
502 ESE_DZ_TX_OPTION_DESC_TSO)) {
503 /* Push the descriptor and update the wptr. */
504 EFX_POPULATE_OWORD_3(oword, ERF_DZ_TX_DESC_WPTR, wptr,
505 ERF_DZ_TX_DESC_HWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_1),
506 ERF_DZ_TX_DESC_LWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_0));
508 /* Ensure ordering of memory (descriptors) and PIO (doorbell) */
509 EFX_DMA_SYNC_QUEUE_FOR_DEVICE(etp->et_esmp, etp->et_mask + 1,
511 EFSYS_PIO_WRITE_BARRIER();
512 EFX_BAR_VI_DOORBELL_WRITEO(enp, ER_DZ_TX_DESC_UPD_REG,
513 etp->et_index, &oword);
518 * Only update the wptr. This is signalled to the hardware by
519 * only writing one DWORD of the doorbell register.
521 EFX_POPULATE_OWORD_1(oword, ERF_DZ_TX_DESC_WPTR, wptr);
522 dword = oword.eo_dword[2];
524 /* Ensure ordering of memory (descriptors) and PIO (doorbell) */
525 EFX_DMA_SYNC_QUEUE_FOR_DEVICE(etp->et_esmp, etp->et_mask + 1,
527 EFSYS_PIO_WRITE_BARRIER();
528 EFX_BAR_VI_WRITED2(enp, ER_DZ_TX_DESC_UPD_REG,
529 etp->et_index, &dword, B_FALSE);
533 __checkReturn efx_rc_t
536 __in_ecount(ndescs) efx_desc_t *ed,
537 __in unsigned int ndescs,
538 __in unsigned int completed,
539 __inout unsigned int *addedp)
541 unsigned int added = *addedp;
544 if (added - completed + ndescs > EFX_TXQ_LIMIT(etp->et_mask + 1))
547 for (i = 0; i < ndescs; i++) {
548 efx_desc_t *edp = &ed[i];
552 id = added++ & etp->et_mask;
553 offset = id * sizeof (efx_desc_t);
555 EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &edp->ed_eq);
558 EFSYS_PROBE3(tx_desc_post, unsigned int, etp->et_index,
559 unsigned int, added, unsigned int, ndescs);
561 EFX_TX_QSTAT_INCR(etp, TX_POST);
568 ef10_tx_qdesc_dma_create(
570 __in efsys_dma_addr_t addr,
573 __out efx_desc_t *edp)
575 _NOTE(ARGUNUSED(etp))
577 /* No limitations on boundary crossing */
578 EFSYS_ASSERT(size <= etp->et_enp->en_nic_cfg.enc_tx_dma_desc_size_max);
580 EFSYS_PROBE4(tx_desc_dma_create, unsigned int, etp->et_index,
581 efsys_dma_addr_t, addr,
582 size_t, size, boolean_t, eop);
584 EFX_POPULATE_QWORD_5(edp->ed_eq,
585 ESF_DZ_TX_KER_TYPE, 0,
586 ESF_DZ_TX_KER_CONT, (eop) ? 0 : 1,
587 ESF_DZ_TX_KER_BYTE_CNT, (uint32_t)(size),
588 ESF_DZ_TX_KER_BUF_ADDR_DW0, (uint32_t)(addr & 0xffffffff),
589 ESF_DZ_TX_KER_BUF_ADDR_DW1, (uint32_t)(addr >> 32));
593 ef10_tx_qdesc_tso_create(
595 __in uint16_t ipv4_id,
596 __in uint32_t tcp_seq,
597 __in uint8_t tcp_flags,
598 __out efx_desc_t *edp)
600 _NOTE(ARGUNUSED(etp))
602 EFSYS_PROBE4(tx_desc_tso_create, unsigned int, etp->et_index,
603 uint16_t, ipv4_id, uint32_t, tcp_seq,
606 EFX_POPULATE_QWORD_5(edp->ed_eq,
607 ESF_DZ_TX_DESC_IS_OPT, 1,
608 ESF_DZ_TX_OPTION_TYPE,
609 ESE_DZ_TX_OPTION_DESC_TSO,
610 ESF_DZ_TX_TSO_TCP_FLAGS, tcp_flags,
611 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
612 ESF_DZ_TX_TSO_TCP_SEQNO, tcp_seq);
616 ef10_tx_qdesc_tso2_create(
618 __in uint16_t ipv4_id,
619 __in uint16_t outer_ipv4_id,
620 __in uint32_t tcp_seq,
621 __in uint16_t tcp_mss,
622 __out_ecount(count) efx_desc_t *edp,
625 _NOTE(ARGUNUSED(etp, count))
627 EFSYS_PROBE4(tx_desc_tso2_create, unsigned int, etp->et_index,
628 uint16_t, ipv4_id, uint32_t, tcp_seq,
631 EFSYS_ASSERT(count >= EFX_TX_FATSOV2_OPT_NDESCS);
633 EFX_POPULATE_QWORD_5(edp[0].ed_eq,
634 ESF_DZ_TX_DESC_IS_OPT, 1,
635 ESF_DZ_TX_OPTION_TYPE,
636 ESE_DZ_TX_OPTION_DESC_TSO,
637 ESF_DZ_TX_TSO_OPTION_TYPE,
638 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
639 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
640 ESF_DZ_TX_TSO_TCP_SEQNO, tcp_seq);
641 EFX_POPULATE_QWORD_5(edp[1].ed_eq,
642 ESF_DZ_TX_DESC_IS_OPT, 1,
643 ESF_DZ_TX_OPTION_TYPE,
644 ESE_DZ_TX_OPTION_DESC_TSO,
645 ESF_DZ_TX_TSO_OPTION_TYPE,
646 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
647 ESF_DZ_TX_TSO_TCP_MSS, tcp_mss,
648 ESF_DZ_TX_TSO_OUTER_IPID, outer_ipv4_id);
652 ef10_tx_qdesc_vlantci_create(
655 __out efx_desc_t *edp)
657 _NOTE(ARGUNUSED(etp))
659 EFSYS_PROBE2(tx_desc_vlantci_create, unsigned int, etp->et_index,
662 EFX_POPULATE_QWORD_4(edp->ed_eq,
663 ESF_DZ_TX_DESC_IS_OPT, 1,
664 ESF_DZ_TX_OPTION_TYPE,
665 ESE_DZ_TX_OPTION_DESC_VLAN,
666 ESF_DZ_TX_VLAN_OP, tci ? 1 : 0,
667 ESF_DZ_TX_VLAN_TAG1, tci);
671 ef10_tx_qdesc_checksum_create(
674 __out efx_desc_t *edp)
676 _NOTE(ARGUNUSED(etp));
678 EFSYS_PROBE2(tx_desc_checksum_create, unsigned int, etp->et_index,
681 EFX_POPULATE_QWORD_6(edp->ed_eq,
682 ESF_DZ_TX_DESC_IS_OPT, 1,
683 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
684 ESF_DZ_TX_OPTION_UDP_TCP_CSUM,
685 (flags & EFX_TXQ_CKSUM_TCPUDP) ? 1 : 0,
686 ESF_DZ_TX_OPTION_IP_CSUM,
687 (flags & EFX_TXQ_CKSUM_IPV4) ? 1 : 0,
688 ESF_DZ_TX_OPTION_INNER_UDP_TCP_CSUM,
689 (flags & EFX_TXQ_CKSUM_INNER_TCPUDP) ? 1 : 0,
690 ESF_DZ_TX_OPTION_INNER_IP_CSUM,
691 (flags & EFX_TXQ_CKSUM_INNER_IPV4) ? 1 : 0);
695 __checkReturn efx_rc_t
698 __in unsigned int ns)
703 _NOTE(ARGUNUSED(etp, ns))
704 _NOTE(CONSTANTCONDITION)
714 EFSYS_PROBE1(fail1, efx_rc_t, rc);
719 __checkReturn efx_rc_t
723 efx_nic_t *enp = etp->et_enp;
726 if ((rc = efx_mcdi_fini_txq(enp, etp->et_index)) != 0)
733 * EALREADY is not an error, but indicates that the MC has rebooted and
734 * that the TXQ has already been destroyed. Callers need to know that
735 * the TXQ flush has completed to avoid waiting until timeout for a
736 * flush done event that will not be delivered.
739 EFSYS_PROBE1(fail1, efx_rc_t, rc);
749 _NOTE(ARGUNUSED(etp))
755 ef10_tx_qstats_update(
757 __inout_ecount(TX_NQSTATS) efsys_stat_t *stat)
761 for (id = 0; id < TX_NQSTATS; id++) {
762 efsys_stat_t *essp = &stat[id];
764 EFSYS_STAT_INCR(essp, etp->et_stat[id]);
765 etp->et_stat[id] = 0;
769 #endif /* EFSYS_OPT_QSTATS */
771 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */