1 /* SPDX-License-Identifier: GPL-2.0
2 * Copyright 2019-2021 NXP Semiconductors
5 #ifndef _NET_DSA_TAG_OCELOT_H
6 #define _NET_DSA_TAG_OCELOT_H
8 #include <linux/packing.h>
10 #define OCELOT_TAG_LEN 16
11 #define OCELOT_SHORT_PREFIX_LEN 4
12 #define OCELOT_LONG_PREFIX_LEN 16
13 #define OCELOT_TOTAL_TAG_LEN (OCELOT_SHORT_PREFIX_LEN + OCELOT_TAG_LEN)
15 /* The CPU injection header and the CPU extraction header can have 3 types of
16 * prefixes: long, short and no prefix. The format of the header itself is the
17 * same in all 3 cases.
19 * Extraction with long prefix:
21 * +-------------------+-------------------+------+------+------------+-------+
22 * | ff:ff:ff:ff:ff:ff | fe:ff:ff:ff:ff:ff | 8880 | 000a | extraction | frame |
23 * | | | | | header | |
24 * +-------------------+-------------------+------+------+------------+-------+
25 * 48 bits 48 bits 16 bits 16 bits 128 bits
27 * Extraction with short prefix:
29 * +------+------+------------+-------+
30 * | 8880 | 000a | extraction | frame |
32 * +------+------+------------+-------+
33 * 16 bits 16 bits 128 bits
35 * Extraction with no prefix:
37 * +------------+-------+
38 * | extraction | frame |
40 * +------------+-------+
44 * Injection with long prefix:
46 * +-------------------+-------------------+------+------+------------+-------+
47 * | any dmac | any smac | 8880 | 000a | injection | frame |
48 * | | | | | header | |
49 * +-------------------+-------------------+------+------+------------+-------+
50 * 48 bits 48 bits 16 bits 16 bits 128 bits
52 * Injection with short prefix:
54 * +------+------+------------+-------+
55 * | 8880 | 000a | injection | frame |
57 * +------+------+------------+-------+
58 * 16 bits 16 bits 128 bits
60 * Injection with no prefix:
62 * +------------+-------+
63 * | injection | frame |
65 * +------------+-------+
68 * The injection header looks like this (network byte order, bit 127
69 * is part of lowest address byte in memory, bit 0 is part of highest
72 * +------+------+------+------+------+------+------+------+
73 * 127:120 |BYPASS| MASQ | MASQ_PORT |REW_OP|REW_OP|
74 * +------+------+------+------+------+------+------+------+
76 * +------+------+------+------+------+------+------+------+
78 * +------+------+------+------+------+------+------+------+
80 * +------+------+------+------+------+------+------+------+
82 * +------+------+------+------+------+------+------+------+
84 * +------+------+------+------+------+------+------+------+
86 * +------+------+------+------+------+------+------+------+
87 * 71: 64 | RSV | DEST |
88 * +------+------+------+------+------+------+------+------+
90 * +------+------+------+------+------+------+------+------+
92 * +------+------+------+------+------+------+------+------+
93 * 47: 40 | RSV | SRC_PORT | RSV |TFRM_TIMER|
94 * +------+------+------+------+------+------+------+------+
95 * 39: 32 | TFRM_TIMER | RSV |
96 * +------+------+------+------+------+------+------+------+
97 * 31: 24 | RSV | DP | POP_CNT | CPUQ |
98 * +------+------+------+------+------+------+------+------+
99 * 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
100 * +------+------+------+------+------+------+------+------+
101 * 15: 8 | PCP | DEI | VID |
102 * +------+------+------+------+------+------+------+------+
104 * +------+------+------+------+------+------+------+------+
106 * And the extraction header looks like this:
108 * +------+------+------+------+------+------+------+------+
109 * 127:120 | RSV | REW_OP |
110 * +------+------+------+------+------+------+------+------+
111 * 119:112 | REW_OP | REW_VAL |
112 * +------+------+------+------+------+------+------+------+
113 * 111:104 | REW_VAL |
114 * +------+------+------+------+------+------+------+------+
115 * 103: 96 | REW_VAL |
116 * +------+------+------+------+------+------+------+------+
118 * +------+------+------+------+------+------+------+------+
119 * 87: 80 | REW_VAL | LLEN |
120 * +------+------+------+------+------+------+------+------+
121 * 79: 72 | LLEN | WLEN |
122 * +------+------+------+------+------+------+------+------+
123 * 71: 64 | WLEN | RSV |
124 * +------+------+------+------+------+------+------+------+
126 * +------+------+------+------+------+------+------+------+
128 * +------+------+------+------+------+------+------+------+
129 * 47: 40 | RSV | SRC_PORT | ACL_ID |
130 * +------+------+------+------+------+------+------+------+
131 * 39: 32 | ACL_ID | RSV | SFLOW_ID |
132 * +------+------+------+------+------+------+------+------+
133 * 31: 24 |ACL_HIT| DP | LRN_FLAGS | CPUQ |
134 * +------+------+------+------+------+------+------+------+
135 * 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
136 * +------+------+------+------+------+------+------+------+
137 * 15: 8 | PCP | DEI | VID |
138 * +------+------+------+------+------+------+------+------+
140 * +------+------+------+------+------+------+------+------+
143 static inline void ocelot_xfh_get_rew_val(void *extraction, u64 *rew_val)
145 packing(extraction, rew_val, 116, 85, OCELOT_TAG_LEN, UNPACK, 0);
148 static inline void ocelot_xfh_get_len(void *extraction, u64 *len)
152 packing(extraction, &llen, 84, 79, OCELOT_TAG_LEN, UNPACK, 0);
153 packing(extraction, &wlen, 78, 71, OCELOT_TAG_LEN, UNPACK, 0);
155 *len = 60 * wlen + llen - 80;
158 static inline void ocelot_xfh_get_src_port(void *extraction, u64 *src_port)
160 packing(extraction, src_port, 46, 43, OCELOT_TAG_LEN, UNPACK, 0);
163 static inline void ocelot_xfh_get_qos_class(void *extraction, u64 *qos_class)
165 packing(extraction, qos_class, 19, 17, OCELOT_TAG_LEN, UNPACK, 0);
168 static inline void ocelot_xfh_get_tag_type(void *extraction, u64 *tag_type)
170 packing(extraction, tag_type, 16, 16, OCELOT_TAG_LEN, UNPACK, 0);
173 static inline void ocelot_xfh_get_vlan_tci(void *extraction, u64 *vlan_tci)
175 packing(extraction, vlan_tci, 15, 0, OCELOT_TAG_LEN, UNPACK, 0);
178 static inline void ocelot_ifh_set_bypass(void *injection, u64 bypass)
180 packing(injection, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
183 static inline void ocelot_ifh_set_rew_op(void *injection, u64 rew_op)
185 packing(injection, &rew_op, 125, 117, OCELOT_TAG_LEN, PACK, 0);
188 static inline void ocelot_ifh_set_dest(void *injection, u64 dest)
190 packing(injection, &dest, 67, 56, OCELOT_TAG_LEN, PACK, 0);
193 static inline void ocelot_ifh_set_qos_class(void *injection, u64 qos_class)
195 packing(injection, &qos_class, 19, 17, OCELOT_TAG_LEN, PACK, 0);
198 static inline void seville_ifh_set_dest(void *injection, u64 dest)
200 packing(injection, &dest, 67, 57, OCELOT_TAG_LEN, PACK, 0);
203 static inline void ocelot_ifh_set_src(void *injection, u64 src)
205 packing(injection, &src, 46, 43, OCELOT_TAG_LEN, PACK, 0);
208 static inline void ocelot_ifh_set_tag_type(void *injection, u64 tag_type)
210 packing(injection, &tag_type, 16, 16, OCELOT_TAG_LEN, PACK, 0);
213 static inline void ocelot_ifh_set_vid(void *injection, u64 vid)
215 packing(injection, &vid, 11, 0, OCELOT_TAG_LEN, PACK, 0);