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.

Dependency Surface

Detected Declarations

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

Implementation Notes