This source file includes following definitions.
- dwmac5_log_error
- dwmac5_handle_mac_err
- dwmac5_handle_mtl_err
- dwmac5_handle_dma_err
- dwmac5_safety_feat_config
- dwmac5_safety_feat_irq_status
- dwmac5_safety_feat_dump
- dwmac5_rxp_disable
- dwmac5_rxp_enable
- dwmac5_rxp_update_single_entry
- dwmac5_rxp_get_next_entry
- dwmac5_rxp_config
- dwmac5_flex_pps_config
1
2
3
4
5 #include <linux/bitops.h>
6 #include <linux/iopoll.h>
7 #include "common.h"
8 #include "dwmac4.h"
9 #include "dwmac5.h"
10 #include "stmmac.h"
11 #include "stmmac_ptp.h"
12
13 struct dwmac5_error_desc {
14 bool valid;
15 const char *desc;
16 const char *detailed_desc;
17 };
18
19 #define STAT_OFF(field) offsetof(struct stmmac_safety_stats, field)
20
21 static void dwmac5_log_error(struct net_device *ndev, u32 value, bool corr,
22 const char *module_name, const struct dwmac5_error_desc *desc,
23 unsigned long field_offset, struct stmmac_safety_stats *stats)
24 {
25 unsigned long loc, mask;
26 u8 *bptr = (u8 *)stats;
27 unsigned long *ptr;
28
29 ptr = (unsigned long *)(bptr + field_offset);
30
31 mask = value;
32 for_each_set_bit(loc, &mask, 32) {
33 netdev_err(ndev, "Found %s error in %s: '%s: %s'\n", corr ?
34 "correctable" : "uncorrectable", module_name,
35 desc[loc].desc, desc[loc].detailed_desc);
36
37
38 ptr[loc]++;
39 }
40 }
41
42 static const struct dwmac5_error_desc dwmac5_mac_errors[32]= {
43 { true, "ATPES", "Application Transmit Interface Parity Check Error" },
44 { true, "TPES", "TSO Data Path Parity Check Error" },
45 { true, "RDPES", "Read Descriptor Parity Check Error" },
46 { true, "MPES", "MTL Data Path Parity Check Error" },
47 { true, "MTSPES", "MTL TX Status Data Path Parity Check Error" },
48 { true, "ARPES", "Application Receive Interface Data Path Parity Check Error" },
49 { true, "CWPES", "CSR Write Data Path Parity Check Error" },
50 { true, "ASRPES", "AXI Slave Read Data Path Parity Check Error" },
51 { true, "TTES", "TX FSM Timeout Error" },
52 { true, "RTES", "RX FSM Timeout Error" },
53 { true, "CTES", "CSR FSM Timeout Error" },
54 { true, "ATES", "APP FSM Timeout Error" },
55 { true, "PTES", "PTP FSM Timeout Error" },
56 { true, "T125ES", "TX125 FSM Timeout Error" },
57 { true, "R125ES", "RX125 FSM Timeout Error" },
58 { true, "RVCTES", "REV MDC FSM Timeout Error" },
59 { true, "MSTTES", "Master Read/Write Timeout Error" },
60 { true, "SLVTES", "Slave Read/Write Timeout Error" },
61 { true, "ATITES", "Application Timeout on ATI Interface Error" },
62 { true, "ARITES", "Application Timeout on ARI Interface Error" },
63 { false, "UNKNOWN", "Unknown Error" },
64 { false, "UNKNOWN", "Unknown Error" },
65 { false, "UNKNOWN", "Unknown Error" },
66 { false, "UNKNOWN", "Unknown Error" },
67 { true, "FSMPES", "FSM State Parity Error" },
68 { false, "UNKNOWN", "Unknown Error" },
69 { false, "UNKNOWN", "Unknown Error" },
70 { false, "UNKNOWN", "Unknown Error" },
71 { false, "UNKNOWN", "Unknown Error" },
72 { false, "UNKNOWN", "Unknown Error" },
73 { false, "UNKNOWN", "Unknown Error" },
74 { false, "UNKNOWN", "Unknown Error" },
75 };
76
77 static void dwmac5_handle_mac_err(struct net_device *ndev,
78 void __iomem *ioaddr, bool correctable,
79 struct stmmac_safety_stats *stats)
80 {
81 u32 value;
82
83 value = readl(ioaddr + MAC_DPP_FSM_INT_STATUS);
84 writel(value, ioaddr + MAC_DPP_FSM_INT_STATUS);
85
86 dwmac5_log_error(ndev, value, correctable, "MAC", dwmac5_mac_errors,
87 STAT_OFF(mac_errors), stats);
88 }
89
90 static const struct dwmac5_error_desc dwmac5_mtl_errors[32]= {
91 { true, "TXCES", "MTL TX Memory Error" },
92 { true, "TXAMS", "MTL TX Memory Address Mismatch Error" },
93 { true, "TXUES", "MTL TX Memory Error" },
94 { false, "UNKNOWN", "Unknown Error" },
95 { true, "RXCES", "MTL RX Memory Error" },
96 { true, "RXAMS", "MTL RX Memory Address Mismatch Error" },
97 { true, "RXUES", "MTL RX Memory Error" },
98 { false, "UNKNOWN", "Unknown Error" },
99 { true, "ECES", "MTL EST Memory Error" },
100 { true, "EAMS", "MTL EST Memory Address Mismatch Error" },
101 { true, "EUES", "MTL EST Memory Error" },
102 { false, "UNKNOWN", "Unknown Error" },
103 { true, "RPCES", "MTL RX Parser Memory Error" },
104 { true, "RPAMS", "MTL RX Parser Memory Address Mismatch Error" },
105 { true, "RPUES", "MTL RX Parser Memory Error" },
106 { false, "UNKNOWN", "Unknown Error" },
107 { false, "UNKNOWN", "Unknown Error" },
108 { false, "UNKNOWN", "Unknown Error" },
109 { false, "UNKNOWN", "Unknown Error" },
110 { false, "UNKNOWN", "Unknown Error" },
111 { false, "UNKNOWN", "Unknown Error" },
112 { false, "UNKNOWN", "Unknown Error" },
113 { false, "UNKNOWN", "Unknown Error" },
114 { false, "UNKNOWN", "Unknown Error" },
115 { false, "UNKNOWN", "Unknown Error" },
116 { false, "UNKNOWN", "Unknown Error" },
117 { false, "UNKNOWN", "Unknown Error" },
118 { false, "UNKNOWN", "Unknown Error" },
119 { false, "UNKNOWN", "Unknown Error" },
120 { false, "UNKNOWN", "Unknown Error" },
121 { false, "UNKNOWN", "Unknown Error" },
122 { false, "UNKNOWN", "Unknown Error" },
123 };
124
125 static void dwmac5_handle_mtl_err(struct net_device *ndev,
126 void __iomem *ioaddr, bool correctable,
127 struct stmmac_safety_stats *stats)
128 {
129 u32 value;
130
131 value = readl(ioaddr + MTL_ECC_INT_STATUS);
132 writel(value, ioaddr + MTL_ECC_INT_STATUS);
133
134 dwmac5_log_error(ndev, value, correctable, "MTL", dwmac5_mtl_errors,
135 STAT_OFF(mtl_errors), stats);
136 }
137
138 static const struct dwmac5_error_desc dwmac5_dma_errors[32]= {
139 { true, "TCES", "DMA TSO Memory Error" },
140 { true, "TAMS", "DMA TSO Memory Address Mismatch Error" },
141 { true, "TUES", "DMA TSO Memory Error" },
142 { false, "UNKNOWN", "Unknown Error" },
143 { false, "UNKNOWN", "Unknown Error" },
144 { false, "UNKNOWN", "Unknown Error" },
145 { false, "UNKNOWN", "Unknown Error" },
146 { false, "UNKNOWN", "Unknown Error" },
147 { false, "UNKNOWN", "Unknown Error" },
148 { false, "UNKNOWN", "Unknown Error" },
149 { false, "UNKNOWN", "Unknown Error" },
150 { false, "UNKNOWN", "Unknown Error" },
151 { false, "UNKNOWN", "Unknown Error" },
152 { false, "UNKNOWN", "Unknown Error" },
153 { false, "UNKNOWN", "Unknown Error" },
154 { false, "UNKNOWN", "Unknown Error" },
155 { false, "UNKNOWN", "Unknown Error" },
156 { false, "UNKNOWN", "Unknown Error" },
157 { false, "UNKNOWN", "Unknown Error" },
158 { false, "UNKNOWN", "Unknown Error" },
159 { false, "UNKNOWN", "Unknown Error" },
160 { false, "UNKNOWN", "Unknown Error" },
161 { false, "UNKNOWN", "Unknown Error" },
162 { false, "UNKNOWN", "Unknown Error" },
163 { false, "UNKNOWN", "Unknown Error" },
164 { false, "UNKNOWN", "Unknown Error" },
165 { false, "UNKNOWN", "Unknown Error" },
166 { false, "UNKNOWN", "Unknown Error" },
167 { false, "UNKNOWN", "Unknown Error" },
168 { false, "UNKNOWN", "Unknown Error" },
169 { false, "UNKNOWN", "Unknown Error" },
170 { false, "UNKNOWN", "Unknown Error" },
171 };
172
173 static void dwmac5_handle_dma_err(struct net_device *ndev,
174 void __iomem *ioaddr, bool correctable,
175 struct stmmac_safety_stats *stats)
176 {
177 u32 value;
178
179 value = readl(ioaddr + DMA_ECC_INT_STATUS);
180 writel(value, ioaddr + DMA_ECC_INT_STATUS);
181
182 dwmac5_log_error(ndev, value, correctable, "DMA", dwmac5_dma_errors,
183 STAT_OFF(dma_errors), stats);
184 }
185
186 int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp)
187 {
188 u32 value;
189
190 if (!asp)
191 return -EINVAL;
192
193
194 value = readl(ioaddr + MTL_ECC_CONTROL);
195 value |= TSOEE;
196 value |= MRXPEE;
197 value |= MESTEE;
198 value |= MRXEE;
199 value |= MTXEE;
200 writel(value, ioaddr + MTL_ECC_CONTROL);
201
202
203 value = readl(ioaddr + MTL_ECC_INT_ENABLE);
204 value |= RPCEIE;
205 value |= ECEIE;
206 value |= RXCEIE;
207 value |= TXCEIE;
208 writel(value, ioaddr + MTL_ECC_INT_ENABLE);
209
210
211 value = readl(ioaddr + DMA_ECC_INT_ENABLE);
212 value |= TCEIE;
213 writel(value, ioaddr + DMA_ECC_INT_ENABLE);
214
215
216 if (asp <= 0x1)
217 return 0;
218
219
220 value = readl(ioaddr + MAC_FSM_CONTROL);
221 value |= PRTYEN;
222 value |= TMOUTEN;
223 writel(value, ioaddr + MAC_FSM_CONTROL);
224
225
226 value = readl(ioaddr + MTL_DPP_CONTROL);
227 value |= EDPP;
228 writel(value, ioaddr + MTL_DPP_CONTROL);
229
230
231
232
233
234 if (asp <= 0x2)
235 return 0;
236
237 value |= EPSI;
238 writel(value, ioaddr + MTL_DPP_CONTROL);
239 return 0;
240 }
241
242 int dwmac5_safety_feat_irq_status(struct net_device *ndev,
243 void __iomem *ioaddr, unsigned int asp,
244 struct stmmac_safety_stats *stats)
245 {
246 bool err, corr;
247 u32 mtl, dma;
248 int ret = 0;
249
250 if (!asp)
251 return -EINVAL;
252
253 mtl = readl(ioaddr + MTL_SAFETY_INT_STATUS);
254 dma = readl(ioaddr + DMA_SAFETY_INT_STATUS);
255
256 err = (mtl & MCSIS) || (dma & MCSIS);
257 corr = false;
258 if (err) {
259 dwmac5_handle_mac_err(ndev, ioaddr, corr, stats);
260 ret |= !corr;
261 }
262
263 err = (mtl & (MEUIS | MECIS)) || (dma & (MSUIS | MSCIS));
264 corr = (mtl & MECIS) || (dma & MSCIS);
265 if (err) {
266 dwmac5_handle_mtl_err(ndev, ioaddr, corr, stats);
267 ret |= !corr;
268 }
269
270 err = dma & (DEUIS | DECIS);
271 corr = dma & DECIS;
272 if (err) {
273 dwmac5_handle_dma_err(ndev, ioaddr, corr, stats);
274 ret |= !corr;
275 }
276
277 return ret;
278 }
279
280 static const struct dwmac5_error {
281 const struct dwmac5_error_desc *desc;
282 } dwmac5_all_errors[] = {
283 { dwmac5_mac_errors },
284 { dwmac5_mtl_errors },
285 { dwmac5_dma_errors },
286 };
287
288 int dwmac5_safety_feat_dump(struct stmmac_safety_stats *stats,
289 int index, unsigned long *count, const char **desc)
290 {
291 int module = index / 32, offset = index % 32;
292 unsigned long *ptr = (unsigned long *)stats;
293
294 if (module >= ARRAY_SIZE(dwmac5_all_errors))
295 return -EINVAL;
296 if (!dwmac5_all_errors[module].desc[offset].valid)
297 return -EINVAL;
298 if (count)
299 *count = *(ptr + index);
300 if (desc)
301 *desc = dwmac5_all_errors[module].desc[offset].desc;
302 return 0;
303 }
304
305 static int dwmac5_rxp_disable(void __iomem *ioaddr)
306 {
307 u32 val;
308 int ret;
309
310 val = readl(ioaddr + MTL_OPERATION_MODE);
311 val &= ~MTL_FRPE;
312 writel(val, ioaddr + MTL_OPERATION_MODE);
313
314 ret = readl_poll_timeout(ioaddr + MTL_RXP_CONTROL_STATUS, val,
315 val & RXPI, 1, 10000);
316 if (ret)
317 return ret;
318 return 0;
319 }
320
321 static void dwmac5_rxp_enable(void __iomem *ioaddr)
322 {
323 u32 val;
324
325 val = readl(ioaddr + MTL_OPERATION_MODE);
326 val |= MTL_FRPE;
327 writel(val, ioaddr + MTL_OPERATION_MODE);
328 }
329
330 static int dwmac5_rxp_update_single_entry(void __iomem *ioaddr,
331 struct stmmac_tc_entry *entry,
332 int pos)
333 {
334 int ret, i;
335
336 for (i = 0; i < (sizeof(entry->val) / sizeof(u32)); i++) {
337 int real_pos = pos * (sizeof(entry->val) / sizeof(u32)) + i;
338 u32 val;
339
340
341 ret = readl_poll_timeout(ioaddr + MTL_RXP_IACC_CTRL_STATUS,
342 val, !(val & STARTBUSY), 1, 10000);
343 if (ret)
344 return ret;
345
346
347 val = *((u32 *)&entry->val + i);
348 writel(val, ioaddr + MTL_RXP_IACC_DATA);
349
350
351 val = real_pos & ADDR;
352 writel(val, ioaddr + MTL_RXP_IACC_CTRL_STATUS);
353
354
355 val |= WRRDN;
356 writel(val, ioaddr + MTL_RXP_IACC_CTRL_STATUS);
357
358
359 val |= STARTBUSY;
360 writel(val, ioaddr + MTL_RXP_IACC_CTRL_STATUS);
361
362
363 ret = readl_poll_timeout(ioaddr + MTL_RXP_IACC_CTRL_STATUS,
364 val, !(val & STARTBUSY), 1, 10000);
365 if (ret)
366 return ret;
367 }
368
369 return 0;
370 }
371
372 static struct stmmac_tc_entry *
373 dwmac5_rxp_get_next_entry(struct stmmac_tc_entry *entries, unsigned int count,
374 u32 curr_prio)
375 {
376 struct stmmac_tc_entry *entry;
377 u32 min_prio = ~0x0;
378 int i, min_prio_idx;
379 bool found = false;
380
381 for (i = count - 1; i >= 0; i--) {
382 entry = &entries[i];
383
384
385 if (!entry->in_use)
386 continue;
387
388 if (entry->in_hw)
389 continue;
390
391 if (entry->is_last)
392 continue;
393
394 if (entry->is_frag)
395 continue;
396
397 if (entry->prio < curr_prio)
398 continue;
399
400 if (entry->prio < min_prio) {
401 min_prio = entry->prio;
402 min_prio_idx = i;
403 found = true;
404 }
405 }
406
407 if (found)
408 return &entries[min_prio_idx];
409 return NULL;
410 }
411
412 int dwmac5_rxp_config(void __iomem *ioaddr, struct stmmac_tc_entry *entries,
413 unsigned int count)
414 {
415 struct stmmac_tc_entry *entry, *frag;
416 int i, ret, nve = 0;
417 u32 curr_prio = 0;
418 u32 old_val, val;
419
420
421 old_val = readl(ioaddr + GMAC_CONFIG);
422 val = old_val & ~GMAC_CONFIG_RE;
423 writel(val, ioaddr + GMAC_CONFIG);
424
425
426 ret = dwmac5_rxp_disable(ioaddr);
427 if (ret)
428 goto re_enable;
429
430
431 for (i = 0; i < count; i++) {
432 entry = &entries[i];
433 entry->in_hw = false;
434 }
435
436
437 while (1) {
438 entry = dwmac5_rxp_get_next_entry(entries, count, curr_prio);
439 if (!entry)
440 break;
441
442 curr_prio = entry->prio;
443 frag = entry->frag_ptr;
444
445
446 if (frag) {
447 entry->val.af = 0;
448 entry->val.rf = 0;
449 entry->val.nc = 1;
450 entry->val.ok_index = nve + 2;
451 }
452
453 ret = dwmac5_rxp_update_single_entry(ioaddr, entry, nve);
454 if (ret)
455 goto re_enable;
456
457 entry->table_pos = nve++;
458 entry->in_hw = true;
459
460 if (frag && !frag->in_hw) {
461 ret = dwmac5_rxp_update_single_entry(ioaddr, frag, nve);
462 if (ret)
463 goto re_enable;
464 frag->table_pos = nve++;
465 frag->in_hw = true;
466 }
467 }
468
469 if (!nve)
470 goto re_enable;
471
472
473 for (i = 0; i < count; i++) {
474 entry = &entries[i];
475 if (!entry->is_last)
476 continue;
477
478 ret = dwmac5_rxp_update_single_entry(ioaddr, entry, nve);
479 if (ret)
480 goto re_enable;
481
482 entry->table_pos = nve++;
483 }
484
485
486 val = (nve << 16) & NPE;
487 val |= nve & NVE;
488 writel(val, ioaddr + MTL_RXP_CONTROL_STATUS);
489
490
491 dwmac5_rxp_enable(ioaddr);
492
493 re_enable:
494
495 writel(old_val, ioaddr + GMAC_CONFIG);
496 return ret;
497 }
498
499 int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
500 struct stmmac_pps_cfg *cfg, bool enable,
501 u32 sub_second_inc, u32 systime_flags)
502 {
503 u32 tnsec = readl(ioaddr + MAC_PPSx_TARGET_TIME_NSEC(index));
504 u32 val = readl(ioaddr + MAC_PPS_CONTROL);
505 u64 period;
506
507 if (!cfg->available)
508 return -EINVAL;
509 if (tnsec & TRGTBUSY0)
510 return -EBUSY;
511 if (!sub_second_inc || !systime_flags)
512 return -EINVAL;
513
514 val &= ~PPSx_MASK(index);
515
516 if (!enable) {
517 val |= PPSCMDx(index, 0x5);
518 val |= PPSEN0;
519 writel(val, ioaddr + MAC_PPS_CONTROL);
520 return 0;
521 }
522
523 val |= PPSCMDx(index, 0x2);
524 val |= TRGTMODSELx(index, 0x2);
525 val |= PPSEN0;
526
527 writel(cfg->start.tv_sec, ioaddr + MAC_PPSx_TARGET_TIME_SEC(index));
528
529 if (!(systime_flags & PTP_TCR_TSCTRLSSR))
530 cfg->start.tv_nsec = (cfg->start.tv_nsec * 1000) / 465;
531 writel(cfg->start.tv_nsec, ioaddr + MAC_PPSx_TARGET_TIME_NSEC(index));
532
533 period = cfg->period.tv_sec * 1000000000;
534 period += cfg->period.tv_nsec;
535
536 do_div(period, sub_second_inc);
537
538 if (period <= 1)
539 return -EINVAL;
540
541 writel(period - 1, ioaddr + MAC_PPSx_INTERVAL(index));
542
543 period >>= 1;
544 if (period <= 1)
545 return -EINVAL;
546
547 writel(period - 1, ioaddr + MAC_PPSx_WIDTH(index));
548
549
550 writel(val, ioaddr + MAC_PPS_CONTROL);
551 return 0;
552 }