Skip to content

Commit bd28df2

Browse files
Aleksandr Mishinlunn
authored andcommitted
octeon_ep: Implement helper for iterating packets in Rx queue
The common code with some packet and index manipulations is extracted and moved to newly implemented helper to make the code more readable and avoid duplication. This is a preparation for skb allocation failure handling. Found by Linux Verification Center (linuxtesting.org) with SVACE. Suggested-by: Simon Horman <[email protected]> Suggested-by: Paolo Abeni <[email protected]> Signed-off-by: Aleksandr Mishin <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Signed-off-by: Andrew Lunn <[email protected]>
1 parent 4ab3e49 commit bd28df2

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

drivers/net/ethernet/marvell/octeon_ep/octep_rx.c

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,30 @@ static int octep_oq_check_hw_for_pkts(struct octep_device *oct,
336336
return new_pkts;
337337
}
338338

339+
/**
340+
* octep_oq_next_pkt() - Move to the next packet in Rx queue.
341+
*
342+
* @oq: Octeon Rx queue data structure.
343+
* @buff_info: Current packet buffer info.
344+
* @read_idx: Current packet index in the ring.
345+
* @desc_used: Current packet descriptor number.
346+
*
347+
* Free the resources associated with a packet.
348+
* Increment packet index in the ring and packet descriptor number.
349+
*/
350+
static void octep_oq_next_pkt(struct octep_oq *oq,
351+
struct octep_rx_buffer *buff_info,
352+
u32 *read_idx, u32 *desc_used)
353+
{
354+
dma_unmap_page(oq->dev, oq->desc_ring[*read_idx].buffer_ptr,
355+
PAGE_SIZE, DMA_FROM_DEVICE);
356+
buff_info->page = NULL;
357+
(*read_idx)++;
358+
(*desc_used)++;
359+
if (*read_idx == oq->max_count)
360+
*read_idx = 0;
361+
}
362+
339363
/**
340364
* __octep_oq_process_rx() - Process hardware Rx queue and push to stack.
341365
*
@@ -367,10 +391,7 @@ static int __octep_oq_process_rx(struct octep_device *oct,
367391
desc_used = 0;
368392
for (pkt = 0; pkt < pkts_to_process; pkt++) {
369393
buff_info = (struct octep_rx_buffer *)&oq->buff_info[read_idx];
370-
dma_unmap_page(oq->dev, oq->desc_ring[read_idx].buffer_ptr,
371-
PAGE_SIZE, DMA_FROM_DEVICE);
372394
resp_hw = page_address(buff_info->page);
373-
buff_info->page = NULL;
374395

375396
/* Swap the length field that is in Big-Endian to CPU */
376397
buff_info->len = be64_to_cpu(resp_hw->length);
@@ -394,36 +415,27 @@ static int __octep_oq_process_rx(struct octep_device *oct,
394415
data_offset = OCTEP_OQ_RESP_HW_SIZE;
395416
rx_ol_flags = 0;
396417
}
418+
419+
octep_oq_next_pkt(oq, buff_info, &read_idx, &desc_used);
420+
421+
skb = build_skb((void *)resp_hw, PAGE_SIZE);
422+
skb_reserve(skb, data_offset);
423+
397424
rx_bytes += buff_info->len;
398425

399426
if (buff_info->len <= oq->max_single_buffer_size) {
400-
skb = build_skb((void *)resp_hw, PAGE_SIZE);
401-
skb_reserve(skb, data_offset);
402427
skb_put(skb, buff_info->len);
403-
read_idx++;
404-
desc_used++;
405-
if (read_idx == oq->max_count)
406-
read_idx = 0;
407428
} else {
408429
struct skb_shared_info *shinfo;
409430
u16 data_len;
410431

411-
skb = build_skb((void *)resp_hw, PAGE_SIZE);
412-
skb_reserve(skb, data_offset);
413432
/* Head fragment includes response header(s);
414433
* subsequent fragments contains only data.
415434
*/
416435
skb_put(skb, oq->max_single_buffer_size);
417-
read_idx++;
418-
desc_used++;
419-
if (read_idx == oq->max_count)
420-
read_idx = 0;
421-
422436
shinfo = skb_shinfo(skb);
423437
data_len = buff_info->len - oq->max_single_buffer_size;
424438
while (data_len) {
425-
dma_unmap_page(oq->dev, oq->desc_ring[read_idx].buffer_ptr,
426-
PAGE_SIZE, DMA_FROM_DEVICE);
427439
buff_info = (struct octep_rx_buffer *)
428440
&oq->buff_info[read_idx];
429441
if (data_len < oq->buffer_size) {
@@ -438,11 +450,8 @@ static int __octep_oq_process_rx(struct octep_device *oct,
438450
buff_info->page, 0,
439451
buff_info->len,
440452
buff_info->len);
441-
buff_info->page = NULL;
442-
read_idx++;
443-
desc_used++;
444-
if (read_idx == oq->max_count)
445-
read_idx = 0;
453+
454+
octep_oq_next_pkt(oq, buff_info, &read_idx, &desc_used);
446455
}
447456
}
448457

0 commit comments

Comments
 (0)