google/patches/idpf: Add idpf timeout patches These patches will be used for both A4X-Max and H4D, so they're needed for both the lakitu kernel and the 64k kernel. Patch 0001 and 0010 are a revert and reapplication of an upstream commit. If the upstream commit is applied before 0009, it conflicts, but it applies cleanly if reverted first and applied after. BUG=b/458497050 TEST=presubmit RELEASE_NOTE=None cos-patch: bug Signed-off-by: Kevin Berry <kpberry@google.com> Change-Id: Ib2d8f895a01d7c68131c2f4125f2516e05c27df2 Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/121021 Reviewed-by: Robert Kolchmeyer <rkolchmeyer@google.com> Main-Branch-Verified: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com> Reviewed-by: Jacob Moroni <jmoroni@google.com> Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com> (cherry picked from commit 191946cc53109056381208926af6f992526e43fe) Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/121102 Reviewed-by: Kevin Liu <zhihuil@google.com>
diff --git a/google/patches/idpf/0001-Revert-idpf-do-not-linearize-big-TSO-packets.patch b/google/patches/idpf/0001-Revert-idpf-do-not-linearize-big-TSO-packets.patch new file mode 100644 index 0000000..7e0dfc4 --- /dev/null +++ b/google/patches/idpf/0001-Revert-idpf-do-not-linearize-big-TSO-packets.patch
@@ -0,0 +1,309 @@ +From 5bf7e74655bf9b7c4a39c64b69acd4214f7eaa8a Mon Sep 17 00:00:00 2001 +From: Kevin Berry <kpberry@google.com> +Date: Mon, 8 Dec 2025 18:04:27 +0000 +Subject: [PATCH 01/10] Revert "idpf: do not linearize big TSO packets" + +This reverts commit b2caf82bcdfe4f2bddcbe79409d10926d0024459. +--- + drivers/net/ethernet/intel/idpf/idpf.h | 2 - + drivers/net/ethernet/intel/idpf/idpf_lib.c | 102 +--------------- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 129 ++++++++++++++++---- + 3 files changed, 113 insertions(+), 120 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf.h b/drivers/net/ethernet/intel/idpf/idpf.h +index f4d51c885f33..a2b346d91879 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf.h ++++ b/drivers/net/ethernet/intel/idpf/idpf.h +@@ -144,7 +144,6 @@ enum idpf_vport_state { + * @link_speed_mbps: Link speed in mbps + * @vport_idx: Relative vport index + * @max_tx_hdr_size: Max header length hardware can support +- * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather + * @state: See enum idpf_vport_state + * @netstats: Packet and byte stats + * @stats_lock: Lock to protect stats update +@@ -156,7 +155,6 @@ struct idpf_netdev_priv { + u32 link_speed_mbps; + u16 vport_idx; + u16 max_tx_hdr_size; +- u16 tx_max_bufs; + enum idpf_vport_state state; + struct rtnl_link_stats64 netstats; + spinlock_t stats_lock; +diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c +index 371fc5052420..52d9caab2fcb 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_lib.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c +@@ -742,7 +742,6 @@ static int idpf_cfg_netdev(struct idpf_vport *vport) + np->vport_idx = vport->idx; + np->vport_id = vport->vport_id; + np->max_tx_hdr_size = idpf_get_max_tx_hdr_size(adapter); +- np->tx_max_bufs = idpf_get_max_tx_bufs(adapter); + + spin_lock_init(&np->stats_lock); + +@@ -2206,92 +2205,6 @@ static int idpf_change_mtu(struct net_device *netdev, int new_mtu) + return err; + } + +-/** +- * idpf_chk_tso_segment - Check skb is not using too many buffers +- * @skb: send buffer +- * @max_bufs: maximum number of buffers +- * +- * For TSO we need to count the TSO header and segment payload separately. As +- * such we need to check cases where we have max_bufs-1 fragments or more as we +- * can potentially require max_bufs+1 DMA transactions, 1 for the TSO header, 1 +- * for the segment payload in the first descriptor, and another max_buf-1 for +- * the fragments. +- * +- * Returns true if the packet needs to be software segmented by core stack. +- */ +-static bool idpf_chk_tso_segment(const struct sk_buff *skb, +- unsigned int max_bufs) +-{ +- const struct skb_shared_info *shinfo = skb_shinfo(skb); +- const skb_frag_t *frag, *stale; +- int nr_frags, sum; +- +- /* no need to check if number of frags is less than max_bufs - 1 */ +- nr_frags = shinfo->nr_frags; +- if (nr_frags < (max_bufs - 1)) +- return false; +- +- /* We need to walk through the list and validate that each group +- * of max_bufs-2 fragments totals at least gso_size. +- */ +- nr_frags -= max_bufs - 2; +- frag = &shinfo->frags[0]; +- +- /* Initialize size to the negative value of gso_size minus 1. We use +- * this as the worst case scenario in which the frag ahead of us only +- * provides one byte which is why we are limited to max_bufs-2 +- * descriptors for a single transmit as the header and previous +- * fragment are already consuming 2 descriptors. +- */ +- sum = 1 - shinfo->gso_size; +- +- /* Add size of frags 0 through 4 to create our initial sum */ +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- +- /* Walk through fragments adding latest fragment, testing it, and +- * then removing stale fragments from the sum. +- */ +- for (stale = &shinfo->frags[0];; stale++) { +- int stale_size = skb_frag_size(stale); +- +- sum += skb_frag_size(frag++); +- +- /* The stale fragment may present us with a smaller +- * descriptor than the actual fragment size. To account +- * for that we need to remove all the data on the front and +- * figure out what the remainder would be in the last +- * descriptor associated with the fragment. +- */ +- if (stale_size > IDPF_TX_MAX_DESC_DATA) { +- int align_pad = -(skb_frag_off(stale)) & +- (IDPF_TX_MAX_READ_REQ_SIZE - 1); +- +- sum -= align_pad; +- stale_size -= align_pad; +- +- do { +- sum -= IDPF_TX_MAX_DESC_DATA_ALIGNED; +- stale_size -= IDPF_TX_MAX_DESC_DATA_ALIGNED; +- } while (stale_size > IDPF_TX_MAX_DESC_DATA); +- } +- +- /* if sum is negative we failed to make sufficient progress */ +- if (sum < 0) +- return true; +- +- if (!nr_frags--) +- break; +- +- sum -= stale_size; +- } +- +- return false; +-} +- + /** + * idpf_features_check - Validate packet conforms to limits + * @skb: skb buffer +@@ -2313,15 +2226,12 @@ static netdev_features_t idpf_features_check(struct sk_buff *skb, + if (skb->ip_summed != CHECKSUM_PARTIAL) + return features; + +- if (skb_is_gso(skb)) { +- /* We cannot support GSO if the MSS is going to be less than +- * 88 bytes. If it is then we need to drop support for GSO. +- */ +- if (skb_shinfo(skb)->gso_size < IDPF_TX_TSO_MIN_MSS) +- features &= ~NETIF_F_GSO_MASK; +- else if (idpf_chk_tso_segment(skb, np->tx_max_bufs)) +- features &= ~NETIF_F_GSO_MASK; +- } ++ /* We cannot support GSO if the MSS is going to be less than ++ * 88 bytes. If it is then we need to drop support for GSO. ++ */ ++ if (skb_is_gso(skb) && ++ (skb_shinfo(skb)->gso_size < IDPF_TX_TSO_MIN_MSS)) ++ features &= ~NETIF_F_GSO_MASK; + + /* Ensure MACLEN is <= 126 bytes (63 words) and not an odd size */ + len = skb_network_offset(skb); +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 12fa3a2cf946..a86185b40289 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -15,28 +15,8 @@ struct idpf_tx_stash { + #define idpf_tx_buf_compl_tag(buf) (*(u32 *)&(buf)->priv) + LIBETH_SQE_CHECK_PRIV(u32); + +-/** +- * idpf_chk_linearize - Check if skb exceeds max descriptors per packet +- * @skb: send buffer +- * @max_bufs: maximum scatter gather buffers for single packet +- * @count: number of buffers this packet needs +- * +- * Make sure we don't exceed maximum scatter gather buffers for a single +- * packet. +- * TSO case has been handled earlier from idpf_features_check(). +- */ +-static bool idpf_chk_linearize(const struct sk_buff *skb, +- unsigned int max_bufs, +- unsigned int count) +-{ +- if (likely(count <= max_bufs)) +- return false; +- +- if (skb_is_gso(skb)) +- return false; +- +- return true; +-} ++static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, ++ unsigned int count); + + /** + * idpf_buf_lifo_push - push a buffer pointer onto stack +@@ -2597,6 +2577,111 @@ int idpf_tso(struct sk_buff *skb, struct idpf_tx_offload_params *off) + return 1; + } + ++/** ++ * __idpf_chk_linearize - Check skb is not using too many buffers ++ * @skb: send buffer ++ * @max_bufs: maximum number of buffers ++ * ++ * For TSO we need to count the TSO header and segment payload separately. As ++ * such we need to check cases where we have max_bufs-1 fragments or more as we ++ * can potentially require max_bufs+1 DMA transactions, 1 for the TSO header, 1 ++ * for the segment payload in the first descriptor, and another max_buf-1 for ++ * the fragments. ++ */ ++static bool __idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs) ++{ ++ const struct skb_shared_info *shinfo = skb_shinfo(skb); ++ const skb_frag_t *frag, *stale; ++ int nr_frags, sum; ++ ++ /* no need to check if number of frags is less than max_bufs - 1 */ ++ nr_frags = shinfo->nr_frags; ++ if (nr_frags < (max_bufs - 1)) ++ return false; ++ ++ /* We need to walk through the list and validate that each group ++ * of max_bufs-2 fragments totals at least gso_size. ++ */ ++ nr_frags -= max_bufs - 2; ++ frag = &shinfo->frags[0]; ++ ++ /* Initialize size to the negative value of gso_size minus 1. We use ++ * this as the worst case scenario in which the frag ahead of us only ++ * provides one byte which is why we are limited to max_bufs-2 ++ * descriptors for a single transmit as the header and previous ++ * fragment are already consuming 2 descriptors. ++ */ ++ sum = 1 - shinfo->gso_size; ++ ++ /* Add size of frags 0 through 4 to create our initial sum */ ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ ++ /* Walk through fragments adding latest fragment, testing it, and ++ * then removing stale fragments from the sum. ++ */ ++ for (stale = &shinfo->frags[0];; stale++) { ++ int stale_size = skb_frag_size(stale); ++ ++ sum += skb_frag_size(frag++); ++ ++ /* The stale fragment may present us with a smaller ++ * descriptor than the actual fragment size. To account ++ * for that we need to remove all the data on the front and ++ * figure out what the remainder would be in the last ++ * descriptor associated with the fragment. ++ */ ++ if (stale_size > IDPF_TX_MAX_DESC_DATA) { ++ int align_pad = -(skb_frag_off(stale)) & ++ (IDPF_TX_MAX_READ_REQ_SIZE - 1); ++ ++ sum -= align_pad; ++ stale_size -= align_pad; ++ ++ do { ++ sum -= IDPF_TX_MAX_DESC_DATA_ALIGNED; ++ stale_size -= IDPF_TX_MAX_DESC_DATA_ALIGNED; ++ } while (stale_size > IDPF_TX_MAX_DESC_DATA); ++ } ++ ++ /* if sum is negative we failed to make sufficient progress */ ++ if (sum < 0) ++ return true; ++ ++ if (!nr_frags--) ++ break; ++ ++ sum -= stale_size; ++ } ++ ++ return false; ++} ++ ++/** ++ * idpf_chk_linearize - Check if skb exceeds max descriptors per packet ++ * @skb: send buffer ++ * @max_bufs: maximum scatter gather buffers for single packet ++ * @count: number of buffers this packet needs ++ * ++ * Make sure we don't exceed maximum scatter gather buffers for a single ++ * packet. We have to do some special checking around the boundary (max_bufs-1) ++ * if TSO is on since we need count the TSO header and payload separately. ++ * E.g.: a packet with 7 fragments can require 9 DMA transactions; 1 for TSO ++ * header, 1 for segment payload, and then 7 for the fragments. ++ */ ++static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, ++ unsigned int count) ++{ ++ if (likely(count < max_bufs)) ++ return false; ++ if (skb_is_gso(skb)) ++ return __idpf_chk_linearize(skb, max_bufs); ++ ++ return count > max_bufs; ++} + + /** + * idpf_tx_splitq_get_ctx_desc - grab next desc and update buffer ring +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0002-idpf-add-support-for-SW-triggered-interrupts.patch b/google/patches/idpf/0002-idpf-add-support-for-SW-triggered-interrupts.patch new file mode 100644 index 0000000..e5cdf77 --- /dev/null +++ b/google/patches/idpf/0002-idpf-add-support-for-SW-triggered-interrupts.patch
@@ -0,0 +1,96 @@ +From bde1cb810ec3a227546c7098dcbf89e29bb869ab Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Mon, 25 Nov 2024 15:58:54 -0800 +Subject: [PATCH 02/10] idpf: add support for SW triggered interrupts + +[ Upstream commit 93433c1d919775f8ac0f7893692f42e6731a5373 ] + +SW triggered interrupts are guaranteed to fire after their timer +expires, unlike Tx and Rx interrupts which will only fire after the +timer expires _and_ a descriptor write back is available to be processed +by the driver. + +Add the necessary fields, defines, and initializations to enable a SW +triggered interrupt in the vector's dyn_ctl register. + +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Tested-by: Krishneil Singh <krishneil.k.singh@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + drivers/net/ethernet/intel/idpf/idpf_dev.c | 3 +++ + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 8 +++++++- + drivers/net/ethernet/intel/idpf/idpf_vf_dev.c | 3 +++ + 3 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_dev.c b/drivers/net/ethernet/intel/idpf/idpf_dev.c +index 6c913a703df6..41e4bd49402a 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_dev.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_dev.c +@@ -101,6 +101,9 @@ static int idpf_intr_reg_init(struct idpf_vport *vport) + intr->dyn_ctl_itridx_s = PF_GLINT_DYN_CTL_ITR_INDX_S; + intr->dyn_ctl_intrvl_s = PF_GLINT_DYN_CTL_INTERVAL_S; + intr->dyn_ctl_wb_on_itr_m = PF_GLINT_DYN_CTL_WB_ON_ITR_M; ++ intr->dyn_ctl_swint_trig_m = PF_GLINT_DYN_CTL_SWINT_TRIG_M; ++ intr->dyn_ctl_sw_itridx_ena_m = ++ PF_GLINT_DYN_CTL_SW_ITR_INDX_ENA_M; + + spacing = IDPF_ITR_IDX_SPACING(reg_vals[vec_id].itrn_index_spacing, + IDPF_PF_ITR_IDX_SPACING); +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +index bfef38f089d0..12832b5b36f5 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +@@ -355,6 +355,8 @@ struct idpf_vec_regs { + * @dyn_ctl_itridx_m: Mask for ITR index + * @dyn_ctl_intrvl_s: Register bit offset for ITR interval + * @dyn_ctl_wb_on_itr_m: Mask for WB on ITR feature ++ * @dyn_ctl_sw_itridx_ena_m: Mask for SW ITR index ++ * @dyn_ctl_swint_trig_m: Mask for dyn_ctl SW triggered interrupt enable + * @rx_itr: RX ITR register + * @tx_itr: TX ITR register + * @icr_ena: Interrupt cause register offset +@@ -368,6 +370,8 @@ struct idpf_intr_reg { + u32 dyn_ctl_itridx_m; + u32 dyn_ctl_intrvl_s; + u32 dyn_ctl_wb_on_itr_m; ++ u32 dyn_ctl_sw_itridx_ena_m; ++ u32 dyn_ctl_swint_trig_m; + void __iomem *rx_itr; + void __iomem *tx_itr; + void __iomem *icr_ena; +@@ -438,7 +442,7 @@ struct idpf_q_vector { + cpumask_var_t affinity_mask; + __cacheline_group_end_aligned(cold); + }; +-libeth_cacheline_set_assert(struct idpf_q_vector, 112, ++libeth_cacheline_set_assert(struct idpf_q_vector, 120, + 24 + sizeof(struct napi_struct) + + 2 * sizeof(struct dim), + 8 + sizeof(cpumask_var_t)); +@@ -472,6 +476,8 @@ struct idpf_tx_queue_stats { + #define IDPF_ITR_IS_DYNAMIC(itr_mode) (itr_mode) + #define IDPF_ITR_TX_DEF IDPF_ITR_20K + #define IDPF_ITR_RX_DEF IDPF_ITR_20K ++/* Index used for 'SW ITR' update in DYN_CTL register */ ++#define IDPF_SW_ITR_UPDATE_IDX 2 + /* Index used for 'No ITR' update in DYN_CTL register */ + #define IDPF_NO_ITR_UPDATE_IDX 3 + #define IDPF_ITR_IDX_SPACING(spacing, dflt) (spacing ? spacing : dflt) +diff --git a/drivers/net/ethernet/intel/idpf/idpf_vf_dev.c b/drivers/net/ethernet/intel/idpf/idpf_vf_dev.c +index aad62e270ae4..aba828abcb17 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_vf_dev.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_vf_dev.c +@@ -101,6 +101,9 @@ static int idpf_vf_intr_reg_init(struct idpf_vport *vport) + intr->dyn_ctl_itridx_s = VF_INT_DYN_CTLN_ITR_INDX_S; + intr->dyn_ctl_intrvl_s = VF_INT_DYN_CTLN_INTERVAL_S; + intr->dyn_ctl_wb_on_itr_m = VF_INT_DYN_CTLN_WB_ON_ITR_M; ++ intr->dyn_ctl_swint_trig_m = VF_INT_DYN_CTLN_SWINT_TRIG_M; ++ intr->dyn_ctl_sw_itridx_ena_m = ++ VF_INT_DYN_CTLN_SW_ITR_INDX_ENA_M; + + spacing = IDPF_ITR_IDX_SPACING(reg_vals[vec_id].itrn_index_spacing, + IDPF_VF_ITR_IDX_SPACING); +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0003-idpf-trigger-SW-interrupt-when-exiting-wb_on_itr-mod.patch b/google/patches/idpf/0003-idpf-trigger-SW-interrupt-when-exiting-wb_on_itr-mod.patch new file mode 100644 index 0000000..4cab57e --- /dev/null +++ b/google/patches/idpf/0003-idpf-trigger-SW-interrupt-when-exiting-wb_on_itr-mod.patch
@@ -0,0 +1,100 @@ +From 298ae8f0d4f5b05875abd172c3776e4cb5962ca5 Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Mon, 25 Nov 2024 15:58:55 -0800 +Subject: [PATCH 03/10] idpf: trigger SW interrupt when exiting wb_on_itr mode + +[ Upstream commit 0c1683c681681c14f4389e3bfa8de10baf242ba8 ] + +There is a race condition between exiting wb_on_itr and completion write +backs. For example, we are in wb_on_itr mode and a Tx completion is +generated by HW, ready to be written back, as we are re-enabling +interrupts: + + HW SW + | | + | | idpf_tx_splitq_clean_all + | | napi_complete_done + | | + | tx_completion_wb | idpf_vport_intr_update_itr_ena_irq + +That tx_completion_wb happens before the vector is fully re-enabled. +Continuing with this example, it is a UDP stream and the +tx_completion_wb is the last one in the flow (there are no rx packets). +Because the HW generated the completion before the interrupt is fully +enabled, the HW will not fire the interrupt once the timer expires and +the write back will not happen. NAPI poll won't be called. We have +indicated we're back in interrupt mode but nothing else will trigger the +interrupt. Therefore, the completion goes unprocessed, triggering a Tx +timeout. + +To mitigate this, fire a SW triggered interrupt upon exiting wb_on_itr. +This interrupt will catch the rogue completion and avoid the timeout. +Add logic to set the appropriate bits in the vector's dyn_ctl register. + +Fixes: 9c4a27da0ecc ("idpf: enable WB_ON_ITR") +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Tested-by: Krishneil Singh <krishneil.k.singh@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 29 ++++++++++++++------- + 1 file changed, 19 insertions(+), 10 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index a86185b40289..2c034b12ac16 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -3589,21 +3589,31 @@ static void idpf_vport_intr_dis_irq_all(struct idpf_vport *vport) + /** + * idpf_vport_intr_buildreg_itr - Enable default interrupt generation settings + * @q_vector: pointer to q_vector +- * @type: itr index +- * @itr: itr value + */ +-static u32 idpf_vport_intr_buildreg_itr(struct idpf_q_vector *q_vector, +- const int type, u16 itr) ++static u32 idpf_vport_intr_buildreg_itr(struct idpf_q_vector *q_vector) + { +- u32 itr_val; ++ u32 itr_val = q_vector->intr_reg.dyn_ctl_intena_m; ++ int type = IDPF_NO_ITR_UPDATE_IDX; ++ u16 itr = 0; ++ ++ if (q_vector->wb_on_itr) { ++ /* ++ * Trigger a software interrupt when exiting wb_on_itr, to make ++ * sure we catch any pending write backs that might have been ++ * missed due to interrupt state transition. ++ */ ++ itr_val |= q_vector->intr_reg.dyn_ctl_swint_trig_m | ++ q_vector->intr_reg.dyn_ctl_sw_itridx_ena_m; ++ type = IDPF_SW_ITR_UPDATE_IDX; ++ itr = IDPF_ITR_20K; ++ } + + itr &= IDPF_ITR_MASK; + /* Don't clear PBA because that can cause lost interrupts that + * came in while we were cleaning/polling + */ +- itr_val = q_vector->intr_reg.dyn_ctl_intena_m | +- (type << q_vector->intr_reg.dyn_ctl_itridx_s) | +- (itr << (q_vector->intr_reg.dyn_ctl_intrvl_s - 1)); ++ itr_val |= (type << q_vector->intr_reg.dyn_ctl_itridx_s) | ++ (itr << (q_vector->intr_reg.dyn_ctl_intrvl_s - 1)); + + return itr_val; + } +@@ -3701,9 +3711,8 @@ void idpf_vport_intr_update_itr_ena_irq(struct idpf_q_vector *q_vector) + /* net_dim() updates ITR out-of-band using a work item */ + idpf_net_dim(q_vector); + ++ intval = idpf_vport_intr_buildreg_itr(q_vector); + q_vector->wb_on_itr = false; +- intval = idpf_vport_intr_buildreg_itr(q_vector, +- IDPF_NO_ITR_UPDATE_IDX, 0); + + writel(intval, q_vector->intr_reg.dyn_ctl); + } +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0004-idpf-add-support-for-Tx-refillqs-in-flow-scheduling-.patch b/google/patches/idpf/0004-idpf-add-support-for-Tx-refillqs-in-flow-scheduling-.patch new file mode 100644 index 0000000..9ccd1eb --- /dev/null +++ b/google/patches/idpf/0004-idpf-add-support-for-Tx-refillqs-in-flow-scheduling-.patch
@@ -0,0 +1,284 @@ +From bee2e653acf2018405718ace8ea0576ba143de24 Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Fri, 25 Jul 2025 11:42:18 -0700 +Subject: [PATCH 04/10] idpf: add support for Tx refillqs in flow scheduling + mode + +[ Upstream commit cb83b559bea39f207ee214ee2972657e8576ed18 ] + +In certain production environments, it is possible for completion tags +to collide, meaning N packets with the same completion tag are in flight +at the same time. In this environment, any given Tx queue is effectively +used to send both slower traffic and higher throughput traffic +simultaneously. This is the result of a customer's specific +configuration in the device pipeline, the details of which Intel cannot +provide. This configuration results in a small number of out-of-order +completions, i.e., a small number of packets in flight. The existing +guardrails in the driver only protect against a large number of packets +in flight. The slower flow completions are delayed which causes the +out-of-order completions. The fast flow will continue sending traffic +and generating tags. Because tags are generated on the fly, the fast +flow eventually uses the same tag for a packet that is still in flight +from the slower flow. The driver has no idea which packet it should +clean when it processes the completion with that tag, but it will look +for the packet on the buffer ring before the hash table. If the slower +flow packet completion is processed first, it will end up cleaning the +fast flow packet on the ring prematurely. This leaves the descriptor +ring in a bad state resulting in a crash or Tx timeout. + +In summary, generating a tag when a packet is sent can lead to the same +tag being associated with multiple packets. This can lead to resource +leaks, crashes, and/or Tx timeouts. + +Before we can replace the tag generation, we need a new mechanism for +the send path to know what tag to use next. The driver will allocate and +initialize a refillq for each TxQ with all of the possible free tag +values. During send, the driver grabs the next free tag from the refillq +from next_to_clean. While cleaning the packet, the clean routine posts +the tag back to the refillq's next_to_use to indicate that it is now +free to use. + +This mechanism works exactly the same way as the existing Rx refill +queues, which post the cleaned buffer IDs back to the buffer queue to be +reposted to HW. Since we're using the refillqs for both Rx and Tx now, +genericize some of the existing refillq support. + +Note: the refillqs will not be used yet. This is only demonstrating how +they will be used to pass free tags back to the send path. + +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Tested-by: Samuel Salin <Samuel.salin@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 93 +++++++++++++++++++-- + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 8 +- + 2 files changed, 91 insertions(+), 10 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 2c034b12ac16..625974367ba4 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -138,6 +138,9 @@ static void idpf_tx_desc_rel(struct idpf_tx_queue *txq) + if (!txq->desc_ring) + return; + ++ if (txq->refillq) ++ kfree(txq->refillq->ring); ++ + dmam_free_coherent(txq->dev, txq->size, txq->desc_ring, txq->dma); + txq->desc_ring = NULL; + txq->next_to_use = 0; +@@ -243,6 +246,7 @@ static int idpf_tx_desc_alloc(const struct idpf_vport *vport, + struct idpf_tx_queue *tx_q) + { + struct device *dev = tx_q->dev; ++ struct idpf_sw_queue *refillq; + int err; + + err = idpf_tx_buf_alloc_all(tx_q); +@@ -266,6 +270,29 @@ static int idpf_tx_desc_alloc(const struct idpf_vport *vport, + tx_q->next_to_clean = 0; + idpf_queue_set(GEN_CHK, tx_q); + ++ if (!idpf_queue_has(FLOW_SCH_EN, tx_q)) ++ return 0; ++ ++ refillq = tx_q->refillq; ++ refillq->desc_count = tx_q->desc_count; ++ refillq->ring = kcalloc(refillq->desc_count, sizeof(u32), ++ GFP_KERNEL); ++ if (!refillq->ring) { ++ err = -ENOMEM; ++ goto err_alloc; ++ } ++ ++ for (unsigned int i = 0; i < refillq->desc_count; i++) ++ refillq->ring[i] = ++ FIELD_PREP(IDPF_RFL_BI_BUFID_M, i) | ++ FIELD_PREP(IDPF_RFL_BI_GEN_M, ++ idpf_queue_has(GEN_CHK, refillq)); ++ ++ /* Go ahead and flip the GEN bit since this counts as filling ++ * up the ring, i.e. we already ring wrapped. ++ */ ++ idpf_queue_change(GEN_CHK, refillq); ++ + return 0; + + err_alloc: +@@ -602,18 +629,18 @@ static int idpf_rx_hdr_buf_alloc_all(struct idpf_buf_queue *bufq) + } + + /** +- * idpf_rx_post_buf_refill - Post buffer id to refill queue ++ * idpf_post_buf_refill - Post buffer id to refill queue + * @refillq: refill queue to post to + * @buf_id: buffer id to post + */ +-static void idpf_rx_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id) ++static void idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id) + { + u32 nta = refillq->next_to_use; + + /* store the buffer ID and the SW maintained GEN bit to the refillq */ + refillq->ring[nta] = +- FIELD_PREP(IDPF_RX_BI_BUFID_M, buf_id) | +- FIELD_PREP(IDPF_RX_BI_GEN_M, ++ FIELD_PREP(IDPF_RFL_BI_BUFID_M, buf_id) | ++ FIELD_PREP(IDPF_RFL_BI_GEN_M, + idpf_queue_has(GEN_CHK, refillq)); + + if (unlikely(++nta == refillq->desc_count)) { +@@ -996,6 +1023,11 @@ static void idpf_txq_group_rel(struct idpf_vport *vport) + struct idpf_txq_group *txq_grp = &vport->txq_grps[i]; + + for (j = 0; j < txq_grp->num_txq; j++) { ++ if (flow_sch_en) { ++ kfree(txq_grp->txqs[j]->refillq); ++ txq_grp->txqs[j]->refillq = NULL; ++ } ++ + kfree(txq_grp->txqs[j]); + txq_grp->txqs[j] = NULL; + } +@@ -1407,6 +1439,13 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) + } + + idpf_queue_set(FLOW_SCH_EN, q); ++ ++ q->refillq = kzalloc(sizeof(*q->refillq), GFP_KERNEL); ++ if (!q->refillq) ++ goto err_alloc; ++ ++ idpf_queue_set(GEN_CHK, q->refillq); ++ idpf_queue_set(RFL_GEN_CHK, q->refillq); + } + + if (!split) +@@ -1955,6 +1994,8 @@ static void idpf_tx_handle_rs_completion(struct idpf_tx_queue *txq, + + compl_tag = le16_to_cpu(desc->q_head_compl_tag.compl_tag); + ++ idpf_post_buf_refill(txq->refillq, compl_tag); ++ + /* If we didn't clean anything on the ring, this packet must be + * in the hash table. Go clean it there. + */ +@@ -2314,6 +2355,37 @@ static unsigned int idpf_tx_splitq_bump_ntu(struct idpf_tx_queue *txq, u16 ntu) + return ntu; + } + ++/** ++ * idpf_tx_get_free_buf_id - get a free buffer ID from the refill queue ++ * @refillq: refill queue to get buffer ID from ++ * @buf_id: return buffer ID ++ * ++ * Return: true if a buffer ID was found, false if not ++ */ ++static bool idpf_tx_get_free_buf_id(struct idpf_sw_queue *refillq, ++ u16 *buf_id) ++{ ++ u32 ntc = refillq->next_to_clean; ++ u32 refill_desc; ++ ++ refill_desc = refillq->ring[ntc]; ++ ++ if (unlikely(idpf_queue_has(RFL_GEN_CHK, refillq) != ++ !!(refill_desc & IDPF_RFL_BI_GEN_M))) ++ return false; ++ ++ *buf_id = FIELD_GET(IDPF_RFL_BI_BUFID_M, refill_desc); ++ ++ if (unlikely(++ntc == refillq->desc_count)) { ++ idpf_queue_change(RFL_GEN_CHK, refillq); ++ ntc = 0; ++ } ++ ++ refillq->next_to_clean = ntc; ++ ++ return true; ++} ++ + /** + * idpf_tx_splitq_map - Build the Tx flex descriptor + * @tx_q: queue to send buffer on +@@ -2789,6 +2861,13 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + } + + if (idpf_queue_has(FLOW_SCH_EN, tx_q)) { ++ if (unlikely(!idpf_tx_get_free_buf_id(tx_q->refillq, ++ &tx_params.compl_tag))) { ++ u64_stats_update_begin(&tx_q->stats_sync); ++ u64_stats_inc(&tx_q->q_stats.q_busy); ++ u64_stats_update_end(&tx_q->stats_sync); ++ } ++ + tx_params.dtype = IDPF_TX_DESC_DTYPE_FLEX_FLOW_SCHE; + tx_params.eop_cmd = IDPF_TXD_FLEX_FLOW_CMD_EOP; + /* Set the RE bit to catch any packets that may have not been +@@ -3307,7 +3386,7 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget) + skip_data: + rx_buf->page = NULL; + +- idpf_rx_post_buf_refill(refillq, buf_id); ++ idpf_post_buf_refill(refillq, buf_id); + IDPF_RX_BUMP_NTC(rxq, ntc); + + /* skip if it is non EOP desc */ +@@ -3415,10 +3494,10 @@ static void idpf_rx_clean_refillq(struct idpf_buf_queue *bufq, + bool failure; + + if (idpf_queue_has(RFL_GEN_CHK, refillq) != +- !!(refill_desc & IDPF_RX_BI_GEN_M)) ++ !!(refill_desc & IDPF_RFL_BI_GEN_M)) + break; + +- buf_id = FIELD_GET(IDPF_RX_BI_BUFID_M, refill_desc); ++ buf_id = FIELD_GET(IDPF_RFL_BI_BUFID_M, refill_desc); + failure = idpf_rx_update_bufq_desc(bufq, buf_id, buf_desc); + if (failure) + break; +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +index 12832b5b36f5..d72839258235 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +@@ -108,8 +108,8 @@ do { \ + */ + #define IDPF_TX_SPLITQ_RE_MIN_GAP 64 + +-#define IDPF_RX_BI_GEN_M BIT(16) +-#define IDPF_RX_BI_BUFID_M GENMASK(15, 0) ++#define IDPF_RFL_BI_GEN_M BIT(16) ++#define IDPF_RFL_BI_BUFID_M GENMASK(15, 0) + + #define IDPF_RXD_EOF_SPLITQ VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_M + #define IDPF_RXD_EOF_SINGLEQ VIRTCHNL2_RX_BASE_DESC_STATUS_EOF_M +@@ -636,6 +636,7 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64, + * @cleaned_pkts: Number of packets cleaned for the above said case + * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather + * @stash: Tx buffer stash for Flow-based scheduling mode ++ * @refillq: Pointer to refill queue + * @compl_tag_bufid_m: Completion tag buffer id mask + * @compl_tag_cur_gen: Used to keep track of current completion tag generation + * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset +@@ -683,6 +684,7 @@ struct idpf_tx_queue { + + u16 tx_max_bufs; + struct idpf_txq_stash *stash; ++ struct idpf_sw_queue *refillq; + + u16 compl_tag_bufid_m; + u16 compl_tag_cur_gen; +@@ -701,7 +703,7 @@ struct idpf_tx_queue { + __cacheline_group_end_aligned(cold); + }; + libeth_cacheline_set_assert(struct idpf_tx_queue, 64, +- 88 + sizeof(struct u64_stats_sync), ++ 96 + sizeof(struct u64_stats_sync), + 24); + + /** +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0005-idpf-improve-when-to-set-RE-bit-logic.patch b/google/patches/idpf/0005-idpf-improve-when-to-set-RE-bit-logic.patch new file mode 100644 index 0000000..94bc1a6 --- /dev/null +++ b/google/patches/idpf/0005-idpf-improve-when-to-set-RE-bit-logic.patch
@@ -0,0 +1,118 @@ +From 8dc0dd5f1e0fdc646ecefc53e941e0f384014305 Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Fri, 25 Jul 2025 11:42:19 -0700 +Subject: [PATCH 05/10] idpf: improve when to set RE bit logic + +[ Upstream commit f2d18e16479cac7a708d77cbfb4220a9114a71fc ] + +Track the gap between next_to_use and the last RE index. Set RE again +if the gap is large enough to ensure RE bit is set frequently. This is +critical before removing the stashing mechanisms because the +opportunistic descriptor ring cleaning from the out-of-order completions +will go away. Previously the descriptors would be "cleaned" by both the +descriptor (RE) completion and the out-of-order completions. Without the +latter, we must ensure the RE bit is set more frequently. Otherwise, +it's theoretically possible for the descriptor ring next_to_clean to +never advance. The previous implementation was dependent on the start +of a packet falling on a 64th index in the descriptor ring, which is not +guaranteed with large packets. + +Signed-off-by: Luigi Rizzo <lrizzo@google.com> +Signed-off-by: Brian Vazquez <brianvv@google.com> +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Tested-by: Samuel Salin <Samuel.salin@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 20 +++++++++++++++++++- + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 6 ++++-- + 2 files changed, 23 insertions(+), 3 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 625974367ba4..33aa8b6eb78f 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -293,6 +293,8 @@ static int idpf_tx_desc_alloc(const struct idpf_vport *vport, + */ + idpf_queue_change(GEN_CHK, refillq); + ++ tx_q->last_re = tx_q->desc_count - IDPF_TX_SPLITQ_RE_MIN_GAP; ++ + return 0; + + err_alloc: +@@ -2795,6 +2797,21 @@ netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb) + return NETDEV_TX_OK; + } + ++/** ++ * idpf_tx_splitq_need_re - check whether RE bit needs to be set ++ * @tx_q: pointer to Tx queue ++ * ++ * Return: true if RE bit needs to be set, false otherwise ++ */ ++static bool idpf_tx_splitq_need_re(struct idpf_tx_queue *tx_q) ++{ ++ int gap = tx_q->next_to_use - tx_q->last_re; ++ ++ gap += (gap < 0) ? tx_q->desc_count : 0; ++ ++ return gap >= IDPF_TX_SPLITQ_RE_MIN_GAP; ++} ++ + /** + * idpf_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors + * @skb: send buffer +@@ -2875,9 +2892,10 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + * MIN_RING size to ensure it will be set at least once each + * time around the ring. + */ +- if (!(tx_q->next_to_use % IDPF_TX_SPLITQ_RE_MIN_GAP)) { ++ if (idpf_tx_splitq_need_re(tx_q)) { + tx_params.eop_cmd |= IDPF_TXD_FLEX_FLOW_CMD_RE; + tx_q->txq_grp->num_completions_pending++; ++ tx_q->last_re = tx_q->next_to_use; + } + + if (skb->ip_summed == CHECKSUM_PARTIAL) +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +index d72839258235..0e082ba9d54b 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +@@ -624,6 +624,8 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64, + * @netdev: &net_device corresponding to this queue + * @next_to_use: Next descriptor to use + * @next_to_clean: Next descriptor to clean ++ * @last_re: last descriptor index that RE bit was set ++ * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather + * @cleaned_bytes: Splitq only, TXQ only: When a TX completion is received on + * the TX completion queue, it can be for any TXQ associated + * with that completion queue. This means we can clean up to +@@ -634,7 +636,6 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64, + * only once at the end of the cleaning routine. + * @clean_budget: singleq only, queue cleaning budget + * @cleaned_pkts: Number of packets cleaned for the above said case +- * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather + * @stash: Tx buffer stash for Flow-based scheduling mode + * @refillq: Pointer to refill queue + * @compl_tag_bufid_m: Completion tag buffer id mask +@@ -675,6 +676,8 @@ struct idpf_tx_queue { + __cacheline_group_begin_aligned(read_write); + u16 next_to_use; + u16 next_to_clean; ++ u16 last_re; ++ u16 tx_max_bufs; + + union { + u32 cleaned_bytes; +@@ -682,7 +685,6 @@ struct idpf_tx_queue { + }; + u16 cleaned_pkts; + +- u16 tx_max_bufs; + struct idpf_txq_stash *stash; + struct idpf_sw_queue *refillq; + +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0006-idpf-simplify-and-fix-splitq-Tx-packet-rollback-erro.patch b/google/patches/idpf/0006-idpf-simplify-and-fix-splitq-Tx-packet-rollback-erro.patch new file mode 100644 index 0000000..0beee24 --- /dev/null +++ b/google/patches/idpf/0006-idpf-simplify-and-fix-splitq-Tx-packet-rollback-erro.patch
@@ -0,0 +1,266 @@ +From 8c134fc40e2059c7ad46d41b8b433292614d8b49 Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Fri, 25 Jul 2025 11:42:20 -0700 +Subject: [PATCH 06/10] idpf: simplify and fix splitq Tx packet rollback error + path + +[ Upstream commit b61dfa9bc4430ad82b96d3a7c1c485350f91b467 ] + +Move (and rename) the existing rollback logic to singleq.c since that +will be the only consumer. Create a simplified splitq specific rollback +function to loop through and unmap tx_bufs based on the completion tag. +This is critical before replacing the Tx buffer ring with the buffer +pool since the previous rollback indexing will not work to unmap the +chained buffers from the pool. + +Cache the next_to_use index before any portion of the packet is put on +the descriptor ring. In case of an error, the rollback will bump tail to +the correct next_to_use value. Because the splitq path now supports +different types of context descriptors (and potentially multiple in the +future), this will take care of rolling back any and all context +descriptors encoded on the ring for the erroneous packet. The previous +rollback logic was broken for PTP packets since it would not account for +the PTP context descriptor. + +Fixes: 1a49cf814fe1 ("idpf: add Tx timestamp flows") +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Tested-by: Samuel Salin <Samuel.salin@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + .../ethernet/intel/idpf/idpf_singleq_txrx.c | 57 +++++++++++- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 91 ++++++++----------- + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 5 +- + 3 files changed, 95 insertions(+), 58 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +index a986dd572555..ebe1acfc20b8 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +@@ -179,6 +179,58 @@ static int idpf_tx_singleq_csum(struct sk_buff *skb, + return 1; + } + ++/** ++ * idpf_tx_singleq_dma_map_error - handle TX DMA map errors ++ * @txq: queue to send buffer on ++ * @skb: send buffer ++ * @first: original first buffer info buffer for packet ++ * @idx: starting point on ring to unwind ++ */ ++static void idpf_tx_singleq_dma_map_error(struct idpf_tx_queue *txq, ++ struct sk_buff *skb, ++ struct idpf_tx_buf *first, u16 idx) ++{ ++ struct libeth_sq_napi_stats ss = { }; ++ struct libeth_cq_pp cp = { ++ .dev = txq->dev, ++ .ss = &ss, ++ }; ++ ++ u64_stats_update_begin(&txq->stats_sync); ++ u64_stats_inc(&txq->q_stats.dma_map_errs); ++ u64_stats_update_end(&txq->stats_sync); ++ ++ /* clear dma mappings for failed tx_buf map */ ++ for (;;) { ++ struct idpf_tx_buf *tx_buf; ++ ++ tx_buf = &txq->tx_buf[idx]; ++ libeth_tx_complete(tx_buf, &cp); ++ if (tx_buf == first) ++ break; ++ if (idx == 0) ++ idx = txq->desc_count; ++ idx--; ++ } ++ ++ if (skb_is_gso(skb)) { ++ union idpf_tx_flex_desc *tx_desc; ++ ++ /* If we failed a DMA mapping for a TSO packet, we will have ++ * used one additional descriptor for a context ++ * descriptor. Reset that here. ++ */ ++ tx_desc = &txq->flex_tx[idx]; ++ memset(tx_desc, 0, sizeof(*tx_desc)); ++ if (idx == 0) ++ idx = txq->desc_count; ++ idx--; ++ } ++ ++ /* Update tail in case netdev_xmit_more was previously true */ ++ idpf_tx_buf_hw_update(txq, idx, false); ++} ++ + /** + * idpf_tx_singleq_map - Build the Tx base descriptor + * @tx_q: queue to send buffer on +@@ -219,8 +271,9 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q, + for (frag = &skb_shinfo(skb)->frags[0];; frag++) { + unsigned int max_data = IDPF_TX_MAX_DESC_DATA_ALIGNED; + +- if (dma_mapping_error(tx_q->dev, dma)) +- return idpf_tx_dma_map_error(tx_q, skb, first, i); ++ if (unlikely(dma_mapping_error(tx_q->dev, dma))) ++ return idpf_tx_singleq_dma_map_error(tx_q, skb, ++ first, i); + + /* record length, and DMA address */ + dma_unmap_len_set(tx_buf, len, size); +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 33aa8b6eb78f..1b80016d7a12 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -2289,57 +2289,6 @@ unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, + return count; + } + +-/** +- * idpf_tx_dma_map_error - handle TX DMA map errors +- * @txq: queue to send buffer on +- * @skb: send buffer +- * @first: original first buffer info buffer for packet +- * @idx: starting point on ring to unwind +- */ +-void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb, +- struct idpf_tx_buf *first, u16 idx) +-{ +- struct libeth_sq_napi_stats ss = { }; +- struct libeth_cq_pp cp = { +- .dev = txq->dev, +- .ss = &ss, +- }; +- +- u64_stats_update_begin(&txq->stats_sync); +- u64_stats_inc(&txq->q_stats.dma_map_errs); +- u64_stats_update_end(&txq->stats_sync); +- +- /* clear dma mappings for failed tx_buf map */ +- for (;;) { +- struct idpf_tx_buf *tx_buf; +- +- tx_buf = &txq->tx_buf[idx]; +- libeth_tx_complete(tx_buf, &cp); +- if (tx_buf == first) +- break; +- if (idx == 0) +- idx = txq->desc_count; +- idx--; +- } +- +- if (skb_is_gso(skb)) { +- union idpf_tx_flex_desc *tx_desc; +- +- /* If we failed a DMA mapping for a TSO packet, we will have +- * used one additional descriptor for a context +- * descriptor. Reset that here. +- */ +- tx_desc = &txq->flex_tx[idx]; +- memset(tx_desc, 0, sizeof(struct idpf_flex_tx_ctx_desc)); +- if (idx == 0) +- idx = txq->desc_count; +- idx--; +- } +- +- /* Update tail in case netdev_xmit_more was previously true */ +- idpf_tx_buf_hw_update(txq, idx, false); +-} +- + /** + * idpf_tx_splitq_bump_ntu - adjust NTU and generation + * @txq: the tx ring to wrap +@@ -2388,6 +2337,37 @@ static bool idpf_tx_get_free_buf_id(struct idpf_sw_queue *refillq, + return true; + } + ++/** ++ * idpf_tx_splitq_pkt_err_unmap - Unmap buffers and bump tail in case of error ++ * @txq: Tx queue to unwind ++ * @params: pointer to splitq params struct ++ * @first: starting buffer for packet to unmap ++ */ ++static void idpf_tx_splitq_pkt_err_unmap(struct idpf_tx_queue *txq, ++ struct idpf_tx_splitq_params *params, ++ struct idpf_tx_buf *first) ++{ ++ struct libeth_sq_napi_stats ss = { }; ++ struct idpf_tx_buf *tx_buf = first; ++ struct libeth_cq_pp cp = { ++ .dev = txq->dev, ++ .ss = &ss, ++ }; ++ u32 idx = 0; ++ ++ u64_stats_update_begin(&txq->stats_sync); ++ u64_stats_inc(&txq->q_stats.dma_map_errs); ++ u64_stats_update_end(&txq->stats_sync); ++ ++ do { ++ libeth_tx_complete(tx_buf, &cp); ++ idpf_tx_clean_buf_ring_bump_ntc(txq, idx, tx_buf); ++ } while (idpf_tx_buf_compl_tag(tx_buf) == params->compl_tag); ++ ++ /* Update tail in case netdev_xmit_more was previously true. */ ++ idpf_tx_buf_hw_update(txq, params->prev_ntu, false); ++} ++ + /** + * idpf_tx_splitq_map - Build the Tx flex descriptor + * @tx_q: queue to send buffer on +@@ -2432,8 +2412,9 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + for (frag = &skb_shinfo(skb)->frags[0];; frag++) { + unsigned int max_data = IDPF_TX_MAX_DESC_DATA_ALIGNED; + +- if (dma_mapping_error(tx_q->dev, dma)) +- return idpf_tx_dma_map_error(tx_q, skb, first, i); ++ if (unlikely(dma_mapping_error(tx_q->dev, dma))) ++ return idpf_tx_splitq_pkt_err_unmap(tx_q, params, ++ first); + + first->nr_frags++; + idpf_tx_buf_compl_tag(tx_buf) = params->compl_tag; +@@ -2822,7 +2803,9 @@ static bool idpf_tx_splitq_need_re(struct idpf_tx_queue *tx_q) + static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + struct idpf_tx_queue *tx_q) + { +- struct idpf_tx_splitq_params tx_params = { }; ++ struct idpf_tx_splitq_params tx_params = { ++ .prev_ntu = tx_q->next_to_use, ++ }; + struct idpf_tx_buf *first; + unsigned int count; + int tso; +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +index 0e082ba9d54b..8110a1ce4b42 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +@@ -195,6 +195,7 @@ struct idpf_tx_offload_params { + * @compl_tag: Associated tag for completion + * @td_tag: Descriptor tunneling tag + * @offload: Offload parameters ++ * @prev_ntu: stored TxQ next_to_use in case of rollback + */ + struct idpf_tx_splitq_params { + enum idpf_tx_desc_dtype_value dtype; +@@ -205,6 +206,8 @@ struct idpf_tx_splitq_params { + }; + + struct idpf_tx_offload_params offload; ++ ++ u16 prev_ntu; + }; + + enum idpf_tx_ctx_desc_eipt_offload { +@@ -1051,8 +1054,6 @@ void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val, + bool xmit_more); + unsigned int idpf_size_to_txd_count(unsigned int size); + netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb); +-void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb, +- struct idpf_tx_buf *first, u16 ring_idx); + unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, + struct sk_buff *skb); + void idpf_tx_timeout(struct net_device *netdev, unsigned int txqueue); +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0007-idpf-replace-flow-scheduling-buffer-ring-with-buffer.patch b/google/patches/idpf/0007-idpf-replace-flow-scheduling-buffer-ring-with-buffer.patch new file mode 100644 index 0000000..fc01819 --- /dev/null +++ b/google/patches/idpf/0007-idpf-replace-flow-scheduling-buffer-ring-with-buffer.patch
@@ -0,0 +1,529 @@ +From 9d6ba1497dcf1002516c11b307d4ce8927df216b Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Fri, 25 Jul 2025 11:42:21 -0700 +Subject: [PATCH 07/10] idpf: replace flow scheduling buffer ring with buffer + pool + +[ Upstream commit 5f417d551324d2894168b362f2429d120ab06243 ] + +Replace the TxQ buffer ring with one large pool/array of buffers (only +for flow scheduling). This eliminates the tag generation and makes it +impossible for a tag to be associated with more than one packet. + +The completion tag passed to HW through the descriptor is the index into +the array. That same completion tag is posted back to the driver in the +completion descriptor, and used to index into the array to quickly +retrieve the buffer during cleaning. In this way, the tags are treated +as a fix sized resource. If all tags are in use, no more packets can be +sent on that particular queue (until some are freed up). The tag pool +size is 64K since the completion tag width is 16 bits. + +For each packet, the driver pulls a free tag from the refillq to get the +next free buffer index. When cleaning is complete, the tag is posted +back to the refillq. A multi-frag packet spans multiple buffers in the +driver, therefore it uses multiple buffer indexes/tags from the pool. +Each frag pulls from the refillq to get the next free buffer index. +These are tracked in a next_buf field that replaces the completion tag +field in the buffer struct. This chains the buffers together so that the +packet can be cleaned from the starting completion tag taken from the +completion descriptor, then from the next_buf field for each subsequent +buffer. + +In case of a dma_mapping_error occurs or the refillq runs out of free +buf_ids, the packet will execute the rollback error path. This unmaps +any buffers previously mapped for the packet. Since several free +buf_ids could have already been pulled from the refillq, we need to +restore its original state as well. Otherwise, the buf_ids/tags +will be leaked and not used again until the queue is reallocated. + +Descriptor completions only advance the descriptor ring index to "clean" +the descriptors. The packet completions only clean the buffers +associated with the given packet completion tag and do not update the +descriptor ring index. + +When operating in queue based scheduling mode, the array still acts as a +ring and will only have TxQ descriptor count entries. The tx_bufs are +still associated 1:1 with the descriptor ring entries and we can use the +conventional indexing mechanisms. + +Fixes: c2d548cad150 ("idpf: add TX splitq napi poll support") +Signed-off-by: Luigi Rizzo <lrizzo@google.com> +Signed-off-by: Brian Vazquez <brianvv@google.com> +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> +Tested-by: Samuel Salin <Samuel.salin@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 207 +++++++++----------- + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 10 +- + 2 files changed, 105 insertions(+), 112 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 1b80016d7a12..54e054b3d329 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -12,6 +12,7 @@ struct idpf_tx_stash { + struct libeth_sqe buf; + }; + ++#define idpf_tx_buf_next(buf) (*(u32 *)&(buf)->priv) + #define idpf_tx_buf_compl_tag(buf) (*(u32 *)&(buf)->priv) + LIBETH_SQE_CHECK_PRIV(u32); + +@@ -90,7 +91,7 @@ static void idpf_tx_buf_rel_all(struct idpf_tx_queue *txq) + return; + + /* Free all the Tx buffer sk_buffs */ +- for (i = 0; i < txq->desc_count; i++) ++ for (i = 0; i < txq->buf_pool_size; i++) + libeth_tx_complete(&txq->tx_buf[i], &cp); + + kfree(txq->tx_buf); +@@ -198,14 +199,17 @@ static void idpf_tx_desc_rel_all(struct idpf_vport *vport) + static int idpf_tx_buf_alloc_all(struct idpf_tx_queue *tx_q) + { + struct idpf_buf_lifo *buf_stack; +- int buf_size; + int i; + + /* Allocate book keeping buffers only. Buffers to be supplied to HW + * are allocated by kernel network stack and received as part of skb + */ +- buf_size = sizeof(struct idpf_tx_buf) * tx_q->desc_count; +- tx_q->tx_buf = kzalloc(buf_size, GFP_KERNEL); ++ if (idpf_queue_has(FLOW_SCH_EN, tx_q)) ++ tx_q->buf_pool_size = U16_MAX; ++ else ++ tx_q->buf_pool_size = tx_q->desc_count; ++ tx_q->tx_buf = kcalloc(tx_q->buf_pool_size, sizeof(*tx_q->tx_buf), ++ GFP_KERNEL); + if (!tx_q->tx_buf) + return -ENOMEM; + +@@ -274,7 +278,7 @@ static int idpf_tx_desc_alloc(const struct idpf_vport *vport, + return 0; + + refillq = tx_q->refillq; +- refillq->desc_count = tx_q->desc_count; ++ refillq->desc_count = tx_q->buf_pool_size; + refillq->ring = kcalloc(refillq->desc_count, sizeof(u32), + GFP_KERNEL); + if (!refillq->ring) { +@@ -1823,6 +1827,12 @@ static bool idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end, + struct idpf_tx_buf *tx_buf; + bool clean_complete = true; + ++ if (descs_only) { ++ /* Bump ring index to mark as cleaned. */ ++ tx_q->next_to_clean = end; ++ return true; ++ } ++ + tx_desc = &tx_q->flex_tx[ntc]; + next_pending_desc = &tx_q->flex_tx[end]; + tx_buf = &tx_q->tx_buf[ntc]; +@@ -1889,83 +1899,40 @@ do { \ + } while (0) + + /** +- * idpf_tx_clean_buf_ring - clean flow scheduling TX queue buffers ++ * idpf_tx_clean_bufs - clean flow scheduling TX queue buffers + * @txq: queue to clean +- * @compl_tag: completion tag of packet to clean (from completion descriptor) ++ * @buf_id: packet's starting buffer ID, from completion descriptor + * @cleaned: pointer to stats struct to track cleaned packets/bytes + * @budget: Used to determine if we are in netpoll + * +- * Cleans all buffers associated with the input completion tag either from the +- * TX buffer ring or from the hash table if the buffers were previously +- * stashed. Returns the byte/segment count for the cleaned packet associated +- * this completion tag. ++ * Clean all buffers associated with the packet starting at buf_id. Returns the ++ * byte/segment count for the cleaned packet. + */ +-static bool idpf_tx_clean_buf_ring(struct idpf_tx_queue *txq, u16 compl_tag, +- struct libeth_sq_napi_stats *cleaned, +- int budget) ++static bool idpf_tx_clean_bufs(struct idpf_tx_queue *txq, u32 buf_id, ++ struct libeth_sq_napi_stats *cleaned, ++ int budget) + { +- u16 idx = compl_tag & txq->compl_tag_bufid_m; + struct idpf_tx_buf *tx_buf = NULL; + struct libeth_cq_pp cp = { + .dev = txq->dev, + .ss = cleaned, + .napi = budget, + }; +- u16 ntc, orig_idx = idx; +- +- tx_buf = &txq->tx_buf[idx]; +- +- if (unlikely(tx_buf->type <= LIBETH_SQE_CTX || +- idpf_tx_buf_compl_tag(tx_buf) != compl_tag)) +- return false; + +- if (tx_buf->type == LIBETH_SQE_SKB) ++ tx_buf = &txq->tx_buf[buf_id]; ++ if (tx_buf->type == LIBETH_SQE_SKB) { + libeth_tx_complete(tx_buf, &cp); ++ idpf_post_buf_refill(txq->refillq, buf_id); ++ } + +- idpf_tx_clean_buf_ring_bump_ntc(txq, idx, tx_buf); ++ while (idpf_tx_buf_next(tx_buf) != IDPF_TXBUF_NULL) { ++ buf_id = idpf_tx_buf_next(tx_buf); + +- while (idpf_tx_buf_compl_tag(tx_buf) == compl_tag) { ++ tx_buf = &txq->tx_buf[buf_id]; + libeth_tx_complete(tx_buf, &cp); +- idpf_tx_clean_buf_ring_bump_ntc(txq, idx, tx_buf); ++ idpf_post_buf_refill(txq->refillq, buf_id); + } + +- /* +- * It's possible the packet we just cleaned was an out of order +- * completion, which means we can stash the buffers starting from +- * the original next_to_clean and reuse the descriptors. We need +- * to compare the descriptor ring next_to_clean packet's "first" buffer +- * to the "first" buffer of the packet we just cleaned to determine if +- * this is the case. Howevever, next_to_clean can point to either a +- * reserved buffer that corresponds to a context descriptor used for the +- * next_to_clean packet (TSO packet) or the "first" buffer (single +- * packet). The orig_idx from the packet we just cleaned will always +- * point to the "first" buffer. If next_to_clean points to a reserved +- * buffer, let's bump ntc once and start the comparison from there. +- */ +- ntc = txq->next_to_clean; +- tx_buf = &txq->tx_buf[ntc]; +- +- if (tx_buf->type == LIBETH_SQE_CTX) +- idpf_tx_clean_buf_ring_bump_ntc(txq, ntc, tx_buf); +- +- /* +- * If ntc still points to a different "first" buffer, clean the +- * descriptor ring and stash all of the buffers for later cleaning. If +- * we cannot stash all of the buffers, next_to_clean will point to the +- * "first" buffer of the packet that could not be stashed and cleaning +- * will start there next time. +- */ +- if (unlikely(tx_buf != &txq->tx_buf[orig_idx] && +- !idpf_tx_splitq_clean(txq, orig_idx, budget, cleaned, +- true))) +- return true; +- +- /* +- * Otherwise, update next_to_clean to reflect the cleaning that was +- * done above. +- */ +- txq->next_to_clean = idx; +- + return true; + } + +@@ -1996,12 +1963,10 @@ static void idpf_tx_handle_rs_completion(struct idpf_tx_queue *txq, + + compl_tag = le16_to_cpu(desc->q_head_compl_tag.compl_tag); + +- idpf_post_buf_refill(txq->refillq, compl_tag); +- + /* If we didn't clean anything on the ring, this packet must be + * in the hash table. Go clean it there. + */ +- if (!idpf_tx_clean_buf_ring(txq, compl_tag, cleaned, budget)) ++ if (!idpf_tx_clean_bufs(txq, compl_tag, cleaned, budget)) + idpf_tx_clean_stashed_bufs(txq, compl_tag, cleaned, budget); + } + +@@ -2314,7 +2279,7 @@ static unsigned int idpf_tx_splitq_bump_ntu(struct idpf_tx_queue *txq, u16 ntu) + * Return: true if a buffer ID was found, false if not + */ + static bool idpf_tx_get_free_buf_id(struct idpf_sw_queue *refillq, +- u16 *buf_id) ++ u32 *buf_id) + { + u32 ntc = refillq->next_to_clean; + u32 refill_desc; +@@ -2347,25 +2312,34 @@ static void idpf_tx_splitq_pkt_err_unmap(struct idpf_tx_queue *txq, + struct idpf_tx_splitq_params *params, + struct idpf_tx_buf *first) + { ++ struct idpf_sw_queue *refillq = txq->refillq; + struct libeth_sq_napi_stats ss = { }; + struct idpf_tx_buf *tx_buf = first; + struct libeth_cq_pp cp = { + .dev = txq->dev, + .ss = &ss, + }; +- u32 idx = 0; + + u64_stats_update_begin(&txq->stats_sync); + u64_stats_inc(&txq->q_stats.dma_map_errs); + u64_stats_update_end(&txq->stats_sync); + +- do { ++ libeth_tx_complete(tx_buf, &cp); ++ while (idpf_tx_buf_next(tx_buf) != IDPF_TXBUF_NULL) { ++ tx_buf = &txq->tx_buf[idpf_tx_buf_next(tx_buf)]; + libeth_tx_complete(tx_buf, &cp); +- idpf_tx_clean_buf_ring_bump_ntc(txq, idx, tx_buf); +- } while (idpf_tx_buf_compl_tag(tx_buf) == params->compl_tag); ++ } + + /* Update tail in case netdev_xmit_more was previously true. */ + idpf_tx_buf_hw_update(txq, params->prev_ntu, false); ++ ++ if (!refillq) ++ return; ++ ++ /* Restore refillq state to avoid leaking tags. */ ++ if (params->prev_refill_gen != idpf_queue_has(RFL_GEN_CHK, refillq)) ++ idpf_queue_change(RFL_GEN_CHK, refillq); ++ refillq->next_to_clean = params->prev_refill_ntc; + } + + /** +@@ -2389,6 +2363,7 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + struct netdev_queue *nq; + struct sk_buff *skb; + skb_frag_t *frag; ++ u32 next_buf_id; + u16 td_cmd = 0; + dma_addr_t dma; + +@@ -2406,18 +2381,16 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + tx_buf = first; + first->nr_frags = 0; + +- params->compl_tag = +- (tx_q->compl_tag_cur_gen << tx_q->compl_tag_gen_s) | i; +- + for (frag = &skb_shinfo(skb)->frags[0];; frag++) { + unsigned int max_data = IDPF_TX_MAX_DESC_DATA_ALIGNED; + +- if (unlikely(dma_mapping_error(tx_q->dev, dma))) ++ if (unlikely(dma_mapping_error(tx_q->dev, dma))) { ++ idpf_tx_buf_next(tx_buf) = IDPF_TXBUF_NULL; + return idpf_tx_splitq_pkt_err_unmap(tx_q, params, + first); ++ } + + first->nr_frags++; +- idpf_tx_buf_compl_tag(tx_buf) = params->compl_tag; + tx_buf->type = LIBETH_SQE_FRAG; + + /* record length, and DMA address */ +@@ -2473,29 +2446,14 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + max_data); + + if (unlikely(++i == tx_q->desc_count)) { +- tx_buf = tx_q->tx_buf; + tx_desc = &tx_q->flex_tx[0]; + i = 0; + tx_q->compl_tag_cur_gen = + IDPF_TX_ADJ_COMPL_TAG_GEN(tx_q); + } else { +- tx_buf++; + tx_desc++; + } + +- /* Since this packet has a buffer that is going to span +- * multiple descriptors, it's going to leave holes in +- * to the TX buffer ring. To ensure these holes do not +- * cause issues in the cleaning routines, we will clear +- * them of any stale data and assign them the same +- * completion tag as the current packet. Then when the +- * packet is being cleaned, the cleaning routines will +- * simply pass over these holes and finish cleaning the +- * rest of the packet. +- */ +- tx_buf->type = LIBETH_SQE_EMPTY; +- idpf_tx_buf_compl_tag(tx_buf) = params->compl_tag; +- + /* Adjust the DMA offset and the remaining size of the + * fragment. On the first iteration of this loop, + * max_data will be >= 12K and <= 16K-1. On any +@@ -2520,15 +2478,26 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + idpf_tx_splitq_build_desc(tx_desc, params, td_cmd, size); + + if (unlikely(++i == tx_q->desc_count)) { +- tx_buf = tx_q->tx_buf; + tx_desc = &tx_q->flex_tx[0]; + i = 0; + tx_q->compl_tag_cur_gen = IDPF_TX_ADJ_COMPL_TAG_GEN(tx_q); + } else { +- tx_buf++; + tx_desc++; + } + ++ if (idpf_queue_has(FLOW_SCH_EN, tx_q)) { ++ if (unlikely(!idpf_tx_get_free_buf_id(tx_q->refillq, ++ &next_buf_id))) { ++ idpf_tx_buf_next(tx_buf) = IDPF_TXBUF_NULL; ++ return idpf_tx_splitq_pkt_err_unmap(tx_q, params, ++ first); ++ } ++ } else { ++ next_buf_id = i; ++ } ++ idpf_tx_buf_next(tx_buf) = next_buf_id; ++ tx_buf = &tx_q->tx_buf[next_buf_id]; ++ + size = skb_frag_size(frag); + data_len -= size; + +@@ -2543,6 +2512,7 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + + /* write last descriptor with RS and EOP bits */ + first->rs_idx = i; ++ idpf_tx_buf_next(tx_buf) = IDPF_TXBUF_NULL; + td_cmd |= params->eop_cmd; + idpf_tx_splitq_build_desc(tx_desc, params, td_cmd, size); + i = idpf_tx_splitq_bump_ntu(tx_q, i); +@@ -2751,8 +2721,6 @@ idpf_tx_splitq_get_ctx_desc(struct idpf_tx_queue *txq) + struct idpf_flex_tx_ctx_desc *desc; + int i = txq->next_to_use; + +- txq->tx_buf[i].type = LIBETH_SQE_CTX; +- + /* grab the next descriptor */ + desc = &txq->flex_ctx[i]; + txq->next_to_use = idpf_tx_splitq_bump_ntu(txq, i); +@@ -2808,6 +2776,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + }; + struct idpf_tx_buf *first; + unsigned int count; ++ u32 buf_id; + int tso; + + count = idpf_tx_desc_count_required(tx_q, skb); +@@ -2847,26 +2816,28 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + u64_stats_update_end(&tx_q->stats_sync); + } + +- /* record the location of the first descriptor for this packet */ +- first = &tx_q->tx_buf[tx_q->next_to_use]; +- first->skb = skb; ++ if (idpf_queue_has(FLOW_SCH_EN, tx_q)) { ++ struct idpf_sw_queue *refillq = tx_q->refillq; + +- if (tso) { +- first->packets = tx_params.offload.tso_segs; +- first->bytes = skb->len + +- ((first->packets - 1) * tx_params.offload.tso_hdr_len); +- } else { +- first->packets = 1; +- first->bytes = max_t(unsigned int, skb->len, ETH_ZLEN); +- } ++ /* Save refillq state in case of a packet rollback. Otherwise, ++ * the tags will be leaked since they will be popped from the ++ * refillq but never reposted during cleaning. ++ */ ++ tx_params.prev_refill_gen = ++ idpf_queue_has(RFL_GEN_CHK, refillq); ++ tx_params.prev_refill_ntc = refillq->next_to_clean; + +- if (idpf_queue_has(FLOW_SCH_EN, tx_q)) { + if (unlikely(!idpf_tx_get_free_buf_id(tx_q->refillq, +- &tx_params.compl_tag))) { +- u64_stats_update_begin(&tx_q->stats_sync); +- u64_stats_inc(&tx_q->q_stats.q_busy); +- u64_stats_update_end(&tx_q->stats_sync); ++ &buf_id))) { ++ if (tx_params.prev_refill_gen != ++ idpf_queue_has(RFL_GEN_CHK, refillq)) ++ idpf_queue_change(RFL_GEN_CHK, refillq); ++ refillq->next_to_clean = tx_params.prev_refill_ntc; ++ ++ tx_q->next_to_use = tx_params.prev_ntu; ++ return idpf_tx_drop_skb(tx_q, skb); + } ++ tx_params.compl_tag = buf_id; + + tx_params.dtype = IDPF_TX_DESC_DTYPE_FLEX_FLOW_SCHE; + tx_params.eop_cmd = IDPF_TXD_FLEX_FLOW_CMD_EOP; +@@ -2885,6 +2856,8 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + tx_params.offload.td_cmd |= IDPF_TXD_FLEX_FLOW_CMD_CS_EN; + + } else { ++ buf_id = tx_q->next_to_use; ++ + tx_params.dtype = IDPF_TX_DESC_DTYPE_FLEX_L2TAG1_L2TAG2; + tx_params.eop_cmd = IDPF_TXD_LAST_DESC_CMD; + +@@ -2892,6 +2865,18 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + tx_params.offload.td_cmd |= IDPF_TX_FLEX_DESC_CMD_CS_EN; + } + ++ first = &tx_q->tx_buf[buf_id]; ++ first->skb = skb; ++ ++ if (tso) { ++ first->packets = tx_params.offload.tso_segs; ++ first->bytes = skb->len + ++ ((first->packets - 1) * tx_params.offload.tso_hdr_len); ++ } else { ++ first->packets = 1; ++ first->bytes = max_t(unsigned int, skb->len, ETH_ZLEN); ++ } ++ + idpf_tx_splitq_map(tx_q, &tx_params, first); + + return NETDEV_TX_OK; +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +index 8110a1ce4b42..4e30288ae3aa 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +@@ -137,6 +137,8 @@ do { \ + ((++(txq)->compl_tag_cur_gen) >= (txq)->compl_tag_gen_max ? \ + 0 : (txq)->compl_tag_cur_gen) + ++#define IDPF_TXBUF_NULL U32_MAX ++ + #define IDPF_TXD_LAST_DESC_CMD (IDPF_TX_DESC_CMD_EOP | IDPF_TX_DESC_CMD_RS) + + #define IDPF_TX_FLAGS_TSO BIT(0) +@@ -196,6 +198,8 @@ struct idpf_tx_offload_params { + * @td_tag: Descriptor tunneling tag + * @offload: Offload parameters + * @prev_ntu: stored TxQ next_to_use in case of rollback ++ * @prev_refill_ntc: stored refillq next_to_clean in case of packet rollback ++ * @prev_refill_gen: stored refillq generation bit in case of packet rollback + */ + struct idpf_tx_splitq_params { + enum idpf_tx_desc_dtype_value dtype; +@@ -208,6 +212,8 @@ struct idpf_tx_splitq_params { + struct idpf_tx_offload_params offload; + + u16 prev_ntu; ++ u16 prev_refill_ntc; ++ bool prev_refill_gen; + }; + + enum idpf_tx_ctx_desc_eipt_offload { +@@ -650,6 +656,7 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64, + * @size: Length of descriptor ring in bytes + * @dma: Physical address of ring + * @q_vector: Backreference to associated vector ++ * @buf_pool_size: Total number of idpf_tx_buf + */ + struct idpf_tx_queue { + __cacheline_group_begin_aligned(read_mostly); +@@ -705,11 +712,12 @@ struct idpf_tx_queue { + dma_addr_t dma; + + struct idpf_q_vector *q_vector; ++ u32 buf_pool_size; + __cacheline_group_end_aligned(cold); + }; + libeth_cacheline_set_assert(struct idpf_tx_queue, 64, + 96 + sizeof(struct u64_stats_sync), +- 24); ++ 32); + + /** + * struct idpf_buf_queue - software structure representing a buffer queue +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0008-idpf-stop-Tx-if-there-are-insufficient-buffer-resour.patch b/google/patches/idpf/0008-idpf-stop-Tx-if-there-are-insufficient-buffer-resour.patch new file mode 100644 index 0000000..be6cfcc --- /dev/null +++ b/google/patches/idpf/0008-idpf-stop-Tx-if-there-are-insufficient-buffer-resour.patch
@@ -0,0 +1,188 @@ +From bb163295e990fde77e5400cad1e426d9db0628d0 Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Fri, 25 Jul 2025 11:42:22 -0700 +Subject: [PATCH 08/10] idpf: stop Tx if there are insufficient buffer + resources + +[ Upstream commit 0c3f135e840d4a2ba4253e15d530ec61bc30718e ] + +The Tx refillq logic will cause packets to be silently dropped if there +are not enough buffer resources available to send a packet in flow +scheduling mode. Instead, determine how many buffers are needed along +with number of descriptors. Make sure there are enough of both resources +to send the packet, and stop the queue if not. + +Fixes: 7292af042bcf ("idpf: fix a race in txq wakeup") +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Tested-by: Samuel Salin <Samuel.salin@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + .../ethernet/intel/idpf/idpf_singleq_txrx.c | 4 +- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 47 +++++++++++++------ + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 15 +++++- + 3 files changed, 47 insertions(+), 19 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +index ebe1acfc20b8..ea0eec59a072 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +@@ -415,11 +415,11 @@ netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, + { + struct idpf_tx_offload_params offload = { }; + struct idpf_tx_buf *first; ++ u32 count, buf_count = 1; + int csum, tso, needed; +- unsigned int count; + __be16 protocol; + +- count = idpf_tx_desc_count_required(tx_q, skb); ++ count = idpf_tx_res_count_required(tx_q, skb, &buf_count); + if (unlikely(!count)) + return idpf_tx_drop_skb(tx_q, skb); + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 54e054b3d329..05652b0f086f 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -2142,15 +2142,22 @@ void idpf_tx_splitq_build_flow_desc(union idpf_tx_flex_desc *desc, + desc->flow.qw1.compl_tag = cpu_to_le16(params->compl_tag); + } + +-/* Global conditions to tell whether the txq (and related resources) +- * has room to allow the use of "size" descriptors. ++/** ++ * idpf_tx_splitq_has_room - check if enough Tx splitq resources are available ++ * @tx_q: the queue to be checked ++ * @descs_needed: number of descriptors required for this packet ++ * @bufs_needed: number of Tx buffers required for this packet ++ * ++ * Return: 0 if no room available, 1 otherwise + */ +-static int idpf_txq_has_room(struct idpf_tx_queue *tx_q, u32 size) ++static int idpf_txq_has_room(struct idpf_tx_queue *tx_q, u32 descs_needed, ++ u32 bufs_needed) + { +- if (IDPF_DESC_UNUSED(tx_q) < size || ++ if (IDPF_DESC_UNUSED(tx_q) < descs_needed || + IDPF_TX_COMPLQ_PENDING(tx_q->txq_grp) > + IDPF_TX_COMPLQ_OVERFLOW_THRESH(tx_q->txq_grp->complq) || +- IDPF_TX_BUF_RSV_LOW(tx_q)) ++ IDPF_TX_BUF_RSV_LOW(tx_q) || ++ idpf_tx_splitq_get_free_bufs(tx_q->refillq) < bufs_needed) + return 0; + return 1; + } +@@ -2159,14 +2166,21 @@ static int idpf_txq_has_room(struct idpf_tx_queue *tx_q, u32 size) + * idpf_tx_maybe_stop_splitq - 1st level check for Tx splitq stop conditions + * @tx_q: the queue to be checked + * @descs_needed: number of descriptors required for this packet ++ * @bufs_needed: number of buffers needed for this packet + * +- * Returns 0 if stop is not needed ++ * Return: 0 if stop is not needed + */ + static int idpf_tx_maybe_stop_splitq(struct idpf_tx_queue *tx_q, +- unsigned int descs_needed) ++ u32 descs_needed, ++ u32 bufs_needed) + { ++ /* Since we have multiple resources to check for splitq, our ++ * start,stop_thrs becomes a boolean check instead of a count ++ * threshold. ++ */ + if (netif_subqueue_maybe_stop(tx_q->netdev, tx_q->idx, +- idpf_txq_has_room(tx_q, descs_needed), ++ idpf_txq_has_room(tx_q, descs_needed, ++ bufs_needed), + 1, 1)) + return 0; + +@@ -2208,14 +2222,16 @@ void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val, + } + + /** +- * idpf_tx_desc_count_required - calculate number of Tx descriptors needed ++ * idpf_tx_res_count_required - get number of Tx resources needed for this pkt + * @txq: queue to send buffer on + * @skb: send buffer ++ * @bufs_needed: (output) number of buffers needed for this skb. + * +- * Returns number of data descriptors needed for this skb. ++ * Return: number of data descriptors and buffers needed for this skb. + */ +-unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, +- struct sk_buff *skb) ++unsigned int idpf_tx_res_count_required(struct idpf_tx_queue *txq, ++ struct sk_buff *skb, ++ u32 *bufs_needed) + { + const struct skb_shared_info *shinfo; + unsigned int count = 0, i; +@@ -2226,6 +2242,7 @@ unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, + return count; + + shinfo = skb_shinfo(skb); ++ *bufs_needed += shinfo->nr_frags; + for (i = 0; i < shinfo->nr_frags; i++) { + unsigned int size; + +@@ -2775,11 +2792,11 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + .prev_ntu = tx_q->next_to_use, + }; + struct idpf_tx_buf *first; +- unsigned int count; ++ u32 count, buf_count = 1; + u32 buf_id; + int tso; + +- count = idpf_tx_desc_count_required(tx_q, skb); ++ count = idpf_tx_res_count_required(tx_q, skb, &buf_count); + if (unlikely(!count)) + return idpf_tx_drop_skb(tx_q, skb); + +@@ -2789,7 +2806,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + + /* Check for splitq specific TX resources */ + count += (IDPF_TX_DESCS_PER_CACHE_LINE + tso); +- if (idpf_tx_maybe_stop_splitq(tx_q, count)) { ++ if (idpf_tx_maybe_stop_splitq(tx_q, count, buf_count)) { + idpf_tx_buf_hw_update(tx_q, tx_q->next_to_use, false); + + return NETDEV_TX_BUSY; +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +index 4e30288ae3aa..0b66bbe32a8b 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +@@ -1035,6 +1035,17 @@ static inline void idpf_vport_intr_set_wb_on_itr(struct idpf_q_vector *q_vector) + reg->dyn_ctl); + } + ++/** ++ * idpf_tx_splitq_get_free_bufs - get number of free buf_ids in refillq ++ * @refillq: pointer to refillq containing buf_ids ++ */ ++static inline u32 idpf_tx_splitq_get_free_bufs(struct idpf_sw_queue *refillq) ++{ ++ return (refillq->next_to_use > refillq->next_to_clean ? ++ 0 : refillq->desc_count) + ++ refillq->next_to_use - refillq->next_to_clean - 1; ++} ++ + int idpf_vport_singleq_napi_poll(struct napi_struct *napi, int budget); + void idpf_vport_init_num_qs(struct idpf_vport *vport, + struct virtchnl2_create_vport *vport_msg); +@@ -1062,8 +1073,8 @@ void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val, + bool xmit_more); + unsigned int idpf_size_to_txd_count(unsigned int size); + netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb); +-unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, +- struct sk_buff *skb); ++unsigned int idpf_tx_res_count_required(struct idpf_tx_queue *txq, ++ struct sk_buff *skb, u32 *buf_count); + void idpf_tx_timeout(struct net_device *netdev, unsigned int txqueue); + netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, + struct idpf_tx_queue *tx_q); +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0009-idpf-remove-obsolete-stashing-code.patch b/google/patches/idpf/0009-idpf-remove-obsolete-stashing-code.patch new file mode 100644 index 0000000..3c14e4b --- /dev/null +++ b/google/patches/idpf/0009-idpf-remove-obsolete-stashing-code.patch
@@ -0,0 +1,662 @@ +From 4e07e57cc164450faf6a8c03f87bc07610b61c95 Mon Sep 17 00:00:00 2001 +From: Joshua Hay <joshua.a.hay@intel.com> +Date: Fri, 25 Jul 2025 11:42:23 -0700 +Subject: [PATCH 09/10] idpf: remove obsolete stashing code + +[ Upstream commit 6c4e68480238274f84aa50d54da0d9e262df6284 ] + +With the new Tx buffer management scheme, there is no need for all of +the stashing mechanisms, the hash table, the reserve buffer stack, etc. +Remove all of that. + +Signed-off-by: Joshua Hay <joshua.a.hay@intel.com> +Reviewed-by: Madhu Chittim <madhu.chittim@intel.com> +Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> +Tested-by: Samuel Salin <Samuel.salin@intel.com> +Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> +--- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 309 ++------------------ + drivers/net/ethernet/intel/idpf/idpf_txrx.h | 47 +-- + 2 files changed, 22 insertions(+), 334 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 05652b0f086f..809cb2b627dc 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -7,48 +7,12 @@ + #include "idpf.h" + #include "idpf_virtchnl.h" + +-struct idpf_tx_stash { +- struct hlist_node hlist; +- struct libeth_sqe buf; +-}; +- + #define idpf_tx_buf_next(buf) (*(u32 *)&(buf)->priv) +-#define idpf_tx_buf_compl_tag(buf) (*(u32 *)&(buf)->priv) + LIBETH_SQE_CHECK_PRIV(u32); + + static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, + unsigned int count); + +-/** +- * idpf_buf_lifo_push - push a buffer pointer onto stack +- * @stack: pointer to stack struct +- * @buf: pointer to buf to push +- * +- * Returns 0 on success, negative on failure +- **/ +-static int idpf_buf_lifo_push(struct idpf_buf_lifo *stack, +- struct idpf_tx_stash *buf) +-{ +- if (unlikely(stack->top == stack->size)) +- return -ENOSPC; +- +- stack->bufs[stack->top++] = buf; +- +- return 0; +-} +- +-/** +- * idpf_buf_lifo_pop - pop a buffer pointer from stack +- * @stack: pointer to stack struct +- **/ +-static struct idpf_tx_stash *idpf_buf_lifo_pop(struct idpf_buf_lifo *stack) +-{ +- if (unlikely(!stack->top)) +- return NULL; +- +- return stack->bufs[--stack->top]; +-} +- + /** + * idpf_tx_timeout - Respond to a Tx Hang + * @netdev: network interface device structure +@@ -77,14 +41,11 @@ void idpf_tx_timeout(struct net_device *netdev, unsigned int txqueue) + static void idpf_tx_buf_rel_all(struct idpf_tx_queue *txq) + { + struct libeth_sq_napi_stats ss = { }; +- struct idpf_buf_lifo *buf_stack; +- struct idpf_tx_stash *stash; + struct libeth_cq_pp cp = { + .dev = txq->dev, + .ss = &ss, + }; +- struct hlist_node *tmp; +- u32 i, tag; ++ u32 i; + + /* Buffers already cleared, nothing to do */ + if (!txq->tx_buf) +@@ -96,33 +57,6 @@ static void idpf_tx_buf_rel_all(struct idpf_tx_queue *txq) + + kfree(txq->tx_buf); + txq->tx_buf = NULL; +- +- if (!idpf_queue_has(FLOW_SCH_EN, txq)) +- return; +- +- buf_stack = &txq->stash->buf_stack; +- if (!buf_stack->bufs) +- return; +- +- /* +- * If a Tx timeout occurred, there are potentially still bufs in the +- * hash table, free them here. +- */ +- hash_for_each_safe(txq->stash->sched_buf_hash, tag, tmp, stash, +- hlist) { +- if (!stash) +- continue; +- +- libeth_tx_complete(&stash->buf, &cp); +- hash_del(&stash->hlist); +- idpf_buf_lifo_push(buf_stack, stash); +- } +- +- for (i = 0; i < buf_stack->size; i++) +- kfree(buf_stack->bufs[i]); +- +- kfree(buf_stack->bufs); +- buf_stack->bufs = NULL; + } + + /** +@@ -198,9 +132,6 @@ static void idpf_tx_desc_rel_all(struct idpf_vport *vport) + */ + static int idpf_tx_buf_alloc_all(struct idpf_tx_queue *tx_q) + { +- struct idpf_buf_lifo *buf_stack; +- int i; +- + /* Allocate book keeping buffers only. Buffers to be supplied to HW + * are allocated by kernel network stack and received as part of skb + */ +@@ -213,29 +144,6 @@ static int idpf_tx_buf_alloc_all(struct idpf_tx_queue *tx_q) + if (!tx_q->tx_buf) + return -ENOMEM; + +- if (!idpf_queue_has(FLOW_SCH_EN, tx_q)) +- return 0; +- +- buf_stack = &tx_q->stash->buf_stack; +- +- /* Initialize tx buf stack for out-of-order completions if +- * flow scheduling offload is enabled +- */ +- buf_stack->bufs = kcalloc(tx_q->desc_count, sizeof(*buf_stack->bufs), +- GFP_KERNEL); +- if (!buf_stack->bufs) +- return -ENOMEM; +- +- buf_stack->size = tx_q->desc_count; +- buf_stack->top = tx_q->desc_count; +- +- for (i = 0; i < tx_q->desc_count; i++) { +- buf_stack->bufs[i] = kzalloc(sizeof(*buf_stack->bufs[i]), +- GFP_KERNEL); +- if (!buf_stack->bufs[i]) +- return -ENOMEM; +- } +- + return 0; + } + +@@ -349,8 +257,6 @@ static int idpf_tx_desc_alloc_all(struct idpf_vport *vport) + for (i = 0; i < vport->num_txq_grp; i++) { + for (j = 0; j < vport->txq_grps[i].num_txq; j++) { + struct idpf_tx_queue *txq = vport->txq_grps[i].txqs[j]; +- u8 gen_bits = 0; +- u16 bufidx_mask; + + err = idpf_tx_desc_alloc(vport, txq); + if (err) { +@@ -359,34 +265,6 @@ static int idpf_tx_desc_alloc_all(struct idpf_vport *vport) + i); + goto err_out; + } +- +- if (!idpf_is_queue_model_split(vport->txq_model)) +- continue; +- +- txq->compl_tag_cur_gen = 0; +- +- /* Determine the number of bits in the bufid +- * mask and add one to get the start of the +- * generation bits +- */ +- bufidx_mask = txq->desc_count - 1; +- while (bufidx_mask >> 1) { +- txq->compl_tag_gen_s++; +- bufidx_mask = bufidx_mask >> 1; +- } +- txq->compl_tag_gen_s++; +- +- gen_bits = IDPF_TX_SPLITQ_COMPL_TAG_WIDTH - +- txq->compl_tag_gen_s; +- txq->compl_tag_gen_max = GETMAXVAL(gen_bits); +- +- /* Set bufid mask based on location of first +- * gen bit; it cannot simply be the descriptor +- * ring size-1 since we can have size values +- * where not all of those bits are set. +- */ +- txq->compl_tag_bufid_m = +- GETMAXVAL(txq->compl_tag_gen_s); + } + + if (!idpf_is_queue_model_split(vport->txq_model)) +@@ -1043,9 +921,6 @@ static void idpf_txq_group_rel(struct idpf_vport *vport) + + kfree(txq_grp->complq); + txq_grp->complq = NULL; +- +- if (flow_sch_en) +- kfree(txq_grp->stashes); + } + kfree(vport->txq_grps); + vport->txq_grps = NULL; +@@ -1398,7 +1273,6 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) + for (i = 0; i < vport->num_txq_grp; i++) { + struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; + struct idpf_adapter *adapter = vport->adapter; +- struct idpf_txq_stash *stashes; + int j; + + tx_qgrp->vport = vport; +@@ -1411,15 +1285,6 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) + goto err_alloc; + } + +- if (split && flow_sch_en) { +- stashes = kcalloc(num_txq, sizeof(*stashes), +- GFP_KERNEL); +- if (!stashes) +- goto err_alloc; +- +- tx_qgrp->stashes = stashes; +- } +- + for (j = 0; j < tx_qgrp->num_txq; j++) { + struct idpf_tx_queue *q = tx_qgrp->txqs[j]; + +@@ -1439,11 +1304,6 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) + if (!flow_sch_en) + continue; + +- if (split) { +- q->stash = &stashes[j]; +- hash_init(q->stash->sched_buf_hash); +- } +- + idpf_queue_set(FLOW_SCH_EN, q); + + q->refillq = kzalloc(sizeof(*q->refillq), GFP_KERNEL); +@@ -1701,82 +1561,6 @@ static void idpf_tx_handle_sw_marker(struct idpf_tx_queue *tx_q) + wake_up(&vport->sw_marker_wq); + } + +-/** +- * idpf_tx_clean_stashed_bufs - clean bufs that were stored for +- * out of order completions +- * @txq: queue to clean +- * @compl_tag: completion tag of packet to clean (from completion descriptor) +- * @cleaned: pointer to stats struct to track cleaned packets/bytes +- * @budget: Used to determine if we are in netpoll +- */ +-static void idpf_tx_clean_stashed_bufs(struct idpf_tx_queue *txq, +- u16 compl_tag, +- struct libeth_sq_napi_stats *cleaned, +- int budget) +-{ +- struct idpf_tx_stash *stash; +- struct hlist_node *tmp_buf; +- struct libeth_cq_pp cp = { +- .dev = txq->dev, +- .ss = cleaned, +- .napi = budget, +- }; +- +- /* Buffer completion */ +- hash_for_each_possible_safe(txq->stash->sched_buf_hash, stash, tmp_buf, +- hlist, compl_tag) { +- if (unlikely(idpf_tx_buf_compl_tag(&stash->buf) != compl_tag)) +- continue; +- +- hash_del(&stash->hlist); +- libeth_tx_complete(&stash->buf, &cp); +- +- /* Push shadow buf back onto stack */ +- idpf_buf_lifo_push(&txq->stash->buf_stack, stash); +- } +-} +- +-/** +- * idpf_stash_flow_sch_buffers - store buffer parameters info to be freed at a +- * later time (only relevant for flow scheduling mode) +- * @txq: Tx queue to clean +- * @tx_buf: buffer to store +- */ +-static int idpf_stash_flow_sch_buffers(struct idpf_tx_queue *txq, +- struct idpf_tx_buf *tx_buf) +-{ +- struct idpf_tx_stash *stash; +- +- if (unlikely(tx_buf->type <= LIBETH_SQE_CTX)) +- return 0; +- +- stash = idpf_buf_lifo_pop(&txq->stash->buf_stack); +- if (unlikely(!stash)) { +- net_err_ratelimited("%s: No out-of-order TX buffers left!\n", +- netdev_name(txq->netdev)); +- +- return -ENOMEM; +- } +- +- /* Store buffer params in shadow buffer */ +- stash->buf.skb = tx_buf->skb; +- stash->buf.bytes = tx_buf->bytes; +- stash->buf.packets = tx_buf->packets; +- stash->buf.type = tx_buf->type; +- stash->buf.nr_frags = tx_buf->nr_frags; +- dma_unmap_addr_set(&stash->buf, dma, dma_unmap_addr(tx_buf, dma)); +- dma_unmap_len_set(&stash->buf, len, dma_unmap_len(tx_buf, len)); +- idpf_tx_buf_compl_tag(&stash->buf) = idpf_tx_buf_compl_tag(tx_buf); +- +- /* Add buffer to buf_hash table to be freed later */ +- hash_add(txq->stash->sched_buf_hash, &stash->hlist, +- idpf_tx_buf_compl_tag(&stash->buf)); +- +- tx_buf->type = LIBETH_SQE_EMPTY; +- +- return 0; +-} +- + #define idpf_tx_splitq_clean_bump_ntc(txq, ntc, desc, buf) \ + do { \ + if (unlikely(++(ntc) == (txq)->desc_count)) { \ +@@ -1804,14 +1588,8 @@ do { \ + * Separate packet completion events will be reported on the completion queue, + * and the buffers will be cleaned separately. The stats are not updated from + * this function when using flow-based scheduling. +- * +- * Furthermore, in flow scheduling mode, check to make sure there are enough +- * reserve buffers to stash the packet. If there are not, return early, which +- * will leave next_to_clean pointing to the packet that failed to be stashed. +- * +- * Return: false in the scenario above, true otherwise. + */ +-static bool idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end, ++static void idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end, + int napi_budget, + struct libeth_sq_napi_stats *cleaned, + bool descs_only) +@@ -1825,12 +1603,11 @@ static bool idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end, + .napi = napi_budget, + }; + struct idpf_tx_buf *tx_buf; +- bool clean_complete = true; + + if (descs_only) { + /* Bump ring index to mark as cleaned. */ + tx_q->next_to_clean = end; +- return true; ++ return; + } + + tx_desc = &tx_q->flex_tx[ntc]; +@@ -1851,53 +1628,24 @@ static bool idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end, + break; + + eop_idx = tx_buf->rs_idx; ++ libeth_tx_complete(tx_buf, &cp); + +- if (descs_only) { +- if (IDPF_TX_BUF_RSV_UNUSED(tx_q) < tx_buf->nr_frags) { +- clean_complete = false; +- goto tx_splitq_clean_out; +- } +- +- idpf_stash_flow_sch_buffers(tx_q, tx_buf); ++ /* unmap remaining buffers */ ++ while (ntc != eop_idx) { ++ idpf_tx_splitq_clean_bump_ntc(tx_q, ntc, ++ tx_desc, tx_buf); + +- while (ntc != eop_idx) { +- idpf_tx_splitq_clean_bump_ntc(tx_q, ntc, +- tx_desc, tx_buf); +- idpf_stash_flow_sch_buffers(tx_q, tx_buf); +- } +- } else { ++ /* unmap any remaining paged data */ + libeth_tx_complete(tx_buf, &cp); +- +- /* unmap remaining buffers */ +- while (ntc != eop_idx) { +- idpf_tx_splitq_clean_bump_ntc(tx_q, ntc, +- tx_desc, tx_buf); +- +- /* unmap any remaining paged data */ +- libeth_tx_complete(tx_buf, &cp); +- } + } + + fetch_next_txq_desc: + idpf_tx_splitq_clean_bump_ntc(tx_q, ntc, tx_desc, tx_buf); + } + +-tx_splitq_clean_out: + tx_q->next_to_clean = ntc; +- +- return clean_complete; + } + +-#define idpf_tx_clean_buf_ring_bump_ntc(txq, ntc, buf) \ +-do { \ +- (buf)++; \ +- (ntc)++; \ +- if (unlikely((ntc) == (txq)->desc_count)) { \ +- buf = (txq)->tx_buf; \ +- ntc = 0; \ +- } \ +-} while (0) +- + /** + * idpf_tx_clean_bufs - clean flow scheduling TX queue buffers + * @txq: queue to clean +@@ -1908,7 +1656,7 @@ do { \ + * Clean all buffers associated with the packet starting at buf_id. Returns the + * byte/segment count for the cleaned packet. + */ +-static bool idpf_tx_clean_bufs(struct idpf_tx_queue *txq, u32 buf_id, ++static void idpf_tx_clean_bufs(struct idpf_tx_queue *txq, u32 buf_id, + struct libeth_sq_napi_stats *cleaned, + int budget) + { +@@ -1932,8 +1680,6 @@ static bool idpf_tx_clean_bufs(struct idpf_tx_queue *txq, u32 buf_id, + libeth_tx_complete(tx_buf, &cp); + idpf_post_buf_refill(txq->refillq, buf_id); + } +- +- return true; + } + + /** +@@ -1952,22 +1698,17 @@ static void idpf_tx_handle_rs_completion(struct idpf_tx_queue *txq, + struct libeth_sq_napi_stats *cleaned, + int budget) + { +- u16 compl_tag; ++ /* RS completion contains queue head for queue based scheduling or ++ * completion tag for flow based scheduling. ++ */ ++ u16 rs_compl_val = le16_to_cpu(desc->q_head_compl_tag.q_head); + + if (!idpf_queue_has(FLOW_SCH_EN, txq)) { +- u16 head = le16_to_cpu(desc->q_head_compl_tag.q_head); +- +- idpf_tx_splitq_clean(txq, head, budget, cleaned, false); ++ idpf_tx_splitq_clean(txq, rs_compl_val, budget, cleaned, false); + return; + } + +- compl_tag = le16_to_cpu(desc->q_head_compl_tag.compl_tag); +- +- /* If we didn't clean anything on the ring, this packet must be +- * in the hash table. Go clean it there. +- */ +- if (!idpf_tx_clean_bufs(txq, compl_tag, cleaned, budget)) +- idpf_tx_clean_stashed_bufs(txq, compl_tag, cleaned, budget); ++ idpf_tx_clean_bufs(txq, rs_compl_val, cleaned, budget); + } + + /** +@@ -2084,8 +1825,7 @@ static bool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget, + /* Update BQL */ + nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx); + +- dont_wake = !complq_ok || IDPF_TX_BUF_RSV_LOW(tx_q) || +- np->state != __IDPF_VPORT_UP || ++ dont_wake = !complq_ok || np->state != __IDPF_VPORT_UP || + !netif_carrier_ok(tx_q->netdev); + /* Check if the TXQ needs to and can be restarted */ + __netif_txq_completed_wake(nq, tx_q->cleaned_pkts, tx_q->cleaned_bytes, +@@ -2156,7 +1896,6 @@ static int idpf_txq_has_room(struct idpf_tx_queue *tx_q, u32 descs_needed, + if (IDPF_DESC_UNUSED(tx_q) < descs_needed || + IDPF_TX_COMPLQ_PENDING(tx_q->txq_grp) > + IDPF_TX_COMPLQ_OVERFLOW_THRESH(tx_q->txq_grp->complq) || +- IDPF_TX_BUF_RSV_LOW(tx_q) || + idpf_tx_splitq_get_free_bufs(tx_q->refillq) < bufs_needed) + return 0; + return 1; +@@ -2280,10 +2019,8 @@ static unsigned int idpf_tx_splitq_bump_ntu(struct idpf_tx_queue *txq, u16 ntu) + { + ntu++; + +- if (ntu == txq->desc_count) { ++ if (ntu == txq->desc_count) + ntu = 0; +- txq->compl_tag_cur_gen = IDPF_TX_ADJ_COMPL_TAG_GEN(txq); +- } + + return ntu; + } +@@ -2465,8 +2202,6 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + if (unlikely(++i == tx_q->desc_count)) { + tx_desc = &tx_q->flex_tx[0]; + i = 0; +- tx_q->compl_tag_cur_gen = +- IDPF_TX_ADJ_COMPL_TAG_GEN(tx_q); + } else { + tx_desc++; + } +@@ -2497,7 +2232,6 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, + if (unlikely(++i == tx_q->desc_count)) { + tx_desc = &tx_q->flex_tx[0]; + i = 0; +- tx_q->compl_tag_cur_gen = IDPF_TX_ADJ_COMPL_TAG_GEN(tx_q); + } else { + tx_desc++; + } +@@ -2858,10 +2592,9 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, + + tx_params.dtype = IDPF_TX_DESC_DTYPE_FLEX_FLOW_SCHE; + tx_params.eop_cmd = IDPF_TXD_FLEX_FLOW_CMD_EOP; +- /* Set the RE bit to catch any packets that may have not been +- * stashed during RS completion cleaning. MIN_GAP is set to +- * MIN_RING size to ensure it will be set at least once each +- * time around the ring. ++ /* Set the RE bit to periodically "clean" the descriptor ring. ++ * MIN_GAP is set to MIN_RING size to ensure it will be set at ++ * least once each time around the ring. + */ + if (idpf_tx_splitq_need_re(tx_q)) { + tx_params.eop_cmd |= IDPF_TXD_FLEX_FLOW_CMD_RE; +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +index 0b66bbe32a8b..5f8a9b9f5d5d 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h +@@ -118,10 +118,6 @@ do { \ + ((((txq)->next_to_clean > (txq)->next_to_use) ? 0 : (txq)->desc_count) + \ + (txq)->next_to_clean - (txq)->next_to_use - 1) + +-#define IDPF_TX_BUF_RSV_UNUSED(txq) ((txq)->stash->buf_stack.top) +-#define IDPF_TX_BUF_RSV_LOW(txq) (IDPF_TX_BUF_RSV_UNUSED(txq) < \ +- (txq)->desc_count >> 2) +- + #define IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq) ((txcq)->desc_count >> 1) + /* Determine the absolute number of completions pending, i.e. the number of + * completions that are expected to arrive on the TX completion queue. +@@ -131,12 +127,6 @@ do { \ + 0 : U32_MAX) + \ + (txq)->num_completions_pending - (txq)->complq->num_completions) + +-#define IDPF_TX_SPLITQ_COMPL_TAG_WIDTH 16 +-/* Adjust the generation for the completion tag and wrap if necessary */ +-#define IDPF_TX_ADJ_COMPL_TAG_GEN(txq) \ +- ((++(txq)->compl_tag_cur_gen) >= (txq)->compl_tag_gen_max ? \ +- 0 : (txq)->compl_tag_cur_gen) +- + #define IDPF_TXBUF_NULL U32_MAX + + #define IDPF_TXD_LAST_DESC_CMD (IDPF_TX_DESC_CMD_EOP | IDPF_TX_DESC_CMD_RS) +@@ -153,18 +143,6 @@ union idpf_tx_flex_desc { + + #define idpf_tx_buf libeth_sqe + +-/** +- * struct idpf_buf_lifo - LIFO for managing OOO completions +- * @top: Used to know how many buffers are left +- * @size: Total size of LIFO +- * @bufs: Backing array +- */ +-struct idpf_buf_lifo { +- u16 top; +- u16 size; +- struct idpf_tx_stash **bufs; +-}; +- + /** + * struct idpf_tx_offload_params - Offload parameters for a given packet + * @tx_flags: Feature flags enabled for this packet +@@ -492,17 +470,6 @@ struct idpf_tx_queue_stats { + #define IDPF_ITR_IDX_SPACING(spacing, dflt) (spacing ? spacing : dflt) + #define IDPF_DIM_DEFAULT_PROFILE_IX 1 + +-/** +- * struct idpf_txq_stash - Tx buffer stash for Flow-based scheduling mode +- * @buf_stack: Stack of empty buffers to store buffer info for out of order +- * buffer completions. See struct idpf_buf_lifo +- * @sched_buf_hash: Hash table to store buffers +- */ +-struct idpf_txq_stash { +- struct idpf_buf_lifo buf_stack; +- DECLARE_HASHTABLE(sched_buf_hash, 12); +-} ____cacheline_aligned; +- + /** + * struct idpf_rx_queue - software structure representing a receive queue + * @rx: universal receive descriptor array +@@ -645,11 +612,7 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64, + * only once at the end of the cleaning routine. + * @clean_budget: singleq only, queue cleaning budget + * @cleaned_pkts: Number of packets cleaned for the above said case +- * @stash: Tx buffer stash for Flow-based scheduling mode + * @refillq: Pointer to refill queue +- * @compl_tag_bufid_m: Completion tag buffer id mask +- * @compl_tag_cur_gen: Used to keep track of current completion tag generation +- * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset + * @stats_sync: See struct u64_stats_sync + * @q_stats: See union idpf_tx_queue_stats + * @q_id: Queue id +@@ -678,7 +641,6 @@ struct idpf_tx_queue { + u16 desc_count; + + u16 tx_min_pkt_len; +- u16 compl_tag_gen_s; + + struct net_device *netdev; + __cacheline_group_end_aligned(read_mostly); +@@ -695,13 +657,8 @@ struct idpf_tx_queue { + }; + u16 cleaned_pkts; + +- struct idpf_txq_stash *stash; + struct idpf_sw_queue *refillq; + +- u16 compl_tag_bufid_m; +- u16 compl_tag_cur_gen; +- u16 compl_tag_gen_max; +- + struct u64_stats_sync stats_sync; + struct idpf_tx_queue_stats q_stats; + __cacheline_group_end_aligned(read_write); +@@ -716,7 +673,7 @@ struct idpf_tx_queue { + __cacheline_group_end_aligned(cold); + }; + libeth_cacheline_set_assert(struct idpf_tx_queue, 64, +- 96 + sizeof(struct u64_stats_sync), ++ 80 + sizeof(struct u64_stats_sync), + 32); + + /** +@@ -927,7 +884,6 @@ struct idpf_rxq_group { + * @vport: Vport back pointer + * @num_txq: Number of TX queues associated + * @txqs: Array of TX queue pointers +- * @stashes: array of OOO stashes for the queues + * @complq: Associated completion queue pointer, split queue only + * @num_completions_pending: Total number of completions pending for the + * completion queue, acculumated for all TX queues +@@ -942,7 +898,6 @@ struct idpf_txq_group { + + u16 num_txq; + struct idpf_tx_queue *txqs[IDPF_LARGE_MAX_Q]; +- struct idpf_txq_stash *stashes; + + struct idpf_compl_queue *complq; + +-- +2.52.0.223.gf5cc29aaa4-goog +
diff --git a/google/patches/idpf/0010-idpf-do-not-linearize-big-TSO-packets.patch b/google/patches/idpf/0010-idpf-do-not-linearize-big-TSO-packets.patch new file mode 100644 index 0000000..400cadc --- /dev/null +++ b/google/patches/idpf/0010-idpf-do-not-linearize-big-TSO-packets.patch
@@ -0,0 +1,343 @@ +From 4e10659d1d79cb6605113966d1b865faccd0caab Mon Sep 17 00:00:00 2001 +From: Eric Dumazet <edumazet@google.com> +Date: Mon, 18 Aug 2025 19:59:34 +0000 +Subject: [PATCH 10/10] idpf: do not linearize big TSO packets + +[ Upstream commit 02614eee26fbdfd73b944769001cefeff6ed008c ] + +idpf has a limit on number of scatter-gather frags +that can be used per segment. + +Currently, idpf_tx_start() checks if the limit is hit +and forces a linearization of the whole packet. + +This requires high order allocations that can fail +under memory pressure. A full size BIG-TCP packet +would require order-7 alocation on x86_64 :/ + +We can move the check earlier from idpf_features_check() +for TSO packets, to force GSO in this case, removing the +cost of a big copy. + +This means that a linearization will eventually happen +with sizes smaller than one MSS. + +__idpf_chk_linearize() is renamed to idpf_chk_tso_segment() +and moved to idpf_lib.c + +Signed-off-by: Eric Dumazet <edumazet@google.com> +Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com> +Cc: Jacob Keller <jacob.e.keller@intel.com> +Cc: Madhu Chittim <madhu.chittim@intel.com> +Cc: Pavan Kumar Linga <pavan.kumar.linga@intel.com> +Cc: Willem de Bruijn <willemb@google.com> +Cc: Andrew Lunn <andrew+netdev@lunn.ch> +Reviewed-by: Joshua Hay <joshua.a.hay@intel.com> +Tested-by: Brian Vazquez <brianvv@google.com> +Acked-by: Tony Nguyen <anthony.l.nguyen@intel.com> +Link: https://patch.msgid.link/20250818195934.757936-1-edumazet@google.com +Signed-off-by: Jakub Kicinski <kuba@kernel.org> +Signed-off-by: Sasha Levin <sashal@kernel.org> +--- + drivers/net/ethernet/intel/idpf/idpf.h | 2 + + drivers/net/ethernet/intel/idpf/idpf_lib.c | 102 +++++++++++++++- + drivers/net/ethernet/intel/idpf/idpf_txrx.c | 129 ++++---------------- + 3 files changed, 120 insertions(+), 113 deletions(-) + +diff --git a/drivers/net/ethernet/intel/idpf/idpf.h b/drivers/net/ethernet/intel/idpf/idpf.h +index a2b346d91879..f4d51c885f33 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf.h ++++ b/drivers/net/ethernet/intel/idpf/idpf.h +@@ -144,6 +144,7 @@ enum idpf_vport_state { + * @link_speed_mbps: Link speed in mbps + * @vport_idx: Relative vport index + * @max_tx_hdr_size: Max header length hardware can support ++ * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather + * @state: See enum idpf_vport_state + * @netstats: Packet and byte stats + * @stats_lock: Lock to protect stats update +@@ -155,6 +156,7 @@ struct idpf_netdev_priv { + u32 link_speed_mbps; + u16 vport_idx; + u16 max_tx_hdr_size; ++ u16 tx_max_bufs; + enum idpf_vport_state state; + struct rtnl_link_stats64 netstats; + spinlock_t stats_lock; +diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c +index 52d9caab2fcb..371fc5052420 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_lib.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c +@@ -742,6 +742,7 @@ static int idpf_cfg_netdev(struct idpf_vport *vport) + np->vport_idx = vport->idx; + np->vport_id = vport->vport_id; + np->max_tx_hdr_size = idpf_get_max_tx_hdr_size(adapter); ++ np->tx_max_bufs = idpf_get_max_tx_bufs(adapter); + + spin_lock_init(&np->stats_lock); + +@@ -2205,6 +2206,92 @@ static int idpf_change_mtu(struct net_device *netdev, int new_mtu) + return err; + } + ++/** ++ * idpf_chk_tso_segment - Check skb is not using too many buffers ++ * @skb: send buffer ++ * @max_bufs: maximum number of buffers ++ * ++ * For TSO we need to count the TSO header and segment payload separately. As ++ * such we need to check cases where we have max_bufs-1 fragments or more as we ++ * can potentially require max_bufs+1 DMA transactions, 1 for the TSO header, 1 ++ * for the segment payload in the first descriptor, and another max_buf-1 for ++ * the fragments. ++ * ++ * Returns true if the packet needs to be software segmented by core stack. ++ */ ++static bool idpf_chk_tso_segment(const struct sk_buff *skb, ++ unsigned int max_bufs) ++{ ++ const struct skb_shared_info *shinfo = skb_shinfo(skb); ++ const skb_frag_t *frag, *stale; ++ int nr_frags, sum; ++ ++ /* no need to check if number of frags is less than max_bufs - 1 */ ++ nr_frags = shinfo->nr_frags; ++ if (nr_frags < (max_bufs - 1)) ++ return false; ++ ++ /* We need to walk through the list and validate that each group ++ * of max_bufs-2 fragments totals at least gso_size. ++ */ ++ nr_frags -= max_bufs - 2; ++ frag = &shinfo->frags[0]; ++ ++ /* Initialize size to the negative value of gso_size minus 1. We use ++ * this as the worst case scenario in which the frag ahead of us only ++ * provides one byte which is why we are limited to max_bufs-2 ++ * descriptors for a single transmit as the header and previous ++ * fragment are already consuming 2 descriptors. ++ */ ++ sum = 1 - shinfo->gso_size; ++ ++ /* Add size of frags 0 through 4 to create our initial sum */ ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ sum += skb_frag_size(frag++); ++ ++ /* Walk through fragments adding latest fragment, testing it, and ++ * then removing stale fragments from the sum. ++ */ ++ for (stale = &shinfo->frags[0];; stale++) { ++ int stale_size = skb_frag_size(stale); ++ ++ sum += skb_frag_size(frag++); ++ ++ /* The stale fragment may present us with a smaller ++ * descriptor than the actual fragment size. To account ++ * for that we need to remove all the data on the front and ++ * figure out what the remainder would be in the last ++ * descriptor associated with the fragment. ++ */ ++ if (stale_size > IDPF_TX_MAX_DESC_DATA) { ++ int align_pad = -(skb_frag_off(stale)) & ++ (IDPF_TX_MAX_READ_REQ_SIZE - 1); ++ ++ sum -= align_pad; ++ stale_size -= align_pad; ++ ++ do { ++ sum -= IDPF_TX_MAX_DESC_DATA_ALIGNED; ++ stale_size -= IDPF_TX_MAX_DESC_DATA_ALIGNED; ++ } while (stale_size > IDPF_TX_MAX_DESC_DATA); ++ } ++ ++ /* if sum is negative we failed to make sufficient progress */ ++ if (sum < 0) ++ return true; ++ ++ if (!nr_frags--) ++ break; ++ ++ sum -= stale_size; ++ } ++ ++ return false; ++} ++ + /** + * idpf_features_check - Validate packet conforms to limits + * @skb: skb buffer +@@ -2226,12 +2313,15 @@ static netdev_features_t idpf_features_check(struct sk_buff *skb, + if (skb->ip_summed != CHECKSUM_PARTIAL) + return features; + +- /* We cannot support GSO if the MSS is going to be less than +- * 88 bytes. If it is then we need to drop support for GSO. +- */ +- if (skb_is_gso(skb) && +- (skb_shinfo(skb)->gso_size < IDPF_TX_TSO_MIN_MSS)) +- features &= ~NETIF_F_GSO_MASK; ++ if (skb_is_gso(skb)) { ++ /* We cannot support GSO if the MSS is going to be less than ++ * 88 bytes. If it is then we need to drop support for GSO. ++ */ ++ if (skb_shinfo(skb)->gso_size < IDPF_TX_TSO_MIN_MSS) ++ features &= ~NETIF_F_GSO_MASK; ++ else if (idpf_chk_tso_segment(skb, np->tx_max_bufs)) ++ features &= ~NETIF_F_GSO_MASK; ++ } + + /* Ensure MACLEN is <= 126 bytes (63 words) and not an odd size */ + len = skb_network_offset(skb); +diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +index 809cb2b627dc..3ddf7b1e85ef 100644 +--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c ++++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c +@@ -10,8 +10,28 @@ + #define idpf_tx_buf_next(buf) (*(u32 *)&(buf)->priv) + LIBETH_SQE_CHECK_PRIV(u32); + +-static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, +- unsigned int count); ++/** ++ * idpf_chk_linearize - Check if skb exceeds max descriptors per packet ++ * @skb: send buffer ++ * @max_bufs: maximum scatter gather buffers for single packet ++ * @count: number of buffers this packet needs ++ * ++ * Make sure we don't exceed maximum scatter gather buffers for a single ++ * packet. ++ * TSO case has been handled earlier from idpf_features_check(). ++ */ ++static bool idpf_chk_linearize(const struct sk_buff *skb, ++ unsigned int max_bufs, ++ unsigned int count) ++{ ++ if (likely(count <= max_bufs)) ++ return false; ++ ++ if (skb_is_gso(skb)) ++ return false; ++ ++ return true; ++} + + /** + * idpf_tx_timeout - Respond to a Tx Hang +@@ -2353,111 +2373,6 @@ int idpf_tso(struct sk_buff *skb, struct idpf_tx_offload_params *off) + return 1; + } + +-/** +- * __idpf_chk_linearize - Check skb is not using too many buffers +- * @skb: send buffer +- * @max_bufs: maximum number of buffers +- * +- * For TSO we need to count the TSO header and segment payload separately. As +- * such we need to check cases where we have max_bufs-1 fragments or more as we +- * can potentially require max_bufs+1 DMA transactions, 1 for the TSO header, 1 +- * for the segment payload in the first descriptor, and another max_buf-1 for +- * the fragments. +- */ +-static bool __idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs) +-{ +- const struct skb_shared_info *shinfo = skb_shinfo(skb); +- const skb_frag_t *frag, *stale; +- int nr_frags, sum; +- +- /* no need to check if number of frags is less than max_bufs - 1 */ +- nr_frags = shinfo->nr_frags; +- if (nr_frags < (max_bufs - 1)) +- return false; +- +- /* We need to walk through the list and validate that each group +- * of max_bufs-2 fragments totals at least gso_size. +- */ +- nr_frags -= max_bufs - 2; +- frag = &shinfo->frags[0]; +- +- /* Initialize size to the negative value of gso_size minus 1. We use +- * this as the worst case scenario in which the frag ahead of us only +- * provides one byte which is why we are limited to max_bufs-2 +- * descriptors for a single transmit as the header and previous +- * fragment are already consuming 2 descriptors. +- */ +- sum = 1 - shinfo->gso_size; +- +- /* Add size of frags 0 through 4 to create our initial sum */ +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- sum += skb_frag_size(frag++); +- +- /* Walk through fragments adding latest fragment, testing it, and +- * then removing stale fragments from the sum. +- */ +- for (stale = &shinfo->frags[0];; stale++) { +- int stale_size = skb_frag_size(stale); +- +- sum += skb_frag_size(frag++); +- +- /* The stale fragment may present us with a smaller +- * descriptor than the actual fragment size. To account +- * for that we need to remove all the data on the front and +- * figure out what the remainder would be in the last +- * descriptor associated with the fragment. +- */ +- if (stale_size > IDPF_TX_MAX_DESC_DATA) { +- int align_pad = -(skb_frag_off(stale)) & +- (IDPF_TX_MAX_READ_REQ_SIZE - 1); +- +- sum -= align_pad; +- stale_size -= align_pad; +- +- do { +- sum -= IDPF_TX_MAX_DESC_DATA_ALIGNED; +- stale_size -= IDPF_TX_MAX_DESC_DATA_ALIGNED; +- } while (stale_size > IDPF_TX_MAX_DESC_DATA); +- } +- +- /* if sum is negative we failed to make sufficient progress */ +- if (sum < 0) +- return true; +- +- if (!nr_frags--) +- break; +- +- sum -= stale_size; +- } +- +- return false; +-} +- +-/** +- * idpf_chk_linearize - Check if skb exceeds max descriptors per packet +- * @skb: send buffer +- * @max_bufs: maximum scatter gather buffers for single packet +- * @count: number of buffers this packet needs +- * +- * Make sure we don't exceed maximum scatter gather buffers for a single +- * packet. We have to do some special checking around the boundary (max_bufs-1) +- * if TSO is on since we need count the TSO header and payload separately. +- * E.g.: a packet with 7 fragments can require 9 DMA transactions; 1 for TSO +- * header, 1 for segment payload, and then 7 for the fragments. +- */ +-static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, +- unsigned int count) +-{ +- if (likely(count < max_bufs)) +- return false; +- if (skb_is_gso(skb)) +- return __idpf_chk_linearize(skb, max_bufs); +- +- return count > max_bufs; +-} + + /** + * idpf_tx_splitq_get_ctx_desc - grab next desc and update buffer ring +-- +2.52.0.223.gf5cc29aaa4-goog +