Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit fb5fc58028ecd7d476637d7e5a7ea657ed84b9eb 0 parents
@dhkim1027 dhkim1027 authored
Showing with 62,610 additions and 0 deletions.
  1. +43 −0 Makefile
  2. BIN  docs/netl7_compiler_api.pdf
  3. BIN  docs/netl7_dataplane_api.pdf
  4. +312 −0 docs/netl7_devdrv_instr.txt
  5. BIN  docs/netl7_rulefile_spec.pdf
  6. +104 −0 docs/readme.txt
  7. +1 −0  docs/revision.txt
  8. +27 −0 include/LICENSE.TXT
  9. +42 −0 include/nlm_common_api.h
  10. +199 −0 include/nlm_database_api.h
  11. +47 −0 include/nlm_database_extra.h
  12. +46 −0 include/nlm_driver_api.h
  13. +66 −0 include/nlm_error_tbl.def
  14. +220 −0 include/nlm_logger.h
  15. +359 −0 include/nlm_packet_api.h
  16. +62 −0 include/nlm_stdint.h
  17. +221 −0 include/nlm_sync.h
  18. +143 −0 include/nlm_system.h
  19. +6 −0 lib/build_fms_dataplane.sh
  20. BIN  lib/dataplane/.fms_packet_api.c.swp
  21. +27 −0 lib/dataplane/LICENSE.TXT
  22. +30 −0 lib/dataplane/Makefile
  23. +17 −0 lib/dataplane/Makefile.org
  24. +3,982 −0 lib/dataplane/fms_packet_api.c
  25. +62 −0 lib/dataplane/init_all.c
  26. +203 −0 lib/dataplane/init_driver_unix.c
  27. +116 −0 lib/dataplane/loader_common.c
  28. +1,307 −0 lib/dataplane/loader_fms.c
  29. +78 −0 lib/dataplane/nlm_byteswap.h
  30. +24 −0 lib/dataplane/nlm_common_api.c
  31. +2,867 −0 lib/dataplane/nlm_ddr.c
  32. +490 −0 lib/dataplane/nlm_ddr.h
  33. +166 −0 lib/dataplane/nlm_dp_fifo.h
  34. +1,047 −0 lib/dataplane/nlm_fms_formats.h
  35. +2,824 −0 lib/dataplane/nlm_fms_registers.h
  36. +79 −0 lib/dataplane/nlm_loader_common.h
  37. +369 −0 lib/dataplane/nlm_mars_registers.h
  38. +419 −0 lib/dataplane/nlm_packet_api_impl.h
  39. +27 −0 lib/dataplane/nlm_sha2.h
  40. +143 −0 lib/dataplane/nlm_system.h
  41. +78 −0 lib/dataplane/packet_api_common.c
  42. +141 −0 lib/dataplane/print_reg.c
  43. +127 −0 lib/dataplane/sha2.c
  44. +177 −0 lib/dataplane/system.c
  45. BIN  lib/libfms_compiler.a
  46. BIN  lib/libpacket_api_fms.a
  47. +579 −0 libpcap/CHANGES
  48. +145 −0 libpcap/CREDITS
  49. +33 −0 libpcap/ChmodBPF/ChmodBPF
  50. +4 −0 libpcap/ChmodBPF/StartupParameters.plist
  51. +403 −0 libpcap/INSTALL.txt
  52. +19 −0 libpcap/LICENSE
  53. +695 −0 libpcap/Makefile
  54. +690 −0 libpcap/Makefile.in
  55. +104 −0 libpcap/README
  56. +46 −0 libpcap/README.Win32
  57. +81 −0 libpcap/README.aix
  58. +114 −0 libpcap/README.dag
  59. +254 −0 libpcap/README.hpux
  60. +108 −0 libpcap/README.linux
  61. +74 −0 libpcap/README.macosx
  62. +50 −0 libpcap/README.septel
  63. +64 −0 libpcap/README.sita
  64. +49 −0 libpcap/README.tru64
  65. BIN  libpcap/SUNOS4/nit_if.o.sparc
  66. BIN  libpcap/SUNOS4/nit_if.o.sun3
  67. BIN  libpcap/SUNOS4/nit_if.o.sun4c.4.0.3c
  68. +35 −0 libpcap/TODO
  69. +1 −0  libpcap/VERSION
  70. +46 −0 libpcap/Win32/Include/Gnuc.h
  71. +146 −0 libpcap/Win32/Include/addrinfo.h
  72. +349 −0 libpcap/Win32/Include/arpa/nameser.h
  73. +139 −0 libpcap/Win32/Include/bittypes.h
  74. +37 −0 libpcap/Win32/Include/cdecl_ext.h
  75. +67 −0 libpcap/Win32/Include/inetprivate.h
  76. +163 −0 libpcap/Win32/Include/ip6_misc.h
  77. +230 −0 libpcap/Win32/Include/net/if.h
  78. +164 −0 libpcap/Win32/Include/net/netdb.h
  79. +105 −0 libpcap/Win32/Include/net/paths.h
  80. +38 −0 libpcap/Win32/Include/sockstorage.h
  81. +168 −0 libpcap/Win32/Prj/libpcap.dsp
  82. +29 −0 libpcap/Win32/Prj/libpcap.dsw
  83. +54 −0 libpcap/Win32/Src/ffs.c
  84. +83 −0 libpcap/Win32/Src/gai_strerror.c
  85. +1,120 −0 libpcap/Win32/Src/getaddrinfo.c
  86. +44 −0 libpcap/Win32/Src/getnetbynm.c
  87. +119 −0 libpcap/Win32/Src/getnetent.c
  88. +121 −0 libpcap/Win32/Src/getopt.c
  89. +125 −0 libpcap/Win32/Src/getservent.c
  90. +61 −0 libpcap/Win32/Src/inet_aton.c
  91. +101 −0 libpcap/Win32/Src/inet_net.c
  92. +71 −0 libpcap/Win32/Src/inet_pton.c
  93. +1,019 −0 libpcap/aclocal.m4
  94. +52 −0 libpcap/arcnet.h
  95. +87 −0 libpcap/atmuni31.h
  96. +675 −0 libpcap/bpf/net/bpf_filter.c
  97. +62 −0 libpcap/bpf_dump.c
  98. +302 −0 libpcap/bpf_image.c
  99. +19 −0 libpcap/chmod_bpf
  100. +1,502 −0 libpcap/config.guess
  101. +279 −0 libpcap/config.h
  102. +278 −0 libpcap/config.h.in
  103. +1,479 −0 libpcap/config.log
  104. +905 −0 libpcap/config.status
  105. +1,708 −0 libpcap/config.sub
  106. +11,879 −0 libpcap/configure
  107. +1,432 −0 libpcap/configure.in
  108. +358 −0 libpcap/dlpisubs.c
  109. +28 −0 libpcap/dlpisubs.h
  110. +174 −0 libpcap/etherent.c
  111. +119 −0 libpcap/ethertype.h
  112. +291 −0 libpcap/fad-getad.c
  113. +433 −0 libpcap/fad-gifc.c
  114. +386 −0 libpcap/fad-glifc.c
  115. +65 −0 libpcap/fad-null.c
  116. +61 −0 libpcap/fad-sita.c
  117. +327 −0 libpcap/fad-win32.c
  118. +266 −0 libpcap/filtertest.c
  119. +131 −0 libpcap/findalldevstest.c
  120. +8,386 −0 libpcap/gencode.c
  121. +339 −0 libpcap/gencode.h
  122. +694 −0 libpcap/grammar.y
  123. +146 −0 libpcap/ieee80211.h
  124. +903 −0 libpcap/inet.c
  125. +250 −0 libpcap/install-sh
  126. +25 −0 libpcap/lbl/os-aix4.h
  127. +25 −0 libpcap/lbl/os-hpux11.h
  128. +28 −0 libpcap/lbl/os-osf4.h
  129. +32 −0 libpcap/lbl/os-osf5.h
  130. +26 −0 libpcap/lbl/os-solaris2.h
  131. +215 −0 libpcap/lbl/os-sunos4.h
  132. +39 −0 libpcap/lbl/os-ultrix4.h
  133. +69 −0 libpcap/llc.h
  134. +632 −0 libpcap/missing/snprintf.c
  135. +109 −0 libpcap/mkdep
  136. +43 −0 libpcap/msdos/bin2c.c
  137. +80 −0 libpcap/msdos/common.dj
  138. +184 −0 libpcap/msdos/makefile
  139. +152 −0 libpcap/msdos/makefile.dj
  140. +131 −0 libpcap/msdos/makefile.wc
  141. +860 −0 libpcap/msdos/ndis2.c
  142. +559 −0 libpcap/msdos/ndis2.h
  143. +188 −0 libpcap/msdos/ndis_0.asm
  144. +197 −0 libpcap/msdos/pkt_rx0.asm
  145. +155 −0 libpcap/msdos/pkt_rx1.s
Sorry, we could not display the entire diff because too many files (318) changed.
43 Makefile
@@ -0,0 +1,43 @@
+LIB_ROOT = $(PWD)
+
+LIB_DIRS = lib/dataplane libpcap src #pkt_gen
+
+all: make_pkg
+
+make_pkg:
+ @echo ""
+ @for dirs in $(LIB_DIRS); do \
+ if [ -d $${dirs} ]; then \
+ echo "****************** Entering [$${dirs}]"; \
+ cd $${dirs}; \
+ $(MAKE); \
+ if [ $$? != '0' ]; then \
+ echo ""; \
+ exit 1; \
+ fi; \
+ echo "****************** Leaving [$${dirs}]"; \
+ echo ""; \
+ cd $(LIB_ROOT); \
+ else \
+ echo "Can't find directory [$${dirs}]"; \
+ exit 1; \
+ fi; \
+ done;
+
+clean:
+ @echo ""
+ @for dirs in $(LIB_DIRS); do \
+ if [ -d $${dirs} ]; then \
+ echo "****************** Entering [$${dirs}]"; \
+ cd $${dirs}; \
+ $(MAKE) clean; \
+ echo "****************** Leaving [$${dirs}]"; \
+ echo ""; \
+ cd $(LIB_ROOT); \
+ else \
+ echo "Can't find directory [$${dirs}]"; \
+ exit 1; \
+ fi; \
+ done;
+
+
BIN  docs/netl7_compiler_api.pdf
Binary file not shown
BIN  docs/netl7_dataplane_api.pdf
Binary file not shown
312 docs/netl7_devdrv_instr.txt
@@ -0,0 +1,312 @@
+This file contains information about using the Netlogic Microsystems
+Linux device driver for the L7 devices.
+
+Operational modes
+=================
+ The device driver has two modes operation that control how contiguous pages of
+ physical memory are allocated for the L7 chips. The first mode, which is the
+ default as shipped from Netlogic, attempts to allocate largest chunk of free
+ memory from the system. It is strongly recommended that the driver be installed
+ as part of the boot process or immediately after to ensure the memory is not
+ extremely fragmented. The amount of memory allocated by the driver can be seen
+ by looking at the kernel messages using "dmesg". The other mode requires the
+ user to specify the base physical address and size of the memory range when the
+ module is loaded into the Linux kernel.
+
+ The rest of this document provides sample commands/steps to configure the
+ system to load the driver in the fixed address mode.
+
+Usage
+-----
+
+ % insmod netl7driver.ko [fixed_phys_base=XXXX] [fixed_phys_size=YYYY] [dmamem_size=ZZZZ] [verbose={1,0}]
+
+ fixed_phys_base: If specified represents the base of the physical address that
+ has been reserved by the user when booting the kernel. It must
+ be specified along with fixed_phys_size. This physical memory
+ is equally partitioned across all the NetL7 devices on the system.
+
+ fixed_phys_size: The size of physical address region. If specified without the
+ fixed_phys_base, the driver attempts to grab this amount
+ of physical memory from the kernel. By default the driver attempts
+ to allocate 256M of memory.
+
+ dmamem_size: The NetL7 devices require physical addresses for both the
+ system and packet memory. This variable specifies how much
+ of the memory should be reserved for packets. This value
+ is per device. If not specified the default value is 2M
+
+ verbose: Setting this to 1 will cause the driver to emit more messages
+ to the logs.
+
+ The total available memory is first partitioned equally by the driver among all
+ available devices. Further this per device chunk is partitioned into dmamem_size
+ specified and the rest as system memory for the device. For default configuration
+ parametres at least 2Mb of system memory is required by the device. If allocation
+ of big chunk fails, the driver attempts to allocate 2Mb for system and 2 Mb for
+ packet memory per device. All values presented to the driver are rounded to page
+ size boundaries.
+
+ % insmod netl7driver.ko
+
+ Driver makes a best effort of allocating memory for devices and packet memory.
+ By default the driver tries to look for 256M of contigious memory
+
+ % insmod netl7driver.ko fixed_phys_size=536870912
+
+ The driver attempts to reserve 512M of memory. If it cannot it will default
+ to whatever it can allocate. This memory is then partitioned equally among
+ all devices
+
+ % insmod netl7driver.ko fixed_phys_size=536870912 dmamem_size=16777216
+
+ Try to allocate 512M and partition equally among all devices. Out of per
+ device chunk reserve 16M of packet memory for each device. If 512M
+ cannot be allocated, then the driver will default to whatever best it can
+
+ % insmod netl7driver.ko fixed_phys_base=XXXX fixed_phys_size=YYYY dmamem_size=ZZZZ
+
+ The provided fixed physical address region is partitioned equally among
+ all NetL7 devices. Further the value specified by dmamem_size is reserved
+ for packet memory out of the memory chunks obtained by each device
+
+Querying status of device after installation
+--------------------------------------------
+
+ After the driver is installed, one proc file is created per device discovered
+ under /proc/NetL7
+
+ % ls /proc/NetL7/*
+ mars2.0 mars2.1 mars2.2 mars2.3 mars2.4
+
+ Each of the files can be queried for status.
+
+ % cat /proc/NetL7/mars2.0
+ Device Type : MARS2
+ Status: Available
+ config.register_map_base_phys = 0xdfbf0000
+ config.register_map_size = 65536
+ The above variables can be directly plugged into config file
+ ioctl the /proc file from your process to obtain the virtual
+ address of the register map
+ =============================================
+ Driver Assigned memory
+ =============================================
+ System Memory: 0x2000000 | size: 51589120
+ Packet Memory: 0x115ff000 | size: 2097152
+
+
+Detailed instructions on specifying a physical memory region
+------------------------------------------------------------
+ By default the Linux kernel will make use of all available DRAM. However the
+ L7 device requires a contiguous chunk of physical memory. A simple solution is
+ to request a memory chunk from the running kernel. Unfortunately most kernel
+ versions (mips, x86) return only 2 or 4 MB. In general, this is not enough
+ memory to use the Netlogic L7 chips.
+
+ To solve this problem the Linux kernel should be booted with the mem=xxx
+ option to limit the kernel to use less than the amount of DRAM installed in
+ the system. Then the L7 device driver can use the rest of the DRAM. The rest
+ of this document explains how to do this.
+
+ High level overview of how to set up the driver to use fixed physical memory
+ ranges:
+
+1. The kernel command line "mem=" parameter must be set.
+2. Compile the module.
+3. User needs to figure out the correct physical address range to be used by
+ the driver.
+4. Arrange for the module to be loaded with the correct parameters
+
+Detailed instructions:
+
+1. For Fedora it should be as simple as editing /boot/grub/grub.conf and adding
+ mem=xxx to the appropriate line. On Ubuntu and Debian installations the file
+ will be /boot/grub/menu.lst. Red Hat kernels should be similar.
+
+ Add this option to all kernels that will be used with the driver.
+
+ (Refer Appendix for similar information for supported custom kernels).
+
+ The kernel mem=xxx option by default is in bytes, the argument can also have
+ a 'k' or 'K' or 'm' or 'M' or 'g' or 'G' suffix to change the units to
+ kilobytes, megabytes, or gigabytes.
+
+2. On most Linux systems you will need to ensure that the appropriate kernel
+ header packages are installed.
+
+ It should be as simple as typing "make" in the driver directory.
+
+ You should now have a file "netl7driver.ko"
+
+3. Boot the system and look at the output of 'cat /proc/iomem'
+ You should see lines like these:
+
+ 00000000-0009fbff : System RAM
+ 000a0000-000bffff : Video RAM area
+ 000c0000-000c8fff : Video ROM
+ 000cb000-000cbfff : Adapter ROM
+ 000f0000-000fffff : reserved
+ 000f0000-000fffff : System ROM
+ 00100000-cd3fffff : System RAM
+ 00100000-00383359 : Kernel code
+ 0038335a-004a567f : Kernel data
+ 00515000-005c0a1f : Kernel bss
+ d7e7cc00-d7e7ebff : ACPI Non-volatile Storage
+ d7e7ec00-d7e80bff : ACPI Tables
+ d7e80c00-d7ffffff : reserved
+ d8000000-dfffffff : PCI Bus 0000:02
+ d8000000-dfffffff : 0000:02:00.0
+ e0000000-e7ffffff : PCI Bus 0000:05
+ e0000000-e7ffffff : 0000:05:07.0
+ efa00000-efbfffff : PCI Bus 0000:05
+ efa00000-efa1ffff : 0000:05:07.0
+ efaf0000-efafffff : 0000:05:07.0
+ efc00000-efcfffff : PCI Bus 0000:04
+ efcf0000-efcfffff : 0000:04:00.0
+ efcf0000-efcfffff : tg3
+ efd00000-efdfffff : PCI Bus 0000:02
+ efdf0000-efdfffff : 0000:02:00.0
+ efe00000-efefffff : PCI Bus 0000:01
+ effffc00-efffffff : 0000:00:1f.2
+ f0000000-f3ffffff : PCI MMCONFIG 0
+ f0000000-f3ffffff : reserved
+ fec00000-fed003ff : reserved
+ fed00000-fed003ff : HPET 0
+ fed20000-fed9ffff : reserved
+ feda0000-fedacfff : pnp 00:08
+ fee00000-feefffff : reserved
+ fee00000-fee00fff : Local APIC
+ ff980800-ff980bff : 0000:00:1d.7
+ ff980800-ff980bff : ehci_hcd
+ ffb00000-ffffffff : reserved
+
+ Look at the map. Skip the first megabyte and find the big chunk of memory
+ that contains:
+
+ 00100000-cd3fffff : System RAM
+ 00100000-00383359 : Kernel code
+ 0038335a-004a567f : Kernel data
+ 00515000-005c0a1f : Kernel bss
+
+ This is the bulk of your DRAM. After the DRAM you will see ACPI tables and
+ various memory regions where PCI maps its windows. Select amount of memory
+ you need for the system memory. Subtract that amount from the
+ last DRAM address + 1 (in the example above 0xcd3fffff + 1 = 0xcd400000).
+ Then open your grub.conf or menu.lst and put the resulting amount of
+ megabytes to your "mem=" option.
+
+ Reboot.
+
+ Look at the /proc/iomem again, noticing the difference between the last DRAM
+ address and the first address used by BIOS. Your "fixed_phys_base=" will be
+ the Last DRAM address + 1. Your "fixed_phys_size=" will be the difference
+ between the "fixed_phys_base=" and the first address used by BIOS.
+
+4. Load the module
+
+ insmod netl7driver.ko fixed_phys_base=XXXXX fixed_phys_size=YYYYY
+
+ This will tell the L7 device driver what physical addresses to use.
+ The driver also accepts an option "verbose=1" that will turn on additional
+ messages.
+
+ On module load you should see something like this on the console or using
+ the 'dmesg' command:
+
+ ... NetL7_V2.0 : driver load process started.
+ ... NetL7_V2.0_pci 0000:04:00.0: setting latency timer to 64
+ ... NetL7_V2.0_pci 0000:05:00.0: setting latency timer to 64
+ ... NetL7_V2.0_pci 0000:06:00.0: setting latency timer to 64
+ ... NetL7_V2.0_pci 0000:07:00.0: setting latency timer to 64
+ ... NetL7_V2.0_pci 0000:08:00.0: setting latency timer to 64
+ ... NetL7_V2.0 : === Probed device no 0 (efee8200) (MARS2) ===
+ ... NetL7_V2.0 : proc_entry /proc/NetL7/mars2.0
+ ... NetL7_V2.0 : register_map base = 0xdfbf0000 size = 0x10000
+ ... NetL7_V2.0 : system memory base = 0x2f000000 size = 0x3333000
+ ... NetL7_V2.0 : packet memory base = 0x3efff000 size = 0x200000
+ ... NetL7_V2.0 : === Probed device no 1 (efee822c) (MARS2) ===
+ ... NetL7_V2.0 : proc_entry /proc/NetL7/mars2.1
+ ... NetL7_V2.0 : register_map base = 0xdfaf0000 size = 0x10000
+ ... NetL7_V2.0 : system memory base = 0x32333000 size = 0x3333000
+ ... NetL7_V2.0 : packet memory base = 0x3f1ff000 size = 0x200000
+ ... NetL7_V2.0 : === Probed device no 2 (efee8258) (MARS2) ===
+ ... NetL7_V2.0 : proc_entry /proc/NetL7/mars2.2
+ ... NetL7_V2.0 : register_map base = 0xdf9f0000 size = 0x10000
+ ... NetL7_V2.0 : system memory base = 0x35666000 size = 0x3333000
+ ... NetL7_V2.0 : packet memory base = 0x3f3ff000 size = 0x200000
+ ... NetL7_V2.0 : === Probed device no 3 (efee8284) (MARS2) ===
+ ... NetL7_V2.0 : proc_entry /proc/NetL7/mars2.3
+ ... NetL7_V2.0 : register_map base = 0xdf8f0000 size = 0x10000
+ ... NetL7_V2.0 : system memory base = 0x38999000 size = 0x3333000
+ ... NetL7_V2.0 : packet memory base = 0x3f5ff000 size = 0x200000
+ ... NetL7_V2.0 : === Probed device no 4 (efee82b0) (MARS2) ===
+ ... NetL7_V2.0 : proc_entry /proc/NetL7/mars2.4
+ ... NetL7_V2.0 : register_map base = 0xdf7f0000 size = 0x10000
+ ... NetL7_V2.0 : system memory base = 0x3bccc000 size = 0x3333000
+ ... NetL7_V2.0 : packet memory base = 0x3f7ff000 size = 0x200000
+
+
+Appendix
+=========
+
+Reserving memory with Cavium systems
+-------------------------------------
+ Mips:
+ For the Cavium mips boards you need to get to the boot loader prompt.
+ Normally you would need to use the serial port connected to the board.
+
+ List the boot environment vars using "printenv", look for a bootcmd variable,
+ it should be something like "run xxx" create a yyy var that is a copy of xxx
+ but with mem=NNN added to the command line. Change the bootcmd variable.
+ Use the "saveenv" command to write to the flash card.
+
+Reserving memory with RMI systems
+----------------------------------
+
+Instructions for XLS408
+
+1. Reboot the board
+2. When the following message is seen, quickly press any key to stop the
+ auto-boot:
+ A1_XLS408 @ ATX_XLS $
+ Booting in 1 units. Press any key to halt...
+
+ Note that we saw this message right after 7 lines of mac configuration
+ messages:
+ configuring gmac0 in nibble mode @ 2.5MHz (10Mbps): full duplex mode
+
+3. Enter the print_physmap command. This will print list of the memory addresses
+ and their descriptions. The steps below assume that there is 2GB of
+ addressable memory of which the last 512m can be reserved for the netl7
+ driver. If the memory map is different, the steps below may be used as an
+ example to work out the load-time arguments for the driver.
+
+4. Run following command to copy and load OS image vmlinux.atx
+ $ dload pcmcia_1 1 /vmlinux.atx 20000000
+ $ elfload
+
+5. Then, run the following command to restrict the kernel to use 128MB in the
+ low memory region, which region starts at 1m and another 1GB starting from
+ 512m. For this particular device, some of the kernel needs to be in the low
+ memory.
+
+ $ userapp mem=128m@1m mem=1024m@512m
+
+ After the above command, the system will start booting. When complete, the
+ kernel would have occupied upto 1536m, perhaps with some holes in between.
+ The rest of the 512MB is available for the netl7 driver of which it uses
+ 256MB. So the netl7 driver can be loaded with a fixed_phys_base anywhere
+ in the first 256m after 1536m.
+
+6. When the system is ready, load the netl7 driver as:
+ $ insmod netl7driver.ko fixed_phys_base=0x60000000 fixed_phys_size=0x10000000
+
+SDK and compiler flags with RMI systems
+---------------------------------------
+
+1. The recommended SDK and compilation flags are:
+ * <...>/rmi/1.5/mipscross/nptl/bin
+ * -mabi=32
+
+[]
BIN  docs/netl7_rulefile_spec.pdf
Binary file not shown
104 docs/readme.txt
@@ -0,0 +1,104 @@
+This package contains SDK for NLS2008 family of NETL7 devices.
+
+********************************
+Change log w.r.t. release 2.6.1
+********************************
+
+- Optimized peak memory usage for large databases.
+
+
+****************************
+Package Directory Structure
+****************************
+
+docs/netl7_compiler_api.pdf -- compiler/database API manual
+docs/netl7_dataplane_api.pdf -- dataplane API manual
+docs/netl7_rulefile_spec.pdf -- description of rule file format for fms_compiler.c
+docs/netl7_devdrv_instr.txt -- device driver instructions
+
+include/nlm_packet_api.h -- dataplane API
+include/nlm_database_api.h -- compiler/database API
+
+lib/ -- compiler and dataplane libraries/sources(optional)
+
+src/demo.c -- dataplane demo
+src/mtdemo.c -- dataplane multi_thread demo
+src/ringdemo.c -- dataplane multi_ring demo
+src/fms_compiler.c -- compiler demo
+src/driver/ -- demo driver
+
+Recommended environment:
+
+linux kernel 2.6.21+
+gcc 4.1+
+glibc 2.6+
+
+To build and install demo driver, read docs/netl7_devdrv_instr.txt
+and follow:
+
+$ cd src/driver
+$ make
+
+For simple demo run use:
+$ sudo insmod ./netl7driver.ko
+
+For advanced evaluation (more than one device, multiple flows, multiple rings,
+customized database, external traffic, etc) demo driver and kerneldemo should
+be loaded as:
+$ sudo insmod netl7driver.ko fixed_phys_base=XXXXX fixed_phys_size=YYYYY verbose=1
+
+Do NOT use demo driver for production. Write OS specific nlm_prepare_device_config()
+or set up fields of struct nlm_device_config manually in the way appropriate
+for environment. See docs/netl7_dataplane_api.pdf for details.
+
+If package contains dataplane sources, the steps to build them are:
+
+1. cd lib
+2. build_fms_dataplane.sh # builds dataplane library
+3. cd -
+
+then build compiler and dataplane demos:
+
+4. cd src
+5. make # builds compiler/demos
+
+and run demo, demo_mt, demo_ring
+
+$ ./demo
+$ ./demo_mt
+$ ./demo_ring
+
+To compile <rule_file> into binary image <output_file> use:
+
+$ fms_compiler <rule_file> -o <output_file>
+
+fms_compiler.c expects rules to be specified in the format described in netl7_rulefile_spec.pdf
+
+Sample input file:
+# comment
+[1]
+1 a.*b
+2 c.*d.*e
+3 ^.{0,100}huh
+
+[2:1000:group_2]
+2 1000 pattern_2 a.*b
+min_match_length 12
+3 1000 pattern_3 abcd
+4 1000 pattern_4 abcde
+priority 2
+# non-greedy a.*b is the following:
+5 1100 pattern_5 a.*b
+# or the following:
+6 1000 xxx a.*b
+non_greedy
+
+[3]
+10 a.*b
+min_match_length 100
+11 a.*b
+non_greedy
+12 a.*b
+13 a.*b
+match_once
+
1  docs/revision.txt
@@ -0,0 +1 @@
+4837
27 include/LICENSE.TXT
@@ -0,0 +1,27 @@
+/*******************************************************************************
+* Legal Notice:
+* This product is the confidential property of NetLogic Microsystems Inc.
+* ("NetLogic"), is provided under a non-disclosure agreement, and is protected
+* under applicable copyright, patent, and trade secret laws. Unauthorized use,
+* reproduction, distribution or other dissemination without the prior written
+* authorization from NetLogic is strictly prohibited.
+*
+* NETLOGIC DISCLAIMS ALL WARRANTIES OF ANY NATURE, EXPRESS OR IMPLIED,
+* INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF FITNESS FOR A PARTICULAR
+* PURPOSE, MERCHANTABILITY AND/OR NON-INFRINGEMENT OF THIRD PARTY RIGHTS.
+* NETLOGIC ASSUMES NO LIABILITY FOR ANY ERROR OR OMISSIONS IN THIS PRODUCT,OR
+* FOR THE USE OF THIS PRODUCT. IN NO EVENT SHALL NETLOGIC BE LIABLE TO ANY OTHER
+* PARTY FOR ANY SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL DAMAGES, WHETHER
+* BASED ON BREACH OF CONTRACT, TORT, PRODUCT LIABILITY, INFRINGEMENT OF
+* INTELLECTUAL PROPERTY RIGHTS OR OTHERWISE. NETLOGIC RESERVES THE RIGHT TO MAKE
+* CHANGES TO, OR DISCONTINUE, ITS PRODUCTS AT ANY TIME.
+*
+* Distribution of the product herein does not convey a license or any other
+* right in any patent, trademark, or other intellectual property of NetLogic.
+*
+* Use of the product shall serve as acceptance of these terms and conditions.
+* If you do not accept these terms, you should return or destroy the product
+* and any other accompanying information immediately.
+*
+* Copyright, 2008-2010, NetLogic Microsystems, Inc. All rights reserved.
+*******************************************************************************/
42 include/nlm_common_api.h
@@ -0,0 +1,42 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+/** \file nlm_common_api.h
+ header file for shared structures in Dataplane/packet API and Controlplane/database API */
+#ifndef __NLM_COMMON_API_H
+#define __NLM_COMMON_API_H
+
+#include "nlm_stdint.h"
+
+/** status and error codes returned by all API functions */
+typedef enum nlm_status
+{
+#define NLM_INC_SEL(name,string) name,
+#include "nlm_error_tbl.def"
+#undef NLM_INC_SEL
+ NLM_STATUS_LAST_UNUSED
+} nlm_status;
+
+/** function to convert status code to string
+ \param[in] status code to be converted
+ \return string that describes the code */
+const char *nlm_get_status_string (nlm_status status);
+
+/** defines physical address for data plane library */
+typedef unsigned long long nlm_phys_addr;
+
+/* defines for database API */
+#define NLM_FIRST_DATABASE_TYPE 1000
+#define NLM_FIRST_DATABASE_PARAM 1100
+#define NLM_FIRST_RULE_ACTION 1200
+#define NLM_FIRST_PARSER_PARAM 1300
+#define NLM_FIRST_MAPPER_PARAM 1400
+#define NLM_FIRST_PLACER_PARAM 1400
+
+/* defines for device API */
+#define NLM_FIRST_DEVICE_TYPE 2000
+#define NLM_FIRST_DEVICE_PARAM 2100
+#define NLM_FIRST_DEVICE_CONFIG_PARAM 2200
+#define NLM_FIRST_FLOW_TYPE 2300
+
+#endif /* __NLM_COMMON_API_H */
199 include/nlm_database_api.h
@@ -0,0 +1,199 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+/** \file nlm_database_api.h
+ header file for Controlplane/database API */
+#ifndef NLM_DATABASE_API_H
+#define NLM_DATABASE_API_H
+
+#include "nlm_common_api.h"
+
+/* error/warning reporting mechanism setup as callback functions from the compiler */
+#include "nlm_logger.h"
+
+struct nlm_database; /* opaque database handle */
+struct nlm_rule_group; /* opaque rule_group handle */
+struct nlm_rule; /* opaque rule handle */
+
+/** type of the database */
+typedef enum nlm_database_type
+{
+ NLM_INVALID_DATABASE_TYPE = NLM_FIRST_DATABASE_TYPE, /**< marker for invalid database type */
+ NLM_DATABASE_HW_MARS1, /**< NLS055 */
+ NLM_DATABASE_HW_MARS2, /**< NLS205 */
+ NLM_DATABASE_HW_FMS, /**< NLS2008 */
+ NLM_DATABASE_HW_MARS3, /**< NLS2018 */
+ NLM_DATABASE_SW_HORIZON,
+ NLM_DATABASE_SW_FMS_MODEL,
+ NLM_DATABASE_SW_MARS3_MODEL,
+ NLM_LAST_DATABASE_TYPE
+} nlm_database_type;
+
+/** returns size of nlm_database (database handle structure) */
+uint32_t nlm_database_sizeof (nlm_database_type type);
+
+/** parser flags */
+typedef enum nlm_parser_param
+{
+ NLM_INVALID_PARSER_PARAM = NLM_FIRST_PARSER_PARAM,
+ NLM_SYNTAX_PCRE,
+ NLM_SYNTAX_PCRE_EXTENDED,
+ NLM_SYNTAX_PCRE_IGNORE_CASE,
+ NLM_SYNTAX_PCRE_NON_GREEDY,
+ NLM_SYNTAX_NETSCREEN,
+ NLM_SYNTAX_NETSCREEN_NON_GREEDY,
+ NLM_LAST_PARSER_PARAM
+} nlm_parser_param;
+
+/** mapper flags */
+typedef enum nlm_mapper_param
+{
+ NLM_INVALID_MAPPER_PARAM = NLM_FIRST_MAPPER_PARAM,
+ NLM_DO_AGGRESSIVE_MML, /**< should mml graphs be constructed even for
+ unsafe rules(e.g. rules with overlapping prefix & suffix) */
+ NLM_DO_AGGRESSIVE_MATCH_ONCE, /**< compile certain rules in match once mode instead
+ of all-matches to improve HW capacity */
+ NLM_RULE_SYMBOL_LIMIT, /**< don't compile rules with symbol count larger than this limit,
+ (default 0 == compile rules of all sizes) */
+ NLM_REMOVE_REDUNDANCY, /**< remove the prefix and suffix redundant quantifiers based on this
+ value. (default 3 == remove both) */
+ NLM_STITCH_RULES, /**< enable/disable stitcher based on this value. (default 1 == enabled ) */
+ NLM_USE_COUNTER, /**< enable/disable counter usage based on this value. (default 1 == enabled ) */
+ NLM_LAST_MAPPER_PARAM
+} nlm_mapper_param;
+
+struct nlm_database_stat
+{
+ uint32_t parsed_rule_cnt; /**< number of rules successfully parsed */
+ uint32_t graphed_rule_cnt; /**< number of rules for which graph was successfully generated */
+ uint32_t placed_rule_cnt; /**< number of rules successfully placed */
+ uint32_t block_cnt; /**< number of blocks into which the database has compiled */
+};
+
+/** function prototype for callback accessed by nlm_database_set_param (db, NLM_XMALLOC, malloc_callback);
+ and nlm_database_set_param (db, NLM_IMAGE_XMALLOC, image_malloc_callback); */
+typedef void *(*nlm_callback_type_xmalloc) (void *cookie, uint32_t byte_cnt);
+/** proto for NLM_XFREE */
+typedef void (*nlm_callback_type_xfree) (void *cookie, void *mem_ptr);
+
+/** configuration parameters that can be set and get by corresponding functions */
+typedef enum nlm_database_param
+{
+ NLM_INVALID_DATABASE_PARAM = NLM_FIRST_DATABASE_PARAM, /**< marker for invalid parameter */
+ NLM_OPTIMIZATION_LEVEL, /**< optimization level: 0 - no optimization */
+ NLM_VERBOSITY_LEVEL, /**< verbosity level: 0 - no extra messages */
+ NLM_PARSER_PARAM, /**< parser flags (one of nlm_parser_param) */
+ NLM_MAPPER_PARAM, /**< mapper flags */
+ NLM_DEBUG_FLAGS, /**< bitmap to control dumping of internal structures */
+ NLM_CALLBACK_COOKIE, /**< 'void *cookie' to be sent to xmalloc, xfree, xdump callbacks */
+ NLM_IMAGE_XMALLOC, /**< void * (*xmalloc) (void *cookie, uint32_t byte_cnt); callback */
+ NLM_XMALLOC, /**< void * (*xmalloc) (void *cookie, uint32_t byte_cnt); callback */
+ NLM_XFREE, /**< void (*xfree) (void *cookie, void *mem_ptr); callback */
+ NLM_LOGGER, /**< pointer to the nlm_logger */
+ NLM_DATABASE_SW_MODEL_TYPE, /**< sub-type of software model */
+ NLM_DATABASE_STAT, /**< probe function to inquire the status of a compiled database.
+ It is valid to call the function after any non-fatal return from
+ nlm_database_compile() but before the nlm_database_close() */
+ NLM_LAST_DATABASE_PARAM
+} nlm_database_param;
+
+/** init interfaces of the database compiler
+ \param[in] type of database to be initialized
+ \param[in] database pointer to database handle
+ \return status */
+nlm_status nlm_database_interface_init (nlm_database_type type, struct nlm_database *database);
+
+/** shutdown interfaces of the database compiler
+ \param[in] database pointer to database handle
+ \return status */
+nlm_status nlm_database_interface_fini (struct nlm_database *database);
+
+/** Get specified database parameter
+ \param[in] database pointer to database handle
+ \param[in] param database parameter
+ \return status */
+nlm_status nlm_database_get_param (struct nlm_database *database, nlm_database_param param, ...);
+
+/** Set specified database parameter
+ \param[in] database pointer to database handle
+ \param[in] param database parameter
+ \return status */
+nlm_status nlm_database_set_param (struct nlm_database *database, nlm_database_param param, ...);
+
+/** Open and initialize database compiler
+ \param[in] database pointer to database handle
+ \return status */
+nlm_status nlm_database_open (struct nlm_database *database);
+
+/** Close and free database of rules
+ \param[in] database pointer
+ \return status */
+nlm_status nlm_database_close (struct nlm_database *database);
+
+/** Create and add rule group to the \a database
+ \param[in] database pointer
+ \param[in] group_id id of the rule group
+ \param[out] p_group rule group handle
+ \return status */
+nlm_status nlm_database_add_group (struct nlm_database *database,
+ uint32_t group_id,
+ struct nlm_rule_group **p_group);
+
+/** Create and add \a rule to the rule \a group
+ \param[in] database pointer
+ \param[in] group rule group handle
+ \param[in] rule_id id of the rule
+ \param[in] regex rule to be parsed and compiled
+ \param[out] p_rule rule handle
+ \return status */
+nlm_status nlm_database_add_rule (struct nlm_database *database, struct nlm_rule_group *group,
+ uint32_t rule_id, const char *regex,
+ struct nlm_rule **p_rule);
+
+
+/** rule actions to be set */
+typedef enum nlm_rule_action
+{
+ NLM_INVALID_RULE_ACTION = NLM_FIRST_RULE_ACTION, /**< marker for invalid action */
+ NLM_MIN_MATCH_LENGTH, /**< match must meet the minimum match length criterion
+ to be considered a match */
+ NLM_MIN_OFFSET, /**< offset for the end of the match must meet the
+ specified offset criterion */
+ NLM_EXACT_OFFSET, /**< offset for the end of the match must meet the
+ specified offset criterion */
+ NLM_MAX_OFFSET, /**< offset for the end of the match must meet the
+ specified offset criterion */
+ NLM_RESULT_PRIORITY, /**< specifies priority of the rule to be clamped
+ differently by dataplane */
+ NLM_NON_GREEDY, /**< cause rule to match nongreedy (weak nongreedy) */
+ NLM_MATCH_ONCE, /**< cause rule to match just once (strong nongreedy)
+ (only first match reported) */
+ NLM_TRIGGER_GROUP, /**< cause rule to activate the linked group without output */
+ NLM_MATCH_AND_TRIGGER_GROUP, /**< cause rule to activate the linked group with output */
+
+ NLM_LAST_RULE_ACTION
+} nlm_rule_action;
+
+/** Set rule action
+ \param[in] database pointer
+ \param[in] rule handle
+ \param[in] action rule action type
+ \return status */
+nlm_status nlm_database_set_rule_action (struct nlm_database *database,
+ struct nlm_rule *rule,
+ nlm_rule_action action, ...);
+
+/** Compile the whole database
+ \param[in] database pointer
+ \param[out] p_database pointer to the compiled image
+ \param[out] p_size compiled image size
+ \return status */
+nlm_status nlm_database_compile (struct nlm_database *database,
+ const void **p_database,
+ uint32_t *p_size);
+
+#define NLM_MIN_RESULT_PRIORITY 0
+#define NLM_MAX_RESULT_PRIORITY 3
+
+#endif /* NLM_DATABASE_API_H */
+
47 include/nlm_database_extra.h
@@ -0,0 +1,47 @@
+/*******************************************************************************
+* Legal Notice:
+* This product is the confidential property of NetLogic Microsystems Inc.
+* ("NetLogic"), is provided under a non-disclosure agreement, and is protected
+* under applicable copyright, patent, and trade secret laws. Unauthorized use,
+* reproduction, distribution or other dissemination without the prior written
+* authorization from NetLogic is strictly prohibited.
+*
+* NETLOGIC DISCLAIMS ALL WARRANTIES OF ANY NATURE, EXPRESS OR IMPLIED,
+* INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF FITNESS FOR A PARTICULAR
+* PURPOSE, MERCHANTABILITY AND/OR NON-INFRINGEMENT OF THIRD PARTY RIGHTS.
+* NETLOGIC ASSUMES NO LIABILITY FOR ANY ERROR OR OMISSIONS IN THIS PRODUCT,OR
+* FOR THE USE OF THIS PRODUCT. IN NO EVENT SHALL NETLOGIC BE LIABLE TO ANY OTHER
+* PARTY FOR ANY SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL DAMAGES, WHETHER
+* BASED ON BREACH OF CONTRACT, TORT, PRODUCT LIABILITY, INFRINGEMENT OF
+* INTELLECTUAL PROPERTY RIGHTS OR OTHERWISE. NETLOGIC RESERVES THE RIGHT TO MAKE
+* CHANGES TO, OR DISCONTINUE, ITS PRODUCTS AT ANY TIME.
+*
+* Distribution of the product herein does not convey a license or any other
+* right in any patent, trademark, or other intellectual property of NetLogic.
+*
+* Use of the product shall serve as acceptance of these terms and conditions.
+* If you do not accept these terms, you should return or destroy the product
+* and any other accompanying information immediately.
+*
+* Copyright, 2008-2009, NetLogic Microsystems, Inc. All rights reserved.
+*******************************************************************************/
+#ifndef __NLM_DATABASE_EXTRA_H
+#define __NLM_DATABASE_EXTRA_H
+
+#include "nlm_database_api.h"
+
+struct fms_cam_node;
+struct fms_search_state;
+
+nlm_status nlm_db_select_groups (struct nlm_database *database, uint32_t *group_id, uint32_t group_cnt,
+ struct fms_search_state *state);
+
+nlm_status nlm_db_parse_line (struct nlm_database *db, nlm_logger *logger,
+ uint32_t line_num,
+ char *src, char *end);
+
+nlm_status nlm_database_analyze (struct nlm_database *db, const void *image, uint32_t image_size,
+ uint32_t insn_addr, uint32_t *rule_id);
+
+#endif
+
46 include/nlm_driver_api.h
@@ -0,0 +1,46 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+/** \file nlm_driver_api.h
+ header file for linux specific initialization phase of Data plane API */
+#ifndef __NLM_DRIVER_API_H
+#define __NLM_DRIVER_API_H
+
+#include "nlm_packet_api.h"
+
+#define NLM_MAX_DEVICE_COUNT 8
+
+/** Get number of netl7 devices
+ \param[out] n_devices number of the netl7 devices on the system
+ \return status */
+nlm_status nlm_get_device_count (uint32_t *n_devices);
+
+/** Initialize netl7 device configuration
+ Fill in platform specific fields of the configuration like system memory,
+ register map, packet memory addresses.
+ \param[in] device_id id of the netl7 device on the system
+ \param[in] config device configuration
+ \param[out] config device configuration
+ \return status */
+nlm_status nlm_prepare_device_config (uint32_t device_id,
+ struct nlm_device_config *config);
+
+/** Unmap virtual memory mapped by nlm_prepare_device_config() for system memory, packet memory
+ and register memory. Free memory pool */
+nlm_status nlm_free_device_config (struct nlm_device_config *config);
+
+/** Initialize all netl7 devices
+ \param[out] devices array of initialized device handles
+ \param[out] n_devices number of initialized devices
+ \return status */
+nlm_status nlm_init_all_devices (struct nlm_device * devices[NLM_MAX_DEVICE_COUNT],
+ uint32_t *n_devices);
+
+/** Shutdown all netl7 devices
+ \param[in] devices array of device handles to be shutdown
+ \param[in] n_devices number of devices
+ \return status */
+nlm_status nlm_fini_all_devices (struct nlm_device * devices[NLM_MAX_DEVICE_COUNT],
+ uint32_t n_devices);
+
+#endif /* __NLM_DRIVER_API_H */
66 include/nlm_error_tbl.def
@@ -0,0 +1,66 @@
+NLM_INC_SEL(NLM_OK, "all ok")
+NLM_INC_SEL(NLM_END_OF_JOB, "job has ended")
+NLM_INC_SEL(NLM_END_ANCHORED, "match is triggered by end anchored rule")
+NLM_INC_SEL(NLM_BUSY, "device is busy")
+NLM_INC_SEL(NLM_UNSUPPORTED, "unsupported functionality")
+NLM_INC_SEL(NLM_OUT_OF_MEMORY, "user supplied memory pool is full")
+NLM_INC_SEL(NLM_OUT_OF_DEVICE_MEMORY, "device system memory is full")
+NLM_INC_SEL(NLM_OUT_OF_PACKET_MEMORY, "packet memory is out of bounds")
+NLM_INC_SEL(NLM_OUT_OF_DDR_MEMORY, "attached DDR memory is full")
+NLM_INC_SEL(NLM_INPUT_FIFO_FULL, "input fifo is full")
+NLM_INC_SEL(NLM_INVALID_ARGUMENT, "invalid argument - may be null pointer or incorrect size")
+NLM_INC_SEL(NLM_INVALID_DEVICE_CONFIG, "parameters in device configuration are out of range")
+NLM_INC_SEL(NLM_INVALID_FLOW, "invalid flow")
+NLM_INC_SEL(NLM_INVALID_DATABASE, "invalid database")
+NLM_INC_SEL(NLM_INVALID_DATABASE_ID, "invalid database id")
+NLM_INC_SEL(NLM_INVALID_DATABASE_CHECKSUM, "invalid database checksum")
+NLM_INC_SEL(NLM_INVALID_DATABASE_FILE_MAGIC, "invalid database magic number")
+NLM_INC_SEL(NLM_INVALID_DATABASE_VERSION, "invalid database version")
+NLM_INC_SEL(NLM_INVALID_DATABASE_ADDRESS, "invalid destination address while loading the database")
+NLM_INC_SEL(NLM_INVALID_DATABASE_SIZE, "the device is not configured to accept database of this size or the database is too large")
+NLM_INC_SEL(NLM_INVALID_GROUPID, "group id is too large")
+NLM_INC_SEL(NLM_INVALID_PACKET_SIZE, "packet is too large")
+NLM_INC_SEL(NLM_INVALID_JOB, "job pointer is corrupted")
+NLM_INC_SEL(NLM_INVALID_RING_ID, "invalid ring id")
+NLM_INC_SEL(NLM_INCORRECT_ACCESS, "incorrect interface access, like writing into read-only")
+NLM_INC_SEL(NLM_DRIVER_FAILURE, "couldn't communicate with the driver")
+NLM_INC_SEL(NLM_DEVICE_FAILURE, "couldn't communicate with the device")
+NLM_INC_SEL(NLM_DEVICE_PARITY_ERROR, "device parity error")
+NLM_INC_SEL(NLM_DEVICE_ILLEGAL_INSTRUCTION, "Illegal instruction")
+NLM_INC_SEL(NLM_DEVICE_SRAM_ADDR, "invalid addr in device map")
+NLM_INC_SEL(NLM_DEVICE_CONTEXT_FAIL, "device context save/restore failed")
+NLM_INC_SEL(NLM_DEVICE_DMA_FAILURE, "device cannot DMA to system memory")
+NLM_INC_SEL(NLM_DEVICE_NFA_TIMEOUT, "engine timeout on NFA entry")
+NLM_INC_SEL(NLM_DEVICE_DFA_TIMEOUT, "engine timeout on DFA entry")
+NLM_INC_SEL(NLM_DEVICE_BUSY_POLL_TIMEOUT, "engine timeout on PDF busy bit")
+NLM_INC_SEL(NLM_DEVICE_NFA_STATE_LIMIT, "engine NFA state limit reached")
+NLM_INC_SEL(NLM_DEVICE_RESULT_CLAMP, "limit on number of results per packet is reached")
+NLM_INC_SEL(NLM_DEVICE_CONTEXT_CLAMP, "limit on number of context buffers is reached")
+NLM_INC_SEL(NLM_DEVICE_CONTEXT_RING_EMPTY, "context state save/restore ring is empty")
+NLM_INC_SEL(NLM_INVALID_RULE_ID, "invalid rule id")
+NLM_INC_SEL(NLM_INVALID_REGEX, "invalid regex")
+NLM_INC_SEL(NLM_INVALID_EMPTY_RULE_GROUP, "empty rule groups are invalid")
+NLM_INC_SEL(NLM_PLACER_FATAL, "placer had a fatal error")
+NLM_INC_SEL(NLM_PLACER_NO_GRAPH, "placer has no well defined graph")
+NLM_INC_SEL(NLM_LOADER_IN_PROGRESS, "database reconfiguration is in progress")
+NLM_INC_SEL(NLM_LOADER_COMMAND_FIFO_FULL, "loader command fifo buffer is full")
+NLM_INC_SEL(NLM_LOADER_BLOCK_PAUSE_TIMEOUT, "loader block pause wait timeout")
+NLM_INC_SEL(NLM_DATABASE_UNLOADED, "operation attempted on an unloaded database id")
+NLM_INC_SEL(NLM_TOO_BIG, "a size maximum has been exceeded")
+NLM_INC_SEL(NLM_PARTIAL_COMPILE, "partial compilation")
+NLM_INC_SEL(NLM_FILE_IO_ERROR, "file i/o error")
+NLM_INC_SEL(NLM_MAX_ACCEPT_STATES_CLAMP, "maximum number of result entries per block exceeded")
+NLM_INC_SEL(NLM_DDR3_UNSUPPORTED_FREQUENCY, "DDR3 frequency requested is not supported")
+NLM_INC_SEL(NLM_DDR3_CONTROLLER_TIMEOUT, "Timeout waiting for the DDR3 controller to respond")
+NLM_INC_SEL(NLM_DDR3_DELAY_CHANGE_FAIL, "increment or decrement of DLL register failed")
+NLM_INC_SEL(NLM_DDR3_TUNING_MAX_DELAY_REACHED, "tuning failed with a maximum delay for a slice reached")
+NLM_INC_SEL(NLM_DDR3_LEVELING_MAX_DELAY_REACHED, "leveling failed with a maximum delay for a slice reached")
+NLM_INC_SEL(NLM_DEVICE_UNINITIALIZED, "physical device uninitialized")
+NLM_INC_SEL(NLM_INVALID_THREAD_ID, "incorrect thread ID or thread not allowed for requested operation")
+NLM_INC_SEL(NLM_EXCESS_DEVICE_ATTACH, "more than expected number of device attaches called")
+NLM_INC_SEL(NLM_DEVICE_XAUI_BUFFER_INCONSISTENT, "incorrect XAUI free buffer level detected")
+NLM_INC_SEL(NLM_DEVICE_INFINITE_LOOP, "infinite loop detected")
+NLM_INC_SEL(NLM_DEVICE_INVALID_SYSMEM, "device attempted to access invalid system memory region")
+NLM_INC_SEL(NLM_DEVICE_FEOF_DETECTED, "attempt to scan packet on destroyed flow")
+NLM_INC_SEL(NLM_DEVICE_TS_OVERFLOW, "exceeded number of flags in Token Stitcher")
+NLM_INC_SEL(NLM_XAUI_INTERFACE_ERROR, "unexpected error on XAUI interface")
220 include/nlm_logger.h
@@ -0,0 +1,220 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+/** \file nlm_logger.h
+ header file for logger of compiler/database API */
+#ifndef __NLM_LOGGER_H
+#define __NLM_LOGGER_H
+
+#include "nlm_stdint.h"
+
+/** type of the message reported by 'xprint' callback */
+typedef enum nlm_xprint_type
+{
+ NLM_XPRINT_WARNING,
+ NLM_XPRINT_ERROR,
+ NLM_XPRINT_DEBUG,
+ NLM_XPRINT_VERBOSE,
+ NLM_XPRINT_FATAL
+} nlm_xprint_type;
+
+/** module that called 'xprint' callback */
+typedef enum nlm_xprint_module
+{
+ NLM_MODULE_UNKNOWN,
+ NLM_MODULE_RX_PARSER,
+ NLM_MODULE_FMS_GRAPH,
+ NLM_MODULE_FMS_TAIL,
+ NLM_MODULE_ESPRESSO,
+ NLM_MODULE_FMS_PUT_PLACER,
+ NLM_MODULE_FMS_PLACER,
+ NLM_MODULE_DB_MANAGER
+} nlm_xprint_module;
+
+#define NLM_LOGGER_MAX_SPRINTF_BUF 128
+
+/** proto of 'xprint' callback */
+typedef void (*nlm_callback_type_xprint) (void *cookie, nlm_xprint_type type,
+ nlm_xprint_module module, const char *str,
+ unsigned int error_code, void *aux_data);
+
+/** main logger structure.
+ nlm_logger structure is used to setup an 'xprint' callback routine that
+ may be called during compilation process to report error/warning/debug
+ messages to the user */
+typedef struct nlm_logger
+{
+ void *cookie; /**< cookie - 1st argument to xprint callback */
+ nlm_callback_type_xprint xprint; /**< main callback routine */
+ char sprintf_buf[NLM_LOGGER_MAX_SPRINTF_BUF]; /**< internal buffer used to construct a string */
+} nlm_logger;
+
+/** Generic auxiliary data for 'xprint' callback.
+ the last 'aux_data' pointer of the 'xprint' callback can always be casted
+ to 'struct nlm_logger_rule_data *' to retrieve rule and group id of the rule
+ that triggered callback.
+ In some cases 'aux_data' can be casted to 'nlm_log_fms_placer_rule_*'. See below */
+struct nlm_logger_rule_data
+{
+ uint32_t rule_id;
+ uint32_t group_id;
+};
+
+/* NLM_MODULE_FMS_PLACER error_code values for an nlm_logger callback.
+
+ RULE_FATAL
+
+ An otherwise undistinguished fatal error has occured during placement of
+ a particular rule. The auxiliary data struct (defined below) describes
+ the rule. A fatal error is an internal inconsistency within the
+ compilation data structures.
+
+ RULE_NOT_PLACED
+
+ A valid rule element input graph could not be placed. The auxiliary data
+ struct (defined below) describes the rule.
+
+ INPUT_GRAPH_INVALID
+
+ The placer has been passed an input graph that is structurally invalid.
+ This is an internal error of the graph builder. The input graph is that
+ of the rule element that is described in the auxiliary data.
+
+ INPUT_GRAPH_TOO_BIG
+
+ The placer has been passed an input graph that is structurally valid, but
+ that is too big to be placed. (Either it is too big for the target device
+ or it is too big relative to the current capabilities of the placer.) The
+ input graph is that of the rule element that is described in the
+ auxiliary data.
+*/
+
+typedef enum nlm_log_fms_placer
+{
+ NLM_LOG_FMS_PLACER_RULE_FATAL,
+ NLM_LOG_FMS_PLACER_RULE_NOT_PLACED,
+ NLM_LOG_FMS_PLACER_RULE_TRACE,
+ NLM_LOG_FMS_PLACER_INPUT_GRAPH_INVALID,
+ NLM_LOG_FMS_PLACER_INPUT_GRAPH_TOO_BIG
+} nlm_log_fms_placer;
+
+/* NLM_LOG_FMS_PLACER_RULE_FATAL auxiliary data. */
+
+struct nlm_log_fms_placer_rule_fatal
+{
+ struct nlm_logger_rule_data id;
+};
+
+/** Auxiliary data for 'xprint' callback from placer.
+ This auxiliary data is supplied for error codes:
+
+ NLM_LOG_FMS_PLACER_RULE_NOT_PLACED
+ NLM_LOG_FMS_PLACER_RULE_TRACE
+ NLM_LOG_FMS_PLACER_INPUT_GRAPH_INVALID
+ NLM_LOG_FMS_PLACER_INPUT_GRAPH_TOO_BIG
+
+ Note that these logs report the status of exactly one compilation
+ rule element, as opposed to an entire user rule in the sense of
+ nlm_database_add_rule(). In a compiled database, a single user rule
+ may be decomposed into a collection of rule elements. Each of these
+ rule elements either does or does not place independently of all the
+ other rule elements of the user rule. */
+
+struct nlm_log_fms_placer_rule_stat
+{
+ struct nlm_logger_rule_data id; /**< rule and group id of the rule that triggered callback */
+
+ unsigned num_cams; /**< # cams in this rule element */
+ unsigned num_hubs; /**< # hubs " " " " */
+ unsigned num_ctrs; /**< # ctrs " " " */
+ unsigned num_sccs; /**< # SCCs " " " */
+
+ /* The following members give information relating to the cause of
+ non-placement. */
+
+ uint32_t invalid_graph : 1; /**< invalid abstract graph */
+ uint32_t too_big : 1; /**< resources required exceed those of target device */
+
+ /* The following member records the number of placement retries for this
+ rule element, which is the number of times that the database placer has
+ passed this rule to the block placer after the first passing failed to
+ place the element. The value is zero for an element which either has
+ not been passed or has placed in the first passing. */
+
+ uint32_t retries; /**< number of placement retries */
+
+ /* The following member is the compiler's internal handle for the rule
+ element that is being reported as not placing. The user does not
+ dereference this pointer but uses it in subsequent database probe
+ calls which may require the pointer as a handle on the rule element. */
+
+ void *handle; /**< compiler-internal handle */
+};
+
+/* NLM_MODULE_FMS_GRAPH error_code values for an nlm_logger callback.
+
+ NLM_LOG_FMS_GRAPH_INVALID_MML_FOR_REGEX
+
+ For a rule with minimum match length(mml) specification, the mml value is
+ invalid. e.g. if regex is abcd and mml=5
+
+ NLM_LOG_FMS_GRAPH_INVALID_REGEX
+
+ An invalid regex like ab^cd
+
+ NLM_LOG_FMS_GRAPH_INVALID_ZERO_LENGTH_REGEX
+
+ The regex can match empty string. e.g. a? a* ^.* but not ^.*$ .*$
+
+ NLM_LOG_FMS_GRAPH_REGEX_HAS_UNSUPPORTED_CONSTRUCT
+
+ The regex has some unsupported construct like a back reference or a word
+ boundary(\b) or look-ahead/look-behind etc.
+
+ NLM_LOG_FMS_GRAPH_REGEX_TOO_COMPLEX
+ The graph is structurally invalid. This is an internal error of the graph
+ builder. It is the same as NLM_LOG_FMS_PLACER_INPUT_GRAPH_INVALID code of
+ the placer.
+*/
+
+typedef enum nlm_log_fms_graph
+{
+ NLM_LOG_FMS_GRAPH_INVALID_MML_FOR_REGEX = 1,
+ NLM_LOG_FMS_GRAPH_INVALID_REGEX,
+ NLM_LOG_FMS_GRAPH_INVALID_ZERO_LENGTH_REGEX,
+ NLM_LOG_FMS_GRAPH_REGEX_HAS_UNSUPPORTED_CONSTRUCT,
+ NLM_LOG_FMS_GRAPH_REGEX_TOO_COMPLEX,
+ NLM_LOG_FMS_GRAPH_SIZE_EXCEEDS_LIMIT
+} nlm_log_fms_graph;
+
+typedef enum nlm_log_fms_tail
+{
+ NLM_LOG_FMS_TAIL_FANOUT_TOO_HIGH = 1000,
+ NLM_LOG_FMS_TAIL_OFFSET_TOO_LARGE,
+ NLM_LOG_FMS_TAIL_INVALID_REGEX,
+ NLM_LOG_FMS_TAIL_REDUNDANT_PREFIX,
+ NLM_LOG_FMS_TAIL_TOO_MANY_START_STATES
+} nlm_log_fms_tail;
+
+/** default 'xprint' callback */
+extern void default_xprint (void *cookie, nlm_xprint_type type, nlm_xprint_module module,
+ const char *str, unsigned int error_code, void *aux_data);
+/** nop callback that ignores all arguments */
+extern void nop_xprint (void *cookie, nlm_xprint_type type, nlm_xprint_module module,
+ const char *str, unsigned int error_code, void *aux_data);
+
+/* different types of printf */
+extern void nlm_logger_xprintf1 (nlm_logger *logger, const char *fmt, ...);
+extern void nlm_logger_xprintf2 (nlm_logger *logger, nlm_xprint_type type, const char *fmt, ...);
+extern void nlm_logger_xprintf3 (nlm_logger *logger, nlm_xprint_type type, nlm_xprint_module module,
+ const char *fmt, ...);
+extern void nlm_logger_xprintf4 (nlm_logger *logger, nlm_xprint_type type, nlm_xprint_module module,
+ unsigned int error_code, const char *fmt, ...);
+extern void nlm_logger_xprintf5 (nlm_logger *logger, nlm_xprint_type type, nlm_xprint_module module,
+ unsigned int error_code, void *aux_data, const char *fmt, ...);
+
+extern nlm_logger default_logger; /**< logger that prints messages to stdout */
+extern nlm_logger nop_logger; /**< logger that suppresses all messages */
+
+#endif /* __NLM_LOGGER_H */
+
359 include/nlm_packet_api.h
@@ -0,0 +1,359 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+/** \file nlm_packet_api.h
+ header file for Dataplane/packet API */
+#ifndef __NLM_PACKET_API_H
+#define __NLM_PACKET_API_H
+
+#include "nlm_common_api.h"
+
+struct nlm_device; /* prototype of device structure */
+struct nlm_flow; /* prototype of flow structure */
+struct nlm_job; /* opaque job structure */
+
+typedef enum nlm_ring_id
+{
+ NLM_MASTER_RING = 0,
+ NLM_PCIE_RING_1,
+ NLM_PCIE_RING_2,
+ NLM_PCIE_RING_3,
+ NLM_XAUI_RING_0,
+ NLM_XAUI_RING_1,
+ NLM_LAST_UNUSED_RING_ID
+} nlm_ring_id;
+
+#define NLM_MAX_THREADS 256
+#define NLM_MANAGER_THREAD_ID -1
+
+/** structure to pass configuration parameters to data plane library */
+struct nlm_device_config
+{
+ void *register_map_base_virt; /**< virt base addr of register map */
+ nlm_phys_addr register_map_base_phys; /**< phys base addr of register map */
+ uint32_t register_map_size; /**< size of register map in bytes */
+ void *sysmem_base_virt; /**< virt base addr of system memory */
+ nlm_phys_addr sysmem_base_phys; /**< phys base addr of system memory */
+ uint32_t sysmem_size; /**< size of system memory in bytes */
+ uint32_t input_fifo_size; /**< num of elements in input fifo */
+ uint32_t output_fifo_size; /**< num of elements in output fifo */
+ uint32_t size_of_database_extension_area; /**< database spill over size in bytes. Ignored by NLS2008 */
+ uint32_t size_of_context_save_restore_area; /**< context save/restore area in bytes */
+ nlm_phys_addr (*virt_to_phys) (const void *); /**< convert virtual address to physical */
+ nlm_phys_addr packet_base_phys; /**< phys base addr of packet storage area */
+ const void *packet_base_virt; /**< virt base addr of packet storage area */
+ void *memory_pool; /**< user supplied memory pool */
+ uint32_t memory_pool_size; /**< size of memory pool in bytes */
+ int (*try_yield_cpu) (void); /**< function to try to yield cpu */
+
+ /** NLS2008 specific configuration parameters */
+ nlm_phys_addr base_addr_of_ddr_memory; /**< base address of DDR memory (up to 64Gbyte) */
+ uint64_t size_of_ddr_memory; /**< size of attached DDR memory
+ if non zero, it should be bigger
+ than size_of_context_save_restore_area */
+ nlm_ring_id ring_id; /**< 0 - master ring
+ 1,2,3 - slave pcie rings
+ 4 - xaui0
+ 5 - xaui1 (For mars take values in nlm_vring_id */
+ void *cookie; /**< handle to be passed to xmalloc, xfree functions.
+ Not interpreted by datapalne */
+ void *(*xmalloc) (void *cookie, uint32_t); /**< callback function to allocate virtual memory.
+ If specified, memory_pool pointer should be NULL.
+ For each thread at most memory_pool_size
+ of memory will be allocated using this callback.
+ It is assumed this callback function is MT safe */
+ void (*xfree) (void *cookie, void *ptr); /**< callback function to release virtual memory allocated
+ by call to xmalloc above. It is assumed this function
+ is MT safe. */
+
+ uint32_t max_threads; /**< Maximum number of dataplane threads.
+ Default 1 */
+ uint32_t thread_id; /**< Thread ID to which this config belongs */
+ uint32_t using_manager_thread; /**< Will use upto 2 threads for managing the device fifo's */
+
+ int32_t reserved1; /**< Reserved for Device driver/Dataplane communication */
+};
+
+
+/** macro with default initialization values */
+#define DEFAULT_NLM_DEVICE_CONFIG \
+ { \
+ 0, 0, 0, 0, 0, \
+ 0x200000 /** 2Mbyte of sysmem */, \
+ 1024, /** 1K entries in input fifo */ \
+ 4096, /** 4K entries in output fifo */ \
+ 0x180000, /** 1.5Mbyte of spillover */ \
+ 0x40000, /** 256K of context ring */ \
+ 0, 0, 0, 0, \
+ 0x40000, /** 256K of memory pool */ \
+ 0, \
+ 0, /** base of DDR */ \
+ 0, /** size of DDR */ \
+ NLM_MASTER_RING /** ring ID */, \
+ 0, 0, 0, /** cookie, xmalloc, xfree */ \
+ 1, /** Max Threads */ \
+ 0, /** Thread ID */ \
+ 0, /** Manager Thread */ \
+ 0 /** Reserved1 */ \
+ }
+
+/** Estimate netl7 device configuration parameters based on number of flows and jobs
+ and fill in different *_size fields of configuration.
+ \param[in] n_flows number of flows
+ \param[in] n_jobs number of jobs
+ \param[out] config device configuration
+ \return status */
+nlm_status nlm_estimate_device_config (uint32_t n_flows, uint32_t n_jobs,
+ struct nlm_device_config *config);
+
+
+/** Initialize device with 'config' and return pointer to it
+ \param[in] config device configuration parameters as specified in nlm_device_config structure
+ \param[out] p_device returned device handle. This pointer should not be zero
+ \return status
+ \warning Should be called only by thread_id = 0 */
+nlm_status nlm_device_init (struct nlm_device_config *config, struct nlm_device **p_device);
+
+/** Shutdown device
+ \param[in] device device handle
+ \return status
+ \warning should be called only by thread_id = 0 after all remaining DP threads
+ have called nlm_device_detach */
+nlm_status nlm_device_fini (struct nlm_device *device);
+
+/** Attach to initialized device with 'config' and return pointer to it
+ \param[in] config device configuration parameters as specified in nlm_device_config structure
+ \param[out] p_device returned device handle. This pointer should not be zero
+ \return status */
+nlm_status nlm_device_attach (struct nlm_device_config *config, struct nlm_device **p_device);
+
+/** Detach from the live device without shutting it down
+ \param[in] device device handle
+ \return status */
+nlm_status nlm_device_detach (struct nlm_device *device);
+
+/** Try loading the database
+ \param[in] device device handle
+ \param[in] database pointer to compiled rule image
+ \param[in] db_size database buffer size
+ \param[in] replacing_db_id database id the new database is about to replace
+ \param[in] new_db_id database id of the new database
+ \param[in] num_blocks number of physical HW blocks to be occupied by database
+ \return NLM_OK if the database can be successfully loaded or error code otherwise
+ \warning should be called only by thread_id = 0 */
+nlm_status nlm_device_try_load_database (struct nlm_device *device, const void *database,
+ uint32_t db_size, uint32_t replacing_db_id,
+ uint32_t new_db_id, uint32_t num_blocks);
+
+/** Load database onto the device.
+ this function will call yield_cpu() callback from time to time
+ to yield cpu to accommodate OSes with cooperative multi-tasking
+ \param[in] device device handle
+ \param[in] database pointer to compiled rule image
+ \param[in] db_size database buffer size
+ \param[in] database_id id to be assigned to this database that further will be used
+ in nlm_device_unload_database() and nlm_create_flow() functions
+ \param[in] num_blocks number of physical HW blocks to be occupied by database
+ \return NLM_OK if database is fully loaded and error code otherwise
+ \warning should be called only by thread_id = 0 */
+nlm_status nlm_device_load_database (struct nlm_device *device, const void *database,
+ uint32_t db_size, uint32_t database_id, uint32_t num_blocks);
+
+/** Unload database and free associated memory
+ \param[in] device device handle
+ \param[in] database_id id of the database to be unloaded
+ \return status
+ \warning should be called only by thread_id = 0 */
+nlm_status nlm_device_unload_database (struct nlm_device *device, uint32_t database_id);
+
+/** configuration parameters that can be set and get by corresponding functions */
+typedef enum nlm_device_param
+{
+ NLM_INVALID_PARAM
+ = NLM_FIRST_DEVICE_PARAM, /**< marker for invalid parameter */
+ NLM_FLOW_OFFSET, /**< offset of the last byte processed in the flow */
+ NLM_HW_MEMORY, /**< HW memory */
+ NLM_HW_REGISTER, /**< HW register */
+ NLM_MAX_MATCHES_PER_JOB, /**< maximum number of matches per job */
+ NLM_MAX_STATES_PER_BYTE, /**< maximum number of states per byte */
+ NLM_OUTPUT_FIFO_TIMER, /**< HW timer controls when the internal result fifo gets
+ flushed out to system memory */
+ NLM_INPUT_FIFO_TIMER, /**< HW timer that must pass before the DMA engine updates
+ the external input fifo read and output fifo write pointers
+ in system memory */
+ NLM_TIMESTAMP, /**< HW timestamp counter */
+ NLM_DATABASE_COPY_CNT, /**< number of database copies in the device */
+ NLM_DATABASE_BLOCK_CNT, /**< number of blocks loaded into HW memory for given database */
+ NLM_DATABASE_TOTAL_BLOCK_CNT, /**< total number of blocks for given database
+ total == number of blocks in HW memory + blocks in spillover */
+ NLM_DATABASE_BALANCE, /**< Balance loaded databases, set only parameter */
+ NLM_DATABASE_LOAD_POLICY, /**< database load/unload policy */
+ NLM_DATABASE_LOADER_STATUS, /**< info on the current loader state */
+ NLM_TOTAL_BLOCK_CNT, /**< total number of database blocks supported by HW */
+ NLM_PACKET_ENQUEUE_POLICY, /**< packet enqueue policy */
+ NLM_FLOW_FORCE_ONE_FD, /**< force FD to be generated for the next start_jobs() */
+ NLM_XAUI_PASSTHROUGH_FLOW,
+ NLM_LAST_DEVICE_PARAM
+} nlm_device_param;
+
+/** Get specified device parameter */
+nlm_status nlm_device_get_param (struct nlm_device *device, nlm_device_param param, ...);
+/** Set specified device parameter */
+nlm_status nlm_device_set_param (struct nlm_device *device, nlm_device_param param, ...);
+
+/** supported flow types */
+typedef enum nlm_flow_type
+{
+ NLM_FLOW_TYPE_INVALID = NLM_FIRST_FLOW_TYPE, /**< marker for invalid flow */
+ NLM_FLOW_TYPE_STATEFUL, /**< stateful flow */
+ NLM_FLOW_TYPE_STATELESS, /**< stateless flow */
+ NLM_LAST_FLOW_TYPE
+} nlm_flow_type;
+
+/** supported database load policies */
+typedef enum nlm_database_load_policy
+{
+ NLM_DATABASE_LOAD_POLICY_DEFAULT = 0, /**< default load policy for this device */
+ NLM_DATABASE_LOAD_POLICY_MANUAL, /**< user specified load */
+ NLM_DATABASE_LOAD_POLICY_ASYNC, /**< FMS asynchronous load model */
+ NLM_DATABASE_LOAD_POLICY_LAST_UNUSED
+} nlm_database_load_policy;
+
+/** Create flow of the type 'flow_type' on the 'device' for subsequent search
+ in 'database_id'
+ \param[in] device device handle
+ \param[in] flow_type type of flow to be created
+ \param[out] p_flow pointer to the created flow
+ \return status */
+nlm_status nlm_create_flow (struct nlm_device *device, nlm_flow_type flow_type,
+ struct nlm_flow **p_flow);
+
+/** add (database, rule_group) pair to the set of (database, group) pairs searched in
+ the following packets of this flow.
+ \param[in] device device handle
+ \param[in] flow flow handle
+ \param[in] database_id database id to be used during the search
+ \param[in] group_id scan packet with this group id
+ \return status */
+nlm_status nlm_flow_add_database_and_group (struct nlm_device *device, struct nlm_flow *flow,
+ uint32_t database_id, uint32_t group_id);
+
+/** remove (database, rule_group) pair to the set of (database, group) pairs searched in
+ the following packets of this flow.
+ \param[in] device device handle
+ \param[in] flow flow handle
+ \param[in] database_id database id used during the search
+ \param[in] group_id remove this group id
+ \return status */
+nlm_status nlm_flow_remove_database_and_group (struct nlm_device *device, struct nlm_flow *flow,
+ uint32_t database_id, uint32_t group_id);
+
+/** Destroy 'flow' on the 'device'.
+ Sends visible destroy/finish flow request with given \a cookie
+ \param[in] device device handle
+ \param[in] flow flow handle
+ \param[in] cookie is going to be accepted as-is and returned by nlm_get_all_search_results()
+ \return status */
+nlm_status nlm_destroy_stateful_flow (struct nlm_device *device, struct nlm_flow *flow,
+ void *cookie);
+/** Destroy 'flow' on the 'device'.
+ Sends hidden destroy/finish flow request to HW
+ \param[in] device device handle
+ \param[in] flow flow handle
+ \return status */
+nlm_status nlm_destroy_stateless_flow (struct nlm_device *device, struct nlm_flow *flow);
+
+/** Enqueue payload for the search from 'start' to 'end' in 'flow' with 'group_id'
+ and 'cookie' which is going to be accepted as-is and returned by
+ nlm_get_all_search_results()
+ Function returns 'job' pointer for this search request.
+ \param[in] device device handle
+ \param[in] flow flow handle
+ \param[in] start pointer to the first byte to be scanned
+ \param[in] end pointer to the byte after the last byte to be scanned
+ \param[in] cookie is going to be accepted as-is and returned by nlm_get_all_search_results()
+ \param[out] p_job returns job pointer that tracks this search request.
+ p_job pointer should not be zero
+ \return status */
+nlm_status nlm_flow_enqueue_search (struct nlm_device *device, struct nlm_flow *flow,
+ const void *start, const void *end,
+ void *cookie, struct nlm_job **p_job);
+
+/** Cancel 'job' that wasn't sent to the 'device'
+ \param[in] device device handle
+ \param[in] job job handle to be cancelled
+ \return status */
+nlm_status nlm_cancel_job (struct nlm_device *device, struct nlm_job *job);
+
+/** Start searching 'jobs' on the 'device'
+ \param[in] device device handle
+ \param[in] n_jobs number of jobs in the array
+ \param[in] jobs array of jobs to be started
+ \return status */
+nlm_status nlm_start_jobs (struct nlm_device *device, uint32_t n_jobs, struct nlm_job *jobs[]);
+
+/** Information about one result found by HW
+ filled in by nlm_get_all_search_results() function */
+struct nlm_result
+{
+ nlm_status status;
+ /**< status of this result.
+ \li \c NLM_OK u.match.* fields contain info about match
+ \li \c NLM_END_ANCHORED u.match.* fields contain info about match that needs
+ to be post-processed, since it was triggered by end-anchored rule
+ \li \c NLM_END_OF_JOB u.stats.* fields contain statistics for completed job
+ \li \c NLM_* u.* is undefined and status contains the error code
+ for abnormally completed job */
+ void *cookie; /**< cookie for this result */
+ union
+ {
+ struct
+ {
+ uint32_t rule_id; /**< rule ID that triggered the match */
+ uint32_t group_id; /**< group ID that triggered the match */
+ uint32_t database_id; /**< database ID that triggered the match */
+ uint32_t byte_offset; /**< match offset in bytes from the beginning of the job
+ pointing to the last byte of the match */
+ uint64_t flow_offset; /**< match offset in bytes from the beginning of the flow
+ pointing to the last byte of the match */
+ uint32_t match_length; /**< length of the match in bytes */
+ } match;
+ struct
+ {
+ uint64_t timestamp; /**< HW timestamp when end_of_job result goes into ouput fifo */
+ uint32_t total_state_cnt;/**< total number of states executed by HW engine */
+ uint8_t peak_state_cnt; /**< peak number of states seen by HW engine */
+ uint8_t final_state_cnt; /**< final number of states seen by HW engine */
+ } stats;
+ } u;
+};
+
+/** Return all results found so far by \a device into \a buf buffer,
+ but no more than \a n_buf_entries at a time.
+ \param[in] device device handle
+ \param[in] n_buf_entries requested number of entries in the result buffer
+ \param[in] buf result buffer to store results
+ \param[out] n_results actual number of results returned
+ \return NLM_OK, if \a n_results were found and copied into \a buf,
+ \a n_results can be zero, which means that no new results
+ were found and \a buf is not changed */
+nlm_status nlm_get_all_search_results (struct nlm_device *device, uint32_t n_buf_entries,
+ struct nlm_result *buf, uint32_t *n_results);
+
+
+/** Executed by the manager thread. Dispatches accumulated
+ jobs from DP threads to the physical device.
+ \param[in] device device handle
+ \return NLM_OK, if no errors were encountered during submission
+ of jobs to hardware */
+nlm_status nlm_manage_input (struct nlm_device *device);
+
+/** Executed by the manager thread. Return results produced by
+ the physical device to the DP thread buffers for later
+ retreival by the DP threads
+ \param[in] device device handle
+ \return NLM_OK, if no errors were encountered during the
+ the retreival of results from hardware */
+nlm_status nlm_manage_output (struct nlm_device *device);
+
+#endif /* __NLM_PACKET_API_H */
62 include/nlm_stdint.h
@@ -0,0 +1,62 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+#ifndef __NLM_STDINT_H
+#define __NLM_STDINT_H
+
+#if defined (__linux__)
+#ifdef __KERNEL__
+# include <linux/types.h>
+#else
+# include <inttypes.h>
+#endif
+#elif defined (__unix__)
+# include <inttypes.h>
+#else
+# if !defined (__int8_t_defined)
+# define __int8_t_defined
+typedef signed char int8_t;
+typedef short int int16_t;
+typedef int int32_t;
+typedef long long int int64_t;
+# endif
+
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+# if !defined (__uint32_t_defined)
+# define __uint32_t_defined
+typedef unsigned int uint32_t;
+# endif
+typedef unsigned long long int uint64_t;
+#endif
+
+#if defined (__x86_64__) || defined (_LP64) || defined (__LP64__)
+/* 64-bit */
+typedef unsigned long nlm_uintptr_t;
+typedef long nlm_intptr_t;
+#define NLM_PRIdPTR "ld"
+#define NLM_PRIxPTR "lx"
+#define NLM_PRId32 "d"
+#define NLM_PRIu32 "u"
+#define NLM_PRIx32 "x"
+#define NLM_PRId64 "ld"
+#define NLM_PRIu64 "lu"
+#define NLM_PRIx64 "lx"
+#define NLM_PRIxPHYS "llx"
+#else
+/* 32-bit */
+typedef unsigned int nlm_uintptr_t;
+typedef int nlm_intptr_t;
+#define NLM_PRIdPTR "d"
+#define NLM_PRIxPTR "x"
+#define NLM_PRId32 "d"
+#define NLM_PRIu32 "u"
+#define NLM_PRIx32 "x"
+#define NLM_PRId64 "lld"
+#define NLM_PRIu64 "llu"
+#define NLM_PRIx64 "llx"
+#define NLM_PRIxPHYS "llx"
+#endif
+
+#endif /* __NLM_STDINT_H */
+
221 include/nlm_sync.h
@@ -0,0 +1,221 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+#ifndef __NLM_SYNC_H
+#define __NLM_SYNC_H
+
+/* ==================================================
+ SYNCHRONIZATION PRIMITIVES
+ ================================================== */
+typedef struct spinlock_t
+{
+ union
+ {
+ char pad[64];
+ uint32_t lock;
+ } u;
+} spinlock_t;
+
+typedef struct atomic_t
+{
+ volatile uint32_t counter;
+} atomic_t;
+
+#if defined(__KERNEL__) && defined(__arm__)
+
+/* Minimum effort to make arm kernel demo work.
+ * gcc intrinsics __sync_add_and_fetch are defined
+ * as an external function in the library. These functions
+ * are not satisfied at the kernel mode.
+ */
+#define NLM_SPIN_LOCK(lockm)
+#define NLM_SPIN_UNLOCK(lockm)
+#define MEMORY_BARRIER()
+#define NLM_ATOMIC_ADD32_RETURN(addr, value) \
+ ((addr)->counter = (addr)->counter + value, (addr)->counter)
+#define NLM_ATOMIC_ADD32(addr, value) \
+ ((addr)->counter = (addr)->counter + value, (addr)->counter - value)
+#define NLM_ATOMIC_AND_RETURN(addr, value) \
+ ((addr)->counter = (addr)->counter & value, (addr)->counter)
+#define NLM_ATOMIC_OR_RETURN(addr, value) \
+ ((addr)->counter = (addr)->counter | value, (addr)->counter)
+
+#elif defined(__i386) || defined (__amd64) || defined (__arm__)
+
+/* The following use the gcc's builtin atomic primitives.
+ Replace if being used with anything else */
+#define NLM_SPIN_LOCK(lockm)\
+ do\
+ {\
+ while (__sync_lock_test_and_set(&((lockm)->u.lock), 1) != 0);\
+ }\
+ while (0)
+
+#define NLM_SPIN_UNLOCK(lockm) __sync_lock_release(&((lockm)->u.lock))
+
+#define MEMORY_BARRIER()
+
+#define NLM_ATOMIC_ADD32_RETURN(addr, value) __sync_add_and_fetch (&((addr)->counter), value)
+#define NLM_ATOMIC_ADD32(addr, value) __sync_fetch_and_add (&((addr)->counter), value)
+
+#define NLM_ATOMIC_AND_RETURN(addr, value) __sync_and_and_fetch (&((addr)->counter), value)
+#define NLM_ATOMIC_AND(addr, value) __sync_fetch_and_and (&((addr)->counter), value)
+
+#define NLM_ATOMIC_OR_RETURN(addr, value) __sync_or_and_fetch (&((addr)->counter), value)
+#define NLM_ATOMIC_OR(addr, value) __sync_fetch_and_or (&((addr)->counter), value)
+
+#elif defined (_MIPS_ARCH_XLR) || defined (_MIPS_ARCH_OCTEON)
+
+static __inline__
+void NLM_SPIN_LOCK (spinlock_t *lock)
+{
+ unsigned int tmp;
+
+ __asm__ __volatile__(" .set noreorder # NLM_SPIN_LOCK \n"
+ "1: ll %1, %2 \n"
+ " bnez %1, 1b \n"
+ " li %1, 1 \n"
+ " sc %1, %0 \n"
+ " beqz %1, 1b \n"
+ " sync \n"
+ " .set reorder "
+ : "=m" (lock->u.lock), "=&r" (tmp)
+ : "m" (lock->u.lock)
+ : "memory");
+}
+
+static __inline__
+void NLM_SPIN_UNLOCK (spinlock_t *lock)
+{
+ __asm__ __volatile__(" .set noreorder #NLM_SPIN_UNLOCK \n"
+ " sync \n"
+ " sw $0, %0 \n"
+ " .set reorder "
+ : "=m" (lock->u.lock)
+ : "m" (lock->u.lock)
+ : "memory");
+}
+
+static __inline__
+int32_t NLM_ATOMIC_ADD32_RETURN (atomic_t *v, int32_t value)
+{
+ int32_t temp, result;
+
+ __asm__ __volatile__("1: ll %1, %2 #NLM_ATOMIC_ADD32_RETURN \n"
+ " addu %0, %1, %3 \n"
+ " sc %0, %2 \n"
+ " beqz %0, 2f \n"
+ " addu %0, %1, %3 \n"
+ " .subsection 2 \n"
+ "2: b 1b \n"
+ " .previous \n"
+ " .set mips0 "
+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
+ : "Ir" (value), "m" (v->counter)
+ : "memory");
+ return result;
+}
+
+static __inline__
+void NLM_ATOMIC_ADD32 (atomic_t *v, int32_t value)
+{
+ int32_t temp;
+
+ __asm__ __volatile__("1: ll %0, %1 #NLM_ATOMIC_ADD32 \n"
+ " addu %0, %2 \n"
+ " sc %0, %1 \n"
+ " beqz %0, 1b "
+ : "=&r" (temp), "=m" (v->counter)
+ : "Ir" (value), "m" (v->counter));
+}
+
+static __inline__
+int32_t NLM_ATOMIC_AND_RETURN (atomic_t *v, int32_t value)
+{
+ int32_t temp, result;
+
+ __asm__ __volatile__("1: ll %1, %2 #NLM_ATOMIC_AND_RETURN \n"
+ " and %0, %1, %3 \n"
+ " sc %0, %2 \n"
+ " beqz %0, 2f \n"
+ " and %0, %1, %3 \n"
+ " .subsection 2 \n"
+ "2: b 1b \n"
+ " .previous \n"
+ " .set mips0 "
+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
+ : "Ir" (value), "m" (v->counter)
+ : "memory");
+ return result;
+}
+
+static __inline__
+void NLM_ATOMIC_AND (atomic_t *v, int32_t value)
+{
+ int32_t temp;
+
+ __asm__ __volatile__("1: ll %0, %1 #NLM_ATOMIC_ADD32 \n"
+ " and %0, %2 \n"
+ " sc %0, %1 \n"
+ " beqz %0, 1b "
+ : "=&r" (temp), "=m" (v->counter)
+ : "Ir" (value), "m" (v->counter));
+}
+
+static __inline__
+void NLM_ATOMIC_OR (atomic_t *v, int32_t value)
+{
+ int32_t temp;
+
+ __asm__ __volatile__("1: ll %0, %1 #NLM_ATOMIC_ADD32 \n"
+ " or %0, %2 \n"
+ " sc %0, %1 \n"
+ " beqz %0, 1b "
+ : "=&r" (temp), "=m" (v->counter)
+ : "Ir" (value), "m" (v->counter));
+}
+
+static __inline__
+int32_t NLM_ATOMIC_OR_RETURN (atomic_t *v, int32_t value)
+{
+ int32_t temp, result;
+
+ __asm__ __volatile__("1: ll %1, %2 #NLM_ATOMIC_AND_RETURN \n"
+ " or %0, %1, %3 \n"
+ " sc %0, %2 \n"
+ " beqz %0, 2f \n"
+ " or %0, %1, %3 \n"
+ " .subsection 2 \n"
+ "2: b 1b \n"
+ " .previous \n"
+ " .set mips0 "
+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
+ : "Ir" (value), "m" (v->counter)
+ : "memory");
+ return result;
+}
+
+#endif /* XLR OCTEON */
+
+#if defined(_MIPS_ARCH_XLR)
+
+#define MEMORY_BARRIER() __asm__ __volatile__("sync": : :"memory")
+
+#elif defined(_MIPS_ARCH_OCTEON)
+
+static __inline__
+void MEMORY_BARRIER (void)
+{
+ __asm__ __volatile__ (" .set push \n"
+ " .set arch=octeon \n"
+ " syncw \n"
+ " .set pop ");
+}
+#endif /* XLR OCTEON */
+
+#endif /* __NLM_SYNC_H */
+
+
+
+
+
143 include/nlm_system.h
@@ -0,0 +1,143 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+#ifndef __NLM_SYSTEM_H
+#define __NLM_SYSTEM_H
+
+#include "nlm_logger.h"
+
+#ifndef NULL
+#define NULL ((void*)0)
+#endif
+
+extern void pretty_abort (const char *, const char *, int, const char *);
+extern void warning (const char *);
+extern void * default_xmalloc (void *cookie, unsigned int byte_cnt);
+extern void default_xfree (void *cookie, void *mem_ptr);
+
+typedef struct nlm_allocator
+{
+ void *cookie;
+ void * (*xmalloc) (void *cookie, unsigned int byte_cnt);
+ void (*xfree) (void *cookie, void *mem_ptr);
+} nlm_allocator;
+
+extern nlm_allocator default_allocator;
+
+#ifdef __KERNEL__
+# include <linux/kernel.h>
+# ifdef DEBUG
+# define DPRINT(STR, ARGS...) printk ("%s():" STR, __FUNCTION__, ##ARGS)
+# define DDPRINT(STR, ARGS...) printk (STR, ##ARGS)
+# else
+# define DPRINT(STR, ...) ((void)(0 && (STR)))
+# define DDPRINT(STR, ...) ((void)(0 && (STR)))
+# endif
+#else
+# ifdef DEBUG
+# include <stdio.h>
+# ifdef __GNUC__
+# define DPRINT(STR, ARGS...) printf ("%s():" STR, __FUNCTION__, ##ARGS)
+# define DDPRINT(STR, ARGS...) printf (STR, ##ARGS)
+# else
+# define DPRINT(STR, ...) printf (":"STR, __VA_ARGS__)
+# define DDPRINT(STR, ...) printf (STR, __VA_ARGS__)
+# endif
+# else
+# include <stdio.h>
+# ifdef __GNUC__
+# define DPRINT(STR, ARGS...) ((void) (0 && printf ("%s():" STR, __FUNCTION__, ##ARGS)))
+# define DDPRINT(STR, ARGS...) ((void) (0 && printf (STR, ##ARGS)))
+# else
+# define DPRINT(STR, ...) ((void)(0 && (STR)))
+# define DDPRINT(STR, ...) ((void)(0 && (STR)))
+# endif
+# endif
+#endif
+
+#ifndef NDEBUG
+
+#ifdef __GNUC__
+#define pretty_assert(EXP) \
+ ((void)(!(EXP) ? pretty_abort ("assert("#EXP")", __FILE__, __LINE__, __FUNCTION__), 0 : 0))
+#else
+#define pretty_assert(EXP) \
+ ((void)(!(EXP) ? pretty_abort ("assert", __FILE__, __LINE__, ""), 0 : 0))
+#endif
+
+#else
+#define pretty_assert(EXP) ((void)(0 && (EXP)))
+#endif
+
+#ifdef __GNUC__
+#define abort() pretty_abort ("abort", __FILE__, __LINE__, __FUNCTION__)
+#else
+#define abort() pretty_abort ("abort", __FILE__, __LINE__, "")
+#endif
+
+
+#undef MAX
+#define MAX(A, B) ((A)>(B)?(A):(B))
+
+#undef MIN
+#define MIN(A, B) ((A)<(B)?(A):(B))
+
+#define DEF_BITMAP(N) typedef unsigned char BITMAP_##N[N/8]
+#define BITMAP(N) BITMAP_##N
+#define SET_BIT(BITMAP, BITNO) (BITMAP[BITNO/8] |= 1 << (BITNO) % 8)
+#define TEST_BIT(BITMAP, BITNO) (BITMAP[BITNO/8] >> (BITNO) % 8 & 1)
+#define CLEAR_BIT(BITMAP, BITNO) (BITMAP[BITNO/8] &= ~(1 << (BITNO) % 8))
+#define CLEAR_BITMAP(TYPE, BITMAP) do{memset (BITMAP, 0, sizeof (TYPE));}while(0)
+#define SET_ALL_BITMAP_BITS(TYPE, BITMAP) do{memset (BITMAP, 0xff, sizeof (TYPE));}while(0)
+
+#define OR_BITMAP(TYPE, BMP_DST, BMP_SRC) \
+ do {int i; for (i = 0; i < sizeof (TYPE); i++) \
+ BMP_DST[i] |= BMP_SRC[i]; } while (0)
+
+#define AND_BITMAP(TYPE, BMP_DST, BMP_SRC) \
+ do {int i; for (i = 0; i < sizeof (TYPE); i++) \
+ BMP_DST[i] &= BMP_SRC[i]; } while (0)
+
+#define COPY_BITMAP(TYPE, BMP_DST, BMP_SRC) \
+ do {int i; for (i = 0; i < sizeof (TYPE); i++) \
+ BMP_DST[i] = BMP_SRC[i]; } while (0)
+
+#define NEGATE_BITMAP(TYPE, BITMAP) \
+ do {int i; for (i = 0; i < sizeof (TYPE); i++) \
+ BITMAP[i] = ~ BITMAP[i]; } while (0)
+
+#define COMPARE_BITMAP(TYPE, MAPL, MAPR) \
+ memcmp (MAPL, MAPR, sizeof (TYPE)) == 0
+
+#define COUNT_BITMAP_BITS(TYPE, BITMAP, RESULT) \
+ do \
+ { \
+ int i; \
+ unsigned char c; \
+ RESULT = 0; \
+ for (i = 0; i < sizeof (TYPE); i++) \
+ { \
+ c = BITMAP[i]; \
+ while (c) \
+ { \
+ RESULT++; \
+ c &= c -1; \
+ } \
+ } \
+ } \
+ while (0);
+
+#define TRY(A) \
+ { \
+ nlm_status __tmp_status = A; \
+ if (__tmp_status != NLM_OK) \
+ { \
+ DDPRINT (#A" failed: %s\n", nlm_get_status_string (__tmp_status)); \
+ return __tmp_status; \
+ } \
+ }
+
+#define CHECK_NULL(ADDR) do { if ((ADDR) == NULL) return NLM_OUT_OF_MEMORY; } while (0)
+
+#endif /* __NLM_SYSTEM_H */
+
6 lib/build_fms_dataplane.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+cd dataplane
+gcc -O2 -c -DNLM_HW_FMS -I../../include -I../../src *.c
+cd -
+ar r libpacket_api_fms.a dataplane/*.o
BIN  lib/dataplane/.fms_packet_api.c.swp
Binary file not shown
27 lib/dataplane/LICENSE.TXT
@@ -0,0 +1,27 @@
+/*******************************************************************************
+* Legal Notice:
+* This product is the confidential property of NetLogic Microsystems Inc.
+* ("NetLogic"), is provided under a non-disclosure agreement, and is protected
+* under applicable copyright, patent, and trade secret laws. Unauthorized use,
+* reproduction, distribution or other dissemination without the prior written
+* authorization from NetLogic is strictly prohibited.
+*
+* NETLOGIC DISCLAIMS ALL WARRANTIES OF ANY NATURE, EXPRESS OR IMPLIED,
+* INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF FITNESS FOR A PARTICULAR
+* PURPOSE, MERCHANTABILITY AND/OR NON-INFRINGEMENT OF THIRD PARTY RIGHTS.
+* NETLOGIC ASSUMES NO LIABILITY FOR ANY ERROR OR OMISSIONS IN THIS PRODUCT,OR
+* FOR THE USE OF THIS PRODUCT. IN NO EVENT SHALL NETLOGIC BE LIABLE TO ANY OTHER
+* PARTY FOR ANY SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL DAMAGES, WHETHER
+* BASED ON BREACH OF CONTRACT, TORT, PRODUCT LIABILITY, INFRINGEMENT OF
+* INTELLECTUAL PROPERTY RIGHTS OR OTHERWISE. NETLOGIC RESERVES THE RIGHT TO MAKE
+* CHANGES TO, OR DISCONTINUE, ITS PRODUCTS AT ANY TIME.
+*
+* Distribution of the product herein does not convey a license or any other
+* right in any patent, trademark, or other intellectual property of NetLogic.
+*
+* Use of the product shall serve as acceptance of these terms and conditions.
+* If you do not accept these terms, you should return or destroy the product
+* and any other accompanying information immediately.
+*
+* Copyright, 2008-2010, NetLogic Microsystems, Inc. All rights reserved.
+*******************************************************************************/
30 lib/dataplane/Makefile
@@ -0,0 +1,30 @@
+KERNELDIR := /home/kwan/project/SPG/OCTEON-SDK/linux/kernel_2.6/linux
+CROSS_COMPILE = mips64-octeon-linux-gnu-
+
+SRCS = $(wildcard *.c)
+OBJS = $(SRCS:.c=.o)
+
+CC = $(CROSS_COMPILE)gcc
+CXX = $(CROSS_COMPILE)g++
+AR = $(CROSS_COMPILE)ar
+LD = $(CROSS_COMPILE)ld
+NM = $(CROSS_COMPILE)nm
+STRIP = $(CROSS_COMPILE)strip
+OBJCOPY = $(CROSS_COMPILE)objcopy
+
+TARGET = libpacket_api_fms.a
+
+CFLAGS = -O2 #-D__mips -D__GNUC__
+
+all:$(TARGET)
+$(TARGET):$(OBJS)
+ $(AR) r $@ ./*.o
+ cp $@ ../
+
+%.o : %.c
+ @echo compiling... $<
+ $(CC) $(CFLAGS) -c -DNLM_HW_FMS -I../../include -I../../src *.c
+# $(CC) $(CFLAGS) -c $<
+
+clean:
+ rm -f *.o *.a
17 lib/dataplane/Makefile.org
@@ -0,0 +1,17 @@
+KERNELDIR := /home/kwan/project/SPG/OCTEON-SDK/linux/kernel_2.6/linux
+CROSS_COMPILE = mips64-octeon-linux-gnu-
+
+CC = $(CROSS_COMPILE)gcc
+CXX = $(CROSS_COMPILE)g++
+AR = $(CROSS_COMPILE)ar
+LD = $(CROSS_COMPILE)ld
+NM = $(CROSS_COMPILE)nm
+STRIP = $(CROSS_COMPILE)strip
+OBJCOPY = $(CROSS_COMPILE)objcopy
+
+default:
+ $(CC) -O2 -c -DNLM_HW_FMS -I../../include -I../../src *.c
+ $(AR) r libpacket_api_fms.a ./*.o
+ cp libpacket_api_fms.a ../
+clean:
+ rm -f *.o
3,982 lib/dataplane/fms_packet_api.c
3,982 additions, 0 deletions not shown
62 lib/dataplane/init_all.c
@@ -0,0 +1,62 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+#include "nlm_driver_api.h"
+
+/** init all devices */
+nlm_status
+nlm_init_all_devices (struct nlm_device * devices[NLM_MAX_DEVICE_COUNT],
+ uint32_t *n_devices)
+{
+ nlm_status status;
+ int i;
+ uint32_t device_cnt = 0;
+
+ status = nlm_get_device_count (&device_cnt);
+ if (status != NLM_OK)
+ return status;
+
+ if (device_cnt == 0)
+ return NLM_DRIVER_FAILURE;
+
+ *n_devices = device_cnt;
+
+ for (i = 0; i < device_cnt; i++)
+ {
+ struct nlm_device_config config;
+
+ /* estimate netl7 device configuration parameters based on number of flows and jobs */
+ status = nlm_estimate_device_config (1000 /* flows */, 1000 /* jobs */, &config);
+ if (status != NLM_OK)
+ return status;
+
+ status = nlm_prepare_device_config (i, &config);
+ if (status != NLM_OK)
+ return status;
+
+ /* configure device and get device handle */
+ status = nlm_device_init (&config, &devices[i]);
+ if (status != NLM_OK)
+ return status;
+ }
+
+ return NLM_OK;
+}
+
+nlm_status
+nlm_fini_all_devices (struct nlm_device * devices[NLM_MAX_DEVICE_COUNT],
+ uint32_t n_devices)
+{
+ nlm_status status;
+ int i;
+
+ for (i = 0; i < n_devices; i++)
+ {
+ status = nlm_device_fini (devices[i]);
+ if (status != NLM_OK)
+ return status;
+ }
+
+ return NLM_OK;
+}
+
203 lib/dataplane/init_driver_unix.c
@@ -0,0 +1,203 @@
+/* This program is covered by the license described in LICENSE.TXT
+ * Copyright, 2007-2009, NetLogic Microsystems, Inc. */
+
+#include <string.h>
+#include <stdlib.h>
+#include "nlm_system.h"
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <driver/netl7driver.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "nlm_driver_api.h"
+
+#ifndef api_assert
+#define api_assert pretty_assert
+#endif
+
+nlm_status
+nlm_prepare_device_config (uint32_t device_id,
+ struct nlm_device_config *config)
+{
+ nlm_sys_cfg_t sys_cfg;
+ char buf[1024];
+ int dev_handle;
+ void *virt_addr;
+
+ printf("[%s] in, ring_id:%d\n", __FUNCTION__, config->ring_id);
+
+ if (config == NULL)
+ {
+ DPRINT ("device config pointer is null\n");
+ return NLM_INVALID_ARGUMENT;
+ }
+
+ if (device_id >= NLM_MAX_DEVICE_COUNT)
+ {
+ DPRINT ("Device id is too large\n");
+ return NLM_INVALID_ARGUMENT;
+ }
+
+ if (config->memory_pool_size == 0 || config->input_fifo_size == 0
+ || config->output_fifo_size == 0 || config->sysmem_size == 0)
+ return NLM_INVALID_ARGUMENT;
+
+ /* allocate memory pool if it is still NULL, and no xmalloc pointer
+ is specified for dynamic allocation through the dataplane */
+ if (config->memory_pool == NULL
+ && config->xmalloc == NULL)
+ {
+ config->memory_pool = malloc (config->memory_pool_size);
+ if (config->memory_pool == NULL)
+ return NLM_OUT_OF_MEMORY;
+ }
+
+ /* open the device */
+#if defined (NLM_HW_FMS)
+ if (snprintf (buf, sizeof (buf), NLM_FMS_PROC_PATH, device_id, config->ring_id) < 0)
+ return NLM_DRIVER_FAILURE;
+#elif defined (NLM_HW_MARS2)
+ if (snprintf (buf, sizeof (buf), NLM_MARS2_PROC_PATH, device_id) < 0)
+ return NLM_DRIVER_FAILURE;
+#elif defined (NLM_HW_MARS1)
+ if (snprintf (buf, sizeof (buf), NLM_MARS1_PROC_PATH, device_id) < 0)
+ return NLM_DRIVER_FAILURE;
+#else
+ if (snprintf (buf, sizeof (buf), NLM_MARS3_PROC_PATH, device_id) < 0)
+ return NLM_DRIVER_FAILURE;
+#endif
+
+ dev_handle = config->reserved1 = open (buf, O_RDWR | O_SYNC, 0);
+ if (dev_handle < 0)
+ {
+ DPRINT ("open of %s failed\n", buf);
+ return NLM_DRIVER_FAILURE;
+ }
+
+ /* get size and address of register map */
+ if (ioctl (dev_handle, _IOR (NLM_IOCTL_GET_REGMEM, 0, nlm_sys_cfg_t), &sys_cfg) < 0)
+ return NLM_DRIVER_FAILURE;
+
+ virt_addr = mmap (0, sys_cfg.mem_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, dev_handle, sys_cfg.physical_addr);
+ if (virt_addr == MAP_FAILED)
+ return NLM_DRIVER_FAILURE;
+
+ DPRINT ("register map base = 0x%llx\n", sys_cfg.physical_addr);
+ DPRINT ("register map size = 0x%x\n", sys_cfg.mem_size);
+ DPRINT ("register map virt = 0x%p\n", virt_addr);
+
+ config->register_map_size = sys_cfg.mem_size;
+ config->register_map_base_virt = virt_addr;
+ config->register_map_base_phys = sys_cfg.physical_addr;
+
+ sys_cfg.mem_size = config->sysmem_size;
+ if (ioctl (dev_handle, _IOR (NLM_IOCTL_GET_SYSMEM, 0, nlm_sys_cfg_t), &sys_cfg) < 0)
+ return NLM_DRIVER_FAILURE;
+
+ if (sys_cfg.mem_size < config->sysmem_size)
+ return NLM_OUT_OF_DEVICE_MEMORY;
+
+ virt_addr = mmap (0, sys_cfg.mem_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, dev_handle, sys_cfg.physical_addr);
+ if (virt_addr == MAP_FAILED)
+ return NLM_DRIVER_FAILURE;
+
+ DPRINT ("system memory virt = 0x%p\n", virt_addr);
+ DPRINT ("Driver installed with fixed memory\n");
+ DPRINT ("system memory base = 0x%llx\n", sys_cfg.physical_addr);
+ DPRINT ("system memory size = 0x%x\n", sys_cfg.mem_size);
+
+ /* store phys addr of system memory */
+#if defined (_MIPS_ARCH_OCTEON) && defined (NLM_HW_MARS1)
+ config->sysmem_base_phys = sys_cfg.physical_addr | (1ull<<39);
+#else
+ config->sysmem_base_phys = sys_cfg.physical_addr;
+#endif
+ config->sysmem_base_virt = virt_addr;
+ config->sysmem_size = sys_cfg.mem_size;
+
+ /* get the DMA-able packet memory */
+ if (ioctl (dev_handle, _IOR (NLM_IOCTL_GET_DMAMEM, 0, nlm_sys_cfg_t), &sys_cfg) < 0)
+ return NLM_DRIVER_FAILURE;
+
+ if (sys_cfg.mem_size == 0)
+ return NLM_OUT_OF_DEVICE_MEMORY;
+
+ virt_addr = mmap (0, sys_cfg.mem_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, dev_handle, sys_cfg.physical_addr);
+
+ if (virt_addr == MAP_FAILED)
+ return NLM_DRIVER_FAILURE;
+
+#if defined (_MIPS_ARCH_OCTEON) && defined (NLM_HW_MARS1)
+ config->packet_base_phys = sys_cfg.physical_addr | (1ull<<39);
+#else
+ config->packet_base_phys = sys_cfg.physical_addr;
+#endif
+
+ config->packet_base_virt = virt_addr;
+ /* device handle should be open, if not memory will be freed */
+ printf("[%s] out \n", __FUNCTION__);
+
+ return NLM_OK;
+}
+
+nlm_status
+nlm_free_device_config (struct nlm_device_config *config)
+{
+ if (config == NULL)
+ return NLM_INVALID_ARGUMENT;
+
+ if (config->memory_pool && config->xfree == NULL)
+ free (config->memory_pool);
+