1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2019 NXP
8 #define PFE_MTU_RESET_MASK 0xC000FFFF
12 unsigned long ddr_phys_base_addr;
13 unsigned int ddr_size;
14 static struct pe_info pe[MAX_PE];
16 /* Initializes the PFE library.
17 * Must be called before using any of the library functions.
19 * @param[in] cbus_base CBUS virtual base address (as mapped in
20 * the host CPU address space)
21 * @param[in] ddr_base PFE DDR range virtual base address (as
22 * mapped in the host CPU address space)
23 * @param[in] ddr_phys_base PFE DDR range physical base address (as
25 * @param[in] size PFE DDR range size (as defined by the host
29 pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
32 cbus_base_addr = cbus_base;
33 ddr_base_addr = ddr_base;
34 ddr_phys_base_addr = ddr_phys_base;
37 pe[CLASS0_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(0);
38 pe[CLASS0_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(0);
39 pe[CLASS0_ID].pmem_size = CLASS_IMEM_SIZE;
40 pe[CLASS0_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
41 pe[CLASS0_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
42 pe[CLASS0_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
44 pe[CLASS1_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(1);
45 pe[CLASS1_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(1);
46 pe[CLASS1_ID].pmem_size = CLASS_IMEM_SIZE;
47 pe[CLASS1_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
48 pe[CLASS1_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
49 pe[CLASS1_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
51 pe[CLASS2_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(2);
52 pe[CLASS2_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(2);
53 pe[CLASS2_ID].pmem_size = CLASS_IMEM_SIZE;
54 pe[CLASS2_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
55 pe[CLASS2_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
56 pe[CLASS2_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
58 pe[CLASS3_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(3);
59 pe[CLASS3_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(3);
60 pe[CLASS3_ID].pmem_size = CLASS_IMEM_SIZE;
61 pe[CLASS3_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
62 pe[CLASS3_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
63 pe[CLASS3_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
65 pe[CLASS4_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(4);
66 pe[CLASS4_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(4);
67 pe[CLASS4_ID].pmem_size = CLASS_IMEM_SIZE;
68 pe[CLASS4_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
69 pe[CLASS4_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
70 pe[CLASS4_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
72 pe[CLASS5_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(5);
73 pe[CLASS5_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(5);
74 pe[CLASS5_ID].pmem_size = CLASS_IMEM_SIZE;
75 pe[CLASS5_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
76 pe[CLASS5_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
77 pe[CLASS5_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
79 pe[TMU0_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(0);
80 pe[TMU0_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(0);
81 pe[TMU0_ID].pmem_size = TMU_IMEM_SIZE;
82 pe[TMU0_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
83 pe[TMU0_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
84 pe[TMU0_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
86 pe[TMU1_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(1);
87 pe[TMU1_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(1);
88 pe[TMU1_ID].pmem_size = TMU_IMEM_SIZE;
89 pe[TMU1_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
90 pe[TMU1_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
91 pe[TMU1_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
93 pe[TMU3_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(3);
94 pe[TMU3_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(3);
95 pe[TMU3_ID].pmem_size = TMU_IMEM_SIZE;
96 pe[TMU3_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
97 pe[TMU3_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
98 pe[TMU3_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
100 #if !defined(CONFIG_FSL_PFE_UTIL_DISABLED)
101 pe[UTIL_ID].dmem_base_addr = UTIL_DMEM_BASE_ADDR;
102 pe[UTIL_ID].mem_access_wdata = UTIL_MEM_ACCESS_WDATA;
103 pe[UTIL_ID].mem_access_addr = UTIL_MEM_ACCESS_ADDR;
104 pe[UTIL_ID].mem_access_rdata = UTIL_MEM_ACCESS_RDATA;
108 /**************************** MTIP GEMAC ***************************/
110 /* Enable Rx Checksum Engine. With this enabled, Frame with bad IP,
111 * TCP or UDP checksums are discarded
113 * @param[in] base GEMAC base address.
116 gemac_enable_rx_checksum_offload(__rte_unused void *base)
118 /*Do not find configuration to do this */
121 /* Disable Rx Checksum Engine.
123 * @param[in] base GEMAC base address.
126 gemac_disable_rx_checksum_offload(__rte_unused void *base)
128 /*Do not find configuration to do this */
132 * @param[in] base GEMAC base address
133 * @param[in] speed GEMAC speed (10, 100 or 1000 Mbps)
136 gemac_set_speed(void *base, enum mac_speed gem_speed)
138 u32 ecr = readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_SPEED;
139 u32 rcr = readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_RMII_10T;
143 rcr |= EMAC_RCNTRL_RMII_10T;
147 ecr |= EMAC_ECNTRL_SPEED;
152 /*It is in 100M mode */
155 writel(ecr, (base + EMAC_ECNTRL_REG));
156 writel(rcr, (base + EMAC_RCNTRL_REG));
160 * @param[in] base GEMAC base address
161 * @param[in] duplex GEMAC duplex mode (Full, Half)
164 gemac_set_duplex(void *base, int duplex)
166 if (duplex == DUPLEX_HALF) {
167 writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_FDEN, base
169 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_DRT, (base
172 writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_FDEN, base
174 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_DRT, (base
180 * @param[in] base GEMAC base address
181 * @param[in] mode GEMAC operation mode (MII, RMII, RGMII, SGMII)
184 gemac_set_mode(void *base, __rte_unused int mode)
186 u32 val = readl(base + EMAC_RCNTRL_REG);
189 val &= ~EMAC_RCNTRL_LOOP;
191 /*Enable flow control and MII mode*/
192 val |= (EMAC_RCNTRL_FCE | EMAC_RCNTRL_MII_MODE | EMAC_RCNTRL_CRC_FWD);
194 writel(val, base + EMAC_RCNTRL_REG);
197 /* GEMAC enable function.
198 * @param[in] base GEMAC base address
201 gemac_enable(void *base)
203 writel(readl(base + EMAC_ECNTRL_REG) | EMAC_ECNTRL_ETHER_EN, base +
207 /* GEMAC disable function.
208 * @param[in] base GEMAC base address
211 gemac_disable(void *base)
213 writel(readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_ETHER_EN, base +
217 /* GEMAC TX disable function.
218 * @param[in] base GEMAC base address
221 gemac_tx_disable(void *base)
223 writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_GTS, base +
228 gemac_tx_enable(void *base)
230 writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_GTS, base +
234 /* Sets the hash register of the MAC.
235 * This register is used for matching unicast and multicast frames.
237 * @param[in] base GEMAC base address.
238 * @param[in] hash 64-bit hash to be configured.
241 gemac_set_hash(void *base, struct pfe_mac_addr *hash)
243 writel(hash->bottom, base + EMAC_GALR);
244 writel(hash->top, base + EMAC_GAUR);
248 gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
249 unsigned int entry_index)
251 if (entry_index < 1 || entry_index > EMAC_SPEC_ADDR_MAX)
254 entry_index = entry_index - 1;
255 if (entry_index < 1) {
256 writel(htonl(address->bottom), base + EMAC_PHY_ADDR_LOW);
257 writel((htonl(address->top) | 0x8808), base +
260 writel(htonl(address->bottom), base + ((entry_index - 1) * 8)
262 writel((htonl(address->top) | 0x8808), base + ((entry_index -
263 1) * 8) + EMAC_SMAC_0_1);
268 gemac_clear_laddrN(void *base, unsigned int entry_index)
270 if (entry_index < 1 || entry_index > EMAC_SPEC_ADDR_MAX)
273 entry_index = entry_index - 1;
274 if (entry_index < 1) {
275 writel(0, base + EMAC_PHY_ADDR_LOW);
276 writel(0, base + EMAC_PHY_ADDR_HIGH);
278 writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_0);
279 writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_1);
283 /* Set the loopback mode of the MAC. This can be either no loopback for
284 * normal operation, local loopback through MAC internal loopback module or PHY
285 * loopback for external loopback through a PHY. This asserts the external
288 * @param[in] base GEMAC base address.
289 * @param[in] gem_loop Loopback mode to be enabled. LB_LOCAL - MAC
291 * LB_EXT - PHY Loopback.
294 gemac_set_loop(void *base, __rte_unused enum mac_loop gem_loop)
296 pr_info("%s()\n", __func__);
297 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_LOOP, (base +
301 /* GEMAC allow frames
302 * @param[in] base GEMAC base address
305 gemac_enable_copy_all(void *base)
307 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_PROM, (base +
311 /* GEMAC do not allow frames
312 * @param[in] base GEMAC base address
315 gemac_disable_copy_all(void *base)
317 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_PROM, (base +
321 /* GEMAC allow broadcast function.
322 * @param[in] base GEMAC base address
325 gemac_allow_broadcast(void *base)
327 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_BC_REJ, base +
331 /* GEMAC no broadcast function.
332 * @param[in] base GEMAC base address
335 gemac_no_broadcast(void *base)
337 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_BC_REJ, base +
341 /* GEMAC enable 1536 rx function.
342 * @param[in] base GEMAC base address
345 gemac_enable_1536_rx(void *base)
347 /* Set 1536 as Maximum frame length */
348 writel((readl(base + EMAC_RCNTRL_REG) & PFE_MTU_RESET_MASK)
350 base + EMAC_RCNTRL_REG);
353 /* GEMAC set Max rx function.
354 * @param[in] base GEMAC base address
357 gemac_set_rx(void *base, int mtu)
359 if (mtu < HIF_RX_PKT_MIN_SIZE || mtu > JUMBO_FRAME_SIZE) {
360 PFE_PMD_ERR("Invalid or not support MTU size");
364 if (pfe_svr == SVR_LS1012A_REV1 &&
365 mtu > (MAX_MTU_ON_REV1 + PFE_ETH_OVERHEAD)) {
366 PFE_PMD_ERR("Max supported MTU on Rev1 is %d", MAX_MTU_ON_REV1);
370 writel((readl(base + EMAC_RCNTRL_REG) & PFE_MTU_RESET_MASK)
372 base + EMAC_RCNTRL_REG);
376 /* GEMAC enable jumbo function.
377 * @param[in] base GEMAC base address
380 gemac_enable_rx_jmb(void *base)
382 if (pfe_svr == SVR_LS1012A_REV1) {
383 PFE_PMD_ERR("Jumbo not supported on Rev1");
387 writel((readl(base + EMAC_RCNTRL_REG) & PFE_MTU_RESET_MASK) |
388 (JUMBO_FRAME_SIZE << 16), base + EMAC_RCNTRL_REG);
391 /* GEMAC enable stacked vlan function.
392 * @param[in] base GEMAC base address
395 gemac_enable_stacked_vlan(__rte_unused void *base)
397 /* MTIP doesn't support stacked vlan */
400 /* GEMAC enable pause rx function.
401 * @param[in] base GEMAC base address
404 gemac_enable_pause_rx(void *base)
406 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_FCE,
407 base + EMAC_RCNTRL_REG);
410 /* GEMAC disable pause rx function.
411 * @param[in] base GEMAC base address
414 gemac_disable_pause_rx(void *base)
416 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_FCE,
417 base + EMAC_RCNTRL_REG);
420 /* GEMAC enable pause tx function.
421 * @param[in] base GEMAC base address
424 gemac_enable_pause_tx(void *base)
426 writel(EMAC_RX_SECTION_EMPTY_V, base + EMAC_RX_SECTION_EMPTY);
429 /* GEMAC disable pause tx function.
430 * @param[in] base GEMAC base address
433 gemac_disable_pause_tx(void *base)
435 writel(0x0, base + EMAC_RX_SECTION_EMPTY);
438 /* GEMAC wol configuration
439 * @param[in] base GEMAC base address
440 * @param[in] wol_conf WoL register configuration
443 gemac_set_wol(void *base, u32 wol_conf)
445 u32 val = readl(base + EMAC_ECNTRL_REG);
448 val |= (EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
450 val &= ~(EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
451 writel(val, base + EMAC_ECNTRL_REG);
454 /* Sets Gemac bus width to 64bit
455 * @param[in] base GEMAC base address
456 * @param[in] width gemac bus width to be set possible values are 32/64/128
459 gemac_set_bus_width(__rte_unused void *base, __rte_unused int width)
463 /* Sets Gemac configuration.
464 * @param[in] base GEMAC base address
465 * @param[in] cfg GEMAC configuration
468 gemac_set_config(void *base, struct gemac_cfg *cfg)
470 /*GEMAC config taken from VLSI */
471 writel(0x00000004, base + EMAC_TFWR_STR_FWD);
472 writel(0x00000005, base + EMAC_RX_SECTION_FULL);
474 if (pfe_svr == SVR_LS1012A_REV1)
475 writel(0x00000768, base + EMAC_TRUNC_FL);
477 writel(0x00003fff, base + EMAC_TRUNC_FL);
479 writel(0x00000030, base + EMAC_TX_SECTION_EMPTY);
480 writel(0x00000000, base + EMAC_MIB_CTRL_STS_REG);
482 gemac_set_mode(base, cfg->mode);
484 gemac_set_speed(base, cfg->speed);
486 gemac_set_duplex(base, cfg->duplex);
489 /**************************** GPI ***************************/
491 /* Initializes a GPI block.
492 * @param[in] base GPI base address
493 * @param[in] cfg GPI configuration
496 gpi_init(void *base, struct gpi_cfg *cfg)
502 gpi_set_config(base, cfg);
505 /* Resets a GPI block.
506 * @param[in] base GPI base address
509 gpi_reset(void *base)
511 writel(CORE_SW_RESET, base + GPI_CTRL);
514 /* Enables a GPI block.
515 * @param[in] base GPI base address
518 gpi_enable(void *base)
520 writel(CORE_ENABLE, base + GPI_CTRL);
523 /* Disables a GPI block.
524 * @param[in] base GPI base address
527 gpi_disable(void *base)
529 writel(CORE_DISABLE, base + GPI_CTRL);
532 /* Sets the configuration of a GPI block.
533 * @param[in] base GPI base address
534 * @param[in] cfg GPI configuration
537 gpi_set_config(void *base, struct gpi_cfg *cfg)
539 writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_ALLOC_CTRL), base
540 + GPI_LMEM_ALLOC_ADDR);
541 writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_FREE_CTRL), base
542 + GPI_LMEM_FREE_ADDR);
543 writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_ALLOC_CTRL), base
544 + GPI_DDR_ALLOC_ADDR);
545 writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL), base
546 + GPI_DDR_FREE_ADDR);
547 writel(CBUS_VIRT_TO_PFE(CLASS_INQ_PKTPTR), base + GPI_CLASS_ADDR);
548 writel(DDR_HDR_SIZE, base + GPI_DDR_DATA_OFFSET);
549 writel(LMEM_HDR_SIZE, base + GPI_LMEM_DATA_OFFSET);
550 writel(0, base + GPI_LMEM_SEC_BUF_DATA_OFFSET);
551 writel(0, base + GPI_DDR_SEC_BUF_DATA_OFFSET);
552 writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, base + GPI_HDR_SIZE);
553 writel((DDR_BUF_SIZE << 16) | LMEM_BUF_SIZE, base + GPI_BUF_SIZE);
555 writel(((cfg->lmem_rtry_cnt << 16) | (GPI_DDR_BUF_EN << 1) |
556 GPI_LMEM_BUF_EN), base + GPI_RX_CONFIG);
557 writel(cfg->tmlf_txthres, base + GPI_TMLF_TX);
558 writel(cfg->aseq_len, base + GPI_DTX_ASEQ);
559 writel(1, base + GPI_TOE_CHKSUM_EN);
561 if (cfg->mtip_pause_reg) {
562 writel(cfg->mtip_pause_reg, base + GPI_CSR_MTIP_PAUSE_REG);
563 writel(EGPI_PAUSE_TIME, base + GPI_TX_PAUSE_TIME);
567 /**************************** HIF ***************************/
568 /* Initializes HIF copy block.
574 /*Initialize HIF registers*/
575 writel((HIF_RX_POLL_CTRL_CYCLE << 16) | HIF_TX_POLL_CTRL_CYCLE,
579 /* Enable hif tx DMA and interrupt
585 writel(HIF_CTRL_DMA_EN, HIF_TX_CTRL);
586 writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_TXPKT_INT_EN),
590 /* Disable hif tx DMA and interrupt
598 writel(0, HIF_TX_CTRL);
600 hif_int = readl(HIF_INT_ENABLE);
601 hif_int &= HIF_TXPKT_INT_EN;
602 writel(hif_int, HIF_INT_ENABLE);
605 /* Enable hif rx DMA and interrupt
612 writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_RXPKT_INT_EN),
616 /* Disable hif rx DMA and interrupt
624 writel(0, HIF_RX_CTRL);
626 hif_int = readl(HIF_INT_ENABLE);
627 hif_int &= HIF_RXPKT_INT_EN;
628 writel(hif_int, HIF_INT_ENABLE);