drivers/net/can/bxcan.c
Source file repositories/reference/linux-study-clean/drivers/net/can/bxcan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/can/bxcan.c- Extension
.c- Size
- 27756 bytes
- Lines
- 1102
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/can.hlinux/can/dev.hlinux/can/error.hlinux/can/rx-offload.hlinux/clk.hlinux/ethtool.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/mfd/syscon.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct bxcan_mbstruct bxcan_regsstruct bxcan_privenum bxcan_lec_codeenum bxcan_cfgfunction bxcan_rmwfunction bxcan_disable_filtersfunction bxcan_enable_filtersfunction bxcan_get_tx_headfunction bxcan_get_tx_tailfunction bxcan_get_tx_freefunction bxcan_tx_busyfunction bxcan_chip_softresetfunction bxcan_enter_init_modefunction bxcan_leave_init_modefunction bxcan_enter_sleep_modefunction bxcan_leave_sleep_modefunction bxcan_rx_isrfunction bxcan_tx_isrfunction bxcan_handle_state_changefunction bxcan_handle_bus_errfunction bxcan_state_change_isrfunction bxcan_chip_startfunction bxcan_openfunction bxcan_chip_stopfunction bxcan_stopfunction bxcan_start_xmitfunction bxcan_do_set_modefunction bxcan_get_berr_counterfunction bxcan_probefunction bxcan_removefunction bxcan_suspendfunction bxcan_resume
Annotated Snippet
static const struct net_device_ops bxcan_netdev_ops = {
.ndo_open = bxcan_open,
.ndo_stop = bxcan_stop,
.ndo_start_xmit = bxcan_start_xmit,
};
static const struct ethtool_ops bxcan_ethtool_ops = {
.get_ts_info = ethtool_op_get_ts_info,
};
static int bxcan_do_set_mode(struct net_device *ndev, enum can_mode mode)
{
int err;
switch (mode) {
case CAN_MODE_START:
err = bxcan_chip_start(ndev);
if (err)
return err;
netif_wake_queue(ndev);
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static int bxcan_get_berr_counter(const struct net_device *ndev,
struct can_berr_counter *bec)
{
struct bxcan_priv *priv = netdev_priv(ndev);
struct bxcan_regs __iomem *regs = priv->regs;
u32 esr;
int err;
err = clk_prepare_enable(priv->clk);
if (err)
return err;
esr = readl(®s->esr);
bec->txerr = FIELD_GET(BXCAN_ESR_TEC_MASK, esr);
bec->rxerr = FIELD_GET(BXCAN_ESR_REC_MASK, esr);
clk_disable_unprepare(priv->clk);
return 0;
}
static int bxcan_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct device *dev = &pdev->dev;
struct net_device *ndev;
struct bxcan_priv *priv;
struct clk *clk = NULL;
void __iomem *regs;
struct regmap *gcan;
enum bxcan_cfg cfg;
int err, rx_irq, tx_irq, sce_irq;
regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(regs)) {
dev_err(dev, "failed to get base address\n");
return PTR_ERR(regs);
}
gcan = syscon_regmap_lookup_by_phandle(np, "st,gcan");
if (IS_ERR(gcan)) {
dev_err(dev, "failed to get shared memory base address\n");
return PTR_ERR(gcan);
}
if (of_property_read_bool(np, "st,can-primary"))
cfg = BXCAN_CFG_DUAL_PRIMARY;
else if (of_property_read_bool(np, "st,can-secondary"))
cfg = BXCAN_CFG_DUAL_SECONDARY;
else
cfg = BXCAN_CFG_SINGLE;
clk = devm_clk_get(dev, NULL);
if (IS_ERR(clk)) {
dev_err(dev, "failed to get clock\n");
return PTR_ERR(clk);
}
rx_irq = platform_get_irq_byname(pdev, "rx0");
if (rx_irq < 0)
return rx_irq;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/can.h`, `linux/can/dev.h`, `linux/can/error.h`, `linux/can/rx-offload.h`, `linux/clk.h`, `linux/ethtool.h`, `linux/interrupt.h`.
- Detected declarations: `struct bxcan_mb`, `struct bxcan_regs`, `struct bxcan_priv`, `enum bxcan_lec_code`, `enum bxcan_cfg`, `function bxcan_rmw`, `function bxcan_disable_filters`, `function bxcan_enable_filters`, `function bxcan_get_tx_head`, `function bxcan_get_tx_tail`.
- 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.