Skip to content

Commit c1eaf8b

Browse files
scosumarckleinebudde
authored andcommitted
can: m_can: Eliminate double read of TXFQS in tx_handler
The TXFQS register is read first to check if the fifo is full and then immediately again to get the putidx. This is unnecessary and adds significant overhead if read requests are done over a slow bus, for example SPI with tcan4x5x. Add a variable to store the value of the register. Split the m_can_tx_fifo_full function into two to avoid the hidden m_can_read call if not needed. 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 3abcc01 commit c1eaf8b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/net/can/m_can/m_can.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,14 @@ m_can_txe_fifo_read(struct m_can_classdev *cdev, u32 fgi, u32 offset, u32 *val)
369369
return cdev->ops->read_fifo(cdev, addr_offset, val, 1);
370370
}
371371

372+
static inline bool _m_can_tx_fifo_full(u32 txfqs)
373+
{
374+
return !!(txfqs & TXFQS_TFQF);
375+
}
376+
372377
static inline bool m_can_tx_fifo_full(struct m_can_classdev *cdev)
373378
{
374-
return !!(m_can_read(cdev, M_CAN_TXFQS) & TXFQS_TFQF);
379+
return _m_can_tx_fifo_full(m_can_read(cdev, M_CAN_TXFQS));
375380
}
376381

377382
static void m_can_config_endisable(struct m_can_classdev *cdev, bool enable)
@@ -1609,6 +1614,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
16091614
struct sk_buff *skb = cdev->tx_skb;
16101615
struct id_and_dlc fifo_header;
16111616
u32 cccr, fdflags;
1617+
u32 txfqs;
16121618
int err;
16131619
int putidx;
16141620

@@ -1665,8 +1671,10 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
16651671
} else {
16661672
/* Transmit routine for version >= v3.1.x */
16671673

1674+
txfqs = m_can_read(cdev, M_CAN_TXFQS);
1675+
16681676
/* Check if FIFO full */
1669-
if (m_can_tx_fifo_full(cdev)) {
1677+
if (_m_can_tx_fifo_full(txfqs)) {
16701678
/* This shouldn't happen */
16711679
netif_stop_queue(dev);
16721680
netdev_warn(dev,
@@ -1682,8 +1690,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
16821690
}
16831691

16841692
/* get put index for frame */
1685-
putidx = FIELD_GET(TXFQS_TFQPI_MASK,
1686-
m_can_read(cdev, M_CAN_TXFQS));
1693+
putidx = FIELD_GET(TXFQS_TFQPI_MASK, txfqs);
16871694

16881695
/* Construct DLC Field, with CAN-FD configuration.
16891696
* Use the put index of the fifo as the message marker,

0 commit comments

Comments
 (0)