Skip to content

Commit f237817

Browse files
stanislav-poborildkalowsk
authored andcommitted
drivers: ethernet: eth_nxp_enet_qos: fix rx buffer processing order
Always reading from descriptor with index 0 could cause processing of the buffers in a different order than they were received. Fixed by reading from the next unprocessed position in the ring of descriptors instead. Fixed unused variable warnings. Signed-off-by: Stanislav Poboril <stanislav.poboril@nxp.com>
1 parent 59334fa commit f237817

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

drivers/ethernet/eth_nxp_enet_qos/eth_nxp_enet_qos_mac.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 NXP
2+
* Copyright 2024-2025 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -176,6 +176,7 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
176176
CONTAINER_OF(rx_data, struct nxp_enet_qos_mac_data, rx);
177177
volatile union nxp_enet_qos_rx_desc *desc_arr = data->rx.descriptors;
178178
volatile union nxp_enet_qos_rx_desc *desc;
179+
uint32_t desc_idx;
179180
struct net_pkt *pkt;
180181
struct net_buf *new_buf;
181182
struct net_buf *buf;
@@ -184,13 +185,16 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
184185
LOG_DBG("iteration work:%p, rx_data:%p, data:%p", work, rx_data, data);
185186
/* We are going to find all of the descriptors we own and update them */
186187
for (int i = 0; i < NUM_RX_BUFDESC; i++) {
187-
desc = &desc_arr[i];
188+
desc_idx = rx_data->next_desc_idx;
189+
desc = &desc_arr[desc_idx];
188190

189191
if (desc->write.control3 & OWN_FLAG) {
190192
/* The DMA owns the descriptor, we cannot touch it */
191-
continue;
193+
break;
192194
}
193195

196+
rx_data->next_desc_idx = (desc_idx + 1U) % NUM_RX_BUFDESC;
197+
194198
if ((desc->write.control3 & (FIRST_TX_DESCRIPTOR_FLAG | LAST_TX_DESCRIPTOR_FLAG)) !=
195199
(FIRST_TX_DESCRIPTOR_FLAG | LAST_TX_DESCRIPTOR_FLAG)) {
196200
LOG_DBG("receive packet mask %X ", (desc->write.control3 >> 28) & 0x0f);
@@ -211,7 +215,7 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
211215
continue;
212216
}
213217

214-
LOG_DBG("Created new RX pkt %d of %d: %p", i + 1, NUM_RX_BUFDESC, pkt);
218+
LOG_DBG("Created new RX pkt %u of %d: %p", desc_idx + 1U, NUM_RX_BUFDESC, pkt);
215219
/* We need to know if we can replace the reserved fragment in advance.
216220
* At no point can we allow the driver to have less the amount of reserved
217221
* buffers it needs to function, so we will not give up our previous buffer
@@ -231,7 +235,7 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
231235
continue;
232236
}
233237

234-
buf = data->rx.reserved_bufs[i];
238+
buf = data->rx.reserved_bufs[desc_idx];
235239
pkt_len = desc->write.control3 & DESC_RX_PKT_LEN;
236240

237241
LOG_DBG("Receiving RX packet");
@@ -252,7 +256,7 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
252256

253257
LOG_DBG("Swap RX buf");
254258
/* Fresh meat */
255-
data->rx.reserved_bufs[i] = new_buf;
259+
data->rx.reserved_bufs[desc_idx] = new_buf;
256260
desc->read.buf1_addr = (uint32_t)new_buf->data;
257261
desc->read.control = rx_desc_refresh_flags;
258262

@@ -530,6 +534,9 @@ static inline int enet_qos_rx_desc_init(enet_qos_t *base, struct nxp_enet_qos_rx
530534
rx->descriptors[i].read.control |= rx_desc_refresh_flags;
531535
}
532536

537+
/* Set next descriptor where data will be received */
538+
rx->next_desc_idx = 0U;
539+
533540
/* Set up RX descriptors on channel 0 */
534541
base->DMA_CH[0].DMA_CHX_RXDESC_LIST_ADDR =
535542
/* Start of tx descriptors buffer */

drivers/ethernet/eth_nxp_enet_qos/nxp_enet_qos_priv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* NXP ENET QOS Header
22
*
3-
* Copyright 2024 NXP
3+
* Copyright 2024-2025 NXP
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
@@ -113,6 +113,7 @@ struct nxp_enet_qos_tx_data {
113113
struct nxp_enet_qos_rx_data {
114114
struct k_work rx_work;
115115
atomic_t rbu_flag;
116+
uint32_t next_desc_idx;
116117
volatile union nxp_enet_qos_rx_desc descriptors[NUM_RX_BUFDESC];
117118
struct net_buf *reserved_bufs[NUM_RX_BUFDESC];
118119
};

0 commit comments

Comments
 (0)