Skip to content

Commit 6355a3c

Browse files
scosumarckleinebudde
authored andcommitted
can: m_can: Count read getindex in the driver
The getindex gets increased by one every time. We can calculate the correct getindex in the driver and avoid the additional reads of rxfs. Signed-off-by: Markus Schneider-Pargmann <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent d4535b9 commit 6355a3c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/net/can/m_can/m_can.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,19 +477,16 @@ static void m_can_receive_skb(struct m_can_classdev *cdev,
477477
}
478478
}
479479

480-
static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
480+
static int m_can_read_fifo(struct net_device *dev, u32 fgi)
481481
{
482482
struct net_device_stats *stats = &dev->stats;
483483
struct m_can_classdev *cdev = netdev_priv(dev);
484484
struct canfd_frame *cf;
485485
struct sk_buff *skb;
486486
struct id_and_dlc fifo_header;
487-
u32 fgi;
488487
u32 timestamp = 0;
489488
int err;
490489

491-
/* calculate the fifo get index for where to read data */
492-
fgi = FIELD_GET(RXFS_FGI_MASK, rxfs);
493490
err = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_ID, &fifo_header, 2);
494491
if (err)
495492
goto out_fail;
@@ -554,6 +551,9 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota)
554551
struct m_can_classdev *cdev = netdev_priv(dev);
555552
u32 pkts = 0;
556553
u32 rxfs;
554+
u32 rx_count;
555+
u32 fgi;
556+
int i;
557557
int err;
558558

559559
rxfs = m_can_read(cdev, M_CAN_RXF0S);
@@ -562,14 +562,17 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota)
562562
return 0;
563563
}
564564

565-
while ((rxfs & RXFS_FFL_MASK) && (quota > 0)) {
566-
err = m_can_read_fifo(dev, rxfs);
565+
rx_count = FIELD_GET(RXFS_FFL_MASK, rxfs);
566+
fgi = FIELD_GET(RXFS_FGI_MASK, rxfs);
567+
568+
for (i = 0; i < rx_count && quota > 0; ++i) {
569+
err = m_can_read_fifo(dev, fgi);
567570
if (err)
568571
return err;
569572

570573
quota--;
571574
pkts++;
572-
rxfs = m_can_read(cdev, M_CAN_RXF0S);
575+
fgi = (++fgi >= cdev->mcfg[MRAM_RXF0].num ? 0 : fgi);
573576
}
574577

575578
return pkts;

0 commit comments

Comments
 (0)