net/mlx5: add VLAN push/pop DR commands to glue
[dpdk.git] / drivers / net / ipn3ke / ipn3ke_flow.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #ifndef _IPN3KE_FLOW_H_
6 #define _IPN3KE_FLOW_H_
7
8 /**
9  * Expand the length to DWORD alignment with 'Unused' field.
10  *
11  * FLOW KEY:
12  *  | Unused |Ruler id (id)  | Key1 Key2 … (data) |
13  *  |--------+---------------+--------------------|
14  *  | 17bits |    3 bits     |   Total 108 bits   |
15  * MSB                 --->                      LSB
16  *
17  * Note: And the MSb of key data is filled to 0 when it is less
18  *       than 108 bit.
19  */
20 #define IPN3KE_FLOW_KEY_UNUSED_BITS  17
21 #define IPN3KE_FLOW_KEY_ID_BITS      3
22 #define IPN3KE_FLOW_KEY_DATA_BITS    108
23
24 #define IPN3KE_FLOW_KEY_TOTAL_BITS \
25                 (IPN3KE_FLOW_KEY_UNUSED_BITS + \
26                 IPN3KE_FLOW_KEY_ID_BITS + \
27                 IPN3KE_FLOW_KEY_DATA_BITS)
28
29 #define IPN3KE_FLOW_KEY_ID_OFFSET \
30                 (IPN3KE_FLOW_KEY_UNUSED_BITS)
31
32 #define IPN3KE_FLOW_KEY_DATA_OFFSET \
33                 (IPN3KE_FLOW_KEY_ID_OFFSET + IPN3KE_FLOW_KEY_ID_BITS)
34
35 /**
36  * Expand the length to DWORD alignment with 'Unused' field.
37  *
38  * FLOW RESULT:
39  *  |  Unused | enable (acl) |    uid       |
40  *  |---------+--------------+--------------|
41  *  | 15 bits |    1 bit     |   16 bits    |
42  * MSB              --->                   LSB
43  */
44
45 #define IPN3KE_FLOW_RESULT_UNUSED_BITS 15
46 #define IPN3KE_FLOW_RESULT_ACL_BITS    1
47 #define IPN3KE_FLOW_RESULT_UID_BITS    16
48
49 #define IPN3KE_FLOW_RESULT_TOTAL_BITS \
50                 (IPN3KE_FLOW_RESULT_UNUSED_BITS + \
51                 IPN3KE_FLOW_RESULT_ACL_BITS + \
52                 IPN3KE_FLOW_RESULT_UID_BITS)
53
54 #define IPN3KE_FLOW_RESULT_ACL_OFFSET \
55                 (IPN3KE_FLOW_RESULT_UNUSED_BITS)
56
57 #define IPN3KE_FLOW_RESULT_UID_OFFSET \
58                 (IPN3KE_FLOW_RESULT_ACL_OFFSET + IPN3KE_FLOW_RESULT_ACL_BITS)
59
60 #define IPN3KE_FLOW_RESULT_UID_MAX \
61                 ((1UL << IPN3KE_FLOW_RESULT_UID_BITS) - 1)
62
63 #ifndef BITS_PER_BYTE
64 #define BITS_PER_BYTE    8
65 #endif
66 #define BITS_TO_BYTES(bits) \
67         (((bits) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
68
69 struct ipn3ke_flow_rule {
70         uint8_t key[BITS_TO_BYTES(IPN3KE_FLOW_KEY_TOTAL_BITS)];
71         uint8_t result[BITS_TO_BYTES(IPN3KE_FLOW_RESULT_TOTAL_BITS)];
72 };
73
74 struct rte_flow {
75         TAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */
76
77         struct ipn3ke_flow_rule rule;
78 };
79
80 TAILQ_HEAD(ipn3ke_flow_list, rte_flow);
81
82 static inline uint16_t ipn3ke_swap16(uint16_t x)
83 {
84         return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
85 }
86
87 static inline uint32_t ipn3ke_swap32(uint32_t x)
88 {
89         uint32_t high, low;
90         uint32_t high1, low1;
91
92         high = (x >> 16) & 0xffff;
93         low = x & 0xffff;
94         high1 = ipn3ke_swap16(low);
95         high1 = high1 << 16;
96         low1 = ipn3ke_swap16(high);
97         low1 = low1 & 0xffff;
98
99         return high1 | low1;
100 }
101
102 extern const struct rte_flow_ops ipn3ke_flow_ops;
103
104 int ipn3ke_flow_init(void *dev);
105
106 #endif /* _IPN3KE_FLOW_H_ */