drivers/net/ethernet/mellanox/mlxsw/i2c.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/i2c.c- Extension
.c- Size
- 21595 bytes
- Lines
- 768
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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.
- 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/err.hlinux/i2c.hlinux/init.hlinux/jiffies.hlinux/kernel.hlinux/mutex.hlinux/module.hlinux/mod_devicetable.hlinux/platform_data/mlxreg.hlinux/slab.hcmd.hcore.hi2c.hresources.h
Detected Declarations
struct mlxsw_i2cfunction mlxsw_i2c_convert_mboxfunction mlxsw_i2c_get_reg_sizefunction mlxsw_i2c_set_slave_addrfunction mlxsw_i2c_wait_go_bitfunction mlxsw_i2c_write_cmdfunction mlxsw_i2c_write_init_cmdfunction mlxsw_i2c_get_mboxfunction mlxsw_i2c_writefunction mlxsw_i2c_cmdfunction mlxsw_i2c_cmd_execfunction mlxsw_i2c_skb_transmit_busyfunction mlxsw_i2c_skb_transmitfunction mlxsw_i2c_initfunction mlxsw_i2c_finifunction mlxsw_i2c_work_handlerfunction mlxsw_i2c_irq_handlerfunction mlxsw_i2c_irq_initfunction mlxsw_i2c_irq_finifunction mlxsw_i2c_probefunction mlxsw_i2c_removefunction mlxsw_i2c_driver_registerfunction mlxsw_i2c_driver_unregisterexport mlxsw_i2c_driver_registerexport mlxsw_i2c_driver_unregister
Annotated Snippet
struct mlxsw_i2c {
struct {
u32 mb_size_in;
u32 mb_off_in;
u32 mb_size_out;
u32 mb_off_out;
struct mutex lock;
} cmd;
struct device *dev;
struct mlxsw_core *core;
struct mlxsw_bus_info bus_info;
u16 block_size;
struct mlxreg_core_hotplug_platform_data *pdata;
struct work_struct irq_work;
int irq;
};
#define MLXSW_I2C_READ_MSG(_client, _addr_buf, _buf, _len) { \
{ .addr = (_client)->addr, \
.buf = (_addr_buf), \
.len = MLXSW_I2C_ADDR_BUF_SIZE, \
.flags = 0 }, \
{ .addr = (_client)->addr, \
.buf = (_buf), \
.len = (_len), \
.flags = I2C_M_RD } }
#define MLXSW_I2C_WRITE_MSG(_client, _buf, _len) \
{ .addr = (_client)->addr, \
.buf = (u8 *)(_buf), \
.len = (_len), \
.flags = 0 }
/* Routine converts in and out mail boxes offset and size. */
static inline void
mlxsw_i2c_convert_mbox(struct mlxsw_i2c *mlxsw_i2c, u8 *buf)
{
u32 tmp;
/* Local in/out mailboxes: 20 bits for offset, 12 for size */
tmp = be32_to_cpup((__be32 *) buf);
mlxsw_i2c->cmd.mb_off_in = tmp &
GENMASK(MLXSW_I2C_MBOX_OFFSET_BITS - 1, 0);
mlxsw_i2c->cmd.mb_size_in = (tmp & GENMASK(31,
MLXSW_I2C_MBOX_OFFSET_BITS)) >>
MLXSW_I2C_MBOX_OFFSET_BITS;
tmp = be32_to_cpup((__be32 *) (buf + MLXSW_I2C_ADDR_WIDTH));
mlxsw_i2c->cmd.mb_off_out = tmp &
GENMASK(MLXSW_I2C_MBOX_OFFSET_BITS - 1, 0);
mlxsw_i2c->cmd.mb_size_out = (tmp & GENMASK(31,
MLXSW_I2C_MBOX_OFFSET_BITS)) >>
MLXSW_I2C_MBOX_OFFSET_BITS;
}
/* Routine obtains register size from mail box buffer. */
static inline int mlxsw_i2c_get_reg_size(u8 *in_mbox)
{
u16 tmp = be16_to_cpup((__be16 *) (in_mbox + MLXSW_I2C_TLV_HDR_SIZE));
return (tmp & 0x7ff) * 4 + MLXSW_I2C_TLV_HDR_SIZE;
}
/* Routine sets I2C device internal offset in the transaction buffer. */
static inline void mlxsw_i2c_set_slave_addr(u8 *buf, u32 off)
{
__be32 *val = (__be32 *) buf;
*val = htonl(off);
}
/* Routine waits until go bit is cleared. */
static int mlxsw_i2c_wait_go_bit(struct i2c_client *client,
struct mlxsw_i2c *mlxsw_i2c, u8 *p_status)
{
u8 addr_buf[MLXSW_I2C_ADDR_BUF_SIZE];
u8 buf[MLXSW_I2C_READ_SEMA_SIZE];
int len = MLXSW_I2C_READ_SEMA_SIZE;
struct i2c_msg read_sema[] =
MLXSW_I2C_READ_MSG(client, addr_buf, buf, len);
bool wait_done = false;
unsigned long end;
int i = 0, err;
mlxsw_i2c_set_slave_addr(addr_buf, MLXSW_I2C_CIR2_OFF_STATUS);
end = jiffies + msecs_to_jiffies(MLXSW_I2C_TIMEOUT_MSECS);
do {
u32 ctrl;
Annotation
- Immediate include surface: `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/jiffies.h`, `linux/kernel.h`, `linux/mutex.h`, `linux/module.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct mlxsw_i2c`, `function mlxsw_i2c_convert_mbox`, `function mlxsw_i2c_get_reg_size`, `function mlxsw_i2c_set_slave_addr`, `function mlxsw_i2c_wait_go_bit`, `function mlxsw_i2c_write_cmd`, `function mlxsw_i2c_write_init_cmd`, `function mlxsw_i2c_get_mbox`, `function mlxsw_i2c_write`, `function mlxsw_i2c_cmd`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration 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.