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.

Dependency Surface

Detected Declarations

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

Implementation Notes