1 /* SPDX-License-Identifier: BSD-3-Clause
11 /* This header declares things about Fman hardware itself (the format of status
12 * words and an inline implementation of CRC64). We include it only in order to
13 * instantiate the one global variable it depends on.
16 #include <fsl_fman_crc64.h>
19 /* Instantiate the global variable that the inline CRC64 implementation (in
20 * <fsl_fman.h>) depends on.
22 DECLARE_FMAN_CRC64_TABLE();
24 #define ETH_ADDR_TO_UINT64(eth_addr) \
25 (uint64_t)(((uint64_t)(eth_addr)[0] << 40) | \
26 ((uint64_t)(eth_addr)[1] << 32) | \
27 ((uint64_t)(eth_addr)[2] << 24) | \
28 ((uint64_t)(eth_addr)[3] << 16) | \
29 ((uint64_t)(eth_addr)[4] << 8) | \
30 ((uint64_t)(eth_addr)[5]))
33 fman_if_set_mcast_filter_table(struct fman_if *p)
35 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
39 hashtable_ctrl = &((struct memac_regs *)__if->ccsr_map)->hashtable_ctrl;
40 for (i = 0; i < 64; i++)
41 out_be32(hashtable_ctrl, i|HASH_CTRL_MCAST_EN);
45 fman_if_reset_mcast_filter_table(struct fman_if *p)
47 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
51 hashtable_ctrl = &((struct memac_regs *)__if->ccsr_map)->hashtable_ctrl;
52 for (i = 0; i < 64; i++)
53 out_be32(hashtable_ctrl, i & ~HASH_CTRL_MCAST_EN);
57 uint32_t get_mac_hash_code(uint64_t eth_addr)
59 uint64_t mask1, mask2;
63 for (i = 0; i < 6; i++) {
64 mask1 = eth_addr & (uint64_t)0x01;
67 for (j = 0; j < 7; j++) {
68 mask2 = eth_addr & (uint64_t)0x01;
73 xorVal |= (mask1 << (5 - i));
80 fman_if_add_hash_mac_addr(struct fman_if *p, uint8_t *eth)
86 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
88 eth_addr = ETH_ADDR_TO_UINT64(eth);
90 if (!(eth_addr & GROUP_ADDRESS))
93 hash = get_mac_hash_code(eth_addr) & HASH_CTRL_ADDR_MASK;
94 hash = hash | HASH_CTRL_MCAST_EN;
96 hashtable_ctrl = &((struct memac_regs *)__if->ccsr_map)->hashtable_ctrl;
97 out_be32(hashtable_ctrl, hash);
103 fman_if_get_primary_mac_addr(struct fman_if *p, uint8_t *eth)
105 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
107 &((struct memac_regs *)__if->ccsr_map)->mac_addr0.mac_addr_l;
108 u32 val = in_be32(mac_reg);
110 eth[0] = (val & 0x000000ff) >> 0;
111 eth[1] = (val & 0x0000ff00) >> 8;
112 eth[2] = (val & 0x00ff0000) >> 16;
113 eth[3] = (val & 0xff000000) >> 24;
115 mac_reg = &((struct memac_regs *)__if->ccsr_map)->mac_addr0.mac_addr_u;
116 val = in_be32(mac_reg);
118 eth[4] = (val & 0x000000ff) >> 0;
119 eth[5] = (val & 0x0000ff00) >> 8;
125 fman_if_clear_mac_addr(struct fman_if *p, uint8_t addr_num)
127 struct __fman_if *m = container_of(p, struct __fman_if, __if);
131 reg = &((struct memac_regs *)m->ccsr_map)->
132 mac_addr[addr_num-1].mac_addr_l;
134 reg = &((struct memac_regs *)m->ccsr_map)->
135 mac_addr[addr_num-1].mac_addr_u;
138 reg = &((struct memac_regs *)m->ccsr_map)->mac_addr0.mac_addr_l;
140 reg = &((struct memac_regs *)m->ccsr_map)->mac_addr0.mac_addr_u;
146 fman_if_add_mac_addr(struct fman_if *p, uint8_t *eth, uint8_t addr_num)
148 struct __fman_if *m = container_of(p, struct __fman_if, __if);
153 memcpy(&m->__if.mac_addr, eth, ETHER_ADDR_LEN);
156 reg = &((struct memac_regs *)m->ccsr_map)->
157 mac_addr[addr_num-1].mac_addr_l;
159 reg = &((struct memac_regs *)m->ccsr_map)->mac_addr0.mac_addr_l;
161 val = (m->__if.mac_addr.addr_bytes[0] |
162 (m->__if.mac_addr.addr_bytes[1] << 8) |
163 (m->__if.mac_addr.addr_bytes[2] << 16) |
164 (m->__if.mac_addr.addr_bytes[3] << 24));
168 reg = &((struct memac_regs *)m->ccsr_map)->
169 mac_addr[addr_num-1].mac_addr_u;
171 reg = &((struct memac_regs *)m->ccsr_map)->mac_addr0.mac_addr_u;
173 val = ((m->__if.mac_addr.addr_bytes[4] << 0) |
174 (m->__if.mac_addr.addr_bytes[5] << 8));
181 fman_if_set_rx_ignore_pause_frames(struct fman_if *p, bool enable)
183 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
187 assert(fman_ccsr_map_fd != -1);
189 /* Set Rx Ignore Pause Frames */
190 cmdcfg = &((struct memac_regs *)__if->ccsr_map)->command_config;
192 value = in_be32(cmdcfg) | CMD_CFG_PAUSE_IGNORE;
194 value = in_be32(cmdcfg) & ~CMD_CFG_PAUSE_IGNORE;
196 out_be32(cmdcfg, value);
200 fman_if_conf_max_frame_len(struct fman_if *p, unsigned int max_frame_len)
202 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
203 unsigned int *maxfrm;
205 assert(fman_ccsr_map_fd != -1);
207 /* Set Max frame length */
208 maxfrm = &((struct memac_regs *)__if->ccsr_map)->maxfrm;
209 out_be32(maxfrm, (MAXFRM_RX_MASK & max_frame_len));
213 fman_if_stats_get(struct fman_if *p, struct rte_eth_stats *stats)
215 struct __fman_if *m = container_of(p, struct __fman_if, __if);
216 struct memac_regs *regs = m->ccsr_map;
218 /* read recved packet count */
219 stats->ipackets = ((u64)in_be32(®s->rfrm_u)) << 32 |
220 in_be32(®s->rfrm_l);
221 stats->ibytes = ((u64)in_be32(®s->roct_u)) << 32 |
222 in_be32(®s->roct_l);
223 stats->ierrors = ((u64)in_be32(®s->rerr_u)) << 32 |
224 in_be32(®s->rerr_l);
226 /* read xmited packet count */
227 stats->opackets = ((u64)in_be32(®s->tfrm_u)) << 32 |
228 in_be32(®s->tfrm_l);
229 stats->obytes = ((u64)in_be32(®s->toct_u)) << 32 |
230 in_be32(®s->toct_l);
231 stats->oerrors = ((u64)in_be32(®s->terr_u)) << 32 |
232 in_be32(®s->terr_l);
236 fman_if_stats_get_all(struct fman_if *p, uint64_t *value, int n)
238 struct __fman_if *m = container_of(p, struct __fman_if, __if);
239 struct memac_regs *regs = m->ccsr_map;
241 uint64_t base_offset = offsetof(struct memac_regs, reoct_l);
243 for (i = 0; i < n; i++)
244 value[i] = ((u64)in_be32((char *)regs
245 + base_offset + 8 * i + 4)) << 32 |
246 ((u64)in_be32((char *)regs
247 + base_offset + 8 * i));
251 fman_if_stats_reset(struct fman_if *p)
253 struct __fman_if *m = container_of(p, struct __fman_if, __if);
254 struct memac_regs *regs = m->ccsr_map;
257 tmp = in_be32(®s->statn_config);
259 tmp |= STATS_CFG_CLR;
261 out_be32(®s->statn_config, tmp);
263 while (in_be32(®s->statn_config) & STATS_CFG_CLR)
268 fman_if_promiscuous_enable(struct fman_if *p)
270 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
273 assert(fman_ccsr_map_fd != -1);
275 /* Enable Rx promiscuous mode */
276 cmdcfg = &((struct memac_regs *)__if->ccsr_map)->command_config;
277 out_be32(cmdcfg, in_be32(cmdcfg) | CMD_CFG_PROMIS_EN);
281 fman_if_promiscuous_disable(struct fman_if *p)
283 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
286 assert(fman_ccsr_map_fd != -1);
288 /* Disable Rx promiscuous mode */
289 cmdcfg = &((struct memac_regs *)__if->ccsr_map)->command_config;
290 out_be32(cmdcfg, in_be32(cmdcfg) & (~CMD_CFG_PROMIS_EN));
294 fman_if_enable_rx(struct fman_if *p)
296 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
298 assert(fman_ccsr_map_fd != -1);
300 /* enable Rx and Tx */
301 out_be32(__if->ccsr_map + 8, in_be32(__if->ccsr_map + 8) | 3);
305 fman_if_disable_rx(struct fman_if *p)
307 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
309 assert(fman_ccsr_map_fd != -1);
311 /* only disable Rx, not Tx */
312 out_be32(__if->ccsr_map + 8, in_be32(__if->ccsr_map + 8) & ~(u32)2);
316 fman_if_loopback_enable(struct fman_if *p)
318 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
320 assert(fman_ccsr_map_fd != -1);
322 /* Enable loopback mode */
323 if ((__if->__if.is_memac) && (__if->__if.is_rgmii)) {
324 unsigned int *ifmode =
325 &((struct memac_regs *)__if->ccsr_map)->if_mode;
326 out_be32(ifmode, in_be32(ifmode) | IF_MODE_RLP);
328 unsigned int *cmdcfg =
329 &((struct memac_regs *)__if->ccsr_map)->command_config;
330 out_be32(cmdcfg, in_be32(cmdcfg) | CMD_CFG_LOOPBACK_EN);
335 fman_if_loopback_disable(struct fman_if *p)
337 struct __fman_if *__if = container_of(p, struct __fman_if, __if);
339 assert(fman_ccsr_map_fd != -1);
340 /* Disable loopback mode */
341 if ((__if->__if.is_memac) && (__if->__if.is_rgmii)) {
342 unsigned int *ifmode =
343 &((struct memac_regs *)__if->ccsr_map)->if_mode;
344 out_be32(ifmode, in_be32(ifmode) & ~IF_MODE_RLP);
346 unsigned int *cmdcfg =
347 &((struct memac_regs *)__if->ccsr_map)->command_config;
348 out_be32(cmdcfg, in_be32(cmdcfg) & ~CMD_CFG_LOOPBACK_EN);
353 fman_if_set_bp(struct fman_if *fm_if, unsigned num __always_unused,
354 int bpid, size_t bufsize)
357 u32 ebmpi_val_ace = 0xc0000000;
358 u32 ebmpi_mask = 0xffc00000;
360 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
362 assert(fman_ccsr_map_fd != -1);
365 in_be32(&((struct rx_bmi_regs *)__if->bmi_map)->fmbm_ebmpi[0]);
366 fmbm_ebmpi = ebmpi_val_ace | (fmbm_ebmpi & ebmpi_mask) | (bpid << 16) |
369 out_be32(&((struct rx_bmi_regs *)__if->bmi_map)->fmbm_ebmpi[0],
374 fman_if_get_fc_threshold(struct fman_if *fm_if)
376 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
377 unsigned int *fmbm_mpd;
379 assert(fman_ccsr_map_fd != -1);
381 fmbm_mpd = &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_mpd;
382 return in_be32(fmbm_mpd);
386 fman_if_set_fc_threshold(struct fman_if *fm_if, u32 high_water,
387 u32 low_water, u32 bpid)
389 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
390 unsigned int *fmbm_mpd;
392 assert(fman_ccsr_map_fd != -1);
394 fmbm_mpd = &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_mpd;
395 out_be32(fmbm_mpd, FMAN_ENABLE_BPOOL_DEPLETION);
396 return bm_pool_set_hw_threshold(bpid, low_water, high_water);
401 fman_if_get_fc_quanta(struct fman_if *fm_if)
403 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
405 assert(fman_ccsr_map_fd != -1);
407 return in_be32(&((struct memac_regs *)__if->ccsr_map)->pause_quanta[0]);
411 fman_if_set_fc_quanta(struct fman_if *fm_if, u16 pause_quanta)
413 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
415 assert(fman_ccsr_map_fd != -1);
417 out_be32(&((struct memac_regs *)__if->ccsr_map)->pause_quanta[0],
423 fman_if_get_fdoff(struct fman_if *fm_if)
427 int iceof_mask = 0x001f0000;
428 int icsz_mask = 0x0000001f;
430 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
432 assert(fman_ccsr_map_fd != -1);
435 in_be32(&((struct rx_bmi_regs *)__if->bmi_map)->fmbm_ricp);
437 fdoff = ((fmbm_ricp & iceof_mask) >> 16) * 16 +
438 (fmbm_ricp & icsz_mask) * 16;
444 fman_if_set_err_fqid(struct fman_if *fm_if, uint32_t err_fqid)
446 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
448 assert(fman_ccsr_map_fd != -1);
450 unsigned int *fmbm_refqid =
451 &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_refqid;
452 out_be32(fmbm_refqid, err_fqid);
456 fman_if_get_ic_params(struct fman_if *fm_if, struct fman_if_ic_params *icp)
458 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
460 int iceof_mask = 0x001f0000;
461 int icsz_mask = 0x0000001f;
462 int iciof_mask = 0x00000f00;
464 assert(fman_ccsr_map_fd != -1);
466 unsigned int *fmbm_ricp =
467 &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_ricp;
468 val = in_be32(fmbm_ricp);
470 icp->iceof = (val & iceof_mask) >> 12;
471 icp->iciof = (val & iciof_mask) >> 4;
472 icp->icsz = (val & icsz_mask) << 4;
478 fman_if_set_ic_params(struct fman_if *fm_if,
479 const struct fman_if_ic_params *icp)
481 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
483 int iceof_mask = 0x001f0000;
484 int icsz_mask = 0x0000001f;
485 int iciof_mask = 0x00000f00;
487 assert(fman_ccsr_map_fd != -1);
489 val |= (icp->iceof << 12) & iceof_mask;
490 val |= (icp->iciof << 4) & iciof_mask;
491 val |= (icp->icsz >> 4) & icsz_mask;
493 unsigned int *fmbm_ricp =
494 &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_ricp;
495 out_be32(fmbm_ricp, val);
501 fman_if_set_fdoff(struct fman_if *fm_if, uint32_t fd_offset)
503 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
504 unsigned int *fmbm_rebm;
506 assert(fman_ccsr_map_fd != -1);
508 fmbm_rebm = &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_rebm;
510 out_be32(fmbm_rebm, in_be32(fmbm_rebm) | (fd_offset << 16));
514 fman_if_set_maxfrm(struct fman_if *fm_if, uint16_t max_frm)
516 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
517 unsigned int *reg_maxfrm;
519 assert(fman_ccsr_map_fd != -1);
521 reg_maxfrm = &((struct memac_regs *)__if->ccsr_map)->maxfrm;
523 out_be32(reg_maxfrm, (in_be32(reg_maxfrm) & 0xFFFF0000) | max_frm);
527 fman_if_get_maxfrm(struct fman_if *fm_if)
529 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
530 unsigned int *reg_maxfrm;
532 assert(fman_ccsr_map_fd != -1);
534 reg_maxfrm = &((struct memac_regs *)__if->ccsr_map)->maxfrm;
536 return (in_be32(reg_maxfrm) | 0x0000FFFF);
540 fman_if_set_dnia(struct fman_if *fm_if, uint32_t nia)
542 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
543 unsigned int *fmqm_pndn;
545 assert(fman_ccsr_map_fd != -1);
547 fmqm_pndn = &((struct fman_port_qmi_regs *)__if->qmi_map)->fmqm_pndn;
549 out_be32(fmqm_pndn, nia);
553 fman_if_discard_rx_errors(struct fman_if *fm_if)
555 struct __fman_if *__if = container_of(fm_if, struct __fman_if, __if);
556 unsigned int *fmbm_rfsdm, *fmbm_rfsem;
558 fmbm_rfsem = &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_rfsem;
559 out_be32(fmbm_rfsem, 0);
561 /* Configure the discard mask to discard the error packets which have
562 * DMA errors, Frame size error, Header error etc. The mask 0x010CE3F0
563 * is to configured discard all the errors which come in the FD[STATUS]
565 fmbm_rfsdm = &((struct rx_bmi_regs *)__if->bmi_map)->fmbm_rfsdm;
566 out_be32(fmbm_rfsdm, 0x010CE3F0);