net/core/ieee8021q_helpers.c

Source file repositories/reference/linux-study-clean/net/core/ieee8021q_helpers.c

File Facts

System
Linux kernel
Corpus path
net/core/ieee8021q_helpers.c
Extension
.c
Size
7506 bytes
Lines
225
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2024 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>

#include <linux/array_size.h>
#include <linux/printk.h>
#include <linux/types.h>
#include <net/dscp.h>
#include <net/ieee8021q.h>

/* verify that table covers all 8 traffic types */
#define TT_MAP_SIZE_OK(tbl)                                 \
	compiletime_assert(ARRAY_SIZE(tbl) == IEEE8021Q_TT_MAX, \
			   #tbl " size mismatch")

/* The following arrays map Traffic Types (TT) to traffic classes (TC) for
 * different number of queues as shown in the example provided by
 * IEEE 802.1Q-2022 in Annex I "I.3 Traffic type to traffic class mapping" and
 * Table I-1 "Traffic type to traffic class mapping".
 */
static const u8 ieee8021q_8queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0,
	[IEEE8021Q_TT_BE] = 1,
	[IEEE8021Q_TT_EE] = 2,
	[IEEE8021Q_TT_CA] = 3,
	[IEEE8021Q_TT_VI] = 4,
	[IEEE8021Q_TT_VO] = 5,
	[IEEE8021Q_TT_IC] = 6,
	[IEEE8021Q_TT_NC] = 7,
};

static const u8 ieee8021q_7queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0,
	[IEEE8021Q_TT_BE] = 1,
	[IEEE8021Q_TT_EE] = 2,
	[IEEE8021Q_TT_CA] = 3,
	[IEEE8021Q_TT_VI] = 4,	[IEEE8021Q_TT_VO] = 4,
	[IEEE8021Q_TT_IC] = 5,
	[IEEE8021Q_TT_NC] = 6,
};

static const u8 ieee8021q_6queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0,
	[IEEE8021Q_TT_BE] = 1,
	[IEEE8021Q_TT_EE] = 2,	[IEEE8021Q_TT_CA] = 2,
	[IEEE8021Q_TT_VI] = 3,	[IEEE8021Q_TT_VO] = 3,
	[IEEE8021Q_TT_IC] = 4,
	[IEEE8021Q_TT_NC] = 5,
};

static const u8 ieee8021q_5queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
	[IEEE8021Q_TT_EE] = 1, [IEEE8021Q_TT_CA] = 1,
	[IEEE8021Q_TT_VI] = 2, [IEEE8021Q_TT_VO] = 2,
	[IEEE8021Q_TT_IC] = 3,
	[IEEE8021Q_TT_NC] = 4,
};

static const u8 ieee8021q_4queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
	[IEEE8021Q_TT_EE] = 1, [IEEE8021Q_TT_CA] = 1,
	[IEEE8021Q_TT_VI] = 2, [IEEE8021Q_TT_VO] = 2,
	[IEEE8021Q_TT_IC] = 3, [IEEE8021Q_TT_NC] = 3,
};

static const u8 ieee8021q_3queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
	[IEEE8021Q_TT_EE] = 0, [IEEE8021Q_TT_CA] = 0,
	[IEEE8021Q_TT_VI] = 1, [IEEE8021Q_TT_VO] = 1,
	[IEEE8021Q_TT_IC] = 2, [IEEE8021Q_TT_NC] = 2,
};

static const u8 ieee8021q_2queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
	[IEEE8021Q_TT_EE] = 0, [IEEE8021Q_TT_CA] = 0,
	[IEEE8021Q_TT_VI] = 1, [IEEE8021Q_TT_VO] = 1,
	[IEEE8021Q_TT_IC] = 1, [IEEE8021Q_TT_NC] = 1,
};

static const u8 ieee8021q_1queue_tt_tc_map[] = {
	[IEEE8021Q_TT_BK] = 0, [IEEE8021Q_TT_BE] = 0,
	[IEEE8021Q_TT_EE] = 0, [IEEE8021Q_TT_CA] = 0,
	[IEEE8021Q_TT_VI] = 0, [IEEE8021Q_TT_VO] = 0,
	[IEEE8021Q_TT_IC] = 0, [IEEE8021Q_TT_NC] = 0,
};

/**
 * ieee8021q_tt_to_tc - Map IEEE 802.1Q Traffic Type to Traffic Class
 * @tt: IEEE 802.1Q Traffic Type
 * @num_queues: Number of queues
 *

Annotation

Implementation Notes