drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c- Extension
.c- Size
- 26582 bytes
- Lines
- 1092
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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
lib/sd.h../lag/lag.hmlx5_core.hlib/mlx5.hdevlink.heswitch.hfs_cmd.hlinux/mlx5/eswitch.hlinux/mlx5/vport.hlinux/debugfs.h
Detected Declarations
struct mlx5_sdenum mlx5_sd_statefunction mlx5_sd_get_host_busesfunction mlx5_sd_is_primaryfunction mlx5_sd_pf_num_getfunction mlx5_sd_primary_get_peerfunction mlx5_sd_ch_ix_get_dev_ixfunction mlx5_sd_ch_ix_get_vec_ixfunction ft_create_alias_supportedfunction mlx5_query_sdfunction mlx5_sd_group_idfunction mlx5_sd_caps_supportedfunction mlx5_sd_is_supportedfunction sd_initfunction sd_cleanupfunction sd_lag_state_showfunction sd_lag_initfunction mlx5_sd_for_each_secondaryfunction sd_lag_cleanupfunction sd_handle_fw_silent_checkfunction sd_handle_primary_setfunction sd_handle_secondaries_setfunction mlx5_sd_devcom_eventfunction sd_registerfunction sd_unregisterfunction sd_cmd_set_primaryfunction sd_cmd_unset_primaryfunction sd_secondary_create_alias_ftfunction sd_secondary_destroy_alias_ftfunction mlx5_sd_secondary_conf_tx_rootfunction sd_cmd_set_secondaryfunction sd_cmd_unset_secondaryfunction sd_print_groupfunction dev_readfunction mlx5_sd_initfunction mlx5_sd_for_each_secondaryfunction mlx5_sd_cleanupfunction mlx5_sd_all_pairedfunction mlx5_sd_for_each_secondaryfunction mlx5_sd_activate_shared_fdbfunction esw_offloads_enablefunction mlx5_sd_eswitch_mode_setfunction mlx5_sd_put_adev
Annotated Snippet
static const struct file_operations dev_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = dev_read,
};
int mlx5_sd_init(struct mlx5_core_dev *dev)
{
struct mlx5_core_dev *primary, *pos, *to;
struct mlx5_sd *sd = mlx5_get_sd(dev);
u8 alias_key[ACCESS_KEY_LEN];
struct mlx5_sd *primary_sd;
int err, i;
err = sd_init(dev);
if (err)
return err;
sd = mlx5_get_sd(dev);
if (!sd)
return 0;
err = sd_register(dev);
if (err)
goto err_sd_cleanup;
mlx5_devcom_comp_lock(sd->devcom);
if (!mlx5_devcom_comp_is_ready(sd->devcom))
goto out;
primary = mlx5_sd_get_primary(dev);
if (!primary)
goto out;
primary_sd = mlx5_get_sd(primary);
if (primary_sd->state != MLX5_SD_STATE_DOWN)
goto out;
for (i = 0; i < ACCESS_KEY_LEN; i++)
alias_key[i] = get_random_u8();
err = sd_cmd_set_primary(primary, alias_key);
if (err)
goto err_sd_unregister;
mlx5_sd_for_each_secondary(i, primary, pos) {
err = sd_cmd_set_secondary(pos, primary, alias_key);
if (err)
goto err_unset_secondaries;
}
sd_lag_init(primary);
primary_sd->dfs =
debugfs_create_dir("multi-pf",
mlx5_debugfs_get_dev_root(primary));
mlx5_sd_for_each_secondary(i, primary, pos) {
char name[32];
snprintf(name, sizeof(name), "secondary_%d", i - 1);
debugfs_create_file(name, 0400, primary_sd->dfs, pos,
&dev_fops);
}
debugfs_create_file("sd_lag_state", 0400, primary_sd->dfs, primary,
&sd_lag_state_fops);
debugfs_create_x32("group_id", 0400, primary_sd->dfs,
&primary_sd->group_id);
debugfs_create_file("primary", 0400, primary_sd->dfs, primary,
&dev_fops);
sd_info(primary, "group id %#x, size %d, combined\n",
sd->group_id, mlx5_devcom_comp_get_size(sd->devcom));
sd_print_group(primary);
primary_sd->state = MLX5_SD_STATE_UP;
out:
mlx5_devcom_comp_unlock(sd->devcom);
return 0;
err_unset_secondaries:
to = pos;
mlx5_sd_for_each_secondary_to(i, primary, to, pos)
sd_cmd_unset_secondary(pos);
sd_cmd_unset_primary(primary);
err_sd_unregister:
mlx5_sd_for_each_secondary(i, primary, pos) {
struct mlx5_sd *peer_sd = mlx5_get_sd(pos);
primary_sd->secondaries[i - 1] = NULL;
Annotation
- Immediate include surface: `lib/sd.h`, `../lag/lag.h`, `mlx5_core.h`, `lib/mlx5.h`, `devlink.h`, `eswitch.h`, `fs_cmd.h`, `linux/mlx5/eswitch.h`.
- Detected declarations: `struct mlx5_sd`, `enum mlx5_sd_state`, `function mlx5_sd_get_host_buses`, `function mlx5_sd_is_primary`, `function mlx5_sd_pf_num_get`, `function mlx5_sd_primary_get_peer`, `function mlx5_sd_ch_ix_get_dev_ix`, `function mlx5_sd_ch_ix_get_vec_ix`, `function ft_create_alias_supported`, `function mlx5_query_sd`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern 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.