1 /* SPDX-License-Identifier: GPL-2.0
2 * Copyright 2019-2021 NXP
5 #ifndef _NET_DSA_TAG_OCELOT_H
6 #define _NET_DSA_TAG_OCELOT_H
8 #include <linux/kthread.h>
9 #include <linux/packing.h>
10 #include <linux/skbuff.h>
12 struct ocelot_skb_cb {
13 struct sk_buff *clone;
14 unsigned int ptp_class; /* valid only for clones */
19 #define OCELOT_SKB_CB(skb) \
20 ((struct ocelot_skb_cb *)((skb)->cb))
22 #define IFH_TAG_TYPE_C 0
23 #define IFH_TAG_TYPE_S 1
25 #define IFH_REW_OP_NOOP 0x0
26 #define IFH_REW_OP_DSCP 0x1
27 #define IFH_REW_OP_ONE_STEP_PTP 0x2
28 #define IFH_REW_OP_TWO_STEP_PTP 0x3
29 #define IFH_REW_OP_ORIGIN_PTP 0x5
31 #define OCELOT_TAG_LEN 16
32 #define OCELOT_SHORT_PREFIX_LEN 4
33 #define OCELOT_LONG_PREFIX_LEN 16
34 #define OCELOT_TOTAL_TAG_LEN (OCELOT_SHORT_PREFIX_LEN + OCELOT_TAG_LEN)
36 /* The CPU injection header and the CPU extraction header can have 3 types of
37 * prefixes: long, short and no prefix. The format of the header itself is the
38 * same in all 3 cases.
40 * Extraction with long prefix:
42 * +-------------------+-------------------+------+------+------------+-------+
43 * | ff:ff:ff:ff:ff:ff | fe:ff:ff:ff:ff:ff | 8880 | 000a | extraction | frame |
44 * | | | | | header | |
45 * +-------------------+-------------------+------+------+------------+-------+
46 * 48 bits 48 bits 16 bits 16 bits 128 bits
48 * Extraction with short prefix:
50 * +------+------+------------+-------+
51 * | 8880 | 000a | extraction | frame |
53 * +------+------+------------+-------+
54 * 16 bits 16 bits 128 bits
56 * Extraction with no prefix:
58 * +------------+-------+
59 * | extraction | frame |
61 * +------------+-------+
65 * Injection with long prefix:
67 * +-------------------+-------------------+------+------+------------+-------+
68 * | any dmac | any smac | 8880 | 000a | injection | frame |
69 * | | | | | header | |
70 * +-------------------+-------------------+------+------+------------+-------+
71 * 48 bits 48 bits 16 bits 16 bits 128 bits
73 * Injection with short prefix:
75 * +------+------+------------+-------+
76 * | 8880 | 000a | injection | frame |
78 * +------+------+------------+-------+
79 * 16 bits 16 bits 128 bits
81 * Injection with no prefix:
83 * +------------+-------+
84 * | injection | frame |
86 * +------------+-------+
89 * The injection header looks like this (network byte order, bit 127
90 * is part of lowest address byte in memory, bit 0 is part of highest
93 * +------+------+------+------+------+------+------+------+
94 * 127:120 |BYPASS| MASQ | MASQ_PORT |REW_OP|REW_OP|
95 * +------+------+------+------+------+------+------+------+
97 * +------+------+------+------+------+------+------+------+
99 * +------+------+------+------+------+------+------+------+
100 * 103: 96 | REW_VAL |
101 * +------+------+------+------+------+------+------+------+
103 * +------+------+------+------+------+------+------+------+
105 * +------+------+------+------+------+------+------+------+
107 * +------+------+------+------+------+------+------+------+
108 * 71: 64 | RSV | DEST |
109 * +------+------+------+------+------+------+------+------+
111 * +------+------+------+------+------+------+------+------+
113 * +------+------+------+------+------+------+------+------+
114 * 47: 40 | RSV | SRC_PORT | RSV |TFRM_TIMER|
115 * +------+------+------+------+------+------+------+------+
116 * 39: 32 | TFRM_TIMER | RSV |
117 * +------+------+------+------+------+------+------+------+
118 * 31: 24 | RSV | DP | POP_CNT | CPUQ |
119 * +------+------+------+------+------+------+------+------+
120 * 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
121 * +------+------+------+------+------+------+------+------+
122 * 15: 8 | PCP | DEI | VID |
123 * +------+------+------+------+------+------+------+------+
125 * +------+------+------+------+------+------+------+------+
127 * And the extraction header looks like this:
129 * +------+------+------+------+------+------+------+------+
130 * 127:120 | RSV | REW_OP |
131 * +------+------+------+------+------+------+------+------+
132 * 119:112 | REW_OP | REW_VAL |
133 * +------+------+------+------+------+------+------+------+
134 * 111:104 | REW_VAL |
135 * +------+------+------+------+------+------+------+------+
136 * 103: 96 | REW_VAL |
137 * +------+------+------+------+------+------+------+------+
139 * +------+------+------+------+------+------+------+------+
140 * 87: 80 | REW_VAL | LLEN |
141 * +------+------+------+------+------+------+------+------+
142 * 79: 72 | LLEN | WLEN |
143 * +------+------+------+------+------+------+------+------+
144 * 71: 64 | WLEN | RSV |
145 * +------+------+------+------+------+------+------+------+
147 * +------+------+------+------+------+------+------+------+
149 * +------+------+------+------+------+------+------+------+
150 * 47: 40 | RSV | SRC_PORT | ACL_ID |
151 * +------+------+------+------+------+------+------+------+
152 * 39: 32 | ACL_ID | RSV | SFLOW_ID |
153 * +------+------+------+------+------+------+------+------+
154 * 31: 24 |ACL_HIT| DP | LRN_FLAGS | CPUQ |
155 * +------+------+------+------+------+------+------+------+
156 * 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
157 * +------+------+------+------+------+------+------+------+
158 * 15: 8 | PCP | DEI | VID |
159 * +------+------+------+------+------+------+------+------+
161 * +------+------+------+------+------+------+------+------+
164 struct felix_deferred_xmit_work {
167 struct kthread_work work;
171 void (*xmit_work_fn)(struct kthread_work *work);
172 struct kthread_worker *xmit_worker;
175 static inline void ocelot_xfh_get_rew_val(void *extraction, u64 *rew_val)
177 packing(extraction, rew_val, 116, 85, OCELOT_TAG_LEN, UNPACK, 0);
180 static inline void ocelot_xfh_get_len(void *extraction, u64 *len)
184 packing(extraction, &llen, 84, 79, OCELOT_TAG_LEN, UNPACK, 0);
185 packing(extraction, &wlen, 78, 71, OCELOT_TAG_LEN, UNPACK, 0);
187 *len = 60 * wlen + llen - 80;
190 static inline void ocelot_xfh_get_src_port(void *extraction, u64 *src_port)
192 packing(extraction, src_port, 46, 43, OCELOT_TAG_LEN, UNPACK, 0);
195 static inline void ocelot_xfh_get_qos_class(void *extraction, u64 *qos_class)
197 packing(extraction, qos_class, 19, 17, OCELOT_TAG_LEN, UNPACK, 0);
200 static inline void ocelot_xfh_get_tag_type(void *extraction, u64 *tag_type)
202 packing(extraction, tag_type, 16, 16, OCELOT_TAG_LEN, UNPACK, 0);
205 static inline void ocelot_xfh_get_vlan_tci(void *extraction, u64 *vlan_tci)
207 packing(extraction, vlan_tci, 15, 0, OCELOT_TAG_LEN, UNPACK, 0);
210 static inline void ocelot_ifh_set_bypass(void *injection, u64 bypass)
212 packing(injection, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
215 static inline void ocelot_ifh_set_rew_op(void *injection, u64 rew_op)
217 packing(injection, &rew_op, 125, 117, OCELOT_TAG_LEN, PACK, 0);
220 static inline void ocelot_ifh_set_dest(void *injection, u64 dest)
222 packing(injection, &dest, 67, 56, OCELOT_TAG_LEN, PACK, 0);
225 static inline void ocelot_ifh_set_qos_class(void *injection, u64 qos_class)
227 packing(injection, &qos_class, 19, 17, OCELOT_TAG_LEN, PACK, 0);
230 static inline void seville_ifh_set_dest(void *injection, u64 dest)
232 packing(injection, &dest, 67, 57, OCELOT_TAG_LEN, PACK, 0);
235 static inline void ocelot_ifh_set_src(void *injection, u64 src)
237 packing(injection, &src, 46, 43, OCELOT_TAG_LEN, PACK, 0);
240 static inline void ocelot_ifh_set_tag_type(void *injection, u64 tag_type)
242 packing(injection, &tag_type, 16, 16, OCELOT_TAG_LEN, PACK, 0);
245 static inline void ocelot_ifh_set_vid(void *injection, u64 vid)
247 packing(injection, &vid, 11, 0, OCELOT_TAG_LEN, PACK, 0);
250 /* Determine the PTP REW_OP to use for injecting the given skb */
251 static inline u32 ocelot_ptp_rew_op(struct sk_buff *skb)
253 struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone;
254 u8 ptp_cmd = OCELOT_SKB_CB(skb)->ptp_cmd;
257 if (ptp_cmd == IFH_REW_OP_TWO_STEP_PTP && clone) {
259 rew_op |= OCELOT_SKB_CB(clone)->ts_id << 3;
260 } else if (ptp_cmd == IFH_REW_OP_ORIGIN_PTP) {