1 From 35745905430a4c9827c235d42f3a61bef34043e8 Mon Sep 17 00:00:00 2001
2 From: Biwen Li <biwen.li@nxp.com>
3 Date: Fri, 19 Apr 2019 13:21:09 +0800
4 Subject: [PATCH] pfe-eth: support layerscape
6 This is an integrated patch of pfe-eth for layerscape
8 Signed-off-by: Akhila Kavi <akhila.kavi@nxp.com>
9 Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
10 Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
11 Signed-off-by: Archana Madhavan <archana.madhavan@nxp.com>
12 Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya@nxp.com>
13 Signed-off-by: Biwen Li <biwen.li@nxp.com>
14 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
15 Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
16 Signed-off-by: Guanhua Gao <guanhua.gao@nxp.com>
17 Signed-off-by: Sachin Saxena <sachin.saxena@nxp.com>
18 Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
19 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
21 .../devicetree/bindings/net/fsl_ppfe/pfe.txt | 199 ++
22 drivers/staging/fsl_ppfe/Kconfig | 21 +
23 drivers/staging/fsl_ppfe/Makefile | 20 +
24 drivers/staging/fsl_ppfe/TODO | 2 +
25 drivers/staging/fsl_ppfe/include/pfe/cbus.h | 78 +
26 .../staging/fsl_ppfe/include/pfe/cbus/bmu.h | 55 +
27 .../fsl_ppfe/include/pfe/cbus/class_csr.h | 289 ++
28 .../fsl_ppfe/include/pfe/cbus/emac_mtip.h | 242 ++
29 .../staging/fsl_ppfe/include/pfe/cbus/gpi.h | 86 +
30 .../staging/fsl_ppfe/include/pfe/cbus/hif.h | 100 +
31 .../fsl_ppfe/include/pfe/cbus/hif_nocpy.h | 50 +
32 .../fsl_ppfe/include/pfe/cbus/tmu_csr.h | 168 ++
33 .../fsl_ppfe/include/pfe/cbus/util_csr.h | 61 +
34 drivers/staging/fsl_ppfe/include/pfe/pfe.h | 372 +++
35 drivers/staging/fsl_ppfe/pfe_cdev.c | 258 ++
36 drivers/staging/fsl_ppfe/pfe_cdev.h | 41 +
37 drivers/staging/fsl_ppfe/pfe_ctrl.c | 226 ++
38 drivers/staging/fsl_ppfe/pfe_ctrl.h | 100 +
39 drivers/staging/fsl_ppfe/pfe_debugfs.c | 99 +
40 drivers/staging/fsl_ppfe/pfe_debugfs.h | 13 +
41 drivers/staging/fsl_ppfe/pfe_eth.c | 2554 +++++++++++++++++
42 drivers/staging/fsl_ppfe/pfe_eth.h | 175 ++
43 drivers/staging/fsl_ppfe/pfe_firmware.c | 302 ++
44 drivers/staging/fsl_ppfe/pfe_firmware.h | 20 +
45 drivers/staging/fsl_ppfe/pfe_hal.c | 1516 ++++++++++
46 drivers/staging/fsl_ppfe/pfe_hif.c | 1060 +++++++
47 drivers/staging/fsl_ppfe/pfe_hif.h | 200 ++
48 drivers/staging/fsl_ppfe/pfe_hif_lib.c | 628 ++++
49 drivers/staging/fsl_ppfe/pfe_hif_lib.h | 229 ++
50 drivers/staging/fsl_ppfe/pfe_hw.c | 164 ++
51 drivers/staging/fsl_ppfe/pfe_hw.h | 15 +
52 .../staging/fsl_ppfe/pfe_ls1012a_platform.c | 368 +++
53 drivers/staging/fsl_ppfe/pfe_mod.c | 158 +
54 drivers/staging/fsl_ppfe/pfe_mod.h | 103 +
55 drivers/staging/fsl_ppfe/pfe_perfmon.h | 26 +
56 drivers/staging/fsl_ppfe/pfe_sysfs.c | 806 ++++++
57 drivers/staging/fsl_ppfe/pfe_sysfs.h | 17 +
58 37 files changed, 10821 insertions(+)
59 create mode 100644 Documentation/devicetree/bindings/net/fsl_ppfe/pfe.txt
60 create mode 100644 drivers/staging/fsl_ppfe/Kconfig
61 create mode 100644 drivers/staging/fsl_ppfe/Makefile
62 create mode 100644 drivers/staging/fsl_ppfe/TODO
63 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus.h
64 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h
65 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h
66 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h
67 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h
68 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h
69 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h
70 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h
71 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h
72 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/pfe.h
73 create mode 100644 drivers/staging/fsl_ppfe/pfe_cdev.c
74 create mode 100644 drivers/staging/fsl_ppfe/pfe_cdev.h
75 create mode 100644 drivers/staging/fsl_ppfe/pfe_ctrl.c
76 create mode 100644 drivers/staging/fsl_ppfe/pfe_ctrl.h
77 create mode 100644 drivers/staging/fsl_ppfe/pfe_debugfs.c
78 create mode 100644 drivers/staging/fsl_ppfe/pfe_debugfs.h
79 create mode 100644 drivers/staging/fsl_ppfe/pfe_eth.c
80 create mode 100644 drivers/staging/fsl_ppfe/pfe_eth.h
81 create mode 100644 drivers/staging/fsl_ppfe/pfe_firmware.c
82 create mode 100644 drivers/staging/fsl_ppfe/pfe_firmware.h
83 create mode 100644 drivers/staging/fsl_ppfe/pfe_hal.c
84 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif.c
85 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif.h
86 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif_lib.c
87 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif_lib.h
88 create mode 100644 drivers/staging/fsl_ppfe/pfe_hw.c
89 create mode 100644 drivers/staging/fsl_ppfe/pfe_hw.h
90 create mode 100644 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
91 create mode 100644 drivers/staging/fsl_ppfe/pfe_mod.c
92 create mode 100644 drivers/staging/fsl_ppfe/pfe_mod.h
93 create mode 100644 drivers/staging/fsl_ppfe/pfe_perfmon.h
94 create mode 100644 drivers/staging/fsl_ppfe/pfe_sysfs.c
95 create mode 100644 drivers/staging/fsl_ppfe/pfe_sysfs.h
98 +++ b/Documentation/devicetree/bindings/net/fsl_ppfe/pfe.txt
100 +=============================================================================
101 +NXP Programmable Packet Forwarding Engine Device Bindings
107 +=============================================================================
112 +PFE Node has all the properties associated with Packet Forwarding Engine block.
118 + Value type: <stringlist>
119 + Definition: Must include "fsl,pfe"
123 + Value type: <prop-encoded-array>
124 + Definition: A standard property.
125 + Specifies the offset of the following registers:
126 + - PFE configuration registers
127 + - DDR memory used by PFE
129 +- fsl,pfe-num-interfaces
132 + Definition: Must be present. Value can be either one or two.
136 + Value type: <prop-encoded-array>
137 + Definition: Three interrupts are specified in this property.
139 + - HIF NO COPY interrupt
140 + - Wake On LAN interrupt
144 + Value type: <stringlist>
145 + Definition: Following strings are defined for the 3 interrupts.
146 + "pfe_hif" - HIF interrupt
147 + "pfe_hif_nocpy" - HIF NO COPY interrupt
148 + "pfe_wol" - Wake On LAN interrupt
152 + Value type: <phandle>
153 + Definition: phandle to a node describing reserved memory used by pfe.
154 + Refer:- Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
158 + Value type: <phandle>
159 + Definition: phandle for scfg.
163 + Value type: <phandle>
164 + Definition: phandle for rcpm.
168 + Value type: <phandle>
169 + Definition: phandle for clockgen.
173 + Value type: <string>
174 + Definition: phandle for clock name.
179 + compatible = "fsl,pfe";
180 + reg = <0x0 0x04000000 0x0 0xc00000>, /* AXI 16M */
181 + <0x0 0x83400000 0x0 0xc00000>; /* PFE DDR 12M */
182 + reg-names = "pfe", "pfe-ddr";
183 + fsl,pfe-num-interfaces = <0x2>;
184 + interrupts = <0 172 0x4>, /* HIF interrupt */
185 + <0 173 0x4>, /*HIF_NOCPY interrupt */
186 + <0 174 0x4>; /* WoL interrupt */
187 + interrupt-names = "pfe_hif", "pfe_hif_nocpy", "pfe_wol";
188 + memory-region = <&pfe_reserved>;
189 + fsl,pfe-scfg = <&scfg 0>;
190 + fsl,rcpm-wakeup = <&rcpm 0xf0000020>;
191 + clocks = <&clockgen 4 0>;
192 + clock-names = "pfe";
195 + pfe_mac0: ethernet@0 {
198 + pfe_mac1: ethernet@1 {
202 +=============================================================================
207 +Ethernet Node has all the properties associated with PFE used by platforms to
214 + Value type: <stringlist>
215 + Definition: Must include "fsl,pfe-gemac-port"
219 + Value type: <prop-encoded-array>
220 + Definition: A standard property.
221 + Specifies the gemacid of the interface.
226 + Definition: Must be present. Value should be the id of the bus
227 + connected to gemac.
229 +- fsl,gemac-phy-id (deprecated binding)
232 + Definition: This binding shouldn't be used with new platforms.
233 + Must be present. Value should be the id of the phy
234 + connected to gemac.
239 + Definition: Must be present. Value can be either 0 or 2 or 3.
240 + This value is used to configure the mux to enable mdio.
244 + Value type: <string>
245 + Definition: Must include "sgmii"
247 +- fsl,pfe-phy-if-flags (deprecated binding)
250 + Definition: This binding shouldn't be used with new platforms.
251 + Must be present. Value should be 0 by default.
252 + If there is not phy connected, this need to be 1.
256 + Value type: <phandle>
257 + Definition: phandle to the PHY device connected to this device.
259 +- mdio : A required subnode which specifies the mdio bus in the PFE and used as
260 +a container for phy nodes according to ../phy.txt.
265 + compatible = "fsl,pfe-gemac-port";
266 + #address-cells = <1>;
268 + reg = <0x0>; /* GEM_ID */
269 + fsl,gemac-bus-id = <0x0>; /* BUS_ID */
270 + fsl,mdio-mux-val = <0x0>;
271 + phy-mode = "sgmii";
272 + phy-handle = <&sgmii_phy1>;
277 + compatible = "fsl,pfe-gemac-port";
278 + #address-cells = <1>;
280 + reg = <0x1>; /* GEM_ID */
281 + fsl,gemac-bus-id = <0x1>; /* BUS_ID */
282 + fsl,mdio-mux-val = <0x0>;
283 + phy-mode = "sgmii";
284 + phy-handle = <&sgmii_phy2>;
288 + #address-cells = <1>;
291 + sgmii_phy1: ethernet-phy@2 {
295 + sgmii_phy2: ethernet-phy@1 {
300 +++ b/drivers/staging/fsl_ppfe/Kconfig
303 +# Freescale Programmable Packet Forwarding Engine driver
306 + bool "Freescale PPFE Driver"
310 + Freescale LS1012A SoC has a Programmable Packet Forwarding Engine.
311 + It provides two high performance ethernet interfaces.
312 + This driver initializes, programs and controls the PPFE.
313 + Use this driver to enable network connectivity on LS1012A platforms.
317 +config FSL_PPFE_UTIL_DISABLED
318 + bool "Disable PPFE UTIL Processor Engine"
320 + UTIL PE has to be enabled only if required.
324 +++ b/drivers/staging/fsl_ppfe/Makefile
327 +# Makefile for Freesecale PPFE driver
330 +ccflags-y += -I$(src)/include -I$(src)
334 +pfe-y += pfe_mod.o \
343 + pfe_ls1012a_platform.o \
347 +++ b/drivers/staging/fsl_ppfe/TODO
350 + - provide pfe pe monitoring support
352 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus.h
355 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
356 + * Copyright 2017 NXP
358 + * This program is free software; you can redistribute it and/or modify
359 + * it under the terms of the GNU General Public License as published by
360 + * the Free Software Foundation; either version 2 of the License, or
361 + * (at your option) any later version.
363 + * This program is distributed in the hope that it will be useful,
364 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
365 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
366 + * GNU General Public License for more details.
368 + * You should have received a copy of the GNU General Public License
369 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
375 +#define EMAC1_BASE_ADDR (CBUS_BASE_ADDR + 0x200000)
376 +#define EGPI1_BASE_ADDR (CBUS_BASE_ADDR + 0x210000)
377 +#define EMAC2_BASE_ADDR (CBUS_BASE_ADDR + 0x220000)
378 +#define EGPI2_BASE_ADDR (CBUS_BASE_ADDR + 0x230000)
379 +#define BMU1_BASE_ADDR (CBUS_BASE_ADDR + 0x240000)
380 +#define BMU2_BASE_ADDR (CBUS_BASE_ADDR + 0x250000)
381 +#define ARB_BASE_ADDR (CBUS_BASE_ADDR + 0x260000)
382 +#define DDR_CONFIG_BASE_ADDR (CBUS_BASE_ADDR + 0x270000)
383 +#define HIF_BASE_ADDR (CBUS_BASE_ADDR + 0x280000)
384 +#define HGPI_BASE_ADDR (CBUS_BASE_ADDR + 0x290000)
385 +#define LMEM_BASE_ADDR (CBUS_BASE_ADDR + 0x300000)
386 +#define LMEM_SIZE 0x10000
387 +#define LMEM_END (LMEM_BASE_ADDR + LMEM_SIZE)
388 +#define TMU_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x310000)
389 +#define CLASS_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x320000)
390 +#define HIF_NOCPY_BASE_ADDR (CBUS_BASE_ADDR + 0x350000)
391 +#define UTIL_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x360000)
392 +#define CBUS_GPT_BASE_ADDR (CBUS_BASE_ADDR + 0x370000)
395 + * defgroup XXX_MEM_ACCESS_ADDR PE memory access through CSR
396 + * XXX_MEM_ACCESS_ADDR register bit definitions.
398 +#define PE_MEM_ACCESS_WRITE BIT(31) /* Internal Memory Write. */
399 +#define PE_MEM_ACCESS_IMEM BIT(15)
400 +#define PE_MEM_ACCESS_DMEM BIT(16)
402 +/* Byte Enables of the Internal memory access. These are interpred in BE */
403 +#define PE_MEM_ACCESS_BYTE_ENABLE(offset, size) \
404 + ({ typeof(size) size_ = (size); \
405 + (((BIT(size_) - 1) << (4 - (offset) - (size_))) & 0xf) << 24; })
407 +#include "cbus/emac_mtip.h"
408 +#include "cbus/gpi.h"
409 +#include "cbus/bmu.h"
410 +#include "cbus/hif.h"
411 +#include "cbus/tmu_csr.h"
412 +#include "cbus/class_csr.h"
413 +#include "cbus/hif_nocpy.h"
414 +#include "cbus/util_csr.h"
416 +/* PFE cores states */
417 +#define CORE_DISABLE 0x00000000
418 +#define CORE_ENABLE 0x00000001
419 +#define CORE_SW_RESET 0x00000002
422 +#define LMEM_HDR_SIZE 0x0010
423 +#define LMEM_BUF_SIZE_LN2 0x7
424 +#define LMEM_BUF_SIZE BIT(LMEM_BUF_SIZE_LN2)
427 +#define DDR_HDR_SIZE 0x0100
428 +#define DDR_BUF_SIZE_LN2 0xb
429 +#define DDR_BUF_SIZE BIT(DDR_BUF_SIZE_LN2)
431 +#endif /* _CBUS_H_ */
433 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h
436 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
437 + * Copyright 2017 NXP
439 + * This program is free software; you can redistribute it and/or modify
440 + * it under the terms of the GNU General Public License as published by
441 + * the Free Software Foundation; either version 2 of the License, or
442 + * (at your option) any later version.
444 + * This program is distributed in the hope that it will be useful,
445 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
446 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
447 + * GNU General Public License for more details.
449 + * You should have received a copy of the GNU General Public License
450 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
456 +#define BMU_VERSION 0x000
457 +#define BMU_CTRL 0x004
458 +#define BMU_UCAST_CONFIG 0x008
459 +#define BMU_UCAST_BASE_ADDR 0x00c
460 +#define BMU_BUF_SIZE 0x010
461 +#define BMU_BUF_CNT 0x014
462 +#define BMU_THRES 0x018
463 +#define BMU_INT_SRC 0x020
464 +#define BMU_INT_ENABLE 0x024
465 +#define BMU_ALLOC_CTRL 0x030
466 +#define BMU_FREE_CTRL 0x034
467 +#define BMU_FREE_ERR_ADDR 0x038
468 +#define BMU_CURR_BUF_CNT 0x03c
469 +#define BMU_MCAST_CNT 0x040
470 +#define BMU_MCAST_ALLOC_CTRL 0x044
471 +#define BMU_REM_BUF_CNT 0x048
472 +#define BMU_LOW_WATERMARK 0x050
473 +#define BMU_HIGH_WATERMARK 0x054
474 +#define BMU_INT_MEM_ACCESS 0x100
477 + unsigned long baseaddr;
481 + u32 high_watermark;
484 +#define BMU1_BUF_SIZE LMEM_BUF_SIZE_LN2
485 +#define BMU2_BUF_SIZE DDR_BUF_SIZE_LN2
487 +#define BMU2_MCAST_ALLOC_CTRL (BMU2_BASE_ADDR + BMU_MCAST_ALLOC_CTRL)
489 +#endif /* _BMU_H_ */
491 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h
494 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
495 + * Copyright 2017 NXP
497 + * This program is free software; you can redistribute it and/or modify
498 + * it under the terms of the GNU General Public License as published by
499 + * the Free Software Foundation; either version 2 of the License, or
500 + * (at your option) any later version.
502 + * This program is distributed in the hope that it will be useful,
503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
505 + * GNU General Public License for more details.
507 + * You should have received a copy of the GNU General Public License
508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
511 +#ifndef _CLASS_CSR_H_
512 +#define _CLASS_CSR_H_
514 +/* @file class_csr.h.
515 + * class_csr - block containing all the classifier control and status register.
516 + * Mapped on CBUS and accessible from all PE's and ARM.
518 +#define CLASS_VERSION (CLASS_CSR_BASE_ADDR + 0x000)
519 +#define CLASS_TX_CTRL (CLASS_CSR_BASE_ADDR + 0x004)
520 +#define CLASS_INQ_PKTPTR (CLASS_CSR_BASE_ADDR + 0x010)
522 +/* (ddr_hdr_size[24:16], lmem_hdr_size[5:0]) */
523 +#define CLASS_HDR_SIZE (CLASS_CSR_BASE_ADDR + 0x014)
525 +/* LMEM header size for the Classifier block.\ Data in the LMEM
526 + * is written from this offset.
528 +#define CLASS_HDR_SIZE_LMEM(off) ((off) & 0x3f)
530 +/* DDR header size for the Classifier block.\ Data in the DDR
531 + * is written from this offset.
533 +#define CLASS_HDR_SIZE_DDR(off) (((off) & 0x1ff) << 16)
535 +#define CLASS_PE0_QB_DM_ADDR0 (CLASS_CSR_BASE_ADDR + 0x020)
537 +/* DMEM address of first [15:0] and second [31:16] buffers on QB side. */
538 +#define CLASS_PE0_QB_DM_ADDR1 (CLASS_CSR_BASE_ADDR + 0x024)
540 +/* DMEM address of third [15:0] and fourth [31:16] buffers on QB side. */
541 +#define CLASS_PE0_RO_DM_ADDR0 (CLASS_CSR_BASE_ADDR + 0x060)
543 +/* DMEM address of first [15:0] and second [31:16] buffers on RO side. */
544 +#define CLASS_PE0_RO_DM_ADDR1 (CLASS_CSR_BASE_ADDR + 0x064)
546 +/* DMEM address of third [15:0] and fourth [31:16] buffers on RO side. */
548 +/* @name Class PE memory access. Allows external PE's and HOST to
549 + * read/write PMEM/DMEM memory ranges for each classifier PE.
551 +/* {sr_pe_mem_cmd[31], csr_pe_mem_wren[27:24], csr_pe_mem_addr[23:0]},
552 + * See \ref XXX_MEM_ACCESS_ADDR for details.
554 +#define CLASS_MEM_ACCESS_ADDR (CLASS_CSR_BASE_ADDR + 0x100)
556 +/* Internal Memory Access Write Data [31:0] */
557 +#define CLASS_MEM_ACCESS_WDATA (CLASS_CSR_BASE_ADDR + 0x104)
559 +/* Internal Memory Access Read Data [31:0] */
560 +#define CLASS_MEM_ACCESS_RDATA (CLASS_CSR_BASE_ADDR + 0x108)
561 +#define CLASS_TM_INQ_ADDR (CLASS_CSR_BASE_ADDR + 0x114)
562 +#define CLASS_PE_STATUS (CLASS_CSR_BASE_ADDR + 0x118)
564 +#define CLASS_PHY1_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x11c)
565 +#define CLASS_PHY1_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x120)
566 +#define CLASS_PHY1_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x124)
567 +#define CLASS_PHY1_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x128)
568 +#define CLASS_PHY1_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x12c)
569 +#define CLASS_PHY1_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x130)
570 +#define CLASS_PHY1_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x134)
571 +#define CLASS_PHY1_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x138)
572 +#define CLASS_PHY1_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x13c)
573 +#define CLASS_PHY1_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x140)
574 +#define CLASS_PHY2_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x144)
575 +#define CLASS_PHY2_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x148)
576 +#define CLASS_PHY2_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x14c)
577 +#define CLASS_PHY2_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x150)
578 +#define CLASS_PHY2_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x154)
579 +#define CLASS_PHY2_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x158)
580 +#define CLASS_PHY2_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x15c)
581 +#define CLASS_PHY2_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x160)
582 +#define CLASS_PHY2_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x164)
583 +#define CLASS_PHY2_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x168)
584 +#define CLASS_PHY3_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x16c)
585 +#define CLASS_PHY3_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x170)
586 +#define CLASS_PHY3_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x174)
587 +#define CLASS_PHY3_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x178)
588 +#define CLASS_PHY3_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x17c)
589 +#define CLASS_PHY3_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x180)
590 +#define CLASS_PHY3_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x184)
591 +#define CLASS_PHY3_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x188)
592 +#define CLASS_PHY3_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x18c)
593 +#define CLASS_PHY3_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x190)
594 +#define CLASS_PHY1_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x194)
595 +#define CLASS_PHY1_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x198)
596 +#define CLASS_PHY1_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x19c)
597 +#define CLASS_PHY1_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a0)
598 +#define CLASS_PHY2_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a4)
599 +#define CLASS_PHY2_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a8)
600 +#define CLASS_PHY2_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1ac)
601 +#define CLASS_PHY2_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b0)
602 +#define CLASS_PHY3_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b4)
603 +#define CLASS_PHY3_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b8)
604 +#define CLASS_PHY3_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1bc)
605 +#define CLASS_PHY3_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c0)
606 +#define CLASS_PHY4_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c4)
607 +#define CLASS_PHY4_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c8)
608 +#define CLASS_PHY4_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1cc)
609 +#define CLASS_PHY4_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1d0)
610 +#define CLASS_PHY4_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x1d4)
611 +#define CLASS_PHY4_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x1d8)
612 +#define CLASS_PHY4_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1dc)
613 +#define CLASS_PHY4_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1e0)
614 +#define CLASS_PHY4_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x1e4)
615 +#define CLASS_PHY4_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1e8)
616 +#define CLASS_PHY4_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x1ec)
617 +#define CLASS_PHY4_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x1f0)
618 +#define CLASS_PHY4_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x1f4)
619 +#define CLASS_PHY4_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x1f8)
621 +#define CLASS_PE_SYS_CLK_RATIO (CLASS_CSR_BASE_ADDR + 0x200)
622 +#define CLASS_AFULL_THRES (CLASS_CSR_BASE_ADDR + 0x204)
623 +#define CLASS_GAP_BETWEEN_READS (CLASS_CSR_BASE_ADDR + 0x208)
624 +#define CLASS_MAX_BUF_CNT (CLASS_CSR_BASE_ADDR + 0x20c)
625 +#define CLASS_TSQ_FIFO_THRES (CLASS_CSR_BASE_ADDR + 0x210)
626 +#define CLASS_TSQ_MAX_CNT (CLASS_CSR_BASE_ADDR + 0x214)
627 +#define CLASS_IRAM_DATA_0 (CLASS_CSR_BASE_ADDR + 0x218)
628 +#define CLASS_IRAM_DATA_1 (CLASS_CSR_BASE_ADDR + 0x21c)
629 +#define CLASS_IRAM_DATA_2 (CLASS_CSR_BASE_ADDR + 0x220)
630 +#define CLASS_IRAM_DATA_3 (CLASS_CSR_BASE_ADDR + 0x224)
632 +#define CLASS_BUS_ACCESS_ADDR (CLASS_CSR_BASE_ADDR + 0x228)
634 +#define CLASS_BUS_ACCESS_WDATA (CLASS_CSR_BASE_ADDR + 0x22c)
635 +#define CLASS_BUS_ACCESS_RDATA (CLASS_CSR_BASE_ADDR + 0x230)
637 +/* (route_entry_size[9:0], route_hash_size[23:16]
638 + * (this is actually ln2(size)))
640 +#define CLASS_ROUTE_HASH_ENTRY_SIZE (CLASS_CSR_BASE_ADDR + 0x234)
642 +#define CLASS_ROUTE_ENTRY_SIZE(size) ((size) & 0x1ff)
643 +#define CLASS_ROUTE_HASH_SIZE(hash_bits) (((hash_bits) & 0xff) << 16)
645 +#define CLASS_ROUTE_TABLE_BASE (CLASS_CSR_BASE_ADDR + 0x238)
647 +#define CLASS_ROUTE_MULTI (CLASS_CSR_BASE_ADDR + 0x23c)
648 +#define CLASS_SMEM_OFFSET (CLASS_CSR_BASE_ADDR + 0x240)
649 +#define CLASS_LMEM_BUF_SIZE (CLASS_CSR_BASE_ADDR + 0x244)
650 +#define CLASS_VLAN_ID (CLASS_CSR_BASE_ADDR + 0x248)
651 +#define CLASS_BMU1_BUF_FREE (CLASS_CSR_BASE_ADDR + 0x24c)
652 +#define CLASS_USE_TMU_INQ (CLASS_CSR_BASE_ADDR + 0x250)
653 +#define CLASS_VLAN_ID1 (CLASS_CSR_BASE_ADDR + 0x254)
655 +#define CLASS_BUS_ACCESS_BASE (CLASS_CSR_BASE_ADDR + 0x258)
656 +#define CLASS_BUS_ACCESS_BASE_MASK (0xFF000000)
657 +/* bit 31:24 of PE peripheral address are stored in CLASS_BUS_ACCESS_BASE */
659 +#define CLASS_HIF_PARSE (CLASS_CSR_BASE_ADDR + 0x25c)
661 +#define CLASS_HOST_PE0_GP (CLASS_CSR_BASE_ADDR + 0x260)
662 +#define CLASS_PE0_GP (CLASS_CSR_BASE_ADDR + 0x264)
663 +#define CLASS_HOST_PE1_GP (CLASS_CSR_BASE_ADDR + 0x268)
664 +#define CLASS_PE1_GP (CLASS_CSR_BASE_ADDR + 0x26c)
665 +#define CLASS_HOST_PE2_GP (CLASS_CSR_BASE_ADDR + 0x270)
666 +#define CLASS_PE2_GP (CLASS_CSR_BASE_ADDR + 0x274)
667 +#define CLASS_HOST_PE3_GP (CLASS_CSR_BASE_ADDR + 0x278)
668 +#define CLASS_PE3_GP (CLASS_CSR_BASE_ADDR + 0x27c)
669 +#define CLASS_HOST_PE4_GP (CLASS_CSR_BASE_ADDR + 0x280)
670 +#define CLASS_PE4_GP (CLASS_CSR_BASE_ADDR + 0x284)
671 +#define CLASS_HOST_PE5_GP (CLASS_CSR_BASE_ADDR + 0x288)
672 +#define CLASS_PE5_GP (CLASS_CSR_BASE_ADDR + 0x28c)
674 +#define CLASS_PE_INT_SRC (CLASS_CSR_BASE_ADDR + 0x290)
675 +#define CLASS_PE_INT_ENABLE (CLASS_CSR_BASE_ADDR + 0x294)
677 +#define CLASS_TPID0_TPID1 (CLASS_CSR_BASE_ADDR + 0x298)
678 +#define CLASS_TPID2 (CLASS_CSR_BASE_ADDR + 0x29c)
680 +#define CLASS_L4_CHKSUM_ADDR (CLASS_CSR_BASE_ADDR + 0x2a0)
682 +#define CLASS_PE0_DEBUG (CLASS_CSR_BASE_ADDR + 0x2a4)
683 +#define CLASS_PE1_DEBUG (CLASS_CSR_BASE_ADDR + 0x2a8)
684 +#define CLASS_PE2_DEBUG (CLASS_CSR_BASE_ADDR + 0x2ac)
685 +#define CLASS_PE3_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b0)
686 +#define CLASS_PE4_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b4)
687 +#define CLASS_PE5_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b8)
689 +#define CLASS_STATE (CLASS_CSR_BASE_ADDR + 0x2bc)
692 +#define CLASS_PBUF_SIZE 0x100 /* Fixed by hardware */
693 +#define CLASS_PBUF_HEADER_OFFSET 0x80 /* Can be configured */
695 +/* Can be configured */
696 +#define CLASS_PBUF0_BASE_ADDR 0x000
697 +/* Can be configured */
698 +#define CLASS_PBUF1_BASE_ADDR (CLASS_PBUF0_BASE_ADDR + CLASS_PBUF_SIZE)
699 +/* Can be configured */
700 +#define CLASS_PBUF2_BASE_ADDR (CLASS_PBUF1_BASE_ADDR + CLASS_PBUF_SIZE)
701 +/* Can be configured */
702 +#define CLASS_PBUF3_BASE_ADDR (CLASS_PBUF2_BASE_ADDR + CLASS_PBUF_SIZE)
704 +#define CLASS_PBUF0_HEADER_BASE_ADDR (CLASS_PBUF0_BASE_ADDR + \
705 + CLASS_PBUF_HEADER_OFFSET)
706 +#define CLASS_PBUF1_HEADER_BASE_ADDR (CLASS_PBUF1_BASE_ADDR + \
707 + CLASS_PBUF_HEADER_OFFSET)
708 +#define CLASS_PBUF2_HEADER_BASE_ADDR (CLASS_PBUF2_BASE_ADDR + \
709 + CLASS_PBUF_HEADER_OFFSET)
710 +#define CLASS_PBUF3_HEADER_BASE_ADDR (CLASS_PBUF3_BASE_ADDR + \
711 + CLASS_PBUF_HEADER_OFFSET)
713 +#define CLASS_PE0_RO_DM_ADDR0_VAL ((CLASS_PBUF1_BASE_ADDR << 16) | \
714 + CLASS_PBUF0_BASE_ADDR)
715 +#define CLASS_PE0_RO_DM_ADDR1_VAL ((CLASS_PBUF3_BASE_ADDR << 16) | \
716 + CLASS_PBUF2_BASE_ADDR)
718 +#define CLASS_PE0_QB_DM_ADDR0_VAL ((CLASS_PBUF1_HEADER_BASE_ADDR << 16) |\
719 + CLASS_PBUF0_HEADER_BASE_ADDR)
720 +#define CLASS_PE0_QB_DM_ADDR1_VAL ((CLASS_PBUF3_HEADER_BASE_ADDR << 16) |\
721 + CLASS_PBUF2_HEADER_BASE_ADDR)
723 +#define CLASS_ROUTE_SIZE 128
724 +#define CLASS_MAX_ROUTE_SIZE 256
725 +#define CLASS_ROUTE_HASH_BITS 20
726 +#define CLASS_ROUTE_HASH_MASK (BIT(CLASS_ROUTE_HASH_BITS) - 1)
728 +/* Can be configured */
729 +#define CLASS_ROUTE0_BASE_ADDR 0x400
730 +/* Can be configured */
731 +#define CLASS_ROUTE1_BASE_ADDR (CLASS_ROUTE0_BASE_ADDR + CLASS_ROUTE_SIZE)
732 +/* Can be configured */
733 +#define CLASS_ROUTE2_BASE_ADDR (CLASS_ROUTE1_BASE_ADDR + CLASS_ROUTE_SIZE)
734 +/* Can be configured */
735 +#define CLASS_ROUTE3_BASE_ADDR (CLASS_ROUTE2_BASE_ADDR + CLASS_ROUTE_SIZE)
737 +#define CLASS_SA_SIZE 128
738 +#define CLASS_IPSEC_SA0_BASE_ADDR 0x600
740 +#define CLASS_IPSEC_SA1_BASE_ADDR (CLASS_IPSEC_SA0_BASE_ADDR + CLASS_SA_SIZE)
742 +#define CLASS_IPSEC_SA2_BASE_ADDR (CLASS_IPSEC_SA1_BASE_ADDR + CLASS_SA_SIZE)
744 +#define CLASS_IPSEC_SA3_BASE_ADDR (CLASS_IPSEC_SA2_BASE_ADDR + CLASS_SA_SIZE)
746 +/* generic purpose free dmem buffer, last portion of 2K dmem pbuf */
747 +#define CLASS_GP_DMEM_BUF_SIZE (2048 - (CLASS_PBUF_SIZE * 4) - \
748 + (CLASS_ROUTE_SIZE * 4) - (CLASS_SA_SIZE))
749 +#define CLASS_GP_DMEM_BUF ((void *)(CLASS_IPSEC_SA0_BASE_ADDR + \
752 +#define TWO_LEVEL_ROUTE BIT(0)
753 +#define PHYNO_IN_HASH BIT(1)
754 +#define HW_ROUTE_FETCH BIT(3)
755 +#define HW_BRIDGE_FETCH BIT(5)
756 +#define IP_ALIGNED BIT(6)
757 +#define ARC_HIT_CHECK_EN BIT(7)
758 +#define CLASS_TOE BIT(11)
759 +#define HASH_NORMAL (0 << 12)
760 +#define HASH_CRC_PORT BIT(12)
761 +#define HASH_CRC_IP (2 << 12)
762 +#define HASH_CRC_PORT_IP (3 << 12)
763 +#define QB2BUS_LE BIT(15)
765 +#define TCP_CHKSUM_DROP BIT(0)
766 +#define UDP_CHKSUM_DROP BIT(1)
767 +#define IPV4_CHKSUM_DROP BIT(9)
769 +/*CLASS_HIF_PARSE bits*/
770 +#define HIF_PKT_CLASS_EN BIT(0)
771 +#define HIF_PKT_OFFSET(ofst) (((ofst) & 0xF) << 1)
775 + unsigned long route_table_baseaddr;
776 + u32 route_table_hash_bits;
777 + u32 pe_sys_clk_ratio;
781 +#endif /* _CLASS_CSR_H_ */
783 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h
786 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
787 + * Copyright 2017 NXP
789 + * This program is free software; you can redistribute it and/or modify
790 + * it under the terms of the GNU General Public License as published by
791 + * the Free Software Foundation; either version 2 of the License, or
792 + * (at your option) any later version.
794 + * This program is distributed in the hope that it will be useful,
795 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
796 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
797 + * GNU General Public License for more details.
799 + * You should have received a copy of the GNU General Public License
800 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
806 +#include <linux/ethtool.h>
808 +#define EMAC_IEVENT_REG 0x004
809 +#define EMAC_IMASK_REG 0x008
810 +#define EMAC_R_DES_ACTIVE_REG 0x010
811 +#define EMAC_X_DES_ACTIVE_REG 0x014
812 +#define EMAC_ECNTRL_REG 0x024
813 +#define EMAC_MII_DATA_REG 0x040
814 +#define EMAC_MII_CTRL_REG 0x044
815 +#define EMAC_MIB_CTRL_STS_REG 0x064
816 +#define EMAC_RCNTRL_REG 0x084
817 +#define EMAC_TCNTRL_REG 0x0C4
818 +#define EMAC_PHY_ADDR_LOW 0x0E4
819 +#define EMAC_PHY_ADDR_HIGH 0x0E8
820 +#define EMAC_GAUR 0x120
821 +#define EMAC_GALR 0x124
822 +#define EMAC_TFWR_STR_FWD 0x144
823 +#define EMAC_RX_SECTION_FULL 0x190
824 +#define EMAC_RX_SECTION_EMPTY 0x194
825 +#define EMAC_TX_SECTION_EMPTY 0x1A0
826 +#define EMAC_TRUNC_FL 0x1B0
828 +#define RMON_T_DROP 0x200 /* Count of frames not cntd correctly */
829 +#define RMON_T_PACKETS 0x204 /* RMON TX packet count */
830 +#define RMON_T_BC_PKT 0x208 /* RMON TX broadcast pkts */
831 +#define RMON_T_MC_PKT 0x20c /* RMON TX multicast pkts */
832 +#define RMON_T_CRC_ALIGN 0x210 /* RMON TX pkts with CRC align err */
833 +#define RMON_T_UNDERSIZE 0x214 /* RMON TX pkts < 64 bytes, good CRC */
834 +#define RMON_T_OVERSIZE 0x218 /* RMON TX pkts > MAX_FL bytes good CRC */
835 +#define RMON_T_FRAG 0x21c /* RMON TX pkts < 64 bytes, bad CRC */
836 +#define RMON_T_JAB 0x220 /* RMON TX pkts > MAX_FL bytes, bad CRC */
837 +#define RMON_T_COL 0x224 /* RMON TX collision count */
838 +#define RMON_T_P64 0x228 /* RMON TX 64 byte pkts */
839 +#define RMON_T_P65TO127 0x22c /* RMON TX 65 to 127 byte pkts */
840 +#define RMON_T_P128TO255 0x230 /* RMON TX 128 to 255 byte pkts */
841 +#define RMON_T_P256TO511 0x234 /* RMON TX 256 to 511 byte pkts */
842 +#define RMON_T_P512TO1023 0x238 /* RMON TX 512 to 1023 byte pkts */
843 +#define RMON_T_P1024TO2047 0x23c /* RMON TX 1024 to 2047 byte pkts */
844 +#define RMON_T_P_GTE2048 0x240 /* RMON TX pkts > 2048 bytes */
845 +#define RMON_T_OCTETS 0x244 /* RMON TX octets */
846 +#define IEEE_T_DROP 0x248 /* Count of frames not counted crtly */
847 +#define IEEE_T_FRAME_OK 0x24c /* Frames tx'd OK */
848 +#define IEEE_T_1COL 0x250 /* Frames tx'd with single collision */
849 +#define IEEE_T_MCOL 0x254 /* Frames tx'd with multiple collision */
850 +#define IEEE_T_DEF 0x258 /* Frames tx'd after deferral delay */
851 +#define IEEE_T_LCOL 0x25c /* Frames tx'd with late collision */
852 +#define IEEE_T_EXCOL 0x260 /* Frames tx'd with excesv collisions */
853 +#define IEEE_T_MACERR 0x264 /* Frames tx'd with TX FIFO underrun */
854 +#define IEEE_T_CSERR 0x268 /* Frames tx'd with carrier sense err */
855 +#define IEEE_T_SQE 0x26c /* Frames tx'd with SQE err */
856 +#define IEEE_T_FDXFC 0x270 /* Flow control pause frames tx'd */
857 +#define IEEE_T_OCTETS_OK 0x274 /* Octet count for frames tx'd w/o err */
858 +#define RMON_R_PACKETS 0x284 /* RMON RX packet count */
859 +#define RMON_R_BC_PKT 0x288 /* RMON RX broadcast pkts */
860 +#define RMON_R_MC_PKT 0x28c /* RMON RX multicast pkts */
861 +#define RMON_R_CRC_ALIGN 0x290 /* RMON RX pkts with CRC alignment err */
862 +#define RMON_R_UNDERSIZE 0x294 /* RMON RX pkts < 64 bytes, good CRC */
863 +#define RMON_R_OVERSIZE 0x298 /* RMON RX pkts > MAX_FL bytes good CRC */
864 +#define RMON_R_FRAG 0x29c /* RMON RX pkts < 64 bytes, bad CRC */
865 +#define RMON_R_JAB 0x2a0 /* RMON RX pkts > MAX_FL bytes, bad CRC */
866 +#define RMON_R_RESVD_O 0x2a4 /* Reserved */
867 +#define RMON_R_P64 0x2a8 /* RMON RX 64 byte pkts */
868 +#define RMON_R_P65TO127 0x2ac /* RMON RX 65 to 127 byte pkts */
869 +#define RMON_R_P128TO255 0x2b0 /* RMON RX 128 to 255 byte pkts */
870 +#define RMON_R_P256TO511 0x2b4 /* RMON RX 256 to 511 byte pkts */
871 +#define RMON_R_P512TO1023 0x2b8 /* RMON RX 512 to 1023 byte pkts */
872 +#define RMON_R_P1024TO2047 0x2bc /* RMON RX 1024 to 2047 byte pkts */
873 +#define RMON_R_P_GTE2048 0x2c0 /* RMON RX pkts > 2048 bytes */
874 +#define RMON_R_OCTETS 0x2c4 /* RMON RX octets */
875 +#define IEEE_R_DROP 0x2c8 /* Count frames not counted correctly */
876 +#define IEEE_R_FRAME_OK 0x2cc /* Frames rx'd OK */
877 +#define IEEE_R_CRC 0x2d0 /* Frames rx'd with CRC err */
878 +#define IEEE_R_ALIGN 0x2d4 /* Frames rx'd with alignment err */
879 +#define IEEE_R_MACERR 0x2d8 /* Receive FIFO overflow count */
880 +#define IEEE_R_FDXFC 0x2dc /* Flow control pause frames rx'd */
881 +#define IEEE_R_OCTETS_OK 0x2e0 /* Octet cnt for frames rx'd w/o err */
883 +#define EMAC_SMAC_0_0 0x500 /*Supplemental MAC Address 0 (RW).*/
884 +#define EMAC_SMAC_0_1 0x504 /*Supplemental MAC Address 0 (RW).*/
886 +/* GEMAC definitions and settings */
888 +#define EMAC_PORT_0 0
889 +#define EMAC_PORT_1 1
891 +/* GEMAC Bit definitions */
892 +#define EMAC_IEVENT_HBERR 0x80000000
893 +#define EMAC_IEVENT_BABR 0x40000000
894 +#define EMAC_IEVENT_BABT 0x20000000
895 +#define EMAC_IEVENT_GRA 0x10000000
896 +#define EMAC_IEVENT_TXF 0x08000000
897 +#define EMAC_IEVENT_TXB 0x04000000
898 +#define EMAC_IEVENT_RXF 0x02000000
899 +#define EMAC_IEVENT_RXB 0x01000000
900 +#define EMAC_IEVENT_MII 0x00800000
901 +#define EMAC_IEVENT_EBERR 0x00400000
902 +#define EMAC_IEVENT_LC 0x00200000
903 +#define EMAC_IEVENT_RL 0x00100000
904 +#define EMAC_IEVENT_UN 0x00080000
906 +#define EMAC_IMASK_HBERR 0x80000000
907 +#define EMAC_IMASK_BABR 0x40000000
908 +#define EMAC_IMASKT_BABT 0x20000000
909 +#define EMAC_IMASK_GRA 0x10000000
910 +#define EMAC_IMASKT_TXF 0x08000000
911 +#define EMAC_IMASK_TXB 0x04000000
912 +#define EMAC_IMASKT_RXF 0x02000000
913 +#define EMAC_IMASK_RXB 0x01000000
914 +#define EMAC_IMASK_MII 0x00800000
915 +#define EMAC_IMASK_EBERR 0x00400000
916 +#define EMAC_IMASK_LC 0x00200000
917 +#define EMAC_IMASKT_RL 0x00100000
918 +#define EMAC_IMASK_UN 0x00080000
920 +#define EMAC_RCNTRL_MAX_FL_SHIFT 16
921 +#define EMAC_RCNTRL_LOOP 0x00000001
922 +#define EMAC_RCNTRL_DRT 0x00000002
923 +#define EMAC_RCNTRL_MII_MODE 0x00000004
924 +#define EMAC_RCNTRL_PROM 0x00000008
925 +#define EMAC_RCNTRL_BC_REJ 0x00000010
926 +#define EMAC_RCNTRL_FCE 0x00000020
927 +#define EMAC_RCNTRL_RGMII 0x00000040
928 +#define EMAC_RCNTRL_SGMII 0x00000080
929 +#define EMAC_RCNTRL_RMII 0x00000100
930 +#define EMAC_RCNTRL_RMII_10T 0x00000200
931 +#define EMAC_RCNTRL_CRC_FWD 0x00004000
933 +#define EMAC_TCNTRL_GTS 0x00000001
934 +#define EMAC_TCNTRL_HBC 0x00000002
935 +#define EMAC_TCNTRL_FDEN 0x00000004
936 +#define EMAC_TCNTRL_TFC_PAUSE 0x00000008
937 +#define EMAC_TCNTRL_RFC_PAUSE 0x00000010
939 +#define EMAC_ECNTRL_RESET 0x00000001 /* reset the EMAC */
940 +#define EMAC_ECNTRL_ETHER_EN 0x00000002 /* enable the EMAC */
941 +#define EMAC_ECNTRL_MAGIC_ENA 0x00000004
942 +#define EMAC_ECNTRL_SLEEP 0x00000008
943 +#define EMAC_ECNTRL_SPEED 0x00000020
944 +#define EMAC_ECNTRL_DBSWAP 0x00000100
946 +#define EMAC_X_WMRK_STRFWD 0x00000100
948 +#define EMAC_X_DES_ACTIVE_TDAR 0x01000000
949 +#define EMAC_R_DES_ACTIVE_RDAR 0x01000000
951 +#define EMAC_RX_SECTION_EMPTY_V 0x00010006
953 + * The possible operating speeds of the MAC, currently supporting 10, 100 and
956 +enum mac_speed {SPEED_10M, SPEED_100M, SPEED_1000M, SPEED_1000M_PCS};
958 +/* MII-related definitios */
959 +#define EMAC_MII_DATA_ST 0x40000000 /* Start of frame delimiter */
960 +#define EMAC_MII_DATA_OP_RD 0x20000000 /* Perform a read operation */
961 +#define EMAC_MII_DATA_OP_CL45_RD 0x30000000 /* Perform a read operation */
962 +#define EMAC_MII_DATA_OP_WR 0x10000000 /* Perform a write operation */
963 +#define EMAC_MII_DATA_OP_CL45_WR 0x10000000 /* Perform a write operation */
964 +#define EMAC_MII_DATA_PA_MSK 0x0f800000 /* PHY Address field mask */
965 +#define EMAC_MII_DATA_RA_MSK 0x007c0000 /* PHY Register field mask */
966 +#define EMAC_MII_DATA_TA 0x00020000 /* Turnaround */
967 +#define EMAC_MII_DATA_DATAMSK 0x0000ffff /* PHY data field */
969 +#define EMAC_MII_DATA_RA_SHIFT 18 /* MII Register address bits */
970 +#define EMAC_MII_DATA_RA_MASK 0x1F /* MII Register address mask */
971 +#define EMAC_MII_DATA_PA_SHIFT 23 /* MII PHY address bits */
972 +#define EMAC_MII_DATA_PA_MASK 0x1F /* MII PHY address mask */
974 +#define EMAC_MII_DATA_RA(v) (((v) & EMAC_MII_DATA_RA_MASK) << \
975 + EMAC_MII_DATA_RA_SHIFT)
976 +#define EMAC_MII_DATA_PA(v) (((v) & EMAC_MII_DATA_RA_MASK) << \
977 + EMAC_MII_DATA_PA_SHIFT)
978 +#define EMAC_MII_DATA(v) ((v) & 0xffff)
980 +#define EMAC_MII_SPEED_SHIFT 1
981 +#define EMAC_HOLDTIME_SHIFT 8
982 +#define EMAC_HOLDTIME_MASK 0x7
983 +#define EMAC_HOLDTIME(v) (((v) & EMAC_HOLDTIME_MASK) << \
984 + EMAC_HOLDTIME_SHIFT)
987 + * The Address organisation for the MAC device. All addresses are split into
988 + * two 32-bit register fields. The first one (bottom) is the lower 32-bits of
989 + * the address and the other field are the high order bits - this may be 16-bits
990 + * in the case of MAC addresses, or 32-bits for the hash address.
991 + * In terms of memory storage, the first item (bottom) is assumed to be at a
992 + * lower address location than 'top'. i.e. top should be at address location of
993 + * 'bottom' + 4 bytes.
995 +struct pfe_mac_addr {
996 + u32 bottom; /* Lower 32-bits of address. */
997 + u32 top; /* Upper 32-bits of address. */
1001 + * The following is the organisation of the address filters section of the MAC
1002 + * registers. The Cadence MAC contains four possible specific address match
1003 + * addresses, if an incoming frame corresponds to any one of these four
1004 + * addresses then the frame will be copied to memory.
1005 + * It is not necessary for all four of the address match registers to be
1006 + * programmed, this is application dependent.
1009 + struct pfe_mac_addr one; /* Specific address register 1. */
1010 + struct pfe_mac_addr two; /* Specific address register 2. */
1011 + struct pfe_mac_addr three; /* Specific address register 3. */
1012 + struct pfe_mac_addr four; /* Specific address register 4. */
1021 +/* EMAC Hash size */
1022 +#define EMAC_HASH_REG_BITS 64
1024 +#define EMAC_SPEC_ADDR_MAX 4
1026 +#endif /* _EMAC_H_ */
1028 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h
1031 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1032 + * Copyright 2017 NXP
1034 + * This program is free software; you can redistribute it and/or modify
1035 + * it under the terms of the GNU General Public License as published by
1036 + * the Free Software Foundation; either version 2 of the License, or
1037 + * (at your option) any later version.
1039 + * This program is distributed in the hope that it will be useful,
1040 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1041 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1042 + * GNU General Public License for more details.
1044 + * You should have received a copy of the GNU General Public License
1045 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1051 +#define GPI_VERSION 0x00
1052 +#define GPI_CTRL 0x04
1053 +#define GPI_RX_CONFIG 0x08
1054 +#define GPI_HDR_SIZE 0x0c
1055 +#define GPI_BUF_SIZE 0x10
1056 +#define GPI_LMEM_ALLOC_ADDR 0x14
1057 +#define GPI_LMEM_FREE_ADDR 0x18
1058 +#define GPI_DDR_ALLOC_ADDR 0x1c
1059 +#define GPI_DDR_FREE_ADDR 0x20
1060 +#define GPI_CLASS_ADDR 0x24
1061 +#define GPI_DRX_FIFO 0x28
1062 +#define GPI_TRX_FIFO 0x2c
1063 +#define GPI_INQ_PKTPTR 0x30
1064 +#define GPI_DDR_DATA_OFFSET 0x34
1065 +#define GPI_LMEM_DATA_OFFSET 0x38
1066 +#define GPI_TMLF_TX 0x4c
1067 +#define GPI_DTX_ASEQ 0x50
1068 +#define GPI_FIFO_STATUS 0x54
1069 +#define GPI_FIFO_DEBUG 0x58
1070 +#define GPI_TX_PAUSE_TIME 0x5c
1071 +#define GPI_LMEM_SEC_BUF_DATA_OFFSET 0x60
1072 +#define GPI_DDR_SEC_BUF_DATA_OFFSET 0x64
1073 +#define GPI_TOE_CHKSUM_EN 0x68
1074 +#define GPI_OVERRUN_DROPCNT 0x6c
1075 +#define GPI_CSR_MTIP_PAUSE_REG 0x74
1076 +#define GPI_CSR_MTIP_PAUSE_QUANTUM 0x78
1077 +#define GPI_CSR_RX_CNT 0x7c
1078 +#define GPI_CSR_TX_CNT 0x80
1079 +#define GPI_CSR_DEBUG1 0x84
1080 +#define GPI_CSR_DEBUG2 0x88
1083 + u32 lmem_rtry_cnt;
1086 + u32 mtip_pause_reg;
1089 +/* GPI commons defines */
1090 +#define GPI_LMEM_BUF_EN 0x1
1091 +#define GPI_DDR_BUF_EN 0x1
1093 +/* EGPI 1 defines */
1094 +#define EGPI1_LMEM_RTRY_CNT 0x40
1095 +#define EGPI1_TMLF_TXTHRES 0xBC
1096 +#define EGPI1_ASEQ_LEN 0x50
1098 +/* EGPI 2 defines */
1099 +#define EGPI2_LMEM_RTRY_CNT 0x40
1100 +#define EGPI2_TMLF_TXTHRES 0xBC
1101 +#define EGPI2_ASEQ_LEN 0x40
1103 +/* EGPI 3 defines */
1104 +#define EGPI3_LMEM_RTRY_CNT 0x40
1105 +#define EGPI3_TMLF_TXTHRES 0xBC
1106 +#define EGPI3_ASEQ_LEN 0x40
1109 +#define HGPI_LMEM_RTRY_CNT 0x40
1110 +#define HGPI_TMLF_TXTHRES 0xBC
1111 +#define HGPI_ASEQ_LEN 0x40
1113 +#define EGPI_PAUSE_TIME 0x000007D0
1114 +#define EGPI_PAUSE_ENABLE 0x40000000
1115 +#endif /* _GPI_H_ */
1117 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h
1120 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1121 + * Copyright 2017 NXP
1123 + * This program is free software; you can redistribute it and/or modify
1124 + * it under the terms of the GNU General Public License as published by
1125 + * the Free Software Foundation; either version 2 of the License, or
1126 + * (at your option) any later version.
1128 + * This program is distributed in the hope that it will be useful,
1129 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1130 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1131 + * GNU General Public License for more details.
1133 + * You should have received a copy of the GNU General Public License
1134 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1141 + * hif - PFE hif block control and status register.
1142 + * Mapped on CBUS and accessible from all PE's and ARM.
1144 +#define HIF_VERSION (HIF_BASE_ADDR + 0x00)
1145 +#define HIF_TX_CTRL (HIF_BASE_ADDR + 0x04)
1146 +#define HIF_TX_CURR_BD_ADDR (HIF_BASE_ADDR + 0x08)
1147 +#define HIF_TX_ALLOC (HIF_BASE_ADDR + 0x0c)
1148 +#define HIF_TX_BDP_ADDR (HIF_BASE_ADDR + 0x10)
1149 +#define HIF_TX_STATUS (HIF_BASE_ADDR + 0x14)
1150 +#define HIF_RX_CTRL (HIF_BASE_ADDR + 0x20)
1151 +#define HIF_RX_BDP_ADDR (HIF_BASE_ADDR + 0x24)
1152 +#define HIF_RX_STATUS (HIF_BASE_ADDR + 0x30)
1153 +#define HIF_INT_SRC (HIF_BASE_ADDR + 0x34)
1154 +#define HIF_INT_ENABLE (HIF_BASE_ADDR + 0x38)
1155 +#define HIF_POLL_CTRL (HIF_BASE_ADDR + 0x3c)
1156 +#define HIF_RX_CURR_BD_ADDR (HIF_BASE_ADDR + 0x40)
1157 +#define HIF_RX_ALLOC (HIF_BASE_ADDR + 0x44)
1158 +#define HIF_TX_DMA_STATUS (HIF_BASE_ADDR + 0x48)
1159 +#define HIF_RX_DMA_STATUS (HIF_BASE_ADDR + 0x4c)
1160 +#define HIF_INT_COAL (HIF_BASE_ADDR + 0x50)
1162 +/* HIF_INT_SRC/ HIF_INT_ENABLE control bits */
1163 +#define HIF_INT BIT(0)
1164 +#define HIF_RXBD_INT BIT(1)
1165 +#define HIF_RXPKT_INT BIT(2)
1166 +#define HIF_TXBD_INT BIT(3)
1167 +#define HIF_TXPKT_INT BIT(4)
1169 +/* HIF_TX_CTRL bits */
1170 +#define HIF_CTRL_DMA_EN BIT(0)
1171 +#define HIF_CTRL_BDP_POLL_CTRL_EN BIT(1)
1172 +#define HIF_CTRL_BDP_CH_START_WSTB BIT(2)
1174 +/* HIF_RX_STATUS bits */
1175 +#define BDP_CSR_RX_DMA_ACTV BIT(16)
1177 +/* HIF_INT_ENABLE bits */
1178 +#define HIF_INT_EN BIT(0)
1179 +#define HIF_RXBD_INT_EN BIT(1)
1180 +#define HIF_RXPKT_INT_EN BIT(2)
1181 +#define HIF_TXBD_INT_EN BIT(3)
1182 +#define HIF_TXPKT_INT_EN BIT(4)
1184 +/* HIF_POLL_CTRL bits*/
1185 +#define HIF_RX_POLL_CTRL_CYCLE 0x0400
1186 +#define HIF_TX_POLL_CTRL_CYCLE 0x0400
1188 +/* HIF_INT_COAL bits*/
1189 +#define HIF_INT_COAL_ENABLE BIT(31)
1191 +/* Buffer descriptor control bits */
1192 +#define BD_CTRL_BUFLEN_MASK 0x3fff
1193 +#define BD_BUF_LEN(x) ((x) & BD_CTRL_BUFLEN_MASK)
1194 +#define BD_CTRL_CBD_INT_EN BIT(16)
1195 +#define BD_CTRL_PKT_INT_EN BIT(17)
1196 +#define BD_CTRL_LIFM BIT(18)
1197 +#define BD_CTRL_LAST_BD BIT(19)
1198 +#define BD_CTRL_DIR BIT(20)
1199 +#define BD_CTRL_LMEM_CPY BIT(21) /* Valid only for HIF_NOCPY */
1200 +#define BD_CTRL_PKT_XFER BIT(24)
1201 +#define BD_CTRL_DESC_EN BIT(31)
1202 +#define BD_CTRL_PARSE_DISABLE BIT(25)
1203 +#define BD_CTRL_BRFETCH_DISABLE BIT(26)
1204 +#define BD_CTRL_RTFETCH_DISABLE BIT(27)
1206 +/* Buffer descriptor status bits*/
1207 +#define BD_STATUS_CONN_ID(x) ((x) & 0xffff)
1208 +#define BD_STATUS_DIR_PROC_ID BIT(16)
1209 +#define BD_STATUS_CONN_ID_EN BIT(17)
1210 +#define BD_STATUS_PE2PROC_ID(x) (((x) & 7) << 18)
1211 +#define BD_STATUS_LE_DATA BIT(21)
1212 +#define BD_STATUS_CHKSUM_EN BIT(22)
1214 +/* HIF Buffer descriptor status bits */
1215 +#define DIR_PROC_ID BIT(16)
1216 +#define PROC_ID(id) ((id) << 18)
1218 +#endif /* _HIF_H_ */
1220 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h
1223 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1224 + * Copyright 2017 NXP
1226 + * This program is free software; you can redistribute it and/or modify
1227 + * it under the terms of the GNU General Public License as published by
1228 + * the Free Software Foundation; either version 2 of the License, or
1229 + * (at your option) any later version.
1231 + * This program is distributed in the hope that it will be useful,
1232 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1233 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1234 + * GNU General Public License for more details.
1236 + * You should have received a copy of the GNU General Public License
1237 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1240 +#ifndef _HIF_NOCPY_H_
1241 +#define _HIF_NOCPY_H_
1243 +#define HIF_NOCPY_VERSION (HIF_NOCPY_BASE_ADDR + 0x00)
1244 +#define HIF_NOCPY_TX_CTRL (HIF_NOCPY_BASE_ADDR + 0x04)
1245 +#define HIF_NOCPY_TX_CURR_BD_ADDR (HIF_NOCPY_BASE_ADDR + 0x08)
1246 +#define HIF_NOCPY_TX_ALLOC (HIF_NOCPY_BASE_ADDR + 0x0c)
1247 +#define HIF_NOCPY_TX_BDP_ADDR (HIF_NOCPY_BASE_ADDR + 0x10)
1248 +#define HIF_NOCPY_TX_STATUS (HIF_NOCPY_BASE_ADDR + 0x14)
1249 +#define HIF_NOCPY_RX_CTRL (HIF_NOCPY_BASE_ADDR + 0x20)
1250 +#define HIF_NOCPY_RX_BDP_ADDR (HIF_NOCPY_BASE_ADDR + 0x24)
1251 +#define HIF_NOCPY_RX_STATUS (HIF_NOCPY_BASE_ADDR + 0x30)
1252 +#define HIF_NOCPY_INT_SRC (HIF_NOCPY_BASE_ADDR + 0x34)
1253 +#define HIF_NOCPY_INT_ENABLE (HIF_NOCPY_BASE_ADDR + 0x38)
1254 +#define HIF_NOCPY_POLL_CTRL (HIF_NOCPY_BASE_ADDR + 0x3c)
1255 +#define HIF_NOCPY_RX_CURR_BD_ADDR (HIF_NOCPY_BASE_ADDR + 0x40)
1256 +#define HIF_NOCPY_RX_ALLOC (HIF_NOCPY_BASE_ADDR + 0x44)
1257 +#define HIF_NOCPY_TX_DMA_STATUS (HIF_NOCPY_BASE_ADDR + 0x48)
1258 +#define HIF_NOCPY_RX_DMA_STATUS (HIF_NOCPY_BASE_ADDR + 0x4c)
1259 +#define HIF_NOCPY_RX_INQ0_PKTPTR (HIF_NOCPY_BASE_ADDR + 0x50)
1260 +#define HIF_NOCPY_RX_INQ1_PKTPTR (HIF_NOCPY_BASE_ADDR + 0x54)
1261 +#define HIF_NOCPY_TX_PORT_NO (HIF_NOCPY_BASE_ADDR + 0x60)
1262 +#define HIF_NOCPY_LMEM_ALLOC_ADDR (HIF_NOCPY_BASE_ADDR + 0x64)
1263 +#define HIF_NOCPY_CLASS_ADDR (HIF_NOCPY_BASE_ADDR + 0x68)
1264 +#define HIF_NOCPY_TMU_PORT0_ADDR (HIF_NOCPY_BASE_ADDR + 0x70)
1265 +#define HIF_NOCPY_TMU_PORT1_ADDR (HIF_NOCPY_BASE_ADDR + 0x74)
1266 +#define HIF_NOCPY_TMU_PORT2_ADDR (HIF_NOCPY_BASE_ADDR + 0x7c)
1267 +#define HIF_NOCPY_TMU_PORT3_ADDR (HIF_NOCPY_BASE_ADDR + 0x80)
1268 +#define HIF_NOCPY_TMU_PORT4_ADDR (HIF_NOCPY_BASE_ADDR + 0x84)
1269 +#define HIF_NOCPY_INT_COAL (HIF_NOCPY_BASE_ADDR + 0x90)
1271 +#endif /* _HIF_NOCPY_H_ */
1273 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h
1276 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1277 + * Copyright 2017 NXP
1279 + * This program is free software; you can redistribute it and/or modify
1280 + * it under the terms of the GNU General Public License as published by
1281 + * the Free Software Foundation; either version 2 of the License, or
1282 + * (at your option) any later version.
1284 + * This program is distributed in the hope that it will be useful,
1285 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1286 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1287 + * GNU General Public License for more details.
1289 + * You should have received a copy of the GNU General Public License
1290 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1293 +#ifndef _TMU_CSR_H_
1294 +#define _TMU_CSR_H_
1296 +#define TMU_VERSION (TMU_CSR_BASE_ADDR + 0x000)
1297 +#define TMU_INQ_WATERMARK (TMU_CSR_BASE_ADDR + 0x004)
1298 +#define TMU_PHY_INQ_PKTPTR (TMU_CSR_BASE_ADDR + 0x008)
1299 +#define TMU_PHY_INQ_PKTINFO (TMU_CSR_BASE_ADDR + 0x00c)
1300 +#define TMU_PHY_INQ_FIFO_CNT (TMU_CSR_BASE_ADDR + 0x010)
1301 +#define TMU_SYS_GENERIC_CONTROL (TMU_CSR_BASE_ADDR + 0x014)
1302 +#define TMU_SYS_GENERIC_STATUS (TMU_CSR_BASE_ADDR + 0x018)
1303 +#define TMU_SYS_GEN_CON0 (TMU_CSR_BASE_ADDR + 0x01c)
1304 +#define TMU_SYS_GEN_CON1 (TMU_CSR_BASE_ADDR + 0x020)
1305 +#define TMU_SYS_GEN_CON2 (TMU_CSR_BASE_ADDR + 0x024)
1306 +#define TMU_SYS_GEN_CON3 (TMU_CSR_BASE_ADDR + 0x028)
1307 +#define TMU_SYS_GEN_CON4 (TMU_CSR_BASE_ADDR + 0x02c)
1308 +#define TMU_TEQ_DISABLE_DROPCHK (TMU_CSR_BASE_ADDR + 0x030)
1309 +#define TMU_TEQ_CTRL (TMU_CSR_BASE_ADDR + 0x034)
1310 +#define TMU_TEQ_QCFG (TMU_CSR_BASE_ADDR + 0x038)
1311 +#define TMU_TEQ_DROP_STAT (TMU_CSR_BASE_ADDR + 0x03c)
1312 +#define TMU_TEQ_QAVG (TMU_CSR_BASE_ADDR + 0x040)
1313 +#define TMU_TEQ_WREG_PROB (TMU_CSR_BASE_ADDR + 0x044)
1314 +#define TMU_TEQ_TRANS_STAT (TMU_CSR_BASE_ADDR + 0x048)
1315 +#define TMU_TEQ_HW_PROB_CFG0 (TMU_CSR_BASE_ADDR + 0x04c)
1316 +#define TMU_TEQ_HW_PROB_CFG1 (TMU_CSR_BASE_ADDR + 0x050)
1317 +#define TMU_TEQ_HW_PROB_CFG2 (TMU_CSR_BASE_ADDR + 0x054)
1318 +#define TMU_TEQ_HW_PROB_CFG3 (TMU_CSR_BASE_ADDR + 0x058)
1319 +#define TMU_TEQ_HW_PROB_CFG4 (TMU_CSR_BASE_ADDR + 0x05c)
1320 +#define TMU_TEQ_HW_PROB_CFG5 (TMU_CSR_BASE_ADDR + 0x060)
1321 +#define TMU_TEQ_HW_PROB_CFG6 (TMU_CSR_BASE_ADDR + 0x064)
1322 +#define TMU_TEQ_HW_PROB_CFG7 (TMU_CSR_BASE_ADDR + 0x068)
1323 +#define TMU_TEQ_HW_PROB_CFG8 (TMU_CSR_BASE_ADDR + 0x06c)
1324 +#define TMU_TEQ_HW_PROB_CFG9 (TMU_CSR_BASE_ADDR + 0x070)
1325 +#define TMU_TEQ_HW_PROB_CFG10 (TMU_CSR_BASE_ADDR + 0x074)
1326 +#define TMU_TEQ_HW_PROB_CFG11 (TMU_CSR_BASE_ADDR + 0x078)
1327 +#define TMU_TEQ_HW_PROB_CFG12 (TMU_CSR_BASE_ADDR + 0x07c)
1328 +#define TMU_TEQ_HW_PROB_CFG13 (TMU_CSR_BASE_ADDR + 0x080)
1329 +#define TMU_TEQ_HW_PROB_CFG14 (TMU_CSR_BASE_ADDR + 0x084)
1330 +#define TMU_TEQ_HW_PROB_CFG15 (TMU_CSR_BASE_ADDR + 0x088)
1331 +#define TMU_TEQ_HW_PROB_CFG16 (TMU_CSR_BASE_ADDR + 0x08c)
1332 +#define TMU_TEQ_HW_PROB_CFG17 (TMU_CSR_BASE_ADDR + 0x090)
1333 +#define TMU_TEQ_HW_PROB_CFG18 (TMU_CSR_BASE_ADDR + 0x094)
1334 +#define TMU_TEQ_HW_PROB_CFG19 (TMU_CSR_BASE_ADDR + 0x098)
1335 +#define TMU_TEQ_HW_PROB_CFG20 (TMU_CSR_BASE_ADDR + 0x09c)
1336 +#define TMU_TEQ_HW_PROB_CFG21 (TMU_CSR_BASE_ADDR + 0x0a0)
1337 +#define TMU_TEQ_HW_PROB_CFG22 (TMU_CSR_BASE_ADDR + 0x0a4)
1338 +#define TMU_TEQ_HW_PROB_CFG23 (TMU_CSR_BASE_ADDR + 0x0a8)
1339 +#define TMU_TEQ_HW_PROB_CFG24 (TMU_CSR_BASE_ADDR + 0x0ac)
1340 +#define TMU_TEQ_HW_PROB_CFG25 (TMU_CSR_BASE_ADDR + 0x0b0)
1341 +#define TMU_TDQ_IIFG_CFG (TMU_CSR_BASE_ADDR + 0x0b4)
1342 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
1343 + * This is a global Enable for all schedulers in PHY0
1345 +#define TMU_TDQ0_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x0b8)
1347 +#define TMU_LLM_CTRL (TMU_CSR_BASE_ADDR + 0x0bc)
1348 +#define TMU_LLM_BASE_ADDR (TMU_CSR_BASE_ADDR + 0x0c0)
1349 +#define TMU_LLM_QUE_LEN (TMU_CSR_BASE_ADDR + 0x0c4)
1350 +#define TMU_LLM_QUE_HEADPTR (TMU_CSR_BASE_ADDR + 0x0c8)
1351 +#define TMU_LLM_QUE_TAILPTR (TMU_CSR_BASE_ADDR + 0x0cc)
1352 +#define TMU_LLM_QUE_DROPCNT (TMU_CSR_BASE_ADDR + 0x0d0)
1353 +#define TMU_INT_EN (TMU_CSR_BASE_ADDR + 0x0d4)
1354 +#define TMU_INT_SRC (TMU_CSR_BASE_ADDR + 0x0d8)
1355 +#define TMU_INQ_STAT (TMU_CSR_BASE_ADDR + 0x0dc)
1356 +#define TMU_CTRL (TMU_CSR_BASE_ADDR + 0x0e0)
1358 +/* [31] Mem Access Command. 0 = Internal Memory Read, 1 = Internal memory
1359 + * Write [27:24] Byte Enables of the Internal memory access [23:0] Address of
1360 + * the internal memory. This address is used to access both the PM and DM of
1363 +#define TMU_MEM_ACCESS_ADDR (TMU_CSR_BASE_ADDR + 0x0e4)
1365 +/* Internal Memory Access Write Data */
1366 +#define TMU_MEM_ACCESS_WDATA (TMU_CSR_BASE_ADDR + 0x0e8)
1367 +/* Internal Memory Access Read Data. The commands are blocked
1368 + * at the mem_access only
1370 +#define TMU_MEM_ACCESS_RDATA (TMU_CSR_BASE_ADDR + 0x0ec)
1372 +/* [31:0] PHY0 in queue address (must be initialized with one of the
1373 + * xxx_INQ_PKTPTR cbus addresses)
1375 +#define TMU_PHY0_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f0)
1376 +/* [31:0] PHY1 in queue address (must be initialized with one of the
1377 + * xxx_INQ_PKTPTR cbus addresses)
1379 +#define TMU_PHY1_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f4)
1380 +/* [31:0] PHY2 in queue address (must be initialized with one of the
1381 + * xxx_INQ_PKTPTR cbus addresses)
1383 +#define TMU_PHY2_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f8)
1384 +/* [31:0] PHY3 in queue address (must be initialized with one of the
1385 + * xxx_INQ_PKTPTR cbus addresses)
1387 +#define TMU_PHY3_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0fc)
1388 +#define TMU_BMU_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x100)
1389 +#define TMU_TX_CTRL (TMU_CSR_BASE_ADDR + 0x104)
1391 +#define TMU_BUS_ACCESS_WDATA (TMU_CSR_BASE_ADDR + 0x108)
1392 +#define TMU_BUS_ACCESS (TMU_CSR_BASE_ADDR + 0x10c)
1393 +#define TMU_BUS_ACCESS_RDATA (TMU_CSR_BASE_ADDR + 0x110)
1395 +#define TMU_PE_SYS_CLK_RATIO (TMU_CSR_BASE_ADDR + 0x114)
1396 +#define TMU_PE_STATUS (TMU_CSR_BASE_ADDR + 0x118)
1397 +#define TMU_TEQ_MAX_THRESHOLD (TMU_CSR_BASE_ADDR + 0x11c)
1398 +/* [31:0] PHY4 in queue address (must be initialized with one of the
1399 + * xxx_INQ_PKTPTR cbus addresses)
1401 +#define TMU_PHY4_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x134)
1402 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
1403 + * This is a global Enable for all schedulers in PHY1
1405 +#define TMU_TDQ1_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x138)
1406 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
1407 + * This is a global Enable for all schedulers in PHY2
1409 +#define TMU_TDQ2_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x13c)
1410 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
1411 + * This is a global Enable for all schedulers in PHY3
1413 +#define TMU_TDQ3_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x140)
1414 +#define TMU_BMU_BUF_SIZE (TMU_CSR_BASE_ADDR + 0x144)
1415 +/* [31:0] PHY5 in queue address (must be initialized with one of the
1416 + * xxx_INQ_PKTPTR cbus addresses)
1418 +#define TMU_PHY5_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x148)
1420 +#define SW_RESET BIT(0) /* Global software reset */
1421 +#define INQ_RESET BIT(2)
1422 +#define TEQ_RESET BIT(3)
1423 +#define TDQ_RESET BIT(4)
1424 +#define PE_RESET BIT(5)
1425 +#define MEM_INIT BIT(6)
1426 +#define MEM_INIT_DONE BIT(7)
1427 +#define LLM_INIT BIT(8)
1428 +#define LLM_INIT_DONE BIT(9)
1429 +#define ECC_MEM_INIT_DONE BIT(10)
1432 + u32 pe_sys_clk_ratio;
1433 + unsigned long llm_base_addr;
1434 + u32 llm_queue_len;
1437 +/* Not HW related for pfe_ctrl / pfe common defines */
1438 +#define DEFAULT_MAX_QDEPTH 80
1439 +#define DEFAULT_Q0_QDEPTH 511 /*We keep one large queue for host tx qos */
1440 +#define DEFAULT_TMU3_QDEPTH 127
1442 +#endif /* _TMU_CSR_H_ */
1444 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h
1447 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1448 + * Copyright 2017 NXP
1450 + * This program is free software; you can redistribute it and/or modify
1451 + * it under the terms of the GNU General Public License as published by
1452 + * the Free Software Foundation; either version 2 of the License, or
1453 + * (at your option) any later version.
1455 + * This program is distributed in the hope that it will be useful,
1456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1458 + * GNU General Public License for more details.
1460 + * You should have received a copy of the GNU General Public License
1461 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1464 +#ifndef _UTIL_CSR_H_
1465 +#define _UTIL_CSR_H_
1467 +#define UTIL_VERSION (UTIL_CSR_BASE_ADDR + 0x000)
1468 +#define UTIL_TX_CTRL (UTIL_CSR_BASE_ADDR + 0x004)
1469 +#define UTIL_INQ_PKTPTR (UTIL_CSR_BASE_ADDR + 0x010)
1471 +#define UTIL_HDR_SIZE (UTIL_CSR_BASE_ADDR + 0x014)
1473 +#define UTIL_PE0_QB_DM_ADDR0 (UTIL_CSR_BASE_ADDR + 0x020)
1474 +#define UTIL_PE0_QB_DM_ADDR1 (UTIL_CSR_BASE_ADDR + 0x024)
1475 +#define UTIL_PE0_RO_DM_ADDR0 (UTIL_CSR_BASE_ADDR + 0x060)
1476 +#define UTIL_PE0_RO_DM_ADDR1 (UTIL_CSR_BASE_ADDR + 0x064)
1478 +#define UTIL_MEM_ACCESS_ADDR (UTIL_CSR_BASE_ADDR + 0x100)
1479 +#define UTIL_MEM_ACCESS_WDATA (UTIL_CSR_BASE_ADDR + 0x104)
1480 +#define UTIL_MEM_ACCESS_RDATA (UTIL_CSR_BASE_ADDR + 0x108)
1482 +#define UTIL_TM_INQ_ADDR (UTIL_CSR_BASE_ADDR + 0x114)
1483 +#define UTIL_PE_STATUS (UTIL_CSR_BASE_ADDR + 0x118)
1485 +#define UTIL_PE_SYS_CLK_RATIO (UTIL_CSR_BASE_ADDR + 0x200)
1486 +#define UTIL_AFULL_THRES (UTIL_CSR_BASE_ADDR + 0x204)
1487 +#define UTIL_GAP_BETWEEN_READS (UTIL_CSR_BASE_ADDR + 0x208)
1488 +#define UTIL_MAX_BUF_CNT (UTIL_CSR_BASE_ADDR + 0x20c)
1489 +#define UTIL_TSQ_FIFO_THRES (UTIL_CSR_BASE_ADDR + 0x210)
1490 +#define UTIL_TSQ_MAX_CNT (UTIL_CSR_BASE_ADDR + 0x214)
1491 +#define UTIL_IRAM_DATA_0 (UTIL_CSR_BASE_ADDR + 0x218)
1492 +#define UTIL_IRAM_DATA_1 (UTIL_CSR_BASE_ADDR + 0x21c)
1493 +#define UTIL_IRAM_DATA_2 (UTIL_CSR_BASE_ADDR + 0x220)
1494 +#define UTIL_IRAM_DATA_3 (UTIL_CSR_BASE_ADDR + 0x224)
1496 +#define UTIL_BUS_ACCESS_ADDR (UTIL_CSR_BASE_ADDR + 0x228)
1497 +#define UTIL_BUS_ACCESS_WDATA (UTIL_CSR_BASE_ADDR + 0x22c)
1498 +#define UTIL_BUS_ACCESS_RDATA (UTIL_CSR_BASE_ADDR + 0x230)
1500 +#define UTIL_INQ_AFULL_THRES (UTIL_CSR_BASE_ADDR + 0x234)
1503 + u32 pe_sys_clk_ratio;
1506 +#endif /* _UTIL_CSR_H_ */
1508 +++ b/drivers/staging/fsl_ppfe/include/pfe/pfe.h
1511 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1512 + * Copyright 2017 NXP
1514 + * This program is free software; you can redistribute it and/or modify
1515 + * it under the terms of the GNU General Public License as published by
1516 + * the Free Software Foundation; either version 2 of the License, or
1517 + * (at your option) any later version.
1519 + * This program is distributed in the hope that it will be useful,
1520 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1521 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1522 + * GNU General Public License for more details.
1524 + * You should have received a copy of the GNU General Public License
1525 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1533 +#define CLASS_DMEM_BASE_ADDR(i) (0x00000000 | ((i) << 20))
1535 + * Only valid for mem access register interface
1537 +#define CLASS_IMEM_BASE_ADDR(i) (0x00000000 | ((i) << 20))
1538 +#define CLASS_DMEM_SIZE 0x00002000
1539 +#define CLASS_IMEM_SIZE 0x00008000
1541 +#define TMU_DMEM_BASE_ADDR(i) (0x00000000 + ((i) << 20))
1543 + * Only valid for mem access register interface
1545 +#define TMU_IMEM_BASE_ADDR(i) (0x00000000 + ((i) << 20))
1546 +#define TMU_DMEM_SIZE 0x00000800
1547 +#define TMU_IMEM_SIZE 0x00002000
1549 +#define UTIL_DMEM_BASE_ADDR 0x00000000
1550 +#define UTIL_DMEM_SIZE 0x00002000
1552 +#define PE_LMEM_BASE_ADDR 0xc3010000
1553 +#define PE_LMEM_SIZE 0x8000
1554 +#define PE_LMEM_END (PE_LMEM_BASE_ADDR + PE_LMEM_SIZE)
1556 +#define DMEM_BASE_ADDR 0x00000000
1557 +#define DMEM_SIZE 0x2000 /* TMU has less... */
1558 +#define DMEM_END (DMEM_BASE_ADDR + DMEM_SIZE)
1560 +#define PMEM_BASE_ADDR 0x00010000
1561 +#define PMEM_SIZE 0x8000 /* TMU has less... */
1562 +#define PMEM_END (PMEM_BASE_ADDR + PMEM_SIZE)
1564 +/* These check memory ranges from PE point of view/memory map */
1565 +#define IS_DMEM(addr, len) \
1566 + ({ typeof(addr) addr_ = (addr); \
1567 + ((unsigned long)(addr_) >= DMEM_BASE_ADDR) && \
1568 + (((unsigned long)(addr_) + (len)) <= DMEM_END); })
1570 +#define IS_PMEM(addr, len) \
1571 + ({ typeof(addr) addr_ = (addr); \
1572 + ((unsigned long)(addr_) >= PMEM_BASE_ADDR) && \
1573 + (((unsigned long)(addr_) + (len)) <= PMEM_END); })
1575 +#define IS_PE_LMEM(addr, len) \
1576 + ({ typeof(addr) addr_ = (addr); \
1577 + ((unsigned long)(addr_) >= \
1578 + PE_LMEM_BASE_ADDR) && \
1579 + (((unsigned long)(addr_) + \
1580 + (len)) <= PE_LMEM_END); })
1582 +#define IS_PFE_LMEM(addr, len) \
1583 + ({ typeof(addr) addr_ = (addr); \
1584 + ((unsigned long)(addr_) >= \
1585 + CBUS_VIRT_TO_PFE(LMEM_BASE_ADDR)) && \
1586 + (((unsigned long)(addr_) + (len)) <= \
1587 + CBUS_VIRT_TO_PFE(LMEM_END)); })
1589 +#define __IS_PHYS_DDR(addr, len) \
1590 + ({ typeof(addr) addr_ = (addr); \
1591 + ((unsigned long)(addr_) >= \
1592 + DDR_PHYS_BASE_ADDR) && \
1593 + (((unsigned long)(addr_) + (len)) <= \
1596 +#define IS_PHYS_DDR(addr, len) __IS_PHYS_DDR(DDR_PFE_TO_PHYS(addr), len)
1599 + * If using a run-time virtual address for the cbus base address use this code
1601 +extern void *cbus_base_addr;
1602 +extern void *ddr_base_addr;
1603 +extern unsigned long ddr_phys_base_addr;
1604 +extern unsigned int ddr_size;
1606 +#define CBUS_BASE_ADDR cbus_base_addr
1607 +#define DDR_PHYS_BASE_ADDR ddr_phys_base_addr
1608 +#define DDR_BASE_ADDR ddr_base_addr
1609 +#define DDR_SIZE ddr_size
1611 +#define DDR_PHYS_END (DDR_PHYS_BASE_ADDR + DDR_SIZE)
1613 +#define LS1012A_PFE_RESET_WA /*
1614 + * PFE doesn't have global reset and re-init
1615 + * should takecare few things to make PFE
1616 + * functional after reset
1618 +#define PFE_CBUS_PHYS_BASE_ADDR 0xc0000000 /* CBUS physical base address
1619 + * as seen by PE's.
1621 +/* CBUS physical base address as seen by PE's. */
1622 +#define PFE_CBUS_PHYS_BASE_ADDR_FROM_PFE 0xc0000000
1624 +#define DDR_PHYS_TO_PFE(p) (((unsigned long int)(p)) & 0x7FFFFFFF)
1625 +#define DDR_PFE_TO_PHYS(p) (((unsigned long int)(p)) | 0x80000000)
1626 +#define CBUS_PHYS_TO_PFE(p) (((p) - PFE_CBUS_PHYS_BASE_ADDR) + \
1627 + PFE_CBUS_PHYS_BASE_ADDR_FROM_PFE)
1628 +/* Translates to PFE address map */
1630 +#define DDR_PHYS_TO_VIRT(p) (((p) - DDR_PHYS_BASE_ADDR) + DDR_BASE_ADDR)
1631 +#define DDR_VIRT_TO_PHYS(v) (((v) - DDR_BASE_ADDR) + DDR_PHYS_BASE_ADDR)
1632 +#define DDR_VIRT_TO_PFE(p) (DDR_PHYS_TO_PFE(DDR_VIRT_TO_PHYS(p)))
1634 +#define CBUS_VIRT_TO_PFE(v) (((v) - CBUS_BASE_ADDR) + \
1635 + PFE_CBUS_PHYS_BASE_ADDR)
1636 +#define CBUS_PFE_TO_VIRT(p) (((unsigned long int)(p) - \
1637 + PFE_CBUS_PHYS_BASE_ADDR) + CBUS_BASE_ADDR)
1639 +/* The below part of the code is used in QOS control driver from host */
1640 +#define TMU_APB_BASE_ADDR 0xc1000000 /* TMU base address seen by
1655 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
1661 +#define CLASS_MASK (BIT(CLASS0_ID) | BIT(CLASS1_ID) |\
1662 + BIT(CLASS2_ID) | BIT(CLASS3_ID) |\
1663 + BIT(CLASS4_ID) | BIT(CLASS5_ID))
1664 +#define CLASS_MAX_ID CLASS5_ID
1666 +#define TMU_MASK (BIT(TMU0_ID) | BIT(TMU1_ID) |\
1669 +#define TMU_MAX_ID TMU3_ID
1671 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
1672 +#define UTIL_MASK BIT(UTIL_ID)
1677 + u32 activity_counter;
1684 +#if defined(CFG_PE_DEBUG)
1685 + u32 debug_indicator;
1690 +struct pe_sync_mailbox {
1695 +/* Drop counter definitions */
1697 +#define CLASS_NUM_DROP_COUNTERS 13
1698 +#define UTIL_NUM_DROP_COUNTERS 8
1701 + * Structure containing PE's specific information. It is used to create
1702 + * generic C functions common to all PE's.
1703 + * Before using the library functions this structure needs to be initialized
1704 + * with the different registers virtual addresses
1705 + * (according to the ARM MMU mmaping). The default initialization supports a
1706 + * virtual == physical mapping.
1709 + u32 dmem_base_addr; /* PE's dmem base address */
1710 + u32 pmem_base_addr; /* PE's pmem base address */
1711 + u32 pmem_size; /* PE's pmem size */
1713 + void *mem_access_wdata; /* PE's _MEM_ACCESS_WDATA register
1716 + void *mem_access_addr; /* PE's _MEM_ACCESS_ADDR register
1719 + void *mem_access_rdata; /* PE's _MEM_ACCESS_RDATA register
1724 +void pe_lmem_read(u32 *dst, u32 len, u32 offset);
1725 +void pe_lmem_write(u32 *src, u32 len, u32 offset);
1727 +void pe_dmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len);
1728 +void pe_pmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len);
1730 +u32 pe_pmem_read(int id, u32 addr, u8 size);
1732 +void pe_dmem_write(int id, u32 val, u32 addr, u8 size);
1733 +u32 pe_dmem_read(int id, u32 addr, u8 size);
1734 +void class_pe_lmem_memcpy_to32(u32 dst, const void *src, unsigned int len);
1735 +void class_pe_lmem_memset(u32 dst, int val, unsigned int len);
1736 +void class_bus_write(u32 val, u32 addr, u8 size);
1737 +u32 class_bus_read(u32 addr, u8 size);
1739 +#define class_bus_readl(addr) class_bus_read(addr, 4)
1740 +#define class_bus_readw(addr) class_bus_read(addr, 2)
1741 +#define class_bus_readb(addr) class_bus_read(addr, 1)
1743 +#define class_bus_writel(val, addr) class_bus_write(val, addr, 4)
1744 +#define class_bus_writew(val, addr) class_bus_write(val, addr, 2)
1745 +#define class_bus_writeb(val, addr) class_bus_write(val, addr, 1)
1747 +#define pe_dmem_readl(id, addr) pe_dmem_read(id, addr, 4)
1748 +#define pe_dmem_readw(id, addr) pe_dmem_read(id, addr, 2)
1749 +#define pe_dmem_readb(id, addr) pe_dmem_read(id, addr, 1)
1751 +#define pe_dmem_writel(id, val, addr) pe_dmem_write(id, val, addr, 4)
1752 +#define pe_dmem_writew(id, val, addr) pe_dmem_write(id, val, addr, 2)
1753 +#define pe_dmem_writeb(id, val, addr) pe_dmem_write(id, val, addr, 1)
1755 +/*int pe_load_elf_section(int id, const void *data, elf32_shdr *shdr); */
1756 +int pe_load_elf_section(int id, const void *data, struct elf32_shdr *shdr,
1757 + struct device *dev);
1759 +void pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
1760 + unsigned int ddr_size);
1761 +void bmu_init(void *base, struct BMU_CFG *cfg);
1762 +void bmu_reset(void *base);
1763 +void bmu_enable(void *base);
1764 +void bmu_disable(void *base);
1765 +void bmu_set_config(void *base, struct BMU_CFG *cfg);
1768 + * An enumerated type for loopback values. This can be one of three values, no
1769 + * loopback -normal operation, local loopback with internal loopback module of
1770 + * MAC or PHY loopback which is through the external PHY.
1772 +#ifndef __MAC_LOOP_ENUM__
1773 +#define __MAC_LOOP_ENUM__
1774 +enum mac_loop {LB_NONE, LB_EXT, LB_LOCAL};
1777 +void gemac_init(void *base, void *config);
1778 +void gemac_disable_rx_checksum_offload(void *base);
1779 +void gemac_enable_rx_checksum_offload(void *base);
1780 +void gemac_set_speed(void *base, enum mac_speed gem_speed);
1781 +void gemac_set_duplex(void *base, int duplex);
1782 +void gemac_set_mode(void *base, int mode);
1783 +void gemac_enable(void *base);
1784 +void gemac_tx_disable(void *base);
1785 +void gemac_tx_enable(void *base);
1786 +void gemac_disable(void *base);
1787 +void gemac_reset(void *base);
1788 +void gemac_set_address(void *base, struct spec_addr *addr);
1789 +struct spec_addr gemac_get_address(void *base);
1790 +void gemac_set_loop(void *base, enum mac_loop gem_loop);
1791 +void gemac_set_laddr1(void *base, struct pfe_mac_addr *address);
1792 +void gemac_set_laddr2(void *base, struct pfe_mac_addr *address);
1793 +void gemac_set_laddr3(void *base, struct pfe_mac_addr *address);
1794 +void gemac_set_laddr4(void *base, struct pfe_mac_addr *address);
1795 +void gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
1796 + unsigned int entry_index);
1797 +void gemac_clear_laddr1(void *base);
1798 +void gemac_clear_laddr2(void *base);
1799 +void gemac_clear_laddr3(void *base);
1800 +void gemac_clear_laddr4(void *base);
1801 +void gemac_clear_laddrN(void *base, unsigned int entry_index);
1802 +struct pfe_mac_addr gemac_get_hash(void *base);
1803 +void gemac_set_hash(void *base, struct pfe_mac_addr *hash);
1804 +struct pfe_mac_addr gem_get_laddr1(void *base);
1805 +struct pfe_mac_addr gem_get_laddr2(void *base);
1806 +struct pfe_mac_addr gem_get_laddr3(void *base);
1807 +struct pfe_mac_addr gem_get_laddr4(void *base);
1808 +struct pfe_mac_addr gem_get_laddrN(void *base, unsigned int entry_index);
1809 +void gemac_set_config(void *base, struct gemac_cfg *cfg);
1810 +void gemac_allow_broadcast(void *base);
1811 +void gemac_no_broadcast(void *base);
1812 +void gemac_enable_1536_rx(void *base);
1813 +void gemac_disable_1536_rx(void *base);
1814 +void gemac_set_rx_max_fl(void *base, int mtu);
1815 +void gemac_enable_rx_jmb(void *base);
1816 +void gemac_disable_rx_jmb(void *base);
1817 +void gemac_enable_stacked_vlan(void *base);
1818 +void gemac_disable_stacked_vlan(void *base);
1819 +void gemac_enable_pause_rx(void *base);
1820 +void gemac_disable_pause_rx(void *base);
1821 +void gemac_enable_copy_all(void *base);
1822 +void gemac_disable_copy_all(void *base);
1823 +void gemac_set_bus_width(void *base, int width);
1824 +void gemac_set_wol(void *base, u32 wol_conf);
1826 +void gpi_init(void *base, struct gpi_cfg *cfg);
1827 +void gpi_reset(void *base);
1828 +void gpi_enable(void *base);
1829 +void gpi_disable(void *base);
1830 +void gpi_set_config(void *base, struct gpi_cfg *cfg);
1832 +void class_init(struct class_cfg *cfg);
1833 +void class_reset(void);
1834 +void class_enable(void);
1835 +void class_disable(void);
1836 +void class_set_config(struct class_cfg *cfg);
1838 +void tmu_reset(void);
1839 +void tmu_init(struct tmu_cfg *cfg);
1840 +void tmu_enable(u32 pe_mask);
1841 +void tmu_disable(u32 pe_mask);
1842 +u32 tmu_qstatus(u32 if_id);
1843 +u32 tmu_pkts_processed(u32 if_id);
1845 +void util_init(struct util_cfg *cfg);
1846 +void util_reset(void);
1847 +void util_enable(void);
1848 +void util_disable(void);
1850 +void hif_init(void);
1851 +void hif_tx_enable(void);
1852 +void hif_tx_disable(void);
1853 +void hif_rx_enable(void);
1854 +void hif_rx_disable(void);
1856 +/* Get Chip Revision level
1859 +static inline unsigned int CHIP_REVISION(void)
1861 + /*For LS1012A return always 1 */
1865 +/* Start HIF rx DMA
1868 +static inline void hif_rx_dma_start(void)
1870 + writel(HIF_CTRL_DMA_EN | HIF_CTRL_BDP_CH_START_WSTB, HIF_RX_CTRL);
1873 +/* Start HIF tx DMA
1876 +static inline void hif_tx_dma_start(void)
1878 + writel(HIF_CTRL_DMA_EN | HIF_CTRL_BDP_CH_START_WSTB, HIF_TX_CTRL);
1881 +#endif /* _PFE_H_ */
1883 +++ b/drivers/staging/fsl_ppfe/pfe_cdev.c
1885 +// SPDX-License-Identifier: GPL-2.0+
1887 + * Copyright 2018 NXP
1891 + * Dummy device representing the PFE US in userspace.
1892 + * - used for interacting with the kernel layer for link status
1895 +#include <linux/eventfd.h>
1896 +#include <linux/irqreturn.h>
1897 +#include <linux/io.h>
1898 +#include <asm/irq.h>
1900 +#include "pfe_cdev.h"
1901 +#include "pfe_mod.h"
1903 +static int pfe_majno;
1904 +static struct class *pfe_char_class;
1905 +static struct device *pfe_char_dev;
1906 +struct eventfd_ctx *g_trigger;
1908 +struct pfe_shared_info link_states[PFE_CDEV_ETH_COUNT];
1910 +static int pfe_cdev_open(struct inode *inp, struct file *fp)
1912 + pr_debug("PFE CDEV device opened.\n");
1916 +static ssize_t pfe_cdev_read(struct file *fp, char *buf,
1917 + size_t len, loff_t *off)
1921 + pr_info("PFE CDEV attempt copying (%lu) size of user.\n",
1922 + sizeof(link_states));
1924 + pr_debug("Dump link_state on screen before copy_to_user\n");
1925 + for (; ret < PFE_CDEV_ETH_COUNT; ret++) {
1926 + pr_debug("%u %u", link_states[ret].phy_id,
1927 + link_states[ret].state);
1931 + /* Copy to user the value in buffer sized len */
1932 + ret = copy_to_user(buf, &link_states, sizeof(link_states));
1934 + pr_err("Failed to send (%d)bytes of (%lu) requested.\n",
1939 + /* offset set back to 0 as there is contextual reading offset */
1941 + pr_debug("Read of (%lu) bytes performed.\n", sizeof(link_states));
1943 + return sizeof(link_states);
1947 + * This function is for getting some commands from user through non-IOCTL
1948 + * channel. It can used to configure the device.
1949 + * TODO: To be filled in future, if require duplex communication with user
1952 +static ssize_t pfe_cdev_write(struct file *fp, const char *buf,
1953 + size_t len, loff_t *off)
1955 + pr_info("PFE CDEV Write operation not supported!\n");
1960 +static int pfe_cdev_release(struct inode *inp, struct file *fp)
1963 + free_irq(pfe->hif_irq, g_trigger);
1964 + eventfd_ctx_put(g_trigger);
1968 + pr_info("PFE_CDEV: Device successfully closed\n");
1974 + * This ISR routine processes Rx/Tx done interrupts from the HIF hardware block
1976 +static irqreturn_t hif_us_isr(int irq, void *arg)
1978 + struct eventfd_ctx *trigger = (struct eventfd_ctx *)arg;
1980 + int int_enable_mask;
1982 + /*Read hif interrupt source register */
1983 + int_status = readl_relaxed(HIF_INT_SRC);
1984 + int_enable_mask = readl_relaxed(HIF_INT_ENABLE);
1986 + if ((int_status & HIF_INT) == 0)
1989 + if (int_status & HIF_RXPKT_INT) {
1990 + int_enable_mask &= ~(HIF_RXPKT_INT);
1991 + /* Disable interrupts, they will be enabled after
1992 + * they are serviced
1994 + writel_relaxed(int_enable_mask, HIF_INT_ENABLE);
1996 + eventfd_signal(trigger, 1);
1999 + return IRQ_HANDLED;
2002 +#define PFE_INTR_COAL_USECS 100
2003 +static long pfe_cdev_ioctl(struct file *fp, unsigned int cmd,
2004 + unsigned long arg)
2006 + int ret = -EFAULT;
2007 + int __user *argp = (int __user *)arg;
2009 + pr_debug("PFE CDEV IOCTL Called with cmd=(%u)\n", cmd);
2012 + case PFE_CDEV_ETH0_STATE_GET:
2013 + /* Return an unsigned int (link state) for ETH0 */
2014 + *argp = link_states[0].state;
2015 + pr_debug("Returning state=%d for ETH0\n", *argp);
2018 + case PFE_CDEV_ETH1_STATE_GET:
2019 + /* Return an unsigned int (link state) for ETH0 */
2020 + *argp = link_states[1].state;
2021 + pr_debug("Returning state=%d for ETH1\n", *argp);
2024 + case PFE_CDEV_HIF_INTR_EN:
2025 + /* Return success/failure */
2026 + g_trigger = eventfd_ctx_fdget(*argp);
2027 + if (IS_ERR(g_trigger))
2028 + return PTR_ERR(g_trigger);
2029 + ret = request_irq(pfe->hif_irq, hif_us_isr, 0, "pfe_hif",
2032 + pr_err("%s: failed to get the hif IRQ = %d\n",
2033 + __func__, pfe->hif_irq);
2034 + eventfd_ctx_put(g_trigger);
2037 + writel((PFE_INTR_COAL_USECS * (pfe->ctrl.sys_clk / 1000)) |
2038 + HIF_INT_COAL_ENABLE, HIF_INT_COAL);
2040 + pr_debug("request_irq for hif interrupt: %d\n", pfe->hif_irq);
2044 + pr_info("Unsupport cmd (%d) for PFE CDEV.\n", cmd);
2051 +static unsigned int pfe_cdev_poll(struct file *fp,
2052 + struct poll_table_struct *wait)
2054 + pr_info("PFE CDEV poll method not supported\n");
2058 +static const struct file_operations pfe_cdev_fops = {
2059 + .open = pfe_cdev_open,
2060 + .read = pfe_cdev_read,
2061 + .write = pfe_cdev_write,
2062 + .release = pfe_cdev_release,
2063 + .unlocked_ioctl = pfe_cdev_ioctl,
2064 + .poll = pfe_cdev_poll,
2067 +int pfe_cdev_init(void)
2071 + pr_debug("PFE CDEV initialization begin\n");
2073 + /* Register the major number for the device */
2074 + pfe_majno = register_chrdev(0, PFE_CDEV_NAME, &pfe_cdev_fops);
2075 + if (pfe_majno < 0) {
2076 + pr_err("Unable to register PFE CDEV. PFE CDEV not available\n");
2081 + pr_debug("PFE CDEV assigned major number: %d\n", pfe_majno);
2083 + /* Register the class for the device */
2084 + pfe_char_class = class_create(THIS_MODULE, PFE_CLASS_NAME);
2085 + if (IS_ERR(pfe_char_class)) {
2087 + "Failed to init class for PFE CDEV. PFE CDEV not available.\n");
2091 + pr_debug("PFE CDEV Class created successfully.\n");
2093 + /* Create the device without any parent and without any callback data */
2094 + pfe_char_dev = device_create(pfe_char_class, NULL,
2095 + MKDEV(pfe_majno, 0), NULL,
2097 + if (IS_ERR(pfe_char_dev)) {
2098 + pr_err("Unable to PFE CDEV device. PFE CDEV not available.\n");
2099 + ret = PTR_ERR(pfe_char_dev);
2103 + /* Information structure being shared with the userspace */
2104 + memset(link_states, 0, sizeof(struct pfe_shared_info) *
2105 + PFE_CDEV_ETH_COUNT);
2107 + pr_info("PFE CDEV created: %s\n", PFE_CDEV_NAME);
2113 + if (!IS_ERR(pfe_char_class))
2114 + class_destroy(pfe_char_class);
2116 + if (pfe_majno > 0)
2117 + unregister_chrdev(pfe_majno, PFE_CDEV_NAME);
2123 +void pfe_cdev_exit(void)
2125 + if (!IS_ERR(pfe_char_dev))
2126 + device_destroy(pfe_char_class, MKDEV(pfe_majno, 0));
2128 + if (!IS_ERR(pfe_char_class)) {
2129 + class_unregister(pfe_char_class);
2130 + class_destroy(pfe_char_class);
2133 + if (pfe_majno > 0)
2134 + unregister_chrdev(pfe_majno, PFE_CDEV_NAME);
2136 + /* reset the variables */
2138 + pfe_char_class = NULL;
2139 + pfe_char_dev = NULL;
2141 + pr_info("PFE CDEV Removed.\n");
2144 +++ b/drivers/staging/fsl_ppfe/pfe_cdev.h
2146 +/* SPDX-License-Identifier: GPL-2.0+ */
2148 + * Copyright 2018 NXP
2151 +#ifndef _PFE_CDEV_H_
2152 +#define _PFE_CDEV_H_
2154 +#include <linux/init.h>
2155 +#include <linux/device.h>
2156 +#include <linux/err.h>
2157 +#include <linux/kernel.h>
2158 +#include <linux/fs.h>
2159 +#include <linux/uaccess.h>
2160 +#include <linux/poll.h>
2162 +#define PFE_CDEV_NAME "pfe_us_cdev"
2163 +#define PFE_CLASS_NAME "ppfe_us"
2165 +/* Extracted from ls1012a_pfe_platform_data, there are 3 interfaces which are
2166 + * supported by PFE driver. Should be updated if number of eth devices are
2169 +#define PFE_CDEV_ETH_COUNT 3
2171 +struct pfe_shared_info {
2172 + uint32_t phy_id; /* Link phy ID */
2173 + uint8_t state; /* Has either 0 or 1 */
2176 +extern struct pfe_shared_info link_states[PFE_CDEV_ETH_COUNT];
2178 +/* IOCTL Commands */
2179 +#define PFE_CDEV_ETH0_STATE_GET _IOR('R', 0, int)
2180 +#define PFE_CDEV_ETH1_STATE_GET _IOR('R', 1, int)
2181 +#define PFE_CDEV_HIF_INTR_EN _IOWR('R', 2, int)
2183 +int pfe_cdev_init(void);
2184 +void pfe_cdev_exit(void);
2186 +#endif /* _PFE_CDEV_H_ */
2188 +++ b/drivers/staging/fsl_ppfe/pfe_ctrl.c
2190 +// SPDX-License-Identifier: GPL-2.0+
2192 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2193 + * Copyright 2017 NXP
2196 +#include <linux/kernel.h>
2197 +#include <linux/sched.h>
2198 +#include <linux/module.h>
2199 +#include <linux/list.h>
2200 +#include <linux/kthread.h>
2202 +#include "pfe_mod.h"
2203 +#include "pfe_ctrl.h"
2205 +#define TIMEOUT_MS 1000
2207 +int relax(unsigned long end)
2209 + if (time_after(jiffies, end)) {
2210 + if (time_after(jiffies, end + (TIMEOUT_MS * HZ) / 1000))
2213 + if (need_resched())
2220 +void pfe_ctrl_suspend(struct pfe_ctrl *ctrl)
2224 + mutex_lock(&ctrl->mutex);
2226 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++)
2227 + pe_dmem_write(id, cpu_to_be32(0x1), CLASS_DM_RESUME, 4);
2229 + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
2230 + if (id == TMU2_ID)
2232 + pe_dmem_write(id, cpu_to_be32(0x1), TMU_DM_RESUME, 4);
2235 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2236 + pe_dmem_write(UTIL_ID, cpu_to_be32(0x1), UTIL_DM_RESUME, 4);
2238 + mutex_unlock(&ctrl->mutex);
2241 +void pfe_ctrl_resume(struct pfe_ctrl *ctrl)
2243 + int pe_mask = CLASS_MASK | TMU_MASK;
2245 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2246 + pe_mask |= UTIL_MASK;
2248 + mutex_lock(&ctrl->mutex);
2249 + pe_start(&pfe->ctrl, pe_mask);
2250 + mutex_unlock(&ctrl->mutex);
2254 + * Stops packet processing for a list of PE's (specified using a bitmask).
2255 + * The caller must hold ctrl->mutex.
2257 + * @param ctrl Control context
2258 + * @param pe_mask Mask of PE id's to stop
2261 +int pe_sync_stop(struct pfe_ctrl *ctrl, int pe_mask)
2263 + struct pe_sync_mailbox *mbox;
2264 + int pe_stopped = 0;
2265 + unsigned long end = jiffies + 2;
2268 + pe_mask &= 0x2FF; /*Exclude Util + TMU2 */
2270 + for (i = 0; i < MAX_PE; i++)
2271 + if (pe_mask & (1 << i)) {
2272 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2274 + pe_dmem_write(i, cpu_to_be32(0x1), (unsigned
2275 + long)&mbox->stop, 4);
2278 + while (pe_stopped != pe_mask) {
2279 + for (i = 0; i < MAX_PE; i++)
2280 + if ((pe_mask & (1 << i)) && !(pe_stopped & (1 << i))) {
2281 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2283 + if (pe_dmem_read(i, (unsigned
2284 + long)&mbox->stopped, 4) &
2286 + pe_stopped |= (1 << i);
2289 + if (relax(end) < 0)
2296 + pr_err("%s: timeout, %x %x\n", __func__, pe_mask, pe_stopped);
2298 + for (i = 0; i < MAX_PE; i++)
2299 + if (pe_mask & (1 << i)) {
2300 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2302 + pe_dmem_write(i, cpu_to_be32(0x0), (unsigned
2303 + long)&mbox->stop, 4);
2310 + * Starts packet processing for a list of PE's (specified using a bitmask).
2311 + * The caller must hold ctrl->mutex.
2313 + * @param ctrl Control context
2314 + * @param pe_mask Mask of PE id's to start
2317 +void pe_start(struct pfe_ctrl *ctrl, int pe_mask)
2319 + struct pe_sync_mailbox *mbox;
2322 + for (i = 0; i < MAX_PE; i++)
2323 + if (pe_mask & (1 << i)) {
2324 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2326 + pe_dmem_write(i, cpu_to_be32(0x0), (unsigned
2327 + long)&mbox->stop, 4);
2331 +/* This function will ensure all PEs are put in to idle state */
2332 +int pe_reset_all(struct pfe_ctrl *ctrl)
2334 + struct pe_sync_mailbox *mbox;
2335 + int pe_stopped = 0;
2336 + unsigned long end = jiffies + 2;
2338 + int pe_mask = CLASS_MASK | TMU_MASK;
2340 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2341 + pe_mask |= UTIL_MASK;
2344 + for (i = 0; i < MAX_PE; i++)
2345 + if (pe_mask & (1 << i)) {
2346 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2348 + pe_dmem_write(i, cpu_to_be32(0x2), (unsigned
2349 + long)&mbox->stop, 4);
2352 + while (pe_stopped != pe_mask) {
2353 + for (i = 0; i < MAX_PE; i++)
2354 + if ((pe_mask & (1 << i)) && !(pe_stopped & (1 << i))) {
2355 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2357 + if (pe_dmem_read(i, (unsigned long)
2358 + &mbox->stopped, 4) &
2360 + pe_stopped |= (1 << i);
2363 + if (relax(end) < 0)
2370 + pr_err("%s: timeout, %x %x\n", __func__, pe_mask, pe_stopped);
2374 +int pfe_ctrl_init(struct pfe *pfe)
2376 + struct pfe_ctrl *ctrl = &pfe->ctrl;
2379 + pr_info("%s\n", __func__);
2381 + mutex_init(&ctrl->mutex);
2382 + spin_lock_init(&ctrl->lock);
2384 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
2385 + ctrl->sync_mailbox_baseaddr[id] = CLASS_DM_SYNC_MBOX;
2386 + ctrl->msg_mailbox_baseaddr[id] = CLASS_DM_MSG_MBOX;
2389 + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
2390 + if (id == TMU2_ID)
2392 + ctrl->sync_mailbox_baseaddr[id] = TMU_DM_SYNC_MBOX;
2393 + ctrl->msg_mailbox_baseaddr[id] = TMU_DM_MSG_MBOX;
2396 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2397 + ctrl->sync_mailbox_baseaddr[UTIL_ID] = UTIL_DM_SYNC_MBOX;
2398 + ctrl->msg_mailbox_baseaddr[UTIL_ID] = UTIL_DM_MSG_MBOX;
2401 + ctrl->hash_array_baseaddr = pfe->ddr_baseaddr + ROUTE_TABLE_BASEADDR;
2402 + ctrl->hash_array_phys_baseaddr = pfe->ddr_phys_baseaddr +
2403 + ROUTE_TABLE_BASEADDR;
2405 + ctrl->dev = pfe->dev;
2407 + pr_info("%s finished\n", __func__);
2412 +void pfe_ctrl_exit(struct pfe *pfe)
2414 + pr_info("%s\n", __func__);
2417 +++ b/drivers/staging/fsl_ppfe/pfe_ctrl.h
2419 +/* SPDX-License-Identifier: GPL-2.0+ */
2421 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2422 + * Copyright 2017 NXP
2425 +#ifndef _PFE_CTRL_H_
2426 +#define _PFE_CTRL_H_
2428 +#include <linux/dmapool.h>
2430 +#include "pfe_mod.h"
2431 +#include "pfe/pfe.h"
2433 +#define DMA_BUF_SIZE_128 0x80 /* enough for 1 conntracks */
2434 +#define DMA_BUF_SIZE_256 0x100
2435 +/* enough for 2 conntracks, 1 bridge entry or 1 multicast entry */
2436 +#define DMA_BUF_SIZE_512 0x200
2437 +/* 512bytes dma allocated buffers used by rtp relay feature */
2438 +#define DMA_BUF_MIN_ALIGNMENT 8
2439 +#define DMA_BUF_BOUNDARY (4 * 1024)
2440 +/* bursts can not cross 4k boundary */
2442 +#define CMD_TX_ENABLE 0x0501
2443 +#define CMD_TX_DISABLE 0x0502
2445 +#define CMD_RX_LRO 0x0011
2446 +#define CMD_PKTCAP_ENABLE 0x0d01
2447 +#define CMD_QM_EXPT_RATE 0x020c
2449 +#define CLASS_DM_SH_STATIC (0x800)
2450 +#define CLASS_DM_CPU_TICKS (CLASS_DM_SH_STATIC)
2451 +#define CLASS_DM_SYNC_MBOX (0x808)
2452 +#define CLASS_DM_MSG_MBOX (0x810)
2453 +#define CLASS_DM_DROP_CNTR (0x820)
2454 +#define CLASS_DM_RESUME (0x854)
2455 +#define CLASS_DM_PESTATUS (0x860)
2457 +#define TMU_DM_SH_STATIC (0x80)
2458 +#define TMU_DM_CPU_TICKS (TMU_DM_SH_STATIC)
2459 +#define TMU_DM_SYNC_MBOX (0x88)
2460 +#define TMU_DM_MSG_MBOX (0x90)
2461 +#define TMU_DM_RESUME (0xA0)
2462 +#define TMU_DM_PESTATUS (0xB0)
2463 +#define TMU_DM_CONTEXT (0x300)
2464 +#define TMU_DM_TX_TRANS (0x480)
2466 +#define UTIL_DM_SH_STATIC (0x0)
2467 +#define UTIL_DM_CPU_TICKS (UTIL_DM_SH_STATIC)
2468 +#define UTIL_DM_SYNC_MBOX (0x8)
2469 +#define UTIL_DM_MSG_MBOX (0x10)
2470 +#define UTIL_DM_DROP_CNTR (0x20)
2471 +#define UTIL_DM_RESUME (0x40)
2472 +#define UTIL_DM_PESTATUS (0x50)
2475 + struct mutex mutex; /* to serialize pfe control access */
2479 + void *dma_pool_512;
2480 + void *dma_pool_128;
2482 + struct device *dev;
2484 + void *hash_array_baseaddr; /*
2485 + * Virtual base address of
2486 + * the conntrack hash array
2488 + unsigned long hash_array_phys_baseaddr; /*
2489 + * Physical base address of
2490 + * the conntrack hash array
2493 + int (*event_cb)(u16, u16, u16*);
2495 + unsigned long sync_mailbox_baseaddr[MAX_PE]; /*
2496 + * Sync mailbox PFE
2497 + * internal address,
2499 + * when parsing elf images
2501 + unsigned long msg_mailbox_baseaddr[MAX_PE]; /*
2502 + * Msg mailbox PFE internal
2503 + * address, initialized
2504 + * when parsing elf images
2506 + unsigned int sys_clk; /* AXI clock value, in KHz */
2509 +int pfe_ctrl_init(struct pfe *pfe);
2510 +void pfe_ctrl_exit(struct pfe *pfe);
2511 +int pe_sync_stop(struct pfe_ctrl *ctrl, int pe_mask);
2512 +void pe_start(struct pfe_ctrl *ctrl, int pe_mask);
2513 +int pe_reset_all(struct pfe_ctrl *ctrl);
2514 +void pfe_ctrl_suspend(struct pfe_ctrl *ctrl);
2515 +void pfe_ctrl_resume(struct pfe_ctrl *ctrl);
2516 +int relax(unsigned long end);
2518 +#endif /* _PFE_CTRL_H_ */
2520 +++ b/drivers/staging/fsl_ppfe/pfe_debugfs.c
2522 +// SPDX-License-Identifier: GPL-2.0+
2524 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2525 + * Copyright 2017 NXP
2528 +#include <linux/module.h>
2529 +#include <linux/debugfs.h>
2530 +#include <linux/platform_device.h>
2532 +#include "pfe_mod.h"
2534 +static int dmem_show(struct seq_file *s, void *unused)
2536 + u32 dmem_addr, val;
2537 + int id = (long int)s->private;
2540 + for (dmem_addr = 0; dmem_addr < CLASS_DMEM_SIZE; dmem_addr += 8 * 4) {
2541 + seq_printf(s, "%04x:", dmem_addr);
2543 + for (i = 0; i < 8; i++) {
2544 + val = pe_dmem_read(id, dmem_addr + i * 4, 4);
2545 + seq_printf(s, " %02x %02x %02x %02x", val & 0xff,
2546 + (val >> 8) & 0xff, (val >> 16) & 0xff,
2547 + (val >> 24) & 0xff);
2550 + seq_puts(s, "\n");
2556 +static int dmem_open(struct inode *inode, struct file *file)
2558 + return single_open(file, dmem_show, inode->i_private);
2561 +static const struct file_operations dmem_fops = {
2562 + .open = dmem_open,
2564 + .llseek = seq_lseek,
2565 + .release = single_release,
2568 +int pfe_debugfs_init(struct pfe *pfe)
2572 + pr_info("%s\n", __func__);
2574 + pfe->dentry = debugfs_create_dir("pfe", NULL);
2575 + if (IS_ERR_OR_NULL(pfe->dentry))
2578 + d = debugfs_create_file("pe0_dmem", 0444, pfe->dentry, (void *)0,
2580 + if (IS_ERR_OR_NULL(d))
2583 + d = debugfs_create_file("pe1_dmem", 0444, pfe->dentry, (void *)1,
2585 + if (IS_ERR_OR_NULL(d))
2588 + d = debugfs_create_file("pe2_dmem", 0444, pfe->dentry, (void *)2,
2590 + if (IS_ERR_OR_NULL(d))
2593 + d = debugfs_create_file("pe3_dmem", 0444, pfe->dentry, (void *)3,
2595 + if (IS_ERR_OR_NULL(d))
2598 + d = debugfs_create_file("pe4_dmem", 0444, pfe->dentry, (void *)4,
2600 + if (IS_ERR_OR_NULL(d))
2603 + d = debugfs_create_file("pe5_dmem", 0444, pfe->dentry, (void *)5,
2605 + if (IS_ERR_OR_NULL(d))
2611 + debugfs_remove_recursive(pfe->dentry);
2617 +void pfe_debugfs_exit(struct pfe *pfe)
2619 + debugfs_remove_recursive(pfe->dentry);
2622 +++ b/drivers/staging/fsl_ppfe/pfe_debugfs.h
2624 +/* SPDX-License-Identifier: GPL-2.0+ */
2626 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2627 + * Copyright 2017 NXP
2630 +#ifndef _PFE_DEBUGFS_H_
2631 +#define _PFE_DEBUGFS_H_
2633 +int pfe_debugfs_init(struct pfe *pfe);
2634 +void pfe_debugfs_exit(struct pfe *pfe);
2636 +#endif /* _PFE_DEBUGFS_H_ */
2638 +++ b/drivers/staging/fsl_ppfe/pfe_eth.c
2640 +// SPDX-License-Identifier: GPL-2.0+
2642 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2643 + * Copyright 2017 NXP
2647 + * Ethernet driver for to handle exception path for PFE.
2648 + * - uses HIF functions to send/receive packets.
2649 + * - uses ctrl function to start/stop interfaces.
2650 + * - uses direct register accesses to control phy operation.
2652 +#include <linux/version.h>
2653 +#include <linux/kernel.h>
2654 +#include <linux/interrupt.h>
2655 +#include <linux/dma-mapping.h>
2656 +#include <linux/dmapool.h>
2657 +#include <linux/netdevice.h>
2658 +#include <linux/etherdevice.h>
2659 +#include <linux/ethtool.h>
2660 +#include <linux/mii.h>
2661 +#include <linux/phy.h>
2662 +#include <linux/timer.h>
2663 +#include <linux/hrtimer.h>
2664 +#include <linux/platform_device.h>
2666 +#include <net/ip.h>
2667 +#include <net/sock.h>
2669 +#include <linux/of.h>
2670 +#include <linux/of_mdio.h>
2672 +#include <linux/io.h>
2673 +#include <asm/irq.h>
2674 +#include <linux/delay.h>
2675 +#include <linux/regmap.h>
2676 +#include <linux/i2c.h>
2677 +#include <linux/fsl/guts.h>
2679 +#if defined(CONFIG_NF_CONNTRACK_MARK)
2680 +#include <net/netfilter/nf_conntrack.h>
2683 +#include "pfe_mod.h"
2684 +#include "pfe_eth.h"
2685 +#include "pfe_cdev.h"
2687 +#define LS1012A_REV_1_0 0x87040010
2689 +bool pfe_use_old_dts_phy;
2690 +bool pfe_errata_a010897;
2692 +static void *cbus_emac_base[3];
2693 +static void *cbus_gpi_base[3];
2695 +/* Forward Declaration */
2696 +static void pfe_eth_exit_one(struct pfe_eth_priv_s *priv);
2697 +static void pfe_eth_flush_tx(struct pfe_eth_priv_s *priv);
2698 +static void pfe_eth_flush_txQ(struct pfe_eth_priv_s *priv, int tx_q_num, int
2699 + from_tx, int n_desc);
2701 +/* MDIO registers */
2702 +#define MDIO_SGMII_CR 0x00
2703 +#define MDIO_SGMII_SR 0x01
2704 +#define MDIO_SGMII_DEV_ABIL_SGMII 0x04
2705 +#define MDIO_SGMII_LINK_TMR_L 0x12
2706 +#define MDIO_SGMII_LINK_TMR_H 0x13
2707 +#define MDIO_SGMII_IF_MODE 0x14
2709 +/* SGMII Control defines */
2710 +#define SGMII_CR_RST 0x8000
2711 +#define SGMII_CR_AN_EN 0x1000
2712 +#define SGMII_CR_RESTART_AN 0x0200
2713 +#define SGMII_CR_FD 0x0100
2714 +#define SGMII_CR_SPEED_SEL1_1G 0x0040
2715 +#define SGMII_CR_DEF_VAL (SGMII_CR_AN_EN | SGMII_CR_FD | \
2716 + SGMII_CR_SPEED_SEL1_1G)
2718 +/* SGMII IF Mode */
2719 +#define SGMII_DUPLEX_HALF 0x10
2720 +#define SGMII_SPEED_10MBPS 0x00
2721 +#define SGMII_SPEED_100MBPS 0x04
2722 +#define SGMII_SPEED_1GBPS 0x08
2723 +#define SGMII_USE_SGMII_AN 0x02
2724 +#define SGMII_EN 0x01
2726 +/* SGMII Device Ability for SGMII */
2727 +#define SGMII_DEV_ABIL_ACK 0x4000
2728 +#define SGMII_DEV_ABIL_EEE_CLK_STP_EN 0x0100
2729 +#define SGMII_DEV_ABIL_SGMII 0x0001
2731 +unsigned int gemac_regs[] = {
2732 + 0x0004, /* Interrupt event */
2733 + 0x0008, /* Interrupt mask */
2734 + 0x0024, /* Ethernet control */
2735 + 0x0064, /* MIB Control/Status */
2736 + 0x0084, /* Receive control/status */
2737 + 0x00C4, /* Transmit control */
2738 + 0x00E4, /* Physical address low */
2739 + 0x00E8, /* Physical address high */
2740 + 0x0144, /* Transmit FIFO Watermark and Store and Forward Control*/
2741 + 0x0190, /* Receive FIFO Section Full Threshold */
2742 + 0x01A0, /* Transmit FIFO Section Empty Threshold */
2743 + 0x01B0, /* Frame Truncation Length */
2746 +/********************************************************************/
2747 +/* SYSFS INTERFACE */
2748 +/********************************************************************/
2750 +#ifdef PFE_ETH_NAPI_STATS
2752 + * pfe_eth_show_napi_stats
2754 +static ssize_t pfe_eth_show_napi_stats(struct device *dev,
2755 + struct device_attribute *attr,
2758 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
2761 + len += sprintf(buf + len, "sched: %u\n",
2762 + priv->napi_counters[NAPI_SCHED_COUNT]);
2763 + len += sprintf(buf + len, "poll: %u\n",
2764 + priv->napi_counters[NAPI_POLL_COUNT]);
2765 + len += sprintf(buf + len, "packet: %u\n",
2766 + priv->napi_counters[NAPI_PACKET_COUNT]);
2767 + len += sprintf(buf + len, "budget: %u\n",
2768 + priv->napi_counters[NAPI_FULL_BUDGET_COUNT]);
2769 + len += sprintf(buf + len, "desc: %u\n",
2770 + priv->napi_counters[NAPI_DESC_COUNT]);
2776 + * pfe_eth_set_napi_stats
2778 +static ssize_t pfe_eth_set_napi_stats(struct device *dev,
2779 + struct device_attribute *attr,
2780 + const char *buf, size_t count)
2782 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
2784 + memset(priv->napi_counters, 0, sizeof(priv->napi_counters));
2789 +#ifdef PFE_ETH_TX_STATS
2790 +/* pfe_eth_show_tx_stats
2793 +static ssize_t pfe_eth_show_tx_stats(struct device *dev,
2794 + struct device_attribute *attr,
2797 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
2801 + len += sprintf(buf + len, "TX queues stats:\n");
2803 + for (i = 0; i < emac_txq_cnt; i++) {
2804 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
2807 + len += sprintf(buf + len, "\n");
2808 + __netif_tx_lock_bh(tx_queue);
2810 + hif_tx_lock(&pfe->hif);
2811 + len += sprintf(buf + len,
2812 + "Queue %2d : credits = %10d\n"
2813 + , i, hif_lib_tx_credit_avail(pfe, priv->id, i));
2814 + len += sprintf(buf + len,
2815 + " tx packets = %10d\n"
2816 + , pfe->tmu_credit.tx_packets[priv->id][i]);
2817 + hif_tx_unlock(&pfe->hif);
2819 + /* Don't output additionnal stats if queue never used */
2820 + if (!pfe->tmu_credit.tx_packets[priv->id][i])
2823 + len += sprintf(buf + len,
2824 + " clean_fail = %10d\n"
2825 + , priv->clean_fail[i]);
2826 + len += sprintf(buf + len,
2827 + " stop_queue = %10d\n"
2828 + , priv->stop_queue_total[i]);
2829 + len += sprintf(buf + len,
2830 + " stop_queue_hif = %10d\n"
2831 + , priv->stop_queue_hif[i]);
2832 + len += sprintf(buf + len,
2833 + " stop_queue_hif_client = %10d\n"
2834 + , priv->stop_queue_hif_client[i]);
2835 + len += sprintf(buf + len,
2836 + " stop_queue_credit = %10d\n"
2837 + , priv->stop_queue_credit[i]);
2839 + __netif_tx_unlock_bh(tx_queue);
2844 +/* pfe_eth_set_tx_stats
2847 +static ssize_t pfe_eth_set_tx_stats(struct device *dev,
2848 + struct device_attribute *attr,
2849 + const char *buf, size_t count)
2851 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
2854 + for (i = 0; i < emac_txq_cnt; i++) {
2855 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
2858 + __netif_tx_lock_bh(tx_queue);
2859 + priv->clean_fail[i] = 0;
2860 + priv->stop_queue_total[i] = 0;
2861 + priv->stop_queue_hif[i] = 0;
2862 + priv->stop_queue_hif_client[i] = 0;
2863 + priv->stop_queue_credit[i] = 0;
2864 + __netif_tx_unlock_bh(tx_queue);
2870 +/* pfe_eth_show_txavail
2873 +static ssize_t pfe_eth_show_txavail(struct device *dev,
2874 + struct device_attribute *attr,
2877 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
2881 + for (i = 0; i < emac_txq_cnt; i++) {
2882 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
2885 + __netif_tx_lock_bh(tx_queue);
2887 + len += sprintf(buf + len, "%d",
2888 + hif_lib_tx_avail(&priv->client, i));
2890 + __netif_tx_unlock_bh(tx_queue);
2892 + if (i == (emac_txq_cnt - 1))
2893 + len += sprintf(buf + len, "\n");
2895 + len += sprintf(buf + len, " ");
2901 +/* pfe_eth_show_default_priority
2904 +static ssize_t pfe_eth_show_default_priority(struct device *dev,
2905 + struct device_attribute *attr,
2908 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
2909 + unsigned long flags;
2912 + spin_lock_irqsave(&priv->lock, flags);
2913 + rc = sprintf(buf, "%d\n", priv->default_priority);
2914 + spin_unlock_irqrestore(&priv->lock, flags);
2919 +/* pfe_eth_set_default_priority
2923 +static ssize_t pfe_eth_set_default_priority(struct device *dev,
2924 + struct device_attribute *attr,
2925 + const char *buf, size_t count)
2927 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
2928 + unsigned long flags;
2930 + spin_lock_irqsave(&priv->lock, flags);
2931 + priv->default_priority = kstrtoul(buf, 0, 0);
2932 + spin_unlock_irqrestore(&priv->lock, flags);
2937 +static DEVICE_ATTR(txavail, 0444, pfe_eth_show_txavail, NULL);
2938 +static DEVICE_ATTR(default_priority, 0644, pfe_eth_show_default_priority,
2939 + pfe_eth_set_default_priority);
2941 +#ifdef PFE_ETH_NAPI_STATS
2942 +static DEVICE_ATTR(napi_stats, 0644, pfe_eth_show_napi_stats,
2943 + pfe_eth_set_napi_stats);
2946 +#ifdef PFE_ETH_TX_STATS
2947 +static DEVICE_ATTR(tx_stats, 0644, pfe_eth_show_tx_stats,
2948 + pfe_eth_set_tx_stats);
2952 + * pfe_eth_sysfs_init
2955 +static int pfe_eth_sysfs_init(struct net_device *ndev)
2957 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
2960 + /* Initialize the default values */
2963 + * By default, packets without conntrack will use this default low
2966 + priv->default_priority = 0;
2968 + /* Create our sysfs files */
2969 + err = device_create_file(&ndev->dev, &dev_attr_default_priority);
2972 + "failed to create default_priority sysfs files\n");
2973 + goto err_priority;
2976 + err = device_create_file(&ndev->dev, &dev_attr_txavail);
2979 + "failed to create default_priority sysfs files\n");
2983 +#ifdef PFE_ETH_NAPI_STATS
2984 + err = device_create_file(&ndev->dev, &dev_attr_napi_stats);
2986 + netdev_err(ndev, "failed to create napi stats sysfs files\n");
2991 +#ifdef PFE_ETH_TX_STATS
2992 + err = device_create_file(&ndev->dev, &dev_attr_tx_stats);
2994 + netdev_err(ndev, "failed to create tx stats sysfs files\n");
3001 +#ifdef PFE_ETH_TX_STATS
3004 +#ifdef PFE_ETH_NAPI_STATS
3005 + device_remove_file(&ndev->dev, &dev_attr_napi_stats);
3009 + device_remove_file(&ndev->dev, &dev_attr_txavail);
3012 + device_remove_file(&ndev->dev, &dev_attr_default_priority);
3018 +/* pfe_eth_sysfs_exit
3021 +void pfe_eth_sysfs_exit(struct net_device *ndev)
3023 +#ifdef PFE_ETH_TX_STATS
3024 + device_remove_file(&ndev->dev, &dev_attr_tx_stats);
3027 +#ifdef PFE_ETH_NAPI_STATS
3028 + device_remove_file(&ndev->dev, &dev_attr_napi_stats);
3030 + device_remove_file(&ndev->dev, &dev_attr_txavail);
3031 + device_remove_file(&ndev->dev, &dev_attr_default_priority);
3034 +/*************************************************************************/
3035 +/* ETHTOOL INTERCAE */
3036 +/*************************************************************************/
3039 +static const struct fec_stat {
3040 + char name[ETH_GSTRING_LEN];
3044 + { "tx_dropped", RMON_T_DROP },
3045 + { "tx_packets", RMON_T_PACKETS },
3046 + { "tx_broadcast", RMON_T_BC_PKT },
3047 + { "tx_multicast", RMON_T_MC_PKT },
3048 + { "tx_crc_errors", RMON_T_CRC_ALIGN },
3049 + { "tx_undersize", RMON_T_UNDERSIZE },
3050 + { "tx_oversize", RMON_T_OVERSIZE },
3051 + { "tx_fragment", RMON_T_FRAG },
3052 + { "tx_jabber", RMON_T_JAB },
3053 + { "tx_collision", RMON_T_COL },
3054 + { "tx_64byte", RMON_T_P64 },
3055 + { "tx_65to127byte", RMON_T_P65TO127 },
3056 + { "tx_128to255byte", RMON_T_P128TO255 },
3057 + { "tx_256to511byte", RMON_T_P256TO511 },
3058 + { "tx_512to1023byte", RMON_T_P512TO1023 },
3059 + { "tx_1024to2047byte", RMON_T_P1024TO2047 },
3060 + { "tx_GTE2048byte", RMON_T_P_GTE2048 },
3061 + { "tx_octets", RMON_T_OCTETS },
3064 + { "IEEE_tx_drop", IEEE_T_DROP },
3065 + { "IEEE_tx_frame_ok", IEEE_T_FRAME_OK },
3066 + { "IEEE_tx_1col", IEEE_T_1COL },
3067 + { "IEEE_tx_mcol", IEEE_T_MCOL },
3068 + { "IEEE_tx_def", IEEE_T_DEF },
3069 + { "IEEE_tx_lcol", IEEE_T_LCOL },
3070 + { "IEEE_tx_excol", IEEE_T_EXCOL },
3071 + { "IEEE_tx_macerr", IEEE_T_MACERR },
3072 + { "IEEE_tx_cserr", IEEE_T_CSERR },
3073 + { "IEEE_tx_sqe", IEEE_T_SQE },
3074 + { "IEEE_tx_fdxfc", IEEE_T_FDXFC },
3075 + { "IEEE_tx_octets_ok", IEEE_T_OCTETS_OK },
3078 + { "rx_packets", RMON_R_PACKETS },
3079 + { "rx_broadcast", RMON_R_BC_PKT },
3080 + { "rx_multicast", RMON_R_MC_PKT },
3081 + { "rx_crc_errors", RMON_R_CRC_ALIGN },
3082 + { "rx_undersize", RMON_R_UNDERSIZE },
3083 + { "rx_oversize", RMON_R_OVERSIZE },
3084 + { "rx_fragment", RMON_R_FRAG },
3085 + { "rx_jabber", RMON_R_JAB },
3086 + { "rx_64byte", RMON_R_P64 },
3087 + { "rx_65to127byte", RMON_R_P65TO127 },
3088 + { "rx_128to255byte", RMON_R_P128TO255 },
3089 + { "rx_256to511byte", RMON_R_P256TO511 },
3090 + { "rx_512to1023byte", RMON_R_P512TO1023 },
3091 + { "rx_1024to2047byte", RMON_R_P1024TO2047 },
3092 + { "rx_GTE2048byte", RMON_R_P_GTE2048 },
3093 + { "rx_octets", RMON_R_OCTETS },
3096 + { "IEEE_rx_drop", IEEE_R_DROP },
3097 + { "IEEE_rx_frame_ok", IEEE_R_FRAME_OK },
3098 + { "IEEE_rx_crc", IEEE_R_CRC },
3099 + { "IEEE_rx_align", IEEE_R_ALIGN },
3100 + { "IEEE_rx_macerr", IEEE_R_MACERR },
3101 + { "IEEE_rx_fdxfc", IEEE_R_FDXFC },
3102 + { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK },
3105 +static void pfe_eth_fill_stats(struct net_device *ndev, struct ethtool_stats
3106 + *stats, u64 *data)
3108 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3111 + for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
3112 + data[i] = readl(priv->EMAC_baseaddr + fec_stats[i].offset);
3115 +static void pfe_eth_gstrings(struct net_device *netdev,
3116 + u32 stringset, u8 *data)
3120 + switch (stringset) {
3121 + case ETH_SS_STATS:
3122 + for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
3123 + memcpy(data + i * ETH_GSTRING_LEN,
3124 + fec_stats[i].name, ETH_GSTRING_LEN);
3129 +static int pfe_eth_stats_count(struct net_device *ndev, int sset)
3132 + case ETH_SS_STATS:
3133 + return ARRAY_SIZE(fec_stats);
3135 + return -EOPNOTSUPP;
3140 + * pfe_eth_gemac_reglen - Return the length of the register structure.
3143 +static int pfe_eth_gemac_reglen(struct net_device *ndev)
3145 + pr_info("%s()\n", __func__);
3146 + return (sizeof(gemac_regs) / sizeof(u32));
3150 + * pfe_eth_gemac_get_regs - Return the gemac register structure.
3153 +static void pfe_eth_gemac_get_regs(struct net_device *ndev, struct ethtool_regs
3154 + *regs, void *regbuf)
3158 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3159 + u32 *buf = (u32 *)regbuf;
3161 + pr_info("%s()\n", __func__);
3162 + for (i = 0; i < sizeof(gemac_regs) / sizeof(u32); i++)
3163 + buf[i] = readl(priv->EMAC_baseaddr + gemac_regs[i]);
3167 + * pfe_eth_set_wol - Set the magic packet option, in WoL register.
3170 +static int pfe_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
3172 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3174 + if (wol->wolopts & ~WAKE_MAGIC)
3175 + return -EOPNOTSUPP;
3177 + /* for MTIP we store wol->wolopts */
3178 + priv->wol = wol->wolopts;
3180 + device_set_wakeup_enable(&ndev->dev, wol->wolopts & WAKE_MAGIC);
3187 + * pfe_eth_get_wol - Get the WoL options.
3190 +static void pfe_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo
3193 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3195 + wol->supported = WAKE_MAGIC;
3198 + if (priv->wol & WAKE_MAGIC)
3199 + wol->wolopts = WAKE_MAGIC;
3201 + memset(&wol->sopass, 0, sizeof(wol->sopass));
3205 + * pfe_eth_get_drvinfo - Fills in the drvinfo structure with some basic info
3208 +static void pfe_eth_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo
3211 + strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
3212 + strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
3213 + strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
3214 + strlcpy(drvinfo->bus_info, "N/A", sizeof(drvinfo->bus_info));
3218 + * pfe_eth_set_settings - Used to send commands to PHY.
3221 +static int pfe_eth_set_settings(struct net_device *ndev,
3222 + const struct ethtool_link_ksettings *cmd)
3224 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3225 + struct phy_device *phydev = priv->phydev;
3230 + return phy_ethtool_ksettings_set(phydev, cmd);
3234 + * pfe_eth_getsettings - Return the current settings in the ethtool_cmd
3238 +static int pfe_eth_get_settings(struct net_device *ndev,
3239 + struct ethtool_link_ksettings *cmd)
3241 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3242 + struct phy_device *phydev = priv->phydev;
3247 + phy_ethtool_ksettings_get(phydev, cmd);
3253 + * pfe_eth_get_msglevel - Gets the debug message mask.
3256 +static uint32_t pfe_eth_get_msglevel(struct net_device *ndev)
3258 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3260 + return priv->msg_enable;
3264 + * pfe_eth_set_msglevel - Sets the debug message mask.
3267 +static void pfe_eth_set_msglevel(struct net_device *ndev, uint32_t data)
3269 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3271 + priv->msg_enable = data;
3274 +#define HIF_RX_COAL_MAX_CLKS (~(1 << 31))
3275 +#define HIF_RX_COAL_CLKS_PER_USEC (pfe->ctrl.sys_clk / 1000)
3276 +#define HIF_RX_COAL_MAX_USECS (HIF_RX_COAL_MAX_CLKS / \
3277 + HIF_RX_COAL_CLKS_PER_USEC)
3280 + * pfe_eth_set_coalesce - Sets rx interrupt coalescing timer.
3283 +static int pfe_eth_set_coalesce(struct net_device *ndev,
3284 + struct ethtool_coalesce *ec)
3286 + if (ec->rx_coalesce_usecs > HIF_RX_COAL_MAX_USECS)
3289 + if (!ec->rx_coalesce_usecs) {
3290 + writel(0, HIF_INT_COAL);
3294 + writel((ec->rx_coalesce_usecs * HIF_RX_COAL_CLKS_PER_USEC) |
3295 + HIF_INT_COAL_ENABLE, HIF_INT_COAL);
3301 + * pfe_eth_get_coalesce - Gets rx interrupt coalescing timer value.
3304 +static int pfe_eth_get_coalesce(struct net_device *ndev,
3305 + struct ethtool_coalesce *ec)
3307 + int reg_val = readl(HIF_INT_COAL);
3309 + if (reg_val & HIF_INT_COAL_ENABLE)
3310 + ec->rx_coalesce_usecs = (reg_val & HIF_RX_COAL_MAX_CLKS) /
3311 + HIF_RX_COAL_CLKS_PER_USEC;
3313 + ec->rx_coalesce_usecs = 0;
3319 + * pfe_eth_set_pauseparam - Sets pause parameters
3322 +static int pfe_eth_set_pauseparam(struct net_device *ndev,
3323 + struct ethtool_pauseparam *epause)
3325 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3327 + if (epause->tx_pause != epause->rx_pause) {
3329 + "hardware only support enable/disable both tx and rx\n");
3333 + priv->pause_flag = 0;
3334 + priv->pause_flag |= epause->rx_pause ? PFE_PAUSE_FLAG_ENABLE : 0;
3335 + priv->pause_flag |= epause->autoneg ? PFE_PAUSE_FLAG_AUTONEG : 0;
3337 + if (epause->rx_pause || epause->autoneg) {
3338 + gemac_enable_pause_rx(priv->EMAC_baseaddr);
3339 + writel((readl(priv->GPI_baseaddr + GPI_TX_PAUSE_TIME) |
3340 + EGPI_PAUSE_ENABLE),
3341 + priv->GPI_baseaddr + GPI_TX_PAUSE_TIME);
3342 + if (priv->phydev) {
3343 + priv->phydev->supported |= ADVERTISED_Pause |
3344 + ADVERTISED_Asym_Pause;
3345 + priv->phydev->advertising |= ADVERTISED_Pause |
3346 + ADVERTISED_Asym_Pause;
3349 + gemac_disable_pause_rx(priv->EMAC_baseaddr);
3350 + writel((readl(priv->GPI_baseaddr + GPI_TX_PAUSE_TIME) &
3351 + ~EGPI_PAUSE_ENABLE),
3352 + priv->GPI_baseaddr + GPI_TX_PAUSE_TIME);
3353 + if (priv->phydev) {
3354 + priv->phydev->supported &= ~(ADVERTISED_Pause |
3355 + ADVERTISED_Asym_Pause);
3356 + priv->phydev->advertising &= ~(ADVERTISED_Pause |
3357 + ADVERTISED_Asym_Pause);
3365 + * pfe_eth_get_pauseparam - Gets pause parameters
3368 +static void pfe_eth_get_pauseparam(struct net_device *ndev,
3369 + struct ethtool_pauseparam *epause)
3371 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3373 + epause->autoneg = (priv->pause_flag & PFE_PAUSE_FLAG_AUTONEG) != 0;
3374 + epause->tx_pause = (priv->pause_flag & PFE_PAUSE_FLAG_ENABLE) != 0;
3375 + epause->rx_pause = epause->tx_pause;
3379 + * pfe_eth_get_hash
3381 +#define PFE_HASH_BITS 6 /* #bits in hash */
3382 +#define CRC32_POLY 0xEDB88320
3384 +static int pfe_eth_get_hash(u8 *addr)
3386 + unsigned int i, bit, data, crc, hash;
3388 + /* calculate crc32 value of mac address */
3391 + for (i = 0; i < 6; i++) {
3393 + for (bit = 0; bit < 8; bit++, data >>= 1) {
3394 + crc = (crc >> 1) ^
3395 + (((crc ^ data) & 1) ? CRC32_POLY : 0);
3400 + * only upper 6 bits (PFE_HASH_BITS) are used
3401 + * which point to specific bit in the hash registers
3403 + hash = (crc >> (32 - PFE_HASH_BITS)) & 0x3f;
3408 +const struct ethtool_ops pfe_ethtool_ops = {
3409 + .get_drvinfo = pfe_eth_get_drvinfo,
3410 + .get_regs_len = pfe_eth_gemac_reglen,
3411 + .get_regs = pfe_eth_gemac_get_regs,
3412 + .get_link = ethtool_op_get_link,
3413 + .get_wol = pfe_eth_get_wol,
3414 + .set_wol = pfe_eth_set_wol,
3415 + .set_pauseparam = pfe_eth_set_pauseparam,
3416 + .get_pauseparam = pfe_eth_get_pauseparam,
3417 + .get_strings = pfe_eth_gstrings,
3418 + .get_sset_count = pfe_eth_stats_count,
3419 + .get_ethtool_stats = pfe_eth_fill_stats,
3420 + .get_msglevel = pfe_eth_get_msglevel,
3421 + .set_msglevel = pfe_eth_set_msglevel,
3422 + .set_coalesce = pfe_eth_set_coalesce,
3423 + .get_coalesce = pfe_eth_get_coalesce,
3424 + .get_link_ksettings = pfe_eth_get_settings,
3425 + .set_link_ksettings = pfe_eth_set_settings,
3428 +/* pfe_eth_mdio_reset
3430 +int pfe_eth_mdio_reset(struct mii_bus *bus)
3432 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
3436 + mutex_lock(&bus->mdio_lock);
3439 + * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
3441 + * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
3442 + * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'.
3444 + phy_speed = (DIV_ROUND_UP((pfe->ctrl.sys_clk * 1000), 4000000)
3445 + << EMAC_MII_SPEED_SHIFT);
3446 + phy_speed |= EMAC_HOLDTIME(0x5);
3447 + __raw_writel(phy_speed, priv->mdio_base + EMAC_MII_CTRL_REG);
3449 + mutex_unlock(&bus->mdio_lock);
3454 +/* pfe_eth_mdio_timeout
3457 +static int pfe_eth_mdio_timeout(struct pfe_mdio_priv_s *priv, int timeout)
3459 + while (!(__raw_readl(priv->mdio_base + EMAC_IEVENT_REG) &
3460 + EMAC_IEVENT_MII)) {
3461 + if (timeout-- <= 0)
3463 + usleep_range(10, 20);
3465 + __raw_writel(EMAC_IEVENT_MII, priv->mdio_base + EMAC_IEVENT_REG);
3469 +static int pfe_eth_mdio_mux(u8 muxval)
3471 + struct i2c_adapter *a;
3472 + struct i2c_msg msg;
3473 + unsigned char buf[2];
3476 + a = i2c_get_adapter(0);
3480 + /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
3481 + buf[0] = 0x54; /* reg number */
3482 + buf[1] = (muxval << 6) | 0x3; /* data */
3487 + ret = i2c_transfer(a, &msg, 1);
3488 + i2c_put_adapter(a);
3494 +static int pfe_eth_mdio_write_addr(struct mii_bus *bus, int mii_id,
3495 + int dev_addr, int regnum)
3497 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
3499 + __raw_writel(EMAC_MII_DATA_PA(mii_id) |
3500 + EMAC_MII_DATA_RA(dev_addr) |
3501 + EMAC_MII_DATA_TA | EMAC_MII_DATA(regnum),
3502 + priv->mdio_base + EMAC_MII_DATA_REG);
3504 + if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
3505 + dev_err(&bus->dev, "phy MDIO address write timeout\n");
3512 +static int pfe_eth_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
3515 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
3517 + /*To access external PHYs on QDS board mux needs to be configured*/
3518 + if ((mii_id) && (pfe->mdio_muxval[mii_id]))
3519 + pfe_eth_mdio_mux(pfe->mdio_muxval[mii_id]);
3521 + if (regnum & MII_ADDR_C45) {
3522 + pfe_eth_mdio_write_addr(bus, mii_id, (regnum >> 16) & 0x1f,
3524 + __raw_writel(EMAC_MII_DATA_OP_CL45_WR |
3525 + EMAC_MII_DATA_PA(mii_id) |
3526 + EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
3527 + EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
3528 + priv->mdio_base + EMAC_MII_DATA_REG);
3530 + /* start a write op */
3531 + __raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_WR |
3532 + EMAC_MII_DATA_PA(mii_id) |
3533 + EMAC_MII_DATA_RA(regnum) |
3534 + EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
3535 + priv->mdio_base + EMAC_MII_DATA_REG);
3538 + if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
3539 + dev_err(&bus->dev, "%s: phy MDIO write timeout\n", __func__);
3545 +static int pfe_eth_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
3547 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
3550 + /*To access external PHYs on QDS board mux needs to be configured*/
3551 + if ((mii_id) && (pfe->mdio_muxval[mii_id]))
3552 + pfe_eth_mdio_mux(pfe->mdio_muxval[mii_id]);
3554 + if (regnum & MII_ADDR_C45) {
3555 + pfe_eth_mdio_write_addr(bus, mii_id, (regnum >> 16) & 0x1f,
3557 + __raw_writel(EMAC_MII_DATA_OP_CL45_RD |
3558 + EMAC_MII_DATA_PA(mii_id) |
3559 + EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
3561 + priv->mdio_base + EMAC_MII_DATA_REG);
3563 + /* start a read op */
3564 + __raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_RD |
3565 + EMAC_MII_DATA_PA(mii_id) |
3566 + EMAC_MII_DATA_RA(regnum) |
3567 + EMAC_MII_DATA_TA, priv->mdio_base +
3568 + EMAC_MII_DATA_REG);
3571 + if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
3572 + dev_err(&bus->dev, "%s: phy MDIO read timeout\n", __func__);
3576 + value = EMAC_MII_DATA(__raw_readl(priv->mdio_base +
3577 + EMAC_MII_DATA_REG));
3581 +static int pfe_eth_mdio_init(struct pfe *pfe,
3582 + struct ls1012a_pfe_platform_data *pfe_info,
3585 + struct pfe_mdio_priv_s *priv = NULL;
3586 + struct ls1012a_mdio_platform_data *mdio_info;
3587 + struct mii_bus *bus;
3588 + struct device_node *mdio_node;
3591 + mdio_info = (struct ls1012a_mdio_platform_data *)
3592 + pfe_info->ls1012a_mdio_pdata;
3593 + mdio_info->id = ii;
3595 + bus = mdiobus_alloc_size(sizeof(struct pfe_mdio_priv_s));
3597 + pr_err("mdiobus_alloc() failed\n");
3599 + goto err_mdioalloc;
3602 + bus->name = "ls1012a MDIO Bus";
3603 + snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", mdio_info->id);
3605 + bus->read = &pfe_eth_mdio_read;
3606 + bus->write = &pfe_eth_mdio_write;
3607 + bus->reset = &pfe_eth_mdio_reset;
3608 + bus->parent = pfe->dev;
3609 + bus->phy_mask = mdio_info->phy_mask;
3610 + bus->irq[0] = mdio_info->irq[0];
3612 + priv->mdio_base = cbus_emac_base[ii];
3614 + priv->mdc_div = mdio_info->mdc_div;
3615 + if (!priv->mdc_div)
3616 + priv->mdc_div = 64;
3617 + dev_info(bus->parent, "%s: mdc_div: %d, phy_mask: %x\n",
3618 + __func__, priv->mdc_div, bus->phy_mask);
3620 + mdio_node = of_get_child_by_name(pfe->dev->of_node, "mdio");
3621 + if ((mdio_info->id == 0) && mdio_node) {
3622 + rc = of_mdiobus_register(bus, mdio_node);
3623 + of_node_put(mdio_node);
3625 + rc = mdiobus_register(bus);
3629 + dev_err(bus->parent, "mdiobus_register(%s) failed\n",
3631 + goto err_mdioregister;
3634 + priv->mii_bus = bus;
3635 + pfe->mdio.mdio_priv[ii] = priv;
3637 + pfe_eth_mdio_reset(bus);
3642 + mdiobus_free(bus);
3647 +/* pfe_eth_mdio_exit
3649 +static void pfe_eth_mdio_exit(struct pfe *pfe,
3652 + struct pfe_mdio_priv_s *mdio_priv = pfe->mdio.mdio_priv[ii];
3653 + struct mii_bus *bus = mdio_priv->mii_bus;
3657 + mdiobus_unregister(bus);
3658 + mdiobus_free(bus);
3661 +/* pfe_get_phydev_speed
3663 +static int pfe_get_phydev_speed(struct phy_device *phydev)
3665 + switch (phydev->speed) {
3669 + return SPEED_100M;
3672 + return SPEED_1000M;
3676 +/* pfe_set_rgmii_speed
3678 +#define RGMIIPCR 0x434
3679 +/* RGMIIPCR bit definitions*/
3680 +#define SCFG_RGMIIPCR_EN_AUTO (0x00000008)
3681 +#define SCFG_RGMIIPCR_SETSP_1000M (0x00000004)
3682 +#define SCFG_RGMIIPCR_SETSP_100M (0x00000000)
3683 +#define SCFG_RGMIIPCR_SETSP_10M (0x00000002)
3684 +#define SCFG_RGMIIPCR_SETFD (0x00000001)
3686 +#define MDIOSELCR 0x484
3687 +#define MDIOSEL_SERDES 0x0
3688 +#define MDIOSEL_EXTPHY 0x80000000
3690 +static void pfe_set_rgmii_speed(struct phy_device *phydev)
3694 + regmap_read(pfe->scfg, RGMIIPCR, &rgmii_pcr);
3695 + rgmii_pcr &= ~(SCFG_RGMIIPCR_SETSP_1000M | SCFG_RGMIIPCR_SETSP_10M);
3697 + switch (phydev->speed) {
3699 + rgmii_pcr |= SCFG_RGMIIPCR_SETSP_10M;
3702 + rgmii_pcr |= SCFG_RGMIIPCR_SETSP_1000M;
3706 + /* Default is 100M */
3709 + regmap_write(pfe->scfg, RGMIIPCR, rgmii_pcr);
3712 +/* pfe_get_phydev_duplex
3714 +static int pfe_get_phydev_duplex(struct phy_device *phydev)
3716 + /*return (phydev->duplex == DUPLEX_HALF) ? DUP_HALF:DUP_FULL ; */
3717 + return DUPLEX_FULL;
3720 +/* pfe_eth_adjust_link
3722 +static void pfe_eth_adjust_link(struct net_device *ndev)
3724 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3725 + unsigned long flags;
3726 + struct phy_device *phydev = priv->phydev;
3727 + int new_state = 0;
3729 + netif_info(priv, drv, ndev, "%s\n", __func__);
3731 + spin_lock_irqsave(&priv->lock, flags);
3733 + if (phydev->link) {
3735 + * Now we make sure that we can be in full duplex mode.
3736 + * If not, we operate in half-duplex mode.
3738 + if (phydev->duplex != priv->oldduplex) {
3740 + gemac_set_duplex(priv->EMAC_baseaddr,
3741 + pfe_get_phydev_duplex(phydev));
3742 + priv->oldduplex = phydev->duplex;
3745 + if (phydev->speed != priv->oldspeed) {
3747 + gemac_set_speed(priv->EMAC_baseaddr,
3748 + pfe_get_phydev_speed(phydev));
3749 + if (priv->einfo->mii_config ==
3750 + PHY_INTERFACE_MODE_RGMII_TXID)
3751 + pfe_set_rgmii_speed(phydev);
3752 + priv->oldspeed = phydev->speed;
3755 + if (!priv->oldlink) {
3757 + priv->oldlink = 1;
3760 + } else if (priv->oldlink) {
3762 + priv->oldlink = 0;
3763 + priv->oldspeed = 0;
3764 + priv->oldduplex = -1;
3767 + if (new_state && netif_msg_link(priv))
3768 + phy_print_status(phydev);
3770 + spin_unlock_irqrestore(&priv->lock, flags);
3772 + /* Now, dump the details to the cdev.
3773 + * XXX: Locking would be required? (uniprocess arch)
3774 + * Or, maybe move it in spinlock above
3776 + if (us && priv->einfo->gem_id < PFE_CDEV_ETH_COUNT) {
3777 + pr_debug("Changing link state from (%u) to (%u) for ID=(%u)\n",
3778 + link_states[priv->einfo->gem_id].state,
3780 + priv->einfo->gem_id);
3781 + link_states[priv->einfo->gem_id].phy_id = priv->einfo->gem_id;
3782 + link_states[priv->einfo->gem_id].state = phydev->link;
3788 +static void pfe_phy_exit(struct net_device *ndev)
3790 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3792 + netif_info(priv, drv, ndev, "%s\n", __func__);
3794 + phy_disconnect(priv->phydev);
3795 + priv->phydev = NULL;
3800 +static void pfe_eth_stop(struct net_device *ndev, int wake)
3802 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3804 + netif_info(priv, drv, ndev, "%s\n", __func__);
3807 + gemac_tx_disable(priv->EMAC_baseaddr);
3809 + gemac_disable(priv->EMAC_baseaddr);
3810 + gpi_disable(priv->GPI_baseaddr);
3813 + phy_stop(priv->phydev);
3819 +static int pfe_eth_start(struct pfe_eth_priv_s *priv)
3821 + netif_info(priv, drv, priv->ndev, "%s\n", __func__);
3824 + phy_start(priv->phydev);
3826 + gpi_enable(priv->GPI_baseaddr);
3827 + gemac_enable(priv->EMAC_baseaddr);
3833 + * Configure on chip serdes through mdio
3835 +static void ls1012a_configure_serdes(struct net_device *ndev)
3837 + struct pfe_eth_priv_s *eth_priv = netdev_priv(ndev);
3838 + struct pfe_mdio_priv_s *mdio_priv = pfe->mdio.mdio_priv[eth_priv->id];
3839 + int sgmii_2500 = 0;
3840 + struct mii_bus *bus = mdio_priv->mii_bus;
3843 + if (eth_priv->einfo->mii_config == PHY_INTERFACE_MODE_2500SGMII)
3846 + netif_info(eth_priv, drv, ndev, "%s\n", __func__);
3847 + /* PCS configuration done with corresponding GEMAC */
3849 + pfe_eth_mdio_read(bus, 0, MDIO_SGMII_CR);
3850 + pfe_eth_mdio_read(bus, 0, MDIO_SGMII_SR);
3852 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_CR, SGMII_CR_RST);
3855 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_IF_MODE, SGMII_SPEED_1GBPS
3857 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_DEV_ABIL_SGMII,
3858 + SGMII_DEV_ABIL_ACK | SGMII_DEV_ABIL_SGMII);
3859 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_L, 0xa120);
3860 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_H, 0x7);
3861 + /* Autonegotiation need to be disabled for 2.5G SGMII mode*/
3862 + value = SGMII_CR_FD | SGMII_CR_SPEED_SEL1_1G;
3863 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_CR, value);
3865 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_IF_MODE,
3867 + | SGMII_USE_SGMII_AN
3869 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_DEV_ABIL_SGMII,
3870 + SGMII_DEV_ABIL_EEE_CLK_STP_EN
3872 + | SGMII_DEV_ABIL_SGMII);
3873 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_L, 0x400);
3874 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_H, 0x0);
3875 + value = SGMII_CR_AN_EN | SGMII_CR_FD | SGMII_CR_SPEED_SEL1_1G;
3876 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_CR, value);
3884 +static int pfe_phy_init(struct net_device *ndev)
3886 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3887 + struct phy_device *phydev;
3888 + char phy_id[MII_BUS_ID_SIZE + 3];
3889 + char bus_id[MII_BUS_ID_SIZE];
3890 + phy_interface_t interface;
3892 + priv->oldlink = 0;
3893 + priv->oldspeed = 0;
3894 + priv->oldduplex = -1;
3896 + snprintf(bus_id, MII_BUS_ID_SIZE, "ls1012a-%d", 0);
3897 + snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
3898 + priv->einfo->phy_id);
3899 + netif_info(priv, drv, ndev, "%s: %s\n", __func__, phy_id);
3900 + interface = priv->einfo->mii_config;
3901 + if ((interface == PHY_INTERFACE_MODE_SGMII) ||
3902 + (interface == PHY_INTERFACE_MODE_2500SGMII)) {
3903 + /*Configure SGMII PCS */
3905 + /* Config MDIO from serdes */
3906 + regmap_write(pfe->scfg, MDIOSELCR, MDIOSEL_SERDES);
3908 + ls1012a_configure_serdes(ndev);
3912 + /*Config MDIO from PAD */
3913 + regmap_write(pfe->scfg, MDIOSELCR, MDIOSEL_EXTPHY);
3916 + priv->oldlink = 0;
3917 + priv->oldspeed = 0;
3918 + priv->oldduplex = -1;
3919 + pr_info("%s interface %x\n", __func__, interface);
3921 + if (priv->phy_node) {
3922 + phydev = of_phy_connect(ndev, priv->phy_node,
3923 + pfe_eth_adjust_link, 0,
3924 + priv->einfo->mii_config);
3926 + netdev_err(ndev, "Unable to connect to phy\n");
3931 + phydev = phy_connect(ndev, phy_id,
3932 + &pfe_eth_adjust_link, interface);
3933 + if (IS_ERR(phydev)) {
3934 + netdev_err(ndev, "Unable to connect to phy\n");
3935 + return PTR_ERR(phydev);
3939 + priv->phydev = phydev;
3940 + phydev->irq = PHY_POLL;
3947 +static int pfe_gemac_init(struct pfe_eth_priv_s *priv)
3949 + struct gemac_cfg cfg;
3951 + netif_info(priv, ifup, priv->ndev, "%s\n", __func__);
3953 + cfg.speed = SPEED_1000M;
3954 + cfg.duplex = DUPLEX_FULL;
3956 + gemac_set_config(priv->EMAC_baseaddr, &cfg);
3957 + gemac_allow_broadcast(priv->EMAC_baseaddr);
3958 + gemac_enable_1536_rx(priv->EMAC_baseaddr);
3959 + gemac_enable_stacked_vlan(priv->EMAC_baseaddr);
3960 + gemac_enable_pause_rx(priv->EMAC_baseaddr);
3961 + gemac_set_bus_width(priv->EMAC_baseaddr, 64);
3963 + /*GEM will perform checksum verifications*/
3964 + if (priv->ndev->features & NETIF_F_RXCSUM)
3965 + gemac_enable_rx_checksum_offload(priv->EMAC_baseaddr);
3967 + gemac_disable_rx_checksum_offload(priv->EMAC_baseaddr);
3972 +/* pfe_eth_event_handler
3974 +static int pfe_eth_event_handler(void *data, int event, int qno)
3976 + struct pfe_eth_priv_s *priv = data;
3979 + case EVENT_RX_PKT_IND:
3982 + if (napi_schedule_prep(&priv->high_napi)) {
3983 + netif_info(priv, intr, priv->ndev,
3984 + "%s: schedule high prio poll\n"
3987 +#ifdef PFE_ETH_NAPI_STATS
3988 + priv->napi_counters[NAPI_SCHED_COUNT]++;
3991 + __napi_schedule(&priv->high_napi);
3993 + } else if (qno == 1) {
3994 + if (napi_schedule_prep(&priv->low_napi)) {
3995 + netif_info(priv, intr, priv->ndev,
3996 + "%s: schedule low prio poll\n"
3999 +#ifdef PFE_ETH_NAPI_STATS
4000 + priv->napi_counters[NAPI_SCHED_COUNT]++;
4002 + __napi_schedule(&priv->low_napi);
4004 + } else if (qno == 2) {
4005 + if (napi_schedule_prep(&priv->lro_napi)) {
4006 + netif_info(priv, intr, priv->ndev,
4007 + "%s: schedule lro prio poll\n"
4010 +#ifdef PFE_ETH_NAPI_STATS
4011 + priv->napi_counters[NAPI_SCHED_COUNT]++;
4013 + __napi_schedule(&priv->lro_napi);
4019 + case EVENT_TXDONE_IND:
4020 + pfe_eth_flush_tx(priv);
4021 + hif_lib_event_handler_start(&priv->client, EVENT_TXDONE_IND, 0);
4023 + case EVENT_HIGH_RX_WM:
4031 +static int pfe_eth_change_mtu(struct net_device *ndev, int new_mtu)
4033 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4035 + ndev->mtu = new_mtu;
4036 + new_mtu += ETH_HLEN + ETH_FCS_LEN;
4037 + gemac_set_rx_max_fl(priv->EMAC_baseaddr, new_mtu);
4044 +static int pfe_eth_open(struct net_device *ndev)
4046 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4047 + struct hif_client_s *client;
4050 + netif_info(priv, ifup, ndev, "%s\n", __func__);
4052 + /* Register client driver with HIF */
4053 + client = &priv->client;
4054 + memset(client, 0, sizeof(*client));
4055 + client->id = PFE_CL_GEM0 + priv->id;
4056 + client->tx_qn = emac_txq_cnt;
4057 + client->rx_qn = EMAC_RXQ_CNT;
4058 + client->priv = priv;
4059 + client->pfe = priv->pfe;
4060 + client->event_handler = pfe_eth_event_handler;
4062 + client->tx_qsize = EMAC_TXQ_DEPTH;
4063 + client->rx_qsize = EMAC_RXQ_DEPTH;
4065 + rc = hif_lib_client_register(client);
4067 + netdev_err(ndev, "%s: hif_lib_client_register(%d) failed\n",
4068 + __func__, client->id);
4072 + netif_info(priv, drv, ndev, "%s: registered client: %p\n", __func__,
4075 + pfe_gemac_init(priv);
4077 + if (!is_valid_ether_addr(ndev->dev_addr)) {
4078 + netdev_err(ndev, "%s: invalid MAC address\n", __func__);
4079 + rc = -EADDRNOTAVAIL;
4083 + gemac_set_laddrN(priv->EMAC_baseaddr,
4084 + (struct pfe_mac_addr *)ndev->dev_addr, 1);
4086 + napi_enable(&priv->high_napi);
4087 + napi_enable(&priv->low_napi);
4088 + napi_enable(&priv->lro_napi);
4090 + rc = pfe_eth_start(priv);
4092 + netif_tx_wake_all_queues(ndev);
4097 + hif_lib_client_unregister(&priv->client);
4104 + * pfe_eth_shutdown
4106 +int pfe_eth_shutdown(struct net_device *ndev, int wake)
4108 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4110 + unsigned long next_poll = jiffies + 1, end = jiffies +
4111 + (TX_POLL_TIMEOUT_MS * HZ) / 1000;
4112 + int tx_pkts, prv_tx_pkts;
4114 + netif_info(priv, ifdown, ndev, "%s\n", __func__);
4116 + for (i = 0; i < emac_txq_cnt; i++)
4117 + hrtimer_cancel(&priv->fast_tx_timeout[i].timer);
4119 + netif_tx_stop_all_queues(ndev);
4123 + pfe_eth_flush_tx(priv);
4125 + for (i = 0; i < emac_txq_cnt; i++)
4126 + tx_pkts += hif_lib_tx_pending(&priv->client, i);
4129 + /*Don't wait forever, break if we cross max timeout */
4130 + if (time_after(jiffies, end)) {
4132 + "(%s)Tx is not complete after %dmsec\n",
4133 + ndev->name, TX_POLL_TIMEOUT_MS);
4137 + pr_info("%s : (%s) Waiting for tx packets to free. Pending tx pkts = %d.\n"
4138 + , __func__, ndev->name, tx_pkts);
4139 + if (need_resched())
4143 + } while (tx_pkts);
4145 + end = jiffies + (TX_POLL_TIMEOUT_MS * HZ) / 1000;
4147 + prv_tx_pkts = tmu_pkts_processed(priv->id);
4149 + * Wait till TMU transmits all pending packets
4150 + * poll tmu_qstatus and pkts processed by TMU for every 10ms
4151 + * Consider TMU is busy, If we see TMU qeueu pending or any packets
4152 + * processed by TMU
4155 + if (time_after(jiffies, next_poll)) {
4156 + tx_pkts = tmu_pkts_processed(priv->id);
4157 + qstatus = tmu_qstatus(priv->id) & 0x7ffff;
4159 + if (!qstatus && (tx_pkts == prv_tx_pkts))
4161 + /* Don't wait forever, break if we cross max
4162 + * timeout(TX_POLL_TIMEOUT_MS)
4164 + if (time_after(jiffies, end)) {
4165 + pr_err("TMU%d is busy after %dmsec\n",
4166 + priv->id, TX_POLL_TIMEOUT_MS);
4169 + prv_tx_pkts = tx_pkts;
4172 + if (need_resched())
4175 + /* Wait for some more time to complete transmitting packet if any */
4176 + next_poll = jiffies + 1;
4178 + if (time_after(jiffies, next_poll))
4180 + if (need_resched())
4184 + pfe_eth_stop(ndev, wake);
4186 + napi_disable(&priv->lro_napi);
4187 + napi_disable(&priv->low_napi);
4188 + napi_disable(&priv->high_napi);
4190 + hif_lib_client_unregister(&priv->client);
4198 +static int pfe_eth_close(struct net_device *ndev)
4200 + pfe_eth_shutdown(ndev, 0);
4207 + * return value : 1 if netdevice is configured to wakeup system
4210 +int pfe_eth_suspend(struct net_device *ndev)
4212 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4216 + gemac_set_wol(priv->EMAC_baseaddr, priv->wol);
4219 + pfe_eth_shutdown(ndev, priv->wol);
4227 +int pfe_eth_resume(struct net_device *ndev)
4229 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4232 + gemac_set_wol(priv->EMAC_baseaddr, 0);
4233 + gemac_tx_enable(priv->EMAC_baseaddr);
4235 + return pfe_eth_open(ndev);
4238 +/* pfe_eth_get_queuenum
4240 +static int pfe_eth_get_queuenum(struct pfe_eth_priv_s *priv, struct sk_buff
4244 + unsigned long flags;
4246 + /* Get the Fast Path queue number */
4248 + * Use conntrack mark (if conntrack exists), then packet mark (if any),
4249 + * then fallback to default
4251 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) || defined(CONFIG_NF_CONNTRACK_MARK)
4253 + enum ip_conntrack_info cinfo;
4254 + struct nf_conn *ct;
4256 + ct = nf_ct_get(skb, &cinfo);
4261 + connmark = ct->mark;
4263 + if ((connmark & 0x80000000) && priv->id != 0)
4266 + queuenum = connmark & EMAC_QUEUENUM_MASK;
4268 + } else {/* continued after #endif ... */
4271 + queuenum = skb->mark & EMAC_QUEUENUM_MASK;
4273 + spin_lock_irqsave(&priv->lock, flags);
4274 + queuenum = priv->default_priority & EMAC_QUEUENUM_MASK;
4275 + spin_unlock_irqrestore(&priv->lock, flags);
4277 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) || defined(CONFIG_NF_CONNTRACK_MARK)
4283 +/* pfe_eth_might_stop_tx
4286 +static int pfe_eth_might_stop_tx(struct pfe_eth_priv_s *priv, int queuenum,
4287 + struct netdev_queue *tx_queue,
4288 + unsigned int n_desc,
4289 + unsigned int n_segs)
4295 + if (unlikely((__hif_tx_avail(&pfe->hif) < n_desc) ||
4296 + (hif_lib_tx_avail(&priv->client, queuenum) < n_desc) ||
4297 + (hif_lib_tx_credit_avail(pfe, priv->id, queuenum) < n_segs))) {
4299 + __hif_lib_update_credit(&priv->client, queuenum);
4303 +#ifdef PFE_ETH_TX_STATS
4304 + if (__hif_tx_avail(&pfe->hif) < n_desc) {
4305 + priv->stop_queue_hif[queuenum]++;
4306 + } else if (hif_lib_tx_avail(&priv->client, queuenum) < n_desc) {
4307 + priv->stop_queue_hif_client[queuenum]++;
4308 + } else if (hif_lib_tx_credit_avail(pfe, priv->id, queuenum) <
4310 + priv->stop_queue_credit[queuenum]++;
4312 + priv->stop_queue_total[queuenum]++;
4314 + netif_tx_stop_queue(tx_queue);
4316 + kt = ktime_set(0, LS1012A_TX_FAST_RECOVERY_TIMEOUT_MS *
4318 + hrtimer_start(&priv->fast_tx_timeout[queuenum].timer, kt,
4319 + HRTIMER_MODE_REL);
4326 +#define SA_MAX_OP 2
4327 +/* pfe_hif_send_packet
4329 + * At this level if TX fails we drop the packet
4331 +static void pfe_hif_send_packet(struct sk_buff *skb, struct pfe_eth_priv_s
4332 + *priv, int queuenum)
4334 + struct skb_shared_info *sh = skb_shinfo(skb);
4335 + unsigned int nr_frags;
4338 + netif_info(priv, tx_queued, priv->ndev, "%s\n", __func__);
4340 + if (skb_is_gso(skb)) {
4341 + priv->stats.tx_dropped++;
4345 + if (skb->ip_summed == CHECKSUM_PARTIAL)
4346 + ctrl = HIF_CTRL_TX_CHECKSUM;
4348 + nr_frags = sh->nr_frags;
4354 + __hif_lib_xmit_pkt(&priv->client, queuenum, skb->data,
4355 + skb_headlen(skb), ctrl, HIF_FIRST_BUFFER,
4358 + for (i = 0; i < nr_frags - 1; i++) {
4359 + f = &sh->frags[i];
4360 + __hif_lib_xmit_pkt(&priv->client, queuenum,
4361 + skb_frag_address(f),
4366 + f = &sh->frags[i];
4368 + __hif_lib_xmit_pkt(&priv->client, queuenum,
4369 + skb_frag_address(f), skb_frag_size(f),
4370 + 0x0, HIF_LAST_BUFFER | HIF_DATA_VALID,
4373 + netif_info(priv, tx_queued, priv->ndev,
4374 + "%s: pkt sent successfully skb:%p nr_frags:%d len:%d\n",
4375 + __func__, skb, nr_frags, skb->len);
4377 + __hif_lib_xmit_pkt(&priv->client, queuenum, skb->data,
4378 + skb->len, ctrl, HIF_FIRST_BUFFER |
4379 + HIF_LAST_BUFFER | HIF_DATA_VALID,
4381 + netif_info(priv, tx_queued, priv->ndev,
4382 + "%s: pkt sent successfully skb:%p len:%d\n",
4383 + __func__, skb, skb->len);
4385 + hif_tx_dma_start();
4386 + priv->stats.tx_packets++;
4387 + priv->stats.tx_bytes += skb->len;
4388 + hif_lib_tx_credit_use(pfe, priv->id, queuenum, 1);
4391 +/* pfe_eth_flush_txQ
4393 +static void pfe_eth_flush_txQ(struct pfe_eth_priv_s *priv, int tx_q_num, int
4394 + from_tx, int n_desc)
4396 + struct sk_buff *skb;
4397 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
4399 + unsigned int flags;
4401 + netif_info(priv, tx_done, priv->ndev, "%s\n", __func__);
4404 + __netif_tx_lock_bh(tx_queue);
4406 + /* Clean HIF and client queue */
4407 + while ((skb = hif_lib_tx_get_next_complete(&priv->client,
4409 + HIF_TX_DESC_NT))) {
4410 + if (flags & HIF_DATA_VALID)
4411 + dev_kfree_skb_any(skb);
4414 + __netif_tx_unlock_bh(tx_queue);
4417 +/* pfe_eth_flush_tx
4419 +static void pfe_eth_flush_tx(struct pfe_eth_priv_s *priv)
4423 + netif_info(priv, tx_done, priv->ndev, "%s\n", __func__);
4425 + for (ii = 0; ii < emac_txq_cnt; ii++) {
4426 + pfe_eth_flush_txQ(priv, ii, 0, 0);
4427 + __hif_lib_update_credit(&priv->client, ii);
4431 +void pfe_tx_get_req_desc(struct sk_buff *skb, unsigned int *n_desc, unsigned int
4434 + struct skb_shared_info *sh = skb_shinfo(skb);
4436 + /* Scattered data */
4437 + if (sh->nr_frags) {
4438 + *n_desc = sh->nr_frags + 1;
4440 + /* Regular case */
4447 +/* pfe_eth_send_packet
4449 +static int pfe_eth_send_packet(struct sk_buff *skb, struct net_device *ndev)
4451 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4452 + int tx_q_num = skb_get_queue_mapping(skb);
4453 + int n_desc, n_segs;
4454 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
4457 + netif_info(priv, tx_queued, ndev, "%s\n", __func__);
4459 + if ((!skb_is_gso(skb)) && (skb_headroom(skb) < (PFE_PKT_HEADER_SZ +
4460 + sizeof(unsigned long)))) {
4461 + netif_warn(priv, tx_err, priv->ndev, "%s: copying skb\n",
4464 + if (pskb_expand_head(skb, (PFE_PKT_HEADER_SZ + sizeof(unsigned
4465 + long)), 0, GFP_ATOMIC)) {
4466 + /* No need to re-transmit, no way to recover*/
4468 + priv->stats.tx_dropped++;
4469 + return NETDEV_TX_OK;
4473 + pfe_tx_get_req_desc(skb, &n_desc, &n_segs);
4475 + hif_tx_lock(&pfe->hif);
4476 + if (unlikely(pfe_eth_might_stop_tx(priv, tx_q_num, tx_queue, n_desc,
4478 +#ifdef PFE_ETH_TX_STATS
4479 + if (priv->was_stopped[tx_q_num]) {
4480 + priv->clean_fail[tx_q_num]++;
4481 + priv->was_stopped[tx_q_num] = 0;
4484 + hif_tx_unlock(&pfe->hif);
4485 + return NETDEV_TX_BUSY;
4488 + pfe_hif_send_packet(skb, priv, tx_q_num);
4490 + hif_tx_unlock(&pfe->hif);
4492 + tx_queue->trans_start = jiffies;
4494 +#ifdef PFE_ETH_TX_STATS
4495 + priv->was_stopped[tx_q_num] = 0;
4498 + return NETDEV_TX_OK;
4501 +/* pfe_eth_select_queue
4504 +static u16 pfe_eth_select_queue(struct net_device *ndev, struct sk_buff *skb,
4506 + select_queue_fallback_t fallback)
4508 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4510 + return pfe_eth_get_queuenum(priv, skb);
4513 +/* pfe_eth_get_stats
4515 +static struct net_device_stats *pfe_eth_get_stats(struct net_device *ndev)
4517 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4519 + netif_info(priv, drv, ndev, "%s\n", __func__);
4521 + return &priv->stats;
4524 +/* pfe_eth_set_mac_address
4526 +static int pfe_eth_set_mac_address(struct net_device *ndev, void *addr)
4528 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4529 + struct sockaddr *sa = addr;
4531 + netif_info(priv, drv, ndev, "%s\n", __func__);
4533 + if (!is_valid_ether_addr(sa->sa_data))
4534 + return -EADDRNOTAVAIL;
4536 + memcpy(ndev->dev_addr, sa->sa_data, ETH_ALEN);
4538 + gemac_set_laddrN(priv->EMAC_baseaddr,
4539 + (struct pfe_mac_addr *)ndev->dev_addr, 1);
4544 +/* pfe_eth_enet_addr_byte_mac
4546 +int pfe_eth_enet_addr_byte_mac(u8 *enet_byte_addr,
4547 + struct pfe_mac_addr *enet_addr)
4549 + if (!enet_byte_addr || !enet_addr) {
4553 + enet_addr->bottom = enet_byte_addr[0] |
4554 + (enet_byte_addr[1] << 8) |
4555 + (enet_byte_addr[2] << 16) |
4556 + (enet_byte_addr[3] << 24);
4557 + enet_addr->top = enet_byte_addr[4] |
4558 + (enet_byte_addr[5] << 8);
4563 +/* pfe_eth_set_multi
4565 +static void pfe_eth_set_multi(struct net_device *ndev)
4567 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4568 + struct pfe_mac_addr hash_addr; /* hash register structure */
4569 + /* specific mac address register structure */
4570 + struct pfe_mac_addr spec_addr;
4571 + int result; /* index into hash register to set.. */
4573 + struct netdev_hw_addr *ha;
4575 + if (ndev->flags & IFF_PROMISC) {
4576 + netif_info(priv, drv, ndev, "entering promiscuous mode\n");
4578 + priv->promisc = 1;
4579 + gemac_enable_copy_all(priv->EMAC_baseaddr);
4581 + priv->promisc = 0;
4582 + gemac_disable_copy_all(priv->EMAC_baseaddr);
4585 + /* Enable broadcast frame reception if required. */
4586 + if (ndev->flags & IFF_BROADCAST) {
4587 + gemac_allow_broadcast(priv->EMAC_baseaddr);
4589 + netif_info(priv, drv, ndev,
4590 + "disabling broadcast frame reception\n");
4592 + gemac_no_broadcast(priv->EMAC_baseaddr);
4595 + if (ndev->flags & IFF_ALLMULTI) {
4596 + /* Set the hash to rx all multicast frames */
4597 + hash_addr.bottom = 0xFFFFFFFF;
4598 + hash_addr.top = 0xFFFFFFFF;
4599 + gemac_set_hash(priv->EMAC_baseaddr, &hash_addr);
4600 + netdev_for_each_uc_addr(ha, ndev) {
4601 + if (uc_count >= MAX_UC_SPEC_ADDR_REG)
4603 + pfe_eth_enet_addr_byte_mac(ha->addr, &spec_addr);
4604 + gemac_set_laddrN(priv->EMAC_baseaddr, &spec_addr,
4608 + } else if ((netdev_mc_count(ndev) > 0) || (netdev_uc_count(ndev))) {
4611 + hash_addr.bottom = 0;
4612 + hash_addr.top = 0;
4614 + netdev_for_each_mc_addr(ha, ndev) {
4617 + netif_info(priv, drv, ndev,
4618 + "adding multicast address %X:%X:%X:%X:%X:%X to gem filter\n",
4619 + addr[0], addr[1], addr[2],
4620 + addr[3], addr[4], addr[5]);
4622 + result = pfe_eth_get_hash(addr);
4624 + if (result < EMAC_HASH_REG_BITS) {
4626 + hash_addr.bottom |= (1 << result);
4628 + hash_addr.top |= (1 << (result - 32));
4635 + netdev_for_each_uc_addr(ha, ndev) {
4638 + if (++uc_count < MAX_UC_SPEC_ADDR_REG) {
4640 + "adding unicast address %02x:%02x:%02x:%02x:%02x:%02x to gem filter\n",
4641 + addr[0], addr[1], addr[2],
4642 + addr[3], addr[4], addr[5]);
4643 + pfe_eth_enet_addr_byte_mac(addr, &spec_addr);
4644 + gemac_set_laddrN(priv->EMAC_baseaddr,
4645 + &spec_addr, uc_count + 2);
4647 + netif_info(priv, drv, ndev,
4648 + "adding unicast address %02x:%02x:%02x:%02x:%02x:%02x to gem hash\n",
4649 + addr[0], addr[1], addr[2],
4650 + addr[3], addr[4], addr[5]);
4652 + result = pfe_eth_get_hash(addr);
4653 + if (result >= EMAC_HASH_REG_BITS) {
4658 + hash_addr.bottom |= (1 <<
4661 + hash_addr.top |= (1 <<
4667 + gemac_set_hash(priv->EMAC_baseaddr, &hash_addr);
4670 + if (!(netdev_uc_count(ndev) >= MAX_UC_SPEC_ADDR_REG)) {
4672 + * Check if there are any specific address HW registers that
4673 + * need to be flushed
4675 + for (uc_count = netdev_uc_count(ndev); uc_count <
4676 + MAX_UC_SPEC_ADDR_REG; uc_count++)
4677 + gemac_clear_laddrN(priv->EMAC_baseaddr, uc_count + 2);
4680 + if (ndev->flags & IFF_LOOPBACK)
4681 + gemac_set_loop(priv->EMAC_baseaddr, LB_LOCAL);
4684 +/* pfe_eth_set_features
4686 +static int pfe_eth_set_features(struct net_device *ndev, netdev_features_t
4689 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4692 + if (features & NETIF_F_RXCSUM)
4693 + gemac_enable_rx_checksum_offload(priv->EMAC_baseaddr);
4695 + gemac_disable_rx_checksum_offload(priv->EMAC_baseaddr);
4699 +/* pfe_eth_fast_tx_timeout
4701 +static enum hrtimer_restart pfe_eth_fast_tx_timeout(struct hrtimer *timer)
4703 + struct pfe_eth_fast_timer *fast_tx_timeout = container_of(timer, struct
4704 + pfe_eth_fast_timer,
4706 + struct pfe_eth_priv_s *priv = container_of(fast_tx_timeout->base,
4707 + struct pfe_eth_priv_s,
4709 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
4710 + fast_tx_timeout->queuenum);
4712 + if (netif_tx_queue_stopped(tx_queue)) {
4713 +#ifdef PFE_ETH_TX_STATS
4714 + priv->was_stopped[fast_tx_timeout->queuenum] = 1;
4716 + netif_tx_wake_queue(tx_queue);
4719 + return HRTIMER_NORESTART;
4722 +/* pfe_eth_fast_tx_timeout_init
4724 +static void pfe_eth_fast_tx_timeout_init(struct pfe_eth_priv_s *priv)
4728 + for (i = 0; i < emac_txq_cnt; i++) {
4729 + priv->fast_tx_timeout[i].queuenum = i;
4730 + hrtimer_init(&priv->fast_tx_timeout[i].timer, CLOCK_MONOTONIC,
4731 + HRTIMER_MODE_REL);
4732 + priv->fast_tx_timeout[i].timer.function =
4733 + pfe_eth_fast_tx_timeout;
4734 + priv->fast_tx_timeout[i].base = priv->fast_tx_timeout;
4738 +static struct sk_buff *pfe_eth_rx_skb(struct net_device *ndev,
4739 + struct pfe_eth_priv_s *priv,
4743 + unsigned int rx_ctrl;
4744 + unsigned int desc_ctrl = 0;
4745 + struct hif_ipsec_hdr *ipsec_hdr = NULL;
4746 + struct sk_buff *skb;
4747 + struct sk_buff *skb_frag, *skb_frag_last = NULL;
4748 + int length = 0, offset;
4750 + skb = priv->skb_inflight[qno];
4753 + skb_frag_last = skb_shinfo(skb)->frag_list;
4754 + if (skb_frag_last) {
4755 + while (skb_frag_last->next)
4756 + skb_frag_last = skb_frag_last->next;
4760 + while (!(desc_ctrl & CL_DESC_LAST)) {
4761 + buf_addr = hif_lib_receive_pkt(&priv->client, qno, &length,
4762 + &offset, &rx_ctrl, &desc_ctrl,
4763 + (void **)&ipsec_hdr);
4767 +#ifdef PFE_ETH_NAPI_STATS
4768 + priv->napi_counters[NAPI_DESC_COUNT]++;
4772 + if (desc_ctrl & CL_DESC_FIRST) {
4773 + skb = build_skb(buf_addr, 0);
4774 + if (unlikely(!skb))
4777 + skb_reserve(skb, offset);
4778 + skb_put(skb, length);
4781 + if ((ndev->features & NETIF_F_RXCSUM) && (rx_ctrl &
4782 + HIF_CTRL_RX_CHECKSUMMED))
4783 + skb->ip_summed = CHECKSUM_UNNECESSARY;
4785 + skb_checksum_none_assert(skb);
4789 + if (unlikely(!skb)) {
4790 + pr_err("%s: NULL skb_inflight\n",
4795 + skb_frag = build_skb(buf_addr, 0);
4797 + if (unlikely(!skb_frag)) {
4802 + skb_reserve(skb_frag, offset);
4803 + skb_put(skb_frag, length);
4805 + skb_frag->dev = ndev;
4807 + if (skb_shinfo(skb)->frag_list)
4808 + skb_frag_last->next = skb_frag;
4810 + skb_shinfo(skb)->frag_list = skb_frag;
4812 + skb->truesize += skb_frag->truesize;
4813 + skb->data_len += length;
4814 + skb->len += length;
4815 + skb_frag_last = skb_frag;
4819 + priv->skb_inflight[qno] = NULL;
4823 + priv->skb_inflight[qno] = skb;
4827 + priv->skb_inflight[qno] = NULL;
4834 + priv->stats.rx_errors++;
4841 +static int pfe_eth_poll(struct pfe_eth_priv_s *priv, struct napi_struct *napi,
4842 + unsigned int qno, int budget)
4844 + struct net_device *ndev = priv->ndev;
4845 + struct sk_buff *skb;
4846 + int work_done = 0;
4849 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
4851 +#ifdef PFE_ETH_NAPI_STATS
4852 + priv->napi_counters[NAPI_POLL_COUNT]++;
4856 + skb = pfe_eth_rx_skb(ndev, priv, qno);
4863 + /* Packet will be processed */
4864 + skb->protocol = eth_type_trans(skb, ndev);
4866 + netif_receive_skb(skb);
4868 + priv->stats.rx_packets++;
4869 + priv->stats.rx_bytes += len;
4873 +#ifdef PFE_ETH_NAPI_STATS
4874 + priv->napi_counters[NAPI_PACKET_COUNT]++;
4877 + } while (work_done < budget);
4880 + * If no Rx receive nor cleanup work was done, exit polling mode.
4881 + * No more netif_running(dev) check is required here , as this is
4882 + * checked in net/core/dev.c (2.6.33.5 kernel specific).
4884 + if (work_done < budget) {
4885 + napi_complete(napi);
4887 + hif_lib_event_handler_start(&priv->client, EVENT_RX_PKT_IND,
4890 +#ifdef PFE_ETH_NAPI_STATS
4892 + priv->napi_counters[NAPI_FULL_BUDGET_COUNT]++;
4899 + * pfe_eth_lro_poll
4901 +static int pfe_eth_lro_poll(struct napi_struct *napi, int budget)
4903 + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
4906 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
4908 + return pfe_eth_poll(priv, napi, 2, budget);
4911 +/* pfe_eth_low_poll
4913 +static int pfe_eth_low_poll(struct napi_struct *napi, int budget)
4915 + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
4918 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
4920 + return pfe_eth_poll(priv, napi, 1, budget);
4923 +/* pfe_eth_high_poll
4925 +static int pfe_eth_high_poll(struct napi_struct *napi, int budget)
4927 + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
4930 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
4932 + return pfe_eth_poll(priv, napi, 0, budget);
4935 +static const struct net_device_ops pfe_netdev_ops = {
4936 + .ndo_open = pfe_eth_open,
4937 + .ndo_stop = pfe_eth_close,
4938 + .ndo_start_xmit = pfe_eth_send_packet,
4939 + .ndo_select_queue = pfe_eth_select_queue,
4940 + .ndo_set_rx_mode = pfe_eth_set_multi,
4941 + .ndo_set_mac_address = pfe_eth_set_mac_address,
4942 + .ndo_validate_addr = eth_validate_addr,
4943 + .ndo_change_mtu = pfe_eth_change_mtu,
4944 + .ndo_get_stats = pfe_eth_get_stats,
4945 + .ndo_set_features = pfe_eth_set_features,
4948 +/* pfe_eth_init_one
4950 +static int pfe_eth_init_one(struct pfe *pfe,
4951 + struct ls1012a_pfe_platform_data *pfe_info,
4954 + struct net_device *ndev = NULL;
4955 + struct pfe_eth_priv_s *priv = NULL;
4956 + struct ls1012a_eth_platform_data *einfo;
4959 + einfo = (struct ls1012a_eth_platform_data *)
4960 + pfe_info->ls1012a_eth_pdata;
4962 + /* einfo never be NULL, but no harm in having this check */
4965 + "%s: pfe missing additional gemacs platform data\n"
4972 + emac_txq_cnt = EMAC_TXQ_CNT;
4973 + /* Create an ethernet device instance */
4974 + ndev = alloc_etherdev_mq(sizeof(*priv), emac_txq_cnt);
4977 + pr_err("%s: gemac %d device allocation failed\n",
4978 + __func__, einfo[id].gem_id);
4983 + priv = netdev_priv(ndev);
4984 + priv->ndev = ndev;
4985 + priv->id = einfo[id].gem_id;
4987 + priv->phy_node = einfo[id].phy_node;
4989 + SET_NETDEV_DEV(priv->ndev, priv->pfe->dev);
4991 + pfe->eth.eth_priv[id] = priv;
4993 + /* Set the info in the priv to the current info */
4994 + priv->einfo = &einfo[id];
4995 + priv->EMAC_baseaddr = cbus_emac_base[id];
4996 + priv->GPI_baseaddr = cbus_gpi_base[id];
4998 + spin_lock_init(&priv->lock);
5000 + pfe_eth_fast_tx_timeout_init(priv);
5002 + /* Copy the station address into the dev structure, */
5003 + memcpy(ndev->dev_addr, einfo[id].mac_addr, ETH_ALEN);
5010 + /* Set MTU limits */
5011 + ndev->min_mtu = ETH_MIN_MTU;
5014 + * Jumbo frames are not supported on LS1012A rev-1.0.
5015 + * So max mtu should be restricted to supported frame length.
5017 + if (pfe_errata_a010897)
5018 + ndev->max_mtu = JUMBO_FRAME_SIZE_V1 - ETH_HLEN - ETH_FCS_LEN;
5020 + ndev->max_mtu = JUMBO_FRAME_SIZE_V2 - ETH_HLEN - ETH_FCS_LEN;
5022 + /*Enable after checksum offload is validated */
5023 + ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
5024 + NETIF_F_IPV6_CSUM | NETIF_F_SG;
5026 + /* enabled by default */
5027 + ndev->features = ndev->hw_features;
5029 + priv->usr_features = ndev->features;
5031 + ndev->netdev_ops = &pfe_netdev_ops;
5033 + ndev->ethtool_ops = &pfe_ethtool_ops;
5035 + /* Enable basic messages by default */
5036 + priv->msg_enable = NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_LINK |
5039 + netif_napi_add(ndev, &priv->low_napi, pfe_eth_low_poll,
5040 + HIF_RX_POLL_WEIGHT - 16);
5041 + netif_napi_add(ndev, &priv->high_napi, pfe_eth_high_poll,
5042 + HIF_RX_POLL_WEIGHT - 16);
5043 + netif_napi_add(ndev, &priv->lro_napi, pfe_eth_lro_poll,
5044 + HIF_RX_POLL_WEIGHT - 16);
5046 + err = register_netdev(ndev);
5048 + netdev_err(ndev, "register_netdev() failed\n");
5052 + if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
5053 + ((pfe_use_old_dts_phy) &&
5054 + (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
5055 + pr_info("%s: No PHY or fixed-link\n", __func__);
5056 + goto skip_phy_init;
5060 + device_init_wakeup(&ndev->dev, WAKE_MAGIC);
5062 + err = pfe_phy_init(ndev);
5064 + netdev_err(ndev, "%s: pfe_phy_init() failed\n",
5071 + phy_start(priv->phydev);
5075 + netif_carrier_on(ndev);
5078 + /* Create all the sysfs files */
5079 + if (pfe_eth_sysfs_init(ndev))
5082 + netif_info(priv, probe, ndev, "%s: created interface, baseaddr: %p\n",
5083 + __func__, priv->EMAC_baseaddr);
5088 + pfe_phy_exit(priv->ndev);
5092 + unregister_netdev(ndev);
5094 + free_netdev(priv->ndev);
5101 +int pfe_eth_init(struct pfe *pfe)
5105 + struct ls1012a_pfe_platform_data *pfe_info;
5107 + pr_info("%s\n", __func__);
5109 + cbus_emac_base[0] = EMAC1_BASE_ADDR;
5110 + cbus_emac_base[1] = EMAC2_BASE_ADDR;
5112 + cbus_gpi_base[0] = EGPI1_BASE_ADDR;
5113 + cbus_gpi_base[1] = EGPI2_BASE_ADDR;
5115 + pfe_info = (struct ls1012a_pfe_platform_data *)
5116 + pfe->dev->platform_data;
5118 + pr_err("%s: pfe missing additional platform data\n", __func__);
5123 + for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
5124 + err = pfe_eth_mdio_init(pfe, pfe_info, ii);
5126 + pr_err("%s: pfe_eth_mdio_init() failed\n", __func__);
5127 + goto err_mdio_init;
5131 + if (fsl_guts_get_svr() == LS1012A_REV_1_0)
5132 + pfe_errata_a010897 = true;
5134 + pfe_errata_a010897 = false;
5136 + for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
5137 + err = pfe_eth_init_one(pfe, pfe_info, ii);
5139 + goto err_eth_init;
5146 + pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
5147 + pfe_eth_mdio_exit(pfe, ii);
5155 +/* pfe_eth_exit_one
5157 +static void pfe_eth_exit_one(struct pfe_eth_priv_s *priv)
5159 + netif_info(priv, probe, priv->ndev, "%s\n", __func__);
5162 + pfe_eth_sysfs_exit(priv->ndev);
5164 + if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
5165 + ((pfe_use_old_dts_phy) &&
5166 + (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
5167 + pr_info("%s: No PHY or fixed-link\n", __func__);
5168 + goto skip_phy_exit;
5171 + pfe_phy_exit(priv->ndev);
5175 + unregister_netdev(priv->ndev);
5177 + free_netdev(priv->ndev);
5182 +void pfe_eth_exit(struct pfe *pfe)
5186 + pr_info("%s\n", __func__);
5188 + for (ii = NUM_GEMAC_SUPPORT - 1; ii >= 0; ii--)
5189 + pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
5191 + for (ii = NUM_GEMAC_SUPPORT - 1; ii >= 0; ii--)
5192 + pfe_eth_mdio_exit(pfe, ii);
5195 +++ b/drivers/staging/fsl_ppfe/pfe_eth.h
5197 +/* SPDX-License-Identifier: GPL-2.0+ */
5199 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
5200 + * Copyright 2017 NXP
5203 +#ifndef _PFE_ETH_H_
5204 +#define _PFE_ETH_H_
5205 +#include <linux/kernel.h>
5206 +#include <linux/netdevice.h>
5207 +#include <linux/etherdevice.h>
5208 +#include <linux/ethtool.h>
5209 +#include <linux/mii.h>
5210 +#include <linux/phy.h>
5211 +#include <linux/clk.h>
5212 +#include <linux/interrupt.h>
5213 +#include <linux/time.h>
5215 +#define PFE_ETH_NAPI_STATS
5216 +#define PFE_ETH_TX_STATS
5218 +#define PFE_ETH_FRAGS_MAX (65536 / HIF_RX_PKT_MIN_SIZE)
5219 +#define LRO_LEN_COUNT_MAX 32
5220 +#define LRO_NB_COUNT_MAX 32
5222 +#define PFE_PAUSE_FLAG_ENABLE 1
5223 +#define PFE_PAUSE_FLAG_AUTONEG 2
5225 +/* GEMAC configured by SW */
5226 +/* GEMAC configured by phy lines (not for MII/GMII) */
5228 +#define GEMAC_SW_FULL_DUPLEX BIT(9)
5229 +#define GEMAC_SW_SPEED_10M (0 << 12)
5230 +#define GEMAC_SW_SPEED_100M BIT(12)
5231 +#define GEMAC_SW_SPEED_1G (2 << 12)
5233 +#define GEMAC_NO_PHY BIT(0)
5235 +struct ls1012a_eth_platform_data {
5236 + /* board specific information */
5242 + u8 mac_addr[ETH_ALEN];
5243 + struct device_node *phy_node;
5246 +struct ls1012a_mdio_platform_data {
5253 +struct ls1012a_pfe_platform_data {
5254 + struct ls1012a_eth_platform_data ls1012a_eth_pdata[3];
5255 + struct ls1012a_mdio_platform_data ls1012a_mdio_pdata[3];
5258 +#define NUM_GEMAC_SUPPORT 2
5259 +#define DRV_NAME "pfe-eth"
5260 +#define DRV_VERSION "1.0"
5262 +#define LS1012A_TX_FAST_RECOVERY_TIMEOUT_MS 3
5263 +#define TX_POLL_TIMEOUT_MS 1000
5265 +#define EMAC_TXQ_CNT 16
5266 +#define EMAC_TXQ_DEPTH (HIF_TX_DESC_NT)
5268 +#define JUMBO_FRAME_SIZE_V1 1900
5269 +#define JUMBO_FRAME_SIZE_V2 10258
5271 + * Client Tx queue threshold, for txQ flush condition.
5272 + * It must be smaller than the queue size (in case we ever change it in the
5275 +#define HIF_CL_TX_FLUSH_MARK 32
5278 + * Max number of TX resources (HIF descriptors or skbs) that will be released
5279 + * in a single go during batch recycling.
5280 + * Should be lower than the flush mark so the SW can provide the HW with a
5281 + * continuous stream of packets instead of bursts.
5283 +#define TX_FREE_MAX_COUNT 16
5284 +#define EMAC_RXQ_CNT 3
5285 +#define EMAC_RXQ_DEPTH HIF_RX_DESC_NT
5286 +/* make sure clients can receive a full burst of packets */
5287 +#define EMAC_RMON_TXBYTES_POS 0x00
5288 +#define EMAC_RMON_RXBYTES_POS 0x14
5290 +#define EMAC_QUEUENUM_MASK (emac_txq_cnt - 1)
5291 +#define EMAC_MDIO_TIMEOUT 1000
5292 +#define MAX_UC_SPEC_ADDR_REG 31
5294 +struct pfe_eth_fast_timer {
5296 + struct hrtimer timer;
5300 +struct pfe_eth_priv_s {
5302 + struct hif_client_s client;
5303 + struct napi_struct lro_napi;
5304 + struct napi_struct low_napi;
5305 + struct napi_struct high_napi;
5308 + struct net_device_stats stats;
5309 + struct net_device *ndev;
5312 + unsigned int msg_enable;
5313 + unsigned int usr_features;
5315 + spinlock_t lock; /* protect member variables */
5316 + unsigned int event_status;
5318 + void *EMAC_baseaddr;
5319 + void *GPI_baseaddr;
5321 + struct phy_device *phydev;
5325 + struct device_node *phy_node;
5326 + struct clk *gemtx_clk;
5330 + int default_priority;
5331 + struct pfe_eth_fast_timer fast_tx_timeout[EMAC_TXQ_CNT];
5333 + struct ls1012a_eth_platform_data *einfo;
5334 + struct sk_buff *skb_inflight[EMAC_RXQ_CNT + 6];
5336 +#ifdef PFE_ETH_TX_STATS
5337 + unsigned int stop_queue_total[EMAC_TXQ_CNT];
5338 + unsigned int stop_queue_hif[EMAC_TXQ_CNT];
5339 + unsigned int stop_queue_hif_client[EMAC_TXQ_CNT];
5340 + unsigned int stop_queue_credit[EMAC_TXQ_CNT];
5341 + unsigned int clean_fail[EMAC_TXQ_CNT];
5342 + unsigned int was_stopped[EMAC_TXQ_CNT];
5345 +#ifdef PFE_ETH_NAPI_STATS
5346 + unsigned int napi_counters[NAPI_MAX_COUNT];
5348 + unsigned int frags_inflight[EMAC_RXQ_CNT + 6];
5352 + struct pfe_eth_priv_s *eth_priv[3];
5355 +struct pfe_mdio_priv_s {
5356 + void __iomem *mdio_base;
5358 + struct mii_bus *mii_bus;
5362 + struct pfe_mdio_priv_s *mdio_priv[3];
5365 +int pfe_eth_init(struct pfe *pfe);
5366 +void pfe_eth_exit(struct pfe *pfe);
5367 +int pfe_eth_suspend(struct net_device *dev);
5368 +int pfe_eth_resume(struct net_device *dev);
5369 +int pfe_eth_mdio_reset(struct mii_bus *bus);
5371 +#endif /* _PFE_ETH_H_ */
5373 +++ b/drivers/staging/fsl_ppfe/pfe_firmware.c
5375 +// SPDX-License-Identifier: GPL-2.0+
5377 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
5378 + * Copyright 2017 NXP
5383 + * Contains all the functions to handle parsing and loading of PE firmware
5386 +#include <linux/firmware.h>
5388 +#include "pfe_mod.h"
5389 +#include "pfe_firmware.h"
5390 +#include "pfe/pfe.h"
5392 +static struct elf32_shdr *get_elf_section_header(const struct firmware *fw,
5393 + const char *section)
5395 + struct elf32_hdr *elf_hdr = (struct elf32_hdr *)fw->data;
5396 + struct elf32_shdr *shdr;
5397 + struct elf32_shdr *shdr_shstr;
5398 + Elf32_Off e_shoff = be32_to_cpu(elf_hdr->e_shoff);
5399 + Elf32_Half e_shentsize = be16_to_cpu(elf_hdr->e_shentsize);
5400 + Elf32_Half e_shnum = be16_to_cpu(elf_hdr->e_shnum);
5401 + Elf32_Half e_shstrndx = be16_to_cpu(elf_hdr->e_shstrndx);
5402 + Elf32_Off shstr_offset;
5403 + Elf32_Word sh_name;
5407 + /* Section header strings */
5408 + shdr_shstr = (struct elf32_shdr *)(fw->data + e_shoff + e_shstrndx *
5410 + shstr_offset = be32_to_cpu(shdr_shstr->sh_offset);
5412 + for (i = 0; i < e_shnum; i++) {
5413 + shdr = (struct elf32_shdr *)(fw->data + e_shoff
5414 + + i * e_shentsize);
5416 + sh_name = be32_to_cpu(shdr->sh_name);
5418 + name = (const char *)(fw->data + shstr_offset + sh_name);
5420 + if (!strcmp(name, section))
5424 + pr_err("%s: didn't find section %s\n", __func__, section);
5429 +#if defined(CFG_DIAGS)
5430 +static int pfe_get_diags_info(const struct firmware *fw, struct pfe_diags_info
5433 + struct elf32_shdr *shdr;
5434 + unsigned long offset, size;
5436 + shdr = get_elf_section_header(fw, ".pfe_diags_str");
5438 + offset = be32_to_cpu(shdr->sh_offset);
5439 + size = be32_to_cpu(shdr->sh_size);
5440 + diags_info->diags_str_base = be32_to_cpu(shdr->sh_addr);
5441 + diags_info->diags_str_size = size;
5442 + diags_info->diags_str_array = kmalloc(size, GFP_KERNEL);
5443 + memcpy(diags_info->diags_str_array, fw->data + offset, size);
5452 +static void pfe_check_version_info(const struct firmware *fw)
5454 + /*static char *version = NULL;*/
5455 + static char *version;
5457 + struct elf32_shdr *shdr = get_elf_section_header(fw, ".version");
5462 + * this is the first fw we load, use its version
5463 + * string as reference (whatever it is)
5465 + version = (char *)(fw->data +
5466 + be32_to_cpu(shdr->sh_offset));
5468 + pr_info("PFE binary version: %s\n", version);
5471 + * already have loaded at least one firmware, check
5472 + * sequence can start now
5474 + if (strcmp(version, (char *)(fw->data +
5475 + be32_to_cpu(shdr->sh_offset)))) {
5477 + "WARNING: PFE firmware binaries from incompatible version\n");
5482 + * version cannot be verified, a potential issue that should
5486 + "WARNING: PFE firmware binaries from incompatible version\n");
5490 +/* PFE elf firmware loader.
5491 + * Loads an elf firmware image into a list of PE's (specified using a bitmask)
5493 + * @param pe_mask Mask of PE id's to load firmware to
5494 + * @param fw Pointer to the firmware image
5496 + * @return 0 on success, a negative value on error
5499 +int pfe_load_elf(int pe_mask, const struct firmware *fw, struct pfe *pfe)
5501 + struct elf32_hdr *elf_hdr = (struct elf32_hdr *)fw->data;
5502 + Elf32_Half sections = be16_to_cpu(elf_hdr->e_shnum);
5503 + struct elf32_shdr *shdr = (struct elf32_shdr *)(fw->data +
5504 + be32_to_cpu(elf_hdr->e_shoff));
5508 + pr_info("%s\n", __func__);
5510 + /* Some sanity checks */
5511 + if (strncmp(&elf_hdr->e_ident[EI_MAG0], ELFMAG, SELFMAG)) {
5512 + pr_err("%s: incorrect elf magic number\n", __func__);
5516 + if (elf_hdr->e_ident[EI_CLASS] != ELFCLASS32) {
5517 + pr_err("%s: incorrect elf class(%x)\n", __func__,
5518 + elf_hdr->e_ident[EI_CLASS]);
5522 + if (elf_hdr->e_ident[EI_DATA] != ELFDATA2MSB) {
5523 + pr_err("%s: incorrect elf data(%x)\n", __func__,
5524 + elf_hdr->e_ident[EI_DATA]);
5528 + if (be16_to_cpu(elf_hdr->e_type) != ET_EXEC) {
5529 + pr_err("%s: incorrect elf file type(%x)\n", __func__,
5530 + be16_to_cpu(elf_hdr->e_type));
5534 + for (section = 0; section < sections; section++, shdr++) {
5535 + if (!(be32_to_cpu(shdr->sh_flags) & (SHF_WRITE | SHF_ALLOC |
5539 + for (id = 0; id < MAX_PE; id++)
5540 + if (pe_mask & (1 << id)) {
5541 + rc = pe_load_elf_section(id, fw->data, shdr,
5548 + pfe_check_version_info(fw);
5556 +/* PFE firmware initialization.
5557 + * Loads different firmware files from filesystem.
5558 + * Initializes PE IMEM/DMEM and UTIL-PE DDR
5559 + * Initializes control path symbol addresses (by looking them up in the elf
5561 + * Takes PE's out of reset
5563 + * @return 0 on success, a negative value on error
5566 +int pfe_firmware_init(struct pfe *pfe)
5568 + const struct firmware *class_fw, *tmu_fw;
5570 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
5571 + const char *util_fw_name;
5572 + const struct firmware *util_fw;
5575 + pr_info("%s\n", __func__);
5577 + if (request_firmware(&class_fw, CLASS_FIRMWARE_FILENAME, pfe->dev)) {
5578 + pr_err("%s: request firmware %s failed\n", __func__,
5579 + CLASS_FIRMWARE_FILENAME);
5584 + if (request_firmware(&tmu_fw, TMU_FIRMWARE_FILENAME, pfe->dev)) {
5585 + pr_err("%s: request firmware %s failed\n", __func__,
5586 + TMU_FIRMWARE_FILENAME);
5591 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
5592 + util_fw_name = UTIL_FIRMWARE_FILENAME;
5594 + if (request_firmware(&util_fw, util_fw_name, pfe->dev)) {
5595 + pr_err("%s: request firmware %s failed\n", __func__,
5601 + rc = pfe_load_elf(CLASS_MASK, class_fw, pfe);
5603 + pr_err("%s: class firmware load failed\n", __func__);
5607 +#if defined(CFG_DIAGS)
5608 + rc = pfe_get_diags_info(class_fw, &pfe->diags.class_diags_info);
5611 + "PFE diags won't be available for class PEs\n");
5616 + rc = pfe_load_elf(TMU_MASK, tmu_fw, pfe);
5618 + pr_err("%s: tmu firmware load failed\n", __func__);
5622 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
5623 + rc = pfe_load_elf(UTIL_MASK, util_fw, pfe);
5625 + pr_err("%s: util firmware load failed\n", __func__);
5629 +#if defined(CFG_DIAGS)
5630 + rc = pfe_get_diags_info(util_fw, &pfe->diags.util_diags_info);
5633 + "PFE diags won't be available for util PE\n");
5645 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
5646 + release_firmware(util_fw);
5650 + release_firmware(tmu_fw);
5653 + release_firmware(class_fw);
5659 +/* PFE firmware cleanup
5660 + * Puts PE's in reset
5664 +void pfe_firmware_exit(struct pfe *pfe)
5666 + pr_info("%s\n", __func__);
5668 + if (pe_reset_all(&pfe->ctrl) != 0)
5669 + pr_err("Error: Failed to stop PEs, PFE reload may not work correctly\n");
5673 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
5678 +++ b/drivers/staging/fsl_ppfe/pfe_firmware.h
5680 +/* SPDX-License-Identifier: GPL-2.0+ */
5682 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
5683 + * Copyright 2017 NXP
5686 +#ifndef _PFE_FIRMWARE_H_
5687 +#define _PFE_FIRMWARE_H_
5689 +#define CLASS_FIRMWARE_FILENAME "ppfe_class_ls1012a.elf"
5690 +#define TMU_FIRMWARE_FILENAME "ppfe_tmu_ls1012a.elf"
5692 +#define PFE_FW_CHECK_PASS 0
5693 +#define PFE_FW_CHECK_FAIL 1
5694 +#define NUM_PFE_FW 3
5696 +int pfe_firmware_init(struct pfe *pfe);
5697 +void pfe_firmware_exit(struct pfe *pfe);
5699 +#endif /* _PFE_FIRMWARE_H_ */
5701 +++ b/drivers/staging/fsl_ppfe/pfe_hal.c
5703 +// SPDX-License-Identifier: GPL-2.0+
5705 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
5706 + * Copyright 2017 NXP
5709 +#include "pfe_mod.h"
5710 +#include "pfe/pfe.h"
5712 +/* A-010897: Jumbo frame is not supported */
5713 +extern bool pfe_errata_a010897;
5715 +#define PFE_RCR_MAX_FL_MASK 0xC000FFFF
5717 +void *cbus_base_addr;
5718 +void *ddr_base_addr;
5719 +unsigned long ddr_phys_base_addr;
5720 +unsigned int ddr_size;
5722 +static struct pe_info pe[MAX_PE];
5724 +/* Initializes the PFE library.
5725 + * Must be called before using any of the library functions.
5727 + * @param[in] cbus_base CBUS virtual base address (as mapped in
5728 + * the host CPU address space)
5729 + * @param[in] ddr_base PFE DDR range virtual base address (as
5730 + * mapped in the host CPU address space)
5731 + * @param[in] ddr_phys_base PFE DDR range physical base address (as
5732 + * mapped in platform)
5733 + * @param[in] size PFE DDR range size (as defined by the host
5736 +void pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
5737 + unsigned int size)
5739 + cbus_base_addr = cbus_base;
5740 + ddr_base_addr = ddr_base;
5741 + ddr_phys_base_addr = ddr_phys_base;
5744 + pe[CLASS0_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(0);
5745 + pe[CLASS0_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(0);
5746 + pe[CLASS0_ID].pmem_size = CLASS_IMEM_SIZE;
5747 + pe[CLASS0_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
5748 + pe[CLASS0_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
5749 + pe[CLASS0_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
5751 + pe[CLASS1_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(1);
5752 + pe[CLASS1_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(1);
5753 + pe[CLASS1_ID].pmem_size = CLASS_IMEM_SIZE;
5754 + pe[CLASS1_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
5755 + pe[CLASS1_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
5756 + pe[CLASS1_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
5758 + pe[CLASS2_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(2);
5759 + pe[CLASS2_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(2);
5760 + pe[CLASS2_ID].pmem_size = CLASS_IMEM_SIZE;
5761 + pe[CLASS2_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
5762 + pe[CLASS2_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
5763 + pe[CLASS2_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
5765 + pe[CLASS3_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(3);
5766 + pe[CLASS3_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(3);
5767 + pe[CLASS3_ID].pmem_size = CLASS_IMEM_SIZE;
5768 + pe[CLASS3_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
5769 + pe[CLASS3_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
5770 + pe[CLASS3_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
5772 + pe[CLASS4_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(4);
5773 + pe[CLASS4_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(4);
5774 + pe[CLASS4_ID].pmem_size = CLASS_IMEM_SIZE;
5775 + pe[CLASS4_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
5776 + pe[CLASS4_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
5777 + pe[CLASS4_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
5779 + pe[CLASS5_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(5);
5780 + pe[CLASS5_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(5);
5781 + pe[CLASS5_ID].pmem_size = CLASS_IMEM_SIZE;
5782 + pe[CLASS5_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
5783 + pe[CLASS5_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
5784 + pe[CLASS5_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
5786 + pe[TMU0_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(0);
5787 + pe[TMU0_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(0);
5788 + pe[TMU0_ID].pmem_size = TMU_IMEM_SIZE;
5789 + pe[TMU0_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
5790 + pe[TMU0_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
5791 + pe[TMU0_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
5793 + pe[TMU1_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(1);
5794 + pe[TMU1_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(1);
5795 + pe[TMU1_ID].pmem_size = TMU_IMEM_SIZE;
5796 + pe[TMU1_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
5797 + pe[TMU1_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
5798 + pe[TMU1_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
5800 + pe[TMU3_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(3);
5801 + pe[TMU3_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(3);
5802 + pe[TMU3_ID].pmem_size = TMU_IMEM_SIZE;
5803 + pe[TMU3_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
5804 + pe[TMU3_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
5805 + pe[TMU3_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
5807 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
5808 + pe[UTIL_ID].dmem_base_addr = UTIL_DMEM_BASE_ADDR;
5809 + pe[UTIL_ID].mem_access_wdata = UTIL_MEM_ACCESS_WDATA;
5810 + pe[UTIL_ID].mem_access_addr = UTIL_MEM_ACCESS_ADDR;
5811 + pe[UTIL_ID].mem_access_rdata = UTIL_MEM_ACCESS_RDATA;
5815 +/* Writes a buffer to PE internal memory from the host
5816 + * through indirect access registers.
5818 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
5820 + * @param[in] src Buffer source address
5821 + * @param[in] mem_access_addr DMEM destination address (must be 32bit
5823 + * @param[in] len Number of bytes to copy
5825 +void pe_mem_memcpy_to32(int id, u32 mem_access_addr, const void *src, unsigned
5828 + u32 offset = 0, val, addr;
5829 + unsigned int len32 = len >> 2;
5832 + addr = mem_access_addr | PE_MEM_ACCESS_WRITE |
5833 + PE_MEM_ACCESS_BYTE_ENABLE(0, 4);
5835 + for (i = 0; i < len32; i++, offset += 4, src += 4) {
5836 + val = *(u32 *)src;
5837 + writel(cpu_to_be32(val), pe[id].mem_access_wdata);
5838 + writel(addr + offset, pe[id].mem_access_addr);
5841 + len = (len & 0x3);
5845 + addr = (mem_access_addr | PE_MEM_ACCESS_WRITE |
5846 + PE_MEM_ACCESS_BYTE_ENABLE(0, len)) + offset;
5848 + for (i = 0; i < len; i++, src++)
5849 + val |= (*(u8 *)src) << (8 * i);
5851 + writel(cpu_to_be32(val), pe[id].mem_access_wdata);
5852 + writel(addr, pe[id].mem_access_addr);
5856 +/* Writes a buffer to PE internal data memory (DMEM) from the host
5857 + * through indirect access registers.
5858 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
5860 + * @param[in] src Buffer source address
5861 + * @param[in] dst DMEM destination address (must be 32bit
5863 + * @param[in] len Number of bytes to copy
5865 +void pe_dmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len)
5867 + pe_mem_memcpy_to32(id, pe[id].dmem_base_addr | dst |
5868 + PE_MEM_ACCESS_DMEM, src, len);
5871 +/* Writes a buffer to PE internal program memory (PMEM) from the host
5872 + * through indirect access registers.
5873 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
5875 + * @param[in] src Buffer source address
5876 + * @param[in] dst PMEM destination address (must be 32bit
5878 + * @param[in] len Number of bytes to copy
5880 +void pe_pmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len)
5882 + pe_mem_memcpy_to32(id, pe[id].pmem_base_addr | (dst & (pe[id].pmem_size
5883 + - 1)) | PE_MEM_ACCESS_IMEM, src, len);
5886 +/* Reads PE internal program memory (IMEM) from the host
5887 + * through indirect access registers.
5888 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
5890 + * @param[in] addr PMEM read address (must be aligned on size)
5891 + * @param[in] size Number of bytes to read (maximum 4, must not
5892 + * cross 32bit boundaries)
5893 + * @return the data read (in PE endianness, i.e BE).
5895 +u32 pe_pmem_read(int id, u32 addr, u8 size)
5897 + u32 offset = addr & 0x3;
5898 + u32 mask = 0xffffffff >> ((4 - size) << 3);
5901 + addr = pe[id].pmem_base_addr | ((addr & ~0x3) & (pe[id].pmem_size - 1))
5902 + | PE_MEM_ACCESS_IMEM | PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
5904 + writel(addr, pe[id].mem_access_addr);
5905 + val = be32_to_cpu(readl(pe[id].mem_access_rdata));
5907 + return (val >> (offset << 3)) & mask;
5910 +/* Writes PE internal data memory (DMEM) from the host
5911 + * through indirect access registers.
5912 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
5914 + * @param[in] addr DMEM write address (must be aligned on size)
5915 + * @param[in] val Value to write (in PE endianness, i.e BE)
5916 + * @param[in] size Number of bytes to write (maximum 4, must not
5917 + * cross 32bit boundaries)
5919 +void pe_dmem_write(int id, u32 val, u32 addr, u8 size)
5921 + u32 offset = addr & 0x3;
5923 + addr = pe[id].dmem_base_addr | (addr & ~0x3) | PE_MEM_ACCESS_WRITE |
5924 + PE_MEM_ACCESS_DMEM | PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
5926 + /* Indirect access interface is byte swapping data being written */
5927 + writel(cpu_to_be32(val << (offset << 3)), pe[id].mem_access_wdata);
5928 + writel(addr, pe[id].mem_access_addr);
5931 +/* Reads PE internal data memory (DMEM) from the host
5932 + * through indirect access registers.
5933 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
5935 + * @param[in] addr DMEM read address (must be aligned on size)
5936 + * @param[in] size Number of bytes to read (maximum 4, must not
5937 + * cross 32bit boundaries)
5938 + * @return the data read (in PE endianness, i.e BE).
5940 +u32 pe_dmem_read(int id, u32 addr, u8 size)
5942 + u32 offset = addr & 0x3;
5943 + u32 mask = 0xffffffff >> ((4 - size) << 3);
5946 + addr = pe[id].dmem_base_addr | (addr & ~0x3) | PE_MEM_ACCESS_DMEM |
5947 + PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
5949 + writel(addr, pe[id].mem_access_addr);
5951 + /* Indirect access interface is byte swapping data being read */
5952 + val = be32_to_cpu(readl(pe[id].mem_access_rdata));
5954 + return (val >> (offset << 3)) & mask;
5957 +/* This function is used to write to CLASS internal bus peripherals (ccu,
5958 + * pe-lem) from the host
5959 + * through indirect access registers.
5960 + * @param[in] val value to write
5961 + * @param[in] addr Address to write to (must be aligned on size)
5962 + * @param[in] size Number of bytes to write (1, 2 or 4)
5965 +void class_bus_write(u32 val, u32 addr, u8 size)
5967 + u32 offset = addr & 0x3;
5969 + writel((addr & CLASS_BUS_ACCESS_BASE_MASK), CLASS_BUS_ACCESS_BASE);
5971 + addr = (addr & ~CLASS_BUS_ACCESS_BASE_MASK) | PE_MEM_ACCESS_WRITE |
5974 + writel(cpu_to_be32(val << (offset << 3)), CLASS_BUS_ACCESS_WDATA);
5975 + writel(addr, CLASS_BUS_ACCESS_ADDR);
5978 +/* Reads from CLASS internal bus peripherals (ccu, pe-lem) from the host
5979 + * through indirect access registers.
5980 + * @param[in] addr Address to read from (must be aligned on size)
5981 + * @param[in] size Number of bytes to read (1, 2 or 4)
5982 + * @return the read data
5985 +u32 class_bus_read(u32 addr, u8 size)
5987 + u32 offset = addr & 0x3;
5988 + u32 mask = 0xffffffff >> ((4 - size) << 3);
5991 + writel((addr & CLASS_BUS_ACCESS_BASE_MASK), CLASS_BUS_ACCESS_BASE);
5993 + addr = (addr & ~CLASS_BUS_ACCESS_BASE_MASK) | (size << 24);
5995 + writel(addr, CLASS_BUS_ACCESS_ADDR);
5996 + val = be32_to_cpu(readl(CLASS_BUS_ACCESS_RDATA));
5998 + return (val >> (offset << 3)) & mask;
6001 +/* Writes data to the cluster memory (PE_LMEM)
6002 + * @param[in] dst PE LMEM destination address (must be 32bit aligned)
6003 + * @param[in] src Buffer source address
6004 + * @param[in] len Number of bytes to copy
6006 +void class_pe_lmem_memcpy_to32(u32 dst, const void *src, unsigned int len)
6008 + u32 len32 = len >> 2;
6011 + for (i = 0; i < len32; i++, src += 4, dst += 4)
6012 + class_bus_write(*(u32 *)src, dst, 4);
6015 + class_bus_write(*(u16 *)src, dst, 2);
6021 + class_bus_write(*(u8 *)src, dst, 1);
6027 +/* Writes value to the cluster memory (PE_LMEM)
6028 + * @param[in] dst PE LMEM destination address (must be 32bit aligned)
6029 + * @param[in] val Value to write
6030 + * @param[in] len Number of bytes to write
6032 +void class_pe_lmem_memset(u32 dst, int val, unsigned int len)
6034 + u32 len32 = len >> 2;
6037 + val = val | (val << 8) | (val << 16) | (val << 24);
6039 + for (i = 0; i < len32; i++, dst += 4)
6040 + class_bus_write(val, dst, 4);
6043 + class_bus_write(val, dst, 2);
6048 + class_bus_write(val, dst, 1);
6053 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6055 +/* Writes UTIL program memory (DDR) from the host.
6057 + * @param[in] addr Address to write (virtual, must be aligned on size)
6058 + * @param[in] val Value to write (in PE endianness, i.e BE)
6059 + * @param[in] size Number of bytes to write (2 or 4)
6061 +static void util_pmem_write(u32 val, void *addr, u8 size)
6063 + void *addr64 = (void *)((unsigned long)addr & ~0x7);
6064 + unsigned long off = 8 - ((unsigned long)addr & 0x7) - size;
6067 + * IMEM should be loaded as a 64bit swapped value in a 64bit aligned
6071 + writel(be32_to_cpu(val), addr64 + off);
6073 + writew(be16_to_cpu((u16)val), addr64 + off);
6076 +/* Writes a buffer to UTIL program memory (DDR) from the host.
6078 + * @param[in] dst Address to write (virtual, must be at least 16bit
6080 + * @param[in] src Buffer to write (in PE endianness, i.e BE, must have
6081 + * same alignment as dst)
6082 + * @param[in] len Number of bytes to write (must be at least 16bit
6085 +static void util_pmem_memcpy(void *dst, const void *src, unsigned int len)
6087 + unsigned int len32;
6090 + if ((unsigned long)src & 0x2) {
6091 + util_pmem_write(*(u16 *)src, dst, 2);
6099 + for (i = 0; i < len32; i++, dst += 4, src += 4)
6100 + util_pmem_write(*(u32 *)src, dst, 4);
6103 + util_pmem_write(*(u16 *)src, dst, len & 0x2);
6107 +/* Loads an elf section into pmem
6108 + * Code needs to be at least 16bit aligned and only PROGBITS sections are
6111 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID, ...,
6113 + * @param[in] data pointer to the elf firmware
6114 + * @param[in] shdr pointer to the elf section header
6117 +static int pe_load_pmem_section(int id, const void *data,
6118 + struct elf32_shdr *shdr)
6120 + u32 offset = be32_to_cpu(shdr->sh_offset);
6121 + u32 addr = be32_to_cpu(shdr->sh_addr);
6122 + u32 size = be32_to_cpu(shdr->sh_size);
6123 + u32 type = be32_to_cpu(shdr->sh_type);
6125 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6126 + if (id == UTIL_ID) {
6127 + pr_err("%s: unsupported pmem section for UTIL\n",
6133 + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
6135 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
6136 + , __func__, addr, (unsigned long)data + offset);
6142 + pr_err("%s: load address(%x) is not 16bit aligned\n",
6148 + pr_err("%s: load size(%x) is not 16bit aligned\n",
6154 + case SHT_PROGBITS:
6155 + pe_pmem_memcpy_to32(id, addr, data + offset, size);
6160 + pr_err("%s: unsupported section type(%x)\n", __func__,
6168 +/* Loads an elf section into dmem
6169 + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
6170 + * initialized to 0
6172 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6174 + * @param[in] data pointer to the elf firmware
6175 + * @param[in] shdr pointer to the elf section header
6178 +static int pe_load_dmem_section(int id, const void *data,
6179 + struct elf32_shdr *shdr)
6181 + u32 offset = be32_to_cpu(shdr->sh_offset);
6182 + u32 addr = be32_to_cpu(shdr->sh_addr);
6183 + u32 size = be32_to_cpu(shdr->sh_size);
6184 + u32 type = be32_to_cpu(shdr->sh_type);
6185 + u32 size32 = size >> 2;
6188 + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
6190 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n",
6191 + __func__, addr, (unsigned long)data + offset);
6197 + pr_err("%s: load address(%x) is not 32bit aligned\n",
6203 + case SHT_PROGBITS:
6204 + pe_dmem_memcpy_to32(id, addr, data + offset, size);
6208 + for (i = 0; i < size32; i++, addr += 4)
6209 + pe_dmem_write(id, 0, addr, 4);
6212 + pe_dmem_write(id, 0, addr, size & 0x3);
6217 + pr_err("%s: unsupported section type(%x)\n", __func__,
6225 +/* Loads an elf section into DDR
6226 + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
6227 + * initialized to 0
6229 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6231 + * @param[in] data pointer to the elf firmware
6232 + * @param[in] shdr pointer to the elf section header
6235 +static int pe_load_ddr_section(int id, const void *data,
6236 + struct elf32_shdr *shdr,
6237 + struct device *dev) {
6238 + u32 offset = be32_to_cpu(shdr->sh_offset);
6239 + u32 addr = be32_to_cpu(shdr->sh_addr);
6240 + u32 size = be32_to_cpu(shdr->sh_size);
6241 + u32 type = be32_to_cpu(shdr->sh_type);
6242 + u32 flags = be32_to_cpu(shdr->sh_flags);
6245 + case SHT_PROGBITS:
6246 + if (flags & SHF_EXECINSTR) {
6247 + if (id <= CLASS_MAX_ID) {
6248 + /* DO the loading only once in DDR */
6249 + if (id == CLASS0_ID) {
6251 + "%s: load address(%x) and elf file address(%lx) rcvd\n",
6253 + (unsigned long)data + offset);
6254 + if (((unsigned long)(data + offset)
6255 + & 0x3) != (addr & 0x3)) {
6257 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
6259 + (unsigned long)data + offset);
6266 + "%s: load address(%x) is not 16bit aligned\n"
6267 + , __func__, addr);
6273 + "%s: load length(%x) is not 16bit aligned\n"
6274 + , __func__, size);
6277 + memcpy(DDR_PHYS_TO_VIRT(
6278 + DDR_PFE_TO_PHYS(addr)),
6279 + data + offset, size);
6281 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6282 + } else if (id == UTIL_ID) {
6283 + if (((unsigned long)(data + offset) & 0x3)
6284 + != (addr & 0x3)) {
6286 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
6288 + (unsigned long)data + offset);
6295 + "%s: load address(%x) is not 16bit aligned\n"
6296 + , __func__, addr);
6302 + "%s: load length(%x) is not 16bit aligned\n"
6303 + , __func__, size);
6307 + util_pmem_memcpy(DDR_PHYS_TO_VIRT(
6308 + DDR_PFE_TO_PHYS(addr)),
6309 + data + offset, size);
6314 + "%s: unsupported ddr section type(%x) for PE(%d)\n"
6315 + , __func__, type, id);
6320 + memcpy(DDR_PHYS_TO_VIRT(DDR_PFE_TO_PHYS(addr)), data
6327 + memset(DDR_PHYS_TO_VIRT(DDR_PFE_TO_PHYS(addr)), 0, size);
6332 + pr_err("%s: unsupported section type(%x)\n", __func__,
6340 +/* Loads an elf section into pe lmem
6341 + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
6342 + * initialized to 0
6344 + * @param[in] id PE identification (CLASS0_ID,..., CLASS5_ID)
6345 + * @param[in] data pointer to the elf firmware
6346 + * @param[in] shdr pointer to the elf section header
6349 +static int pe_load_pe_lmem_section(int id, const void *data,
6350 + struct elf32_shdr *shdr)
6352 + u32 offset = be32_to_cpu(shdr->sh_offset);
6353 + u32 addr = be32_to_cpu(shdr->sh_addr);
6354 + u32 size = be32_to_cpu(shdr->sh_size);
6355 + u32 type = be32_to_cpu(shdr->sh_type);
6357 + if (id > CLASS_MAX_ID) {
6359 + "%s: unsupported pe-lmem section type(%x) for PE(%d)\n",
6360 + __func__, type, id);
6364 + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
6366 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n",
6367 + __func__, addr, (unsigned long)data + offset);
6373 + pr_err("%s: load address(%x) is not 32bit aligned\n",
6379 + case SHT_PROGBITS:
6380 + class_pe_lmem_memcpy_to32(addr, data + offset, size);
6384 + class_pe_lmem_memset(addr, 0, size);
6388 + pr_err("%s: unsupported section type(%x)\n", __func__,
6396 +/* Loads an elf section into a PE
6397 + * For now only supports loading a section to dmem (all PE's), pmem (class and
6399 + * DDDR (util PE code)
6401 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6403 + * @param[in] data pointer to the elf firmware
6404 + * @param[in] shdr pointer to the elf section header
6407 +int pe_load_elf_section(int id, const void *data, struct elf32_shdr *shdr,
6408 + struct device *dev) {
6409 + u32 addr = be32_to_cpu(shdr->sh_addr);
6410 + u32 size = be32_to_cpu(shdr->sh_size);
6412 + if (IS_DMEM(addr, size))
6413 + return pe_load_dmem_section(id, data, shdr);
6414 + else if (IS_PMEM(addr, size))
6415 + return pe_load_pmem_section(id, data, shdr);
6416 + else if (IS_PFE_LMEM(addr, size))
6418 + else if (IS_PHYS_DDR(addr, size))
6419 + return pe_load_ddr_section(id, data, shdr, dev);
6420 + else if (IS_PE_LMEM(addr, size))
6421 + return pe_load_pe_lmem_section(id, data, shdr);
6423 + pr_err("%s: unsupported memory range(%x)\n", __func__,
6428 +/**************************** BMU ***************************/
6430 +/* Initializes a BMU block.
6431 + * @param[in] base BMU block base address
6432 + * @param[in] cfg BMU configuration
6434 +void bmu_init(void *base, struct BMU_CFG *cfg)
6436 + bmu_disable(base);
6438 + bmu_set_config(base, cfg);
6443 +/* Resets a BMU block.
6444 + * @param[in] base BMU block base address
6446 +void bmu_reset(void *base)
6448 + writel(CORE_SW_RESET, base + BMU_CTRL);
6450 + /* Wait for self clear */
6451 + while (readl(base + BMU_CTRL) & CORE_SW_RESET)
6455 +/* Enabled a BMU block.
6456 + * @param[in] base BMU block base address
6458 +void bmu_enable(void *base)
6460 + writel(CORE_ENABLE, base + BMU_CTRL);
6463 +/* Disables a BMU block.
6464 + * @param[in] base BMU block base address
6466 +void bmu_disable(void *base)
6468 + writel(CORE_DISABLE, base + BMU_CTRL);
6471 +/* Sets the configuration of a BMU block.
6472 + * @param[in] base BMU block base address
6473 + * @param[in] cfg BMU configuration
6475 +void bmu_set_config(void *base, struct BMU_CFG *cfg)
6477 + writel(cfg->baseaddr, base + BMU_UCAST_BASE_ADDR);
6478 + writel(cfg->count & 0xffff, base + BMU_UCAST_CONFIG);
6479 + writel(cfg->size & 0xffff, base + BMU_BUF_SIZE);
6481 + /* Interrupts are never used */
6482 + writel(cfg->low_watermark, base + BMU_LOW_WATERMARK);
6483 + writel(cfg->high_watermark, base + BMU_HIGH_WATERMARK);
6484 + writel(0x0, base + BMU_INT_ENABLE);
6487 +/**************************** MTIP GEMAC ***************************/
6489 +/* Enable Rx Checksum Engine. With this enabled, Frame with bad IP,
6490 + * TCP or UDP checksums are discarded
6492 + * @param[in] base GEMAC base address.
6494 +void gemac_enable_rx_checksum_offload(void *base)
6496 + /*Do not find configuration to do this */
6499 +/* Disable Rx Checksum Engine.
6501 + * @param[in] base GEMAC base address.
6503 +void gemac_disable_rx_checksum_offload(void *base)
6505 + /*Do not find configuration to do this */
6508 +/* GEMAC set speed.
6509 + * @param[in] base GEMAC base address
6510 + * @param[in] speed GEMAC speed (10, 100 or 1000 Mbps)
6512 +void gemac_set_speed(void *base, enum mac_speed gem_speed)
6514 + u32 ecr = readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_SPEED;
6515 + u32 rcr = readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_RMII_10T;
6517 + switch (gem_speed) {
6519 + rcr |= EMAC_RCNTRL_RMII_10T;
6523 + ecr |= EMAC_ECNTRL_SPEED;
6528 + /*It is in 100M mode */
6531 + writel(ecr, (base + EMAC_ECNTRL_REG));
6532 + writel(rcr, (base + EMAC_RCNTRL_REG));
6535 +/* GEMAC set duplex.
6536 + * @param[in] base GEMAC base address
6537 + * @param[in] duplex GEMAC duplex mode (Full, Half)
6539 +void gemac_set_duplex(void *base, int duplex)
6541 + if (duplex == DUPLEX_HALF) {
6542 + writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_FDEN, base
6543 + + EMAC_TCNTRL_REG);
6544 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_DRT, (base
6545 + + EMAC_RCNTRL_REG));
6547 + writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_FDEN, base
6548 + + EMAC_TCNTRL_REG);
6549 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_DRT, (base
6550 + + EMAC_RCNTRL_REG));
6555 + * @param[in] base GEMAC base address
6556 + * @param[in] mode GEMAC operation mode (MII, RMII, RGMII, SGMII)
6558 +void gemac_set_mode(void *base, int mode)
6560 + u32 val = readl(base + EMAC_RCNTRL_REG);
6562 + /*Remove loopbank*/
6563 + val &= ~EMAC_RCNTRL_LOOP;
6565 + /* Enable flow control and MII mode and terminate received CRC */
6566 + val |= (EMAC_RCNTRL_FCE | EMAC_RCNTRL_MII_MODE | EMAC_RCNTRL_CRC_FWD);
6568 + writel(val, base + EMAC_RCNTRL_REG);
6571 +/* GEMAC enable function.
6572 + * @param[in] base GEMAC base address
6574 +void gemac_enable(void *base)
6576 + writel(readl(base + EMAC_ECNTRL_REG) | EMAC_ECNTRL_ETHER_EN, base +
6580 +/* GEMAC disable function.
6581 + * @param[in] base GEMAC base address
6583 +void gemac_disable(void *base)
6585 + writel(readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_ETHER_EN, base +
6589 +/* GEMAC TX disable function.
6590 + * @param[in] base GEMAC base address
6592 +void gemac_tx_disable(void *base)
6594 + writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_GTS, base +
6598 +void gemac_tx_enable(void *base)
6600 + writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_GTS, base +
6604 +/* Sets the hash register of the MAC.
6605 + * This register is used for matching unicast and multicast frames.
6607 + * @param[in] base GEMAC base address.
6608 + * @param[in] hash 64-bit hash to be configured.
6610 +void gemac_set_hash(void *base, struct pfe_mac_addr *hash)
6612 + writel(hash->bottom, base + EMAC_GALR);
6613 + writel(hash->top, base + EMAC_GAUR);
6616 +void gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
6617 + unsigned int entry_index)
6619 + if ((entry_index < 1) || (entry_index > EMAC_SPEC_ADDR_MAX))
6622 + entry_index = entry_index - 1;
6623 + if (entry_index < 1) {
6624 + writel(htonl(address->bottom), base + EMAC_PHY_ADDR_LOW);
6625 + writel((htonl(address->top) | 0x8808), base +
6626 + EMAC_PHY_ADDR_HIGH);
6628 + writel(htonl(address->bottom), base + ((entry_index - 1) * 8)
6630 + writel((htonl(address->top) | 0x8808), base + ((entry_index -
6631 + 1) * 8) + EMAC_SMAC_0_1);
6635 +void gemac_clear_laddrN(void *base, unsigned int entry_index)
6637 + if ((entry_index < 1) || (entry_index > EMAC_SPEC_ADDR_MAX))
6640 + entry_index = entry_index - 1;
6641 + if (entry_index < 1) {
6642 + writel(0, base + EMAC_PHY_ADDR_LOW);
6643 + writel(0, base + EMAC_PHY_ADDR_HIGH);
6645 + writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_0);
6646 + writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_1);
6650 +/* Set the loopback mode of the MAC. This can be either no loopback for
6651 + * normal operation, local loopback through MAC internal loopback module or PHY
6652 + * loopback for external loopback through a PHY. This asserts the external
6655 + * @param[in] base GEMAC base address.
6656 + * @param[in] gem_loop Loopback mode to be enabled. LB_LOCAL - MAC
6658 + * LB_EXT - PHY Loopback.
6660 +void gemac_set_loop(void *base, enum mac_loop gem_loop)
6662 + pr_info("%s()\n", __func__);
6663 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_LOOP, (base +
6664 + EMAC_RCNTRL_REG));
6667 +/* GEMAC allow frames
6668 + * @param[in] base GEMAC base address
6670 +void gemac_enable_copy_all(void *base)
6672 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_PROM, (base +
6673 + EMAC_RCNTRL_REG));
6676 +/* GEMAC do not allow frames
6677 + * @param[in] base GEMAC base address
6679 +void gemac_disable_copy_all(void *base)
6681 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_PROM, (base +
6682 + EMAC_RCNTRL_REG));
6685 +/* GEMAC allow broadcast function.
6686 + * @param[in] base GEMAC base address
6688 +void gemac_allow_broadcast(void *base)
6690 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_BC_REJ, base +
6694 +/* GEMAC no broadcast function.
6695 + * @param[in] base GEMAC base address
6697 +void gemac_no_broadcast(void *base)
6699 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_BC_REJ, base +
6703 +/* GEMAC enable 1536 rx function.
6704 + * @param[in] base GEMAC base address
6706 +void gemac_enable_1536_rx(void *base)
6708 + /* Set 1536 as Maximum frame length */
6709 + writel((readl(base + EMAC_RCNTRL_REG) & PFE_RCR_MAX_FL_MASK)
6710 + | (1536 << 16), base + EMAC_RCNTRL_REG);
6713 +/* GEMAC set rx Max frame length.
6714 + * @param[in] base GEMAC base address
6715 + * @param[in] mtu new mtu
6717 +void gemac_set_rx_max_fl(void *base, int mtu)
6719 + /* Set mtu as Maximum frame length */
6720 + writel((readl(base + EMAC_RCNTRL_REG) & PFE_RCR_MAX_FL_MASK)
6721 + | (mtu << 16), base + EMAC_RCNTRL_REG);
6724 +/* GEMAC enable stacked vlan function.
6725 + * @param[in] base GEMAC base address
6727 +void gemac_enable_stacked_vlan(void *base)
6729 + /* MTIP doesn't support stacked vlan */
6732 +/* GEMAC enable pause rx function.
6733 + * @param[in] base GEMAC base address
6735 +void gemac_enable_pause_rx(void *base)
6737 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_FCE,
6738 + base + EMAC_RCNTRL_REG);
6741 +/* GEMAC disable pause rx function.
6742 + * @param[in] base GEMAC base address
6744 +void gemac_disable_pause_rx(void *base)
6746 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_FCE,
6747 + base + EMAC_RCNTRL_REG);
6750 +/* GEMAC enable pause tx function.
6751 + * @param[in] base GEMAC base address
6753 +void gemac_enable_pause_tx(void *base)
6755 + writel(EMAC_RX_SECTION_EMPTY_V, base + EMAC_RX_SECTION_EMPTY);
6758 +/* GEMAC disable pause tx function.
6759 + * @param[in] base GEMAC base address
6761 +void gemac_disable_pause_tx(void *base)
6763 + writel(0x0, base + EMAC_RX_SECTION_EMPTY);
6766 +/* GEMAC wol configuration
6767 + * @param[in] base GEMAC base address
6768 + * @param[in] wol_conf WoL register configuration
6770 +void gemac_set_wol(void *base, u32 wol_conf)
6772 + u32 val = readl(base + EMAC_ECNTRL_REG);
6775 + val |= (EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
6777 + val &= ~(EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
6778 + writel(val, base + EMAC_ECNTRL_REG);
6781 +/* Sets Gemac bus width to 64bit
6782 + * @param[in] base GEMAC base address
6783 + * @param[in] width gemac bus width to be set possible values are 32/64/128
6785 +void gemac_set_bus_width(void *base, int width)
6789 +/* Sets Gemac configuration.
6790 + * @param[in] base GEMAC base address
6791 + * @param[in] cfg GEMAC configuration
6793 +void gemac_set_config(void *base, struct gemac_cfg *cfg)
6795 + /*GEMAC config taken from VLSI */
6796 + writel(0x00000004, base + EMAC_TFWR_STR_FWD);
6797 + writel(0x00000005, base + EMAC_RX_SECTION_FULL);
6799 + if (pfe_errata_a010897)
6800 + writel(0x0000076c, base + EMAC_TRUNC_FL);
6802 + writel(0x00003fff, base + EMAC_TRUNC_FL);
6804 + writel(0x00000030, base + EMAC_TX_SECTION_EMPTY);
6805 + writel(0x00000000, base + EMAC_MIB_CTRL_STS_REG);
6807 + gemac_set_mode(base, cfg->mode);
6809 + gemac_set_speed(base, cfg->speed);
6811 + gemac_set_duplex(base, cfg->duplex);
6814 +/**************************** GPI ***************************/
6816 +/* Initializes a GPI block.
6817 + * @param[in] base GPI base address
6818 + * @param[in] cfg GPI configuration
6820 +void gpi_init(void *base, struct gpi_cfg *cfg)
6824 + gpi_disable(base);
6826 + gpi_set_config(base, cfg);
6829 +/* Resets a GPI block.
6830 + * @param[in] base GPI base address
6832 +void gpi_reset(void *base)
6834 + writel(CORE_SW_RESET, base + GPI_CTRL);
6837 +/* Enables a GPI block.
6838 + * @param[in] base GPI base address
6840 +void gpi_enable(void *base)
6842 + writel(CORE_ENABLE, base + GPI_CTRL);
6845 +/* Disables a GPI block.
6846 + * @param[in] base GPI base address
6848 +void gpi_disable(void *base)
6850 + writel(CORE_DISABLE, base + GPI_CTRL);
6853 +/* Sets the configuration of a GPI block.
6854 + * @param[in] base GPI base address
6855 + * @param[in] cfg GPI configuration
6857 +void gpi_set_config(void *base, struct gpi_cfg *cfg)
6859 + writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_ALLOC_CTRL), base
6860 + + GPI_LMEM_ALLOC_ADDR);
6861 + writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_FREE_CTRL), base
6862 + + GPI_LMEM_FREE_ADDR);
6863 + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_ALLOC_CTRL), base
6864 + + GPI_DDR_ALLOC_ADDR);
6865 + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL), base
6866 + + GPI_DDR_FREE_ADDR);
6867 + writel(CBUS_VIRT_TO_PFE(CLASS_INQ_PKTPTR), base + GPI_CLASS_ADDR);
6868 + writel(DDR_HDR_SIZE, base + GPI_DDR_DATA_OFFSET);
6869 + writel(LMEM_HDR_SIZE, base + GPI_LMEM_DATA_OFFSET);
6870 + writel(0, base + GPI_LMEM_SEC_BUF_DATA_OFFSET);
6871 + writel(0, base + GPI_DDR_SEC_BUF_DATA_OFFSET);
6872 + writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, base + GPI_HDR_SIZE);
6873 + writel((DDR_BUF_SIZE << 16) | LMEM_BUF_SIZE, base + GPI_BUF_SIZE);
6875 + writel(((cfg->lmem_rtry_cnt << 16) | (GPI_DDR_BUF_EN << 1) |
6876 + GPI_LMEM_BUF_EN), base + GPI_RX_CONFIG);
6877 + writel(cfg->tmlf_txthres, base + GPI_TMLF_TX);
6878 + writel(cfg->aseq_len, base + GPI_DTX_ASEQ);
6879 + writel(1, base + GPI_TOE_CHKSUM_EN);
6881 + if (cfg->mtip_pause_reg) {
6882 + writel(cfg->mtip_pause_reg, base + GPI_CSR_MTIP_PAUSE_REG);
6883 + writel(EGPI_PAUSE_TIME, base + GPI_TX_PAUSE_TIME);
6887 +/**************************** CLASSIFIER ***************************/
6889 +/* Initializes CLASSIFIER block.
6890 + * @param[in] cfg CLASSIFIER configuration
6892 +void class_init(struct class_cfg *cfg)
6898 + class_set_config(cfg);
6901 +/* Resets CLASSIFIER block.
6904 +void class_reset(void)
6906 + writel(CORE_SW_RESET, CLASS_TX_CTRL);
6909 +/* Enables all CLASS-PE's cores.
6912 +void class_enable(void)
6914 + writel(CORE_ENABLE, CLASS_TX_CTRL);
6917 +/* Disables all CLASS-PE's cores.
6920 +void class_disable(void)
6922 + writel(CORE_DISABLE, CLASS_TX_CTRL);
6926 + * Sets the configuration of the CLASSIFIER block.
6927 + * @param[in] cfg CLASSIFIER configuration
6929 +void class_set_config(struct class_cfg *cfg)
6933 + /* Initialize route table */
6935 + memset(DDR_PHYS_TO_VIRT(cfg->route_table_baseaddr), 0, (1 <<
6936 + cfg->route_table_hash_bits) * CLASS_ROUTE_SIZE);
6938 +#if !defined(LS1012A_PFE_RESET_WA)
6939 + writel(cfg->pe_sys_clk_ratio, CLASS_PE_SYS_CLK_RATIO);
6942 + writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, CLASS_HDR_SIZE);
6943 + writel(LMEM_BUF_SIZE, CLASS_LMEM_BUF_SIZE);
6944 + writel(CLASS_ROUTE_ENTRY_SIZE(CLASS_ROUTE_SIZE) |
6945 + CLASS_ROUTE_HASH_SIZE(cfg->route_table_hash_bits),
6946 + CLASS_ROUTE_HASH_ENTRY_SIZE);
6947 + writel(HIF_PKT_CLASS_EN | HIF_PKT_OFFSET(sizeof(struct hif_hdr)),
6950 + val = HASH_CRC_PORT_IP | QB2BUS_LE;
6952 +#if defined(CONFIG_IP_ALIGNED)
6953 + val |= IP_ALIGNED;
6957 + * Class PE packet steering will only work if TOE mode, bridge fetch or
6958 + * route fetch are enabled (see class/qb_fet.v). Route fetch would
6959 + * trigger additional memory copies (likely from DDR because of hash
6960 + * table size, which cannot be reduced because PE software still
6961 + * relies on hash value computed in HW), so when not in TOE mode we
6962 + * simply enable HW bridge fetch even though we don't use it.
6964 + if (cfg->toe_mode)
6967 + val |= HW_BRIDGE_FETCH;
6969 + writel(val, CLASS_ROUTE_MULTI);
6971 + writel(DDR_PHYS_TO_PFE(cfg->route_table_baseaddr),
6972 + CLASS_ROUTE_TABLE_BASE);
6973 + writel(CLASS_PE0_RO_DM_ADDR0_VAL, CLASS_PE0_RO_DM_ADDR0);
6974 + writel(CLASS_PE0_RO_DM_ADDR1_VAL, CLASS_PE0_RO_DM_ADDR1);
6975 + writel(CLASS_PE0_QB_DM_ADDR0_VAL, CLASS_PE0_QB_DM_ADDR0);
6976 + writel(CLASS_PE0_QB_DM_ADDR1_VAL, CLASS_PE0_QB_DM_ADDR1);
6977 + writel(CBUS_VIRT_TO_PFE(TMU_PHY_INQ_PKTPTR), CLASS_TM_INQ_ADDR);
6979 + writel(23, CLASS_AFULL_THRES);
6980 + writel(23, CLASS_TSQ_FIFO_THRES);
6982 + writel(24, CLASS_MAX_BUF_CNT);
6983 + writel(24, CLASS_TSQ_MAX_CNT);
6986 +/**************************** TMU ***************************/
6988 +void tmu_reset(void)
6990 + writel(SW_RESET, TMU_CTRL);
6993 +/* Initializes TMU block.
6994 + * @param[in] cfg TMU configuration
6996 +void tmu_init(struct tmu_cfg *cfg)
7003 +#if !defined(LS1012A_PFE_RESET_WA)
7004 + /* keep in soft reset */
7005 + writel(SW_RESET, TMU_CTRL);
7007 + writel(0x3, TMU_SYS_GENERIC_CONTROL);
7008 + writel(750, TMU_INQ_WATERMARK);
7009 + writel(CBUS_VIRT_TO_PFE(EGPI1_BASE_ADDR +
7010 + GPI_INQ_PKTPTR), TMU_PHY0_INQ_ADDR);
7011 + writel(CBUS_VIRT_TO_PFE(EGPI2_BASE_ADDR +
7012 + GPI_INQ_PKTPTR), TMU_PHY1_INQ_ADDR);
7013 + writel(CBUS_VIRT_TO_PFE(HGPI_BASE_ADDR +
7014 + GPI_INQ_PKTPTR), TMU_PHY3_INQ_ADDR);
7015 + writel(CBUS_VIRT_TO_PFE(HIF_NOCPY_RX_INQ0_PKTPTR), TMU_PHY4_INQ_ADDR);
7016 + writel(CBUS_VIRT_TO_PFE(UTIL_INQ_PKTPTR), TMU_PHY5_INQ_ADDR);
7017 + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL),
7018 + TMU_BMU_INQ_ADDR);
7020 + writel(0x3FF, TMU_TDQ0_SCH_CTRL); /*
7022 + * schedulers [9:0] of each TDQ
7024 + writel(0x3FF, TMU_TDQ1_SCH_CTRL);
7025 + writel(0x3FF, TMU_TDQ3_SCH_CTRL);
7027 +#if !defined(LS1012A_PFE_RESET_WA)
7028 + writel(cfg->pe_sys_clk_ratio, TMU_PE_SYS_CLK_RATIO);
7031 +#if !defined(LS1012A_PFE_RESET_WA)
7032 + writel(DDR_PHYS_TO_PFE(cfg->llm_base_addr), TMU_LLM_BASE_ADDR);
7033 + /* Extra packet pointers will be stored from this address onwards */
7035 + writel(cfg->llm_queue_len, TMU_LLM_QUE_LEN);
7036 + writel(5, TMU_TDQ_IIFG_CFG);
7037 + writel(DDR_BUF_SIZE, TMU_BMU_BUF_SIZE);
7039 + writel(0x0, TMU_CTRL);
7042 + pr_info("%s: mem init\n", __func__);
7043 + writel(MEM_INIT, TMU_CTRL);
7045 + while (!(readl(TMU_CTRL) & MEM_INIT_DONE))
7049 + pr_info("%s: lmem init\n", __func__);
7050 + writel(LLM_INIT, TMU_CTRL);
7052 + while (!(readl(TMU_CTRL) & LLM_INIT_DONE))
7055 + /* set up each queue for tail drop */
7056 + for (phyno = 0; phyno < 4; phyno++) {
7059 + for (q = 0; q < 16; q++) {
7062 + writel((phyno << 8) | q, TMU_TEQ_CTRL);
7063 + writel(1 << 22, TMU_TEQ_QCFG); /*Enable tail drop */
7066 + qdepth = DEFAULT_TMU3_QDEPTH;
7068 + qdepth = (q == 0) ? DEFAULT_Q0_QDEPTH :
7069 + DEFAULT_MAX_QDEPTH;
7073 + * The following is a workaround for the reordered
7074 + * packet and BMU2 buffer leakage issue.
7076 + if (CHIP_REVISION() == 0)
7079 + writel(qdepth << 18, TMU_TEQ_HW_PROB_CFG2);
7080 + writel(qdepth >> 14, TMU_TEQ_HW_PROB_CFG3);
7085 + /* Set TMU-3 queue 5 (LRO) in no-drop mode */
7086 + writel((3 << 8) | TMU_QUEUE_LRO, TMU_TEQ_CTRL);
7087 + writel(0, TMU_TEQ_QCFG);
7090 + writel(0x05, TMU_TEQ_DISABLE_DROPCHK);
7092 + writel(0x0, TMU_CTRL);
7095 +/* Enables TMU-PE cores.
7096 + * @param[in] pe_mask TMU PE mask
7098 +void tmu_enable(u32 pe_mask)
7100 + writel(readl(TMU_TX_CTRL) | (pe_mask & 0xF), TMU_TX_CTRL);
7103 +/* Disables TMU cores.
7104 + * @param[in] pe_mask TMU PE mask
7106 +void tmu_disable(u32 pe_mask)
7108 + writel(readl(TMU_TX_CTRL) & ~(pe_mask & 0xF), TMU_TX_CTRL);
7111 +/* This will return the tmu queue status
7112 + * @param[in] if_id gem interface id or TMU index
7113 + * @return returns the bit mask of busy queues, zero means all
7114 + * queues are empty
7116 +u32 tmu_qstatus(u32 if_id)
7118 + return cpu_to_be32(pe_dmem_read(TMU0_ID + if_id, TMU_DM_PESTATUS +
7119 + offsetof(struct pe_status, tmu_qstatus), 4));
7122 +u32 tmu_pkts_processed(u32 if_id)
7124 + return cpu_to_be32(pe_dmem_read(TMU0_ID + if_id, TMU_DM_PESTATUS +
7125 + offsetof(struct pe_status, rx), 4));
7128 +/**************************** UTIL ***************************/
7130 +/* Resets UTIL block.
7132 +void util_reset(void)
7134 + writel(CORE_SW_RESET, UTIL_TX_CTRL);
7137 +/* Initializes UTIL block.
7138 + * @param[in] cfg UTIL configuration
7140 +void util_init(struct util_cfg *cfg)
7142 + writel(cfg->pe_sys_clk_ratio, UTIL_PE_SYS_CLK_RATIO);
7145 +/* Enables UTIL-PE core.
7148 +void util_enable(void)
7150 + writel(CORE_ENABLE, UTIL_TX_CTRL);
7153 +/* Disables UTIL-PE core.
7156 +void util_disable(void)
7158 + writel(CORE_DISABLE, UTIL_TX_CTRL);
7161 +/**************************** HIF ***************************/
7162 +/* Initializes HIF copy block.
7165 +void hif_init(void)
7167 + /*Initialize HIF registers*/
7168 + writel((HIF_RX_POLL_CTRL_CYCLE << 16) | HIF_TX_POLL_CTRL_CYCLE,
7172 +/* Enable hif tx DMA and interrupt
7175 +void hif_tx_enable(void)
7177 + writel(HIF_CTRL_DMA_EN, HIF_TX_CTRL);
7178 + writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_TXPKT_INT_EN),
7182 +/* Disable hif tx DMA and interrupt
7185 +void hif_tx_disable(void)
7189 + writel(0, HIF_TX_CTRL);
7191 + hif_int = readl(HIF_INT_ENABLE);
7192 + hif_int &= HIF_TXPKT_INT_EN;
7193 + writel(hif_int, HIF_INT_ENABLE);
7196 +/* Enable hif rx DMA and interrupt
7199 +void hif_rx_enable(void)
7201 + hif_rx_dma_start();
7202 + writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_RXPKT_INT_EN),
7206 +/* Disable hif rx DMA and interrupt
7209 +void hif_rx_disable(void)
7213 + writel(0, HIF_RX_CTRL);
7215 + hif_int = readl(HIF_INT_ENABLE);
7216 + hif_int &= HIF_RXPKT_INT_EN;
7217 + writel(hif_int, HIF_INT_ENABLE);
7220 +++ b/drivers/staging/fsl_ppfe/pfe_hif.c
7222 +// SPDX-License-Identifier: GPL-2.0+
7224 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
7225 + * Copyright 2017 NXP
7228 +#include <linux/kernel.h>
7229 +#include <linux/interrupt.h>
7230 +#include <linux/dma-mapping.h>
7231 +#include <linux/dmapool.h>
7232 +#include <linux/sched.h>
7233 +#include <linux/module.h>
7234 +#include <linux/list.h>
7235 +#include <linux/kthread.h>
7236 +#include <linux/slab.h>
7238 +#include <linux/io.h>
7239 +#include <asm/irq.h>
7241 +#include "pfe_mod.h"
7243 +#define HIF_INT_MASK (HIF_INT | HIF_RXPKT_INT | HIF_TXPKT_INT)
7245 +unsigned char napi_first_batch;
7247 +static void pfe_tx_do_cleanup(unsigned long data);
7249 +static int pfe_hif_alloc_descr(struct pfe_hif *hif)
7252 + dma_addr_t dma_addr;
7255 + pr_info("%s\n", __func__);
7256 + addr = dma_alloc_coherent(pfe->dev,
7257 + HIF_RX_DESC_NT * sizeof(struct hif_desc) +
7258 + HIF_TX_DESC_NT * sizeof(struct hif_desc),
7259 + &dma_addr, GFP_KERNEL);
7262 + pr_err("%s: Could not allocate buffer descriptors!\n"
7268 + hif->descr_baseaddr_p = dma_addr;
7269 + hif->descr_baseaddr_v = addr;
7270 + hif->rx_ring_size = HIF_RX_DESC_NT;
7271 + hif->tx_ring_size = HIF_TX_DESC_NT;
7279 +#if defined(LS1012A_PFE_RESET_WA)
7280 +static void pfe_hif_disable_rx_desc(struct pfe_hif *hif)
7283 + struct hif_desc *desc = hif->rx_base;
7285 + /*Mark all descriptors as LAST_BD */
7286 + for (ii = 0; ii < hif->rx_ring_size; ii++) {
7287 + desc->ctrl |= BD_CTRL_LAST_BD;
7292 +struct class_rx_hdr_t {
7293 + u32 next_ptr; /* ptr to the start of the first DDR buffer */
7294 + u16 length; /* total packet length */
7295 + u16 phyno; /* input physical port number */
7296 + u32 status; /* gemac status bits */
7297 + u32 status2; /* reserved for software usage */
7300 +/* STATUS_BAD_FRAME_ERR is set for all errors (including checksums if enabled)
7303 +#define STATUS_BAD_FRAME_ERR BIT(16)
7304 +#define STATUS_LENGTH_ERR BIT(17)
7305 +#define STATUS_CRC_ERR BIT(18)
7306 +#define STATUS_TOO_SHORT_ERR BIT(19)
7307 +#define STATUS_TOO_LONG_ERR BIT(20)
7308 +#define STATUS_CODE_ERR BIT(21)
7309 +#define STATUS_MC_HASH_MATCH BIT(22)
7310 +#define STATUS_CUMULATIVE_ARC_HIT BIT(23)
7311 +#define STATUS_UNICAST_HASH_MATCH BIT(24)
7312 +#define STATUS_IP_CHECKSUM_CORRECT BIT(25)
7313 +#define STATUS_TCP_CHECKSUM_CORRECT BIT(26)
7314 +#define STATUS_UDP_CHECKSUM_CORRECT BIT(27)
7315 +#define STATUS_OVERFLOW_ERR BIT(28) /* GPI error */
7316 +#define MIN_PKT_SIZE 64
7318 +static inline void copy_to_lmem(u32 *dst, u32 *src, int len)
7322 + for (i = 0; i < len; i += sizeof(u32)) {
7323 + *dst = htonl(*src);
7328 +static void send_dummy_pkt_to_hif(void)
7330 + void *lmem_ptr, *ddr_ptr, *lmem_virt_addr;
7332 + struct class_rx_hdr_t local_hdr;
7333 + static u32 dummy_pkt[] = {
7334 + 0x33221100, 0x2b785544, 0xd73093cb, 0x01000608,
7335 + 0x04060008, 0x2b780200, 0xd73093cb, 0x0a01a8c0,
7336 + 0x33221100, 0xa8c05544, 0x00000301, 0x00000000,
7337 + 0x00000000, 0x00000000, 0x00000000, 0xbe86c51f };
7339 + ddr_ptr = (void *)((u64)readl(BMU2_BASE_ADDR + BMU_ALLOC_CTRL));
7343 + lmem_ptr = (void *)((u64)readl(BMU1_BASE_ADDR + BMU_ALLOC_CTRL));
7347 + pr_info("Sending a dummy pkt to HIF %p %p\n", ddr_ptr, lmem_ptr);
7348 + physaddr = (u32)DDR_VIRT_TO_PFE(ddr_ptr);
7350 + lmem_virt_addr = (void *)CBUS_PFE_TO_VIRT((unsigned long int)lmem_ptr);
7352 + local_hdr.phyno = htons(0); /* RX_PHY_0 */
7353 + local_hdr.length = htons(MIN_PKT_SIZE);
7355 + local_hdr.next_ptr = htonl((u32)physaddr);
7356 + /*Mark checksum is correct */
7357 + local_hdr.status = htonl((STATUS_IP_CHECKSUM_CORRECT |
7358 + STATUS_UDP_CHECKSUM_CORRECT |
7359 + STATUS_TCP_CHECKSUM_CORRECT |
7360 + STATUS_UNICAST_HASH_MATCH |
7361 + STATUS_CUMULATIVE_ARC_HIT));
7362 + copy_to_lmem((u32 *)lmem_virt_addr, (u32 *)&local_hdr,
7363 + sizeof(local_hdr));
7365 + copy_to_lmem((u32 *)(lmem_virt_addr + LMEM_HDR_SIZE), (u32 *)dummy_pkt,
7368 + writel((unsigned long int)lmem_ptr, CLASS_INQ_PKTPTR);
7371 +void pfe_hif_rx_idle(struct pfe_hif *hif)
7373 + int hif_stop_loop = 10;
7376 + pfe_hif_disable_rx_desc(hif);
7377 + pr_info("Bringing hif to idle state...");
7378 + writel(0, HIF_INT_ENABLE);
7379 + /*If HIF Rx BDP is busy send a dummy packet */
7381 + rx_status = readl(HIF_RX_STATUS);
7382 + if (rx_status & BDP_CSR_RX_DMA_ACTV)
7383 + send_dummy_pkt_to_hif();
7385 + usleep_range(100, 150);
7386 + } while (--hif_stop_loop);
7388 + if (readl(HIF_RX_STATUS) & BDP_CSR_RX_DMA_ACTV)
7389 + pr_info("Failed\n");
7391 + pr_info("Done\n");
7395 +static void pfe_hif_free_descr(struct pfe_hif *hif)
7397 + pr_info("%s\n", __func__);
7399 + dma_free_coherent(pfe->dev,
7400 + hif->rx_ring_size * sizeof(struct hif_desc) +
7401 + hif->tx_ring_size * sizeof(struct hif_desc),
7402 + hif->descr_baseaddr_v, hif->descr_baseaddr_p);
7405 +void pfe_hif_desc_dump(struct pfe_hif *hif)
7407 + struct hif_desc *desc;
7408 + unsigned long desc_p;
7411 + pr_info("%s\n", __func__);
7413 + desc = hif->rx_base;
7414 + desc_p = (u32)((u64)desc - (u64)hif->descr_baseaddr_v +
7415 + hif->descr_baseaddr_p);
7417 + pr_info("HIF Rx desc base %p physical %x\n", desc, (u32)desc_p);
7418 + for (ii = 0; ii < hif->rx_ring_size; ii++) {
7419 + pr_info("status: %08x, ctrl: %08x, data: %08x, next: %x\n",
7420 + readl(&desc->status), readl(&desc->ctrl),
7421 + readl(&desc->data), readl(&desc->next));
7425 + desc = hif->tx_base;
7426 + desc_p = ((u64)desc - (u64)hif->descr_baseaddr_v +
7427 + hif->descr_baseaddr_p);
7429 + pr_info("HIF Tx desc base %p physical %x\n", desc, (u32)desc_p);
7430 + for (ii = 0; ii < hif->tx_ring_size; ii++) {
7431 + pr_info("status: %08x, ctrl: %08x, data: %08x, next: %x\n",
7432 + readl(&desc->status), readl(&desc->ctrl),
7433 + readl(&desc->data), readl(&desc->next));
7438 +/* pfe_hif_release_buffers */
7439 +static void pfe_hif_release_buffers(struct pfe_hif *hif)
7441 + struct hif_desc *desc;
7444 + hif->rx_base = hif->descr_baseaddr_v;
7446 + pr_info("%s\n", __func__);
7448 + /*Free Rx buffers */
7449 + desc = hif->rx_base;
7450 + for (i = 0; i < hif->rx_ring_size; i++) {
7451 + if (readl(&desc->data)) {
7452 + if ((i < hif->shm->rx_buf_pool_cnt) &&
7453 + (!hif->shm->rx_buf_pool[i])) {
7455 + * dma_unmap_single(hif->dev, desc->data,
7456 + * hif->rx_buf_len[i], DMA_FROM_DEVICE);
7458 + dma_unmap_single(hif->dev,
7460 + readl(&desc->data)),
7461 + hif->rx_buf_len[i],
7463 + hif->shm->rx_buf_pool[i] = hif->rx_buf_addr[i];
7465 + pr_err("%s: buffer pool already full\n"
7470 + writel(0, &desc->data);
7471 + writel(0, &desc->status);
7472 + writel(0, &desc->ctrl);
7478 + * pfe_hif_init_buffers
7479 + * This function initializes the HIF Rx/Tx ring descriptors and
7480 + * initialize Rx queue with buffers.
7482 +static int pfe_hif_init_buffers(struct pfe_hif *hif)
7484 + struct hif_desc *desc, *first_desc_p;
7488 + pr_info("%s\n", __func__);
7490 + /* Check enough Rx buffers available in the shared memory */
7491 + if (hif->shm->rx_buf_pool_cnt < hif->rx_ring_size)
7494 + hif->rx_base = hif->descr_baseaddr_v;
7495 + memset(hif->rx_base, 0, hif->rx_ring_size * sizeof(struct hif_desc));
7497 + /*Initialize Rx descriptors */
7498 + desc = hif->rx_base;
7499 + first_desc_p = (struct hif_desc *)hif->descr_baseaddr_p;
7501 + for (i = 0; i < hif->rx_ring_size; i++) {
7502 + /* Initialize Rx buffers from the shared memory */
7504 + data = (u32)dma_map_single(hif->dev, hif->shm->rx_buf_pool[i],
7505 + pfe_pkt_size, DMA_FROM_DEVICE);
7506 + hif->rx_buf_addr[i] = hif->shm->rx_buf_pool[i];
7507 + hif->rx_buf_len[i] = pfe_pkt_size;
7508 + hif->shm->rx_buf_pool[i] = NULL;
7510 + if (likely(dma_mapping_error(hif->dev, data) == 0)) {
7511 + writel(DDR_PHYS_TO_PFE(data), &desc->data);
7513 + pr_err("%s : low on mem\n", __func__);
7518 + writel(0, &desc->status);
7521 + * Ensure everything else is written to DDR before
7522 + * writing bd->ctrl
7526 + writel((BD_CTRL_PKT_INT_EN | BD_CTRL_LIFM
7527 + | BD_CTRL_DIR | BD_CTRL_DESC_EN
7528 + | BD_BUF_LEN(pfe_pkt_size)), &desc->ctrl);
7530 + /* Chain descriptors */
7531 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p + i + 1), &desc->next);
7535 + /* Overwrite last descriptor to chain it to first one*/
7537 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), &desc->next);
7539 + hif->rxtoclean_index = 0;
7541 + /*Initialize Rx buffer descriptor ring base address */
7542 + writel(DDR_PHYS_TO_PFE(hif->descr_baseaddr_p), HIF_RX_BDP_ADDR);
7544 + hif->tx_base = hif->rx_base + hif->rx_ring_size;
7545 + first_desc_p = (struct hif_desc *)hif->descr_baseaddr_p +
7546 + hif->rx_ring_size;
7547 + memset(hif->tx_base, 0, hif->tx_ring_size * sizeof(struct hif_desc));
7549 + /*Initialize tx descriptors */
7550 + desc = hif->tx_base;
7552 + for (i = 0; i < hif->tx_ring_size; i++) {
7553 + /* Chain descriptors */
7554 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p + i + 1), &desc->next);
7555 + writel(0, &desc->ctrl);
7559 + /* Overwrite last descriptor to chain it to first one */
7561 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), &desc->next);
7562 + hif->txavail = hif->tx_ring_size;
7563 + hif->txtosend = 0;
7564 + hif->txtoclean = 0;
7565 + hif->txtoflush = 0;
7567 + /*Initialize Tx buffer descriptor ring base address */
7568 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), HIF_TX_BDP_ADDR);
7573 + pfe_hif_release_buffers(hif);
7578 + * pfe_hif_client_register
7580 + * This function used to register a client driver with the HIF driver.
7583 + * 0 - on Successful registration
7585 +static int pfe_hif_client_register(struct pfe_hif *hif, u32 client_id,
7586 + struct hif_client_shm *client_shm)
7588 + struct hif_client *client = &hif->client[client_id];
7590 + struct rx_queue_desc *rx_qbase;
7591 + struct tx_queue_desc *tx_qbase;
7592 + struct hif_rx_queue *rx_queue;
7593 + struct hif_tx_queue *tx_queue;
7596 + pr_info("%s\n", __func__);
7598 + spin_lock_bh(&hif->tx_lock);
7600 + if (test_bit(client_id, &hif->shm->g_client_status[0])) {
7601 + pr_err("%s: client %d already registered\n",
7602 + __func__, client_id);
7607 + memset(client, 0, sizeof(struct hif_client));
7609 + /* Initialize client Rx queues baseaddr, size */
7611 + cnt = CLIENT_CTRL_RX_Q_CNT(client_shm->ctrl);
7612 + /* Check if client is requesting for more queues than supported */
7613 + if (cnt > HIF_CLIENT_QUEUES_MAX)
7614 + cnt = HIF_CLIENT_QUEUES_MAX;
7616 + client->rx_qn = cnt;
7617 + rx_qbase = (struct rx_queue_desc *)client_shm->rx_qbase;
7618 + for (i = 0; i < cnt; i++) {
7619 + rx_queue = &client->rx_q[i];
7620 + rx_queue->base = rx_qbase + i * client_shm->rx_qsize;
7621 + rx_queue->size = client_shm->rx_qsize;
7622 + rx_queue->write_idx = 0;
7625 + /* Initialize client Tx queues baseaddr, size */
7626 + cnt = CLIENT_CTRL_TX_Q_CNT(client_shm->ctrl);
7628 + /* Check if client is requesting for more queues than supported */
7629 + if (cnt > HIF_CLIENT_QUEUES_MAX)
7630 + cnt = HIF_CLIENT_QUEUES_MAX;
7632 + client->tx_qn = cnt;
7633 + tx_qbase = (struct tx_queue_desc *)client_shm->tx_qbase;
7634 + for (i = 0; i < cnt; i++) {
7635 + tx_queue = &client->tx_q[i];
7636 + tx_queue->base = tx_qbase + i * client_shm->tx_qsize;
7637 + tx_queue->size = client_shm->tx_qsize;
7638 + tx_queue->ack_idx = 0;
7641 + set_bit(client_id, &hif->shm->g_client_status[0]);
7644 + spin_unlock_bh(&hif->tx_lock);
7650 + * pfe_hif_client_unregister
7652 + * This function used to unregister a client from the HIF driver.
7655 +static void pfe_hif_client_unregister(struct pfe_hif *hif, u32 client_id)
7657 + pr_info("%s\n", __func__);
7660 + * Mark client as no longer available (which prevents further packet
7661 + * receive for this client)
7663 + spin_lock_bh(&hif->tx_lock);
7665 + if (!test_bit(client_id, &hif->shm->g_client_status[0])) {
7666 + pr_err("%s: client %d not registered\n", __func__,
7669 + spin_unlock_bh(&hif->tx_lock);
7673 + clear_bit(client_id, &hif->shm->g_client_status[0]);
7675 + spin_unlock_bh(&hif->tx_lock);
7679 + * client_put_rxpacket-
7680 + * This functions puts the Rx pkt in the given client Rx queue.
7681 + * It actually swap the Rx pkt in the client Rx descriptor buffer
7682 + * and returns the free buffer from it.
7684 + * If the function returns NULL means client Rx queue is full and
7685 + * packet couldn't send to client queue.
7687 +static void *client_put_rxpacket(struct hif_rx_queue *queue, void *pkt, u32 len,
7688 + u32 flags, u32 client_ctrl, u32 *rem_len)
7690 + void *free_pkt = NULL;
7691 + struct rx_queue_desc *desc = queue->base + queue->write_idx;
7693 + if (readl(&desc->ctrl) & CL_DESC_OWN) {
7695 + int rem_page_size = PAGE_SIZE -
7696 + PRESENT_OFST_IN_PAGE(pkt);
7697 + int cur_pkt_size = ROUND_MIN_RX_SIZE(len +
7698 + pfe_pkt_headroom);
7699 + *rem_len = (rem_page_size - cur_pkt_size);
7701 + free_pkt = pkt + cur_pkt_size;
7702 + get_page(virt_to_page(free_pkt));
7705 + *)__get_free_page(GFP_ATOMIC | GFP_DMA_PFE);
7706 + *rem_len = pfe_pkt_size;
7709 + free_pkt = kmalloc(PFE_BUF_SIZE, GFP_ATOMIC |
7711 + *rem_len = PFE_BUF_SIZE - pfe_pkt_headroom;
7716 + desc->client_ctrl = client_ctrl;
7718 + * Ensure everything else is written to DDR before
7719 + * writing bd->ctrl
7722 + writel(CL_DESC_BUF_LEN(len) | flags, &desc->ctrl);
7723 + queue->write_idx = (queue->write_idx + 1)
7724 + & (queue->size - 1);
7726 + free_pkt += pfe_pkt_headroom;
7734 + * pfe_hif_rx_process-
7735 + * This function does pfe hif rx queue processing.
7736 + * Dequeue packet from Rx queue and send it to corresponding client queue
7738 +static int pfe_hif_rx_process(struct pfe_hif *hif, int budget)
7740 + struct hif_desc *desc;
7741 + struct hif_hdr *pkt_hdr;
7742 + struct __hif_hdr hif_hdr;
7744 + int rtc, len, rx_processed = 0;
7745 + struct __hif_desc local_desc;
7747 + unsigned int desc_p;
7748 + unsigned int buf_size = 0;
7750 + spin_lock_bh(&hif->lock);
7752 + rtc = hif->rxtoclean_index;
7754 + while (rx_processed < budget) {
7755 + desc = hif->rx_base + rtc;
7757 + __memcpy12(&local_desc, desc);
7759 + /* ACK pending Rx interrupt */
7760 + if (local_desc.ctrl & BD_CTRL_DESC_EN) {
7761 + writel(HIF_INT | HIF_RXPKT_INT, HIF_INT_SRC);
7763 + if (rx_processed == 0) {
7764 + if (napi_first_batch == 1) {
7765 + desc_p = hif->descr_baseaddr_p +
7766 + ((unsigned long int)(desc) -
7768 + int)hif->descr_baseaddr_v);
7769 + napi_first_batch = 0;
7773 + __memcpy12(&local_desc, desc);
7775 + if (local_desc.ctrl & BD_CTRL_DESC_EN)
7779 + napi_first_batch = 0;
7781 +#ifdef HIF_NAPI_STATS
7782 + hif->napi_counters[NAPI_DESC_COUNT]++;
7784 + len = BD_BUF_LEN(local_desc.ctrl);
7786 + * dma_unmap_single(hif->dev, DDR_PFE_TO_PHYS(local_desc.data),
7787 + * hif->rx_buf_len[rtc], DMA_FROM_DEVICE);
7789 + dma_unmap_single(hif->dev, DDR_PFE_TO_PHYS(local_desc.data),
7790 + hif->rx_buf_len[rtc], DMA_FROM_DEVICE);
7792 + pkt_hdr = (struct hif_hdr *)hif->rx_buf_addr[rtc];
7794 + /* Track last HIF header received */
7795 + if (!hif->started) {
7798 + __memcpy8(&hif_hdr, pkt_hdr);
7800 + hif->qno = hif_hdr.hdr.q_num;
7801 + hif->client_id = hif_hdr.hdr.client_id;
7802 + hif->client_ctrl = (hif_hdr.hdr.client_ctrl1 << 16) |
7803 + hif_hdr.hdr.client_ctrl;
7804 + flags = CL_DESC_FIRST;
7810 + if (local_desc.ctrl & BD_CTRL_LIFM)
7811 + flags |= CL_DESC_LAST;
7813 + /* Check for valid client id and still registered */
7814 + if ((hif->client_id >= HIF_CLIENTS_MAX) ||
7815 + !(test_bit(hif->client_id,
7816 + &hif->shm->g_client_status[0]))) {
7817 + printk_ratelimited("%s: packet with invalid client id %d q_num %d\n",
7822 + free_buf = pkt_hdr;
7827 + /* Check to valid queue number */
7828 + if (hif->client[hif->client_id].rx_qn <= hif->qno) {
7829 + pr_info("%s: packet with invalid queue: %d\n"
7830 + , __func__, hif->qno);
7835 + client_put_rxpacket(&hif->client[hif->client_id].rx_q[hif->qno],
7836 + (void *)pkt_hdr, len, flags,
7837 + hif->client_ctrl, &buf_size);
7839 + hif_lib_indicate_client(hif->client_id, EVENT_RX_PKT_IND,
7842 + if (unlikely(!free_buf)) {
7843 +#ifdef HIF_NAPI_STATS
7844 + hif->napi_counters[NAPI_CLIENT_FULL_COUNT]++;
7847 + * If we want to keep in polling mode to retry later,
7848 + * we need to tell napi that we consumed
7849 + * the full budget or we will hit a livelock scenario.
7850 + * The core code keeps this napi instance
7851 + * at the head of the list and none of the other
7852 + * instances get to run
7854 + rx_processed = budget;
7856 + if (flags & CL_DESC_FIRST)
7863 + /*Fill free buffer in the descriptor */
7864 + hif->rx_buf_addr[rtc] = free_buf;
7865 + hif->rx_buf_len[rtc] = min(pfe_pkt_size, buf_size);
7866 + writel((DDR_PHYS_TO_PFE
7867 + ((u32)dma_map_single(hif->dev,
7868 + free_buf, hif->rx_buf_len[rtc], DMA_FROM_DEVICE))),
7871 + * Ensure everything else is written to DDR before
7872 + * writing bd->ctrl
7875 + writel((BD_CTRL_PKT_INT_EN | BD_CTRL_LIFM | BD_CTRL_DIR |
7876 + BD_CTRL_DESC_EN | BD_BUF_LEN(hif->rx_buf_len[rtc])),
7879 + rtc = (rtc + 1) & (hif->rx_ring_size - 1);
7881 + if (local_desc.ctrl & BD_CTRL_LIFM) {
7882 + if (!(hif->client_ctrl & HIF_CTRL_RX_CONTINUED)) {
7885 +#ifdef HIF_NAPI_STATS
7886 + hif->napi_counters[NAPI_PACKET_COUNT]++;
7893 + hif->rxtoclean_index = rtc;
7894 + spin_unlock_bh(&hif->lock);
7896 + /* we made some progress, re-start rx dma in case it stopped */
7897 + hif_rx_dma_start();
7899 + return rx_processed;
7903 + * client_ack_txpacket-
7904 + * This function ack the Tx packet in the give client Tx queue by resetting
7905 + * ownership bit in the descriptor.
7907 +static int client_ack_txpacket(struct pfe_hif *hif, unsigned int client_id,
7908 + unsigned int q_no)
7910 + struct hif_tx_queue *queue = &hif->client[client_id].tx_q[q_no];
7911 + struct tx_queue_desc *desc = queue->base + queue->ack_idx;
7913 + if (readl(&desc->ctrl) & CL_DESC_OWN) {
7914 + writel((readl(&desc->ctrl) & ~CL_DESC_OWN), &desc->ctrl);
7915 + queue->ack_idx = (queue->ack_idx + 1) & (queue->size - 1);
7920 + /*This should not happen */
7921 + pr_err("%s: %d %d %d %d %d %p %d\n", __func__,
7922 + hif->txtosend, hif->txtoclean, hif->txavail,
7923 + client_id, q_no, queue, queue->ack_idx);
7924 + WARN(1, "%s: doesn't own this descriptor", __func__);
7929 +void __hif_tx_done_process(struct pfe_hif *hif, int count)
7931 + struct hif_desc *desc;
7932 + struct hif_desc_sw *desc_sw;
7934 + int pkts_done[HIF_CLIENTS_MAX] = {0, 0};
7936 + ttc = hif->txtoclean;
7937 + tx_avl = hif->txavail;
7939 + while ((tx_avl < hif->tx_ring_size) && count--) {
7940 + desc = hif->tx_base + ttc;
7942 + if (readl(&desc->ctrl) & BD_CTRL_DESC_EN)
7945 + desc_sw = &hif->tx_sw_queue[ttc];
7947 + if (desc_sw->data) {
7949 + * dmap_unmap_single(hif->dev, desc_sw->data,
7950 + * desc_sw->len, DMA_TO_DEVICE);
7952 + dma_unmap_single(hif->dev, desc_sw->data,
7953 + desc_sw->len, DMA_TO_DEVICE);
7956 + if (desc_sw->client_id > HIF_CLIENTS_MAX)
7957 + pr_err("Invalid cl id %d\n", desc_sw->client_id);
7959 + pkts_done[desc_sw->client_id]++;
7961 + client_ack_txpacket(hif, desc_sw->client_id, desc_sw->q_no);
7963 + ttc = (ttc + 1) & (hif->tx_ring_size - 1);
7968 + hif_lib_indicate_client(0, EVENT_TXDONE_IND, 0);
7970 + hif_lib_indicate_client(1, EVENT_TXDONE_IND, 0);
7972 + hif->txtoclean = ttc;
7973 + hif->txavail = tx_avl;
7976 + tasklet_schedule(&hif->tx_cleanup_tasklet);
7978 + /*Enable Tx done interrupt */
7979 + writel(readl_relaxed(HIF_INT_ENABLE) | HIF_TXPKT_INT,
7984 +static void pfe_tx_do_cleanup(unsigned long data)
7986 + struct pfe_hif *hif = (struct pfe_hif *)data;
7988 + writel(HIF_INT | HIF_TXPKT_INT, HIF_INT_SRC);
7990 + hif_tx_done_process(hif, 64);
7994 + * __hif_xmit_pkt -
7995 + * This function puts one packet in the HIF Tx queue
7997 +void __hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int
7998 + q_no, void *data, u32 len, unsigned int flags)
8000 + struct hif_desc *desc;
8001 + struct hif_desc_sw *desc_sw;
8003 + desc = hif->tx_base + hif->txtosend;
8004 + desc_sw = &hif->tx_sw_queue[hif->txtosend];
8006 + desc_sw->len = len;
8007 + desc_sw->client_id = client_id;
8008 + desc_sw->q_no = q_no;
8009 + desc_sw->flags = flags;
8011 + if (flags & HIF_DONT_DMA_MAP) {
8012 + desc_sw->data = 0;
8013 + writel((u32)DDR_PHYS_TO_PFE(data), &desc->data);
8015 + desc_sw->data = dma_map_single(hif->dev, data, len,
8017 + writel((u32)DDR_PHYS_TO_PFE(desc_sw->data), &desc->data);
8020 + hif->txtosend = (hif->txtosend + 1) & (hif->tx_ring_size - 1);
8023 + if ((!((flags & HIF_DATA_VALID) && (flags &
8024 + HIF_LAST_BUFFER))))
8028 + * Ensure everything else is written to DDR before
8029 + * writing bd->ctrl
8034 + desc_sw = &hif->tx_sw_queue[hif->txtoflush];
8035 + desc = hif->tx_base + hif->txtoflush;
8037 + if (desc_sw->flags & HIF_LAST_BUFFER) {
8038 + writel((BD_CTRL_LIFM |
8039 + BD_CTRL_BRFETCH_DISABLE | BD_CTRL_RTFETCH_DISABLE
8040 + | BD_CTRL_PARSE_DISABLE | BD_CTRL_DESC_EN |
8041 + BD_CTRL_PKT_INT_EN | BD_BUF_LEN(desc_sw->len)),
8044 + writel((BD_CTRL_DESC_EN |
8045 + BD_BUF_LEN(desc_sw->len)), &desc->ctrl);
8047 + hif->txtoflush = (hif->txtoflush + 1) & (hif->tx_ring_size - 1);
8049 + while (hif->txtoflush != hif->txtosend)
8056 +static irqreturn_t wol_isr(int irq, void *dev_id)
8059 + gemac_set_wol(EMAC1_BASE_ADDR, 0);
8060 + gemac_set_wol(EMAC2_BASE_ADDR, 0);
8061 + return IRQ_HANDLED;
8066 + * This ISR routine processes Rx/Tx done interrupts from the HIF hardware block
8068 +static irqreturn_t hif_isr(int irq, void *dev_id)
8070 + struct pfe_hif *hif = (struct pfe_hif *)dev_id;
8072 + int int_enable_mask;
8074 + /*Read hif interrupt source register */
8075 + int_status = readl_relaxed(HIF_INT_SRC);
8076 + int_enable_mask = readl_relaxed(HIF_INT_ENABLE);
8078 + if ((int_status & HIF_INT) == 0)
8081 + int_status &= ~(HIF_INT);
8083 + if (int_status & HIF_RXPKT_INT) {
8084 + int_status &= ~(HIF_RXPKT_INT);
8085 + int_enable_mask &= ~(HIF_RXPKT_INT);
8087 + napi_first_batch = 1;
8089 + if (napi_schedule_prep(&hif->napi)) {
8090 +#ifdef HIF_NAPI_STATS
8091 + hif->napi_counters[NAPI_SCHED_COUNT]++;
8093 + __napi_schedule(&hif->napi);
8097 + if (int_status & HIF_TXPKT_INT) {
8098 + int_status &= ~(HIF_TXPKT_INT);
8099 + int_enable_mask &= ~(HIF_TXPKT_INT);
8100 + /*Schedule tx cleanup tassklet */
8101 + tasklet_schedule(&hif->tx_cleanup_tasklet);
8104 + /*Disable interrupts, they will be enabled after they are serviced */
8105 + writel_relaxed(int_enable_mask, HIF_INT_ENABLE);
8108 + pr_info("%s : Invalid interrupt : %d\n", __func__,
8110 + writel(int_status, HIF_INT_SRC);
8113 + return IRQ_HANDLED;
8116 +void hif_process_client_req(struct pfe_hif *hif, int req, int data1, int data2)
8118 + unsigned int client_id = data1;
8120 + if (client_id >= HIF_CLIENTS_MAX) {
8121 + pr_err("%s: client id %d out of bounds\n", __func__,
8127 + case REQUEST_CL_REGISTER:
8128 + /* Request for register a client */
8129 + pr_info("%s: register client_id %d\n",
8130 + __func__, client_id);
8131 + pfe_hif_client_register(hif, client_id, (struct
8132 + hif_client_shm *)&hif->shm->client[client_id]);
8135 + case REQUEST_CL_UNREGISTER:
8136 + pr_info("%s: unregister client_id %d\n",
8137 + __func__, client_id);
8139 + /* Request for unregister a client */
8140 + pfe_hif_client_unregister(hif, client_id);
8145 + pr_err("%s: unsupported request %d\n",
8151 + * Process client Tx queues
8152 + * Currently we don't have checking for tx pending
8158 + * This function is NAPI poll function to process HIF Rx queue.
8160 +static int pfe_hif_rx_poll(struct napi_struct *napi, int budget)
8162 + struct pfe_hif *hif = container_of(napi, struct pfe_hif, napi);
8165 +#ifdef HIF_NAPI_STATS
8166 + hif->napi_counters[NAPI_POLL_COUNT]++;
8169 + work_done = pfe_hif_rx_process(hif, budget);
8171 + if (work_done < budget) {
8172 + napi_complete(napi);
8173 + writel(readl_relaxed(HIF_INT_ENABLE) | HIF_RXPKT_INT,
8176 +#ifdef HIF_NAPI_STATS
8178 + hif->napi_counters[NAPI_FULL_BUDGET_COUNT]++;
8186 + * This function initializes the baseaddresses and irq, etc.
8188 +int pfe_hif_init(struct pfe *pfe)
8190 + struct pfe_hif *hif = &pfe->hif;
8193 + pr_info("%s\n", __func__);
8195 + hif->dev = pfe->dev;
8196 + hif->irq = pfe->hif_irq;
8198 + err = pfe_hif_alloc_descr(hif);
8202 + if (pfe_hif_init_buffers(hif)) {
8203 + pr_err("%s: Could not initialize buffer descriptors\n"
8209 + /* Initialize NAPI for Rx processing */
8210 + init_dummy_netdev(&hif->dummy_dev);
8211 + netif_napi_add(&hif->dummy_dev, &hif->napi, pfe_hif_rx_poll,
8212 + HIF_RX_POLL_WEIGHT);
8213 + napi_enable(&hif->napi);
8215 + spin_lock_init(&hif->tx_lock);
8216 + spin_lock_init(&hif->lock);
8222 + /* Disable tx done interrupt */
8223 + writel(HIF_INT_MASK, HIF_INT_ENABLE);
8225 + gpi_enable(HGPI_BASE_ADDR);
8227 + err = request_irq(hif->irq, hif_isr, 0, "pfe_hif", hif);
8229 + pr_err("%s: failed to get the hif IRQ = %d\n",
8230 + __func__, hif->irq);
8234 + err = request_irq(pfe->wol_irq, wol_isr, 0, "pfe_wol", pfe);
8236 + pr_err("%s: failed to get the wol IRQ = %d\n",
8237 + __func__, pfe->wol_irq);
8241 + tasklet_init(&hif->tx_cleanup_tasklet,
8242 + (void(*)(unsigned long))pfe_tx_do_cleanup,
8243 + (unsigned long)hif);
8247 + pfe_hif_free_descr(hif);
8252 +/* pfe_hif_exit- */
8253 +void pfe_hif_exit(struct pfe *pfe)
8255 + struct pfe_hif *hif = &pfe->hif;
8257 + pr_info("%s\n", __func__);
8259 + tasklet_kill(&hif->tx_cleanup_tasklet);
8261 + spin_lock_bh(&hif->lock);
8262 + hif->shm->g_client_status[0] = 0;
8263 + /* Make sure all clients are disabled*/
8264 + hif->shm->g_client_status[1] = 0;
8266 + spin_unlock_bh(&hif->lock);
8268 + /*Disable Rx/Tx */
8269 + gpi_disable(HGPI_BASE_ADDR);
8273 + napi_disable(&hif->napi);
8274 + netif_napi_del(&hif->napi);
8276 + free_irq(pfe->wol_irq, pfe);
8277 + free_irq(hif->irq, hif);
8279 + pfe_hif_release_buffers(hif);
8280 + pfe_hif_free_descr(hif);
8283 +++ b/drivers/staging/fsl_ppfe/pfe_hif.h
8285 +/* SPDX-License-Identifier: GPL-2.0+ */
8287 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
8288 + * Copyright 2017 NXP
8291 +#ifndef _PFE_HIF_H_
8292 +#define _PFE_HIF_H_
8294 +#include <linux/netdevice.h>
8295 +#include <linux/interrupt.h>
8297 +#define HIF_NAPI_STATS
8299 +#define HIF_CLIENT_QUEUES_MAX 16
8300 +#define HIF_RX_POLL_WEIGHT 64
8302 +#define HIF_RX_PKT_MIN_SIZE 0x800 /* 2KB */
8303 +#define HIF_RX_PKT_MIN_SIZE_MASK ~(HIF_RX_PKT_MIN_SIZE - 1)
8304 +#define ROUND_MIN_RX_SIZE(_sz) (((_sz) + (HIF_RX_PKT_MIN_SIZE - 1)) \
8305 + & HIF_RX_PKT_MIN_SIZE_MASK)
8306 +#define PRESENT_OFST_IN_PAGE(_buf) (((unsigned long int)(_buf) & (PAGE_SIZE \
8307 + - 1)) & HIF_RX_PKT_MIN_SIZE_MASK)
8310 + NAPI_SCHED_COUNT = 0,
8312 + NAPI_PACKET_COUNT,
8314 + NAPI_FULL_BUDGET_COUNT,
8315 + NAPI_CLIENT_FULL_COUNT,
8320 + * HIF_TX_DESC_NT value should be always greter than 4,
8321 + * Otherwise HIF_TX_POLL_MARK will become zero.
8323 +#define HIF_RX_DESC_NT 256
8324 +#define HIF_TX_DESC_NT 2048
8326 +#define HIF_FIRST_BUFFER BIT(0)
8327 +#define HIF_LAST_BUFFER BIT(1)
8328 +#define HIF_DONT_DMA_MAP BIT(2)
8329 +#define HIF_DATA_VALID BIT(3)
8330 +#define HIF_TSO BIT(4)
8338 +/*structure to store client queue info */
8339 +struct hif_rx_queue {
8340 + struct rx_queue_desc *base;
8345 +struct hif_tx_queue {
8346 + struct tx_queue_desc *base;
8351 +/*Structure to store the client info */
8352 +struct hif_client {
8354 + struct hif_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
8356 + struct hif_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
8359 +/*HIF hardware buffer descriptor */
8367 +struct __hif_desc {
8373 +struct hif_desc_sw {
8390 + struct hif_hdr hdr;
8395 +struct hif_ipsec_hdr {
8399 +/* HIF_CTRL_TX... defines */
8400 +#define HIF_CTRL_TX_CHECKSUM BIT(2)
8402 +/* HIF_CTRL_RX... defines */
8403 +#define HIF_CTRL_RX_OFFSET_OFST (24)
8404 +#define HIF_CTRL_RX_CHECKSUMMED BIT(2)
8405 +#define HIF_CTRL_RX_CONTINUED BIT(1)
8408 + /* To store registered clients in hif layer */
8409 + struct hif_client client[HIF_CLIENTS_MAX];
8410 + struct hif_shm *shm;
8413 + void *descr_baseaddr_v;
8414 + unsigned long descr_baseaddr_p;
8416 + struct hif_desc *rx_base;
8418 + u32 rxtoclean_index;
8419 + void *rx_buf_addr[HIF_RX_DESC_NT];
8420 + int rx_buf_len[HIF_RX_DESC_NT];
8422 + unsigned int client_id;
8423 + unsigned int client_ctrl;
8424 + unsigned int started;
8426 + struct hif_desc *tx_base;
8432 + struct hif_desc_sw tx_sw_queue[HIF_TX_DESC_NT];
8434 +/* tx_lock synchronizes hif packet tx as well as pfe_hif structure access */
8435 + spinlock_t tx_lock;
8436 +/* lock synchronizes hif rx queue processing */
8438 + struct net_device dummy_dev;
8439 + struct napi_struct napi;
8440 + struct device *dev;
8442 +#ifdef HIF_NAPI_STATS
8443 + unsigned int napi_counters[NAPI_MAX_COUNT];
8445 + struct tasklet_struct tx_cleanup_tasklet;
8448 +void __hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int
8449 + q_no, void *data, u32 len, unsigned int flags);
8450 +int hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int q_no,
8451 + void *data, unsigned int len);
8452 +void __hif_tx_done_process(struct pfe_hif *hif, int count);
8453 +void hif_process_client_req(struct pfe_hif *hif, int req, int data1, int
8455 +int pfe_hif_init(struct pfe *pfe);
8456 +void pfe_hif_exit(struct pfe *pfe);
8457 +void pfe_hif_rx_idle(struct pfe_hif *hif);
8458 +static inline void hif_tx_done_process(struct pfe_hif *hif, int count)
8460 + spin_lock_bh(&hif->tx_lock);
8461 + __hif_tx_done_process(hif, count);
8462 + spin_unlock_bh(&hif->tx_lock);
8465 +static inline void hif_tx_lock(struct pfe_hif *hif)
8467 + spin_lock_bh(&hif->tx_lock);
8470 +static inline void hif_tx_unlock(struct pfe_hif *hif)
8472 + spin_unlock_bh(&hif->tx_lock);
8475 +static inline int __hif_tx_avail(struct pfe_hif *hif)
8477 + return hif->txavail;
8480 +#define __memcpy8(dst, src) memcpy(dst, src, 8)
8481 +#define __memcpy12(dst, src) memcpy(dst, src, 12)
8482 +#define __memcpy(dst, src, len) memcpy(dst, src, len)
8484 +#endif /* _PFE_HIF_H_ */
8486 +++ b/drivers/staging/fsl_ppfe/pfe_hif_lib.c
8488 +// SPDX-License-Identifier: GPL-2.0+
8490 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
8491 + * Copyright 2017 NXP
8494 +#include <linux/version.h>
8495 +#include <linux/kernel.h>
8496 +#include <linux/slab.h>
8497 +#include <linux/interrupt.h>
8498 +#include <linux/workqueue.h>
8499 +#include <linux/dma-mapping.h>
8500 +#include <linux/dmapool.h>
8501 +#include <linux/sched.h>
8502 +#include <linux/skbuff.h>
8503 +#include <linux/moduleparam.h>
8504 +#include <linux/cpu.h>
8506 +#include "pfe_mod.h"
8507 +#include "pfe_hif.h"
8508 +#include "pfe_hif_lib.h"
8510 +unsigned int lro_mode;
8511 +unsigned int page_mode;
8512 +unsigned int tx_qos = 1;
8513 +module_param(tx_qos, uint, 0444);
8514 +MODULE_PARM_DESC(tx_qos, "0: disable ,\n"
8515 + "1: enable (default), guarantee no packet drop at TMU level\n");
8516 +unsigned int pfe_pkt_size;
8517 +unsigned int pfe_pkt_headroom;
8518 +unsigned int emac_txq_cnt;
8522 + * Common functions used by HIF client drivers
8525 +/*HIF shared memory Global variable */
8526 +struct hif_shm ghif_shm;
8528 +/* Cleanup the HIF shared memory, release HIF rx_buffer_pool.
8529 + * This function should be called after pfe_hif_exit
8531 + * @param[in] hif_shm Shared memory address location in DDR
8533 +static void pfe_hif_shm_clean(struct hif_shm *hif_shm)
8538 + for (i = 0; i < hif_shm->rx_buf_pool_cnt; i++) {
8539 + pkt = hif_shm->rx_buf_pool[i];
8541 + hif_shm->rx_buf_pool[i] = NULL;
8542 + pkt -= pfe_pkt_headroom;
8545 + put_page(virt_to_page(pkt));
8552 +/* Initialize shared memory used between HIF driver and clients,
8553 + * allocate rx_buffer_pool required for HIF Rx descriptors.
8554 + * This function should be called before initializing HIF driver.
8556 + * @param[in] hif_shm Shared memory address location in DDR
8557 + * @rerurn 0 - on succes, <0 on fail to initialize
8559 +static int pfe_hif_shm_init(struct hif_shm *hif_shm)
8564 + memset(hif_shm, 0, sizeof(struct hif_shm));
8565 + hif_shm->rx_buf_pool_cnt = HIF_RX_DESC_NT;
8567 + for (i = 0; i < hif_shm->rx_buf_pool_cnt; i++) {
8569 + pkt = (void *)__get_free_page(GFP_KERNEL |
8572 + pkt = kmalloc(PFE_BUF_SIZE, GFP_KERNEL | GFP_DMA_PFE);
8576 + hif_shm->rx_buf_pool[i] = pkt + pfe_pkt_headroom;
8584 + pr_err("%s Low memory\n", __func__);
8585 + pfe_hif_shm_clean(hif_shm);
8589 +/*This function sends indication to HIF driver
8591 + * @param[in] hif hif context
8593 +static void hif_lib_indicate_hif(struct pfe_hif *hif, int req, int data1, int
8596 + hif_process_client_req(hif, req, data1, data2);
8599 +void hif_lib_indicate_client(int client_id, int event_type, int qno)
8601 + struct hif_client_s *client = pfe->hif_client[client_id];
8603 + if (!client || (event_type >= HIF_EVENT_MAX) || (qno >=
8604 + HIF_CLIENT_QUEUES_MAX))
8607 + if (!test_and_set_bit(qno, &client->queue_mask[event_type]))
8608 + client->event_handler(client->priv, event_type, qno);
8611 +/*This function releases Rx queue descriptors memory and pre-filled buffers
8613 + * @param[in] client hif_client context
8615 +static void hif_lib_client_release_rx_buffers(struct hif_client_s *client)
8617 + struct rx_queue_desc *desc;
8621 + for (qno = 0; qno < client->rx_qn; qno++) {
8622 + desc = client->rx_q[qno].base;
8624 + for (ii = 0; ii < client->rx_q[qno].size; ii++) {
8625 + buf = (void *)desc->data;
8627 + buf -= pfe_pkt_headroom;
8630 + free_page((unsigned long)buf);
8641 + kfree(client->rx_qbase);
8644 +/*This function allocates memory for the rxq descriptors and pre-fill rx queues
8646 + * @param[in] client client context
8647 + * @param[in] q_size size of the rxQ, all queues are of same size
8649 +static int hif_lib_client_init_rx_buffers(struct hif_client_s *client, int
8652 + struct rx_queue_desc *desc;
8653 + struct hif_client_rx_queue *queue;
8656 + /*Allocate memory for the client queues */
8657 + client->rx_qbase = kzalloc(client->rx_qn * q_size * sizeof(struct
8658 + rx_queue_desc), GFP_KERNEL);
8659 + if (!client->rx_qbase)
8662 + for (qno = 0; qno < client->rx_qn; qno++) {
8663 + queue = &client->rx_q[qno];
8665 + queue->base = client->rx_qbase + qno * q_size * sizeof(struct
8667 + queue->size = q_size;
8668 + queue->read_idx = 0;
8669 + queue->write_idx = 0;
8671 + pr_debug("rx queue: %d, base: %p, size: %d\n", qno,
8672 + queue->base, queue->size);
8675 + for (qno = 0; qno < client->rx_qn; qno++) {
8676 + queue = &client->rx_q[qno];
8677 + desc = queue->base;
8679 + for (ii = 0; ii < queue->size; ii++) {
8680 + desc->ctrl = CL_DESC_BUF_LEN(pfe_pkt_size) |
8693 +static void hif_lib_client_cleanup_tx_queue(struct hif_client_tx_queue *queue)
8695 + pr_debug("%s\n", __func__);
8698 + * Check if there are any pending packets. Client must flush the tx
8699 + * queues before unregistering, by calling by calling
8700 + * hif_lib_tx_get_next_complete()
8702 + * Hif no longer calls since we are no longer registered
8704 + if (queue->tx_pending)
8705 + pr_err("%s: pending transmit packets\n", __func__);
8708 +static void hif_lib_client_release_tx_buffers(struct hif_client_s *client)
8712 + pr_debug("%s\n", __func__);
8714 + for (qno = 0; qno < client->tx_qn; qno++)
8715 + hif_lib_client_cleanup_tx_queue(&client->tx_q[qno]);
8717 + kfree(client->tx_qbase);
8720 +static int hif_lib_client_init_tx_buffers(struct hif_client_s *client, int
8723 + struct hif_client_tx_queue *queue;
8726 + client->tx_qbase = kzalloc(client->tx_qn * q_size * sizeof(struct
8727 + tx_queue_desc), GFP_KERNEL);
8728 + if (!client->tx_qbase)
8731 + for (qno = 0; qno < client->tx_qn; qno++) {
8732 + queue = &client->tx_q[qno];
8734 + queue->base = client->tx_qbase + qno * q_size * sizeof(struct
8736 + queue->size = q_size;
8737 + queue->read_idx = 0;
8738 + queue->write_idx = 0;
8739 + queue->tx_pending = 0;
8740 + queue->nocpy_flag = 0;
8741 + queue->prev_tmu_tx_pkts = 0;
8742 + queue->done_tmu_tx_pkts = 0;
8744 + pr_debug("tx queue: %d, base: %p, size: %d\n", qno,
8745 + queue->base, queue->size);
8751 +static int hif_lib_event_dummy(void *priv, int event_type, int qno)
8756 +int hif_lib_client_register(struct hif_client_s *client)
8758 + struct hif_shm *hif_shm;
8759 + struct hif_client_shm *client_shm;
8761 + /* int loop_cnt = 0; */
8763 + pr_debug("%s\n", __func__);
8765 + /*Allocate memory before spin_lock*/
8766 + if (hif_lib_client_init_rx_buffers(client, client->rx_qsize)) {
8771 + if (hif_lib_client_init_tx_buffers(client, client->tx_qsize)) {
8776 + spin_lock_bh(&pfe->hif.lock);
8777 + if (!(client->pfe) || (client->id >= HIF_CLIENTS_MAX) ||
8778 + (pfe->hif_client[client->id])) {
8783 + hif_shm = client->pfe->hif.shm;
8785 + if (!client->event_handler)
8786 + client->event_handler = hif_lib_event_dummy;
8788 + /*Initialize client specific shared memory */
8789 + client_shm = (struct hif_client_shm *)&hif_shm->client[client->id];
8790 + client_shm->rx_qbase = (unsigned long int)client->rx_qbase;
8791 + client_shm->rx_qsize = client->rx_qsize;
8792 + client_shm->tx_qbase = (unsigned long int)client->tx_qbase;
8793 + client_shm->tx_qsize = client->tx_qsize;
8794 + client_shm->ctrl = (client->tx_qn << CLIENT_CTRL_TX_Q_CNT_OFST) |
8795 + (client->rx_qn << CLIENT_CTRL_RX_Q_CNT_OFST);
8796 + /* spin_lock_init(&client->rx_lock); */
8798 + for (i = 0; i < HIF_EVENT_MAX; i++) {
8799 + client->queue_mask[i] = 0; /*
8800 + * By default all events are
8805 + /*Indicate to HIF driver*/
8806 + hif_lib_indicate_hif(&pfe->hif, REQUEST_CL_REGISTER, client->id, 0);
8808 + pr_debug("%s: client: %p, client_id: %d, tx_qsize: %d, rx_qsize: %d\n",
8809 + __func__, client, client->id, client->tx_qsize,
8810 + client->rx_qsize);
8812 + client->cpu_id = -1;
8814 + pfe->hif_client[client->id] = client;
8815 + spin_unlock_bh(&pfe->hif.lock);
8820 + spin_unlock_bh(&pfe->hif.lock);
8821 + hif_lib_client_release_tx_buffers(client);
8824 + hif_lib_client_release_rx_buffers(client);
8830 +int hif_lib_client_unregister(struct hif_client_s *client)
8832 + struct pfe *pfe = client->pfe;
8833 + u32 client_id = client->id;
8836 + "%s : client: %p, client_id: %d, txQ_depth: %d, rxQ_depth: %d\n"
8837 + , __func__, client, client->id, client->tx_qsize,
8838 + client->rx_qsize);
8840 + spin_lock_bh(&pfe->hif.lock);
8841 + hif_lib_indicate_hif(&pfe->hif, REQUEST_CL_UNREGISTER, client->id, 0);
8843 + hif_lib_client_release_tx_buffers(client);
8844 + hif_lib_client_release_rx_buffers(client);
8845 + pfe->hif_client[client_id] = NULL;
8846 + spin_unlock_bh(&pfe->hif.lock);
8851 +int hif_lib_event_handler_start(struct hif_client_s *client, int event,
8854 + struct hif_client_rx_queue *queue = &client->rx_q[qno];
8855 + struct rx_queue_desc *desc = queue->base + queue->read_idx;
8857 + if ((event >= HIF_EVENT_MAX) || (qno >= HIF_CLIENT_QUEUES_MAX)) {
8858 + pr_debug("%s: Unsupported event : %d queue number : %d\n",
8859 + __func__, event, qno);
8863 + test_and_clear_bit(qno, &client->queue_mask[event]);
8866 + case EVENT_RX_PKT_IND:
8867 + if (!(desc->ctrl & CL_DESC_OWN))
8868 + hif_lib_indicate_client(client->id,
8869 + EVENT_RX_PKT_IND, qno);
8872 + case EVENT_HIGH_RX_WM:
8873 + case EVENT_TXDONE_IND:
8882 + * This function gets one packet from the specified client queue
8883 + * It also refill the rx buffer
8885 +void *hif_lib_receive_pkt(struct hif_client_s *client, int qno, int *len, int
8886 + *ofst, unsigned int *rx_ctrl,
8887 + unsigned int *desc_ctrl, void **priv_data)
8889 + struct hif_client_rx_queue *queue = &client->rx_q[qno];
8890 + struct rx_queue_desc *desc;
8894 + * Following lock is to protect rx queue access from,
8895 + * hif_lib_event_handler_start.
8896 + * In general below lock is not required, because hif_lib_xmit_pkt and
8897 + * hif_lib_event_handler_start are called from napi poll and which is
8898 + * not re-entrant. But if some client use in different way this lock is
8901 + /*spin_lock_irqsave(&client->rx_lock, flags); */
8902 + desc = queue->base + queue->read_idx;
8903 + if (!(desc->ctrl & CL_DESC_OWN)) {
8904 + pkt = desc->data - pfe_pkt_headroom;
8906 + *rx_ctrl = desc->client_ctrl;
8907 + *desc_ctrl = desc->ctrl;
8909 + if (desc->ctrl & CL_DESC_FIRST) {
8910 + u16 size = *rx_ctrl >> HIF_CTRL_RX_OFFSET_OFST;
8913 + size += PFE_PARSE_INFO_SIZE;
8914 + *len = CL_DESC_BUF_LEN(desc->ctrl) -
8915 + PFE_PKT_HEADER_SZ - size;
8916 + *ofst = pfe_pkt_headroom + PFE_PKT_HEADER_SZ
8918 + *priv_data = desc->data + PFE_PKT_HEADER_SZ;
8920 + *len = CL_DESC_BUF_LEN(desc->ctrl) -
8921 + PFE_PKT_HEADER_SZ - PFE_PARSE_INFO_SIZE;
8922 + *ofst = pfe_pkt_headroom
8923 + + PFE_PKT_HEADER_SZ
8924 + + PFE_PARSE_INFO_SIZE;
8925 + *priv_data = NULL;
8929 + *len = CL_DESC_BUF_LEN(desc->ctrl);
8930 + *ofst = pfe_pkt_headroom;
8934 + * Needed so we don't free a buffer/page
8935 + * twice on module_exit
8937 + desc->data = NULL;
8940 + * Ensure everything else is written to DDR before
8941 + * writing bd->ctrl
8945 + desc->ctrl = CL_DESC_BUF_LEN(pfe_pkt_size) | CL_DESC_OWN;
8946 + queue->read_idx = (queue->read_idx + 1) & (queue->size - 1);
8949 + /*spin_unlock_irqrestore(&client->rx_lock, flags); */
8953 +static inline void hif_hdr_write(struct hif_hdr *pkt_hdr, unsigned int
8954 + client_id, unsigned int qno,
8957 + /* Optimize the write since the destinaton may be non-cacheable */
8958 + if (!((unsigned long)pkt_hdr & 0x3)) {
8959 + ((u32 *)pkt_hdr)[0] = (client_ctrl << 16) | (qno << 8) |
8962 + ((u16 *)pkt_hdr)[0] = (qno << 8) | (client_id & 0xFF);
8963 + ((u16 *)pkt_hdr)[1] = (client_ctrl & 0xFFFF);
8967 +/*This function puts the given packet in the specific client queue */
8968 +void __hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void
8969 + *data, unsigned int len, u32 client_ctrl,
8970 + unsigned int flags, void *client_data)
8972 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
8973 + struct tx_queue_desc *desc = queue->base + queue->write_idx;
8975 + /* First buffer */
8976 + if (flags & HIF_FIRST_BUFFER) {
8977 + data -= sizeof(struct hif_hdr);
8978 + len += sizeof(struct hif_hdr);
8980 + hif_hdr_write(data, client->id, qno, client_ctrl);
8983 + desc->data = client_data;
8984 + desc->ctrl = CL_DESC_OWN | CL_DESC_FLAGS(flags);
8986 + __hif_xmit_pkt(&pfe->hif, client->id, qno, data, len, flags);
8988 + queue->write_idx = (queue->write_idx + 1) & (queue->size - 1);
8989 + queue->tx_pending++;
8990 + queue->jiffies_last_packet = jiffies;
8993 +void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
8994 + unsigned int *flags, int count)
8996 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
8997 + struct tx_queue_desc *desc = queue->base + queue->read_idx;
8999 + pr_debug("%s: qno : %d rd_indx: %d pending:%d\n", __func__, qno,
9000 + queue->read_idx, queue->tx_pending);
9002 + if (!queue->tx_pending)
9005 + if (queue->nocpy_flag && !queue->done_tmu_tx_pkts) {
9006 + u32 tmu_tx_pkts = be32_to_cpu(pe_dmem_read(TMU0_ID +
9007 + client->id, TMU_DM_TX_TRANS, 4));
9009 + if (queue->prev_tmu_tx_pkts > tmu_tx_pkts)
9010 + queue->done_tmu_tx_pkts = UINT_MAX -
9011 + queue->prev_tmu_tx_pkts + tmu_tx_pkts;
9013 + queue->done_tmu_tx_pkts = tmu_tx_pkts -
9014 + queue->prev_tmu_tx_pkts;
9016 + queue->prev_tmu_tx_pkts = tmu_tx_pkts;
9018 + if (!queue->done_tmu_tx_pkts)
9022 + if (desc->ctrl & CL_DESC_OWN)
9025 + queue->read_idx = (queue->read_idx + 1) & (queue->size - 1);
9026 + queue->tx_pending--;
9028 + *flags = CL_DESC_GET_FLAGS(desc->ctrl);
9030 + if (queue->done_tmu_tx_pkts && (*flags & HIF_LAST_BUFFER))
9031 + queue->done_tmu_tx_pkts--;
9033 + return desc->data;
9036 +static void hif_lib_tmu_credit_init(struct pfe *pfe)
9040 + for (i = 0; i < NUM_GEMAC_SUPPORT; i++)
9041 + for (q = 0; q < emac_txq_cnt; q++) {
9042 + pfe->tmu_credit.tx_credit_max[i][q] = (q == 0) ?
9043 + DEFAULT_Q0_QDEPTH : DEFAULT_MAX_QDEPTH;
9044 + pfe->tmu_credit.tx_credit[i][q] =
9045 + pfe->tmu_credit.tx_credit_max[i][q];
9049 +/* __hif_lib_update_credit
9051 + * @param[in] client hif client context
9052 + * @param[in] queue queue number in match with TMU
9054 +void __hif_lib_update_credit(struct hif_client_s *client, unsigned int queue)
9056 + unsigned int tmu_tx_packets, tmp;
9059 + tmu_tx_packets = be32_to_cpu(pe_dmem_read(TMU0_ID +
9060 + client->id, (TMU_DM_TX_TRANS + (queue * 4)), 4));
9062 + /* tx_packets counter overflowed */
9063 + if (tmu_tx_packets >
9064 + pfe->tmu_credit.tx_packets[client->id][queue]) {
9065 + tmp = UINT_MAX - tmu_tx_packets +
9066 + pfe->tmu_credit.tx_packets[client->id][queue];
9068 + pfe->tmu_credit.tx_credit[client->id][queue] =
9069 + pfe->tmu_credit.tx_credit_max[client->id][queue] - tmp;
9071 + /* TMU tx <= pfe_eth tx, normal case or both OF since
9074 + pfe->tmu_credit.tx_credit[client->id][queue] =
9075 + pfe->tmu_credit.tx_credit_max[client->id][queue] -
9076 + (pfe->tmu_credit.tx_packets[client->id][queue] -
9082 +int pfe_hif_lib_init(struct pfe *pfe)
9086 + pr_info("%s\n", __func__);
9090 + pfe_pkt_size = min(PAGE_SIZE, MAX_PFE_PKT_SIZE);
9091 + pfe_pkt_headroom = 0;
9094 + pfe_pkt_size = PFE_PKT_SIZE;
9095 + pfe_pkt_headroom = PFE_PKT_HEADROOM;
9099 + emac_txq_cnt = EMAC_TXQ_CNT / 2;
9101 + emac_txq_cnt = EMAC_TXQ_CNT;
9103 + hif_lib_tmu_credit_init(pfe);
9104 + pfe->hif.shm = &ghif_shm;
9105 + rc = pfe_hif_shm_init(pfe->hif.shm);
9110 +void pfe_hif_lib_exit(struct pfe *pfe)
9112 + pr_info("%s\n", __func__);
9114 + pfe_hif_shm_clean(pfe->hif.shm);
9117 +++ b/drivers/staging/fsl_ppfe/pfe_hif_lib.h
9119 +/* SPDX-License-Identifier: GPL-2.0+ */
9121 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9122 + * Copyright 2017 NXP
9125 +#ifndef _PFE_HIF_LIB_H_
9126 +#define _PFE_HIF_LIB_H_
9128 +#include "pfe_hif.h"
9130 +#define HIF_CL_REQ_TIMEOUT 10
9131 +#define GFP_DMA_PFE 0
9132 +#define PFE_PARSE_INFO_SIZE 16
9135 + REQUEST_CL_REGISTER = 0,
9136 + REQUEST_CL_UNREGISTER,
9141 + /* Event to indicate that client rx queue is reached water mark level */
9142 + EVENT_HIGH_RX_WM = 0,
9143 + /* Event to indicate that, packet received for client */
9145 + /* Event to indicate that, packet tx done for client */
9150 +/*structure to store client queue info */
9152 +/*structure to store client queue info */
9153 +struct hif_client_rx_queue {
9154 + struct rx_queue_desc *base;
9160 +struct hif_client_tx_queue {
9161 + struct tx_queue_desc *base;
9166 + unsigned long jiffies_last_packet;
9168 + u32 prev_tmu_tx_pkts;
9169 + u32 done_tmu_tx_pkts;
9172 +struct hif_client_s {
9181 + struct hif_client_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
9182 + struct hif_client_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
9183 + int (*event_handler)(void *priv, int event, int data);
9184 + unsigned long queue_mask[HIF_EVENT_MAX];
9190 + * Client specific shared memory
9191 + * It contains number of Rx/Tx queues, base addresses and queue sizes
9193 +struct hif_client_shm {
9194 + u32 ctrl; /*0-7: number of Rx queues, 8-15: number of tx queues */
9195 + unsigned long rx_qbase; /*Rx queue base address */
9196 + u32 rx_qsize; /*each Rx queue size, all Rx queues are of same size */
9197 + unsigned long tx_qbase; /* Tx queue base address */
9198 + u32 tx_qsize; /*each Tx queue size, all Tx queues are of same size */
9201 +/*Client shared memory ctrl bit description */
9202 +#define CLIENT_CTRL_RX_Q_CNT_OFST 0
9203 +#define CLIENT_CTRL_TX_Q_CNT_OFST 8
9204 +#define CLIENT_CTRL_RX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_RX_Q_CNT_OFST) \
9206 +#define CLIENT_CTRL_TX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_TX_Q_CNT_OFST) \
9210 + * Shared memory used to communicate between HIF driver and host/client drivers
9211 + * Before starting the hif driver rx_buf_pool ans rx_buf_pool_cnt should be
9212 + * initialized with host buffers and buffers count in the pool.
9213 + * rx_buf_pool_cnt should be >= HIF_RX_DESC_NT.
9217 + u32 rx_buf_pool_cnt; /*Number of rx buffers available*/
9218 + /*Rx buffers required to initialize HIF rx descriptors */
9219 + void *rx_buf_pool[HIF_RX_DESC_NT];
9220 + unsigned long g_client_status[2]; /*Global client status bit mask */
9221 + /* Client specific shared memory */
9222 + struct hif_client_shm client[HIF_CLIENTS_MAX];
9225 +#define CL_DESC_OWN BIT(31)
9226 +/* This sets owner ship to HIF driver */
9227 +#define CL_DESC_LAST BIT(30)
9228 +/* This indicates last packet for multi buffers handling */
9229 +#define CL_DESC_FIRST BIT(29)
9230 +/* This indicates first packet for multi buffers handling */
9232 +#define CL_DESC_BUF_LEN(x) ((x) & 0xFFFF)
9233 +#define CL_DESC_FLAGS(x) (((x) & 0xF) << 16)
9234 +#define CL_DESC_GET_FLAGS(x) (((x) >> 16) & 0xF)
9236 +struct rx_queue_desc {
9238 + u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
9242 +struct tx_queue_desc {
9244 + u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
9247 +/* HIF Rx is not working properly for 2-byte aligned buffers and
9248 + * ip_header should be 4byte aligned for better iperformance.
9249 + * "ip_header = 64 + 6(hif_header) + 14 (MAC Header)" will be 4byte aligned.
9251 +#define PFE_PKT_HEADER_SZ sizeof(struct hif_hdr)
9252 +/* must be big enough for headroom, pkt size and skb shared info */
9253 +#define PFE_BUF_SIZE 2048
9254 +#define PFE_PKT_HEADROOM 128
9256 +#define SKB_SHARED_INFO_SIZE SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
9257 +#define PFE_PKT_SIZE (PFE_BUF_SIZE - PFE_PKT_HEADROOM \
9258 + - SKB_SHARED_INFO_SIZE)
9259 +#define MAX_L2_HDR_SIZE 14 /* Not correct for VLAN/PPPoE */
9260 +#define MAX_L3_HDR_SIZE 20 /* Not correct for IPv6 */
9261 +#define MAX_L4_HDR_SIZE 60 /* TCP with maximum options */
9262 +#define MAX_HDR_SIZE (MAX_L2_HDR_SIZE + MAX_L3_HDR_SIZE \
9263 + + MAX_L4_HDR_SIZE)
9264 +/* Used in page mode to clamp packet size to the maximum supported by the hif
9265 + *hw interface (<16KiB)
9267 +#define MAX_PFE_PKT_SIZE 16380UL
9269 +extern unsigned int pfe_pkt_size;
9270 +extern unsigned int pfe_pkt_headroom;
9271 +extern unsigned int page_mode;
9272 +extern unsigned int lro_mode;
9273 +extern unsigned int tx_qos;
9274 +extern unsigned int emac_txq_cnt;
9276 +int pfe_hif_lib_init(struct pfe *pfe);
9277 +void pfe_hif_lib_exit(struct pfe *pfe);
9278 +int hif_lib_client_register(struct hif_client_s *client);
9279 +int hif_lib_client_unregister(struct hif_client_s *client);
9280 +void __hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void
9281 + *data, unsigned int len, u32 client_ctrl,
9282 + unsigned int flags, void *client_data);
9283 +int hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void *data,
9284 + unsigned int len, u32 client_ctrl, void *client_data);
9285 +void hif_lib_indicate_client(int cl_id, int event, int data);
9286 +int hif_lib_event_handler_start(struct hif_client_s *client, int event, int
9288 +int hif_lib_tmu_queue_start(struct hif_client_s *client, int qno);
9289 +int hif_lib_tmu_queue_stop(struct hif_client_s *client, int qno);
9290 +void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
9291 + unsigned int *flags, int count);
9292 +void *hif_lib_receive_pkt(struct hif_client_s *client, int qno, int *len, int
9293 + *ofst, unsigned int *rx_ctrl,
9294 + unsigned int *desc_ctrl, void **priv_data);
9295 +void __hif_lib_update_credit(struct hif_client_s *client, unsigned int queue);
9296 +void hif_lib_set_rx_cpu_affinity(struct hif_client_s *client, int cpu_id);
9297 +void hif_lib_set_tx_queue_nocpy(struct hif_client_s *client, int qno, int
9299 +static inline int hif_lib_tx_avail(struct hif_client_s *client, unsigned int
9302 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
9304 + return (queue->size - queue->tx_pending);
9307 +static inline int hif_lib_get_tx_wr_index(struct hif_client_s *client, unsigned
9310 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
9312 + return queue->write_idx;
9315 +static inline int hif_lib_tx_pending(struct hif_client_s *client, unsigned int
9318 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
9320 + return queue->tx_pending;
9323 +#define hif_lib_tx_credit_avail(pfe, id, qno) \
9324 + ((pfe)->tmu_credit.tx_credit[id][qno])
9326 +#define hif_lib_tx_credit_max(pfe, id, qno) \
9327 + ((pfe)->tmu_credit.tx_credit_max[id][qno])
9332 +#define hif_lib_tx_credit_use(pfe, id, qno, credit) \
9333 + ({ typeof(pfe) pfe_ = pfe; \
9334 + typeof(id) id_ = id; \
9335 + typeof(qno) qno_ = qno_; \
9336 + typeof(credit) credit_ = credit; \
9339 + (pfe_)->tmu_credit.tx_credit[id_][qno_]\
9341 + (pfe_)->tmu_credit.tx_packets[id_][qno_]\
9347 +#endif /* _PFE_HIF_LIB_H_ */
9349 +++ b/drivers/staging/fsl_ppfe/pfe_hw.c
9351 +// SPDX-License-Identifier: GPL-2.0+
9353 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9354 + * Copyright 2017 NXP
9357 +#include "pfe_mod.h"
9358 +#include "pfe_hw.h"
9360 +/* Functions to handle most of pfe hw register initialization */
9361 +int pfe_hw_init(struct pfe *pfe, int resume)
9363 + struct class_cfg class_cfg = {
9364 + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
9365 + .route_table_baseaddr = pfe->ddr_phys_baseaddr +
9366 + ROUTE_TABLE_BASEADDR,
9367 + .route_table_hash_bits = ROUTE_TABLE_HASH_BITS,
9370 + struct tmu_cfg tmu_cfg = {
9371 + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
9372 + .llm_base_addr = pfe->ddr_phys_baseaddr + TMU_LLM_BASEADDR,
9373 + .llm_queue_len = TMU_LLM_QUEUE_LEN,
9376 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
9377 + struct util_cfg util_cfg = {
9378 + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
9382 + struct BMU_CFG bmu1_cfg = {
9383 + .baseaddr = CBUS_VIRT_TO_PFE(LMEM_BASE_ADDR +
9384 + BMU1_LMEM_BASEADDR),
9385 + .count = BMU1_BUF_COUNT,
9386 + .size = BMU1_BUF_SIZE,
9387 + .low_watermark = 10,
9388 + .high_watermark = 15,
9391 + struct BMU_CFG bmu2_cfg = {
9392 + .baseaddr = DDR_PHYS_TO_PFE(pfe->ddr_phys_baseaddr +
9393 + BMU2_DDR_BASEADDR),
9394 + .count = BMU2_BUF_COUNT,
9395 + .size = BMU2_BUF_SIZE,
9396 + .low_watermark = 250,
9397 + .high_watermark = 253,
9400 + struct gpi_cfg egpi1_cfg = {
9401 + .lmem_rtry_cnt = EGPI1_LMEM_RTRY_CNT,
9402 + .tmlf_txthres = EGPI1_TMLF_TXTHRES,
9403 + .aseq_len = EGPI1_ASEQ_LEN,
9404 + .mtip_pause_reg = CBUS_VIRT_TO_PFE(EMAC1_BASE_ADDR +
9408 + struct gpi_cfg egpi2_cfg = {
9409 + .lmem_rtry_cnt = EGPI2_LMEM_RTRY_CNT,
9410 + .tmlf_txthres = EGPI2_TMLF_TXTHRES,
9411 + .aseq_len = EGPI2_ASEQ_LEN,
9412 + .mtip_pause_reg = CBUS_VIRT_TO_PFE(EMAC2_BASE_ADDR +
9416 + struct gpi_cfg hgpi_cfg = {
9417 + .lmem_rtry_cnt = HGPI_LMEM_RTRY_CNT,
9418 + .tmlf_txthres = HGPI_TMLF_TXTHRES,
9419 + .aseq_len = HGPI_ASEQ_LEN,
9420 + .mtip_pause_reg = 0,
9423 + pr_info("%s\n", __func__);
9425 +#if !defined(LS1012A_PFE_RESET_WA)
9426 + /* LS1012A needs this to make PE work correctly */
9427 + writel(0x3, CLASS_PE_SYS_CLK_RATIO);
9428 + writel(0x3, TMU_PE_SYS_CLK_RATIO);
9429 + writel(0x3, UTIL_PE_SYS_CLK_RATIO);
9430 + usleep_range(10, 20);
9433 + pr_info("CLASS version: %x\n", readl(CLASS_VERSION));
9434 + pr_info("TMU version: %x\n", readl(TMU_VERSION));
9436 + pr_info("BMU1 version: %x\n", readl(BMU1_BASE_ADDR +
9438 + pr_info("BMU2 version: %x\n", readl(BMU2_BASE_ADDR +
9441 + pr_info("EGPI1 version: %x\n", readl(EGPI1_BASE_ADDR +
9443 + pr_info("EGPI2 version: %x\n", readl(EGPI2_BASE_ADDR +
9445 + pr_info("HGPI version: %x\n", readl(HGPI_BASE_ADDR +
9448 + pr_info("HIF version: %x\n", readl(HIF_VERSION));
9449 + pr_info("HIF NOPCY version: %x\n", readl(HIF_NOCPY_VERSION));
9451 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
9452 + pr_info("UTIL version: %x\n", readl(UTIL_VERSION));
9454 + while (!(readl(TMU_CTRL) & ECC_MEM_INIT_DONE))
9460 + bmu_init(BMU1_BASE_ADDR, &bmu1_cfg);
9462 + pr_info("bmu_init(1) done\n");
9464 + bmu_init(BMU2_BASE_ADDR, &bmu2_cfg);
9466 + pr_info("bmu_init(2) done\n");
9468 + class_cfg.resume = resume ? 1 : 0;
9470 + class_init(&class_cfg);
9472 + pr_info("class_init() done\n");
9474 + tmu_init(&tmu_cfg);
9476 + pr_info("tmu_init() done\n");
9477 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
9478 + util_init(&util_cfg);
9480 + pr_info("util_init() done\n");
9482 + gpi_init(EGPI1_BASE_ADDR, &egpi1_cfg);
9484 + pr_info("gpi_init(1) done\n");
9486 + gpi_init(EGPI2_BASE_ADDR, &egpi2_cfg);
9488 + pr_info("gpi_init(2) done\n");
9490 + gpi_init(HGPI_BASE_ADDR, &hgpi_cfg);
9492 + pr_info("gpi_init(hif) done\n");
9494 + bmu_enable(BMU1_BASE_ADDR);
9496 + pr_info("bmu_enable(1) done\n");
9498 + bmu_enable(BMU2_BASE_ADDR);
9500 + pr_info("bmu_enable(2) done\n");
9505 +void pfe_hw_exit(struct pfe *pfe)
9507 + pr_info("%s\n", __func__);
9509 + bmu_disable(BMU1_BASE_ADDR);
9510 + bmu_reset(BMU1_BASE_ADDR);
9512 + bmu_disable(BMU2_BASE_ADDR);
9513 + bmu_reset(BMU2_BASE_ADDR);
9516 +++ b/drivers/staging/fsl_ppfe/pfe_hw.h
9518 +/* SPDX-License-Identifier: GPL-2.0+ */
9520 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9521 + * Copyright 2017 NXP
9527 +#define PE_SYS_CLK_RATIO 1 /* SYS/AXI = 250MHz, HFE = 500MHz */
9529 +int pfe_hw_init(struct pfe *pfe, int resume);
9530 +void pfe_hw_exit(struct pfe *pfe);
9532 +#endif /* _PFE_HW_H_ */
9534 +++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
9536 +// SPDX-License-Identifier: GPL-2.0+
9538 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9539 + * Copyright 2017 NXP
9542 +#include <linux/module.h>
9543 +#include <linux/device.h>
9544 +#include <linux/of.h>
9545 +#include <linux/of_net.h>
9546 +#include <linux/of_address.h>
9547 +#include <linux/of_mdio.h>
9548 +#include <linux/platform_device.h>
9549 +#include <linux/slab.h>
9550 +#include <linux/clk.h>
9551 +#include <linux/mfd/syscon.h>
9552 +#include <linux/regmap.h>
9554 +#include "pfe_mod.h"
9556 +extern bool pfe_use_old_dts_phy;
9557 +struct ls1012a_pfe_platform_data pfe_platform_data;
9559 +static int pfe_get_gemac_if_properties(struct device_node *gem,
9561 + struct ls1012a_pfe_platform_data *pdata)
9563 + struct device_node *phy_node = NULL;
9567 + const void *mac_addr;
9569 + addr = of_get_property(gem, "reg", &size);
9570 + port = be32_to_cpup(addr);
9572 + pdata->ls1012a_eth_pdata[port].gem_id = port;
9574 + mac_addr = of_get_mac_address(gem);
9576 + memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
9580 + phy_node = of_parse_phandle(gem, "phy-handle", 0);
9581 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
9583 + pfe_use_old_dts_phy = false;
9584 + goto process_phynode;
9585 + } else if (of_phy_is_fixed_link(gem)) {
9586 + pfe_use_old_dts_phy = false;
9587 + if (of_phy_register_fixed_link(gem) < 0) {
9588 + pr_err("broken fixed-link specification\n");
9591 + phy_node = of_node_get(gem);
9592 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
9593 + } else if (of_get_property(gem, "fsl,pfe-phy-if-flags", &size)) {
9594 + pfe_use_old_dts_phy = true;
9595 + /* Use old dts properties for phy handling */
9596 + addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
9597 + pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
9599 + addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
9601 + pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
9604 + phy_id = be32_to_cpup(addr);
9605 + pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
9606 + pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
9609 + /* If PHY is enabled, read mdio properties */
9610 + if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
9614 + pr_info("%s: No PHY or fixed-link\n", __func__);
9619 + pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
9620 + if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
9621 + pr_err("%s:%d Incorrect Phy mode....\n", __func__,
9624 + addr = of_get_property(gem, "fsl,mdio-mux-val", &size);
9626 + pr_err("%s: Invalid mdio-mux-val....\n", __func__);
9628 + phy_id = be32_to_cpup(addr);
9629 + pdata->ls1012a_eth_pdata[port].mdio_muxval = phy_id;
9632 + if (pdata->ls1012a_eth_pdata[port].phy_id < 32)
9633 + pfe->mdio_muxval[pdata->ls1012a_eth_pdata[port].phy_id] =
9634 + pdata->ls1012a_eth_pdata[port].mdio_muxval;
9637 + pdata->ls1012a_mdio_pdata[port].irq[0] = PHY_POLL;
9648 + * pfe_platform_probe -
9652 +static int pfe_platform_probe(struct platform_device *pdev)
9654 + struct resource res;
9655 + int ii, rc, interface_count = 0, size = 0;
9657 + struct device_node *np, *gem = NULL;
9658 + struct clk *pfe_clk;
9660 + np = pdev->dev.of_node;
9663 + pr_err("Invalid device node\n");
9667 + pfe = kzalloc(sizeof(*pfe), GFP_KERNEL);
9673 + platform_set_drvdata(pdev, pfe);
9675 + dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9677 + if (of_address_to_resource(np, 1, &res)) {
9679 + pr_err("failed to get ddr resource\n");
9683 + pfe->ddr_phys_baseaddr = res.start;
9684 + pfe->ddr_size = resource_size(&res);
9685 + pfe->ddr_baseaddr = phys_to_virt(res.start);
9688 + syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
9690 + if (IS_ERR(pfe->scfg)) {
9691 + dev_err(&pdev->dev, "No syscfg phandle specified\n");
9692 + return PTR_ERR(pfe->scfg);
9695 + pfe->cbus_baseaddr = of_iomap(np, 0);
9696 + if (!pfe->cbus_baseaddr) {
9698 + pr_err("failed to get axi resource\n");
9702 + pfe->hif_irq = platform_get_irq(pdev, 0);
9703 + if (pfe->hif_irq < 0) {
9704 + pr_err("platform_get_irq for hif failed\n");
9705 + rc = pfe->hif_irq;
9709 + pfe->wol_irq = platform_get_irq(pdev, 2);
9710 + if (pfe->wol_irq < 0) {
9711 + pr_err("platform_get_irq for WoL failed\n");
9712 + rc = pfe->wol_irq;
9716 + /* Read interface count */
9717 + prop = of_get_property(np, "fsl,pfe-num-interfaces", &size);
9719 + pr_err("Failed to read number of interfaces\n");
9724 + interface_count = be32_to_cpup(prop);
9725 + if (interface_count <= 0) {
9726 + pr_err("No ethernet interface count : %d\n",
9732 + pfe_platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
9734 + for (ii = 0; ii < interface_count; ii++) {
9735 + gem = of_get_next_child(np, gem);
9737 + pfe_get_gemac_if_properties(gem, ii,
9738 + &pfe_platform_data);
9740 + pr_err("Unable to find interface %d\n", ii);
9744 + pfe->dev = &pdev->dev;
9746 + pfe->dev->platform_data = &pfe_platform_data;
9748 + /* declare WoL capabilities */
9749 + device_init_wakeup(&pdev->dev, true);
9751 + /* find the clocks */
9752 + pfe_clk = devm_clk_get(pfe->dev, "pfe");
9753 + if (IS_ERR(pfe_clk))
9754 + return PTR_ERR(pfe_clk);
9756 + /* PFE clock is (platform clock / 2) */
9757 + /* save sys_clk value as KHz */
9758 + pfe->ctrl.sys_clk = clk_get_rate(pfe_clk) / (2 * 1000);
9760 + rc = pfe_probe(pfe);
9769 + iounmap(pfe->cbus_baseaddr);
9773 + platform_set_drvdata(pdev, NULL);
9782 + * pfe_platform_remove -
9784 +static int pfe_platform_remove(struct platform_device *pdev)
9786 + struct pfe *pfe = platform_get_drvdata(pdev);
9789 + pr_info("%s\n", __func__);
9791 + rc = pfe_remove(pfe);
9793 + iounmap(pfe->cbus_baseaddr);
9795 + platform_set_drvdata(pdev, NULL);
9803 +#ifdef CONFIG_PM_SLEEP
9804 +int pfe_platform_suspend(struct device *dev)
9806 + struct pfe *pfe = platform_get_drvdata(to_platform_device(dev));
9807 + struct net_device *netdev;
9812 + for (i = 0; i < (NUM_GEMAC_SUPPORT); i++) {
9813 + netdev = pfe->eth.eth_priv[i]->ndev;
9815 + netif_device_detach(netdev);
9817 + if (netif_running(netdev))
9818 + if (pfe_eth_suspend(netdev))
9822 + /* Shutdown PFE only if we're not waking up the system */
9824 +#if defined(LS1012A_PFE_RESET_WA)
9825 + pfe_hif_rx_idle(&pfe->hif);
9827 + pfe_ctrl_suspend(&pfe->ctrl);
9828 + pfe_firmware_exit(pfe);
9830 + pfe_hif_exit(pfe);
9831 + pfe_hif_lib_exit(pfe);
9839 +static int pfe_platform_resume(struct device *dev)
9841 + struct pfe *pfe = platform_get_drvdata(to_platform_device(dev));
9842 + struct net_device *netdev;
9846 + pfe_hw_init(pfe, 1);
9847 + pfe_hif_lib_init(pfe);
9848 + pfe_hif_init(pfe);
9849 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
9854 + pfe_ctrl_resume(&pfe->ctrl);
9857 + for (i = 0; i < (NUM_GEMAC_SUPPORT); i++) {
9858 + netdev = pfe->eth.eth_priv[i]->ndev;
9860 + if (pfe->mdio.mdio_priv[i]->mii_bus)
9861 + pfe_eth_mdio_reset(pfe->mdio.mdio_priv[i]->mii_bus);
9863 + if (netif_running(netdev))
9864 + pfe_eth_resume(netdev);
9866 + netif_device_attach(netdev);
9871 +#define pfe_platform_suspend NULL
9872 +#define pfe_platform_resume NULL
9875 +static const struct dev_pm_ops pfe_platform_pm_ops = {
9876 + SET_SYSTEM_SLEEP_PM_OPS(pfe_platform_suspend, pfe_platform_resume)
9880 +static const struct of_device_id pfe_match[] = {
9882 + .compatible = "fsl,pfe",
9886 +MODULE_DEVICE_TABLE(of, pfe_match);
9888 +static struct platform_driver pfe_platform_driver = {
9889 + .probe = pfe_platform_probe,
9890 + .remove = pfe_platform_remove,
9893 + .of_match_table = pfe_match,
9895 + .pm = &pfe_platform_pm_ops,
9900 +module_platform_driver(pfe_platform_driver);
9901 +MODULE_LICENSE("GPL");
9902 +MODULE_DESCRIPTION("PFE Ethernet driver");
9903 +MODULE_AUTHOR("NXP DNCPE");
9905 +++ b/drivers/staging/fsl_ppfe/pfe_mod.c
9907 +// SPDX-License-Identifier: GPL-2.0+
9909 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9910 + * Copyright 2017 NXP
9913 +#include <linux/dma-mapping.h>
9914 +#include "pfe_mod.h"
9915 +#include "pfe_cdev.h"
9918 +module_param(us, uint, 0444);
9919 +MODULE_PARM_DESC(us, "0: module enabled for kernel networking (DEFAULT)\n"
9920 + "1: module enabled for userspace networking\n");
9926 +int pfe_probe(struct pfe *pfe)
9930 + if (pfe->ddr_size < DDR_MAX_SIZE) {
9931 + pr_err("%s: required DDR memory (%x) above platform ddr memory (%x)\n",
9932 + __func__, (unsigned int)DDR_MAX_SIZE, pfe->ddr_size);
9937 + if (((int)(pfe->ddr_phys_baseaddr + BMU2_DDR_BASEADDR) &
9938 + (8 * SZ_1M - 1)) != 0) {
9939 + pr_err("%s: BMU2 base address (0x%x) must be aligned on 8MB boundary\n",
9940 + __func__, (int)pfe->ddr_phys_baseaddr +
9941 + BMU2_DDR_BASEADDR);
9946 + pr_info("cbus_baseaddr: %lx, ddr_baseaddr: %lx, ddr_phys_baseaddr: %lx, ddr_size: %x\n",
9947 + (unsigned long)pfe->cbus_baseaddr,
9948 + (unsigned long)pfe->ddr_baseaddr,
9949 + pfe->ddr_phys_baseaddr, pfe->ddr_size);
9951 + pfe_lib_init(pfe->cbus_baseaddr, pfe->ddr_baseaddr,
9952 + pfe->ddr_phys_baseaddr, pfe->ddr_size);
9954 + rc = pfe_hw_init(pfe, 0);
9959 + goto firmware_init;
9961 + rc = pfe_hif_lib_init(pfe);
9965 + rc = pfe_hif_init(pfe);
9970 + rc = pfe_firmware_init(pfe);
9972 + goto err_firmware;
9974 + rc = pfe_ctrl_init(pfe);
9978 + rc = pfe_eth_init(pfe);
9982 + rc = pfe_sysfs_init(pfe);
9986 + rc = pfe_debugfs_init(pfe);
9991 + /* Creating a character device */
9992 + rc = pfe_cdev_init();
10000 + pfe_debugfs_exit(pfe);
10003 + pfe_sysfs_exit(pfe);
10006 + pfe_eth_exit(pfe);
10009 + pfe_ctrl_exit(pfe);
10012 + pfe_firmware_exit(pfe);
10016 + goto err_hif_lib;
10018 + pfe_hif_exit(pfe);
10021 + pfe_hif_lib_exit(pfe);
10024 + pfe_hw_exit(pfe);
10033 +int pfe_remove(struct pfe *pfe)
10035 + pr_info("%s\n", __func__);
10040 + pfe_debugfs_exit(pfe);
10042 + pfe_sysfs_exit(pfe);
10044 + pfe_eth_exit(pfe);
10046 + pfe_ctrl_exit(pfe);
10048 +#if defined(LS1012A_PFE_RESET_WA)
10049 + pfe_hif_rx_idle(&pfe->hif);
10051 + pfe_firmware_exit(pfe);
10056 + pfe_hif_exit(pfe);
10058 + pfe_hif_lib_exit(pfe);
10061 + pfe_hw_exit(pfe);
10066 +++ b/drivers/staging/fsl_ppfe/pfe_mod.h
10068 +/* SPDX-License-Identifier: GPL-2.0+ */
10070 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10071 + * Copyright 2017 NXP
10074 +#ifndef _PFE_MOD_H_
10075 +#define _PFE_MOD_H_
10077 +#include <linux/device.h>
10078 +#include <linux/elf.h>
10080 +extern unsigned int us;
10084 +#include "pfe_hw.h"
10085 +#include "pfe_firmware.h"
10086 +#include "pfe_ctrl.h"
10087 +#include "pfe_hif.h"
10088 +#include "pfe_hif_lib.h"
10089 +#include "pfe_eth.h"
10090 +#include "pfe_sysfs.h"
10091 +#include "pfe_perfmon.h"
10092 +#include "pfe_debugfs.h"
10094 +#define PHYID_MAX_VAL 32
10096 +struct pfe_tmu_credit {
10097 + /* Number of allowed TX packet in-flight, matches TMU queue size */
10098 + unsigned int tx_credit[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
10099 + unsigned int tx_credit_max[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
10100 + unsigned int tx_packets[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
10104 + struct regmap *scfg;
10105 + unsigned long ddr_phys_baseaddr;
10106 + void *ddr_baseaddr;
10107 + unsigned int ddr_size;
10108 + void *cbus_baseaddr;
10109 + void *apb_baseaddr;
10110 + unsigned long iram_phys_baseaddr;
10111 + void *iram_baseaddr;
10112 + unsigned long ipsec_phys_baseaddr;
10113 + void *ipsec_baseaddr;
10116 + int hif_client_irq;
10117 + struct device *dev;
10118 + struct dentry *dentry;
10119 + struct pfe_ctrl ctrl;
10120 + struct pfe_hif hif;
10121 + struct pfe_eth eth;
10122 + struct pfe_mdio mdio;
10123 + struct hif_client_s *hif_client[HIF_CLIENTS_MAX];
10124 +#if defined(CFG_DIAGS)
10125 + struct pfe_diags diags;
10127 + struct pfe_tmu_credit tmu_credit;
10128 + struct pfe_cpumon cpumon;
10129 + struct pfe_memmon memmon;
10131 + int mdio_muxval[PHYID_MAX_VAL];
10132 + struct clk *hfe_clock;
10135 +extern struct pfe *pfe;
10137 +int pfe_probe(struct pfe *pfe);
10138 +int pfe_remove(struct pfe *pfe);
10140 +/* DDR Mapping in reserved memory*/
10141 +#define ROUTE_TABLE_BASEADDR 0
10142 +#define ROUTE_TABLE_HASH_BITS 15 /* 32K entries */
10143 +#define ROUTE_TABLE_SIZE ((1 << ROUTE_TABLE_HASH_BITS) \
10144 + * CLASS_ROUTE_SIZE)
10145 +#define BMU2_DDR_BASEADDR (ROUTE_TABLE_BASEADDR + ROUTE_TABLE_SIZE)
10146 +#define BMU2_BUF_COUNT (4096 - 256)
10147 +/* This is to get a total DDR size of 12MiB */
10148 +#define BMU2_DDR_SIZE (DDR_BUF_SIZE * BMU2_BUF_COUNT)
10149 +#define UTIL_CODE_BASEADDR (BMU2_DDR_BASEADDR + BMU2_DDR_SIZE)
10150 +#define UTIL_CODE_SIZE (128 * SZ_1K)
10151 +#define UTIL_DDR_DATA_BASEADDR (UTIL_CODE_BASEADDR + UTIL_CODE_SIZE)
10152 +#define UTIL_DDR_DATA_SIZE (64 * SZ_1K)
10153 +#define CLASS_DDR_DATA_BASEADDR (UTIL_DDR_DATA_BASEADDR + UTIL_DDR_DATA_SIZE)
10154 +#define CLASS_DDR_DATA_SIZE (32 * SZ_1K)
10155 +#define TMU_DDR_DATA_BASEADDR (CLASS_DDR_DATA_BASEADDR + CLASS_DDR_DATA_SIZE)
10156 +#define TMU_DDR_DATA_SIZE (32 * SZ_1K)
10157 +#define TMU_LLM_BASEADDR (TMU_DDR_DATA_BASEADDR + TMU_DDR_DATA_SIZE)
10158 +#define TMU_LLM_QUEUE_LEN (8 * 512)
10159 +/* Must be power of two and at least 16 * 8 = 128 bytes */
10160 +#define TMU_LLM_SIZE (4 * 16 * TMU_LLM_QUEUE_LEN)
10161 +/* (4 TMU's x 16 queues x queue_len) */
10163 +#define DDR_MAX_SIZE (TMU_LLM_BASEADDR + TMU_LLM_SIZE)
10165 +/* LMEM Mapping */
10166 +#define BMU1_LMEM_BASEADDR 0
10167 +#define BMU1_BUF_COUNT 256
10168 +#define BMU1_LMEM_SIZE (LMEM_BUF_SIZE * BMU1_BUF_COUNT)
10170 +#endif /* _PFE_MOD_H */
10172 +++ b/drivers/staging/fsl_ppfe/pfe_perfmon.h
10174 +/* SPDX-License-Identifier: GPL-2.0+ */
10176 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10177 + * Copyright 2017 NXP
10180 +#ifndef _PFE_PERFMON_H_
10181 +#define _PFE_PERFMON_H_
10183 +#include "pfe/pfe.h"
10185 +#define CT_CPUMON_INTERVAL (1 * TIMER_TICKS_PER_SEC)
10187 +struct pfe_cpumon {
10188 + u32 cpu_usage_pct[MAX_PE];
10189 + u32 class_usage_pct;
10192 +struct pfe_memmon {
10193 + u32 kernel_memory_allocated;
10196 +int pfe_perfmon_init(struct pfe *pfe);
10197 +void pfe_perfmon_exit(struct pfe *pfe);
10199 +#endif /* _PFE_PERFMON_H_ */
10201 +++ b/drivers/staging/fsl_ppfe/pfe_sysfs.c
10203 +// SPDX-License-Identifier: GPL-2.0+
10205 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10206 + * Copyright 2017 NXP
10209 +#include <linux/module.h>
10210 +#include <linux/platform_device.h>
10212 +#include "pfe_mod.h"
10214 +#define PE_EXCEPTION_DUMP_ADDRESS 0x1fa8
10215 +#define NUM_QUEUES 16
10217 +static char register_name[20][5] = {
10218 + "EPC", "ECAS", "EID", "ED",
10219 + "r0", "r1", "r2", "r3",
10220 + "r4", "r5", "r6", "r7",
10221 + "r8", "r9", "r10", "r11",
10222 + "r12", "r13", "r14", "r15",
10225 +static char exception_name[14][20] = {
10227 + "HardwareFailure",
10229 + "InstBreakpoint",
10230 + "DataBreakpoint",
10232 + "PrivilegeViolation",
10235 + "AlignmentError",
10236 + "ArithmeticError",
10238 + "MemoryManagement",
10242 +static unsigned long class_do_clear;
10243 +static unsigned long tmu_do_clear;
10244 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10245 +static unsigned long util_do_clear;
10248 +static ssize_t display_pe_status(char *buf, int id, u32 dmem_addr, unsigned long
10253 + char statebuf[5];
10254 + struct pfe_cpumon *cpumon = &pfe->cpumon;
10255 + u32 debug_indicator;
10258 + *(u32 *)statebuf = pe_dmem_read(id, dmem_addr, 4);
10261 + statebuf[4] = '\0';
10262 + len += sprintf(buf + len, "state=%4s ", statebuf);
10264 + val = pe_dmem_read(id, dmem_addr, 4);
10266 + len += sprintf(buf + len, "ctr=%08x ", cpu_to_be32(val));
10268 + val = pe_dmem_read(id, dmem_addr, 4);
10269 + if (do_clear && val)
10270 + pe_dmem_write(id, 0, dmem_addr, 4);
10272 + len += sprintf(buf + len, "rx=%u ", cpu_to_be32(val));
10274 + val = pe_dmem_read(id, dmem_addr, 4);
10275 + if (do_clear && val)
10276 + pe_dmem_write(id, 0, dmem_addr, 4);
10278 + if (id >= TMU0_ID && id <= TMU_MAX_ID)
10279 + len += sprintf(buf + len, "qstatus=%x", cpu_to_be32(val));
10281 + len += sprintf(buf + len, "tx=%u", cpu_to_be32(val));
10283 + val = pe_dmem_read(id, dmem_addr, 4);
10284 + if (do_clear && val)
10285 + pe_dmem_write(id, 0, dmem_addr, 4);
10288 + len += sprintf(buf + len, " drop=%u", cpu_to_be32(val));
10290 + len += sprintf(buf + len, " load=%d%%", cpumon->cpu_usage_pct[id]);
10292 + len += sprintf(buf + len, "\n");
10294 + debug_indicator = pe_dmem_read(id, dmem_addr, 4);
10296 + if (!strncmp((char *)&debug_indicator, "DBUG", 4)) {
10299 + for (j = 0; j < 16; j++) {
10300 + debug[j] = pe_dmem_read(id, dmem_addr, 4);
10303 + pe_dmem_write(id, 0, dmem_addr, 4);
10308 + for (j = 0; j < last; j++) {
10309 + len += sprintf(buf + len, "%08x%s",
10310 + cpu_to_be32(debug[j]),
10311 + (j & 0x7) == 0x7 || j == last - 1 ? "\n" : " ");
10315 + if (!strncmp(statebuf, "DEAD", 4)) {
10316 + u32 i, dump = PE_EXCEPTION_DUMP_ADDRESS;
10318 + len += sprintf(buf + len, "Exception details:\n");
10319 + for (i = 0; i < 20; i++) {
10320 + debug[i] = pe_dmem_read(id, dump, 4);
10323 + len += sprintf(buf + len, "%4s = %08x (=%s) ",
10324 + register_name[i], cpu_to_be32(debug[i]),
10325 + exception_name[min((u32)
10326 + cpu_to_be32(debug[i]), (u32)13)]);
10328 + len += sprintf(buf + len, "%4s = %08x%s",
10329 + register_name[i], cpu_to_be32(debug[i]),
10330 + (i & 0x3) == 0x3 || i == 19 ? "\n" : " ");
10337 +static ssize_t class_phy_stats(char *buf, int phy)
10340 + int off1 = phy * 0x28;
10341 + int off2 = phy * 0x10;
10344 + off1 = CLASS_PHY4_RX_PKTS - CLASS_PHY1_RX_PKTS;
10346 + len += sprintf(buf + len, "phy: %d\n", phy);
10347 + len += sprintf(buf + len,
10348 + " rx: %10u, tx: %10u, intf: %10u, ipv4: %10u, ipv6: %10u\n",
10349 + readl(CLASS_PHY1_RX_PKTS + off1),
10350 + readl(CLASS_PHY1_TX_PKTS + off1),
10351 + readl(CLASS_PHY1_INTF_MATCH_PKTS + off1),
10352 + readl(CLASS_PHY1_V4_PKTS + off1),
10353 + readl(CLASS_PHY1_V6_PKTS + off1));
10355 + len += sprintf(buf + len,
10356 + " icmp: %10u, igmp: %10u, tcp: %10u, udp: %10u\n",
10357 + readl(CLASS_PHY1_ICMP_PKTS + off2),
10358 + readl(CLASS_PHY1_IGMP_PKTS + off2),
10359 + readl(CLASS_PHY1_TCP_PKTS + off2),
10360 + readl(CLASS_PHY1_UDP_PKTS + off2));
10362 + len += sprintf(buf + len, " err\n");
10363 + len += sprintf(buf + len,
10364 + " lp: %10u, intf: %10u, l3: %10u, chcksum: %10u, ttl: %10u\n",
10365 + readl(CLASS_PHY1_LP_FAIL_PKTS + off1),
10366 + readl(CLASS_PHY1_INTF_FAIL_PKTS + off1),
10367 + readl(CLASS_PHY1_L3_FAIL_PKTS + off1),
10368 + readl(CLASS_PHY1_CHKSUM_ERR_PKTS + off1),
10369 + readl(CLASS_PHY1_TTL_ERR_PKTS + off1));
10374 +/* qm_read_drop_stat
10375 + * This function is used to read the drop statistics from the TMU
10376 + * hw drop counter. Since the hw counter is always cleared afer
10377 + * reading, this function maintains the previous drop count, and
10378 + * adds the new value to it. That value can be retrieved by
10379 + * passing a pointer to it with the total_drops arg.
10381 + * @param tmu TMU number (0 - 3)
10382 + * @param queue queue number (0 - 15)
10383 + * @param total_drops pointer to location to store total drops (or NULL)
10384 + * @param do_reset if TRUE, clear total drops after updating
10386 +u32 qm_read_drop_stat(u32 tmu, u32 queue, u32 *total_drops, int do_reset)
10388 + static u32 qtotal[TMU_MAX_ID + 1][NUM_QUEUES];
10391 + writel((tmu << 8) | queue, TMU_TEQ_CTRL);
10392 + writel((tmu << 8) | queue, TMU_LLM_CTRL);
10393 + val = readl(TMU_TEQ_DROP_STAT);
10394 + qtotal[tmu][queue] += val;
10396 + *total_drops = qtotal[tmu][queue];
10398 + qtotal[tmu][queue] = 0;
10402 +static ssize_t tmu_queue_stats(char *buf, int tmu, int queue)
10407 + len += sprintf(buf + len, "%d-%02d, ", tmu, queue);
10409 + drops = qm_read_drop_stat(tmu, queue, NULL, 0);
10411 + /* Select queue */
10412 + writel((tmu << 8) | queue, TMU_TEQ_CTRL);
10413 + writel((tmu << 8) | queue, TMU_LLM_CTRL);
10415 + len += sprintf(buf + len,
10416 + "(teq) drop: %10u, tx: %10u (llm) head: %08x, tail: %08x, drop: %10u\n",
10417 + drops, readl(TMU_TEQ_TRANS_STAT),
10418 + readl(TMU_LLM_QUE_HEADPTR), readl(TMU_LLM_QUE_TAILPTR),
10419 + readl(TMU_LLM_QUE_DROPCNT));
10424 +static ssize_t tmu_queues(char *buf, int tmu)
10429 + for (queue = 0; queue < 16; queue++)
10430 + len += tmu_queue_stats(buf + len, tmu, queue);
10435 +static ssize_t block_version(char *buf, void *addr)
10440 + val = readl(addr);
10441 + len += sprintf(buf + len, "revision: %x, version: %x, id: %x\n",
10442 + (val >> 24) & 0xff, (val >> 16) & 0xff, val & 0xffff);
10447 +static ssize_t bmu(char *buf, int id, void *base)
10451 + len += sprintf(buf + len, "%s: %d\n ", __func__, id);
10453 + len += block_version(buf + len, base + BMU_VERSION);
10455 + len += sprintf(buf + len, " buf size: %x\n", (1 << readl(base +
10457 + len += sprintf(buf + len, " buf count: %x\n", readl(base +
10459 + len += sprintf(buf + len, " buf rem: %x\n", readl(base +
10460 + BMU_REM_BUF_CNT));
10461 + len += sprintf(buf + len, " buf curr: %x\n", readl(base +
10462 + BMU_CURR_BUF_CNT));
10463 + len += sprintf(buf + len, " free err: %x\n", readl(base +
10464 + BMU_FREE_ERR_ADDR));
10469 +static ssize_t gpi(char *buf, int id, void *base)
10474 + len += sprintf(buf + len, "%s%d:\n ", __func__, id);
10475 + len += block_version(buf + len, base + GPI_VERSION);
10477 + len += sprintf(buf + len, " tx under stick: %x\n", readl(base +
10478 + GPI_FIFO_STATUS));
10479 + val = readl(base + GPI_FIFO_DEBUG);
10480 + len += sprintf(buf + len, " tx pkts: %x\n", (val >> 23) &
10482 + len += sprintf(buf + len, " rx pkts: %x\n", (val >> 18) &
10484 + len += sprintf(buf + len, " tx bytes: %x\n", (val >> 9) &
10486 + len += sprintf(buf + len, " rx bytes: %x\n", (val >> 0) &
10488 + len += sprintf(buf + len, " overrun: %x\n", readl(base +
10489 + GPI_OVERRUN_DROPCNT));
10494 +static ssize_t pfe_set_class(struct device *dev, struct device_attribute *attr,
10495 + const char *buf, size_t count)
10497 + class_do_clear = kstrtoul(buf, 0, 0);
10501 +static ssize_t pfe_show_class(struct device *dev, struct device_attribute *attr,
10507 + struct pfe_cpumon *cpumon = &pfe->cpumon;
10509 + len += block_version(buf + len, CLASS_VERSION);
10511 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
10512 + len += sprintf(buf + len, "%d: ", id - CLASS0_ID);
10514 + val = readl(CLASS_PE0_DEBUG + id * 4);
10515 + len += sprintf(buf + len, "pc=1%04x ", val & 0xffff);
10517 + len += display_pe_status(buf + len, id, CLASS_DM_PESTATUS,
10520 + len += sprintf(buf + len, "aggregate load=%d%%\n\n",
10521 + cpumon->class_usage_pct);
10523 + len += sprintf(buf + len, "pe status: 0x%x\n",
10524 + readl(CLASS_PE_STATUS));
10525 + len += sprintf(buf + len, "max buf cnt: 0x%x afull thres: 0x%x\n",
10526 + readl(CLASS_MAX_BUF_CNT), readl(CLASS_AFULL_THRES));
10527 + len += sprintf(buf + len, "tsq max cnt: 0x%x tsq fifo thres: 0x%x\n",
10528 + readl(CLASS_TSQ_MAX_CNT), readl(CLASS_TSQ_FIFO_THRES));
10529 + len += sprintf(buf + len, "state: 0x%x\n", readl(CLASS_STATE));
10531 + len += class_phy_stats(buf + len, 0);
10532 + len += class_phy_stats(buf + len, 1);
10533 + len += class_phy_stats(buf + len, 2);
10534 + len += class_phy_stats(buf + len, 3);
10539 +static ssize_t pfe_set_tmu(struct device *dev, struct device_attribute *attr,
10540 + const char *buf, size_t count)
10542 + tmu_do_clear = kstrtoul(buf, 0, 0);
10546 +static ssize_t pfe_show_tmu(struct device *dev, struct device_attribute *attr,
10553 + len += block_version(buf + len, TMU_VERSION);
10555 + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
10556 + if (id == TMU2_ID)
10558 + len += sprintf(buf + len, "%d: ", id - TMU0_ID);
10560 + len += display_pe_status(buf + len, id, TMU_DM_PESTATUS,
10564 + len += sprintf(buf + len, "pe status: %x\n", readl(TMU_PE_STATUS));
10565 + len += sprintf(buf + len, "inq fifo cnt: %x\n",
10566 + readl(TMU_PHY_INQ_FIFO_CNT));
10567 + val = readl(TMU_INQ_STAT);
10568 + len += sprintf(buf + len, "inq wr ptr: %x\n", val & 0x3ff);
10569 + len += sprintf(buf + len, "inq rd ptr: %x\n", val >> 10);
10574 +static unsigned long drops_do_clear;
10575 +static u32 class_drop_counter[CLASS_NUM_DROP_COUNTERS];
10576 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10577 +static u32 util_drop_counter[UTIL_NUM_DROP_COUNTERS];
10580 +char *class_drop_description[CLASS_NUM_DROP_COUNTERS] = {
10582 + "Host Pkt Error",
10584 + "IPsec Outbound",
10586 + "EXPT IPsec Error",
10596 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10597 +char *util_drop_description[UTIL_NUM_DROP_COUNTERS] = {
10598 + "IPsec Outbound",
10600 + "IPsec Rate Limiter",
10608 +static ssize_t pfe_set_drops(struct device *dev, struct device_attribute *attr,
10609 + const char *buf, size_t count)
10611 + drops_do_clear = kstrtoul(buf, 0, 0);
10615 +static u32 tmu_drops[4][16];
10616 +static ssize_t pfe_show_drops(struct device *dev, struct device_attribute *attr,
10624 + int num_class_drops = 0, num_tmu_drops = 0, num_util_drops = 0;
10625 + struct pfe_ctrl *ctrl = &pfe->ctrl;
10627 + memset(class_drop_counter, 0, sizeof(class_drop_counter));
10628 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
10629 + if (drops_do_clear)
10630 + pe_sync_stop(ctrl, (1 << id));
10631 + for (dropnum = 0; dropnum < CLASS_NUM_DROP_COUNTERS;
10633 + dmem_addr = CLASS_DM_DROP_CNTR;
10634 + val = be32_to_cpu(pe_dmem_read(id, dmem_addr, 4));
10635 + class_drop_counter[dropnum] += val;
10636 + num_class_drops += val;
10637 + if (drops_do_clear)
10638 + pe_dmem_write(id, 0, dmem_addr, 4);
10640 + if (drops_do_clear)
10641 + pe_start(ctrl, (1 << id));
10644 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10645 + if (drops_do_clear)
10646 + pe_sync_stop(ctrl, (1 << UTIL_ID));
10647 + for (dropnum = 0; dropnum < UTIL_NUM_DROP_COUNTERS; dropnum++) {
10648 + dmem_addr = UTIL_DM_DROP_CNTR;
10649 + val = be32_to_cpu(pe_dmem_read(UTIL_ID, dmem_addr, 4));
10650 + util_drop_counter[dropnum] = val;
10651 + num_util_drops += val;
10652 + if (drops_do_clear)
10653 + pe_dmem_write(UTIL_ID, 0, dmem_addr, 4);
10655 + if (drops_do_clear)
10656 + pe_start(ctrl, (1 << UTIL_ID));
10658 + for (tmu = 0; tmu < 4; tmu++) {
10659 + for (queue = 0; queue < 16; queue++) {
10660 + qm_read_drop_stat(tmu, queue, &tmu_drops[tmu][queue],
10662 + num_tmu_drops += tmu_drops[tmu][queue];
10666 + if (num_class_drops == 0 && num_util_drops == 0 && num_tmu_drops == 0)
10667 + len += sprintf(buf + len, "No PE drops\n\n");
10669 + if (num_class_drops > 0) {
10670 + len += sprintf(buf + len, "Class PE drops --\n");
10671 + for (dropnum = 0; dropnum < CLASS_NUM_DROP_COUNTERS;
10673 + if (class_drop_counter[dropnum] > 0)
10674 + len += sprintf(buf + len, " %s: %d\n",
10675 + class_drop_description[dropnum],
10676 + class_drop_counter[dropnum]);
10678 + len += sprintf(buf + len, "\n");
10681 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10682 + if (num_util_drops > 0) {
10683 + len += sprintf(buf + len, "Util PE drops --\n");
10684 + for (dropnum = 0; dropnum < UTIL_NUM_DROP_COUNTERS; dropnum++) {
10685 + if (util_drop_counter[dropnum] > 0)
10686 + len += sprintf(buf + len, " %s: %d\n",
10687 + util_drop_description[dropnum],
10688 + util_drop_counter[dropnum]);
10690 + len += sprintf(buf + len, "\n");
10693 + if (num_tmu_drops > 0) {
10694 + len += sprintf(buf + len, "TMU drops --\n");
10695 + for (tmu = 0; tmu < 4; tmu++) {
10696 + for (queue = 0; queue < 16; queue++) {
10697 + if (tmu_drops[tmu][queue] > 0)
10698 + len += sprintf(buf + len,
10699 + " TMU%d-Q%d: %d\n"
10700 + , tmu, queue, tmu_drops[tmu][queue]);
10703 + len += sprintf(buf + len, "\n");
10709 +static ssize_t pfe_show_tmu0_queues(struct device *dev, struct device_attribute
10710 + *attr, char *buf)
10712 + return tmu_queues(buf, 0);
10715 +static ssize_t pfe_show_tmu1_queues(struct device *dev, struct device_attribute
10716 + *attr, char *buf)
10718 + return tmu_queues(buf, 1);
10721 +static ssize_t pfe_show_tmu2_queues(struct device *dev, struct device_attribute
10722 + *attr, char *buf)
10724 + return tmu_queues(buf, 2);
10727 +static ssize_t pfe_show_tmu3_queues(struct device *dev, struct device_attribute
10728 + *attr, char *buf)
10730 + return tmu_queues(buf, 3);
10733 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10734 +static ssize_t pfe_set_util(struct device *dev, struct device_attribute *attr,
10735 + const char *buf, size_t count)
10737 + util_do_clear = kstrtoul(buf, NULL, 0);
10741 +static ssize_t pfe_show_util(struct device *dev, struct device_attribute *attr,
10745 + struct pfe_ctrl *ctrl = &pfe->ctrl;
10747 + len += block_version(buf + len, UTIL_VERSION);
10749 + pe_sync_stop(ctrl, (1 << UTIL_ID));
10750 + len += display_pe_status(buf + len, UTIL_ID, UTIL_DM_PESTATUS,
10752 + pe_start(ctrl, (1 << UTIL_ID));
10754 + len += sprintf(buf + len, "pe status: %x\n", readl(UTIL_PE_STATUS));
10755 + len += sprintf(buf + len, "max buf cnt: %x\n",
10756 + readl(UTIL_MAX_BUF_CNT));
10757 + len += sprintf(buf + len, "tsq max cnt: %x\n",
10758 + readl(UTIL_TSQ_MAX_CNT));
10764 +static ssize_t pfe_show_bmu(struct device *dev, struct device_attribute *attr,
10769 + len += bmu(buf + len, 1, BMU1_BASE_ADDR);
10770 + len += bmu(buf + len, 2, BMU2_BASE_ADDR);
10775 +static ssize_t pfe_show_hif(struct device *dev, struct device_attribute *attr,
10780 + len += sprintf(buf + len, "hif:\n ");
10781 + len += block_version(buf + len, HIF_VERSION);
10783 + len += sprintf(buf + len, " tx curr bd: %x\n",
10784 + readl(HIF_TX_CURR_BD_ADDR));
10785 + len += sprintf(buf + len, " tx status: %x\n",
10786 + readl(HIF_TX_STATUS));
10787 + len += sprintf(buf + len, " tx dma status: %x\n",
10788 + readl(HIF_TX_DMA_STATUS));
10790 + len += sprintf(buf + len, " rx curr bd: %x\n",
10791 + readl(HIF_RX_CURR_BD_ADDR));
10792 + len += sprintf(buf + len, " rx status: %x\n",
10793 + readl(HIF_RX_STATUS));
10794 + len += sprintf(buf + len, " rx dma status: %x\n",
10795 + readl(HIF_RX_DMA_STATUS));
10797 + len += sprintf(buf + len, "hif nocopy:\n ");
10798 + len += block_version(buf + len, HIF_NOCPY_VERSION);
10800 + len += sprintf(buf + len, " tx curr bd: %x\n",
10801 + readl(HIF_NOCPY_TX_CURR_BD_ADDR));
10802 + len += sprintf(buf + len, " tx status: %x\n",
10803 + readl(HIF_NOCPY_TX_STATUS));
10804 + len += sprintf(buf + len, " tx dma status: %x\n",
10805 + readl(HIF_NOCPY_TX_DMA_STATUS));
10807 + len += sprintf(buf + len, " rx curr bd: %x\n",
10808 + readl(HIF_NOCPY_RX_CURR_BD_ADDR));
10809 + len += sprintf(buf + len, " rx status: %x\n",
10810 + readl(HIF_NOCPY_RX_STATUS));
10811 + len += sprintf(buf + len, " rx dma status: %x\n",
10812 + readl(HIF_NOCPY_RX_DMA_STATUS));
10817 +static ssize_t pfe_show_gpi(struct device *dev, struct device_attribute *attr,
10822 + len += gpi(buf + len, 0, EGPI1_BASE_ADDR);
10823 + len += gpi(buf + len, 1, EGPI2_BASE_ADDR);
10824 + len += gpi(buf + len, 3, HGPI_BASE_ADDR);
10829 +static ssize_t pfe_show_pfemem(struct device *dev, struct device_attribute
10830 + *attr, char *buf)
10833 + struct pfe_memmon *memmon = &pfe->memmon;
10835 + len += sprintf(buf + len, "Kernel Memory: %d Bytes (%d KB)\n",
10836 + memmon->kernel_memory_allocated,
10837 + (memmon->kernel_memory_allocated + 1023) / 1024);
10842 +#ifdef HIF_NAPI_STATS
10843 +static ssize_t pfe_show_hif_napi_stats(struct device *dev,
10844 + struct device_attribute *attr,
10847 + struct platform_device *pdev = to_platform_device(dev);
10848 + struct pfe *pfe = platform_get_drvdata(pdev);
10851 + len += sprintf(buf + len, "sched: %u\n",
10852 + pfe->hif.napi_counters[NAPI_SCHED_COUNT]);
10853 + len += sprintf(buf + len, "poll: %u\n",
10854 + pfe->hif.napi_counters[NAPI_POLL_COUNT]);
10855 + len += sprintf(buf + len, "packet: %u\n",
10856 + pfe->hif.napi_counters[NAPI_PACKET_COUNT]);
10857 + len += sprintf(buf + len, "budget: %u\n",
10858 + pfe->hif.napi_counters[NAPI_FULL_BUDGET_COUNT]);
10859 + len += sprintf(buf + len, "desc: %u\n",
10860 + pfe->hif.napi_counters[NAPI_DESC_COUNT]);
10861 + len += sprintf(buf + len, "full: %u\n",
10862 + pfe->hif.napi_counters[NAPI_CLIENT_FULL_COUNT]);
10867 +static ssize_t pfe_set_hif_napi_stats(struct device *dev,
10868 + struct device_attribute *attr,
10869 + const char *buf, size_t count)
10871 + struct platform_device *pdev = to_platform_device(dev);
10872 + struct pfe *pfe = platform_get_drvdata(pdev);
10874 + memset(pfe->hif.napi_counters, 0, sizeof(pfe->hif.napi_counters));
10879 +static DEVICE_ATTR(hif_napi_stats, 0644, pfe_show_hif_napi_stats,
10880 + pfe_set_hif_napi_stats);
10883 +static DEVICE_ATTR(class, 0644, pfe_show_class, pfe_set_class);
10884 +static DEVICE_ATTR(tmu, 0644, pfe_show_tmu, pfe_set_tmu);
10885 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10886 +static DEVICE_ATTR(util, 0644, pfe_show_util, pfe_set_util);
10888 +static DEVICE_ATTR(bmu, 0444, pfe_show_bmu, NULL);
10889 +static DEVICE_ATTR(hif, 0444, pfe_show_hif, NULL);
10890 +static DEVICE_ATTR(gpi, 0444, pfe_show_gpi, NULL);
10891 +static DEVICE_ATTR(drops, 0644, pfe_show_drops, pfe_set_drops);
10892 +static DEVICE_ATTR(tmu0_queues, 0444, pfe_show_tmu0_queues, NULL);
10893 +static DEVICE_ATTR(tmu1_queues, 0444, pfe_show_tmu1_queues, NULL);
10894 +static DEVICE_ATTR(tmu2_queues, 0444, pfe_show_tmu2_queues, NULL);
10895 +static DEVICE_ATTR(tmu3_queues, 0444, pfe_show_tmu3_queues, NULL);
10896 +static DEVICE_ATTR(pfemem, 0444, pfe_show_pfemem, NULL);
10898 +int pfe_sysfs_init(struct pfe *pfe)
10900 + if (device_create_file(pfe->dev, &dev_attr_class))
10903 + if (device_create_file(pfe->dev, &dev_attr_tmu))
10906 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10907 + if (device_create_file(pfe->dev, &dev_attr_util))
10911 + if (device_create_file(pfe->dev, &dev_attr_bmu))
10914 + if (device_create_file(pfe->dev, &dev_attr_hif))
10917 + if (device_create_file(pfe->dev, &dev_attr_gpi))
10920 + if (device_create_file(pfe->dev, &dev_attr_drops))
10923 + if (device_create_file(pfe->dev, &dev_attr_tmu0_queues))
10924 + goto err_tmu0_queues;
10926 + if (device_create_file(pfe->dev, &dev_attr_tmu1_queues))
10927 + goto err_tmu1_queues;
10929 + if (device_create_file(pfe->dev, &dev_attr_tmu2_queues))
10930 + goto err_tmu2_queues;
10932 + if (device_create_file(pfe->dev, &dev_attr_tmu3_queues))
10933 + goto err_tmu3_queues;
10935 + if (device_create_file(pfe->dev, &dev_attr_pfemem))
10938 +#ifdef HIF_NAPI_STATS
10939 + if (device_create_file(pfe->dev, &dev_attr_hif_napi_stats))
10940 + goto err_hif_napi_stats;
10945 +#ifdef HIF_NAPI_STATS
10946 +err_hif_napi_stats:
10947 + device_remove_file(pfe->dev, &dev_attr_pfemem);
10951 + device_remove_file(pfe->dev, &dev_attr_tmu3_queues);
10954 + device_remove_file(pfe->dev, &dev_attr_tmu2_queues);
10957 + device_remove_file(pfe->dev, &dev_attr_tmu1_queues);
10960 + device_remove_file(pfe->dev, &dev_attr_tmu0_queues);
10963 + device_remove_file(pfe->dev, &dev_attr_drops);
10966 + device_remove_file(pfe->dev, &dev_attr_gpi);
10969 + device_remove_file(pfe->dev, &dev_attr_hif);
10972 + device_remove_file(pfe->dev, &dev_attr_bmu);
10975 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10976 + device_remove_file(pfe->dev, &dev_attr_util);
10980 + device_remove_file(pfe->dev, &dev_attr_tmu);
10983 + device_remove_file(pfe->dev, &dev_attr_class);
10989 +void pfe_sysfs_exit(struct pfe *pfe)
10991 +#ifdef HIF_NAPI_STATS
10992 + device_remove_file(pfe->dev, &dev_attr_hif_napi_stats);
10994 + device_remove_file(pfe->dev, &dev_attr_pfemem);
10995 + device_remove_file(pfe->dev, &dev_attr_tmu3_queues);
10996 + device_remove_file(pfe->dev, &dev_attr_tmu2_queues);
10997 + device_remove_file(pfe->dev, &dev_attr_tmu1_queues);
10998 + device_remove_file(pfe->dev, &dev_attr_tmu0_queues);
10999 + device_remove_file(pfe->dev, &dev_attr_drops);
11000 + device_remove_file(pfe->dev, &dev_attr_gpi);
11001 + device_remove_file(pfe->dev, &dev_attr_hif);
11002 + device_remove_file(pfe->dev, &dev_attr_bmu);
11003 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11004 + device_remove_file(pfe->dev, &dev_attr_util);
11006 + device_remove_file(pfe->dev, &dev_attr_tmu);
11007 + device_remove_file(pfe->dev, &dev_attr_class);
11010 +++ b/drivers/staging/fsl_ppfe/pfe_sysfs.h
11012 +/* SPDX-License-Identifier: GPL-2.0+ */
11014 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
11015 + * Copyright 2017 NXP
11018 +#ifndef _PFE_SYSFS_H_
11019 +#define _PFE_SYSFS_H_
11021 +#include <linux/proc_fs.h>
11023 +u32 qm_read_drop_stat(u32 tmu, u32 queue, u32 *total_drops, int do_reset);
11025 +int pfe_sysfs_init(struct pfe *pfe);
11026 +void pfe_sysfs_exit(struct pfe *pfe);
11028 +#endif /* _PFE_SYSFS_H_ */