Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2019-2021 NXP
3 : : */
4 : :
5 : : #include <time.h>
6 : : #include <net/if.h>
7 : :
8 : : #include <rte_mbuf.h>
9 : : #include <ethdev_driver.h>
10 : : #include <rte_malloc.h>
11 : : #include <rte_memcpy.h>
12 : : #include <rte_string_fns.h>
13 : : #include <rte_cycles.h>
14 : : #include <rte_kvargs.h>
15 : : #include <dev_driver.h>
16 : : #include <bus_fslmc_driver.h>
17 : : #include <rte_flow_driver.h>
18 : :
19 : : #include "dpaa2_pmd_logs.h"
20 : : #include <fslmc_vfio.h>
21 : : #include <dpaa2_hw_pvt.h>
22 : : #include <dpaa2_hw_mempool.h>
23 : : #include <dpaa2_hw_dpio.h>
24 : : #include <mc/fsl_dpmng.h>
25 : : #include "dpaa2_ethdev.h"
26 : : #include "dpaa2_sparser.h"
27 : : #include <fsl_qbman_debug.h>
28 : :
29 : : #include <rte_io.h>
30 : : #include <unistd.h>
31 : : #include <sys/mman.h>
32 : :
33 : : #ifndef PAGE_SIZE
34 : : #define PAGE_SIZE (sysconf(_SC_PAGESIZE))
35 : : #endif
36 : : #define PAGE_MASK (~(PAGE_SIZE - 1))
37 : :
38 : : #define LSX_SERDES_LAN_NB 8
39 : : #define LSX_SERDES_REG_BASE 0x1ea0000
40 : : #define LSX_LB_EN_BIT 0x10000000
41 : :
42 : : #define CONFIG_SYS_IMMR 0x01000000
43 : :
44 : : #define CONFIG_SYS_FSL_GUTS_ADDR (CONFIG_SYS_IMMR + 0x00E00000)
45 : : #define CONFIG_SYS_FSL_SERDES_ADDR (CONFIG_SYS_IMMR + 0xEA0000)
46 : :
47 : : #define FSL_LX_SRDS1_PRTCL_SHIFT 16
48 : : #define FSL_LX_SRDS2_PRTCL_SHIFT 21
49 : : #define FSL_LX_SRDS3_PRTCL_SHIFT 26
50 : :
51 : : #define FSL_LS_SRDS1_PRTCL_SHIFT 16
52 : : #define FSL_LS_SRDS2_PRTCL_SHIFT 0
53 : :
54 : : #define FSL_LX_SRDS1_REGSR 29
55 : : #define FSL_LX_SRDS2_REGSR 29
56 : : #define FSL_LX_SRDS3_REGSR 29
57 : :
58 : : #define FSL_LS_SRDS1_REGSR 29
59 : : #define FSL_LS_SRDS2_REGSR 30
60 : :
61 : : #define FSL_LX_SRDS1_PRTCL_MASK 0x001F0000
62 : : #define FSL_LX_SRDS2_PRTCL_MASK 0x03E00000
63 : : #define FSL_LX_SRDS3_PRTCL_MASK 0x7C000000
64 : :
65 : : #define FSL_LS_SRDS1_PRTCL_MASK 0xFFFF0000
66 : : #define FSL_LS_SRDS2_PRTCL_MASK 0x0000FFFF
67 : :
68 : : struct __rte_packed_begin ccsr_lx_serdes_lan {
69 : : uint8_t unused1[0xa0];
70 : : uint32_t lnatcsr0;
71 : : uint8_t unused2[0x100 - 0xa4];
72 : : } __rte_packed_end;
73 : :
74 : : struct __rte_packed_begin ccsr_lx_serdes {
75 : : uint8_t unused0[0x800];
76 : : struct ccsr_lx_serdes_lan lane[LSX_SERDES_LAN_NB];
77 : : } __rte_packed_end;
78 : :
79 : : struct __rte_packed_begin ccsr_ls_serdes {
80 : : uint8_t unused[0x800];
81 : : struct serdes_lane {
82 : : uint32_t gcr0; /* General Control Register 0 */
83 : : uint32_t gcr1; /* General Control Register 1 */
84 : : uint32_t gcr2; /* General Control Register 2 */
85 : : uint32_t ssc0; /* Speed Switch Control 0 */
86 : : uint32_t rec0; /* Receive Equalization Control 0 */
87 : : uint32_t rec1; /* Receive Equalization Control 1 */
88 : : uint32_t tec0; /* Transmit Equalization Control 0 */
89 : : uint32_t ssc1; /* Speed Switch Control 1 */
90 : : uint32_t ttlc;
91 : : uint32_t rev[6];
92 : : uint32_t tsc3;
93 : : } lane[LSX_SERDES_LAN_NB];
94 : : uint8_t res5[0x19fc - 0xa00];
95 : : } __rte_packed_end;
96 : :
97 : : struct __rte_packed_begin ccsr_gur {
98 : : uint32_t porsr1; /* POR status 1 */
99 : : uint32_t porsr2; /* POR status 2 */
100 : : uint8_t res_008[0x20 - 0x8];
101 : : uint32_t gpporcr1; /* General-purpose POR configuration */
102 : : uint32_t gpporcr2; /* General-purpose POR configuration 2 */
103 : : uint32_t gpporcr3;
104 : : uint32_t gpporcr4;
105 : : uint8_t res_030[0x60 - 0x30];
106 : : uint32_t dcfg_fusesr; /* Fuse status register */
107 : : uint8_t res_064[0x70 - 0x64];
108 : : uint32_t devdisr; /* Device disable control 1 */
109 : : uint32_t devdisr2; /* Device disable control 2 */
110 : : uint32_t devdisr3; /* Device disable control 3 */
111 : : uint32_t devdisr4; /* Device disable control 4 */
112 : : uint32_t devdisr5; /* Device disable control 5 */
113 : : uint32_t devdisr6; /* Device disable control 6 */
114 : : uint8_t res_088[0x94 - 0x88];
115 : : uint32_t coredisr; /* Device disable control 7 */
116 : : uint8_t res_098[0xa0 - 0x98];
117 : : uint32_t pvr; /* Processor version */
118 : : uint32_t svr; /* System version */
119 : : uint8_t res_0a8[0x100 - 0xa8];
120 : : uint32_t rcwsr[30]; /* Reset control word status */
121 : :
122 : : uint8_t res_178[0x200 - 0x178];
123 : : uint32_t scratchrw[16]; /* Scratch Read/Write */
124 : : uint8_t res_240[0x300 - 0x240];
125 : : uint32_t scratchw1r[4]; /* Scratch Read (Write once) */
126 : : uint8_t res_310[0x400 - 0x310];
127 : : uint32_t bootlocptrl; /* Boot location pointer low-order addr */
128 : : uint32_t bootlocptrh; /* Boot location pointer high-order addr */
129 : : uint8_t res_408[0x520 - 0x408];
130 : : uint32_t usb1_amqr;
131 : : uint32_t usb2_amqr;
132 : : uint8_t res_528[0x530 - 0x528]; /* add more registers when needed */
133 : : uint32_t sdmm1_amqr;
134 : : uint32_t sdmm2_amqr;
135 : : uint8_t res_538[0x550 - 0x538]; /* add more registers when needed */
136 : : uint32_t sata1_amqr;
137 : : uint32_t sata2_amqr;
138 : : uint32_t sata3_amqr;
139 : : uint32_t sata4_amqr;
140 : : uint8_t res_560[0x570 - 0x560]; /* add more registers when needed */
141 : : uint32_t misc1_amqr;
142 : : uint8_t res_574[0x590 - 0x574]; /* add more registers when needed */
143 : : uint32_t spare1_amqr;
144 : : uint32_t spare2_amqr;
145 : : uint32_t spare3_amqr;
146 : : uint8_t res_59c[0x620 - 0x59c]; /* add more registers when needed */
147 : : uint32_t gencr[7]; /* General Control Registers */
148 : : uint8_t res_63c[0x640 - 0x63c]; /* add more registers when needed */
149 : : uint32_t cgensr1; /* Core General Status Register */
150 : : uint8_t res_644[0x660 - 0x644]; /* add more registers when needed */
151 : : uint32_t cgencr1; /* Core General Control Register */
152 : : uint8_t res_664[0x740 - 0x664]; /* add more registers when needed */
153 : : uint32_t tp_ityp[64]; /* Topology Initiator Type Register */
154 : : struct {
155 : : uint32_t upper;
156 : : uint32_t lower;
157 : : } tp_cluster[4]; /* Core cluster n Topology Register */
158 : : uint8_t res_864[0x920 - 0x864]; /* add more registers when needed */
159 : : uint32_t ioqoscr[8]; /*I/O Quality of Services Register */
160 : : uint32_t uccr;
161 : : uint8_t res_944[0x960 - 0x944]; /* add more registers when needed */
162 : : uint32_t ftmcr;
163 : : uint8_t res_964[0x990 - 0x964]; /* add more registers when needed */
164 : : uint32_t coredisablesr;
165 : : uint8_t res_994[0xa00 - 0x994]; /* add more registers when needed */
166 : : uint32_t sdbgcr; /*Secure Debug Configuration Register */
167 : : uint8_t res_a04[0xbf8 - 0xa04]; /* add more registers when needed */
168 : : uint32_t ipbrr1;
169 : : uint32_t ipbrr2;
170 : : uint8_t res_858[0x1000 - 0xc00];
171 : : } __rte_packed_end;
172 : :
173 : 0 : static void *lsx_ccsr_map_region(uint64_t addr, size_t len)
174 : : {
175 : : int fd;
176 : : void *tmp;
177 : : uint64_t start;
178 : : uint64_t offset;
179 : : uint64_t page_mask;
180 : : long page_size;
181 : : size_t map_len;
182 : :
183 : : fd = open("/dev/mem", O_RDWR);
184 [ # # ]: 0 : if (fd < 0) {
185 : 0 : DPAA2_PMD_ERR("Fail to open /dev/mem");
186 : 0 : return NULL;
187 : : }
188 : :
189 : 0 : page_size = sysconf(_SC_PAGESIZE);
190 [ # # ]: 0 : if (page_size <= 0) {
191 : 0 : close(fd);
192 : 0 : return NULL;
193 : : }
194 : 0 : page_mask = ~((uint64_t)page_size - 1);
195 : 0 : start = addr & page_mask;
196 : 0 : offset = addr - start;
197 : 0 : map_len = RTE_ALIGN_CEIL(offset + len, (size_t)page_size);
198 : :
199 : 0 : tmp = mmap(NULL, map_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, start);
200 : :
201 : 0 : close(fd);
202 : :
203 [ # # ]: 0 : if (tmp == MAP_FAILED)
204 : : return NULL;
205 : :
206 : 0 : return (uint8_t *)tmp + offset;
207 : : }
208 : :
209 : : static const uint8_t ls_sd1_prot_idx_map[] = {
210 : : 0x03, 0x05, 0x07, 0x09, 0x0a, 0x0c, 0x0e,
211 : : 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c,
212 : : 0x1e, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2a,
213 : : 0x2b, 0x2d, 0x2e, 0x30, 0x32, 0x33, 0x35,
214 : : 0x37, 0x39, 0x3b, 0x4b, 0x4c, 0x4d, 0x58
215 : : };
216 : :
217 : : static const uint8_t ls_sd2_prot_idx_map[] = {
218 : : 0x07, 0x09, 0x0a, 0x0c, 0x0e, 0x10, 0x12,
219 : : 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20,
220 : : 0x22, 0x24, 0x3d, 0x3f, 0x41, 0x43, 0x45,
221 : : 0x47, 0x49, 0x4f, 0x50, 0x51, 0x52, 0x53,
222 : : 0x54, 0x55, 0x56, 0x57
223 : : };
224 : :
225 : : static const uint8_t ls_sd1_eth_loopback_support[][LSX_SERDES_LAN_NB] = {
226 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x03*/
227 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 0x05*/
228 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x07*/
229 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x09*/
230 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x0a*/
231 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x0c*/
232 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x0e*/
233 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x10*/
234 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x12*/
235 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x14*/
236 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x16*/
237 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x18*/
238 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x1a*/
239 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x1c*/
240 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x1e*/
241 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x20*/
242 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x22*/
243 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x24*/
244 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x26*/
245 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x28*/
246 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x2a*/
247 : :
248 : : {0, 0, 0, 0, 1, 1, 1, 1}, /* 0x2b*/
249 : : {0, 0, 0, 0, 1, 1, 1, 1}, /* 0x2d*/
250 : : {0, 0, 0, 0, 1, 1, 1, 1}, /* 0x2e*/
251 : : {0, 0, 0, 0, 1, 1, 1, 1}, /* 0x30*/
252 : :
253 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x32*/
254 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x33*/
255 : :
256 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 0x35*/
257 : : {1, 1, 0, 0, 0, 0, 0, 0}, /* 0x37*/
258 : :
259 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 0x39*/
260 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 0x3b*/
261 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 0x4b*/
262 : : {0, 0, 0, 0, 1, 1, 1, 1}, /* 0x4c*/
263 : : {0, 0, 1, 1, 0, 0, 1, 1}, /* 0x4d*/
264 : : {0, 0, 0, 0, 0, 0, 1, 1} /* 0x58*/
265 : : };
266 : :
267 : : static const uint8_t ls_sd2_eth_loopback_support[][LSX_SERDES_LAN_NB] = {
268 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x07*/
269 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x09*/
270 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x0a*/
271 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x0c*/
272 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x0e*/
273 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x10*/
274 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x12*/
275 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x14*/
276 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x16*/
277 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x18*/
278 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x1a*/
279 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x1c*/
280 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x1e*/
281 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x20*/
282 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x22*/
283 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 0x24*/
284 : :
285 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x3d*/
286 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x3f*/
287 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x41*/
288 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x43*/
289 : :
290 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 0x45*/
291 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 0x47*/
292 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 0x49*/
293 : :
294 : : {0, 0, 1, 1, 0, 0, 1, 1}, /* 0x4f*/
295 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x50*/
296 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0x51*/
297 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 0x52*/
298 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 0x53*/
299 : : {0, 0, 1, 1, 0, 0, 1, 1}, /* 0x54*/
300 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 0x55*/
301 : : {0, 0, 1, 1, 0, 0, 1, 1}, /* 0x56*/
302 : : {0, 0, 0, 0, 0, 0, 1, 1} /* 0x57*/
303 : : };
304 : :
305 : : enum lsx_serdes_id {
306 : : LSX_SERDES_1 = 1,
307 : : LSX_SERDES_2 = 2
308 : : };
309 : :
310 : : static const uint8_t lx_sd1_loopback_support[][LSX_SERDES_LAN_NB] = {
311 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0 prot*/
312 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 1 prot*/
313 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 2 prot*/
314 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 3 prot*/
315 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 4 prot*/
316 : : {0, 0, 0, 0, 1, 1, 1, 1}, /* 5 prot*/
317 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 6 prot*/
318 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 7 prot*/
319 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 8 prot*/
320 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 9 prot*/
321 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 10 prot*/
322 : : {0, 0, 1, 1, 0, 0, 1, 1}, /* 11 prot*/
323 : : {0, 0, 0, 0, 0, 0, 1, 1}, /* 12 prot*/
324 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 13 prot*/
325 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 14 prot*/
326 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 15 prot*/
327 : : {0, 0, 1, 1, 0, 0, 0, 0}, /* 16 prot*/
328 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 17 prot*/
329 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 18 prot*/
330 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 19 prot*/
331 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 20 prot*/
332 : : {1, 1, 1, 1, 0, 0, 1, 1}, /* 21 prot*/
333 : : {1, 1, 1, 1, 0, 0, 1, 1} /* 22 prot*/
334 : : };
335 : :
336 : : static const uint8_t lx_sd2_loopback_support[][LSX_SERDES_LAN_NB] = {
337 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 0 prot*/
338 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 1 prot*/
339 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 2 prot*/
340 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 3 prot*/
341 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 4 prot*/
342 : : {0, 0, 0, 0, 0, 0, 0, 0}, /* 5 prot*/
343 : : {0, 0, 0, 0, 1, 1, 1, 1}, /* 6 prot*/
344 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 7 prot*/
345 : : {0, 0, 0, 0, 0, 0, 1, 1}, /* 8 prot*/
346 : : {1, 1, 1, 1, 1, 1, 1, 1}, /* 9 prot*/
347 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 10 prot*/
348 : : {0, 1, 1, 1, 0, 1, 1, 1}, /* 11 prot*/
349 : : {1, 1, 1, 1, 0, 0, 0, 0}, /* 12 prot*/
350 : : {0, 0, 0, 0, 0, 0, 1, 1}, /* 13 prot*/
351 : : {0, 0, 1, 1, 0, 0, 1, 1} /* 14 prot*/
352 : : };
353 : :
354 : : static inline int
355 : : ls_mac_to_serdes_id(uint8_t mac_id)
356 : : {
357 : 0 : if (mac_id >= 1 && mac_id <= 8)
358 : : return LSX_SERDES_1;
359 [ # # ]: 0 : if (mac_id >= 9 && mac_id <= 16)
360 : : return LSX_SERDES_2;
361 : :
362 : : return -1;
363 : : }
364 : :
365 : : static inline int
366 : : lx_mac_to_serdes_id(uint8_t mac_id)
367 : : {
368 : 0 : if (mac_id >= 1 && mac_id <= 10)
369 : : return LSX_SERDES_1;
370 [ # # ]: 0 : if (mac_id >= 11 && mac_id <= 18)
371 : : return LSX_SERDES_2;
372 : :
373 : : return -1;
374 : : }
375 : :
376 : : static inline int
377 : : ls_serdes_cfg_to_idx(uint8_t sd_cfg, int sd_id)
378 : : {
379 : : int i;
380 : :
381 : 0 : if (sd_id == LSX_SERDES_1) {
382 [ # # ]: 0 : for (i = 0; i < (int)sizeof(ls_sd1_prot_idx_map); i++) {
383 [ # # ]: 0 : if (ls_sd1_prot_idx_map[i] == sd_cfg)
384 : : return i;
385 : : }
386 : : } else if (sd_id == LSX_SERDES_2) {
387 [ # # ]: 0 : for (i = 0; i < (int)sizeof(ls_sd2_prot_idx_map); i++) {
388 [ # # ]: 0 : if (ls_sd2_prot_idx_map[i] == sd_cfg)
389 : : return i;
390 : : }
391 : : }
392 : :
393 : : return -1;
394 : : }
395 : :
396 : : static inline int
397 : : lx_serdes_cfg_to_idx(uint8_t sd_cfg, int sd_id __rte_unused)
398 : : {
399 : : return sd_cfg;
400 : : }
401 : :
402 : : static inline int
403 : 0 : ls_mac_serdes_lpbk_support(uint16_t mac_id,
404 : : uint16_t *serdes_id, uint16_t *lan_id)
405 : : {
406 : : struct ccsr_gur *gur_base =
407 : 0 : lsx_ccsr_map_region(CONFIG_SYS_FSL_GUTS_ADDR,
408 : : sizeof(struct ccsr_gur) / 64 * 64 + 64);
409 : : uint32_t sd_cfg;
410 : : int sd_id, sd_idx;
411 : : uint16_t lan_id_tmp = 0;
412 : : const uint8_t *ls_sd_loopback_support;
413 : :
414 [ # # ]: 0 : sd_id = ls_mac_to_serdes_id(mac_id);
415 : :
416 : : if (sd_id == LSX_SERDES_1) {
417 : : sd_cfg = rte_read32(&gur_base->rcwsr[FSL_LS_SRDS1_REGSR - 1]) &
418 : : FSL_LS_SRDS1_PRTCL_MASK;
419 : : sd_cfg >>= FSL_LS_SRDS1_PRTCL_SHIFT;
420 [ # # ]: 0 : } else if (sd_id == LSX_SERDES_2) {
421 : 0 : sd_cfg = rte_read32(&gur_base->rcwsr[FSL_LS_SRDS2_REGSR - 1]) &
422 : : FSL_LS_SRDS2_PRTCL_MASK;
423 : : sd_cfg >>= FSL_LS_SRDS2_PRTCL_SHIFT;
424 : : } else {
425 : : return false;
426 : : }
427 : 0 : sd_cfg = sd_cfg & 0xff;
428 : :
429 [ # # ]: 0 : sd_idx = ls_serdes_cfg_to_idx(sd_cfg, sd_id);
430 [ # # ]: 0 : if (sd_idx < 0) {
431 : 0 : DPAA2_PMD_ERR("Serdes protocol(0x%02x) does not exist",
432 : : sd_cfg);
433 : 0 : return false;
434 : : }
435 : :
436 [ # # ]: 0 : if (sd_id == LSX_SERDES_1) {
437 : 0 : ls_sd_loopback_support =
438 : : &ls_sd1_eth_loopback_support[sd_idx][0];
439 : : } else {
440 : 0 : ls_sd_loopback_support =
441 : : &ls_sd2_eth_loopback_support[sd_idx][0];
442 : : }
443 : :
444 [ # # ]: 0 : if (sd_id == LSX_SERDES_1)
445 : 0 : lan_id_tmp = (mac_id - 1);
446 : : else
447 : 0 : lan_id_tmp = (mac_id - 9);
448 : :
449 [ # # ]: 0 : if (lan_id_tmp >= LSX_SERDES_LAN_NB) {
450 : 0 : DPAA2_PMD_ERR("Invalid serdes lan(%d).", lan_id_tmp);
451 : 0 : return false;
452 : : }
453 : :
454 [ # # ]: 0 : if (!ls_sd_loopback_support[lan_id_tmp])
455 : : return false;
456 : :
457 [ # # ]: 0 : if (lan_id)
458 : 0 : *lan_id = lan_id_tmp;
459 [ # # ]: 0 : if (serdes_id)
460 : 0 : *serdes_id = sd_id;
461 : :
462 : : return true;
463 : : }
464 : :
465 : : static inline int
466 : 0 : lx_mac_serdes_lpbk_support(uint16_t mac_id,
467 : : uint16_t *serdes_id, uint16_t *lan_id)
468 : : {
469 : : struct ccsr_gur *gur_base =
470 : 0 : lsx_ccsr_map_region(CONFIG_SYS_FSL_GUTS_ADDR,
471 : : sizeof(struct ccsr_gur) / 64 * 64 + 64);
472 : : uint32_t sd_cfg;
473 : : int sd_id, sd_idx;
474 : : uint16_t lan_id_tmp = 0;
475 : : const uint8_t *lx_sd_loopback_support;
476 : :
477 [ # # ]: 0 : sd_id = lx_mac_to_serdes_id(mac_id);
478 : :
479 : : if (sd_id == LSX_SERDES_1) {
480 : : sd_cfg = rte_read32(&gur_base->rcwsr[FSL_LX_SRDS1_REGSR - 1]) &
481 : : FSL_LX_SRDS1_PRTCL_MASK;
482 : 0 : sd_cfg >>= FSL_LX_SRDS1_PRTCL_SHIFT;
483 [ # # ]: 0 : } else if (sd_id == LSX_SERDES_2) {
484 : : sd_cfg = rte_read32(&gur_base->rcwsr[FSL_LX_SRDS2_REGSR - 1]) &
485 : : FSL_LX_SRDS2_PRTCL_MASK;
486 : 0 : sd_cfg >>= FSL_LX_SRDS2_PRTCL_SHIFT;
487 : : } else {
488 : : return false;
489 : : }
490 : : sd_cfg = sd_cfg & 0xff;
491 : :
492 : 0 : sd_idx = lx_serdes_cfg_to_idx(sd_cfg, sd_id);
493 : : if (sd_idx < 0)
494 : : return false;
495 : :
496 [ # # ]: 0 : if (sd_id == LSX_SERDES_1)
497 : 0 : lx_sd_loopback_support = &lx_sd1_loopback_support[sd_idx][0];
498 : : else
499 : 0 : lx_sd_loopback_support = &lx_sd2_loopback_support[sd_idx][0];
500 : :
501 [ # # ]: 0 : if (sd_id == LSX_SERDES_1) {
502 [ # # ]: 0 : if (mac_id == 1)
503 : : lan_id_tmp = 0;
504 [ # # ]: 0 : else if (mac_id == 2)
505 : : lan_id_tmp = 4;
506 : : else
507 : 0 : lan_id_tmp = (mac_id - 3);
508 : : } else {
509 : : if (mac_id == 11)
510 : : lan_id_tmp = 0;
511 : : else if (mac_id == 12)
512 : : lan_id_tmp = 1;
513 : : else if (mac_id == 13)
514 : : lan_id_tmp = 6;
515 : : else if (mac_id == 14)
516 : : lan_id_tmp = 7;
517 : : else if (mac_id == 15)
518 : : lan_id_tmp = 4;
519 : : else if (mac_id == 16)
520 : : lan_id_tmp = 5;
521 : : else if (mac_id == 17)
522 : : lan_id_tmp = 2;
523 : : else if (mac_id == 18)
524 : : lan_id_tmp = 3;
525 : : else
526 : : return false;
527 : : }
528 : :
529 [ # # ]: 0 : if (lan_id_tmp >= LSX_SERDES_LAN_NB)
530 : : return false;
531 : :
532 [ # # ]: 0 : if (!lx_sd_loopback_support[lan_id_tmp])
533 : : return false;
534 : :
535 [ # # ]: 0 : if (lan_id)
536 : 0 : *lan_id = lan_id_tmp;
537 [ # # ]: 0 : if (serdes_id)
538 : 0 : *serdes_id = sd_id;
539 : :
540 : : return true;
541 : : }
542 : :
543 : : static inline int
544 : 0 : ls_serdes_eth_lpbk(uint16_t mac_id, int en)
545 : : {
546 : : uint16_t serdes_id, lan_id;
547 : : int ret;
548 : : uint32_t data;
549 : : struct ccsr_ls_serdes *serdes_base;
550 : : void *reg = 0;
551 : :
552 : 0 : ret = ls_mac_serdes_lpbk_support(mac_id, &serdes_id, &lan_id);
553 [ # # ]: 0 : if (!ret)
554 : : return -ENOTSUP;
555 : :
556 : 0 : serdes_base = lsx_ccsr_map_region(CONFIG_SYS_FSL_SERDES_ADDR +
557 : : (serdes_id - LSX_SERDES_1) * 0x10000,
558 : : sizeof(struct ccsr_ls_serdes) / 64 * 64 + 64);
559 [ # # ]: 0 : if (!serdes_base) {
560 : 0 : DPAA2_PMD_ERR("Serdes register map failed");
561 : 0 : return -ENOMEM;
562 : : }
563 : :
564 [ # # ]: 0 : if (serdes_id == LSX_SERDES_1)
565 : 0 : lan_id = LSX_SERDES_LAN_NB - lan_id - 1;
566 : :
567 : 0 : reg = &serdes_base->lane[lan_id].tsc3;
568 : :
569 : : data = rte_read32(reg);
570 [ # # ]: 0 : if (en)
571 : 0 : rte_write32(data | LSX_LB_EN_BIT, reg);
572 : : else
573 : 0 : rte_write32(data & (~LSX_LB_EN_BIT), reg);
574 : :
575 : : return 0;
576 : : }
577 : :
578 : : static inline int
579 : 0 : lx_serdes_eth_lpbk(uint16_t mac_id, int en)
580 : : {
581 : 0 : uint16_t serdes_id = 0xffff, lan_id = 0xffff;
582 : : int ret;
583 : : uint32_t data;
584 : : struct ccsr_lx_serdes *serdes_base;
585 : : void *reg = 0;
586 : :
587 : 0 : ret = lx_mac_serdes_lpbk_support(mac_id, &serdes_id, &lan_id);
588 [ # # ]: 0 : if (!ret)
589 : : return -ENOTSUP;
590 : :
591 : 0 : serdes_base = lsx_ccsr_map_region(CONFIG_SYS_FSL_SERDES_ADDR +
592 : : (serdes_id - LSX_SERDES_1) * 0x10000,
593 : : sizeof(struct ccsr_lx_serdes) / 64 * 64 + 64);
594 [ # # ]: 0 : if (!serdes_base) {
595 : 0 : DPAA2_PMD_ERR("Serdes register map failed");
596 : 0 : return -ENOMEM;
597 : : }
598 : :
599 [ # # ]: 0 : if (serdes_id == LSX_SERDES_1)
600 : 0 : lan_id = LSX_SERDES_LAN_NB - lan_id - 1;
601 : :
602 : 0 : reg = &serdes_base->lane[lan_id].lnatcsr0;
603 : :
604 : : data = rte_read32(reg);
605 [ # # ]: 0 : if (en)
606 : 0 : rte_write32(data | LSX_LB_EN_BIT, reg);
607 : : else
608 : 0 : rte_write32(data & (~LSX_LB_EN_BIT), reg);
609 : :
610 : : return 0;
611 : : }
612 : :
613 : : /* Configure dpaa2 port as recycle port */
614 : : int
615 : 0 : dpaa2_dev_recycle_config(struct rte_eth_dev *eth_dev)
616 : : {
617 : 0 : struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
618 : 0 : struct rte_dpaa2_device *dpaa2_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *dpaa2_dev);
619 : 0 : struct fsl_mc_io *dpni_dev = eth_dev->process_private;
620 : : struct dpni_port_cfg port_cfg;
621 : : int ret;
622 : :
623 [ # # ]: 0 : if (priv->flags & DPAA2_TX_LOOPBACK_MODE) {
624 : 0 : DPAA2_PMD_INFO("%s has been configured recycle device.",
625 : : eth_dev->data->name);
626 : :
627 : 0 : return 0;
628 : : }
629 : :
630 [ # # ]: 0 : if (dpaa2_dev->ep_dev_type == DPAA2_MAC) {
631 : : /** For dpmac-dpni connection,
632 : : * try setting serdes loopback as recycle device at first.
633 : : */
634 [ # # ]: 0 : if (dpaa2_svr_family == SVR_LS2088A) {
635 : 0 : ret = ls_serdes_eth_lpbk(dpaa2_dev->ep_object_id, 1);
636 [ # # ]: 0 : if (!ret) {
637 : 0 : priv->flags |= DPAA2_TX_SERDES_LOOPBACK_MODE;
638 : 0 : return 0;
639 : : }
640 [ # # ]: 0 : } else if (dpaa2_svr_family == SVR_LX2160A) {
641 : 0 : ret = lx_serdes_eth_lpbk(dpaa2_dev->ep_object_id, 1);
642 [ # # ]: 0 : if (!ret) {
643 : 0 : priv->flags |= DPAA2_TX_SERDES_LOOPBACK_MODE;
644 : 0 : return 0;
645 : : }
646 : : } else {
647 : 0 : DPAA2_PMD_DEBUG("Serdes loopback not support SoC(0x%08x)",
648 : : dpaa2_svr_family);
649 : : }
650 : :
651 : : /** If serdes loopback is not supported for this mac,
652 : : * trying set mac loopback.
653 : : */
654 : :
655 : 0 : port_cfg.loopback_en = 1;
656 : 0 : ret = dpni_set_port_cfg(dpni_dev, CMD_PRI_LOW,
657 : 0 : priv->token,
658 : : DPNI_PORT_CFG_LOOPBACK,
659 : : &port_cfg);
660 [ # # ]: 0 : if (ret) {
661 : 0 : DPAA2_PMD_ERR("Error(%d) to enable loopback", ret);
662 : 0 : return -ENOTSUP;
663 : : }
664 : :
665 : 0 : priv->flags |= DPAA2_TX_MAC_LOOPBACK_MODE;
666 : :
667 : 0 : return 0;
668 : : }
669 : :
670 [ # # ]: 0 : if (dpaa2_dev->ep_dev_type == DPAA2_ETH &&
671 [ # # ]: 0 : dpaa2_dev->object_id == dpaa2_dev->ep_object_id) {
672 : 0 : priv->flags |= DPAA2_TX_DPNI_LOOPBACK_MODE;
673 : :
674 : 0 : return 0;
675 : : }
676 : :
677 : : return -ENOTSUP;
678 : : }
679 : :
680 : : int
681 : 0 : dpaa2_dev_recycle_deconfig(struct rte_eth_dev *eth_dev)
682 : : {
683 : 0 : struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
684 : 0 : struct rte_dpaa2_device *dpaa2_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *dpaa2_dev);
685 : 0 : struct fsl_mc_io *dpni_dev = eth_dev->process_private;
686 : : struct dpni_port_cfg port_cfg;
687 : : int ret = 0;
688 : :
689 [ # # ]: 0 : if (!(priv->flags & DPAA2_TX_LOOPBACK_MODE))
690 : : return 0;
691 : :
692 [ # # ]: 0 : if (priv->flags & DPAA2_TX_SERDES_LOOPBACK_MODE) {
693 [ # # ]: 0 : if (dpaa2_svr_family == SVR_LS2088A) {
694 : 0 : ret = ls_serdes_eth_lpbk(dpaa2_dev->ep_object_id, 0);
695 [ # # ]: 0 : if (ret) {
696 : 0 : DPAA2_PMD_WARN("Error(%d) to disable Serdes loopback",
697 : : ret);
698 : : } else {
699 : 0 : priv->flags &= ~DPAA2_TX_SERDES_LOOPBACK_MODE;
700 : : }
701 [ # # ]: 0 : } else if (dpaa2_svr_family == SVR_LX2160A) {
702 : 0 : ret = lx_serdes_eth_lpbk(dpaa2_dev->ep_object_id, 0);
703 [ # # ]: 0 : if (ret) {
704 : 0 : DPAA2_PMD_WARN("Error(%d) to disable Serdes loopback",
705 : : ret);
706 : : } else {
707 : 0 : priv->flags &= ~DPAA2_TX_SERDES_LOOPBACK_MODE;
708 : : }
709 : : } else {
710 : 0 : DPAA2_PMD_DEBUG("Serdes loopback not support SoC(0x%08x)",
711 : : dpaa2_svr_family);
712 : : }
713 : : }
714 : :
715 [ # # ]: 0 : if (priv->flags & DPAA2_TX_MAC_LOOPBACK_MODE) {
716 : 0 : port_cfg.loopback_en = 0;
717 : 0 : ret = dpni_set_port_cfg(dpni_dev, CMD_PRI_LOW,
718 : 0 : priv->token,
719 : : DPNI_PORT_CFG_LOOPBACK,
720 : : &port_cfg);
721 [ # # ]: 0 : if (ret) {
722 : 0 : DPAA2_PMD_ERR("Error(%d) to disable TX mac loopback",
723 : : ret);
724 : : } else {
725 : 0 : priv->flags &= ~DPAA2_TX_MAC_LOOPBACK_MODE;
726 : : }
727 : : }
728 : :
729 [ # # ]: 0 : if (priv->flags & DPAA2_TX_DPNI_LOOPBACK_MODE)
730 : 0 : priv->flags &= ~DPAA2_TX_DPNI_LOOPBACK_MODE;
731 : :
732 : : return ret;
733 : : }
|