Skip to content

Commit e55b963

Browse files
scosumarckleinebudde
authored andcommitted
can: m_can: Add tx coalescing ethtool support
Add TX support to get/set functions for ethtool coalescing. tx-frames-irq and tx-usecs-irq can only be set/unset together. tx-frames-irq needs to be less than TXE and TXB. As rx and tx share the same timer, rx-usecs-irq and tx-usecs-irq can be enabled/disabled individually but they need to have the same value if enabled. Polling is excluded from TX irq coalescing. Signed-off-by: Markus Schneider-Pargmann <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 9515223 commit e55b963

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

drivers/net/can/m_can/m_can.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,8 @@ static int m_can_get_coalesce(struct net_device *dev,
19861986

19871987
ec->rx_max_coalesced_frames_irq = cdev->rx_max_coalesced_frames_irq;
19881988
ec->rx_coalesce_usecs_irq = cdev->rx_coalesce_usecs_irq;
1989+
ec->tx_max_coalesced_frames_irq = cdev->tx_max_coalesced_frames_irq;
1990+
ec->tx_coalesce_usecs_irq = cdev->tx_coalesce_usecs_irq;
19891991

19901992
return 0;
19911993
}
@@ -2012,16 +2014,50 @@ static int m_can_set_coalesce(struct net_device *dev,
20122014
netdev_err(dev, "rx-frames-irq and rx-usecs-irq can only be set together\n");
20132015
return -EINVAL;
20142016
}
2017+
if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXE].num) {
2018+
netdev_err(dev, "tx-frames-irq %u greater than the TX event FIFO %u\n",
2019+
ec->tx_max_coalesced_frames_irq,
2020+
cdev->mcfg[MRAM_TXE].num);
2021+
return -EINVAL;
2022+
}
2023+
if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXB].num) {
2024+
netdev_err(dev, "tx-frames-irq %u greater than the TX FIFO %u\n",
2025+
ec->tx_max_coalesced_frames_irq,
2026+
cdev->mcfg[MRAM_TXB].num);
2027+
return -EINVAL;
2028+
}
2029+
if ((ec->tx_max_coalesced_frames_irq == 0) != (ec->tx_coalesce_usecs_irq == 0)) {
2030+
netdev_err(dev, "tx-frames-irq and tx-usecs-irq can only be set together\n");
2031+
return -EINVAL;
2032+
}
2033+
if (ec->rx_coalesce_usecs_irq != 0 && ec->tx_coalesce_usecs_irq != 0 &&
2034+
ec->rx_coalesce_usecs_irq != ec->tx_coalesce_usecs_irq) {
2035+
netdev_err(dev, "rx-usecs-irq %u needs to be equal to tx-usecs-irq %u if both are enabled\n",
2036+
ec->rx_coalesce_usecs_irq,
2037+
ec->tx_coalesce_usecs_irq);
2038+
return -EINVAL;
2039+
}
20152040

20162041
cdev->rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
20172042
cdev->rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
2043+
cdev->tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
2044+
cdev->tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
2045+
2046+
if (cdev->rx_coalesce_usecs_irq)
2047+
cdev->irq_timer_wait =
2048+
ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC);
2049+
else
2050+
cdev->irq_timer_wait =
2051+
ns_to_ktime(cdev->tx_coalesce_usecs_irq * NSEC_PER_USEC);
20182052

20192053
return 0;
20202054
}
20212055

20222056
static const struct ethtool_ops m_can_ethtool_ops = {
20232057
.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ |
2024-
ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ,
2058+
ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ |
2059+
ETHTOOL_COALESCE_TX_USECS_IRQ |
2060+
ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ,
20252061
.get_ts_info = ethtool_op_get_ts_info,
20262062
.get_coalesce = m_can_get_coalesce,
20272063
.set_coalesce = m_can_set_coalesce,

0 commit comments

Comments
 (0)