Commit 812270e5 authored by Matt Kline's avatar Matt Kline Committed by Marc Kleine-Budde

can: m_can: Batch FIFO writes during CAN transmit

Give FIFO writes the same treatment as reads to avoid fixed costs of
individual transfers on a slow bus (e.g., tcan4x5x).

Link: https://lore.kernel.org/r/20210817050853.14875-4-matt@bitbashing.ioSigned-off-by: default avatarMatt Kline <matt@bitbashing.io>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 1aa6772f
...@@ -279,7 +279,7 @@ enum m_can_reg { ...@@ -279,7 +279,7 @@ enum m_can_reg {
/* Message RAM Elements */ /* Message RAM Elements */
#define M_CAN_FIFO_ID 0x0 #define M_CAN_FIFO_ID 0x0
#define M_CAN_FIFO_DLC 0x4 #define M_CAN_FIFO_DLC 0x4
#define M_CAN_FIFO_DATA(n) (0x8 + ((n) << 2)) #define M_CAN_FIFO_DATA 0x8
/* Rx Buffer Element */ /* Rx Buffer Element */
/* R0 */ /* R0 */
...@@ -514,7 +514,7 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs) ...@@ -514,7 +514,7 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
if (fifo_header.dlc & RX_BUF_BRS) if (fifo_header.dlc & RX_BUF_BRS)
cf->flags |= CANFD_BRS; cf->flags |= CANFD_BRS;
err = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_DATA(0), err = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_DATA,
cf->data, DIV_ROUND_UP(cf->len, 4)); cf->data, DIV_ROUND_UP(cf->len, 4));
if (err) if (err)
goto out_fail; goto out_fail;
...@@ -1588,8 +1588,9 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) ...@@ -1588,8 +1588,9 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data; struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data;
struct net_device *dev = cdev->net; struct net_device *dev = cdev->net;
struct sk_buff *skb = cdev->tx_skb; struct sk_buff *skb = cdev->tx_skb;
u32 id, dlc, cccr, fdflags; struct id_and_dlc fifo_header;
int i, err; u32 cccr, fdflags;
int err;
int putidx; int putidx;
cdev->tx_skb = NULL; cdev->tx_skb = NULL;
...@@ -1597,34 +1598,30 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) ...@@ -1597,34 +1598,30 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
/* Generate ID field for TX buffer Element */ /* Generate ID field for TX buffer Element */
/* Common to all supported M_CAN versions */ /* Common to all supported M_CAN versions */
if (cf->can_id & CAN_EFF_FLAG) { if (cf->can_id & CAN_EFF_FLAG) {
id = cf->can_id & CAN_EFF_MASK; fifo_header.id = cf->can_id & CAN_EFF_MASK;
id |= TX_BUF_XTD; fifo_header.id |= TX_BUF_XTD;
} else { } else {
id = ((cf->can_id & CAN_SFF_MASK) << 18); fifo_header.id = ((cf->can_id & CAN_SFF_MASK) << 18);
} }
if (cf->can_id & CAN_RTR_FLAG) if (cf->can_id & CAN_RTR_FLAG)
id |= TX_BUF_RTR; fifo_header.id |= TX_BUF_RTR;
if (cdev->version == 30) { if (cdev->version == 30) {
netif_stop_queue(dev); netif_stop_queue(dev);
/* message ram configuration */ fifo_header.dlc = can_fd_len2dlc(cf->len) << 16;
err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, &id, 1);
/* Write the frame ID, DLC, and payload to the FIFO element. */
err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, &fifo_header, 2);
if (err) if (err)
goto out_fail; goto out_fail;
dlc = can_fd_len2dlc(cf->len) << 16; err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_DATA,
err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_DLC, &dlc, 1); cf->data, DIV_ROUND_UP(cf->len, 4));
if (err) if (err)
goto out_fail; goto out_fail;
for (i = 0; i < cf->len; i += 4) {
err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_DATA(i / 4), cf->data + i, 1);
if (err)
goto out_fail;
}
can_put_echo_skb(skb, dev, 0, 0); can_put_echo_skb(skb, dev, 0, 0);
if (cdev->can.ctrlmode & CAN_CTRLMODE_FD) { if (cdev->can.ctrlmode & CAN_CTRLMODE_FD) {
...@@ -1667,10 +1664,11 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) ...@@ -1667,10 +1664,11 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
/* get put index for frame */ /* get put index for frame */
putidx = FIELD_GET(TXFQS_TFQPI_MASK, putidx = FIELD_GET(TXFQS_TFQPI_MASK,
m_can_read(cdev, M_CAN_TXFQS)); m_can_read(cdev, M_CAN_TXFQS));
/* Write ID Field to FIFO Element */
err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_ID, &id, 1); /* Construct DLC Field, with CAN-FD configuration.
if (err) * Use the put index of the fifo as the message marker,
goto out_fail; * used in the TX interrupt for sending the correct echo frame.
*/
/* get CAN FD configuration of frame */ /* get CAN FD configuration of frame */
fdflags = 0; fdflags = 0;
...@@ -1680,24 +1678,17 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) ...@@ -1680,24 +1678,17 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
fdflags |= TX_BUF_BRS; fdflags |= TX_BUF_BRS;
} }
/* Construct DLC Field. Also contains CAN-FD configuration fifo_header.dlc = FIELD_PREP(TX_BUF_MM_MASK, putidx) |
* use put index of fifo as message marker
* it is used in TX interrupt for
* sending the correct echo frame
*/
dlc = FIELD_PREP(TX_BUF_MM_MASK, putidx) |
FIELD_PREP(TX_BUF_DLC_MASK, can_fd_len2dlc(cf->len)) | FIELD_PREP(TX_BUF_DLC_MASK, can_fd_len2dlc(cf->len)) |
fdflags | TX_BUF_EFC; fdflags | TX_BUF_EFC;
err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_DLC, &dlc, 1); err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_ID, &fifo_header, 2);
if (err) if (err)
goto out_fail; goto out_fail;
for (i = 0; i < cf->len; i += 4) { err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_DATA,
err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_DATA(i / 4), cf->data, DIV_ROUND_UP(cf->len, 4));
cf->data + i, 1); if (err)
if (err) goto out_fail;
goto out_fail;
}
/* Push loopback echo. /* Push loopback echo.
* Will be looped back on TX interrupt based on message marker * Will be looped back on TX interrupt based on message marker
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment