1 From 4bb50554937246443767e89d32e54df7a12396ca Mon Sep 17 00:00:00 2001
2 From: Calvin Johnson <calvin.johnson@nxp.com>
3 Date: Sat, 16 Sep 2017 07:05:49 +0530
4 Subject: [PATCH] staging: add fsl_ppfe driver
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This is squash of all commits with ppfe driver taken from NXP 6.1 tree:
10 https://github.com/nxp-qoriq/linux/tree/lf-6.1.y
12 List of original commits:
14 net: fsl_ppfe: dts binding for ppfe
16 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
17 Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
19 staging: fsl_ppfe/eth: header files for pfe driver
21 This patch has all pfe header files.
23 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
24 Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
26 staging: fsl_ppfe/eth: introduce pfe driver
28 This patch introduces Linux support for NXP's LS1012A Packet
29 Forwarding Engine (pfe_eth). LS1012A uses hardware packet forwarding
30 engine to provide high performance Ethernet interfaces. The device
31 includes two Ethernet ports.
33 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
34 Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
36 staging: fsl_ppfe/eth: fix RGMII tx delay issue
38 Recently logic to enable RGMII tx delay was changed by
41 https://patchwork.kernel.org/patch/9447581/
43 Based on the patch, appropriate change is made in PFE driver.
45 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
46 Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
48 staging: fsl_ppfe/eth: remove unused functions
50 Remove unused functions hif_xmit_pkt & hif_lib_xmit_pkt.
52 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
54 staging: fsl_ppfe/eth: fix read/write/ack idx issue
56 While fixing checkpatch errors some of the index increments
57 were commented out. They are enabled.
59 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
61 staging: fsl_ppfe/eth: Make phy_ethtool_ksettings_get return void
63 Make return value void since function never return meaningful value
65 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
67 staging: fsl_ppfe/eth: add function to update tmu credits
69 __hif_lib_update_credit function is used to update the tmu credits.
70 If tx_qos is set, tmu credit is updated based on the number of packets
73 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
74 Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
76 staging: fsl_ppfe/eth: Avoid packet drop at TMU queues
78 Added flow control between TMU queues and PFE Linux driver,
79 based on TMU credits availability.
80 Added tx_qos module parameter to control this behavior.
81 Use queue-0 as default queue to transmit packets.
83 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
84 Signed-off-by: Akhila Kavi <akhila.kavi@nxp.com>
85 Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
87 staging: fsl_ppfe/eth: Enable PFE in clause 45 mode
89 when we opearate in clause 45 mode, we need to call
90 the function get_phy_device() with its 3rd argument as
91 "true" and then the resultant phy device needs to be
92 register with phy layer via phy_device_register()
94 Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya@nxp.com>
96 staging: fsl_ppfe/eth: Disable autonegotiation for 2.5G SGMII
98 PCS initialization sequence for 2.5G SGMII interface governs
99 auto negotiation to be in disabled mode
101 Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya@nxp.com>
103 staging: fsl_ppfe/eth: calculate PFE_PKT_SIZE with SKB_DATA_ALIGN
105 pfe packet size was calculated without considering skb data alignment
106 and this resulted in jumbo frames crashing kernel when the
107 cacheline size increased from 64 to 128 bytes with
108 commit 97303480753e ("arm64: Increase the max granular size").
110 Modify pfe packet size caclulation to include skb data alignment of
111 sizeof(struct skb_shared_info).
113 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
115 staging: fsl_ppfe/eth: support for userspace networking
117 This patch adds the userspace mode support to fsl_ppfe network driver.
118 In the new mode, basic hardware initialization is performed in kernel, while
119 the datapath and HIF handling is the responsibility of the userspace.
121 The new command line parameter is added to initialize the ppfe module
122 in userspace mode. By default the module remains in kernelspace networking
124 To enable userspace mode, use "insmod pfe.ko us=1"
126 Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
127 Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
129 staging: fsl_ppfe/eth: unregister netdev after pfe_phy_exit
131 rmmod pfe.ko throws below warning:
133 kernfs: can not remove 'phydev', no directory
134 ------------[ cut here ]------------
135 WARNING: CPU: 0 PID: 2230 at fs/kernfs/dir.c:1481
136 kernfs_remove_by_name_ns+0x90/0xa0
138 This is caused when the unregistered netdev structure is accessed to
141 Resolve the issue by unregistering netdev after disconnecting phy.
143 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
145 staging: fsl_ppfe/eth: HW parse results for DPDK
147 HW Parse results are included in the packet headroom.
148 Length and Offset calculation now accommodates parse info size.
150 Signed-off-by: Archana Madhavan <archana.madhavan@nxp.com>
152 staging: fsl_ppfe/eth: reorganize pfe_netdev_ops
154 Reorganize members of struct pfe_netdev_ops to match with the order
155 of members in struct net_device_ops defined in include/linux/netdevice.h
157 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
159 staging: fsl_ppfe/eth: use mask for rx max frame len
161 Define and use PFE_RCR_MAX_FL_MASK to properly set Rx max frame
162 length of MAC Receive Control Register.
164 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
166 staging: fsl_ppfe/eth: define pfe ndo_change_mtu function
168 Define ndo_change_mtu function for pfe. This sets the max Rx frame
169 length to the new mtu.
171 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
173 staging: fsl_ppfe/eth: remove jumbo frame enable from gemac init
175 MAC Receive Control Register was configured to allow jumbo frames.
176 This is removed as jumbo frames can be supported anytime by changing
177 mtu which will in turn modify MAX_FL field of MAC RCR.
178 Jumbo frames caused pfe to hang on LS1012A rev 1.0 Silicon due to
181 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
183 staging: fsl_ppfe/eth: disable CRC removal
185 Disable CRC removal from the packet, so that packets are forwarded
187 CRC configuration in MAC will be reflected in the packet received
190 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
192 staging: fsl_ppfe/eth: handle ls1012a errata_a010897
194 On LS1012A rev 1.0, Jumbo frames are not supported as it causes
195 the PFE controller to hang. A reset of the entire chip is required
196 to resume normal operation.
198 To handle this errata, frames with length > 1900 are truncated for
201 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
203 staging: fsl_ppfe/eth: replace magic numbers
205 Replace magic numbers and some cosmetic changes.
207 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
209 staging: fsl_ppfe/eth: resolve indentation warning
211 Resolve the following indentation warning:
213 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c:
214 In function ‘pfe_get_gemac_if_proprties’:
215 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c:96:2:
216 warning: this ‘else’ clause does not guard...
217 [-Wmisleading-indentation]
220 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c:98:3:
221 note: ...this statement, but the latter is misleadingly indented as
222 if it were guarded by the ‘else’
223 pdata->ls1012a_eth_pdata[port].mdio_muxval = phy_id;
226 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
228 staging: fsl_ppfe/eth: add fixed-link support
230 In cases where MAC is not connected to a normal MDIO-managed PHY
231 device, and instead to a switch, it is configured as a "fixed-link".
232 Code to handle this scenario is added here.
234 phy_node in the dtb is checked to identify a fixed-link.
235 On identification of a fixed-link, it is registered and connected.
237 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
239 staging: fsl_ppfe: add support for a char dev for link status
241 Read and IOCTL support is added. Application would need to open,
242 read/ioctl the /dev/pfe_us_cdev device.
243 select is pending as it requires a wait_queue.
245 Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
246 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
248 staging: fsl_ppfe: enable hif event from userspace
250 HIF interrupts are enabled using ioctl from user space,
251 and epoll wait from user space wakes up when there is an HIF
254 Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
256 staging: fsl_ppfe: performance tuning for user space
258 interrupt coalescing of 100 usec is added.
260 Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
261 Signed-off-by: Sachin Saxena <sachin.saxena@nxp.com>
263 staging: fsl_ppfe/eth: Update to use SPDX identifiers
265 Replace license text with corresponding SPDX identifiers and update the
266 format of existing SPDX identifiers to follow the new guideline
267 Documentation/process/license-rules.rst.
269 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
271 staging: fsl_ppfe/eth: misc clean up
273 - remove redundant hwfeature init
274 - remove unused vars from ls1012a_eth_platform_data
275 - To handle ls1012a errata_a010897, PPFE driver requires GUTS driver
276 to be compiled in. Select FSL_GUTS when PPFE driver is compiled.
278 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
280 staging: fsl_ppfe/eth: reorganize platform phy parameters
282 - Use "phy-handle" and of_* functions to get phy node and fixed-link
285 - Reorganize phy parameters and initialize them only if phy-handle
286 or fixed-link is defined in the dtb.
288 - correct typo pfe_get_gemac_if_proprties to pfe_get_gemac_if_properties
290 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
292 staging: fsl_ppfe/eth: support single interface initialization
294 - arrange members of struct mii_bus in sequence matching phy.h
295 - if mdio node is defined, use of_mdiobus_register to register
296 child nodes (phy devices) available on the mdio bus.
297 - remove of_phy_register_fixed_link from pfe_phy_init as it is being
298 handled in pfe_get_gemac_if_properties
299 - remove mdio enabled check
300 - skip phy init, if no PHY or fixed-link
302 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
304 net: fsl_ppfe: update dts properties for phy
306 Use commonly used phy-handle property and mdio subnode to handle
309 Deprecate bindings fsl,gemac-phy-id & fsl,pfe-phy-if-flags.
311 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
313 staging: fsl_ppfe/eth: remove unused code
315 - remove gemac-bus-id related code that is unused.
316 - remove unused prototype gemac_set_mdc_div.
318 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
320 staging: fsl_ppfe/eth: separate mdio init from mac init
322 - separate mdio initialization from mac initialization
323 - Define pfe_mdio_priv_s structure to hold mii_bus structure and other
325 - Modify functions to work with the separted mdio init model.
327 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
329 staging: fsl_ppfe/eth: adapt to link mode based phydev changes
331 Setting link mode bits have changed with the integration of
332 commit (3c1bcc8 net: ethernet: Convert phydev advertize and
333 supported from u32 to link mode). Adapt to the new method of
334 setting and clearing the link mode bits.
336 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
338 staging: fsl_ppfe/eth: use generic soc_device infra instead of fsl_guts_get_svr()
340 Commit ("soc: fsl: guts: make fsl_guts_get_svr() static") has
341 made fsl_guts_get_svr() static and hence use generic soc_device
342 infrastructure to check SoC revision.
344 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
346 staging: fsl_ppfe/eth: use memremap() to map RAM area used by PFE
348 RAM area used by PFE should be mapped using memremap() instead of
349 directly traslating physical addr to virtual. This will ensure proper
350 checks are done before the area is used.
352 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
354 staging: fsl_ppfe/eth: remove 'fallback' argument from dev->ndo_select_queue()
356 To be consistent with upstream API change.
358 Signed-off-by: Li Yang <leoyang.li@nxp.com>
360 staging: fsl_ppfe/eth: prefix header search paths with $(srctree)/
362 Currently, the rules for configuring search paths in Kbuild have
363 changed: https://lkml.org/lkml/2019/5/13/37
365 This will lead the below error:
367 fatal error: pfe/pfe.h: No such file or directory
369 Fix it by adding $(srctree)/ prefix to the search paths.
371 Signed-off-by: Ting Liu <ting.liu@nxp.com>
373 staging: fsl_ppfe/eth: add pfe support to Kconfig and Makefile
375 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
376 [ Aisheng: fix minor conflict due to removed VBOXSF_FS ]
377 Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
379 staging: fsl_ppfe/eth: Disable termination of CRC fwd.
381 LS1012A MAC PCS block has an erratum that is seen with specific PHY AR803x.
382 The issue is triggered by the (spec-compliant) operation of the AR803x PHY
383 on the LS1012A-FRWY board.Due to this, good FCS packet is reported as error
384 packet by MAC, so for these error packets FCS should be validated and
385 discard only real error packets in PFE Rx packet path.
387 Signed-off-by: Nagesh Koneti <koneti.nagesh@nxp.com>
388 Signed-off-by: Nagesh Koneti <“koneti.nagesh@nxp.com”>
390 net: ppfe: Cope with of_get_phy_mode() API change
392 Signed-off-by: Li Yang <leoyang.li@nxp.com>
394 staging: fsl_ppfe/eth: Enhance error checking in platform probe
396 Fix the kernel crash when MAC addr is not passed in dtb.
398 Signed-off-by: Anji Jagarlmudi <anji.jagarlmudi@nxp.com>
400 staging: fsl_ppfe/eth: reject unsupported coalescing params
402 Set ethtool_ops->supported_coalesce_params to let
403 the core reject unsupported coalescing parameters.
405 Signed-off-by: Anji Jagarlmudi <anji.jagarlmudi@nxp.com>
407 staging: fsl_ppfe/eth:check "reg" property before pfe_get_gemac_if_properties()
409 It has been observed that the function pfe_get_gemac_if_properties() is
410 been called blindly for the next two child nodes. There might be some
411 cases where it may go wrong and that lead to missing interfaces.
412 with these changes it is ensured thats not the case.
414 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
415 Signed-off-by: Anji J <anji.jagarlmudi@nxp.com>
417 staging: fsl_ppfe/eth: "struct firmware" dereference is reduced in many functions
419 firmware structure's data variable is the actual elf data. It has been
420 dereferenced in multiple functions and this has been reduced.
422 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
423 Signed-off-by: Anji J <anji.jagarlmudi@nxp.com>
425 staging: fsl_ppfe/eth: LF-27 load pfe binaries from FDT
427 FDT prepared in uboot now has pfe firmware part of it.
428 These changes will read the firmware by default from it and tries to load
429 the elf into the PFE PEs. This help build the pfe driver pasrt of kernel.
431 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
432 Signed-off-by: Anji J <anji.jagarlmudi@nxp.com>
434 staging: fsl_ppfe/eth: proper handling for RGMII delay mode
436 The correct setting for the RGMII ports on LS1012ARDB is to
437 enable delay on both Tx and Rx. So the phy mode to be matched
438 is PHY_INTERFACE_MODE_RGMII_ID.
440 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
441 Signed-off-by: Anji Jagarlmudi <anji.jagarlmudi@nxp.com>
443 LF-1762-2 staging: fsl_ppfe: replace '---help---' in Kconfig files with 'help'
445 Update Kconfig to cope with upstream change
446 commit 84af7a6194e4 ("checkpatch: kconfig: prefer 'help' over
449 Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
451 staging: fsl_ppfe/eth: Nesting level does not match indentation
453 corrected nesting level
454 LF-1661 and Coverity CID: 8879316
456 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
458 staging: fsl_ppfe/eth: Initialized scalar variable
460 Proper initialization of scalar variable
461 LF-1657 and Coverity CID: 3335133
463 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
465 staging: fsl_ppfe/eth: misspelt variable name
467 variable name corrected
468 LF-1656 and Coverity CID: 3335119
470 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
472 staging: fsl_ppfe/eth: Avoiding out-of-bound writes
474 avoid out-of-bound writes with proper error handling
475 LF-1654, LF-1652 and Coverity CID: 3335106, 3335090
477 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
479 staging: fsl_ppfe/eth: Initializing scalar variable
481 proper initialization of scalar variable.
482 LF-1653 and Coverity CID: 3335101
484 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
486 staging: fsl_ppfe/eth: checking return value
488 proper checks added and handled for return value.
489 LF-1644 and Coverity CID: 241888
491 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
493 staging: fsl_ppfe/eth: Avoid out-of-bound access
495 proper handling to avoid out-of-bound access
496 LF-1642, LF-1641 and Coverity CID: 240910, 240891
498 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
500 staging: fsl_ppfe/eth: Avoiding out-of-bound writes
502 avoid out-of-bound writes with proper error handling
503 LF-1654, LF-1652 and Coverity CID: 3335106, 3335090
505 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
507 staging: fsl_ppfe/eth: return value init in error case
509 proper err return in error case.
510 LF-1806 and Coverity CID: 10468592
512 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
514 staging: fsl_ppfe/eth: Avoid recursion in header inclusion
516 Avoiding header inclusions that are not necessary and also that are
517 causing header inclusion recursion.
519 LF-2102 and Coverity CID: 240838
521 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
523 staging: fsl_ppfe/eth: Avoiding return value overwrite
525 avoid return value overwrite at the end of function.
526 LF-2136, LF-2137 and Coverity CID: 8879341, 8879364
528 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
530 staging: fsl_ppfe/eth: LF-27 enabling PFE firmware load from FDT
532 The macro, "LOAD_PFEFIRMWARE_FROM_FILESYSTEM" is been disabled to load
533 the firmware from FDT by default. Enabling the macro will load the
534 firmware from filesystem.
536 Also, the Makefile is now tuned to build pfe as per the config option
538 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
540 staging: fsl_ppfe/eth: Ethtool stats correction for IEEE_rx_drop counter
542 Due to carrier extended bug the phy counter IEEE_rx_drop counter is
543 incremented some times and phy reports the packet has crc error.
544 Because of this PFE revalidates all the packets that are marked crc
545 error by phy. Now, the counter phy reports is till bogus and this
546 patch decrements the counter by pfe revalidated (and are crc ok)
549 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
551 staging: fsl_ppfe/eth: PFE firmware load enhancements
553 PFE driver enhancements to load the PE firmware from filesystem
554 when the firmware is not found in FDT.
556 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
558 staging: fsl_ppfe: deal with upstream API change of of_get_mac_address()
560 Uptream commit 83216e398 changed the of_get_mac_address() API, update
561 the user accordingly.
563 Signed-off-by: Li Yang <leoyang.li@nxp.com>
565 staging: fsl_ppfe: update coalesce setting uAPI usage
568 f3ccfda19319 ("ethtool: extend coalesce setting uAPI with CQE mode")
570 Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
572 staging: fsl_ppfe: Addressed build warnings
574 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
576 staging: fsl_ppfe: Addressed build warnings
578 Signed-off-by: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
580 Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
582 .../devicetree/bindings/net/fsl_ppfe/pfe.txt | 199 ++
584 drivers/staging/Kconfig | 2 +
585 drivers/staging/Makefile | 1 +
586 drivers/staging/fsl_ppfe/Kconfig | 21 +
587 drivers/staging/fsl_ppfe/Makefile | 20 +
588 drivers/staging/fsl_ppfe/TODO | 2 +
589 drivers/staging/fsl_ppfe/include/pfe/cbus.h | 78 +
590 .../staging/fsl_ppfe/include/pfe/cbus/bmu.h | 55 +
591 .../fsl_ppfe/include/pfe/cbus/class_csr.h | 289 ++
592 .../fsl_ppfe/include/pfe/cbus/emac_mtip.h | 242 ++
593 .../staging/fsl_ppfe/include/pfe/cbus/gpi.h | 86 +
594 .../staging/fsl_ppfe/include/pfe/cbus/hif.h | 100 +
595 .../fsl_ppfe/include/pfe/cbus/hif_nocpy.h | 50 +
596 .../fsl_ppfe/include/pfe/cbus/tmu_csr.h | 168 ++
597 .../fsl_ppfe/include/pfe/cbus/util_csr.h | 61 +
598 drivers/staging/fsl_ppfe/include/pfe/pfe.h | 372 +++
599 drivers/staging/fsl_ppfe/pfe_cdev.c | 258 ++
600 drivers/staging/fsl_ppfe/pfe_cdev.h | 41 +
601 drivers/staging/fsl_ppfe/pfe_ctrl.c | 226 ++
602 drivers/staging/fsl_ppfe/pfe_ctrl.h | 100 +
603 drivers/staging/fsl_ppfe/pfe_debugfs.c | 99 +
604 drivers/staging/fsl_ppfe/pfe_debugfs.h | 13 +
605 drivers/staging/fsl_ppfe/pfe_eth.c | 2588 +++++++++++++++++
606 drivers/staging/fsl_ppfe/pfe_eth.h | 175 ++
607 drivers/staging/fsl_ppfe/pfe_firmware.c | 398 +++
608 drivers/staging/fsl_ppfe/pfe_firmware.h | 21 +
609 drivers/staging/fsl_ppfe/pfe_hal.c | 1517 ++++++++++
610 drivers/staging/fsl_ppfe/pfe_hif.c | 1063 +++++++
611 drivers/staging/fsl_ppfe/pfe_hif.h | 199 ++
612 drivers/staging/fsl_ppfe/pfe_hif_lib.c | 628 ++++
613 drivers/staging/fsl_ppfe/pfe_hif_lib.h | 229 ++
614 drivers/staging/fsl_ppfe/pfe_hw.c | 164 ++
615 drivers/staging/fsl_ppfe/pfe_hw.h | 15 +
616 .../staging/fsl_ppfe/pfe_ls1012a_platform.c | 383 +++
617 drivers/staging/fsl_ppfe/pfe_mod.c | 158 +
618 drivers/staging/fsl_ppfe/pfe_mod.h | 103 +
619 drivers/staging/fsl_ppfe/pfe_perfmon.h | 26 +
620 drivers/staging/fsl_ppfe/pfe_sysfs.c | 840 ++++++
621 drivers/staging/fsl_ppfe/pfe_sysfs.h | 17 +
622 40 files changed, 11015 insertions(+)
623 create mode 100644 Documentation/devicetree/bindings/net/fsl_ppfe/pfe.txt
624 create mode 100644 drivers/staging/fsl_ppfe/Kconfig
625 create mode 100644 drivers/staging/fsl_ppfe/Makefile
626 create mode 100644 drivers/staging/fsl_ppfe/TODO
627 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus.h
628 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h
629 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h
630 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h
631 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h
632 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h
633 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h
634 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h
635 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h
636 create mode 100644 drivers/staging/fsl_ppfe/include/pfe/pfe.h
637 create mode 100644 drivers/staging/fsl_ppfe/pfe_cdev.c
638 create mode 100644 drivers/staging/fsl_ppfe/pfe_cdev.h
639 create mode 100644 drivers/staging/fsl_ppfe/pfe_ctrl.c
640 create mode 100644 drivers/staging/fsl_ppfe/pfe_ctrl.h
641 create mode 100644 drivers/staging/fsl_ppfe/pfe_debugfs.c
642 create mode 100644 drivers/staging/fsl_ppfe/pfe_debugfs.h
643 create mode 100644 drivers/staging/fsl_ppfe/pfe_eth.c
644 create mode 100644 drivers/staging/fsl_ppfe/pfe_eth.h
645 create mode 100644 drivers/staging/fsl_ppfe/pfe_firmware.c
646 create mode 100644 drivers/staging/fsl_ppfe/pfe_firmware.h
647 create mode 100644 drivers/staging/fsl_ppfe/pfe_hal.c
648 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif.c
649 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif.h
650 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif_lib.c
651 create mode 100644 drivers/staging/fsl_ppfe/pfe_hif_lib.h
652 create mode 100644 drivers/staging/fsl_ppfe/pfe_hw.c
653 create mode 100644 drivers/staging/fsl_ppfe/pfe_hw.h
654 create mode 100644 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
655 create mode 100644 drivers/staging/fsl_ppfe/pfe_mod.c
656 create mode 100644 drivers/staging/fsl_ppfe/pfe_mod.h
657 create mode 100644 drivers/staging/fsl_ppfe/pfe_perfmon.h
658 create mode 100644 drivers/staging/fsl_ppfe/pfe_sysfs.c
659 create mode 100644 drivers/staging/fsl_ppfe/pfe_sysfs.h
662 +++ b/Documentation/devicetree/bindings/net/fsl_ppfe/pfe.txt
664 +=============================================================================
665 +NXP Programmable Packet Forwarding Engine Device Bindings
671 +=============================================================================
676 +PFE Node has all the properties associated with Packet Forwarding Engine block.
682 + Value type: <stringlist>
683 + Definition: Must include "fsl,pfe"
687 + Value type: <prop-encoded-array>
688 + Definition: A standard property.
689 + Specifies the offset of the following registers:
690 + - PFE configuration registers
691 + - DDR memory used by PFE
693 +- fsl,pfe-num-interfaces
696 + Definition: Must be present. Value can be either one or two.
700 + Value type: <prop-encoded-array>
701 + Definition: Three interrupts are specified in this property.
703 + - HIF NO COPY interrupt
704 + - Wake On LAN interrupt
708 + Value type: <stringlist>
709 + Definition: Following strings are defined for the 3 interrupts.
710 + "pfe_hif" - HIF interrupt
711 + "pfe_hif_nocpy" - HIF NO COPY interrupt
712 + "pfe_wol" - Wake On LAN interrupt
716 + Value type: <phandle>
717 + Definition: phandle to a node describing reserved memory used by pfe.
718 + Refer:- Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
722 + Value type: <phandle>
723 + Definition: phandle for scfg.
727 + Value type: <phandle>
728 + Definition: phandle for rcpm.
732 + Value type: <phandle>
733 + Definition: phandle for clockgen.
737 + Value type: <string>
738 + Definition: phandle for clock name.
743 + compatible = "fsl,pfe";
744 + reg = <0x0 0x04000000 0x0 0xc00000>, /* AXI 16M */
745 + <0x0 0x83400000 0x0 0xc00000>; /* PFE DDR 12M */
746 + reg-names = "pfe", "pfe-ddr";
747 + fsl,pfe-num-interfaces = <0x2>;
748 + interrupts = <0 172 0x4>, /* HIF interrupt */
749 + <0 173 0x4>, /*HIF_NOCPY interrupt */
750 + <0 174 0x4>; /* WoL interrupt */
751 + interrupt-names = "pfe_hif", "pfe_hif_nocpy", "pfe_wol";
752 + memory-region = <&pfe_reserved>;
753 + fsl,pfe-scfg = <&scfg 0>;
754 + fsl,rcpm-wakeup = <&rcpm 0xf0000020>;
755 + clocks = <&clockgen 4 0>;
756 + clock-names = "pfe";
759 + pfe_mac0: ethernet@0 {
762 + pfe_mac1: ethernet@1 {
766 +=============================================================================
771 +Ethernet Node has all the properties associated with PFE used by platforms to
778 + Value type: <stringlist>
779 + Definition: Must include "fsl,pfe-gemac-port"
783 + Value type: <prop-encoded-array>
784 + Definition: A standard property.
785 + Specifies the gemacid of the interface.
790 + Definition: Must be present. Value should be the id of the bus
791 + connected to gemac.
793 +- fsl,gemac-phy-id (deprecated binding)
796 + Definition: This binding shouldn't be used with new platforms.
797 + Must be present. Value should be the id of the phy
798 + connected to gemac.
803 + Definition: Must be present. Value can be either 0 or 2 or 3.
804 + This value is used to configure the mux to enable mdio.
808 + Value type: <string>
809 + Definition: Must include "sgmii"
811 +- fsl,pfe-phy-if-flags (deprecated binding)
814 + Definition: This binding shouldn't be used with new platforms.
815 + Must be present. Value should be 0 by default.
816 + If there is not phy connected, this need to be 1.
820 + Value type: <phandle>
821 + Definition: phandle to the PHY device connected to this device.
823 +- mdio : A required subnode which specifies the mdio bus in the PFE and used as
824 +a container for phy nodes according to ../phy.txt.
829 + compatible = "fsl,pfe-gemac-port";
830 + #address-cells = <1>;
832 + reg = <0x0>; /* GEM_ID */
833 + fsl,gemac-bus-id = <0x0>; /* BUS_ID */
834 + fsl,mdio-mux-val = <0x0>;
835 + phy-mode = "sgmii";
836 + phy-handle = <&sgmii_phy1>;
841 + compatible = "fsl,pfe-gemac-port";
842 + #address-cells = <1>;
844 + reg = <0x1>; /* GEM_ID */
845 + fsl,gemac-bus-id = <0x1>; /* BUS_ID */
846 + fsl,mdio-mux-val = <0x0>;
847 + phy-mode = "sgmii";
848 + phy-handle = <&sgmii_phy2>;
852 + #address-cells = <1>;
855 + sgmii_phy1: ethernet-phy@2 {
859 + sgmii_phy2: ethernet-phy@1 {
865 @@ -8255,6 +8255,14 @@ F: drivers/ptp/ptp_qoriq.c
866 F: drivers/ptp/ptp_qoriq_debugfs.c
867 F: include/linux/fsl/ptp_qoriq.h
869 +FREESCALE QORIQ PPFE ETHERNET DRIVER
870 +M: Anji Jagarlmudi <anji.jagarlmudi@nxp.com>
871 +M: Calvin Johnson <calvin.johnson@nxp.com>
872 +L: netdev@vger.kernel.org
874 +F: drivers/staging/fsl_ppfe
875 +F: Documentation/devicetree/bindings/net/fsl_ppfe/pfe.txt
877 FREESCALE QUAD SPI DRIVER
878 M: Han Xu <han.xu@nxp.com>
879 L: linux-spi@vger.kernel.org
880 --- a/drivers/staging/Kconfig
881 +++ b/drivers/staging/Kconfig
882 @@ -80,4 +80,6 @@ source "drivers/staging/qlge/Kconfig"
884 source "drivers/staging/vme_user/Kconfig"
886 +source "drivers/staging/fsl_ppfe/Kconfig"
889 --- a/drivers/staging/Makefile
890 +++ b/drivers/staging/Makefile
891 @@ -29,3 +29,4 @@ obj-$(CONFIG_PI433) += pi433/
892 obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/
893 obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
894 obj-$(CONFIG_QLGE) += qlge/
895 +obj-$(CONFIG_FSL_PPFE) += fsl_ppfe/
897 +++ b/drivers/staging/fsl_ppfe/Kconfig
900 +# Freescale Programmable Packet Forwarding Engine driver
903 + tristate "Freescale PPFE Driver"
907 + Freescale LS1012A SoC has a Programmable Packet Forwarding Engine.
908 + It provides two high performance ethernet interfaces.
909 + This driver initializes, programs and controls the PPFE.
910 + Use this driver to enable network connectivity on LS1012A platforms.
914 +config FSL_PPFE_UTIL_DISABLED
915 + bool "Disable PPFE UTIL Processor Engine"
917 + UTIL PE has to be enabled only if required.
921 +++ b/drivers/staging/fsl_ppfe/Makefile
924 +# Makefile for Freesecale PPFE driver
927 +ccflags-y += -I $(srctree)/$(src)/include -I $(srctree)/$(src)
929 +obj-$(CONFIG_FSL_PPFE) += pfe.o
931 +pfe-y += pfe_mod.o \
940 + pfe_ls1012a_platform.o \
944 +++ b/drivers/staging/fsl_ppfe/TODO
947 + - provide pfe pe monitoring support
949 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus.h
952 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
953 + * Copyright 2017 NXP
955 + * This program is free software; you can redistribute it and/or modify
956 + * it under the terms of the GNU General Public License as published by
957 + * the Free Software Foundation; either version 2 of the License, or
958 + * (at your option) any later version.
960 + * This program is distributed in the hope that it will be useful,
961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
963 + * GNU General Public License for more details.
965 + * You should have received a copy of the GNU General Public License
966 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
972 +#define EMAC1_BASE_ADDR (CBUS_BASE_ADDR + 0x200000)
973 +#define EGPI1_BASE_ADDR (CBUS_BASE_ADDR + 0x210000)
974 +#define EMAC2_BASE_ADDR (CBUS_BASE_ADDR + 0x220000)
975 +#define EGPI2_BASE_ADDR (CBUS_BASE_ADDR + 0x230000)
976 +#define BMU1_BASE_ADDR (CBUS_BASE_ADDR + 0x240000)
977 +#define BMU2_BASE_ADDR (CBUS_BASE_ADDR + 0x250000)
978 +#define ARB_BASE_ADDR (CBUS_BASE_ADDR + 0x260000)
979 +#define DDR_CONFIG_BASE_ADDR (CBUS_BASE_ADDR + 0x270000)
980 +#define HIF_BASE_ADDR (CBUS_BASE_ADDR + 0x280000)
981 +#define HGPI_BASE_ADDR (CBUS_BASE_ADDR + 0x290000)
982 +#define LMEM_BASE_ADDR (CBUS_BASE_ADDR + 0x300000)
983 +#define LMEM_SIZE 0x10000
984 +#define LMEM_END (LMEM_BASE_ADDR + LMEM_SIZE)
985 +#define TMU_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x310000)
986 +#define CLASS_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x320000)
987 +#define HIF_NOCPY_BASE_ADDR (CBUS_BASE_ADDR + 0x350000)
988 +#define UTIL_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x360000)
989 +#define CBUS_GPT_BASE_ADDR (CBUS_BASE_ADDR + 0x370000)
992 + * defgroup XXX_MEM_ACCESS_ADDR PE memory access through CSR
993 + * XXX_MEM_ACCESS_ADDR register bit definitions.
995 +#define PE_MEM_ACCESS_WRITE BIT(31) /* Internal Memory Write. */
996 +#define PE_MEM_ACCESS_IMEM BIT(15)
997 +#define PE_MEM_ACCESS_DMEM BIT(16)
999 +/* Byte Enables of the Internal memory access. These are interpred in BE */
1000 +#define PE_MEM_ACCESS_BYTE_ENABLE(offset, size) \
1001 + ({ typeof(size) size_ = (size); \
1002 + (((BIT(size_) - 1) << (4 - (offset) - (size_))) & 0xf) << 24; })
1004 +#include "cbus/emac_mtip.h"
1005 +#include "cbus/gpi.h"
1006 +#include "cbus/bmu.h"
1007 +#include "cbus/hif.h"
1008 +#include "cbus/tmu_csr.h"
1009 +#include "cbus/class_csr.h"
1010 +#include "cbus/hif_nocpy.h"
1011 +#include "cbus/util_csr.h"
1013 +/* PFE cores states */
1014 +#define CORE_DISABLE 0x00000000
1015 +#define CORE_ENABLE 0x00000001
1016 +#define CORE_SW_RESET 0x00000002
1019 +#define LMEM_HDR_SIZE 0x0010
1020 +#define LMEM_BUF_SIZE_LN2 0x7
1021 +#define LMEM_BUF_SIZE BIT(LMEM_BUF_SIZE_LN2)
1024 +#define DDR_HDR_SIZE 0x0100
1025 +#define DDR_BUF_SIZE_LN2 0xb
1026 +#define DDR_BUF_SIZE BIT(DDR_BUF_SIZE_LN2)
1028 +#endif /* _CBUS_H_ */
1030 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h
1033 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1034 + * Copyright 2017 NXP
1036 + * This program is free software; you can redistribute it and/or modify
1037 + * it under the terms of the GNU General Public License as published by
1038 + * the Free Software Foundation; either version 2 of the License, or
1039 + * (at your option) any later version.
1041 + * This program is distributed in the hope that it will be useful,
1042 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1043 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1044 + * GNU General Public License for more details.
1046 + * You should have received a copy of the GNU General Public License
1047 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1053 +#define BMU_VERSION 0x000
1054 +#define BMU_CTRL 0x004
1055 +#define BMU_UCAST_CONFIG 0x008
1056 +#define BMU_UCAST_BASE_ADDR 0x00c
1057 +#define BMU_BUF_SIZE 0x010
1058 +#define BMU_BUF_CNT 0x014
1059 +#define BMU_THRES 0x018
1060 +#define BMU_INT_SRC 0x020
1061 +#define BMU_INT_ENABLE 0x024
1062 +#define BMU_ALLOC_CTRL 0x030
1063 +#define BMU_FREE_CTRL 0x034
1064 +#define BMU_FREE_ERR_ADDR 0x038
1065 +#define BMU_CURR_BUF_CNT 0x03c
1066 +#define BMU_MCAST_CNT 0x040
1067 +#define BMU_MCAST_ALLOC_CTRL 0x044
1068 +#define BMU_REM_BUF_CNT 0x048
1069 +#define BMU_LOW_WATERMARK 0x050
1070 +#define BMU_HIGH_WATERMARK 0x054
1071 +#define BMU_INT_MEM_ACCESS 0x100
1074 + unsigned long baseaddr;
1077 + u32 low_watermark;
1078 + u32 high_watermark;
1081 +#define BMU1_BUF_SIZE LMEM_BUF_SIZE_LN2
1082 +#define BMU2_BUF_SIZE DDR_BUF_SIZE_LN2
1084 +#define BMU2_MCAST_ALLOC_CTRL (BMU2_BASE_ADDR + BMU_MCAST_ALLOC_CTRL)
1086 +#endif /* _BMU_H_ */
1088 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h
1091 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1092 + * Copyright 2017 NXP
1094 + * This program is free software; you can redistribute it and/or modify
1095 + * it under the terms of the GNU General Public License as published by
1096 + * the Free Software Foundation; either version 2 of the License, or
1097 + * (at your option) any later version.
1099 + * This program is distributed in the hope that it will be useful,
1100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1102 + * GNU General Public License for more details.
1104 + * You should have received a copy of the GNU General Public License
1105 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1108 +#ifndef _CLASS_CSR_H_
1109 +#define _CLASS_CSR_H_
1111 +/* @file class_csr.h.
1112 + * class_csr - block containing all the classifier control and status register.
1113 + * Mapped on CBUS and accessible from all PE's and ARM.
1115 +#define CLASS_VERSION (CLASS_CSR_BASE_ADDR + 0x000)
1116 +#define CLASS_TX_CTRL (CLASS_CSR_BASE_ADDR + 0x004)
1117 +#define CLASS_INQ_PKTPTR (CLASS_CSR_BASE_ADDR + 0x010)
1119 +/* (ddr_hdr_size[24:16], lmem_hdr_size[5:0]) */
1120 +#define CLASS_HDR_SIZE (CLASS_CSR_BASE_ADDR + 0x014)
1122 +/* LMEM header size for the Classifier block.\ Data in the LMEM
1123 + * is written from this offset.
1125 +#define CLASS_HDR_SIZE_LMEM(off) ((off) & 0x3f)
1127 +/* DDR header size for the Classifier block.\ Data in the DDR
1128 + * is written from this offset.
1130 +#define CLASS_HDR_SIZE_DDR(off) (((off) & 0x1ff) << 16)
1132 +#define CLASS_PE0_QB_DM_ADDR0 (CLASS_CSR_BASE_ADDR + 0x020)
1134 +/* DMEM address of first [15:0] and second [31:16] buffers on QB side. */
1135 +#define CLASS_PE0_QB_DM_ADDR1 (CLASS_CSR_BASE_ADDR + 0x024)
1137 +/* DMEM address of third [15:0] and fourth [31:16] buffers on QB side. */
1138 +#define CLASS_PE0_RO_DM_ADDR0 (CLASS_CSR_BASE_ADDR + 0x060)
1140 +/* DMEM address of first [15:0] and second [31:16] buffers on RO side. */
1141 +#define CLASS_PE0_RO_DM_ADDR1 (CLASS_CSR_BASE_ADDR + 0x064)
1143 +/* DMEM address of third [15:0] and fourth [31:16] buffers on RO side. */
1145 +/* @name Class PE memory access. Allows external PE's and HOST to
1146 + * read/write PMEM/DMEM memory ranges for each classifier PE.
1148 +/* {sr_pe_mem_cmd[31], csr_pe_mem_wren[27:24], csr_pe_mem_addr[23:0]},
1149 + * See \ref XXX_MEM_ACCESS_ADDR for details.
1151 +#define CLASS_MEM_ACCESS_ADDR (CLASS_CSR_BASE_ADDR + 0x100)
1153 +/* Internal Memory Access Write Data [31:0] */
1154 +#define CLASS_MEM_ACCESS_WDATA (CLASS_CSR_BASE_ADDR + 0x104)
1156 +/* Internal Memory Access Read Data [31:0] */
1157 +#define CLASS_MEM_ACCESS_RDATA (CLASS_CSR_BASE_ADDR + 0x108)
1158 +#define CLASS_TM_INQ_ADDR (CLASS_CSR_BASE_ADDR + 0x114)
1159 +#define CLASS_PE_STATUS (CLASS_CSR_BASE_ADDR + 0x118)
1161 +#define CLASS_PHY1_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x11c)
1162 +#define CLASS_PHY1_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x120)
1163 +#define CLASS_PHY1_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x124)
1164 +#define CLASS_PHY1_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x128)
1165 +#define CLASS_PHY1_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x12c)
1166 +#define CLASS_PHY1_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x130)
1167 +#define CLASS_PHY1_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x134)
1168 +#define CLASS_PHY1_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x138)
1169 +#define CLASS_PHY1_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x13c)
1170 +#define CLASS_PHY1_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x140)
1171 +#define CLASS_PHY2_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x144)
1172 +#define CLASS_PHY2_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x148)
1173 +#define CLASS_PHY2_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x14c)
1174 +#define CLASS_PHY2_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x150)
1175 +#define CLASS_PHY2_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x154)
1176 +#define CLASS_PHY2_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x158)
1177 +#define CLASS_PHY2_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x15c)
1178 +#define CLASS_PHY2_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x160)
1179 +#define CLASS_PHY2_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x164)
1180 +#define CLASS_PHY2_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x168)
1181 +#define CLASS_PHY3_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x16c)
1182 +#define CLASS_PHY3_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x170)
1183 +#define CLASS_PHY3_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x174)
1184 +#define CLASS_PHY3_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x178)
1185 +#define CLASS_PHY3_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x17c)
1186 +#define CLASS_PHY3_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x180)
1187 +#define CLASS_PHY3_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x184)
1188 +#define CLASS_PHY3_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x188)
1189 +#define CLASS_PHY3_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x18c)
1190 +#define CLASS_PHY3_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x190)
1191 +#define CLASS_PHY1_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x194)
1192 +#define CLASS_PHY1_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x198)
1193 +#define CLASS_PHY1_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x19c)
1194 +#define CLASS_PHY1_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a0)
1195 +#define CLASS_PHY2_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a4)
1196 +#define CLASS_PHY2_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a8)
1197 +#define CLASS_PHY2_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1ac)
1198 +#define CLASS_PHY2_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b0)
1199 +#define CLASS_PHY3_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b4)
1200 +#define CLASS_PHY3_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b8)
1201 +#define CLASS_PHY3_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1bc)
1202 +#define CLASS_PHY3_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c0)
1203 +#define CLASS_PHY4_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c4)
1204 +#define CLASS_PHY4_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c8)
1205 +#define CLASS_PHY4_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1cc)
1206 +#define CLASS_PHY4_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1d0)
1207 +#define CLASS_PHY4_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x1d4)
1208 +#define CLASS_PHY4_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x1d8)
1209 +#define CLASS_PHY4_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1dc)
1210 +#define CLASS_PHY4_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1e0)
1211 +#define CLASS_PHY4_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x1e4)
1212 +#define CLASS_PHY4_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1e8)
1213 +#define CLASS_PHY4_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x1ec)
1214 +#define CLASS_PHY4_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x1f0)
1215 +#define CLASS_PHY4_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x1f4)
1216 +#define CLASS_PHY4_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x1f8)
1218 +#define CLASS_PE_SYS_CLK_RATIO (CLASS_CSR_BASE_ADDR + 0x200)
1219 +#define CLASS_AFULL_THRES (CLASS_CSR_BASE_ADDR + 0x204)
1220 +#define CLASS_GAP_BETWEEN_READS (CLASS_CSR_BASE_ADDR + 0x208)
1221 +#define CLASS_MAX_BUF_CNT (CLASS_CSR_BASE_ADDR + 0x20c)
1222 +#define CLASS_TSQ_FIFO_THRES (CLASS_CSR_BASE_ADDR + 0x210)
1223 +#define CLASS_TSQ_MAX_CNT (CLASS_CSR_BASE_ADDR + 0x214)
1224 +#define CLASS_IRAM_DATA_0 (CLASS_CSR_BASE_ADDR + 0x218)
1225 +#define CLASS_IRAM_DATA_1 (CLASS_CSR_BASE_ADDR + 0x21c)
1226 +#define CLASS_IRAM_DATA_2 (CLASS_CSR_BASE_ADDR + 0x220)
1227 +#define CLASS_IRAM_DATA_3 (CLASS_CSR_BASE_ADDR + 0x224)
1229 +#define CLASS_BUS_ACCESS_ADDR (CLASS_CSR_BASE_ADDR + 0x228)
1231 +#define CLASS_BUS_ACCESS_WDATA (CLASS_CSR_BASE_ADDR + 0x22c)
1232 +#define CLASS_BUS_ACCESS_RDATA (CLASS_CSR_BASE_ADDR + 0x230)
1234 +/* (route_entry_size[9:0], route_hash_size[23:16]
1235 + * (this is actually ln2(size)))
1237 +#define CLASS_ROUTE_HASH_ENTRY_SIZE (CLASS_CSR_BASE_ADDR + 0x234)
1239 +#define CLASS_ROUTE_ENTRY_SIZE(size) ((size) & 0x1ff)
1240 +#define CLASS_ROUTE_HASH_SIZE(hash_bits) (((hash_bits) & 0xff) << 16)
1242 +#define CLASS_ROUTE_TABLE_BASE (CLASS_CSR_BASE_ADDR + 0x238)
1244 +#define CLASS_ROUTE_MULTI (CLASS_CSR_BASE_ADDR + 0x23c)
1245 +#define CLASS_SMEM_OFFSET (CLASS_CSR_BASE_ADDR + 0x240)
1246 +#define CLASS_LMEM_BUF_SIZE (CLASS_CSR_BASE_ADDR + 0x244)
1247 +#define CLASS_VLAN_ID (CLASS_CSR_BASE_ADDR + 0x248)
1248 +#define CLASS_BMU1_BUF_FREE (CLASS_CSR_BASE_ADDR + 0x24c)
1249 +#define CLASS_USE_TMU_INQ (CLASS_CSR_BASE_ADDR + 0x250)
1250 +#define CLASS_VLAN_ID1 (CLASS_CSR_BASE_ADDR + 0x254)
1252 +#define CLASS_BUS_ACCESS_BASE (CLASS_CSR_BASE_ADDR + 0x258)
1253 +#define CLASS_BUS_ACCESS_BASE_MASK (0xFF000000)
1254 +/* bit 31:24 of PE peripheral address are stored in CLASS_BUS_ACCESS_BASE */
1256 +#define CLASS_HIF_PARSE (CLASS_CSR_BASE_ADDR + 0x25c)
1258 +#define CLASS_HOST_PE0_GP (CLASS_CSR_BASE_ADDR + 0x260)
1259 +#define CLASS_PE0_GP (CLASS_CSR_BASE_ADDR + 0x264)
1260 +#define CLASS_HOST_PE1_GP (CLASS_CSR_BASE_ADDR + 0x268)
1261 +#define CLASS_PE1_GP (CLASS_CSR_BASE_ADDR + 0x26c)
1262 +#define CLASS_HOST_PE2_GP (CLASS_CSR_BASE_ADDR + 0x270)
1263 +#define CLASS_PE2_GP (CLASS_CSR_BASE_ADDR + 0x274)
1264 +#define CLASS_HOST_PE3_GP (CLASS_CSR_BASE_ADDR + 0x278)
1265 +#define CLASS_PE3_GP (CLASS_CSR_BASE_ADDR + 0x27c)
1266 +#define CLASS_HOST_PE4_GP (CLASS_CSR_BASE_ADDR + 0x280)
1267 +#define CLASS_PE4_GP (CLASS_CSR_BASE_ADDR + 0x284)
1268 +#define CLASS_HOST_PE5_GP (CLASS_CSR_BASE_ADDR + 0x288)
1269 +#define CLASS_PE5_GP (CLASS_CSR_BASE_ADDR + 0x28c)
1271 +#define CLASS_PE_INT_SRC (CLASS_CSR_BASE_ADDR + 0x290)
1272 +#define CLASS_PE_INT_ENABLE (CLASS_CSR_BASE_ADDR + 0x294)
1274 +#define CLASS_TPID0_TPID1 (CLASS_CSR_BASE_ADDR + 0x298)
1275 +#define CLASS_TPID2 (CLASS_CSR_BASE_ADDR + 0x29c)
1277 +#define CLASS_L4_CHKSUM_ADDR (CLASS_CSR_BASE_ADDR + 0x2a0)
1279 +#define CLASS_PE0_DEBUG (CLASS_CSR_BASE_ADDR + 0x2a4)
1280 +#define CLASS_PE1_DEBUG (CLASS_CSR_BASE_ADDR + 0x2a8)
1281 +#define CLASS_PE2_DEBUG (CLASS_CSR_BASE_ADDR + 0x2ac)
1282 +#define CLASS_PE3_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b0)
1283 +#define CLASS_PE4_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b4)
1284 +#define CLASS_PE5_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b8)
1286 +#define CLASS_STATE (CLASS_CSR_BASE_ADDR + 0x2bc)
1288 +/* CLASS defines */
1289 +#define CLASS_PBUF_SIZE 0x100 /* Fixed by hardware */
1290 +#define CLASS_PBUF_HEADER_OFFSET 0x80 /* Can be configured */
1292 +/* Can be configured */
1293 +#define CLASS_PBUF0_BASE_ADDR 0x000
1294 +/* Can be configured */
1295 +#define CLASS_PBUF1_BASE_ADDR (CLASS_PBUF0_BASE_ADDR + CLASS_PBUF_SIZE)
1296 +/* Can be configured */
1297 +#define CLASS_PBUF2_BASE_ADDR (CLASS_PBUF1_BASE_ADDR + CLASS_PBUF_SIZE)
1298 +/* Can be configured */
1299 +#define CLASS_PBUF3_BASE_ADDR (CLASS_PBUF2_BASE_ADDR + CLASS_PBUF_SIZE)
1301 +#define CLASS_PBUF0_HEADER_BASE_ADDR (CLASS_PBUF0_BASE_ADDR + \
1302 + CLASS_PBUF_HEADER_OFFSET)
1303 +#define CLASS_PBUF1_HEADER_BASE_ADDR (CLASS_PBUF1_BASE_ADDR + \
1304 + CLASS_PBUF_HEADER_OFFSET)
1305 +#define CLASS_PBUF2_HEADER_BASE_ADDR (CLASS_PBUF2_BASE_ADDR + \
1306 + CLASS_PBUF_HEADER_OFFSET)
1307 +#define CLASS_PBUF3_HEADER_BASE_ADDR (CLASS_PBUF3_BASE_ADDR + \
1308 + CLASS_PBUF_HEADER_OFFSET)
1310 +#define CLASS_PE0_RO_DM_ADDR0_VAL ((CLASS_PBUF1_BASE_ADDR << 16) | \
1311 + CLASS_PBUF0_BASE_ADDR)
1312 +#define CLASS_PE0_RO_DM_ADDR1_VAL ((CLASS_PBUF3_BASE_ADDR << 16) | \
1313 + CLASS_PBUF2_BASE_ADDR)
1315 +#define CLASS_PE0_QB_DM_ADDR0_VAL ((CLASS_PBUF1_HEADER_BASE_ADDR << 16) |\
1316 + CLASS_PBUF0_HEADER_BASE_ADDR)
1317 +#define CLASS_PE0_QB_DM_ADDR1_VAL ((CLASS_PBUF3_HEADER_BASE_ADDR << 16) |\
1318 + CLASS_PBUF2_HEADER_BASE_ADDR)
1320 +#define CLASS_ROUTE_SIZE 128
1321 +#define CLASS_MAX_ROUTE_SIZE 256
1322 +#define CLASS_ROUTE_HASH_BITS 20
1323 +#define CLASS_ROUTE_HASH_MASK (BIT(CLASS_ROUTE_HASH_BITS) - 1)
1325 +/* Can be configured */
1326 +#define CLASS_ROUTE0_BASE_ADDR 0x400
1327 +/* Can be configured */
1328 +#define CLASS_ROUTE1_BASE_ADDR (CLASS_ROUTE0_BASE_ADDR + CLASS_ROUTE_SIZE)
1329 +/* Can be configured */
1330 +#define CLASS_ROUTE2_BASE_ADDR (CLASS_ROUTE1_BASE_ADDR + CLASS_ROUTE_SIZE)
1331 +/* Can be configured */
1332 +#define CLASS_ROUTE3_BASE_ADDR (CLASS_ROUTE2_BASE_ADDR + CLASS_ROUTE_SIZE)
1334 +#define CLASS_SA_SIZE 128
1335 +#define CLASS_IPSEC_SA0_BASE_ADDR 0x600
1337 +#define CLASS_IPSEC_SA1_BASE_ADDR (CLASS_IPSEC_SA0_BASE_ADDR + CLASS_SA_SIZE)
1339 +#define CLASS_IPSEC_SA2_BASE_ADDR (CLASS_IPSEC_SA1_BASE_ADDR + CLASS_SA_SIZE)
1341 +#define CLASS_IPSEC_SA3_BASE_ADDR (CLASS_IPSEC_SA2_BASE_ADDR + CLASS_SA_SIZE)
1343 +/* generic purpose free dmem buffer, last portion of 2K dmem pbuf */
1344 +#define CLASS_GP_DMEM_BUF_SIZE (2048 - (CLASS_PBUF_SIZE * 4) - \
1345 + (CLASS_ROUTE_SIZE * 4) - (CLASS_SA_SIZE))
1346 +#define CLASS_GP_DMEM_BUF ((void *)(CLASS_IPSEC_SA0_BASE_ADDR + \
1349 +#define TWO_LEVEL_ROUTE BIT(0)
1350 +#define PHYNO_IN_HASH BIT(1)
1351 +#define HW_ROUTE_FETCH BIT(3)
1352 +#define HW_BRIDGE_FETCH BIT(5)
1353 +#define IP_ALIGNED BIT(6)
1354 +#define ARC_HIT_CHECK_EN BIT(7)
1355 +#define CLASS_TOE BIT(11)
1356 +#define HASH_NORMAL (0 << 12)
1357 +#define HASH_CRC_PORT BIT(12)
1358 +#define HASH_CRC_IP (2 << 12)
1359 +#define HASH_CRC_PORT_IP (3 << 12)
1360 +#define QB2BUS_LE BIT(15)
1362 +#define TCP_CHKSUM_DROP BIT(0)
1363 +#define UDP_CHKSUM_DROP BIT(1)
1364 +#define IPV4_CHKSUM_DROP BIT(9)
1366 +/*CLASS_HIF_PARSE bits*/
1367 +#define HIF_PKT_CLASS_EN BIT(0)
1368 +#define HIF_PKT_OFFSET(ofst) (((ofst) & 0xF) << 1)
1372 + unsigned long route_table_baseaddr;
1373 + u32 route_table_hash_bits;
1374 + u32 pe_sys_clk_ratio;
1378 +#endif /* _CLASS_CSR_H_ */
1380 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h
1383 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1384 + * Copyright 2017 NXP
1386 + * This program is free software; you can redistribute it and/or modify
1387 + * it under the terms of the GNU General Public License as published by
1388 + * the Free Software Foundation; either version 2 of the License, or
1389 + * (at your option) any later version.
1391 + * This program is distributed in the hope that it will be useful,
1392 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1393 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1394 + * GNU General Public License for more details.
1396 + * You should have received a copy of the GNU General Public License
1397 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1403 +#include <linux/ethtool.h>
1405 +#define EMAC_IEVENT_REG 0x004
1406 +#define EMAC_IMASK_REG 0x008
1407 +#define EMAC_R_DES_ACTIVE_REG 0x010
1408 +#define EMAC_X_DES_ACTIVE_REG 0x014
1409 +#define EMAC_ECNTRL_REG 0x024
1410 +#define EMAC_MII_DATA_REG 0x040
1411 +#define EMAC_MII_CTRL_REG 0x044
1412 +#define EMAC_MIB_CTRL_STS_REG 0x064
1413 +#define EMAC_RCNTRL_REG 0x084
1414 +#define EMAC_TCNTRL_REG 0x0C4
1415 +#define EMAC_PHY_ADDR_LOW 0x0E4
1416 +#define EMAC_PHY_ADDR_HIGH 0x0E8
1417 +#define EMAC_GAUR 0x120
1418 +#define EMAC_GALR 0x124
1419 +#define EMAC_TFWR_STR_FWD 0x144
1420 +#define EMAC_RX_SECTION_FULL 0x190
1421 +#define EMAC_RX_SECTION_EMPTY 0x194
1422 +#define EMAC_TX_SECTION_EMPTY 0x1A0
1423 +#define EMAC_TRUNC_FL 0x1B0
1425 +#define RMON_T_DROP 0x200 /* Count of frames not cntd correctly */
1426 +#define RMON_T_PACKETS 0x204 /* RMON TX packet count */
1427 +#define RMON_T_BC_PKT 0x208 /* RMON TX broadcast pkts */
1428 +#define RMON_T_MC_PKT 0x20c /* RMON TX multicast pkts */
1429 +#define RMON_T_CRC_ALIGN 0x210 /* RMON TX pkts with CRC align err */
1430 +#define RMON_T_UNDERSIZE 0x214 /* RMON TX pkts < 64 bytes, good CRC */
1431 +#define RMON_T_OVERSIZE 0x218 /* RMON TX pkts > MAX_FL bytes good CRC */
1432 +#define RMON_T_FRAG 0x21c /* RMON TX pkts < 64 bytes, bad CRC */
1433 +#define RMON_T_JAB 0x220 /* RMON TX pkts > MAX_FL bytes, bad CRC */
1434 +#define RMON_T_COL 0x224 /* RMON TX collision count */
1435 +#define RMON_T_P64 0x228 /* RMON TX 64 byte pkts */
1436 +#define RMON_T_P65TO127 0x22c /* RMON TX 65 to 127 byte pkts */
1437 +#define RMON_T_P128TO255 0x230 /* RMON TX 128 to 255 byte pkts */
1438 +#define RMON_T_P256TO511 0x234 /* RMON TX 256 to 511 byte pkts */
1439 +#define RMON_T_P512TO1023 0x238 /* RMON TX 512 to 1023 byte pkts */
1440 +#define RMON_T_P1024TO2047 0x23c /* RMON TX 1024 to 2047 byte pkts */
1441 +#define RMON_T_P_GTE2048 0x240 /* RMON TX pkts > 2048 bytes */
1442 +#define RMON_T_OCTETS 0x244 /* RMON TX octets */
1443 +#define IEEE_T_DROP 0x248 /* Count of frames not counted crtly */
1444 +#define IEEE_T_FRAME_OK 0x24c /* Frames tx'd OK */
1445 +#define IEEE_T_1COL 0x250 /* Frames tx'd with single collision */
1446 +#define IEEE_T_MCOL 0x254 /* Frames tx'd with multiple collision */
1447 +#define IEEE_T_DEF 0x258 /* Frames tx'd after deferral delay */
1448 +#define IEEE_T_LCOL 0x25c /* Frames tx'd with late collision */
1449 +#define IEEE_T_EXCOL 0x260 /* Frames tx'd with excesv collisions */
1450 +#define IEEE_T_MACERR 0x264 /* Frames tx'd with TX FIFO underrun */
1451 +#define IEEE_T_CSERR 0x268 /* Frames tx'd with carrier sense err */
1452 +#define IEEE_T_SQE 0x26c /* Frames tx'd with SQE err */
1453 +#define IEEE_T_FDXFC 0x270 /* Flow control pause frames tx'd */
1454 +#define IEEE_T_OCTETS_OK 0x274 /* Octet count for frames tx'd w/o err */
1455 +#define RMON_R_PACKETS 0x284 /* RMON RX packet count */
1456 +#define RMON_R_BC_PKT 0x288 /* RMON RX broadcast pkts */
1457 +#define RMON_R_MC_PKT 0x28c /* RMON RX multicast pkts */
1458 +#define RMON_R_CRC_ALIGN 0x290 /* RMON RX pkts with CRC alignment err */
1459 +#define RMON_R_UNDERSIZE 0x294 /* RMON RX pkts < 64 bytes, good CRC */
1460 +#define RMON_R_OVERSIZE 0x298 /* RMON RX pkts > MAX_FL bytes good CRC */
1461 +#define RMON_R_FRAG 0x29c /* RMON RX pkts < 64 bytes, bad CRC */
1462 +#define RMON_R_JAB 0x2a0 /* RMON RX pkts > MAX_FL bytes, bad CRC */
1463 +#define RMON_R_RESVD_O 0x2a4 /* Reserved */
1464 +#define RMON_R_P64 0x2a8 /* RMON RX 64 byte pkts */
1465 +#define RMON_R_P65TO127 0x2ac /* RMON RX 65 to 127 byte pkts */
1466 +#define RMON_R_P128TO255 0x2b0 /* RMON RX 128 to 255 byte pkts */
1467 +#define RMON_R_P256TO511 0x2b4 /* RMON RX 256 to 511 byte pkts */
1468 +#define RMON_R_P512TO1023 0x2b8 /* RMON RX 512 to 1023 byte pkts */
1469 +#define RMON_R_P1024TO2047 0x2bc /* RMON RX 1024 to 2047 byte pkts */
1470 +#define RMON_R_P_GTE2048 0x2c0 /* RMON RX pkts > 2048 bytes */
1471 +#define RMON_R_OCTETS 0x2c4 /* RMON RX octets */
1472 +#define IEEE_R_DROP 0x2c8 /* Count frames not counted correctly */
1473 +#define IEEE_R_FRAME_OK 0x2cc /* Frames rx'd OK */
1474 +#define IEEE_R_CRC 0x2d0 /* Frames rx'd with CRC err */
1475 +#define IEEE_R_ALIGN 0x2d4 /* Frames rx'd with alignment err */
1476 +#define IEEE_R_MACERR 0x2d8 /* Receive FIFO overflow count */
1477 +#define IEEE_R_FDXFC 0x2dc /* Flow control pause frames rx'd */
1478 +#define IEEE_R_OCTETS_OK 0x2e0 /* Octet cnt for frames rx'd w/o err */
1480 +#define EMAC_SMAC_0_0 0x500 /*Supplemental MAC Address 0 (RW).*/
1481 +#define EMAC_SMAC_0_1 0x504 /*Supplemental MAC Address 0 (RW).*/
1483 +/* GEMAC definitions and settings */
1485 +#define EMAC_PORT_0 0
1486 +#define EMAC_PORT_1 1
1488 +/* GEMAC Bit definitions */
1489 +#define EMAC_IEVENT_HBERR 0x80000000
1490 +#define EMAC_IEVENT_BABR 0x40000000
1491 +#define EMAC_IEVENT_BABT 0x20000000
1492 +#define EMAC_IEVENT_GRA 0x10000000
1493 +#define EMAC_IEVENT_TXF 0x08000000
1494 +#define EMAC_IEVENT_TXB 0x04000000
1495 +#define EMAC_IEVENT_RXF 0x02000000
1496 +#define EMAC_IEVENT_RXB 0x01000000
1497 +#define EMAC_IEVENT_MII 0x00800000
1498 +#define EMAC_IEVENT_EBERR 0x00400000
1499 +#define EMAC_IEVENT_LC 0x00200000
1500 +#define EMAC_IEVENT_RL 0x00100000
1501 +#define EMAC_IEVENT_UN 0x00080000
1503 +#define EMAC_IMASK_HBERR 0x80000000
1504 +#define EMAC_IMASK_BABR 0x40000000
1505 +#define EMAC_IMASKT_BABT 0x20000000
1506 +#define EMAC_IMASK_GRA 0x10000000
1507 +#define EMAC_IMASKT_TXF 0x08000000
1508 +#define EMAC_IMASK_TXB 0x04000000
1509 +#define EMAC_IMASKT_RXF 0x02000000
1510 +#define EMAC_IMASK_RXB 0x01000000
1511 +#define EMAC_IMASK_MII 0x00800000
1512 +#define EMAC_IMASK_EBERR 0x00400000
1513 +#define EMAC_IMASK_LC 0x00200000
1514 +#define EMAC_IMASKT_RL 0x00100000
1515 +#define EMAC_IMASK_UN 0x00080000
1517 +#define EMAC_RCNTRL_MAX_FL_SHIFT 16
1518 +#define EMAC_RCNTRL_LOOP 0x00000001
1519 +#define EMAC_RCNTRL_DRT 0x00000002
1520 +#define EMAC_RCNTRL_MII_MODE 0x00000004
1521 +#define EMAC_RCNTRL_PROM 0x00000008
1522 +#define EMAC_RCNTRL_BC_REJ 0x00000010
1523 +#define EMAC_RCNTRL_FCE 0x00000020
1524 +#define EMAC_RCNTRL_RGMII 0x00000040
1525 +#define EMAC_RCNTRL_SGMII 0x00000080
1526 +#define EMAC_RCNTRL_RMII 0x00000100
1527 +#define EMAC_RCNTRL_RMII_10T 0x00000200
1528 +#define EMAC_RCNTRL_CRC_FWD 0x00004000
1530 +#define EMAC_TCNTRL_GTS 0x00000001
1531 +#define EMAC_TCNTRL_HBC 0x00000002
1532 +#define EMAC_TCNTRL_FDEN 0x00000004
1533 +#define EMAC_TCNTRL_TFC_PAUSE 0x00000008
1534 +#define EMAC_TCNTRL_RFC_PAUSE 0x00000010
1536 +#define EMAC_ECNTRL_RESET 0x00000001 /* reset the EMAC */
1537 +#define EMAC_ECNTRL_ETHER_EN 0x00000002 /* enable the EMAC */
1538 +#define EMAC_ECNTRL_MAGIC_ENA 0x00000004
1539 +#define EMAC_ECNTRL_SLEEP 0x00000008
1540 +#define EMAC_ECNTRL_SPEED 0x00000020
1541 +#define EMAC_ECNTRL_DBSWAP 0x00000100
1543 +#define EMAC_X_WMRK_STRFWD 0x00000100
1545 +#define EMAC_X_DES_ACTIVE_TDAR 0x01000000
1546 +#define EMAC_R_DES_ACTIVE_RDAR 0x01000000
1548 +#define EMAC_RX_SECTION_EMPTY_V 0x00010006
1550 + * The possible operating speeds of the MAC, currently supporting 10, 100 and
1553 +enum mac_speed {SPEED_10M, SPEED_100M, SPEED_1000M, SPEED_1000M_PCS};
1555 +/* MII-related definitios */
1556 +#define EMAC_MII_DATA_ST 0x40000000 /* Start of frame delimiter */
1557 +#define EMAC_MII_DATA_OP_RD 0x20000000 /* Perform a read operation */
1558 +#define EMAC_MII_DATA_OP_CL45_RD 0x30000000 /* Perform a read operation */
1559 +#define EMAC_MII_DATA_OP_WR 0x10000000 /* Perform a write operation */
1560 +#define EMAC_MII_DATA_OP_CL45_WR 0x10000000 /* Perform a write operation */
1561 +#define EMAC_MII_DATA_PA_MSK 0x0f800000 /* PHY Address field mask */
1562 +#define EMAC_MII_DATA_RA_MSK 0x007c0000 /* PHY Register field mask */
1563 +#define EMAC_MII_DATA_TA 0x00020000 /* Turnaround */
1564 +#define EMAC_MII_DATA_DATAMSK 0x0000ffff /* PHY data field */
1566 +#define EMAC_MII_DATA_RA_SHIFT 18 /* MII Register address bits */
1567 +#define EMAC_MII_DATA_RA_MASK 0x1F /* MII Register address mask */
1568 +#define EMAC_MII_DATA_PA_SHIFT 23 /* MII PHY address bits */
1569 +#define EMAC_MII_DATA_PA_MASK 0x1F /* MII PHY address mask */
1571 +#define EMAC_MII_DATA_RA(v) (((v) & EMAC_MII_DATA_RA_MASK) << \
1572 + EMAC_MII_DATA_RA_SHIFT)
1573 +#define EMAC_MII_DATA_PA(v) (((v) & EMAC_MII_DATA_RA_MASK) << \
1574 + EMAC_MII_DATA_PA_SHIFT)
1575 +#define EMAC_MII_DATA(v) ((v) & 0xffff)
1577 +#define EMAC_MII_SPEED_SHIFT 1
1578 +#define EMAC_HOLDTIME_SHIFT 8
1579 +#define EMAC_HOLDTIME_MASK 0x7
1580 +#define EMAC_HOLDTIME(v) (((v) & EMAC_HOLDTIME_MASK) << \
1581 + EMAC_HOLDTIME_SHIFT)
1584 + * The Address organisation for the MAC device. All addresses are split into
1585 + * two 32-bit register fields. The first one (bottom) is the lower 32-bits of
1586 + * the address and the other field are the high order bits - this may be 16-bits
1587 + * in the case of MAC addresses, or 32-bits for the hash address.
1588 + * In terms of memory storage, the first item (bottom) is assumed to be at a
1589 + * lower address location than 'top'. i.e. top should be at address location of
1590 + * 'bottom' + 4 bytes.
1592 +struct pfe_mac_addr {
1593 + u32 bottom; /* Lower 32-bits of address. */
1594 + u32 top; /* Upper 32-bits of address. */
1598 + * The following is the organisation of the address filters section of the MAC
1599 + * registers. The Cadence MAC contains four possible specific address match
1600 + * addresses, if an incoming frame corresponds to any one of these four
1601 + * addresses then the frame will be copied to memory.
1602 + * It is not necessary for all four of the address match registers to be
1603 + * programmed, this is application dependent.
1606 + struct pfe_mac_addr one; /* Specific address register 1. */
1607 + struct pfe_mac_addr two; /* Specific address register 2. */
1608 + struct pfe_mac_addr three; /* Specific address register 3. */
1609 + struct pfe_mac_addr four; /* Specific address register 4. */
1618 +/* EMAC Hash size */
1619 +#define EMAC_HASH_REG_BITS 64
1621 +#define EMAC_SPEC_ADDR_MAX 4
1623 +#endif /* _EMAC_H_ */
1625 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h
1628 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1629 + * Copyright 2017 NXP
1631 + * This program is free software; you can redistribute it and/or modify
1632 + * it under the terms of the GNU General Public License as published by
1633 + * the Free Software Foundation; either version 2 of the License, or
1634 + * (at your option) any later version.
1636 + * This program is distributed in the hope that it will be useful,
1637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1639 + * GNU General Public License for more details.
1641 + * You should have received a copy of the GNU General Public License
1642 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1648 +#define GPI_VERSION 0x00
1649 +#define GPI_CTRL 0x04
1650 +#define GPI_RX_CONFIG 0x08
1651 +#define GPI_HDR_SIZE 0x0c
1652 +#define GPI_BUF_SIZE 0x10
1653 +#define GPI_LMEM_ALLOC_ADDR 0x14
1654 +#define GPI_LMEM_FREE_ADDR 0x18
1655 +#define GPI_DDR_ALLOC_ADDR 0x1c
1656 +#define GPI_DDR_FREE_ADDR 0x20
1657 +#define GPI_CLASS_ADDR 0x24
1658 +#define GPI_DRX_FIFO 0x28
1659 +#define GPI_TRX_FIFO 0x2c
1660 +#define GPI_INQ_PKTPTR 0x30
1661 +#define GPI_DDR_DATA_OFFSET 0x34
1662 +#define GPI_LMEM_DATA_OFFSET 0x38
1663 +#define GPI_TMLF_TX 0x4c
1664 +#define GPI_DTX_ASEQ 0x50
1665 +#define GPI_FIFO_STATUS 0x54
1666 +#define GPI_FIFO_DEBUG 0x58
1667 +#define GPI_TX_PAUSE_TIME 0x5c
1668 +#define GPI_LMEM_SEC_BUF_DATA_OFFSET 0x60
1669 +#define GPI_DDR_SEC_BUF_DATA_OFFSET 0x64
1670 +#define GPI_TOE_CHKSUM_EN 0x68
1671 +#define GPI_OVERRUN_DROPCNT 0x6c
1672 +#define GPI_CSR_MTIP_PAUSE_REG 0x74
1673 +#define GPI_CSR_MTIP_PAUSE_QUANTUM 0x78
1674 +#define GPI_CSR_RX_CNT 0x7c
1675 +#define GPI_CSR_TX_CNT 0x80
1676 +#define GPI_CSR_DEBUG1 0x84
1677 +#define GPI_CSR_DEBUG2 0x88
1680 + u32 lmem_rtry_cnt;
1683 + u32 mtip_pause_reg;
1686 +/* GPI commons defines */
1687 +#define GPI_LMEM_BUF_EN 0x1
1688 +#define GPI_DDR_BUF_EN 0x1
1690 +/* EGPI 1 defines */
1691 +#define EGPI1_LMEM_RTRY_CNT 0x40
1692 +#define EGPI1_TMLF_TXTHRES 0xBC
1693 +#define EGPI1_ASEQ_LEN 0x50
1695 +/* EGPI 2 defines */
1696 +#define EGPI2_LMEM_RTRY_CNT 0x40
1697 +#define EGPI2_TMLF_TXTHRES 0xBC
1698 +#define EGPI2_ASEQ_LEN 0x40
1700 +/* EGPI 3 defines */
1701 +#define EGPI3_LMEM_RTRY_CNT 0x40
1702 +#define EGPI3_TMLF_TXTHRES 0xBC
1703 +#define EGPI3_ASEQ_LEN 0x40
1706 +#define HGPI_LMEM_RTRY_CNT 0x40
1707 +#define HGPI_TMLF_TXTHRES 0xBC
1708 +#define HGPI_ASEQ_LEN 0x40
1710 +#define EGPI_PAUSE_TIME 0x000007D0
1711 +#define EGPI_PAUSE_ENABLE 0x40000000
1712 +#endif /* _GPI_H_ */
1714 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h
1717 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1718 + * Copyright 2017 NXP
1720 + * This program is free software; you can redistribute it and/or modify
1721 + * it under the terms of the GNU General Public License as published by
1722 + * the Free Software Foundation; either version 2 of the License, or
1723 + * (at your option) any later version.
1725 + * This program is distributed in the hope that it will be useful,
1726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1728 + * GNU General Public License for more details.
1730 + * You should have received a copy of the GNU General Public License
1731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1738 + * hif - PFE hif block control and status register.
1739 + * Mapped on CBUS and accessible from all PE's and ARM.
1741 +#define HIF_VERSION (HIF_BASE_ADDR + 0x00)
1742 +#define HIF_TX_CTRL (HIF_BASE_ADDR + 0x04)
1743 +#define HIF_TX_CURR_BD_ADDR (HIF_BASE_ADDR + 0x08)
1744 +#define HIF_TX_ALLOC (HIF_BASE_ADDR + 0x0c)
1745 +#define HIF_TX_BDP_ADDR (HIF_BASE_ADDR + 0x10)
1746 +#define HIF_TX_STATUS (HIF_BASE_ADDR + 0x14)
1747 +#define HIF_RX_CTRL (HIF_BASE_ADDR + 0x20)
1748 +#define HIF_RX_BDP_ADDR (HIF_BASE_ADDR + 0x24)
1749 +#define HIF_RX_STATUS (HIF_BASE_ADDR + 0x30)
1750 +#define HIF_INT_SRC (HIF_BASE_ADDR + 0x34)
1751 +#define HIF_INT_ENABLE (HIF_BASE_ADDR + 0x38)
1752 +#define HIF_POLL_CTRL (HIF_BASE_ADDR + 0x3c)
1753 +#define HIF_RX_CURR_BD_ADDR (HIF_BASE_ADDR + 0x40)
1754 +#define HIF_RX_ALLOC (HIF_BASE_ADDR + 0x44)
1755 +#define HIF_TX_DMA_STATUS (HIF_BASE_ADDR + 0x48)
1756 +#define HIF_RX_DMA_STATUS (HIF_BASE_ADDR + 0x4c)
1757 +#define HIF_INT_COAL (HIF_BASE_ADDR + 0x50)
1759 +/* HIF_INT_SRC/ HIF_INT_ENABLE control bits */
1760 +#define HIF_INT BIT(0)
1761 +#define HIF_RXBD_INT BIT(1)
1762 +#define HIF_RXPKT_INT BIT(2)
1763 +#define HIF_TXBD_INT BIT(3)
1764 +#define HIF_TXPKT_INT BIT(4)
1766 +/* HIF_TX_CTRL bits */
1767 +#define HIF_CTRL_DMA_EN BIT(0)
1768 +#define HIF_CTRL_BDP_POLL_CTRL_EN BIT(1)
1769 +#define HIF_CTRL_BDP_CH_START_WSTB BIT(2)
1771 +/* HIF_RX_STATUS bits */
1772 +#define BDP_CSR_RX_DMA_ACTV BIT(16)
1774 +/* HIF_INT_ENABLE bits */
1775 +#define HIF_INT_EN BIT(0)
1776 +#define HIF_RXBD_INT_EN BIT(1)
1777 +#define HIF_RXPKT_INT_EN BIT(2)
1778 +#define HIF_TXBD_INT_EN BIT(3)
1779 +#define HIF_TXPKT_INT_EN BIT(4)
1781 +/* HIF_POLL_CTRL bits*/
1782 +#define HIF_RX_POLL_CTRL_CYCLE 0x0400
1783 +#define HIF_TX_POLL_CTRL_CYCLE 0x0400
1785 +/* HIF_INT_COAL bits*/
1786 +#define HIF_INT_COAL_ENABLE BIT(31)
1788 +/* Buffer descriptor control bits */
1789 +#define BD_CTRL_BUFLEN_MASK 0x3fff
1790 +#define BD_BUF_LEN(x) ((x) & BD_CTRL_BUFLEN_MASK)
1791 +#define BD_CTRL_CBD_INT_EN BIT(16)
1792 +#define BD_CTRL_PKT_INT_EN BIT(17)
1793 +#define BD_CTRL_LIFM BIT(18)
1794 +#define BD_CTRL_LAST_BD BIT(19)
1795 +#define BD_CTRL_DIR BIT(20)
1796 +#define BD_CTRL_LMEM_CPY BIT(21) /* Valid only for HIF_NOCPY */
1797 +#define BD_CTRL_PKT_XFER BIT(24)
1798 +#define BD_CTRL_DESC_EN BIT(31)
1799 +#define BD_CTRL_PARSE_DISABLE BIT(25)
1800 +#define BD_CTRL_BRFETCH_DISABLE BIT(26)
1801 +#define BD_CTRL_RTFETCH_DISABLE BIT(27)
1803 +/* Buffer descriptor status bits*/
1804 +#define BD_STATUS_CONN_ID(x) ((x) & 0xffff)
1805 +#define BD_STATUS_DIR_PROC_ID BIT(16)
1806 +#define BD_STATUS_CONN_ID_EN BIT(17)
1807 +#define BD_STATUS_PE2PROC_ID(x) (((x) & 7) << 18)
1808 +#define BD_STATUS_LE_DATA BIT(21)
1809 +#define BD_STATUS_CHKSUM_EN BIT(22)
1811 +/* HIF Buffer descriptor status bits */
1812 +#define DIR_PROC_ID BIT(16)
1813 +#define PROC_ID(id) ((id) << 18)
1815 +#endif /* _HIF_H_ */
1817 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h
1820 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1821 + * Copyright 2017 NXP
1823 + * This program is free software; you can redistribute it and/or modify
1824 + * it under the terms of the GNU General Public License as published by
1825 + * the Free Software Foundation; either version 2 of the License, or
1826 + * (at your option) any later version.
1828 + * This program is distributed in the hope that it will be useful,
1829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1831 + * GNU General Public License for more details.
1833 + * You should have received a copy of the GNU General Public License
1834 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1837 +#ifndef _HIF_NOCPY_H_
1838 +#define _HIF_NOCPY_H_
1840 +#define HIF_NOCPY_VERSION (HIF_NOCPY_BASE_ADDR + 0x00)
1841 +#define HIF_NOCPY_TX_CTRL (HIF_NOCPY_BASE_ADDR + 0x04)
1842 +#define HIF_NOCPY_TX_CURR_BD_ADDR (HIF_NOCPY_BASE_ADDR + 0x08)
1843 +#define HIF_NOCPY_TX_ALLOC (HIF_NOCPY_BASE_ADDR + 0x0c)
1844 +#define HIF_NOCPY_TX_BDP_ADDR (HIF_NOCPY_BASE_ADDR + 0x10)
1845 +#define HIF_NOCPY_TX_STATUS (HIF_NOCPY_BASE_ADDR + 0x14)
1846 +#define HIF_NOCPY_RX_CTRL (HIF_NOCPY_BASE_ADDR + 0x20)
1847 +#define HIF_NOCPY_RX_BDP_ADDR (HIF_NOCPY_BASE_ADDR + 0x24)
1848 +#define HIF_NOCPY_RX_STATUS (HIF_NOCPY_BASE_ADDR + 0x30)
1849 +#define HIF_NOCPY_INT_SRC (HIF_NOCPY_BASE_ADDR + 0x34)
1850 +#define HIF_NOCPY_INT_ENABLE (HIF_NOCPY_BASE_ADDR + 0x38)
1851 +#define HIF_NOCPY_POLL_CTRL (HIF_NOCPY_BASE_ADDR + 0x3c)
1852 +#define HIF_NOCPY_RX_CURR_BD_ADDR (HIF_NOCPY_BASE_ADDR + 0x40)
1853 +#define HIF_NOCPY_RX_ALLOC (HIF_NOCPY_BASE_ADDR + 0x44)
1854 +#define HIF_NOCPY_TX_DMA_STATUS (HIF_NOCPY_BASE_ADDR + 0x48)
1855 +#define HIF_NOCPY_RX_DMA_STATUS (HIF_NOCPY_BASE_ADDR + 0x4c)
1856 +#define HIF_NOCPY_RX_INQ0_PKTPTR (HIF_NOCPY_BASE_ADDR + 0x50)
1857 +#define HIF_NOCPY_RX_INQ1_PKTPTR (HIF_NOCPY_BASE_ADDR + 0x54)
1858 +#define HIF_NOCPY_TX_PORT_NO (HIF_NOCPY_BASE_ADDR + 0x60)
1859 +#define HIF_NOCPY_LMEM_ALLOC_ADDR (HIF_NOCPY_BASE_ADDR + 0x64)
1860 +#define HIF_NOCPY_CLASS_ADDR (HIF_NOCPY_BASE_ADDR + 0x68)
1861 +#define HIF_NOCPY_TMU_PORT0_ADDR (HIF_NOCPY_BASE_ADDR + 0x70)
1862 +#define HIF_NOCPY_TMU_PORT1_ADDR (HIF_NOCPY_BASE_ADDR + 0x74)
1863 +#define HIF_NOCPY_TMU_PORT2_ADDR (HIF_NOCPY_BASE_ADDR + 0x7c)
1864 +#define HIF_NOCPY_TMU_PORT3_ADDR (HIF_NOCPY_BASE_ADDR + 0x80)
1865 +#define HIF_NOCPY_TMU_PORT4_ADDR (HIF_NOCPY_BASE_ADDR + 0x84)
1866 +#define HIF_NOCPY_INT_COAL (HIF_NOCPY_BASE_ADDR + 0x90)
1868 +#endif /* _HIF_NOCPY_H_ */
1870 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h
1873 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
1874 + * Copyright 2017 NXP
1876 + * This program is free software; you can redistribute it and/or modify
1877 + * it under the terms of the GNU General Public License as published by
1878 + * the Free Software Foundation; either version 2 of the License, or
1879 + * (at your option) any later version.
1881 + * This program is distributed in the hope that it will be useful,
1882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1884 + * GNU General Public License for more details.
1886 + * You should have received a copy of the GNU General Public License
1887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1890 +#ifndef _TMU_CSR_H_
1891 +#define _TMU_CSR_H_
1893 +#define TMU_VERSION (TMU_CSR_BASE_ADDR + 0x000)
1894 +#define TMU_INQ_WATERMARK (TMU_CSR_BASE_ADDR + 0x004)
1895 +#define TMU_PHY_INQ_PKTPTR (TMU_CSR_BASE_ADDR + 0x008)
1896 +#define TMU_PHY_INQ_PKTINFO (TMU_CSR_BASE_ADDR + 0x00c)
1897 +#define TMU_PHY_INQ_FIFO_CNT (TMU_CSR_BASE_ADDR + 0x010)
1898 +#define TMU_SYS_GENERIC_CONTROL (TMU_CSR_BASE_ADDR + 0x014)
1899 +#define TMU_SYS_GENERIC_STATUS (TMU_CSR_BASE_ADDR + 0x018)
1900 +#define TMU_SYS_GEN_CON0 (TMU_CSR_BASE_ADDR + 0x01c)
1901 +#define TMU_SYS_GEN_CON1 (TMU_CSR_BASE_ADDR + 0x020)
1902 +#define TMU_SYS_GEN_CON2 (TMU_CSR_BASE_ADDR + 0x024)
1903 +#define TMU_SYS_GEN_CON3 (TMU_CSR_BASE_ADDR + 0x028)
1904 +#define TMU_SYS_GEN_CON4 (TMU_CSR_BASE_ADDR + 0x02c)
1905 +#define TMU_TEQ_DISABLE_DROPCHK (TMU_CSR_BASE_ADDR + 0x030)
1906 +#define TMU_TEQ_CTRL (TMU_CSR_BASE_ADDR + 0x034)
1907 +#define TMU_TEQ_QCFG (TMU_CSR_BASE_ADDR + 0x038)
1908 +#define TMU_TEQ_DROP_STAT (TMU_CSR_BASE_ADDR + 0x03c)
1909 +#define TMU_TEQ_QAVG (TMU_CSR_BASE_ADDR + 0x040)
1910 +#define TMU_TEQ_WREG_PROB (TMU_CSR_BASE_ADDR + 0x044)
1911 +#define TMU_TEQ_TRANS_STAT (TMU_CSR_BASE_ADDR + 0x048)
1912 +#define TMU_TEQ_HW_PROB_CFG0 (TMU_CSR_BASE_ADDR + 0x04c)
1913 +#define TMU_TEQ_HW_PROB_CFG1 (TMU_CSR_BASE_ADDR + 0x050)
1914 +#define TMU_TEQ_HW_PROB_CFG2 (TMU_CSR_BASE_ADDR + 0x054)
1915 +#define TMU_TEQ_HW_PROB_CFG3 (TMU_CSR_BASE_ADDR + 0x058)
1916 +#define TMU_TEQ_HW_PROB_CFG4 (TMU_CSR_BASE_ADDR + 0x05c)
1917 +#define TMU_TEQ_HW_PROB_CFG5 (TMU_CSR_BASE_ADDR + 0x060)
1918 +#define TMU_TEQ_HW_PROB_CFG6 (TMU_CSR_BASE_ADDR + 0x064)
1919 +#define TMU_TEQ_HW_PROB_CFG7 (TMU_CSR_BASE_ADDR + 0x068)
1920 +#define TMU_TEQ_HW_PROB_CFG8 (TMU_CSR_BASE_ADDR + 0x06c)
1921 +#define TMU_TEQ_HW_PROB_CFG9 (TMU_CSR_BASE_ADDR + 0x070)
1922 +#define TMU_TEQ_HW_PROB_CFG10 (TMU_CSR_BASE_ADDR + 0x074)
1923 +#define TMU_TEQ_HW_PROB_CFG11 (TMU_CSR_BASE_ADDR + 0x078)
1924 +#define TMU_TEQ_HW_PROB_CFG12 (TMU_CSR_BASE_ADDR + 0x07c)
1925 +#define TMU_TEQ_HW_PROB_CFG13 (TMU_CSR_BASE_ADDR + 0x080)
1926 +#define TMU_TEQ_HW_PROB_CFG14 (TMU_CSR_BASE_ADDR + 0x084)
1927 +#define TMU_TEQ_HW_PROB_CFG15 (TMU_CSR_BASE_ADDR + 0x088)
1928 +#define TMU_TEQ_HW_PROB_CFG16 (TMU_CSR_BASE_ADDR + 0x08c)
1929 +#define TMU_TEQ_HW_PROB_CFG17 (TMU_CSR_BASE_ADDR + 0x090)
1930 +#define TMU_TEQ_HW_PROB_CFG18 (TMU_CSR_BASE_ADDR + 0x094)
1931 +#define TMU_TEQ_HW_PROB_CFG19 (TMU_CSR_BASE_ADDR + 0x098)
1932 +#define TMU_TEQ_HW_PROB_CFG20 (TMU_CSR_BASE_ADDR + 0x09c)
1933 +#define TMU_TEQ_HW_PROB_CFG21 (TMU_CSR_BASE_ADDR + 0x0a0)
1934 +#define TMU_TEQ_HW_PROB_CFG22 (TMU_CSR_BASE_ADDR + 0x0a4)
1935 +#define TMU_TEQ_HW_PROB_CFG23 (TMU_CSR_BASE_ADDR + 0x0a8)
1936 +#define TMU_TEQ_HW_PROB_CFG24 (TMU_CSR_BASE_ADDR + 0x0ac)
1937 +#define TMU_TEQ_HW_PROB_CFG25 (TMU_CSR_BASE_ADDR + 0x0b0)
1938 +#define TMU_TDQ_IIFG_CFG (TMU_CSR_BASE_ADDR + 0x0b4)
1939 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
1940 + * This is a global Enable for all schedulers in PHY0
1942 +#define TMU_TDQ0_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x0b8)
1944 +#define TMU_LLM_CTRL (TMU_CSR_BASE_ADDR + 0x0bc)
1945 +#define TMU_LLM_BASE_ADDR (TMU_CSR_BASE_ADDR + 0x0c0)
1946 +#define TMU_LLM_QUE_LEN (TMU_CSR_BASE_ADDR + 0x0c4)
1947 +#define TMU_LLM_QUE_HEADPTR (TMU_CSR_BASE_ADDR + 0x0c8)
1948 +#define TMU_LLM_QUE_TAILPTR (TMU_CSR_BASE_ADDR + 0x0cc)
1949 +#define TMU_LLM_QUE_DROPCNT (TMU_CSR_BASE_ADDR + 0x0d0)
1950 +#define TMU_INT_EN (TMU_CSR_BASE_ADDR + 0x0d4)
1951 +#define TMU_INT_SRC (TMU_CSR_BASE_ADDR + 0x0d8)
1952 +#define TMU_INQ_STAT (TMU_CSR_BASE_ADDR + 0x0dc)
1953 +#define TMU_CTRL (TMU_CSR_BASE_ADDR + 0x0e0)
1955 +/* [31] Mem Access Command. 0 = Internal Memory Read, 1 = Internal memory
1956 + * Write [27:24] Byte Enables of the Internal memory access [23:0] Address of
1957 + * the internal memory. This address is used to access both the PM and DM of
1960 +#define TMU_MEM_ACCESS_ADDR (TMU_CSR_BASE_ADDR + 0x0e4)
1962 +/* Internal Memory Access Write Data */
1963 +#define TMU_MEM_ACCESS_WDATA (TMU_CSR_BASE_ADDR + 0x0e8)
1964 +/* Internal Memory Access Read Data. The commands are blocked
1965 + * at the mem_access only
1967 +#define TMU_MEM_ACCESS_RDATA (TMU_CSR_BASE_ADDR + 0x0ec)
1969 +/* [31:0] PHY0 in queue address (must be initialized with one of the
1970 + * xxx_INQ_PKTPTR cbus addresses)
1972 +#define TMU_PHY0_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f0)
1973 +/* [31:0] PHY1 in queue address (must be initialized with one of the
1974 + * xxx_INQ_PKTPTR cbus addresses)
1976 +#define TMU_PHY1_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f4)
1977 +/* [31:0] PHY2 in queue address (must be initialized with one of the
1978 + * xxx_INQ_PKTPTR cbus addresses)
1980 +#define TMU_PHY2_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f8)
1981 +/* [31:0] PHY3 in queue address (must be initialized with one of the
1982 + * xxx_INQ_PKTPTR cbus addresses)
1984 +#define TMU_PHY3_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0fc)
1985 +#define TMU_BMU_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x100)
1986 +#define TMU_TX_CTRL (TMU_CSR_BASE_ADDR + 0x104)
1988 +#define TMU_BUS_ACCESS_WDATA (TMU_CSR_BASE_ADDR + 0x108)
1989 +#define TMU_BUS_ACCESS (TMU_CSR_BASE_ADDR + 0x10c)
1990 +#define TMU_BUS_ACCESS_RDATA (TMU_CSR_BASE_ADDR + 0x110)
1992 +#define TMU_PE_SYS_CLK_RATIO (TMU_CSR_BASE_ADDR + 0x114)
1993 +#define TMU_PE_STATUS (TMU_CSR_BASE_ADDR + 0x118)
1994 +#define TMU_TEQ_MAX_THRESHOLD (TMU_CSR_BASE_ADDR + 0x11c)
1995 +/* [31:0] PHY4 in queue address (must be initialized with one of the
1996 + * xxx_INQ_PKTPTR cbus addresses)
1998 +#define TMU_PHY4_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x134)
1999 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
2000 + * This is a global Enable for all schedulers in PHY1
2002 +#define TMU_TDQ1_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x138)
2003 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
2004 + * This is a global Enable for all schedulers in PHY2
2006 +#define TMU_TDQ2_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x13c)
2007 +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
2008 + * This is a global Enable for all schedulers in PHY3
2010 +#define TMU_TDQ3_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x140)
2011 +#define TMU_BMU_BUF_SIZE (TMU_CSR_BASE_ADDR + 0x144)
2012 +/* [31:0] PHY5 in queue address (must be initialized with one of the
2013 + * xxx_INQ_PKTPTR cbus addresses)
2015 +#define TMU_PHY5_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x148)
2017 +#define SW_RESET BIT(0) /* Global software reset */
2018 +#define INQ_RESET BIT(2)
2019 +#define TEQ_RESET BIT(3)
2020 +#define TDQ_RESET BIT(4)
2021 +#define PE_RESET BIT(5)
2022 +#define MEM_INIT BIT(6)
2023 +#define MEM_INIT_DONE BIT(7)
2024 +#define LLM_INIT BIT(8)
2025 +#define LLM_INIT_DONE BIT(9)
2026 +#define ECC_MEM_INIT_DONE BIT(10)
2029 + u32 pe_sys_clk_ratio;
2030 + unsigned long llm_base_addr;
2031 + u32 llm_queue_len;
2034 +/* Not HW related for pfe_ctrl / pfe common defines */
2035 +#define DEFAULT_MAX_QDEPTH 80
2036 +#define DEFAULT_Q0_QDEPTH 511 /*We keep one large queue for host tx qos */
2037 +#define DEFAULT_TMU3_QDEPTH 127
2039 +#endif /* _TMU_CSR_H_ */
2041 +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h
2044 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2045 + * Copyright 2017 NXP
2047 + * This program is free software; you can redistribute it and/or modify
2048 + * it under the terms of the GNU General Public License as published by
2049 + * the Free Software Foundation; either version 2 of the License, or
2050 + * (at your option) any later version.
2052 + * This program is distributed in the hope that it will be useful,
2053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2055 + * GNU General Public License for more details.
2057 + * You should have received a copy of the GNU General Public License
2058 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2061 +#ifndef _UTIL_CSR_H_
2062 +#define _UTIL_CSR_H_
2064 +#define UTIL_VERSION (UTIL_CSR_BASE_ADDR + 0x000)
2065 +#define UTIL_TX_CTRL (UTIL_CSR_BASE_ADDR + 0x004)
2066 +#define UTIL_INQ_PKTPTR (UTIL_CSR_BASE_ADDR + 0x010)
2068 +#define UTIL_HDR_SIZE (UTIL_CSR_BASE_ADDR + 0x014)
2070 +#define UTIL_PE0_QB_DM_ADDR0 (UTIL_CSR_BASE_ADDR + 0x020)
2071 +#define UTIL_PE0_QB_DM_ADDR1 (UTIL_CSR_BASE_ADDR + 0x024)
2072 +#define UTIL_PE0_RO_DM_ADDR0 (UTIL_CSR_BASE_ADDR + 0x060)
2073 +#define UTIL_PE0_RO_DM_ADDR1 (UTIL_CSR_BASE_ADDR + 0x064)
2075 +#define UTIL_MEM_ACCESS_ADDR (UTIL_CSR_BASE_ADDR + 0x100)
2076 +#define UTIL_MEM_ACCESS_WDATA (UTIL_CSR_BASE_ADDR + 0x104)
2077 +#define UTIL_MEM_ACCESS_RDATA (UTIL_CSR_BASE_ADDR + 0x108)
2079 +#define UTIL_TM_INQ_ADDR (UTIL_CSR_BASE_ADDR + 0x114)
2080 +#define UTIL_PE_STATUS (UTIL_CSR_BASE_ADDR + 0x118)
2082 +#define UTIL_PE_SYS_CLK_RATIO (UTIL_CSR_BASE_ADDR + 0x200)
2083 +#define UTIL_AFULL_THRES (UTIL_CSR_BASE_ADDR + 0x204)
2084 +#define UTIL_GAP_BETWEEN_READS (UTIL_CSR_BASE_ADDR + 0x208)
2085 +#define UTIL_MAX_BUF_CNT (UTIL_CSR_BASE_ADDR + 0x20c)
2086 +#define UTIL_TSQ_FIFO_THRES (UTIL_CSR_BASE_ADDR + 0x210)
2087 +#define UTIL_TSQ_MAX_CNT (UTIL_CSR_BASE_ADDR + 0x214)
2088 +#define UTIL_IRAM_DATA_0 (UTIL_CSR_BASE_ADDR + 0x218)
2089 +#define UTIL_IRAM_DATA_1 (UTIL_CSR_BASE_ADDR + 0x21c)
2090 +#define UTIL_IRAM_DATA_2 (UTIL_CSR_BASE_ADDR + 0x220)
2091 +#define UTIL_IRAM_DATA_3 (UTIL_CSR_BASE_ADDR + 0x224)
2093 +#define UTIL_BUS_ACCESS_ADDR (UTIL_CSR_BASE_ADDR + 0x228)
2094 +#define UTIL_BUS_ACCESS_WDATA (UTIL_CSR_BASE_ADDR + 0x22c)
2095 +#define UTIL_BUS_ACCESS_RDATA (UTIL_CSR_BASE_ADDR + 0x230)
2097 +#define UTIL_INQ_AFULL_THRES (UTIL_CSR_BASE_ADDR + 0x234)
2100 + u32 pe_sys_clk_ratio;
2103 +#endif /* _UTIL_CSR_H_ */
2105 +++ b/drivers/staging/fsl_ppfe/include/pfe/pfe.h
2108 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2109 + * Copyright 2017 NXP
2111 + * This program is free software; you can redistribute it and/or modify
2112 + * it under the terms of the GNU General Public License as published by
2113 + * the Free Software Foundation; either version 2 of the License, or
2114 + * (at your option) any later version.
2116 + * This program is distributed in the hope that it will be useful,
2117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2119 + * GNU General Public License for more details.
2121 + * You should have received a copy of the GNU General Public License
2122 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2130 +#define CLASS_DMEM_BASE_ADDR(i) (0x00000000 | ((i) << 20))
2132 + * Only valid for mem access register interface
2134 +#define CLASS_IMEM_BASE_ADDR(i) (0x00000000 | ((i) << 20))
2135 +#define CLASS_DMEM_SIZE 0x00002000
2136 +#define CLASS_IMEM_SIZE 0x00008000
2138 +#define TMU_DMEM_BASE_ADDR(i) (0x00000000 + ((i) << 20))
2140 + * Only valid for mem access register interface
2142 +#define TMU_IMEM_BASE_ADDR(i) (0x00000000 + ((i) << 20))
2143 +#define TMU_DMEM_SIZE 0x00000800
2144 +#define TMU_IMEM_SIZE 0x00002000
2146 +#define UTIL_DMEM_BASE_ADDR 0x00000000
2147 +#define UTIL_DMEM_SIZE 0x00002000
2149 +#define PE_LMEM_BASE_ADDR 0xc3010000
2150 +#define PE_LMEM_SIZE 0x8000
2151 +#define PE_LMEM_END (PE_LMEM_BASE_ADDR + PE_LMEM_SIZE)
2153 +#define DMEM_BASE_ADDR 0x00000000
2154 +#define DMEM_SIZE 0x2000 /* TMU has less... */
2155 +#define DMEM_END (DMEM_BASE_ADDR + DMEM_SIZE)
2157 +#define PMEM_BASE_ADDR 0x00010000
2158 +#define PMEM_SIZE 0x8000 /* TMU has less... */
2159 +#define PMEM_END (PMEM_BASE_ADDR + PMEM_SIZE)
2161 +/* These check memory ranges from PE point of view/memory map */
2162 +#define IS_DMEM(addr, len) \
2163 + ({ typeof(addr) addr_ = (addr); \
2164 + ((unsigned long)(addr_) >= DMEM_BASE_ADDR) && \
2165 + (((unsigned long)(addr_) + (len)) <= DMEM_END); })
2167 +#define IS_PMEM(addr, len) \
2168 + ({ typeof(addr) addr_ = (addr); \
2169 + ((unsigned long)(addr_) >= PMEM_BASE_ADDR) && \
2170 + (((unsigned long)(addr_) + (len)) <= PMEM_END); })
2172 +#define IS_PE_LMEM(addr, len) \
2173 + ({ typeof(addr) addr_ = (addr); \
2174 + ((unsigned long)(addr_) >= \
2175 + PE_LMEM_BASE_ADDR) && \
2176 + (((unsigned long)(addr_) + \
2177 + (len)) <= PE_LMEM_END); })
2179 +#define IS_PFE_LMEM(addr, len) \
2180 + ({ typeof(addr) addr_ = (addr); \
2181 + ((unsigned long)(addr_) >= \
2182 + CBUS_VIRT_TO_PFE(LMEM_BASE_ADDR)) && \
2183 + (((unsigned long)(addr_) + (len)) <= \
2184 + CBUS_VIRT_TO_PFE(LMEM_END)); })
2186 +#define __IS_PHYS_DDR(addr, len) \
2187 + ({ typeof(addr) addr_ = (addr); \
2188 + ((unsigned long)(addr_) >= \
2189 + DDR_PHYS_BASE_ADDR) && \
2190 + (((unsigned long)(addr_) + (len)) <= \
2193 +#define IS_PHYS_DDR(addr, len) __IS_PHYS_DDR(DDR_PFE_TO_PHYS(addr), len)
2196 + * If using a run-time virtual address for the cbus base address use this code
2198 +extern void *cbus_base_addr;
2199 +extern void *ddr_base_addr;
2200 +extern unsigned long ddr_phys_base_addr;
2201 +extern unsigned int ddr_size;
2203 +#define CBUS_BASE_ADDR cbus_base_addr
2204 +#define DDR_PHYS_BASE_ADDR ddr_phys_base_addr
2205 +#define DDR_BASE_ADDR ddr_base_addr
2206 +#define DDR_SIZE ddr_size
2208 +#define DDR_PHYS_END (DDR_PHYS_BASE_ADDR + DDR_SIZE)
2210 +#define LS1012A_PFE_RESET_WA /*
2211 + * PFE doesn't have global reset and re-init
2212 + * should takecare few things to make PFE
2213 + * functional after reset
2215 +#define PFE_CBUS_PHYS_BASE_ADDR 0xc0000000 /* CBUS physical base address
2216 + * as seen by PE's.
2218 +/* CBUS physical base address as seen by PE's. */
2219 +#define PFE_CBUS_PHYS_BASE_ADDR_FROM_PFE 0xc0000000
2221 +#define DDR_PHYS_TO_PFE(p) (((unsigned long int)(p)) & 0x7FFFFFFF)
2222 +#define DDR_PFE_TO_PHYS(p) (((unsigned long int)(p)) | 0x80000000)
2223 +#define CBUS_PHYS_TO_PFE(p) (((p) - PFE_CBUS_PHYS_BASE_ADDR) + \
2224 + PFE_CBUS_PHYS_BASE_ADDR_FROM_PFE)
2225 +/* Translates to PFE address map */
2227 +#define DDR_PHYS_TO_VIRT(p) (((p) - DDR_PHYS_BASE_ADDR) + DDR_BASE_ADDR)
2228 +#define DDR_VIRT_TO_PHYS(v) (((v) - DDR_BASE_ADDR) + DDR_PHYS_BASE_ADDR)
2229 +#define DDR_VIRT_TO_PFE(p) (DDR_PHYS_TO_PFE(DDR_VIRT_TO_PHYS(p)))
2231 +#define CBUS_VIRT_TO_PFE(v) (((v) - CBUS_BASE_ADDR) + \
2232 + PFE_CBUS_PHYS_BASE_ADDR)
2233 +#define CBUS_PFE_TO_VIRT(p) (((unsigned long int)(p) - \
2234 + PFE_CBUS_PHYS_BASE_ADDR) + CBUS_BASE_ADDR)
2236 +/* The below part of the code is used in QOS control driver from host */
2237 +#define TMU_APB_BASE_ADDR 0xc1000000 /* TMU base address seen by
2252 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2258 +#define CLASS_MASK (BIT(CLASS0_ID) | BIT(CLASS1_ID) |\
2259 + BIT(CLASS2_ID) | BIT(CLASS3_ID) |\
2260 + BIT(CLASS4_ID) | BIT(CLASS5_ID))
2261 +#define CLASS_MAX_ID CLASS5_ID
2263 +#define TMU_MASK (BIT(TMU0_ID) | BIT(TMU1_ID) |\
2266 +#define TMU_MAX_ID TMU3_ID
2268 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2269 +#define UTIL_MASK BIT(UTIL_ID)
2274 + u32 activity_counter;
2281 +#if defined(CFG_PE_DEBUG)
2282 + u32 debug_indicator;
2287 +struct pe_sync_mailbox {
2292 +/* Drop counter definitions */
2294 +#define CLASS_NUM_DROP_COUNTERS 13
2295 +#define UTIL_NUM_DROP_COUNTERS 8
2298 + * Structure containing PE's specific information. It is used to create
2299 + * generic C functions common to all PE's.
2300 + * Before using the library functions this structure needs to be initialized
2301 + * with the different registers virtual addresses
2302 + * (according to the ARM MMU mmaping). The default initialization supports a
2303 + * virtual == physical mapping.
2306 + u32 dmem_base_addr; /* PE's dmem base address */
2307 + u32 pmem_base_addr; /* PE's pmem base address */
2308 + u32 pmem_size; /* PE's pmem size */
2310 + void *mem_access_wdata; /* PE's _MEM_ACCESS_WDATA register
2313 + void *mem_access_addr; /* PE's _MEM_ACCESS_ADDR register
2316 + void *mem_access_rdata; /* PE's _MEM_ACCESS_RDATA register
2321 +void pe_lmem_read(u32 *dst, u32 len, u32 offset);
2322 +void pe_lmem_write(u32 *src, u32 len, u32 offset);
2324 +void pe_dmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len);
2325 +void pe_pmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len);
2327 +u32 pe_pmem_read(int id, u32 addr, u8 size);
2329 +void pe_dmem_write(int id, u32 val, u32 addr, u8 size);
2330 +u32 pe_dmem_read(int id, u32 addr, u8 size);
2331 +void class_pe_lmem_memcpy_to32(u32 dst, const void *src, unsigned int len);
2332 +void class_pe_lmem_memset(u32 dst, int val, unsigned int len);
2333 +void class_bus_write(u32 val, u32 addr, u8 size);
2334 +u32 class_bus_read(u32 addr, u8 size);
2336 +#define class_bus_readl(addr) class_bus_read(addr, 4)
2337 +#define class_bus_readw(addr) class_bus_read(addr, 2)
2338 +#define class_bus_readb(addr) class_bus_read(addr, 1)
2340 +#define class_bus_writel(val, addr) class_bus_write(val, addr, 4)
2341 +#define class_bus_writew(val, addr) class_bus_write(val, addr, 2)
2342 +#define class_bus_writeb(val, addr) class_bus_write(val, addr, 1)
2344 +#define pe_dmem_readl(id, addr) pe_dmem_read(id, addr, 4)
2345 +#define pe_dmem_readw(id, addr) pe_dmem_read(id, addr, 2)
2346 +#define pe_dmem_readb(id, addr) pe_dmem_read(id, addr, 1)
2348 +#define pe_dmem_writel(id, val, addr) pe_dmem_write(id, val, addr, 4)
2349 +#define pe_dmem_writew(id, val, addr) pe_dmem_write(id, val, addr, 2)
2350 +#define pe_dmem_writeb(id, val, addr) pe_dmem_write(id, val, addr, 1)
2352 +/*int pe_load_elf_section(int id, const void *data, elf32_shdr *shdr); */
2353 +int pe_load_elf_section(int id, const void *data, struct elf32_shdr *shdr,
2354 + struct device *dev);
2356 +void pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
2357 + unsigned int ddr_size);
2358 +void bmu_init(void *base, struct BMU_CFG *cfg);
2359 +void bmu_reset(void *base);
2360 +void bmu_enable(void *base);
2361 +void bmu_disable(void *base);
2362 +void bmu_set_config(void *base, struct BMU_CFG *cfg);
2365 + * An enumerated type for loopback values. This can be one of three values, no
2366 + * loopback -normal operation, local loopback with internal loopback module of
2367 + * MAC or PHY loopback which is through the external PHY.
2369 +#ifndef __MAC_LOOP_ENUM__
2370 +#define __MAC_LOOP_ENUM__
2371 +enum mac_loop {LB_NONE, LB_EXT, LB_LOCAL};
2374 +void gemac_init(void *base, void *config);
2375 +void gemac_disable_rx_checksum_offload(void *base);
2376 +void gemac_enable_rx_checksum_offload(void *base);
2377 +void gemac_set_speed(void *base, enum mac_speed gem_speed);
2378 +void gemac_set_duplex(void *base, int duplex);
2379 +void gemac_set_mode(void *base, int mode);
2380 +void gemac_enable(void *base);
2381 +void gemac_tx_disable(void *base);
2382 +void gemac_tx_enable(void *base);
2383 +void gemac_disable(void *base);
2384 +void gemac_reset(void *base);
2385 +void gemac_set_address(void *base, struct spec_addr *addr);
2386 +struct spec_addr gemac_get_address(void *base);
2387 +void gemac_set_loop(void *base, enum mac_loop gem_loop);
2388 +void gemac_set_laddr1(void *base, struct pfe_mac_addr *address);
2389 +void gemac_set_laddr2(void *base, struct pfe_mac_addr *address);
2390 +void gemac_set_laddr3(void *base, struct pfe_mac_addr *address);
2391 +void gemac_set_laddr4(void *base, struct pfe_mac_addr *address);
2392 +void gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
2393 + unsigned int entry_index);
2394 +void gemac_clear_laddr1(void *base);
2395 +void gemac_clear_laddr2(void *base);
2396 +void gemac_clear_laddr3(void *base);
2397 +void gemac_clear_laddr4(void *base);
2398 +void gemac_clear_laddrN(void *base, unsigned int entry_index);
2399 +struct pfe_mac_addr gemac_get_hash(void *base);
2400 +void gemac_set_hash(void *base, struct pfe_mac_addr *hash);
2401 +struct pfe_mac_addr gem_get_laddr1(void *base);
2402 +struct pfe_mac_addr gem_get_laddr2(void *base);
2403 +struct pfe_mac_addr gem_get_laddr3(void *base);
2404 +struct pfe_mac_addr gem_get_laddr4(void *base);
2405 +struct pfe_mac_addr gem_get_laddrN(void *base, unsigned int entry_index);
2406 +void gemac_set_config(void *base, struct gemac_cfg *cfg);
2407 +void gemac_allow_broadcast(void *base);
2408 +void gemac_no_broadcast(void *base);
2409 +void gemac_enable_1536_rx(void *base);
2410 +void gemac_disable_1536_rx(void *base);
2411 +void gemac_set_rx_max_fl(void *base, int mtu);
2412 +void gemac_enable_rx_jmb(void *base);
2413 +void gemac_disable_rx_jmb(void *base);
2414 +void gemac_enable_stacked_vlan(void *base);
2415 +void gemac_disable_stacked_vlan(void *base);
2416 +void gemac_enable_pause_rx(void *base);
2417 +void gemac_disable_pause_rx(void *base);
2418 +void gemac_enable_copy_all(void *base);
2419 +void gemac_disable_copy_all(void *base);
2420 +void gemac_set_bus_width(void *base, int width);
2421 +void gemac_set_wol(void *base, u32 wol_conf);
2423 +void gpi_init(void *base, struct gpi_cfg *cfg);
2424 +void gpi_reset(void *base);
2425 +void gpi_enable(void *base);
2426 +void gpi_disable(void *base);
2427 +void gpi_set_config(void *base, struct gpi_cfg *cfg);
2429 +void class_init(struct class_cfg *cfg);
2430 +void class_reset(void);
2431 +void class_enable(void);
2432 +void class_disable(void);
2433 +void class_set_config(struct class_cfg *cfg);
2435 +void tmu_reset(void);
2436 +void tmu_init(struct tmu_cfg *cfg);
2437 +void tmu_enable(u32 pe_mask);
2438 +void tmu_disable(u32 pe_mask);
2439 +u32 tmu_qstatus(u32 if_id);
2440 +u32 tmu_pkts_processed(u32 if_id);
2442 +void util_init(struct util_cfg *cfg);
2443 +void util_reset(void);
2444 +void util_enable(void);
2445 +void util_disable(void);
2447 +void hif_init(void);
2448 +void hif_tx_enable(void);
2449 +void hif_tx_disable(void);
2450 +void hif_rx_enable(void);
2451 +void hif_rx_disable(void);
2453 +/* Get Chip Revision level
2456 +static inline unsigned int CHIP_REVISION(void)
2458 + /*For LS1012A return always 1 */
2462 +/* Start HIF rx DMA
2465 +static inline void hif_rx_dma_start(void)
2467 + writel(HIF_CTRL_DMA_EN | HIF_CTRL_BDP_CH_START_WSTB, HIF_RX_CTRL);
2470 +/* Start HIF tx DMA
2473 +static inline void hif_tx_dma_start(void)
2475 + writel(HIF_CTRL_DMA_EN | HIF_CTRL_BDP_CH_START_WSTB, HIF_TX_CTRL);
2478 +#endif /* _PFE_H_ */
2480 +++ b/drivers/staging/fsl_ppfe/pfe_cdev.c
2482 +// SPDX-License-Identifier: GPL-2.0+
2484 + * Copyright 2018 NXP
2488 + * Dummy device representing the PFE US in userspace.
2489 + * - used for interacting with the kernel layer for link status
2492 +#include <linux/eventfd.h>
2493 +#include <linux/irqreturn.h>
2494 +#include <linux/io.h>
2495 +#include <asm/irq.h>
2497 +#include "pfe_cdev.h"
2498 +#include "pfe_mod.h"
2500 +static int pfe_majno;
2501 +static struct class *pfe_char_class;
2502 +static struct device *pfe_char_dev;
2503 +struct eventfd_ctx *g_trigger;
2505 +struct pfe_shared_info link_states[PFE_CDEV_ETH_COUNT];
2507 +static int pfe_cdev_open(struct inode *inp, struct file *fp)
2509 + pr_debug("PFE CDEV device opened.\n");
2513 +static ssize_t pfe_cdev_read(struct file *fp, char *buf,
2514 + size_t len, loff_t *off)
2518 + pr_info("PFE CDEV attempt copying (%lu) size of user.\n",
2519 + sizeof(link_states));
2521 + pr_debug("Dump link_state on screen before copy_to_user\n");
2522 + for (; ret < PFE_CDEV_ETH_COUNT; ret++) {
2523 + pr_debug("%u %u", link_states[ret].phy_id,
2524 + link_states[ret].state);
2528 + /* Copy to user the value in buffer sized len */
2529 + ret = copy_to_user(buf, &link_states, sizeof(link_states));
2531 + pr_err("Failed to send (%d)bytes of (%lu) requested.\n",
2536 + /* offset set back to 0 as there is contextual reading offset */
2538 + pr_debug("Read of (%lu) bytes performed.\n", sizeof(link_states));
2540 + return sizeof(link_states);
2544 + * This function is for getting some commands from user through non-IOCTL
2545 + * channel. It can used to configure the device.
2546 + * TODO: To be filled in future, if require duplex communication with user
2549 +static ssize_t pfe_cdev_write(struct file *fp, const char *buf,
2550 + size_t len, loff_t *off)
2552 + pr_info("PFE CDEV Write operation not supported!\n");
2557 +static int pfe_cdev_release(struct inode *inp, struct file *fp)
2560 + free_irq(pfe->hif_irq, g_trigger);
2561 + eventfd_ctx_put(g_trigger);
2565 + pr_info("PFE_CDEV: Device successfully closed\n");
2571 + * This ISR routine processes Rx/Tx done interrupts from the HIF hardware block
2573 +static irqreturn_t hif_us_isr(int irq, void *arg)
2575 + struct eventfd_ctx *trigger = (struct eventfd_ctx *)arg;
2577 + int int_enable_mask;
2579 + /*Read hif interrupt source register */
2580 + int_status = readl_relaxed(HIF_INT_SRC);
2581 + int_enable_mask = readl_relaxed(HIF_INT_ENABLE);
2583 + if ((int_status & HIF_INT) == 0)
2586 + if (int_status & HIF_RXPKT_INT) {
2587 + int_enable_mask &= ~(HIF_RXPKT_INT);
2588 + /* Disable interrupts, they will be enabled after
2589 + * they are serviced
2591 + writel_relaxed(int_enable_mask, HIF_INT_ENABLE);
2593 + eventfd_signal(trigger, 1);
2596 + return IRQ_HANDLED;
2599 +#define PFE_INTR_COAL_USECS 100
2600 +static long pfe_cdev_ioctl(struct file *fp, unsigned int cmd,
2601 + unsigned long arg)
2603 + int ret = -EFAULT;
2604 + int __user *argp = (int __user *)arg;
2606 + pr_debug("PFE CDEV IOCTL Called with cmd=(%u)\n", cmd);
2609 + case PFE_CDEV_ETH0_STATE_GET:
2610 + /* Return an unsigned int (link state) for ETH0 */
2611 + *argp = link_states[0].state;
2612 + pr_debug("Returning state=%d for ETH0\n", *argp);
2615 + case PFE_CDEV_ETH1_STATE_GET:
2616 + /* Return an unsigned int (link state) for ETH0 */
2617 + *argp = link_states[1].state;
2618 + pr_debug("Returning state=%d for ETH1\n", *argp);
2621 + case PFE_CDEV_HIF_INTR_EN:
2622 + /* Return success/failure */
2623 + g_trigger = eventfd_ctx_fdget(*argp);
2624 + if (IS_ERR(g_trigger))
2625 + return PTR_ERR(g_trigger);
2626 + ret = request_irq(pfe->hif_irq, hif_us_isr, 0, "pfe_hif",
2629 + pr_err("%s: failed to get the hif IRQ = %d\n",
2630 + __func__, pfe->hif_irq);
2631 + eventfd_ctx_put(g_trigger);
2634 + writel((PFE_INTR_COAL_USECS * (pfe->ctrl.sys_clk / 1000)) |
2635 + HIF_INT_COAL_ENABLE, HIF_INT_COAL);
2637 + pr_debug("request_irq for hif interrupt: %d\n", pfe->hif_irq);
2641 + pr_info("Unsupport cmd (%d) for PFE CDEV.\n", cmd);
2648 +static unsigned int pfe_cdev_poll(struct file *fp,
2649 + struct poll_table_struct *wait)
2651 + pr_info("PFE CDEV poll method not supported\n");
2655 +static const struct file_operations pfe_cdev_fops = {
2656 + .open = pfe_cdev_open,
2657 + .read = pfe_cdev_read,
2658 + .write = pfe_cdev_write,
2659 + .release = pfe_cdev_release,
2660 + .unlocked_ioctl = pfe_cdev_ioctl,
2661 + .poll = pfe_cdev_poll,
2664 +int pfe_cdev_init(void)
2668 + pr_debug("PFE CDEV initialization begin\n");
2670 + /* Register the major number for the device */
2671 + pfe_majno = register_chrdev(0, PFE_CDEV_NAME, &pfe_cdev_fops);
2672 + if (pfe_majno < 0) {
2673 + pr_err("Unable to register PFE CDEV. PFE CDEV not available\n");
2678 + pr_debug("PFE CDEV assigned major number: %d\n", pfe_majno);
2680 + /* Register the class for the device */
2681 + pfe_char_class = class_create(THIS_MODULE, PFE_CLASS_NAME);
2682 + if (IS_ERR(pfe_char_class)) {
2684 + "Failed to init class for PFE CDEV. PFE CDEV not available.\n");
2685 + ret = PTR_ERR(pfe_char_class);
2689 + pr_debug("PFE CDEV Class created successfully.\n");
2691 + /* Create the device without any parent and without any callback data */
2692 + pfe_char_dev = device_create(pfe_char_class, NULL,
2693 + MKDEV(pfe_majno, 0), NULL,
2695 + if (IS_ERR(pfe_char_dev)) {
2696 + pr_err("Unable to PFE CDEV device. PFE CDEV not available.\n");
2697 + ret = PTR_ERR(pfe_char_dev);
2701 + /* Information structure being shared with the userspace */
2702 + memset(link_states, 0, sizeof(struct pfe_shared_info) *
2703 + PFE_CDEV_ETH_COUNT);
2705 + pr_info("PFE CDEV created: %s\n", PFE_CDEV_NAME);
2711 + if (!IS_ERR(pfe_char_class))
2712 + class_destroy(pfe_char_class);
2714 + if (pfe_majno > 0)
2715 + unregister_chrdev(pfe_majno, PFE_CDEV_NAME);
2720 +void pfe_cdev_exit(void)
2722 + if (!IS_ERR(pfe_char_dev))
2723 + device_destroy(pfe_char_class, MKDEV(pfe_majno, 0));
2725 + if (!IS_ERR(pfe_char_class)) {
2726 + class_unregister(pfe_char_class);
2727 + class_destroy(pfe_char_class);
2730 + if (pfe_majno > 0)
2731 + unregister_chrdev(pfe_majno, PFE_CDEV_NAME);
2733 + /* reset the variables */
2735 + pfe_char_class = NULL;
2736 + pfe_char_dev = NULL;
2738 + pr_info("PFE CDEV Removed.\n");
2741 +++ b/drivers/staging/fsl_ppfe/pfe_cdev.h
2743 +/* SPDX-License-Identifier: GPL-2.0+ */
2745 + * Copyright 2018 NXP
2748 +#ifndef _PFE_CDEV_H_
2749 +#define _PFE_CDEV_H_
2751 +#include <linux/init.h>
2752 +#include <linux/device.h>
2753 +#include <linux/err.h>
2754 +#include <linux/kernel.h>
2755 +#include <linux/fs.h>
2756 +#include <linux/uaccess.h>
2757 +#include <linux/poll.h>
2759 +#define PFE_CDEV_NAME "pfe_us_cdev"
2760 +#define PFE_CLASS_NAME "ppfe_us"
2762 +/* Extracted from ls1012a_pfe_platform_data, there are 3 interfaces which are
2763 + * supported by PFE driver. Should be updated if number of eth devices are
2766 +#define PFE_CDEV_ETH_COUNT 3
2768 +struct pfe_shared_info {
2769 + uint32_t phy_id; /* Link phy ID */
2770 + uint8_t state; /* Has either 0 or 1 */
2773 +extern struct pfe_shared_info link_states[PFE_CDEV_ETH_COUNT];
2775 +/* IOCTL Commands */
2776 +#define PFE_CDEV_ETH0_STATE_GET _IOR('R', 0, int)
2777 +#define PFE_CDEV_ETH1_STATE_GET _IOR('R', 1, int)
2778 +#define PFE_CDEV_HIF_INTR_EN _IOWR('R', 2, int)
2780 +int pfe_cdev_init(void);
2781 +void pfe_cdev_exit(void);
2783 +#endif /* _PFE_CDEV_H_ */
2785 +++ b/drivers/staging/fsl_ppfe/pfe_ctrl.c
2787 +// SPDX-License-Identifier: GPL-2.0+
2789 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
2790 + * Copyright 2017 NXP
2793 +#include <linux/kernel.h>
2794 +#include <linux/sched.h>
2795 +#include <linux/module.h>
2796 +#include <linux/list.h>
2797 +#include <linux/kthread.h>
2799 +#include "pfe_mod.h"
2800 +#include "pfe_ctrl.h"
2802 +#define TIMEOUT_MS 1000
2804 +int relax(unsigned long end)
2806 + if (time_after(jiffies, end)) {
2807 + if (time_after(jiffies, end + (TIMEOUT_MS * HZ) / 1000))
2810 + if (need_resched())
2817 +void pfe_ctrl_suspend(struct pfe_ctrl *ctrl)
2821 + mutex_lock(&ctrl->mutex);
2823 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++)
2824 + pe_dmem_write(id, cpu_to_be32(0x1), CLASS_DM_RESUME, 4);
2826 + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
2827 + if (id == TMU2_ID)
2829 + pe_dmem_write(id, cpu_to_be32(0x1), TMU_DM_RESUME, 4);
2832 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2833 + pe_dmem_write(UTIL_ID, cpu_to_be32(0x1), UTIL_DM_RESUME, 4);
2835 + mutex_unlock(&ctrl->mutex);
2838 +void pfe_ctrl_resume(struct pfe_ctrl *ctrl)
2840 + int pe_mask = CLASS_MASK | TMU_MASK;
2842 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2843 + pe_mask |= UTIL_MASK;
2845 + mutex_lock(&ctrl->mutex);
2846 + pe_start(&pfe->ctrl, pe_mask);
2847 + mutex_unlock(&ctrl->mutex);
2851 + * Stops packet processing for a list of PE's (specified using a bitmask).
2852 + * The caller must hold ctrl->mutex.
2854 + * @param ctrl Control context
2855 + * @param pe_mask Mask of PE id's to stop
2858 +int pe_sync_stop(struct pfe_ctrl *ctrl, int pe_mask)
2860 + struct pe_sync_mailbox *mbox;
2861 + int pe_stopped = 0;
2862 + unsigned long end = jiffies + 2;
2865 + pe_mask &= 0x2FF; /*Exclude Util + TMU2 */
2867 + for (i = 0; i < MAX_PE; i++)
2868 + if (pe_mask & (1 << i)) {
2869 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2871 + pe_dmem_write(i, cpu_to_be32(0x1), (unsigned
2872 + long)&mbox->stop, 4);
2875 + while (pe_stopped != pe_mask) {
2876 + for (i = 0; i < MAX_PE; i++)
2877 + if ((pe_mask & (1 << i)) && !(pe_stopped & (1 << i))) {
2878 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2880 + if (pe_dmem_read(i, (unsigned
2881 + long)&mbox->stopped, 4) &
2883 + pe_stopped |= (1 << i);
2886 + if (relax(end) < 0)
2893 + pr_err("%s: timeout, %x %x\n", __func__, pe_mask, pe_stopped);
2895 + for (i = 0; i < MAX_PE; i++)
2896 + if (pe_mask & (1 << i)) {
2897 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2899 + pe_dmem_write(i, cpu_to_be32(0x0), (unsigned
2900 + long)&mbox->stop, 4);
2907 + * Starts packet processing for a list of PE's (specified using a bitmask).
2908 + * The caller must hold ctrl->mutex.
2910 + * @param ctrl Control context
2911 + * @param pe_mask Mask of PE id's to start
2914 +void pe_start(struct pfe_ctrl *ctrl, int pe_mask)
2916 + struct pe_sync_mailbox *mbox;
2919 + for (i = 0; i < MAX_PE; i++)
2920 + if (pe_mask & (1 << i)) {
2921 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2923 + pe_dmem_write(i, cpu_to_be32(0x0), (unsigned
2924 + long)&mbox->stop, 4);
2928 +/* This function will ensure all PEs are put in to idle state */
2929 +int pe_reset_all(struct pfe_ctrl *ctrl)
2931 + struct pe_sync_mailbox *mbox;
2932 + int pe_stopped = 0;
2933 + unsigned long end = jiffies + 2;
2935 + int pe_mask = CLASS_MASK | TMU_MASK;
2937 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2938 + pe_mask |= UTIL_MASK;
2941 + for (i = 0; i < MAX_PE; i++)
2942 + if (pe_mask & (1 << i)) {
2943 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2945 + pe_dmem_write(i, cpu_to_be32(0x2), (unsigned
2946 + long)&mbox->stop, 4);
2949 + while (pe_stopped != pe_mask) {
2950 + for (i = 0; i < MAX_PE; i++)
2951 + if ((pe_mask & (1 << i)) && !(pe_stopped & (1 << i))) {
2952 + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
2954 + if (pe_dmem_read(i, (unsigned long)
2955 + &mbox->stopped, 4) &
2957 + pe_stopped |= (1 << i);
2960 + if (relax(end) < 0)
2967 + pr_err("%s: timeout, %x %x\n", __func__, pe_mask, pe_stopped);
2971 +int pfe_ctrl_init(struct pfe *pfe)
2973 + struct pfe_ctrl *ctrl = &pfe->ctrl;
2976 + pr_info("%s\n", __func__);
2978 + mutex_init(&ctrl->mutex);
2979 + spin_lock_init(&ctrl->lock);
2981 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
2982 + ctrl->sync_mailbox_baseaddr[id] = CLASS_DM_SYNC_MBOX;
2983 + ctrl->msg_mailbox_baseaddr[id] = CLASS_DM_MSG_MBOX;
2986 + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
2987 + if (id == TMU2_ID)
2989 + ctrl->sync_mailbox_baseaddr[id] = TMU_DM_SYNC_MBOX;
2990 + ctrl->msg_mailbox_baseaddr[id] = TMU_DM_MSG_MBOX;
2993 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
2994 + ctrl->sync_mailbox_baseaddr[UTIL_ID] = UTIL_DM_SYNC_MBOX;
2995 + ctrl->msg_mailbox_baseaddr[UTIL_ID] = UTIL_DM_MSG_MBOX;
2998 + ctrl->hash_array_baseaddr = pfe->ddr_baseaddr + ROUTE_TABLE_BASEADDR;
2999 + ctrl->hash_array_phys_baseaddr = pfe->ddr_phys_baseaddr +
3000 + ROUTE_TABLE_BASEADDR;
3002 + ctrl->dev = pfe->dev;
3004 + pr_info("%s finished\n", __func__);
3009 +void pfe_ctrl_exit(struct pfe *pfe)
3011 + pr_info("%s\n", __func__);
3014 +++ b/drivers/staging/fsl_ppfe/pfe_ctrl.h
3016 +/* SPDX-License-Identifier: GPL-2.0+ */
3018 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
3019 + * Copyright 2017 NXP
3022 +#ifndef _PFE_CTRL_H_
3023 +#define _PFE_CTRL_H_
3025 +#include <linux/dmapool.h>
3027 +#include "pfe/pfe.h"
3029 +#define DMA_BUF_SIZE_128 0x80 /* enough for 1 conntracks */
3030 +#define DMA_BUF_SIZE_256 0x100
3031 +/* enough for 2 conntracks, 1 bridge entry or 1 multicast entry */
3032 +#define DMA_BUF_SIZE_512 0x200
3033 +/* 512bytes dma allocated buffers used by rtp relay feature */
3034 +#define DMA_BUF_MIN_ALIGNMENT 8
3035 +#define DMA_BUF_BOUNDARY (4 * 1024)
3036 +/* bursts can not cross 4k boundary */
3038 +#define CMD_TX_ENABLE 0x0501
3039 +#define CMD_TX_DISABLE 0x0502
3041 +#define CMD_RX_LRO 0x0011
3042 +#define CMD_PKTCAP_ENABLE 0x0d01
3043 +#define CMD_QM_EXPT_RATE 0x020c
3045 +#define CLASS_DM_SH_STATIC (0x800)
3046 +#define CLASS_DM_CPU_TICKS (CLASS_DM_SH_STATIC)
3047 +#define CLASS_DM_SYNC_MBOX (0x808)
3048 +#define CLASS_DM_MSG_MBOX (0x810)
3049 +#define CLASS_DM_DROP_CNTR (0x820)
3050 +#define CLASS_DM_RESUME (0x854)
3051 +#define CLASS_DM_PESTATUS (0x860)
3052 +#define CLASS_DM_CRC_VALIDATED (0x14b0)
3054 +#define TMU_DM_SH_STATIC (0x80)
3055 +#define TMU_DM_CPU_TICKS (TMU_DM_SH_STATIC)
3056 +#define TMU_DM_SYNC_MBOX (0x88)
3057 +#define TMU_DM_MSG_MBOX (0x90)
3058 +#define TMU_DM_RESUME (0xA0)
3059 +#define TMU_DM_PESTATUS (0xB0)
3060 +#define TMU_DM_CONTEXT (0x300)
3061 +#define TMU_DM_TX_TRANS (0x480)
3063 +#define UTIL_DM_SH_STATIC (0x0)
3064 +#define UTIL_DM_CPU_TICKS (UTIL_DM_SH_STATIC)
3065 +#define UTIL_DM_SYNC_MBOX (0x8)
3066 +#define UTIL_DM_MSG_MBOX (0x10)
3067 +#define UTIL_DM_DROP_CNTR (0x20)
3068 +#define UTIL_DM_RESUME (0x40)
3069 +#define UTIL_DM_PESTATUS (0x50)
3072 + struct mutex mutex; /* to serialize pfe control access */
3076 + void *dma_pool_512;
3077 + void *dma_pool_128;
3079 + struct device *dev;
3081 + void *hash_array_baseaddr; /*
3082 + * Virtual base address of
3083 + * the conntrack hash array
3085 + unsigned long hash_array_phys_baseaddr; /*
3086 + * Physical base address of
3087 + * the conntrack hash array
3090 + int (*event_cb)(u16, u16, u16*);
3092 + unsigned long sync_mailbox_baseaddr[MAX_PE]; /*
3093 + * Sync mailbox PFE
3094 + * internal address,
3096 + * when parsing elf images
3098 + unsigned long msg_mailbox_baseaddr[MAX_PE]; /*
3099 + * Msg mailbox PFE internal
3100 + * address, initialized
3101 + * when parsing elf images
3103 + unsigned int sys_clk; /* AXI clock value, in KHz */
3106 +int pfe_ctrl_init(struct pfe *pfe);
3107 +void pfe_ctrl_exit(struct pfe *pfe);
3108 +int pe_sync_stop(struct pfe_ctrl *ctrl, int pe_mask);
3109 +void pe_start(struct pfe_ctrl *ctrl, int pe_mask);
3110 +int pe_reset_all(struct pfe_ctrl *ctrl);
3111 +void pfe_ctrl_suspend(struct pfe_ctrl *ctrl);
3112 +void pfe_ctrl_resume(struct pfe_ctrl *ctrl);
3113 +int relax(unsigned long end);
3115 +#endif /* _PFE_CTRL_H_ */
3117 +++ b/drivers/staging/fsl_ppfe/pfe_debugfs.c
3119 +// SPDX-License-Identifier: GPL-2.0+
3121 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
3122 + * Copyright 2017 NXP
3125 +#include <linux/module.h>
3126 +#include <linux/debugfs.h>
3127 +#include <linux/platform_device.h>
3129 +#include "pfe_mod.h"
3131 +static int dmem_show(struct seq_file *s, void *unused)
3133 + u32 dmem_addr, val;
3134 + int id = (long int)s->private;
3137 + for (dmem_addr = 0; dmem_addr < CLASS_DMEM_SIZE; dmem_addr += 8 * 4) {
3138 + seq_printf(s, "%04x:", dmem_addr);
3140 + for (i = 0; i < 8; i++) {
3141 + val = pe_dmem_read(id, dmem_addr + i * 4, 4);
3142 + seq_printf(s, " %02x %02x %02x %02x", val & 0xff,
3143 + (val >> 8) & 0xff, (val >> 16) & 0xff,
3144 + (val >> 24) & 0xff);
3147 + seq_puts(s, "\n");
3153 +static int dmem_open(struct inode *inode, struct file *file)
3155 + return single_open(file, dmem_show, inode->i_private);
3158 +static const struct file_operations dmem_fops = {
3159 + .open = dmem_open,
3161 + .llseek = seq_lseek,
3162 + .release = single_release,
3165 +int pfe_debugfs_init(struct pfe *pfe)
3169 + pr_info("%s\n", __func__);
3171 + pfe->dentry = debugfs_create_dir("pfe", NULL);
3172 + if (IS_ERR_OR_NULL(pfe->dentry))
3175 + d = debugfs_create_file("pe0_dmem", 0444, pfe->dentry, (void *)0,
3177 + if (IS_ERR_OR_NULL(d))
3180 + d = debugfs_create_file("pe1_dmem", 0444, pfe->dentry, (void *)1,
3182 + if (IS_ERR_OR_NULL(d))
3185 + d = debugfs_create_file("pe2_dmem", 0444, pfe->dentry, (void *)2,
3187 + if (IS_ERR_OR_NULL(d))
3190 + d = debugfs_create_file("pe3_dmem", 0444, pfe->dentry, (void *)3,
3192 + if (IS_ERR_OR_NULL(d))
3195 + d = debugfs_create_file("pe4_dmem", 0444, pfe->dentry, (void *)4,
3197 + if (IS_ERR_OR_NULL(d))
3200 + d = debugfs_create_file("pe5_dmem", 0444, pfe->dentry, (void *)5,
3202 + if (IS_ERR_OR_NULL(d))
3208 + debugfs_remove_recursive(pfe->dentry);
3214 +void pfe_debugfs_exit(struct pfe *pfe)
3216 + debugfs_remove_recursive(pfe->dentry);
3219 +++ b/drivers/staging/fsl_ppfe/pfe_debugfs.h
3221 +/* SPDX-License-Identifier: GPL-2.0+ */
3223 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
3224 + * Copyright 2017 NXP
3227 +#ifndef _PFE_DEBUGFS_H_
3228 +#define _PFE_DEBUGFS_H_
3230 +int pfe_debugfs_init(struct pfe *pfe);
3231 +void pfe_debugfs_exit(struct pfe *pfe);
3233 +#endif /* _PFE_DEBUGFS_H_ */
3235 +++ b/drivers/staging/fsl_ppfe/pfe_eth.c
3237 +// SPDX-License-Identifier: GPL-2.0+
3239 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
3240 + * Copyright 2017 NXP
3244 + * Ethernet driver for to handle exception path for PFE.
3245 + * - uses HIF functions to send/receive packets.
3246 + * - uses ctrl function to start/stop interfaces.
3247 + * - uses direct register accesses to control phy operation.
3249 +#include <linux/version.h>
3250 +#include <linux/kernel.h>
3251 +#include <linux/interrupt.h>
3252 +#include <linux/dma-mapping.h>
3253 +#include <linux/dmapool.h>
3254 +#include <linux/netdevice.h>
3255 +#include <linux/etherdevice.h>
3256 +#include <linux/ethtool.h>
3257 +#include <linux/mii.h>
3258 +#include <linux/phy.h>
3259 +#include <linux/timer.h>
3260 +#include <linux/hrtimer.h>
3261 +#include <linux/platform_device.h>
3263 +#include <net/ip.h>
3264 +#include <net/sock.h>
3266 +#include <linux/of.h>
3267 +#include <linux/of_mdio.h>
3269 +#include <linux/io.h>
3270 +#include <asm/irq.h>
3271 +#include <linux/delay.h>
3272 +#include <linux/regmap.h>
3273 +#include <linux/i2c.h>
3274 +#include <linux/sys_soc.h>
3276 +#if defined(CONFIG_NF_CONNTRACK_MARK)
3277 +#include <net/netfilter/nf_conntrack.h>
3280 +#include "pfe_mod.h"
3281 +#include "pfe_eth.h"
3282 +#include "pfe_cdev.h"
3284 +#define LS1012A_REV_1_0 0x87040010
3286 +bool pfe_use_old_dts_phy;
3287 +bool pfe_errata_a010897;
3289 +static void *cbus_emac_base[3];
3290 +static void *cbus_gpi_base[3];
3292 +/* Forward Declaration */
3293 +static void pfe_eth_exit_one(struct pfe_eth_priv_s *priv);
3294 +static void pfe_eth_flush_tx(struct pfe_eth_priv_s *priv);
3295 +static void pfe_eth_flush_txQ(struct pfe_eth_priv_s *priv, int tx_q_num, int
3296 + from_tx, int n_desc);
3298 +/* MDIO registers */
3299 +#define MDIO_SGMII_CR 0x00
3300 +#define MDIO_SGMII_SR 0x01
3301 +#define MDIO_SGMII_DEV_ABIL_SGMII 0x04
3302 +#define MDIO_SGMII_LINK_TMR_L 0x12
3303 +#define MDIO_SGMII_LINK_TMR_H 0x13
3304 +#define MDIO_SGMII_IF_MODE 0x14
3306 +/* SGMII Control defines */
3307 +#define SGMII_CR_RST 0x8000
3308 +#define SGMII_CR_AN_EN 0x1000
3309 +#define SGMII_CR_RESTART_AN 0x0200
3310 +#define SGMII_CR_FD 0x0100
3311 +#define SGMII_CR_SPEED_SEL1_1G 0x0040
3312 +#define SGMII_CR_DEF_VAL (SGMII_CR_AN_EN | SGMII_CR_FD | \
3313 + SGMII_CR_SPEED_SEL1_1G)
3315 +/* SGMII IF Mode */
3316 +#define SGMII_DUPLEX_HALF 0x10
3317 +#define SGMII_SPEED_10MBPS 0x00
3318 +#define SGMII_SPEED_100MBPS 0x04
3319 +#define SGMII_SPEED_1GBPS 0x08
3320 +#define SGMII_USE_SGMII_AN 0x02
3321 +#define SGMII_EN 0x01
3323 +/* SGMII Device Ability for SGMII */
3324 +#define SGMII_DEV_ABIL_ACK 0x4000
3325 +#define SGMII_DEV_ABIL_EEE_CLK_STP_EN 0x0100
3326 +#define SGMII_DEV_ABIL_SGMII 0x0001
3328 +unsigned int gemac_regs[] = {
3329 + 0x0004, /* Interrupt event */
3330 + 0x0008, /* Interrupt mask */
3331 + 0x0024, /* Ethernet control */
3332 + 0x0064, /* MIB Control/Status */
3333 + 0x0084, /* Receive control/status */
3334 + 0x00C4, /* Transmit control */
3335 + 0x00E4, /* Physical address low */
3336 + 0x00E8, /* Physical address high */
3337 + 0x0144, /* Transmit FIFO Watermark and Store and Forward Control*/
3338 + 0x0190, /* Receive FIFO Section Full Threshold */
3339 + 0x01A0, /* Transmit FIFO Section Empty Threshold */
3340 + 0x01B0, /* Frame Truncation Length */
3343 +const struct soc_device_attribute ls1012a_rev1_soc_attr[] = {
3344 + { .family = "QorIQ LS1012A",
3345 + .soc_id = "svr:0x87040010",
3346 + .revision = "1.0",
3351 +/********************************************************************/
3352 +/* SYSFS INTERFACE */
3353 +/********************************************************************/
3355 +#ifdef PFE_ETH_NAPI_STATS
3357 + * pfe_eth_show_napi_stats
3359 +static ssize_t pfe_eth_show_napi_stats(struct device *dev,
3360 + struct device_attribute *attr,
3363 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
3366 + len += sprintf(buf + len, "sched: %u\n",
3367 + priv->napi_counters[NAPI_SCHED_COUNT]);
3368 + len += sprintf(buf + len, "poll: %u\n",
3369 + priv->napi_counters[NAPI_POLL_COUNT]);
3370 + len += sprintf(buf + len, "packet: %u\n",
3371 + priv->napi_counters[NAPI_PACKET_COUNT]);
3372 + len += sprintf(buf + len, "budget: %u\n",
3373 + priv->napi_counters[NAPI_FULL_BUDGET_COUNT]);
3374 + len += sprintf(buf + len, "desc: %u\n",
3375 + priv->napi_counters[NAPI_DESC_COUNT]);
3381 + * pfe_eth_set_napi_stats
3383 +static ssize_t pfe_eth_set_napi_stats(struct device *dev,
3384 + struct device_attribute *attr,
3385 + const char *buf, size_t count)
3387 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
3389 + memset(priv->napi_counters, 0, sizeof(priv->napi_counters));
3394 +#ifdef PFE_ETH_TX_STATS
3395 +/* pfe_eth_show_tx_stats
3398 +static ssize_t pfe_eth_show_tx_stats(struct device *dev,
3399 + struct device_attribute *attr,
3402 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
3406 + len += sprintf(buf + len, "TX queues stats:\n");
3408 + for (i = 0; i < emac_txq_cnt; i++) {
3409 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
3412 + len += sprintf(buf + len, "\n");
3413 + __netif_tx_lock_bh(tx_queue);
3415 + hif_tx_lock(&pfe->hif);
3416 + len += sprintf(buf + len,
3417 + "Queue %2d : credits = %10d\n"
3418 + , i, hif_lib_tx_credit_avail(pfe, priv->id, i));
3419 + len += sprintf(buf + len,
3420 + " tx packets = %10d\n"
3421 + , pfe->tmu_credit.tx_packets[priv->id][i]);
3422 + hif_tx_unlock(&pfe->hif);
3424 + /* Don't output additionnal stats if queue never used */
3425 + if (!pfe->tmu_credit.tx_packets[priv->id][i])
3428 + len += sprintf(buf + len,
3429 + " clean_fail = %10d\n"
3430 + , priv->clean_fail[i]);
3431 + len += sprintf(buf + len,
3432 + " stop_queue = %10d\n"
3433 + , priv->stop_queue_total[i]);
3434 + len += sprintf(buf + len,
3435 + " stop_queue_hif = %10d\n"
3436 + , priv->stop_queue_hif[i]);
3437 + len += sprintf(buf + len,
3438 + " stop_queue_hif_client = %10d\n"
3439 + , priv->stop_queue_hif_client[i]);
3440 + len += sprintf(buf + len,
3441 + " stop_queue_credit = %10d\n"
3442 + , priv->stop_queue_credit[i]);
3444 + __netif_tx_unlock_bh(tx_queue);
3449 +/* pfe_eth_set_tx_stats
3452 +static ssize_t pfe_eth_set_tx_stats(struct device *dev,
3453 + struct device_attribute *attr,
3454 + const char *buf, size_t count)
3456 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
3459 + for (i = 0; i < emac_txq_cnt; i++) {
3460 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
3463 + __netif_tx_lock_bh(tx_queue);
3464 + priv->clean_fail[i] = 0;
3465 + priv->stop_queue_total[i] = 0;
3466 + priv->stop_queue_hif[i] = 0;
3467 + priv->stop_queue_hif_client[i] = 0;
3468 + priv->stop_queue_credit[i] = 0;
3469 + __netif_tx_unlock_bh(tx_queue);
3475 +/* pfe_eth_show_txavail
3478 +static ssize_t pfe_eth_show_txavail(struct device *dev,
3479 + struct device_attribute *attr,
3482 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
3486 + for (i = 0; i < emac_txq_cnt; i++) {
3487 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
3490 + __netif_tx_lock_bh(tx_queue);
3492 + len += sprintf(buf + len, "%d",
3493 + hif_lib_tx_avail(&priv->client, i));
3495 + __netif_tx_unlock_bh(tx_queue);
3497 + if (i == (emac_txq_cnt - 1))
3498 + len += sprintf(buf + len, "\n");
3500 + len += sprintf(buf + len, " ");
3506 +/* pfe_eth_show_default_priority
3509 +static ssize_t pfe_eth_show_default_priority(struct device *dev,
3510 + struct device_attribute *attr,
3513 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
3514 + unsigned long flags;
3517 + spin_lock_irqsave(&priv->lock, flags);
3518 + rc = sprintf(buf, "%d\n", priv->default_priority);
3519 + spin_unlock_irqrestore(&priv->lock, flags);
3524 +/* pfe_eth_set_default_priority
3528 +static ssize_t pfe_eth_set_default_priority(struct device *dev,
3529 + struct device_attribute *attr,
3530 + const char *buf, size_t count)
3532 + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
3533 + unsigned long flags;
3535 + spin_lock_irqsave(&priv->lock, flags);
3536 + priv->default_priority = kstrtoul(buf, 0, 0);
3537 + spin_unlock_irqrestore(&priv->lock, flags);
3542 +static DEVICE_ATTR(txavail, 0444, pfe_eth_show_txavail, NULL);
3543 +static DEVICE_ATTR(default_priority, 0644, pfe_eth_show_default_priority,
3544 + pfe_eth_set_default_priority);
3546 +#ifdef PFE_ETH_NAPI_STATS
3547 +static DEVICE_ATTR(napi_stats, 0644, pfe_eth_show_napi_stats,
3548 + pfe_eth_set_napi_stats);
3551 +#ifdef PFE_ETH_TX_STATS
3552 +static DEVICE_ATTR(tx_stats, 0644, pfe_eth_show_tx_stats,
3553 + pfe_eth_set_tx_stats);
3557 + * pfe_eth_sysfs_init
3560 +static int pfe_eth_sysfs_init(struct net_device *ndev)
3562 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3565 + /* Initialize the default values */
3568 + * By default, packets without conntrack will use this default low
3571 + priv->default_priority = 0;
3573 + /* Create our sysfs files */
3574 + err = device_create_file(&ndev->dev, &dev_attr_default_priority);
3577 + "failed to create default_priority sysfs files\n");
3578 + goto err_priority;
3581 + err = device_create_file(&ndev->dev, &dev_attr_txavail);
3584 + "failed to create default_priority sysfs files\n");
3588 +#ifdef PFE_ETH_NAPI_STATS
3589 + err = device_create_file(&ndev->dev, &dev_attr_napi_stats);
3591 + netdev_err(ndev, "failed to create napi stats sysfs files\n");
3596 +#ifdef PFE_ETH_TX_STATS
3597 + err = device_create_file(&ndev->dev, &dev_attr_tx_stats);
3599 + netdev_err(ndev, "failed to create tx stats sysfs files\n");
3606 +#ifdef PFE_ETH_TX_STATS
3609 +#ifdef PFE_ETH_NAPI_STATS
3610 + device_remove_file(&ndev->dev, &dev_attr_napi_stats);
3614 + device_remove_file(&ndev->dev, &dev_attr_txavail);
3617 + device_remove_file(&ndev->dev, &dev_attr_default_priority);
3623 +/* pfe_eth_sysfs_exit
3626 +void pfe_eth_sysfs_exit(struct net_device *ndev)
3628 +#ifdef PFE_ETH_TX_STATS
3629 + device_remove_file(&ndev->dev, &dev_attr_tx_stats);
3632 +#ifdef PFE_ETH_NAPI_STATS
3633 + device_remove_file(&ndev->dev, &dev_attr_napi_stats);
3635 + device_remove_file(&ndev->dev, &dev_attr_txavail);
3636 + device_remove_file(&ndev->dev, &dev_attr_default_priority);
3639 +/*************************************************************************/
3640 +/* ETHTOOL INTERCAE */
3641 +/*************************************************************************/
3644 +static const struct fec_stat {
3645 + char name[ETH_GSTRING_LEN];
3649 + { "tx_dropped", RMON_T_DROP },
3650 + { "tx_packets", RMON_T_PACKETS },
3651 + { "tx_broadcast", RMON_T_BC_PKT },
3652 + { "tx_multicast", RMON_T_MC_PKT },
3653 + { "tx_crc_errors", RMON_T_CRC_ALIGN },
3654 + { "tx_undersize", RMON_T_UNDERSIZE },
3655 + { "tx_oversize", RMON_T_OVERSIZE },
3656 + { "tx_fragment", RMON_T_FRAG },
3657 + { "tx_jabber", RMON_T_JAB },
3658 + { "tx_collision", RMON_T_COL },
3659 + { "tx_64byte", RMON_T_P64 },
3660 + { "tx_65to127byte", RMON_T_P65TO127 },
3661 + { "tx_128to255byte", RMON_T_P128TO255 },
3662 + { "tx_256to511byte", RMON_T_P256TO511 },
3663 + { "tx_512to1023byte", RMON_T_P512TO1023 },
3664 + { "tx_1024to2047byte", RMON_T_P1024TO2047 },
3665 + { "tx_GTE2048byte", RMON_T_P_GTE2048 },
3666 + { "tx_octets", RMON_T_OCTETS },
3669 + { "IEEE_tx_drop", IEEE_T_DROP },
3670 + { "IEEE_tx_frame_ok", IEEE_T_FRAME_OK },
3671 + { "IEEE_tx_1col", IEEE_T_1COL },
3672 + { "IEEE_tx_mcol", IEEE_T_MCOL },
3673 + { "IEEE_tx_def", IEEE_T_DEF },
3674 + { "IEEE_tx_lcol", IEEE_T_LCOL },
3675 + { "IEEE_tx_excol", IEEE_T_EXCOL },
3676 + { "IEEE_tx_macerr", IEEE_T_MACERR },
3677 + { "IEEE_tx_cserr", IEEE_T_CSERR },
3678 + { "IEEE_tx_sqe", IEEE_T_SQE },
3679 + { "IEEE_tx_fdxfc", IEEE_T_FDXFC },
3680 + { "IEEE_tx_octets_ok", IEEE_T_OCTETS_OK },
3683 + { "rx_packets", RMON_R_PACKETS },
3684 + { "rx_broadcast", RMON_R_BC_PKT },
3685 + { "rx_multicast", RMON_R_MC_PKT },
3686 + { "rx_crc_errors", RMON_R_CRC_ALIGN },
3687 + { "rx_undersize", RMON_R_UNDERSIZE },
3688 + { "rx_oversize", RMON_R_OVERSIZE },
3689 + { "rx_fragment", RMON_R_FRAG },
3690 + { "rx_jabber", RMON_R_JAB },
3691 + { "rx_64byte", RMON_R_P64 },
3692 + { "rx_65to127byte", RMON_R_P65TO127 },
3693 + { "rx_128to255byte", RMON_R_P128TO255 },
3694 + { "rx_256to511byte", RMON_R_P256TO511 },
3695 + { "rx_512to1023byte", RMON_R_P512TO1023 },
3696 + { "rx_1024to2047byte", RMON_R_P1024TO2047 },
3697 + { "rx_GTE2048byte", RMON_R_P_GTE2048 },
3698 + { "rx_octets", RMON_R_OCTETS },
3701 + { "IEEE_rx_drop", IEEE_R_DROP },
3702 + { "IEEE_rx_frame_ok", IEEE_R_FRAME_OK },
3703 + { "IEEE_rx_crc", IEEE_R_CRC },
3704 + { "IEEE_rx_align", IEEE_R_ALIGN },
3705 + { "IEEE_rx_macerr", IEEE_R_MACERR },
3706 + { "IEEE_rx_fdxfc", IEEE_R_FDXFC },
3707 + { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK },
3710 +static void pfe_eth_fill_stats(struct net_device *ndev, struct ethtool_stats
3711 + *stats, u64 *data)
3713 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3715 + u64 pfe_crc_validated = 0;
3718 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
3719 + pfe_crc_validated += be32_to_cpu(pe_dmem_read(id,
3720 + CLASS_DM_CRC_VALIDATED + (priv->id * 4), 4));
3723 + for (i = 0; i < ARRAY_SIZE(fec_stats); i++) {
3724 + data[i] = readl(priv->EMAC_baseaddr + fec_stats[i].offset);
3726 + if (fec_stats[i].offset == IEEE_R_DROP)
3727 + data[i] -= pfe_crc_validated;
3731 +static void pfe_eth_gstrings(struct net_device *netdev,
3732 + u32 stringset, u8 *data)
3736 + switch (stringset) {
3737 + case ETH_SS_STATS:
3738 + for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
3739 + memcpy(data + i * ETH_GSTRING_LEN,
3740 + fec_stats[i].name, ETH_GSTRING_LEN);
3745 +static int pfe_eth_stats_count(struct net_device *ndev, int sset)
3748 + case ETH_SS_STATS:
3749 + return ARRAY_SIZE(fec_stats);
3751 + return -EOPNOTSUPP;
3756 + * pfe_eth_gemac_reglen - Return the length of the register structure.
3759 +static int pfe_eth_gemac_reglen(struct net_device *ndev)
3761 + pr_info("%s()\n", __func__);
3762 + return (sizeof(gemac_regs) / sizeof(u32));
3766 + * pfe_eth_gemac_get_regs - Return the gemac register structure.
3769 +static void pfe_eth_gemac_get_regs(struct net_device *ndev, struct ethtool_regs
3770 + *regs, void *regbuf)
3774 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3775 + u32 *buf = (u32 *)regbuf;
3777 + pr_info("%s()\n", __func__);
3778 + for (i = 0; i < sizeof(gemac_regs) / sizeof(u32); i++)
3779 + buf[i] = readl(priv->EMAC_baseaddr + gemac_regs[i]);
3783 + * pfe_eth_set_wol - Set the magic packet option, in WoL register.
3786 +static int pfe_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
3788 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3790 + if (wol->wolopts & ~WAKE_MAGIC)
3791 + return -EOPNOTSUPP;
3793 + /* for MTIP we store wol->wolopts */
3794 + priv->wol = wol->wolopts;
3796 + device_set_wakeup_enable(&ndev->dev, wol->wolopts & WAKE_MAGIC);
3803 + * pfe_eth_get_wol - Get the WoL options.
3806 +static void pfe_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo
3809 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3811 + wol->supported = WAKE_MAGIC;
3814 + if (priv->wol & WAKE_MAGIC)
3815 + wol->wolopts = WAKE_MAGIC;
3817 + memset(&wol->sopass, 0, sizeof(wol->sopass));
3821 + * pfe_eth_get_drvinfo - Fills in the drvinfo structure with some basic info
3824 +static void pfe_eth_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo
3827 + strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
3828 + strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
3829 + strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
3830 + strlcpy(drvinfo->bus_info, "N/A", sizeof(drvinfo->bus_info));
3834 + * pfe_eth_set_settings - Used to send commands to PHY.
3837 +static int pfe_eth_set_settings(struct net_device *ndev,
3838 + const struct ethtool_link_ksettings *cmd)
3840 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3841 + struct phy_device *phydev = priv->phydev;
3846 + return phy_ethtool_ksettings_set(phydev, cmd);
3850 + * pfe_eth_getsettings - Return the current settings in the ethtool_cmd
3854 +static int pfe_eth_get_settings(struct net_device *ndev,
3855 + struct ethtool_link_ksettings *cmd)
3857 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3858 + struct phy_device *phydev = priv->phydev;
3863 + phy_ethtool_ksettings_get(phydev, cmd);
3869 + * pfe_eth_get_msglevel - Gets the debug message mask.
3872 +static uint32_t pfe_eth_get_msglevel(struct net_device *ndev)
3874 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3876 + return priv->msg_enable;
3880 + * pfe_eth_set_msglevel - Sets the debug message mask.
3883 +static void pfe_eth_set_msglevel(struct net_device *ndev, uint32_t data)
3885 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3887 + priv->msg_enable = data;
3890 +#define HIF_RX_COAL_MAX_CLKS (~(1 << 31))
3891 +#define HIF_RX_COAL_CLKS_PER_USEC (pfe->ctrl.sys_clk / 1000)
3892 +#define HIF_RX_COAL_MAX_USECS (HIF_RX_COAL_MAX_CLKS / \
3893 + HIF_RX_COAL_CLKS_PER_USEC)
3896 + * pfe_eth_set_coalesce - Sets rx interrupt coalescing timer.
3899 +static int pfe_eth_set_coalesce(struct net_device *ndev,
3900 + struct ethtool_coalesce *ec,
3901 + struct kernel_ethtool_coalesce *kernel_coal,
3902 + struct netlink_ext_ack *extack)
3904 + if (ec->rx_coalesce_usecs > HIF_RX_COAL_MAX_USECS)
3907 + if (!ec->rx_coalesce_usecs) {
3908 + writel(0, HIF_INT_COAL);
3912 + writel((ec->rx_coalesce_usecs * HIF_RX_COAL_CLKS_PER_USEC) |
3913 + HIF_INT_COAL_ENABLE, HIF_INT_COAL);
3919 + * pfe_eth_get_coalesce - Gets rx interrupt coalescing timer value.
3922 +static int pfe_eth_get_coalesce(struct net_device *ndev,
3923 + struct ethtool_coalesce *ec,
3924 + struct kernel_ethtool_coalesce *kernel_coal,
3925 + struct netlink_ext_ack *extack)
3927 + int reg_val = readl(HIF_INT_COAL);
3929 + if (reg_val & HIF_INT_COAL_ENABLE)
3930 + ec->rx_coalesce_usecs = (reg_val & HIF_RX_COAL_MAX_CLKS) /
3931 + HIF_RX_COAL_CLKS_PER_USEC;
3933 + ec->rx_coalesce_usecs = 0;
3939 + * pfe_eth_set_pauseparam - Sets pause parameters
3942 +static int pfe_eth_set_pauseparam(struct net_device *ndev,
3943 + struct ethtool_pauseparam *epause)
3945 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
3947 + if (epause->tx_pause != epause->rx_pause) {
3949 + "hardware only support enable/disable both tx and rx\n");
3953 + priv->pause_flag = 0;
3954 + priv->pause_flag |= epause->rx_pause ? PFE_PAUSE_FLAG_ENABLE : 0;
3955 + priv->pause_flag |= epause->autoneg ? PFE_PAUSE_FLAG_AUTONEG : 0;
3957 + if (epause->rx_pause || epause->autoneg) {
3958 + gemac_enable_pause_rx(priv->EMAC_baseaddr);
3959 + writel((readl(priv->GPI_baseaddr + GPI_TX_PAUSE_TIME) |
3960 + EGPI_PAUSE_ENABLE),
3961 + priv->GPI_baseaddr + GPI_TX_PAUSE_TIME);
3962 + if (priv->phydev) {
3963 + linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
3964 + priv->phydev->supported);
3965 + linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
3966 + priv->phydev->supported);
3967 + linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
3968 + priv->phydev->advertising);
3969 + linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
3970 + priv->phydev->advertising);
3973 + gemac_disable_pause_rx(priv->EMAC_baseaddr);
3974 + writel((readl(priv->GPI_baseaddr + GPI_TX_PAUSE_TIME) &
3975 + ~EGPI_PAUSE_ENABLE),
3976 + priv->GPI_baseaddr + GPI_TX_PAUSE_TIME);
3977 + if (priv->phydev) {
3978 + linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT,
3979 + priv->phydev->supported);
3980 + linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
3981 + priv->phydev->supported);
3982 + linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT,
3983 + priv->phydev->advertising);
3984 + linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
3985 + priv->phydev->advertising);
3993 + * pfe_eth_get_pauseparam - Gets pause parameters
3996 +static void pfe_eth_get_pauseparam(struct net_device *ndev,
3997 + struct ethtool_pauseparam *epause)
3999 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4001 + epause->autoneg = (priv->pause_flag & PFE_PAUSE_FLAG_AUTONEG) != 0;
4002 + epause->tx_pause = (priv->pause_flag & PFE_PAUSE_FLAG_ENABLE) != 0;
4003 + epause->rx_pause = epause->tx_pause;
4007 + * pfe_eth_get_hash
4009 +#define PFE_HASH_BITS 6 /* #bits in hash */
4010 +#define CRC32_POLY 0xEDB88320
4012 +static int pfe_eth_get_hash(u8 *addr)
4014 + unsigned int i, bit, data, crc, hash;
4016 + /* calculate crc32 value of mac address */
4019 + for (i = 0; i < 6; i++) {
4021 + for (bit = 0; bit < 8; bit++, data >>= 1) {
4022 + crc = (crc >> 1) ^
4023 + (((crc ^ data) & 1) ? CRC32_POLY : 0);
4028 + * only upper 6 bits (PFE_HASH_BITS) are used
4029 + * which point to specific bit in the hash registers
4031 + hash = (crc >> (32 - PFE_HASH_BITS)) & 0x3f;
4036 +const struct ethtool_ops pfe_ethtool_ops = {
4037 + .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS,
4038 + .get_drvinfo = pfe_eth_get_drvinfo,
4039 + .get_regs_len = pfe_eth_gemac_reglen,
4040 + .get_regs = pfe_eth_gemac_get_regs,
4041 + .get_link = ethtool_op_get_link,
4042 + .get_wol = pfe_eth_get_wol,
4043 + .set_wol = pfe_eth_set_wol,
4044 + .set_pauseparam = pfe_eth_set_pauseparam,
4045 + .get_pauseparam = pfe_eth_get_pauseparam,
4046 + .get_strings = pfe_eth_gstrings,
4047 + .get_sset_count = pfe_eth_stats_count,
4048 + .get_ethtool_stats = pfe_eth_fill_stats,
4049 + .get_msglevel = pfe_eth_get_msglevel,
4050 + .set_msglevel = pfe_eth_set_msglevel,
4051 + .set_coalesce = pfe_eth_set_coalesce,
4052 + .get_coalesce = pfe_eth_get_coalesce,
4053 + .get_link_ksettings = pfe_eth_get_settings,
4054 + .set_link_ksettings = pfe_eth_set_settings,
4057 +/* pfe_eth_mdio_reset
4059 +int pfe_eth_mdio_reset(struct mii_bus *bus)
4061 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
4065 + mutex_lock(&bus->mdio_lock);
4068 + * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
4070 + * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
4071 + * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'.
4073 + phy_speed = (DIV_ROUND_UP((pfe->ctrl.sys_clk * 1000), 4000000)
4074 + << EMAC_MII_SPEED_SHIFT);
4075 + phy_speed |= EMAC_HOLDTIME(0x5);
4076 + __raw_writel(phy_speed, priv->mdio_base + EMAC_MII_CTRL_REG);
4078 + mutex_unlock(&bus->mdio_lock);
4083 +/* pfe_eth_mdio_timeout
4086 +static int pfe_eth_mdio_timeout(struct pfe_mdio_priv_s *priv, int timeout)
4088 + while (!(__raw_readl(priv->mdio_base + EMAC_IEVENT_REG) &
4089 + EMAC_IEVENT_MII)) {
4090 + if (timeout-- <= 0)
4092 + usleep_range(10, 20);
4094 + __raw_writel(EMAC_IEVENT_MII, priv->mdio_base + EMAC_IEVENT_REG);
4098 +static int pfe_eth_mdio_mux(u8 muxval)
4100 + struct i2c_adapter *a;
4101 + struct i2c_msg msg;
4102 + unsigned char buf[2];
4105 + a = i2c_get_adapter(0);
4109 + /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
4110 + buf[0] = 0x54; /* reg number */
4111 + buf[1] = (muxval << 6) | 0x3; /* data */
4116 + ret = i2c_transfer(a, &msg, 1);
4117 + i2c_put_adapter(a);
4123 +static int pfe_eth_mdio_write_addr(struct mii_bus *bus, int mii_id,
4124 + int dev_addr, int regnum)
4126 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
4128 + __raw_writel(EMAC_MII_DATA_PA(mii_id) |
4129 + EMAC_MII_DATA_RA(dev_addr) |
4130 + EMAC_MII_DATA_TA | EMAC_MII_DATA(regnum),
4131 + priv->mdio_base + EMAC_MII_DATA_REG);
4133 + if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
4134 + dev_err(&bus->dev, "phy MDIO address write timeout\n");
4141 +static int pfe_eth_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
4144 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
4146 + /*To access external PHYs on QDS board mux needs to be configured*/
4147 + if ((mii_id) && (pfe->mdio_muxval[mii_id]))
4148 + pfe_eth_mdio_mux(pfe->mdio_muxval[mii_id]);
4150 + if (regnum & MII_ADDR_C45) {
4151 + pfe_eth_mdio_write_addr(bus, mii_id, (regnum >> 16) & 0x1f,
4153 + __raw_writel(EMAC_MII_DATA_OP_CL45_WR |
4154 + EMAC_MII_DATA_PA(mii_id) |
4155 + EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
4156 + EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
4157 + priv->mdio_base + EMAC_MII_DATA_REG);
4159 + /* start a write op */
4160 + __raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_WR |
4161 + EMAC_MII_DATA_PA(mii_id) |
4162 + EMAC_MII_DATA_RA(regnum) |
4163 + EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
4164 + priv->mdio_base + EMAC_MII_DATA_REG);
4167 + if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
4168 + dev_err(&bus->dev, "%s: phy MDIO write timeout\n", __func__);
4174 +static int pfe_eth_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
4176 + struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
4179 + /*To access external PHYs on QDS board mux needs to be configured*/
4180 + if ((mii_id) && (pfe->mdio_muxval[mii_id]))
4181 + pfe_eth_mdio_mux(pfe->mdio_muxval[mii_id]);
4183 + if (regnum & MII_ADDR_C45) {
4184 + pfe_eth_mdio_write_addr(bus, mii_id, (regnum >> 16) & 0x1f,
4186 + __raw_writel(EMAC_MII_DATA_OP_CL45_RD |
4187 + EMAC_MII_DATA_PA(mii_id) |
4188 + EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
4190 + priv->mdio_base + EMAC_MII_DATA_REG);
4192 + /* start a read op */
4193 + __raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_RD |
4194 + EMAC_MII_DATA_PA(mii_id) |
4195 + EMAC_MII_DATA_RA(regnum) |
4196 + EMAC_MII_DATA_TA, priv->mdio_base +
4197 + EMAC_MII_DATA_REG);
4200 + if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
4201 + dev_err(&bus->dev, "%s: phy MDIO read timeout\n", __func__);
4205 + value = EMAC_MII_DATA(__raw_readl(priv->mdio_base +
4206 + EMAC_MII_DATA_REG));
4210 +static int pfe_eth_mdio_init(struct pfe *pfe,
4211 + struct ls1012a_pfe_platform_data *pfe_info,
4214 + struct pfe_mdio_priv_s *priv = NULL;
4215 + struct ls1012a_mdio_platform_data *mdio_info;
4216 + struct mii_bus *bus;
4217 + struct device_node *mdio_node;
4220 + mdio_info = (struct ls1012a_mdio_platform_data *)
4221 + pfe_info->ls1012a_mdio_pdata;
4222 + mdio_info->id = ii;
4224 + bus = mdiobus_alloc_size(sizeof(struct pfe_mdio_priv_s));
4226 + pr_err("mdiobus_alloc() failed\n");
4228 + goto err_mdioalloc;
4231 + bus->name = "ls1012a MDIO Bus";
4232 + snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", mdio_info->id);
4234 + bus->read = &pfe_eth_mdio_read;
4235 + bus->write = &pfe_eth_mdio_write;
4236 + bus->reset = &pfe_eth_mdio_reset;
4237 + bus->parent = pfe->dev;
4238 + bus->phy_mask = mdio_info->phy_mask;
4239 + bus->irq[0] = mdio_info->irq[0];
4241 + priv->mdio_base = cbus_emac_base[ii];
4243 + priv->mdc_div = mdio_info->mdc_div;
4244 + if (!priv->mdc_div)
4245 + priv->mdc_div = 64;
4247 + dev_info(bus->parent, "%s: mdc_div: %d, phy_mask: %x\n",
4248 + __func__, priv->mdc_div, bus->phy_mask);
4249 + mdio_node = of_get_child_by_name(pfe->dev->of_node, "mdio");
4250 + if ((mdio_info->id == 0) && mdio_node) {
4251 + rc = of_mdiobus_register(bus, mdio_node);
4252 + of_node_put(mdio_node);
4254 + rc = mdiobus_register(bus);
4258 + dev_err(bus->parent, "mdiobus_register(%s) failed\n",
4260 + goto err_mdioregister;
4263 + priv->mii_bus = bus;
4264 + pfe->mdio.mdio_priv[ii] = priv;
4266 + pfe_eth_mdio_reset(bus);
4271 + mdiobus_free(bus);
4276 +/* pfe_eth_mdio_exit
4278 +static void pfe_eth_mdio_exit(struct pfe *pfe,
4281 + struct pfe_mdio_priv_s *mdio_priv = pfe->mdio.mdio_priv[ii];
4282 + struct mii_bus *bus = mdio_priv->mii_bus;
4286 + mdiobus_unregister(bus);
4287 + mdiobus_free(bus);
4290 +/* pfe_get_phydev_speed
4292 +static int pfe_get_phydev_speed(struct phy_device *phydev)
4294 + switch (phydev->speed) {
4298 + return SPEED_100M;
4301 + return SPEED_1000M;
4305 +/* pfe_set_rgmii_speed
4307 +#define RGMIIPCR 0x434
4308 +/* RGMIIPCR bit definitions*/
4309 +#define SCFG_RGMIIPCR_EN_AUTO (0x00000008)
4310 +#define SCFG_RGMIIPCR_SETSP_1000M (0x00000004)
4311 +#define SCFG_RGMIIPCR_SETSP_100M (0x00000000)
4312 +#define SCFG_RGMIIPCR_SETSP_10M (0x00000002)
4313 +#define SCFG_RGMIIPCR_SETFD (0x00000001)
4315 +#define MDIOSELCR 0x484
4316 +#define MDIOSEL_SERDES 0x0
4317 +#define MDIOSEL_EXTPHY 0x80000000
4319 +static void pfe_set_rgmii_speed(struct phy_device *phydev)
4323 + regmap_read(pfe->scfg, RGMIIPCR, &rgmii_pcr);
4324 + rgmii_pcr &= ~(SCFG_RGMIIPCR_SETSP_1000M | SCFG_RGMIIPCR_SETSP_10M);
4326 + switch (phydev->speed) {
4328 + rgmii_pcr |= SCFG_RGMIIPCR_SETSP_10M;
4331 + rgmii_pcr |= SCFG_RGMIIPCR_SETSP_1000M;
4335 + /* Default is 100M */
4338 + regmap_write(pfe->scfg, RGMIIPCR, rgmii_pcr);
4341 +/* pfe_get_phydev_duplex
4343 +static int pfe_get_phydev_duplex(struct phy_device *phydev)
4345 + /*return (phydev->duplex == DUPLEX_HALF) ? DUP_HALF:DUP_FULL ; */
4346 + return DUPLEX_FULL;
4349 +/* pfe_eth_adjust_link
4351 +static void pfe_eth_adjust_link(struct net_device *ndev)
4353 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4354 + unsigned long flags;
4355 + struct phy_device *phydev = priv->phydev;
4356 + int new_state = 0;
4358 + netif_info(priv, drv, ndev, "%s\n", __func__);
4360 + spin_lock_irqsave(&priv->lock, flags);
4362 + if (phydev->link) {
4364 + * Now we make sure that we can be in full duplex mode.
4365 + * If not, we operate in half-duplex mode.
4367 + if (phydev->duplex != priv->oldduplex) {
4369 + gemac_set_duplex(priv->EMAC_baseaddr,
4370 + pfe_get_phydev_duplex(phydev));
4371 + priv->oldduplex = phydev->duplex;
4374 + if (phydev->speed != priv->oldspeed) {
4376 + gemac_set_speed(priv->EMAC_baseaddr,
4377 + pfe_get_phydev_speed(phydev));
4378 + if (priv->einfo->mii_config ==
4379 + PHY_INTERFACE_MODE_RGMII_ID)
4380 + pfe_set_rgmii_speed(phydev);
4381 + priv->oldspeed = phydev->speed;
4384 + if (!priv->oldlink) {
4386 + priv->oldlink = 1;
4389 + } else if (priv->oldlink) {
4391 + priv->oldlink = 0;
4392 + priv->oldspeed = 0;
4393 + priv->oldduplex = -1;
4396 + if (new_state && netif_msg_link(priv))
4397 + phy_print_status(phydev);
4399 + spin_unlock_irqrestore(&priv->lock, flags);
4401 + /* Now, dump the details to the cdev.
4402 + * XXX: Locking would be required? (uniprocess arch)
4403 + * Or, maybe move it in spinlock above
4405 + if (us && priv->einfo->gem_id < PFE_CDEV_ETH_COUNT) {
4406 + pr_debug("Changing link state from (%u) to (%u) for ID=(%u)\n",
4407 + link_states[priv->einfo->gem_id].state,
4409 + priv->einfo->gem_id);
4410 + link_states[priv->einfo->gem_id].phy_id = priv->einfo->gem_id;
4411 + link_states[priv->einfo->gem_id].state = phydev->link;
4417 +static void pfe_phy_exit(struct net_device *ndev)
4419 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4421 + netif_info(priv, drv, ndev, "%s\n", __func__);
4423 + phy_disconnect(priv->phydev);
4424 + priv->phydev = NULL;
4429 +static void pfe_eth_stop(struct net_device *ndev, int wake)
4431 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4433 + netif_info(priv, drv, ndev, "%s\n", __func__);
4436 + gemac_tx_disable(priv->EMAC_baseaddr);
4438 + gemac_disable(priv->EMAC_baseaddr);
4439 + gpi_disable(priv->GPI_baseaddr);
4442 + phy_stop(priv->phydev);
4448 +static int pfe_eth_start(struct pfe_eth_priv_s *priv)
4450 + netif_info(priv, drv, priv->ndev, "%s\n", __func__);
4453 + phy_start(priv->phydev);
4455 + gpi_enable(priv->GPI_baseaddr);
4456 + gemac_enable(priv->EMAC_baseaddr);
4462 + * Configure on chip serdes through mdio
4464 +static void ls1012a_configure_serdes(struct net_device *ndev)
4466 + struct pfe_eth_priv_s *eth_priv = netdev_priv(ndev);
4467 + struct pfe_mdio_priv_s *mdio_priv = pfe->mdio.mdio_priv[eth_priv->id];
4468 + int sgmii_2500 = 0;
4469 + struct mii_bus *bus = mdio_priv->mii_bus;
4472 + if (eth_priv->einfo->mii_config == PHY_INTERFACE_MODE_2500SGMII)
4475 + netif_info(eth_priv, drv, ndev, "%s\n", __func__);
4476 + /* PCS configuration done with corresponding GEMAC */
4478 + pfe_eth_mdio_read(bus, 0, MDIO_SGMII_CR);
4479 + pfe_eth_mdio_read(bus, 0, MDIO_SGMII_SR);
4481 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_CR, SGMII_CR_RST);
4484 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_IF_MODE, SGMII_SPEED_1GBPS
4486 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_DEV_ABIL_SGMII,
4487 + SGMII_DEV_ABIL_ACK | SGMII_DEV_ABIL_SGMII);
4488 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_L, 0xa120);
4489 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_H, 0x7);
4490 + /* Autonegotiation need to be disabled for 2.5G SGMII mode*/
4491 + value = SGMII_CR_FD | SGMII_CR_SPEED_SEL1_1G;
4492 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_CR, value);
4494 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_IF_MODE,
4496 + | SGMII_USE_SGMII_AN
4498 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_DEV_ABIL_SGMII,
4499 + SGMII_DEV_ABIL_EEE_CLK_STP_EN
4501 + | SGMII_DEV_ABIL_SGMII);
4502 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_L, 0x400);
4503 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_LINK_TMR_H, 0x0);
4504 + value = SGMII_CR_AN_EN | SGMII_CR_FD | SGMII_CR_SPEED_SEL1_1G;
4505 + pfe_eth_mdio_write(bus, 0, MDIO_SGMII_CR, value);
4513 +static int pfe_phy_init(struct net_device *ndev)
4515 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4516 + struct phy_device *phydev;
4517 + char phy_id[MII_BUS_ID_SIZE + 3];
4518 + char bus_id[MII_BUS_ID_SIZE];
4519 + phy_interface_t interface;
4521 + priv->oldlink = 0;
4522 + priv->oldspeed = 0;
4523 + priv->oldduplex = -1;
4525 + snprintf(bus_id, MII_BUS_ID_SIZE, "ls1012a-%d", 0);
4526 + snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
4527 + priv->einfo->phy_id);
4528 + netif_info(priv, drv, ndev, "%s: %s\n", __func__, phy_id);
4529 + interface = priv->einfo->mii_config;
4530 + if ((interface == PHY_INTERFACE_MODE_SGMII) ||
4531 + (interface == PHY_INTERFACE_MODE_2500SGMII)) {
4532 + /*Configure SGMII PCS */
4534 + /* Config MDIO from serdes */
4535 + regmap_write(pfe->scfg, MDIOSELCR, MDIOSEL_SERDES);
4537 + ls1012a_configure_serdes(ndev);
4541 + /*Config MDIO from PAD */
4542 + regmap_write(pfe->scfg, MDIOSELCR, MDIOSEL_EXTPHY);
4545 + priv->oldlink = 0;
4546 + priv->oldspeed = 0;
4547 + priv->oldduplex = -1;
4548 + pr_info("%s interface %x\n", __func__, interface);
4550 + if (priv->phy_node) {
4551 + phydev = of_phy_connect(ndev, priv->phy_node,
4552 + pfe_eth_adjust_link, 0,
4553 + priv->einfo->mii_config);
4555 + netdev_err(ndev, "Unable to connect to phy\n");
4560 + phydev = phy_connect(ndev, phy_id,
4561 + &pfe_eth_adjust_link, interface);
4562 + if (IS_ERR(phydev)) {
4563 + netdev_err(ndev, "Unable to connect to phy\n");
4564 + return PTR_ERR(phydev);
4568 + priv->phydev = phydev;
4569 + phydev->irq = PHY_POLL;
4576 +static int pfe_gemac_init(struct pfe_eth_priv_s *priv)
4578 + struct gemac_cfg cfg;
4580 + netif_info(priv, ifup, priv->ndev, "%s\n", __func__);
4583 + cfg.speed = SPEED_1000M;
4584 + cfg.duplex = DUPLEX_FULL;
4586 + gemac_set_config(priv->EMAC_baseaddr, &cfg);
4587 + gemac_allow_broadcast(priv->EMAC_baseaddr);
4588 + gemac_enable_1536_rx(priv->EMAC_baseaddr);
4589 + gemac_enable_stacked_vlan(priv->EMAC_baseaddr);
4590 + gemac_enable_pause_rx(priv->EMAC_baseaddr);
4591 + gemac_set_bus_width(priv->EMAC_baseaddr, 64);
4593 + /*GEM will perform checksum verifications*/
4594 + if (priv->ndev->features & NETIF_F_RXCSUM)
4595 + gemac_enable_rx_checksum_offload(priv->EMAC_baseaddr);
4597 + gemac_disable_rx_checksum_offload(priv->EMAC_baseaddr);
4602 +/* pfe_eth_event_handler
4604 +static int pfe_eth_event_handler(void *data, int event, int qno)
4606 + struct pfe_eth_priv_s *priv = data;
4609 + case EVENT_RX_PKT_IND:
4612 + if (napi_schedule_prep(&priv->high_napi)) {
4613 + netif_info(priv, intr, priv->ndev,
4614 + "%s: schedule high prio poll\n"
4617 +#ifdef PFE_ETH_NAPI_STATS
4618 + priv->napi_counters[NAPI_SCHED_COUNT]++;
4621 + __napi_schedule(&priv->high_napi);
4623 + } else if (qno == 1) {
4624 + if (napi_schedule_prep(&priv->low_napi)) {
4625 + netif_info(priv, intr, priv->ndev,
4626 + "%s: schedule low prio poll\n"
4629 +#ifdef PFE_ETH_NAPI_STATS
4630 + priv->napi_counters[NAPI_SCHED_COUNT]++;
4632 + __napi_schedule(&priv->low_napi);
4634 + } else if (qno == 2) {
4635 + if (napi_schedule_prep(&priv->lro_napi)) {
4636 + netif_info(priv, intr, priv->ndev,
4637 + "%s: schedule lro prio poll\n"
4640 +#ifdef PFE_ETH_NAPI_STATS
4641 + priv->napi_counters[NAPI_SCHED_COUNT]++;
4643 + __napi_schedule(&priv->lro_napi);
4649 + case EVENT_TXDONE_IND:
4650 + pfe_eth_flush_tx(priv);
4651 + hif_lib_event_handler_start(&priv->client, EVENT_TXDONE_IND, 0);
4653 + case EVENT_HIGH_RX_WM:
4661 +static int pfe_eth_change_mtu(struct net_device *ndev, int new_mtu)
4663 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4665 + ndev->mtu = new_mtu;
4666 + new_mtu += ETH_HLEN + ETH_FCS_LEN;
4667 + gemac_set_rx_max_fl(priv->EMAC_baseaddr, new_mtu);
4674 +static int pfe_eth_open(struct net_device *ndev)
4676 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4677 + struct hif_client_s *client;
4680 + netif_info(priv, ifup, ndev, "%s\n", __func__);
4682 + /* Register client driver with HIF */
4683 + client = &priv->client;
4684 + memset(client, 0, sizeof(*client));
4685 + client->id = PFE_CL_GEM0 + priv->id;
4686 + client->tx_qn = emac_txq_cnt;
4687 + client->rx_qn = EMAC_RXQ_CNT;
4688 + client->priv = priv;
4689 + client->pfe = priv->pfe;
4690 + client->event_handler = pfe_eth_event_handler;
4692 + client->tx_qsize = EMAC_TXQ_DEPTH;
4693 + client->rx_qsize = EMAC_RXQ_DEPTH;
4695 + rc = hif_lib_client_register(client);
4697 + netdev_err(ndev, "%s: hif_lib_client_register(%d) failed\n",
4698 + __func__, client->id);
4702 + netif_info(priv, drv, ndev, "%s: registered client: %p\n", __func__,
4705 + pfe_gemac_init(priv);
4707 + if (!is_valid_ether_addr(ndev->dev_addr)) {
4708 + netdev_err(ndev, "%s: invalid MAC address\n", __func__);
4709 + rc = -EADDRNOTAVAIL;
4713 + gemac_set_laddrN(priv->EMAC_baseaddr,
4714 + (struct pfe_mac_addr *)ndev->dev_addr, 1);
4716 + napi_enable(&priv->high_napi);
4717 + napi_enable(&priv->low_napi);
4718 + napi_enable(&priv->lro_napi);
4720 + rc = pfe_eth_start(priv);
4722 + netif_tx_wake_all_queues(ndev);
4727 + hif_lib_client_unregister(&priv->client);
4734 + * pfe_eth_shutdown
4736 +int pfe_eth_shutdown(struct net_device *ndev, int wake)
4738 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4739 + int i, qstatus, id;
4740 + unsigned long next_poll = jiffies + 1, end = jiffies +
4741 + (TX_POLL_TIMEOUT_MS * HZ) / 1000;
4742 + int tx_pkts, prv_tx_pkts;
4744 + netif_info(priv, ifdown, ndev, "%s\n", __func__);
4746 + for (i = 0; i < emac_txq_cnt; i++)
4747 + hrtimer_cancel(&priv->fast_tx_timeout[i].timer);
4749 + netif_tx_stop_all_queues(ndev);
4753 + pfe_eth_flush_tx(priv);
4755 + for (i = 0; i < emac_txq_cnt; i++)
4756 + tx_pkts += hif_lib_tx_pending(&priv->client, i);
4759 + /*Don't wait forever, break if we cross max timeout */
4760 + if (time_after(jiffies, end)) {
4762 + "(%s)Tx is not complete after %dmsec\n",
4763 + ndev->name, TX_POLL_TIMEOUT_MS);
4767 + pr_info("%s : (%s) Waiting for tx packets to free. Pending tx pkts = %d.\n"
4768 + , __func__, ndev->name, tx_pkts);
4769 + if (need_resched())
4773 + } while (tx_pkts);
4775 + end = jiffies + (TX_POLL_TIMEOUT_MS * HZ) / 1000;
4777 + prv_tx_pkts = tmu_pkts_processed(priv->id);
4779 + * Wait till TMU transmits all pending packets
4780 + * poll tmu_qstatus and pkts processed by TMU for every 10ms
4781 + * Consider TMU is busy, If we see TMU qeueu pending or any packets
4782 + * processed by TMU
4785 + if (time_after(jiffies, next_poll)) {
4786 + tx_pkts = tmu_pkts_processed(priv->id);
4787 + qstatus = tmu_qstatus(priv->id) & 0x7ffff;
4789 + if (!qstatus && (tx_pkts == prv_tx_pkts))
4791 + /* Don't wait forever, break if we cross max
4792 + * timeout(TX_POLL_TIMEOUT_MS)
4794 + if (time_after(jiffies, end)) {
4795 + pr_err("TMU%d is busy after %dmsec\n",
4796 + priv->id, TX_POLL_TIMEOUT_MS);
4799 + prv_tx_pkts = tx_pkts;
4802 + if (need_resched())
4805 + /* Wait for some more time to complete transmitting packet if any */
4806 + next_poll = jiffies + 1;
4808 + if (time_after(jiffies, next_poll))
4810 + if (need_resched())
4814 + pfe_eth_stop(ndev, wake);
4816 + napi_disable(&priv->lro_napi);
4817 + napi_disable(&priv->low_napi);
4818 + napi_disable(&priv->high_napi);
4820 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
4821 + pe_dmem_write(id, 0, CLASS_DM_CRC_VALIDATED
4822 + + (priv->id * 4), 4);
4825 + hif_lib_client_unregister(&priv->client);
4833 +static int pfe_eth_close(struct net_device *ndev)
4835 + pfe_eth_shutdown(ndev, 0);
4842 + * return value : 1 if netdevice is configured to wakeup system
4845 +int pfe_eth_suspend(struct net_device *ndev)
4847 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4851 + gemac_set_wol(priv->EMAC_baseaddr, priv->wol);
4854 + pfe_eth_shutdown(ndev, priv->wol);
4862 +int pfe_eth_resume(struct net_device *ndev)
4864 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
4867 + gemac_set_wol(priv->EMAC_baseaddr, 0);
4868 + gemac_tx_enable(priv->EMAC_baseaddr);
4870 + return pfe_eth_open(ndev);
4873 +/* pfe_eth_get_queuenum
4875 +static int pfe_eth_get_queuenum(struct pfe_eth_priv_s *priv, struct sk_buff
4879 + unsigned long flags;
4881 + /* Get the Fast Path queue number */
4883 + * Use conntrack mark (if conntrack exists), then packet mark (if any),
4884 + * then fallback to default
4886 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) || defined(CONFIG_NF_CONNTRACK_MARK)
4888 + enum ip_conntrack_info cinfo;
4889 + struct nf_conn *ct;
4891 + ct = nf_ct_get(skb, &cinfo);
4896 + connmark = ct->mark;
4898 + if ((connmark & 0x80000000) && priv->id != 0)
4901 + queuenum = connmark & EMAC_QUEUENUM_MASK;
4903 + } else {/* continued after #endif ... */
4906 + queuenum = skb->mark & EMAC_QUEUENUM_MASK;
4908 + spin_lock_irqsave(&priv->lock, flags);
4909 + queuenum = priv->default_priority & EMAC_QUEUENUM_MASK;
4910 + spin_unlock_irqrestore(&priv->lock, flags);
4912 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) || defined(CONFIG_NF_CONNTRACK_MARK)
4918 +/* pfe_eth_might_stop_tx
4921 +static int pfe_eth_might_stop_tx(struct pfe_eth_priv_s *priv, int queuenum,
4922 + struct netdev_queue *tx_queue,
4923 + unsigned int n_desc,
4924 + unsigned int n_segs)
4930 + if (unlikely((__hif_tx_avail(&pfe->hif) < n_desc) ||
4931 + (hif_lib_tx_avail(&priv->client, queuenum) < n_desc) ||
4932 + (hif_lib_tx_credit_avail(pfe, priv->id, queuenum) < n_segs))) {
4934 + __hif_lib_update_credit(&priv->client, queuenum);
4938 +#ifdef PFE_ETH_TX_STATS
4939 + if (__hif_tx_avail(&pfe->hif) < n_desc) {
4940 + priv->stop_queue_hif[queuenum]++;
4941 + } else if (hif_lib_tx_avail(&priv->client, queuenum) < n_desc) {
4942 + priv->stop_queue_hif_client[queuenum]++;
4943 + } else if (hif_lib_tx_credit_avail(pfe, priv->id, queuenum) <
4945 + priv->stop_queue_credit[queuenum]++;
4947 + priv->stop_queue_total[queuenum]++;
4949 + netif_tx_stop_queue(tx_queue);
4951 + kt = ktime_set(0, LS1012A_TX_FAST_RECOVERY_TIMEOUT_MS *
4953 + hrtimer_start(&priv->fast_tx_timeout[queuenum].timer, kt,
4954 + HRTIMER_MODE_REL);
4961 +#define SA_MAX_OP 2
4962 +/* pfe_hif_send_packet
4964 + * At this level if TX fails we drop the packet
4966 +static void pfe_hif_send_packet(struct sk_buff *skb, struct pfe_eth_priv_s
4967 + *priv, int queuenum)
4969 + struct skb_shared_info *sh = skb_shinfo(skb);
4970 + unsigned int nr_frags;
4973 + netif_info(priv, tx_queued, priv->ndev, "%s\n", __func__);
4975 + if (skb_is_gso(skb)) {
4976 + priv->stats.tx_dropped++;
4980 + if (skb->ip_summed == CHECKSUM_PARTIAL)
4981 + ctrl = HIF_CTRL_TX_CHECKSUM;
4983 + nr_frags = sh->nr_frags;
4989 + __hif_lib_xmit_pkt(&priv->client, queuenum, skb->data,
4990 + skb_headlen(skb), ctrl, HIF_FIRST_BUFFER,
4993 + for (i = 0; i < nr_frags - 1; i++) {
4994 + f = &sh->frags[i];
4995 + __hif_lib_xmit_pkt(&priv->client, queuenum,
4996 + skb_frag_address(f),
5001 + f = &sh->frags[i];
5003 + __hif_lib_xmit_pkt(&priv->client, queuenum,
5004 + skb_frag_address(f), skb_frag_size(f),
5005 + 0x0, HIF_LAST_BUFFER | HIF_DATA_VALID,
5008 + netif_info(priv, tx_queued, priv->ndev,
5009 + "%s: pkt sent successfully skb:%p nr_frags:%d len:%d\n",
5010 + __func__, skb, nr_frags, skb->len);
5012 + __hif_lib_xmit_pkt(&priv->client, queuenum, skb->data,
5013 + skb->len, ctrl, HIF_FIRST_BUFFER |
5014 + HIF_LAST_BUFFER | HIF_DATA_VALID,
5016 + netif_info(priv, tx_queued, priv->ndev,
5017 + "%s: pkt sent successfully skb:%p len:%d\n",
5018 + __func__, skb, skb->len);
5020 + hif_tx_dma_start();
5021 + priv->stats.tx_packets++;
5022 + priv->stats.tx_bytes += skb->len;
5023 + hif_lib_tx_credit_use(pfe, priv->id, queuenum, 1);
5026 +/* pfe_eth_flush_txQ
5028 +static void pfe_eth_flush_txQ(struct pfe_eth_priv_s *priv, int tx_q_num, int
5029 + from_tx, int n_desc)
5031 + struct sk_buff *skb;
5032 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
5034 + unsigned int flags;
5036 + netif_info(priv, tx_done, priv->ndev, "%s\n", __func__);
5039 + __netif_tx_lock_bh(tx_queue);
5041 + /* Clean HIF and client queue */
5042 + while ((skb = hif_lib_tx_get_next_complete(&priv->client,
5044 + HIF_TX_DESC_NT))) {
5045 + if (flags & HIF_DATA_VALID)
5046 + dev_kfree_skb_any(skb);
5049 + __netif_tx_unlock_bh(tx_queue);
5052 +/* pfe_eth_flush_tx
5054 +static void pfe_eth_flush_tx(struct pfe_eth_priv_s *priv)
5058 + netif_info(priv, tx_done, priv->ndev, "%s\n", __func__);
5060 + for (ii = 0; ii < emac_txq_cnt; ii++) {
5061 + pfe_eth_flush_txQ(priv, ii, 0, 0);
5062 + __hif_lib_update_credit(&priv->client, ii);
5066 +void pfe_tx_get_req_desc(struct sk_buff *skb, unsigned int *n_desc, unsigned int
5069 + struct skb_shared_info *sh = skb_shinfo(skb);
5071 + /* Scattered data */
5072 + if (sh->nr_frags) {
5073 + *n_desc = sh->nr_frags + 1;
5075 + /* Regular case */
5082 +/* pfe_eth_send_packet
5084 +static int pfe_eth_send_packet(struct sk_buff *skb, struct net_device *ndev)
5086 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
5087 + int tx_q_num = skb_get_queue_mapping(skb);
5088 + int n_desc, n_segs;
5089 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
5092 + netif_info(priv, tx_queued, ndev, "%s\n", __func__);
5094 + if ((!skb_is_gso(skb)) && (skb_headroom(skb) < (PFE_PKT_HEADER_SZ +
5095 + sizeof(unsigned long)))) {
5096 + netif_warn(priv, tx_err, priv->ndev, "%s: copying skb\n",
5099 + if (pskb_expand_head(skb, (PFE_PKT_HEADER_SZ + sizeof(unsigned
5100 + long)), 0, GFP_ATOMIC)) {
5101 + /* No need to re-transmit, no way to recover*/
5103 + priv->stats.tx_dropped++;
5104 + return NETDEV_TX_OK;
5108 + pfe_tx_get_req_desc(skb, &n_desc, &n_segs);
5110 + hif_tx_lock(&pfe->hif);
5111 + if (unlikely(pfe_eth_might_stop_tx(priv, tx_q_num, tx_queue, n_desc,
5113 +#ifdef PFE_ETH_TX_STATS
5114 + if (priv->was_stopped[tx_q_num]) {
5115 + priv->clean_fail[tx_q_num]++;
5116 + priv->was_stopped[tx_q_num] = 0;
5119 + hif_tx_unlock(&pfe->hif);
5120 + return NETDEV_TX_BUSY;
5123 + pfe_hif_send_packet(skb, priv, tx_q_num);
5125 + hif_tx_unlock(&pfe->hif);
5127 + tx_queue->trans_start = jiffies;
5129 +#ifdef PFE_ETH_TX_STATS
5130 + priv->was_stopped[tx_q_num] = 0;
5133 + return NETDEV_TX_OK;
5136 +/* pfe_eth_select_queue
5139 +static u16 pfe_eth_select_queue(struct net_device *ndev, struct sk_buff *skb,
5140 + struct net_device *sb_dev)
5142 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
5144 + return pfe_eth_get_queuenum(priv, skb);
5147 +/* pfe_eth_get_stats
5149 +static struct net_device_stats *pfe_eth_get_stats(struct net_device *ndev)
5151 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
5153 + netif_info(priv, drv, ndev, "%s\n", __func__);
5155 + return &priv->stats;
5158 +/* pfe_eth_set_mac_address
5160 +static int pfe_eth_set_mac_address(struct net_device *ndev, void *addr)
5162 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
5163 + struct sockaddr *sa = addr;
5165 + netif_info(priv, drv, ndev, "%s\n", __func__);
5167 + if (!is_valid_ether_addr(sa->sa_data))
5168 + return -EADDRNOTAVAIL;
5170 + dev_addr_set(ndev, sa->sa_data);
5172 + gemac_set_laddrN(priv->EMAC_baseaddr,
5173 + (struct pfe_mac_addr *)ndev->dev_addr, 1);
5178 +/* pfe_eth_enet_addr_byte_mac
5180 +int pfe_eth_enet_addr_byte_mac(u8 *enet_byte_addr,
5181 + struct pfe_mac_addr *enet_addr)
5183 + if (!enet_byte_addr || !enet_addr) {
5187 + enet_addr->bottom = enet_byte_addr[0] |
5188 + (enet_byte_addr[1] << 8) |
5189 + (enet_byte_addr[2] << 16) |
5190 + (enet_byte_addr[3] << 24);
5191 + enet_addr->top = enet_byte_addr[4] |
5192 + (enet_byte_addr[5] << 8);
5197 +/* pfe_eth_set_multi
5199 +static void pfe_eth_set_multi(struct net_device *ndev)
5201 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
5202 + struct pfe_mac_addr hash_addr; /* hash register structure */
5203 + /* specific mac address register structure */
5204 + struct pfe_mac_addr spec_addr;
5205 + int result; /* index into hash register to set.. */
5207 + struct netdev_hw_addr *ha;
5209 + if (ndev->flags & IFF_PROMISC) {
5210 + netif_info(priv, drv, ndev, "entering promiscuous mode\n");
5212 + priv->promisc = 1;
5213 + gemac_enable_copy_all(priv->EMAC_baseaddr);
5215 + priv->promisc = 0;
5216 + gemac_disable_copy_all(priv->EMAC_baseaddr);
5219 + /* Enable broadcast frame reception if required. */
5220 + if (ndev->flags & IFF_BROADCAST) {
5221 + gemac_allow_broadcast(priv->EMAC_baseaddr);
5223 + netif_info(priv, drv, ndev,
5224 + "disabling broadcast frame reception\n");
5226 + gemac_no_broadcast(priv->EMAC_baseaddr);
5229 + if (ndev->flags & IFF_ALLMULTI) {
5230 + /* Set the hash to rx all multicast frames */
5231 + hash_addr.bottom = 0xFFFFFFFF;
5232 + hash_addr.top = 0xFFFFFFFF;
5233 + gemac_set_hash(priv->EMAC_baseaddr, &hash_addr);
5234 + netdev_for_each_uc_addr(ha, ndev) {
5235 + if (uc_count >= MAX_UC_SPEC_ADDR_REG)
5237 + pfe_eth_enet_addr_byte_mac(ha->addr, &spec_addr);
5238 + gemac_set_laddrN(priv->EMAC_baseaddr, &spec_addr,
5242 + } else if ((netdev_mc_count(ndev) > 0) || (netdev_uc_count(ndev))) {
5245 + hash_addr.bottom = 0;
5246 + hash_addr.top = 0;
5248 + netdev_for_each_mc_addr(ha, ndev) {
5251 + netif_info(priv, drv, ndev,
5252 + "adding multicast address %X:%X:%X:%X:%X:%X to gem filter\n",
5253 + addr[0], addr[1], addr[2],
5254 + addr[3], addr[4], addr[5]);
5256 + result = pfe_eth_get_hash(addr);
5258 + if (result < EMAC_HASH_REG_BITS) {
5260 + hash_addr.bottom |= (1 << result);
5262 + hash_addr.top |= (1 << (result - 32));
5269 + netdev_for_each_uc_addr(ha, ndev) {
5272 + if (++uc_count < MAX_UC_SPEC_ADDR_REG) {
5274 + "adding unicast address %02x:%02x:%02x:%02x:%02x:%02x to gem filter\n",
5275 + addr[0], addr[1], addr[2],
5276 + addr[3], addr[4], addr[5]);
5277 + pfe_eth_enet_addr_byte_mac(addr, &spec_addr);
5278 + gemac_set_laddrN(priv->EMAC_baseaddr,
5279 + &spec_addr, uc_count + 2);
5281 + netif_info(priv, drv, ndev,
5282 + "adding unicast address %02x:%02x:%02x:%02x:%02x:%02x to gem hash\n",
5283 + addr[0], addr[1], addr[2],
5284 + addr[3], addr[4], addr[5]);
5286 + result = pfe_eth_get_hash(addr);
5287 + if (result >= EMAC_HASH_REG_BITS) {
5292 + hash_addr.bottom |= (1 <<
5295 + hash_addr.top |= (1 <<
5301 + gemac_set_hash(priv->EMAC_baseaddr, &hash_addr);
5304 + if (!(netdev_uc_count(ndev) >= MAX_UC_SPEC_ADDR_REG)) {
5306 + * Check if there are any specific address HW registers that
5307 + * need to be flushed
5309 + for (uc_count = netdev_uc_count(ndev); uc_count <
5310 + MAX_UC_SPEC_ADDR_REG; uc_count++)
5311 + gemac_clear_laddrN(priv->EMAC_baseaddr, uc_count + 2);
5314 + if (ndev->flags & IFF_LOOPBACK)
5315 + gemac_set_loop(priv->EMAC_baseaddr, LB_LOCAL);
5318 +/* pfe_eth_set_features
5320 +static int pfe_eth_set_features(struct net_device *ndev, netdev_features_t
5323 + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
5326 + if (features & NETIF_F_RXCSUM)
5327 + gemac_enable_rx_checksum_offload(priv->EMAC_baseaddr);
5329 + gemac_disable_rx_checksum_offload(priv->EMAC_baseaddr);
5333 +/* pfe_eth_fast_tx_timeout
5335 +static enum hrtimer_restart pfe_eth_fast_tx_timeout(struct hrtimer *timer)
5337 + struct pfe_eth_fast_timer *fast_tx_timeout = container_of(timer, struct
5338 + pfe_eth_fast_timer,
5340 + struct pfe_eth_priv_s *priv = container_of(fast_tx_timeout->base,
5341 + struct pfe_eth_priv_s,
5343 + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
5344 + fast_tx_timeout->queuenum);
5346 + if (netif_tx_queue_stopped(tx_queue)) {
5347 +#ifdef PFE_ETH_TX_STATS
5348 + priv->was_stopped[fast_tx_timeout->queuenum] = 1;
5350 + netif_tx_wake_queue(tx_queue);
5353 + return HRTIMER_NORESTART;
5356 +/* pfe_eth_fast_tx_timeout_init
5358 +static void pfe_eth_fast_tx_timeout_init(struct pfe_eth_priv_s *priv)
5362 + for (i = 0; i < emac_txq_cnt; i++) {
5363 + priv->fast_tx_timeout[i].queuenum = i;
5364 + hrtimer_init(&priv->fast_tx_timeout[i].timer, CLOCK_MONOTONIC,
5365 + HRTIMER_MODE_REL);
5366 + priv->fast_tx_timeout[i].timer.function =
5367 + pfe_eth_fast_tx_timeout;
5368 + priv->fast_tx_timeout[i].base = priv->fast_tx_timeout;
5372 +static struct sk_buff *pfe_eth_rx_skb(struct net_device *ndev,
5373 + struct pfe_eth_priv_s *priv,
5377 + unsigned int rx_ctrl;
5378 + unsigned int desc_ctrl = 0;
5379 + struct hif_ipsec_hdr *ipsec_hdr = NULL;
5380 + struct sk_buff *skb;
5381 + struct sk_buff *skb_frag, *skb_frag_last = NULL;
5382 + int length = 0, offset;
5384 + skb = priv->skb_inflight[qno];
5387 + skb_frag_last = skb_shinfo(skb)->frag_list;
5388 + if (skb_frag_last) {
5389 + while (skb_frag_last->next)
5390 + skb_frag_last = skb_frag_last->next;
5394 + while (!(desc_ctrl & CL_DESC_LAST)) {
5395 + buf_addr = hif_lib_receive_pkt(&priv->client, qno, &length,
5396 + &offset, &rx_ctrl, &desc_ctrl,
5397 + (void **)&ipsec_hdr);
5401 +#ifdef PFE_ETH_NAPI_STATS
5402 + priv->napi_counters[NAPI_DESC_COUNT]++;
5406 + if (desc_ctrl & CL_DESC_FIRST) {
5407 + skb = build_skb(buf_addr, 0);
5408 + if (unlikely(!skb))
5411 + skb_reserve(skb, offset);
5412 + skb_put(skb, length);
5415 + if ((ndev->features & NETIF_F_RXCSUM) && (rx_ctrl &
5416 + HIF_CTRL_RX_CHECKSUMMED))
5417 + skb->ip_summed = CHECKSUM_UNNECESSARY;
5419 + skb_checksum_none_assert(skb);
5423 + if (unlikely(!skb)) {
5424 + pr_err("%s: NULL skb_inflight\n",
5429 + skb_frag = build_skb(buf_addr, 0);
5431 + if (unlikely(!skb_frag)) {
5436 + skb_reserve(skb_frag, offset);
5437 + skb_put(skb_frag, length);
5439 + skb_frag->dev = ndev;
5441 + if (skb_shinfo(skb)->frag_list)
5442 + skb_frag_last->next = skb_frag;
5444 + skb_shinfo(skb)->frag_list = skb_frag;
5446 + skb->truesize += skb_frag->truesize;
5447 + skb->data_len += length;
5448 + skb->len += length;
5449 + skb_frag_last = skb_frag;
5453 + priv->skb_inflight[qno] = NULL;
5457 + priv->skb_inflight[qno] = skb;
5461 + priv->skb_inflight[qno] = NULL;
5468 + priv->stats.rx_errors++;
5475 +static int pfe_eth_poll(struct pfe_eth_priv_s *priv, struct napi_struct *napi,
5476 + unsigned int qno, int budget)
5478 + struct net_device *ndev = priv->ndev;
5479 + struct sk_buff *skb;
5480 + int work_done = 0;
5483 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
5485 +#ifdef PFE_ETH_NAPI_STATS
5486 + priv->napi_counters[NAPI_POLL_COUNT]++;
5490 + skb = pfe_eth_rx_skb(ndev, priv, qno);
5497 + /* Packet will be processed */
5498 + skb->protocol = eth_type_trans(skb, ndev);
5500 + netif_receive_skb(skb);
5502 + priv->stats.rx_packets++;
5503 + priv->stats.rx_bytes += len;
5507 +#ifdef PFE_ETH_NAPI_STATS
5508 + priv->napi_counters[NAPI_PACKET_COUNT]++;
5511 + } while (work_done < budget);
5514 + * If no Rx receive nor cleanup work was done, exit polling mode.
5515 + * No more netif_running(dev) check is required here , as this is
5516 + * checked in net/core/dev.c (2.6.33.5 kernel specific).
5518 + if (work_done < budget) {
5519 + napi_complete(napi);
5521 + hif_lib_event_handler_start(&priv->client, EVENT_RX_PKT_IND,
5524 +#ifdef PFE_ETH_NAPI_STATS
5526 + priv->napi_counters[NAPI_FULL_BUDGET_COUNT]++;
5533 + * pfe_eth_lro_poll
5535 +static int pfe_eth_lro_poll(struct napi_struct *napi, int budget)
5537 + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
5540 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
5542 + return pfe_eth_poll(priv, napi, 2, budget);
5545 +/* pfe_eth_low_poll
5547 +static int pfe_eth_low_poll(struct napi_struct *napi, int budget)
5549 + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
5552 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
5554 + return pfe_eth_poll(priv, napi, 1, budget);
5557 +/* pfe_eth_high_poll
5559 +static int pfe_eth_high_poll(struct napi_struct *napi, int budget)
5561 + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
5564 + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
5566 + return pfe_eth_poll(priv, napi, 0, budget);
5569 +static const struct net_device_ops pfe_netdev_ops = {
5570 + .ndo_open = pfe_eth_open,
5571 + .ndo_stop = pfe_eth_close,
5572 + .ndo_start_xmit = pfe_eth_send_packet,
5573 + .ndo_select_queue = pfe_eth_select_queue,
5574 + .ndo_set_rx_mode = pfe_eth_set_multi,
5575 + .ndo_set_mac_address = pfe_eth_set_mac_address,
5576 + .ndo_validate_addr = eth_validate_addr,
5577 + .ndo_change_mtu = pfe_eth_change_mtu,
5578 + .ndo_get_stats = pfe_eth_get_stats,
5579 + .ndo_set_features = pfe_eth_set_features,
5582 +/* pfe_eth_init_one
5584 +static int pfe_eth_init_one(struct pfe *pfe,
5585 + struct ls1012a_pfe_platform_data *pfe_info,
5588 + struct net_device *ndev = NULL;
5589 + struct pfe_eth_priv_s *priv = NULL;
5590 + struct ls1012a_eth_platform_data *einfo;
5593 + einfo = (struct ls1012a_eth_platform_data *)
5594 + pfe_info->ls1012a_eth_pdata;
5596 + /* einfo never be NULL, but no harm in having this check */
5599 + "%s: pfe missing additional gemacs platform data\n"
5606 + emac_txq_cnt = EMAC_TXQ_CNT;
5607 + /* Create an ethernet device instance */
5608 + ndev = alloc_etherdev_mq(sizeof(*priv), emac_txq_cnt);
5611 + pr_err("%s: gemac %d device allocation failed\n",
5612 + __func__, einfo[id].gem_id);
5617 + priv = netdev_priv(ndev);
5618 + priv->ndev = ndev;
5619 + priv->id = einfo[id].gem_id;
5621 + priv->phy_node = einfo[id].phy_node;
5623 + SET_NETDEV_DEV(priv->ndev, priv->pfe->dev);
5625 + pfe->eth.eth_priv[id] = priv;
5627 + /* Set the info in the priv to the current info */
5628 + priv->einfo = &einfo[id];
5629 + priv->EMAC_baseaddr = cbus_emac_base[id];
5630 + priv->GPI_baseaddr = cbus_gpi_base[id];
5632 + spin_lock_init(&priv->lock);
5634 + pfe_eth_fast_tx_timeout_init(priv);
5636 + /* Copy the station address into the dev structure, */
5637 + dev_addr_set(ndev, einfo[id].mac_addr);
5644 + /* Set MTU limits */
5645 + ndev->min_mtu = ETH_MIN_MTU;
5648 + * Jumbo frames are not supported on LS1012A rev-1.0.
5649 + * So max mtu should be restricted to supported frame length.
5651 + if (pfe_errata_a010897)
5652 + ndev->max_mtu = JUMBO_FRAME_SIZE_V1 - ETH_HLEN - ETH_FCS_LEN;
5654 + ndev->max_mtu = JUMBO_FRAME_SIZE_V2 - ETH_HLEN - ETH_FCS_LEN;
5656 + /*Enable after checksum offload is validated */
5657 + ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
5658 + NETIF_F_IPV6_CSUM | NETIF_F_SG;
5660 + /* enabled by default */
5661 + ndev->features = ndev->hw_features;
5663 + priv->usr_features = ndev->features;
5665 + ndev->netdev_ops = &pfe_netdev_ops;
5667 + ndev->ethtool_ops = &pfe_ethtool_ops;
5669 + /* Enable basic messages by default */
5670 + priv->msg_enable = NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_LINK |
5673 + netif_napi_add(ndev, &priv->low_napi, pfe_eth_low_poll);
5674 + netif_napi_add(ndev, &priv->high_napi, pfe_eth_high_poll);
5675 + netif_napi_add(ndev, &priv->lro_napi, pfe_eth_lro_poll);
5677 + err = register_netdev(ndev);
5679 + netdev_err(ndev, "register_netdev() failed\n");
5683 + if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
5684 + ((pfe_use_old_dts_phy) &&
5685 + (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
5686 + pr_info("%s: No PHY or fixed-link\n", __func__);
5687 + goto skip_phy_init;
5691 + device_init_wakeup(&ndev->dev, true);
5693 + err = pfe_phy_init(ndev);
5695 + netdev_err(ndev, "%s: pfe_phy_init() failed\n",
5702 + phy_start(priv->phydev);
5706 + netif_carrier_on(ndev);
5709 + /* Create all the sysfs files */
5710 + if (pfe_eth_sysfs_init(ndev))
5713 + netif_info(priv, probe, ndev, "%s: created interface, baseaddr: %p\n",
5714 + __func__, priv->EMAC_baseaddr);
5719 + pfe_phy_exit(priv->ndev);
5723 + unregister_netdev(ndev);
5725 + free_netdev(priv->ndev);
5732 +int pfe_eth_init(struct pfe *pfe)
5736 + struct ls1012a_pfe_platform_data *pfe_info;
5738 + pr_info("%s\n", __func__);
5740 + cbus_emac_base[0] = EMAC1_BASE_ADDR;
5741 + cbus_emac_base[1] = EMAC2_BASE_ADDR;
5743 + cbus_gpi_base[0] = EGPI1_BASE_ADDR;
5744 + cbus_gpi_base[1] = EGPI2_BASE_ADDR;
5746 + pfe_info = (struct ls1012a_pfe_platform_data *)
5747 + pfe->dev->platform_data;
5749 + pr_err("%s: pfe missing additional platform data\n", __func__);
5754 + for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
5755 + err = pfe_eth_mdio_init(pfe, pfe_info, ii);
5757 + pr_err("%s: pfe_eth_mdio_init() failed\n", __func__);
5758 + goto err_mdio_init;
5762 + if (soc_device_match(ls1012a_rev1_soc_attr))
5763 + pfe_errata_a010897 = true;
5765 + pfe_errata_a010897 = false;
5767 + for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
5768 + err = pfe_eth_init_one(pfe, pfe_info, ii);
5770 + goto err_eth_init;
5777 + pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
5778 + pfe_eth_mdio_exit(pfe, ii);
5786 +/* pfe_eth_exit_one
5788 +static void pfe_eth_exit_one(struct pfe_eth_priv_s *priv)
5790 + netif_info(priv, probe, priv->ndev, "%s\n", __func__);
5793 + pfe_eth_sysfs_exit(priv->ndev);
5795 + if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
5796 + ((pfe_use_old_dts_phy) &&
5797 + (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
5798 + pr_info("%s: No PHY or fixed-link\n", __func__);
5799 + goto skip_phy_exit;
5802 + pfe_phy_exit(priv->ndev);
5806 + unregister_netdev(priv->ndev);
5808 + free_netdev(priv->ndev);
5813 +void pfe_eth_exit(struct pfe *pfe)
5817 + pr_info("%s\n", __func__);
5819 + for (ii = NUM_GEMAC_SUPPORT - 1; ii >= 0; ii--)
5820 + pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
5822 + for (ii = NUM_GEMAC_SUPPORT - 1; ii >= 0; ii--)
5823 + pfe_eth_mdio_exit(pfe, ii);
5826 +++ b/drivers/staging/fsl_ppfe/pfe_eth.h
5828 +/* SPDX-License-Identifier: GPL-2.0+ */
5830 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
5831 + * Copyright 2017 NXP
5834 +#ifndef _PFE_ETH_H_
5835 +#define _PFE_ETH_H_
5836 +#include <linux/kernel.h>
5837 +#include <linux/netdevice.h>
5838 +#include <linux/etherdevice.h>
5839 +#include <linux/ethtool.h>
5840 +#include <linux/mii.h>
5841 +#include <linux/phy.h>
5842 +#include <linux/clk.h>
5843 +#include <linux/interrupt.h>
5844 +#include <linux/time.h>
5846 +#define PFE_ETH_NAPI_STATS
5847 +#define PFE_ETH_TX_STATS
5849 +#define PFE_ETH_FRAGS_MAX (65536 / HIF_RX_PKT_MIN_SIZE)
5850 +#define LRO_LEN_COUNT_MAX 32
5851 +#define LRO_NB_COUNT_MAX 32
5853 +#define PFE_PAUSE_FLAG_ENABLE 1
5854 +#define PFE_PAUSE_FLAG_AUTONEG 2
5856 +/* GEMAC configured by SW */
5857 +/* GEMAC configured by phy lines (not for MII/GMII) */
5859 +#define GEMAC_SW_FULL_DUPLEX BIT(9)
5860 +#define GEMAC_SW_SPEED_10M (0 << 12)
5861 +#define GEMAC_SW_SPEED_100M BIT(12)
5862 +#define GEMAC_SW_SPEED_1G (2 << 12)
5864 +#define GEMAC_NO_PHY BIT(0)
5866 +struct ls1012a_eth_platform_data {
5867 + /* board specific information */
5868 + phy_interface_t mii_config;
5873 + u8 mac_addr[ETH_ALEN];
5874 + struct device_node *phy_node;
5877 +struct ls1012a_mdio_platform_data {
5884 +struct ls1012a_pfe_platform_data {
5885 + struct ls1012a_eth_platform_data ls1012a_eth_pdata[3];
5886 + struct ls1012a_mdio_platform_data ls1012a_mdio_pdata[3];
5889 +#define NUM_GEMAC_SUPPORT 2
5890 +#define DRV_NAME "pfe-eth"
5891 +#define DRV_VERSION "1.0"
5893 +#define LS1012A_TX_FAST_RECOVERY_TIMEOUT_MS 3
5894 +#define TX_POLL_TIMEOUT_MS 1000
5896 +#define EMAC_TXQ_CNT 16
5897 +#define EMAC_TXQ_DEPTH (HIF_TX_DESC_NT)
5899 +#define JUMBO_FRAME_SIZE_V1 1900
5900 +#define JUMBO_FRAME_SIZE_V2 10258
5902 + * Client Tx queue threshold, for txQ flush condition.
5903 + * It must be smaller than the queue size (in case we ever change it in the
5906 +#define HIF_CL_TX_FLUSH_MARK 32
5909 + * Max number of TX resources (HIF descriptors or skbs) that will be released
5910 + * in a single go during batch recycling.
5911 + * Should be lower than the flush mark so the SW can provide the HW with a
5912 + * continuous stream of packets instead of bursts.
5914 +#define TX_FREE_MAX_COUNT 16
5915 +#define EMAC_RXQ_CNT 3
5916 +#define EMAC_RXQ_DEPTH HIF_RX_DESC_NT
5917 +/* make sure clients can receive a full burst of packets */
5918 +#define EMAC_RMON_TXBYTES_POS 0x00
5919 +#define EMAC_RMON_RXBYTES_POS 0x14
5921 +#define EMAC_QUEUENUM_MASK (emac_txq_cnt - 1)
5922 +#define EMAC_MDIO_TIMEOUT 1000
5923 +#define MAX_UC_SPEC_ADDR_REG 31
5925 +struct pfe_eth_fast_timer {
5927 + struct hrtimer timer;
5931 +struct pfe_eth_priv_s {
5933 + struct hif_client_s client;
5934 + struct napi_struct lro_napi;
5935 + struct napi_struct low_napi;
5936 + struct napi_struct high_napi;
5939 + struct net_device_stats stats;
5940 + struct net_device *ndev;
5943 + unsigned int msg_enable;
5944 + unsigned int usr_features;
5946 + spinlock_t lock; /* protect member variables */
5947 + unsigned int event_status;
5949 + void *EMAC_baseaddr;
5950 + void *GPI_baseaddr;
5952 + struct phy_device *phydev;
5956 + struct device_node *phy_node;
5957 + struct clk *gemtx_clk;
5961 + int default_priority;
5962 + struct pfe_eth_fast_timer fast_tx_timeout[EMAC_TXQ_CNT];
5964 + struct ls1012a_eth_platform_data *einfo;
5965 + struct sk_buff *skb_inflight[EMAC_RXQ_CNT + 6];
5967 +#ifdef PFE_ETH_TX_STATS
5968 + unsigned int stop_queue_total[EMAC_TXQ_CNT];
5969 + unsigned int stop_queue_hif[EMAC_TXQ_CNT];
5970 + unsigned int stop_queue_hif_client[EMAC_TXQ_CNT];
5971 + unsigned int stop_queue_credit[EMAC_TXQ_CNT];
5972 + unsigned int clean_fail[EMAC_TXQ_CNT];
5973 + unsigned int was_stopped[EMAC_TXQ_CNT];
5976 +#ifdef PFE_ETH_NAPI_STATS
5977 + unsigned int napi_counters[NAPI_MAX_COUNT];
5979 + unsigned int frags_inflight[EMAC_RXQ_CNT + 6];
5983 + struct pfe_eth_priv_s *eth_priv[3];
5986 +struct pfe_mdio_priv_s {
5987 + void __iomem *mdio_base;
5989 + struct mii_bus *mii_bus;
5993 + struct pfe_mdio_priv_s *mdio_priv[3];
5996 +int pfe_eth_init(struct pfe *pfe);
5997 +void pfe_eth_exit(struct pfe *pfe);
5998 +int pfe_eth_suspend(struct net_device *dev);
5999 +int pfe_eth_resume(struct net_device *dev);
6000 +int pfe_eth_mdio_reset(struct mii_bus *bus);
6002 +#endif /* _PFE_ETH_H_ */
6004 +++ b/drivers/staging/fsl_ppfe/pfe_firmware.c
6006 +// SPDX-License-Identifier: GPL-2.0+
6008 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
6009 + * Copyright 2017 NXP
6014 + * Contains all the functions to handle parsing and loading of PE firmware
6017 +#include <linux/firmware.h>
6019 +#include "pfe_mod.h"
6020 +#include "pfe_firmware.h"
6021 +#include "pfe/pfe.h"
6022 +#include <linux/of_platform.h>
6023 +#include <linux/of_address.h>
6025 +static struct elf32_shdr *get_elf_section_header(const u8 *fw,
6026 + const char *section)
6028 + struct elf32_hdr *elf_hdr = (struct elf32_hdr *)fw;
6029 + struct elf32_shdr *shdr;
6030 + struct elf32_shdr *shdr_shstr;
6031 + Elf32_Off e_shoff = be32_to_cpu(elf_hdr->e_shoff);
6032 + Elf32_Half e_shentsize = be16_to_cpu(elf_hdr->e_shentsize);
6033 + Elf32_Half e_shnum = be16_to_cpu(elf_hdr->e_shnum);
6034 + Elf32_Half e_shstrndx = be16_to_cpu(elf_hdr->e_shstrndx);
6035 + Elf32_Off shstr_offset;
6036 + Elf32_Word sh_name;
6040 + /* Section header strings */
6041 + shdr_shstr = (struct elf32_shdr *)((u8 *)elf_hdr + e_shoff + e_shstrndx
6043 + shstr_offset = be32_to_cpu(shdr_shstr->sh_offset);
6045 + for (i = 0; i < e_shnum; i++) {
6046 + shdr = (struct elf32_shdr *)((u8 *)elf_hdr + e_shoff
6047 + + i * e_shentsize);
6049 + sh_name = be32_to_cpu(shdr->sh_name);
6051 + name = (const char *)((u8 *)elf_hdr + shstr_offset + sh_name);
6053 + if (!strcmp(name, section))
6057 + pr_err("%s: didn't find section %s\n", __func__, section);
6062 +#if defined(CFG_DIAGS)
6063 +static int pfe_get_diags_info(const u8 *fw, struct pfe_diags_info
6066 + struct elf32_shdr *shdr;
6067 + unsigned long offset, size;
6069 + shdr = get_elf_section_header(fw, ".pfe_diags_str");
6071 + offset = be32_to_cpu(shdr->sh_offset);
6072 + size = be32_to_cpu(shdr->sh_size);
6073 + diags_info->diags_str_base = be32_to_cpu(shdr->sh_addr);
6074 + diags_info->diags_str_size = size;
6075 + diags_info->diags_str_array = kmalloc(size, GFP_KERNEL);
6076 + memcpy(diags_info->diags_str_array, fw + offset, size);
6085 +static void pfe_check_version_info(const u8 *fw)
6087 + /*static char *version = NULL;*/
6088 + const u8 *elf_data = fw;
6089 + static char *version;
6091 + struct elf32_shdr *shdr = get_elf_section_header(fw, ".version");
6096 + * this is the first fw we load, use its version
6097 + * string as reference (whatever it is)
6099 + version = (char *)(elf_data +
6100 + be32_to_cpu(shdr->sh_offset));
6102 + pr_info("PFE binary version: %s\n", version);
6105 + * already have loaded at least one firmware, check
6106 + * sequence can start now
6108 + if (strcmp(version, (char *)(elf_data +
6109 + be32_to_cpu(shdr->sh_offset)))) {
6111 + "WARNING: PFE firmware binaries from incompatible version\n");
6116 + * version cannot be verified, a potential issue that should
6120 + "WARNING: PFE firmware binaries from incompatible version\n");
6124 +/* PFE elf firmware loader.
6125 + * Loads an elf firmware image into a list of PE's (specified using a bitmask)
6127 + * @param pe_mask Mask of PE id's to load firmware to
6128 + * @param fw Pointer to the firmware image
6130 + * @return 0 on success, a negative value on error
6133 +int pfe_load_elf(int pe_mask, const u8 *fw, struct pfe *pfe)
6135 + struct elf32_hdr *elf_hdr = (struct elf32_hdr *)fw;
6136 + Elf32_Half sections = be16_to_cpu(elf_hdr->e_shnum);
6137 + struct elf32_shdr *shdr = (struct elf32_shdr *)(fw +
6138 + be32_to_cpu(elf_hdr->e_shoff));
6142 + pr_info("%s\n", __func__);
6144 + /* Some sanity checks */
6145 + if (strncmp(&elf_hdr->e_ident[EI_MAG0], ELFMAG, SELFMAG)) {
6146 + pr_err("%s: incorrect elf magic number\n", __func__);
6150 + if (elf_hdr->e_ident[EI_CLASS] != ELFCLASS32) {
6151 + pr_err("%s: incorrect elf class(%x)\n", __func__,
6152 + elf_hdr->e_ident[EI_CLASS]);
6156 + if (elf_hdr->e_ident[EI_DATA] != ELFDATA2MSB) {
6157 + pr_err("%s: incorrect elf data(%x)\n", __func__,
6158 + elf_hdr->e_ident[EI_DATA]);
6162 + if (be16_to_cpu(elf_hdr->e_type) != ET_EXEC) {
6163 + pr_err("%s: incorrect elf file type(%x)\n", __func__,
6164 + be16_to_cpu(elf_hdr->e_type));
6168 + for (section = 0; section < sections; section++, shdr++) {
6169 + if (!(be32_to_cpu(shdr->sh_flags) & (SHF_WRITE | SHF_ALLOC |
6173 + for (id = 0; id < MAX_PE; id++)
6174 + if (pe_mask & (1 << id)) {
6175 + rc = pe_load_elf_section(id, elf_hdr, shdr,
6182 + pfe_check_version_info(fw);
6190 +int get_firmware_in_fdt(const u8 **pe_fw, const char *name)
6192 + struct device_node *np;
6193 + const unsigned int *len;
6196 + if (!strcmp(name, CLASS_FIRMWARE_FILENAME)) {
6197 + /* The firmware should be inside the device tree. */
6198 + np = of_find_compatible_node(NULL, NULL,
6199 + "fsl,pfe-class-firmware");
6201 + pr_info("Failed to find the node\n");
6205 + data = of_get_property(np, "fsl,class-firmware", NULL);
6207 + len = of_get_property(np, "length", NULL);
6208 + pr_info("CLASS fw of length %d bytes loaded from FDT.\n",
6209 + be32_to_cpu(*len));
6211 + pr_info("fsl,class-firmware not found!!!!\n");
6216 + } else if (!strcmp(name, TMU_FIRMWARE_FILENAME)) {
6217 + np = of_find_compatible_node(NULL, NULL,
6218 + "fsl,pfe-tmu-firmware");
6220 + pr_info("Failed to find the node\n");
6224 + data = of_get_property(np, "fsl,tmu-firmware", NULL);
6226 + len = of_get_property(np, "length", NULL);
6227 + pr_info("TMU fw of length %d bytes loaded from FDT.\n",
6228 + be32_to_cpu(*len));
6230 + pr_info("fsl,tmu-firmware not found!!!!\n");
6235 + } else if (!strcmp(name, UTIL_FIRMWARE_FILENAME)) {
6236 + np = of_find_compatible_node(NULL, NULL,
6237 + "fsl,pfe-util-firmware");
6239 + pr_info("Failed to find the node\n");
6243 + data = of_get_property(np, "fsl,util-firmware", NULL);
6245 + len = of_get_property(np, "length", NULL);
6246 + pr_info("UTIL fw of length %d bytes loaded from FDT.\n",
6247 + be32_to_cpu(*len));
6249 + pr_info("fsl,util-firmware not found!!!!\n");
6255 + pr_err("firmware:%s not known\n", name);
6262 +/* PFE firmware initialization.
6263 + * Loads different firmware files from filesystem.
6264 + * Initializes PE IMEM/DMEM and UTIL-PE DDR
6265 + * Initializes control path symbol addresses (by looking them up in the elf
6267 + * Takes PE's out of reset
6269 + * @return 0 on success, a negative value on error
6272 +int pfe_firmware_init(struct pfe *pfe)
6274 + const struct firmware *class_fw, *tmu_fw;
6275 + const u8 *class_elf_fw, *tmu_elf_fw;
6276 + int rc = 0, fs_load = 0;
6277 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6278 + const struct firmware *util_fw;
6279 + const u8 *util_elf_fw;
6283 + pr_info("%s\n", __func__);
6285 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6286 + if (get_firmware_in_fdt(&class_elf_fw, CLASS_FIRMWARE_FILENAME) ||
6287 + get_firmware_in_fdt(&tmu_elf_fw, TMU_FIRMWARE_FILENAME) ||
6288 + get_firmware_in_fdt(&util_elf_fw, UTIL_FIRMWARE_FILENAME))
6290 + if (get_firmware_in_fdt(&class_elf_fw, CLASS_FIRMWARE_FILENAME) ||
6291 + get_firmware_in_fdt(&tmu_elf_fw, TMU_FIRMWARE_FILENAME))
6294 + pr_info("%s:PFE firmware not found in FDT.\n", __func__);
6295 + pr_info("%s:Trying to load firmware from filesystem...!\n", __func__);
6297 + /* look for firmware in filesystem...!*/
6299 + if (request_firmware(&class_fw, CLASS_FIRMWARE_FILENAME, pfe->dev)) {
6300 + pr_err("%s: request firmware %s failed\n", __func__,
6301 + CLASS_FIRMWARE_FILENAME);
6305 + class_elf_fw = class_fw->data;
6307 + if (request_firmware(&tmu_fw, TMU_FIRMWARE_FILENAME, pfe->dev)) {
6308 + pr_err("%s: request firmware %s failed\n", __func__,
6309 + TMU_FIRMWARE_FILENAME);
6313 + tmu_elf_fw = tmu_fw->data;
6315 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6316 + if (request_firmware(&util_fw, UTIL_FIRMWARE_FILENAME, pfe->dev)) {
6317 + pr_err("%s: request firmware %s failed\n", __func__,
6318 + UTIL_FIRMWARE_FILENAME);
6322 + util_elf_fw = util_fw->data;
6326 + rc = pfe_load_elf(CLASS_MASK, class_elf_fw, pfe);
6328 + pr_err("%s: class firmware load failed\n", __func__);
6332 +#if defined(CFG_DIAGS)
6333 + rc = pfe_get_diags_info(class_elf_fw, &pfe->diags.class_diags_info);
6336 + "PFE diags won't be available for class PEs\n");
6341 + rc = pfe_load_elf(TMU_MASK, tmu_elf_fw, pfe);
6343 + pr_err("%s: tmu firmware load failed\n", __func__);
6347 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6348 + rc = pfe_load_elf(UTIL_MASK, util_elf_fw, pfe);
6350 + pr_err("%s: util firmware load failed\n", __func__);
6354 +#if defined(CFG_DIAGS)
6355 + rc = pfe_get_diags_info(util_elf_fw, &pfe->diags.util_diags_info);
6358 + "PFE diags won't be available for util PE\n");
6370 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6372 + release_firmware(util_fw);
6376 + release_firmware(tmu_fw);
6380 + release_firmware(class_fw);
6386 +/* PFE firmware cleanup
6387 + * Puts PE's in reset
6391 +void pfe_firmware_exit(struct pfe *pfe)
6393 + pr_info("%s\n", __func__);
6395 + if (pe_reset_all(&pfe->ctrl) != 0)
6396 + pr_err("Error: Failed to stop PEs, PFE reload may not work correctly\n");
6400 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6405 +++ b/drivers/staging/fsl_ppfe/pfe_firmware.h
6407 +/* SPDX-License-Identifier: GPL-2.0+ */
6409 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
6410 + * Copyright 2017 NXP
6413 +#ifndef _PFE_FIRMWARE_H_
6414 +#define _PFE_FIRMWARE_H_
6416 +#define CLASS_FIRMWARE_FILENAME "ppfe_class_ls1012a.elf"
6417 +#define TMU_FIRMWARE_FILENAME "ppfe_tmu_ls1012a.elf"
6418 +#define UTIL_FIRMWARE_FILENAME "ppfe_util_ls1012a.elf"
6420 +#define PFE_FW_CHECK_PASS 0
6421 +#define PFE_FW_CHECK_FAIL 1
6422 +#define NUM_PFE_FW 3
6424 +int pfe_firmware_init(struct pfe *pfe);
6425 +void pfe_firmware_exit(struct pfe *pfe);
6427 +#endif /* _PFE_FIRMWARE_H_ */
6429 +++ b/drivers/staging/fsl_ppfe/pfe_hal.c
6431 +// SPDX-License-Identifier: GPL-2.0+
6433 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
6434 + * Copyright 2017 NXP
6437 +#include "pfe_mod.h"
6438 +#include "pfe/pfe.h"
6440 +/* A-010897: Jumbo frame is not supported */
6441 +extern bool pfe_errata_a010897;
6443 +#define PFE_RCR_MAX_FL_MASK 0xC000FFFF
6445 +void *cbus_base_addr;
6446 +void *ddr_base_addr;
6447 +unsigned long ddr_phys_base_addr;
6448 +unsigned int ddr_size;
6450 +static struct pe_info pe[MAX_PE];
6452 +/* Initializes the PFE library.
6453 + * Must be called before using any of the library functions.
6455 + * @param[in] cbus_base CBUS virtual base address (as mapped in
6456 + * the host CPU address space)
6457 + * @param[in] ddr_base PFE DDR range virtual base address (as
6458 + * mapped in the host CPU address space)
6459 + * @param[in] ddr_phys_base PFE DDR range physical base address (as
6460 + * mapped in platform)
6461 + * @param[in] size PFE DDR range size (as defined by the host
6464 +void pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
6465 + unsigned int size)
6467 + cbus_base_addr = cbus_base;
6468 + ddr_base_addr = ddr_base;
6469 + ddr_phys_base_addr = ddr_phys_base;
6472 + pe[CLASS0_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(0);
6473 + pe[CLASS0_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(0);
6474 + pe[CLASS0_ID].pmem_size = CLASS_IMEM_SIZE;
6475 + pe[CLASS0_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
6476 + pe[CLASS0_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
6477 + pe[CLASS0_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
6479 + pe[CLASS1_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(1);
6480 + pe[CLASS1_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(1);
6481 + pe[CLASS1_ID].pmem_size = CLASS_IMEM_SIZE;
6482 + pe[CLASS1_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
6483 + pe[CLASS1_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
6484 + pe[CLASS1_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
6486 + pe[CLASS2_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(2);
6487 + pe[CLASS2_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(2);
6488 + pe[CLASS2_ID].pmem_size = CLASS_IMEM_SIZE;
6489 + pe[CLASS2_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
6490 + pe[CLASS2_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
6491 + pe[CLASS2_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
6493 + pe[CLASS3_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(3);
6494 + pe[CLASS3_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(3);
6495 + pe[CLASS3_ID].pmem_size = CLASS_IMEM_SIZE;
6496 + pe[CLASS3_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
6497 + pe[CLASS3_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
6498 + pe[CLASS3_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
6500 + pe[CLASS4_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(4);
6501 + pe[CLASS4_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(4);
6502 + pe[CLASS4_ID].pmem_size = CLASS_IMEM_SIZE;
6503 + pe[CLASS4_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
6504 + pe[CLASS4_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
6505 + pe[CLASS4_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
6507 + pe[CLASS5_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(5);
6508 + pe[CLASS5_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(5);
6509 + pe[CLASS5_ID].pmem_size = CLASS_IMEM_SIZE;
6510 + pe[CLASS5_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
6511 + pe[CLASS5_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
6512 + pe[CLASS5_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
6514 + pe[TMU0_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(0);
6515 + pe[TMU0_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(0);
6516 + pe[TMU0_ID].pmem_size = TMU_IMEM_SIZE;
6517 + pe[TMU0_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
6518 + pe[TMU0_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
6519 + pe[TMU0_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
6521 + pe[TMU1_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(1);
6522 + pe[TMU1_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(1);
6523 + pe[TMU1_ID].pmem_size = TMU_IMEM_SIZE;
6524 + pe[TMU1_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
6525 + pe[TMU1_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
6526 + pe[TMU1_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
6528 + pe[TMU3_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(3);
6529 + pe[TMU3_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(3);
6530 + pe[TMU3_ID].pmem_size = TMU_IMEM_SIZE;
6531 + pe[TMU3_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
6532 + pe[TMU3_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
6533 + pe[TMU3_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
6535 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6536 + pe[UTIL_ID].dmem_base_addr = UTIL_DMEM_BASE_ADDR;
6537 + pe[UTIL_ID].mem_access_wdata = UTIL_MEM_ACCESS_WDATA;
6538 + pe[UTIL_ID].mem_access_addr = UTIL_MEM_ACCESS_ADDR;
6539 + pe[UTIL_ID].mem_access_rdata = UTIL_MEM_ACCESS_RDATA;
6543 +/* Writes a buffer to PE internal memory from the host
6544 + * through indirect access registers.
6546 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6548 + * @param[in] src Buffer source address
6549 + * @param[in] mem_access_addr DMEM destination address (must be 32bit
6551 + * @param[in] len Number of bytes to copy
6553 +void pe_mem_memcpy_to32(int id, u32 mem_access_addr, const void *src, unsigned
6556 + u32 offset = 0, val, addr;
6557 + unsigned int len32 = len >> 2;
6560 + addr = mem_access_addr | PE_MEM_ACCESS_WRITE |
6561 + PE_MEM_ACCESS_BYTE_ENABLE(0, 4);
6563 + for (i = 0; i < len32; i++, offset += 4, src += 4) {
6564 + val = *(u32 *)src;
6565 + writel(cpu_to_be32(val), pe[id].mem_access_wdata);
6566 + writel(addr + offset, pe[id].mem_access_addr);
6569 + len = (len & 0x3);
6573 + addr = (mem_access_addr | PE_MEM_ACCESS_WRITE |
6574 + PE_MEM_ACCESS_BYTE_ENABLE(0, len)) + offset;
6576 + for (i = 0; i < len; i++, src++)
6577 + val |= (*(u8 *)src) << (8 * i);
6579 + writel(cpu_to_be32(val), pe[id].mem_access_wdata);
6580 + writel(addr, pe[id].mem_access_addr);
6584 +/* Writes a buffer to PE internal data memory (DMEM) from the host
6585 + * through indirect access registers.
6586 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6588 + * @param[in] src Buffer source address
6589 + * @param[in] dst DMEM destination address (must be 32bit
6591 + * @param[in] len Number of bytes to copy
6593 +void pe_dmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len)
6595 + pe_mem_memcpy_to32(id, pe[id].dmem_base_addr | dst |
6596 + PE_MEM_ACCESS_DMEM, src, len);
6599 +/* Writes a buffer to PE internal program memory (PMEM) from the host
6600 + * through indirect access registers.
6601 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6603 + * @param[in] src Buffer source address
6604 + * @param[in] dst PMEM destination address (must be 32bit
6606 + * @param[in] len Number of bytes to copy
6608 +void pe_pmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len)
6610 + pe_mem_memcpy_to32(id, pe[id].pmem_base_addr | (dst & (pe[id].pmem_size
6611 + - 1)) | PE_MEM_ACCESS_IMEM, src, len);
6614 +/* Reads PE internal program memory (IMEM) from the host
6615 + * through indirect access registers.
6616 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6618 + * @param[in] addr PMEM read address (must be aligned on size)
6619 + * @param[in] size Number of bytes to read (maximum 4, must not
6620 + * cross 32bit boundaries)
6621 + * @return the data read (in PE endianness, i.e BE).
6623 +u32 pe_pmem_read(int id, u32 addr, u8 size)
6625 + u32 offset = addr & 0x3;
6626 + u32 mask = 0xffffffff >> ((4 - size) << 3);
6629 + addr = pe[id].pmem_base_addr | ((addr & ~0x3) & (pe[id].pmem_size - 1))
6630 + | PE_MEM_ACCESS_IMEM | PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
6632 + writel(addr, pe[id].mem_access_addr);
6633 + val = be32_to_cpu(readl(pe[id].mem_access_rdata));
6635 + return (val >> (offset << 3)) & mask;
6638 +/* Writes PE internal data memory (DMEM) from the host
6639 + * through indirect access registers.
6640 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6642 + * @param[in] addr DMEM write address (must be aligned on size)
6643 + * @param[in] val Value to write (in PE endianness, i.e BE)
6644 + * @param[in] size Number of bytes to write (maximum 4, must not
6645 + * cross 32bit boundaries)
6647 +void pe_dmem_write(int id, u32 val, u32 addr, u8 size)
6649 + u32 offset = addr & 0x3;
6651 + addr = pe[id].dmem_base_addr | (addr & ~0x3) | PE_MEM_ACCESS_WRITE |
6652 + PE_MEM_ACCESS_DMEM | PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
6654 + /* Indirect access interface is byte swapping data being written */
6655 + writel(cpu_to_be32(val << (offset << 3)), pe[id].mem_access_wdata);
6656 + writel(addr, pe[id].mem_access_addr);
6659 +/* Reads PE internal data memory (DMEM) from the host
6660 + * through indirect access registers.
6661 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6663 + * @param[in] addr DMEM read address (must be aligned on size)
6664 + * @param[in] size Number of bytes to read (maximum 4, must not
6665 + * cross 32bit boundaries)
6666 + * @return the data read (in PE endianness, i.e BE).
6668 +u32 pe_dmem_read(int id, u32 addr, u8 size)
6670 + u32 offset = addr & 0x3;
6671 + u32 mask = 0xffffffff >> ((4 - size) << 3);
6674 + addr = pe[id].dmem_base_addr | (addr & ~0x3) | PE_MEM_ACCESS_DMEM |
6675 + PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
6677 + writel(addr, pe[id].mem_access_addr);
6679 + /* Indirect access interface is byte swapping data being read */
6680 + val = be32_to_cpu(readl(pe[id].mem_access_rdata));
6682 + return (val >> (offset << 3)) & mask;
6685 +/* This function is used to write to CLASS internal bus peripherals (ccu,
6686 + * pe-lem) from the host
6687 + * through indirect access registers.
6688 + * @param[in] val value to write
6689 + * @param[in] addr Address to write to (must be aligned on size)
6690 + * @param[in] size Number of bytes to write (1, 2 or 4)
6693 +void class_bus_write(u32 val, u32 addr, u8 size)
6695 + u32 offset = addr & 0x3;
6697 + writel((addr & CLASS_BUS_ACCESS_BASE_MASK), CLASS_BUS_ACCESS_BASE);
6699 + addr = (addr & ~CLASS_BUS_ACCESS_BASE_MASK) | PE_MEM_ACCESS_WRITE |
6702 + writel(cpu_to_be32(val << (offset << 3)), CLASS_BUS_ACCESS_WDATA);
6703 + writel(addr, CLASS_BUS_ACCESS_ADDR);
6706 +/* Reads from CLASS internal bus peripherals (ccu, pe-lem) from the host
6707 + * through indirect access registers.
6708 + * @param[in] addr Address to read from (must be aligned on size)
6709 + * @param[in] size Number of bytes to read (1, 2 or 4)
6710 + * @return the read data
6713 +u32 class_bus_read(u32 addr, u8 size)
6715 + u32 offset = addr & 0x3;
6716 + u32 mask = 0xffffffff >> ((4 - size) << 3);
6719 + writel((addr & CLASS_BUS_ACCESS_BASE_MASK), CLASS_BUS_ACCESS_BASE);
6721 + addr = (addr & ~CLASS_BUS_ACCESS_BASE_MASK) | (size << 24);
6723 + writel(addr, CLASS_BUS_ACCESS_ADDR);
6724 + val = be32_to_cpu(readl(CLASS_BUS_ACCESS_RDATA));
6726 + return (val >> (offset << 3)) & mask;
6729 +/* Writes data to the cluster memory (PE_LMEM)
6730 + * @param[in] dst PE LMEM destination address (must be 32bit aligned)
6731 + * @param[in] src Buffer source address
6732 + * @param[in] len Number of bytes to copy
6734 +void class_pe_lmem_memcpy_to32(u32 dst, const void *src, unsigned int len)
6736 + u32 len32 = len >> 2;
6739 + for (i = 0; i < len32; i++, src += 4, dst += 4)
6740 + class_bus_write(*(u32 *)src, dst, 4);
6743 + class_bus_write(*(u16 *)src, dst, 2);
6749 + class_bus_write(*(u8 *)src, dst, 1);
6755 +/* Writes value to the cluster memory (PE_LMEM)
6756 + * @param[in] dst PE LMEM destination address (must be 32bit aligned)
6757 + * @param[in] val Value to write
6758 + * @param[in] len Number of bytes to write
6760 +void class_pe_lmem_memset(u32 dst, int val, unsigned int len)
6762 + u32 len32 = len >> 2;
6765 + val = val | (val << 8) | (val << 16) | (val << 24);
6767 + for (i = 0; i < len32; i++, dst += 4)
6768 + class_bus_write(val, dst, 4);
6771 + class_bus_write(val, dst, 2);
6776 + class_bus_write(val, dst, 1);
6781 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6783 +/* Writes UTIL program memory (DDR) from the host.
6785 + * @param[in] addr Address to write (virtual, must be aligned on size)
6786 + * @param[in] val Value to write (in PE endianness, i.e BE)
6787 + * @param[in] size Number of bytes to write (2 or 4)
6789 +static void util_pmem_write(u32 val, void *addr, u8 size)
6791 + void *addr64 = (void *)((unsigned long)addr & ~0x7);
6792 + unsigned long off = 8 - ((unsigned long)addr & 0x7) - size;
6795 + * IMEM should be loaded as a 64bit swapped value in a 64bit aligned
6799 + writel(be32_to_cpu(val), addr64 + off);
6801 + writew(be16_to_cpu((u16)val), addr64 + off);
6804 +/* Writes a buffer to UTIL program memory (DDR) from the host.
6806 + * @param[in] dst Address to write (virtual, must be at least 16bit
6808 + * @param[in] src Buffer to write (in PE endianness, i.e BE, must have
6809 + * same alignment as dst)
6810 + * @param[in] len Number of bytes to write (must be at least 16bit
6813 +static void util_pmem_memcpy(void *dst, const void *src, unsigned int len)
6815 + unsigned int len32;
6818 + if ((unsigned long)src & 0x2) {
6819 + util_pmem_write(*(u16 *)src, dst, 2);
6827 + for (i = 0; i < len32; i++, dst += 4, src += 4)
6828 + util_pmem_write(*(u32 *)src, dst, 4);
6831 + util_pmem_write(*(u16 *)src, dst, len & 0x2);
6835 +/* Loads an elf section into pmem
6836 + * Code needs to be at least 16bit aligned and only PROGBITS sections are
6839 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID, ...,
6841 + * @param[in] data pointer to the elf firmware
6842 + * @param[in] shdr pointer to the elf section header
6845 +static int pe_load_pmem_section(int id, const void *data,
6846 + struct elf32_shdr *shdr)
6848 + u32 offset = be32_to_cpu(shdr->sh_offset);
6849 + u32 addr = be32_to_cpu(shdr->sh_addr);
6850 + u32 size = be32_to_cpu(shdr->sh_size);
6851 + u32 type = be32_to_cpu(shdr->sh_type);
6853 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
6854 + if (id == UTIL_ID) {
6855 + pr_err("%s: unsupported pmem section for UTIL\n",
6861 + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
6863 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
6864 + , __func__, addr, (unsigned long)data + offset);
6870 + pr_err("%s: load address(%x) is not 16bit aligned\n",
6876 + pr_err("%s: load size(%x) is not 16bit aligned\n",
6882 + case SHT_PROGBITS:
6883 + pe_pmem_memcpy_to32(id, addr, data + offset, size);
6888 + pr_err("%s: unsupported section type(%x)\n", __func__,
6896 +/* Loads an elf section into dmem
6897 + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
6898 + * initialized to 0
6900 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6902 + * @param[in] data pointer to the elf firmware
6903 + * @param[in] shdr pointer to the elf section header
6906 +static int pe_load_dmem_section(int id, const void *data,
6907 + struct elf32_shdr *shdr)
6909 + u32 offset = be32_to_cpu(shdr->sh_offset);
6910 + u32 addr = be32_to_cpu(shdr->sh_addr);
6911 + u32 size = be32_to_cpu(shdr->sh_size);
6912 + u32 type = be32_to_cpu(shdr->sh_type);
6913 + u32 size32 = size >> 2;
6916 + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
6918 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n",
6919 + __func__, addr, (unsigned long)data + offset);
6925 + pr_err("%s: load address(%x) is not 32bit aligned\n",
6931 + case SHT_PROGBITS:
6932 + pe_dmem_memcpy_to32(id, addr, data + offset, size);
6936 + for (i = 0; i < size32; i++, addr += 4)
6937 + pe_dmem_write(id, 0, addr, 4);
6940 + pe_dmem_write(id, 0, addr, size & 0x3);
6945 + pr_err("%s: unsupported section type(%x)\n", __func__,
6953 +/* Loads an elf section into DDR
6954 + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
6955 + * initialized to 0
6957 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
6959 + * @param[in] data pointer to the elf firmware
6960 + * @param[in] shdr pointer to the elf section header
6963 +static int pe_load_ddr_section(int id, const void *data,
6964 + struct elf32_shdr *shdr,
6965 + struct device *dev) {
6966 + u32 offset = be32_to_cpu(shdr->sh_offset);
6967 + u32 addr = be32_to_cpu(shdr->sh_addr);
6968 + u32 size = be32_to_cpu(shdr->sh_size);
6969 + u32 type = be32_to_cpu(shdr->sh_type);
6970 + u32 flags = be32_to_cpu(shdr->sh_flags);
6973 + case SHT_PROGBITS:
6974 + if (flags & SHF_EXECINSTR) {
6975 + if (id <= CLASS_MAX_ID) {
6976 + /* DO the loading only once in DDR */
6977 + if (id == CLASS0_ID) {
6979 + "%s: load address(%x) and elf file address(%lx) rcvd\n",
6981 + (unsigned long)data + offset);
6982 + if (((unsigned long)(data + offset)
6983 + & 0x3) != (addr & 0x3)) {
6985 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
6987 + (unsigned long)data + offset);
6994 + "%s: load address(%x) is not 16bit aligned\n"
6995 + , __func__, addr);
7001 + "%s: load length(%x) is not 16bit aligned\n"
7002 + , __func__, size);
7005 + memcpy(DDR_PHYS_TO_VIRT(
7006 + DDR_PFE_TO_PHYS(addr)),
7007 + data + offset, size);
7009 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
7010 + } else if (id == UTIL_ID) {
7011 + if (((unsigned long)(data + offset) & 0x3)
7012 + != (addr & 0x3)) {
7014 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
7016 + (unsigned long)data + offset);
7023 + "%s: load address(%x) is not 16bit aligned\n"
7024 + , __func__, addr);
7030 + "%s: load length(%x) is not 16bit aligned\n"
7031 + , __func__, size);
7035 + util_pmem_memcpy(DDR_PHYS_TO_VIRT(
7036 + DDR_PFE_TO_PHYS(addr)),
7037 + data + offset, size);
7042 + "%s: unsupported ddr section type(%x) for PE(%d)\n"
7043 + , __func__, type, id);
7048 + memcpy(DDR_PHYS_TO_VIRT(DDR_PFE_TO_PHYS(addr)), data
7055 + memset(DDR_PHYS_TO_VIRT(DDR_PFE_TO_PHYS(addr)), 0, size);
7060 + pr_err("%s: unsupported section type(%x)\n", __func__,
7068 +/* Loads an elf section into pe lmem
7069 + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
7070 + * initialized to 0
7072 + * @param[in] id PE identification (CLASS0_ID,..., CLASS5_ID)
7073 + * @param[in] data pointer to the elf firmware
7074 + * @param[in] shdr pointer to the elf section header
7077 +static int pe_load_pe_lmem_section(int id, const void *data,
7078 + struct elf32_shdr *shdr)
7080 + u32 offset = be32_to_cpu(shdr->sh_offset);
7081 + u32 addr = be32_to_cpu(shdr->sh_addr);
7082 + u32 size = be32_to_cpu(shdr->sh_size);
7083 + u32 type = be32_to_cpu(shdr->sh_type);
7085 + if (id > CLASS_MAX_ID) {
7087 + "%s: unsupported pe-lmem section type(%x) for PE(%d)\n",
7088 + __func__, type, id);
7092 + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
7094 + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n",
7095 + __func__, addr, (unsigned long)data + offset);
7101 + pr_err("%s: load address(%x) is not 32bit aligned\n",
7107 + case SHT_PROGBITS:
7108 + class_pe_lmem_memcpy_to32(addr, data + offset, size);
7112 + class_pe_lmem_memset(addr, 0, size);
7116 + pr_err("%s: unsupported section type(%x)\n", __func__,
7124 +/* Loads an elf section into a PE
7125 + * For now only supports loading a section to dmem (all PE's), pmem (class and
7127 + * DDDR (util PE code)
7129 + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
7131 + * @param[in] data pointer to the elf firmware
7132 + * @param[in] shdr pointer to the elf section header
7135 +int pe_load_elf_section(int id, const void *data, struct elf32_shdr *shdr,
7136 + struct device *dev) {
7137 + u32 addr = be32_to_cpu(shdr->sh_addr);
7138 + u32 size = be32_to_cpu(shdr->sh_size);
7140 + if (IS_DMEM(addr, size))
7141 + return pe_load_dmem_section(id, data, shdr);
7142 + else if (IS_PMEM(addr, size))
7143 + return pe_load_pmem_section(id, data, shdr);
7144 + else if (IS_PFE_LMEM(addr, size))
7146 + else if (IS_PHYS_DDR(addr, size))
7147 + return pe_load_ddr_section(id, data, shdr, dev);
7148 + else if (IS_PE_LMEM(addr, size))
7149 + return pe_load_pe_lmem_section(id, data, shdr);
7151 + pr_err("%s: unsupported memory range(%x)\n", __func__,
7156 +/**************************** BMU ***************************/
7158 +/* Initializes a BMU block.
7159 + * @param[in] base BMU block base address
7160 + * @param[in] cfg BMU configuration
7162 +void bmu_init(void *base, struct BMU_CFG *cfg)
7164 + bmu_disable(base);
7166 + bmu_set_config(base, cfg);
7171 +/* Resets a BMU block.
7172 + * @param[in] base BMU block base address
7174 +void bmu_reset(void *base)
7176 + writel(CORE_SW_RESET, base + BMU_CTRL);
7178 + /* Wait for self clear */
7179 + while (readl(base + BMU_CTRL) & CORE_SW_RESET)
7183 +/* Enabled a BMU block.
7184 + * @param[in] base BMU block base address
7186 +void bmu_enable(void *base)
7188 + writel(CORE_ENABLE, base + BMU_CTRL);
7191 +/* Disables a BMU block.
7192 + * @param[in] base BMU block base address
7194 +void bmu_disable(void *base)
7196 + writel(CORE_DISABLE, base + BMU_CTRL);
7199 +/* Sets the configuration of a BMU block.
7200 + * @param[in] base BMU block base address
7201 + * @param[in] cfg BMU configuration
7203 +void bmu_set_config(void *base, struct BMU_CFG *cfg)
7205 + writel(cfg->baseaddr, base + BMU_UCAST_BASE_ADDR);
7206 + writel(cfg->count & 0xffff, base + BMU_UCAST_CONFIG);
7207 + writel(cfg->size & 0xffff, base + BMU_BUF_SIZE);
7209 + /* Interrupts are never used */
7210 + writel(cfg->low_watermark, base + BMU_LOW_WATERMARK);
7211 + writel(cfg->high_watermark, base + BMU_HIGH_WATERMARK);
7212 + writel(0x0, base + BMU_INT_ENABLE);
7215 +/**************************** MTIP GEMAC ***************************/
7217 +/* Enable Rx Checksum Engine. With this enabled, Frame with bad IP,
7218 + * TCP or UDP checksums are discarded
7220 + * @param[in] base GEMAC base address.
7222 +void gemac_enable_rx_checksum_offload(void *base)
7224 + /*Do not find configuration to do this */
7227 +/* Disable Rx Checksum Engine.
7229 + * @param[in] base GEMAC base address.
7231 +void gemac_disable_rx_checksum_offload(void *base)
7233 + /*Do not find configuration to do this */
7236 +/* GEMAC set speed.
7237 + * @param[in] base GEMAC base address
7238 + * @param[in] speed GEMAC speed (10, 100 or 1000 Mbps)
7240 +void gemac_set_speed(void *base, enum mac_speed gem_speed)
7242 + u32 ecr = readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_SPEED;
7243 + u32 rcr = readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_RMII_10T;
7245 + switch (gem_speed) {
7247 + rcr |= EMAC_RCNTRL_RMII_10T;
7251 + ecr |= EMAC_ECNTRL_SPEED;
7256 + /*It is in 100M mode */
7259 + writel(ecr, (base + EMAC_ECNTRL_REG));
7260 + writel(rcr, (base + EMAC_RCNTRL_REG));
7263 +/* GEMAC set duplex.
7264 + * @param[in] base GEMAC base address
7265 + * @param[in] duplex GEMAC duplex mode (Full, Half)
7267 +void gemac_set_duplex(void *base, int duplex)
7269 + if (duplex == DUPLEX_HALF) {
7270 + writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_FDEN, base
7271 + + EMAC_TCNTRL_REG);
7272 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_DRT, (base
7273 + + EMAC_RCNTRL_REG));
7275 + writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_FDEN, base
7276 + + EMAC_TCNTRL_REG);
7277 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_DRT, (base
7278 + + EMAC_RCNTRL_REG));
7283 + * @param[in] base GEMAC base address
7284 + * @param[in] mode GEMAC operation mode (MII, RMII, RGMII, SGMII)
7286 +void gemac_set_mode(void *base, int mode)
7288 + u32 val = readl(base + EMAC_RCNTRL_REG);
7290 + /*Remove loopbank*/
7291 + val &= ~EMAC_RCNTRL_LOOP;
7293 + /* Enable flow control and MII mode.PFE firmware always expects
7294 + CRC should be forwarded by MAC to validate CRC in software.*/
7295 + val |= (EMAC_RCNTRL_FCE | EMAC_RCNTRL_MII_MODE);
7297 + writel(val, base + EMAC_RCNTRL_REG);
7300 +/* GEMAC enable function.
7301 + * @param[in] base GEMAC base address
7303 +void gemac_enable(void *base)
7305 + writel(readl(base + EMAC_ECNTRL_REG) | EMAC_ECNTRL_ETHER_EN, base +
7309 +/* GEMAC disable function.
7310 + * @param[in] base GEMAC base address
7312 +void gemac_disable(void *base)
7314 + writel(readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_ETHER_EN, base +
7318 +/* GEMAC TX disable function.
7319 + * @param[in] base GEMAC base address
7321 +void gemac_tx_disable(void *base)
7323 + writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_GTS, base +
7327 +void gemac_tx_enable(void *base)
7329 + writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_GTS, base +
7333 +/* Sets the hash register of the MAC.
7334 + * This register is used for matching unicast and multicast frames.
7336 + * @param[in] base GEMAC base address.
7337 + * @param[in] hash 64-bit hash to be configured.
7339 +void gemac_set_hash(void *base, struct pfe_mac_addr *hash)
7341 + writel(hash->bottom, base + EMAC_GALR);
7342 + writel(hash->top, base + EMAC_GAUR);
7345 +void gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
7346 + unsigned int entry_index)
7348 + if ((entry_index < 1) || (entry_index > EMAC_SPEC_ADDR_MAX))
7351 + entry_index = entry_index - 1;
7352 + if (entry_index < 1) {
7353 + writel(htonl(address->bottom), base + EMAC_PHY_ADDR_LOW);
7354 + writel((htonl(address->top) | 0x8808), base +
7355 + EMAC_PHY_ADDR_HIGH);
7357 + writel(htonl(address->bottom), base + ((entry_index - 1) * 8)
7359 + writel((htonl(address->top) | 0x8808), base + ((entry_index -
7360 + 1) * 8) + EMAC_SMAC_0_1);
7364 +void gemac_clear_laddrN(void *base, unsigned int entry_index)
7366 + if ((entry_index < 1) || (entry_index > EMAC_SPEC_ADDR_MAX))
7369 + entry_index = entry_index - 1;
7370 + if (entry_index < 1) {
7371 + writel(0, base + EMAC_PHY_ADDR_LOW);
7372 + writel(0, base + EMAC_PHY_ADDR_HIGH);
7374 + writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_0);
7375 + writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_1);
7379 +/* Set the loopback mode of the MAC. This can be either no loopback for
7380 + * normal operation, local loopback through MAC internal loopback module or PHY
7381 + * loopback for external loopback through a PHY. This asserts the external
7384 + * @param[in] base GEMAC base address.
7385 + * @param[in] gem_loop Loopback mode to be enabled. LB_LOCAL - MAC
7387 + * LB_EXT - PHY Loopback.
7389 +void gemac_set_loop(void *base, enum mac_loop gem_loop)
7391 + pr_info("%s()\n", __func__);
7392 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_LOOP, (base +
7393 + EMAC_RCNTRL_REG));
7396 +/* GEMAC allow frames
7397 + * @param[in] base GEMAC base address
7399 +void gemac_enable_copy_all(void *base)
7401 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_PROM, (base +
7402 + EMAC_RCNTRL_REG));
7405 +/* GEMAC do not allow frames
7406 + * @param[in] base GEMAC base address
7408 +void gemac_disable_copy_all(void *base)
7410 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_PROM, (base +
7411 + EMAC_RCNTRL_REG));
7414 +/* GEMAC allow broadcast function.
7415 + * @param[in] base GEMAC base address
7417 +void gemac_allow_broadcast(void *base)
7419 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_BC_REJ, base +
7423 +/* GEMAC no broadcast function.
7424 + * @param[in] base GEMAC base address
7426 +void gemac_no_broadcast(void *base)
7428 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_BC_REJ, base +
7432 +/* GEMAC enable 1536 rx function.
7433 + * @param[in] base GEMAC base address
7435 +void gemac_enable_1536_rx(void *base)
7437 + /* Set 1536 as Maximum frame length */
7438 + writel((readl(base + EMAC_RCNTRL_REG) & PFE_RCR_MAX_FL_MASK)
7439 + | (1536 << 16), base + EMAC_RCNTRL_REG);
7442 +/* GEMAC set rx Max frame length.
7443 + * @param[in] base GEMAC base address
7444 + * @param[in] mtu new mtu
7446 +void gemac_set_rx_max_fl(void *base, int mtu)
7448 + /* Set mtu as Maximum frame length */
7449 + writel((readl(base + EMAC_RCNTRL_REG) & PFE_RCR_MAX_FL_MASK)
7450 + | (mtu << 16), base + EMAC_RCNTRL_REG);
7453 +/* GEMAC enable stacked vlan function.
7454 + * @param[in] base GEMAC base address
7456 +void gemac_enable_stacked_vlan(void *base)
7458 + /* MTIP doesn't support stacked vlan */
7461 +/* GEMAC enable pause rx function.
7462 + * @param[in] base GEMAC base address
7464 +void gemac_enable_pause_rx(void *base)
7466 + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_FCE,
7467 + base + EMAC_RCNTRL_REG);
7470 +/* GEMAC disable pause rx function.
7471 + * @param[in] base GEMAC base address
7473 +void gemac_disable_pause_rx(void *base)
7475 + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_FCE,
7476 + base + EMAC_RCNTRL_REG);
7479 +/* GEMAC enable pause tx function.
7480 + * @param[in] base GEMAC base address
7482 +void gemac_enable_pause_tx(void *base)
7484 + writel(EMAC_RX_SECTION_EMPTY_V, base + EMAC_RX_SECTION_EMPTY);
7487 +/* GEMAC disable pause tx function.
7488 + * @param[in] base GEMAC base address
7490 +void gemac_disable_pause_tx(void *base)
7492 + writel(0x0, base + EMAC_RX_SECTION_EMPTY);
7495 +/* GEMAC wol configuration
7496 + * @param[in] base GEMAC base address
7497 + * @param[in] wol_conf WoL register configuration
7499 +void gemac_set_wol(void *base, u32 wol_conf)
7501 + u32 val = readl(base + EMAC_ECNTRL_REG);
7504 + val |= (EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
7506 + val &= ~(EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
7507 + writel(val, base + EMAC_ECNTRL_REG);
7510 +/* Sets Gemac bus width to 64bit
7511 + * @param[in] base GEMAC base address
7512 + * @param[in] width gemac bus width to be set possible values are 32/64/128
7514 +void gemac_set_bus_width(void *base, int width)
7518 +/* Sets Gemac configuration.
7519 + * @param[in] base GEMAC base address
7520 + * @param[in] cfg GEMAC configuration
7522 +void gemac_set_config(void *base, struct gemac_cfg *cfg)
7524 + /*GEMAC config taken from VLSI */
7525 + writel(0x00000004, base + EMAC_TFWR_STR_FWD);
7526 + writel(0x00000005, base + EMAC_RX_SECTION_FULL);
7528 + if (pfe_errata_a010897)
7529 + writel(0x0000076c, base + EMAC_TRUNC_FL);
7531 + writel(0x00003fff, base + EMAC_TRUNC_FL);
7533 + writel(0x00000030, base + EMAC_TX_SECTION_EMPTY);
7534 + writel(0x00000000, base + EMAC_MIB_CTRL_STS_REG);
7536 + gemac_set_mode(base, cfg->mode);
7538 + gemac_set_speed(base, cfg->speed);
7540 + gemac_set_duplex(base, cfg->duplex);
7543 +/**************************** GPI ***************************/
7545 +/* Initializes a GPI block.
7546 + * @param[in] base GPI base address
7547 + * @param[in] cfg GPI configuration
7549 +void gpi_init(void *base, struct gpi_cfg *cfg)
7553 + gpi_disable(base);
7555 + gpi_set_config(base, cfg);
7558 +/* Resets a GPI block.
7559 + * @param[in] base GPI base address
7561 +void gpi_reset(void *base)
7563 + writel(CORE_SW_RESET, base + GPI_CTRL);
7566 +/* Enables a GPI block.
7567 + * @param[in] base GPI base address
7569 +void gpi_enable(void *base)
7571 + writel(CORE_ENABLE, base + GPI_CTRL);
7574 +/* Disables a GPI block.
7575 + * @param[in] base GPI base address
7577 +void gpi_disable(void *base)
7579 + writel(CORE_DISABLE, base + GPI_CTRL);
7582 +/* Sets the configuration of a GPI block.
7583 + * @param[in] base GPI base address
7584 + * @param[in] cfg GPI configuration
7586 +void gpi_set_config(void *base, struct gpi_cfg *cfg)
7588 + writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_ALLOC_CTRL), base
7589 + + GPI_LMEM_ALLOC_ADDR);
7590 + writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_FREE_CTRL), base
7591 + + GPI_LMEM_FREE_ADDR);
7592 + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_ALLOC_CTRL), base
7593 + + GPI_DDR_ALLOC_ADDR);
7594 + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL), base
7595 + + GPI_DDR_FREE_ADDR);
7596 + writel(CBUS_VIRT_TO_PFE(CLASS_INQ_PKTPTR), base + GPI_CLASS_ADDR);
7597 + writel(DDR_HDR_SIZE, base + GPI_DDR_DATA_OFFSET);
7598 + writel(LMEM_HDR_SIZE, base + GPI_LMEM_DATA_OFFSET);
7599 + writel(0, base + GPI_LMEM_SEC_BUF_DATA_OFFSET);
7600 + writel(0, base + GPI_DDR_SEC_BUF_DATA_OFFSET);
7601 + writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, base + GPI_HDR_SIZE);
7602 + writel((DDR_BUF_SIZE << 16) | LMEM_BUF_SIZE, base + GPI_BUF_SIZE);
7604 + writel(((cfg->lmem_rtry_cnt << 16) | (GPI_DDR_BUF_EN << 1) |
7605 + GPI_LMEM_BUF_EN), base + GPI_RX_CONFIG);
7606 + writel(cfg->tmlf_txthres, base + GPI_TMLF_TX);
7607 + writel(cfg->aseq_len, base + GPI_DTX_ASEQ);
7608 + writel(1, base + GPI_TOE_CHKSUM_EN);
7610 + if (cfg->mtip_pause_reg) {
7611 + writel(cfg->mtip_pause_reg, base + GPI_CSR_MTIP_PAUSE_REG);
7612 + writel(EGPI_PAUSE_TIME, base + GPI_TX_PAUSE_TIME);
7616 +/**************************** CLASSIFIER ***************************/
7618 +/* Initializes CLASSIFIER block.
7619 + * @param[in] cfg CLASSIFIER configuration
7621 +void class_init(struct class_cfg *cfg)
7627 + class_set_config(cfg);
7630 +/* Resets CLASSIFIER block.
7633 +void class_reset(void)
7635 + writel(CORE_SW_RESET, CLASS_TX_CTRL);
7638 +/* Enables all CLASS-PE's cores.
7641 +void class_enable(void)
7643 + writel(CORE_ENABLE, CLASS_TX_CTRL);
7646 +/* Disables all CLASS-PE's cores.
7649 +void class_disable(void)
7651 + writel(CORE_DISABLE, CLASS_TX_CTRL);
7655 + * Sets the configuration of the CLASSIFIER block.
7656 + * @param[in] cfg CLASSIFIER configuration
7658 +void class_set_config(struct class_cfg *cfg)
7662 + /* Initialize route table */
7664 + memset(DDR_PHYS_TO_VIRT(cfg->route_table_baseaddr), 0, (1 <<
7665 + cfg->route_table_hash_bits) * CLASS_ROUTE_SIZE);
7667 +#if !defined(LS1012A_PFE_RESET_WA)
7668 + writel(cfg->pe_sys_clk_ratio, CLASS_PE_SYS_CLK_RATIO);
7671 + writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, CLASS_HDR_SIZE);
7672 + writel(LMEM_BUF_SIZE, CLASS_LMEM_BUF_SIZE);
7673 + writel(CLASS_ROUTE_ENTRY_SIZE(CLASS_ROUTE_SIZE) |
7674 + CLASS_ROUTE_HASH_SIZE(cfg->route_table_hash_bits),
7675 + CLASS_ROUTE_HASH_ENTRY_SIZE);
7676 + writel(HIF_PKT_CLASS_EN | HIF_PKT_OFFSET(sizeof(struct hif_hdr)),
7679 + val = HASH_CRC_PORT_IP | QB2BUS_LE;
7681 +#if defined(CONFIG_IP_ALIGNED)
7682 + val |= IP_ALIGNED;
7686 + * Class PE packet steering will only work if TOE mode, bridge fetch or
7687 + * route fetch are enabled (see class/qb_fet.v). Route fetch would
7688 + * trigger additional memory copies (likely from DDR because of hash
7689 + * table size, which cannot be reduced because PE software still
7690 + * relies on hash value computed in HW), so when not in TOE mode we
7691 + * simply enable HW bridge fetch even though we don't use it.
7693 + if (cfg->toe_mode)
7696 + val |= HW_BRIDGE_FETCH;
7698 + writel(val, CLASS_ROUTE_MULTI);
7700 + writel(DDR_PHYS_TO_PFE(cfg->route_table_baseaddr),
7701 + CLASS_ROUTE_TABLE_BASE);
7702 + writel(CLASS_PE0_RO_DM_ADDR0_VAL, CLASS_PE0_RO_DM_ADDR0);
7703 + writel(CLASS_PE0_RO_DM_ADDR1_VAL, CLASS_PE0_RO_DM_ADDR1);
7704 + writel(CLASS_PE0_QB_DM_ADDR0_VAL, CLASS_PE0_QB_DM_ADDR0);
7705 + writel(CLASS_PE0_QB_DM_ADDR1_VAL, CLASS_PE0_QB_DM_ADDR1);
7706 + writel(CBUS_VIRT_TO_PFE(TMU_PHY_INQ_PKTPTR), CLASS_TM_INQ_ADDR);
7708 + writel(23, CLASS_AFULL_THRES);
7709 + writel(23, CLASS_TSQ_FIFO_THRES);
7711 + writel(24, CLASS_MAX_BUF_CNT);
7712 + writel(24, CLASS_TSQ_MAX_CNT);
7715 +/**************************** TMU ***************************/
7717 +void tmu_reset(void)
7719 + writel(SW_RESET, TMU_CTRL);
7722 +/* Initializes TMU block.
7723 + * @param[in] cfg TMU configuration
7725 +void tmu_init(struct tmu_cfg *cfg)
7732 +#if !defined(LS1012A_PFE_RESET_WA)
7733 + /* keep in soft reset */
7734 + writel(SW_RESET, TMU_CTRL);
7736 + writel(0x3, TMU_SYS_GENERIC_CONTROL);
7737 + writel(750, TMU_INQ_WATERMARK);
7738 + writel(CBUS_VIRT_TO_PFE(EGPI1_BASE_ADDR +
7739 + GPI_INQ_PKTPTR), TMU_PHY0_INQ_ADDR);
7740 + writel(CBUS_VIRT_TO_PFE(EGPI2_BASE_ADDR +
7741 + GPI_INQ_PKTPTR), TMU_PHY1_INQ_ADDR);
7742 + writel(CBUS_VIRT_TO_PFE(HGPI_BASE_ADDR +
7743 + GPI_INQ_PKTPTR), TMU_PHY3_INQ_ADDR);
7744 + writel(CBUS_VIRT_TO_PFE(HIF_NOCPY_RX_INQ0_PKTPTR), TMU_PHY4_INQ_ADDR);
7745 + writel(CBUS_VIRT_TO_PFE(UTIL_INQ_PKTPTR), TMU_PHY5_INQ_ADDR);
7746 + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL),
7747 + TMU_BMU_INQ_ADDR);
7749 + writel(0x3FF, TMU_TDQ0_SCH_CTRL); /*
7751 + * schedulers [9:0] of each TDQ
7753 + writel(0x3FF, TMU_TDQ1_SCH_CTRL);
7754 + writel(0x3FF, TMU_TDQ3_SCH_CTRL);
7756 +#if !defined(LS1012A_PFE_RESET_WA)
7757 + writel(cfg->pe_sys_clk_ratio, TMU_PE_SYS_CLK_RATIO);
7760 +#if !defined(LS1012A_PFE_RESET_WA)
7761 + writel(DDR_PHYS_TO_PFE(cfg->llm_base_addr), TMU_LLM_BASE_ADDR);
7762 + /* Extra packet pointers will be stored from this address onwards */
7764 + writel(cfg->llm_queue_len, TMU_LLM_QUE_LEN);
7765 + writel(5, TMU_TDQ_IIFG_CFG);
7766 + writel(DDR_BUF_SIZE, TMU_BMU_BUF_SIZE);
7768 + writel(0x0, TMU_CTRL);
7771 + pr_info("%s: mem init\n", __func__);
7772 + writel(MEM_INIT, TMU_CTRL);
7774 + while (!(readl(TMU_CTRL) & MEM_INIT_DONE))
7778 + pr_info("%s: lmem init\n", __func__);
7779 + writel(LLM_INIT, TMU_CTRL);
7781 + while (!(readl(TMU_CTRL) & LLM_INIT_DONE))
7784 + /* set up each queue for tail drop */
7785 + for (phyno = 0; phyno < 4; phyno++) {
7788 + for (q = 0; q < 16; q++) {
7791 + writel((phyno << 8) | q, TMU_TEQ_CTRL);
7792 + writel(1 << 22, TMU_TEQ_QCFG); /*Enable tail drop */
7795 + qdepth = DEFAULT_TMU3_QDEPTH;
7797 + qdepth = (q == 0) ? DEFAULT_Q0_QDEPTH :
7798 + DEFAULT_MAX_QDEPTH;
7802 + * The following is a workaround for the reordered
7803 + * packet and BMU2 buffer leakage issue.
7805 + if (CHIP_REVISION() == 0)
7808 + writel(qdepth << 18, TMU_TEQ_HW_PROB_CFG2);
7809 + writel(qdepth >> 14, TMU_TEQ_HW_PROB_CFG3);
7814 + /* Set TMU-3 queue 5 (LRO) in no-drop mode */
7815 + writel((3 << 8) | TMU_QUEUE_LRO, TMU_TEQ_CTRL);
7816 + writel(0, TMU_TEQ_QCFG);
7819 + writel(0x05, TMU_TEQ_DISABLE_DROPCHK);
7821 + writel(0x0, TMU_CTRL);
7824 +/* Enables TMU-PE cores.
7825 + * @param[in] pe_mask TMU PE mask
7827 +void tmu_enable(u32 pe_mask)
7829 + writel(readl(TMU_TX_CTRL) | (pe_mask & 0xF), TMU_TX_CTRL);
7832 +/* Disables TMU cores.
7833 + * @param[in] pe_mask TMU PE mask
7835 +void tmu_disable(u32 pe_mask)
7837 + writel(readl(TMU_TX_CTRL) & ~(pe_mask & 0xF), TMU_TX_CTRL);
7840 +/* This will return the tmu queue status
7841 + * @param[in] if_id gem interface id or TMU index
7842 + * @return returns the bit mask of busy queues, zero means all
7843 + * queues are empty
7845 +u32 tmu_qstatus(u32 if_id)
7847 + return cpu_to_be32(pe_dmem_read(TMU0_ID + if_id, TMU_DM_PESTATUS +
7848 + offsetof(struct pe_status, tmu_qstatus), 4));
7851 +u32 tmu_pkts_processed(u32 if_id)
7853 + return cpu_to_be32(pe_dmem_read(TMU0_ID + if_id, TMU_DM_PESTATUS +
7854 + offsetof(struct pe_status, rx), 4));
7857 +/**************************** UTIL ***************************/
7859 +/* Resets UTIL block.
7861 +void util_reset(void)
7863 + writel(CORE_SW_RESET, UTIL_TX_CTRL);
7866 +/* Initializes UTIL block.
7867 + * @param[in] cfg UTIL configuration
7869 +void util_init(struct util_cfg *cfg)
7871 + writel(cfg->pe_sys_clk_ratio, UTIL_PE_SYS_CLK_RATIO);
7874 +/* Enables UTIL-PE core.
7877 +void util_enable(void)
7879 + writel(CORE_ENABLE, UTIL_TX_CTRL);
7882 +/* Disables UTIL-PE core.
7885 +void util_disable(void)
7887 + writel(CORE_DISABLE, UTIL_TX_CTRL);
7890 +/**************************** HIF ***************************/
7891 +/* Initializes HIF copy block.
7894 +void hif_init(void)
7896 + /*Initialize HIF registers*/
7897 + writel((HIF_RX_POLL_CTRL_CYCLE << 16) | HIF_TX_POLL_CTRL_CYCLE,
7901 +/* Enable hif tx DMA and interrupt
7904 +void hif_tx_enable(void)
7906 + writel(HIF_CTRL_DMA_EN, HIF_TX_CTRL);
7907 + writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_TXPKT_INT_EN),
7911 +/* Disable hif tx DMA and interrupt
7914 +void hif_tx_disable(void)
7918 + writel(0, HIF_TX_CTRL);
7920 + hif_int = readl(HIF_INT_ENABLE);
7921 + hif_int &= HIF_TXPKT_INT_EN;
7922 + writel(hif_int, HIF_INT_ENABLE);
7925 +/* Enable hif rx DMA and interrupt
7928 +void hif_rx_enable(void)
7930 + hif_rx_dma_start();
7931 + writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_RXPKT_INT_EN),
7935 +/* Disable hif rx DMA and interrupt
7938 +void hif_rx_disable(void)
7942 + writel(0, HIF_RX_CTRL);
7944 + hif_int = readl(HIF_INT_ENABLE);
7945 + hif_int &= HIF_RXPKT_INT_EN;
7946 + writel(hif_int, HIF_INT_ENABLE);
7949 +++ b/drivers/staging/fsl_ppfe/pfe_hif.c
7951 +// SPDX-License-Identifier: GPL-2.0+
7953 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
7954 + * Copyright 2017 NXP
7957 +#include <linux/kernel.h>
7958 +#include <linux/interrupt.h>
7959 +#include <linux/dma-mapping.h>
7960 +#include <linux/dmapool.h>
7961 +#include <linux/sched.h>
7962 +#include <linux/module.h>
7963 +#include <linux/list.h>
7964 +#include <linux/kthread.h>
7965 +#include <linux/slab.h>
7967 +#include <linux/io.h>
7968 +#include <asm/irq.h>
7970 +#include "pfe_mod.h"
7972 +#define HIF_INT_MASK (HIF_INT | HIF_RXPKT_INT | HIF_TXPKT_INT)
7974 +unsigned char napi_first_batch;
7976 +static void pfe_tx_do_cleanup(unsigned long data);
7978 +static int pfe_hif_alloc_descr(struct pfe_hif *hif)
7981 + dma_addr_t dma_addr;
7984 + pr_info("%s\n", __func__);
7985 + addr = dma_alloc_coherent(pfe->dev,
7986 + HIF_RX_DESC_NT * sizeof(struct hif_desc) +
7987 + HIF_TX_DESC_NT * sizeof(struct hif_desc),
7988 + &dma_addr, GFP_KERNEL);
7991 + pr_err("%s: Could not allocate buffer descriptors!\n"
7997 + hif->descr_baseaddr_p = dma_addr;
7998 + hif->descr_baseaddr_v = addr;
7999 + hif->rx_ring_size = HIF_RX_DESC_NT;
8000 + hif->tx_ring_size = HIF_TX_DESC_NT;
8008 +#if defined(LS1012A_PFE_RESET_WA)
8009 +static void pfe_hif_disable_rx_desc(struct pfe_hif *hif)
8012 + struct hif_desc *desc = hif->rx_base;
8014 + /*Mark all descriptors as LAST_BD */
8015 + for (ii = 0; ii < hif->rx_ring_size; ii++) {
8016 + desc->ctrl |= BD_CTRL_LAST_BD;
8021 +struct class_rx_hdr_t {
8022 + u32 next_ptr; /* ptr to the start of the first DDR buffer */
8023 + u16 length; /* total packet length */
8024 + u16 phyno; /* input physical port number */
8025 + u32 status; /* gemac status bits */
8026 + u32 status2; /* reserved for software usage */
8029 +/* STATUS_BAD_FRAME_ERR is set for all errors (including checksums if enabled)
8032 +#define STATUS_BAD_FRAME_ERR BIT(16)
8033 +#define STATUS_LENGTH_ERR BIT(17)
8034 +#define STATUS_CRC_ERR BIT(18)
8035 +#define STATUS_TOO_SHORT_ERR BIT(19)
8036 +#define STATUS_TOO_LONG_ERR BIT(20)
8037 +#define STATUS_CODE_ERR BIT(21)
8038 +#define STATUS_MC_HASH_MATCH BIT(22)
8039 +#define STATUS_CUMULATIVE_ARC_HIT BIT(23)
8040 +#define STATUS_UNICAST_HASH_MATCH BIT(24)
8041 +#define STATUS_IP_CHECKSUM_CORRECT BIT(25)
8042 +#define STATUS_TCP_CHECKSUM_CORRECT BIT(26)
8043 +#define STATUS_UDP_CHECKSUM_CORRECT BIT(27)
8044 +#define STATUS_OVERFLOW_ERR BIT(28) /* GPI error */
8045 +#define MIN_PKT_SIZE 64
8047 +static inline void copy_to_lmem(u32 *dst, u32 *src, int len)
8051 + for (i = 0; i < len; i += sizeof(u32)) {
8052 + *dst = htonl(*src);
8057 +static void send_dummy_pkt_to_hif(void)
8059 + void *lmem_ptr, *ddr_ptr, *lmem_virt_addr;
8061 + struct class_rx_hdr_t local_hdr;
8062 + static u32 dummy_pkt[] = {
8063 + 0x33221100, 0x2b785544, 0xd73093cb, 0x01000608,
8064 + 0x04060008, 0x2b780200, 0xd73093cb, 0x0a01a8c0,
8065 + 0x33221100, 0xa8c05544, 0x00000301, 0x00000000,
8066 + 0x00000000, 0x00000000, 0x00000000, 0xbe86c51f };
8068 + ddr_ptr = (void *)((u64)readl(BMU2_BASE_ADDR + BMU_ALLOC_CTRL));
8072 + lmem_ptr = (void *)((u64)readl(BMU1_BASE_ADDR + BMU_ALLOC_CTRL));
8076 + pr_info("Sending a dummy pkt to HIF %p %p\n", ddr_ptr, lmem_ptr);
8077 + physaddr = (u32)DDR_VIRT_TO_PFE(ddr_ptr);
8079 + lmem_virt_addr = (void *)CBUS_PFE_TO_VIRT((unsigned long int)lmem_ptr);
8081 + local_hdr.phyno = htons(0); /* RX_PHY_0 */
8082 + local_hdr.length = htons(MIN_PKT_SIZE);
8084 + local_hdr.next_ptr = htonl((u32)physaddr);
8085 + /*Mark checksum is correct */
8086 + local_hdr.status = htonl((STATUS_IP_CHECKSUM_CORRECT |
8087 + STATUS_UDP_CHECKSUM_CORRECT |
8088 + STATUS_TCP_CHECKSUM_CORRECT |
8089 + STATUS_UNICAST_HASH_MATCH |
8090 + STATUS_CUMULATIVE_ARC_HIT));
8091 + local_hdr.status2 = 0;
8093 + copy_to_lmem((u32 *)lmem_virt_addr, (u32 *)&local_hdr,
8094 + sizeof(local_hdr));
8096 + copy_to_lmem((u32 *)(lmem_virt_addr + LMEM_HDR_SIZE), (u32 *)dummy_pkt,
8099 + writel((unsigned long int)lmem_ptr, CLASS_INQ_PKTPTR);
8102 +void pfe_hif_rx_idle(struct pfe_hif *hif)
8104 + int hif_stop_loop = 10;
8107 + pfe_hif_disable_rx_desc(hif);
8108 + pr_info("Bringing hif to idle state...");
8109 + writel(0, HIF_INT_ENABLE);
8110 + /*If HIF Rx BDP is busy send a dummy packet */
8112 + rx_status = readl(HIF_RX_STATUS);
8113 + if (rx_status & BDP_CSR_RX_DMA_ACTV)
8114 + send_dummy_pkt_to_hif();
8116 + usleep_range(100, 150);
8117 + } while (--hif_stop_loop);
8119 + if (readl(HIF_RX_STATUS) & BDP_CSR_RX_DMA_ACTV)
8120 + pr_info("Failed\n");
8122 + pr_info("Done\n");
8126 +static void pfe_hif_free_descr(struct pfe_hif *hif)
8128 + pr_info("%s\n", __func__);
8130 + dma_free_coherent(pfe->dev,
8131 + hif->rx_ring_size * sizeof(struct hif_desc) +
8132 + hif->tx_ring_size * sizeof(struct hif_desc),
8133 + hif->descr_baseaddr_v, hif->descr_baseaddr_p);
8136 +void pfe_hif_desc_dump(struct pfe_hif *hif)
8138 + struct hif_desc *desc;
8139 + unsigned long desc_p;
8142 + pr_info("%s\n", __func__);
8144 + desc = hif->rx_base;
8145 + desc_p = (u32)((u64)desc - (u64)hif->descr_baseaddr_v +
8146 + hif->descr_baseaddr_p);
8148 + pr_info("HIF Rx desc base %p physical %x\n", desc, (u32)desc_p);
8149 + for (ii = 0; ii < hif->rx_ring_size; ii++) {
8150 + pr_info("status: %08x, ctrl: %08x, data: %08x, next: %x\n",
8151 + readl(&desc->status), readl(&desc->ctrl),
8152 + readl(&desc->data), readl(&desc->next));
8156 + desc = hif->tx_base;
8157 + desc_p = ((u64)desc - (u64)hif->descr_baseaddr_v +
8158 + hif->descr_baseaddr_p);
8160 + pr_info("HIF Tx desc base %p physical %x\n", desc, (u32)desc_p);
8161 + for (ii = 0; ii < hif->tx_ring_size; ii++) {
8162 + pr_info("status: %08x, ctrl: %08x, data: %08x, next: %x\n",
8163 + readl(&desc->status), readl(&desc->ctrl),
8164 + readl(&desc->data), readl(&desc->next));
8169 +/* pfe_hif_release_buffers */
8170 +static void pfe_hif_release_buffers(struct pfe_hif *hif)
8172 + struct hif_desc *desc;
8175 + hif->rx_base = hif->descr_baseaddr_v;
8177 + pr_info("%s\n", __func__);
8179 + /*Free Rx buffers */
8180 + desc = hif->rx_base;
8181 + for (i = 0; i < hif->rx_ring_size; i++) {
8182 + if (readl(&desc->data)) {
8183 + if ((i < hif->shm->rx_buf_pool_cnt) &&
8184 + (!hif->shm->rx_buf_pool[i])) {
8186 + * dma_unmap_single(hif->dev, desc->data,
8187 + * hif->rx_buf_len[i], DMA_FROM_DEVICE);
8189 + dma_unmap_single(hif->dev,
8191 + readl(&desc->data)),
8192 + hif->rx_buf_len[i],
8194 + hif->shm->rx_buf_pool[i] = hif->rx_buf_addr[i];
8196 + pr_err("%s: buffer pool already full\n"
8201 + writel(0, &desc->data);
8202 + writel(0, &desc->status);
8203 + writel(0, &desc->ctrl);
8209 + * pfe_hif_init_buffers
8210 + * This function initializes the HIF Rx/Tx ring descriptors and
8211 + * initialize Rx queue with buffers.
8213 +static int pfe_hif_init_buffers(struct pfe_hif *hif)
8215 + struct hif_desc *desc, *first_desc_p;
8219 + pr_info("%s\n", __func__);
8221 + /* Check enough Rx buffers available in the shared memory */
8222 + if (hif->shm->rx_buf_pool_cnt < hif->rx_ring_size)
8225 + hif->rx_base = hif->descr_baseaddr_v;
8226 + memset(hif->rx_base, 0, hif->rx_ring_size * sizeof(struct hif_desc));
8228 + /*Initialize Rx descriptors */
8229 + desc = hif->rx_base;
8230 + first_desc_p = (struct hif_desc *)hif->descr_baseaddr_p;
8232 + for (i = 0; i < hif->rx_ring_size; i++) {
8233 + /* Initialize Rx buffers from the shared memory */
8235 + data = (u32)dma_map_single(hif->dev, hif->shm->rx_buf_pool[i],
8236 + pfe_pkt_size, DMA_FROM_DEVICE);
8237 + hif->rx_buf_addr[i] = hif->shm->rx_buf_pool[i];
8238 + hif->rx_buf_len[i] = pfe_pkt_size;
8239 + hif->shm->rx_buf_pool[i] = NULL;
8241 + if (likely(dma_mapping_error(hif->dev, data) == 0)) {
8242 + writel(DDR_PHYS_TO_PFE(data), &desc->data);
8244 + pr_err("%s : low on mem\n", __func__);
8249 + writel(0, &desc->status);
8252 + * Ensure everything else is written to DDR before
8253 + * writing bd->ctrl
8257 + writel((BD_CTRL_PKT_INT_EN | BD_CTRL_LIFM
8258 + | BD_CTRL_DIR | BD_CTRL_DESC_EN
8259 + | BD_BUF_LEN(pfe_pkt_size)), &desc->ctrl);
8261 + /* Chain descriptors */
8262 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p + i + 1), &desc->next);
8266 + /* Overwrite last descriptor to chain it to first one*/
8268 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), &desc->next);
8270 + hif->rxtoclean_index = 0;
8272 + /*Initialize Rx buffer descriptor ring base address */
8273 + writel(DDR_PHYS_TO_PFE(hif->descr_baseaddr_p), HIF_RX_BDP_ADDR);
8275 + hif->tx_base = hif->rx_base + hif->rx_ring_size;
8276 + first_desc_p = (struct hif_desc *)hif->descr_baseaddr_p +
8277 + hif->rx_ring_size;
8278 + memset(hif->tx_base, 0, hif->tx_ring_size * sizeof(struct hif_desc));
8280 + /*Initialize tx descriptors */
8281 + desc = hif->tx_base;
8283 + for (i = 0; i < hif->tx_ring_size; i++) {
8284 + /* Chain descriptors */
8285 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p + i + 1), &desc->next);
8286 + writel(0, &desc->ctrl);
8290 + /* Overwrite last descriptor to chain it to first one */
8292 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), &desc->next);
8293 + hif->txavail = hif->tx_ring_size;
8294 + hif->txtosend = 0;
8295 + hif->txtoclean = 0;
8296 + hif->txtoflush = 0;
8298 + /*Initialize Tx buffer descriptor ring base address */
8299 + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), HIF_TX_BDP_ADDR);
8304 + pfe_hif_release_buffers(hif);
8309 + * pfe_hif_client_register
8311 + * This function used to register a client driver with the HIF driver.
8314 + * 0 - on Successful registration
8316 +static int pfe_hif_client_register(struct pfe_hif *hif, u32 client_id,
8317 + struct hif_client_shm *client_shm)
8319 + struct hif_client *client = &hif->client[client_id];
8321 + struct rx_queue_desc *rx_qbase;
8322 + struct tx_queue_desc *tx_qbase;
8323 + struct hif_rx_queue *rx_queue;
8324 + struct hif_tx_queue *tx_queue;
8327 + pr_info("%s\n", __func__);
8329 + spin_lock_bh(&hif->tx_lock);
8331 + if (test_bit(client_id, &hif->shm->g_client_status[0])) {
8332 + pr_err("%s: client %d already registered\n",
8333 + __func__, client_id);
8338 + memset(client, 0, sizeof(struct hif_client));
8340 + /* Initialize client Rx queues baseaddr, size */
8342 + cnt = CLIENT_CTRL_RX_Q_CNT(client_shm->ctrl);
8343 + /* Check if client is requesting for more queues than supported */
8344 + if (cnt > HIF_CLIENT_QUEUES_MAX)
8345 + cnt = HIF_CLIENT_QUEUES_MAX;
8347 + client->rx_qn = cnt;
8348 + rx_qbase = (struct rx_queue_desc *)client_shm->rx_qbase;
8349 + for (i = 0; i < cnt; i++) {
8350 + rx_queue = &client->rx_q[i];
8351 + rx_queue->base = rx_qbase + i * client_shm->rx_qsize;
8352 + rx_queue->size = client_shm->rx_qsize;
8353 + rx_queue->write_idx = 0;
8356 + /* Initialize client Tx queues baseaddr, size */
8357 + cnt = CLIENT_CTRL_TX_Q_CNT(client_shm->ctrl);
8359 + /* Check if client is requesting for more queues than supported */
8360 + if (cnt > HIF_CLIENT_QUEUES_MAX)
8361 + cnt = HIF_CLIENT_QUEUES_MAX;
8363 + client->tx_qn = cnt;
8364 + tx_qbase = (struct tx_queue_desc *)client_shm->tx_qbase;
8365 + for (i = 0; i < cnt; i++) {
8366 + tx_queue = &client->tx_q[i];
8367 + tx_queue->base = tx_qbase + i * client_shm->tx_qsize;
8368 + tx_queue->size = client_shm->tx_qsize;
8369 + tx_queue->ack_idx = 0;
8372 + set_bit(client_id, &hif->shm->g_client_status[0]);
8375 + spin_unlock_bh(&hif->tx_lock);
8381 + * pfe_hif_client_unregister
8383 + * This function used to unregister a client from the HIF driver.
8386 +static void pfe_hif_client_unregister(struct pfe_hif *hif, u32 client_id)
8388 + pr_info("%s\n", __func__);
8391 + * Mark client as no longer available (which prevents further packet
8392 + * receive for this client)
8394 + spin_lock_bh(&hif->tx_lock);
8396 + if (!test_bit(client_id, &hif->shm->g_client_status[0])) {
8397 + pr_err("%s: client %d not registered\n", __func__,
8400 + spin_unlock_bh(&hif->tx_lock);
8404 + clear_bit(client_id, &hif->shm->g_client_status[0]);
8406 + spin_unlock_bh(&hif->tx_lock);
8410 + * client_put_rxpacket-
8411 + * This functions puts the Rx pkt in the given client Rx queue.
8412 + * It actually swap the Rx pkt in the client Rx descriptor buffer
8413 + * and returns the free buffer from it.
8415 + * If the function returns NULL means client Rx queue is full and
8416 + * packet couldn't send to client queue.
8418 +static void *client_put_rxpacket(struct hif_rx_queue *queue, void *pkt, u32 len,
8419 + u32 flags, u32 client_ctrl, u32 *rem_len)
8421 + void *free_pkt = NULL;
8422 + struct rx_queue_desc *desc = queue->base + queue->write_idx;
8424 + if (readl(&desc->ctrl) & CL_DESC_OWN) {
8426 + int rem_page_size = PAGE_SIZE -
8427 + PRESENT_OFST_IN_PAGE(pkt);
8428 + int cur_pkt_size = ROUND_MIN_RX_SIZE(len +
8429 + pfe_pkt_headroom);
8430 + *rem_len = (rem_page_size - cur_pkt_size);
8432 + free_pkt = pkt + cur_pkt_size;
8433 + get_page(virt_to_page(free_pkt));
8436 + *)__get_free_page(GFP_ATOMIC | GFP_DMA_PFE);
8437 + *rem_len = pfe_pkt_size;
8440 + free_pkt = kmalloc(PFE_BUF_SIZE, GFP_ATOMIC |
8442 + *rem_len = PFE_BUF_SIZE - pfe_pkt_headroom;
8447 + desc->client_ctrl = client_ctrl;
8449 + * Ensure everything else is written to DDR before
8450 + * writing bd->ctrl
8453 + writel(CL_DESC_BUF_LEN(len) | flags, &desc->ctrl);
8454 + queue->write_idx = (queue->write_idx + 1)
8455 + & (queue->size - 1);
8457 + free_pkt += pfe_pkt_headroom;
8465 + * pfe_hif_rx_process-
8466 + * This function does pfe hif rx queue processing.
8467 + * Dequeue packet from Rx queue and send it to corresponding client queue
8469 +static int pfe_hif_rx_process(struct pfe_hif *hif, int budget)
8471 + struct hif_desc *desc;
8472 + struct hif_hdr *pkt_hdr;
8473 + struct __hif_hdr hif_hdr;
8475 + int rtc, len, rx_processed = 0;
8476 + struct __hif_desc local_desc;
8478 + unsigned int desc_p;
8479 + unsigned int buf_size = 0;
8481 + spin_lock_bh(&hif->lock);
8483 + rtc = hif->rxtoclean_index;
8485 + while (rx_processed < budget) {
8486 + desc = hif->rx_base + rtc;
8488 + __memcpy12(&local_desc, desc);
8490 + /* ACK pending Rx interrupt */
8491 + if (local_desc.ctrl & BD_CTRL_DESC_EN) {
8492 + writel(HIF_INT | HIF_RXPKT_INT, HIF_INT_SRC);
8494 + if (rx_processed == 0) {
8495 + if (napi_first_batch == 1) {
8496 + desc_p = hif->descr_baseaddr_p +
8497 + ((unsigned long int)(desc) -
8499 + int)hif->descr_baseaddr_v);
8500 + napi_first_batch = 0;
8504 + __memcpy12(&local_desc, desc);
8506 + if (local_desc.ctrl & BD_CTRL_DESC_EN)
8510 + napi_first_batch = 0;
8512 +#ifdef HIF_NAPI_STATS
8513 + hif->napi_counters[NAPI_DESC_COUNT]++;
8515 + len = BD_BUF_LEN(local_desc.ctrl);
8517 + * dma_unmap_single(hif->dev, DDR_PFE_TO_PHYS(local_desc.data),
8518 + * hif->rx_buf_len[rtc], DMA_FROM_DEVICE);
8520 + dma_unmap_single(hif->dev, DDR_PFE_TO_PHYS(local_desc.data),
8521 + hif->rx_buf_len[rtc], DMA_FROM_DEVICE);
8523 + pkt_hdr = (struct hif_hdr *)hif->rx_buf_addr[rtc];
8525 + /* Track last HIF header received */
8526 + if (!hif->started) {
8529 + __memcpy8(&hif_hdr, pkt_hdr);
8531 + hif->qno = hif_hdr.hdr.q_num;
8532 + hif->client_id = hif_hdr.hdr.client_id;
8533 + hif->client_ctrl = (hif_hdr.hdr.client_ctrl1 << 16) |
8534 + hif_hdr.hdr.client_ctrl;
8535 + flags = CL_DESC_FIRST;
8541 + if (local_desc.ctrl & BD_CTRL_LIFM)
8542 + flags |= CL_DESC_LAST;
8544 + /* Check for valid client id and still registered */
8545 + if ((hif->client_id >= HIF_CLIENTS_MAX) ||
8546 + !(test_bit(hif->client_id,
8547 + &hif->shm->g_client_status[0]))) {
8548 + printk_ratelimited("%s: packet with invalid client id %d q_num %d\n",
8553 + free_buf = pkt_hdr;
8558 + /* Check to valid queue number */
8559 + if (hif->client[hif->client_id].rx_qn <= hif->qno) {
8560 + pr_info("%s: packet with invalid queue: %d\n"
8561 + , __func__, hif->qno);
8566 + client_put_rxpacket(&hif->client[hif->client_id].rx_q[hif->qno],
8567 + (void *)pkt_hdr, len, flags,
8568 + hif->client_ctrl, &buf_size);
8570 + hif_lib_indicate_client(hif->client_id, EVENT_RX_PKT_IND,
8573 + if (unlikely(!free_buf)) {
8574 +#ifdef HIF_NAPI_STATS
8575 + hif->napi_counters[NAPI_CLIENT_FULL_COUNT]++;
8578 + * If we want to keep in polling mode to retry later,
8579 + * we need to tell napi that we consumed
8580 + * the full budget or we will hit a livelock scenario.
8581 + * The core code keeps this napi instance
8582 + * at the head of the list and none of the other
8583 + * instances get to run
8585 + rx_processed = budget;
8587 + if (flags & CL_DESC_FIRST)
8594 + /*Fill free buffer in the descriptor */
8595 + hif->rx_buf_addr[rtc] = free_buf;
8596 + hif->rx_buf_len[rtc] = min(pfe_pkt_size, buf_size);
8597 + writel((DDR_PHYS_TO_PFE
8598 + ((u32)dma_map_single(hif->dev,
8599 + free_buf, hif->rx_buf_len[rtc], DMA_FROM_DEVICE))),
8602 + * Ensure everything else is written to DDR before
8603 + * writing bd->ctrl
8606 + writel((BD_CTRL_PKT_INT_EN | BD_CTRL_LIFM | BD_CTRL_DIR |
8607 + BD_CTRL_DESC_EN | BD_BUF_LEN(hif->rx_buf_len[rtc])),
8610 + rtc = (rtc + 1) & (hif->rx_ring_size - 1);
8612 + if (local_desc.ctrl & BD_CTRL_LIFM) {
8613 + if (!(hif->client_ctrl & HIF_CTRL_RX_CONTINUED)) {
8616 +#ifdef HIF_NAPI_STATS
8617 + hif->napi_counters[NAPI_PACKET_COUNT]++;
8624 + hif->rxtoclean_index = rtc;
8625 + spin_unlock_bh(&hif->lock);
8627 + /* we made some progress, re-start rx dma in case it stopped */
8628 + hif_rx_dma_start();
8630 + return rx_processed;
8634 + * client_ack_txpacket-
8635 + * This function ack the Tx packet in the give client Tx queue by resetting
8636 + * ownership bit in the descriptor.
8638 +static int client_ack_txpacket(struct pfe_hif *hif, unsigned int client_id,
8639 + unsigned int q_no)
8641 + struct hif_tx_queue *queue = &hif->client[client_id].tx_q[q_no];
8642 + struct tx_queue_desc *desc = queue->base + queue->ack_idx;
8644 + if (readl(&desc->ctrl) & CL_DESC_OWN) {
8645 + writel((readl(&desc->ctrl) & ~CL_DESC_OWN), &desc->ctrl);
8646 + queue->ack_idx = (queue->ack_idx + 1) & (queue->size - 1);
8651 + /*This should not happen */
8652 + pr_err("%s: %d %d %d %d %d %p %d\n", __func__,
8653 + hif->txtosend, hif->txtoclean, hif->txavail,
8654 + client_id, q_no, queue, queue->ack_idx);
8655 + WARN(1, "%s: doesn't own this descriptor", __func__);
8660 +void __hif_tx_done_process(struct pfe_hif *hif, int count)
8662 + struct hif_desc *desc;
8663 + struct hif_desc_sw *desc_sw;
8665 + int pkts_done[HIF_CLIENTS_MAX] = {0, 0};
8667 + ttc = hif->txtoclean;
8668 + tx_avl = hif->txavail;
8670 + while ((tx_avl < hif->tx_ring_size) && count--) {
8671 + desc = hif->tx_base + ttc;
8673 + if (readl(&desc->ctrl) & BD_CTRL_DESC_EN)
8676 + desc_sw = &hif->tx_sw_queue[ttc];
8678 + if (desc_sw->data) {
8680 + * dmap_unmap_single(hif->dev, desc_sw->data,
8681 + * desc_sw->len, DMA_TO_DEVICE);
8683 + dma_unmap_single(hif->dev, desc_sw->data,
8684 + desc_sw->len, DMA_TO_DEVICE);
8687 + if (desc_sw->client_id >= HIF_CLIENTS_MAX) {
8688 + pr_err("Invalid cl id %d\n", desc_sw->client_id);
8692 + pkts_done[desc_sw->client_id]++;
8694 + client_ack_txpacket(hif, desc_sw->client_id, desc_sw->q_no);
8696 + ttc = (ttc + 1) & (hif->tx_ring_size - 1);
8701 + hif_lib_indicate_client(0, EVENT_TXDONE_IND, 0);
8703 + hif_lib_indicate_client(1, EVENT_TXDONE_IND, 0);
8705 + hif->txtoclean = ttc;
8706 + hif->txavail = tx_avl;
8709 + tasklet_schedule(&hif->tx_cleanup_tasklet);
8711 + /*Enable Tx done interrupt */
8712 + writel(readl_relaxed(HIF_INT_ENABLE) | HIF_TXPKT_INT,
8717 +static void pfe_tx_do_cleanup(unsigned long data)
8719 + struct pfe_hif *hif = (struct pfe_hif *)data;
8721 + writel(HIF_INT | HIF_TXPKT_INT, HIF_INT_SRC);
8723 + hif_tx_done_process(hif, 64);
8727 + * __hif_xmit_pkt -
8728 + * This function puts one packet in the HIF Tx queue
8730 +void __hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int
8731 + q_no, void *data, u32 len, unsigned int flags)
8733 + struct hif_desc *desc;
8734 + struct hif_desc_sw *desc_sw;
8736 + desc = hif->tx_base + hif->txtosend;
8737 + desc_sw = &hif->tx_sw_queue[hif->txtosend];
8739 + desc_sw->len = len;
8740 + desc_sw->client_id = client_id;
8741 + desc_sw->q_no = q_no;
8742 + desc_sw->flags = flags;
8744 + if (flags & HIF_DONT_DMA_MAP) {
8745 + desc_sw->data = 0;
8746 + writel((u32)DDR_PHYS_TO_PFE(data), &desc->data);
8748 + desc_sw->data = dma_map_single(hif->dev, data, len,
8750 + writel((u32)DDR_PHYS_TO_PFE(desc_sw->data), &desc->data);
8753 + hif->txtosend = (hif->txtosend + 1) & (hif->tx_ring_size - 1);
8756 + if ((!((flags & HIF_DATA_VALID) && (flags &
8757 + HIF_LAST_BUFFER))))
8761 + * Ensure everything else is written to DDR before
8762 + * writing bd->ctrl
8767 + desc_sw = &hif->tx_sw_queue[hif->txtoflush];
8768 + desc = hif->tx_base + hif->txtoflush;
8770 + if (desc_sw->flags & HIF_LAST_BUFFER) {
8771 + writel((BD_CTRL_LIFM |
8772 + BD_CTRL_BRFETCH_DISABLE | BD_CTRL_RTFETCH_DISABLE
8773 + | BD_CTRL_PARSE_DISABLE | BD_CTRL_DESC_EN |
8774 + BD_CTRL_PKT_INT_EN | BD_BUF_LEN(desc_sw->len)),
8777 + writel((BD_CTRL_DESC_EN |
8778 + BD_BUF_LEN(desc_sw->len)), &desc->ctrl);
8780 + hif->txtoflush = (hif->txtoflush + 1) & (hif->tx_ring_size - 1);
8782 + while (hif->txtoflush != hif->txtosend)
8789 +static irqreturn_t wol_isr(int irq, void *dev_id)
8792 + gemac_set_wol(EMAC1_BASE_ADDR, 0);
8793 + gemac_set_wol(EMAC2_BASE_ADDR, 0);
8794 + return IRQ_HANDLED;
8799 + * This ISR routine processes Rx/Tx done interrupts from the HIF hardware block
8801 +static irqreturn_t hif_isr(int irq, void *dev_id)
8803 + struct pfe_hif *hif = (struct pfe_hif *)dev_id;
8805 + int int_enable_mask;
8807 + /*Read hif interrupt source register */
8808 + int_status = readl_relaxed(HIF_INT_SRC);
8809 + int_enable_mask = readl_relaxed(HIF_INT_ENABLE);
8811 + if ((int_status & HIF_INT) == 0)
8814 + int_status &= ~(HIF_INT);
8816 + if (int_status & HIF_RXPKT_INT) {
8817 + int_status &= ~(HIF_RXPKT_INT);
8818 + int_enable_mask &= ~(HIF_RXPKT_INT);
8820 + napi_first_batch = 1;
8822 + if (napi_schedule_prep(&hif->napi)) {
8823 +#ifdef HIF_NAPI_STATS
8824 + hif->napi_counters[NAPI_SCHED_COUNT]++;
8826 + __napi_schedule(&hif->napi);
8830 + if (int_status & HIF_TXPKT_INT) {
8831 + int_status &= ~(HIF_TXPKT_INT);
8832 + int_enable_mask &= ~(HIF_TXPKT_INT);
8833 + /*Schedule tx cleanup tassklet */
8834 + tasklet_schedule(&hif->tx_cleanup_tasklet);
8837 + /*Disable interrupts, they will be enabled after they are serviced */
8838 + writel_relaxed(int_enable_mask, HIF_INT_ENABLE);
8841 + pr_info("%s : Invalid interrupt : %d\n", __func__,
8843 + writel(int_status, HIF_INT_SRC);
8846 + return IRQ_HANDLED;
8849 +void hif_process_client_req(struct pfe_hif *hif, int req, int data1, int data2)
8851 + unsigned int client_id = data1;
8853 + if (client_id >= HIF_CLIENTS_MAX) {
8854 + pr_err("%s: client id %d out of bounds\n", __func__,
8860 + case REQUEST_CL_REGISTER:
8861 + /* Request for register a client */
8862 + pr_info("%s: register client_id %d\n",
8863 + __func__, client_id);
8864 + pfe_hif_client_register(hif, client_id, (struct
8865 + hif_client_shm *)&hif->shm->client[client_id]);
8868 + case REQUEST_CL_UNREGISTER:
8869 + pr_info("%s: unregister client_id %d\n",
8870 + __func__, client_id);
8872 + /* Request for unregister a client */
8873 + pfe_hif_client_unregister(hif, client_id);
8878 + pr_err("%s: unsupported request %d\n",
8884 + * Process client Tx queues
8885 + * Currently we don't have checking for tx pending
8891 + * This function is NAPI poll function to process HIF Rx queue.
8893 +static int pfe_hif_rx_poll(struct napi_struct *napi, int budget)
8895 + struct pfe_hif *hif = container_of(napi, struct pfe_hif, napi);
8898 +#ifdef HIF_NAPI_STATS
8899 + hif->napi_counters[NAPI_POLL_COUNT]++;
8902 + work_done = pfe_hif_rx_process(hif, budget);
8904 + if (work_done < budget) {
8905 + napi_complete(napi);
8906 + writel(readl_relaxed(HIF_INT_ENABLE) | HIF_RXPKT_INT,
8909 +#ifdef HIF_NAPI_STATS
8911 + hif->napi_counters[NAPI_FULL_BUDGET_COUNT]++;
8919 + * This function initializes the baseaddresses and irq, etc.
8921 +int pfe_hif_init(struct pfe *pfe)
8923 + struct pfe_hif *hif = &pfe->hif;
8926 + pr_info("%s\n", __func__);
8928 + hif->dev = pfe->dev;
8929 + hif->irq = pfe->hif_irq;
8931 + err = pfe_hif_alloc_descr(hif);
8935 + if (pfe_hif_init_buffers(hif)) {
8936 + pr_err("%s: Could not initialize buffer descriptors\n"
8942 + /* Initialize NAPI for Rx processing */
8943 + init_dummy_netdev(&hif->dummy_dev);
8944 + netif_napi_add(&hif->dummy_dev, &hif->napi, pfe_hif_rx_poll);
8945 + napi_enable(&hif->napi);
8947 + spin_lock_init(&hif->tx_lock);
8948 + spin_lock_init(&hif->lock);
8954 + /* Disable tx done interrupt */
8955 + writel(HIF_INT_MASK, HIF_INT_ENABLE);
8957 + gpi_enable(HGPI_BASE_ADDR);
8959 + err = request_irq(hif->irq, hif_isr, 0, "pfe_hif", hif);
8961 + pr_err("%s: failed to get the hif IRQ = %d\n",
8962 + __func__, hif->irq);
8966 + err = request_irq(pfe->wol_irq, wol_isr, 0, "pfe_wol", pfe);
8968 + pr_err("%s: failed to get the wol IRQ = %d\n",
8969 + __func__, pfe->wol_irq);
8973 + tasklet_init(&hif->tx_cleanup_tasklet,
8974 + (void(*)(unsigned long))pfe_tx_do_cleanup,
8975 + (unsigned long)hif);
8979 + pfe_hif_free_descr(hif);
8984 +/* pfe_hif_exit- */
8985 +void pfe_hif_exit(struct pfe *pfe)
8987 + struct pfe_hif *hif = &pfe->hif;
8989 + pr_info("%s\n", __func__);
8991 + tasklet_kill(&hif->tx_cleanup_tasklet);
8993 + spin_lock_bh(&hif->lock);
8994 + hif->shm->g_client_status[0] = 0;
8995 + /* Make sure all clients are disabled*/
8996 + hif->shm->g_client_status[1] = 0;
8998 + spin_unlock_bh(&hif->lock);
9000 + /*Disable Rx/Tx */
9001 + gpi_disable(HGPI_BASE_ADDR);
9005 + napi_disable(&hif->napi);
9006 + netif_napi_del(&hif->napi);
9008 + free_irq(pfe->wol_irq, pfe);
9009 + free_irq(hif->irq, hif);
9011 + pfe_hif_release_buffers(hif);
9012 + pfe_hif_free_descr(hif);
9015 +++ b/drivers/staging/fsl_ppfe/pfe_hif.h
9017 +/* SPDX-License-Identifier: GPL-2.0+ */
9019 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9020 + * Copyright 2017 NXP
9023 +#ifndef _PFE_HIF_H_
9024 +#define _PFE_HIF_H_
9026 +#include <linux/netdevice.h>
9028 +#define HIF_NAPI_STATS
9030 +#define HIF_CLIENT_QUEUES_MAX 16
9031 +#define HIF_RX_POLL_WEIGHT 64
9033 +#define HIF_RX_PKT_MIN_SIZE 0x800 /* 2KB */
9034 +#define HIF_RX_PKT_MIN_SIZE_MASK ~(HIF_RX_PKT_MIN_SIZE - 1)
9035 +#define ROUND_MIN_RX_SIZE(_sz) (((_sz) + (HIF_RX_PKT_MIN_SIZE - 1)) \
9036 + & HIF_RX_PKT_MIN_SIZE_MASK)
9037 +#define PRESENT_OFST_IN_PAGE(_buf) (((unsigned long int)(_buf) & (PAGE_SIZE \
9038 + - 1)) & HIF_RX_PKT_MIN_SIZE_MASK)
9041 + NAPI_SCHED_COUNT = 0,
9043 + NAPI_PACKET_COUNT,
9045 + NAPI_FULL_BUDGET_COUNT,
9046 + NAPI_CLIENT_FULL_COUNT,
9051 + * HIF_TX_DESC_NT value should be always greter than 4,
9052 + * Otherwise HIF_TX_POLL_MARK will become zero.
9054 +#define HIF_RX_DESC_NT 256
9055 +#define HIF_TX_DESC_NT 2048
9057 +#define HIF_FIRST_BUFFER BIT(0)
9058 +#define HIF_LAST_BUFFER BIT(1)
9059 +#define HIF_DONT_DMA_MAP BIT(2)
9060 +#define HIF_DATA_VALID BIT(3)
9061 +#define HIF_TSO BIT(4)
9069 +/*structure to store client queue info */
9070 +struct hif_rx_queue {
9071 + struct rx_queue_desc *base;
9076 +struct hif_tx_queue {
9077 + struct tx_queue_desc *base;
9082 +/*Structure to store the client info */
9083 +struct hif_client {
9085 + struct hif_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
9087 + struct hif_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
9090 +/*HIF hardware buffer descriptor */
9098 +struct __hif_desc {
9104 +struct hif_desc_sw {
9121 + struct hif_hdr hdr;
9126 +struct hif_ipsec_hdr {
9130 +/* HIF_CTRL_TX... defines */
9131 +#define HIF_CTRL_TX_CHECKSUM BIT(2)
9133 +/* HIF_CTRL_RX... defines */
9134 +#define HIF_CTRL_RX_OFFSET_OFST (24)
9135 +#define HIF_CTRL_RX_CHECKSUMMED BIT(2)
9136 +#define HIF_CTRL_RX_CONTINUED BIT(1)
9139 + /* To store registered clients in hif layer */
9140 + struct hif_client client[HIF_CLIENTS_MAX];
9141 + struct hif_shm *shm;
9144 + void *descr_baseaddr_v;
9145 + unsigned long descr_baseaddr_p;
9147 + struct hif_desc *rx_base;
9149 + u32 rxtoclean_index;
9150 + void *rx_buf_addr[HIF_RX_DESC_NT];
9151 + int rx_buf_len[HIF_RX_DESC_NT];
9153 + unsigned int client_id;
9154 + unsigned int client_ctrl;
9155 + unsigned int started;
9157 + struct hif_desc *tx_base;
9163 + struct hif_desc_sw tx_sw_queue[HIF_TX_DESC_NT];
9165 +/* tx_lock synchronizes hif packet tx as well as pfe_hif structure access */
9166 + spinlock_t tx_lock;
9167 +/* lock synchronizes hif rx queue processing */
9169 + struct net_device dummy_dev;
9170 + struct napi_struct napi;
9171 + struct device *dev;
9173 +#ifdef HIF_NAPI_STATS
9174 + unsigned int napi_counters[NAPI_MAX_COUNT];
9176 + struct tasklet_struct tx_cleanup_tasklet;
9179 +void __hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int
9180 + q_no, void *data, u32 len, unsigned int flags);
9181 +int hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int q_no,
9182 + void *data, unsigned int len);
9183 +void __hif_tx_done_process(struct pfe_hif *hif, int count);
9184 +void hif_process_client_req(struct pfe_hif *hif, int req, int data1, int
9186 +int pfe_hif_init(struct pfe *pfe);
9187 +void pfe_hif_exit(struct pfe *pfe);
9188 +void pfe_hif_rx_idle(struct pfe_hif *hif);
9189 +static inline void hif_tx_done_process(struct pfe_hif *hif, int count)
9191 + spin_lock_bh(&hif->tx_lock);
9192 + __hif_tx_done_process(hif, count);
9193 + spin_unlock_bh(&hif->tx_lock);
9196 +static inline void hif_tx_lock(struct pfe_hif *hif)
9198 + spin_lock_bh(&hif->tx_lock);
9201 +static inline void hif_tx_unlock(struct pfe_hif *hif)
9203 + spin_unlock_bh(&hif->tx_lock);
9206 +static inline int __hif_tx_avail(struct pfe_hif *hif)
9208 + return hif->txavail;
9211 +#define __memcpy8(dst, src) memcpy(dst, src, 8)
9212 +#define __memcpy12(dst, src) memcpy(dst, src, 12)
9213 +#define __memcpy(dst, src, len) memcpy(dst, src, len)
9215 +#endif /* _PFE_HIF_H_ */
9217 +++ b/drivers/staging/fsl_ppfe/pfe_hif_lib.c
9219 +// SPDX-License-Identifier: GPL-2.0+
9221 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9222 + * Copyright 2017 NXP
9225 +#include <linux/version.h>
9226 +#include <linux/kernel.h>
9227 +#include <linux/slab.h>
9228 +#include <linux/interrupt.h>
9229 +#include <linux/workqueue.h>
9230 +#include <linux/dma-mapping.h>
9231 +#include <linux/dmapool.h>
9232 +#include <linux/sched.h>
9233 +#include <linux/skbuff.h>
9234 +#include <linux/moduleparam.h>
9235 +#include <linux/cpu.h>
9237 +#include "pfe_mod.h"
9238 +#include "pfe_hif.h"
9239 +#include "pfe_hif_lib.h"
9241 +unsigned int lro_mode;
9242 +unsigned int page_mode;
9243 +unsigned int tx_qos = 1;
9244 +module_param(tx_qos, uint, 0444);
9245 +MODULE_PARM_DESC(tx_qos, "0: disable ,\n"
9246 + "1: enable (default), guarantee no packet drop at TMU level\n");
9247 +unsigned int pfe_pkt_size;
9248 +unsigned int pfe_pkt_headroom;
9249 +unsigned int emac_txq_cnt;
9253 + * Common functions used by HIF client drivers
9256 +/*HIF shared memory Global variable */
9257 +struct hif_shm ghif_shm;
9259 +/* Cleanup the HIF shared memory, release HIF rx_buffer_pool.
9260 + * This function should be called after pfe_hif_exit
9262 + * @param[in] hif_shm Shared memory address location in DDR
9264 +static void pfe_hif_shm_clean(struct hif_shm *hif_shm)
9269 + for (i = 0; i < hif_shm->rx_buf_pool_cnt; i++) {
9270 + pkt = hif_shm->rx_buf_pool[i];
9272 + hif_shm->rx_buf_pool[i] = NULL;
9273 + pkt -= pfe_pkt_headroom;
9276 + put_page(virt_to_page(pkt));
9283 +/* Initialize shared memory used between HIF driver and clients,
9284 + * allocate rx_buffer_pool required for HIF Rx descriptors.
9285 + * This function should be called before initializing HIF driver.
9287 + * @param[in] hif_shm Shared memory address location in DDR
9288 + * @rerurn 0 - on succes, <0 on fail to initialize
9290 +static int pfe_hif_shm_init(struct hif_shm *hif_shm)
9295 + memset(hif_shm, 0, sizeof(struct hif_shm));
9296 + hif_shm->rx_buf_pool_cnt = HIF_RX_DESC_NT;
9298 + for (i = 0; i < hif_shm->rx_buf_pool_cnt; i++) {
9300 + pkt = (void *)__get_free_page(GFP_KERNEL |
9303 + pkt = kmalloc(PFE_BUF_SIZE, GFP_KERNEL | GFP_DMA_PFE);
9307 + hif_shm->rx_buf_pool[i] = pkt + pfe_pkt_headroom;
9315 + pr_err("%s Low memory\n", __func__);
9316 + pfe_hif_shm_clean(hif_shm);
9320 +/*This function sends indication to HIF driver
9322 + * @param[in] hif hif context
9324 +static void hif_lib_indicate_hif(struct pfe_hif *hif, int req, int data1, int
9327 + hif_process_client_req(hif, req, data1, data2);
9330 +void hif_lib_indicate_client(int client_id, int event_type, int qno)
9332 + struct hif_client_s *client = pfe->hif_client[client_id];
9334 + if (!client || (event_type >= HIF_EVENT_MAX) || (qno >=
9335 + HIF_CLIENT_QUEUES_MAX))
9338 + if (!test_and_set_bit(qno, &client->queue_mask[event_type]))
9339 + client->event_handler(client->priv, event_type, qno);
9342 +/*This function releases Rx queue descriptors memory and pre-filled buffers
9344 + * @param[in] client hif_client context
9346 +static void hif_lib_client_release_rx_buffers(struct hif_client_s *client)
9348 + struct rx_queue_desc *desc;
9352 + for (qno = 0; qno < client->rx_qn; qno++) {
9353 + desc = client->rx_q[qno].base;
9355 + for (ii = 0; ii < client->rx_q[qno].size; ii++) {
9356 + buf = (void *)desc->data;
9358 + buf -= pfe_pkt_headroom;
9361 + free_page((unsigned long)buf);
9372 + kfree(client->rx_qbase);
9375 +/*This function allocates memory for the rxq descriptors and pre-fill rx queues
9377 + * @param[in] client client context
9378 + * @param[in] q_size size of the rxQ, all queues are of same size
9380 +static int hif_lib_client_init_rx_buffers(struct hif_client_s *client, int
9383 + struct rx_queue_desc *desc;
9384 + struct hif_client_rx_queue *queue;
9387 + /*Allocate memory for the client queues */
9388 + client->rx_qbase = kzalloc(client->rx_qn * q_size * sizeof(struct
9389 + rx_queue_desc), GFP_KERNEL);
9390 + if (!client->rx_qbase)
9393 + for (qno = 0; qno < client->rx_qn; qno++) {
9394 + queue = &client->rx_q[qno];
9396 + queue->base = client->rx_qbase + qno * q_size * sizeof(struct
9398 + queue->size = q_size;
9399 + queue->read_idx = 0;
9400 + queue->write_idx = 0;
9402 + pr_debug("rx queue: %d, base: %p, size: %d\n", qno,
9403 + queue->base, queue->size);
9406 + for (qno = 0; qno < client->rx_qn; qno++) {
9407 + queue = &client->rx_q[qno];
9408 + desc = queue->base;
9410 + for (ii = 0; ii < queue->size; ii++) {
9411 + desc->ctrl = CL_DESC_BUF_LEN(pfe_pkt_size) |
9424 +static void hif_lib_client_cleanup_tx_queue(struct hif_client_tx_queue *queue)
9426 + pr_debug("%s\n", __func__);
9429 + * Check if there are any pending packets. Client must flush the tx
9430 + * queues before unregistering, by calling by calling
9431 + * hif_lib_tx_get_next_complete()
9433 + * Hif no longer calls since we are no longer registered
9435 + if (queue->tx_pending)
9436 + pr_err("%s: pending transmit packets\n", __func__);
9439 +static void hif_lib_client_release_tx_buffers(struct hif_client_s *client)
9443 + pr_debug("%s\n", __func__);
9445 + for (qno = 0; qno < client->tx_qn; qno++)
9446 + hif_lib_client_cleanup_tx_queue(&client->tx_q[qno]);
9448 + kfree(client->tx_qbase);
9451 +static int hif_lib_client_init_tx_buffers(struct hif_client_s *client, int
9454 + struct hif_client_tx_queue *queue;
9457 + client->tx_qbase = kzalloc(client->tx_qn * q_size * sizeof(struct
9458 + tx_queue_desc), GFP_KERNEL);
9459 + if (!client->tx_qbase)
9462 + for (qno = 0; qno < client->tx_qn; qno++) {
9463 + queue = &client->tx_q[qno];
9465 + queue->base = client->tx_qbase + qno * q_size * sizeof(struct
9467 + queue->size = q_size;
9468 + queue->read_idx = 0;
9469 + queue->write_idx = 0;
9470 + queue->tx_pending = 0;
9471 + queue->nocpy_flag = 0;
9472 + queue->prev_tmu_tx_pkts = 0;
9473 + queue->done_tmu_tx_pkts = 0;
9475 + pr_debug("tx queue: %d, base: %p, size: %d\n", qno,
9476 + queue->base, queue->size);
9482 +static int hif_lib_event_dummy(void *priv, int event_type, int qno)
9487 +int hif_lib_client_register(struct hif_client_s *client)
9489 + struct hif_shm *hif_shm;
9490 + struct hif_client_shm *client_shm;
9492 + /* int loop_cnt = 0; */
9494 + pr_debug("%s\n", __func__);
9496 + /*Allocate memory before spin_lock*/
9497 + if (hif_lib_client_init_rx_buffers(client, client->rx_qsize)) {
9502 + if (hif_lib_client_init_tx_buffers(client, client->tx_qsize)) {
9507 + spin_lock_bh(&pfe->hif.lock);
9508 + if (!(client->pfe) || (client->id >= HIF_CLIENTS_MAX) ||
9509 + (pfe->hif_client[client->id])) {
9514 + hif_shm = client->pfe->hif.shm;
9516 + if (!client->event_handler)
9517 + client->event_handler = hif_lib_event_dummy;
9519 + /*Initialize client specific shared memory */
9520 + client_shm = (struct hif_client_shm *)&hif_shm->client[client->id];
9521 + client_shm->rx_qbase = (unsigned long int)client->rx_qbase;
9522 + client_shm->rx_qsize = client->rx_qsize;
9523 + client_shm->tx_qbase = (unsigned long int)client->tx_qbase;
9524 + client_shm->tx_qsize = client->tx_qsize;
9525 + client_shm->ctrl = (client->tx_qn << CLIENT_CTRL_TX_Q_CNT_OFST) |
9526 + (client->rx_qn << CLIENT_CTRL_RX_Q_CNT_OFST);
9527 + /* spin_lock_init(&client->rx_lock); */
9529 + for (i = 0; i < HIF_EVENT_MAX; i++) {
9530 + client->queue_mask[i] = 0; /*
9531 + * By default all events are
9536 + /*Indicate to HIF driver*/
9537 + hif_lib_indicate_hif(&pfe->hif, REQUEST_CL_REGISTER, client->id, 0);
9539 + pr_debug("%s: client: %p, client_id: %d, tx_qsize: %d, rx_qsize: %d\n",
9540 + __func__, client, client->id, client->tx_qsize,
9541 + client->rx_qsize);
9543 + client->cpu_id = -1;
9545 + pfe->hif_client[client->id] = client;
9546 + spin_unlock_bh(&pfe->hif.lock);
9551 + spin_unlock_bh(&pfe->hif.lock);
9552 + hif_lib_client_release_tx_buffers(client);
9555 + hif_lib_client_release_rx_buffers(client);
9561 +int hif_lib_client_unregister(struct hif_client_s *client)
9563 + struct pfe *pfe = client->pfe;
9564 + u32 client_id = client->id;
9567 + "%s : client: %p, client_id: %d, txQ_depth: %d, rxQ_depth: %d\n"
9568 + , __func__, client, client->id, client->tx_qsize,
9569 + client->rx_qsize);
9571 + spin_lock_bh(&pfe->hif.lock);
9572 + hif_lib_indicate_hif(&pfe->hif, REQUEST_CL_UNREGISTER, client->id, 0);
9574 + hif_lib_client_release_tx_buffers(client);
9575 + hif_lib_client_release_rx_buffers(client);
9576 + pfe->hif_client[client_id] = NULL;
9577 + spin_unlock_bh(&pfe->hif.lock);
9582 +int hif_lib_event_handler_start(struct hif_client_s *client, int event,
9585 + struct hif_client_rx_queue *queue = &client->rx_q[qno];
9586 + struct rx_queue_desc *desc = queue->base + queue->read_idx;
9588 + if ((event >= HIF_EVENT_MAX) || (qno >= HIF_CLIENT_QUEUES_MAX)) {
9589 + pr_debug("%s: Unsupported event : %d queue number : %d\n",
9590 + __func__, event, qno);
9594 + test_and_clear_bit(qno, &client->queue_mask[event]);
9597 + case EVENT_RX_PKT_IND:
9598 + if (!(desc->ctrl & CL_DESC_OWN))
9599 + hif_lib_indicate_client(client->id,
9600 + EVENT_RX_PKT_IND, qno);
9603 + case EVENT_HIGH_RX_WM:
9604 + case EVENT_TXDONE_IND:
9613 + * This function gets one packet from the specified client queue
9614 + * It also refill the rx buffer
9616 +void *hif_lib_receive_pkt(struct hif_client_s *client, int qno, int *len, int
9617 + *ofst, unsigned int *rx_ctrl,
9618 + unsigned int *desc_ctrl, void **priv_data)
9620 + struct hif_client_rx_queue *queue = &client->rx_q[qno];
9621 + struct rx_queue_desc *desc;
9625 + * Following lock is to protect rx queue access from,
9626 + * hif_lib_event_handler_start.
9627 + * In general below lock is not required, because hif_lib_xmit_pkt and
9628 + * hif_lib_event_handler_start are called from napi poll and which is
9629 + * not re-entrant. But if some client use in different way this lock is
9632 + /*spin_lock_irqsave(&client->rx_lock, flags); */
9633 + desc = queue->base + queue->read_idx;
9634 + if (!(desc->ctrl & CL_DESC_OWN)) {
9635 + pkt = desc->data - pfe_pkt_headroom;
9637 + *rx_ctrl = desc->client_ctrl;
9638 + *desc_ctrl = desc->ctrl;
9640 + if (desc->ctrl & CL_DESC_FIRST) {
9641 + u16 size = *rx_ctrl >> HIF_CTRL_RX_OFFSET_OFST;
9644 + size += PFE_PARSE_INFO_SIZE;
9645 + *len = CL_DESC_BUF_LEN(desc->ctrl) -
9646 + PFE_PKT_HEADER_SZ - size;
9647 + *ofst = pfe_pkt_headroom + PFE_PKT_HEADER_SZ
9649 + *priv_data = desc->data + PFE_PKT_HEADER_SZ;
9651 + *len = CL_DESC_BUF_LEN(desc->ctrl) -
9652 + PFE_PKT_HEADER_SZ - PFE_PARSE_INFO_SIZE;
9653 + *ofst = pfe_pkt_headroom
9654 + + PFE_PKT_HEADER_SZ
9655 + + PFE_PARSE_INFO_SIZE;
9656 + *priv_data = NULL;
9660 + *len = CL_DESC_BUF_LEN(desc->ctrl);
9661 + *ofst = pfe_pkt_headroom;
9665 + * Needed so we don't free a buffer/page
9666 + * twice on module_exit
9668 + desc->data = NULL;
9671 + * Ensure everything else is written to DDR before
9672 + * writing bd->ctrl
9676 + desc->ctrl = CL_DESC_BUF_LEN(pfe_pkt_size) | CL_DESC_OWN;
9677 + queue->read_idx = (queue->read_idx + 1) & (queue->size - 1);
9680 + /*spin_unlock_irqrestore(&client->rx_lock, flags); */
9684 +static inline void hif_hdr_write(struct hif_hdr *pkt_hdr, unsigned int
9685 + client_id, unsigned int qno,
9688 + /* Optimize the write since the destinaton may be non-cacheable */
9689 + if (!((unsigned long)pkt_hdr & 0x3)) {
9690 + ((u32 *)pkt_hdr)[0] = (client_ctrl << 16) | (qno << 8) |
9693 + ((u16 *)pkt_hdr)[0] = (qno << 8) | (client_id & 0xFF);
9694 + ((u16 *)pkt_hdr)[1] = (client_ctrl & 0xFFFF);
9698 +/*This function puts the given packet in the specific client queue */
9699 +void __hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void
9700 + *data, unsigned int len, u32 client_ctrl,
9701 + unsigned int flags, void *client_data)
9703 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
9704 + struct tx_queue_desc *desc = queue->base + queue->write_idx;
9706 + /* First buffer */
9707 + if (flags & HIF_FIRST_BUFFER) {
9708 + data -= sizeof(struct hif_hdr);
9709 + len += sizeof(struct hif_hdr);
9711 + hif_hdr_write(data, client->id, qno, client_ctrl);
9714 + desc->data = client_data;
9715 + desc->ctrl = CL_DESC_OWN | CL_DESC_FLAGS(flags);
9717 + __hif_xmit_pkt(&pfe->hif, client->id, qno, data, len, flags);
9719 + queue->write_idx = (queue->write_idx + 1) & (queue->size - 1);
9720 + queue->tx_pending++;
9721 + queue->jiffies_last_packet = jiffies;
9724 +void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
9725 + unsigned int *flags, int count)
9727 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
9728 + struct tx_queue_desc *desc = queue->base + queue->read_idx;
9730 + pr_debug("%s: qno : %d rd_indx: %d pending:%d\n", __func__, qno,
9731 + queue->read_idx, queue->tx_pending);
9733 + if (!queue->tx_pending)
9736 + if (queue->nocpy_flag && !queue->done_tmu_tx_pkts) {
9737 + u32 tmu_tx_pkts = be32_to_cpu(pe_dmem_read(TMU0_ID +
9738 + client->id, TMU_DM_TX_TRANS, 4));
9740 + if (queue->prev_tmu_tx_pkts > tmu_tx_pkts)
9741 + queue->done_tmu_tx_pkts = UINT_MAX -
9742 + queue->prev_tmu_tx_pkts + tmu_tx_pkts;
9744 + queue->done_tmu_tx_pkts = tmu_tx_pkts -
9745 + queue->prev_tmu_tx_pkts;
9747 + queue->prev_tmu_tx_pkts = tmu_tx_pkts;
9749 + if (!queue->done_tmu_tx_pkts)
9753 + if (desc->ctrl & CL_DESC_OWN)
9756 + queue->read_idx = (queue->read_idx + 1) & (queue->size - 1);
9757 + queue->tx_pending--;
9759 + *flags = CL_DESC_GET_FLAGS(desc->ctrl);
9761 + if (queue->done_tmu_tx_pkts && (*flags & HIF_LAST_BUFFER))
9762 + queue->done_tmu_tx_pkts--;
9764 + return desc->data;
9767 +static void hif_lib_tmu_credit_init(struct pfe *pfe)
9771 + for (i = 0; i < NUM_GEMAC_SUPPORT; i++)
9772 + for (q = 0; q < emac_txq_cnt; q++) {
9773 + pfe->tmu_credit.tx_credit_max[i][q] = (q == 0) ?
9774 + DEFAULT_Q0_QDEPTH : DEFAULT_MAX_QDEPTH;
9775 + pfe->tmu_credit.tx_credit[i][q] =
9776 + pfe->tmu_credit.tx_credit_max[i][q];
9780 +/* __hif_lib_update_credit
9782 + * @param[in] client hif client context
9783 + * @param[in] queue queue number in match with TMU
9785 +void __hif_lib_update_credit(struct hif_client_s *client, unsigned int queue)
9787 + unsigned int tmu_tx_packets, tmp;
9790 + tmu_tx_packets = be32_to_cpu(pe_dmem_read(TMU0_ID +
9791 + client->id, (TMU_DM_TX_TRANS + (queue * 4)), 4));
9793 + /* tx_packets counter overflowed */
9794 + if (tmu_tx_packets >
9795 + pfe->tmu_credit.tx_packets[client->id][queue]) {
9796 + tmp = UINT_MAX - tmu_tx_packets +
9797 + pfe->tmu_credit.tx_packets[client->id][queue];
9799 + pfe->tmu_credit.tx_credit[client->id][queue] =
9800 + pfe->tmu_credit.tx_credit_max[client->id][queue] - tmp;
9802 + /* TMU tx <= pfe_eth tx, normal case or both OF since
9805 + pfe->tmu_credit.tx_credit[client->id][queue] =
9806 + pfe->tmu_credit.tx_credit_max[client->id][queue] -
9807 + (pfe->tmu_credit.tx_packets[client->id][queue] -
9813 +int pfe_hif_lib_init(struct pfe *pfe)
9817 + pr_info("%s\n", __func__);
9821 + pfe_pkt_size = min(PAGE_SIZE, MAX_PFE_PKT_SIZE);
9822 + pfe_pkt_headroom = 0;
9825 + pfe_pkt_size = PFE_PKT_SIZE;
9826 + pfe_pkt_headroom = PFE_PKT_HEADROOM;
9830 + emac_txq_cnt = EMAC_TXQ_CNT / 2;
9832 + emac_txq_cnt = EMAC_TXQ_CNT;
9834 + hif_lib_tmu_credit_init(pfe);
9835 + pfe->hif.shm = &ghif_shm;
9836 + rc = pfe_hif_shm_init(pfe->hif.shm);
9841 +void pfe_hif_lib_exit(struct pfe *pfe)
9843 + pr_info("%s\n", __func__);
9845 + pfe_hif_shm_clean(pfe->hif.shm);
9848 +++ b/drivers/staging/fsl_ppfe/pfe_hif_lib.h
9850 +/* SPDX-License-Identifier: GPL-2.0+ */
9852 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
9853 + * Copyright 2017 NXP
9856 +#ifndef _PFE_HIF_LIB_H_
9857 +#define _PFE_HIF_LIB_H_
9859 +#include "pfe_hif.h"
9861 +#define HIF_CL_REQ_TIMEOUT 10
9862 +#define GFP_DMA_PFE 0
9863 +#define PFE_PARSE_INFO_SIZE 16
9866 + REQUEST_CL_REGISTER = 0,
9867 + REQUEST_CL_UNREGISTER,
9872 + /* Event to indicate that client rx queue is reached water mark level */
9873 + EVENT_HIGH_RX_WM = 0,
9874 + /* Event to indicate that, packet received for client */
9876 + /* Event to indicate that, packet tx done for client */
9881 +/*structure to store client queue info */
9883 +/*structure to store client queue info */
9884 +struct hif_client_rx_queue {
9885 + struct rx_queue_desc *base;
9891 +struct hif_client_tx_queue {
9892 + struct tx_queue_desc *base;
9897 + unsigned long jiffies_last_packet;
9899 + u32 prev_tmu_tx_pkts;
9900 + u32 done_tmu_tx_pkts;
9903 +struct hif_client_s {
9912 + struct hif_client_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
9913 + struct hif_client_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
9914 + int (*event_handler)(void *priv, int event, int data);
9915 + unsigned long queue_mask[HIF_EVENT_MAX];
9921 + * Client specific shared memory
9922 + * It contains number of Rx/Tx queues, base addresses and queue sizes
9924 +struct hif_client_shm {
9925 + u32 ctrl; /*0-7: number of Rx queues, 8-15: number of tx queues */
9926 + unsigned long rx_qbase; /*Rx queue base address */
9927 + u32 rx_qsize; /*each Rx queue size, all Rx queues are of same size */
9928 + unsigned long tx_qbase; /* Tx queue base address */
9929 + u32 tx_qsize; /*each Tx queue size, all Tx queues are of same size */
9932 +/*Client shared memory ctrl bit description */
9933 +#define CLIENT_CTRL_RX_Q_CNT_OFST 0
9934 +#define CLIENT_CTRL_TX_Q_CNT_OFST 8
9935 +#define CLIENT_CTRL_RX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_RX_Q_CNT_OFST) \
9937 +#define CLIENT_CTRL_TX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_TX_Q_CNT_OFST) \
9941 + * Shared memory used to communicate between HIF driver and host/client drivers
9942 + * Before starting the hif driver rx_buf_pool ans rx_buf_pool_cnt should be
9943 + * initialized with host buffers and buffers count in the pool.
9944 + * rx_buf_pool_cnt should be >= HIF_RX_DESC_NT.
9948 + u32 rx_buf_pool_cnt; /*Number of rx buffers available*/
9949 + /*Rx buffers required to initialize HIF rx descriptors */
9950 + void *rx_buf_pool[HIF_RX_DESC_NT];
9951 + unsigned long g_client_status[2]; /*Global client status bit mask */
9952 + /* Client specific shared memory */
9953 + struct hif_client_shm client[HIF_CLIENTS_MAX];
9956 +#define CL_DESC_OWN BIT(31)
9957 +/* This sets owner ship to HIF driver */
9958 +#define CL_DESC_LAST BIT(30)
9959 +/* This indicates last packet for multi buffers handling */
9960 +#define CL_DESC_FIRST BIT(29)
9961 +/* This indicates first packet for multi buffers handling */
9963 +#define CL_DESC_BUF_LEN(x) ((x) & 0xFFFF)
9964 +#define CL_DESC_FLAGS(x) (((x) & 0xF) << 16)
9965 +#define CL_DESC_GET_FLAGS(x) (((x) >> 16) & 0xF)
9967 +struct rx_queue_desc {
9969 + u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
9973 +struct tx_queue_desc {
9975 + u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
9978 +/* HIF Rx is not working properly for 2-byte aligned buffers and
9979 + * ip_header should be 4byte aligned for better iperformance.
9980 + * "ip_header = 64 + 6(hif_header) + 14 (MAC Header)" will be 4byte aligned.
9982 +#define PFE_PKT_HEADER_SZ sizeof(struct hif_hdr)
9983 +/* must be big enough for headroom, pkt size and skb shared info */
9984 +#define PFE_BUF_SIZE 2048
9985 +#define PFE_PKT_HEADROOM 128
9987 +#define SKB_SHARED_INFO_SIZE SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
9988 +#define PFE_PKT_SIZE (PFE_BUF_SIZE - PFE_PKT_HEADROOM \
9989 + - SKB_SHARED_INFO_SIZE)
9990 +#define MAX_L2_HDR_SIZE 14 /* Not correct for VLAN/PPPoE */
9991 +#define MAX_L3_HDR_SIZE 20 /* Not correct for IPv6 */
9992 +#define MAX_L4_HDR_SIZE 60 /* TCP with maximum options */
9993 +#define MAX_HDR_SIZE (MAX_L2_HDR_SIZE + MAX_L3_HDR_SIZE \
9994 + + MAX_L4_HDR_SIZE)
9995 +/* Used in page mode to clamp packet size to the maximum supported by the hif
9996 + *hw interface (<16KiB)
9998 +#define MAX_PFE_PKT_SIZE 16380UL
10000 +extern unsigned int pfe_pkt_size;
10001 +extern unsigned int pfe_pkt_headroom;
10002 +extern unsigned int page_mode;
10003 +extern unsigned int lro_mode;
10004 +extern unsigned int tx_qos;
10005 +extern unsigned int emac_txq_cnt;
10007 +int pfe_hif_lib_init(struct pfe *pfe);
10008 +void pfe_hif_lib_exit(struct pfe *pfe);
10009 +int hif_lib_client_register(struct hif_client_s *client);
10010 +int hif_lib_client_unregister(struct hif_client_s *client);
10011 +void __hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void
10012 + *data, unsigned int len, u32 client_ctrl,
10013 + unsigned int flags, void *client_data);
10014 +int hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void *data,
10015 + unsigned int len, u32 client_ctrl, void *client_data);
10016 +void hif_lib_indicate_client(int cl_id, int event, int data);
10017 +int hif_lib_event_handler_start(struct hif_client_s *client, int event, int
10019 +int hif_lib_tmu_queue_start(struct hif_client_s *client, int qno);
10020 +int hif_lib_tmu_queue_stop(struct hif_client_s *client, int qno);
10021 +void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
10022 + unsigned int *flags, int count);
10023 +void *hif_lib_receive_pkt(struct hif_client_s *client, int qno, int *len, int
10024 + *ofst, unsigned int *rx_ctrl,
10025 + unsigned int *desc_ctrl, void **priv_data);
10026 +void __hif_lib_update_credit(struct hif_client_s *client, unsigned int queue);
10027 +void hif_lib_set_rx_cpu_affinity(struct hif_client_s *client, int cpu_id);
10028 +void hif_lib_set_tx_queue_nocpy(struct hif_client_s *client, int qno, int
10030 +static inline int hif_lib_tx_avail(struct hif_client_s *client, unsigned int
10033 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
10035 + return (queue->size - queue->tx_pending);
10038 +static inline int hif_lib_get_tx_wr_index(struct hif_client_s *client, unsigned
10041 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
10043 + return queue->write_idx;
10046 +static inline int hif_lib_tx_pending(struct hif_client_s *client, unsigned int
10049 + struct hif_client_tx_queue *queue = &client->tx_q[qno];
10051 + return queue->tx_pending;
10054 +#define hif_lib_tx_credit_avail(pfe, id, qno) \
10055 + ((pfe)->tmu_credit.tx_credit[id][qno])
10057 +#define hif_lib_tx_credit_max(pfe, id, qno) \
10058 + ((pfe)->tmu_credit.tx_credit_max[id][qno])
10063 +#define hif_lib_tx_credit_use(pfe, id, qno, credit) \
10064 + ({ typeof(pfe) pfe_ = pfe; \
10065 + typeof(id) id_ = id; \
10066 + typeof(qno) qno_ = qno; \
10067 + typeof(credit) credit_ = credit; \
10070 + (pfe_)->tmu_credit.tx_credit[id_][qno_]\
10072 + (pfe_)->tmu_credit.tx_packets[id_][qno_]\
10078 +#endif /* _PFE_HIF_LIB_H_ */
10080 +++ b/drivers/staging/fsl_ppfe/pfe_hw.c
10082 +// SPDX-License-Identifier: GPL-2.0+
10084 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10085 + * Copyright 2017 NXP
10088 +#include "pfe_mod.h"
10089 +#include "pfe_hw.h"
10091 +/* Functions to handle most of pfe hw register initialization */
10092 +int pfe_hw_init(struct pfe *pfe, int resume)
10094 + struct class_cfg class_cfg = {
10095 + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
10096 + .route_table_baseaddr = pfe->ddr_phys_baseaddr +
10097 + ROUTE_TABLE_BASEADDR,
10098 + .route_table_hash_bits = ROUTE_TABLE_HASH_BITS,
10101 + struct tmu_cfg tmu_cfg = {
10102 + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
10103 + .llm_base_addr = pfe->ddr_phys_baseaddr + TMU_LLM_BASEADDR,
10104 + .llm_queue_len = TMU_LLM_QUEUE_LEN,
10107 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10108 + struct util_cfg util_cfg = {
10109 + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
10113 + struct BMU_CFG bmu1_cfg = {
10114 + .baseaddr = CBUS_VIRT_TO_PFE(LMEM_BASE_ADDR +
10115 + BMU1_LMEM_BASEADDR),
10116 + .count = BMU1_BUF_COUNT,
10117 + .size = BMU1_BUF_SIZE,
10118 + .low_watermark = 10,
10119 + .high_watermark = 15,
10122 + struct BMU_CFG bmu2_cfg = {
10123 + .baseaddr = DDR_PHYS_TO_PFE(pfe->ddr_phys_baseaddr +
10124 + BMU2_DDR_BASEADDR),
10125 + .count = BMU2_BUF_COUNT,
10126 + .size = BMU2_BUF_SIZE,
10127 + .low_watermark = 250,
10128 + .high_watermark = 253,
10131 + struct gpi_cfg egpi1_cfg = {
10132 + .lmem_rtry_cnt = EGPI1_LMEM_RTRY_CNT,
10133 + .tmlf_txthres = EGPI1_TMLF_TXTHRES,
10134 + .aseq_len = EGPI1_ASEQ_LEN,
10135 + .mtip_pause_reg = CBUS_VIRT_TO_PFE(EMAC1_BASE_ADDR +
10136 + EMAC_TCNTRL_REG),
10139 + struct gpi_cfg egpi2_cfg = {
10140 + .lmem_rtry_cnt = EGPI2_LMEM_RTRY_CNT,
10141 + .tmlf_txthres = EGPI2_TMLF_TXTHRES,
10142 + .aseq_len = EGPI2_ASEQ_LEN,
10143 + .mtip_pause_reg = CBUS_VIRT_TO_PFE(EMAC2_BASE_ADDR +
10144 + EMAC_TCNTRL_REG),
10147 + struct gpi_cfg hgpi_cfg = {
10148 + .lmem_rtry_cnt = HGPI_LMEM_RTRY_CNT,
10149 + .tmlf_txthres = HGPI_TMLF_TXTHRES,
10150 + .aseq_len = HGPI_ASEQ_LEN,
10151 + .mtip_pause_reg = 0,
10154 + pr_info("%s\n", __func__);
10156 +#if !defined(LS1012A_PFE_RESET_WA)
10157 + /* LS1012A needs this to make PE work correctly */
10158 + writel(0x3, CLASS_PE_SYS_CLK_RATIO);
10159 + writel(0x3, TMU_PE_SYS_CLK_RATIO);
10160 + writel(0x3, UTIL_PE_SYS_CLK_RATIO);
10161 + usleep_range(10, 20);
10164 + pr_info("CLASS version: %x\n", readl(CLASS_VERSION));
10165 + pr_info("TMU version: %x\n", readl(TMU_VERSION));
10167 + pr_info("BMU1 version: %x\n", readl(BMU1_BASE_ADDR +
10169 + pr_info("BMU2 version: %x\n", readl(BMU2_BASE_ADDR +
10172 + pr_info("EGPI1 version: %x\n", readl(EGPI1_BASE_ADDR +
10174 + pr_info("EGPI2 version: %x\n", readl(EGPI2_BASE_ADDR +
10176 + pr_info("HGPI version: %x\n", readl(HGPI_BASE_ADDR +
10179 + pr_info("HIF version: %x\n", readl(HIF_VERSION));
10180 + pr_info("HIF NOPCY version: %x\n", readl(HIF_NOCPY_VERSION));
10182 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10183 + pr_info("UTIL version: %x\n", readl(UTIL_VERSION));
10185 + while (!(readl(TMU_CTRL) & ECC_MEM_INIT_DONE))
10188 + hif_rx_disable();
10189 + hif_tx_disable();
10191 + bmu_init(BMU1_BASE_ADDR, &bmu1_cfg);
10193 + pr_info("bmu_init(1) done\n");
10195 + bmu_init(BMU2_BASE_ADDR, &bmu2_cfg);
10197 + pr_info("bmu_init(2) done\n");
10199 + class_cfg.resume = resume ? 1 : 0;
10201 + class_init(&class_cfg);
10203 + pr_info("class_init() done\n");
10205 + tmu_init(&tmu_cfg);
10207 + pr_info("tmu_init() done\n");
10208 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10209 + util_init(&util_cfg);
10211 + pr_info("util_init() done\n");
10213 + gpi_init(EGPI1_BASE_ADDR, &egpi1_cfg);
10215 + pr_info("gpi_init(1) done\n");
10217 + gpi_init(EGPI2_BASE_ADDR, &egpi2_cfg);
10219 + pr_info("gpi_init(2) done\n");
10221 + gpi_init(HGPI_BASE_ADDR, &hgpi_cfg);
10223 + pr_info("gpi_init(hif) done\n");
10225 + bmu_enable(BMU1_BASE_ADDR);
10227 + pr_info("bmu_enable(1) done\n");
10229 + bmu_enable(BMU2_BASE_ADDR);
10231 + pr_info("bmu_enable(2) done\n");
10236 +void pfe_hw_exit(struct pfe *pfe)
10238 + pr_info("%s\n", __func__);
10240 + bmu_disable(BMU1_BASE_ADDR);
10241 + bmu_reset(BMU1_BASE_ADDR);
10243 + bmu_disable(BMU2_BASE_ADDR);
10244 + bmu_reset(BMU2_BASE_ADDR);
10247 +++ b/drivers/staging/fsl_ppfe/pfe_hw.h
10249 +/* SPDX-License-Identifier: GPL-2.0+ */
10251 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10252 + * Copyright 2017 NXP
10255 +#ifndef _PFE_HW_H_
10256 +#define _PFE_HW_H_
10258 +#define PE_SYS_CLK_RATIO 1 /* SYS/AXI = 250MHz, HFE = 500MHz */
10260 +int pfe_hw_init(struct pfe *pfe, int resume);
10261 +void pfe_hw_exit(struct pfe *pfe);
10263 +#endif /* _PFE_HW_H_ */
10265 +++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
10267 +// SPDX-License-Identifier: GPL-2.0+
10269 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10270 + * Copyright 2017 NXP
10273 +#include <linux/module.h>
10274 +#include <linux/device.h>
10275 +#include <linux/of.h>
10276 +#include <linux/of_net.h>
10277 +#include <linux/of_address.h>
10278 +#include <linux/of_mdio.h>
10279 +#include <linux/platform_device.h>
10280 +#include <linux/slab.h>
10281 +#include <linux/clk.h>
10282 +#include <linux/mfd/syscon.h>
10283 +#include <linux/regmap.h>
10285 +#include "pfe_mod.h"
10287 +extern bool pfe_use_old_dts_phy;
10288 +struct ls1012a_pfe_platform_data pfe_platform_data;
10290 +static int pfe_get_gemac_if_properties(struct device_node *gem,
10292 + struct ls1012a_pfe_platform_data *pdata)
10294 + struct device_node *phy_node = NULL;
10300 + addr = of_get_property(gem, "reg", &size);
10302 + port = be32_to_cpup(addr);
10306 + pdata->ls1012a_eth_pdata[port].gem_id = port;
10308 + err = of_get_mac_address(gem, pdata->ls1012a_eth_pdata[port].mac_addr);
10310 + phy_node = of_parse_phandle(gem, "phy-handle", 0);
10311 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
10313 + pfe_use_old_dts_phy = false;
10314 + goto process_phynode;
10315 + } else if (of_phy_is_fixed_link(gem)) {
10316 + pfe_use_old_dts_phy = false;
10317 + if (of_phy_register_fixed_link(gem) < 0) {
10318 + pr_err("broken fixed-link specification\n");
10321 + phy_node = of_node_get(gem);
10322 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
10323 + } else if (of_get_property(gem, "fsl,pfe-phy-if-flags", &size)) {
10324 + pfe_use_old_dts_phy = true;
10325 + /* Use old dts properties for phy handling */
10326 + addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
10327 + pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
10329 + addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
10331 + pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
10334 + phy_id = be32_to_cpup(addr);
10335 + pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
10336 + pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
10339 + /* If PHY is enabled, read mdio properties */
10340 + if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
10344 + pr_info("%s: No PHY or fixed-link\n", __func__);
10349 + err = of_get_phy_mode(gem, &pdata->ls1012a_eth_pdata[port].mii_config);
10351 + pr_err("%s:%d Incorrect Phy mode....\n", __func__,
10354 + addr = of_get_property(gem, "fsl,mdio-mux-val", &size);
10356 + pr_err("%s: Invalid mdio-mux-val....\n", __func__);
10358 + phy_id = be32_to_cpup(addr);
10359 + pdata->ls1012a_eth_pdata[port].mdio_muxval = phy_id;
10362 + if (pdata->ls1012a_eth_pdata[port].phy_id < 32)
10363 + pfe->mdio_muxval[pdata->ls1012a_eth_pdata[port].phy_id] =
10364 + pdata->ls1012a_eth_pdata[port].mdio_muxval;
10367 + pdata->ls1012a_mdio_pdata[port].irq[0] = PHY_POLL;
10378 + * pfe_platform_probe -
10382 +static int pfe_platform_probe(struct platform_device *pdev)
10384 + struct resource res;
10385 + int ii = 0, rc, interface_count = 0, size = 0;
10387 + struct device_node *np, *gem = NULL;
10388 + struct clk *pfe_clk;
10390 + np = pdev->dev.of_node;
10393 + pr_err("Invalid device node\n");
10397 + pfe = kzalloc(sizeof(*pfe), GFP_KERNEL);
10403 + platform_set_drvdata(pdev, pfe);
10405 + if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
10407 + pr_err("unable to configure DMA mask.\n");
10411 + if (of_address_to_resource(np, 1, &res)) {
10413 + pr_err("failed to get ddr resource\n");
10417 + pfe->ddr_phys_baseaddr = res.start;
10418 + pfe->ddr_size = resource_size(&res);
10420 + pfe->ddr_baseaddr = memremap(res.start, resource_size(&res),
10422 + if (!pfe->ddr_baseaddr) {
10423 + pr_err("memremap() ddr failed\n");
10429 + syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
10431 + if (IS_ERR(pfe->scfg)) {
10432 + dev_err(&pdev->dev, "No syscfg phandle specified\n");
10433 + return PTR_ERR(pfe->scfg);
10436 + pfe->cbus_baseaddr = of_iomap(np, 0);
10437 + if (!pfe->cbus_baseaddr) {
10439 + pr_err("failed to get axi resource\n");
10443 + pfe->hif_irq = platform_get_irq(pdev, 0);
10444 + if (pfe->hif_irq < 0) {
10445 + pr_err("platform_get_irq for hif failed\n");
10446 + rc = pfe->hif_irq;
10447 + goto err_hif_irq;
10450 + pfe->wol_irq = platform_get_irq(pdev, 2);
10451 + if (pfe->wol_irq < 0) {
10452 + pr_err("platform_get_irq for WoL failed\n");
10453 + rc = pfe->wol_irq;
10454 + goto err_hif_irq;
10457 + /* Read interface count */
10458 + prop = of_get_property(np, "fsl,pfe-num-interfaces", &size);
10460 + pr_err("Failed to read number of interfaces\n");
10465 + interface_count = be32_to_cpup(prop);
10466 + if (interface_count <= 0) {
10467 + pr_err("No ethernet interface count : %d\n",
10468 + interface_count);
10473 + pfe_platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
10475 + while ((gem = of_get_next_child(np, gem))) {
10476 + if (of_find_property(gem, "reg", &size)) {
10477 + pfe_get_gemac_if_properties(gem, ii,
10478 + &pfe_platform_data);
10483 + if (interface_count != ii)
10484 + pr_info("missing some of gemac interface properties.\n");
10486 + pfe->dev = &pdev->dev;
10488 + pfe->dev->platform_data = &pfe_platform_data;
10490 + /* declare WoL capabilities */
10491 + device_init_wakeup(&pdev->dev, true);
10493 + /* find the clocks */
10494 + pfe_clk = devm_clk_get(pfe->dev, "pfe");
10495 + if (IS_ERR(pfe_clk))
10496 + return PTR_ERR(pfe_clk);
10498 + /* PFE clock is (platform clock / 2) */
10499 + /* save sys_clk value as KHz */
10500 + pfe->ctrl.sys_clk = clk_get_rate(pfe_clk) / (2 * 1000);
10502 + rc = pfe_probe(pfe);
10511 + iounmap(pfe->cbus_baseaddr);
10514 + memunmap(pfe->ddr_baseaddr);
10517 + platform_set_drvdata(pdev, NULL);
10526 + * pfe_platform_remove -
10528 +static int pfe_platform_remove(struct platform_device *pdev)
10530 + struct pfe *pfe = platform_get_drvdata(pdev);
10533 + pr_info("%s\n", __func__);
10535 + rc = pfe_remove(pfe);
10537 + iounmap(pfe->cbus_baseaddr);
10539 + memunmap(pfe->ddr_baseaddr);
10541 + platform_set_drvdata(pdev, NULL);
10549 +#ifdef CONFIG_PM_SLEEP
10550 +int pfe_platform_suspend(struct device *dev)
10552 + struct pfe *pfe = platform_get_drvdata(to_platform_device(dev));
10553 + struct net_device *netdev;
10558 + for (i = 0; i < (NUM_GEMAC_SUPPORT); i++) {
10559 + netdev = pfe->eth.eth_priv[i]->ndev;
10561 + netif_device_detach(netdev);
10563 + if (netif_running(netdev))
10564 + if (pfe_eth_suspend(netdev))
10568 + /* Shutdown PFE only if we're not waking up the system */
10569 + if (!pfe->wake) {
10570 +#if defined(LS1012A_PFE_RESET_WA)
10571 + pfe_hif_rx_idle(&pfe->hif);
10573 + pfe_ctrl_suspend(&pfe->ctrl);
10574 + pfe_firmware_exit(pfe);
10576 + pfe_hif_exit(pfe);
10577 + pfe_hif_lib_exit(pfe);
10579 + pfe_hw_exit(pfe);
10585 +static int pfe_platform_resume(struct device *dev)
10587 + struct pfe *pfe = platform_get_drvdata(to_platform_device(dev));
10588 + struct net_device *netdev;
10591 + if (!pfe->wake) {
10592 + pfe_hw_init(pfe, 1);
10593 + pfe_hif_lib_init(pfe);
10594 + pfe_hif_init(pfe);
10595 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10600 + pfe_ctrl_resume(&pfe->ctrl);
10603 + for (i = 0; i < (NUM_GEMAC_SUPPORT); i++) {
10604 + netdev = pfe->eth.eth_priv[i]->ndev;
10606 + if (pfe->mdio.mdio_priv[i]->mii_bus)
10607 + pfe_eth_mdio_reset(pfe->mdio.mdio_priv[i]->mii_bus);
10609 + if (netif_running(netdev))
10610 + pfe_eth_resume(netdev);
10612 + netif_device_attach(netdev);
10617 +#define pfe_platform_suspend NULL
10618 +#define pfe_platform_resume NULL
10621 +static const struct dev_pm_ops pfe_platform_pm_ops = {
10622 + SET_SYSTEM_SLEEP_PM_OPS(pfe_platform_suspend, pfe_platform_resume)
10626 +static const struct of_device_id pfe_match[] = {
10628 + .compatible = "fsl,pfe",
10632 +MODULE_DEVICE_TABLE(of, pfe_match);
10634 +static struct platform_driver pfe_platform_driver = {
10635 + .probe = pfe_platform_probe,
10636 + .remove = pfe_platform_remove,
10639 + .of_match_table = pfe_match,
10641 + .pm = &pfe_platform_pm_ops,
10646 +module_platform_driver(pfe_platform_driver);
10647 +MODULE_LICENSE("GPL");
10648 +MODULE_DESCRIPTION("PFE Ethernet driver");
10649 +MODULE_AUTHOR("NXP DNCPE");
10651 +++ b/drivers/staging/fsl_ppfe/pfe_mod.c
10653 +// SPDX-License-Identifier: GPL-2.0+
10655 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10656 + * Copyright 2017 NXP
10659 +#include <linux/dma-mapping.h>
10660 +#include "pfe_mod.h"
10661 +#include "pfe_cdev.h"
10664 +module_param(us, uint, 0444);
10665 +MODULE_PARM_DESC(us, "0: module enabled for kernel networking (DEFAULT)\n"
10666 + "1: module enabled for userspace networking\n");
10672 +int pfe_probe(struct pfe *pfe)
10676 + if (pfe->ddr_size < DDR_MAX_SIZE) {
10677 + pr_err("%s: required DDR memory (%x) above platform ddr memory (%x)\n",
10678 + __func__, (unsigned int)DDR_MAX_SIZE, pfe->ddr_size);
10683 + if (((int)(pfe->ddr_phys_baseaddr + BMU2_DDR_BASEADDR) &
10684 + (8 * SZ_1M - 1)) != 0) {
10685 + pr_err("%s: BMU2 base address (0x%x) must be aligned on 8MB boundary\n",
10686 + __func__, (int)pfe->ddr_phys_baseaddr +
10687 + BMU2_DDR_BASEADDR);
10692 + pr_info("cbus_baseaddr: %lx, ddr_baseaddr: %lx, ddr_phys_baseaddr: %lx, ddr_size: %x\n",
10693 + (unsigned long)pfe->cbus_baseaddr,
10694 + (unsigned long)pfe->ddr_baseaddr,
10695 + pfe->ddr_phys_baseaddr, pfe->ddr_size);
10697 + pfe_lib_init(pfe->cbus_baseaddr, pfe->ddr_baseaddr,
10698 + pfe->ddr_phys_baseaddr, pfe->ddr_size);
10700 + rc = pfe_hw_init(pfe, 0);
10705 + goto firmware_init;
10707 + rc = pfe_hif_lib_init(pfe);
10709 + goto err_hif_lib;
10711 + rc = pfe_hif_init(pfe);
10716 + rc = pfe_firmware_init(pfe);
10718 + goto err_firmware;
10720 + rc = pfe_ctrl_init(pfe);
10724 + rc = pfe_eth_init(pfe);
10728 + rc = pfe_sysfs_init(pfe);
10732 + rc = pfe_debugfs_init(pfe);
10734 + goto err_debugfs;
10737 + /* Creating a character device */
10738 + rc = pfe_cdev_init();
10746 + pfe_debugfs_exit(pfe);
10749 + pfe_sysfs_exit(pfe);
10752 + pfe_eth_exit(pfe);
10755 + pfe_ctrl_exit(pfe);
10758 + pfe_firmware_exit(pfe);
10762 + goto err_hif_lib;
10764 + pfe_hif_exit(pfe);
10767 + pfe_hif_lib_exit(pfe);
10770 + pfe_hw_exit(pfe);
10779 +int pfe_remove(struct pfe *pfe)
10781 + pr_info("%s\n", __func__);
10786 + pfe_debugfs_exit(pfe);
10788 + pfe_sysfs_exit(pfe);
10790 + pfe_eth_exit(pfe);
10792 + pfe_ctrl_exit(pfe);
10794 +#if defined(LS1012A_PFE_RESET_WA)
10795 + pfe_hif_rx_idle(&pfe->hif);
10797 + pfe_firmware_exit(pfe);
10802 + pfe_hif_exit(pfe);
10804 + pfe_hif_lib_exit(pfe);
10807 + pfe_hw_exit(pfe);
10812 +++ b/drivers/staging/fsl_ppfe/pfe_mod.h
10814 +/* SPDX-License-Identifier: GPL-2.0+ */
10816 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10817 + * Copyright 2017 NXP
10820 +#ifndef _PFE_MOD_H_
10821 +#define _PFE_MOD_H_
10823 +#include <linux/device.h>
10824 +#include <linux/elf.h>
10826 +extern unsigned int us;
10830 +#include "pfe_hw.h"
10831 +#include "pfe_firmware.h"
10832 +#include "pfe_ctrl.h"
10833 +#include "pfe_hif.h"
10834 +#include "pfe_hif_lib.h"
10835 +#include "pfe_eth.h"
10836 +#include "pfe_sysfs.h"
10837 +#include "pfe_perfmon.h"
10838 +#include "pfe_debugfs.h"
10840 +#define PHYID_MAX_VAL 32
10842 +struct pfe_tmu_credit {
10843 + /* Number of allowed TX packet in-flight, matches TMU queue size */
10844 + unsigned int tx_credit[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
10845 + unsigned int tx_credit_max[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
10846 + unsigned int tx_packets[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
10850 + struct regmap *scfg;
10851 + unsigned long ddr_phys_baseaddr;
10852 + void *ddr_baseaddr;
10853 + unsigned int ddr_size;
10854 + void *cbus_baseaddr;
10855 + void *apb_baseaddr;
10856 + unsigned long iram_phys_baseaddr;
10857 + void *iram_baseaddr;
10858 + unsigned long ipsec_phys_baseaddr;
10859 + void *ipsec_baseaddr;
10862 + int hif_client_irq;
10863 + struct device *dev;
10864 + struct dentry *dentry;
10865 + struct pfe_ctrl ctrl;
10866 + struct pfe_hif hif;
10867 + struct pfe_eth eth;
10868 + struct pfe_mdio mdio;
10869 + struct hif_client_s *hif_client[HIF_CLIENTS_MAX];
10870 +#if defined(CFG_DIAGS)
10871 + struct pfe_diags diags;
10873 + struct pfe_tmu_credit tmu_credit;
10874 + struct pfe_cpumon cpumon;
10875 + struct pfe_memmon memmon;
10877 + int mdio_muxval[PHYID_MAX_VAL];
10878 + struct clk *hfe_clock;
10881 +extern struct pfe *pfe;
10883 +int pfe_probe(struct pfe *pfe);
10884 +int pfe_remove(struct pfe *pfe);
10886 +/* DDR Mapping in reserved memory*/
10887 +#define ROUTE_TABLE_BASEADDR 0
10888 +#define ROUTE_TABLE_HASH_BITS 15 /* 32K entries */
10889 +#define ROUTE_TABLE_SIZE ((1 << ROUTE_TABLE_HASH_BITS) \
10890 + * CLASS_ROUTE_SIZE)
10891 +#define BMU2_DDR_BASEADDR (ROUTE_TABLE_BASEADDR + ROUTE_TABLE_SIZE)
10892 +#define BMU2_BUF_COUNT (4096 - 256)
10893 +/* This is to get a total DDR size of 12MiB */
10894 +#define BMU2_DDR_SIZE (DDR_BUF_SIZE * BMU2_BUF_COUNT)
10895 +#define UTIL_CODE_BASEADDR (BMU2_DDR_BASEADDR + BMU2_DDR_SIZE)
10896 +#define UTIL_CODE_SIZE (128 * SZ_1K)
10897 +#define UTIL_DDR_DATA_BASEADDR (UTIL_CODE_BASEADDR + UTIL_CODE_SIZE)
10898 +#define UTIL_DDR_DATA_SIZE (64 * SZ_1K)
10899 +#define CLASS_DDR_DATA_BASEADDR (UTIL_DDR_DATA_BASEADDR + UTIL_DDR_DATA_SIZE)
10900 +#define CLASS_DDR_DATA_SIZE (32 * SZ_1K)
10901 +#define TMU_DDR_DATA_BASEADDR (CLASS_DDR_DATA_BASEADDR + CLASS_DDR_DATA_SIZE)
10902 +#define TMU_DDR_DATA_SIZE (32 * SZ_1K)
10903 +#define TMU_LLM_BASEADDR (TMU_DDR_DATA_BASEADDR + TMU_DDR_DATA_SIZE)
10904 +#define TMU_LLM_QUEUE_LEN (8 * 512)
10905 +/* Must be power of two and at least 16 * 8 = 128 bytes */
10906 +#define TMU_LLM_SIZE (4 * 16 * TMU_LLM_QUEUE_LEN)
10907 +/* (4 TMU's x 16 queues x queue_len) */
10909 +#define DDR_MAX_SIZE (TMU_LLM_BASEADDR + TMU_LLM_SIZE)
10911 +/* LMEM Mapping */
10912 +#define BMU1_LMEM_BASEADDR 0
10913 +#define BMU1_BUF_COUNT 256
10914 +#define BMU1_LMEM_SIZE (LMEM_BUF_SIZE * BMU1_BUF_COUNT)
10916 +#endif /* _PFE_MOD_H */
10918 +++ b/drivers/staging/fsl_ppfe/pfe_perfmon.h
10920 +/* SPDX-License-Identifier: GPL-2.0+ */
10922 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10923 + * Copyright 2017 NXP
10926 +#ifndef _PFE_PERFMON_H_
10927 +#define _PFE_PERFMON_H_
10929 +#include "pfe/pfe.h"
10931 +#define CT_CPUMON_INTERVAL (1 * TIMER_TICKS_PER_SEC)
10933 +struct pfe_cpumon {
10934 + u32 cpu_usage_pct[MAX_PE];
10935 + u32 class_usage_pct;
10938 +struct pfe_memmon {
10939 + u32 kernel_memory_allocated;
10942 +int pfe_perfmon_init(struct pfe *pfe);
10943 +void pfe_perfmon_exit(struct pfe *pfe);
10945 +#endif /* _PFE_PERFMON_H_ */
10947 +++ b/drivers/staging/fsl_ppfe/pfe_sysfs.c
10949 +// SPDX-License-Identifier: GPL-2.0+
10951 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
10952 + * Copyright 2017 NXP
10955 +#include <linux/module.h>
10956 +#include <linux/platform_device.h>
10958 +#include "pfe_mod.h"
10960 +#define PE_EXCEPTION_DUMP_ADDRESS 0x1fa8
10961 +#define NUM_QUEUES 16
10963 +static char register_name[20][5] = {
10964 + "EPC", "ECAS", "EID", "ED",
10965 + "r0", "r1", "r2", "r3",
10966 + "r4", "r5", "r6", "r7",
10967 + "r8", "r9", "r10", "r11",
10968 + "r12", "r13", "r14", "r15",
10971 +static char exception_name[14][20] = {
10973 + "HardwareFailure",
10975 + "InstBreakpoint",
10976 + "DataBreakpoint",
10978 + "PrivilegeViolation",
10981 + "AlignmentError",
10982 + "ArithmeticError",
10984 + "MemoryManagement",
10988 +static unsigned long class_do_clear;
10989 +static unsigned long tmu_do_clear;
10990 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
10991 +static unsigned long util_do_clear;
10994 +static ssize_t display_pe_status(char *buf, int id, u32 dmem_addr, unsigned long
10999 + char statebuf[5];
11000 + struct pfe_cpumon *cpumon = &pfe->cpumon;
11001 + u32 debug_indicator;
11004 + if (id < CLASS0_ID || id >= MAX_PE)
11007 + *(u32 *)statebuf = pe_dmem_read(id, dmem_addr, 4);
11010 + statebuf[4] = '\0';
11011 + len += sprintf(buf + len, "state=%4s ", statebuf);
11013 + val = pe_dmem_read(id, dmem_addr, 4);
11015 + len += sprintf(buf + len, "ctr=%08x ", cpu_to_be32(val));
11017 + val = pe_dmem_read(id, dmem_addr, 4);
11018 + if (do_clear && val)
11019 + pe_dmem_write(id, 0, dmem_addr, 4);
11021 + len += sprintf(buf + len, "rx=%u ", cpu_to_be32(val));
11023 + val = pe_dmem_read(id, dmem_addr, 4);
11024 + if (do_clear && val)
11025 + pe_dmem_write(id, 0, dmem_addr, 4);
11027 + if (id >= TMU0_ID && id <= TMU_MAX_ID)
11028 + len += sprintf(buf + len, "qstatus=%x", cpu_to_be32(val));
11030 + len += sprintf(buf + len, "tx=%u", cpu_to_be32(val));
11032 + val = pe_dmem_read(id, dmem_addr, 4);
11033 + if (do_clear && val)
11034 + pe_dmem_write(id, 0, dmem_addr, 4);
11037 + len += sprintf(buf + len, " drop=%u", cpu_to_be32(val));
11039 + len += sprintf(buf + len, " load=%d%%", cpumon->cpu_usage_pct[id]);
11041 + len += sprintf(buf + len, "\n");
11043 + debug_indicator = pe_dmem_read(id, dmem_addr, 4);
11045 + if (!strncmp((char *)&debug_indicator, "DBUG", 4)) {
11048 + for (j = 0; j < 16; j++) {
11049 + debug[j] = pe_dmem_read(id, dmem_addr, 4);
11052 + pe_dmem_write(id, 0, dmem_addr, 4);
11057 + for (j = 0; j < last; j++) {
11058 + len += sprintf(buf + len, "%08x%s",
11059 + cpu_to_be32(debug[j]),
11060 + (j & 0x7) == 0x7 || j == last - 1 ? "\n" : " ");
11064 + if (!strncmp(statebuf, "DEAD", 4)) {
11065 + u32 i, dump = PE_EXCEPTION_DUMP_ADDRESS;
11067 + len += sprintf(buf + len, "Exception details:\n");
11068 + for (i = 0; i < 20; i++) {
11069 + debug[i] = pe_dmem_read(id, dump, 4);
11072 + len += sprintf(buf + len, "%4s = %08x (=%s) ",
11073 + register_name[i], cpu_to_be32(debug[i]),
11074 + exception_name[min((u32)
11075 + cpu_to_be32(debug[i]), (u32)13)]);
11077 + len += sprintf(buf + len, "%4s = %08x%s",
11078 + register_name[i], cpu_to_be32(debug[i]),
11079 + (i & 0x3) == 0x3 || i == 19 ? "\n" : " ");
11086 +static ssize_t class_phy_stats(char *buf, int phy)
11089 + int off1 = phy * 0x28;
11090 + int off2 = phy * 0x10;
11093 + off1 = CLASS_PHY4_RX_PKTS - CLASS_PHY1_RX_PKTS;
11095 + len += sprintf(buf + len, "phy: %d\n", phy);
11096 + len += sprintf(buf + len,
11097 + " rx: %10u, tx: %10u, intf: %10u, ipv4: %10u, ipv6: %10u\n",
11098 + readl(CLASS_PHY1_RX_PKTS + off1),
11099 + readl(CLASS_PHY1_TX_PKTS + off1),
11100 + readl(CLASS_PHY1_INTF_MATCH_PKTS + off1),
11101 + readl(CLASS_PHY1_V4_PKTS + off1),
11102 + readl(CLASS_PHY1_V6_PKTS + off1));
11104 + len += sprintf(buf + len,
11105 + " icmp: %10u, igmp: %10u, tcp: %10u, udp: %10u\n",
11106 + readl(CLASS_PHY1_ICMP_PKTS + off2),
11107 + readl(CLASS_PHY1_IGMP_PKTS + off2),
11108 + readl(CLASS_PHY1_TCP_PKTS + off2),
11109 + readl(CLASS_PHY1_UDP_PKTS + off2));
11111 + len += sprintf(buf + len, " err\n");
11112 + len += sprintf(buf + len,
11113 + " lp: %10u, intf: %10u, l3: %10u, chcksum: %10u, ttl: %10u\n",
11114 + readl(CLASS_PHY1_LP_FAIL_PKTS + off1),
11115 + readl(CLASS_PHY1_INTF_FAIL_PKTS + off1),
11116 + readl(CLASS_PHY1_L3_FAIL_PKTS + off1),
11117 + readl(CLASS_PHY1_CHKSUM_ERR_PKTS + off1),
11118 + readl(CLASS_PHY1_TTL_ERR_PKTS + off1));
11123 +/* qm_read_drop_stat
11124 + * This function is used to read the drop statistics from the TMU
11125 + * hw drop counter. Since the hw counter is always cleared afer
11126 + * reading, this function maintains the previous drop count, and
11127 + * adds the new value to it. That value can be retrieved by
11128 + * passing a pointer to it with the total_drops arg.
11130 + * @param tmu TMU number (0 - 3)
11131 + * @param queue queue number (0 - 15)
11132 + * @param total_drops pointer to location to store total drops (or NULL)
11133 + * @param do_reset if TRUE, clear total drops after updating
11135 +u32 qm_read_drop_stat(u32 tmu, u32 queue, u32 *total_drops, int do_reset)
11137 + static u32 qtotal[TMU_MAX_ID + 1][NUM_QUEUES];
11140 + writel((tmu << 8) | queue, TMU_TEQ_CTRL);
11141 + writel((tmu << 8) | queue, TMU_LLM_CTRL);
11142 + val = readl(TMU_TEQ_DROP_STAT);
11143 + qtotal[tmu][queue] += val;
11145 + *total_drops = qtotal[tmu][queue];
11147 + qtotal[tmu][queue] = 0;
11151 +static ssize_t tmu_queue_stats(char *buf, int tmu, int queue)
11156 + len += sprintf(buf + len, "%d-%02d, ", tmu, queue);
11158 + drops = qm_read_drop_stat(tmu, queue, NULL, 0);
11160 + /* Select queue */
11161 + writel((tmu << 8) | queue, TMU_TEQ_CTRL);
11162 + writel((tmu << 8) | queue, TMU_LLM_CTRL);
11164 + len += sprintf(buf + len,
11165 + "(teq) drop: %10u, tx: %10u (llm) head: %08x, tail: %08x, drop: %10u\n",
11166 + drops, readl(TMU_TEQ_TRANS_STAT),
11167 + readl(TMU_LLM_QUE_HEADPTR), readl(TMU_LLM_QUE_TAILPTR),
11168 + readl(TMU_LLM_QUE_DROPCNT));
11173 +static ssize_t tmu_queues(char *buf, int tmu)
11178 + for (queue = 0; queue < 16; queue++)
11179 + len += tmu_queue_stats(buf + len, tmu, queue);
11184 +static ssize_t block_version(char *buf, void *addr)
11189 + val = readl(addr);
11190 + len += sprintf(buf + len, "revision: %x, version: %x, id: %x\n",
11191 + (val >> 24) & 0xff, (val >> 16) & 0xff, val & 0xffff);
11196 +static ssize_t bmu(char *buf, int id, void *base)
11200 + len += sprintf(buf + len, "%s: %d\n ", __func__, id);
11202 + len += block_version(buf + len, base + BMU_VERSION);
11204 + len += sprintf(buf + len, " buf size: %x\n", (1 << readl(base +
11206 + len += sprintf(buf + len, " buf count: %x\n", readl(base +
11208 + len += sprintf(buf + len, " buf rem: %x\n", readl(base +
11209 + BMU_REM_BUF_CNT));
11210 + len += sprintf(buf + len, " buf curr: %x\n", readl(base +
11211 + BMU_CURR_BUF_CNT));
11212 + len += sprintf(buf + len, " free err: %x\n", readl(base +
11213 + BMU_FREE_ERR_ADDR));
11218 +static ssize_t gpi(char *buf, int id, void *base)
11223 + len += sprintf(buf + len, "%s%d:\n ", __func__, id);
11224 + len += block_version(buf + len, base + GPI_VERSION);
11226 + len += sprintf(buf + len, " tx under stick: %x\n", readl(base +
11227 + GPI_FIFO_STATUS));
11228 + val = readl(base + GPI_FIFO_DEBUG);
11229 + len += sprintf(buf + len, " tx pkts: %x\n", (val >> 23) &
11231 + len += sprintf(buf + len, " rx pkts: %x\n", (val >> 18) &
11233 + len += sprintf(buf + len, " tx bytes: %x\n", (val >> 9) &
11235 + len += sprintf(buf + len, " rx bytes: %x\n", (val >> 0) &
11237 + len += sprintf(buf + len, " overrun: %x\n", readl(base +
11238 + GPI_OVERRUN_DROPCNT));
11243 +static ssize_t pfe_set_class(struct device *dev, struct device_attribute *attr,
11244 + const char *buf, size_t count)
11246 + class_do_clear = kstrtoul(buf, 0, 0);
11250 +static ssize_t pfe_show_class(struct device *dev, struct device_attribute *attr,
11256 + struct pfe_cpumon *cpumon = &pfe->cpumon;
11258 + len += block_version(buf + len, CLASS_VERSION);
11260 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
11261 + len += sprintf(buf + len, "%d: ", id - CLASS0_ID);
11263 + val = readl(CLASS_PE0_DEBUG + id * 4);
11264 + len += sprintf(buf + len, "pc=1%04x ", val & 0xffff);
11266 + len += display_pe_status(buf + len, id, CLASS_DM_PESTATUS,
11269 + len += sprintf(buf + len, "aggregate load=%d%%\n\n",
11270 + cpumon->class_usage_pct);
11272 + len += sprintf(buf + len, "pe status: 0x%x\n",
11273 + readl(CLASS_PE_STATUS));
11274 + len += sprintf(buf + len, "max buf cnt: 0x%x afull thres: 0x%x\n",
11275 + readl(CLASS_MAX_BUF_CNT), readl(CLASS_AFULL_THRES));
11276 + len += sprintf(buf + len, "tsq max cnt: 0x%x tsq fifo thres: 0x%x\n",
11277 + readl(CLASS_TSQ_MAX_CNT), readl(CLASS_TSQ_FIFO_THRES));
11278 + len += sprintf(buf + len, "state: 0x%x\n", readl(CLASS_STATE));
11280 + len += class_phy_stats(buf + len, 0);
11281 + len += class_phy_stats(buf + len, 1);
11282 + len += class_phy_stats(buf + len, 2);
11283 + len += class_phy_stats(buf + len, 3);
11288 +static ssize_t pfe_set_tmu(struct device *dev, struct device_attribute *attr,
11289 + const char *buf, size_t count)
11291 + tmu_do_clear = kstrtoul(buf, 0, 0);
11295 +static ssize_t pfe_show_tmu(struct device *dev, struct device_attribute *attr,
11302 + len += block_version(buf + len, TMU_VERSION);
11304 + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
11305 + if (id == TMU2_ID)
11307 + len += sprintf(buf + len, "%d: ", id - TMU0_ID);
11309 + len += display_pe_status(buf + len, id, TMU_DM_PESTATUS,
11313 + len += sprintf(buf + len, "pe status: %x\n", readl(TMU_PE_STATUS));
11314 + len += sprintf(buf + len, "inq fifo cnt: %x\n",
11315 + readl(TMU_PHY_INQ_FIFO_CNT));
11316 + val = readl(TMU_INQ_STAT);
11317 + len += sprintf(buf + len, "inq wr ptr: %x\n", val & 0x3ff);
11318 + len += sprintf(buf + len, "inq rd ptr: %x\n", val >> 10);
11323 +static unsigned long drops_do_clear;
11324 +static u32 class_drop_counter[CLASS_NUM_DROP_COUNTERS];
11325 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11326 +static u32 util_drop_counter[UTIL_NUM_DROP_COUNTERS];
11329 +char *class_drop_description[CLASS_NUM_DROP_COUNTERS] = {
11331 + "Host Pkt Error",
11333 + "IPsec Outbound",
11335 + "EXPT IPsec Error",
11345 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11346 +char *util_drop_description[UTIL_NUM_DROP_COUNTERS] = {
11347 + "IPsec Outbound",
11349 + "IPsec Rate Limiter",
11357 +static ssize_t pfe_set_drops(struct device *dev, struct device_attribute *attr,
11358 + const char *buf, size_t count)
11360 + drops_do_clear = kstrtoul(buf, 0, 0);
11364 +static u32 tmu_drops[4][16];
11365 +static ssize_t pfe_show_drops(struct device *dev, struct device_attribute *attr,
11373 + int num_class_drops = 0, num_tmu_drops = 0, num_util_drops = 0;
11374 + struct pfe_ctrl *ctrl = &pfe->ctrl;
11376 + memset(class_drop_counter, 0, sizeof(class_drop_counter));
11377 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
11378 + if (drops_do_clear)
11379 + pe_sync_stop(ctrl, (1 << id));
11380 + for (dropnum = 0; dropnum < CLASS_NUM_DROP_COUNTERS;
11382 + dmem_addr = CLASS_DM_DROP_CNTR;
11383 + val = be32_to_cpu(pe_dmem_read(id, dmem_addr, 4));
11384 + class_drop_counter[dropnum] += val;
11385 + num_class_drops += val;
11386 + if (drops_do_clear)
11387 + pe_dmem_write(id, 0, dmem_addr, 4);
11389 + if (drops_do_clear)
11390 + pe_start(ctrl, (1 << id));
11393 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11394 + if (drops_do_clear)
11395 + pe_sync_stop(ctrl, (1 << UTIL_ID));
11396 + for (dropnum = 0; dropnum < UTIL_NUM_DROP_COUNTERS; dropnum++) {
11397 + dmem_addr = UTIL_DM_DROP_CNTR;
11398 + val = be32_to_cpu(pe_dmem_read(UTIL_ID, dmem_addr, 4));
11399 + util_drop_counter[dropnum] = val;
11400 + num_util_drops += val;
11401 + if (drops_do_clear)
11402 + pe_dmem_write(UTIL_ID, 0, dmem_addr, 4);
11404 + if (drops_do_clear)
11405 + pe_start(ctrl, (1 << UTIL_ID));
11407 + for (tmu = 0; tmu < 4; tmu++) {
11408 + for (queue = 0; queue < 16; queue++) {
11409 + qm_read_drop_stat(tmu, queue, &tmu_drops[tmu][queue],
11411 + num_tmu_drops += tmu_drops[tmu][queue];
11415 + if (num_class_drops == 0 && num_util_drops == 0 && num_tmu_drops == 0)
11416 + len += sprintf(buf + len, "No PE drops\n\n");
11418 + if (num_class_drops > 0) {
11419 + len += sprintf(buf + len, "Class PE drops --\n");
11420 + for (dropnum = 0; dropnum < CLASS_NUM_DROP_COUNTERS;
11422 + if (class_drop_counter[dropnum] > 0)
11423 + len += sprintf(buf + len, " %s: %d\n",
11424 + class_drop_description[dropnum],
11425 + class_drop_counter[dropnum]);
11427 + len += sprintf(buf + len, "\n");
11430 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11431 + if (num_util_drops > 0) {
11432 + len += sprintf(buf + len, "Util PE drops --\n");
11433 + for (dropnum = 0; dropnum < UTIL_NUM_DROP_COUNTERS; dropnum++) {
11434 + if (util_drop_counter[dropnum] > 0)
11435 + len += sprintf(buf + len, " %s: %d\n",
11436 + util_drop_description[dropnum],
11437 + util_drop_counter[dropnum]);
11439 + len += sprintf(buf + len, "\n");
11442 + if (num_tmu_drops > 0) {
11443 + len += sprintf(buf + len, "TMU drops --\n");
11444 + for (tmu = 0; tmu < 4; tmu++) {
11445 + for (queue = 0; queue < 16; queue++) {
11446 + if (tmu_drops[tmu][queue] > 0)
11447 + len += sprintf(buf + len,
11448 + " TMU%d-Q%d: %d\n"
11449 + , tmu, queue, tmu_drops[tmu][queue]);
11452 + len += sprintf(buf + len, "\n");
11458 +static ssize_t pfe_show_tmu0_queues(struct device *dev, struct device_attribute
11459 + *attr, char *buf)
11461 + return tmu_queues(buf, 0);
11464 +static ssize_t pfe_show_tmu1_queues(struct device *dev, struct device_attribute
11465 + *attr, char *buf)
11467 + return tmu_queues(buf, 1);
11470 +static ssize_t pfe_show_tmu2_queues(struct device *dev, struct device_attribute
11471 + *attr, char *buf)
11473 + return tmu_queues(buf, 2);
11476 +static ssize_t pfe_show_tmu3_queues(struct device *dev, struct device_attribute
11477 + *attr, char *buf)
11479 + return tmu_queues(buf, 3);
11482 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11483 +static ssize_t pfe_set_util(struct device *dev, struct device_attribute *attr,
11484 + const char *buf, size_t count)
11486 + util_do_clear = kstrtoul(buf, NULL, 0);
11490 +static ssize_t pfe_show_util(struct device *dev, struct device_attribute *attr,
11494 + struct pfe_ctrl *ctrl = &pfe->ctrl;
11496 + len += block_version(buf + len, UTIL_VERSION);
11498 + pe_sync_stop(ctrl, (1 << UTIL_ID));
11499 + len += display_pe_status(buf + len, UTIL_ID, UTIL_DM_PESTATUS,
11501 + pe_start(ctrl, (1 << UTIL_ID));
11503 + len += sprintf(buf + len, "pe status: %x\n", readl(UTIL_PE_STATUS));
11504 + len += sprintf(buf + len, "max buf cnt: %x\n",
11505 + readl(UTIL_MAX_BUF_CNT));
11506 + len += sprintf(buf + len, "tsq max cnt: %x\n",
11507 + readl(UTIL_TSQ_MAX_CNT));
11513 +static ssize_t pfe_show_bmu(struct device *dev, struct device_attribute *attr,
11518 + len += bmu(buf + len, 1, BMU1_BASE_ADDR);
11519 + len += bmu(buf + len, 2, BMU2_BASE_ADDR);
11524 +static ssize_t pfe_show_hif(struct device *dev, struct device_attribute *attr,
11529 + len += sprintf(buf + len, "hif:\n ");
11530 + len += block_version(buf + len, HIF_VERSION);
11532 + len += sprintf(buf + len, " tx curr bd: %x\n",
11533 + readl(HIF_TX_CURR_BD_ADDR));
11534 + len += sprintf(buf + len, " tx status: %x\n",
11535 + readl(HIF_TX_STATUS));
11536 + len += sprintf(buf + len, " tx dma status: %x\n",
11537 + readl(HIF_TX_DMA_STATUS));
11539 + len += sprintf(buf + len, " rx curr bd: %x\n",
11540 + readl(HIF_RX_CURR_BD_ADDR));
11541 + len += sprintf(buf + len, " rx status: %x\n",
11542 + readl(HIF_RX_STATUS));
11543 + len += sprintf(buf + len, " rx dma status: %x\n",
11544 + readl(HIF_RX_DMA_STATUS));
11546 + len += sprintf(buf + len, "hif nocopy:\n ");
11547 + len += block_version(buf + len, HIF_NOCPY_VERSION);
11549 + len += sprintf(buf + len, " tx curr bd: %x\n",
11550 + readl(HIF_NOCPY_TX_CURR_BD_ADDR));
11551 + len += sprintf(buf + len, " tx status: %x\n",
11552 + readl(HIF_NOCPY_TX_STATUS));
11553 + len += sprintf(buf + len, " tx dma status: %x\n",
11554 + readl(HIF_NOCPY_TX_DMA_STATUS));
11556 + len += sprintf(buf + len, " rx curr bd: %x\n",
11557 + readl(HIF_NOCPY_RX_CURR_BD_ADDR));
11558 + len += sprintf(buf + len, " rx status: %x\n",
11559 + readl(HIF_NOCPY_RX_STATUS));
11560 + len += sprintf(buf + len, " rx dma status: %x\n",
11561 + readl(HIF_NOCPY_RX_DMA_STATUS));
11566 +static ssize_t pfe_show_gpi(struct device *dev, struct device_attribute *attr,
11571 + len += gpi(buf + len, 0, EGPI1_BASE_ADDR);
11572 + len += gpi(buf + len, 1, EGPI2_BASE_ADDR);
11573 + len += gpi(buf + len, 3, HGPI_BASE_ADDR);
11578 +static ssize_t pfe_show_pfemem(struct device *dev, struct device_attribute
11579 + *attr, char *buf)
11582 + struct pfe_memmon *memmon = &pfe->memmon;
11584 + len += sprintf(buf + len, "Kernel Memory: %d Bytes (%d KB)\n",
11585 + memmon->kernel_memory_allocated,
11586 + (memmon->kernel_memory_allocated + 1023) / 1024);
11591 +static ssize_t pfe_show_crc_revalidated(struct device *dev,
11592 + struct device_attribute *attr,
11595 + u64 crc_validated = 0;
11599 + len += sprintf(buf + len, "FCS re-validated by PFE:\n");
11601 + for (phyid = 0; phyid < 2; phyid++) {
11602 + crc_validated = 0;
11603 + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
11604 + crc_validated += be32_to_cpu(pe_dmem_read(id,
11605 + CLASS_DM_CRC_VALIDATED + (phyid * 4), 4));
11607 + len += sprintf(buf + len, "MAC %d:\n count:%10llu\n",
11608 + phyid, crc_validated);
11614 +#ifdef HIF_NAPI_STATS
11615 +static ssize_t pfe_show_hif_napi_stats(struct device *dev,
11616 + struct device_attribute *attr,
11619 + struct platform_device *pdev = to_platform_device(dev);
11620 + struct pfe *pfe = platform_get_drvdata(pdev);
11623 + len += sprintf(buf + len, "sched: %u\n",
11624 + pfe->hif.napi_counters[NAPI_SCHED_COUNT]);
11625 + len += sprintf(buf + len, "poll: %u\n",
11626 + pfe->hif.napi_counters[NAPI_POLL_COUNT]);
11627 + len += sprintf(buf + len, "packet: %u\n",
11628 + pfe->hif.napi_counters[NAPI_PACKET_COUNT]);
11629 + len += sprintf(buf + len, "budget: %u\n",
11630 + pfe->hif.napi_counters[NAPI_FULL_BUDGET_COUNT]);
11631 + len += sprintf(buf + len, "desc: %u\n",
11632 + pfe->hif.napi_counters[NAPI_DESC_COUNT]);
11633 + len += sprintf(buf + len, "full: %u\n",
11634 + pfe->hif.napi_counters[NAPI_CLIENT_FULL_COUNT]);
11639 +static ssize_t pfe_set_hif_napi_stats(struct device *dev,
11640 + struct device_attribute *attr,
11641 + const char *buf, size_t count)
11643 + struct platform_device *pdev = to_platform_device(dev);
11644 + struct pfe *pfe = platform_get_drvdata(pdev);
11646 + memset(pfe->hif.napi_counters, 0, sizeof(pfe->hif.napi_counters));
11651 +static DEVICE_ATTR(hif_napi_stats, 0644, pfe_show_hif_napi_stats,
11652 + pfe_set_hif_napi_stats);
11655 +static DEVICE_ATTR(class, 0644, pfe_show_class, pfe_set_class);
11656 +static DEVICE_ATTR(tmu, 0644, pfe_show_tmu, pfe_set_tmu);
11657 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11658 +static DEVICE_ATTR(util, 0644, pfe_show_util, pfe_set_util);
11660 +static DEVICE_ATTR(bmu, 0444, pfe_show_bmu, NULL);
11661 +static DEVICE_ATTR(hif, 0444, pfe_show_hif, NULL);
11662 +static DEVICE_ATTR(gpi, 0444, pfe_show_gpi, NULL);
11663 +static DEVICE_ATTR(drops, 0644, pfe_show_drops, pfe_set_drops);
11664 +static DEVICE_ATTR(tmu0_queues, 0444, pfe_show_tmu0_queues, NULL);
11665 +static DEVICE_ATTR(tmu1_queues, 0444, pfe_show_tmu1_queues, NULL);
11666 +static DEVICE_ATTR(tmu2_queues, 0444, pfe_show_tmu2_queues, NULL);
11667 +static DEVICE_ATTR(tmu3_queues, 0444, pfe_show_tmu3_queues, NULL);
11668 +static DEVICE_ATTR(pfemem, 0444, pfe_show_pfemem, NULL);
11669 +static DEVICE_ATTR(fcs_revalidated, 0444, pfe_show_crc_revalidated, NULL);
11671 +int pfe_sysfs_init(struct pfe *pfe)
11673 + if (device_create_file(pfe->dev, &dev_attr_class))
11676 + if (device_create_file(pfe->dev, &dev_attr_tmu))
11679 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11680 + if (device_create_file(pfe->dev, &dev_attr_util))
11684 + if (device_create_file(pfe->dev, &dev_attr_bmu))
11687 + if (device_create_file(pfe->dev, &dev_attr_hif))
11690 + if (device_create_file(pfe->dev, &dev_attr_gpi))
11693 + if (device_create_file(pfe->dev, &dev_attr_drops))
11696 + if (device_create_file(pfe->dev, &dev_attr_tmu0_queues))
11697 + goto err_tmu0_queues;
11699 + if (device_create_file(pfe->dev, &dev_attr_tmu1_queues))
11700 + goto err_tmu1_queues;
11702 + if (device_create_file(pfe->dev, &dev_attr_tmu2_queues))
11703 + goto err_tmu2_queues;
11705 + if (device_create_file(pfe->dev, &dev_attr_tmu3_queues))
11706 + goto err_tmu3_queues;
11708 + if (device_create_file(pfe->dev, &dev_attr_pfemem))
11711 + if (device_create_file(pfe->dev, &dev_attr_fcs_revalidated))
11712 + goto err_crc_revalidated;
11714 +#ifdef HIF_NAPI_STATS
11715 + if (device_create_file(pfe->dev, &dev_attr_hif_napi_stats))
11716 + goto err_hif_napi_stats;
11721 +#ifdef HIF_NAPI_STATS
11722 +err_hif_napi_stats:
11723 + device_remove_file(pfe->dev, &dev_attr_fcs_revalidated);
11726 +err_crc_revalidated:
11727 + device_remove_file(pfe->dev, &dev_attr_pfemem);
11730 + device_remove_file(pfe->dev, &dev_attr_tmu3_queues);
11733 + device_remove_file(pfe->dev, &dev_attr_tmu2_queues);
11736 + device_remove_file(pfe->dev, &dev_attr_tmu1_queues);
11739 + device_remove_file(pfe->dev, &dev_attr_tmu0_queues);
11742 + device_remove_file(pfe->dev, &dev_attr_drops);
11745 + device_remove_file(pfe->dev, &dev_attr_gpi);
11748 + device_remove_file(pfe->dev, &dev_attr_hif);
11751 + device_remove_file(pfe->dev, &dev_attr_bmu);
11754 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11755 + device_remove_file(pfe->dev, &dev_attr_util);
11759 + device_remove_file(pfe->dev, &dev_attr_tmu);
11762 + device_remove_file(pfe->dev, &dev_attr_class);
11768 +void pfe_sysfs_exit(struct pfe *pfe)
11770 +#ifdef HIF_NAPI_STATS
11771 + device_remove_file(pfe->dev, &dev_attr_hif_napi_stats);
11773 + device_remove_file(pfe->dev, &dev_attr_fcs_revalidated);
11774 + device_remove_file(pfe->dev, &dev_attr_pfemem);
11775 + device_remove_file(pfe->dev, &dev_attr_tmu3_queues);
11776 + device_remove_file(pfe->dev, &dev_attr_tmu2_queues);
11777 + device_remove_file(pfe->dev, &dev_attr_tmu1_queues);
11778 + device_remove_file(pfe->dev, &dev_attr_tmu0_queues);
11779 + device_remove_file(pfe->dev, &dev_attr_drops);
11780 + device_remove_file(pfe->dev, &dev_attr_gpi);
11781 + device_remove_file(pfe->dev, &dev_attr_hif);
11782 + device_remove_file(pfe->dev, &dev_attr_bmu);
11783 +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
11784 + device_remove_file(pfe->dev, &dev_attr_util);
11786 + device_remove_file(pfe->dev, &dev_attr_tmu);
11787 + device_remove_file(pfe->dev, &dev_attr_class);
11790 +++ b/drivers/staging/fsl_ppfe/pfe_sysfs.h
11792 +/* SPDX-License-Identifier: GPL-2.0+ */
11794 + * Copyright 2015-2016 Freescale Semiconductor, Inc.
11795 + * Copyright 2017 NXP
11798 +#ifndef _PFE_SYSFS_H_
11799 +#define _PFE_SYSFS_H_
11801 +#include <linux/proc_fs.h>
11803 +u32 qm_read_drop_stat(u32 tmu, u32 queue, u32 *total_drops, int do_reset);
11805 +int pfe_sysfs_init(struct pfe *pfe);
11806 +void pfe_sysfs_exit(struct pfe *pfe);
11808 +#endif /* _PFE_SYSFS_H_ */