drivers/net/can/mscan/mscan.c
Source file repositories/reference/linux-study-clean/drivers/net/can/mscan/mscan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/can/mscan/mscan.c- Extension
.c- Size
- 17503 bytes
- Lines
- 699
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/interrupt.hlinux/delay.hlinux/netdevice.hlinux/if_arp.hlinux/if_ether.hlinux/list.hlinux/can/dev.hlinux/can/error.hlinux/io.hmscan.h
Detected Declarations
function mscan_set_modefunction mscan_startfunction mscan_restartfunction mscan_start_xmitfunction get_new_statefunction mscan_get_rx_framefunction mscan_get_err_framefunction mscan_rx_pollfunction mscan_isrfunction list_for_each_safefunction mscan_do_set_modefunction mscan_do_set_bittimingfunction mscan_get_berr_counterfunction mscan_openfunction mscan_closefunction register_mscandevfunction unregister_mscandev
Annotated Snippet
static const struct net_device_ops mscan_netdev_ops = {
.ndo_open = mscan_open,
.ndo_stop = mscan_close,
.ndo_start_xmit = mscan_start_xmit,
};
static const struct ethtool_ops mscan_ethtool_ops = {
.get_ts_info = ethtool_op_get_ts_info,
};
int register_mscandev(struct net_device *dev, int mscan_clksrc)
{
struct mscan_priv *priv = netdev_priv(dev);
struct mscan_regs __iomem *regs = priv->reg_base;
u8 ctl1;
ctl1 = in_8(®s->canctl1);
if (mscan_clksrc)
ctl1 |= MSCAN_CLKSRC;
else
ctl1 &= ~MSCAN_CLKSRC;
if (priv->type == MSCAN_TYPE_MPC5121) {
priv->can.do_get_berr_counter = mscan_get_berr_counter;
ctl1 |= MSCAN_BORM; /* bus-off recovery upon request */
}
ctl1 |= MSCAN_CANE;
out_8(®s->canctl1, ctl1);
udelay(100);
/* acceptance mask/acceptance code (accept everything) */
out_be16(®s->canidar1_0, 0);
out_be16(®s->canidar3_2, 0);
out_be16(®s->canidar5_4, 0);
out_be16(®s->canidar7_6, 0);
out_be16(®s->canidmr1_0, 0xffff);
out_be16(®s->canidmr3_2, 0xffff);
out_be16(®s->canidmr5_4, 0xffff);
out_be16(®s->canidmr7_6, 0xffff);
/* Two 32 bit Acceptance Filters */
out_8(®s->canidac, MSCAN_AF_32BIT);
mscan_set_mode(dev, MSCAN_INIT_MODE);
return register_candev(dev);
}
void unregister_mscandev(struct net_device *dev)
{
struct mscan_priv *priv = netdev_priv(dev);
struct mscan_regs __iomem *regs = priv->reg_base;
mscan_set_mode(dev, MSCAN_INIT_MODE);
clrbits8(®s->canctl1, MSCAN_CANE);
unregister_candev(dev);
}
struct net_device *alloc_mscandev(void)
{
struct net_device *dev;
struct mscan_priv *priv;
int i;
dev = alloc_candev(sizeof(struct mscan_priv), MSCAN_ECHO_SKB_MAX);
if (!dev)
return NULL;
priv = netdev_priv(dev);
dev->netdev_ops = &mscan_netdev_ops;
dev->ethtool_ops = &mscan_ethtool_ops;
dev->flags |= IFF_ECHO; /* we support local echo */
netif_napi_add_weight(dev, &priv->napi, mscan_rx_poll, 8);
priv->can.bittiming_const = &mscan_bittiming_const;
priv->can.do_set_bittiming = mscan_do_set_bittiming;
priv->can.do_set_mode = mscan_do_set_mode;
priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
CAN_CTRLMODE_LISTENONLY;
for (i = 0; i < TX_QUEUE_SIZE; i++) {
priv->tx_queue[i].id = i;
priv->tx_queue[i].mask = 1 << i;
}
return dev;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/netdevice.h`, `linux/if_arp.h`, `linux/if_ether.h`, `linux/list.h`.
- Detected declarations: `function mscan_set_mode`, `function mscan_start`, `function mscan_restart`, `function mscan_start_xmit`, `function get_new_state`, `function mscan_get_rx_frame`, `function mscan_get_err_frame`, `function mscan_rx_poll`, `function mscan_isr`, `function list_for_each_safe`.
- 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.