From: Benjamin Berg Report split RX buffers to the opmode rather than silently discarding them. This requires a few adjustments as multiple RBs will be used each iteration in iwl_pcie_rx_handle. Simply remove the call to iwl_pcie_rx_move_to_allocator. iwl_pcie_rx_reuse_rbd already takes care of that, even if it is not done for every RB there. Signed-off-by: Benjamin Berg Assisted-by: LLM Reviewed-by: Johannes Berg Signed-off-by: Miri Korenblit --- .../net/wireless/intel/iwlwifi/iwl-devtrace.c | 12 +- .../net/wireless/intel/iwlwifi/iwl-devtrace.h | 10 +- .../wireless/intel/iwlwifi/pcie/internal.h | 5 +- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 233 +++++++++++------- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 8 +- 5 files changed, 166 insertions(+), 102 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.c b/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.c index 7e686297963d..cef8618cb9f8 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Copyright(c) 2009 - 2014 Intel Corporation. All rights reserved. - * Copyright (C) 2018, 2023 Intel Corporation + * Copyright (C) 2018, 2023, 2026 Intel Corporation *****************************************************************************/ #include @@ -24,13 +24,15 @@ EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_wrap_event); #include "iwl-devtrace.h" #endif /* __CHECKER__ */ -void __trace_iwlwifi_dev_rx(struct iwl_trans *trans, void *pkt, size_t len) +void __trace_iwlwifi_dev_rx(struct iwl_trans *trans, void *pkt, size_t len, + size_t first_frag_len) { size_t hdr_offset = 0, trace_len; - trace_len = iwl_rx_trace_len(trans, pkt, len, &hdr_offset); + trace_len = iwl_rx_trace_len(trans, pkt, first_frag_len, &hdr_offset); trace_iwlwifi_dev_rx(trans->dev, pkt, len, trace_len, hdr_offset); - if (trace_len < len) - trace_iwlwifi_dev_rx_data(trans->dev, pkt, len, trace_len); + if (trace_len < first_frag_len) + trace_iwlwifi_dev_rx_data(trans->dev, pkt, first_frag_len, + trace_len); } diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.h b/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.h index 99789c7cef3b..b17ba944c45a 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.h +++ b/drivers/net/wireless/intel/iwlwifi/iwl-devtrace.h @@ -3,7 +3,7 @@ * * Copyright(c) 2009 - 2014 Intel Corporation. All rights reserved. * Copyright(C) 2016 Intel Deutschland GmbH - * Copyright(c) 2018, 2023, 2025 Intel Corporation + * Copyright(c) 2018, 2023, 2025 - 2026 Intel Corporation *****************************************************************************/ #ifndef __IWLWIFI_DEVICE_TRACE @@ -101,15 +101,17 @@ DECLARE_TRACEPOINT(iwlwifi_dev_rx); DECLARE_TRACEPOINT(iwlwifi_dev_rx_data); #endif -void __trace_iwlwifi_dev_rx(struct iwl_trans *trans, void *pkt, size_t len); +void __trace_iwlwifi_dev_rx(struct iwl_trans *trans, void *pkt, size_t len, + size_t first_frag_len); static inline void maybe_trace_iwlwifi_dev_rx(struct iwl_trans *trans, - void *pkt, size_t len) + void *pkt, size_t len, + size_t first_frag_len) { #ifdef CONFIG_IWLWIFI_DEVICE_TRACING if (tracepoint_enabled(iwlwifi_dev_rx) || tracepoint_enabled(iwlwifi_dev_rx_data)) - __trace_iwlwifi_dev_rx(trans, pkt, len); + __trace_iwlwifi_dev_rx(trans, pkt, len, first_frag_len); #endif } #endif /* __IWLWIFI_DEVICE_TRACE */ diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h index eaf369dbf17b..fba854922d22 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/internal.h +++ b/drivers/net/wireless/intel/iwlwifi/pcie/internal.h @@ -145,9 +145,8 @@ struct iwl_rx_completion_desc_bz { * @rb_stts: driver's pointer to receive buffer status * @rb_stts_dma: bus address of receive buffer status * @lock: per-queue lock + * @incomplete_split_rb: next RB is a continuation of an invalid split RB * @queue: actual rx queue. Not used for multi-rx queue. - * @next_rb_is_fragment: indicates that the previous RB that we handled set - * the fragmented flag, so the next one is still another fragment * @napi: NAPI struct for this queue * @queue_size: size of this queue * @@ -167,7 +166,7 @@ struct iwl_rxq { u32 queue_size; struct list_head rx_free; struct list_head rx_used; - bool need_update, next_rb_is_fragment; + bool need_update, incomplete_split_rb; void *rb_stts; dma_addr_t rb_stts_dma; spinlock_t lock; diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c index e66d685eea6f..0693568f5e9f 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c @@ -1119,6 +1119,7 @@ static int _iwl_pcie_rx_init(struct iwl_trans *trans) rxq->read = 0; rxq->write = 0; rxq->write_actual = 0; + rxq->incomplete_split_rb = false; memset(rxq->rb_stts, 0, (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) ? @@ -1352,13 +1353,14 @@ static void iwl_pcie_rx_recycle_rbd(struct iwl_trans *trans, static bool iwl_pcie_rx_handle_pkt(struct iwl_trans *trans, struct iwl_rxq *rxq, struct iwl_rx_cmd_buffer *rxcb, - struct iwl_rx_packet *pkt, int len) + struct iwl_rx_packet *pkt, int len, + size_t first_frag_len) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); struct iwl_txq *txq = trans_pcie->txqs.txq[trans->conf.cmd_queue]; bool reclaim; - maybe_trace_iwlwifi_dev_rx(trans, pkt, len); + maybe_trace_iwlwifi_dev_rx(trans, pkt, len, first_frag_len); /* Reclaim a command buffer only if this packet is a response * to a (driver-originated) command. @@ -1409,32 +1411,94 @@ static bool iwl_pcie_rx_handle_pkt(struct iwl_trans *trans, return rxcb->_pages_stolen; } -static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans, - struct iwl_rxq *rxq, - struct iwl_rx_mem_buffer *rxb, - bool emergency, - int i) +static struct iwl_rx_mem_buffer *iwl_pcie_get_rxb(struct iwl_trans *trans, + struct iwl_rxq *rxq, u32 i) +{ + struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + struct iwl_rx_mem_buffer *rxb; + u16 vid; + + BUILD_BUG_ON(sizeof(struct iwl_rx_completion_desc) != 32); + BUILD_BUG_ON(sizeof(struct iwl_rx_completion_desc_bz) != 4); + + if (!trans->mac_cfg->mq_rx_supported) { + rxb = rxq->queue[i]; + rxq->queue[i] = NULL; + return rxb; + } + + if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { + struct iwl_rx_completion_desc_bz *cd = rxq->used_bd; + + vid = le16_to_cpu(cd[i].rbid); + } else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { + struct iwl_rx_completion_desc *cd = rxq->used_bd; + + vid = le16_to_cpu(cd[i].rbid); + } else { + __le32 *cd = rxq->used_bd; + + vid = le32_to_cpu(cd[i]) & 0x0FFF; /* 12-bit VID */ + } + + if (!vid || vid > RX_POOL_SIZE(trans_pcie->num_rx_bufs)) + goto out_err; + + rxb = trans_pcie->global_table[vid - 1]; + if (rxb->invalid) + goto out_err; + + IWL_DEBUG_RX(trans, "Got virtual RB ID %u\n", (u32)rxb->vid); + + rxb->invalid = true; + + return rxb; + +out_err: + WARN(1, "Invalid rxb from HW %u\n", (u32)vid); + iwl_trans_force_nmi(trans); + return NULL; +} + +static void iwl_pcie_rx_handle_rbs(struct iwl_trans *trans, struct iwl_rxq *rxq, + u32 idx, unsigned int n, bool emergency) { struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); + struct iwl_rx_mem_buffer *rxbs[IWL_RX_MAX_SPLIT_RBS] = {}; + u32 max_len = trans_pcie->rx_buf_bytes; + struct iwl_rx_cmd_buffer rxcb = { + ._rx_page_order = trans_pcie->rx_page_order, + .truesize = max_len, + }; bool pages_stolen = false; - int max_len = trans_pcie->rx_buf_bytes; + bool error = false; u32 offset = 0; - if (WARN_ON(!rxb)) - return; + for (int i = 0; i < n; i++) { + rxbs[i] = iwl_pcie_get_rxb(trans, rxq, + (idx + i) & (rxq->queue_size - 1)); + if (!rxbs[i]) { + error = true; + continue; + } - dma_unmap_page(trans->dev, rxb->page_dma, max_len, DMA_FROM_DEVICE); + dma_unmap_page(trans->dev, rxbs[i]->page_dma, max_len, + DMA_FROM_DEVICE); + + rxcb._frags[i].page = rxbs[i]->page; + rxcb._frags[i].offset = rxbs[i]->offset; + } + if (error) + goto out_recycle; while (offset + sizeof(u32) + sizeof(struct iwl_cmd_header) < max_len) { struct iwl_rx_packet *pkt; - int len; - struct iwl_rx_cmd_buffer rxcb = { - ._rx_page_order = trans_pcie->rx_page_order, - .truesize = max_len, - ._frags[0].offset = rxb->offset + offset, - ._frags[0].page = rxb->page, - ._pages_stolen = false, - }; + u32 first_frag_len; + u32 len; + + /* Reset/update for next command on <= AX210 (n == 1) */ + rxcb._pages_stolen = false; + rxcb._frags[0].offset = rxbs[0]->offset + offset; pkt = rxb_addr(&rxcb); @@ -1462,73 +1526,67 @@ static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans, len = iwl_rx_packet_len(pkt); len += sizeof(u32); /* account for status word */ + first_frag_len = min(len, max_len - offset); + /* Verify offset (pre-AX210, n == 1) and length for newer HW */ offset += ALIGN(len, FH_RSCSR_FRAME_ALIGN); - - /* check that what the device tells us made sense */ - if (len < sizeof(*pkt) || offset > max_len) + if (len < sizeof(*pkt) || offset > n * max_len) break; pages_stolen |= iwl_pcie_rx_handle_pkt(trans, rxq, &rxcb, - pkt, len); + pkt, len, + first_frag_len); if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) break; } - iwl_pcie_rx_recycle_rbd(trans, rxq, rxb, emergency, pages_stolen); +out_recycle: + /* the op mode took either all of the pages or none */ + for (int i = 0; i < n; i++) { + if (rxbs[i]) + iwl_pcie_rx_recycle_rbd(trans, rxq, rxbs[i], emergency, + pages_stolen); + } } -static struct iwl_rx_mem_buffer *iwl_pcie_get_rxb(struct iwl_trans *trans, - struct iwl_rxq *rxq, int i, - bool *join) +static bool iwl_pcie_rx_is_fragmented(struct iwl_trans *trans, + struct iwl_rxq *rxq, u32 i) { - struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); - struct iwl_rx_mem_buffer *rxb; - u16 vid; - - BUILD_BUG_ON(sizeof(struct iwl_rx_completion_desc) != 32); - BUILD_BUG_ON(sizeof(struct iwl_rx_completion_desc_bz) != 4); - - if (!trans->mac_cfg->mq_rx_supported) { - rxb = rxq->queue[i]; - rxq->queue[i] = NULL; - return rxb; - } - if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) { struct iwl_rx_completion_desc_bz *cd = rxq->used_bd; - vid = le16_to_cpu(cd[i].rbid); - *join = cd[i].flags & IWL_RX_CD_FLAGS_FRAGMENTED; + return cd[i].flags & IWL_RX_CD_FLAGS_FRAGMENTED; } else if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { struct iwl_rx_completion_desc *cd = rxq->used_bd; - vid = le16_to_cpu(cd[i].rbid); - *join = cd[i].flags & IWL_RX_CD_FLAGS_FRAGMENTED; - } else { - __le32 *cd = rxq->used_bd; - - vid = le32_to_cpu(cd[i]) & 0x0FFF; /* 12-bit VID */ + return cd[i].flags & IWL_RX_CD_FLAGS_FRAGMENTED; } - if (!vid || vid > RX_POOL_SIZE(trans_pcie->num_rx_bufs)) - goto out_err; + return false; +} - rxb = trans_pcie->global_table[vid - 1]; - if (rxb->invalid) - goto out_err; +static int iwl_pcie_rx_count_rbs(struct iwl_trans *trans, + struct iwl_rxq *rxq, u32 i, u32 r, + bool *incomplete) +{ + int n = 1; - IWL_DEBUG_RX(trans, "Got virtual RB ID %u\n", (u32)rxb->vid); + while (iwl_pcie_rx_is_fragmented(trans, rxq, i)) { + /* the split RB is too long and cannot be processed */ + if (n == IWL_RX_MAX_SPLIT_RBS) { + *incomplete = true; + return n; + } - rxb->invalid = true; + i = (i + 1) & (rxq->queue_size - 1); + n++; - return rxb; + if (i == r) + return 0; + } -out_err: - WARN(1, "Invalid rxb from HW %u\n", (u32)vid); - iwl_trans_force_nmi(trans); - return NULL; + return n; } /* @@ -1567,12 +1625,12 @@ static int iwl_pcie_rx_handle(struct iwl_trans *trans, int queue, int budget) while (i != r && ++handled < budget) { struct iwl_rb_allocator *rba = &trans_pcie->rba; - struct iwl_rx_mem_buffer *rxb; /* number of RBDs still waiting for page allocation */ u32 rb_pending_alloc = atomic_read(&trans_pcie->rba.req_pending) * RX_CLAIM_REQ_ALLOC; - bool join = false; + bool incomplete = false; + int n; if (unlikely(rb_pending_alloc >= rxq->queue_size / 2 && !emergency)) { @@ -1585,31 +1643,33 @@ static int iwl_pcie_rx_handle(struct iwl_trans *trans, int queue, int budget) IWL_DEBUG_RX(trans, "Q %d: HW = %d, SW = %d\n", rxq->id, r, i); - rxb = iwl_pcie_get_rxb(trans, rxq, i, &join); - if (!rxb) + n = iwl_pcie_rx_count_rbs(trans, rxq, i, r, &incomplete); + + /* incomplete split RB, just leave the RBs unread */ + if (!n) goto out; - if (unlikely(join || rxq->next_rb_is_fragment)) { - rxq->next_rb_is_fragment = join; - /* - * We can only get a multi-RB in the following cases: - * - firmware issue, sending a too big notification - * - sniffer mode with a large A-MSDU - * - large MTU frames (>2k) - * since the multi-RB functionality is limited to newer - * hardware that cannot put multiple entries into a - * single RB. - * - * Right now, the higher layers aren't set up to deal - * with that, so discard all of these. - */ - list_add_tail(&rxb->list, &rxq->rx_free); - rxq->free_count++; + if (!incomplete && !rxq->incomplete_split_rb) { + iwl_pcie_rx_handle_rbs(trans, rxq, i, n, emergency); } else { - iwl_pcie_rx_handle_rb(trans, rxq, rxb, emergency, i); + IWL_FW_CHECK(trans, !rxq->incomplete_split_rb, + "got too large split RB!\n"); + + /* Not unmapped, put back into the rx_free list */ + for (int j = 0; j < n; j++) { + struct iwl_rx_mem_buffer *rxb = + iwl_pcie_get_rxb(trans, rxq, + (j + i) & (rxq->queue_size - 1)); + + if (rxb) { + list_add_tail(&rxb->list, &rxq->rx_free); + rxq->free_count++; + } + } } - i = (i + 1) & (rxq->queue_size - 1); + rxq->incomplete_split_rb = incomplete; + i = (i + n) & (rxq->queue_size - 1); /* * If we have RX_CLAIM_REQ_ALLOC released rx buffers - @@ -1621,12 +1681,9 @@ static int iwl_pcie_rx_handle(struct iwl_trans *trans, int queue, int budget) if (rxq->used_count >= RX_CLAIM_REQ_ALLOC) iwl_pcie_rx_allocator_get(trans, rxq); - if (rxq->used_count % RX_CLAIM_REQ_ALLOC == 0 && !emergency) { - /* Add the remaining empty RBDs for allocator use */ - iwl_pcie_rx_move_to_allocator(rxq, rba); - } else if (emergency) { - count++; - if (count == 8) { + if (emergency) { + count += n; + if (count >= 8) { count = 0; if (rb_pending_alloc < rxq->queue_size / 3) { IWL_DEBUG_TPT(trans, diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c index ea0279948ef4..d5e3d417bf9f 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c @@ -1632,8 +1632,12 @@ void iwl_pcie_hcmd_complete(struct iwl_trans *trans, else iwl_txq_gen1_tfd_unmap(trans, meta, txq, index); - /* Input error checking is done when commands are added to queue. */ - if (meta->flags & CMD_WANT_SKB) { + /* + * Input error checking is done when commands are added to queue. + * + * Ignore split RBs here, iwl_trans_send_cmd will error out. + */ + if ((meta->flags & CMD_WANT_SKB) && !rxb_is_split(rxb)) { struct page *p = rxb_steal_page(rxb); meta->source->resp_pkt = pkt; -- 2.34.1