drivers/net/mctp/mctp-i2c.c
Source file repositories/reference/linux-study-clean/drivers/net/mctp/mctp-i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mctp/mctp-i2c.c- Extension
.c- Size
- 29155 bytes
- Lines
- 1157
- 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.
- 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/module.hlinux/netdevice.hlinux/i2c.hlinux/i2c-mux.hlinux/if_arp.hnet/mctp.hnet/mctpdevice.h
Detected Declarations
struct mctp_i2c_clientstruct mctp_i2c_devstruct mctp_i2c_clientstruct mctp_i2c_hdrenum mctp_i2c_flow_statefunction mctp_i2c_free_clientfunction __mctp_i2c_device_selectfunction mctp_i2c_device_selectfunction mctp_i2c_slave_cbfunction mctp_i2c_recvfunction mctp_i2c_get_tx_flow_statefunction mctp_i2c_lock_nestfunction mctp_i2c_unlock_nestfunction mctp_i2c_unlock_resetfunction mctp_i2c_invalidate_tx_flowfunction mctp_i2c_xmitfunction mctp_i2c_flow_releasefunction mctp_i2c_header_createfunction mctp_i2c_tx_threadfunction mctp_i2c_start_xmitfunction mctp_i2c_release_flowfunction mctp_i2c_net_setupfunction mctp_i2c_midev_freefunction mctp_i2c_unregisterfunction mctp_i2c_ndo_uninitfunction mctp_i2c_ndo_openfunction mctp_i2c_add_netdevfunction mctp_i2c_remove_netdevfunction mctp_i2c_adapter_matchfunction mctp_i2c_client_try_attachfunction mctp_i2c_notify_addfunction mctp_i2c_notify_delfunction mctp_i2c_probefunction mctp_i2c_removefunction mctp_i2c_notifier_callfunction mctp_i2c_mod_initfunction mctp_i2c_mod_exitmodule init mctp_i2c_mod_init
Annotated Snippet
static const struct net_device_ops mctp_i2c_ops = {
.ndo_start_xmit = mctp_i2c_start_xmit,
.ndo_uninit = mctp_i2c_ndo_uninit,
.ndo_open = mctp_i2c_ndo_open,
};
static const struct header_ops mctp_i2c_headops = {
.create = mctp_i2c_header_create,
};
static const struct mctp_netdev_ops mctp_i2c_mctp_ops = {
.release_flow = mctp_i2c_release_flow,
};
static void mctp_i2c_net_setup(struct net_device *dev)
{
dev->type = ARPHRD_MCTP;
dev->mtu = MCTP_I2C_MAXMTU;
dev->min_mtu = MCTP_I2C_MINMTU;
dev->max_mtu = MCTP_I2C_MAXMTU;
dev->tx_queue_len = MCTP_I2C_TX_QUEUE_LEN;
dev->hard_header_len = sizeof(struct mctp_i2c_hdr);
dev->addr_len = 1;
dev->netdev_ops = &mctp_i2c_ops;
dev->header_ops = &mctp_i2c_headops;
}
/* Populates the mctp_i2c_dev priv struct for a netdev.
* Returns an error pointer on failure.
*/
static struct mctp_i2c_dev *mctp_i2c_midev_init(struct net_device *dev,
struct mctp_i2c_client *mcli,
struct i2c_adapter *adap)
{
struct mctp_i2c_dev *midev = netdev_priv(dev);
unsigned long flags;
midev->tx_thread = kthread_create(mctp_i2c_tx_thread, midev,
"%s/tx", dev->name);
if (IS_ERR(midev->tx_thread))
return ERR_CAST(midev->tx_thread);
midev->ndev = dev;
get_device(&adap->dev);
midev->adapter = adap;
get_device(&mcli->client->dev);
midev->client = mcli;
INIT_LIST_HEAD(&midev->list);
spin_lock_init(&midev->lock);
midev->i2c_lock_count = 0;
midev->release_count = 0;
init_completion(&midev->rx_done);
complete(&midev->rx_done);
init_waitqueue_head(&midev->tx_wq);
skb_queue_head_init(&midev->tx_queue);
/* Add to the parent mcli */
spin_lock_irqsave(&mcli->sel_lock, flags);
list_add(&midev->list, &mcli->devs);
/* Select a device by default */
if (!mcli->sel)
__mctp_i2c_device_select(mcli, midev);
spin_unlock_irqrestore(&mcli->sel_lock, flags);
/* Start the worker thread */
wake_up_process(midev->tx_thread);
return midev;
}
/* Counterpart of mctp_i2c_midev_init */
static void mctp_i2c_midev_free(struct mctp_i2c_dev *midev)
{
struct mctp_i2c_client *mcli = midev->client;
unsigned long flags;
if (midev->tx_thread) {
kthread_stop(midev->tx_thread);
midev->tx_thread = NULL;
}
/* Unconditionally unlock on close */
mctp_i2c_unlock_reset(midev);
/* Remove the netdev from the parent i2c client. */
spin_lock_irqsave(&mcli->sel_lock, flags);
list_del(&midev->list);
Annotation
- Immediate include surface: `linux/module.h`, `linux/netdevice.h`, `linux/i2c.h`, `linux/i2c-mux.h`, `linux/if_arp.h`, `net/mctp.h`, `net/mctpdevice.h`.
- Detected declarations: `struct mctp_i2c_client`, `struct mctp_i2c_dev`, `struct mctp_i2c_client`, `struct mctp_i2c_hdr`, `enum mctp_i2c_flow_state`, `function mctp_i2c_free_client`, `function __mctp_i2c_device_select`, `function mctp_i2c_device_select`, `function mctp_i2c_slave_cb`, `function mctp_i2c_recv`.
- 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.