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.

Dependency Surface

Detected Declarations

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

Implementation Notes