drivers/net/can/m_can/m_can.c
Source file repositories/reference/linux-study-clean/drivers/net/can/m_can/m_can.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/can/m_can/m_can.c- Extension
.c- Size
- 69222 bytes
- Lines
- 2681
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/can/dev.hlinux/ethtool.hlinux/hrtimer.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/module.hlinux/netdevice.hlinux/of.hlinux/phy/phy.hlinux/pinctrl/consumer.hlinux/platform_device.hlinux/pm_runtime.hlinux/reset.hm_can.h
Detected Declarations
struct id_and_dlcstruct m_can_fifo_elementenum m_can_regfunction m_can_readfunction m_can_writefunction m_can_fifo_readfunction m_can_fifo_writefunction m_can_fifo_write_no_offfunction m_can_txe_fifo_readfunction m_can_cccr_update_bitsfunction m_can_config_enablefunction m_can_config_disablefunction m_can_interrupt_enablefunction m_can_coalescing_disablefunction m_can_enable_all_interruptsfunction m_can_disable_all_interruptsfunction m_can_get_timestampfunction m_can_cleanfunction m_can_receive_skbfunction m_can_read_fifofunction m_can_do_rx_pollfunction m_can_handle_lost_msgfunction m_can_handle_lec_errfunction __m_can_get_berr_counterfunction m_can_clk_startfunction m_can_clk_stopfunction m_can_get_berr_counterfunction m_can_handle_state_changefunction m_can_state_get_by_psrfunction m_can_handle_state_errorsfunction m_can_handle_other_errfunction is_lec_errfunction m_can_is_protocol_errfunction m_can_handle_protocol_errorfunction m_can_handle_bus_errorsfunction m_can_rx_handlerfunction m_can_readfunction m_can_pollfunction m_can_tx_update_statsfunction m_can_finish_txfunction m_can_start_txfunction m_can_echo_tx_eventfunction m_can_coalescing_updatefunction m_can_interrupt_handlerfunction m_can_isrfunction m_can_coalescing_timerfunction m_can_init_ramfunction m_can_set_bittiming
Annotated Snippet
static const struct net_device_ops m_can_netdev_ops = {
.ndo_open = m_can_open,
.ndo_stop = m_can_close,
.ndo_start_xmit = m_can_start_xmit,
};
static int m_can_get_coalesce(struct net_device *dev,
struct ethtool_coalesce *ec,
struct kernel_ethtool_coalesce *kec,
struct netlink_ext_ack *ext_ack)
{
struct m_can_classdev *cdev = netdev_priv(dev);
ec->rx_max_coalesced_frames_irq = cdev->rx_max_coalesced_frames_irq;
ec->rx_coalesce_usecs_irq = cdev->rx_coalesce_usecs_irq;
ec->tx_max_coalesced_frames = cdev->tx_max_coalesced_frames;
ec->tx_max_coalesced_frames_irq = cdev->tx_max_coalesced_frames_irq;
ec->tx_coalesce_usecs_irq = cdev->tx_coalesce_usecs_irq;
return 0;
}
static int m_can_set_coalesce(struct net_device *dev,
struct ethtool_coalesce *ec,
struct kernel_ethtool_coalesce *kec,
struct netlink_ext_ack *ext_ack)
{
struct m_can_classdev *cdev = netdev_priv(dev);
if (cdev->can.state != CAN_STATE_STOPPED) {
netdev_err(dev, "Device is in use, please shut it down first\n");
return -EBUSY;
}
if (ec->rx_max_coalesced_frames_irq > cdev->mcfg[MRAM_RXF0].num) {
netdev_err(dev, "rx-frames-irq %u greater than the RX FIFO %u\n",
ec->rx_max_coalesced_frames_irq,
cdev->mcfg[MRAM_RXF0].num);
return -EINVAL;
}
if ((ec->rx_max_coalesced_frames_irq == 0) != (ec->rx_coalesce_usecs_irq == 0)) {
netdev_err(dev, "rx-frames-irq and rx-usecs-irq can only be set together\n");
return -EINVAL;
}
if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXE].num) {
netdev_err(dev, "tx-frames-irq %u greater than the TX event FIFO %u\n",
ec->tx_max_coalesced_frames_irq,
cdev->mcfg[MRAM_TXE].num);
return -EINVAL;
}
if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXB].num) {
netdev_err(dev, "tx-frames-irq %u greater than the TX FIFO %u\n",
ec->tx_max_coalesced_frames_irq,
cdev->mcfg[MRAM_TXB].num);
return -EINVAL;
}
if ((ec->tx_max_coalesced_frames_irq == 0) != (ec->tx_coalesce_usecs_irq == 0)) {
netdev_err(dev, "tx-frames-irq and tx-usecs-irq can only be set together\n");
return -EINVAL;
}
if (ec->tx_max_coalesced_frames > cdev->mcfg[MRAM_TXE].num) {
netdev_err(dev, "tx-frames %u greater than the TX event FIFO %u\n",
ec->tx_max_coalesced_frames,
cdev->mcfg[MRAM_TXE].num);
return -EINVAL;
}
if (ec->tx_max_coalesced_frames > cdev->mcfg[MRAM_TXB].num) {
netdev_err(dev, "tx-frames %u greater than the TX FIFO %u\n",
ec->tx_max_coalesced_frames,
cdev->mcfg[MRAM_TXB].num);
return -EINVAL;
}
if (ec->rx_coalesce_usecs_irq != 0 && ec->tx_coalesce_usecs_irq != 0 &&
ec->rx_coalesce_usecs_irq != ec->tx_coalesce_usecs_irq) {
netdev_err(dev, "rx-usecs-irq %u needs to be equal to tx-usecs-irq %u if both are enabled\n",
ec->rx_coalesce_usecs_irq,
ec->tx_coalesce_usecs_irq);
return -EINVAL;
}
cdev->rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
cdev->rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
cdev->tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
cdev->tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
cdev->tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
if (cdev->rx_coalesce_usecs_irq)
cdev->irq_timer_wait = us_to_ktime(cdev->rx_coalesce_usecs_irq);
else
cdev->irq_timer_wait = us_to_ktime(cdev->tx_coalesce_usecs_irq);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/can/dev.h`, `linux/ethtool.h`, `linux/hrtimer.h`, `linux/interrupt.h`, `linux/io.h`, `linux/iopoll.h`, `linux/kernel.h`.
- Detected declarations: `struct id_and_dlc`, `struct m_can_fifo_element`, `enum m_can_reg`, `function m_can_read`, `function m_can_write`, `function m_can_fifo_read`, `function m_can_fifo_write`, `function m_can_fifo_write_no_off`, `function m_can_txe_fifo_read`, `function m_can_cccr_update_bits`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.