Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018-2023 NXP
3 : : */
4 : :
5 : : #include <rte_mbuf.h>
6 : : #include <rte_ethdev.h>
7 : : #include <rte_malloc.h>
8 : : #include <rte_memcpy.h>
9 : : #include <rte_string_fns.h>
10 : : #include <dev_driver.h>
11 : :
12 : : #include <fslmc_logs.h>
13 : : #include <fslmc_vfio.h>
14 : : #include <dpaa2_hw_pvt.h>
15 : : #include <dpaa2_hw_dpio.h>
16 : : #include <dpaa2_hw_mempool.h>
17 : : #include <dpaa2_pmd_logs.h>
18 : :
19 : : #include "dpaa2_ethdev.h"
20 : : #include "dpaa2_sparser.h"
21 : : #include "base/dpaa2_hw_dpni_annot.h"
22 : : #define __STDC_FORMAT_MACROS
23 : : #include <stdint.h>
24 : : #include <inttypes.h>
25 : :
26 : : uint8_t wriop_bytecode[] = {
27 : : 0x00, 0x04, 0x29, 0x42, 0x03, 0xe0, 0x12, 0x00, 0x29, 0x02,
28 : : 0x18, 0x00, 0x87, 0x3c, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00
29 : : };
30 : :
31 : : struct frame_attr frame_attr_arr[] = {
32 : : /* Frame Attribute Flags 1 */
33 : : /* 000 */ {"Routing header present in IPv6 header 2 ", 0, 0x80000000},
34 : : /* 001 */ {"GTP Primed was detected ", 0, 0x40000000},
35 : : /* 002 */ {"VLAN with VID = 0 was detected ", 0, 0x20000000},
36 : : /* 003 */ {"A PTP frame was detected ", 0, 0x10000000},
37 : : /* 004 */ {"VXLAN was parsed ", 0, 0x08000000},
38 : : /* 005 */ {"A VXLAN HXS parsing error was detected ", 0, 0x04000000},
39 : : /* 006 */ {"Ethernet control protocol was detected ", 0, 0x02000000},
40 : : /* 007 */ {"IKE was detected at UDP port 4500 ", 0, 0x01000000},
41 : : /* 008 */ {"Shim Shell Soft Parsing Error ", 0, 0x00800000},
42 : : /* 009 */ {"Parsing Error ", 0, 0x00400000},
43 : : /* 010 */ {"Ethernet MAC Present ", 0, 0x00200000},
44 : : /* 011 */ {"Ethernet Unicast ", 0, 0x00100000},
45 : : /* 012 */ {"Ethernet Multicast ", 0, 0x00080000},
46 : : /* 013 */ {"Ethernet Broadcast ", 0, 0x00040000},
47 : : /* 014 */ {"BPDU frame (MAC DA is 01:80:C2:00:00:00)", 0, 0x00020000},
48 : : /* 015 */ {"FCoE detected (Ether type is 0x8906) ", 0, 0x00010000},
49 : : /* 016 */ {"FIP detected (Ether type is 0x8914) ", 0, 0x00008000},
50 : : /* 017 */ {"Ethernet Parsing Error ", 0, 0x00004000},
51 : : /* 018 */ {"LLC+SNAP Present ", 0, 0x00002000},
52 : : /* 019 */ {"Unknown LLC/OUI ", 0, 0x00001000},
53 : : /* 020 */ {"LLC+SNAP Error ", 0, 0x00000800},
54 : : /* 021 */ {"VLAN 1 Present ", 0, 0x00000400},
55 : : /* 022 */ {"VLAN n Present ", 0, 0x00000200},
56 : : /* 023 */ {"CFI bit in a \"8100\" VLAN tag is set ", 0, 0x00000100},
57 : : /* 024 */ {"VLAN Parsing Error ", 0, 0x00000080},
58 : : /* 025 */ {"PPPoE+PPP Present ", 0, 0x00000040},
59 : : /* 026 */ {"PPPoE+PPP Parsing Error ", 0, 0x00000020},
60 : : /* 027 */ {"MPLS 1 Present ", 0, 0x00000010},
61 : : /* 028 */ {"MPLS n Present ", 0, 0x00000008},
62 : : /* 029 */ {"MPLS Parsing Error ", 0, 0x00000004},
63 : : /* 030 */ {"ARP frame Present (Ethertype 0x0806) ", 0, 0x00000002},
64 : : /* 031 */ {"ARP Parsing Error ", 0, 0x00000001},
65 : : /* Frame Attribute Flags 2 */
66 : : /* 032 */ {"L2 Unknown Protocol ", 1, 0x80000000},
67 : : /* 033 */ {"L2 Soft Parsing Error ", 1, 0x40000000},
68 : : /* 034 */ {"IPv4 1 Present ", 1, 0x20000000},
69 : : /* 035 */ {"IPv4 1 Unicast ", 1, 0x10000000},
70 : : /* 036 */ {"IPv4 1 Multicast ", 1, 0x08000000},
71 : : /* 037 */ {"IPv4 1 Broadcast ", 1, 0x04000000},
72 : : /* 038 */ {"IPv4 n Present ", 1, 0x02000000},
73 : : /* 039 */ {"IPv4 n Unicast ", 1, 0x01000000},
74 : : /* 040 */ {"IPv4 n Multicast ", 1, 0x00800000},
75 : : /* 041 */ {"IPv4 n Broadcast ", 1, 0x00400000},
76 : : /* 042 */ {"IPv6 1 Present ", 1, 0x00200000},
77 : : /* 043 */ {"IPv6 1 Unicast ", 1, 0x00100000},
78 : : /* 044 */ {"IPv6 1 Multicast ", 1, 0x00080000},
79 : : /* 045 */ {"IPv6 n Present ", 1, 0x00040000},
80 : : /* 046 */ {"IPv6 n Unicast ", 1, 0x00020000},
81 : : /* 047 */ {"IPv6 n Multicast ", 1, 0x00010000},
82 : : /* 048 */ {"IP 1 option present ", 1, 0x00008000},
83 : : /* 049 */ {"IP 1 Unknown Protocol ", 1, 0x00004000},
84 : : /* 050 */ {"IP 1 Packet is a fragment ", 1, 0x00002000},
85 : : /* 051 */ {"IP 1 Packet is an initial fragment ", 1, 0x00001000},
86 : : /* 052 */ {"IP 1 Parsing Error ", 1, 0x00000800},
87 : : /* 053 */ {"IP n option present ", 1, 0x00000400},
88 : : /* 054 */ {"IP n Unknown Protocol ", 1, 0x00000200},
89 : : /* 055 */ {"IP n Packet is a fragment ", 1, 0x00000100},
90 : : /* 056 */ {"IP n Packet is an initial fragment ", 1, 0x00000080},
91 : : /* 057 */ {"ICMP detected (IP proto is 1) ", 1, 0x00000040},
92 : : /* 058 */ {"IGMP detected (IP proto is 2) ", 1, 0x00000020},
93 : : /* 059 */ {"ICMPv6 detected (IP proto is 3a) ", 1, 0x00000010},
94 : : /* 060 */ {"UDP Light detected (IP proto is 136) ", 1, 0x00000008},
95 : : /* 061 */ {"IP n Parsing Error ", 1, 0x00000004},
96 : : /* 062 */ {"Min. Encap Present ", 1, 0x00000002},
97 : : /* 063 */ {"Min. Encap S flag set ", 1, 0x00000001},
98 : : /* Frame Attribute Flags 3 */
99 : : /* 064 */ {"Min. Encap Parsing Error ", 2, 0x80000000},
100 : : /* 065 */ {"GRE Present ", 2, 0x40000000},
101 : : /* 066 */ {"GRE R bit set ", 2, 0x20000000},
102 : : /* 067 */ {"GRE Parsing Error ", 2, 0x10000000},
103 : : /* 068 */ {"L3 Unknown Protocol ", 2, 0x08000000},
104 : : /* 069 */ {"L3 Soft Parsing Error ", 2, 0x04000000},
105 : : /* 070 */ {"UDP Present ", 2, 0x02000000},
106 : : /* 071 */ {"UDP Parsing Error ", 2, 0x01000000},
107 : : /* 072 */ {"TCP Present ", 2, 0x00800000},
108 : : /* 073 */ {"TCP options present ", 2, 0x00400000},
109 : : /* 074 */ {"TCP Control bits 6-11 set ", 2, 0x00200000},
110 : : /* 075 */ {"TCP Control bits 3-5 set ", 2, 0x00100000},
111 : : /* 076 */ {"TCP Parsing Error ", 2, 0x00080000},
112 : : /* 077 */ {"IPSec Present ", 2, 0x00040000},
113 : : /* 078 */ {"IPSec ESP found ", 2, 0x00020000},
114 : : /* 079 */ {"IPSec AH found ", 2, 0x00010000},
115 : : /* 080 */ {"IPSec Parsing Error ", 2, 0x00008000},
116 : : /* 081 */ {"SCTP Present ", 2, 0x00004000},
117 : : /* 082 */ {"SCTP Parsing Error ", 2, 0x00002000},
118 : : /* 083 */ {"DCCP Present ", 2, 0x00001000},
119 : : /* 084 */ {"DCCP Parsing Error ", 2, 0x00000800},
120 : : /* 085 */ {"L4 Unknown Protocol ", 2, 0x00000400},
121 : : /* 086 */ {"L4 Soft Parsing Error ", 2, 0x00000200},
122 : : /* 087 */ {"GTP Present ", 2, 0x00000100},
123 : : /* 088 */ {"GTP Parsing Error ", 2, 0x00000080},
124 : : /* 089 */ {"ESP Present ", 2, 0x00000040},
125 : : /* 090 */ {"ESP Parsing Error ", 2, 0x00000020},
126 : : /* 091 */ {"iSCSI detected (Port# 860) ", 2, 0x00000010},
127 : : /* 092 */ {"Capwap-control detected (Port# 5246) ", 2, 0x00000008},
128 : : /* 093 */ {"Capwap-data detected (Port# 5247) ", 2, 0x00000004},
129 : : /* 094 */ {"L5 Soft Parsing Error ", 2, 0x00000002},
130 : : /* 095 */ {"IPv6 Route hdr1 present ", 2, 0x00000001},
131 : : /* 096 */ {NULL, 0, 0x00000000}
132 : : };
133 : :
134 : : struct frame_attr_ext frame_attr_ext_arr[] = {
135 : : /* Frame Attribute Flags Extension */
136 : : /* 096 */ {"User defined soft parser bit #0 ", 0, 0x8000},
137 : : /* 096 */ {"User defined soft parser bit #1 ", 0, 0x4000},
138 : : /* 096 */ {"User defined soft parser bit #2 ", 0, 0x2000},
139 : : /* 096 */ {"User defined soft parser bit #3 ", 0, 0x1000},
140 : : /* 096 */ {"User defined soft parser bit #4 ", 0, 0x0800},
141 : : /* 096 */ {"User defined soft parser bit #5 ", 0, 0x0400},
142 : : /* 096 */ {"User defined soft parser bit #6 ", 0, 0x0200},
143 : : /* 096 */ {"User defined soft parser bit #7 ", 0, 0x0100},
144 : : /* 097 */ {"Reserved ", 0, 0x00ff},
145 : : /* 112 */ {NULL, 0, 0x0000}
146 : : };
147 : :
148 : 0 : int dpaa2_eth_load_wriop_soft_parser(struct dpaa2_dev_priv *priv,
149 : : enum dpni_soft_sequence_dest dest)
150 : : {
151 : 0 : struct fsl_mc_io *dpni = priv->hw;
152 : : struct dpni_load_ss_cfg cfg;
153 : : struct dpni_drv_sparser_param sp_param;
154 : : uint8_t *addr;
155 : : int ret;
156 : :
157 : : memset(&sp_param, 0, sizeof(sp_param));
158 : 0 : sp_param.start_pc = priv->ss_offset;
159 : 0 : sp_param.byte_code = &wriop_bytecode[0];
160 : 0 : sp_param.size = sizeof(wriop_bytecode);
161 : :
162 : 0 : cfg.dest = dest;
163 : 0 : cfg.ss_offset = sp_param.start_pc;
164 : 0 : cfg.ss_size = sp_param.size;
165 : :
166 : 0 : addr = rte_malloc(NULL, sp_param.size, 64);
167 [ # # ]: 0 : if (!addr) {
168 : 0 : DPAA2_PMD_ERR("Memory unavailable for soft parser param");
169 : 0 : return -1;
170 : : }
171 : :
172 : : memcpy(addr, sp_param.byte_code, sp_param.size);
173 : 0 : cfg.ss_iova = DPAA2_VADDR_TO_IOVA_AND_CHECK(addr, sp_param.size);
174 [ # # ]: 0 : if (cfg.ss_iova == RTE_BAD_IOVA) {
175 : 0 : DPAA2_PMD_ERR("No IOMMU map for soft sequence(%p), size=%d",
176 : : addr, sp_param.size);
177 : 0 : rte_free(addr);
178 : :
179 : 0 : return -ENOBUFS;
180 : : }
181 : :
182 : 0 : ret = dpni_load_sw_sequence(dpni, CMD_PRI_LOW, priv->token, &cfg);
183 [ # # ]: 0 : if (ret) {
184 : 0 : DPAA2_PMD_ERR("dpni_load_sw_sequence failed");
185 : 0 : rte_free(addr);
186 : 0 : return ret;
187 : : }
188 : :
189 : 0 : priv->ss_iova = cfg.ss_iova;
190 : 0 : priv->ss_offset += sp_param.size;
191 : 0 : DPAA2_PMD_INFO("Soft parser loaded for dpni@%d", priv->hw_id);
192 : :
193 : 0 : rte_free(addr);
194 : 0 : return 0;
195 : : }
196 : :
197 : 0 : int dpaa2_eth_enable_wriop_soft_parser(struct dpaa2_dev_priv *priv,
198 : : enum dpni_soft_sequence_dest dest)
199 : : {
200 : 0 : struct fsl_mc_io *dpni = priv->hw;
201 : : struct dpni_enable_ss_cfg cfg;
202 : : uint8_t pa[3];
203 : : struct dpni_drv_sparser_param sp_param;
204 : : uint8_t *param_addr = NULL;
205 : : int ret;
206 : :
207 : : memset(&sp_param, 0, sizeof(sp_param));
208 : 0 : pa[0] = 32; /* Custom Header Length in bytes */
209 : 0 : sp_param.custom_header_first = 1;
210 : 0 : sp_param.param_offset = 32;
211 : 0 : sp_param.param_size = 1;
212 : 0 : sp_param.start_pc = priv->ss_offset;
213 : 0 : sp_param.param_array = (uint8_t *)&pa[0];
214 : :
215 : 0 : cfg.dest = dest;
216 : 0 : cfg.ss_offset = sp_param.start_pc;
217 : 0 : cfg.set_start = sp_param.custom_header_first;
218 : 0 : cfg.hxs = (uint16_t)sp_param.link_to_hard_hxs;
219 : 0 : cfg.param_offset = sp_param.param_offset;
220 : 0 : cfg.param_size = sp_param.param_size;
221 : : if (cfg.param_size) {
222 : 0 : param_addr = rte_malloc(NULL, cfg.param_size, 64);
223 [ # # ]: 0 : if (!param_addr) {
224 : 0 : DPAA2_PMD_ERR("Memory unavailable for soft parser param");
225 : 0 : return -1;
226 : : }
227 : :
228 : 0 : memcpy(param_addr, sp_param.param_array, cfg.param_size);
229 : 0 : cfg.param_iova = DPAA2_VADDR_TO_IOVA_AND_CHECK(param_addr,
230 : : cfg.param_size);
231 [ # # ]: 0 : if (cfg.param_iova == RTE_BAD_IOVA) {
232 : 0 : DPAA2_PMD_ERR("%s: No IOMMU map for %p, size=%d",
233 : : __func__, param_addr, cfg.param_size);
234 : 0 : rte_free(param_addr);
235 : :
236 : 0 : return -ENOBUFS;
237 : : }
238 : 0 : priv->ss_param_iova = cfg.param_iova;
239 : : } else {
240 : : cfg.param_iova = 0;
241 : : }
242 : :
243 : 0 : ret = dpni_enable_sw_sequence(dpni, CMD_PRI_LOW, priv->token, &cfg);
244 [ # # ]: 0 : if (ret) {
245 : 0 : DPAA2_PMD_ERR("Soft parser enabled for dpni@%d failed",
246 : : priv->hw_id);
247 : 0 : rte_free(param_addr);
248 : 0 : return ret;
249 : : }
250 : :
251 : 0 : rte_free(param_addr);
252 : 0 : DPAA2_PMD_INFO("Soft parser enabled for dpni@%d", priv->hw_id);
253 : 0 : return 0;
254 : : }
|