├── .gitignore ├── COPYING ├── Makefile ├── README.md ├── apps ├── Makefile ├── lab4_cli │ ├── Makefile.prepared │ └── README.md ├── lab5 │ ├── Makefile │ ├── README.md │ ├── blm_custom.h │ ├── config.h │ ├── init │ │ ├── nfp_nbi8_dma_i32_i33.json │ │ └── wire.sh │ ├── mac_stats.c │ ├── pcap │ │ ├── udp_pkt.pcap │ │ ├── udp_v2.pcap │ │ └── udp_v3.pcap │ └── wire_main.c ├── lab_template │ ├── Makefile │ └── README └── wire │ ├── Makefile │ ├── README │ ├── blm_custom.h │ ├── config.h │ ├── init │ ├── nfp_nbi8_dma_i32_i33.json │ └── wire.sh │ ├── pkt_count.c │ ├── pkt_count.h │ └── wire_main.c ├── microc ├── blocks │ ├── blm │ │ ├── _h │ │ │ ├── blm_c.h │ │ │ ├── blm_internal.h │ │ │ └── blm_uc.h │ │ ├── _uc │ │ │ └── blm_nbi.uc │ │ ├── blm.h │ │ ├── blm_api.uc │ │ ├── blm_cfg.h │ │ ├── blm_main.uc │ │ └── libblm.c │ └── init │ │ ├── _uc │ │ ├── init_nbi.uc │ │ ├── init_nbi_dma.uc │ │ ├── init_nbi_dma_csr.uc │ │ ├── init_nbi_pc.uc │ │ ├── init_nbi_pc_csr.uc │ │ ├── init_nbi_tm.uc │ │ └── init_nbi_tm_csr.uc │ │ ├── init_config.h │ │ └── init_main.uc ├── include │ ├── assert.h │ ├── nfp6000 │ │ ├── nfp_cls.h │ │ ├── nfp_ctm.h │ │ ├── nfp_event.h │ │ ├── nfp_mac.h │ │ ├── nfp_mac_csr_synch.h │ │ ├── nfp_me.h │ │ ├── nfp_nbi_pc.h │ │ ├── nfp_nbi_tm.h │ │ ├── nfp_pcie.h │ │ └── nfp_qc.h │ ├── stdint.h │ └── types.h └── lib │ ├── net │ ├── _c │ │ ├── csum.c │ │ └── hdr_ext.c │ ├── ah.h │ ├── arp.h │ ├── csum.h │ ├── esp.h │ ├── eth.h │ ├── gre.h │ ├── hdr_ext.h │ ├── icmp.h │ ├── ip.h │ ├── libnet.c │ ├── mpls.h │ ├── sctp.h │ ├── tcp.h │ ├── udp.h │ └── vxlan.h │ ├── nfp │ ├── _c │ │ ├── cls.c │ │ ├── mac_csr_synch.c │ │ ├── macstats.c │ │ ├── me.c │ │ ├── mem_atomic.c │ │ ├── mem_bulk.c │ │ ├── mem_cam.c │ │ ├── mem_lkup.c │ │ ├── mem_pe.c │ │ ├── mem_ring.c │ │ ├── pcie.c │ │ ├── remote_me.c │ │ ├── tm_config.c │ │ ├── tmq.c │ │ └── xpb.c │ ├── cls.h │ ├── libnfp.c │ ├── mac_csr_synch.h │ ├── macstats.h │ ├── me.h │ ├── mem_atomic.h │ ├── mem_bulk.h │ ├── mem_cam.h │ ├── mem_lkup.h │ ├── mem_pe.h │ ├── mem_ring.h │ ├── pcie.h │ ├── remote_me.h │ ├── tm_config.h │ ├── tmq.h │ └── xpb.h │ ├── pkt │ ├── libpkt.c │ └── pkt.h │ └── std │ ├── _c │ ├── cntrs.c │ ├── event.c │ ├── hash.c │ ├── reg_utils.c │ ├── synch.c │ └── write_alert.c │ ├── cntrs.h │ ├── event.h │ ├── hash.h │ ├── libstd.c │ ├── reg_utils.h │ ├── synch.h │ └── write_alert.h └── scripts ├── Makefile.debug ├── Makefile.nfp.config └── Makefile.templates /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | 3 | *.fw 4 | *.uci 5 | *.ucp 6 | *.list 7 | *.obj 8 | *.map 9 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | This file is a summary of the licensing of files in this distribution. 2 | Some files may be marked specifically with a different license, in 3 | which case that license applies to the file in question. 4 | 5 | Most files are licensed under the Apache License, Version 2.0: 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at: 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file Makefile 17 | # @brief Root Makefile 18 | # 19 | 20 | 21 | ROOT_SRC_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 22 | 23 | ALL: help 24 | 25 | help: 26 | @echo "This is the toplevel Makefile for NFP firmware builds" 27 | @echo 28 | @echo "For more help use 'make '" 29 | @echo 30 | @echo "Useful help targets": 31 | @echo " help_build" 32 | @echo " This target provides help on setting up a build directory" 33 | @echo " help_make_app" 34 | @echo " Provides help on making an app" 35 | 36 | help_make_app: 37 | @echo "To build a particular app, such as 'lab', use:" 38 | @echo " make APP=lab all" 39 | @echo "If you are building within the source tree then the application" 40 | @echo "will be built in me/apps/APP" 41 | @echo "" 42 | @echo "If you are building outside of the source tree then the application" 43 | @echo "will be built in this directory" 44 | @echo "" 45 | @echo "It is also possible to simply build the application from within" 46 | @echo "its own directory, for example:" 47 | @echo " cd me/apps/wire" 48 | @echo " make" 49 | 50 | help_build: 51 | @echo "For building firmware is recommended to use a build directory" 52 | @echo "To create one in, for example, your home directory" 53 | @echo " cd ~" 54 | @echo " mkdir nfp_fw_build" 55 | @echo " cd nfp_fw_build" 56 | @echo " make -f /Makefile configure" 57 | @echo "This will create a makefile in ~/nfp_fw_build that can be used to" 58 | @echo "build firmware" 59 | 60 | configure: 61 | @echo "Creating local 'makefile'" 62 | @echo "ROOT_SRC_DIR = $(ROOT_SRC_DIR)" > makefile 63 | @echo "include $(ROOT_SRC_DIR)/Makefile" >> makefile 64 | 65 | include $(ROOT_SRC_DIR)/apps/Makefile 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | This repo contains files necessary to build a firmware image for certain 3 | Netronome Intelligent Server Adapters (more details https://netronome.com). 4 | 5 | The applications included here are firmware components useful for learning 6 | the basics of programming the Netronome Network Flow Processor (NFP) based 7 | Server Adapters. 8 | 9 | Some of the applications included were used as examples at the Netronome 10 | 'P4devcon' workshop (http://open-nfp.org/). 11 | 12 | # Directory Structure 13 | Several folders are in this repo: 14 | * 'apps' where you can find the applications. 15 | * 'microc' contains the libraries used by the applications. 16 | * 'scripts' few Makefile templates. 17 | 18 | # 'P4DevCon' Lab applications 19 | The applications used in the workshop contained in this repo are 20 | 'Lab4' and 'Lab5'. 21 | 22 | ## Lab4 23 | For running Lab4 please check README.md file at apps/lab4. 24 | 25 | ## Lab5 26 | For running Lab5 please check README.md file at apps/lab5. 27 | -------------------------------------------------------------------------------- /apps/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file microc/Makefile 17 | # @brief Makefiles for the firmware apps 18 | # 19 | 20 | include $(ROOT_SRC_DIR)/apps/lab5/Makefile 21 | include $(ROOT_SRC_DIR)/apps/wire/Makefile 22 | -------------------------------------------------------------------------------- /apps/lab4_cli/Makefile.prepared: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file apps/lab_template/Makefile 17 | # @brief Makefile for a template lab 18 | # 19 | 20 | # Define src_dir FIRST - it is the directory that this makefile resides in 21 | # MUST OCCUR BEFORE ANY include's (which will change MAKEFILE_LIST) 22 | app_src_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 23 | ROOT_SRC_DIR ?= $(realpath $(app_src_dir)/../..) 24 | base_dir := $(ROOT_SRC_DIR) 25 | 26 | microc_blocks_dir := $(base_dir)/microc/blocks 27 | microc_libs_dir := $(base_dir)/microc/lib 28 | microc_inc_dir := $(base_dir)/microc/include 29 | scripts_dir := $(base_dir)/scripts 30 | 31 | include $(scripts_dir)/Makefile.nfp.config 32 | -include Makefile.nfp.config 33 | 34 | FW_BUILD := $(app_src_dir) 35 | FW_FW := $(app_src_dir) 36 | include $(scripts_dir)/Makefile.templates 37 | 38 | # 39 | # Application definition starts here 40 | # 41 | # 42 | $(eval $(call micro_c.compile_with_rtl,hello_world_obj,hello_world.c)) 43 | $(eval $(call fw.add_obj,hello_world,hello_world_obj,i32.me0 i32.me1)) 44 | $(eval $(call fw.link_with_rtsyms,hello_world)) 45 | 46 | # 47 | # Debug 48 | # 49 | include $(scripts_dir)/Makefile.debug 50 | 51 | -------------------------------------------------------------------------------- /apps/lab5/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file apps/lab_template/Makefile 17 | # @brief Makefile for a template lab 18 | # 19 | 20 | # Define src_dir FIRST - it is the directory that this makefile resides in 21 | # MUST OCCUR BEFORE ANY include's (which will change MAKEFILE_LIST) 22 | app_src_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 23 | ROOT_SRC_DIR ?= $(realpath $(app_src_dir)/../..) 24 | base_dir := $(ROOT_SRC_DIR) 25 | 26 | microc_blocks_dir := $(base_dir)/microc/blocks 27 | microc_libs_dir := $(base_dir)/microc/lib 28 | microc_inc_dir := $(base_dir)/microc/include 29 | scripts_dir := $(base_dir)/scripts 30 | 31 | include $(scripts_dir)/Makefile.nfp.config 32 | -include Makefile.nfp.config 33 | 34 | include $(scripts_dir)/Makefile.templates 35 | 36 | PKT_NBI_OFFSET ?= 64 37 | 38 | # BLM 39 | $(eval $(call microcode.assemble,blm_obj,$(microc_blocks_dir)/blm,blm_main.uc)) 40 | $(eval $(call microcode.add_flags,blm_obj,-DBLM_CUSTOM_CONFIG -DSINGLE_NBI -DPKT_NBI_OFFSET=$(PKT_NBI_OFFSET))) 41 | $(eval $(call microcode.add_flags,blm_obj,-DBLM_BLQ_EMEM_TYPE=emem -DNBII=8 -DBLM_INSTANCE_ID=0)) 42 | $(eval $(call microcode.add_flags,blm_obj,-DBLM_INIT_EMU_RINGS)) 43 | $(eval $(call microcode.add_flags,blm_obj,-DNFP_LIB_ANY_NFAS_VERSION)) 44 | $(eval $(call microcode.add_flags,blm_obj,-I$(microc_blocks_dir)/blm)) 45 | $(eval $(call microcode.add_flags,blm_obj,-I$(microc_blocks_dir)/blm/_h)) 46 | $(eval $(call microcode.add_flags,blm_obj,-I$(microc_blocks_dir)/blm/_uc)) 47 | 48 | # 49 | # Gather MAC statistics 50 | # 51 | $(eval $(call micro_c.compile_with_rtl,stats_obj,mac_stats.c)) 52 | $(eval $(call micro_c.add_fw_libs,stats_obj,nfp std)) 53 | 54 | # 55 | # Application definition 56 | # 57 | $(eval $(call micro_c.compile_with_rtl,wire_obj,wire_main.c)) 58 | $(eval $(call micro_c.add_fw_libs,wire_obj,nfp pkt std net)) 59 | $(eval $(call micro_c.force_include,wire_obj,config)) 60 | $(eval $(call fw.add_obj,wire,wire_obj,i32.me0 i32.me1 i32.me2 i32.me3 i32.me4 i32.me5 i32.me6 i32.me7 i32.me8 i32.me9 i32.me10 i32.me11)) 61 | $(eval $(call fw.add_obj,wire,wire_obj,i33.me0 i33.me1 i33.me2 i33.me3 i33.me4 i33.me5 i33.me6 i33.me7 i33.me8 i33.me9 i33.me10 i33.me11)) 62 | $(eval $(call fw.add_obj,wire,stats_obj,i34.me0)) 63 | $(eval $(call fw.add_obj,wire,blm_obj,i48.me0)) 64 | $(eval $(call fw.link_with_rtsyms,wire)) 65 | $(eval $(call fw.add_ppc,wire,i8,$(PICO_CODE))) 66 | 67 | # 68 | # Debug 69 | # 70 | -include $(scripts_dir)/Makefile.debug 71 | -include Makefile.debug 72 | -------------------------------------------------------------------------------- /apps/lab5/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file apps/wire/config.h 17 | * @brief Infrastructure configuration for the wire application. 18 | */ 19 | 20 | #ifndef __APP_CONFIG_H__ 21 | #define __APP_CONFIG_H__ 22 | 23 | 24 | /* 25 | * RX/TX configuration 26 | * - Configure RX checksum offload so the wire can validate checksums 27 | */ 28 | #define CFG_RX_CSUM_PREPEND 29 | #define PKT_NBI_OFFSET 64 30 | #define MAC_PREPEND_BYTES 4 31 | 32 | /* 33 | * Mapping between channel and TM queue 34 | */ 35 | 36 | enum port_type { 37 | PKT_PTYPE_DROP = 0, 38 | PKT_PTYPE_WIRE = 1, 39 | PKT_PTYPE_HOST = 2, 40 | PKT_PTYPE_WQ = 3, 41 | PKT_PTYPE_NONE = 4 42 | }; 43 | 44 | #define PKT_SET_PORT(type, subsys, port) \ 45 | ((type) << 13) | ((subsys) << 10) | ((port)) 46 | 47 | #define PKT_WIRE_PORT(_nbi, _q) \ 48 | PKT_SET_PORT(PKT_PTYPE_WIRE, (_nbi), (_q)) 49 | 50 | #define PORT_TO_CHANNEL(x) ((x) << 3) 51 | 52 | #define PKTIO_MAX_TM_QUEUES 256 53 | #define PKT_PORT_QUEUE_of(_port) ((_port) & ((PKTIO_MAX_TM_QUEUES) - 1)) 54 | 55 | 56 | #endif /* __APP_CONFIG_H__ */ 57 | -------------------------------------------------------------------------------- /apps/lab5/init/nfp_nbi8_dma_i32_i33.json: -------------------------------------------------------------------------------- 1 | { 2 | "nfp_nbi_dma_nbi_dma_config": 3 | { 4 | "ctm_poll_search_enable" : true, 5 | "rate_limit_enable" :false, 6 | "ctm_poll_interval" :0, 7 | "ctm_poll_enable" : true, 8 | "nbi_number":1, 9 | "dis_rx_blq_wr_in_err":false, 10 | "dis_rx_alloc_in_err":false, 11 | "dis_rx_push_last_err":false, 12 | "dis_buf_rd_err":false, 13 | "dis_bd_ram_err":false, 14 | "dis_ds_ram_err":false, 15 | "dis_bc_ram_err":false, 16 | "dis_push_bus_select":0 17 | }, 18 | "nfp_nbi_dma_bp_config": 19 | { 20 | "0": { 21 | "bp" : 0, 22 | "drop_enable" : true, 23 | "ctm_offset" : 1, 24 | "primary_buffer_list" : 0, 25 | "secondary_buffer_list" : 0, 26 | "ctm_split_length" : 3, 27 | "bpe_head" : 0, 28 | "bpe_chain_end" : 1 29 | }, 30 | "1": { 31 | "bp" : 1, 32 | "drop_enable" : true, 33 | "ctm_offset" : 1, 34 | "primary_buffer_list" : 0, 35 | "secondary_buffer_list" : 0, 36 | "ctm_split_length" : 3, 37 | "bpe_head" : 0, 38 | "bpe_chain_end" : 1 39 | }, 40 | "2": { 41 | "bp" : 2, 42 | "drop_enable" : true, 43 | "ctm_offset" : 1, 44 | "primary_buffer_list" : 0, 45 | "secondary_buffer_list" : 0, 46 | "ctm_split_length" : 3, 47 | "bpe_head" : 0, 48 | "bpe_chain_end" : 1 49 | }, 50 | "3": { 51 | "bp" : 3, 52 | "drop_enable" : true, 53 | "ctm_offset" : 1, 54 | "primary_buffer_list" : 0, 55 | "secondary_buffer_list" : 0, 56 | "ctm_split_length" : 3, 57 | "bpe_head" : 0, 58 | "bpe_chain_end" : 1 59 | }, 60 | "4": { 61 | "bp" : 4, 62 | "drop_enable" : true, 63 | "ctm_offset" : 1, 64 | "primary_buffer_list" : 0, 65 | "secondary_buffer_list" : 0, 66 | "ctm_split_length" : 3, 67 | "bpe_head" : 0, 68 | "bpe_chain_end" : 1 69 | }, 70 | "5": { 71 | "bp" : 5, 72 | "drop_enable" : true, 73 | "ctm_offset" : 1, 74 | "primary_buffer_list" : 0, 75 | "secondary_buffer_list" : 0, 76 | "ctm_split_length" : 3, 77 | "bpe_head" : 0, 78 | "bpe_chain_end" : 1 79 | }, 80 | "6": { 81 | "bp" : 6, 82 | "drop_enable" : true, 83 | "ctm_offset" : 1, 84 | "primary_buffer_list" : 0, 85 | "secondary_buffer_list" : 0, 86 | "ctm_split_length" : 3, 87 | "bpe_head" : 0, 88 | "bpe_chain_end" : 1 89 | }, 90 | "7": { 91 | "bp" : 7, 92 | "drop_enable" : true, 93 | "ctm_offset" : 1, 94 | "primary_buffer_list" : 0, 95 | "secondary_buffer_list" : 0, 96 | "ctm_split_length" : 3, 97 | "bpe_head" : 0, 98 | "bpe_chain_end" : 1 99 | } 100 | }, 101 | "nfp_nbi_dma_bpe_config": 102 | { 103 | "0": { 104 | "bpe" : 0, 105 | "ctm_target" : 32, 106 | "packet_credits" : 128, 107 | "buffer_credits" : 63 108 | }, 109 | "1": { 110 | "bpe" : 1, 111 | "ctm_target" : 33, 112 | "packet_credits" : 128, 113 | "buffer_credits" : 63 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /apps/lab5/init/wire.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # @file apps/wire/init/wire.sh 19 | # @brief init script 20 | # 21 | 22 | NFP_SDK_DIR=${NFP_SDK_DIR:-/opt/netronome} 23 | export PATH=${NFP_SDK_DIR}/bin:$PATH 24 | export LD_LIBRARY_PATH=${NFP_SDK_DIR}/lib:$LD_LIBRARY_PATH 25 | 26 | CONFIG_DIR=$(dirname $0) 27 | #output=/dev/null 28 | 29 | OUTPUT="1" 30 | 31 | Usage() { 32 | echo 33 | echo -e "\t ****** Error: $1 ****** " 34 | echo "Usage: $0 < start | stop | restart >" 35 | echo -e "\tstart : Load ME fw and init MAC/TM/DMA" 36 | echo -e "\tstop : Unload ME fw and stop MAC interfaces" 37 | echo -e "\trestart : stop & start" 38 | echo 39 | exit 1 40 | } 41 | 42 | case "$1" in 43 | start) 44 | echo "Starting FW:" 45 | 46 | echo -n " - Init MAC..." 47 | nfp-nsp -M &> $OUTPUT || exit 1 48 | echo "done" 49 | 50 | echo -n " - nfp-nsp Reset..." 51 | nfp-nsp -R &> $OUTPUT || exit 1 52 | echo "done" 53 | 54 | echo -n " - Load FW..." 55 | nfp-nffw $2 load --no-start &> $OUTPUT || exit 1 56 | echo "done" 57 | 58 | 59 | echo -n " - Init DMA..." 60 | nfp init dma 0 ${CONFIG_DIR}/nfp_nbi8_dma_i32_i33.json &> $OUTPUT || exit 1 61 | echo "done" 62 | 63 | 64 | echo -n " - Enable RX..." 65 | #nfp -m mac -e set port rx 0 0 enable &> $OUTPUT || exit 1 66 | #nfp -m mac -e set port rx 0 4 enable &> $OUTPUT || exit 1 67 | nfp -m mac -e set port rx 0 0 enable 68 | nfp -m mac -e set port rx 0 4 enable 69 | echo "done" 70 | 71 | echo -n " - Set EgressPrependEnable..." 72 | nfp-reg xpb:Nbi0IsldXpbMap.NbiTopXpbMap.MacGlbAdrMap.MacCsr.EgCmdPrependEn0Lo.EgCmdPrependEn=0xf000f 73 | echo "done" 74 | 75 | sleep 1 76 | 77 | echo -n " - Start ME's..." 78 | nfp-nffw start || exit 1 79 | echo "done" 80 | 81 | echo "" 82 | ;; 83 | reload|restart) 84 | if [ $# -lt 2 ] 85 | then 86 | Usage "Insufficient Parameters" 87 | fi 88 | $0 stop 89 | sleep 2 90 | $0 start $2 91 | ;; 92 | stop) 93 | 94 | echo "Stopping FW:" 95 | (rmmod nfp || true) 2> /dev/null 96 | modprobe nfp nfp_dev_cpp=1 nfp_pf_netdev=0 97 | echo -n " - Unload FW... " 98 | nfp-nffw unload 99 | echo "done" 100 | echo "" 101 | ;; 102 | *) 103 | Usage "Invalid option" 104 | esac 105 | exit 0 106 | -------------------------------------------------------------------------------- /apps/lab5/mac_stats.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file apps/lab5/mac_stats.c 17 | * @brief Mac stats read. 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | static void read_mac_stats( int nbi_island, int cls_address ) 30 | { 31 | __xread uint64_t rdata[4]; 32 | __xwrite uint64_t wdata[4]; 33 | int hydra; 34 | int port; 35 | int offset; 36 | SIGNAL sig; 37 | 38 | for (hydra=0; hydra<2; hydra++) { 39 | for (port=0; port<12; port++) { 40 | int address_base_shift_8 = (nbi_island<<30) | (1<<12); 41 | address_base_shift_8 = (address_base_shift_8 + ((hydra*0x1000)>>8) + 42 | ((port*0x100)>>8) ); 43 | for (offset=0; offset<256; offset+=32) { 44 | __asm { 45 | nbi[ read, rdata[0], address_base_shift_8,<<8,offset, 4 ],\ 46 | ctx_swap[sig] 47 | } 48 | wdata[0] = rdata[0]; 49 | wdata[1] = rdata[1]; 50 | wdata[2] = rdata[2]; 51 | wdata[3] = rdata[3]; 52 | if (offset==0) { 53 | int offset_p_8; 54 | offset_p_8 = offset+8; 55 | __asm { 56 | cls[ add64, wdata[0], cls_address, offset, 2 ]; 57 | cls[ add, wdata[1], cls_address, offset_p_8, 6 ], \ 58 | ctx_swap[sig] 59 | } 60 | } else { 61 | __asm { 62 | cls[ add, wdata[0], cls_address, offset, 8 ], \ 63 | ctx_swap[sig] 64 | } 65 | } 66 | } 67 | cls_address += 256; 68 | } 69 | } 70 | } 71 | 72 | static void clear_mac_stats( int cls_address ) 73 | { 74 | __xread uint64_t rdata[4]; 75 | __xwrite uint64_t wdata[4]; 76 | int hydra; 77 | int port; 78 | int offset; 79 | SIGNAL sig; 80 | 81 | for (hydra=0; hydra<2; hydra++) { 82 | for (port=0; port<12; port++) { 83 | for (offset=0; offset<256; offset+=32) { 84 | wdata[0] = 0; 85 | wdata[1] = 0; 86 | wdata[2] = 0; 87 | wdata[3] = 0; 88 | __asm { 89 | cls[ write, wdata[0], cls_address, offset, 8 ], \ 90 | ctx_swap[sig] 91 | } 92 | } 93 | cls_address += 256; 94 | } 95 | } 96 | } 97 | 98 | /** main - Read the statistics for both NBI 8 and NBI 9 99 | */ 100 | void main(void) 101 | { 102 | if (ctx()==0) 103 | { 104 | clear_mac_stats(0x0000); 105 | //clear_mac_stats(0x4000); 106 | do { 107 | read_mac_stats(8, 0x0000); 108 | //read_mac_stats(9, 0x4000); 109 | sleep(8192); 110 | } while (1); 111 | } 112 | __asm { 113 | ctx_arb[kill] 114 | } 115 | for (;;); 116 | } 117 | -------------------------------------------------------------------------------- /apps/lab5/pcap/udp_pkt.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-nfpsw/c_packetprocessing/922c3fd387ba2cc4207a64e25074e8a2add31da7/apps/lab5/pcap/udp_pkt.pcap -------------------------------------------------------------------------------- /apps/lab5/pcap/udp_v2.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-nfpsw/c_packetprocessing/922c3fd387ba2cc4207a64e25074e8a2add31da7/apps/lab5/pcap/udp_v2.pcap -------------------------------------------------------------------------------- /apps/lab5/pcap/udp_v3.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-nfpsw/c_packetprocessing/922c3fd387ba2cc4207a64e25074e8a2add31da7/apps/lab5/pcap/udp_v3.pcap -------------------------------------------------------------------------------- /apps/lab5/wire_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file apps/wire/wire_main.c 17 | * @brief Main program for ME cut-through wire app 18 | * 19 | * This application acts as a "wire" which by default will return packets 20 | * back out on the port they were received on. 21 | * 22 | * 23 | * It also doubles up as test code for the header extract 24 | * code. The packet headers are extracted and counts are maintained 25 | * for different types of packets. 26 | */ 27 | 28 | /* Flowenv */ 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | /* 38 | * Mapping between channel and TM queue 39 | */ 40 | #ifndef NBI 41 | #define NBI 0 42 | #endif 43 | 44 | #ifndef PKT_NBI_OFFSET 45 | #define PKT_NBI_OFFSET 128 46 | #endif 47 | 48 | /* DEBUG MACROS */ 49 | 50 | __volatile __export __emem uint32_t debug[8192*64]; 51 | __volatile __export __emem uint32_t debug_idx; 52 | #define DEBUG(_a, _b, _c, _d) do { \ 53 | __xrw uint32_t _idx_val = 4; \ 54 | __xwrite uint32_t _dvals[4]; \ 55 | mem_test_add(&_idx_val, \ 56 | (__mem40 void *)&debug_idx, sizeof(_idx_val)); \ 57 | _dvals[0] = _a; \ 58 | _dvals[1] = _b; \ 59 | _dvals[2] = _c; \ 60 | _dvals[3] = _d; \ 61 | mem_write_atomic(_dvals, (__mem40 void *)\ 62 | (debug + (_idx_val % (1024 * 64))), sizeof(_dvals)); \ 63 | } while(0) 64 | 65 | 66 | /* Counters */ 67 | struct counters { 68 | uint64_t no_vlan; 69 | uint64_t vlan_2; 70 | uint64_t vlan_3; 71 | uint64_t vlan_other; 72 | }; 73 | 74 | struct statistics { 75 | uint64_t no_vlan; 76 | uint64_t vlan_2; 77 | uint64_t vlan_3; 78 | uint64_t vlan_other; 79 | }; 80 | 81 | // __declspec(shared ctm) is one copy shared by all threads in an ME, in CTM 82 | // __declspec(shared export ctm) is one copy shared by all MEs in an island in CTM (CTM default scope for 'export' of island) 83 | // __declspec(shared export imem) is one copy shared by all MEs on the chip in IMU (IMU default scope for 'export' of global) 84 | __declspec(shared scope(island) export cls) struct statistics stats; 85 | __declspec(shared scope(global) export imem) struct counters counters; 86 | 87 | struct pkt_hdr { 88 | struct { 89 | uint32_t mac_timestamp; 90 | uint32_t mac_prepend; 91 | }; 92 | struct eth_vlan_hdr pkt; 93 | }; 94 | 95 | struct pkt_rxed { 96 | struct nbi_meta_catamaran nbi_meta; 97 | struct pkt_hdr pkt_hdr; 98 | }; 99 | 100 | __intrinsic void 101 | stats_packet( struct pkt_rxed *pkt_rxed, 102 | __mem40 struct pkt_hdr *pkt_hdr ) 103 | { 104 | __xwrite uint32_t bytes_to_add; 105 | SIGNAL sig; 106 | int address; 107 | 108 | bytes_to_add = pkt_rxed->nbi_meta.pkt_info.len; 109 | 110 | if (pkt_rxed->pkt_hdr.pkt.tpid!=0x8100) { 111 | address = (uint32_t) &(stats.no_vlan); 112 | } else { 113 | if ((pkt_rxed->pkt_hdr.pkt.tci & 0xfff)==2) { 114 | address = (uint32_t) &(stats.vlan_2); 115 | } else if ((pkt_rxed->pkt_hdr.pkt.tci & 0xfff)==3) { 116 | address = (uint32_t) &(stats.vlan_3); 117 | } else { 118 | address = (uint32_t) &(stats.vlan_other); 119 | } 120 | } 121 | 122 | __asm { 123 | cls[statistic, bytes_to_add, address, 0, 1], ctx_swap[sig] 124 | } 125 | } 126 | 127 | __mem40 struct pkt_hdr * 128 | receive_packet( struct pkt_rxed *pkt_rxed, 129 | size_t size ) 130 | { 131 | __xread struct pkt_rxed pkt_rxed_in; 132 | int island, pnum; 133 | int pkt_off; 134 | __mem40 struct pkt_hdr *pkt_hdr; 135 | 136 | pkt_nbi_recv(&pkt_rxed_in, sizeof(pkt_rxed->nbi_meta)); 137 | pkt_rxed->nbi_meta = pkt_rxed_in.nbi_meta; 138 | 139 | pkt_off = PKT_NBI_OFFSET; 140 | island = pkt_rxed->nbi_meta.pkt_info.isl; 141 | pnum = pkt_rxed->nbi_meta.pkt_info.pnum; 142 | pkt_hdr = pkt_ctm_ptr40(island, pnum, pkt_off); 143 | 144 | mem_read32(&(pkt_rxed_in.pkt_hdr), pkt_hdr, sizeof(pkt_rxed_in.pkt_hdr)); 145 | pkt_rxed->pkt_hdr = pkt_rxed_in.pkt_hdr; 146 | 147 | return pkt_hdr; 148 | } 149 | 150 | void 151 | rewrite_packet( struct pkt_rxed *pkt_rxed, 152 | __mem40 struct pkt_hdr *pkt_hdr ) 153 | { 154 | int vlan; 155 | 156 | vlan = 0; 157 | if (pkt_rxed->pkt_hdr.pkt.tpid==0x8100) { 158 | vlan = pkt_rxed->pkt_hdr.pkt.tci & 0xfff; 159 | if ((vlan==2) || (vlan==3)) { 160 | pkt_hdr->pkt.tci = pkt_rxed->pkt_hdr.pkt.tci ^ 1; 161 | } 162 | } 163 | } 164 | 165 | void 166 | count_packet( struct pkt_rxed *pkt_rxed, 167 | __mem40 struct pkt_hdr *pkt_hdr ) 168 | { 169 | if (pkt_rxed->pkt_hdr.pkt.tpid!=0x8100) { 170 | mem_incr64(&counters.no_vlan); 171 | } else { 172 | if ((pkt_rxed->pkt_hdr.pkt.tci & 0xfff)==2) { 173 | mem_incr64(&counters.vlan_2); 174 | } else if ((pkt_rxed->pkt_hdr.pkt.tci & 0xfff)==3) { 175 | mem_incr64(&counters.vlan_3); 176 | } else { 177 | mem_incr64(&counters.vlan_other); 178 | } 179 | } 180 | } 181 | 182 | void 183 | send_packet( struct nbi_meta_catamaran *nbi_meta, 184 | __mem40 struct pkt_hdr *pkt_hdr ) 185 | { 186 | int island, pnum, plen; 187 | int pkt_off; 188 | __gpr struct pkt_ms_info msi; 189 | __mem40 char *pbuf; 190 | uint16_t q_dst = 0; 191 | 192 | /* Write the MAC egress CMD and adjust offset and len accordingly */ 193 | pkt_off = PKT_NBI_OFFSET + MAC_PREPEND_BYTES; 194 | island = nbi_meta->pkt_info.isl; 195 | pnum = nbi_meta->pkt_info.pnum; 196 | pbuf = pkt_ctm_ptr40(island, pnum, 0); 197 | plen = nbi_meta->pkt_info.len - MAC_PREPEND_BYTES; 198 | 199 | /* Set egress tm queue. 200 | * Set tm_que to mirror pkt to port on which in ingressed. */ 201 | q_dst = PORT_TO_CHANNEL(nbi_meta->port); 202 | 203 | pkt_mac_egress_cmd_write(pbuf, pkt_off, 1, 1); // Write data to make the packet MAC egress generate L3 and L4 checksums 204 | 205 | msi = pkt_msd_write(pbuf, pkt_off); // Write a packet modification script of NULL 206 | pkt_nbi_send(island, 207 | pnum, 208 | &msi, 209 | plen, 210 | NBI, 211 | q_dst, 212 | nbi_meta->seqr, 213 | nbi_meta->seq, 214 | PKT_CTM_SIZE_256); 215 | } 216 | 217 | int 218 | main(void) 219 | { 220 | struct pkt_rxed pkt_rxed; /* The packet header received by the thread */ 221 | __mem40 struct pkt_hdr *pkt_hdr; /* The packet in the CTM */ 222 | 223 | /* 224 | * Endless loop 225 | * 226 | * 1. Get a packet from the wire (NBI) 227 | * 2. Rewrite the packet ready for retransmission 228 | * 3. Count the packet as required 229 | * 4. Do statistics on the packet 230 | * 5. Send the packet back to the wire (NBI) 231 | */ 232 | for (;;) { 233 | /* Receive a packet */ 234 | 235 | pkt_hdr = receive_packet(&pkt_rxed, sizeof(pkt_rxed)); 236 | 237 | /* Rewrite the packet */ 238 | //rewrite_packet(&pkt_rxed, pkt_hdr); 239 | 240 | /* Count the packet */ 241 | //count_packet(&pkt_rxed, pkt_hdr); 242 | 243 | /* Do stats on the packet */ 244 | //stats_packet(&pkt_rxed, pkt_hdr); 245 | 246 | /* Send the packet */ 247 | send_packet(&pkt_rxed.nbi_meta, pkt_hdr); 248 | 249 | } 250 | 251 | return 0; 252 | } 253 | 254 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 255 | -------------------------------------------------------------------------------- /apps/lab_template/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file apps/lab_template/Makefile 17 | # @brief Makefile for a template lab 18 | # 19 | 20 | # Define src_dir FIRST - it is the directory that this makefile resides in 21 | # MUST OCCUR BEFORE ANY include's (which will change MAKEFILE_LIST) 22 | app_src_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 23 | ROOT_SRC_DIR ?= $(realpath $(app_src_dir)/../..) 24 | base_dir := $(ROOT_SRC_DIR) 25 | 26 | microc_blocks_dir := $(base_dir)/microc/blocks 27 | microc_libs_dir := $(base_dir)/microc/lib 28 | microc_inc_dir := $(base_dir)/microc/include 29 | scripts_dir := $(base_dir)/scripts 30 | 31 | include $(scripts_dir)/Makefile.nfp.config 32 | -include Makefile.nfp.config 33 | 34 | FW_BUILD := $(app_src_dir) 35 | FW_FW := $(app_src_dir) 36 | include $(scripts_dir)/Makefile.templates 37 | 38 | # 39 | # Application definition starts here 40 | # 41 | 42 | # 43 | # Debug 44 | # 45 | include $(scripts_dir)/Makefile.debug 46 | 47 | -------------------------------------------------------------------------------- /apps/lab_template/README: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file apps/lab_template/README 17 | # @brief README 18 | # 19 | 20 | # Build 21 | # 22 | make 23 | 24 | # 25 | # Run 26 | # 27 | make fw_start 28 | OR 29 | ./scripts/fw_ctl.sh start ./hello_world.fw 30 | 31 | # 32 | # List Run-time visible symbols 33 | # 34 | make symbols 35 | OR 36 | nfp-rtsym --list 37 | 38 | # 39 | # Look at thread-local storage for i32.me0 in CTM_40 40 | # 41 | nfp-rtsym i32.me0.ctm_40 42 | 43 | # 44 | # Stop 45 | # 46 | make fw_stop 47 | OR 48 | ./scripts/fw_ctl.sh stop 49 | 50 | -------------------------------------------------------------------------------- /apps/wire/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file apps/wire/Makefile 17 | # @brief Makefile for the ME cut-through wire app 18 | # 19 | 20 | # Define src_dir FIRST - it is the directory that this makefile resides in 21 | # MUST OCCUR BEFORE ANY include's (which will change MAKEFILE_LIST) 22 | app_src_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 23 | ROOT_SRC_DIR ?= $(realpath $(app_src_dir)/../..) 24 | base_dir := $(ROOT_SRC_DIR) 25 | 26 | me_blocks_dir := $(base_dir)/microc/blocks 27 | me_libs_dir := $(base_dir)/microc/lib 28 | me_inc_dir := $(base_dir)/microc/include 29 | scripts_dir := $(base_dir)/scripts 30 | 31 | include $(scripts_dir)/Makefile.nfp.config 32 | -include Makefile.nfp.config 33 | 34 | all: wire.fw 35 | 36 | # 37 | # Flags and Options 38 | # 39 | # blm_custom. This should be removed once BLM and NFD have default config. 40 | # Common NFAS flags 41 | wire_NFASFLAGS += $(NFASFLAGS) 42 | wire_NFASFLAGS += $(wire_APPDEFS) -DBLM_CUSTOM_CONFIG 43 | wire_NFASFLAGS += -DNFP_LIB_ANY_NFAS_VERSION 44 | wire_NFASFLAGS += \ 45 | -I. \ 46 | -I$(me_blocks_dir) \ 47 | -I$(me_inc_dir) \ 48 | -I$(me_libs_dir) \ 49 | -I$(NFP_STD_LIB)/include \ 50 | -I$(NFP_STD_LIB)/microcode/include \ 51 | -I$(NFP_STD_LIB)/microcode/src 52 | 53 | # Common NFCC flags 54 | wire_NFCCFLAGS += $(NFCCFLAGS) 55 | wire_NFCCFLAGS += -Qnctx_mode=8 56 | wire_NFCCFLAGS += -FI config.h 57 | wire_NFCCFLAGS += $(wire_APPDEFS) -DBLM_CUSTOM_CONFIG 58 | wire_NFCCFLAGS += \ 59 | -I. \ 60 | -I$(app_src_dir) \ 61 | -I$(me_inc_dir) \ 62 | -I$(me_libs_dir) \ 63 | -I$(me_blocks_dir)/blm \ 64 | -I$(me_blocks_dir)/blm/_h \ 65 | -I$(NFP_STD_LIB)/include \ 66 | -I$(NFP_STD_LIB)/microcode/include 67 | 68 | # Additional MicroC source files (libraries) 69 | wire_NFCCSRCS := \ 70 | $(me_libs_dir)/nfp/libnfp.c \ 71 | $(me_libs_dir)/pkt/libpkt.c \ 72 | $(me_libs_dir)/std/libstd.c \ 73 | $(me_libs_dir)/net/libnet.c \ 74 | $(NFP_STD_LIB)/microc/src/rtl.c 75 | 76 | # Common NFLD flags 77 | wire_NFLDFLAGS += -rtsyms -mip -chip $(CHIP) 78 | 79 | wire_LIST_FILES := 80 | 81 | # 82 | # Infrastructure blocks 83 | # 84 | 85 | # BLM 86 | BLM_DEFS := -DBLM_CUSTOM_CONFIG -DSINGLE_NBI -DPKT_NBI_OFFSET=$(PKT_NBI_OFFSET) 87 | BLM_DEFS += -DBLM_BLQ_EMEM_TYPE=emem -DNBII=8 -DBLM_INSTANCE_ID=0 88 | BLM_DEFS += -DBLM_INIT_EMU_RINGS 89 | 90 | ME_BLM_SRC := $(me_blocks_dir)/blm/blm_main.uc 91 | ME_BLM_LIST := blm.list 92 | ME_BLM_DEFS := $(wire_NFASFLAGS) $(BLM_DEFS) -I. \ 93 | -I$(app_src_dir) \ 94 | -I$(me_blocks_dir)/blm/ \ 95 | -I$(me_blocks_dir)/blm/_h \ 96 | -I$(me_blocks_dir)/blm/_uc 97 | $(ME_BLM_LIST): $(ME_BLM_SRC) 98 | @echo "--- Building $@" 99 | $(Q) $(NFAS) $(ME_BLM_DEFS) -o $@ $< 100 | wire_LIST_FILES += $(ME_BLM_LIST) 101 | 102 | 103 | # 104 | # Application 105 | # 106 | WIRE_SRCS := $(app_src_dir)/wire_main.c $(app_src_dir)/pkt_count.c 107 | WIRE_LIST := wire_main.list 108 | WIRE_DEFS := $(wire_NFCCFLAGS) 109 | $(WIRE_LIST): $(wire_NFCCSRCS) $(WIRE_SRCS) 110 | @echo "--- Building $@" 111 | $(Q) $(NFCC) $(WIRE_DEFS) -Fe$@ $(WIRE_SRCS) $(wire_NFCCSRCS) 112 | wire_LIST_FILES += $(WIRE_LIST) 113 | 114 | 115 | # 116 | # Help 117 | # 118 | .PHONY : app_wire_help 119 | app_wire_help: 120 | @echo "Build Options:" 121 | @echo " Q unset to print compiler output" 122 | @echo "" 123 | @echo "Path Settings:" 124 | @echo " NFP_SDK_DIR SDK installation directory" 125 | @echo "" 126 | @echo "Targets:" 127 | @echo " help this text" 128 | @echo " clean removes compiled binaries" 129 | @echo "" 130 | @echo " wire.fw wire application (default)" 131 | @echo " wire_dbg.fw wire application with single app ME" 132 | @echo "" 133 | 134 | # 135 | # Build 136 | # 137 | wire_dbg.fw: $(wire_LIST_FILES) 138 | @echo "--- Linking $@" 139 | $(NFLD) $(wire_NFLDFLAGS) \ 140 | -elf $@ \ 141 | -u mei0.me0 -l $(WIRE_LIST) \ 142 | -u mei1.me0 -l $(WIRE_LIST) \ 143 | -u ila0.me0 -l $(ME_BLM_LIST) \ 144 | -i i8 -e $(PICO_CODE) 145 | 146 | wire.fw: $(wire_LIST_FILES) 147 | @echo "--- Linking $@" 148 | $(NFLD) $(wire_NFLDFLAGS) \ 149 | -elf $@ \ 150 | -u mei0.me0 -l $(WIRE_LIST) \ 151 | -u mei0.me1 -l $(WIRE_LIST) \ 152 | -u mei0.me2 -l $(WIRE_LIST) \ 153 | -u mei0.me3 -l $(WIRE_LIST) \ 154 | -u mei0.me4 -l $(WIRE_LIST) \ 155 | -u mei0.me5 -l $(WIRE_LIST) \ 156 | -u mei0.me6 -l $(WIRE_LIST) \ 157 | -u mei0.me7 -l $(WIRE_LIST) \ 158 | -u mei0.me8 -l $(WIRE_LIST) \ 159 | -u mei0.me9 -l $(WIRE_LIST) \ 160 | -u mei0.me10 -l $(WIRE_LIST) \ 161 | -u mei0.me11 -l $(WIRE_LIST) \ 162 | -u mei1.me0 -l $(WIRE_LIST) \ 163 | -u mei1.me1 -l $(WIRE_LIST) \ 164 | -u mei1.me2 -l $(WIRE_LIST) \ 165 | -u mei1.me3 -l $(WIRE_LIST) \ 166 | -u mei1.me4 -l $(WIRE_LIST) \ 167 | -u mei1.me5 -l $(WIRE_LIST) \ 168 | -u mei1.me6 -l $(WIRE_LIST) \ 169 | -u mei1.me7 -l $(WIRE_LIST) \ 170 | -u mei1.me8 -l $(WIRE_LIST) \ 171 | -u mei1.me9 -l $(WIRE_LIST) \ 172 | -u mei1.me10 -l $(WIRE_LIST) \ 173 | -u mei1.me11 -l $(WIRE_LIST) \ 174 | -u ila0.me0 -l $(ME_BLM_LIST) \ 175 | -i i8 -e $(PICO_CODE) 176 | 177 | clean: 178 | rm -f *.list 179 | rm -f *.uci 180 | rm -f *.ucp 181 | rm -f *.obj 182 | rm -f wire.fw 183 | rm -f wire_dbg.fw 184 | 185 | distclean: clean 186 | -------------------------------------------------------------------------------- /apps/wire/README: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file apps/wire/README 17 | # @brief README 18 | # 19 | 20 | # 21 | # Overview 22 | # 23 | # This project contains firmware which will program a Netronome NIC 24 | # to act as a wire. As an example, packets ingressing on port 0 will 25 | # egress on port 1, or packets ingressing on port 1 will egress on 26 | # port 0. 27 | # 28 | # When packets are received counters will be incremented according 29 | # to which layer 2 and 3 headers are present in the packet. After 30 | # this is done, the packet will be egressed. 31 | # 32 | 33 | # 34 | # Build firmware 35 | # 36 | make 37 | 38 | # 39 | # Load and run firmware 40 | # 41 | ./init/wire.sh restart ./wire.fw 42 | 43 | # 44 | # Counters 45 | # 46 | 47 | # Mac Counters. Packets received will increment the port 48 | # stats of the port on which it was received. This value is 49 | # cleared after reading. 50 | nfp -m mac show port stats 0 0-11 51 | 52 | # Application Counters. Display the cntrs_if0 and cntrs_if1 runtime symbols 53 | # which will increment according to the layer 2 and 3 headers of the received 54 | # packet. 55 | nfp-rtsym _cntrs_if* 56 | -------------------------------------------------------------------------------- /apps/wire/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file apps/wire/config.h 17 | * @brief Infrastructure configuration for the wire application. 18 | */ 19 | 20 | #ifndef __APP_CONFIG_H__ 21 | #define __APP_CONFIG_H__ 22 | 23 | 24 | /* 25 | * RX/TX configuration 26 | * - Configure RX checksum offload so the wire can validate checksums 27 | */ 28 | #define CFG_RX_CSUM_PREPEND 29 | #define PKT_NBI_OFFSET 64 30 | #define MAC_PREPEND_BYTES 8 31 | 32 | #ifndef NBI 33 | #define NBI 0 34 | #endif 35 | 36 | #define MAC_CHAN_PER_PORT 4 37 | #define TMQ_PER_PORT (MAC_CHAN_PER_PORT * 8) 38 | 39 | #define MAC_TO_PORT(x) (x / MAC_CHAN_PER_PORT) 40 | #define PORT_TO_TMQ(x) (x * TMQ_PER_PORT) 41 | 42 | #ifndef PKT_NBI_OFFSET 43 | #define PKT_NBI_OFFSET 64 44 | #warning PKT_NIB_OFFSET is undefined 45 | #endif 46 | 47 | 48 | #endif /* __APP_CONFIG_H__ */ 49 | -------------------------------------------------------------------------------- /apps/wire/init/nfp_nbi8_dma_i32_i33.json: -------------------------------------------------------------------------------- 1 | { 2 | "nfp_nbi_dma_nbi_dma_config": 3 | { 4 | "ctm_poll_search_enable" : true, 5 | "rate_limit_enable" :false, 6 | "ctm_poll_interval" :0, 7 | "ctm_poll_enable" : true, 8 | "nbi_number":1, 9 | "dis_rx_blq_wr_in_err":false, 10 | "dis_rx_alloc_in_err":false, 11 | "dis_rx_push_last_err":false, 12 | "dis_buf_rd_err":false, 13 | "dis_bd_ram_err":false, 14 | "dis_ds_ram_err":false, 15 | "dis_bc_ram_err":false, 16 | "dis_push_bus_select":0 17 | }, 18 | "nfp_nbi_dma_bp_config": 19 | { 20 | "0": { 21 | "bp" : 0, 22 | "drop_enable" : true, 23 | "ctm_offset" : 1, 24 | "primary_buffer_list" : 0, 25 | "secondary_buffer_list" : 0, 26 | "ctm_split_length" : 3, 27 | "bpe_head" : 0, 28 | "bpe_chain_end" : 1 29 | }, 30 | "1": { 31 | "bp" : 1, 32 | "drop_enable" : true, 33 | "ctm_offset" : 1, 34 | "primary_buffer_list" : 0, 35 | "secondary_buffer_list" : 0, 36 | "ctm_split_length" : 3, 37 | "bpe_head" : 0, 38 | "bpe_chain_end" : 1 39 | }, 40 | "2": { 41 | "bp" : 2, 42 | "drop_enable" : true, 43 | "ctm_offset" : 1, 44 | "primary_buffer_list" : 0, 45 | "secondary_buffer_list" : 0, 46 | "ctm_split_length" : 3, 47 | "bpe_head" : 0, 48 | "bpe_chain_end" : 1 49 | }, 50 | "3": { 51 | "bp" : 3, 52 | "drop_enable" : true, 53 | "ctm_offset" : 1, 54 | "primary_buffer_list" : 0, 55 | "secondary_buffer_list" : 0, 56 | "ctm_split_length" : 3, 57 | "bpe_head" : 0, 58 | "bpe_chain_end" : 1 59 | }, 60 | "4": { 61 | "bp" : 4, 62 | "drop_enable" : true, 63 | "ctm_offset" : 1, 64 | "primary_buffer_list" : 0, 65 | "secondary_buffer_list" : 0, 66 | "ctm_split_length" : 3, 67 | "bpe_head" : 0, 68 | "bpe_chain_end" : 1 69 | }, 70 | "5": { 71 | "bp" : 5, 72 | "drop_enable" : true, 73 | "ctm_offset" : 1, 74 | "primary_buffer_list" : 0, 75 | "secondary_buffer_list" : 0, 76 | "ctm_split_length" : 3, 77 | "bpe_head" : 0, 78 | "bpe_chain_end" : 1 79 | }, 80 | "6": { 81 | "bp" : 6, 82 | "drop_enable" : true, 83 | "ctm_offset" : 1, 84 | "primary_buffer_list" : 0, 85 | "secondary_buffer_list" : 0, 86 | "ctm_split_length" : 3, 87 | "bpe_head" : 0, 88 | "bpe_chain_end" : 1 89 | }, 90 | "7": { 91 | "bp" : 7, 92 | "drop_enable" : true, 93 | "ctm_offset" : 1, 94 | "primary_buffer_list" : 0, 95 | "secondary_buffer_list" : 0, 96 | "ctm_split_length" : 3, 97 | "bpe_head" : 0, 98 | "bpe_chain_end" : 1 99 | } 100 | }, 101 | "nfp_nbi_dma_bpe_config": 102 | { 103 | "0": { 104 | "bpe" : 0, 105 | "ctm_target" : 32, 106 | "packet_credits" : 128, 107 | "buffer_credits" : 63 108 | }, 109 | "1": { 110 | "bpe" : 1, 111 | "ctm_target" : 33, 112 | "packet_credits" : 128, 113 | "buffer_credits" : 63 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /apps/wire/init/wire.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # @file apps/wire/init/wire.sh 19 | # @brief init script 20 | # 21 | 22 | NFP_SDK_DIR=${NFP_SDK_DIR:-/opt/netronome} 23 | export PATH=${NFP_SDK_DIR}/bin:$PATH 24 | export LD_LIBRARY_PATH=${NFP_SDK_DIR}/lib:$LD_LIBRARY_PATH 25 | 26 | CONFIG_DIR=$(dirname $0) 27 | #output=/dev/null 28 | 29 | OUTPUT="1" 30 | 31 | Usage() { 32 | echo 33 | echo -e "\t ****** Error: $1 ****** " 34 | echo "Usage: $0 < start | stop | restart >" 35 | echo -e "\tstart : Load ME fw and init MAC/TM/DMA" 36 | echo -e "\tstop : Unload ME fw and stop MAC interfaces" 37 | echo -e "\trestart : stop & start" 38 | echo 39 | exit 1 40 | } 41 | 42 | case "$1" in 43 | start) 44 | echo "Starting FW:" 45 | 46 | echo -n " - Init MAC..." 47 | nfp-nsp -M &> $OUTPUT || exit 1 48 | echo "done" 49 | 50 | echo -n " - nfp-nsp Reset..." 51 | nfp-nsp -R &> $OUTPUT || exit 1 52 | echo "done" 53 | 54 | echo -n " - Load FW..." 55 | nfp-nffw $2 load --no-start &> $OUTPUT || exit 1 56 | echo "done" 57 | 58 | 59 | echo -n " - Init DMA..." 60 | nfp init dma 0 ${CONFIG_DIR}/nfp_nbi8_dma_i32_i33.json &> $OUTPUT || exit 1 61 | echo "done" 62 | 63 | 64 | echo -n " - Enable RX..." 65 | #nfp -m mac -e set port rx 0 0 enable &> $OUTPUT || exit 1 66 | #nfp -m mac -e set port rx 0 4 enable &> $OUTPUT || exit 1 67 | nfp -m mac -e set port rx 0 0 enable 68 | nfp -m mac -e set port rx 0 4 enable 69 | echo "done" 70 | 71 | echo -n " - Set EgressPrependEnable..." 72 | nfp-reg xpb:Nbi0IsldXpbMap.NbiTopXpbMap.MacGlbAdrMap.MacCsr.EgCmdPrependEn0Lo.EgCmdPrependEn=0xf000f 73 | echo "done" 74 | 75 | sleep 1 76 | 77 | echo -n " - Start ME's..." 78 | nfp-nffw start || exit 1 79 | echo "done" 80 | 81 | echo "" 82 | ;; 83 | reload|restart) 84 | if [ $# -lt 2 ] 85 | then 86 | Usage "Insufficient Parameters" 87 | fi 88 | $0 stop 89 | sleep 2 90 | $0 start $2 91 | ;; 92 | stop) 93 | 94 | echo "Stopping FW:" 95 | (rmmod nfp || true) 2> /dev/null 96 | modprobe nfp nfp_dev_cpp=1 nfp_pf_netdev=0 97 | echo -n " - Unload FW... " 98 | nfp-nffw unload 99 | echo "done" 100 | echo "" 101 | ;; 102 | *) 103 | Usage "Invalid option" 104 | esac 105 | exit 0 106 | -------------------------------------------------------------------------------- /apps/wire/pkt_count.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file apps/wire/pkt_count.c 17 | * @brief Maintain counters based on packet type 18 | * 19 | * This is essentially the test code for the header extract. 20 | */ 21 | 22 | #ifndef _PKT_COUNT_C_ 23 | #define _PKT_COUNT_C_ 24 | 25 | #include "config.h" 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "pkt_count.h" 44 | 45 | /* 46 | * We read packet data from memory into xfer registers at a two byte 47 | * offset so that the IP header gets aligned to a word boundary (i.e., 48 | * xfer register boundary). This makes the header extraction code 49 | * more efficient. 50 | */ 51 | 52 | #define PKT_START_OFF (2) 53 | 54 | /* A structure used for extracting, the different protocol header */ 55 | struct pkt_hdr { 56 | union { 57 | struct eth_hdr eth; 58 | struct vlan_hdr vlan; 59 | struct ip4_hdr ip4; 60 | struct ip6_hdr ip6; 61 | struct tcp_hdr tcp; 62 | struct udp_hdr udp; 63 | }; 64 | }; 65 | 66 | /** 67 | * Check if a Ethernet address is a unicast address. 68 | */ 69 | #define NET_ETH_IS_UC_ADDR(_a) \ 70 | ((((struct eth_addr *)_a)->a[0] & NET_ETH_GROUP_ADDR) == 0) 71 | 72 | /** 73 | * Check if a Ethernet address is a broadcast address. 74 | */ 75 | #define NET_ETH_IS_BC_ADDR(_a) \ 76 | (((uint16_t *)_a)[0] == 0xFFFF && \ 77 | ((uint16_t *)_a)[1] == 0xFFFF && \ 78 | ((uint16_t *)_a)[2] == 0xFFFF) 79 | 80 | /** 81 | * Check if a Ethernet address is a multicast address. 82 | */ 83 | #define NET_ETH_IS_MC_ADDR(_a) \ 84 | (((struct eth_addr *)_a)->a[0] & NET_ETH_GROUP_ADDR) 85 | 86 | 87 | 88 | /* 89 | * Classify and count packets received 90 | */ 91 | __intrinsic void 92 | pkt_count_rx(__mem40 char *buf_addr, __gpr uint32_t buf_off, 93 | __mem40 struct pkt_cnt_if *cntrs) 94 | { 95 | __xread uint32_t pkt_buf[16]; 96 | __lmem uint32_t src_buf[16]; 97 | __gpr struct pkt_hdr eh; 98 | __gpr uint32_t csum_prepend; 99 | __gpr int src_off = buf_off; 100 | __gpr int res; 101 | __gpr int next_proto; 102 | __gpr int len; 103 | 104 | mem_incr64(&cntrs->rx); 105 | 106 | mem_read64(pkt_buf, buf_addr + buf_off - PKT_START_OFF, sizeof(pkt_buf)); 107 | 108 | /* Copy xfer register to a Local Memory buffer for easier extraction */ 109 | reg_cp(src_buf, pkt_buf, sizeof(src_buf)); 110 | src_off = PKT_START_OFF; 111 | 112 | /* 113 | * Handle the checksum prepend if configured 114 | */ 115 | #ifdef CFG_RX_CSUM_PREPEND 116 | /* read the MAC parsing info for CSUM (first 4B are timestamp) */ 117 | csum_prepend = pkt_csum_read(pkt_buf, PKT_START_OFF + 4); 118 | buf_off += MAC_PREPEND_BYTES; 119 | src_off += MAC_PREPEND_BYTES; 120 | 121 | if (NFP_MAC_RX_CSUM_L3_SUM_of(csum_prepend) == 122 | NFP_MAC_RX_CSUM_L3_IPV4_FAIL) { 123 | /* L3 checksum is wrong */ 124 | mem_incr64(&cntrs->err); 125 | return; 126 | } 127 | 128 | if ((NFP_MAC_RX_CSUM_L4_SUM_of(csum_prepend) == 129 | NFP_MAC_RX_CSUM_L4_TCP_FAIL) || 130 | (NFP_MAC_RX_CSUM_L4_SUM_of(csum_prepend) == 131 | NFP_MAC_RX_CSUM_L4_UDP_FAIL)){ 132 | /* L4 checksum is wrong */ 133 | mem_incr64(&cntrs->err); 134 | return; 135 | } 136 | #endif 137 | 138 | /* 139 | * L2 counters 140 | */ 141 | res = he_eth(src_buf, src_off, &eh.eth); 142 | len = HE_RES_LEN_of(res); 143 | next_proto = HE_RES_PROTO_of(res); 144 | src_off += len; 145 | 146 | if (NET_ETH_IS_BC_ADDR((void *)&eh.eth.src) || 147 | NET_ETH_IS_MC_ADDR(&eh.eth.src)) { 148 | mem_incr64(&cntrs->err); 149 | return; 150 | } 151 | 152 | if (NET_ETH_IS_BC_ADDR((void *)&eh.eth.dst) || 153 | NET_ETH_IS_MC_ADDR(&eh.eth.dst)) 154 | mem_incr64(&cntrs->l2_bmcast); 155 | 156 | if (next_proto == HE_8021Q) { 157 | mem_incr64(&cntrs->l2_vlan); 158 | res = he_vlan(src_buf, src_off, &eh.vlan); 159 | len = HE_RES_LEN_of(res); 160 | next_proto = HE_RES_PROTO_of(res); 161 | src_off += len; 162 | } 163 | 164 | /* 165 | * L3 counters 166 | */ 167 | if (next_proto == HE_IP4) { 168 | mem_incr64(&cntrs->ip); 169 | 170 | res = he_ip4(src_buf, src_off, &eh.ip4); 171 | len = HE_RES_LEN_of(res); 172 | next_proto = HE_RES_PROTO_of(res); 173 | src_off += len; 174 | 175 | if (eh.ip4.frag) 176 | mem_incr64(&cntrs->ip_frag); 177 | 178 | if (len > sizeof(struct ip4_hdr)) 179 | mem_incr64(&cntrs->ip_opts); 180 | 181 | } else 182 | return; 183 | 184 | /* 185 | * L4 counters 186 | */ 187 | switch (next_proto) { 188 | case HE_TCP: 189 | case HE_UDP: 190 | mem_incr64(&cntrs->ip_l4); 191 | break; 192 | default: 193 | break; 194 | } 195 | return; 196 | } 197 | 198 | #endif /* _PKT_COUNT_C_ */ 199 | 200 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 201 | -------------------------------------------------------------------------------- /apps/wire/pkt_count.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file apps/wire/pkt_count.h 17 | * @brief Maintain counters based on packet type 18 | * 19 | * Count the different type of packets. This is essentially the test 20 | * code for the header extract. 21 | */ 22 | 23 | #ifndef _PKT_COUNT_H_ 24 | #define _PKT_COUNT_H_ 25 | 26 | #include 27 | #include 28 | 29 | /** 30 | * Per interface counters 31 | */ 32 | struct pkt_cnt_if { 33 | uint64_t rx; /** All packets received */ 34 | uint64_t err; /** Errored frames received (L2 or csum) */ 35 | uint64_t l2_bmcast; /** L2 Broadcast/Multicast frames */ 36 | uint64_t l2_vlan; /** VLANed L2 frames */ 37 | uint64_t ip; /** Number of IP packets received */ 38 | uint64_t ip_l4; /** Number of UDP/TCP packets received */ 39 | uint64_t ip_opts; /** Number of IP packets with IP options */ 40 | uint64_t ip_frag; /** Number of other IP fragments received */ 41 | }; 42 | 43 | /* Marking function prototypes as extern allows us to use 44 | * __forceinline in the implementation to inline the functions. Hmm... */ 45 | 46 | /** 47 | * Classify and count packets received 48 | * 49 | * @param buf_addr Buffer address in memory 50 | * @param offset Offset from buf_addr where packet starts 51 | * @param cntrs Per interface counters to update 52 | * 53 | * This functions reads in the packet header, extracts various items 54 | * from it and updates the per interface counters. It is kinda sorta 55 | * test code for the header extract. 56 | */ 57 | 58 | __intrinsic void pkt_count_rx(__mem40 char *buf_addr, __gpr uint32_t buf_off, 59 | __mem40 struct pkt_cnt_if *cntrs); 60 | 61 | 62 | #endif /* _PKT_COUNT_H_ */ 63 | 64 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 65 | -------------------------------------------------------------------------------- /apps/wire/wire_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file apps/wire/wire_main.c 17 | * @brief Main program for ME cut-through wire app 18 | * 19 | * This application acts as a "wire" which by default will return packets 20 | * back out on the port they were received on. 21 | * 22 | * 23 | * It also doubles up as test code for the header extract 24 | * code. The packet headers are extracted and counts are maintained 25 | * for different types of packets. 26 | */ 27 | 28 | /* Flowenv */ 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "pkt_count.h" 38 | 39 | #include "config.h" 40 | 41 | 42 | /* Counters */ 43 | __export __emem struct pkt_cnt_if cntrs_if0; 44 | __export __emem struct pkt_cnt_if cntrs_if1; 45 | 46 | __intrinsic void 47 | proc_rx(__mem40 char *pbuf, int pkt_off, int port) 48 | { 49 | __mem40 struct pkt_cnt_if *cntrs; 50 | 51 | if (port == 0) 52 | cntrs = &cntrs_if0; 53 | else 54 | cntrs = &cntrs_if1; 55 | 56 | pkt_count_rx(pbuf, pkt_off, cntrs); 57 | } 58 | 59 | int 60 | main(void) 61 | { 62 | __gpr struct pkt_ms_info msi; 63 | __mem40 char *pbuf; 64 | __xread struct nbi_meta_catamaran nbi_meta; 65 | __xread struct nbi_meta_pkt_info *pi = &nbi_meta.pkt_info; 66 | 67 | __gpr enum PKT_CTM_SIZE ctm_buf_size; 68 | __xread pkt_status_t pkt_status; 69 | __gpr int in_port, out_port, pkt_off; 70 | 71 | /* 72 | * Endless loop 73 | * 74 | * 1. Get a packet from the wire (NBI) 75 | * 2. Process the packet incrementing counters 76 | * 4. Send the packet back to the wire (NBI) 77 | */ 78 | for (;;) { 79 | /* Receive a packet */ 80 | pkt_nbi_recv(&nbi_meta, sizeof(nbi_meta)); 81 | in_port = MAC_TO_PORT(nbi_meta.port); 82 | pbuf = pkt_ctm_ptr40(pi->isl, pi->pnum, 0); 83 | 84 | /* Do RX processing on packet */ 85 | pkt_off = PKT_NBI_OFFSET; 86 | proc_rx(pbuf, pkt_off, in_port); 87 | 88 | /* Send the packet */ 89 | 90 | /* Write the MAC egress CMD and adjust offset and len accordingly */ 91 | pkt_off += MAC_PREPEND_BYTES; 92 | pkt_mac_egress_cmd_write(pbuf, pkt_off, 1, 1); 93 | 94 | pkt_off -= 4; 95 | msi = pkt_msd_write(pbuf, pkt_off); 96 | out_port = (in_port) ? 0 : 4; 97 | pkt_nbi_send(pi->isl, 98 | pi->pnum, 99 | &msi, 100 | pi->len - MAC_PREPEND_BYTES + 4, 101 | NBI, 102 | PORT_TO_TMQ(out_port), 103 | nbi_meta.seqr, nbi_meta.seq, PKT_CTM_SIZE_256); 104 | } 105 | 106 | return 0; 107 | } 108 | 109 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 110 | -------------------------------------------------------------------------------- /microc/blocks/blm/blm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file blocks/blm/blm.h 17 | * @brief Micro-C API to the BLM block 18 | */ 19 | 20 | #ifndef __NFP_BLM_H__ 21 | #define __NFP_BLM_H__ 22 | 23 | #if !defined(__NFP_LANG_MICROC) 24 | #error "This file is MicroC only. Use blm_api.uc for microcode." 25 | #endif 26 | 27 | #include 28 | 29 | /* Include the files defining the various BLM resources for nfas and nfcc */ 30 | #include "_h/blm_c.h" 31 | 32 | /** 33 | * This file contains the API for accessing BLM-managed freelists of 34 | * MU buffers. A client would typically use blm_buf_alloc() to allocate 35 | * an MU buffer and blm_buf_free() to release it. The _bulk() variants 36 | * allow the user to allocate and free buffers in batches. These APIs 37 | * do not maintain any local state in the client microengine and do 38 | * not require any explicit initialization. 39 | */ 40 | 41 | /* Not supporting SPLIT_EMU configuration */ 42 | #ifdef SPLIT_EMU_RINGS 43 | #error "SPLIT_EMU_RINGS configuration not supported." 44 | #endif 45 | 46 | /* 47 | * For optimization reasons the following assumptions are made: 48 | * 1. BLM ring IDs are always allocated in an ordered sequence. 49 | * 2. All BLM rings for a given NBI are allocated in the same island. 50 | * 3. BLM rings are big enough to never overflow. 51 | */ 52 | 53 | /** 54 | * blm buffer type 55 | */ 56 | typedef unsigned int blm_buf_handle_t; 57 | 58 | /** 59 | * Convert a blm buffer handle to a 40 bit address 60 | */ 61 | #define blm_buf_handle2ptr(_bh) (__mem40 void *) \ 62 | ((unsigned long long)(_bh) << 11) 63 | 64 | /** 65 | * Convert a 40 bit address to a blm buffer handle 66 | */ 67 | #define blm_buf_ptr2handle(_bp) (blm_buf_handle_t) \ 68 | ((unsigned long long)(_bp) >> 11) 69 | 70 | /** 71 | * Allocate a single buffer from a BLM EMU ring. 72 | * 73 | * @param buf Transfer register to hold the buffer handle 74 | * @param blq The blq number to allocate from (0-3) 75 | * @param sigpair Signal pair to use 76 | * @param sync Sync type to use (sig_done or sig_wait) 77 | * 78 | * @return 0 on success, -1 on failure. 79 | */ 80 | __intrinsic int __blm_buf_alloc(__xread blm_buf_handle_t *buf, 81 | unsigned int blq, 82 | SIGNAL_PAIR *sigpair, sync_t sync); 83 | __intrinsic int blm_buf_alloc(__xread blm_buf_handle_t *buf, 84 | unsigned int blq); 85 | 86 | /** 87 | * Allocate a bulk of buffers from a BLM EMU ring. 88 | * 89 | * @param bufs Transfer register array to hold buffer handles 90 | * @param count Number of buffers to allocate 91 | * @param blq The blq number to allocate from (0-3) 92 | * @param sigpair Signal pair to use 93 | * @param sync Sync type to use (sig_done or sig_wait) 94 | * 95 | * @return 0 on success, -1 on failure. 96 | */ 97 | __intrinsic int __blm_buf_alloc_bulk(__xread blm_buf_handle_t *bufs, 98 | unsigned int count, unsigned int blq, 99 | SIGNAL_PAIR *sigpair, sync_t sync); 100 | __intrinsic int blm_buf_alloc_bulk(__xread blm_buf_handle_t *bufs, 101 | unsigned int count, unsigned int blq); 102 | 103 | /** 104 | * Free a single buffer back into a BLM EMU ring 105 | * 106 | * @param buf The buffer handle to free 107 | * @param blq The blq number to free into (0-3) 108 | */ 109 | __intrinsic void blm_buf_free(blm_buf_handle_t buf, unsigned int blq); 110 | 111 | /** 112 | * Free an array of buffers back into a BLM EMU ring 113 | * 114 | * @param buf [in] The buffers array to free 115 | * @param count [in] Number of buffers to free 116 | * @param blq [in] The blq number to free into (0-3) 117 | * @param sig [in] Signal to use 118 | * @param sync [in] Sync type to use (sig_done or sig_wait) 119 | */ 120 | __intrinsic void __blm_buf_free_bulk(__xwrite blm_buf_handle_t *bufs, 121 | unsigned int count, unsigned int blq, 122 | SIGNAL *sig, sync_t sync); 123 | __intrinsic void blm_buf_free_bulk(__xwrite blm_buf_handle_t *bufs, 124 | unsigned int count, unsigned int blq); 125 | 126 | #endif /* __NFP_BLM_H__ */ 127 | -------------------------------------------------------------------------------- /microc/blocks/blm/blm_api.uc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file blm_api.uc 17 | * @brief Microcode API implementation for BLM buffer alloc/free 18 | */ 19 | 20 | #ifndef __BLM_BUF_API_UC__ 21 | #define __BLM_BUF_API_UC__ 22 | 23 | #include 24 | #include "_h/blm_uc.h" 25 | 26 | /** @file nfp_buf_api.uc Buffer List Manager Macros 27 | * @addtogroup blm_api Buffer List Manager 28 | * @{ 29 | * 30 | * @name Buffer List Manager Macros 31 | * @{ 32 | * 33 | */ 34 | 35 | /* 36 | * Example usage: 37 | * NFP_BLM_BUF_POOL_BIND(BLM_NBI8_BLQ0_EMU_QID, BLM_SMALL_PKT, BLM_NBI8_BLQ0_EMU_Q_LOCALITY, BLM_NBI8_BLQ0_EMU_Q_ISLAND) 38 | * NFP_BLM_BUF_POOL_BIND(BLM_NBI8_BLQ1_EMU_QID, BLM_MEDIUM_PKT, BLM_NBI8_BLQ1_EMU_Q_LOCALITY, BLM_NBI8_BLQ1_EMU_Q_ISLAND) 39 | * NFP_BLM_BUF_POOL_BIND(BLM_NBI8_BLQ2_EMU_QID, BLM_LARGE_PKT, BLM_NBI8_BLQ2_EMU_Q_LOCALITY, BLM_NBI8_BLQ2_EMU_Q_ISLAND) 40 | * NFP_BLM_BUF_POOL_BIND(BLM_NBI8_BLQ3_EMU_QID, BLM_JUMBO_PKT, BLM_NBI8_BLQ3_EMU_Q_LOCALITY, BLM_NBI8_BLQ3_EMU_Q_ISLAND) 41 | */ 42 | #macro NFP_BLM_BUF_POOL_BIND(symbol, pool, locality, island) 43 | .declare_resource blm_qid_/**/pool global 1 symbol 44 | .alloc_resource pool blm_qid_/**/pool global 1 45 | 46 | #if locality == MU_LOCALITY_HIGH 47 | #define_eval _BLM_Q_ADDR_HI ((locality <<30) | (1 <<29) | ((island & 3) <<27)) 48 | #elif locality == MU_LOCALITY_DIRECT_ACCESS 49 | #define_eval _BLM_Q_ADDR_HI ((locality <<30) | ((island & 0x3f) <<24)) 50 | #else 51 | #endif 52 | .declare_resource blm_q_addr_/**/pool global 1 +_BLM_Q_ADDR_HI 53 | .alloc_resource pool/**/_q_loc_iid blm_q_addr_/**/pool global 1 54 | #undef _BLM_Q_ADDR_HI 55 | #endm 56 | 57 | /* 58 | * @param pBuf Output:Packet buffer Transfer register array. Ex: $x[0] 59 | * @param pool Buffer pool to allocate from, synonym for Ring number 60 | * @param base_pool This is 'symbol/ring number' for EMU QID corresponding to BLQ-0. This is used 61 | * to deduce QID locality and Island bits. 62 | * @param len Number of buffer to allocate 63 | * @param sig_name Signal to use 64 | * @param sig_action SIG_NONE or SIG_WAIT 65 | * Example usage: 66 | * In following examples, BLM_SMALL_PKT is the starting QID or base_pool. (It is assumed 67 | * that all QID's for BLM are contiguous. 68 | * nfp_blm_buf_alloc(a, BLM_SMALL_PKT, BLM_SMALL_PKT, 16, sig_buf, SIG_NONE) 69 | * nfp_blm_buf_alloc(b, BLM_SMALL_PKT, BLM_MEDIUM_PKT, 1, sib_buf, SIG_WAIT) 70 | * nfp_blm_buf_alloc(c, BLM_SMALL_PKT, BLM_LARGE_PKT, 2, sig_buf, SIG_NONE) 71 | * nfp_blm_buf_alloc(d, BLM_SMALL_PKT, BLM_JUMBO_PKT, 8, sig_buf, SIG_NONE) 72 | */ 73 | #macro nfp_blm_buf_alloc(pBuf, base_pool, pool, len, sig_name, sig_action) 74 | .begin 75 | .reg ir 76 | .reg q_hi_addr 77 | 78 | move(q_hi_addr, base_pool/**/_q_loc_iid) 79 | #if (isnum(len)) 80 | #if len < 8 81 | mem[pop, pBuf, q_hi_addr, <<8, pool, len], sig_done[sig_name] 82 | #else 83 | #if len > 15 84 | #error "Length range error. Valid range = [1-15]" 85 | #endif 86 | alu[--, --, b, ((len <<1)|1), <<7] ;override LEN & override LEN value 87 | mem[pop, pBuf, q_hi_addr, <<8, pool, max_/**/len], indirect_ref, sig_done[sig_name] 88 | #endif 89 | #else 90 | alu[ir, 1, OR, len, <<1] 91 | alu[--, --, b, ir, <<7] ;override LEN & override LEN value 92 | mem[pop, pBuf, q_hi_addr, <<8, pool, max_8], indirect_ref, sig_done[sig_name] 93 | #endif 94 | 95 | #if (streq('sig_action',SIG_WAIT)) 96 | ctx_arb[sig_name[0]] 97 | #endif 98 | .end 99 | #endm /* nfp_blm_buf_alloc */ 100 | 101 | /* 102 | * @param pBuf Packet buffer Transfer register array. Ex: $x[0] 103 | * @param pool Buffer pool number to return the pBuf to. , synonym for Ring number 104 | * @param base_pool This is 'symbol/ring number' for EMU QID corresponding to BLQ-0. This is used 105 | * to deduce QID locality and Island bits. 106 | * @param len Number of buffers to free 107 | * @param sig_name Signal to use 108 | * @param sig_action SIG_NONE or SIG_WAIT 109 | * 110 | */ 111 | #macro nfp_blm_buf_free(pBuf, base_pool, pool, len, sig_name, sig_action) 112 | .begin 113 | .reg ir q_hi_addr 114 | 115 | move(q_hi_addr, base_pool/**/_q_loc_iid) 116 | #if (isnum(len)) 117 | #if len < 8 118 | mem[put, pBuf, q_hi_addr, <<8, pool, len], sig_done[sig_name] 119 | #else 120 | #if len > 15 121 | #error "Length range error. Valid range = [1-15]" 122 | #endif 123 | alu[--, --, b, ((len <<1)|1), <<7] ;override LEN & override LEN value 124 | mem[put, pBuf, q_hi_addr, <<8, pool, max_/**/len], indirect_ref, sig_done[sig_name] 125 | #endif 126 | #else 127 | alu[ir, 1, OR, len, <<1] 128 | alu[--, --, b, ir, <<7] ;override LEN & override LEN value 129 | mem[put, pBuf, q_hi_addr, <<8, pool, max_8], indirect_ref, sig_done[sig_name] 130 | #endif 131 | 132 | #if (streq('sig_action',SIG_WAIT)) 133 | ctx_arb[sig_name] 134 | #endif 135 | .end 136 | #endm /* nfp_blm_buf_free */ 137 | 138 | /* 139 | * @param pBuf Transfer register. Ex: $x[0] 140 | * @param pool Buffer pool number to return the pBuf to. , synonym for Ring number 141 | * @param base_pool This is 'symbol/ring number' for EMU QID corresponding to BLQ-0. This is used 142 | * to deduce QID locality and Island bits. 143 | * 144 | */ 145 | #macro nfp_blm_buf_free_j(pBuf, base_pool, pool) 146 | .begin 147 | .reg ir q_hi_addr 148 | move(q_hi_addr, base_pool/**/_q_loc_iid) 149 | #if (isnum(pool) || is_rt_const(pool)) 150 | move(ir, ((pool <<16)|(1 <<3))) 151 | #else 152 | alu[--,8, OR, pool, <<16] 153 | #endif 154 | mem[fast_journal, --, q_hi_addr, <<8, pBuf], indirect_ref 155 | .end 156 | #endm /* nfp_blm_buf_free_j */ 157 | 158 | #endif /* __BLM_BUF_API_UC__ */ 159 | -------------------------------------------------------------------------------- /microc/blocks/blm/libblm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file libblm.c 17 | * @brief Micro-C implementation for BLM buffer alloc/free 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "blm.h" 25 | 26 | __intrinsic int 27 | __blm_buf_alloc(__xread blm_buf_handle_t *buf, unsigned int blq, 28 | SIGNAL_PAIR *sigpair, sync_t sync) 29 | { 30 | return __blm_buf_alloc_bulk(buf, 1, blq, sigpair, sync); 31 | } 32 | 33 | __intrinsic int 34 | blm_buf_alloc(__xread blm_buf_handle_t *buf, unsigned int blq) 35 | { 36 | return blm_buf_alloc_bulk(buf, 1, blq); 37 | } 38 | 39 | __intrinsic int 40 | __blm_buf_alloc_bulk(__xread blm_buf_handle_t *bufs, unsigned int count, 41 | unsigned int blq, SIGNAL_PAIR *sigpair, sync_t sync) 42 | { 43 | mem_ring_addr_t raddr_hi; 44 | unsigned int rnum; 45 | 46 | try_ctassert(blq <= 3); 47 | try_ctassert(count <= 16); 48 | 49 | /* BLM ring IDs are always allocated in an ordered sequance */ 50 | rnum = blq + BLM_EMU_RING_ID(8,0); 51 | /* All BLM rings are allocated in the same island */ 52 | raddr_hi = mem_ring_get_addr((__dram void *)BLM_NBI8_BLQ0_EMU_Q_BASE); 53 | 54 | if (sync == sig_done) { 55 | __mem_ring_pop(rnum, raddr_hi, bufs, (count << 2), 64, 56 | sync, sigpair); 57 | } else { 58 | __mem_ring_pop(rnum, raddr_hi, bufs, (count << 2), 64, 59 | sig_done, sigpair); 60 | /* Wait for the completion signal */ 61 | wait_for_all_single(&sigpair->even); 62 | /* Check for an error signal error signal */ 63 | if (signal_test(&sigpair->odd)) 64 | return -1; 65 | } 66 | return 0; 67 | } 68 | 69 | __intrinsic int 70 | blm_buf_alloc_bulk(__xread blm_buf_handle_t *bufs, unsigned int count, 71 | unsigned int blq) 72 | { 73 | SIGNAL_PAIR sigpair; 74 | return __blm_buf_alloc_bulk(bufs, count, blq, &sigpair, ctx_swap); 75 | } 76 | 77 | __intrinsic void 78 | blm_buf_free(blm_buf_handle_t buf, unsigned int blq) 79 | { 80 | mem_ring_addr_t raddr_hi; 81 | unsigned int rnum; 82 | 83 | try_ctassert(blq <= 3); 84 | 85 | /* BLM ring IDs are always allocated in an ordered sequance */ 86 | rnum = blq + BLM_EMU_RING_ID(8,0); 87 | /* All BLM rings are allocated in the same island */ 88 | raddr_hi = mem_ring_get_addr((__dram void *)BLM_NBI8_BLQ0_EMU_Q_BASE); 89 | 90 | mem_ring_journal_fast(rnum, raddr_hi, buf); 91 | } 92 | 93 | __intrinsic void 94 | __blm_buf_free_bulk(__xwrite blm_buf_handle_t *bufs, unsigned int count, 95 | unsigned int blq, SIGNAL *sig, sync_t sync) 96 | { 97 | mem_ring_addr_t raddr_hi; 98 | unsigned int rnum; 99 | 100 | try_ctassert(blq <= 3); 101 | try_ctassert(count <= 16); 102 | 103 | /* BLM ring IDs are always allocated in an ordered sequance */ 104 | rnum = blq + BLM_EMU_RING_ID(8,0); 105 | /* All BLM rings are allocated in the same island */ 106 | raddr_hi = mem_ring_get_addr((__dram void *)BLM_NBI8_BLQ0_EMU_Q_BASE); 107 | 108 | __mem_ring_journal(rnum, raddr_hi, bufs, (count << 2), 64, sync, sig); 109 | } 110 | 111 | __intrinsic void 112 | blm_buf_free_bulk(__xwrite blm_buf_handle_t *bufs, unsigned int count, 113 | unsigned int blq) 114 | { 115 | SIGNAL sig; 116 | __blm_buf_free_bulk(bufs, count, blq, &sig, ctx_swap); 117 | } 118 | -------------------------------------------------------------------------------- /microc/blocks/init/_uc/init_nbi.uc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file: init_nbi.uc 17 | * @brief: Uppermost level of the NBI Island/s initialisation process 18 | * 19 | */ 20 | 21 | /* 22 | * The abstraction of the NBI initialisation looks like this: 23 | * 24 | * Top most level. The nbi_init() calls the distinct setup macros for the DMA, 25 | * Traffic Manager (TM) and Preclassifier (PC). 26 | * init_nbi.uc 27 | * 28 | * Intermediate level. 29 | * init_nbi_dma.uc 30 | * init_nbi_tm.uc 31 | * init_nbi_pc.uc 32 | 33 | * Bottom level. All macros use the .init_csr directives to set the 34 | * registers. 35 | * init_nbi_dma_csr.uc 36 | * init_nbi_tm_csr.uc 37 | * init_nbi_pc_csr.uc 38 | * 39 | */ 40 | 41 | #ifndef _INIT_NBI_UC_ 42 | #define _INIT_NBI_UC_ 43 | 44 | #include "../init_config.h" 45 | #include "init_nbi_tm.uc" 46 | #include "init_nbi_dma.uc" 47 | #include "init_nbi_pc.uc" 48 | 49 | /* Sanity Checks */ 50 | #ifndef NBI_COUNT 51 | #error "NBI_COUNT not defined" 52 | #endif 53 | 54 | #macro nbi_init() 55 | 56 | #define NBI_ID 0 57 | #while (NBI_ID < NBI_COUNT) 58 | 59 | Nbi_Dma_Init(NBI_ID) 60 | Nbi_PreClassifier_Init(NBI_ID) 61 | 62 | #define_eval NBI_ID (NBI_ID + 1) 63 | #endloop 64 | 65 | #ifndef NBI_TM_INIT_SKIP 66 | Nbi_TrafficManager_Init(NBI_COUNT) 67 | #endif 68 | 69 | #endm 70 | 71 | #endif /* _INIT_NBI_UC_ */ 72 | -------------------------------------------------------------------------------- /microc/blocks/init/_uc/init_nbi_pc.uc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file: init_nbi_tm.uc 17 | * @brief: Intermediate Pre-Classifier setup 18 | * 19 | */ 20 | 21 | #ifndef _INIT_NBI_PC_UC_ 22 | #define _INIT_NBI_PC_UC_ 23 | 24 | #ifndef NBI_PKT_PREPEND_BYTES 25 | #error "NBI_PKT_PREPEND_BYTES is not defined" 26 | #endif 27 | 28 | #include "init_nbi_pc_csr.uc" 29 | 30 | /** Nbi_PreClassifier_Init 31 | * 32 | * Pre-Classifier initialisation 33 | * 34 | * @param NBI_ID NBI number, can be 0 or 1 35 | */ 36 | #macro Nbi_PreClassifier_Init(NBI_ID) 37 | #if (NBI_ID < 0) || (NBI_ID > 1) 38 | #error "NBI_ID can only be 0 or 1" 39 | #endif 40 | 41 | /* NBI Packet Classifier Work around for A0 bug 42 | NFPBSP-1226 43 | NFPBSP-1179 44 | */ 45 | #if ((__REVISION_MIN == __REVISION_A0) || \ 46 | (__REVISION_MIN == __REVISION_A1)) 47 | Nbi_PktPreclassifier_NFPBSP_1179(NBI_ID) 48 | #endif 49 | 50 | /* The PortCfg register is write-only, hence we must configure its 51 | fields in one write 52 | */ 53 | #if (NBI_PKT_PREPEND_BYTES>0) 54 | #define_eval PORT_CFG_SKIP (NBI_PKT_PREPEND_BYTES/2) 55 | #else 56 | #define PORT_CFG_SKIP 0 57 | #endif 58 | #define ANALYSIS 1 59 | #define_eval PORT_CFG_VAL ((PORT_CFG_SKIP << 2) | (ANALYSIS)) 60 | #define_eval PORT_CFG_LOOP (127) 61 | #while (PORT_CFG_LOOP >= 0) 62 | Nbi_PktPreclassifier_Characterization_PortCfg(NBI_ID,PORT_CFG_LOOP, 63 | PORT_CFG_VAL) 64 | #define_eval PORT_CFG_LOOP (PORT_CFG_LOOP-1) 65 | 66 | #endloop 67 | #undef ANALYSIS 68 | #undef PORT_CFG_SKIP 69 | #undef PORT_CFG_VAL 70 | #undef PORT_CFG_LOOP 71 | 72 | #endm 73 | 74 | #endif /* _INIT_NBI_PC_UC_ */ 75 | -------------------------------------------------------------------------------- /microc/blocks/init/_uc/init_nbi_pc_csr.uc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file: init_nbi_pc_csr.uc 17 | * @brief: Contains macros to initialise the NBI Packet Pre-Classifier 18 | */ 19 | 20 | #ifndef _INIT_NBI_PC_CSR_UC_ 21 | #define _INIT_NBI_PC_CSR_UC_ 22 | 23 | /** Nbi_PktPreclassifier_Characterization_PortCfg 24 | * 25 | * NBI Pre-Classifier Port configuration. See the NFP-6xxx Databook section on 26 | * the NBI Packet Pre classifier 27 | * 28 | * @param NBI_ID The NBI number, can be 0 or 1 29 | * @param PORT The port number 30 | * @param VALUE Method of interpreting the SRAM data read, to 31 | * produce a result for the lookup 32 | */ 33 | #macro Nbi_PktPreclassifier_Characterization_PortCfg(NBI_ID,PORT,VALUE) 34 | .init_csr xpb:Nbi/**/NBI_ID/**/IsldXpbMap.NbiTopXpbMap.PktPreclassifier.Characterization.PortCfg/**/PORT VALUE const 35 | #endm 36 | 37 | 38 | /** Nbi_PktPreclassifier_Characterization_PortCfg 39 | * 40 | * NBI Pre-Classifier Work-around values for the following bugs: 41 | * NFPBSP-1226 42 | * NFPBSP-1179 43 | * 44 | * @param NBI_ID The NBI number, can be 0 or 1 45 | */ 46 | #macro Nbi_PktPreclassifier_NFPBSP_1179(NBI_ID) 47 | #if (NBI_ID == 0) 48 | .init_csr xpbm:0x0048290000 0x32ff0000 32 const 49 | #else 50 | .init_csr xpbm:0x0049290000 0x32ff0000 32 const 51 | #endif 52 | #endm 53 | 54 | #endif /* _INIT_NBI_PC_CSR_UC_ */ 55 | -------------------------------------------------------------------------------- /microc/blocks/init/init_main.uc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file: init_main.uc 17 | * @brief: Global NFP initialisation settings 18 | * 19 | * @note The list file output of this source file is not intended to be 20 | * loaded on any particular ME. During the build process the 21 | * application can (via the NFCC -L flag) link/load this 22 | * instruction-less list file. 23 | * 24 | */ 25 | #include "_uc/init_nbi.uc" 26 | 27 | .begin 28 | nbi_init() 29 | .end 30 | -------------------------------------------------------------------------------- /microc/include/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file include/assert.h 17 | * @brief Assert macros 18 | */ 19 | #ifndef _ASSERT_H_ 20 | #define _ASSERT_H_ 21 | 22 | #include 23 | 24 | /* 25 | * Compile time asserts are always enabled. Runtime asserts are 26 | * disabled if NDEBUG or NOASSERT is defined. 27 | */ 28 | 29 | #define __CT_ASSERT(expr) __ct_assert(expr, #expr) 30 | 31 | /** 32 | * Perform compile time assertion 33 | * @param expr expression to test 34 | */ 35 | #define ctassert(expr) \ 36 | do { \ 37 | __intrinsic_begin(); \ 38 | __CT_ASSERT(expr); \ 39 | __intrinsic_end(); \ 40 | } while (0) 41 | 42 | /** 43 | * Attempt to perform compile time assertion 44 | * @param expr expression to test 45 | * 46 | * Assertion is not performed unless @expr is a constant expression. 47 | */ 48 | #define try_ctassert(expr) \ 49 | do { \ 50 | __intrinsic_begin(); \ 51 | if (__is_ct_const(expr)) \ 52 | __CT_ASSERT(expr); \ 53 | __intrinsic_end(); \ 54 | } while (0) 55 | 56 | /** 57 | * Print error message and halt compilation 58 | * @param msg message to print 59 | */ 60 | #define cterror(msg) \ 61 | do { \ 62 | __intrinsic_begin(); \ 63 | __ct_assert(0, msg); \ 64 | __intrinsic_end(); \ 65 | } while (0) 66 | 67 | 68 | #if defined(NDEBUG) || defined(NOASSERT) 69 | 70 | /* Turn assert() into a try_ctassert() if compile time constant */ 71 | #define assert(expr) \ 72 | do { \ 73 | __intrinsic_begin(); \ 74 | if (__is_ct_const(expr)) \ 75 | __CT_ASSERT(expr); \ 76 | __intrinsic_end(); \ 77 | } while (0) 78 | 79 | #else /* !NDEBUG */ 80 | 81 | /* 82 | * Lightweight runtime asserts. The ME is suspended and mailbox1 83 | * contains the address where the problem occurred. mailbox 0 is set 84 | * to zero. Excluding the condition check the assert uses about 4 85 | * instructions. You need to link against libnfp to use runtime asserts. 86 | */ 87 | 88 | __intrinsic void ___rt_assert(void *addr); 89 | 90 | __intrinsic void 91 | __rt_assert(void) 92 | { 93 | __gpr unsigned int reg; 94 | __asm { 95 | load_addr[reg, label]; 96 | label: 97 | } 98 | ___rt_assert((void *) reg); 99 | } 100 | 101 | #define __RT_ASSERT(expr) (void)((expr) || (__rt_assert(), 0)) 102 | 103 | /** 104 | * Perform assertion 105 | * @param expr expression to test 106 | * 107 | * If expression is a compile time constant then do a compile time 108 | * assertion. Othterwise do a run time assertion. 109 | */ 110 | #define assert(expr) \ 111 | do { \ 112 | __intrinsic_begin(); \ 113 | if (__is_ct_const(expr)) \ 114 | __CT_ASSERT(expr); \ 115 | else \ 116 | __RT_ASSERT(expr); \ 117 | __intrinsic_end(); \ 118 | } while (0) 119 | 120 | 121 | #endif /* !NDEBUG */ 122 | 123 | #endif /* !_ASSERT_H_ */ 124 | -------------------------------------------------------------------------------- /microc/include/nfp6000/nfp_mac_csr_synch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #ifndef __NFP_MAC_CSR_SYNC_H__ 19 | #define __NFP_MAC_CSR_SYNC_H__ 20 | 21 | /* Firware Status */ 22 | #define ARB_FW_STATUS_ASLEEP 0x23 23 | #define ARB_FW_STATUS_WAKING 0x24 24 | #define ARB_FW_STATUS_AWAKE 0x25 25 | #define ARB_FW_KICKSTART ARB_FW_STATUS_AWAKE 26 | 27 | #define ARB_CLS_RING_NUM 4 28 | #define ARB_CLS_RING_BASE 0x1000 29 | #define ARB_CLS_RING_SIZE 64 30 | #define ARB_CLS_ISLAND 1 31 | #define ARB_ME_ISLAND 1 32 | #define ARB_ME_ID 3 33 | 34 | #define ARB_PORTS_STATS_BASE 0x25000 35 | 36 | #define ARB_CLS_BASE_ADDR (ARB_CLS_ISLAND <<34) 37 | #define ARB_CLS_BASE_ADDR39_32 0x04 38 | #define ARB_CLS_BASE_ADDR_Hi32 0x04000000 39 | 40 | #define ARB_CODE_ETH_CMD_CFG_NOOP 0 41 | #define ARB_CODE_ETH_CMD_CFG_RECACHE 1 42 | #define ARB_CODE_ETH_CMD_CFG_ENABLE_RX 2 43 | #define ARB_CODE_ETH_CMD_CFG_ENABLE_TX 3 44 | #define ARB_CODE_ETH_CMD_CFG_DISABLE_RX 4 45 | #define ARB_CODE_ETH_CMD_CFG_DISABLE_TX 5 46 | #define ARB_CODE_ETH_CMD_CFG_ENABLE_FLUSH 6 47 | #define ARB_CODE_ETH_CMD_CFG_DISABLE_FLUSH 7 48 | /* Update MAX when new commands are added */ 49 | #define ARB_CODE_MAX (ARB_CODE_ETH_CMD_CFG_DISABLE_FLUSH) 50 | 51 | #define ARB_CMD(x) (((x) & 0xff) << 0) 52 | #define ARB_CMD_off(x) (((x) >>0) & 0xff) 53 | #define ARB_PORT(x) (((x) & 0x3f) << 8) 54 | #define ARB_PORT_off(x) (((x) >>8) & 0x3f) 55 | #define ARB_NBI(x) (((x) & 0x1) << 15) 56 | #define ARB_NBI_off(x) (((x) >>15) & 0x1) 57 | #define ARB_CORE(x) (((x) & 0x1) << 14) 58 | #define ARB_CORE_off(x) (((x) >>14) & 0x1) 59 | #define ARB_RECACHE(x) (((x) & 0x1) << 16) 60 | #define ARB_RECACHE_off(x) (((x) >>16) & 0x1) 61 | #define ARB_SOURCE(x) (((x) & 0xff) << 24) 62 | #define ARB_SOURCE_off(x) (((x) >>24) & 0xff) 63 | 64 | /* Mailbox definitions */ 65 | #define ARB_FW_KICKSTART_MBOX 0 66 | #define ARB_FW_GPIO_POLL_MBOX 1 67 | #define ARB_FW_DEBUG_MBOX 2 68 | #define ARB_FW_QUIESCE_MBOX 3 69 | 70 | #define ARB_QUIESCE 0xff 71 | #define ARB_RESUME 0xf5 72 | #define ARB_ACTIVE 0xf5 73 | 74 | #endif /* __NFP_MAC_CSR_SYNC_H__ */ 75 | -------------------------------------------------------------------------------- /microc/include/stdint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file stdint.h 17 | * @brief C99 Integer types 18 | */ 19 | 20 | #ifndef _STDINT_H_ 21 | #define _STDINT_H_ 22 | 23 | /* Integral types */ 24 | typedef signed char int8_t; 25 | typedef short int int16_t; 26 | typedef int int32_t; 27 | typedef long long int int64_t; 28 | 29 | typedef unsigned char uint8_t; 30 | typedef unsigned short int uint16_t; 31 | typedef unsigned int uint32_t; 32 | typedef unsigned long long int uint64_t; 33 | 34 | /* Limits of integral types */ 35 | #define INT8_MIN (-128) 36 | #define INT16_MIN (-32767-1) 37 | #define INT32_MIN (-2147483647-1) 38 | 39 | #define INT8_MAX (127) 40 | #define INT16_MAX (32767) 41 | #define INT32_MAX (2147483647) 42 | 43 | #define UINT8_MAX (255) 44 | #define UINT16_MAX (65535) 45 | #define UINT32_MAX (4294967295U) 46 | 47 | #endif /* _STDINT_H_ */ 48 | -------------------------------------------------------------------------------- /microc/include/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file include/types.h 17 | * @brief Standard types 18 | */ 19 | #ifndef _NFP__TYPES_H_ 20 | #define _NFP__TYPES_H_ 21 | 22 | #if defined(__NFP_LANG_MICROC) 23 | 24 | typedef unsigned int size_t; 25 | typedef int ssize_t; 26 | 27 | 28 | #endif /* __NFP_LANG_MICROC */ 29 | 30 | #endif /* !_NFP__TYPES_H_ */ 31 | -------------------------------------------------------------------------------- /microc/lib/net/ah.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/ah.h 17 | * @brief Definitions for AH header parsing 18 | * 19 | * Incomplete, new definitions will be added as/when needed 20 | */ 21 | 22 | #ifndef _NET_AH_H_ 23 | #define _NET_AH_H_ 24 | 25 | /** 26 | * AH type definitions 27 | */ 28 | 29 | #if defined(__NFP_LANG_MICROC) 30 | 31 | #include 32 | #include 33 | 34 | /** 35 | * AH Header structure 36 | */ 37 | __packed struct ah_hdr { 38 | uint8_t nh; /** Next Header */ 39 | uint8_t pay_len; /** Payload length */ 40 | uint16_t rsvd; /** Reserved */ 41 | uint32_t spi; /** Security Parameters Index */ 42 | uint32_t seq; /** Sequence Number */ 43 | }; 44 | 45 | #endif /* __NFP_LANG_MICROC */ 46 | 47 | #endif /* _NET_AH_H_ */ 48 | 49 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 50 | -------------------------------------------------------------------------------- /microc/lib/net/arp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/arp.h 17 | * @brief Definitions for ARP header parsing 18 | * 19 | */ 20 | 21 | #ifndef _NET_ARP_H_ 22 | #define _NET_ARP_H_ 23 | 24 | #define NET_ARP_HA_LEN 6 25 | 26 | #if defined(__NFP_LANG_MICROC) 27 | 28 | #include 29 | #include 30 | 31 | /** 32 | * ARP header structure 33 | */ 34 | __packed struct arp_hdr { 35 | unsigned int htype:16; /* hardware type */ 36 | unsigned int ptype:16; /* protocol type */ 37 | 38 | unsigned int hlen:8; /* hardware length */ 39 | unsigned int plen:8; /* protocol length */ 40 | unsigned int proto:16; /* operation (1=request, 2=reply) */ 41 | 42 | uint8_t sha[NET_ARP_HA_LEN]; /* sender hardware address */ 43 | 44 | unsigned int spa; /* sender protocol address */ 45 | 46 | uint8_t tha[NET_ARP_HA_LEN]; /* target hardware address */ 47 | 48 | unsigned int tpa; /* target protocol address */ 49 | }; 50 | #endif /* __NFP_LANG_MICROC */ 51 | 52 | #endif /* _NET_ARP_H_ */ 53 | 54 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 55 | -------------------------------------------------------------------------------- /microc/lib/net/esp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/esp.h 17 | * @brief Definitions for ESP header parsing 18 | * 19 | * Incomplete, new definitions will be added as/when needed 20 | */ 21 | 22 | #ifndef _NET_ESP_H_ 23 | #define _NET_ESP_H_ 24 | 25 | /** 26 | * ESP type definitions 27 | */ 28 | 29 | #if defined(__NFP_LANG_MICROC) 30 | 31 | #include 32 | #include 33 | 34 | /** 35 | * ESP Header structure 36 | */ 37 | __packed struct esp_hdr { 38 | uint32_t spi; /** Security Parameters Index */ 39 | uint32_t seq; /** Sequence Number */ 40 | }; 41 | 42 | #endif /* __NFP_LANG_MICROC */ 43 | 44 | #endif /* _NET_ESP_H_ */ 45 | 46 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 47 | -------------------------------------------------------------------------------- /microc/lib/net/eth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/eth.h 17 | * @brief Definitions for Ethernet header parsing 18 | * 19 | * Incomplete, new definitions will be added as/when needed 20 | */ 21 | 22 | #ifndef _NET_ETH_H_ 23 | #define _NET_ETH_H_ 24 | 25 | 26 | /** 27 | * Header length definitions 28 | * @NET_ETH_ALEN Length of Ethernet MAC address 29 | * @NET_8021Q_LEN Length of a VLAN tag 30 | * @NET_ETH_LEN Length of a Ethernet header, no VLAN 31 | * @NET_ETH_8021Q_LEN Length of a Ethernet header, with VLAN 32 | * @NET_ETH_FCS_LEN Length of Ethernet FCS 33 | */ 34 | #define NET_ETH_ALEN 6 35 | #define NET_8021Q_LEN 4 36 | #define NET_ETH_LEN 14 37 | #define NET_ETH_8021Q_LEN (NET_ETH_LEN + NET_8021Q_LEN) 38 | #define NET_ETH_FCS_LEN 4 39 | 40 | 41 | /** 42 | * An incomplete list of Ethernet protocol types 43 | * See: http://en.wikipedia.org/wiki/EtherType 44 | */ 45 | #define NET_ETH_TYPE_IPV4 0x0800 /** Internet Protocol, Version 4 */ 46 | #define NET_ETH_TYPE_ARP 0x0806 /** Address Resolution Protocol (ARP) */ 47 | #define NET_ETH_TYPE_WOL 0x0842 /** Wake-on-LAN Magic Packet */ 48 | #define NET_ETH_TYPE_TRILL 0x22f3 /** IETF TRILL Protocol */ 49 | #define NET_ETH_TYPE_TEB 0x6558 /** Trans Ether Bridging */ 50 | #define NET_ETH_TYPE_RARP 0x8035 /** Reverse Address Resolution */ 51 | #define NET_ETH_TYPE_TPID 0x8100 /** VLAN-tagged frame (IEEE 802.1Q) */ 52 | #define NET_ETH_TYPE_IPV6 0x86dd /** Internet Protocol, Version 6 */ 53 | #define NET_ETH_TYPE_MPLS 0x8847 /** MPLS unicast */ 54 | #define NET_ETH_TYPE_MPLS_MC 0x8848 /** MPLS multicast */ 55 | #define NET_ETH_TYPE_JUMBO 0x8870 /** Jumbo Frames */ 56 | #define NET_ETH_TYPE_LOOPBACK 0x9000 /** Configuration Test Protocol */ 57 | #define NET_ETH_TYPE_QINQ 0x9100 /** Q-in-Q IEEE 802.1ad */ 58 | 59 | /** 60 | * Ethernet address macros 61 | */ 62 | #define NET_ETH_LADMIN_ADDR 0x02 /** Locally assigned address. */ 63 | #define NET_ETH_GROUP_ADDR 0x01 /** Multicast or broadcast address. */ 64 | 65 | 66 | /** 67 | * VLAN definitions. 68 | * 69 | * @NET_ETH_TCI_PCP_of Priority 70 | * @NET_ETH_TCI_CFI_MASK Canonical Format Indicator 71 | * @NET_ETH_TCI_VLAN_PRESENT Appropriate the CFI for VLAN indication 72 | * @NET_ETH_TCI_VID_of VLAN ID 73 | */ 74 | #define NET_ETH_TCI_PCP_of(_x) (((_x) >> 13) & 0x3) 75 | #define NET_ETH_TCI_CFI_MASK 0x1000 76 | #define NET_ETH_TCI_VLAN_PRESENT (NET_ETH_TCI_CFI_MASK) 77 | #define NET_ETH_TCI_VID_of(_x) ((_x) & 0x0fff) 78 | 79 | 80 | #if defined(__NFP_LANG_MICROC) 81 | 82 | #include 83 | #include 84 | #include 85 | 86 | /** 87 | * Ethernet header structure 88 | */ 89 | __packed struct eth_addr { 90 | uint8_t a[NET_ETH_ALEN]; 91 | }; 92 | 93 | __packed struct eth_hdr { 94 | struct eth_addr dst; /** Destination address */ 95 | struct eth_addr src; /** Source address */ 96 | uint16_t type; /** Protocol type */ 97 | }; 98 | 99 | /** 100 | * VLAN header 101 | */ 102 | __packed struct vlan_hdr { 103 | uint16_t tci; /** Tag control identifier */ 104 | uint16_t type; /** Protocol type */ 105 | }; 106 | 107 | /** 108 | * Ethernet + VLAN header structure 109 | */ 110 | __packed struct eth_vlan_hdr { 111 | struct eth_addr dst; /** Destination address */ 112 | struct eth_addr src; /** Source address */ 113 | uint16_t tpid; /** Tag protocol identifier */ 114 | uint16_t tci; /** Tag control identifier */ 115 | uint16_t type; /** Protocol type */ 116 | }; 117 | 118 | 119 | /* 120 | * Utility functions/macros 121 | */ 122 | 123 | /** 124 | * Check if Ethernet address is Multicast 125 | * @param _a pointer for buffer containing Ethernet address to be evaluated 126 | * @ return True or False 127 | * 128 | * NOTE: This also returns True for Broadcast as well. 129 | */ 130 | __intrinsic static int 131 | net_eth_is_mc_addr(void *_a) 132 | { 133 | int is_mc_addr; 134 | ctassert(__is_in_reg_or_lmem(_a)); 135 | if (__is_in_lmem(_a)) { 136 | is_mc_addr = (((__lmem struct eth_addr *)_a)->a[0] & 137 | NET_ETH_GROUP_ADDR); 138 | } else { 139 | is_mc_addr = (((__gpr struct eth_addr *)_a)->a[0] & 140 | NET_ETH_GROUP_ADDR); 141 | } 142 | return is_mc_addr; 143 | } 144 | 145 | /** 146 | * Check if Ethernet address is Broadcast 147 | * @param _a pointer for buffer containing Ethernet address to be evaluated 148 | * @ return True or False 149 | * 150 | */ 151 | __intrinsic static int 152 | net_eth_is_bc_addr(void *_a) 153 | { 154 | int is_bc_addr; 155 | ctassert(__is_in_reg_or_lmem(_a)); 156 | if (__is_in_lmem(_a)) { 157 | is_bc_addr = (((__lmem uint16_t *)_a)[0] == 0xFFFF && 158 | ((__lmem uint16_t *)_a)[1] == 0xFFFF && 159 | ((__lmem uint16_t *)_a)[2] == 0xFFFF); 160 | } else { 161 | is_bc_addr = (((__gpr uint16_t *)_a)[0] == 0xFFFF && 162 | ((__gpr uint16_t *)_a)[1] == 0xFFFF && 163 | ((__gpr uint16_t *)_a)[2] == 0xFFFF); 164 | } 165 | return is_bc_addr; 166 | } 167 | 168 | /** 169 | * Check if Ethernet address is Unicast 170 | * @param _a pointer for buffer containing Ethernet address to be evaluated 171 | * @ return True or False 172 | * 173 | */ 174 | __intrinsic static int 175 | net_eth_is_uc_addr(void *_a) 176 | { 177 | int is_uc_addr; 178 | ctassert(__is_in_reg_or_lmem(_a)); 179 | if (__is_in_lmem(_a)) { 180 | is_uc_addr = ((((__lmem struct eth_addr *)_a)->a[0] & 181 | NET_ETH_GROUP_ADDR) == 0); 182 | } else { 183 | is_uc_addr = ((((__gpr struct eth_addr *)_a)->a[0] & 184 | NET_ETH_GROUP_ADDR) == 0); 185 | } 186 | return is_uc_addr; 187 | } 188 | 189 | /** 190 | * Copy eth addr from source to dest 191 | * 192 | * @param d destination MAC addr 193 | * @param s source MAC addr 194 | */ 195 | __intrinsic static void 196 | net_eth_cp_addr(void *d, void *s) 197 | { 198 | ctassert(__is_in_reg_or_lmem(d)); 199 | ctassert(__is_in_reg_or_lmem(s)); 200 | if (__is_in_lmem(s)) { 201 | ctassert(__is_in_lmem(d)); 202 | *(__lmem struct eth_addr *)d = *(__lmem struct eth_addr *)s; 203 | } else { 204 | ctassert(__is_in_reg(d)); 205 | *(__gpr struct eth_addr *)d = *(__gpr struct eth_addr *)s; 206 | } 207 | } 208 | 209 | #endif /* MicroC code */ 210 | 211 | #endif /* _NET_ETH_H_ */ 212 | 213 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 214 | -------------------------------------------------------------------------------- /microc/lib/net/gre.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/gre.h 17 | * @brief Definitions for GRE header parsing 18 | * 19 | */ 20 | 21 | #ifndef _NET_GRE_H_ 22 | #define _NET_GRE_H_ 23 | 24 | /** 25 | * GRE has several forms depending on the RFC (1701, 2784, DRAFT NVGRE 26 | * or 2890. Here we focus on DRAFT NVGRE and 2890. 27 | * NVGRE has flags C=0, S=0 and K=1. Proto=0x6558 (ethernet bridging) 28 | * NVGRE is a particular case of of 2890 29 | */ 30 | 31 | /** 32 | * GRE Flags 33 | */ 34 | #define NET_GRE_FLAGS_SEQ_PRESENT 0x1 35 | #define NET_GRE_FLAGS_KEY_PRESENT 0x2 36 | #define NET_GRE_FLAGS_CSUM_PRESENT 0x8 37 | 38 | /** 39 | * Convenience macro to determine if a GRE header is NVGRE 40 | * (assumming proto is NET_ETH_TYPE_TEB) 41 | */ 42 | #define NET_GRE_IS_NVGRE(flags) \ 43 | ((!(flags & NET_GRE_FLAGS_CSUM_PRESENT) && \ 44 | !(flags & NET_GRE_FLAGS_SEQ_PRESENT) && \ 45 | (flags & NET_GRE_FLAGS_KEY_PRESENT)) \ 46 | ? 1 : 0) 47 | 48 | #if defined(__NFP_LANG_MICROC) 49 | 50 | #include 51 | #include 52 | 53 | /** 54 | * GRE header structure 55 | */ 56 | __packed struct gre_hdr { 57 | unsigned int flags:4; /** Flags */ 58 | unsigned int reserved0:9; /** Reserved bits */ 59 | unsigned int version:3; /** Version */ 60 | uint16_t proto; /** Protocol */ 61 | }; 62 | 63 | __packed struct nvgre_ext_hdr { 64 | unsigned int vsid:24; /** Virtual subnet ID */ 65 | unsigned int flowID:8; /** Flow ID */ 66 | }; 67 | #endif /* __NFP_LANG_MICROC */ 68 | 69 | #endif /* _NET_GRE_H_ */ 70 | 71 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 72 | -------------------------------------------------------------------------------- /microc/lib/net/icmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/icmp.h 17 | * @brief Definitions for ICMP header parsing 18 | * 19 | * Incomplete, new definitions will be added as/when needed 20 | */ 21 | 22 | #ifndef _NET_ICMP_H_ 23 | #define _NET_ICMP_H_ 24 | 25 | /** 26 | * Header length definitions 27 | * @NET_ICMP_LEN Length of ICMP header 28 | * @NET_ICMP_LEN32 Length of ICMP header (32bit words) 29 | */ 30 | #define NET_ICMP_LEN 8 31 | #define NET_ICMP_LEN32 (NET_ICMP_LEN / 4) 32 | 33 | /** 34 | * ICMP type definitions 35 | */ 36 | #define NET_ICMP_TYPE_ECHO_REPLY 0 37 | #define NET_ICMP_TYPE_DEST_UNREACH 3 38 | #define NET_ICMP_TYPE_REDIRECT 5 39 | #define NET_ICMP_TYPE_ECHO 8 40 | #define NET_ICMP_TYPE_TIME_EXCEEDED 11 41 | #define NET_ICMP_TYPE_PARAM_PROB 12 42 | 43 | /** 44 | * ICMPv6 type definitions 45 | */ 46 | #define NET_ICMP6_TYPE_PKT_TOO_BIG 2 47 | #define NET_ICMP6_TYPE_ECHO_REQ 128 48 | #define NET_ICMP6_TYPE_ECHO_REPLY 129 49 | #define NET_ICMP6_TYPE_ROUTER_SOL 133 50 | #define NET_ICMP6_TYPE_NEIGH_SOL 135 51 | #define NET_ICMP6_TYPE_NEIGH_AD 136 52 | 53 | /* Convenience macro determine if ICMP is ECHO */ 54 | #define NET_ICMP_IS_ECHO(_type) ((_type == NET_ICMP_TYPE_ECHO_REPLY) || \ 55 | (_type == NET_ICMP_TYPE_ECHO)) 56 | 57 | /* Convenience macro determine if ICMP is ERROR */ 58 | /* http://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml used 59 | * for reference. 60 | */ 61 | #define NET_ICMP_IS_ERROR(_type) ((_type == NET_ICMP_TYPE_DEST_UNREACH) || \ 62 | (_type == NET_ICMP_TYPE_REDIRECT) || \ 63 | (_type == NET_ICMP_TYPE_TIME_EXCEEDED) || \ 64 | (_type == NET_ICMP_TYPE_PARAM_PROB)) 65 | 66 | /* Convenience macro determine if ICMPv6 is ECHO */ 67 | #define NET_ICMP6_IS_ECHO(_type) ((_type == NET_ICMP6_TYPE_ECHO_REPLY) || \ 68 | (_type == NET_ICMP6_TYPE_ECHO_REQ)) 69 | 70 | /* Convenience macro determine if ICMPv6 is ERROR */ 71 | #define NET_ICMP6_IS_ERROR(_type) (_type < NET_ICMP6_TYPE_ECHO_REQ) 72 | 73 | #if defined(__NFP_LANG_MICROC) 74 | 75 | #include 76 | #include 77 | #include 78 | 79 | /** 80 | * ICMP Header structure 81 | */ 82 | __packed struct icmp_hdr { 83 | uint8_t type; /** ICMP type */ 84 | uint8_t code; /** ICMP code */ 85 | uint16_t csum; /** ICMP checksum */ 86 | 87 | /* only valid for echo types */ 88 | uint16_t eid; /** ICMP identifier */ 89 | uint16_t eseq; /** ICMP sequence number */ 90 | }; 91 | 92 | /** 93 | * ICMP Error msg structure 94 | */ 95 | __packed struct icmpv4_err { 96 | uint8_t type; /** ICMP type */ 97 | uint8_t code; /** ICMP code */ 98 | uint16_t csum; /** ICMP checksum */ 99 | struct ip4_hdr ip; 100 | uint32_t data[2]; 101 | }; 102 | 103 | #endif /* __NFP_LANG_MICROC */ 104 | 105 | #endif /* _NET_ICMP_H_ */ 106 | 107 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 108 | -------------------------------------------------------------------------------- /microc/lib/net/libnet.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2015 Netronome, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/libnet.c 17 | * @brief Network protocol related functions 18 | */ 19 | 20 | #ifndef _LIB_NET_C_ 21 | #define _LIB_NET_C_ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "_c/csum.c" 38 | #include "_c/hdr_ext.c" 39 | 40 | #endif /* _LIB_NET_C_ */ 41 | 42 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 43 | -------------------------------------------------------------------------------- /microc/lib/net/mpls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/mpls.h 17 | * @brief Definitions for MPLS header parsing 18 | * 19 | */ 20 | 21 | #ifndef _NET_MPLS_H_ 22 | #define _NET_MPLS_H_ 23 | 24 | /* MPLS RFC 5462 is the latest but basic RFC was RFC 3032 */ 25 | 26 | /** 27 | * default MPLS UDP destination port number as per RFC 7510 28 | */ 29 | #define NET_MPLS_PORT 6635 30 | 31 | #if defined(__NFP_LANG_MICROC) 32 | 33 | #include 34 | #include 35 | 36 | /** 37 | * MPLS header structure 38 | */ 39 | __packed struct mpls_hdr { 40 | union { 41 | struct { 42 | unsigned int label:20; /** Label */ 43 | unsigned int tc:3; /** Traffic Class */ 44 | unsigned int s:1; /** Bottom of Stack */ 45 | unsigned int ttl:8; /** Time to Live */ 46 | }; 47 | unsigned int __raw; 48 | }; 49 | }; 50 | 51 | #endif /* __NFP_LANG_MICROC */ 52 | 53 | #endif /* _NET_MPLS_H_ */ 54 | 55 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 56 | -------------------------------------------------------------------------------- /microc/lib/net/sctp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/sctp.h 17 | * @brief Definitions for SCTP header parsing 18 | * 19 | * Incomplete, new definitions will be added as/when needed 20 | */ 21 | 22 | #ifndef _NET_SCTP_H_ 23 | #define _NET_SCTP_H_ 24 | 25 | /** 26 | * Header length definitions 27 | * @NET_SCTP_LEN Length of SCTP header 28 | * @NET_SCTP_LEN32 Length of SCTP header (32bit words) 29 | */ 30 | #define NET_SCTP_LEN 12 31 | #define NET_SCTP_LEN32 (NET_SCTP_LEN / 4) 32 | 33 | /** 34 | * SCTP type definitions 35 | */ 36 | 37 | #if defined(__NFP_LANG_MICROC) 38 | 39 | #include 40 | #include 41 | 42 | /** 43 | * SCTP Header structure 44 | */ 45 | __packed struct sctp_hdr { 46 | uint16_t sport; /** Source port */ 47 | uint16_t dport; /** Destination port */ 48 | 49 | uint32_t ver; /** Verification tag */ 50 | 51 | uint32_t sum; /** Checksum */ 52 | }; 53 | 54 | #endif /* __NFP_LANG_MICROC */ 55 | 56 | #endif /* _NET_SCTP_H_ */ 57 | 58 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 59 | -------------------------------------------------------------------------------- /microc/lib/net/tcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/tcp.h 17 | * @brief Definitions for TCP header parsing 18 | * 19 | * Incomplete, new definitions will be added as/when needed 20 | */ 21 | 22 | #ifndef _NET_TCP_H_ 23 | #define _NET_TCP_H_ 24 | 25 | /** 26 | * Header length definitions 27 | * @NET_TCP_LEN Length of TCP header, no options 28 | * @NET_TCP_LEN32 Length of TCP header, no options (32bit words) 29 | */ 30 | #define NET_TCP_LEN 20 31 | #define NET_TCP_LEN32 (NET_TCP_LEN / 4) 32 | 33 | /* TCP flag defines */ 34 | #define NET_TCP_FLAG_FIN (1 << 0) /* Finished */ 35 | #define NET_TCP_FLAG_SYN (1 << 1) /* Synchronize */ 36 | #define NET_TCP_FLAG_RST (1 << 2) /* Reset */ 37 | #define NET_TCP_FLAG_PSH (1 << 3) /* Push */ 38 | #define NET_TCP_FLAG_ACK (1 << 4) /* Acknowledgment */ 39 | #define NET_TCP_FLAG_URG (1 << 5) /* Urgent */ 40 | #define NET_TCP_FLAG_ECE (1 << 6) /* ECN-Echo */ 41 | #define NET_TCP_FLAG_CWR (1 << 7) /* Congestion Window Reduced */ 42 | 43 | #if defined(__NFP_LANG_MICROC) 44 | 45 | #include 46 | #include 47 | 48 | /** 49 | * TCP Header structure 50 | */ 51 | __packed struct tcp_hdr { 52 | uint16_t sport; /** Source port */ 53 | uint16_t dport; /** Destination port */ 54 | 55 | uint32_t seq; /** Sequence number */ 56 | 57 | uint32_t ack; /** Acknowledgement number */ 58 | 59 | uint8_t off:4; /** Data offset */ 60 | uint8_t x2:4; /** (unused) */ 61 | uint8_t flags; /** Flags */ 62 | uint16_t win; /** Window */ 63 | 64 | uint16_t sum; /** Checksum */ 65 | uint16_t urp; /** Urgent pointer */ 66 | }; 67 | #endif /* __NFP_LANG_MICROC */ 68 | 69 | #endif /* _NET_TCP_H_ */ 70 | 71 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 72 | -------------------------------------------------------------------------------- /microc/lib/net/udp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/udp.h 17 | * @brief Definitions for UDP header parsing 18 | * 19 | * Incomplete, new definitions will be added as/when needed 20 | */ 21 | 22 | #ifndef _NET_UDP_H_ 23 | #define _NET_UDP_H_ 24 | 25 | /** 26 | * Header length definitions 27 | * @NET_UDP_LEN Length of UDP header 28 | * @NET_UDP_LEN32 Length of UDP header (32bit words) 29 | */ 30 | #define NET_UDP_LEN 8 31 | #define NET_UDP_LEN32 (NET_UDP_LEN / 4) 32 | 33 | 34 | #if defined(__NFP_LANG_MICROC) 35 | 36 | #include 37 | #include 38 | 39 | /** 40 | * UDP Header structure 41 | */ 42 | __packed struct udp_hdr { 43 | uint16_t sport; /** Source port */ 44 | uint16_t dport; /** Destination port */ 45 | 46 | uint16_t len; /** Length */ 47 | uint16_t sum; /** Checksum */ 48 | }; 49 | #endif /* __NFP_LANG_MICROC */ 50 | 51 | #endif /* _NET_UDP_H_ */ 52 | 53 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 54 | -------------------------------------------------------------------------------- /microc/lib/net/vxlan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/net/vxlan.h 17 | * @brief Definitions for VXLAN header parsing 18 | * 19 | */ 20 | 21 | #ifndef _NET_VXLAN_H_ 22 | #define _NET_VXLAN_H_ 23 | 24 | /* default VXLAN port in the inner UDP header as per RFC 7348 */ 25 | #define NET_VXLAN_PORT 4789 26 | 27 | #if defined(__NFP_LANG_MICROC) 28 | 29 | #include 30 | #include 31 | 32 | /** 33 | * VXLAN header structure 34 | */ 35 | __packed struct vxlan_hdr { 36 | unsigned int reserved1:4; 37 | unsigned int i:1; /* Indicates valid VNI */ 38 | unsigned int reserved2:3; 39 | unsigned int reserved3:24; 40 | 41 | unsigned int vni:24; /* VXLAN Network Identifier */ 42 | unsigned int reserved4:8; 43 | }; 44 | #endif /* __NFP_LANG_MICROC */ 45 | 46 | #endif /* _NET_VXLAN_H_ */ 47 | 48 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 49 | -------------------------------------------------------------------------------- /microc/lib/nfp/_c/mac_csr_synch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Netronome, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/_c/mac_csr_synch.c 17 | * @brief Sets the MAC ethernet config command using arbiter (ring). 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /* Do not force recache */ 26 | #ifndef MAC_FORCE_RECACHE 27 | #define MAC_FORCE_RECACHE 0 28 | #endif 29 | 30 | /* an arbitrary number to insert as the arbiter source value */ 31 | #ifndef MAC_ARB_SRC_APP 32 | #define MAC_ARB_SRC_APP 4 33 | #endif 34 | 35 | __intrinsic void 36 | __mac_eth_cmd_config(unsigned int nbi, unsigned int core, unsigned int port, 37 | unsigned int cmd, sync_t sync, SIGNAL *sig) 38 | { 39 | __gpr uint32_t ring_num = (ARB_CLS_RING_NUM <<2); 40 | __gpr uint32_t ring_isl = ARB_CLS_BASE_ADDR_Hi32; 41 | __xwrite uint32_t xfr_flush; 42 | 43 | try_ctassert(nbi < NFP_MAC_MAX_ISLANDS_PER_NFP); 44 | try_ctassert(core < NFP_MAX_MAC_CORES_PER_MAC_ISL); 45 | try_ctassert(port < NFP_MAX_ETH_PORTS_PER_MAC_CORE); 46 | try_ctassert(cmd <= ARB_CODE_MAX); 47 | ctassert(__is_ct_const(sync)); 48 | ctassert(sync == sig_done || sync == ctx_swap); 49 | 50 | xfr_flush = ARB_SOURCE(MAC_ARB_SRC_APP) | ARB_RECACHE(MAC_FORCE_RECACHE) | 51 | ARB_NBI(nbi) | ARB_PORT(port) | ARB_CORE(core) | ARB_CMD(cmd); 52 | 53 | if (sync == sig_done) { 54 | __asm cls[ring_workq_add_work, xfr_flush, ring_isl, <<8, ring_num, 1],\ 55 | sig_done[*sig] 56 | } else { 57 | __asm cls[ring_workq_add_work, xfr_flush, ring_isl, <<8, ring_num, 1],\ 58 | ctx_swap[*sig]; 59 | } 60 | } 61 | 62 | 63 | __intrinsic void 64 | mac_eth_cmd_config(unsigned int nbi, unsigned int core, unsigned int port, 65 | unsigned int cmd) 66 | { 67 | SIGNAL sig; 68 | __mac_eth_cmd_config(nbi, core, port, cmd, ctx_swap, &sig); 69 | } -------------------------------------------------------------------------------- /microc/lib/nfp/_c/mem_pe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/_c/mem_pe.c 17 | * @brief NFP memory packet engine interface 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #define _MEM_PE_CMD(cmd, mem_addr, ctm_addr, size, sync, sig, shift) \ 27 | do { \ 28 | struct nfp_mecsr_prev_alu alu_ind; \ 29 | struct nfp_mecsr_cmd_indirect_ref_0 csr_ind; \ 30 | unsigned int count = (size >> shift); \ 31 | unsigned int addr_hi, addr_lo; \ 32 | \ 33 | ctassert(__is_ct_const(sync)); \ 34 | ctassert(sync == sig_done || sync == ctx_swap); \ 35 | \ 36 | addr_hi = (unsigned long long int)mem_addr >> 32; \ 37 | addr_lo = (unsigned long long int)mem_addr & 0xffffffff; \ 38 | \ 39 | /* Set up PrevAlu for the indirect */ \ 40 | alu_ind.__raw = 0; \ 41 | alu_ind.ov_len = 1; \ 42 | alu_ind.ove_data = 2; \ 43 | alu_ind.ov_bm_csr = 1; \ 44 | alu_ind.length = count - 1; \ 45 | alu_ind.data16 = ((unsigned int)ctm_addr >> 3) & 0x7fff; \ 46 | \ 47 | /* Set up CSR cmd for the indirect */ \ 48 | csr_ind.__raw = 0; \ 49 | csr_ind.byte_mask = addr_hi & 0xff; \ 50 | \ 51 | /* addr_hi is the CTM island ID (local). addr_lo is the MU lo addr */ \ 52 | addr_hi = (0x80 | __ISLAND) << 24; \ 53 | if (sync == sig_done) { \ 54 | local_csr_write(local_csr_cmd_indirect_ref_0, csr_ind.__raw); \ 55 | __asm { alu[--, --, B, alu_ind.__raw] } \ 56 | __asm { mem[cmd, --, addr_hi, <<8, addr_lo, --], \ 57 | sig_done[*sig], indirect_ref } \ 58 | } else { \ 59 | local_csr_write(local_csr_cmd_indirect_ref_0, csr_ind.__raw); \ 60 | __asm { alu[--, --, B, alu_ind.__raw] } \ 61 | __asm { mem[cmd, --, addr_hi, <<8, addr_lo, --], \ 62 | ctx_swap[*sig], indirect_ref } \ 63 | } \ 64 | } while (0) 65 | 66 | 67 | __intrinsic void 68 | __mem_pe_dma_mu_to_ctm(__ctm40 void *ctm_addr, __mem40 void *mem_addr, 69 | size_t size, sync_t sync, SIGNAL *sig) 70 | { 71 | try_ctassert(__is_aligned(size, 64)); 72 | try_ctassert(size <= 2048); 73 | 74 | _MEM_PE_CMD(pe_dma_from_memory_buffer, mem_addr, ctm_addr, 75 | size, sync, sig, 6); 76 | } 77 | 78 | __intrinsic void 79 | mem_pe_dma_mu_to_ctm(__ctm40 void *ctm_addr, __mem40 void *mem_addr, 80 | size_t size) 81 | { 82 | SIGNAL sig; 83 | 84 | __mem_pe_dma_mu_to_ctm(ctm_addr, mem_addr, size, ctx_swap, &sig); 85 | } 86 | 87 | __intrinsic void 88 | __mem_pe_dma_ctm_to_mu(__mem40 void *mem_addr, __ctm40 void *ctm_addr, 89 | size_t size, sync_t sync, SIGNAL *sig) 90 | { 91 | try_ctassert(__is_aligned(size, 64)); 92 | try_ctassert(size <= 2048); 93 | 94 | _MEM_PE_CMD(pe_dma_to_memory_buffer, mem_addr, ctm_addr, 95 | size, sync, sig, 6); 96 | } 97 | 98 | __intrinsic void 99 | mem_pe_dma_ctm_to_mu(__mem40 void *mem_addr, __ctm40 void *ctm_addr, 100 | size_t size) 101 | { 102 | SIGNAL sig; 103 | 104 | __mem_pe_dma_ctm_to_mu(mem_addr, ctm_addr, size, ctx_swap, &sig); 105 | } 106 | -------------------------------------------------------------------------------- /microc/lib/nfp/_c/remote_me.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/_c/remote_me.c 17 | * @brief Interface for local-ME-to-remote-ME related functions 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | /* 25 | * Cluster target reflect command address format: 26 | * [31:30] 2'b0 27 | * [29:24] Island number 28 | * [23:17] 7'b0 29 | * [16 ] Xfer/CSR register select (0 = Transfer register, 1 = CSR) 30 | * [15:14] 2'b0 31 | * [13:10] Master ID 32 | * [ 9: 2] First register address 33 | * [ 1: 0] 2'b0 34 | */ 35 | #define CT_REFLECT_ISL_MASK ((1 << 6) - 1) 36 | #define CT_REFLECT_MASTER_MASK ((1 << 4) - 1) 37 | #define CT_REFLECT_REG_MASK ((1 << 8) - 1) 38 | 39 | #define CT_REFLECT_MAX_ME_NUM (CT_REFLECT_MASTER_MASK - 4) 40 | 41 | #define MEREG_CT_REFLECT_ADDR(_isl, _me, _is_csr, _addr) \ 42 | ((((_isl) & CT_REFLECT_ISL_MASK) << 24) | ((_is_csr) ? 0x10000 : 0) | \ 43 | ((((_me) + 4) & CT_REFLECT_MASTER_MASK) << 10) | \ 44 | (((_addr) & CT_REFLECT_REG_MASK) << 2)) 45 | 46 | 47 | static __intrinsic void 48 | remote_me_reg_check_params(unsigned int island, unsigned int me, 49 | unsigned int reg_is_csr, unsigned int reg_addr, 50 | size_t size) 51 | { 52 | try_ctassert((island & ~CT_REFLECT_ISL_MASK) == 0); 53 | try_ctassert(me <= CT_REFLECT_MAX_ME_NUM); 54 | try_ctassert((reg_addr & ~CT_REFLECT_REG_MASK) == 0); 55 | /* Note: From 1-14 words can be transferred. */ 56 | try_ctassert(__is_aligned(size, 4)); 57 | /* TODO: Add indirect reference support for sizes greater than 8. */ 58 | try_ctassert(size >= 4 && size <= 32); 59 | } 60 | 61 | __intrinsic void 62 | __remote_me_reg_read_signal_local(__xread void *data, unsigned int island, 63 | unsigned int me, unsigned int reg_is_csr, 64 | unsigned int reg_addr, size_t size, 65 | sync_t sync, SIGNAL *local_sig) 66 | { 67 | unsigned int addr = MEREG_CT_REFLECT_ADDR(island, me, reg_is_csr, 68 | reg_addr); 69 | unsigned int cnt = size >> 2; 70 | unsigned int local_sig_num = __signal_number(local_sig); 71 | 72 | ctassert(__is_read_reg(data)); 73 | remote_me_reg_check_params(island, me, reg_is_csr, reg_addr, size); 74 | ctassert(__is_ct_const(sync)); 75 | ctassert(sync == sig_done || sync == ctx_swap); 76 | 77 | /* Signal local ME only. */ 78 | if (sync == sig_done) { 79 | __asm ct[reflect_read_sig_init, *data, addr, 0, cnt], sig_done[*local_sig]; 80 | } else { 81 | __asm ct[reflect_read_sig_init, *data, addr, 0, cnt], ctx_swap[*local_sig]; 82 | } 83 | } 84 | 85 | __intrinsic void 86 | remote_me_reg_read_signal_local(__xread void *data, unsigned int island, 87 | unsigned int me, unsigned int reg_is_csr, 88 | unsigned int reg_addr, size_t size) 89 | { 90 | SIGNAL local_sig; 91 | 92 | __remote_me_reg_read_signal_local(data, island, me, reg_is_csr, reg_addr, 93 | size, ctx_swap, &local_sig); 94 | } 95 | 96 | __intrinsic void 97 | remote_me_reg_read_signal_none(__xread void *data, unsigned int island, 98 | unsigned int me, unsigned int reg_is_csr, 99 | unsigned int reg_addr, size_t size) 100 | { 101 | unsigned int addr = MEREG_CT_REFLECT_ADDR(island, me, reg_is_csr, 102 | reg_addr); 103 | unsigned int cnt = size >> 2; 104 | 105 | ctassert(__is_read_reg(data)); 106 | remote_me_reg_check_params(island, me, reg_is_csr, reg_addr, size); 107 | 108 | /* Do not send any ME signals. */ 109 | __asm ct[reflect_read_none, *data, addr, 0, cnt]; 110 | } 111 | 112 | __intrinsic void 113 | __remote_me_reg_write_signal_local(__xwrite void *data, unsigned int island, 114 | unsigned int me, unsigned int reg_is_csr, 115 | unsigned int reg_addr, size_t size, 116 | sync_t sync, SIGNAL *local_sig) 117 | { 118 | unsigned int addr = MEREG_CT_REFLECT_ADDR(island, me, reg_is_csr, 119 | reg_addr); 120 | unsigned int cnt = size >> 2; 121 | unsigned int local_sig_num = __signal_number(local_sig); 122 | 123 | ctassert(__is_write_reg(data)); 124 | remote_me_reg_check_params(island, me, reg_is_csr, reg_addr, size); 125 | ctassert(__is_ct_const(sync)); 126 | ctassert(sync == sig_done || sync == ctx_swap); 127 | 128 | /* Signal local ME only. */ 129 | if (sync == sig_done) { 130 | __asm ct[reflect_write_sig_init, *data, addr, 0, cnt], sig_done[*local_sig]; 131 | } else { 132 | __asm ct[reflect_write_sig_init, *data, addr, 0, cnt], ctx_swap[*local_sig]; 133 | } 134 | } 135 | 136 | __intrinsic void 137 | remote_me_reg_write_signal_local(__xwrite void *data, unsigned int island, 138 | unsigned int me, unsigned int reg_is_csr, 139 | unsigned int reg_addr, size_t size) 140 | { 141 | SIGNAL local_sig; 142 | 143 | __remote_me_reg_write_signal_local(data, island, me, reg_is_csr, reg_addr, 144 | size, ctx_swap, &local_sig); 145 | } 146 | 147 | __intrinsic void 148 | remote_me_reg_write_signal_none(__xwrite void *data, unsigned int island, 149 | unsigned int me, unsigned int reg_is_csr, 150 | unsigned int reg_addr, size_t size) 151 | { 152 | unsigned int addr = MEREG_CT_REFLECT_ADDR(island, me, reg_is_csr, 153 | reg_addr); 154 | unsigned int cnt = size >> 2; 155 | 156 | ctassert(__is_write_reg(data)); 157 | remote_me_reg_check_params(island, me, reg_is_csr, reg_addr, size); 158 | 159 | /* Do not send any ME signals. */ 160 | __asm ct[reflect_write_none, *data, addr, 0, cnt]; 161 | } 162 | 163 | __intrinsic unsigned int 164 | remote_csr_read(unsigned int island, unsigned int me, unsigned int reg_addr) 165 | { 166 | __xread unsigned int data; 167 | 168 | remote_me_reg_read_signal_local(&data, island, me, 1, reg_addr, 169 | sizeof(data)); 170 | 171 | return data; 172 | } 173 | 174 | __intrinsic void 175 | remote_csr_write(unsigned int island, unsigned int me, unsigned int reg_addr, 176 | unsigned int val) 177 | { 178 | __xwrite unsigned int data = val; 179 | 180 | remote_me_reg_write_signal_local(&data, island, me, 1, reg_addr, 181 | sizeof(data)); 182 | } 183 | -------------------------------------------------------------------------------- /microc/lib/nfp/_c/tmq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/tmq.c 17 | * @brief TM queue utilities. 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define MAX_NBI_NUMBER 1 30 | #define MAX_TM_QUEUE_NUM 1023 31 | #define MAX_CMD_BURST_SZ 16 32 | 33 | /** Base addresses for the NBI TM queue registers. */ 34 | #define TMQ_XPB_BASE(_nbi) (NFP_NBI_TM_XPB_OFF(_nbi) + NFP_NBI_TM_QUEUE_REG) 35 | 36 | /** Address of the TM queue drop count register. */ 37 | #define TMQ_DROP_READ_ADDR(_nbi, _qnum) \ 38 | (TMQ_XPB_BASE(_nbi) | NFP_NBI_TM_QUEUE_DROP_COUNT(_qnum)) 39 | 40 | /** Address of the clear-on-read TM queue drop count register. */ 41 | #define TMQ_DROP_READ_CLEAR_ADDR(_nbi, _qnum) \ 42 | (TMQ_XPB_BASE(_nbi) | NFP_NBI_TM_QUEUE_DROP_COUNT_CLEAR(_qnum)) 43 | 44 | /** Address of the TM queue status register. */ 45 | #define TMQ_STATUS_ADDR(_nbi, _qnum) \ 46 | (TMQ_XPB_BASE(_nbi) | NFP_NBI_TM_QUEUE_STATUS(qnum)) 47 | 48 | 49 | /* Reads, and optionally clears, a single queue drop counter. */ 50 | __intrinsic int 51 | tmq_cnt_read(uint32_t nbi, __gpr uint32_t *counter, uint32_t qnum, int clear) 52 | { 53 | __gpr uint32_t addr; 54 | int ret = 0; 55 | 56 | if (nbi > MAX_NBI_NUMBER) { 57 | ret = -1; 58 | goto out; 59 | } 60 | 61 | if (qnum > MAX_TM_QUEUE_NUM) { 62 | ret = -1; 63 | goto out; 64 | } 65 | 66 | if (clear) 67 | addr = TMQ_DROP_READ_CLEAR_ADDR(nbi, qnum); 68 | else 69 | addr = TMQ_DROP_READ_ADDR(nbi, qnum); 70 | 71 | *counter = xpb_read(addr); 72 | 73 | out: 74 | return ret; 75 | } 76 | 77 | 78 | __intrinsic void 79 | __tmq_status_read(__xread void *status, uint32_t nbi, uint32_t qnum, 80 | unsigned int num_qs, sync_t sync, SIGNAL *sig) 81 | { 82 | uint32_t addr = TMQ_STATUS_ADDR(nbi, qnum); 83 | 84 | try_ctassert(nbi < MAX_NBI_NUMBER); 85 | try_ctassert(qnum < MAX_TM_QUEUE_NUM); 86 | 87 | __xpb_read(status, addr, num_qs << 2, MAX_CMD_BURST_SZ, sync, sig); 88 | } 89 | 90 | 91 | __intrinsic void 92 | tmq_status_read(__xread void *status, uint32_t nbi, uint32_t qnum, 93 | unsigned int num_qs) 94 | { 95 | SIGNAL sig; 96 | 97 | __tmq_status_read(status, nbi, qnum, num_qs, ctx_swap, &sig); 98 | } 99 | -------------------------------------------------------------------------------- /microc/lib/nfp/_c/xpb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/_c/xpb.c 17 | * @brief XPB related functions 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | /* 27 | * Cluster target XPB command address format: 28 | * [31 ] 1'b0 29 | * [30 ] Global/local XPB steering bit (0 = local, 1 = global) 30 | * [29:24] Island number 31 | * [23:22] XPB slave index 32 | * [21:16] XPB target device ID 33 | * [15: 2] XPB target register address 34 | * [ 1: 0] 2'b0 35 | */ 36 | #define XPB_ADDR_MASK 0x7FFFFFFC 37 | 38 | #define XPB_CMD(cmdname, data, addr, size, max_size, sync, sig) \ 39 | do { \ 40 | struct nfp_mecsr_prev_alu ind; \ 41 | unsigned int cnt = size >> 2; \ 42 | unsigned int max_cnt = max_size >> 2; \ 43 | \ 44 | try_ctassert((addr & ~XPB_ADDR_MASK) == 0); \ 45 | /* Note: From 1-16 words can be transferred. */ \ 46 | try_ctassert(__is_aligned(size, 4)); \ 47 | try_ctassert(size >= 4 && size <= 64); \ 48 | ctassert(__is_aligned(max_size, 4)); \ 49 | ctassert(max_size >= 4 && max_size <= 64); \ 50 | ctassert(__is_ct_const(sync)); \ 51 | ctassert(sync == sig_done || sync == ctx_swap); \ 52 | \ 53 | if (__is_ct_const(size)) { \ 54 | if (cnt <= 8) { \ 55 | if (sync == sig_done) { \ 56 | __asm { ct[cmdname, *data, addr, 0, \ 57 | __ct_const_val(cnt)], sig_done[*sig] }; \ 58 | } else { \ 59 | __asm { ct[cmdname, *data, addr, 0, \ 60 | __ct_const_val(cnt)], ctx_swap[*sig] }; \ 61 | } \ 62 | } else { \ 63 | /* Set up length in PrevAlu for the indirect */ \ 64 | ind.__raw = 0; \ 65 | ind.ov_len = 1; \ 66 | ind.length = cnt - 1; \ 67 | \ 68 | if (sync == sig_done) { \ 69 | __asm { alu[--, --, B, ind.__raw] }; \ 70 | __asm { ct[cmdname, *data, addr, 0, \ 71 | __ct_const_val(cnt)], sig_done[*sig], \ 72 | indirect_ref }; \ 73 | } else { \ 74 | __asm { alu[--, --, B, ind.__raw] }; \ 75 | __asm { ct[cmdname, *data, addr, 0, \ 76 | __ct_const_val(cnt)], ctx_swap[*sig], \ 77 | indirect_ref }; \ 78 | } \ 79 | } \ 80 | } else { \ 81 | /* Set up length in PrevAlu for the indirect */ \ 82 | ind.__raw = 0; \ 83 | ind.ov_len = 1; \ 84 | ind.length = cnt - 1; \ 85 | \ 86 | if (sync == sig_done) { \ 87 | __asm { alu[--, --, B, ind.__raw] }; \ 88 | __asm { ct[cmdname, *data, addr, 0, \ 89 | __ct_const_val(max_cnt)], sig_done[*sig], \ 90 | indirect_ref }; \ 91 | } else { \ 92 | __asm { alu[--, --, B, ind.__raw] }; \ 93 | __asm { ct[cmdname, *data, addr, 0, \ 94 | __ct_const_val(max_cnt)], ctx_swap[*sig], \ 95 | indirect_ref }; \ 96 | } \ 97 | } \ 98 | } while (0) 99 | 100 | __intrinsic void 101 | __xpb_read(__xread void *data, unsigned int addr, size_t size, 102 | const size_t max_size, sync_t sync, SIGNAL *sig) 103 | { 104 | ctassert(__is_read_reg(data)); 105 | XPB_CMD(xpb_read, data, addr, size, max_size, sync, sig); 106 | } 107 | 108 | __intrinsic unsigned int 109 | xpb_read(unsigned int addr) 110 | { 111 | SIGNAL sig; 112 | __xread unsigned int xfer; 113 | 114 | __xpb_read(&xfer, addr, sizeof(xfer), sizeof(xfer), ctx_swap, &sig); 115 | 116 | return xfer; 117 | } 118 | 119 | __intrinsic void 120 | __xpb_write(__xwrite void *data, unsigned int addr, size_t size, 121 | const size_t max_size, sync_t sync, SIGNAL *sig) 122 | { 123 | ctassert(__is_write_reg(data)); 124 | XPB_CMD(xpb_write, data, addr, size, max_size, sync, sig); 125 | } 126 | 127 | __intrinsic void 128 | xpb_write(unsigned int addr, unsigned int val) 129 | { 130 | SIGNAL sig; 131 | __xwrite unsigned int xfer = val; 132 | 133 | __xpb_write(&xfer, addr, sizeof(xfer), sizeof(xfer), ctx_swap, &sig); 134 | } 135 | -------------------------------------------------------------------------------- /microc/lib/nfp/libnfp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/libnfp.c 17 | * @brief Standard library for NFP 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | /* 27 | * The following files implement all the functionality in . 28 | * They may only have dependencies on and the other include 29 | * files in . They are not protected by header guards and 30 | * should not be included elsewhere. 31 | */ 32 | #include "_c/cls.c" 33 | #include "_c/macstats.c" 34 | #include "_c/me.c" 35 | #include "_c/mem_atomic.c" 36 | #include "_c/mem_bulk.c" 37 | #include "_c/mem_cam.c" 38 | #include "_c/mem_lkup.c" 39 | #include "_c/mem_pe.c" 40 | #include "_c/mem_ring.c" 41 | #include "_c/pcie.c" 42 | #include "_c/remote_me.c" 43 | #include "_c/tmq.c" 44 | #include "_c/xpb.c" 45 | #include "_c/tm_config.c" 46 | #include "_c/mac_csr_synch.c" 47 | 48 | /* 49 | * The following code implements all the functionality in . It 50 | * should not have any external dependencies (including dependencies 51 | * on include files). 52 | */ 53 | __intrinsic void 54 | ___rt_assert(void *addr) 55 | { 56 | local_csr_write(local_csr_mailbox_1, (unsigned int) addr); 57 | local_csr_write(local_csr_mailbox_0, 0); 58 | __asm ctx_arb[bpt]; 59 | } 60 | -------------------------------------------------------------------------------- /microc/lib/nfp/mac_csr_synch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/mac_csr_synch.h 17 | * @brief Prototypes for MAC ethernet config arbiter command. The 18 | * EthCmdConfig arbiter controls access to the EthCmdConfig MAC 19 | * register for every port. 20 | * During a soft reset the EthCmdConfig arbiter is disabled. The 21 | * application should restart the arbiter when required. 22 | * The application should take care to only write to EthCmdConfig 23 | * arbiter when a value has changed as not to overflow the ring. 24 | */ 25 | 26 | #ifndef _NFP__MAC_CSR_SYNCH_H_ 27 | #define _NFP__MAC_CSR_SYNCH_H_ 28 | 29 | 30 | /** 31 | * Set the MacEthCmdCfg register in a controlled manner by use of the 32 | * arbiter ring. 33 | * 34 | * @param nbi The nbi to configure (0/1) 35 | * @param core The MAC core to configure (0/1) 36 | * @param port The MAC port to configure (0..63) 37 | * @param cmd The ARB_CODE_ETH_CMD_CFG_x command to configure 38 | * (see nfp_mac_csr_synch.h) 39 | * @param sync Type of synchronization (sig_done or ctx_swap) 40 | * @param sig Signal to use 41 | * 42 | */ 43 | __intrinsic void __mac_eth_cmd_config(unsigned int nbi, unsigned int core, 44 | unsigned int port, 45 | unsigned int cmd, 46 | sync_t sync, SIGNAL *sig); 47 | 48 | __intrinsic void mac_eth_cmd_config(unsigned int nbi, unsigned int core, 49 | unsigned int port, 50 | unsigned int cmd); 51 | 52 | #endif /* _NFP__MAC_CSR_SYNCH_H_ */ 53 | -------------------------------------------------------------------------------- /microc/lib/nfp/mem_pe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/mem_pe.h 17 | * @brief NFP memory packet engine interface 18 | */ 19 | #ifndef _NFP__MEM_PE_H_ 20 | #define _NFP__MEM_PE_H_ 21 | 22 | #include 23 | #include 24 | 25 | /** 26 | * DMA from MU to CTM. 27 | * @param ctm_addr 32-bit pointer to the CTM start address (destination) 28 | * @param mem_addr 40-bit pointer to the MU start address (source) 29 | * @param size Size of the DMA, must be a multiple of 64B and <= 2048B 30 | * @param sync Type of synchronisation (sig_done or ctx_swap) 31 | * @param sig Signal to use 32 | * 33 | * @note You *must not* have more than 16 outstanding DMA commands per 34 | * CTM. It is the caller's responsibility to enforce 35 | * this. libpktdma provides safe functions which enforce this 36 | * constraint. 37 | * @note @ctm_addr must be a real address not a packet mode address. 38 | */ 39 | __intrinsic void 40 | __mem_pe_dma_mu_to_ctm(__ctm40 void *ctm_addr, __mem40 void *mem_addr, 41 | size_t size, sync_t sync, SIGNAL *sig); 42 | 43 | __intrinsic void 44 | mem_pe_dma_mu_to_ctm(__ctm40 void *ctm_addr, __mem40 void *mem_addr, 45 | size_t size); 46 | 47 | /** 48 | * DMA from CTM to MU. 49 | * @param mem_addr 40-bit pointer to the MU start address (destination) 50 | * @param ctm_addr 32-bit pointer to the CTM start address (source) 51 | * @param size Size of the DMA, must be a multiple of 64B and <= 2048B 52 | * @param sync Type of synchronisation (sig_done or ctx_swap) 53 | * @param sig Signal to use 54 | * 55 | * @note You *must not* have more than 16 outstanding DMA commands per 56 | * CTM. It is the caller's responsibility to enforce 57 | * this. libpktdma provides safe functions which enforce this 58 | * constraint. 59 | * @note @ctm_addr must be a real address not a packet mode address. 60 | */ 61 | __intrinsic void 62 | __mem_pe_dma_ctm_to_mu(__mem40 void *mem_addr, __ctm40 void *ctm_addr, 63 | size_t size, sync_t sync, SIGNAL *sig); 64 | 65 | __intrinsic void 66 | mem_pe_dma_ctm_to_mu(__mem40 void *mem_addr, __ctm40 void *ctm_addr, 67 | size_t size); 68 | 69 | #endif /* !_NFP__MEM_BULK_H_ */ 70 | -------------------------------------------------------------------------------- /microc/lib/nfp/remote_me.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/remote_me.h 17 | * @brief Interface for local-ME-to-remote-ME related functions 18 | */ 19 | #ifndef _NFP__REMOTE_ME_H_ 20 | #define _NFP__REMOTE_ME_H_ 21 | 22 | #include 23 | 24 | #if defined(__NFP_LANG_MICROC) 25 | 26 | /** 27 | * Read from a remote ME register, signalling only the local ME. 28 | * @param data Pointer to local read transfer register 29 | * @param island Remote island number 30 | * @param me Remote ME number 31 | * @param reg_is_csr Indicates remote ME register is a CSR 32 | * (0 = transfer register, 1 = CSR) 33 | * @param reg_addr Remote ME register address 34 | * @param size Size of the read, must be a multiple of 4 35 | * @param sync Type of synchronisation (sig_done or ctx_swap) 36 | * @param local_sig Local signal to use 37 | */ 38 | __intrinsic void __remote_me_reg_read_signal_local(__xread void *data, 39 | unsigned int island, 40 | unsigned int me, 41 | unsigned int reg_is_csr, 42 | unsigned int reg_addr, 43 | size_t size, 44 | sync_t sync, 45 | SIGNAL *local_sig); 46 | 47 | __intrinsic void remote_me_reg_read_signal_local(__xread void *data, 48 | unsigned int island, 49 | unsigned int me, 50 | unsigned int reg_is_csr, 51 | unsigned int reg_addr, 52 | size_t size); 53 | 54 | /** 55 | * Read from a remote ME register, signalling neither ME. 56 | * @param data Pointer to local read transfer register 57 | * @param island Remote island number 58 | * @param me Remote ME number 59 | * @param reg_is_csr Indicates remote ME register is a CSR 60 | * (0 = transfer register, 1 = CSR) 61 | * @param reg_addr Remote ME register address 62 | * @param size Size of the read, must be a multiple of 4 63 | */ 64 | __intrinsic void remote_me_reg_read_signal_none(__xread void *data, 65 | unsigned int island, 66 | unsigned int me, 67 | unsigned int reg_is_csr, 68 | unsigned int reg_addr, 69 | size_t size); 70 | 71 | /** 72 | * Write to a remote ME register, signalling only the local ME. 73 | * @param data Pointer to local write transfer register 74 | * @param island Remote island number 75 | * @param me Remote ME number 76 | * @param reg_is_csr Indicates remote ME register is a CSR 77 | * (0 = transfer register, 1 = CSR) 78 | * @param reg_addr Remote ME register address 79 | * @param size Size of the write, must be a multiple of 4 80 | * @param sync Type of synchronisation (sig_done or ctx_swap) 81 | * @param local_sig Local signal to use 82 | */ 83 | __intrinsic void __remote_me_reg_write_signal_local(__xwrite void *data, 84 | unsigned int island, 85 | unsigned int me, 86 | unsigned int reg_is_csr, 87 | unsigned int reg_addr, 88 | size_t size, 89 | sync_t sync, 90 | SIGNAL *local_sig); 91 | 92 | __intrinsic void remote_me_reg_write_signal_local(__xwrite void *data, 93 | unsigned int island, 94 | unsigned int me, 95 | unsigned int reg_is_csr, 96 | unsigned int reg_addr, 97 | size_t size); 98 | 99 | /** 100 | * Write to a remote ME register, signalling neither ME. 101 | * @param data Pointer to local write transfer register 102 | * @param island Remote island number 103 | * @param me Remote ME number 104 | * @param reg_is_csr Indicates remote ME register is a CSR 105 | * (0 = transfer register, 1 = CSR) 106 | * @param reg_addr Remote ME register address 107 | * @param size Size of the write, must be a multiple of 4 108 | */ 109 | __intrinsic void remote_me_reg_write_signal_none(__xwrite void *data, 110 | unsigned int island, 111 | unsigned int me, 112 | unsigned int reg_is_csr, 113 | unsigned int reg_addr, 114 | size_t size); 115 | 116 | /** 117 | * Read the value from a remote ME CSR. 118 | * @param island Remote island number 119 | * @param me Remote ME number 120 | * @param reg_addr Remote ME CSR address 121 | * @return The value read 122 | */ 123 | __intrinsic unsigned int remote_csr_read(unsigned int island, unsigned int me, 124 | unsigned int reg_addr); 125 | 126 | /** 127 | * Write a value to a remote ME CSR. 128 | * @param island Remote island number 129 | * @param me Remote ME number 130 | * @param reg_addr Remote ME CSR address 131 | * @param val Value to write 132 | */ 133 | __intrinsic void remote_csr_write(unsigned int island, unsigned int me, 134 | unsigned int reg_addr, unsigned int val); 135 | 136 | #endif /* __NFP_LANG_MICROC */ 137 | 138 | #endif /* !_NFP__NFP_REMOTE_ME_H_ */ 139 | -------------------------------------------------------------------------------- /microc/lib/nfp/tmq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/tmq.h 17 | * @brief TM queue utilities. 18 | * 19 | */ 20 | #ifndef _NFP__TMQ_H_ 21 | #define _NFP__TMQ_H_ 22 | 23 | #include 24 | #include 25 | 26 | /** 27 | * Reads, and optionally clears, a single queue drop counter. 28 | * @param nbi NBI to read from (0/1) 29 | * @param counter Read value (if no error) 30 | * @param qnum Queue number (0-1023) 31 | * @param clear Clear on read flag 32 | * @return 0 on success, -1 on error 33 | */ 34 | __intrinsic int tmq_cnt_read(uint32_t nbi, __gpr uint32_t *counter, 35 | uint32_t qnum, int clear); 36 | 37 | /** 38 | * Reads the status of one or a series of TM queues. 39 | * @param status Pointer to local read transfer register for the status 40 | * @param nbi NBI to read from (0/1) 41 | * @param qnum Queue number (0-1023) 42 | * @param num_qs Number of consecutive queues to read (up to 16) 43 | * @param sync Type of synchronization (sig_done or ctx_swap) 44 | * @param sig Signal to use 45 | * @return 0 on success, -1 on error 46 | */ 47 | __intrinsic void __tmq_status_read(__xread void *status, uint32_t nbi, 48 | uint32_t qnum, unsigned int num_qs, 49 | sync_t sync, SIGNAL *sig); 50 | 51 | __intrinsic void tmq_status_read(__xread void *status, uint32_t nbi, 52 | uint32_t qnum, unsigned int num_qs); 53 | 54 | #endif /* !_NFP__TMQ_H_ */ 55 | -------------------------------------------------------------------------------- /microc/lib/nfp/xpb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2017, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/nfp/xpb.h 17 | * @brief Interface for common XPB related functions and types 18 | */ 19 | #ifndef _NFP__XPB_H_ 20 | #define _NFP__XPB_H_ 21 | 22 | #include 23 | 24 | #if defined(__NFP_LANG_MICROC) 25 | 26 | /** 27 | * Read the value from one or a series of XPB addresses. 28 | * @param data Pointer to local read transfer register 29 | * @param addr XPB address 30 | * @param size Size of the read, must be a multiple of 4 31 | * @param max_size Used to determine largest read, if size is not a constant 32 | * @param sync Type of synchronization (sig_done or ctx_swap) 33 | * @param sig Signal to use 34 | */ 35 | __intrinsic void __xpb_read(__xread void *data, unsigned int addr, size_t size, 36 | const size_t max_size, sync_t sync, SIGNAL *sig); 37 | 38 | /** 39 | * Read the value from an XPB address. 40 | * @param addr XPB address 41 | * @return the value read 42 | */ 43 | __intrinsic unsigned int xpb_read(unsigned int addr); 44 | 45 | /** 46 | * Write a value to one or a series of XPB addresses. 47 | * @param data Pointer to local write transfer register 48 | * @param addr XPB address 49 | * @param size Size of the write, must be a multiple of 4 50 | * @param max_size Used to determine largest write, if size is not a constant 51 | * @param sync Type of synchronization (sig_done or ctx_swap) 52 | * @param sig Signal to use 53 | */ 54 | __intrinsic void __xpb_write(__xwrite void *data, unsigned int addr, 55 | size_t size, const size_t max_size, sync_t sync, 56 | SIGNAL *sig); 57 | 58 | /** 59 | * Write a value to an XPB address. 60 | * @param addr XPB address 61 | * @param val Value to write 62 | */ 63 | __intrinsic void xpb_write(unsigned int addr, unsigned int val); 64 | 65 | #endif /* __NFP_LANG_MICROC */ 66 | 67 | #endif /* !_NFP__NFP_XPB_H_ */ 68 | -------------------------------------------------------------------------------- /microc/lib/std/_c/cntrs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2018, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/_c/cntrs.c 17 | * @brief User defined counters support, including 64bits "regular" 18 | * counters and "packets and bytes" counters. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | __intrinsic unsigned int 26 | cntr64_get_addr(__mem40 void *base) 27 | { 28 | unsigned int addr_256b_aligned; 29 | 30 | addr_256b_aligned = ((unsigned long long int)base >> 8) & 0xffffffff; 31 | return addr_256b_aligned; 32 | } 33 | 34 | __intrinsic void 35 | cntr64_clr(unsigned int base, unsigned int offset) 36 | { 37 | struct nfp_mecsr_prev_alu ind; 38 | __gpr unsigned int byte_offset; 39 | 40 | byte_offset = offset << 3; 41 | ind.__raw = 0; 42 | ind.ov_len = 1; 43 | ind.length = 0x9; /* 2-1 , and bit LENGTH[3] shoud be set to 1 */ 44 | ind.ove_data = 2; 45 | ind.data16 = 0; 46 | __asm alu[--, --, B, ind.__raw]; 47 | __asm mem[atomic_write_imm , --, base, <<8, byte_offset], indirect_ref; 48 | } 49 | 50 | __intrinsic void 51 | cntr64_incr(unsigned int base, unsigned int offset) 52 | { 53 | __gpr unsigned int byte_offset; 54 | 55 | byte_offset = offset << 3; 56 | __asm mem[incr64, --, base, <<8, byte_offset]; 57 | } 58 | 59 | __intrinsic void 60 | cntr64_add(unsigned int base, unsigned int offset, unsigned int count) 61 | { 62 | __gpr unsigned int byte_offset; 63 | 64 | try_ctassert(count > 0); 65 | 66 | byte_offset = offset << 3; 67 | if (__is_ct_const(count) && count == 1) { 68 | __asm mem[incr64, --, base, <<8, byte_offset]; 69 | } else if (__is_ct_const(count) && count <= 0xffff) { 70 | struct nfp_mecsr_prev_alu ind; 71 | ind.__raw = 0; 72 | ind.ov_len = 1; 73 | ind.length = 8; /* 1-1 , and bit LENGTH[3] shoud be set to 1 */ 74 | ind.ove_data = 2; 75 | ind.data16 = (count & 0xffff); 76 | __asm alu[--, --, B, ind.__raw]; 77 | __asm mem[add64_imm, --, base, <<8, byte_offset], indirect_ref; 78 | } else { 79 | __xwrite unsigned int value[2]; 80 | SIGNAL add_sig; 81 | value[0] = count; 82 | value[1] = 0; 83 | __asm mem[add64, value, base, <<8, byte_offset, 1], ctx_swap[add_sig]; 84 | } 85 | } 86 | 87 | 88 | __intrinsic unsigned int 89 | cntr64_cls_get_addr(__cls void *base) 90 | { 91 | unsigned int addr_256b_aligned; 92 | 93 | addr_256b_aligned = ((unsigned long long int)base >> 8) & 0xffffffff; 94 | return addr_256b_aligned; 95 | } 96 | 97 | __intrinsic void 98 | cntr64_cls_clr(unsigned int base, unsigned int offset) 99 | { 100 | __xwrite unsigned long long zero; 101 | SIGNAL cls_sig; 102 | __gpr unsigned int byte_offset; 103 | 104 | byte_offset = offset << 3; 105 | zero = 0; 106 | __asm cls[write, zero, base, <<8, byte_offset, 2], ctx_swap[cls_sig]; 107 | } 108 | 109 | __intrinsic void 110 | cntr64_cls_incr(unsigned int base, unsigned int offset) 111 | { 112 | __gpr unsigned int byte_offset; 113 | 114 | byte_offset = offset << 3; 115 | __asm cls[incr64, --, base, <<8, byte_offset]; 116 | } 117 | 118 | __intrinsic void 119 | cntr64_cls_add(unsigned int base, unsigned int offset, unsigned int count) 120 | { 121 | __gpr unsigned int byte_offset; 122 | 123 | try_ctassert(count > 0); 124 | 125 | byte_offset = offset << 3; 126 | if (__is_ct_const(count) && count == 1) { 127 | __asm cls[incr64, --, base, <<8, byte_offset]; 128 | } else if (__is_ct_const(count) && count < 8) { 129 | __asm cls[add64_imm, --, base, <<8, byte_offset, count]; 130 | } else if (__is_ct_const(count) && count <= 0xffff) { 131 | struct nfp_mecsr_prev_alu ind; 132 | ind.__raw = 0; 133 | ind.ov_len = 1; 134 | ind.ove_data = 2; 135 | ind.data16 = (count & 0xffff); 136 | __asm alu[--, --, B, ind.__raw]; 137 | __asm cls[add64_imm, --, base, <<8, byte_offset], indirect_ref; 138 | } else { 139 | __xwrite unsigned int value[2]; 140 | SIGNAL add_sig; 141 | value[0] = count; 142 | value[1] = 0; 143 | __asm cls[add64, value, base, <<8, byte_offset, 2], ctx_swap[add_sig]; 144 | } 145 | } 146 | 147 | 148 | __intrinsic struct pkt_cntr_addr 149 | pkt_cntr_get_addr(__imem __addr40 void *base) 150 | { 151 | struct pkt_cntr_addr cntr_addr; 152 | 153 | cntr_addr.hi = ((unsigned long long int)base >> 8) & 0xff000000; 154 | cntr_addr.lo = ((unsigned long long int)base >> 3) & 0x0007ffff; 155 | 156 | return cntr_addr; 157 | } 158 | 159 | __intrinsic void 160 | pkt_cntr_clr(struct pkt_cntr_addr base, unsigned int offset, 161 | unsigned int base_select, sync_t sync, SIGNAL *sig) 162 | { 163 | /* Unused read back value */ 164 | __xread unsigned long long read_val; 165 | union stats_push_cmd push_cmd; 166 | 167 | try_ctassert(base_select <= 3); 168 | 169 | push_cmd.__raw = 0; 170 | push_cmd.base = base_select; 171 | /* Both base.lo and offset are 64 bits addresses */ 172 | push_cmd.addrs = base.lo + offset; 173 | if (sync == sig_done) { 174 | __asm mem[stats_push_clear, read_val, base.hi, <<8, push_cmd.__raw, 1], sig_done[*sig]; 175 | } else { 176 | __asm mem[stats_push_clear, read_val, base.hi, <<8, push_cmd.__raw, 1], ctx_swap[*sig]; 177 | } 178 | } 179 | 180 | __intrinsic void 181 | pkt_cntr_add(struct pkt_cntr_addr base, unsigned int offset, 182 | unsigned int base_select, unsigned short byte_count, 183 | sync_t sync, SIGNAL *sig) 184 | { 185 | __xwrite unsigned int xfer; 186 | union stats_log_cmd log_cmd; 187 | union stats_addr stts_addr; 188 | 189 | try_ctassert(base_select <= 3); 190 | 191 | log_cmd.__raw = 0; 192 | log_cmd.bytes = byte_count; 193 | log_cmd.pack = STATS_ALL_32_BIT_UNPACKED; 194 | 195 | stts_addr.__raw = 0; 196 | stts_addr.base = base_select; 197 | /* Both base.lo and offset are 64 bits addresses */ 198 | stts_addr.addrs = base.lo + offset; 199 | 200 | xfer = stts_addr.__raw; 201 | 202 | if (sync == sig_done) { 203 | __asm mem[stats_log, xfer, base.hi, <<8, log_cmd.__raw, 2], sig_done[*sig]; 204 | } else { 205 | __asm mem[stats_log, xfer, base.hi, <<8, log_cmd.__raw, 2], ctx_swap[*sig]; 206 | } 207 | } 208 | 209 | __intrinsic void 210 | pkt_cntr_read(struct pkt_cntr_addr base, unsigned int offset, 211 | unsigned int base_select, unsigned int *pkt_count, 212 | unsigned long long *byte_count) 213 | { 214 | __xread unsigned long long read_val; 215 | union stats_push_cmd push_cmd; 216 | SIGNAL read_sig; 217 | 218 | try_ctassert(base_select <= 3); 219 | 220 | push_cmd.__raw = 0; 221 | push_cmd.base = base_select; 222 | /* Both base.lo and offset are 64 bits addresses */ 223 | push_cmd.addrs = base.lo + offset; 224 | 225 | __asm mem[stats_push, read_val, base.hi, <<8, push_cmd.__raw, 1], ctx_swap[read_sig]; 226 | 227 | *pkt_count = (read_val >> 3) & 0x1fffffff; 228 | *byte_count = ((read_val >> 32) | (read_val << 32)) & 0x7ffffffff; 229 | } 230 | 231 | __intrinsic void 232 | pkt_cntr_read_and_clr(struct pkt_cntr_addr base, unsigned int offset, 233 | unsigned int base_select, unsigned int *pkt_count, 234 | unsigned long long *byte_count) 235 | { 236 | __xread unsigned long long read_val; 237 | union stats_push_cmd push_cmd; 238 | SIGNAL read_sig; 239 | 240 | try_ctassert(base_select <= 3); 241 | 242 | push_cmd.__raw = 0; 243 | push_cmd.base = base_select; 244 | /* Both base.lo and offset are 64 bits addresses */ 245 | push_cmd.addrs = base.lo + offset; 246 | 247 | __asm mem[stats_push_clear, read_val, base.hi, <<8, push_cmd.__raw, 1], ctx_swap[read_sig]; 248 | 249 | *pkt_count = (read_val >> 3) & 0x1fffffff; 250 | *byte_count = ((read_val >> 32) | (read_val << 32)) & 0x7ffffffff; 251 | } 252 | -------------------------------------------------------------------------------- /microc/lib/std/_c/event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/_c/event.c 17 | * @brief Event filters, autopush, and event managers 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | struct event_cls_filter; 33 | 34 | __intrinsic __cls struct event_cls_filter * 35 | event_cls_filter_handle(int fnum) 36 | { 37 | return (__cls void *) (NFP_CLS_EM + 38 | NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER(fnum)); 39 | } 40 | 41 | __intrinsic void 42 | event_cls_filter_setup(__cls struct event_cls_filter *filter, 43 | int type, unsigned int match, unsigned int mask, 44 | struct nfp_em_filter_status status) 45 | { 46 | __xwrite unsigned int evmask, evmatch, evstatus; 47 | __xread unsigned int evack; 48 | __cls char *faddr = (__cls char *) filter; 49 | SIGNAL s1, s2, s3, s4; 50 | 51 | evmatch = NFP_EM_FILTER_MATCH_EVENT(match); 52 | evmask = (NFP_EM_FILTER_MASK_TYPE(type) | 53 | NFP_EM_FILTER_MASK_EVENT(mask)); 54 | evstatus = status.__raw; 55 | 56 | __cls_write(&evmatch, faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_MATCH, 57 | sizeof(evmatch), sizeof(evmatch), sig_done, &s1); 58 | __cls_write(&evmask, faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_MASK, 59 | sizeof(evmask), sizeof(evmask), sig_done, &s2); 60 | __cls_write(&evstatus, 61 | faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_STATUS, 62 | sizeof(evstatus), sizeof(evstatus), sig_done, &s4); 63 | __cls_read(&evack, faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_ACK, 64 | sizeof(evack), sizeof(evack), sig_done, &s3); 65 | 66 | wait_for_all(&s1, &s2, &s3, &s4); 67 | 68 | __implicit_read(&evack); 69 | } 70 | 71 | __intrinsic void 72 | event_cls_filter_disable(__cls struct event_cls_filter *filter) 73 | { 74 | __xwrite unsigned int zero = 0; 75 | __cls char *faddr = (__cls char *) filter; 76 | SIGNAL s1, s2, s3; 77 | 78 | __cls_write(&zero, faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_MATCH, 79 | sizeof(zero), sizeof(zero), sig_done, &s1); 80 | __cls_write(&zero, faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_MASK, 81 | sizeof(zero), sizeof(zero), sig_done, &s2); 82 | __cls_write(&zero, faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_STATUS, 83 | sizeof(zero), sizeof(zero), sig_done, &s3); 84 | wait_for_all(&s1, &s2, &s3); 85 | } 86 | 87 | __intrinsic unsigned int 88 | event_cls_filter_ack(__cls struct event_cls_filter *filter) 89 | { 90 | __xread unsigned int evack; 91 | __cls char *faddr = (__cls char *) filter; 92 | 93 | cls_read(&evack, faddr + NFP_CLS_EM_CSR_SPACING * NFP_EM_FILTER_ACK, 94 | sizeof(evack)); 95 | __implicit_read(&evack); 96 | 97 | return evack; 98 | } 99 | 100 | __intrinsic void 101 | event_cls_user_event(unsigned int evdata) 102 | { 103 | __xwrite unsigned int out = evdata; 104 | 105 | cls_write(&out, (__cls void *)NFP_CLS_AUTOPUSH_USER_EVENT, sizeof(out)); 106 | } 107 | 108 | __intrinsic void 109 | event_cls_autopush_signal_setup(unsigned int apnum, unsigned int master, 110 | unsigned int thd, unsigned int signum, 111 | unsigned int xfernum) 112 | { 113 | __cls void *apaddr = (__cls void *)NFP_CLS_AUTOPUSH_SIGNAL(apnum); 114 | __xwrite unsigned int apcfg; 115 | 116 | apcfg = (NFP_CLS_AUTOPUSH_SIGNAL_MASTER_ISL_LO(master>>4) | 117 | NFP_CLS_AUTOPUSH_SIGNAL_MASTER(master) | 118 | NFP_CLS_AUTOPUSH_SIGNAL_SIGNAL_REF( 119 | ((thd & 0x7) << 4) | (signum & 0xf)) | 120 | NFP_CLS_AUTOPUSH_SIGNAL_MASTER_ISL_HI(master>>8) | 121 | NFP_CLS_AUTOPUSH_SIGNAL_DATA_REF( 122 | ((thd & 0x7) << 7) | ((xfernum & 0x3f) << 2))); 123 | 124 | cls_write(&apcfg, apaddr, sizeof(apcfg)); 125 | } 126 | 127 | __intrinsic void 128 | __event_cls_autopush_filter_reset(unsigned int fnum, unsigned int type, 129 | unsigned int autopush, sync_t sync, 130 | SIGNAL *sig) 131 | { 132 | __cls void *apfaddr = (__cls void *)NFP_CLS_AUTOPUSH_STATUS(fnum); 133 | __xwrite unsigned int apfval; 134 | 135 | ctassert(__is_ct_const(sync)); 136 | ctassert(sync == sig_done || sync == ctx_swap); 137 | 138 | apfval = (NFP_CLS_AUTOPUSH_STATUS_MONITOR(type) | 139 | NFP_CLS_AUTOPUSH_STATUS_AUTOPUSH(autopush)); 140 | 141 | __cls_write(&apfval, apfaddr, sizeof(apfval), sizeof(apfval), sync, sig); 142 | } 143 | 144 | __intrinsic void 145 | event_cls_autopush_filter_reset(unsigned int fnum, unsigned int type, 146 | unsigned int autopush) 147 | { 148 | SIGNAL sig; 149 | 150 | __event_cls_autopush_filter_reset(fnum, type, autopush, ctx_swap, &sig); 151 | } 152 | 153 | __intrinsic void 154 | event_cls_autopush_filter_disable(unsigned int fnum) 155 | { 156 | __cls void *apfaddr = (__cls void *)NFP_CLS_AUTOPUSH_STATUS(fnum); 157 | __xwrite unsigned int zero = 0; 158 | 159 | cls_write(&zero, apfaddr, sizeof(zero)); 160 | } 161 | -------------------------------------------------------------------------------- /microc/lib/std/_c/synch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2015 Netronome, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/_c/synch.c 17 | * @brief Synchronization primitives 18 | */ 19 | 20 | #ifndef _STD__SYNCH_C_ 21 | #define _STD__SYNCH_C_ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | 32 | __intrinsic void 33 | synch_cnt_dram_reset(__dram struct synch_cnt *s, uint32_t cnt) 34 | { 35 | __xwrite uint32_t wrval = cnt; 36 | 37 | mem_write_atomic(&wrval, s, sizeof(wrval)); 38 | } 39 | 40 | __intrinsic void 41 | synch_cnt_dram_ack(__dram struct synch_cnt *s) 42 | { 43 | mem_decr32(s); 44 | } 45 | 46 | __intrinsic int 47 | synch_cnt_dram_poll(__dram struct synch_cnt *s) 48 | { 49 | __xread uint32_t rdval; 50 | 51 | mem_read_atomic(&rdval, s, sizeof(rdval)); 52 | return rdval; 53 | } 54 | 55 | __intrinsic void 56 | synch_cnt_dram_wait(__dram struct synch_cnt *s) 57 | { 58 | while (synch_cnt_dram_poll(s)) {} 59 | } 60 | 61 | __intrinsic void 62 | sem_cls_wait(__cls struct sem *s, const uint32_t max_credits, 63 | uint32_t poll_interval) 64 | { 65 | __xrw struct sem xrw; 66 | __gpr int32_t my_credit; 67 | 68 | xrw.next_credit = 1; /* Take a credit */ 69 | xrw.last_complete = 0; /* Zero lets us read without changing the value */ 70 | 71 | /* test_add will read the current credit number, then increment */ 72 | cls_test_add(&xrw, s, sizeof(struct sem)); 73 | my_credit = xrw.next_credit; 74 | 75 | for (;;) { 76 | /* If the credits in flight are more than the total, wait */ 77 | if (my_credit - xrw.last_complete >= max_credits) { 78 | sleep(poll_interval); 79 | cls_read(&xrw.last_complete, &s->last_complete, sizeof(int32_t)); 80 | } else { 81 | break; 82 | } 83 | } 84 | } 85 | 86 | __intrinsic void 87 | sem_cls_post(__cls struct sem *s) 88 | { 89 | cls_incr(&s->last_complete); 90 | } 91 | 92 | #endif /* !_STD__SYNCH_C_ */ 93 | -------------------------------------------------------------------------------- /microc/lib/std/_c/write_alert.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/_c/write_alert.c 17 | * @brief CLS alert functions 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | __intrinsic void 32 | cls_write_alert_setup(unsigned int addr_mask, unsigned int addr_match, 33 | unsigned int region, unsigned int events, 34 | unsigned int data63) 35 | { 36 | __cls void *waaddr = (__cls void *)NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG; 37 | __gpr unsigned int wacfg_temp = 0; 38 | __xwrite unsigned int wacfg; 39 | 40 | if (events) 41 | wacfg_temp |= NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG_EVENTS; 42 | 43 | if (data63) 44 | wacfg_temp |= NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG_DATA63; 45 | 46 | wacfg_temp |= (NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG_ADDR_MASK(addr_mask) | 47 | NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG_ADDR_MATCH(addr_match) | 48 | NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG_REGION(region) | 49 | NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG_ENABLE); 50 | 51 | wacfg = wacfg_temp; 52 | cls_write(&wacfg, waaddr, sizeof(wacfg)); 53 | } 54 | 55 | __intrinsic void 56 | cls_write_alert_disable() 57 | { 58 | __cls void *waaddr = (__cls void *)NFP_CLS_AUTOPUSH_WRITE_ALERT_CFG; 59 | __xwrite unsigned int wacfg = 0; 60 | 61 | cls_write(&wacfg, waaddr, sizeof(wacfg)); 62 | } 63 | 64 | __intrinsic void 65 | __cls_read_write_alert_pending(__xread void *wa_pending, size_t size, 66 | sync_t sync, SIGNAL *sig) 67 | { 68 | ctassert(__is_read_reg(wa_pending)); 69 | try_ctassert(size == 8); 70 | 71 | __cls_read((void *)&wa_pending, 72 | (__cls void *)NFP_CLS_AUTOPUSH_WRITE_ALERT_PEND, 73 | size, size, sync, sig); 74 | } 75 | 76 | __intrinsic void 77 | cls_read_write_alert_pending(__xread void *wa_pending, size_t size) 78 | { 79 | SIGNAL sig; 80 | 81 | __cls_read_write_alert_pending(wa_pending, size, ctx_swap, &sig); 82 | } 83 | 84 | __intrinsic __cls struct event_cls_filter * 85 | cls_write_alert_event_setup(unsigned int fnum, unsigned int apnum, 86 | unsigned int emeid, unsigned int ectx, 87 | unsigned int esig, unsigned int exfer) 88 | { 89 | struct nfp_em_filter_status status; 90 | __cls struct event_cls_filter *filter; 91 | unsigned int event_mask; 92 | unsigned int event_match; 93 | 94 | event_mask = NFP_EVENT_MATCH(0xFF, 0, NFP_EVENT_TYPE_VALUE_UPDATED); 95 | event_match = NFP_EVENT_MATCH((NFP_EVENT_PROVIDER_NUM( 96 | emeid >> 4, 97 | NFP_EVENT_PROVIDER_INDEX_CLS)), 98 | 0, NFP_EVENT_TYPE_VALUE_UPDATED); 99 | 100 | status.__raw = 0; 101 | filter = event_cls_filter_handle(fnum); 102 | event_cls_filter_setup(filter, NFP_EVENT_TYPE_VALUE_UPDATED, event_match, 103 | event_mask, status); 104 | event_cls_autopush_signal_setup(apnum, emeid, ectx, esig, exfer); 105 | cls_write_alert_event_reset(fnum, apnum); 106 | 107 | return filter; 108 | } 109 | 110 | __intrinsic void 111 | cls_write_alert_event_disable(__cls struct event_cls_filter *filter, 112 | unsigned int fnum) 113 | { 114 | event_cls_autopush_filter_disable(fnum); 115 | event_cls_filter_disable(filter); 116 | } 117 | 118 | __intrinsic void 119 | cls_write_alert_event_reset(unsigned int fnum, unsigned int apnum) 120 | { 121 | event_cls_autopush_filter_reset( 122 | fnum, NFP_CLS_AUTOPUSH_STATUS_MONITOR_ONE_SHOT_ACK, apnum); 123 | } 124 | -------------------------------------------------------------------------------- /microc/lib/std/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/event.h 17 | * @brief Interface for event bus and event managers 18 | */ 19 | #ifndef _STD__EVENT_H_ 20 | #define _STD__EVENT_H_ 21 | 22 | #include 23 | 24 | #include 25 | 26 | struct event_cls_filter; 27 | 28 | /** 29 | * Get handler for CLS event filter. 30 | * @param fnum Event filter index 31 | * @return Handle to use for other event_cls_filter functions 32 | */ 33 | __intrinsic __cls struct event_cls_filter *event_cls_filter_handle(int fnum); 34 | 35 | /** 36 | * Setup CLS event filter. 37 | * @param filter Event filter handle 38 | * @param type Type of event filter 39 | * @param match Match value for filter 40 | * @param mask Mask value for filter 41 | * @param status Configuration for the event filter status field 42 | */ 43 | __intrinsic void event_cls_filter_setup(__cls struct event_cls_filter *filter, 44 | int type, 45 | unsigned int match, unsigned int mask, 46 | struct nfp_em_filter_status status); 47 | 48 | /** 49 | * Disable CLS event filter. 50 | * @param filter Event filter handle 51 | */ 52 | __intrinsic void event_cls_filter_disable( 53 | __cls struct event_cls_filter *filter); 54 | 55 | /** 56 | * Acknowledge CLS event filter. 57 | * @param filter Event filter handle 58 | */ 59 | __intrinsic unsigned int event_cls_filter_ack( 60 | __cls struct event_cls_filter *filter); 61 | 62 | 63 | /** 64 | * Trigger event on event bus. 65 | * @param evdata Event data 66 | * 67 | * Trigger an event on the event bus. The upper four bits of the 68 | * event data (i.e., the event provider bits in [19:16]) are hardcoded 69 | * to the current cluster number. 70 | */ 71 | __intrinsic void event_cls_user_event(unsigned int evdata); 72 | 73 | /** 74 | * Setup an event autopush signal. 75 | * @param apnum Autopush signal index number 76 | * @param master Master to push to 77 | * @param thd Thread number 78 | * @param signum Signal number 79 | * @param xfernum xfer register number 80 | * 81 | * Set up an autopush entry to signal the indicated ME thread and push 82 | * a value to the indicated xfer register. The @master parameter is 83 | * only four bits wide, indicating the ME master within the current 84 | * cluster. The xfernum is 6 bits wide and thd is 3 bits wide but they 85 | * combine into signal data reference as 8 bits. When in 8 CTX mode 86 | * the CTX (thd) uses the MSB of the transfer register (CCCT TTTT). When in 87 | * 4 CTX mode the xfernum uses the LSB of the CTX (thd) (CCTT TTTT). They do 88 | * not interfere with each other because in 4 CTX mode CTX (thd) can 89 | * only be (0, 2, 4, 6) and in 8 CTX mode xfernum can only be (0-31). 90 | */ 91 | __intrinsic void event_cls_autopush_signal_setup(unsigned int apnum, 92 | unsigned int master, 93 | unsigned int thd, 94 | unsigned int signum, 95 | unsigned int xfernum); 96 | 97 | /** 98 | * Reset an event autopush filter 99 | * @param fnum Autopush filter number 100 | * @param type Autopush filter type 101 | * @param autopush Autopush signal to invoke 102 | * @param sync Type of synchronization (sig_done or ctx_swap) 103 | * @param sig Signal to use 104 | */ 105 | __intrinsic void __event_cls_autopush_filter_reset(unsigned int fnum, 106 | unsigned int type, 107 | unsigned int autopush, 108 | sync_t sync, 109 | SIGNAL *sig); 110 | 111 | __intrinsic void event_cls_autopush_filter_reset(unsigned int fnum, 112 | unsigned int type, 113 | unsigned int autopush); 114 | 115 | /** 116 | * Disable an event autopush filter. 117 | * @param fnum Autopush filter number 118 | */ 119 | __intrinsic void event_cls_autopush_filter_disable(unsigned int fnum); 120 | 121 | #endif /* !_STD__EVENT_H_ */ 122 | -------------------------------------------------------------------------------- /microc/lib/std/hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/hash.h 17 | * @brief Functions to perform a hash over a register region. 18 | * 19 | * These functions manually unroll loops depending on the size_t 20 | * parameter. For good performance and small code size it is important 21 | * that the size parameter is a compile time constant. 22 | */ 23 | 24 | #ifndef _STD__HASH_H_ 25 | #define _STD__HASH_H_ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | /** 32 | * Compute the CRC32 over a region located in registers. 33 | * @param s Pointer to a region 34 | * @param n Size of region (in bytes) 35 | * @param init Initial seed value 36 | * @return CRC32 checksum 37 | * 38 | * @s can be located in GPR or NN register or LM. 39 | * @n must be a compile time constant and multiple of 4. 40 | */ 41 | __intrinsic uint32_t hash_me_crc32(void *s, size_t n, uint32_t init); 42 | 43 | /** 44 | * Compute the CRC32-C (iSCSI) over a region located in registers. 45 | * @param s Pointer to a region 46 | * @param n Size of region (in bytes) 47 | * @param init Initial seed value 48 | * @return CRC32-C checksum 49 | * 50 | * @s can be located in GPR or NN register or LM. 51 | * @n must be a compile time constant and multiple of 4. 52 | */ 53 | __intrinsic uint32_t hash_me_crc32c(void *s, size_t n, uint32_t init); 54 | 55 | /** 56 | * Initialize the CLS hash mask and configure the CLS hash multiply register. 57 | * @param mask Pointer to the mask in CLS memory 58 | * @param size Size in bytes of the memory allocated for mask. 59 | * Valid [4-128] 60 | * 61 | * This function will initialize the mask to all bits set so that no bits of 62 | * the data are ignored. It also configures the CLS multiply register to use 63 | * m63, m53, m36, and m4 in the hash multiplication equation. 64 | */ 65 | void cls_hash_init(__cls void *mask, uint32_t size); 66 | 67 | /** 68 | * Create a 64-bit hash_index over the transfer registers. 69 | * @param key Pointer to sufficient write transfer registers for the hash 70 | * @param mask Pointer to the start of the mask in CLS 71 | * @param size Size of the key/mask, must be a multiple of 4. Valid [4-128] 72 | * @param idx CLS hash index. Valid [0-7] 73 | * @return 64-bit hash of the key 74 | * 75 | * This function clears the hash index before creating the hash over the 76 | * transfer registers. User should call cls_hash_init() prior to this. 77 | * There are 8 hash indicies, so only 8 contexts can perform a hash at the same 78 | * time if they use unique indicies. It is the user's responsibility to make 79 | * sure that only 1 context is hashing each index at a time. 80 | */ 81 | uint64_t cls_hash(__xwrite void *key, __cls void *mask, uint32_t size, 82 | uint32_t idx); 83 | 84 | /* 85 | * The Toeplitz hash secret key maximum size is 40 bytes. It is 4 86 | * bytes longer than the maximum region size to perform the hash over. 87 | * (e.g. 36 for a IPv6 4-tuple) 88 | */ 89 | #define HASH_TOEPLITZ_SECRET_KEY_SZ 40 90 | 91 | /** 92 | * Compute the Toeplitz hash over a region located in registers. 93 | * @param s Pointer to a region 94 | * @param n Size of region (in bytes) 95 | * @param k Secret hash key (not the input region 's') 96 | * @param kn Key size (in bytes) 97 | * @return Toeplitz hash 98 | * 99 | * @s can be located in GPRs, NN or LMEM. 100 | * @n must be 8, 12, 32, or 36. This accommodates hash computation 101 | * over IPv4 only, IPv4+TCP/UDP, IPv6 only and IPv6+TCP/UDP headers 102 | * respectively. 103 | */ 104 | __intrinsic uint32_t hash_toeplitz(void *s, size_t n, void *k, size_t kn); 105 | 106 | #endif /* !_STD__HASH_H_ */ 107 | 108 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 109 | -------------------------------------------------------------------------------- /microc/lib/std/libstd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/libstd.c 17 | * @brief Standard library for MicroC 18 | */ 19 | 20 | #ifndef _STD__LIBSTD_C_ 21 | #define _STD__LIBSTD_C_ 22 | 23 | /* 24 | * The following files implement all the functionality in . 25 | */ 26 | #include "_c/cntrs.c" 27 | #include "_c/event.c" 28 | #include "_c/hash.c" 29 | #include "_c/reg_utils.c" 30 | #include "_c/synch.c" 31 | #include "_c/write_alert.c" 32 | 33 | #endif /* !_STD__LIBSTD_C_ */ 34 | 35 | -------------------------------------------------------------------------------- /microc/lib/std/reg_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/reg_utils.h 17 | * @brief Functions to treat structures in registers as memory. 18 | * 19 | * The C compiler is quite picky/unhelpful when it comes to storing 20 | * data structures in registers or local memory. This module provide 21 | * generic implementations of some useful functions to handle such 22 | * data structures. 23 | * 24 | * These functions manually unroll loops depending on the size_t 25 | * parameter. For good performance and small code size it is 26 | * important that the size parameter is a compile time constant. 27 | */ 28 | 29 | #ifndef _STD__REG_UTILS_H_ 30 | #define _STD__REG_UTILS_H_ 31 | 32 | #include 33 | #include 34 | 35 | /** 36 | * Set a region located in registers to set value. 37 | * @param d Destination 38 | * @param s_val Set value 39 | * @param n Size of region (in bytes) 40 | * 41 | * @d can be located in any type of register (GPR, NN, XFER) or LMEM. 42 | * @s_val can be any unsigned int. 43 | * @n must be a compile time constant and multiple of 4. 44 | */ 45 | __intrinsic void reg_set(void *d, unsigned int s_val, size_t n); 46 | 47 | /** 48 | * Zero a region located in registers. 49 | * @param s Pointer to the region 50 | * @param n Size of region (in bytes) 51 | * 52 | * @s can be located in any type of register (GPR, NN, XFER) or LMEM. 53 | * @n must be a compile time constant and multiple of 4. 54 | */ 55 | __intrinsic void reg_zero(void *s, size_t n); 56 | 57 | /** 58 | * Copy a region located in registers to another region or memory. 59 | * @param d Destination 60 | * @param s Source 61 | * @param n Size of region (in bytes) 62 | * 63 | * @d can be located in any type of register (GPR, NN, XFER) or LMEM. 64 | * @s can be located in any type of register (GPR, NN, XFER) or LMEM. 65 | * @n must be a compile time constant and multiple of 4. 66 | */ 67 | __intrinsic void reg_cp(void *d, void *s, size_t n); 68 | 69 | /** 70 | * Compare to memory regions located in registers for equality. 71 | * @param s1 Pointer to a region 72 | * @param s2 Pointer to a region 73 | * @param n Size of region (in bytes) 74 | * @return 1 if the regions are equal, 0 otherwise 75 | * 76 | * @s1 and @s2 can be located in any type of register (GPR, NN, XFER) or LMEM. 77 | * @n must be a compile time constant and multiple of 4. 78 | */ 79 | __intrinsic int reg_eq(void *s1, void *s2, size_t n); 80 | 81 | #endif /* !_STD__REG_UTILS_H_ */ 82 | 83 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- */ 84 | -------------------------------------------------------------------------------- /microc/lib/std/synch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2015 Netronome, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/synch.h 17 | * @brief Synchronization primitives 18 | */ 19 | 20 | #ifndef _STD__SYNCH_H_ 21 | #define _STD__SYNCH_H_ 22 | 23 | #include 24 | #include 25 | 26 | struct synch_cnt { 27 | uint32_t value; 28 | }; 29 | 30 | /** 31 | * Semaphore object required for each call 32 | */ 33 | struct sem { 34 | int32_t next_credit; /* Number of credits claimed */ 35 | int32_t last_complete; /* Number of returned credits*/ 36 | }; 37 | 38 | #define SYNCH_SEM_NAME(_name) _name##_sem 39 | #define SYNCH_CRED_NAME(_name) _name##_max_credits 40 | 41 | /** 42 | * Number of cycles to wait if no credits are available 43 | */ 44 | #define SYNCH_SEM_DEFAULT_POLL 1000 45 | 46 | /** 47 | * Declare and initialize a CLS semaphore. 48 | * @param _name Name of the semaphore 49 | * @param _cnt Max number of credits 50 | * 51 | * @note CLS based semaphore should only be used for synchronization within 52 | * an island. 53 | */ 54 | #define SEM_CLS_DECLARE(_name, _cnt) \ 55 | __export __shared __cls struct sem SYNCH_SEM_NAME(_name); \ 56 | static const uint32_t SYNCH_CRED_NAME(_name) = _cnt; 57 | 58 | /** 59 | * Wrapper to take a semaphore. 60 | * @param _name Name of the semaphore 61 | * @param _poll_interval Cycles to wait if no credits are available 62 | * 63 | * @note poll_interval must be less than 0x00100000 (1<<20), see sleep(). 64 | * Start with SYNCH_SEM_DEFAULT_POLL. Increase if there is high 65 | * contention for credits. 66 | */ 67 | #define SEM_WAIT(_name, _poll_interval) \ 68 | sem_cls_wait(&SYNCH_SEM_NAME(_name), SYNCH_CRED_NAME(_name), \ 69 | _poll_interval); 70 | 71 | /** 72 | * Wrapper to give a semaphore. 73 | * @param _name Name of the semaphore 74 | */ 75 | #define SEM_POST(_name) \ 76 | sem_cls_post(&SYNCH_SEM_NAME(_name)); 77 | 78 | /** 79 | * Reset DRAM synch counter. 80 | * @param s Synch counter 81 | * @param cnt Reset value 82 | */ 83 | __intrinsic void synch_cnt_dram_reset(__dram struct synch_cnt *s, uint32_t cnt); 84 | 85 | /** 86 | * Ack DRAM synch counter. 87 | * @param s Synch counter 88 | */ 89 | __intrinsic void synch_cnt_dram_ack(__dram struct synch_cnt *s); 90 | 91 | /** 92 | * Poll DRAM synch counter. 93 | * @param s Synch counter 94 | * 95 | * Poll synch counter and return non-nil if not zero. 96 | */ 97 | __intrinsic int synch_cnt_dram_poll(__dram struct synch_cnt *s); 98 | 99 | /** 100 | * Wait for DRAM synch counter to reach zero. 101 | * @param s Synch counter 102 | */ 103 | __intrinsic void synch_cnt_dram_wait(__dram struct synch_cnt *s); 104 | 105 | /** 106 | * Take a semaphore. Users should use the SEM_WAIT() macro. 107 | * @param sem Semaphore handle 108 | * @param max_credits Max number of credits available 109 | * @param poll_interval Cycles to wait if no credits are available 110 | * 111 | * @note poll_interval must be less than 0x00100000 (1<<20), see sleep(). 112 | * Start with SYNCH_SEM_DEFAULT_POLL. Increase if there is high 113 | * contention for credits. 114 | * @note This function will handle credit claims in order. 115 | */ 116 | __intrinsic void sem_cls_wait(__cls struct sem *sem, const uint32_t max_credits, 117 | uint32_t poll_interval); 118 | 119 | /** 120 | * Give a semaphore. Users should use the SEM_POST() macro. 121 | * @param sem Semaphore handle 122 | * 123 | * @note Users must call sem_cls_wait() before sem_cls_post(). 124 | */ 125 | __intrinsic void sem_cls_post(__cls struct sem *sem); 126 | 127 | #endif /* !_STD__SYNCH_H_ */ 128 | -------------------------------------------------------------------------------- /microc/lib/std/write_alert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2015, Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * @file lib/std/write_alert.h 17 | * @brief Interface for CLS write alert 18 | */ 19 | #ifndef _STD__WRITE_ALERT_H_ 20 | #define _STD__WRITE_ALERT_H_ 21 | 22 | #include 23 | 24 | #include 25 | 26 | /** 27 | * This module provides an API to use the CLS write alert feature. A write 28 | * alert provides the ability to have a notification when CLS is written too. 29 | * Write alert has options to configure how the write alert is triggered, 30 | * the method of notification and how the CLS memory areas sizes are 31 | * configured. 32 | * 33 | * Write alert is triggered as a write occurs to a CLS address with bit 20 of 34 | * the 16 bit CLS address set. If bit 20 is not set then the CLS write does 35 | * not cause a write alert even when write alert is configured. This allows 36 | * the user the ability to choose when to cause a write alert or not depending 37 | * on how the CLS write address is configured regardless of write alert 38 | * configuration. 39 | * 40 | * Write alert notification can be accomplished by just reading the 64 bit 41 | * write alert pending register. This register indicates by bits set where a 42 | * write in CLS a write alert has been triggered. This register clears when it 43 | * is read. 44 | * 45 | * Write alert notifications can also be used to generate an event as well as 46 | * setting the write alert pending bits. The event returns the bit indicating 47 | * the region of CLS that was written to. The write alert events are normal 48 | * CLS events; however a separate write alert event API is provided to 49 | * configure them for write alerting. To enable events the "events" bit must 50 | * be set in the write alert configuration register. Write alert areas also 51 | * can be configured to cover different address ranges. Each of the 64 bits of 52 | * the write alert pending register represents a configurable number of bytes 53 | * from 8B to 1024B per bit called a region. The region is set using the 54 | * region bits in the write alert configuration register. The write alert 55 | * region control also includes a mask/match component which provides a way to 56 | * select the region of interest or split any or those regions in half. The 57 | * mask is 8 bits which is applied on the most significant bits of the CLS 58 | * write address giving the ability to move the write alert window to 59 | * different regions. 60 | */ 61 | 62 | /** 63 | * Usage example: 64 | * A write alert CLS address that does not cause a write alert: 0x000100 65 | * A write alert CLS address that does cause a write alert: 0x100100 66 | * 67 | * Configures the first 512 bytes of CLS for write alerting with events. 68 | * cls_write_alert_setup(0xFE, 0x0, 0, 1, 0); 69 | * 70 | * Configures a write alert event filter on filter 2 autopush 11. 71 | * wa_filter = cls_write_alert_event_setup(2, 11, meid, ctx(), 72 | * __signal_number(&wa_evt_sig), 73 | * __xfer_reg_number(&wa_evt_xfer)); 74 | * 75 | * Reads the write alert pending bits. 76 | * __cls_read_write_alert_pending((void *)&wa_pending, sizeof(wa_pending), 77 | * sig_done, &wa_pending_sig); 78 | * 79 | * Re-arm the event filter. 80 | * cls_write_alert_event_reset(2, 11); 81 | */ 82 | 83 | /** 84 | * Setup a CLS write alert config. 85 | * @param addr_mask Write alert address mask (8 bits) 86 | * @param addr_match Write_alert address match (8 bits) 87 | * @param region Region (0-7) Sets number of bytes per bit set 88 | * @param events Enable write_alert event generation 89 | * @param data63 Enable write alert on 63rd bit set in data 90 | */ 91 | __intrinsic void cls_write_alert_setup(unsigned int addr_mask, 92 | unsigned int addr_match, 93 | unsigned int region, 94 | unsigned int events, 95 | unsigned int data63); 96 | 97 | /** 98 | * Disables a CLS write alert config 99 | */ 100 | __intrinsic void cls_write_alert_disable(); 101 | 102 | /** 103 | * Read CLS write alert pending value. 104 | * @param wa_pending Each bit indicates the region a write alert occurred in 105 | * @param size Size of bytes to read (must be 8) 106 | * @param sync Type of synchronization (sig_done or ctx_swap) 107 | * @param sig Signal to use 108 | * 109 | * Reads the write alert pending and returns it in wa_pending. 110 | * Write alert pending is a 64 bit value. 111 | * The process of reading write alert pending also auto clears the bits on 112 | * read. 113 | */ 114 | __intrinsic void __cls_read_write_alert_pending(__xread void *wa_pending, 115 | size_t size, sync_t sync, 116 | SIGNAL *sig); 117 | 118 | __intrinsic void cls_read_write_alert_pending(__xread void *wa_pending, 119 | size_t size); 120 | 121 | /** 122 | * Configures CLS write alert events. 123 | * @param fnum Event filter number 124 | * @param apnum Autopush signal number 125 | * @parpm emeid Event micro engine id 126 | * @param ectx Event context 127 | * @param esig Event signal 128 | * @param exfer Event read register 129 | * @return Filter handle to be used if a write alert is being disabled later. 130 | * 131 | * The write alert feature only sends a NFP_EVENT_TYPE_VALUE_UPDATED event 132 | * type when write alerting has "events" enabled. This function does not need 133 | * called if events are not enabled. The match and mask are fixed to only see 134 | * this event type. This setup routine also resets a CLS write alert autopush 135 | * event so it is ready to receive events once the configuration is setup. 136 | * This function creates an event handle, configures the event filter and 137 | * autopush, and arms the event. 138 | * NOTE: after an event is received cls_write_alert_event_reset() must be 139 | * called to re-arm the the event. 140 | */ 141 | __intrinsic __cls struct event_cls_filter *cls_write_alert_event_setup( 142 | unsigned int fnum, unsigned int apnum, 143 | unsigned int emeid, unsigned int ectx, 144 | unsigned int esig, unsigned int exfer); 145 | 146 | /** 147 | * Disable CLS write alert events. 148 | * @param filter Event filter handle 149 | * @param fnum Event filter number 150 | * 151 | * This function tears down both the event filter and autopush using the filter 152 | * event handle obtained when the write alert event was setup. 153 | * NOTE: there is almost never a time where we would disable an already 154 | * configured write alert event. 155 | */ 156 | __intrinsic void cls_write_alert_event_disable(__cls struct event_cls_filter 157 | *filter, unsigned int fnum); 158 | 159 | /** 160 | * Resets (re-arms) a CLS write alert event. 161 | * @param fnum Event filter number 162 | * @param apnum Autopush signal number 163 | * 164 | * Resets a CLS write alert autopush event. The write alert always uses a 165 | * NFP_CLS_AUTOPUSH_STATUS_MONITOR_ONE_SHOT_ACK monitor type. 166 | */ 167 | __intrinsic void cls_write_alert_event_reset(unsigned int fnum, 168 | unsigned int apnum); 169 | 170 | #endif /* !_STD__WRITE_ALERT_H_ */ 171 | -------------------------------------------------------------------------------- /scripts/Makefile.debug: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file scripts/Makefile.debug 17 | # @brief Makefile 18 | # 19 | 20 | fw_unload: 21 | nfp-nffw unload 22 | 23 | fw_start: 24 | nfp-nffw start 25 | 26 | i32me0: 27 | nfp-reg mecsr:i32.me0.Mailbox0 mecsr:i32.me0.Mailbox1 mecsr:i32.me0.Mailbox2 mecsr:i32.me0.Mailbox3 28 | 29 | i33me0: 30 | nfp-reg mecsr:i33.me0.Mailbox0 mecsr:i33.me0.Mailbox1 mecsr:i33.me0.Mailbox2 mecsr:i33.me0.Mailbox3 -------------------------------------------------------------------------------- /scripts/Makefile.nfp.config: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015-2018, Netronome Systems, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # @file apps/wire/Makefile 17 | # @brief Makefile for the ME cut-through wire app 18 | # 19 | 20 | # Configuration 21 | NFP_SDK_DIR ?= /opt/netronome 22 | NFP_STD_LIB ?= $(NFP_SDK_DIR)/components/standardlibrary 23 | PICO_CODE ?= $(NFP_STD_LIB)/picocode/nfp6000/catamaran/catamaran.npfw 24 | Q ?= @ 25 | 26 | NFAS ?= $(NFP_SDK_DIR)/bin/nfas 27 | NFCC ?= $(NFP_SDK_DIR)/bin/nfcc 28 | NFLD ?= $(NFP_SDK_DIR)/bin/nfld 29 | 30 | CHIP ?= nfp-4xxx-b0 31 | 32 | # Default nfas flags 33 | # -t => terse output 34 | # -W3 => warning level 3 35 | # -R => require register declarations 36 | # -lm 0 => define start of local memory allocation to be byte 0 37 | # -C => enable case sensitivity 38 | # -chip => build for the specified CHIP 39 | NFASFLAGS ?= -t -W3 -R -lm 0 -C -chip $(CHIP) 40 | 41 | NFLDFLAGS ?= -chip $(CHIP) 42 | 43 | # Default nfas flags 44 | # -W3 => warning level 3 45 | # -Gx6000 => specify NFP-6xxx target architecture, add -D__NFP_IS_6000 46 | # -Qspill=7 => no register spilling 47 | # -Qnn_mode=1 => next neighbor registers are self accessible (not neighbor accessible) 48 | # -Qno_decl_volatile => make all C declarations nonvolatile unless explicitly specified to be volatile 49 | # -single_dram_signal => use standard approach of bulk memory transactions use a single signal 50 | NFCCFLAGS ?= -W3 -chip $(CHIP) -Qspill=7 -Qnn_mode=1 \ 51 | -Qno_decl_volatile -single_dram_signal \ 52 | -Qnctx_mode=8 53 | 54 | FW_BUILD := $(app_src_dir) 55 | FW_FW := $(app_src_dir) 56 | FIRMWARE_DIR := $(base_dir)/microc 57 | NFCC_BASE_INC := -I. -I$(base_dir)/microc/include -I$(base_dir)/microc/lib 58 | NFAS_BASE_FLAGS := $(NFASFLAGS) 59 | NFLD_BASE_FLAGS := $(NFLDFLAGS) 60 | NFAS_BASE_INC := -I. -I$(microc_blocks_dir) -I$(microc_libs_dir) -I$(microc_inc_dir) -I$(NFP_STD_LIB)/microcode/src -I$(NFP_STD_LIB)/include 61 | 62 | --------------------------------------------------------------------------------