drivers/net/mctp/mctp-serial.c
Source file repositories/reference/linux-study-clean/drivers/net/mctp/mctp-serial.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mctp/mctp-serial.c- Extension
.c- Size
- 13608 bytes
- Lines
- 635
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/idr.hlinux/if_arp.hlinux/module.hlinux/skbuff.hlinux/tty.hlinux/workqueue.hlinux/crc-ccitt.hlinux/mctp.hnet/mctp.hnet/mctpdevice.hnet/pkt_sched.hkunit/test.h
Detected Declarations
struct mctp_serialstruct test_chunk_txenum mctp_serial_statefunction needs_escapefunction next_chunk_lenfunction write_chunkfunction mctp_serial_tx_workfunction mctp_serial_txfunction mctp_serial_tty_write_wakeupfunction mctp_serial_rxfunction mctp_serial_push_headerfunction mctp_serial_push_trailerfunction mctp_serial_pushfunction mctp_serial_tty_receive_buffunction mctp_serial_uninitfunction mctp_serial_setupfunction mctp_serial_openfunction mctp_serial_closefunction mctp_serial_initfunction mctp_serial_exitfunction test_next_chunk_lenmodule init mctp_serial_init
Annotated Snippet
static const struct net_device_ops mctp_serial_netdev_ops = {
.ndo_start_xmit = mctp_serial_tx,
.ndo_uninit = mctp_serial_uninit,
};
static void mctp_serial_setup(struct net_device *ndev)
{
ndev->type = ARPHRD_MCTP;
/* we limit at the fixed MTU, which is also the MCTP-standard
* baseline MTU, so is also our minimum
*/
ndev->mtu = MCTP_SERIAL_MTU;
ndev->max_mtu = MCTP_SERIAL_MTU;
ndev->min_mtu = MCTP_SERIAL_MTU;
ndev->hard_header_len = 0;
ndev->addr_len = 0;
ndev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
ndev->flags = IFF_NOARP;
ndev->netdev_ops = &mctp_serial_netdev_ops;
ndev->needs_free_netdev = true;
}
static int mctp_serial_open(struct tty_struct *tty)
{
struct mctp_serial *dev;
struct net_device *ndev;
char name[32];
int idx, rc;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (!tty->ops->write)
return -EOPNOTSUPP;
idx = ida_alloc(&mctp_serial_ida, GFP_KERNEL);
if (idx < 0)
return idx;
snprintf(name, sizeof(name), "mctpserial%d", idx);
ndev = alloc_netdev(sizeof(*dev), name, NET_NAME_ENUM,
mctp_serial_setup);
if (!ndev) {
rc = -ENOMEM;
goto free_ida;
}
dev = netdev_priv(ndev);
dev->idx = idx;
dev->tty = tty;
dev->netdev = ndev;
dev->txstate = STATE_IDLE;
dev->rxstate = STATE_IDLE;
spin_lock_init(&dev->lock);
INIT_WORK(&dev->tx_work, mctp_serial_tx_work);
rc = mctp_register_netdev(ndev, NULL, MCTP_PHYS_BINDING_SERIAL);
if (rc)
goto free_netdev;
tty->receive_room = 64 * 1024;
tty->disc_data = dev;
return 0;
free_netdev:
free_netdev(ndev);
free_ida:
ida_free(&mctp_serial_ida, idx);
return rc;
}
static void mctp_serial_close(struct tty_struct *tty)
{
struct mctp_serial *dev = tty->disc_data;
int idx = dev->idx;
mctp_unregister_netdev(dev->netdev);
ida_free(&mctp_serial_ida, idx);
}
static struct tty_ldisc_ops mctp_ldisc = {
.owner = THIS_MODULE,
.num = N_MCTP,
.name = "mctp",
.open = mctp_serial_open,
.close = mctp_serial_close,
Annotation
- Immediate include surface: `linux/idr.h`, `linux/if_arp.h`, `linux/module.h`, `linux/skbuff.h`, `linux/tty.h`, `linux/workqueue.h`, `linux/crc-ccitt.h`, `linux/mctp.h`.
- Detected declarations: `struct mctp_serial`, `struct test_chunk_tx`, `enum mctp_serial_state`, `function needs_escape`, `function next_chunk_len`, `function write_chunk`, `function mctp_serial_tx_work`, `function mctp_serial_tx`, `function mctp_serial_tty_write_wakeup`, `function mctp_serial_rx`.
- 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.
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.