drivers/net/ethernet/wiznet/w5100-spi.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/wiznet/w5100-spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/wiznet/w5100-spi.c- Extension
.c- Size
- 11050 bytes
- Lines
- 484
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/kernel.hlinux/module.hlinux/delay.hlinux/netdevice.hlinux/of.hlinux/of_net.hlinux/spi/spi.hw5100.h
Detected Declarations
struct w5200_spi_privstruct w5500_spi_privfunction Copyrightfunction w5100_spi_writefunction w5100_spi_read16function w5100_spi_write16function w5100_spi_readbulkfunction w5100_spi_writebulkfunction w5200_spi_initfunction w5200_spi_readfunction w5200_spi_writefunction w5200_spi_read16function w5200_spi_write16function w5200_spi_readbulkfunction w5200_spi_writebulkfunction w5500_spi_initfunction w5500_spi_readfunction w5500_spi_writefunction w5500_spi_read16function w5500_spi_write16function w5500_spi_readbulkfunction w5500_spi_writebulkfunction w5100_spi_probefunction w5100_spi_remove
Annotated Snippet
struct w5200_spi_priv {
/* Serialize access to cmd_buf */
struct mutex cmd_lock;
/* DMA (thus cache coherency maintenance) requires the
* transfer buffers to live in their own cache lines.
*/
u8 cmd_buf[4] ____cacheline_aligned;
};
static struct w5200_spi_priv *w5200_spi_priv(struct net_device *ndev)
{
return w5100_ops_priv(ndev);
}
static int w5200_spi_init(struct net_device *ndev)
{
struct w5200_spi_priv *spi_priv = w5200_spi_priv(ndev);
mutex_init(&spi_priv->cmd_lock);
return 0;
}
static int w5200_spi_read(struct net_device *ndev, u32 addr)
{
struct spi_device *spi = to_spi_device(ndev->dev.parent);
u8 cmd[4] = { addr >> 8, addr & 0xff, 0, 1 };
u8 data;
int ret;
ret = spi_write_then_read(spi, cmd, sizeof(cmd), &data, 1);
return ret ? ret : data;
}
static int w5200_spi_write(struct net_device *ndev, u32 addr, u8 data)
{
struct spi_device *spi = to_spi_device(ndev->dev.parent);
u8 cmd[5] = { addr >> 8, addr & 0xff, W5200_SPI_WRITE_OPCODE, 1, data };
return spi_write_then_read(spi, cmd, sizeof(cmd), NULL, 0);
}
static int w5200_spi_read16(struct net_device *ndev, u32 addr)
{
struct spi_device *spi = to_spi_device(ndev->dev.parent);
u8 cmd[4] = { addr >> 8, addr & 0xff, 0, 2 };
__be16 data;
int ret;
ret = spi_write_then_read(spi, cmd, sizeof(cmd), &data, sizeof(data));
return ret ? ret : be16_to_cpu(data);
}
static int w5200_spi_write16(struct net_device *ndev, u32 addr, u16 data)
{
struct spi_device *spi = to_spi_device(ndev->dev.parent);
u8 cmd[6] = {
addr >> 8, addr & 0xff,
W5200_SPI_WRITE_OPCODE, 2,
data >> 8, data & 0xff
};
return spi_write_then_read(spi, cmd, sizeof(cmd), NULL, 0);
}
static int w5200_spi_readbulk(struct net_device *ndev, u32 addr, u8 *buf,
int len)
{
struct spi_device *spi = to_spi_device(ndev->dev.parent);
struct w5200_spi_priv *spi_priv = w5200_spi_priv(ndev);
struct spi_transfer xfer[] = {
{
.tx_buf = spi_priv->cmd_buf,
.len = sizeof(spi_priv->cmd_buf),
},
{
.rx_buf = buf,
.len = len,
},
};
int ret;
mutex_lock(&spi_priv->cmd_lock);
spi_priv->cmd_buf[0] = addr >> 8;
spi_priv->cmd_buf[1] = addr;
spi_priv->cmd_buf[2] = len >> 8;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/delay.h`, `linux/netdevice.h`, `linux/of.h`, `linux/of_net.h`, `linux/spi/spi.h`, `w5100.h`.
- Detected declarations: `struct w5200_spi_priv`, `struct w5500_spi_priv`, `function Copyright`, `function w5100_spi_write`, `function w5100_spi_read16`, `function w5100_spi_write16`, `function w5100_spi_readbulk`, `function w5100_spi_writebulk`, `function w5200_spi_init`, `function w5200_spi_read`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source 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.