49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Copyright (c) 2012-2015 Solarflare Communications Inc.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * All rights reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Redistribution and use in source and binary forms, with or without
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * modification, are permitted provided that the following conditions are met:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 1. Redistributions of source code must retain the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer in the documentation
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * and/or other materials provided with the distribution.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The views and conclusions contained in the software and documentation are
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * those of the authors and should not be interpreted as representing official
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * policies, either expressed or implied, of the FreeBSD Project.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore uint8_t payload[MAX(MC_CMD_INIT_TXQ_IN_LEN(EFX_TXQ_MAX_BUFS),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFX_TXQ_NBUFS(EFX_TXQ_MAXNDESCS(&enp->en_nic_cfg)));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (npages > MC_CMD_INIT_TXQ_IN_DMA_ADDR_MAXNUM) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) memset(payload, 0, sizeof (payload));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore req.emr_in_length = MC_CMD_INIT_TXQ_IN_LEN(npages);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore req.emr_out_length = MC_CMD_INIT_TXQ_OUT_LEN;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_SIZE, size);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_TARGET_EVQ, target_evq);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_LABEL, label);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_INSTANCE, instance);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_POPULATE_DWORD_7(req, INIT_TXQ_IN_FLAGS,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, (flags & EFX_TXQ_FATSOV2) ? 1 : 0,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_OWNER_ID, 0);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_SET_DWORD(req, INIT_TXQ_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore dma_addr = MCDI_IN2(req, efx_qword_t, INIT_TXQ_IN_DMA_ADDR);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore for (i = 0; i < npages; i++) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFX_DWORD_0, (uint32_t)(addr & 0xffffffff));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) memset(payload, 0, sizeof (payload));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore req.emr_out_length = MC_CMD_FINI_TXQ_OUT_LEN;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore MCDI_IN_SET_DWORD(req, FINI_TXQ_IN_INSTANCE, instance);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((req.emr_rc != 0) && (req.emr_rc != MC_CMD_ERR_EALREADY)) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_mcdi_init_txq(enp, n, eep->ee_index, label, index, flags,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * A previous user of this TX queue may have written a descriptor to the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * TX push collector, but not pushed the doorbell (e.g. after a crash).
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The next doorbell write would then push the stale descriptor.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Ensure the (per network port) TX push collector is cleared by writing
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * a no-op TX option descriptor. See bug29981 for details.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Sub-allocate a PIO block from a piobuf */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Link the piobuf to this TXQ */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = ef10_nic_pio_link(enp, etp->et_index, handle)) != 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * et_pio_offset is the offset of the sub-allocated block within the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * hardware PIO buffer. It is used as the buffer address in the PIO
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * option descriptor.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * et_pio_write_offset is the offset of the sub-allocated block from the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * start of the write-combined memory mapping, and is used for writing
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * data into the PIO buffer.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (etp->et_pio_bufnum * ER_DZ_TX_PIOBUF_STEP) +
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) ef10_nic_pio_free(enp, etp->et_pio_bufnum, etp->et_pio_blknum);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Unlink the piobuf from this TXQ */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) ef10_nic_pio_unlink(enp, etp->et_index);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Free the sub-allocated PIO block */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) ef10_nic_pio_free(enp, etp->et_pio_bufnum,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(length % sizeof (efx_qword_t) == 0);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Writes to PIO buffers must be 64 bit aligned, and multiples of
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore write_offset = etp->et_pio_write_offset + offset;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_BAR_WC_WRITEQ(esbp, write_offset, eqp);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (added - completed + 1 > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_PROBE4(tx_pio_post, unsigned int, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore unsigned int, id, uint32_t, etp->et_pio_offset,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ESF_DZ_TX_PIO_BUF_ADDR, etp->et_pio_offset);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &pio_desc);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore __in unsigned int n,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore unsigned int i;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (added - completed + n > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore for (i = 0; i < n; i++) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Fragments must not span 4k boundaries. */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(P2ROUNDUP(addr + 1, 4096) >= (addr + size));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_PROBE5(tx_post, unsigned int, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ESF_DZ_TX_KER_BUF_ADDR_DW0, (uint32_t)(addr & 0xffffffff),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ESF_DZ_TX_KER_BUF_ADDR_DW1, (uint32_t)(addr >> 32));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &qword);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * This improves performance by pushing a TX descriptor at the same time as the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * doorbell. The descriptor must be added to the TXQ, so that can be used if the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * hardware decides not to use the pushed descriptor.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_MEM_READQ(etp->et_esmp, offset, &desc);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ERF_DZ_TX_DESC_HWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_1),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ERF_DZ_TX_DESC_LWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_0));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Guarantee ordering of memory (descriptors) and PIO (doorbell) */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFX_DMA_SYNC_QUEUE_FOR_DEVICE(etp->et_esmp, etp->et_mask + 1, wptr, id);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFX_BAR_TBL_DOORBELL_WRITEO(enp, ER_DZ_TX_DESC_UPD_REG, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore __in unsigned int n,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore unsigned int i;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (added - completed + n > EFX_TXQ_LIMIT(etp->et_mask + 1)) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore for (i = 0; i < n; i++) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_MEM_WRITEQ(etp->et_esmp, offset, &edp->ed_eq);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_PROBE3(tx_desc_post, unsigned int, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore unsigned int, added, unsigned int, n);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Fragments must not span 4k boundaries. */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(P2ROUNDUP(addr + 1, 4096) >= addr + size);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_PROBE4(tx_desc_dma_create, unsigned int, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ESF_DZ_TX_KER_BUF_ADDR_DW0, (uint32_t)(addr & 0xffffffff),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ESF_DZ_TX_KER_BUF_ADDR_DW1, (uint32_t)(addr >> 32));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_PROBE4(tx_desc_tso_create, unsigned int, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_PROBE4(tx_desc_tso2_create, unsigned int, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_ASSERT(count >= EFX_TX_FATSOV2_OPT_NDESCS);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore EFSYS_PROBE2(tx_desc_vlantci_create, unsigned int, etp->et_index,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_mcdi_fini_txq(enp, etp->et_index)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore __inout_ecount(TX_NQSTATS) efsys_stat_t *stat)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#endif /* EFSYS_OPT_QSTATS */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */