1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2019 NXP
10 #define PFE_MTU_RESET_MASK 0xC000FFFF
14 unsigned long ddr_phys_base_addr;
15 unsigned int ddr_size;
16 static struct pe_info pe[MAX_PE];
18 /* Initializes the PFE library.
19 * Must be called before using any of the library functions.
21 * @param[in] cbus_base CBUS virtual base address (as mapped in
22 * the host CPU address space)
23 * @param[in] ddr_base PFE DDR range virtual base address (as
24 * mapped in the host CPU address space)
25 * @param[in] ddr_phys_base PFE DDR range physical base address (as
27 * @param[in] size PFE DDR range size (as defined by the host
31 pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
34 cbus_base_addr = cbus_base;
35 ddr_base_addr = ddr_base;
36 ddr_phys_base_addr = ddr_phys_base;
39 pe[CLASS0_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(0);
40 pe[CLASS0_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(0);
41 pe[CLASS0_ID].pmem_size = CLASS_IMEM_SIZE;
42 pe[CLASS0_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
43 pe[CLASS0_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
44 pe[CLASS0_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
46 pe[CLASS1_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(1);
47 pe[CLASS1_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(1);
48 pe[CLASS1_ID].pmem_size = CLASS_IMEM_SIZE;
49 pe[CLASS1_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
50 pe[CLASS1_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
51 pe[CLASS1_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
53 pe[CLASS2_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(2);
54 pe[CLASS2_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(2);
55 pe[CLASS2_ID].pmem_size = CLASS_IMEM_SIZE;
56 pe[CLASS2_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
57 pe[CLASS2_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
58 pe[CLASS2_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
60 pe[CLASS3_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(3);
61 pe[CLASS3_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(3);
62 pe[CLASS3_ID].pmem_size = CLASS_IMEM_SIZE;
63 pe[CLASS3_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
64 pe[CLASS3_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
65 pe[CLASS3_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
67 pe[CLASS4_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(4);
68 pe[CLASS4_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(4);
69 pe[CLASS4_ID].pmem_size = CLASS_IMEM_SIZE;
70 pe[CLASS4_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
71 pe[CLASS4_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
72 pe[CLASS4_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
74 pe[CLASS5_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(5);
75 pe[CLASS5_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(5);
76 pe[CLASS5_ID].pmem_size = CLASS_IMEM_SIZE;
77 pe[CLASS5_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
78 pe[CLASS5_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
79 pe[CLASS5_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
81 pe[TMU0_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(0);
82 pe[TMU0_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(0);
83 pe[TMU0_ID].pmem_size = TMU_IMEM_SIZE;
84 pe[TMU0_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
85 pe[TMU0_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
86 pe[TMU0_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
88 pe[TMU1_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(1);
89 pe[TMU1_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(1);
90 pe[TMU1_ID].pmem_size = TMU_IMEM_SIZE;
91 pe[TMU1_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
92 pe[TMU1_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
93 pe[TMU1_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
95 pe[TMU3_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(3);
96 pe[TMU3_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(3);
97 pe[TMU3_ID].pmem_size = TMU_IMEM_SIZE;
98 pe[TMU3_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
99 pe[TMU3_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
100 pe[TMU3_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
102 #if !defined(CONFIG_FSL_PFE_UTIL_DISABLED)
103 pe[UTIL_ID].dmem_base_addr = UTIL_DMEM_BASE_ADDR;
104 pe[UTIL_ID].mem_access_wdata = UTIL_MEM_ACCESS_WDATA;
105 pe[UTIL_ID].mem_access_addr = UTIL_MEM_ACCESS_ADDR;
106 pe[UTIL_ID].mem_access_rdata = UTIL_MEM_ACCESS_RDATA;
110 /**************************** MTIP GEMAC ***************************/
112 /* Enable Rx Checksum Engine. With this enabled, Frame with bad IP,
113 * TCP or UDP checksums are discarded
115 * @param[in] base GEMAC base address.
118 gemac_enable_rx_checksum_offload(__rte_unused void *base)
120 /*Do not find configuration to do this */
123 /* Disable Rx Checksum Engine.
125 * @param[in] base GEMAC base address.
128 gemac_disable_rx_checksum_offload(__rte_unused void *base)
130 /*Do not find configuration to do this */
134 * @param[in] base GEMAC base address
135 * @param[in] speed GEMAC speed (10, 100 or 1000 Mbps)
138 gemac_set_speed(void *base, enum mac_speed gem_speed)
140 u32 ecr = readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_SPEED;
141 u32 rcr = readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_RMII_10T;
145 rcr |= EMAC_RCNTRL_RMII_10T;
149 ecr |= EMAC_ECNTRL_SPEED;
154 /*It is in 100M mode */
157 writel(ecr, (base + EMAC_ECNTRL_REG));
158 writel(rcr, (base + EMAC_RCNTRL_REG));
162 * @param[in] base GEMAC base address
163 * @param[in] duplex GEMAC duplex mode (Full, Half)
166 gemac_set_duplex(void *base, int duplex)
168 if (duplex == DUPLEX_HALF) {
169 writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_FDEN, base
171 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_DRT, (base
174 writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_FDEN, base
176 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_DRT, (base
182 * @param[in] base GEMAC base address
183 * @param[in] mode GEMAC operation mode (MII, RMII, RGMII, SGMII)
186 gemac_set_mode(void *base, __rte_unused int mode)
188 u32 val = readl(base + EMAC_RCNTRL_REG);
191 val &= ~EMAC_RCNTRL_LOOP;
193 /*Enable flow control and MII mode*/
194 val |= (EMAC_RCNTRL_FCE | EMAC_RCNTRL_MII_MODE | EMAC_RCNTRL_CRC_FWD);
196 writel(val, base + EMAC_RCNTRL_REG);
199 /* GEMAC enable function.
200 * @param[in] base GEMAC base address
203 gemac_enable(void *base)
205 writel(readl(base + EMAC_ECNTRL_REG) | EMAC_ECNTRL_ETHER_EN, base +
209 /* GEMAC disable function.
210 * @param[in] base GEMAC base address
213 gemac_disable(void *base)
215 writel(readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_ETHER_EN, base +
219 /* GEMAC TX disable function.
220 * @param[in] base GEMAC base address
223 gemac_tx_disable(void *base)
225 writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_GTS, base +
230 gemac_tx_enable(void *base)
232 writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_GTS, base +
236 /* Sets the hash register of the MAC.
237 * This register is used for matching unicast and multicast frames.
239 * @param[in] base GEMAC base address.
240 * @param[in] hash 64-bit hash to be configured.
243 gemac_set_hash(void *base, struct pfe_mac_addr *hash)
245 writel(hash->bottom, base + EMAC_GALR);
246 writel(hash->top, base + EMAC_GAUR);
250 gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
251 unsigned int entry_index)
253 if (entry_index < 1 || entry_index > EMAC_SPEC_ADDR_MAX)
256 entry_index = entry_index - 1;
257 if (entry_index < 1) {
258 writel(htonl(address->bottom), base + EMAC_PHY_ADDR_LOW);
259 writel((htonl(address->top) | 0x8808), base +
262 writel(htonl(address->bottom), base + ((entry_index - 1) * 8)
264 writel((htonl(address->top) | 0x8808), base + ((entry_index -
265 1) * 8) + EMAC_SMAC_0_1);
270 gemac_clear_laddrN(void *base, unsigned int entry_index)
272 if (entry_index < 1 || entry_index > EMAC_SPEC_ADDR_MAX)
275 entry_index = entry_index - 1;
276 if (entry_index < 1) {
277 writel(0, base + EMAC_PHY_ADDR_LOW);
278 writel(0, base + EMAC_PHY_ADDR_HIGH);
280 writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_0);
281 writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_1);
285 /* Set the loopback mode of the MAC. This can be either no loopback for
286 * normal operation, local loopback through MAC internal loopback module or PHY
287 * loopback for external loopback through a PHY. This asserts the external
290 * @param[in] base GEMAC base address.
291 * @param[in] gem_loop Loopback mode to be enabled. LB_LOCAL - MAC
293 * LB_EXT - PHY Loopback.
296 gemac_set_loop(void *base, __rte_unused enum mac_loop gem_loop)
298 pr_info("%s()\n", __func__);
299 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_LOOP, (base +
303 /* GEMAC allow frames
304 * @param[in] base GEMAC base address
307 gemac_enable_copy_all(void *base)
309 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_PROM, (base +
313 /* GEMAC do not allow frames
314 * @param[in] base GEMAC base address
317 gemac_disable_copy_all(void *base)
319 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_PROM, (base +
323 /* GEMAC allow broadcast function.
324 * @param[in] base GEMAC base address
327 gemac_allow_broadcast(void *base)
329 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_BC_REJ, base +
333 /* GEMAC no broadcast function.
334 * @param[in] base GEMAC base address
337 gemac_no_broadcast(void *base)
339 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_BC_REJ, base +
343 /* GEMAC enable 1536 rx function.
344 * @param[in] base GEMAC base address
347 gemac_enable_1536_rx(void *base)
349 /* Set 1536 as Maximum frame length */
350 writel((readl(base + EMAC_RCNTRL_REG) & PFE_MTU_RESET_MASK)
352 base + EMAC_RCNTRL_REG);
355 /* GEMAC set Max rx function.
356 * @param[in] base GEMAC base address
359 gemac_set_rx(void *base, int mtu)
361 if (mtu < HIF_RX_PKT_MIN_SIZE || mtu > JUMBO_FRAME_SIZE) {
362 PFE_PMD_ERR("Invalid or not support MTU size");
366 if (pfe_svr == SVR_LS1012A_REV1 &&
367 mtu > (MAX_MTU_ON_REV1 + PFE_ETH_OVERHEAD)) {
368 PFE_PMD_ERR("Max supported MTU on Rev1 is %d", MAX_MTU_ON_REV1);
372 writel((readl(base + EMAC_RCNTRL_REG) & PFE_MTU_RESET_MASK)
374 base + EMAC_RCNTRL_REG);
378 /* GEMAC enable jumbo function.
379 * @param[in] base GEMAC base address
382 gemac_enable_rx_jmb(void *base)
384 if (pfe_svr == SVR_LS1012A_REV1) {
385 PFE_PMD_ERR("Jumbo not supported on Rev1");
389 writel((readl(base + EMAC_RCNTRL_REG) & PFE_MTU_RESET_MASK) |
390 (JUMBO_FRAME_SIZE << 16), base + EMAC_RCNTRL_REG);
393 /* GEMAC enable stacked vlan function.
394 * @param[in] base GEMAC base address
397 gemac_enable_stacked_vlan(__rte_unused void *base)
399 /* MTIP doesn't support stacked vlan */
402 /* GEMAC enable pause rx function.
403 * @param[in] base GEMAC base address
406 gemac_enable_pause_rx(void *base)
408 writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_FCE,
409 base + EMAC_RCNTRL_REG);
412 /* GEMAC disable pause rx function.
413 * @param[in] base GEMAC base address
416 gemac_disable_pause_rx(void *base)
418 writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_FCE,
419 base + EMAC_RCNTRL_REG);
422 /* GEMAC enable pause tx function.
423 * @param[in] base GEMAC base address
426 gemac_enable_pause_tx(void *base)
428 writel(EMAC_RX_SECTION_EMPTY_V, base + EMAC_RX_SECTION_EMPTY);
431 /* GEMAC disable pause tx function.
432 * @param[in] base GEMAC base address
435 gemac_disable_pause_tx(void *base)
437 writel(0x0, base + EMAC_RX_SECTION_EMPTY);
440 /* GEMAC wol configuration
441 * @param[in] base GEMAC base address
442 * @param[in] wol_conf WoL register configuration
445 gemac_set_wol(void *base, u32 wol_conf)
447 u32 val = readl(base + EMAC_ECNTRL_REG);
450 val |= (EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
452 val &= ~(EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
453 writel(val, base + EMAC_ECNTRL_REG);
456 /* Sets Gemac bus width to 64bit
457 * @param[in] base GEMAC base address
458 * @param[in] width gemac bus width to be set possible values are 32/64/128
461 gemac_set_bus_width(__rte_unused void *base, __rte_unused int width)
465 /* Sets Gemac configuration.
466 * @param[in] base GEMAC base address
467 * @param[in] cfg GEMAC configuration
470 gemac_set_config(void *base, struct gemac_cfg *cfg)
472 /*GEMAC config taken from VLSI */
473 writel(0x00000004, base + EMAC_TFWR_STR_FWD);
474 writel(0x00000005, base + EMAC_RX_SECTION_FULL);
476 if (pfe_svr == SVR_LS1012A_REV1)
477 writel(0x00000768, base + EMAC_TRUNC_FL);
479 writel(0x00003fff, base + EMAC_TRUNC_FL);
481 writel(0x00000030, base + EMAC_TX_SECTION_EMPTY);
482 writel(0x00000000, base + EMAC_MIB_CTRL_STS_REG);
484 gemac_set_mode(base, cfg->mode);
486 gemac_set_speed(base, cfg->speed);
488 gemac_set_duplex(base, cfg->duplex);
491 /**************************** GPI ***************************/
493 /* Initializes a GPI block.
494 * @param[in] base GPI base address
495 * @param[in] cfg GPI configuration
498 gpi_init(void *base, struct gpi_cfg *cfg)
504 gpi_set_config(base, cfg);
507 /* Resets a GPI block.
508 * @param[in] base GPI base address
511 gpi_reset(void *base)
513 writel(CORE_SW_RESET, base + GPI_CTRL);
516 /* Enables a GPI block.
517 * @param[in] base GPI base address
520 gpi_enable(void *base)
522 writel(CORE_ENABLE, base + GPI_CTRL);
525 /* Disables a GPI block.
526 * @param[in] base GPI base address
529 gpi_disable(void *base)
531 writel(CORE_DISABLE, base + GPI_CTRL);
534 /* Sets the configuration of a GPI block.
535 * @param[in] base GPI base address
536 * @param[in] cfg GPI configuration
539 gpi_set_config(void *base, struct gpi_cfg *cfg)
541 writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_ALLOC_CTRL), base
542 + GPI_LMEM_ALLOC_ADDR);
543 writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_FREE_CTRL), base
544 + GPI_LMEM_FREE_ADDR);
545 writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_ALLOC_CTRL), base
546 + GPI_DDR_ALLOC_ADDR);
547 writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL), base
548 + GPI_DDR_FREE_ADDR);
549 writel(CBUS_VIRT_TO_PFE(CLASS_INQ_PKTPTR), base + GPI_CLASS_ADDR);
550 writel(DDR_HDR_SIZE, base + GPI_DDR_DATA_OFFSET);
551 writel(LMEM_HDR_SIZE, base + GPI_LMEM_DATA_OFFSET);
552 writel(0, base + GPI_LMEM_SEC_BUF_DATA_OFFSET);
553 writel(0, base + GPI_DDR_SEC_BUF_DATA_OFFSET);
554 writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, base + GPI_HDR_SIZE);
555 writel((DDR_BUF_SIZE << 16) | LMEM_BUF_SIZE, base + GPI_BUF_SIZE);
557 writel(((cfg->lmem_rtry_cnt << 16) | (GPI_DDR_BUF_EN << 1) |
558 GPI_LMEM_BUF_EN), base + GPI_RX_CONFIG);
559 writel(cfg->tmlf_txthres, base + GPI_TMLF_TX);
560 writel(cfg->aseq_len, base + GPI_DTX_ASEQ);
561 writel(1, base + GPI_TOE_CHKSUM_EN);
563 if (cfg->mtip_pause_reg) {
564 writel(cfg->mtip_pause_reg, base + GPI_CSR_MTIP_PAUSE_REG);
565 writel(EGPI_PAUSE_TIME, base + GPI_TX_PAUSE_TIME);
569 /**************************** HIF ***************************/
570 /* Initializes HIF copy block.
576 /*Initialize HIF registers*/
577 writel((HIF_RX_POLL_CTRL_CYCLE << 16) | HIF_TX_POLL_CTRL_CYCLE,
581 /* Enable hif tx DMA and interrupt
587 writel(HIF_CTRL_DMA_EN, HIF_TX_CTRL);
588 writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_TXPKT_INT_EN),
592 /* Disable hif tx DMA and interrupt
600 writel(0, HIF_TX_CTRL);
602 hif_int = readl(HIF_INT_ENABLE);
603 hif_int &= HIF_TXPKT_INT_EN;
604 writel(hif_int, HIF_INT_ENABLE);
607 /* Enable hif rx DMA and interrupt
614 writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_RXPKT_INT_EN),
618 /* Disable hif rx DMA and interrupt
626 writel(0, HIF_RX_CTRL);
628 hif_int = readl(HIF_INT_ENABLE);
629 hif_int &= HIF_RXPKT_INT_EN;
630 writel(hif_int, HIF_INT_ENABLE);