drivers/net/dsa/microchip/lan937x_main.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/microchip/lan937x_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/microchip/lan937x_main.c- Extension
.c- Size
- 27470 bytes
- Lines
- 1007
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/dsa/ksz_common.hlinux/kernel.hlinux/module.hlinux/iopoll.hlinux/phy.hlinux/of_mdio.hlinux/of_net.hlinux/if_bridge.hlinux/if_vlan.hlinux/math.hnet/dsa.hnet/switchdev.hlan937x_reg.hksz_common.hksz_dcb.hksz9477.hlan937x.h
Detected Declarations
function lan937x_cfgfunction lan937x_port_cfgfunction mappingfunction lan937x_mdio_bus_preinitfunction lan937x_vphy_ind_addr_wrfunction lan937x_internal_phy_writefunction lan937x_internal_phy_readfunction lan937x_phy_read16function lan937x_phy_write16function lan937x_reset_switchfunction lan937x_port_setupfunction lan937x_dsa_port_setupfunction lan937x_config_cpu_portfunction dsa_switch_for_each_cpu_portfunction dsa_switch_for_each_user_portfunction lan937x_change_mtufunction lan937x_set_ageing_timefunction lan937x_set_tune_adjfunction lan937x_set_rgmii_tx_delayfunction lan937x_set_rgmii_rx_delayfunction lan937x_phylink_get_capsfunction lan937x_setup_rgmii_delayfunction lan937x_phylink_mac_configfunction lan937x_tc_cbs_set_cincfunction lan937x_switch_initfunction lan937x_mdio_registerfunction lan937x_setupfunction dsa_switch_for_each_user_portfunction dsa_switch_for_each_user_port_continue_reversefunction lan937x_get_tag_protocolfunction lan937x_connect_tag_protocol
Annotated Snippet
if (dev->info->cpu_ports & (1 << dp->index)) {
dev->cpu_port = dp->index;
/* enable cpu port */
lan937x_port_setup(dev, dp->index, true);
}
}
dsa_switch_for_each_user_port(dp, ds) {
ksz_port_stp_state_set(ds, dp->index, BR_STATE_DISABLED);
}
}
static int lan937x_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
{
struct ksz_device *dev = ds->priv;
int ret;
new_mtu += VLAN_ETH_HLEN + ETH_FCS_LEN;
if (dsa_is_cpu_port(ds, port))
new_mtu += LAN937X_TAG_LEN;
if (new_mtu >= FR_MIN_SIZE)
ret = lan937x_port_cfg(dev, port, REG_PORT_MAC_CTRL_0,
PORT_JUMBO_PACKET, true);
else
ret = lan937x_port_cfg(dev, port, REG_PORT_MAC_CTRL_0,
PORT_JUMBO_PACKET, false);
if (ret < 0) {
dev_err(ds->dev, "failed to enable jumbo\n");
return ret;
}
/* Write the frame size in PORT_MAX_FR_SIZE register */
ret = ksz_pwrite16(dev, port, PORT_MAX_FR_SIZE, new_mtu);
if (ret) {
dev_err(ds->dev, "failed to update mtu for port %d\n", port);
return ret;
}
return 0;
}
static int lan937x_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
{
struct ksz_device *dev = ds->priv;
u8 data, mult, value8;
bool in_msec = false;
u32 max_val, value;
u32 secs = msecs;
int ret;
#define MAX_TIMER_VAL ((1 << 20) - 1)
/* The aging timer comprises a 3-bit multiplier and a 20-bit second
* value. Either of them cannot be zero. The maximum timer is then
* 7 * 1048575 = 7340025 seconds. As this value is too large for
* practical use it can be interpreted as microseconds, making the
* maximum timer 7340 seconds with finer control. This allows for
* maximum 122 minutes compared to 29 minutes in KSZ9477 switch.
*/
if (msecs % 1000)
in_msec = true;
else
secs /= 1000;
if (!secs)
secs = 1;
/* Return error if too large. */
else if (secs > 7 * MAX_TIMER_VAL)
return -EINVAL;
/* Configure how to interpret the number value. */
ret = ksz_rmw8(dev, REG_SW_LUE_CTRL_2, SW_AGE_CNT_IN_MICROSEC,
in_msec ? SW_AGE_CNT_IN_MICROSEC : 0);
if (ret < 0)
return ret;
ret = ksz_read8(dev, REG_SW_LUE_CTRL_0, &value8);
if (ret < 0)
return ret;
/* Check whether there is need to update the multiplier. */
mult = FIELD_GET(SW_AGE_CNT_M, value8);
max_val = MAX_TIMER_VAL;
if (mult > 0) {
/* Try to use the same multiplier already in the register as
* the hardware default uses multiplier 4 and 75 seconds for
* 300 seconds.
Annotation
- Immediate include surface: `linux/dsa/ksz_common.h`, `linux/kernel.h`, `linux/module.h`, `linux/iopoll.h`, `linux/phy.h`, `linux/of_mdio.h`, `linux/of_net.h`, `linux/if_bridge.h`.
- Detected declarations: `function lan937x_cfg`, `function lan937x_port_cfg`, `function mapping`, `function lan937x_mdio_bus_preinit`, `function lan937x_vphy_ind_addr_wr`, `function lan937x_internal_phy_write`, `function lan937x_internal_phy_read`, `function lan937x_phy_read16`, `function lan937x_phy_write16`, `function lan937x_reset_switch`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
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.