drivers/net/can/peak_canfd/peak_canfd.c

Source file repositories/reference/linux-study-clean/drivers/net/can/peak_canfd/peak_canfd.c

File Facts

System
Linux kernel
Corpus path
drivers/net/can/peak_canfd/peak_canfd.c
Extension
.c
Size
20409 bytes
Lines
837
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 peak_canfd_netdev_ops = {
	.ndo_open = peak_canfd_open,
	.ndo_stop = peak_canfd_close,
	.ndo_start_xmit = peak_canfd_start_xmit,
	.ndo_hwtstamp_get = peak_eth_hwtstamp_get,
	.ndo_hwtstamp_set = peak_eth_hwtstamp_set,
};

static int peak_get_ts_info(struct net_device *dev,
			    struct kernel_ethtool_ts_info *info)
{
	info->so_timestamping =
		SOF_TIMESTAMPING_TX_SOFTWARE |
		SOF_TIMESTAMPING_RX_HARDWARE |
		SOF_TIMESTAMPING_RAW_HARDWARE;
	info->tx_types = BIT(HWTSTAMP_TX_OFF);
	info->rx_filters = BIT(HWTSTAMP_FILTER_ALL);

	return 0;
}

static const struct ethtool_ops peak_canfd_ethtool_ops = {
	.get_ts_info = peak_get_ts_info,
};

struct net_device *alloc_peak_canfd_dev(int sizeof_priv, int index,
					int echo_skb_max)
{
	struct net_device *ndev;
	struct peak_canfd_priv *priv;

	/* we DO support local echo */
	if (echo_skb_max < 0)
		echo_skb_max = PCANFD_ECHO_SKB_MAX;

	/* allocate the candev object */
	ndev = alloc_candev(sizeof_priv, echo_skb_max);
	if (!ndev)
		return NULL;

	priv = netdev_priv(ndev);

	/* complete now socket-can initialization side */
	priv->can.state = CAN_STATE_STOPPED;
	priv->can.bittiming_const = &peak_canfd_nominal_const;
	priv->can.fd.data_bittiming_const = &peak_canfd_data_const;

	priv->can.do_set_mode = peak_canfd_set_mode;
	priv->can.do_get_berr_counter = peak_canfd_get_berr_counter;
	priv->can.do_set_bittiming = peak_canfd_set_bittiming;
	priv->can.fd.do_set_data_bittiming = peak_canfd_set_data_bittiming;
	priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
				       CAN_CTRLMODE_LISTENONLY |
				       CAN_CTRLMODE_3_SAMPLES |
				       CAN_CTRLMODE_FD |
				       CAN_CTRLMODE_FD_NON_ISO |
				       CAN_CTRLMODE_BERR_REPORTING;

	priv->ndev = ndev;
	priv->index = index;
	priv->cmd_len = 0;
	spin_lock_init(&priv->echo_lock);

	ndev->flags |= IFF_ECHO;
	ndev->netdev_ops = &peak_canfd_netdev_ops;
	ndev->ethtool_ops = &peak_canfd_ethtool_ops;
	ndev->dev_id = index;

	return ndev;
}

Annotation

Implementation Notes