1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2019 NXP
6 #include <rte_ethdev.h>
7 #include <rte_malloc.h>
8 #include <rte_memcpy.h>
9 #include <rte_string_fns.h>
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>
19 #include "dpaa2_ethdev.h"
20 #include "dpaa2_sparser.h"
21 #include "base/dpaa2_hw_dpni_annot.h"
22 #define __STDC_FORMAT_MACROS
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
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}
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}
148 int dpaa2_eth_load_wriop_soft_parser(struct dpaa2_dev_priv *priv,
149 enum dpni_soft_sequence_dest dest)
151 struct fsl_mc_io *dpni = priv->hw;
152 struct dpni_load_ss_cfg cfg;
153 struct dpni_drv_sparser_param sp_param;
157 memset(&sp_param, 0, sizeof(sp_param));
158 sp_param.start_pc = priv->ss_offset;
159 sp_param.byte_code = &wriop_bytecode[0];
160 sp_param.size = sizeof(wriop_bytecode);
163 cfg.ss_offset = sp_param.start_pc;
164 cfg.ss_size = sp_param.size;
166 addr = rte_malloc(NULL, sp_param.size, 64);
168 DPAA2_PMD_ERR("Memory unavailable for soft parser param\n");
172 memcpy(addr, sp_param.byte_code, sp_param.size);
173 cfg.ss_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(addr));
175 ret = dpni_load_sw_sequence(dpni, CMD_PRI_LOW, priv->token, &cfg);
177 DPAA2_PMD_ERR("dpni_load_sw_sequence failed\n");
182 priv->ss_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(addr));
183 priv->ss_offset += sp_param.size;
184 RTE_LOG(INFO, PMD, "Soft parser loaded for dpni@%d\n", priv->hw_id);
190 int dpaa2_eth_enable_wriop_soft_parser(struct dpaa2_dev_priv *priv,
191 enum dpni_soft_sequence_dest dest)
193 struct fsl_mc_io *dpni = priv->hw;
194 struct dpni_enable_ss_cfg cfg;
196 struct dpni_drv_sparser_param sp_param;
197 uint8_t *param_addr = NULL;
200 memset(&sp_param, 0, sizeof(sp_param));
201 pa[0] = 32; /* Custom Header Length in bytes */
202 sp_param.custom_header_first = 1;
203 sp_param.param_offset = 32;
204 sp_param.param_size = 1;
205 sp_param.start_pc = priv->ss_offset;
206 sp_param.param_array = (uint8_t *)&pa[0];
209 cfg.ss_offset = sp_param.start_pc;
210 cfg.set_start = sp_param.custom_header_first;
211 cfg.hxs = (uint16_t)sp_param.link_to_hard_hxs;
212 cfg.param_offset = sp_param.param_offset;
213 cfg.param_size = sp_param.param_size;
214 if (cfg.param_size) {
215 param_addr = rte_malloc(NULL, cfg.param_size, 64);
217 DPAA2_PMD_ERR("Memory unavailable for soft parser param\n");
221 memcpy(param_addr, sp_param.param_array, cfg.param_size);
222 cfg.param_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(param_addr));
223 priv->ss_param_iova = cfg.param_iova;
228 ret = dpni_enable_sw_sequence(dpni, CMD_PRI_LOW, priv->token, &cfg);
230 DPAA2_PMD_ERR("dpni_enable_sw_sequence failed for dpni%d\n",
232 rte_free(param_addr);
236 rte_free(param_addr);
237 RTE_LOG(INFO, PMD, "Soft parser enabled for dpni@%d\n", priv->hw_id);