drivers/net/can/dummy_can.c
Source file repositories/reference/linux-study-clean/drivers/net/can/dummy_can.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/can/dummy_can.c- Extension
.c- Size
- 7439 bytes
- Lines
- 287
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/array_size.hlinux/errno.hlinux/init.hlinux/kernel.hlinux/module.hlinux/netdevice.hlinux/units.hlinux/string_choices.hlinux/can.hlinux/can/bittiming.hlinux/can/dev.hlinux/can/skb.h
Detected Declarations
struct dummy_canfunction dummy_can_print_bittimingfunction dummy_can_print_tdcfunction dummy_can_print_pwmfunction dummy_can_print_ctrlmodefunction dummy_can_print_bittiming_infofunction dummy_can_netdev_openfunction dummy_can_netdev_closefunction dummy_can_start_xmitfunction dummy_can_initfunction dummy_can_exitmodule init dummy_can_init
Annotated Snippet
static const struct net_device_ops dummy_can_netdev_ops = {
.ndo_open = dummy_can_netdev_open,
.ndo_stop = dummy_can_netdev_close,
.ndo_start_xmit = dummy_can_start_xmit,
};
static const struct ethtool_ops dummy_can_ethtool_ops = {
.get_ts_info = ethtool_op_get_ts_info,
};
static int __init dummy_can_init(void)
{
struct net_device *dev;
struct dummy_can *priv;
int ret;
dev = alloc_candev(sizeof(*priv), 1);
if (!dev)
return -ENOMEM;
dev->netdev_ops = &dummy_can_netdev_ops;
dev->ethtool_ops = &dummy_can_ethtool_ops;
dev->flags |= IFF_ECHO; /* enable echo handling */
priv = netdev_priv(dev);
priv->can.bittiming_const = &dummy_can_bittiming_const;
priv->can.bitrate_max = 20 * MEGA /* BPS */;
priv->can.clock.freq = 160 * MEGA /* Hz */;
priv->can.fd.data_bittiming_const = &dummy_can_fd_databittiming_const;
priv->can.fd.tdc_const = &dummy_can_fd_tdc_const;
priv->can.xl.data_bittiming_const = &dummy_can_xl_databittiming_const;
priv->can.xl.tdc_const = &dummy_can_xl_tdc_const;
priv->can.xl.pwm_const = &dummy_can_pwm_const;
priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
CAN_CTRLMODE_FD | CAN_CTRLMODE_TDC_AUTO |
CAN_CTRLMODE_RESTRICTED | CAN_CTRLMODE_XL |
CAN_CTRLMODE_XL_TDC_AUTO | CAN_CTRLMODE_XL_TMS;
priv->dev = dev;
ret = register_candev(priv->dev);
if (ret) {
free_candev(priv->dev);
return ret;
}
dummy_can = priv;
netdev_dbg(dev, "dummy-can ready\n");
return 0;
}
static void __exit dummy_can_exit(void)
{
struct net_device *dev = dummy_can->dev;
netdev_dbg(dev, "dummy-can bye bye\n");
unregister_candev(dev);
free_candev(dev);
}
module_init(dummy_can_init);
module_exit(dummy_can_exit);
MODULE_DESCRIPTION("A dummy CAN driver, mainly to test the netlink interface");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Vincent Mailhol <mailhol@kernel.org>");
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/errno.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/netdevice.h`, `linux/units.h`, `linux/string_choices.h`.
- Detected declarations: `struct dummy_can`, `function dummy_can_print_bittiming`, `function dummy_can_print_tdc`, `function dummy_can_print_pwm`, `function dummy_can_print_ctrlmode`, `function dummy_can_print_bittiming_info`, `function dummy_can_netdev_open`, `function dummy_can_netdev_close`, `function dummy_can_start_xmit`, `function dummy_can_init`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
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.