drivers/net/can/usb/nct6694_canfd.c
Source file repositories/reference/linux-study-clean/drivers/net/can/usb/nct6694_canfd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/can/usb/nct6694_canfd.c- Extension
.c- Size
- 21297 bytes
- Lines
- 832
- 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.
- 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/can/rx-offload.hlinux/ethtool.hlinux/idr.hlinux/irqdomain.hlinux/kernel.hlinux/mfd/nct6694.hlinux/module.hlinux/netdevice.hlinux/platform_device.h
Detected Declarations
struct nct6694_canfd_privenum nct6694_event_errenum nct6694_event_statusfunction nct6694_canfd_rx_offloadfunction nct6694_canfd_handle_lost_msgfunction nct6694_canfd_handle_rxfunction nct6694_canfd_get_berr_counterfunction nct6694_canfd_handle_state_changefunction nct6694_canfd_handle_bus_errfunction nct6694_canfd_handle_txfunction nct6694_canfd_irqfunction nct6694_canfd_tx_workfunction nct6694_canfd_start_xmitfunction nct6694_canfd_startfunction nct6694_canfd_stopfunction nct6694_canfd_closefunction nct6694_canfd_set_modefunction nct6694_canfd_openfunction nct6694_canfd_get_clockfunction nct6694_canfd_probefunction nct6694_canfd_remove
Annotated Snippet
static const struct net_device_ops nct6694_canfd_netdev_ops = {
.ndo_open = nct6694_canfd_open,
.ndo_stop = nct6694_canfd_close,
.ndo_start_xmit = nct6694_canfd_start_xmit,
};
static const struct ethtool_ops nct6694_canfd_ethtool_ops = {
.get_ts_info = ethtool_op_get_ts_info,
};
static int nct6694_canfd_get_clock(struct nct6694_canfd_priv *priv)
{
struct nct6694_canfd_information *info __free(kfree) = NULL;
static const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_CANFD_MOD,
.cmd = NCT6694_CANFD_INFORMATION,
.sel = NCT6694_CANFD_INFORMATION_SEL,
.len = cpu_to_le16(sizeof(*info))
};
int ret;
info = kzalloc_obj(*info);
if (!info)
return -ENOMEM;
ret = nct6694_read_msg(priv->nct6694, &cmd_hd, info);
if (ret)
return ret;
return le32_to_cpu(info->can_clk);
}
static int nct6694_canfd_probe(struct platform_device *pdev)
{
struct nct6694 *nct6694 = dev_get_drvdata(pdev->dev.parent);
struct nct6694_canfd_priv *priv;
struct net_device *ndev;
int port, irq, ret, can_clk;
port = ida_alloc(&nct6694->canfd_ida, GFP_KERNEL);
if (port < 0)
return port;
irq = irq_create_mapping(nct6694->domain,
NCT6694_IRQ_CAN0 + port);
if (!irq) {
ret = -EINVAL;
goto free_ida;
}
ndev = alloc_candev(sizeof(struct nct6694_canfd_priv), 1);
if (!ndev) {
ret = -ENOMEM;
goto dispose_irq;
}
ndev->irq = irq;
ndev->flags |= IFF_ECHO;
ndev->dev_port = port;
ndev->netdev_ops = &nct6694_canfd_netdev_ops;
ndev->ethtool_ops = &nct6694_canfd_ethtool_ops;
priv = netdev_priv(ndev);
priv->nct6694 = nct6694;
priv->ndev = ndev;
can_clk = nct6694_canfd_get_clock(priv);
if (can_clk < 0) {
ret = dev_err_probe(&pdev->dev, can_clk,
"Failed to get clock\n");
goto free_candev;
}
INIT_WORK(&priv->tx_work, nct6694_canfd_tx_work);
priv->can.clock.freq = can_clk;
priv->can.bittiming_const = &nct6694_canfd_bittiming_nominal_const;
priv->can.fd.data_bittiming_const = &nct6694_canfd_bittiming_data_const;
priv->can.do_set_mode = nct6694_canfd_set_mode;
priv->can.do_get_berr_counter = nct6694_canfd_get_berr_counter;
priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_BERR_REPORTING |
CAN_CTRLMODE_FD_NON_ISO;
ret = can_set_static_ctrlmode(ndev, CAN_CTRLMODE_FD);
if (ret)
goto free_candev;
ret = can_rx_offload_add_manual(ndev, &priv->offload,
NCT6694_NAPI_WEIGHT);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/can/dev.h`, `linux/can/rx-offload.h`, `linux/ethtool.h`, `linux/idr.h`, `linux/irqdomain.h`, `linux/kernel.h`, `linux/mfd/nct6694.h`.
- Detected declarations: `struct nct6694_canfd_priv`, `enum nct6694_event_err`, `enum nct6694_event_status`, `function nct6694_canfd_rx_offload`, `function nct6694_canfd_handle_lost_msg`, `function nct6694_canfd_handle_rx`, `function nct6694_canfd_get_berr_counter`, `function nct6694_canfd_handle_state_change`, `function nct6694_canfd_handle_bus_err`, `function nct6694_canfd_handle_tx`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- 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.