ocelot.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* SPDX-License-Identifier: GPL-2.0
  2. * Copyright 2019-2021 NXP
  3. */
  4. #ifndef _NET_DSA_TAG_OCELOT_H
  5. #define _NET_DSA_TAG_OCELOT_H
  6. #include <linux/kthread.h>
  7. #include <linux/packing.h>
  8. #include <linux/skbuff.h>
  9. #include <net/dsa.h>
  10. struct ocelot_skb_cb {
  11. struct sk_buff *clone;
  12. unsigned int ptp_class; /* valid only for clones */
  13. u32 tstamp_lo;
  14. u8 ptp_cmd;
  15. u8 ts_id;
  16. };
  17. #define OCELOT_SKB_CB(skb) \
  18. ((struct ocelot_skb_cb *)((skb)->cb))
  19. #define IFH_TAG_TYPE_C 0
  20. #define IFH_TAG_TYPE_S 1
  21. #define IFH_REW_OP_NOOP 0x0
  22. #define IFH_REW_OP_DSCP 0x1
  23. #define IFH_REW_OP_ONE_STEP_PTP 0x2
  24. #define IFH_REW_OP_TWO_STEP_PTP 0x3
  25. #define IFH_REW_OP_ORIGIN_PTP 0x5
  26. #define OCELOT_TAG_LEN 16
  27. #define OCELOT_SHORT_PREFIX_LEN 4
  28. #define OCELOT_LONG_PREFIX_LEN 16
  29. #define OCELOT_TOTAL_TAG_LEN (OCELOT_SHORT_PREFIX_LEN + OCELOT_TAG_LEN)
  30. /* The CPU injection header and the CPU extraction header can have 3 types of
  31. * prefixes: long, short and no prefix. The format of the header itself is the
  32. * same in all 3 cases.
  33. *
  34. * Extraction with long prefix:
  35. *
  36. * +-------------------+-------------------+------+------+------------+-------+
  37. * | ff:ff:ff:ff:ff:ff | fe:ff:ff:ff:ff:ff | 8880 | 000a | extraction | frame |
  38. * | | | | | header | |
  39. * +-------------------+-------------------+------+------+------------+-------+
  40. * 48 bits 48 bits 16 bits 16 bits 128 bits
  41. *
  42. * Extraction with short prefix:
  43. *
  44. * +------+------+------------+-------+
  45. * | 8880 | 000a | extraction | frame |
  46. * | | | header | |
  47. * +------+------+------------+-------+
  48. * 16 bits 16 bits 128 bits
  49. *
  50. * Extraction with no prefix:
  51. *
  52. * +------------+-------+
  53. * | extraction | frame |
  54. * | header | |
  55. * +------------+-------+
  56. * 128 bits
  57. *
  58. *
  59. * Injection with long prefix:
  60. *
  61. * +-------------------+-------------------+------+------+------------+-------+
  62. * | any dmac | any smac | 8880 | 000a | injection | frame |
  63. * | | | | | header | |
  64. * +-------------------+-------------------+------+------+------------+-------+
  65. * 48 bits 48 bits 16 bits 16 bits 128 bits
  66. *
  67. * Injection with short prefix:
  68. *
  69. * +------+------+------------+-------+
  70. * | 8880 | 000a | injection | frame |
  71. * | | | header | |
  72. * +------+------+------------+-------+
  73. * 16 bits 16 bits 128 bits
  74. *
  75. * Injection with no prefix:
  76. *
  77. * +------------+-------+
  78. * | injection | frame |
  79. * | header | |
  80. * +------------+-------+
  81. * 128 bits
  82. *
  83. * The injection header looks like this (network byte order, bit 127
  84. * is part of lowest address byte in memory, bit 0 is part of highest
  85. * address byte):
  86. *
  87. * +------+------+------+------+------+------+------+------+
  88. * 127:120 |BYPASS| MASQ | MASQ_PORT |REW_OP|REW_OP|
  89. * +------+------+------+------+------+------+------+------+
  90. * 119:112 | REW_OP |
  91. * +------+------+------+------+------+------+------+------+
  92. * 111:104 | REW_VAL |
  93. * +------+------+------+------+------+------+------+------+
  94. * 103: 96 | REW_VAL |
  95. * +------+------+------+------+------+------+------+------+
  96. * 95: 88 | REW_VAL |
  97. * +------+------+------+------+------+------+------+------+
  98. * 87: 80 | REW_VAL |
  99. * +------+------+------+------+------+------+------+------+
  100. * 79: 72 | RSV |
  101. * +------+------+------+------+------+------+------+------+
  102. * 71: 64 | RSV | DEST |
  103. * +------+------+------+------+------+------+------+------+
  104. * 63: 56 | DEST |
  105. * +------+------+------+------+------+------+------+------+
  106. * 55: 48 | RSV |
  107. * +------+------+------+------+------+------+------+------+
  108. * 47: 40 | RSV | SRC_PORT | RSV |TFRM_TIMER|
  109. * +------+------+------+------+------+------+------+------+
  110. * 39: 32 | TFRM_TIMER | RSV |
  111. * +------+------+------+------+------+------+------+------+
  112. * 31: 24 | RSV | DP | POP_CNT | CPUQ |
  113. * +------+------+------+------+------+------+------+------+
  114. * 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
  115. * +------+------+------+------+------+------+------+------+
  116. * 15: 8 | PCP | DEI | VID |
  117. * +------+------+------+------+------+------+------+------+
  118. * 7: 0 | VID |
  119. * +------+------+------+------+------+------+------+------+
  120. *
  121. * And the extraction header looks like this:
  122. *
  123. * +------+------+------+------+------+------+------+------+
  124. * 127:120 | RSV | REW_OP |
  125. * +------+------+------+------+------+------+------+------+
  126. * 119:112 | REW_OP | REW_VAL |
  127. * +------+------+------+------+------+------+------+------+
  128. * 111:104 | REW_VAL |
  129. * +------+------+------+------+------+------+------+------+
  130. * 103: 96 | REW_VAL |
  131. * +------+------+------+------+------+------+------+------+
  132. * 95: 88 | REW_VAL |
  133. * +------+------+------+------+------+------+------+------+
  134. * 87: 80 | REW_VAL | LLEN |
  135. * +------+------+------+------+------+------+------+------+
  136. * 79: 72 | LLEN | WLEN |
  137. * +------+------+------+------+------+------+------+------+
  138. * 71: 64 | WLEN | RSV |
  139. * +------+------+------+------+------+------+------+------+
  140. * 63: 56 | RSV |
  141. * +------+------+------+------+------+------+------+------+
  142. * 55: 48 | RSV |
  143. * +------+------+------+------+------+------+------+------+
  144. * 47: 40 | RSV | SRC_PORT | ACL_ID |
  145. * +------+------+------+------+------+------+------+------+
  146. * 39: 32 | ACL_ID | RSV | SFLOW_ID |
  147. * +------+------+------+------+------+------+------+------+
  148. * 31: 24 |ACL_HIT| DP | LRN_FLAGS | CPUQ |
  149. * +------+------+------+------+------+------+------+------+
  150. * 23: 16 | CPUQ | QOS_CLASS |TAG_TYPE|
  151. * +------+------+------+------+------+------+------+------+
  152. * 15: 8 | PCP | DEI | VID |
  153. * +------+------+------+------+------+------+------+------+
  154. * 7: 0 | VID |
  155. * +------+------+------+------+------+------+------+------+
  156. */
  157. struct felix_deferred_xmit_work {
  158. struct dsa_port *dp;
  159. struct sk_buff *skb;
  160. struct kthread_work work;
  161. };
  162. struct ocelot_8021q_tagger_data {
  163. void (*xmit_work_fn)(struct kthread_work *work);
  164. };
  165. static inline struct ocelot_8021q_tagger_data *
  166. ocelot_8021q_tagger_data(struct dsa_switch *ds)
  167. {
  168. BUG_ON(ds->dst->tag_ops->proto != DSA_TAG_PROTO_OCELOT_8021Q);
  169. return ds->tagger_data;
  170. }
  171. static inline void ocelot_xfh_get_rew_val(void *extraction, u64 *rew_val)
  172. {
  173. packing(extraction, rew_val, 116, 85, OCELOT_TAG_LEN, UNPACK, 0);
  174. }
  175. static inline void ocelot_xfh_get_len(void *extraction, u64 *len)
  176. {
  177. u64 llen, wlen;
  178. packing(extraction, &llen, 84, 79, OCELOT_TAG_LEN, UNPACK, 0);
  179. packing(extraction, &wlen, 78, 71, OCELOT_TAG_LEN, UNPACK, 0);
  180. *len = 60 * wlen + llen - 80;
  181. }
  182. static inline void ocelot_xfh_get_src_port(void *extraction, u64 *src_port)
  183. {
  184. packing(extraction, src_port, 46, 43, OCELOT_TAG_LEN, UNPACK, 0);
  185. }
  186. static inline void ocelot_xfh_get_qos_class(void *extraction, u64 *qos_class)
  187. {
  188. packing(extraction, qos_class, 19, 17, OCELOT_TAG_LEN, UNPACK, 0);
  189. }
  190. static inline void ocelot_xfh_get_tag_type(void *extraction, u64 *tag_type)
  191. {
  192. packing(extraction, tag_type, 16, 16, OCELOT_TAG_LEN, UNPACK, 0);
  193. }
  194. static inline void ocelot_xfh_get_vlan_tci(void *extraction, u64 *vlan_tci)
  195. {
  196. packing(extraction, vlan_tci, 15, 0, OCELOT_TAG_LEN, UNPACK, 0);
  197. }
  198. static inline void ocelot_ifh_set_bypass(void *injection, u64 bypass)
  199. {
  200. packing(injection, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
  201. }
  202. static inline void ocelot_ifh_set_rew_op(void *injection, u64 rew_op)
  203. {
  204. packing(injection, &rew_op, 125, 117, OCELOT_TAG_LEN, PACK, 0);
  205. }
  206. static inline void ocelot_ifh_set_dest(void *injection, u64 dest)
  207. {
  208. packing(injection, &dest, 67, 56, OCELOT_TAG_LEN, PACK, 0);
  209. }
  210. static inline void ocelot_ifh_set_qos_class(void *injection, u64 qos_class)
  211. {
  212. packing(injection, &qos_class, 19, 17, OCELOT_TAG_LEN, PACK, 0);
  213. }
  214. static inline void seville_ifh_set_dest(void *injection, u64 dest)
  215. {
  216. packing(injection, &dest, 67, 57, OCELOT_TAG_LEN, PACK, 0);
  217. }
  218. static inline void ocelot_ifh_set_src(void *injection, u64 src)
  219. {
  220. packing(injection, &src, 46, 43, OCELOT_TAG_LEN, PACK, 0);
  221. }
  222. static inline void ocelot_ifh_set_tag_type(void *injection, u64 tag_type)
  223. {
  224. packing(injection, &tag_type, 16, 16, OCELOT_TAG_LEN, PACK, 0);
  225. }
  226. static inline void ocelot_ifh_set_vlan_tci(void *injection, u64 vlan_tci)
  227. {
  228. packing(injection, &vlan_tci, 15, 0, OCELOT_TAG_LEN, PACK, 0);
  229. }
  230. /* Determine the PTP REW_OP to use for injecting the given skb */
  231. static inline u32 ocelot_ptp_rew_op(struct sk_buff *skb)
  232. {
  233. struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone;
  234. u8 ptp_cmd = OCELOT_SKB_CB(skb)->ptp_cmd;
  235. u32 rew_op = 0;
  236. if (ptp_cmd == IFH_REW_OP_TWO_STEP_PTP && clone) {
  237. rew_op = ptp_cmd;
  238. rew_op |= OCELOT_SKB_CB(clone)->ts_id << 3;
  239. } else if (ptp_cmd == IFH_REW_OP_ORIGIN_PTP) {
  240. rew_op = ptp_cmd;
  241. }
  242. return rew_op;
  243. }
  244. #endif