drivers/infiniband/hw/mlx5/macsec.c

Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mlx5/macsec.c

File Facts

System
Linux kernel
Corpus path
drivers/infiniband/hw/mlx5/macsec.c
Extension
.c
Size
10024 bytes
Lines
364
Domain
Driver Families
Bucket
drivers/infiniband
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mlx5_reserved_gids {
	int macsec_index;
	const struct ib_gid_attr *physical_gid;
};

struct mlx5_roce_gids {
	struct list_head roce_gid_list_entry;
	u16 gid_idx;
	union {
		struct sockaddr_in  sockaddr_in;
		struct sockaddr_in6 sockaddr_in6;
	} addr;
};

struct mlx5_macsec_device {
	struct list_head macsec_devices_list_entry;
	void *macdev;
	struct list_head macsec_roce_gids;
	struct list_head tx_rules_list;
	struct list_head rx_rules_list;
};

static void cleanup_macsec_device(struct mlx5_macsec_device *macsec_device)
{
	if (!list_empty(&macsec_device->tx_rules_list) ||
	    !list_empty(&macsec_device->rx_rules_list) ||
	    !list_empty(&macsec_device->macsec_roce_gids))
		return;

	list_del(&macsec_device->macsec_devices_list_entry);
	kfree(macsec_device);
}

static struct mlx5_macsec_device *get_macsec_device(void *macdev,
						    struct list_head *macsec_devices_list)
{
	struct mlx5_macsec_device *iter, *macsec_device = NULL;

	list_for_each_entry(iter, macsec_devices_list, macsec_devices_list_entry) {
		if (iter->macdev == macdev) {
			macsec_device = iter;
			break;
		}
	}

	if (macsec_device)
		return macsec_device;

	macsec_device = kzalloc_obj(*macsec_device);
	if (!macsec_device)
		return NULL;

	macsec_device->macdev = macdev;
	INIT_LIST_HEAD(&macsec_device->tx_rules_list);
	INIT_LIST_HEAD(&macsec_device->rx_rules_list);
	INIT_LIST_HEAD(&macsec_device->macsec_roce_gids);
	list_add(&macsec_device->macsec_devices_list_entry, macsec_devices_list);

	return macsec_device;
}

static void mlx5_macsec_del_roce_gid(struct mlx5_macsec_device *macsec_device, u16 gid_idx)
{
	struct mlx5_roce_gids *current_gid, *next_gid;

	list_for_each_entry_safe(current_gid, next_gid, &macsec_device->macsec_roce_gids,
				 roce_gid_list_entry)
		if (current_gid->gid_idx == gid_idx) {
			list_del(&current_gid->roce_gid_list_entry);
			kfree(current_gid);
		}
}

static void mlx5_macsec_save_roce_gid(struct mlx5_macsec_device *macsec_device,
				      const struct sockaddr *addr, u16 gid_idx)
{
	struct mlx5_roce_gids *roce_gids;

	roce_gids = kzalloc_obj(*roce_gids);
	if (!roce_gids)
		return;

	roce_gids->gid_idx = gid_idx;
	if (addr->sa_family == AF_INET)
		memcpy(&roce_gids->addr.sockaddr_in, addr, sizeof(roce_gids->addr.sockaddr_in));
	else
		memcpy(&roce_gids->addr.sockaddr_in6, addr, sizeof(roce_gids->addr.sockaddr_in6));

	list_add_tail(&roce_gids->roce_gid_list_entry, &macsec_device->macsec_roce_gids);
}

Annotation

Implementation Notes