[PATCH net-next v1 1/2] mlxbf_gige: protect against MAC disable during TX

From: Chris Babroski

Date: Fri Nov 20 2026 - 15:24:48 EST


On BlueField, firmware can disable and reset the OOB MAC when it handles
a fatal error or panic. If Linux is still actively transmitting packets
while the MAC is disabled, then it's possible for the HW consumer index
to be reset while the SW completion index in the driver remains the
same. This can cause the two indices to suddenly become far apart, with
a difference that is potentially larger than the TX queue length itself.

Previously, mlxbf_gige_handle_tx_complete() would continue to loop
around the TX queue, counting packets and freeing their memory, until
the two indices were equal. If entries were already freed the first time
through the queue, then a second attempt could cause a NULL pointer
dereference.

Bound the loop over the length of the TX queue so entries are not
handled more than once, and check that the skb at tx_wqe_index is not
NULL before handling.

After the loop, set the SW completion index to the new HW consumer index
to prevent future polls from walking the queue again. In normal
operation the loop already exits with the two indices equal, so there is
no change in behavior.

TX is not recovered after a sudden MAC disable. If firmware has disabled
the MAC then the system is in a state where it will be rebooting
automatically or needs manual intervention to recover.

Signed-off-by: Chris Babroski <cbabroski@xxxxxxxxxx>
---
.../mellanox/mlxbf_gige/mlxbf_gige_tx.c | 29 ++++++++++++-------
1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_tx.c b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_tx.c
index 04982e888c63..73c3033591d5 100644
--- a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_tx.c
+++ b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_tx.c
@@ -130,6 +130,7 @@ bool mlxbf_gige_handle_tx_complete(struct mlxbf_gige *priv)
u64 *tx_wqe_addr;
u64 tx_status;
u16 tx_ci;
+ u16 entry;

tx_status = readq(priv->base + MLXBF_GIGE_TX_STATUS);
if (tx_status & MLXBF_GIGE_TX_STATUS_DATA_FIFO_FULL)
@@ -143,7 +144,8 @@ bool mlxbf_gige_handle_tx_complete(struct mlxbf_gige *priv)
* to be supported, that is TX consumer index wrapped from 0xFFFF
* to 0 while TX completion index is still < 0xFFFF.
*/
- for (; priv->prev_tx_ci != tx_ci; priv->prev_tx_ci++) {
+ for (entry = 0; priv->prev_tx_ci != tx_ci && entry < priv->tx_q_entries;
+ priv->prev_tx_ci++, entry++) {
tx_wqe_index = priv->prev_tx_ci % priv->tx_q_entries;
/* Each TX WQE is 16 bytes. The 8 MSB store the 2KB TX
* buffer address and the 8 LSB contain information
@@ -152,18 +154,25 @@ bool mlxbf_gige_handle_tx_complete(struct mlxbf_gige *priv)
tx_wqe_addr = priv->tx_wqe_base +
(tx_wqe_index * MLXBF_GIGE_TX_WQE_SZ_QWORDS);

- stats->tx_packets++;
- stats->tx_bytes += MLXBF_GIGE_TX_WQE_PKT_LEN(tx_wqe_addr);
-
- dma_unmap_single(priv->dev, *tx_wqe_addr,
- priv->tx_skb[tx_wqe_index]->len, DMA_TO_DEVICE);
- dev_consume_skb_any(priv->tx_skb[tx_wqe_index]);
- priv->tx_skb[tx_wqe_index] = NULL;
+ if (priv->tx_skb[tx_wqe_index]) {
+ stats->tx_packets++;
+ stats->tx_bytes += MLXBF_GIGE_TX_WQE_PKT_LEN(tx_wqe_addr);
+ dma_unmap_single(priv->dev, *tx_wqe_addr,
+ priv->tx_skb[tx_wqe_index]->len, DMA_TO_DEVICE);
+ dev_consume_skb_any(priv->tx_skb[tx_wqe_index]);
+ priv->tx_skb[tx_wqe_index] = NULL;

- /* Ensure completion of updates across all cores */
- mb();
+ /* Ensure completion of updates across all cores */
+ mb();
+ }
}

+ /* At this point the completion index should be equal to the
+ * consumer index. If they aren't then the driver is out of sync
+ * from the HW's state and needs to be adjusted.
+ */
+ priv->prev_tx_ci = tx_ci;
+
/* Since the TX ring was likely just drained, check if TX queue
* had previously been stopped and now that there are TX buffers
* available the TX queue can be awakened.
--
2.34.1