drivers/net/dsa/microchip/ksz8.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/microchip/ksz8.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/microchip/ksz8.c- Extension
.c- Size
- 71350 bytes
- Lines
- 2679
- 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/bitfield.hlinux/delay.hlinux/dsa/ksz_common.hlinux/export.hlinux/gpio.hlinux/if_vlan.hlinux/kernel.hlinux/module.hlinux/platform_data/microchip-ksz.hlinux/phy.hlinux/etherdevice.hlinux/if_bridge.hlinux/micrel_phy.hnet/dsa.hnet/switchdev.hlinux/phylink.hksz_common.hksz_dcb.hksz8_reg.hksz8.h
Detected Declarations
function Copyrightfunction ksz_port_cfgfunction ksz8_ind_write8function ksz8_ind_read8function ksz8_pme_write8function ksz8_pme_pread8function ksz8_pme_pwrite8function ksz8_reset_switchfunction ksz8863_change_mtufunction ksz8795_change_mtufunction ksz8_change_mtufunction ksz8_port_queue_splitfunction ksz8_r_mib_cntfunction ksz8795_r_mib_pktfunction ksz8863_r_mib_pktfunction ksz8_r_mib_pktfunction ksz8_freeze_mibfunction ksz8_port_init_cntfunction ksz8_r_tablefunction ksz8_w_tablefunction ksz8_valid_dyn_entryfunction ksz8_r_dyn_mac_tablefunction ksz8_r_sta_mac_tablefunction ksz8_w_sta_mac_tablefunction ksz8_from_vlanfunction ksz8_to_vlanfunction ksz8_r_vlan_entriesfunction ksz8_r_vlan_tablefunction ksz8_w_vlan_tablefunction ksz879x_get_loopbackfunction ksz879x_set_loopbackfunction ksz87xx_apply_low_loss_presetfunction registerfunction registerfunction ksz8_r_phyfunction ksz8_phy_read16function registerfunction registerfunction ksz8_w_phyfunction ksz8_phy_write16function ksz8_cfg_port_memberfunction ksz8_flush_dyn_mac_tablefunction ksz8_fdb_dumpfunction ksz8_add_sta_macfunction ksz8_del_sta_macfunction ksz8_mdb_addfunction ksz8_mdb_delfunction ksz8_fdb_add
Annotated Snippet
if (check & masks[MIB_COUNTER_VALID]) {
ksz_read32(dev, regs[REG_IND_DATA_LO], &data);
if (check & masks[MIB_COUNTER_OVERFLOW])
*cnt += MIB_COUNTER_VALUE + 1;
*cnt += data & MIB_COUNTER_VALUE;
break;
}
}
mutex_unlock(&dev->alu_mutex);
}
static void ksz8795_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
u64 *dropped, u64 *cnt)
{
const u32 *masks;
const u16 *regs;
u16 ctrl_addr;
u32 data;
u8 check;
int loop;
masks = dev->info->masks;
regs = dev->info->regs;
addr -= dev->info->reg_mib_cnt;
ctrl_addr = (KSZ8795_MIB_TOTAL_RX_1 - KSZ8795_MIB_TOTAL_RX_0) * port;
ctrl_addr += addr + KSZ8795_MIB_TOTAL_RX_0;
ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ);
mutex_lock(&dev->alu_mutex);
ksz_write16(dev, regs[REG_IND_CTRL_0], ctrl_addr);
/* It is almost guaranteed to always read the valid bit because of
* slow SPI speed.
*/
for (loop = 2; loop > 0; loop--) {
ksz_read8(dev, regs[REG_IND_MIB_CHECK], &check);
if (check & masks[MIB_COUNTER_VALID]) {
ksz_read32(dev, regs[REG_IND_DATA_LO], &data);
if (addr < 2) {
u64 total;
total = check & MIB_TOTAL_BYTES_H;
total <<= 32;
*cnt += total;
*cnt += data;
if (check & masks[MIB_COUNTER_OVERFLOW]) {
total = MIB_TOTAL_BYTES_H + 1;
total <<= 32;
*cnt += total;
}
} else {
if (check & masks[MIB_COUNTER_OVERFLOW])
*cnt += MIB_PACKET_DROPPED + 1;
*cnt += data & MIB_PACKET_DROPPED;
}
break;
}
}
mutex_unlock(&dev->alu_mutex);
}
static void ksz8863_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
u64 *dropped, u64 *cnt)
{
u32 *last = (u32 *)dropped;
const u16 *regs;
u16 ctrl_addr;
u32 data;
u32 cur;
regs = dev->info->regs;
addr -= dev->info->reg_mib_cnt;
ctrl_addr = addr ? KSZ8863_MIB_PACKET_DROPPED_TX_0 :
KSZ8863_MIB_PACKET_DROPPED_RX_0;
if (ksz_is_8895_family(dev) &&
ctrl_addr == KSZ8863_MIB_PACKET_DROPPED_RX_0)
ctrl_addr = KSZ8895_MIB_PACKET_DROPPED_RX_0;
ctrl_addr += port;
ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ);
mutex_lock(&dev->alu_mutex);
ksz_write16(dev, regs[REG_IND_CTRL_0], ctrl_addr);
ksz_read32(dev, regs[REG_IND_DATA_LO], &data);
mutex_unlock(&dev->alu_mutex);
data &= MIB_PACKET_DROPPED;
cur = last[addr];
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/delay.h`, `linux/dsa/ksz_common.h`, `linux/export.h`, `linux/gpio.h`, `linux/if_vlan.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `function Copyright`, `function ksz_port_cfg`, `function ksz8_ind_write8`, `function ksz8_ind_read8`, `function ksz8_pme_write8`, `function ksz8_pme_pread8`, `function ksz8_pme_pwrite8`, `function ksz8_reset_switch`, `function ksz8863_change_mtu`, `function ksz8795_change_mtu`.
- 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.