drivers/net/dsa/ks8995.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/ks8995.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/ks8995.c- Extension
.c- Size
- 22394 bytes
- Lines
- 858
- 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.
- 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/bits.hlinux/if_bridge.hlinux/if_vlan.hlinux/types.hlinux/kernel.hlinux/module.hlinux/delay.hlinux/device.hlinux/gpio/consumer.hlinux/of.hlinux/spi/spi.hnet/dsa.h
Detected Declarations
struct ks8995_chip_paramsstruct ks8995_switchenum ks8995_chip_variantfunction get_chip_idfunction get_chip_revfunction create_spi_cmdfunction ks8995_readfunction ks8995_writefunction ks8995_read_regfunction ks8995_write_regfunction ks8995_stopfunction ks8995_startfunction ks8995_resetfunction ks8995_get_revisionfunction ks8995_check_configfunction ks8995_mac_configfunction ks8995_mac_link_downfunction ks8995_get_tag_protocolfunction ks8995_setupfunction ks8995_port_enablefunction ks8995_port_disablefunction ks8995_port_pre_bridge_flagsfunction ks8995_port_bridge_flagsfunction ks8995_port_stp_state_setfunction ks8995_phylink_get_capsfunction ks8995_change_mtufunction ks8995_get_max_mtufunction ks8995_probefunction ks8995_remove
Annotated Snippet
struct ks8995_chip_params {
char *name;
int family_id;
int chip_id;
int regs_size;
int addr_width;
int addr_shift;
};
static const struct ks8995_chip_params ks8995_chip[] = {
[ks8995] = {
.name = "KS8995MA",
.family_id = FAMILY_KS8995,
.chip_id = KS8995_CHIP_ID,
.regs_size = KS8995_REGS_SIZE,
.addr_width = 8,
.addr_shift = 0,
},
[ksz8864] = {
.name = "KSZ8864RMN",
.family_id = FAMILY_KS8995,
.chip_id = KSZ8864_CHIP_ID,
.regs_size = KSZ8864_REGS_SIZE,
.addr_width = 8,
.addr_shift = 0,
},
[ksz8795] = {
.name = "KSZ8795CLX",
.family_id = FAMILY_KSZ8795,
.chip_id = KSZ8795_CHIP_ID,
.regs_size = KSZ8795_REGS_SIZE,
.addr_width = 12,
.addr_shift = 1,
},
};
struct ks8995_switch {
struct spi_device *spi;
struct device *dev;
struct dsa_switch *ds;
struct mutex lock;
struct gpio_desc *reset_gpio;
struct bin_attribute regs_attr;
const struct ks8995_chip_params *chip;
int revision_id;
unsigned int max_mtu[KS8995_NUM_PORTS];
};
static const struct spi_device_id ks8995_id[] = {
{"ks8995", ks8995},
{"ksz8864", ksz8864},
{"ksz8795", ksz8795},
{ }
};
MODULE_DEVICE_TABLE(spi, ks8995_id);
static const struct of_device_id ks8995_spi_of_match[] = {
{ .compatible = "micrel,ks8995" },
{ .compatible = "micrel,ksz8864" },
{ .compatible = "micrel,ksz8795" },
{ },
};
MODULE_DEVICE_TABLE(of, ks8995_spi_of_match);
static inline u8 get_chip_id(u8 val)
{
return (val >> ID1_CHIPID_S) & ID1_CHIPID_M;
}
static inline u8 get_chip_rev(u8 val)
{
return (val >> ID1_REVISION_S) & ID1_REVISION_M;
}
/* create_spi_cmd - create a chip specific SPI command header
* @ks: pointer to switch instance
* @cmd: SPI command for switch
* @address: register address for command
*
* Different chip families use different bit pattern to address the switches
* registers:
*
* KS8995: 8bit command + 8bit address
* KSZ8795: 3bit command + 12bit address + 1bit TR (?)
*/
static inline __be16 create_spi_cmd(struct ks8995_switch *ks, int cmd,
unsigned address)
{
u16 result = cmd;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/if_bridge.h`, `linux/if_vlan.h`, `linux/types.h`, `linux/kernel.h`, `linux/module.h`, `linux/delay.h`, `linux/device.h`.
- Detected declarations: `struct ks8995_chip_params`, `struct ks8995_switch`, `enum ks8995_chip_variant`, `function get_chip_id`, `function get_chip_rev`, `function create_spi_cmd`, `function ks8995_read`, `function ks8995_write`, `function ks8995_read_reg`, `function ks8995_write_reg`.
- 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.