1
1
/*
2
- * Copyright 2024 NXP
2
+ * Copyright 2024-2025 NXP
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
@@ -176,6 +176,7 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
176
176
CONTAINER_OF (rx_data , struct nxp_enet_qos_mac_data , rx );
177
177
volatile union nxp_enet_qos_rx_desc * desc_arr = data -> rx .descriptors ;
178
178
volatile union nxp_enet_qos_rx_desc * desc ;
179
+ uint32_t desc_idx ;
179
180
struct net_pkt * pkt ;
180
181
struct net_buf * new_buf ;
181
182
struct net_buf * buf ;
@@ -184,13 +185,16 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
184
185
LOG_DBG ("iteration work:%p, rx_data:%p, data:%p" , work , rx_data , data );
185
186
/* We are going to find all of the descriptors we own and update them */
186
187
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 ];
188
190
189
191
if (desc -> write .control3 & OWN_FLAG ) {
190
192
/* The DMA owns the descriptor, we cannot touch it */
191
- continue ;
193
+ break ;
192
194
}
193
195
196
+ rx_data -> next_desc_idx = (desc_idx + 1U ) % NUM_RX_BUFDESC ;
197
+
194
198
if ((desc -> write .control3 & (FIRST_TX_DESCRIPTOR_FLAG | LAST_TX_DESCRIPTOR_FLAG )) !=
195
199
(FIRST_TX_DESCRIPTOR_FLAG | LAST_TX_DESCRIPTOR_FLAG )) {
196
200
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)
211
215
continue ;
212
216
}
213
217
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 );
215
219
/* We need to know if we can replace the reserved fragment in advance.
216
220
* At no point can we allow the driver to have less the amount of reserved
217
221
* 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)
231
235
continue ;
232
236
}
233
237
234
- buf = data -> rx .reserved_bufs [i ];
238
+ buf = data -> rx .reserved_bufs [desc_idx ];
235
239
pkt_len = desc -> write .control3 & DESC_RX_PKT_LEN ;
236
240
237
241
LOG_DBG ("Receiving RX packet" );
@@ -252,7 +256,7 @@ static void eth_nxp_enet_qos_rx(struct k_work *work)
252
256
253
257
LOG_DBG ("Swap RX buf" );
254
258
/* Fresh meat */
255
- data -> rx .reserved_bufs [i ] = new_buf ;
259
+ data -> rx .reserved_bufs [desc_idx ] = new_buf ;
256
260
desc -> read .buf1_addr = (uint32_t )new_buf -> data ;
257
261
desc -> read .control = rx_desc_refresh_flags ;
258
262
@@ -530,6 +534,9 @@ static inline int enet_qos_rx_desc_init(enet_qos_t *base, struct nxp_enet_qos_rx
530
534
rx -> descriptors [i ].read .control |= rx_desc_refresh_flags ;
531
535
}
532
536
537
+ /* Set next descriptor where data will be received */
538
+ rx -> next_desc_idx = 0U ;
539
+
533
540
/* Set up RX descriptors on channel 0 */
534
541
base -> DMA_CH [0 ].DMA_CHX_RXDESC_LIST_ADDR =
535
542
/* Start of tx descriptors buffer */
0 commit comments