drivers/net/ethernet/mellanox/mlxsw/core_env.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/core_env.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/core_env.c- Extension
.c- Size
- 43546 bytes
- Lines
- 1535
- 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.
- 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/kernel.hlinux/err.hlinux/ethtool.hlinux/sfp.hlinux/mutex.hcore.hcore_env.hitem.hreg.h
Detected Declarations
struct mlxsw_env_module_infostruct mlxsw_env_line_cardstruct mlxsw_envstruct mlxsw_env_module_temp_warn_eventstruct mlxsw_env_module_plug_unplug_eventfunction __mlxsw_env_linecard_is_activefunction mlxsw_env_linecard_is_activefunction __mlxsw_env_validate_module_typefunction mlxsw_env_validate_module_typefunction mlxsw_env_validate_cable_identfunction mlxsw_env_query_module_eepromfunction mlxsw_env_module_temp_thresholds_getfunction mlxsw_env_get_module_infofunction mlxsw_env_get_module_eepromfunction mlxsw_env_mcia_status_processfunction mlxsw_env_get_module_eeprom_by_pagefunction mlxsw_env_set_module_eeprom_by_pagefunction mlxsw_env_module_resetfunction mlxsw_env_reset_modulefunction mlxsw_env_get_module_power_modefunction mlxsw_env_module_enable_setfunction mlxsw_env_module_low_power_setfunction __mlxsw_env_set_module_power_modefunction mlxsw_env_set_module_power_mode_applyfunction mlxsw_env_set_module_power_modefunction mlxsw_env_module_has_temp_sensorfunction mlxsw_env_temp_event_setfunction mlxsw_env_module_temp_event_enablefunction mlxsw_env_mtwe_event_workfunction mlxsw_env_mtwe_listener_funcfunction mlxsw_env_temp_warn_event_registerfunction mlxsw_env_temp_warn_event_unregisterfunction mlxsw_env_pmpe_event_workfunction mlxsw_env_pmpe_listener_funcfunction mlxsw_env_module_plug_event_registerfunction mlxsw_env_module_plug_event_unregisterfunction mlxsw_env_module_oper_state_event_enablefunction mlxsw_env_module_overheat_counter_getfunction mlxsw_env_module_port_mapfunction mlxsw_env_module_port_unmapfunction mlxsw_env_module_port_upfunction mlxsw_env_module_port_downfunction mlxsw_env_line_cards_allocfunction mlxsw_env_line_cards_freefunction mlxsw_env_module_event_enablefunction mlxsw_env_module_event_disablefunction mlxsw_env_linecard_modules_power_mode_applyfunction mlxsw_env_got_active
Annotated Snippet
struct mlxsw_env_module_info {
u64 module_overheat_counter;
bool is_overheat;
int num_ports_mapped;
int num_ports_up;
enum ethtool_module_power_mode_policy power_mode_policy;
enum mlxsw_reg_pmtm_module_type type;
};
struct mlxsw_env_line_card {
u8 module_count;
bool active;
struct mlxsw_env_module_info module_info[];
};
struct mlxsw_env {
struct mlxsw_core *core;
const struct mlxsw_bus_info *bus_info;
u8 max_module_count; /* Maximum number of modules per-slot. */
u8 num_of_slots; /* Including the main board. */
u8 max_eeprom_len; /* Maximum module EEPROM transaction length. */
struct mutex line_cards_lock; /* Protects line cards. */
struct mlxsw_env_line_card *line_cards[] __counted_by(num_of_slots);
};
static bool __mlxsw_env_linecard_is_active(struct mlxsw_env *mlxsw_env,
u8 slot_index)
{
return mlxsw_env->line_cards[slot_index]->active;
}
static bool mlxsw_env_linecard_is_active(struct mlxsw_env *mlxsw_env,
u8 slot_index)
{
bool active;
mutex_lock(&mlxsw_env->line_cards_lock);
active = __mlxsw_env_linecard_is_active(mlxsw_env, slot_index);
mutex_unlock(&mlxsw_env->line_cards_lock);
return active;
}
static struct
mlxsw_env_module_info *mlxsw_env_module_info_get(struct mlxsw_core *mlxsw_core,
u8 slot_index, u8 module)
{
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
return &mlxsw_env->line_cards[slot_index]->module_info[module];
}
static int __mlxsw_env_validate_module_type(struct mlxsw_core *core,
u8 slot_index, u8 module)
{
struct mlxsw_env *mlxsw_env = mlxsw_core_env(core);
struct mlxsw_env_module_info *module_info;
int err;
if (!__mlxsw_env_linecard_is_active(mlxsw_env, slot_index))
return 0;
module_info = mlxsw_env_module_info_get(core, slot_index, module);
switch (module_info->type) {
case MLXSW_REG_PMTM_MODULE_TYPE_TWISTED_PAIR:
err = -EINVAL;
break;
default:
err = 0;
}
return err;
}
static int mlxsw_env_validate_module_type(struct mlxsw_core *core,
u8 slot_index, u8 module)
{
struct mlxsw_env *mlxsw_env = mlxsw_core_env(core);
int err;
mutex_lock(&mlxsw_env->line_cards_lock);
err = __mlxsw_env_validate_module_type(core, slot_index, module);
mutex_unlock(&mlxsw_env->line_cards_lock);
return err;
}
static int
mlxsw_env_validate_cable_ident(struct mlxsw_core *core, u8 slot_index, int id,
bool *qsfp, bool *cmis)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/err.h`, `linux/ethtool.h`, `linux/sfp.h`, `linux/mutex.h`, `core.h`, `core_env.h`, `item.h`.
- Detected declarations: `struct mlxsw_env_module_info`, `struct mlxsw_env_line_card`, `struct mlxsw_env`, `struct mlxsw_env_module_temp_warn_event`, `struct mlxsw_env_module_plug_unplug_event`, `function __mlxsw_env_linecard_is_active`, `function mlxsw_env_linecard_is_active`, `function __mlxsw_env_validate_module_type`, `function mlxsw_env_validate_module_type`, `function mlxsw_env_validate_cable_ident`.
- 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.
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.